Hi,
I am following a tutorial to understand freeRTOS. I came across with below code snippet in which I didnt understand fully. I hope this is the right place to ask, thank you.
First of all, how come a pointer is converted into uint32_t ?
Why notification value is chosen as cmd ?
void process_command(command_t *cmd)
{
extract_command(cmd);
switch(curr_state)
{
case sMainMenu:
xTaskNotify(handle_menu_task,(uint32_t)cmd , eSetValueWithOverwrite);
break;
case sLedEffect:
xTaskNotify(handle_led_task,(uint32_t)cmd , eSetValueWithOverwrite);
break;
case sRtcMenu:
case sRtcTimeConfig:
case sRtcDateConfig:
case sRtcReport:
xTaskNotify(handle_rtc_task,(uint32_t)cmd , eSetValueWithOverwrite);
break;
}
}
Task notifications are defined as sending a 32 bit word, or setting bits in that word. A pointer is nothing but a set of bits, so, if your pointers are 32 bits, as probably assumed in the sample, then you can convert them to a 32 bit number and back, and get the same value. So by using the mode that send the full 32 bit word as a single value, you can send a 32 bit pointer too.
Thanks Richard. One follow up question. I dont know the usage and need of notification value. What would happen if I provide NULL in my example instead of (uint32_t)cmd ?
Although the API requires a 32 bit notification value as Richard mentioned you might set the cmd pointer to NULL (which is 0) and cast it to a 32 bit value.
BUT this is bad code and if you follow a tutorial with such strange examples you should try another tutorial.