Saturday 3 December 2016

Embedded systems

Introduction to Embedded systems

       Objectives
 After going through this session you should be able to
       Know what an Embedded system is
       Distinguish a Real time embedded system from other systems.
       Categories of embedded systems
       Know the architecture of embedded systems
       Tell the major components of an embedded systems.
       Understand Linux embedded system architecture
       Advantages of using Linux OS for embedded systems
       In day-to-day life we come across a wide variety of consumer electronics products such as TV remote controllers, Mobile phones, fax & xerox machines etc.
       Each of these devices have one or more programmable devices waiting to interact with the environment as effectively as possible.
       These are class of “Embedded systems”, providing service in real time i.e we need not have to wait too long for the action.
       An Embedded system is a special purpose system designed to perform specific control functions often with the real-time computing constraints.
       It is usually “Embedded” as a part of complete device including hardware and software components as compared to a general purpose computer such as PC, which is designed to be flexible and to meet a wide range of end-user needs.

Examples of Embedded system
       Embedded systems controls many of the common devices in use today
       Mobiles
       Digital watches
       Traffic lights
       Printers
       Medical equipment
       MP3 players, digital cameras
       Routers, telephone switches
       Automotive

Characteristics of Real Time Embedded systems (RTES)
       RTES is precisely the union of subsystems to discharge specific task coherently.
       Single-functioned.
       RTES is meant to perform specific task.
       Tightly constraint
       The constraint of the design and marketability of RTES is more rigid than their non-real-time non-embedded systems counter parts.
       Time domain constraints are the first thing to be taken care of.
       Size, weight, power consumption and cost are other major factors
       As embedded systems is dedicated to specific tasks, design engineers can optimize it to reduce the size and cost of the product and increase the reliability and performance.
       Reactive and Real time
       Many embedded systems must continually react to the changes in the system’s environment and must compute certain results in real time without delay.  For e.g.  A car’s cruise controller continuously monitors and reacts to speed and brake sensors.  It must compute acceleration or deceleration amounts repeatedly within a limited time; a delayed computation could result in failure to maintain control of the car.

Classification of embedded systems
       The heart of the embedded systems is customized microprocessor or microcontroller
       Small scale embedded systems
      Single 8/16bit microcontroller
      Little hardware and software complexity
      Mostly  battery operated
      Need to limit power dissipation when system is running continuously
       Medium scale embedded systems
      Single or few 16 or 32 bit microcontrollers or Digital signal processors(DSP)
      Both hardware and software complexity
       Advanced/Sophisticated embedded systems
      Need multiple scalable or configurable processors
      Enormous hardware and software complexity
      Constrained by processing speed available in their hardware units

Embedded systems components
       Hardware
       Processor, interrupt controllers, I/O devices, Memories etc.
       Software
       Performs series of tasks of controlling the hardware.
       Real-time operating system (RTOS)
       RTOS is intended to serve real-time application request.
       A key characteristic of an RTOS is the level of its consistency concerning the amount of time it takes to accept and complete an application’s task
       The chief design goals is not high throughput, but rather  a guarantee of a soft or hard performance category.
       RTOS that usually meets the deadline is soft-real-time OS and if it can meet the deadline deterministically it is hard-real-time OS.
        Every embedded system may not need RTOS.

Design metrics
       A design metrics is a measurable feature of the system’s performance, cost, time for implementation etc.
       Cost
      One time cost of designing the system. Once the system is designed, any units can be manufactured without incurring additional cost.
       Size
      Physical space required by the system, usually in bytes for software and gates or transistors for hardware.
       Performance
      The execution time of the system
       Power consumption
      Amount of power consumed by the system, which may determine the life time of the battery or the cooling requirements of the IC, since more power means more heat.
       Flexibility
      The ability to change the functionality of the system without incurring heavy cost. S/w is typically considered flexible.
       Time to prototype
      Time needed to build the working version of the system which can be used to verify the system’s usefulness and correctness and to refine the system’s functionality.
       Time to market
      Time required to develop a system to the point that it can be released and sold to customers. The main contributors are design time, manufacturing time and testing time.
       Maintainability
      It is the ability to modify the system after its initial release, especially by designers who did not originally design the system.
       Correctness
      This is the measure of the confidence that we have implemented the system’s functionality correctly. We can check the functionality throughout the process of designing the functionality.

