How do you organize code in embedded projects?
code-organization, embedded
Solution
I've written and maintained multiple embedded products (30+ and counting) on a variety of target micros, including MSP430's. The "rules of thumb" I have been most successful with are:
- Try to modularize generic concepts as much as possible (e.g. separate driver code from application code). -- It makes for easier maintenance and reuse/porting of a project to another target micro in the future.
- DO NOT start by worrying about optimized code at the very beginning. Try to solve the domain's problem first and optimize second. -- Your target micro can handle a lot more "stuff" than you might expect.
- Work to ensure readability. Although most embedded projects seem to have short development-cycles, the projects often live longer than you might expect and another developer will undoubtedly have to work with your code.
Problem
Highly embedded (limited code and ram size) projects pose unique challenges for code organization. I have seen quite a few projects with no organization at all. (Mostly by hardware engineers who, in my experience are not typically concerned with non-functional aspects of code.) However, I have been trying to organize my code accordingly: - hardware specific (drivers, initialization) - application specific (not likely to be reused) - reusable, hardware independent For each module I try to keep the purpose to one of these three types. Due to limited size of embedded projects and the emphasis on performance, it is often keep this organization. For some context, my current project is a limited DSP application on a MSP430 with 8k flash and 256 bytes ram.