What is the difference between embedded system and real-time system?

As a first incomplete answer I would say that real-time systems are an important subset of embedded systems. Generally speaking any real-time system is also an embedded system, as well as any RTOS is considered to be also an embedded OS.

Now, the second point would be to define an embedded system and afterwards to trace a line in between real-time systems and rest of embedded systems.

Embedded systems…. what are they? I read many columns and articles on the Internet claiming that it is more appropriate to say which “piece of computing” is NOT an embedded system.

Actually around 90% of microprocessors are manufactured for the embedded industry, so AMD and Intel cores found in our notebooks or desktops are just the tiny top part of the iceberg.

Clearly all kind of PC’s, ranging from desktops, to servers, to notebooks and so on, are not embedded systems. All of those are general purpose computers serve for browsing on the Internet, for audio/video streaming, for text editing, for performing sophisticated math computations and many, many different and complex tasks. Another thing which can be said about PC is that they rarely interact with the environment, usually they receive inputs from the user, via the keyboard, or from another computer via a LAN card.

Read more of this post

Memory pools or best practice in dynamic allocation in embedded systems

Before going into any presentation it is worthwhile to remember one important thing which I missed right from the beginning: only pointers (here I’m including arrays also) can be used in conjunction with dynamic memory allocation.

In C you cannot have something like this:

int n = (*int) malloc (sizeof (int));
// because malloc is returning a (void *) it has to be
// assigned as an r-value to a pointer

I read in many places that the cast to (*int) is not so safe and is better to be avoided but this is more subject of a footer note.

Malloc implementation presented in my previous post had many drawbacks. Just to name few of them:

    – there is no memory overflow handling, only the presumption of a success is considered
    – it cannot be used in multitasking environments because it has no locking mechanism implemented (mutex or semaphore)
    – is_available flag occupies an integer even if should be only one bit
    – it does not handle free space in order to avoid, or at least to limit fragmentation
    – it is non-deterministic, the algorithm has to iterate through each heap location in order to find the right one

Let’s just reacap a little bit how things are passing in the standard way when allocating dynamically memory. At the beginning the operating system granted a chunk of 32 KB memory to the current process (this is the thing that brk and sbrk handled), from which I would like to use (to allocate with malloc) 2 Kbytes:

Read more of this post

Is it good to use dynamic memory allocation in embedded programming?

Before starting I have to mention few references which were really usefull resources in my “Embedded tips and tricks” – related posts. One of them is Dan Saks’ articles and columns on Embedded.com and another one is Netrino web site and Michael Barrs’ articles.

I thought of writing this post in order to explain possible benefits but also the drawbacks that are induced by dynamic memory allocation… in embedded programming. I excluded any faulty use of dynamic allocation such as memory leaks or dangling pointers, so my assumption is that data is correctly allocated and de-allocated.

First of all let me just integrate dynamic allocation in the general storage types classification, there are three types (at least in C):

    Static storage – variables which exist during the whole program execution time; those are global variables and those variables explicitly declared as static

    Automatic storage
    – variables which are allocated upon entrance into a block (something delimited by curly brackets {}) and de-allocated after existing that block (this is the case of local variables)

    Dynamic storage
    – this one falls entirely on users’ responsibility; he manually creates the variables (via malloc, calloc or, in C++ new operator) and he also destroys them (via free or delete)

Dynamic allocation has the advantage of being completely in control of the programmer. Variables storage and lifetime is manipulated solely by the user and it is not necessary to overload the compiler with such task (actually dynamic allocation is done at run-time, so has nothing to do with compiler), but on the other hand he has to be aware that this “freedom” can provoke serious errors.

In embedded programming dynamic memory allocation should not be avoided at all, this is not a good practice, but instead it has to be used carefully.

Read more of this post

GNU toolchain

Generally a toolchain is a chain of tools :)) obviously isn’t it ?

Before starting it is worthwile to say that the GNU toolchain is an essential component for building applications for embedded OSes (or RTOS- do not talk now about the differences between RTOS and embedded OS but this is good to have in mind for a future post)

The result of one tool is taken and used by next one and so on, in a serial way, in order to achieve the desired result. Tool-chain is some kind of ancestor of IDE’s, actually the main idea of having and IDE (Integrated Development Environment – something that “integrates” all development tools that you need) is to ease your work and not to strive with different versions of different tools. Using an IDE avoids unwanted dependency errors that may arise when using a tool-chain.

Its main purpose is to produce executables that can be linked to some standard libraries in order to form a complete operating environment (I mean operating system).

Why to discuss about it? Because it is very important in configuring and compiling RTOS (or embedded OS) kernels but also to develop applications on top of it for embedded systems.

Actually everywhere the Linux kernel is deployed GNU tool-chain is needed in order to configure and to build it for the specific target. As I mentioned in my previous post about Mobile OSes, there are other development tools used for creating mobile applications (even development for Android which is relying on Linux kernel can be done using Eclipse, so without the need of GNU tool-chain), but embedded world is bigger than mobile development …

It can worth a discussion about advantages / disadvantages of using GNU toolchain or an IDE, but I won’t cover this in detail. As far as I know IDEs cost money, well it depends also because if you take MPLAB from Microchip, this is free, but the C compiler costs some dollars, but GNU software is completely free and can be downloaded from here .

But what is it made of?

Read more of this post