www.ti.com
Interfaces and Modules
Guideline 4
All modules that support object creation should support
Note that the
3.1.7 Module Configuration
In an ideal world, a module that implements an API can be used in any system that requires the API. As a practical matter, however, every module implementation must make
It is important, therefore, that multiple implementations of the same API be well supported by any
Suppose for example, that one created a module that implements digital filters. There are several special cases for digital filters that have significant performance differences;
Modules that have one or more "global" configuration parameters should group them together into a C structure, called XYZ_Config, and declare this structure in the module'sheader. In addition, the module should declare a global structure named XYZ of type XYZ_Config that contains the module'scurrent configuration parameters.
3.1.8 Example Module
This section develops a very simple module to illustrate the concept of modules and how they might be implemented in the C language. This module implements a simple FIR filter.
The first two operations that must be supported by all modules are the init() and exit() functions. The init() function is called during system startup while the exit() function is called during system shutdown. These entry points exist to allow the module to perform any
void FIR_init(void)
{
}
void FIR_exit(void)
{
}
The create entry point creates and initializes an object; i.e., a C structure. The object encapsulates all the state necessary for the other functions to do their work. All of the other module entry points are passed a pointer to this object as their first argument. If the functions only reference data that is part of the object (or referenced within the object), the functions will naturally be reentrant.
typedef | struct FIR_Params { | /* FIR_Obj | creation parameters */ | |
int | frameLen; | /* | input/output frame length */ | |
int | *coeff; | /* | pointer to | filter coefficients */ |
} FIR_Params;
FIR_Params FIR_PARAMS = { 64, NULL }; /* default parameters */
30 | Algorithm Component Model | SPRU352G |