vApplicationIdleHook in a C++ application

stanislaus123 wrote on Friday, January 05, 2018:

I am using ZYNQ on a MicroZed
My application is defined as a C++ application !
Below is the absolute minimum program

void vApplicationIdleHook( void );

void MyTask(void* param)
{
for(;;){
print(“blah blah\n”);
vTaskDelay(100);
}
}
void vApplicationIdleHook( void )
{
int i=0;
for(;;){
i++; //In my application will never be called
}

int main()
{
xTaskCreate( MyTask, “MyTask”, 1024, NULL, 2, NULL);
vTaskStartScheduler();
for(;:wink:
return 0;
}

FreeRTOS provides an idle task function called
void vApplicationIdleHook( void ) attribute((weak)); //in portZynq7000.c
To enable the idle function you must

define configUSE_IDLE_HOOK 1 //in FreeRTOSConfig.h

Since the idle hook function is declared as “weak”, I should be able to override
it inside my own application simply by declaring and defining it again like usual
This works just fine in C and the linker will give me NO error, but it does not work when the main application was created as a C++ application like main.cc The overridden function will not be called, but instead the weak function in portZynq7000.c will be called.

Does anybody know a simple trick to make this work in a simple manner?

Thanks
Kurt

rtel wrote on Friday, January 05, 2018:

Does anybody know a simple trick to make this work in a simple manner?

No, I don’t, but sure the C++ folks here will have a more knowledgeable
answer…that said, is portZynq7000.c being compiled as C or C++? If
it were compiled as C, or extern “C” were used, then maybe it would work?

richard_damon wrote on Friday, January 05, 2018:

For FreeRTOS callback functions yoou need to define them something like:

extern “C” {
void vApplicationIdleHook( void );
}

To force name mangling off for the function. You can either include the full defintion of the function inside the extern “C” block or just a forward decleration.

stanislaus123 wrote on Friday, January 05, 2018:

Thanks Richard (both of them)
this actually does work

Kurt