Recent Posts by Category

Coding Standards

Evaluating embedded code
Stack Overflow on 6/20/2010 by Nigel Jones

One of the interesting aspects of being an embedded systems consultant is that I get to look at a lot of code written by others. This can come about in a number of ways, but most commonly occurs when someone wants changes made to an existing code base and the original author(s) of the code [...]

Considerate coding
Stack Overflow on 5/3/2010 by Nigel Jones

One of my major recreational pursuits is bike riding. I live in a rural area with some great terrain, and more to the point a very low traffic density. Naturally on a 5 or 6 hour ride one does encounter some traffic and I’m always struck by the different degrees of consideration afforded to cyclists [...]

Efficient C Tip #12 – Be wary of switch statements
Stack Overflow on 4/10/2010 by Nigel Jones

This is the twelfth in a series of tips on writing efficient C for embedded systems. Like the previous topic, I suspect that this will be a bit controversial. As the title suggests, if you are interested in writing efficient C, you need to be wary of switch statements. Before I explain why, a little [...]

Hardware vs. firmware naming conventions
Stack Overflow on 3/28/2010 by Nigel Jones

Today’s post is motivated in part by Gary Stringham. Gary is the newest member of EmbeddedGurus and he consults and blogs on what he calls the bridge between hardware and firmware. Since I work on both hardware and firmware, I’m looking forward to what Gary has to say in the coming months. Anyway, I’d recently [...]

Free store is not free lunch
State Space on 1/29/2010 by admin

