Saturday, February 22, 2014

Some programming books to read if you want to get into embedded systems.



The classic. The bible. It's the SICP of imperative languages. It's pretty much the only thing all that software engineers can collectively agree is an essential and awesome read. And believe me, getting programmers to agree on something is no simple feat. If you've ever wanted to see a real-life internet argument, get a couple programmers in the room and ask them what's the best way to compute the Fibonacci sequence, get some popcorn, and get ready for fireworks.

In a mere 270 pages, this book will dive into imperative programming, the Unix environment, and even a bit of computer science. It's a vital introduction to C, and also a great book for learning imperative programming in general. Despite what embedded C++ advocates tell you, or what the technologists over at Rust and D and Go all promise, C *is* the language of embedded software, and as such you must be well-versed in her intricacies.

"But muh assembly" you cry, like a rotund child begging for another donut, as his gut slowly protrudes its way beyond the vesicles of his striped polo. Look. There is a time and place for everything, including going down into the assembly level. We've all been there, and it's not pretty. Machine code is a cold, ugly beast that is best left in its slumbers, disturbed only by the ding of a compiler, execrating the object code that it may interpret henceforth.


When doing systems programming for major operating systems, only knowing libc is enough. If you've ever written board support drivers, provided you've recovered from your PTSD, you know it's a whole different game.

It's like going to hell and back. Everything is beautiful inside of x86. It's almost adorable how effortless a printf flawlessly sends out a sequence of characters to your terminal; how freely they flutter their golden trimmed %-formatted tips leeward to your screen. There's little pthreads playing "ring around the semaphore" in the fields of virtual memory, and hearty mallocs over by the red-black tree forests, harvesting the fruits of process' labor, into cozy, petite heaps. Unistd is always a grump, but nobody messes with him too much these days.

But the world of embedded control is a strange, hellish world. It's a world where there's no such thing as mallocs, and a printf is nothing more than a stream of data judiciously churning out of an rs-232 transducer, like a tarpit churning out sludge, except the tarpit has a higher baud rate. Thankfully, even in hell there can be a savior. Given how simple libc is, you might expect implementing the C library to be a simple and annoying chore. And in truth, provided you're working with an architecture that was Godless enough to give you absolutely no libc whatsoever, this isn't too bad. But there's a question of doing it right, and understanding the intricacies of the lib. Why assert is a macro. Why NULL isn't just 0, but 0 cast as a void pointer. Why fflush should be used sparingly at best. This book is here to answer those intricacies, and ultimately, help you build or extend your C library as need be. When was the last time you actually received decent documentation for your embedded C environment?



In the final of the trilogy of C books comes one that you'll keep coming back to long after you've learned the ropes, I give you... a fish.

Well that's what I call this book. "The fish book." I'm not exactly sure what a fish has to do with being an expert C programmer, and I'm pretty sure the author doesn't either. Perhaps it's a grand metaphor for programming in C in general. You are a fish weaving through all of the potential errors that could arise that the compiler won't catch. Daintly programming the trickiest of the tricky buffer to struct castings, throwing up alignment macros like thugs throw up gang signs, firing off float to int bit hacks left and right without a second thought. Ah yes, the C programmer. He swims like a fish and... splashes like a fish, I suppose. Hashtag deep bro.

The book assumes you've already had quite a bit of C programming under your belt, and is here to answer all of those strange questions you might have had during exploration with the language. It's full of little teasers and puzzles specifically designed to help you think better with regards to writing C programs and gain a deeper appreciation of the language in general. It's definitely a read I'd recommend for anybody, but an essential for C programmers. Also, I guess it's better than my undergrad CS 101 book, which was a picture of the side of the author's payroll office.



This O'Reilly book is about how to actually design software for an embedded system in such a way that it doesn't completely suck. Think of this as software engineering techniques for the embedded environment. This read to me is pretty much mandatory, and I won't even let an intern touch trunk code until they read this book cover to cover. Obviously it's just an outline of design techniques, but most programmers are used to the beautiful lands of the PC, and being an embedded programmer requires a different way of thinking.



I have a confession to make. To be honest it's not much of a confession, but EE's still love to smother it in my face, like I'm a dog that mistakenly pissed on the floor. And that mistake was apparently studying Computer Science. I am not a hardware guy. My bachelor's was in Computer Science, not electrical or computer engineering. As such, when it comes to laying out boards or designing schematics, my first question is "why is that capacitor there?" and my second is "what is a capacitor?"

Okay, I know what a capacitor is. I've done my fair share of circuits, electricity, and magnetism, but I really only have a cursory knowledge of hardware, this book helped a lot in introducing to me the hardware aspect of embedded control without getting too crazy. It explains things in a way that's easy to understand from a conceptual point of view, with the obvious intent of being able to ask an EE a question without sounding completely retarded.



Today's embedded software is increasingly becoming more complex. It used to be our firmware would talk directly to the board, and that was it. But nowadays we are starting to see the familiar layers of abstraction we expect in PCs, including tiny operating systems. MicroC/OS is pretty much the de facto standard Real Time Operating System (RTOS) that all others are in some way or form based off of, so reading it is essential.


This book gives you a lot of basic code for interfacing with common devices, such as analogue sensors and motors, UARTs, ethernet, USB, CAN, etc. Highly recommend read, and great reference for developing BSPs and drivers. Also, just look at it. It's a fucking circuit board flying through space. How awesome is that?



Sure you say, I'm only putting it on here for fun. Well, kind of. This book is compendium of a number of useful bit hacks and whatnot, which can and often are useful in the world of embedded systems.

No comments:

Post a Comment