Performance design metrics
       Performance of a system is a measure of how long a system takes to execute the desired tasks.
       Latency or response time
      This is the time between the start of the task’s execution and the end.  For e.g processing an image may take 0.24ms
       Throughput
       This is the number of tasks that can be processed per unit time. For e.g, a camera may be able to process 4 images per second.
       Based on the various design metrics, the functional blocks of RTES are implemented in software or hardware

System on Chip (SOC)
       System-on-chip (SOC) is an integrated circuit that integrates all components of a computer or other electronic system into a single chip
       It may contain digital, analog, mixed-signal and often radio frequency functions – all on one chip.
       In any embedded system application, functional blocks can be
      Level I: External discrete hardware components on board
      Level II: Hardware integrated with CPU on chip(SoC)
      Level III: Done by software running on CPU


Example of Advanced embedded systems
      Multi-core system of chip, like mobile handset which has one chip containing
       DSP processor for audio/video processing
       Embedded processor like ARM
       Custom hardware for GSM
       Custom peripherals (touch screen, memory card, usb)
      Automotive application, which has network of embedded microcontrollers on board communicating together through specific bus protocol like CAN.

Embedded system hardware



Processors
       The central processing unit is the most important components in the embedded systems.
       Depending on the type of applications the processors are broadly classified into 3 categories
       General purpose microprocessors
       Microcontrollers
       Digital signal processors
       General purpose microprocessors
       This microprocessor is designed to solve problems in a large variety of applications as diverse as communications, automotives and industrial embedded systems.
       The prime of microprocessor is to read data, perform extensive calculations on that data and store the results in mass storage device or display the results.
       Have complex architecture with multiple stages of pipeline and parallel processing.
       Microcontrollers
       A microcontroller is a small computer on a single integrated circuits containing a processor, memory and I/O peripherals.
       Using on chip hardware for I/O and RAM/ROM results in pretty low performance CPU. 
       Microcontrollers often use timers to generate interrupts.
       The prime use of microcontroller is to use to control the operations of the machine using a fixed program that is stored in ROM and does not change over the lifetime of the system.
       Digital signal processors
       These processors are designed for handling signal processing algorithms.
       One of the common operations required in such applications is array manipulations which required lot of multiplication/addition operations.
       DSP units generally use multiple access and multiport memory units, allowing more than one memory in one clock cycle.

Embedded hardware for Linux systems
       Processor architecture: Linux kernel supports wide range of 32 and 64 bits architectures
      X86 and x86-64 as found in PC and embedded platforms
      ARM, with hundreds of different SOCs(multimedia, industrial)
      PowerPC (Real-time, industrial)
      MIPS(networking applications)
      Others, SuperH, Blackfin etc.

Memory
       Memory serves processor short and long-term information storage requirements while registers serve the processor’s short term storage requirements.
       Both the programs and data are stored in the memory.
       The memory may be Read-only (ROM) or Random access memory (RAM)
       It may exist of the same chip with processor or outside the chip. On chip memory is faster than off chip memory.
       To reduce the access (read/write) time, a local copy of portion of memory can be kept in a small and fast memory called “cache” memory
       Memory can also be categorized as Static and dynamic.
      Dynamic memory (DRAM) dissipate less power, hence compact and cheaper but access time is slower than static memories.
      Static memory (SRAM) are much faster than DRAMs but consume more power.
       Memory
      RAM, a very basic Linux system can work within 8MB of ram, but a more realistic system will require at least 32MB RAM
       Storage
      Flash storage with NAND and NOR Flash
      Block storage with SD/MMC  and eMMC cards
       Input Output device and interfaces
      Input output interfaces are necessary to the RTES interact with the external world.
      The input output devices kerboard, the display screen, the antenna, microphone, speaker etc.
       Networking, Ethernet, WiFi, bluetooth etc.
       Communications, SPI, I2C, SDIO, USB, UART.

