There is a lot of flexibility in terms of the processing power and memory requirements when you code an application for a desktop, PC, workstation or a server. Jump into the embedded arena and all this flexibility comes to an end. As the name 'embedded' suggests, embedded applications are usually burnt into the circuitry of hardware devices like machinery and control systems.
Processing and memory power is seldom available in abundance for embedded applications. Add to it almost mandatory requirements of low- level hardware access and real time parallel processing. This article delves further into the depth of these bottlenecks, and things to keep in mind while coding for embedded devices.
Size does matter
Perhaps, the biggest consideration is the size of an application. Usually embedded applications cannot afford to be more than a few hundred kilobytes in size because of their use in small footprint devices. The memory consideration includes not only the size of the application, but also the amount of main memory required for it to run. There will always be a never-ending need to optimize the application to make it the best fit.
Hardware access
Much of the software for embedded would be control software to control the hardware machinery. In the programming language you choose, you should be aware of all routines (functions/methods) to send inputs to and receive outputs from the hardware through I/O ports (for example serial, parallel). You should be able to manipulate the data at the bit level. It's because it may be inefficient to use data structures like strings and integers for an embedded system, because of their size.
High performance
In the embedded systems used in defense and control systems, time is a critical factor. Hence processing should be fast. A missile-tracking system should be fast enough to calculate and predict the co-ordinates of a missile flying at several hundred kilometers per hour. For higher performance, besides relying solely on the power of processor, the program code itself should be optimized for extra gains in performance. You should know, how to use powerful, optimizing compilers that can optimize and translate the source code into native hardware instructions. To speed up critical code blocks, you should be able to readily embed low-level instructions (using Assembly language) within the code.
Parallel processing
An embedded application may need to perform more than one task simultaneously. For example, missile system may need to track missiles, predict the missile course, destroy an attacking missile and look up the maps to calculate the missile co-ordinates. A control system in a manufacturing unit should be able to accept new input of raw materials while processing the already fed and also while outputting the finished products. Hence to develop such a system, you should be able to parallelize your code efficiently in such a way that, none of the critical code chunk block due to the processing of another chunk. For this you should know how to use the libraries for multithreading and message passing.
Priority queues
Having talked about parallel processing, sometimes it may become essential to carry out one task before the other. The software system should be able to decide which task (from amongst a list of assigned ones) has higher priority. In software, such a concept is implemented as a queue-a data structure. A priority queue is one in which the tasks are arranged based on their priority. A least priority task is kept at the rear of the queue and the highest priority task is kept at the front.
|
Tasks are worked upon from the front of the queue. So a thorough understanding of priority queues is mandatory.
Error handling
While it may not be possible to develop a 100% error-free program, it is surely possible to develop a program that can handle likely and preferably unlikely errors. While error handling is of utmost importance in all applications it becomes critical in embedded system especially those, which are used in defense and control systems
Hence, you must be able to use methods to trap the errors and perform counter measures to recover from it. For example, on detecting a failure in one of the components of the hardware, the software must switch over to another redundant component or report the error and still try to carry on with the next task.
Precision and accuracy
An embedded application must be precise and accurate for use in a control system.
|
Processes may require precise mathematical calculations to arrive at the output. You should be able to use data structures to hold large integers and floating-point numbers. Especially when calculations involve decimal or floating-point numbers the decimal places must be preserved for accurate results, instead of rounding them off as in case of conventional desktop programming.
The Bottom Line: Programming for embedded is programming with memory constraints, accuracy, performance and error handling. You must understand the underlying device and its capabilities and adhere strictly to the specifications laid out during the project analysis.