I am using xTaskCreate in FreeRTOS whose 4th parameter (void * const) is the parameter to pass to the function invoked by the new Thread.
void __connect_to_foo(void * const task_params) {
void (*on_connected)(void);
on_connected = (void) (*task_params);
on_connected();
}
void connect_to_foo(void (*on_connected)(void)) {
// Start thread
xTaskCreate(
&__connect_to_foo,
"ConnectTask",
STACK_SIZE,
(void*) on_connected, // params
TASK_PRIORITY,
NULL // Handle to the created Task - we don't need it.
);
}
I need to be able to pass in a function pointer with signature
void bar();
But I can't work out how to cast void* to a function pointer that I can invoke. Closest I can get is:
error: 'void*' is not a pointer-to-object type on line 3
How can I cast task_params to a function pointer that I can invoke?
NB the code above is grossly simplified.