Following the IRQ_STORM example, I have written the following code:
Code: Select all
#define MAILBOX_MSG_SIZE 64
static mailbox_t mb;
static msg_t mb_msg[MAILBOX_MSG_SIZE];
static THD_WORKING_AREA(waThdBlinker, 128);
static THD_FUNCTION(ThdBlinker, arg) {
(void)arg;
chRegSetThreadName("Blinker");
static msg_t msgp[MAILBOX_MSG_SIZE];
while (true) {
switch (chMBFetchTimeout(&mb, msgp, TIME_INFINITE)) {
case MSG_OK :
palSetLine(LINE_LED_BLUE);
break;
case MSG_RESET :
case MSG_TIMEOUT :
palSetLine(LINE_LED_RED);
break;
}
}
}
int main(void) {
halInit();
chSysInit();
static msg_t result;
static uint8_t counter = 0;
static uint8_t info[5][MAILBOX_MSG_SIZE] = {"Lorem ipsum dolor sit amet, ",
"consectetur adipiscing elit. ",
"Nam eu mollis velit. ",
"Nulla facilisi. ",
"Integer ut viverra leo."};
chMBObjectInit(&mb, mb_msg, MAILBOX_MSG_SIZE);
chThdCreateStatic(waThdBlinker, sizeof(waThdBlinker), NORMALPRIO + 1,
ThdBlinker, NULL);
while (true) {
if (counter < 5) {
if (chMBPostTimeout(&mb, (msg_t)info[counter], TIME_IMMEDIATE) != MSG_OK) {
palSetLine(LINE_LED_RED);
}
counter++;
}
else {
counter = 0;
}
palToggleLine(LINE_LED_GREEN);
chThdSleepMilliseconds(200);
}
}
When it is executed, an exception is generated.
Code: Select all
Vector3FC:
#endif
bl _unhandled_exception
When I debugged the program, I verified that after creating the thread the chMBFetchTimeout() function returns the MSG_TIMEOUT value. Then, after sending three messages with the chMBPostTimeout() function, the chMBFetchTimeout() function gets the MSG_RESET value but never receives the MSG_OK value.
What am I doing wrong?
EDIT: The buffer that I used with chMBFetchTimeout() function was not defined. However, it still doesn't work.
Thank you.