Posts Tagged ‘embedded’

Perils of Preemption

Saturday, September 16th, 2006 Michael Barr

Embedded.com just picked up a paper I wrote for the upcoming Embedded Systems Conference in Boston. The paper is about the downsides of the dominant RTOS (real-time operating system) scheduling algorithm. It turns out that priority-based preemptive scheduling has one key benefit but more than ten important caveats.

Unfortunately, the formatting and editing was screwed up in several ways in Embedded.com’s publication of this paper. But I have republished it at http://www.netrino.com/Embedded-Systems/How-To/Preemption-Perils.

I’ll be speaking about alternatives to priority-based preemptive RTOSes in Boston on Tuesday, September 26.

Firmware Code of Ethics

Friday, September 15th, 2006 Michael Barr

WE THE MEMBERS OF THE EMBEDDED SOFTWARE COMMUNITY, in order to protect our customers (and their customers) from the risks inherent in our products, extend product lifetimes, lower long-term maintenance costs, promote the general welfare of society, and advance the integrity and reputation of our profession, do hereby ordain and establish the following code of ethical conduct.

Check return codes. If a function can return an error code, it will almost certainly return one eventually. How will our software recover if it doesn’t even know an error has occurred? We will, therefore, always check all return codes. When an error is detected, we will take whatever action is required to recover safely.

Document reasoning. We make dozens of design and implementation decisions each week; we forget the reasoning behind others at a similar pace. We will, therefore, document all of our reasoning in the code itself. Furthermore, we will update these comments if our reasoning changes.

Use version control. Even when done carefully and with discipline, making backup copies of source directories, commenting out code that might be needed again, and tracking changes in comments is insufficient. The use of a good configuration management tool is a must. Furthermore, we agree to always perform a diff and provide a good description of the explanation for all changes each time a file is checked in.

Enforce coding standards. No matter how proud we may be of our abilities, we do not “own” the code we produce. Our employers and clients own it; we and others are hired to develop and maintain it. The true owners have the right to enforce a coding standard upon our work. If they do not choose to exercise this right, we will self-enforce a standard in line with generally accepted programming practices.

Run lint regularly. Compilers are more concerned with generating code than the correctness of your syntax. Only a static analysis tool like lint can watch over our shoulders to ensure we’re not straying into dangerous or non-portable programming constructs. We will, therefore, include lint in our development process. If we don’t remove all code with warnings, we will at least understand why each and every warning remains.

Perform code inspections. Automated tools are helpful, but nothing is better than a peer review for finding logic errors. Code inspections have been shown to be many times more efficient than any other single debugging tool. We will always review our code as a group at least once before each release.

Assign one tester to every developer. Programmers make lousy testers, especially when it’s their own code they’re testing. For best results, one independent tester should be hired for every developer. And the testing team must maintain and rerun regression tests regularly, to certify that a new release is at least as good as the previous one.

Measure performance. Of course, there are some kinds of tests that are best performed by the engineers themselves. In real-time systems, we shall directly measure interrupt latency and the time it takes each of our critical subroutines to complete. An oscilloscope and a spare I/O pin are quite handy in this regard.

These best practices are easy things to do, and all are inexpensive to implement. A one or two person design team can as easily follow these rules as a 50-person engineering department. If you aren’t following these rules today, there are no excuses for tomorrow.

Verticality

Thursday, September 25th, 2003 Michael Barr

More than 6 billion processors of all types (4-bit to 64-bit plus DSPs) were sold in 2002. That astonishing number was actually off about 25% from the record volume of over 8 billion recorded two years earlier. Only about 100 million of those chips (just 1.5%) became the brains of PCs, Macs, and UNIX workstations born each year; embedded systems designers are the cause of the rest.

With about one new processor taking hold per person per year, it would be fair to say embedded systems are everywhere—or soon will be. The technology is only three decades old at this point—imagine the ultimate potential! Applications span the realm of imagination. Think of the number and diversity of insects and you’re on the right track.

There are so many different applications, and thus so many different types of embedded processors, in fact, that it’s becoming increasingly valuable in some circles to break that huge market up into more easily digested chunks. Applications can be grouped roughly into about seven key categories: communications, computer peripherals, industrial controls, military/aerospace, consumer, medical, and automotive, plus the obligatory catchall other/miscellaneous. These are termed vertical markets.

We should give some thought to what it is that ties all of the many vertical markets together. There is significant overlap between the work of designers of embedded systems for applications as seemingly diverse as consumer gadgets and military/aerospace systems. I suspect it is in this overlap that you find your identity as an embedded system designer.

Smart Sensors

