Page 100 - The Art of Designing Embedded Systems
P. 100
CHAPTER 5
Firmware Musings
Hacking Peripheral Drivers
Experienced software engineers find no four-letter word more offen-
sive than “hack.” We believe that only amateurs, with more enthusiasm
than skill, hack code.
Yet hacking is indeed a useful tool in limited circumstances.
This is not a rant against software methodologies-far from it. I
think, though, a clever designer will identify risk areas and take steps to
mitigate those risks early in a development program. Sometimes cranking
code, maybe even lousy code, and diddling with it is the only way to fig-
ure out how to efficiently move forward.
No part of the firmware is more fraught with risks and unknowns
than the peripheral drivers. Don ’t assume you are smart enough to create
complex hardware drivers correctly the first time! Plan for problems in-
stead of switching on the usual panic mode at debug time.
Before writing code, before playing with the hardware, build a shell
of an executable using the tools allocated for the project. Use the same
compiler, locator (if any). linker, and startup code. Create the simplest of
programs, nothing more than the startup code and a null loop in main() (or
its equivalent, when you’re working in another language).
If the processor has internal chip-selects, figure out how to program
these and include the setups in your startup code. Then, make the null loop
work. This gives you confidence in the system’s skeleton, and more im-
portantly creates a backbone to plug test code into.
87

