This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Help needed with ISR function ptr compiler error



Hi

I am working on a Keystone II DSP project.  I am having difficulty fixing a compiler error related to a function pointer for an ISR.

The following code is defined in a .cpp file:

extern void System_registerIsr(uint32 sysEvent, uint32 hostEvent, void (*fxn)(UArg));

// Table to define the interrupt sources
typedef struct
{
    EIntMap intCoreMap;
    uint32 systemInterrupt;
    uint32 hostInterrupt;
    uint32 hwInterrupt;
    void (*isrHandler)(UArg arg);
}Ctrl_IsrCfgTable;

Ctrl_IsrCfgTable IsrCfgTable[ISR_NUM_ENTRIES] =
{
  {INT_COREA, 158, 68, 4, &Isr_A},
  {INT_COREA, 300, 69, 5, &Isr_B},
<snip>
};

void myFunc()
{
    System_registerIsr( IsrCfgTable[idx].systemInterrupt,
                                    IsrCfgTable[idx].hostInterrupt,
                                    IsrCfgTable[idx].isrHandler );

The call to System_registerIsr() yields error:

error #169: argument of type "void (*)(UArg) C" is incompatible with parameter of type "void (*)(UArg)"

System_registerIsr() is declared in another .cpp file.

Why am I getting this error?

Best regards

David

  • Interrupt handlers are typically C functions, not C++ functions.  In C++, you must declare C functions as 'extern "C"'.  Most likely you should be including the header file which defines System_registerIsr in an 'extern "C"' block, like so:

    extern "C" {
    #include <registerisr.h>
    }

    Ideally the header file should be taking care of this itself, but often this is overlooked.

  • Thanks for your reply but it has not solved my problem.  Please let me restate the problem.

    I have an interrupt configuration table that is stored in IsrCfgTable.  I have a function called System_registerIsr() that I use to register the ISR's defined in IsrCfgTable.  IsrCfgTable, System_registerIsr() and the function that calls System_registerIsr() live in source file isr.cpp.  The pertinant code is:

    Ctrl_IsrCfgTable    IsrCfgTable[ISR_NUM_ENTRIES] =
    {
    {INT_COREA, 158, (68+(10*MY_CORE)), 4, &Isr_ulAif2ReceiveQpend},
    {INT_COREA, 300, (69+(10*MY_CORE)), 5, &Isr_ulBitReverseQpend},
    {INT_COREA, 159, (70+(10*MY_CORE)), 6, &Isr_ulVcpCompletionQpend},
    {INT_COREA, 206, (71+(10*MY_CORE)), 7, &Isr_aif2Mntr},
    };
    
    void System_registerIsr(uint32 sysEvent, uint32 hostEvent, void (*fxn)(UArg))
    {
        int eventId = CpIntc_getEventId(hostEvent);
        CpIntc_dispatchPlug(sysEvent, (CpIntc_FuncPtr)fxn, sysEvent, TRUE);
        CpIntc_mapSysIntToHostInt(0, sysEvent, hostEvent);
        CpIntc_enableHostInt(0, hostEvent);
        CpIntc_enableSysInt(0, sysEvent);
    }
    
    void Ctrl_InitInterrupts(void)
    {
        Hwi_Params hwiParams;
    
        // Setup all the necessary mapped interrupts for the relevant cores
        for (uint32 idx=0; idx <ISR_NUM_ENTRIES; idx ++)
        {
            if(IsrCfgTable[idx].intCoreMap == MY_CORE)
            {
                System_registerIsr(IsrCfgTable[idx].systemInterrupt,
                                               IsrCfgTable[idx].hostInterrupt,
                                               IsrCfgTable[idx].isrHandler);          <====== Error
    

    The error for the indicated line is:

    argument of type "void (*)(UArg) C" is incompatible with parameter of type "void (*)(UArg)"

    As I said above, all the above code is in a .cpp file.  How can I resolve this error please?

    Best regards

    David 

  • FIrst I'll illustrate your error with a contrived example.

    % type file.cpp
    void register_isr(void (*fxn)(int));
    extern "C" void isr_handler(int);
    
    void do_stuff()
    {
       register_isr(isr_handler);
    }
    
    % cl6x --verbose_diagnostics file.cpp
    "file.cpp", line 6: error: argument of type "void (*)(int) C" is incompatible
              with parameter of type "void (*)(int)"
         register_isr(isr_handler);
                      ^
    
    1 error detected in the compilation of "file.cpp".
    
    >> Compilation failure

    The fix is to make the type of the argument to register_isr match with the declaration for isr_handler.  There are two ways to do that.  One is to make register_isr extern "C".  

    extern "C" {                               // new code here
       void register_isr(void (*fxn)(int));
    }
    
    extern "C" void isr_handler(int);
    
    void do_stuff()
    {
       register_isr(isr_handler);
    }

    The other method is to remove extern "C" from the declaration of isr_handler.

    void register_isr(void (*fxn)(int));
    void isr_handler(int);                // change here
    
    void do_stuff()
    {
       register_isr(isr_handler);
    }

    I'm not sure which approach is best in your case.

    Thanks and regards,

    -George

  • Hi George

    Thanks for your answer. My problem is now fixed.

    Best regards

    David