Page 106 - The Art of Designing Embedded Systems
P. 106
Firmware Musings 93
dedicated allocation size. Heap 1 might return a 2000-byte buffer, heap 2
100 bytes, and so on. You then constrain allocations to these standard-size
blocks to eliminate the fragmentation problem.
When using C, if possible (depending on resource issues and proces-
sor limitations), always include Walter Bright’s MEM package (www.
snippets.org/mem.txt) with the code, at least for debugging. MEM provides
the following:
ISO/ANSI verification of allocatiodreallocation functions
Logging of all allocations and frees
Verifications of frees
Detection of pointer over- and under-runs
Memory leak detection
Pointer chechng
Out-of-memory handling
Banking
When asked how much money is enough, Nelson Rockefeller re-
portedly replied, “Just a little bit more.” We poor folks may have trouble
understanding his perspective, but all too often we exhibit the same re-
sponse when picking the size of the address space for a new design. Given
that the code inexorably grows to fill any allocated space, “just a little
more” is a plea we hear from the software people all too often.
Is the solution to use 32-bit machines exclusively, cramming a full 4
GB of RAM into our cost-sensitive application in the hopes that no one
could possibly use that much memory?
Though clearly most systems couldn’t tolerate the costs associated
with such a poor decision, an awful lot of designers take a middle tack. se-
lecting high-end processors to cover their posterior parts.
A 32-bit CPU has tons of address space. A 16-bitter sports (generally)
1 to 16 Mb. It’s hard to imagine needing more than 16 Mb for a typical em-
bedded app; even 1 Mb is enough for the vast majority of designs.
A typical &bit processor, though, is limited to 64k. Once this was an
ocean of memory we could never imagine filling. Now C compilers let us
reasonably produce applications far more complex than we dreamed of
even a few years ago. Today the midrange embedded systems I see usually
bum up something between 64k and 256k of program and data space-too
much for an 8-bitter to handle without some help.
If horsepower were not an issue, I’d simply toss in an 80188 and
profit from the cheap 8-bit bus that runs 16-bit instructions over 1 Mb of

