Unit Tests for Embedded Code

Stephen Friederichs March 5, 201411 comments

I originate from an electrical engineering background and my first industry experience was in a large, staid defense contractor. Both of these experiences contributed to a significant lack of knowledge with regards to software development best practices. Electrical engineers often have a backwards view of software in general; large defense contractors have similar views of software and couple it with a general disdain for any sort of automation or ‘immature’ practices.  While there...

Bad Hash Functions and Other Stories: Trapped in a Cage of Irresponsibility and Garden Rakes

Jason Sachs January 28, 20141 comment

I was recently using the publish() function in MATLAB to develop some documentation, and I ran into a problem caused by a bad hash function.

In a resource-limited embedded system, you aren't likely to run into hash functions. They have three major applications: cryptography, data integrity, and data structures. In all these cases, hash functions are used to take some type of data, and deterministically boil it down to a fixed-size "fingerprint" or "hash" of the original data, such that...

Implementing State Machines

Stephen Friederichs January 18, 20145 comments

State machines are a great way to design software but they can be difficult to implement well.To illustrate this I’ll develop a simple state machine then increase the complexity to demonstrate some of the difficulties

We’ve all washed dishes before - it’s easy isn’t it? Scrub, rinse, dry, scrub, rinse dry. Scrub the dish until all of the gunk is off of it, rinse until the soap is off, put it in the drying rack. If you want to design software to implement this you have options. You...

Understanding and Preventing Overflow (I Had Too Much to Add Last Night)

Jason Sachs December 4, 2013

Happy Thanksgiving! Maybe the memory of eating too much turkey is fresh in your mind. If so, this would be a good time to talk about overflow.

In the world of floating-point arithmetic, overflow is possible but not particularly common. You can get it when numbers become too large; IEEE double-precision floating-point numbers support a range of just under 21024, and if you go beyond that you have problems:

for k in [10, 100, 1000, 1020, 1023, 1023.9, 1023.9999, 1024]: try: ...

Delayed printf for real-time logging

Yossi Kreinin October 25, 20133 comments

You often debug by adding a few printfs and looking at the logs. In some real-time/low-level contexts though, you don't have time for text formatting.

You don't want prints to affect timing too much, because then timing-related bugs you're chasing might disappear. And you certainly don't want the system to stop functioning altogether because prints cause it to miss real-time deadlines.

A common alternative to prints is more "raw" logging - an event buffer, where event is a union keeping...

Coroutines in one page of C

Yossi Kreinin August 20, 201316 comments

A coroutine is a function that you can jump back into after returning from it - and it remembers where it was in the code, and all the variables. This is very useful at times.

One use is generating a sequence of values. Here's how you can generate all the x,y pairs in a 2D range in Python:

def iterate(max_x, max_y): for x in range(max_x): for y in range(max_y): yield x,y for x,y in iterate(2,2): print x,y

This prints:

0 0 0 1 1 0 1 1

The yield keyword is like...

Code Metrics - SLOC Count

Stephen Friederichs August 19, 2013

Many programmers will start having flashbacks at the title of this article because it contains the words 'metrics' and 'SLOC'.  Newer programmers are probably wondering what all of the fuss is about - most probably have no negative connotations with the term 'code metrics' and some may not even know what SLOC is.  While there is much baggage associated with metrics and SLOC you shouldn't be afraid to gather fundamentally useful data such as SLOC count from your programming projects...

[ C Programming Techniques: integer type optimization ]

Fabien Le Mentec May 22, 20131 comment

I am currently working on a voltage controller running on a ATMEGA328P, ATMEL AVR 8 bits microcontroller. The controller logic is implemented in the main() routine and relies on a periodical timer whose frequency is fixed at application setup. Among other things, the timer ISR handler increments some per tick counters which are then used by the main routine to implement the voltage controller timing logic.By looking at the code, one noticed that I use the uint8_t type for counters instead of...

Interfacing LINUX with microcontrollers

Fabien Le Mentec May 7, 20132 comments

I am increasingly asked to work on small spare time projects where a user needs to control some device over the INTERNET. Recently, a friend needed to control heater relays and measure the temperature of its geographically distant secondary house. Another case relates to the control of a pan tilt home monitoring camera. A last one is the control of an old XY plotter DACs.

In both applications, the user wants to access the system over a web browser using HTTP. From the user...

C Programming Techniques: Function Call Inlining

Fabien Le Mentec April 29, 20137 comments

