www.ti.com
Interfaces and Modules
typedef | struct FIR_Obj { /* | FIR_Obj definition | */ | |
int | hist[16]; | /* | previous input value */ | |
int | frameLen; | /* input frame length | */ | |
int | *coeff; |
|
|
|
} FIR_Obj;
FIR_Handle FIR_create(FIR_Obj *fir, const FIR_Params *params)
{
if (fir != NULL) {
if (params == NULL) { /* use defaults if params is NULL */ params = &FIR_PARAMS;
}
}
return (fir);
}
The delete entry point should release any resource held by the object being deleted and should gracefully handle the deletion of partially constructed objects; the delete entry point may be called by the create operation. In this case, there is nothing to do.
void FIR_delete(FIR_Handle fir)
{
}
Finally, the FIR module must provide a method for filtering a signal. This is accomplished via the apply operation shown below.
void FIR_apply(FIR_Handle fir, int in[], int out[])
{
int I;
/* filter data using coefficients
for (I = 0; I <
out[i] = filter(in[i],
}
}
Of course, in a real FIR module, the filter operation would be implemented in assembly language. However, because the state necessary to compute the algorithm is entirely contained in the object pointed to by fir, this algorithm is reentrant. Thus, it is easy to use this module in multichannel applications or in
3.1.9 Multiple Interface Support
Modern component programming models support the ability of a single component to implement more than one interface. This allows a single component to be used concurrently by a variety of different applications. For example, in addition to a component'sconcrete interface (defined by its header) a component might also support a debug interface that allows debuggers to inquire about the existence and extent of the component'sdebug capabilities. If all debuggable components implement a common abstract debug interface, debuggers can be written that can uniformly debug arbitrary components.
Support for multiple interfaces is generally incorporated into the development environment (via Code wizards), the programming language itself, or both. Since this standard is intended to only require the C language, the ability of a module to support multiple interfaces is at best awkward.
However, several significant benefits make this approach worthwhile:
∙a vendor may decide not to implement certain interfaces for some components,
∙new interfaces can be defined without affecting existing components,
∙multiple implementations of the same interface may be present in a single system, and
∙partitioning a large interface into multiple simpler interfaces makes it easier to understand the component as a whole.
As stated before, interfaces are defined by header files; each header defines a single interface. A
SPRU352G | Algorithm Component Model | 31 |