I'm trying to come up with a simple yet extensible method of writing firmware with hardware abstraction. For example, suppose one has a two different boards with some overlap in software functionality and similar CPUs (same arch., different mfgr). Furthermore, these two boards have different revision levels which cause some of the functions to do things slightly differently. I've been talking to my workmates and we've been oozing in the direction of the following:
i) a board depends on its rev. and the CPU type ii) an application depends on its board
So if I have board a and board be and an application foo then I'd have foo.c, board_a.c, and board_b.c. Now foo.c would have foo application generic functions while board_a.c and board_b.c would have functions with identical names and signatures, prototyped in board.h, but each file would have board-specific differences in implementation (see Fig. 1). Furthermore, board_a,b.c file would have rev. difference files and CPU primative files to isolate them from the containing the annoying rev. based changes and minutia of CPU differences.
I just can't seem to get my arms around this problem though. Any help appreciated.
Figure 1: foo.c #include "board.h"
init_board(); main();
board.h #ifdef BOARD_TYPE == A # include "board_a.h" #elif BOARD_TYPE == B # include "board_b.h" #else # error "Bad board choice" #endif
init_board();
board_a.h #define BOARD_MEM_SIZE 1024 #define BOARD_CLOCK_HZ 100000000
board_a.c #include "board.h"
init_board() { }
board_b.h #define BOARD_MEM_SIZE 4096 #define BOARD_CLOCK_HZ 400000000
board_b.c #include "board.h"
init_board() { }
Thanks,