Abstraction is a key to manage software systems as they increase in size and complexity. As shown in a previous post, abstraction requires a developper to clearly define a software interface for both data and functions, and eventually hide the underlying implementation.When using the C language, the interface is often exposed in a header '.h' file, while the implementation is put in one or more  corresponding '.c' files.

First, separating an interface from its...

Scorchers, Part 2: Unknown Bugs and Popcorn

Jason Sachs April 5, 20203 comments

This is a short article about diminishing returns in the context of software releases.

Those of you who have been working professionally on software or firmware have probably faced this dilemma before. The scrum masters of the world will probably harp on terms like the Definition of Done and the Minimum Viable Product. Blah blah blah. In simple terms, how do you know when your product is ready to release? This is both an easy and a difficult question to answer.

What makes...

3 Overlooked Embedded Software Elements

Jacob Beningo July 9, 20224 comments

Have you ever wondered, while you and your team are busy writing software if the foundation of how embedded software systems are built has changed and left you in the dust? What if while you were busily focusing on getting your product out the door, fighting bugs, and dealing with supply issues, there were techniques and processes that you completely overlooked that could save the day? I’ve found three elements embedded software teams often underutilize that could dramatically improve...

Short Circuit Execution vs. Unit Testing

Stephen Friederichs July 7, 20141 comment

The key to effective communication is to say what you mean and avoid ambiguity.  Words and phrases with multiple meanings can confuse your audience and hinder communication. That’s why so many programmers prefer writing code to writing specifications: written human language introduces ambiguity and subsequently, confusion. Code only has one interpretation, period. This doesn’t, however, ensure that the right message is getting through. Code can, indeed, only do one thing,...

A brief overview of flight control software

Igor Mišić May 3, 20193 comments

It has been a long time since the first drones appeared. If you are interested in such a topic, you may be confused about how and where to jump in. Since I went through the same phase, I'd like to write my findings here and help others.

For this blog post, I've created chart and table with all open source flight control programs I've been able to find.

The chart shows the course of development of the existing software. It is separated in years and you can see when which project...

Lightweight hardware abstraction

Gene Breniman January 31, 2012

Some lessons are tougher than others to master.  You would think that hard fought battles would be easier to remember, but sometimes it just does not work that way.  Recently, I was asked to pick-up a project that had been managed by another employee.  The project was yet another cost reduction project.  The hardware group was tasked with updating a currently shipping product, to reduce the existing failure rate, while at the same time to remove cost from the...

Tenderfoot: Introduction to Magic (Numbers that is...)

Matthew Eshleman May 10, 20173 comments

Once upon a time, while participating in a source code review, I stumbled across the following C code in a header file:

struct Foo { //various structure fields char string_buffer[45+3]; //buffer requires about 45 bytes };

My right eyebrow raised, I took a note, and continued with the code review, only to later stumble into this line of code in the body of a C function:

char * temp_string_buffer = (char*) malloc(45+3);

Again, I took a note on this function, and continued...

Embedded Toolbox: Source Code Whitespace Cleanup

Miro Samek August 5, 2017

In this installment of my "Embedded Toolbox" series, I would like to share with you the free source code cleanup utility called QClean for cleaning whitespace in your source files, header files, makefiles, linker scripts, etc.

You probably wonder why you might need such a utility? In fact, the common thinking is that compilers (C, C++, etc.) ignore whitespace anyway, so why bother? But, as a professional software developer you should not ignore whitespace, because it can cause all sorts...

Is it a Bug or an Error?

Michael Barr January 31, 20184 comments

Probably you’ve heard the story of how Adm. Grace Hopper attached a moth that was dislodged from a relay in the Harvard Mark II mainframe to an engineering notebook and labeled it the “First actual case of bug being found.”

Designers of electronics, including Thomas Edison, had been using the term bug for decades. But it was mostly after this amusing 1947 event hat the use of words like “bugs” and “debugging” took off in the emerging software realm.

So why is it that if a...

Kind of Buggy! The state machine fantastic//

Richard Dorfner August 31, 20112 comments

Over the years, I have had the opportunity to experience a lot of different kinds of coding mistakes. There were many that most programmers are familiar with, counting errors, indexing errors (the infamous 'off by one' bug), memory space sharing errors (A threading issue) as well as numerous others.  I ran into one recently that I wound up using an old trick to help find.

My current project is a Pan/Tilt camera that was, upon occasion, not homing properly in one axis. The camera is a...