Why MSP430? / Modular Philosophy
A common problem is how to write low level modules which must not be
modified for every specific target application the module is used for.
Example: a module which performs a keypad scan functionality must be
assigned ports for the rows and columns of the keyboard matrix. In
order to prevent loss of flexibility, portability and reusability of
the source code, macro names must be used in the source of the module
instead of actual port name resp. port bit names. The macronames must
be dereferenced in a .h-file. This may be done in the .h-file of the
module itself, but this requires .h-file modifications of each
specific target project.
The following solution is proposed (and has been proved to be effective):
Name the top level source text of your application project simply
main.c. It is even not practical to name it according to the
project´s name, because external readers of the sources cannot
identify the top level source text immediately. It is also not
necessary, because the sources are normally located into a
subdirectory named according to the project.
Having stated this, one can follow that every project also has a
main.h-file. Always this name. Now one can include always a
main.h file into the .c-file of low level sources which contain
target specific references. Now the macro names are resolved in the
main.h-file rather than the "lowlevel.h" file. All this
implies that much of the information in main.h-files of medium to
bigger projects contains a lot of information not of interest to the
low-level modules, but that´s harmless compared to the
capability offered here to maintain low level modules fully
independently of target projects. This implicitly allows for updating
improved low-level modules into specific projects without worry.
There is another advantage of this philosophy. All port pin
assigments can be found in a single file: main.h. This implies a full
overview of all assignments and optional settings of control macros
within a single section of a file. This allows quick checking of
double assignments or free port pins.
It is practical to maintain every low level module in its own
subdirectory. Here at least three files are present: lowlevel.c,
lowlevel.h and main.h. Actually, main.h is a template here which
contains macroname, port and control macro assignments related to
that module. The template can be inserted in the target´s
main.h and then modified according to the target specification. The
subdirectory may also contain a main.c-file here having the function
of testbench for the module only. |