Author: Elecia White
Publisher: O'Reilly, 2011
Aimed at: Programmers wanting to get into embedded
Cons: Not specific enough to be practical
Reviewed by: Harry Fairhead
The idea of getting programmers interested in embedded systems is a good one but how best to do it?
The subtitle of this book is "Design Patterns for Great Software". The problem is that design patterns are not the sort of thing you usually associate with embedded design. The reason is that embedded works seems to vary so much with the actual system you are working on that it seems very difficult to extract the common ideas. However on the other side of the coin there is no doubt that as you tackle project after project you do notice that you are using the same skills over and over again. Perhaps there is something that can be taught that is general.
This said it is much easier to teach a general idea once the student has encountered a particular real example. This book attempts to do the job while remaining as general as possible. As a result this isn't a practical book that urges you to buy a development kit and get on with building something. In fact it goes out of its way to not be specific to any particular hardware and this makes its task so much more difficult.
Chapter 1 gives you the clear impression that this is going to be a software book. It starts off with a look at the key modern programming ideas - compilers, languages and objects. Each chapter also ends with an Interview question - this is a book that aims to get you a job in an embedded team as much as just enthusing you with a passion for hardware. Chapter 2 is about systems architecture and it covers drawing system diagrams and encapsulating your functionality. The advice is create drivers in the Unix style and use the adaptor pattern to cover up the hardware details as much as possible. The code examples are in C which is a reasonable choice as most professional embedded systems use it and other languages are similar. The level is fairly abstract and you will even have the currently trendy MVC pattern explained to you.
Thus far the book has mostly been about traditional software design and there hasn't been much emphasis on the hardware. Chapter 3 attempts to put this right with an explanation of the common elements in getting to grips with hardware. It explains how to read a data sheet. Electronics types find this fairly easy but software people are often mystified by the way a hardware data sheet presents information. The way pinouts and timing diagrams work are explained with reference to an Analog Triceratops rather than a real component. This is possibly a mistake because a real component wouldn't have made the task much more difficult.
This is nicely done but I'm not at all sure about the need for a programmer to know about such things. Mostly you can get by with details of the control registers that a device exposes. Worrying about timing diagrams and fan outs is something that a hardware expert does - unless you are going to do the full design job all on your own. If so then I doubt that the information is enough. At best it is a peek into the other world of hardware.
Next we have some idea about getting to know a new processor - basically its like a new language. Finally the chapter closes with a look at what testing gear you need - multimeter, scope etc. Again not enough information to master anything much unless you already know some electronics.
Having started on hardware the book continues with a chapter on how to toggle an output, use inputs and timers. In this case the example uses an Amtel processor - it has to get real at some point. The explanation is good but for a programmer knowing nothing about electronics the most mysterious component - the current limiting resistor isn't even mentioned let alone explained. Basic knowledge of electronics isn't something that is easy to fake and unless the reader is prepared to read a book on the subject there is going to be a lot of mystery and a lot of smoking components. The chapter closes with a look at input - switch debouncing - and dependency injection.
The next chapter is about a much more software oriented topic - flow of control. This covers multitasking and interrupts. It avoids making reference to any particular OS and later demonstrates how useful the state machine model is. The later part of the chapter deals with interrupts, a topic that is one of the main differences between big machine and embedded systems programming. Finally we get to the Watchdog idea which again is something specific to embedded programming.
From here the book deals with peripherals with an overview of devices you might connect to the processor and a look at the different busses and protocols. None of these are dealt with in enough detail or specificity to be practically useful. It is more like a survey overview. Then we have an odd chapter on using flash memory to update code.
The final three chapters are really useful. Chapter 8 - doing more with less - is a catalog of the sort of tricks that embedded programmers use to get their programs to fit into the space or run fast enough to be useful. This is old fashioned coding. Chapter 9 describes the lost art of doing arithmetic without floating point and chapter 10 is on reducing power consumption. These really are about issues specific to embedded that programmers need to know about.
Overall this is a slightly odd book. You get the impression that the author would really like to have got to grips with some real hardware development system but doesn't in an attempt to keep the book general.
Many of the attempts to introduce high-level software concepts are mostly out of place - introducing MVC and dependency injection for example.You almost get the feeling that the author has to try to include such high-level software ideas in an attempt to be "professional". They don't really connect with the embedded world described.
The book works best when it gets onto topics that are specific to embedded programming and are software oriented - timers, state-machines, interrupts, non-floating point arithmetic. These really are the things that you need to know to be an embedded programmer - you can leave much of the hardware and reading of data sheets to someone else. Of course if you want to know about the hardware then I would suggest that you get a book that introduces electronics and another that demonstrates how to build things using a real development kit - an Arduino would be fine.
If you are a programmer and are happy not to get too specific and want to know some of the ideas that occur in embedded programming but not so much in more general "high level" programming then you will probably enjoy this book. I did.