I’m experiencing a strange problem in passing parameters to a simple task of toggling an led. Below is my code:
//=================================================================================
const unsigned long SLEEP_TIME[] = {1000000, 3000000}; //sleep for 1 and 3 sec.
void tskFlashLED( void * ptr ) {
unsigned int index = *((unsigned int*)ptr); //index of led
for(;;){
if(index < 2){
vTaskDelay( (unsigned long)SLEEP_TIME[index]/(1000*portTICK_RATE_MS) ); //Delay for 1 or 3 sec
if(led_status(index) == 0){
led_on(index); //Turn on led
} else{
led_off(index); //Turn off led
}
}
}
}
What can I do to work round the problem? In fact, I’ve already taken reference to the example code on BlockQ.c, and I’ve already saved a copy of the value when I enter the function as follow:
void tskFlashLED( void * ptr ) {
unsigned int index = *((unsigned int*)ptr); //index of led
…
}
Since $arg1 is reside in the function vUserMain(), on exit of the function, the local variable $arg1 will not be valid anymore. So $arg1 should either be global of declared static (as in dynamic.c).