Embedded Linux system architecture



Software components
       Cross-compilation tool chain
      Compilers that runs on the development machines but generates code for the target machine
       Boot loader
      Started by the hardware, responsible for basic hardware initialization, loading and executing the kernel
       Operation system
      Contains the process and memory management, network stack, device drivers and services to user space
       C Library
      The interface between the kernel and user space applications
       Libraries and applications
      All user space components, open source, 3rd party or in-house

Boot loaders
       Boot loader is a piece of code which performs
      Basic hardware initialization
      Loading of an application binary, usually OS kernel, from the flash storage, from the network or from another type of non-volatile storage
      Possibly decompression of application binary
      Execution of the application
       Most boot loaders also provides command line interface with various commands implementing different operations.

Boot loaders on x86
       X86 processors are typically bundled with non-volatile memory containing program called BIOS.
       This program is executed by CPU on reset and is responsible for initialization of basic hardware and loading a small piece code from non-volatile memory.
       This piece of code is usually the 1st stage boot loader, which will load the full boot loader.
       The boat loader than offer all its features. It understands file system formats so that kernel file is loaded directly from normal file systems.



Embedded boot loaders
       On reset, the CPU starts executing code at fix address.
       BIOS is usually not present on embedded devices.
       The hardware design must ensure that the NOR flash chip is wired so that it is accessible at the address at which CPU starts executing code.
       The first stage boot loader must be programmed at this address in the NOR flash.



Introduction to Linux kernel
       User/Application space, where applications are executed.
       Kernel Space, where the kernel exist
       GNU C library, this provides the system call interface, a mechanism to communicate between user space application and kernel
       Fundamental architecture of Linux operating system



Kernel subsystem



       System call interface: provides the means to perform function calls from user space into the kernel.
       Process Management
      Kernel in-charge of process creation and termination.
      Communication  among different processes (signals, IPC primitives)
      Process scheduling, how processes share the CPU
       Memory management
      The kernel builds up the virtual address space for all the processes.
       File systems
      Linux is heavily based on file system concepts; almost everything is treated as file.
      Linux supports multiple file systems types, i.e different ways of organizing data on the physical medium.
      E.g.  Ext2, ext3,
      Virtual File system(VFS) provides a common interface abstraction for the various file systems supported by the kernel.
       Networking
      The network stack is part of the kernel.
      It is in charge of delivering data packets across applications and network interfaces.
      All routing and address resolution issues are implemented within the kernel.
       Device control
      Almost  every system operations eventually maps to the physical device. Few exceptions such as CPU, memory, etc,
      All device control operations are performed by the code, called as Device Driver.
       IPC
      The interprocess communication on Linux includes signals, pipes and sockets, shared memory and message queues.

User space
   User space on Linux is based on the following concepts
       Program: This is the image of an application, resides on a filesystem. When an application needs to be run, the image is loaded into memory and run.
       Virtual memory: allows each process to have its own address space including memory map for code, global data and dynamic data, stack etc
       System calls: These are entry points into the kernel so that the kernel can execute services on behalf of the application.


Advantages of Linux and open-source for embedded systems
       Reusability
      The key advantage of Linux and open-source in embedded systems is the ability to re-use components.
      Open-source ecosystem already provides many components for standard features from hardware support to n/w protocols, multimedia, graphics libraries.
      Allows to quickly design and develop complicated products based on existing components.
       Low cost
      Free software can be duplicated on as many systems as you want, free of charge.
      If your embedded systems uses only free software, you can reduce the cost of software license to zero.
      Allows you to have higher budget for hardware.
       Full control
      With open-source, you have source code for all the components
      Allows unlimited modifications, changes, tuning, debugging, optimizing of code.
      Allows to have full control over the software part of your system.
       Quality
     Allows to design your system with high quality components
      Many open-source components are widely used on millions of systems.
      Usually higher quality than what an in-house development can produce or even propriety vendors.
       Eases testing of new features
      Allows to easily explore the new possibilities and solutions as open-sources is freely available.
       Community support
      Allows to speed up the resolution of problems when developing your system, as open-source software components are developed by communities of developers and users, which can provide high-quality support.