Saturday, July 19th, 2003 Michael Barr

A lot of media attention is generally focused on the latest gee-whiz processor advances and forecasts of their potential uses and market sizes. But the trend of older technologies coming down in price and thus creating new markets for themselves is sometimes even more exciting. As prices fall, new uses for old components emerge. One example of this trend is the increasing use of so-called “smart sensors,” which have on-board processing.

Being analog components, most sensors are prone to nonlinearities; they also exhibit offset and gain errors. At the outputs, sensors typically have limited dynamic range and high impedance, which make them susceptible to electrical noise as well. As a result, ordinary (dumb?) sensors typically require dedicated external circuitry for signal conditioning and to perform error compensation and filtering. If lots of data is generated in spurts, buffering too may be required.

Unlike their dumb brethren, smart sensors integrate the sensor along with the required buffering and conditioning circuitry in a single enclosure. Circuitry on-board the smart sensor usually consists of data converters, a processor and firmware, and some form of nonvolatile memory. Being processor-based devices, such sensors can be custom-programmed to satisfy specific system requirements and later reprogrammed as needed.

A smart sensor can be easily added to a piece of embedded hardware, say as a single chip or a daughtercard via a digital interface. Or, as is increasingly common in the field of remote data sensing, a wireless-equipped smart sensor can perform local processing of the raw data then ship the processed data up to a base station at regular intervals.

The benefits are tremendous. Vendor-supplied firmware on-board a smart sensor can automate the removal of nonlinearities and offset and gain errors from raw sensor readings, thus eliminating the need for custom post-processing at the main processor. The calibration data on a smart sensor can also be stored locally, in nonvolatile memory, so that the sensor module as a whole can be moved and reused without recalibration.

On-board data processing and local storage also make new capabilities at the sensor’s location, such as the ability to take action without intervention by the host processor. For example, a smart sensor could issue a quick early warning when measured parameters are approaching critical limits, or are changing at an abnormal rate. A sensor could even send a maintenance alert to the main system controller calling for replacement.

Even components as seemingly mundane as these can be made significantly more interesting with a little firmware. As the price of computing power drops, useful new applications for that power do indeed emerge.

Firmer-ware?

Sunday, June 29th, 2003 Michael Barr

Too much of the terminology embedded systems engineers use in their everyday oral communications and written documentation is only vaguely defined—at best. For example, terms like mutex, binary semaphore, and semaphore are often interchanged by software developers. In a related context, task, thread, and process are also tossed around as if they all represented the very same construct.

Hardware designers too are terminologically challenged. For example, does the new board need a 1 kb, 1 kB, or 1 KB FIFO? Will it have flash or Flash, or is that flash really an EEPROM? There are also terms like emulator, which are overloaded with multiple meanings and must be expanded to be fully understood.

About a year ago, Jack Ganssle and I teamed up to finally do something about all this linguistic nonsense. We have since combined our years of experience as embedded hardware and software developers and precisely defined more than 2,800 terms used in the field of embedded systems design, development, and testing. The results, called the Embedded Systems Dictionary, should be available from CMP Books about the time you read this.

But this is not meant to be a sales pitch. I bring all this up only as background. You see, at a joint “book launch” attended by Jack and me at the CMP Books booth at the Embedded Systems Conference San Francisco, we had a very interesting conversation with a hardware designer who considered the results of his Verilog coding to be firmware. Neither Jack nor I had encountered such a usage of the term before.

In fact, Jack and I have both often seen the use of the term firmware somewhat restricted to either specifically DSP code or embedded software written entirely in assembly. When compiling the dictionary we agreed, however, that the definition ought properly to include code written in any programming language:

firmware n. Executable software that is stored within ROM. (Usage Note: This term is interchangeable with “embedded software” and sometimes used even when the executable is not stored in ROM.)

But this fellow brought up a very interesting point. At what point does hardware written in Verilog (or VHDL) and compiled into an executable binary format become indistinguishable from software written in C (or any other language) and compiled into an executable binary format. Is the hardware executable “firmer”-ware than the software executable? Or are they both just different flavors of firmware?

What will happen when, ultimately, a special-purpose C compiler can generate hardware? Or when a UML tool can automatically (and optimally) partition the description of a system’s requirements into hardware and software and output a pair of binaries for the processor and the programmable logic in a single-chip platform FPGA?

At that point, will the hardware designers and software developers even be able to distinguish themselves from each other? As the line between hardware and software continues to blur, perhaps it is only the hours we keep and the forms of caffeine we favor that will belie our EE or CS backgrounds. That’s when things will get really interesting.