Main Content

Call a Legacy Lookup Table Function Using C Caller block

This example shows how to use the C Caller block to call legacy C functions that implement N-dimensional table lookups.

In this example the legacy C functions are defined inlookupTable.h, and implemented indirectLookupTableND.c. The type definitions used in this example can be found inyour_types.h.

To enable calling the C functions from the C Function block, in the model, specify the header file and the source file in theConfiguration Parameters>Simulation Targetpane. The prototype of the legacy function being called in this example is:

FLT directLookupTableND(const FLT *tableND, const UINT32 nbDims, const UINT32 *tableDims, const UINT32 *tableIdx)

whereFLTis a type definition to a floating-point type, andUINT32is a type definition to an unsigned 32-bit integer.

  • const FLT *tableND- Table

  • const UINT32 nbDims- Dimensionality of the table

  • const UINT32 *tableDims- Size of the table

  • const UINT32 *tableIdx- Table index

In the C Caller block,tableNDandtableDimsare mapped to C Caller block parameters,nbDimsis a block constant, andtableIdxis the input to the block. The value returned by the legacy C function is the output of the block.

model ='slexCCallerLookupTable'; open_system(model); sim(model); slcc('clearCustomCodeModules');