Embedded Linux development environment
       Embedded Linux solutions: Two ways to switch to embedded linux
      Use solutions provided and supported by vendors such as MontaVista, WindRiver or TimeSys. These solutions come with their own development tools and environment. They use mix of open source & proprietary tools
      Use community solutions, open source solutions. We will use open source solutions for the course.

OS for Linux development
       Using Linux as desktop operating system is recommended to embedded linux developers.
      All community tools are developed and designed to run on Linux
      All knowledge used for using desktop, also applies to embedded devices
       Desktop Linux distribution
      Any good and sufficiently recent Linux desktop distribution
       Ubuntu, Fedora , Redhat etc
       We have chosen Ubuntu as it is widely and easy to use desktop Linux distribution.

Software packages
       The distribution mechanism for software for GNU/Linux is different from the one used in windows.
       Linux distributions provides a central and coherent way of installing, updating and removing applications and libraries: packages
       Packages contains the applications or library files, associated meta-data such as version and dependencies
      .deb on Debian and Ubuntu
      .rpm on Redhat
       Packages are stored in repositaries, usually on HTTP or FTP servers

Managing software packages
       Instructions for Debian based GNU/Linux systems (Debian/Ubuntu)
      Packages repositories are specified in
       /etc/apt/sources.list
      To update package repository list
       Sudo apt-get update
      To install  a given package
       Sudo apt-get install <package-name>
      To remove a given package
       Sudo apt-get remove <package-name>
      To install all available package updates
       Sudo apt-get dist-upgrade
      Get information about the package
       apt-cache show <package-name>
      Graphical Interfaces
       Synaptic for GNOME
       KpackageKit for KDE

Host Vs. Target environment
       In embedded development, there is always a spilt between
      The Host, the development workstation, which is typically a powerful PC
      The target, which is the embedded system under development.
      They are connected by various means, almost always a serial line for debugging, frequently an Ethernet connection and sometimes JTAG for low level debugging


Cross-compiling Toolchain
       The usual tool chain available on Linux workstation is a native toolchain.
       This toolchain runs on your desktop/workstation and generates code for your workstation, usually x86
       A cross-compiled toolchain is required for target. They run on the workstation but generate code for your target.

Cross-compilation toolchain components
       Binutils
      Binutils are set of programs necessary for  compilation, linking, assembling and other debugging operations
       as -  the assembler, that generates binary code from assembler source code
       Ld, the linker
       As, ranlib to .a archives used for libraries
       Objdump, readelf, nm, strings to inspect binaries
       Strip, to strip useless part of binaries in order to reduce their size
       http://www.gnu.org/software/binutils/
       GNU C compiler
       The basic C compiler used for generating object code (both kernel and applications)
       Can compile C, C++, Ada, Fortran, Java, Objective-C, Objective-C++, and generate code for a large number of CPU architectures, including ARM, AVR, Blackn, CRIS, FRV, M32, MIPS, MN10300, PowerPC, SH, v850, i386, x86 64, IA64, Xtensa, etc.
        http://gcc.gnu.org/
        Available under the GPL license, libraries under the LGPL.

C library
       The C library is an essential component of a Linux system
       Interface between the applications and the kernel
       Provides the well-known standard C API to ease application development
       Several C libraries are available:
      glibc, uClibc, eglibc, dietlibc, newlib, etc.
       The choice of the C library must be made at the time of the cross-compiling toolchain generation, as the GCC compiler is compiled against a specific C library.

Machines in build procedures
       Three machines must be distinguished when discussing toolchain creation
      The build machine, where the toolchain is built.
      The host machine, where the toolchain will be executed.
      The target machine, where the binaries created by the toolchain are executed.
       Four common build types are possible for toolchains

Different tool chain build procedures


No comments:

Post a Comment