Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314902 - Configuring a function pointer fails if function signature contains a UInt16 arg
Summary: Configuring a function pointer fails if function signature contains a UInt16 arg
Status: RESOLVED INVALID
Alias: None
Product: RTSC
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Sasha Slijepcevic CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-28 11:57 EDT by Brian Cruickshank CLA
Modified: 2012-09-24 14:54 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Cruickshank CLA 2010-05-28 11:57:29 EDT
Configuring a function pointer with the address of a function only seems to work if the function signature does not contain any UInt16 arguments.

If the function signature contains one or more UInt16 arguments, the following error is reported (XDC 3.16.02.32):
-----------------------
package/cfg/log_xem3.c", line 3455:
error: declaration is incompatible with "void ti_uia_stm_LoggerSTM_writeMemoryRange__E(ti_uia_stm_LoggerST M_Handle, xdc_runtime_Types_Event, xdc_UInt32, xdc_IArg, xdc_IArg, xdc_IArg, xdc_IArg, xdc_UInt16)" (declared at line 408 of "C:/UIA_work/ti/uia/stm/LoggerSTM.h")

1 error detected in the compilation of "package/cfg/log_xem3.c
-----------------------

Changing the last argument type to either UInt32 or IArg allows the project to compile without errors.

Here's how the function pointer is declared:

in ti/uia/runtime/LoggerTypes.xdc:
typedef Void (*LogMemoryRangeFxn)(Ptr, Types.Event, UInt32, IArg, IArg, IArg, IArg, UInt16);

in the .xdc file of the module to be configured:
config ti.uia.runtime.LoggerTypes.LogMemoryRangeFxn loggerMemoryRangeFxn = null;

in the .xdc file of the module that contains the implementation of the function:
instance:
@DirectCall
Void writeMemoryRange(xdc.runtime.Types.Event evt, UInt32 snapshotId, IArg fileName, IArg LineNum, IArg fmt, IArg startAdrs, UInt16 lengthInMAUs);

in the .xs file that assigns the function address to the function pointer:
var cn = mod.common$.logger.$orig.$module.$name.replace(/\./g, '_');
...
mod.loggerMemoryRangeFxn = $externFxn(cn + '_writeMemoryRange__E');

or in the .cfg file that assigns the function address to the function pointer:
LogSnapshot.loggerMemoryRangeFxn = $externFxn(ti_uia_stm_LoggerSTM_writeMemoryRange__E);
Comment 1 Dave Russo CLA 2012-09-24 14:54:57 EDT
$externFxn("foo") can only be used to declare the specified function, foo, as follows:
   extern void foo();

The errors below suggest that the compiler is refusing to allow the assignment of this type of function pointer to a function pointer of type (void *(ti_uia_stm_LoggerST M_Handle, xdc_runtime_Types_Event, xdc_UInt32, xdc_IArg, xdc_IArg, xdc_IArg, xdc_IArg, xdc_UInt16))

To ensure an exact type match in the generated C file, you can use the following syntax:

    var LoggerSTM = xdc.module("ti.uia.stm.LoggerSTM");
    LogSnapshot.loggerMemoryRangeFxn = LoggerSTM.writeMemoryRange;

If the function is _not_ defined by a module (e.g., defined in your application's C code), you can use the following:
    LogSnapshot.loggerMemoryRangeFxn = "&nameOfMyCFunction";