Code Katas With An Embedded Software Twist

There’s been talk about Code Katas for quite some time now. The lore on the internet states that the idea of a code kata, or practice exercises that a programmer can go through to hone their skills, was created within the book “The Pragmatic Programmer” by coauthor Dave Thomas (interestingly, he keeps a rather cool blog with various katas listed to help programmers). Katas are great ideas for application coders, so I figured they’d be great for embedded coders as well; as they say, practice makes perfect.

Here’s my first exercise:

How big, how fast
With embedded software and hardware, understanding your resource utilization, system speeds, and code lengths are of paramount importance. You want your software system to be as fast as possible working with limited resources and you want margin for future modifications and features.

Microsoft Windows Vista, for example, doesn’t have a prayer of running on a 20MHz microcontroller, it’s just too much code that has to run that is timing critical that a slow processor like that can’t keep up with. Likewise, original copies of the game Wolfenstein 3D assumed certain things about the processor speed of the system it was running on; if you’ve ever tried to run original (I say original, because they later fixed this when they released the game for free), it’s unplayable on modern computers because the game play is too fast and it assumed much slower processors.

Adding on to Dave Thomas’s Kata 3: How Long, How Fast and making it Embedded software focused, ponder these ideas:

  1. How Big?
    1. How much memory does your system have versus how much do you need for a minimal set of complete functionality?
    2. How much space does a given function compile down to and, in addition, is there a more efficient way to write that code so that it performs the same functional task, but takes up less space in memory?
    3. Even though a standard library function does what you want it to do, how much less room can you take up by writing the function yourself?
    4. When is an inline function call more efficient than a standard function call and vice versa?
    5. If possible, is there a piece of software functionality in your system that is better suited to be moved to a hardware implantation than remain in software? (an answer to this may fit under both topics of how big and how fast in reality)
    6. When is using a macro (function or value) more efficient than a constant and when should you avoid using macros?
  2. How Fast?
    1. How would you create a delay loop to precisely time portions of your code either through blocking, polling, and/or hardware controlled interrupts?
    2. How long does it take for your system to perform a context switch for an interrupt?
    3. What’s the slowest your system can be run at while still meeting all of it’s processing deadlines?
    4. How much data do you need to pass around in your system, would passing by reference or getting a pointer to the data be more efficient in your implementation than passing by value?
    5. Will unrolling your for loops better utilize your resources or just make the code harder to understand?

Tags:

 
 
 

Comments are closed.