In my previous post “A Heap of Problems” I have compiled a list of problems the free store (heap) can cause in real-time embedded (RTE) systems. This was quite a litany, although I didn’t even touch the more subtle problems yet (for example, the C++ exception handling mechanism can cause memory leaks when a thrown [...]

Efficient C/C++

Efficient C Tip #12 – Be wary of switch statements
Stack Overflow on 4/10/2010 by Nigel Jones

This is the twelfth in a series of tips on writing efficient C for embedded systems. Like the previous topic, I suspect that this will be a bit controversial. As the title suggests, if you are interested in writing efficient C, you need to be wary of switch statements. Before I explain why, a little [...]

Efficient C Tip #11 – Avoid passing parameters by using more small functions
Stack Overflow on 2/6/2010 by Nigel Jones

This is the eleventh in a series of tips on writing efficient C for embedded systems. Today’s topic will, I suspect, be slightly controversial. This post is based upon two basic observations: Passing parameters to functions is costly. Conditional branch instructions can be very costly on CPUs that have instruction caches (even with branch prediction). I don’t think [...]

Minimizing memory use in embedded systems Tip #3 – Don’t use printf()
Stack Overflow on 9/24/2009 by Nigel Jones

This is the third in a series of tips on minimizing memory consumption in embedded systems. If you are like me, the first C program you saw was K&R’s famous ‘hello, world’ code, reproduced below: main() { printf(“hello, world\n”); } In my opinion, this program has done incalculable harm to the realm of embedded systems programming! I appreciate that this [...]

Minimizing memory use in embedded systems tip#2 – Be completely consistent in your coding style
Stack Overflow on 9/4/2009 by Nigel Jones

This is the second in a series of postings on how to minimize the memory consumption of an embedded system. As the title suggests, you’ll often get a nice reduction in code size if you are completely consistent in your HLL coding style. To show how this works, its necessary to take a trip into assembly [...]

Efficient C Tips #10 – Use unsigned integers
Stack Overflow on 7/31/2009 by Nigel Jones

This is the tenth in a series of tips on writing efficient C for embedded systems. Today I consider the topic of whether one should use signed integers or unsigned integers in order to produce faster code. Well the short answer is that unsigned integers nearly always produce faster code. Why is this you ask? [...]

Firmware Bugs

I hate RTOSes
State Space on 4/12/2010 by Miro Samek

I have to confess that I’ve been experiencing a severe writer’s block lately. It’s not that I’m short of subjects to talk about, but I’m getting tired of circling around the most important issues that matter to me most and should matter the most to any embedded software developer. I mean the basic software structure. Unfortunately, [...]

Firmware-Specific Bug #5: Heap Fragmentation
Barr Code on 3/15/2010 by Michael Barr

Dynamic memory allocation is not widely used by embedded software developers—and for good reasons. One of those is the problem of fragmentation of the heap. All data structures created via C’s malloc() standard library routine or C++’s new keyword live on the heap. The heap is a specific area in RAM of a pre-determined [...]

Firmware-Specific Bug #4: Stack Overflow
Barr Code on 3/11/2010 by Michael Barr

Every programmer knows that a stack overflow is a Very Bad Thing™. The effect of each stack overflow varies, though. The nature of the damage and the timing of the misbehavior depend entirely on which data or instructions are clobbered and how they are used. Importantly, the length of time between a [...]

The Challenge of Debugging Cache Coherency Problems
Barr Code on 2/19/2010 by Michael Barr

The following is an example of a cache-related embedded software bug that is a real challenge to solve for several reasons, not the least of which is the fact that the actual problem was masked in the debugger’s view of memory. One nasty bug that came up recently for us was the realization that we were [...]

Firmware-Specific Bug #3: Missing Volatile Keyword
Barr Code on 2/18/2010 by Michael Barr

Failure to tag certain types of variables with C’s ‘volatile’ keyword, can cause a number of symptoms in a system that works properly only when the compiler’s optimizer is set to a low level or disabled. The volatile qualifier is used during variable declarations, where its purpose is to prevent optimization of the reads [...]

Low Power Design

Tools to help lower power consumption
Stack Overflow on 6/29/2010 by Nigel Jones

Regular readers will know that low power designs are an interest of mine. Indeed one of the very first blog posts I made lamented how difficult it is to ascertain how much energy it takes to perform various tasks typical to an embedded system. Thus it was a pleasant surprise to receive [...]

Lowering power consumption tip #4 – transmitting serial data
Stack Overflow on 5/20/2010 by Nigel Jones

This is the fourth in a series of tips on lowering power consumption in embedded systems. For this post I thought I’d delve into the common task of transmitting serial data. I compare polling and interrupting and show you how a hybrid approach can sometimes be optimal. Almost every embedded system I have ever worked on [...]

Lowering power consumption tip #3 – Using Relays
Stack Overflow on 11/2/2009 by Nigel Jones

This is the third in a series of tips on lowering power consumption in embedded systems. Today’s topic concerns relays. It may be just the markets that I operate in, but relays seem to crop up in a very large percentage of the designs that I work on. If this is true for you, then [...]

Lowering power consumption tip #2 – modulate LEDs
Stack Overflow on 9/22/2009 by Nigel Jones

This is the second in a series of tips on lowering power consumption in embedded systems. LEDs are found on a huge percentage of embedded systems. Furthermore their current consumption can often be a very large percentage of the overall power budget for a system. As such reducing the power consumption of LEDs can have a [...]

Lowering power consumption tip #1 – Avoid zeros on the I2C bus
Stack Overflow on 7/17/2009 by Nigel Jones

I already have a series of tips on efficient C and another on effective C. Today I’m introducing a third series of tips – this time centered on lowering the power consumption of embedded systems. As well as the environmental benefits of reducing the power consumption of an embedded system, there are also a plethora [...]

RTOS Multithreading

RTOS without blocking?
State Space on 4/19/2010 by Miro Samek

In my previous post, “I hate RTOSes”, I have identified blocking as the main cause of the particular brittleness and inflexibility of the programs based on RTOSes. Here I’d like to discuss techniques of minimizing blocking and eradicating it completely from the application-level code. In other words, I’d like to show you how to use [...]

I hate RTOSes
State Space on 4/12/2010 by Miro Samek

I have to confess that I’ve been experiencing a severe writer’s block lately. It’s not that I’m short of subjects to talk about, but I’m getting tired of circling around the most important issues that matter to me most and should matter the most to any embedded software developer. I mean the basic software structure. Unfortunately, [...]

Rate Monotonic Analysis and Round Robin Scheduling
Barr Code on 1/22/2010 by Michael Barr

Rate Monotonic Analysis (RMA) is a way of proving a priori via mathematics (rather than post-implementation via testing) that a set of tasks and interrupt service routines (ISRs) will always meet their deadlines–even under worst-case timing.  In this blog, I address the issue of what to do if two or more tasks or ISRs have [...]

Worst-Case Context Switch Times by RTOS
Barr Code on 1/6/2010 by Michael Barr

This morning I received an e-mail from an embedded software developer. It read in part: We are trying to find the best case, average, and worst-case context switch times for the ThreadX and eCOS real-time operating systems. I have searched the Internet extensively. I found one source stating that the ThreadX context switch [...]

Is Reliable Multithreaded Software Possible?
Barr Code on 12/23/2009 by Michael Barr

Until earlier this month, I’d overlooked a most interesting May 2006 article in Embedded Software Design magazine by Mark Bereit titled “Escape the Software Development Paradigm Trap“. The article opines that the methods we use to design embedded software, particularly multitasked software with interrupt service routines and/or real-time operating systems, are fundamentally incompatible with [...]