anonymous wrote on Sunday, November 03, 2013:
Hi!
I try to create a C++ application (and C++ tasks) based on FreeRTOS but I can not call the xTaskCreate() function from my C++ code.
Default FreeRTOS main() function:
/* default FreeRTOS main() */
int main( void )
{
prvSetupHardware();
/* Exported C++ function */
runTask();
...
}
Below the header and source files based on the following both examples:
http://sourceforge.net/p/freertos/discussion/382005/thread/5d5201c0
http://interactive.freertos.org/entries/223648-using-freertos-with-c
I think I have included all relevant C-header files in my C++ header:
#ifdef __cplusplus
extern "C" {
#endif
#include <FreeRTOS.h>
#include <task.h>
#ifdef __cplusplus
}
#endif
… and my C/C++ wrapper functions:
#ifdef __cplusplus
extern "C" {
#endif
void tskWrp(void* p);
void runTask();
#ifdef __cplusplus
}
#endif
C++ source file: prl_task.cc
/* C++ source file: prl_task.cc /*
/*-----------------------------*/
/* 2 simple tasks */
void vTask1( void ) {
doSomething();
}
void vTask2( void ) {
doSomething();
}
/*------------------------------*/
/* base class CTask */
CTask::CTask(char const* name,
unsigned portBASE_TYPE priority,
unsigned portSHORT stackDepth=1000) {
/* Code works up to here! */
//vTask1();
xTaskCreate(&tskWrp, (signed char*)name, 1000, this, 1, NULL);
}
void CTask::Task() {
vTask1();
}
/*-------------------------------*/
/* derived class CTask1 */
CTask1::CTask1(char const* name,
unsigned portBASE_TYPE priority,
unsigned portSHORT stackDepth=1000) : CTask(name, priority,stackDepth) {
}
void CTask1::Task() {
vTask2();
}
/*--------------------------------*/
/* interface functions C C++ */
void runTask(){
CTask1 task("tsk",1,1000);
}
/*--------------------------------*/
/* wrapper function */
void tskWrp(void* p) {
(static_cast<CTask*>(p))->Task();
}
I can compile the code without errors but the xTaskCreate() function will be “ignored” and the program is not running on my MPU. If I call directly another functions e.g. vTask1() instead of xTaskCreate() the program works fine on the MPU.
By the way my IDE throws a warning “Function ‘xTaskGenericCreate’ could not be resolved”. I’m not sure whether the IDE warning or any other reason is the cause of my problem.
Maybe someone can help me?
Florian