Bogotobogo
contact@bogotobogo.com
- C++ Home
- Algorithms in C++
- auto_ptr
- Binary Tree Example Code
- Blackjack with Qt
- Boost
- Classes and Structs
- Constructor
- C++11(C++0x): rvalue references, move constructor, and lambda, etc.
- C++ API Testing
- C++ Keywords
- C++ with Eclipse
- Debugging Crash & Memory Leak
- Design Patterns in C++
- Dynamic Cast Operator
- Embedded Systems Programming
- Exceptions
- Friend Functions and Friend Classes
- fstream: input & output
- Functors (Function Objects)
- Libraries
- Linked List Examples
- make and gnu make
- Memory Allocation
- Multi-Threaded Programming - Terminology
- Multi-Threaded Programming II - Native Thread for Win32 (A)
- Multi-Threaded Programming II - Native Thread for Win32 (B)
- Multi-Threaded Programming II - Native Thread for Win32 (C)
- Multi-Threaded Programming II - C++ Thread for Win32
- Multi-Threaded Programming III - C/C++ Class Thread for Pthreads
- MultiThreading/Parallel Programming - IPC
- Multi-Threaded Programming with C++11 Part A (start, join(), detach(), and ownership)
- Multi-Threaded Programming with C++11 Part B (Sharing Data - mutex, and race conditions, and deadlock)
- Multithread Debugging
- Object Returning
- Object Slicing and Virtual Table
- Operator Overloading
- Pass by Value vs. Pass by Reference
- Pointers
- Pointers II - void pointers & arrays
- Pointers III - pointer to function & multi-dimensional arrays
- Preprocessor - Macro
- Private Inheritance
- Python & C++ with SIP
- References for Built-in Types
- Socket - Server & Client
- Socket - Server & Client with Qt (Asynchronous / ThreadPool etc.)
- Stack Unwinding
- Standard Template Library (STL) I - Vector & List
- Standard Template Library (STL) II - Maps
- Standard Template Library (STL) III - Iterators
- Standard Template Library (STL) IV - Algorithms
- Static Variables and Static Class Members
- String
- Taste of Assembly
- Templates
- The this Pointer
- Type Cast Operators
- Upcasting and Downcasting
- Virtual Functions
- Programming Questions and Solutions
When we talk about embedded systems programming, in general, it's about writing programs for gadgets.
Gadget with a brain is the embedded system. Whether the brain is a microcontroller or a digital signal processor (DSP), gadgets have some interactions between hardware and software designed to perform one or a few dedicated functions, often with real-time computing constraints.
Usually, embedded systems are resource constrained compared to the desktop PC. Embedded systems, typically, have limited memory, small or no hard drives, and in some cases with no external network connectivity.
Picture: https://blogs.akamai.com - The Performance Arms Race
Presentation Materials: Effective C++ in an Embedded Environment (pdf) by Scott Meyers, 2012
http://www.artima.com/shop/effective_cpp_in_an_embedded_environment.
According to LinuxDevices.com, Linux has emerged as the dominant OS for embedded systems, and it will reach 70% of the market by 2012.
Go to Embedded Linux.
COMs gain traction as time-to-market accelerators for OEMs
By combining COM express modules with off-the-shelf COMs, suppliers are able to offer several different configurations of CPU boards and leverage COMs' interchangeable characteristics. CPU vendors can thus offer a fairly wide range of boards without incurring high design and inventory carrying costs.
PC/104 module family under pressure
Although VDC data projects the PC/104 family will experience a single-digit rebound from the low points of the recent recession, vendors will have to commit resources to developing newer strategies in order for this technology to remain viable. Otherwise, the recovery of these architectures is likely to stall or decline in 2011.
Asia continues to rise in the development of embedded technology
2011 will see further strengthening of the Asian embedded supplier community as supply chain synergies, R&D capabilities and fabrication automation increases between upstream and downstream ecosystem partners.
China's growth will power MCU market
Continued economic growth in China will drive the country's automotive market and expand the need for MCU (microcontroller unit) technology. Despite reduction in government subsidies, VDC expects the Chinese automotive market to expand substantially through 2015, driving adoption of MCU solutions.
Suppliers will invest in services value chain
While embedded hardware margins show signs of stability in 2011, it's clear to VDC that leading embedded suppliers also recognize the value their clients place on a range of services capabilities. As a result, many leading suppliers will try to differentiate by investing in critical aspects of the services value chain, from consulting capabilities to enhanced warranty and end-of-life policies.
FPGA and GPU will expand into a number of market segments
The medical, industrial automation and military segments provide an attractive opportunity for FPGA (Field Programmable Gate Array) devices. From imaging equipment to diagnostic devices, there is a need for adaptable health care, factory control and military C4 solutions. The programmability, flexibility and reduced NRE (non-recurring engineering) costs associated with FPGAs will lend themselves to broader adoption in these markets.
Tier 2/Tier 3 OEMs and ISVs will become more important
Investment in solutions requiring embedded platforms continues to rebound; however, the market will still be driven by small- to mid-sized projects. This is related to the slow return of larger, blanket purchase orders let by Tier 1 accounts and to the user community preferences for projects with smaller footprints that fit within narrower application definitions and require short, sharply defined systems integration support. These projects are tailor-made for local, expert ISVs and ISIs, as well as Tier 2/Tier 3 OEMs.
The market explores HaaS (Hardware as a Service) bundles
Broad market expansion and deep application penetration of remote monitoring and control capabilities will advance across a number of market segments, foretelling a broader migration to managed services solution development and deployment models in supervisory monitoring and control applications. These embedded application clouds will require local points of presence (POPs) or on-site infrastructure and hardware rolled into service level agreements (SLAs) supporting the software and service delivery portions of contracts.
Cross-platform processor suppliers learn to play nice
From broader, bigger, more aggressive, public licensing agreements to M&A, the market will force suppliers of CPU, FPGA and GPU (graphics processing unit) technologies to collaborate more in 2011. VDC Research's surveys of hundreds of OEMS across a number of embedded markets reveal significant growth in OEM plans to develop solutions on hybrid platforms incorporating two or more of these technologies.
Competition will intensify and growth will accelerate
Even if the market does not return to pre-recession levels, growth will accelerate during 2011. VDC sees virtually every vertical market growing more than five percent, and most technology categories achieving the same five percent CAGR. However, profitability results may not be so positive. Demand for stable technologies, brutal price concessions and expanded services requirements will provide opportunities for differentiation and revenues, but not necessarily margin.
Android to catalyze further growth in commercial Linux market
As device manufacturers take Android into new application classes beyond mobile, the commercial Linux market will experience further growth.
Multi-OS systems will grow in designs
More application classes will have sophisticated UI functionality that is not supported by traditional OSs and end-users will seek out multi-OS systems.
Virtualization in embedded and mobile systems will increase
Driven by hardware bill of materials savings and reduced concerns regarding additional run-time execution latencies and costs, operating system virtualization will provide increased growth opportunities, and therefore will continue to be a significant focus for many suppliers.
Symbian's loss to become MeeGo's gain
Intel's increasing focus on embedded combined with Symbian's loss of strategic direction will drive additional gains for MeeGo as Nokia turns their attention toward the Linux-based platform.
OEMs to increase focus on the use of web security test tools
Increased interaction with the cloud and web-based content by more embedded device classes will increase OEM focus on use of web security test tools.
Telecom vertical will reaccelerate spend on commercial products
The increasing burden of mobile device data usage is driving the need for investment in wireless infrastructure and the telecom vertical market will reaccelerate spending on commercial products.
Microsoft will regain relevance in the mobile phone sector
Riding the wave of Windows Phone 7 buzz, Microsoft will re-emerge as a leading player in the mobile phone arena.
Another acquisition to come?
Following a string of high profile acquisitions in 2009/2010, VDC anticipates yet another major embedded real-time operating system supplier will get acquired in 2011.
Here are some characteristics of embedded systems, and few systems suffer all of these constrains.
- Reliability - failure is very expensive.
- Limited Resources - memory, processor cycles, power.
- Real-time Response.
- A system may be Running Forever.
The characteristics of embedded systems affect the embedded systems programming:
- Correctness - producing the results at the right time, in the right order, and using only an acceptable set of resources.
- Fault tolerance
- No downtime.
- Real-time constraints.
- Predictability.
- Concurrency.
Following features of C++ language are not predictable:
- new and delete
Static memory poses no special problem in embedded systems programming since all is taken care of before the program starts to run and long before a system is deployed.
Stack memory can be a problem because it is possible to use too much of it. One way is to avoid recursive functions and stick to iterative implementation.
Dynamic memory allocation is usually banned or restricted. new is either banned or its use restricted to a startup period, and delete is banned because of the predictability and fragmentation.
- Pool is a data structure from which we can allocate object of a given type and later deallocate such object. A pool contains a maximum number of objects; that number is specified when the pool is created.
- Stack is a data structure from which we can allocate chunks of memory and deallocate the last allocated chunk.
- C++ standard containers such as vector, map, etc. and the standard string are not to be used because they indirectly use new.
However, there are two data structures that are particularly useful for predictable memory allocations: stacks and pools:
Exceptions
How can we catch all exceptions and how long it will take to find a matching catch.
Avoid language features and programming techniques that have proved error-prone. Pointers!
- Explicit conversions which are unchecked and unsafe - avoid them.
- Passing pointers to array elements - An array is often passed to a function as a pointer to an element. Therefore, they lose their size, so that the receiving function cannot directly tell how many elements are pointed to. This is a cause of many bugs.
In code meant to be portable, use should use <limits> to make sure our assumption about sizes is correct. Here is the list of sizes of the primitive types:
- bool - 1 bit, but takes up a byte
- char - 8 bits
- short - 16 bits
- int - 32 bits, but many embedded systems have 16-bit ints
- long int - 32 bits or 64 bits
#include <iostream>
#include <bitset>
#include <iomanip>
int main( )
{
using namespace std;
int i;
while(cin >> i)
cout << dec << i << "=="
<< hex << "0x" << i << "=="
<< bitset<8*sizeof(int)>(i)<< endl;
return 0;
}
Outoput is:
4 4==0x4==00000000000000000000000000000100 8 8==0x8==00000000000000000000000000001000 16 16==0x10==00000000000000000000000000010000 32 32==0x20==00000000000000000000000000100000 127 127==0x7f==00000000000000000000000001111111
In the code, to print the individual bits of the integer, we used a standard library bitset:
bitset<8*sizeof(int)>(i)
A bitset is a fixed number of bits. In the above example, we used the number of bits in an int, which is 8*sizeof(int). Then, we initialized that bitset with i.
Another example:
#include <iostream>
#include <bitset>
int main( )
{
using namespace std;
const int max = 8;
bitset<max> b;
while(cin >> b) {
cout << b << endl;
for(int i = 0; i < max; ++i) cout << b[i];
cout << endl;
}
}
Output is:
10100111 10100111 11100101
Let's look at the following example which looks innocent.
#include <iostream>
#include <vector>
int main( )
{
using namespace std;
const int max = 10;
vector<int> v(max,77);
for(int i = 0; i < v.size(); ++i)
cout << v[i] << endl;
}
When we compile it, we get a warning something like this:
signed/unsigned mismatch
That's because the index i is signed integer, but v.size() is unsigned integer. Mixing signed and unsigned could lead to disaster. For instance, the loop variable i might overflow. In other words, v.size() might be larger than the largest signed int. Then, i would reach the highest value that could represent a positive integer in a signed int. Then, the next ++ couldn't yield the next-highest integer and would instead result in a negative value. The loop would never terminate!
Here, we have two choices:
- vector<int>::size_type
for(vector<int>::size_type i = 0; i < v.size(); ++i) cout << v[i] << endl;
- iterator
for(vector<int>::iterator it = v.begin(); it != v.end(); ++it) cout << *it << endl;
The size_type is guaranteed to be unsigned, so the first form has one more bit to play with than the int version. That can be significant, but it is still gives only a single bit of range. The loop using iterators has no such limitation.
"People who play with bits will be bitten"
"People who play with bytes will be bytten"
When do we need to manipulate bits?
- flags as hardware indicators
- low-level communications - we need to extract from byte streams
- graphics - we need to compose picture out of several images
- encryption
Here is an example of extracting information from a short integer.
#include <iostream>
#include <bitset>
int main( )
{
using namespace std;
const int max = 8;
short val = 4;
unsigned char left = val & 0xff; // leftmost (least significant) byte
cout << bitset<max>(left) << endl;
unsigned char right = (val >> 8) & 0xff; // rightmost (most significant) byte
cout << bitset<max>(right) << endl;
val = 256;
right = (val >> 8) & 0xff;
cout << bitset<max>(right) << endl;
val = 2*val;
right = (val >> 8) & 0xff;
cout << bitset<max>(right) << endl;
val = -8;
bool sign_bit = val & 0x8000; // sign bit
cout << sign_bit << endl;
}
Output is:
00000100 00000000 00000001 00000010 1
The operations are known as shift and mask. We shift to place the bits we want to consider to the rightmost (least significant) part of the word where they are easy to manipulate. We mask using and (&) together with a bit pattern such as
From wiki
Firstly, Embedded processors can be broken into two broad categories: ordinary microprocessors (µP) and microcontrollers ((µC), which have many more peripherals on chip, reducing cost and size. Contrasting to the personal computer and server markets, a fairly large number of basic CPU architectures are used; there are Von Neumann as well as various degrees of Harvard architectures, RISC as well as non-RISC and VLIW; word lengths vary from 4-bit to 64-bits and beyond (mainly in DSP processors) although the most typical remain 8/16-bit. Most architectures come in a large number of different variants and shapes, many of which are also manufactured by several different companies.
A long but still not exhaustive list of common architectures are: 65816, 65C02, 68HC08, 68HC11, 68k, 8051, ARM, AVR, AVR32, Blackfin, C167, Coldfire, COP8, Cortus APS3, eZ8, eZ80, FR-V, H8, HT48, M16C, M32C, MIPS, MSP430, PIC, PowerPC, R8C, SHARC, SPARC, ST6, SuperH, TLCS-47, TLCS-870, TLCS-900, Tricore, V850, x86, XE8000, Z80, AsAP etc.
From wiki
Embedded Linux is the use of Linux in embedded computer systems such as mobile phones, personal digital assistants, media players, set-top boxes, and other consumer electronics devices, networking equipment, machine control, industrial automation, navigation equipment and medical instruments. According to survey conducted by Venture Development Corporation, Linux was used by 18% of embedded engineers.
Linux has been ported to a variety of processors not always suited for use as the processor of desktop or server computers, such as various CPUs including ARM, AVR32, Blackfin, ETRAX CRIS, FR-V, H8300, IP7000 M32R, m68k, MIPS, mn10300, PowerPC, SuperH, or Xtensa processors, as an alternative to using a proprietary operating system and toolchain.
The advantages of embedded Linux over proprietary embedded operating systems include no royalties or licensing fees, a stable kernel, a support base that is not restricted to the employees of a single software company, and the ability to modify and redistribute the source code. The disadvantages include a comparatively larger memory footprint (kernel and root filesystem), complexities of user mode and kernel mode memory access and complex device drivers framework.
There are non-proprietary embedded operating systems that share the open-source advantages of Linux, without the memory requirements that make Linux unsuitable for many embedded applications.
See Linux Kernel - My first driver
- C++ Home
- Algorithms in C++
- auto_ptr
- Binary Tree Example Code
- Blackjack with Qt
- Boost
- Classes and Structs
- Constructor
- C++11(C++0x): rvalue references, move constructor, and lambda, etc.
- C++ API Testing
- C++ Keywords
- C++ with Eclipse
- Debugging Crash & Memory Leak
- Design Patterns in C++
- Dynamic Cast Operator
- Embedded Systems Programming
- Exceptions
- Friend Functions and Friend Classes
- fstream: input & output
- Functors (Function Objects)
- Libraries
- Linked List Examples
- make and gnu make
- Memory Allocation
- Multi-Threaded Programming - Terminology
- Multi-Threaded Programming II - Native Thread for Win32 (A)
- Multi-Threaded Programming II - Native Thread for Win32 (B)
- Multi-Threaded Programming II - Native Thread for Win32 (C)
- Multi-Threaded Programming II - C++ Thread for Win32
- Multi-Threaded Programming III - C/C++ Class Thread for Pthreads
- MultiThreading/Parallel Programming - IPC
- Multi-Threaded Programming with C++11 Part A (start, join(), detach(), and ownership)
- Multi-Threaded Programming with C++11 Part B (Sharing Data - mutex, and race conditions, and deadlock)
- Multithread Debugging
- Object Returning
- Object Slicing and Virtual Table
- Operator Overloading
- Pass by Value vs. Pass by Reference
- Pointers
- Pointers II - void pointers & arrays
- Pointers III - pointer to function & multi-dimensional arrays
- Preprocessor - Macro
- Private Inheritance
- Python & C++ with SIP
- References for Built-in Types
- Socket - Server & Client
- Socket - Server & Client with Qt (Asynchronous / ThreadPool etc.)
- Stack Unwinding
- Standard Template Library (STL) I - Vector & List
- Standard Template Library (STL) II - Maps
- Standard Template Library (STL) III - Iterators
- Standard Template Library (STL) IV - Algorithms
- Static Variables and Static Class Members
- String
- Taste of Assembly
- Templates
- The this Pointer
- Type Cast Operators
- Upcasting and Downcasting
- Virtual Functions
- Programming Questions and Solutions