The structure of the message is like this:
Code: Select all
typedef struct
{
uint8_t length;
uint8_t tag;
uint8_t *msg;
DisplayFont *font;
} ui_msg;in header file
menu.h
Code: Select all
// Global variables
extern Thread *thMenu;
extern ui_msg menu_message;In menu.c
Code: Select all
Thread *thMenu;
ui_msg menu_message;
....
static WORKING_AREA (waMenu, UI_WA_SIZE);
static msg_t MenuServer(void *arg);
...
void MenuInit(void)
{
thMenu = chThdCreateStatic(waMenu, sizeof(waMenu), NORMALPRIO, MenuServer, NULL); // NULL here should be changed to a stream later
...
}
static msg_t MenuServer(void *arg) // "Server" where message should com
{
Thread *tpmenu;
ui_msg *message;
uint8_t button, displaystate;
uint8_t data[4];
(void)arg;
menuitem *CurrentMenu, *item;
chRegSetThreadName("Menu");
....
CurrentMenu = MainScreen;
ShowMenu(CurrentMenu, &CurrentReading, FULLMENU);
while (true)
{
/* Waiting for a queued message then retrieving it.*/
tpmenu = chMsgWait();
message = (ui_msg *)chMsgGet(tpmenu);
chMsgRelease(tpmenu, MSG_OK);
switch(message->tag) // <---- Set breakpoint here
{
case KEYBOARD: button = *(message->msg);
break;
case MENUCHANGE: CurrentMenu = (menuitem *)(message->msg);
break;
default: break;
}
if((message->tag) == KEYBOARD)
{ ... } // KEYBOARD
}
return 0;
}
static void RunCalibrationMenu(void *arg)
{
(void)arg;
chVTReset(&MenuTimer); // reset timeout timer for the button
ShowMenu(CalibrationMenu, &CurrentReading, FULLMENU);
chSysLock();
screenstate = CALIBMENU;
menu_message.length = 1; // fill the global menu_message with data
menu_message.tag = MENUCHANGE;
menu_message.msg = (uint8_t *)CalibrationMenu;
chSysUnlock();
chMsgSend(thMenu,(msg_t)&menu_message); // <--- Does not send the message?!!!
}
in ui_driver.c
Code: Select all
#include "menu.h" // for having access to the menu_message
...
static msg_t UI_EventsHandler(void *arg) // VT and keyboards interrupts events handler
{
...
uint8_t evdata[16], evindata;
tUI_EventsHandler = chThdSelf();
while(true)
{
inevent = chEvtWaitAny((eventmask_t)(DISPLAY_VT_REQUEST | KEYB_RD_REQUEST));
if(inevent & DISPLAY_VT_REQUEST)
{ .... }
if(inevent & KEYB_RD_REQUEST)
{
....
chSysLock();
menu_message.tag = KEYBOARD; // fill the global menu_message with required data
menu_message.msg = &evindata; //
chSysUnlock();
chMsgSend(thMenu,(msg_t)&menu_message); // <--- Sending message works just fine!!!
}
}
return 0;
}
So, why the similar procedure of filling structure with data and sending message to the same thread works fine in one case and does not in another? Debugging stops at the shown breakpoint when UI_EventsHandler() sends the messages and does not when RunCalibrationMenu() sends it.
Can it happen because RunCalibrationMenu() is a callback?