A typical modern digital computer
-
Most of them follow the Von Neumann architecture
- Stored program architecture
- Arithmetic and logical processing unit, the CPU
- Read/Write memory which stores both the instructions (program) and the data that needs to be manipulated
-
The CPU keeps fetching instructions from the memory and executes them in sequence.
- Control transfer instructions can be used to alter the flow of programs
- Typically used when the logic has to take different actions based on some conditions
- Control transfer instructions can be used to alter the flow of programs
-
Modern digital computers are equipped with multiple input and output devices that allow humans to interact with them efficiently.
-
There are 2 broad types of architectures
- Harvard - has data memory and instruction memory separate
- Von Neumann - data and instruction memory are kept together
-
What is digital and why digital:
- All information is stored in digital form, which is 1’s and 0’s and is manipulated with the help of computer programs
- All values are discrete values
- Binary representation give a good amount of error resilience, and it is easy to build hardware circuitry to implement the basic arithmetic and logical operations needed.
How are numbers stored
- Binary number system
- The decimal number system has base 10.
- The binary number system has base 2.
- We represent negative numbers using 2s complement notation
Binary operations
- The addition and subtraction rules are straightforward
- It is easy to construct digital hardware circuitry to do binary addition, complement generation, subtraction and also multiplication and division using efficient algorithms.
- Logical operations like comparision of two numbers can also be achieved using these basic arithmetic operations (subtracting and checking the result)
- More bit level operations can also be easily implemented in hardware
Storing text
- Only 0s and 1s can be stored.
- So text has to be encoded before storage
- One standard encoding is ASCII, and to accomodate more symbols we also invented Unicode.
- Essentially every computer has agreed to store and implement the binary values as per a definite standard to encode the text.
Basic operation of a CPU
- The CPU in every computer keeps doing the following:
- Read an instruction from memory, say location X
- decode the instruction ie understand what operation needs to be done
- execute - do that operation
- then go to the next instruction location say X + 1 and repeat the process
- Control transfer instructions will modify the next instruction location to effect change in the logical flow of a program
- This is known as the fetch decode and execute cycle.
Instruction sequence
- MOV A, 0 - Store 0 in register A
- MOV B, Addr M - Read values from address location M, store in B
- ADD B - value of B is added to A
- MOV B, Addr M + 1 - Read value from next location into register B, the next number
- ADD B - A contained the partial sum, now add the next sum
- MOV B, Addr M + 2 - Read next location
- and so on
Interrupts and exceptions
- other than the control flow statements that change change the sequence of processor execution, there are 2 other conditions that change the flow of instruction execution.
- Interrupts - There are typically external inputs which are indicated to the CPU by the means of one or more hardware pins on the chip. Typically at the end of every instruction execution, the CPu checks for the status of these pins, and if there is no active signal, the processor recognizes this as some external devices needs attention and the flow of execution jumps to a specific routine.
- This routine is known as the interrupt service routine.
- Normally this routine checks the actual cause of the interrupe and takes necessary action such as
- Reading a data register to receive incoming data, or writing a data register to transmit data - interrupt will be raised when the incoming register is filled up or the earlier contents of the outgoing register has been transmitted successfully.
- Responding in any other fashion as indicated by the source of the interrupt. For example, if the interrupe is due to the tank becoming empty, the tourine may take action to turn on the motor.
Architecture of an embedded system
- Microcontroller or microprocessor based design
- Popular processors are from the ARM family
- Boot code is either in flash memory or external based on the design
- A good range of peripherals is supported on the chip itself, keeps cost low for most applications
- Software complexity ranges from simple tight loop systems to linux based systems based on the complexity
- Grade of processor varies based on the need. A simple tight loop software may use an ARM M series microcontroller, whereas a high end home router design running Linux wull use an ARM A series SoC with good amount of external memory and other specific peripherals.
ARM Cortex M4 (48 MHz)
- This block represents the microprocessor core, which is an ARM cortex M4
- This processor includes support for a floating point unit, and also has special digital signal processing instruction support
- DSP support is great for encoding audio and video signals
- It also shows a memory protection unit (MPU) which provides some functionality to check for conditions like stack over/undeflows helping in identifying issues and improving reliability of the software
- NVIC is a Nested Vector Interrupt Controller which helps in handling the interrupts generated from multiple sources.
- There is also a system timer and support for debug interfaces.
Memory
- The Renesas RA4M1 does not support any external memory, and all the code and data needs to be stored in the on chip memory areas.
- On chip memory is of 2 types
- Flash memory, this is non - volatile and needs to be programmed using the boot monitor that is built in and external flash programmer softwre/device.
- 256KB of code flash
- 8KB of Data flash
- SRAM - This is volatile static RAM
- Flash memory, this is non - volatile and needs to be programmed using the boot monitor that is built in and external flash programmer softwre/device.
System control area
- This block represents the different registers and controls that need to be programmed for the microcontroller to be properly initialized and setup for use.
- Processor modes, clock generation, reset handling, power management are some of the functions that are part of this.
- Initialization software typically has to program different registers to setup the MCU as needed by the application.
Direct Memory Access (DMA)
- Most modern microcontrollers/microprocessor has this block
- This is a special hardware block which allows data to be transferred to and from memory and peripherals without the CPU executing code.
- Helps in improving the overall efficiency and throughput of the system and the CPU is free to focus on other tasks and not get burdened with data movement.
Timers
- This block shows all the different timers that are available on the chip.
- This includes multiple general purpose timers (GPT), a real time clock (RTC), support for PWM waveform generation, watchdog timers
- Many embedded applications have a need to measure the passage of time for completing certain actions and support for a good set of flexible timers helps the embedded system designer to implement such functionality easily
- Watchdog timers are very useful to restart the system automatically when there are issues that cause the software to freeze or to be in some endless loops.
- In a healthy system, the software is designed to reset the watchdog timer periodically, i.e. before it fires.
- If this reset does not happen, it is likely due to the system not being responsive and the CPU is stuck in some process/task that does not allow the watchdog resetting task to execute. In such cases, the watchdog timer expiry would trigger a reset of the entire system which will help in recovering.
Communication interfaces
- The embedded system needs to communicate with other devices, sensors, peripherals, etc and so multiple interfaces are provided in the RA4M1
- SCI - Can be configured to function like a UART, a simple clock synchronous interface or simple IIC, SPI or a smart card interface. Can support multiple protocols. Its programmable.
- IIC port - full support for IIC
- SPI port - serial peripheral interface - full duplex support
- SSIR port - serial sound interface enhanced
- CAN port - controller area network - used in electromagnetically noisy environments
- USBFS port - USB full speed port
Human machine interface
- These are interfaces which allow input and output to human users or operators
- CTSU - capacitive touch sensing unity which is used to interface with touch based input signals
- SLCDC - segment LCD controller to provide support for an LCD
Security and other features
- SCE5 - secure cryptographic engine
- supports AES encryption
- 32 bit true random number generator (TRNG) using the physical characteristics of the chip itself to generate truly (not pseudo) random numbers - critical for security
- unique ID (unique to that device)
- CRC - cyclic redundancy check module to ensure data integrity
- Dedicated HW blocks for AES, CRC ensures that the CPU does not get loaded by running these computationally intensive algorithms, This ensures good performance without compromising security.
Analog support
- Many embedded systems need to support measurement of external conditions like temperature, pressure, etc, which are usually done with sensors that provide an analog output, typically voltage proportional to the sensed parameter. These need to be processed by the CPU, and it can be done by converting it into a digital for, This is done by an ADC.
- 14 bit ADC - successive approximation method
- Similarlym there is also a need to drive things like a motor or other devices where speed, etc can be controlled by an analog input to those devices. The software can generate digital values that are converted into ana analog form by DAC.
- 12 bit DAC with output amplifier
- 8 bit DAC without output amplifier to generate reference voltages
- Low power analog comparator
- Temperature sensor
- Operational amplifiers
Embedded systems software
- Endless loop
- for simple systems, the entire software is implemented as an endless loop. In every iteration of the loop, a series of tasks are performed. Based on the system there could be sometimes a delay sleep between each iteration of the loop
- Custom built kernels
- Slightly more complex systems can be built by designing a small kernel (a simple OS) that supports the notion of tasks and simple communication primitives between them. Many embedded systems are built in this manner.
- Commercial RTOS (Real time operating system)
- for more complex and mission critical applications, especially hard real time systems, a commercial RTOS like VxWorks or QNX is often used. Free - (FreeRTOS)
- They provide extensive support for tasks, priority based scheduling, multiple communication and synchronization primitives between the tasks, and extensive support for I/O and networking.
- for more complex and mission critical applications, especially hard real time systems, a commercial RTOS like VxWorks or QNX is often used. Free - (FreeRTOS)
- Flavours of Linux
- A large class of embedded systems fall under what can be called soft real time systems and linux is a good fit for many of these applications.
- Linux is a general purpose OS, but in these systems, the normal end user is not allowed to run arbitrary programs on the system. Generally all the required software components are pre-built and shipped.
- Often the user is not aware that the product is using linux.
- It is a very good choice for a large class of systems dure to the wide support for different types of input and output devices and excellent support for networking, and a huge base of open source middleware commponents databases, etc.
- The underlying kernel (linux) is the same, but it is distributed in a lot of distributions (flavours)
- A large class of embedded systems fall under what can be called soft real time systems and linux is a good fit for many of these applications.
RTOS components
- Task or process abstraction - allows one to split the functionality into multiple threads of execution, often concurrent
- Inter task communication - provides ways for the different tasks to communicate with each other. Common methods include message passing, shared memory, queues, etc.
- Inter task synchronization - often the sequence of activities needs to be closely coordinated between the various tasks. Also, if a particular task is interacting with a particular device or peripheral, other tasks need to wait for the first task to complete. Various primitives are provided to support these like mutex locks, semaphores, etc.
- Device handling layer - Most RTOS provide a layer of software that allows the various tasks to access the devices ina standardized manner.
- Networking and other protocol support
- Custom built kernels often provide a subset of these features, based on the need of the application.
Linux components
- Linux provides a standard abstraction of a process where individual processes have their own protected address space which helps in building complex systems in a robust manner.
- There is also support for multiple threads within a single process, which all share the same address space (of the process) this is loosely similar to tasks in a RTOS
- Good inter process communication and synchronization upport
- Extensive support for storage and networkinig with a full range of protocols being available
- Huge set of middle ware components like RDBMS, key value stores, in memory caches, messaging buses, graphics and more which help in building the product quicly and reliably
- Some flavours of linux also support additional scheduling classes (algorithms) which help in better management og the timing constraints of the system, allows one to build systems which have more real time constraints.