我一直在开发基于 CMSIS-RTOS 的软件,但函数 osMessageGet 有问题。我的软件由四个 RTOS 任务组成,其中两个通过 osMessageQueue 和 osPool 交换数据。一个任务 (Task_100ms) 是生产者,第二个任务 (Task_200ms) 是消费者。
Task_100ms 从 CAN 总线接收数据并创建包含接收数据的结构。生产者使用函数 osPoolAlloc 在池 (flash_pool) 上分配内存,并接收指向已分配内存的指针。Producer 使用这个指针将交换结构的内容复制到池中的内存块中,并使用函数 osMessagePut 将该指针的副本放入队列(flash_queue)中(请参见下面的put_program_chunk函数代码)。
Task_200ms 尝试使用 osMessageGet 函数从 flash_queue 检索指针(请参阅下面的program_chunk函数代码)。只要队列是空的,消费者就会等待并且一切正常。然后 Task_100ms 将第一个指针放在 flash_queue 上。Task_200ms 调用 osMessageGet 函数,这会导致 uC 重置,以防 osMessageGet 的超时设置为 osWaitForever。如果 osMessageGet 的超时设置为 0,则不会调用软件重置。但是在这两种情况下(超时等于 0 或 osWaitForever),当我单步执行 Eclipse 中的代码时,我无法在 osMessageGet 函数调用之后立即实现以下语句。
任何人都可以给我任何建议,我的问题的原因可能是什么?如果需要,我可以将整个源代码发送给您。在此先感谢您的任何建议。
BOOL put_program_chunk(main_controller_req_t req){
main_controller_req_t *p_req;
BOOL retval;
BOOL no_memory = FALSE;
/*!!!*/
osStatus status;
uint8_t tmp;
// allocate memory in pool
p_req = (main_controller_req_t *)osPoolAlloc(flash_pool);
if(p_blk == NULL){
printf("No more space in flash pool.\r\n");
}
if(p_req != NULL){
*p_req = req;
// insert the prepared request into the transmission queue
// put the message into the queue
// wait 5 ms?
status = osMessagePut(flash_queue, (uint32_t)(p_req), 5);
/*!!!*/
if(status == osOK){
tmp = 1;
}else{
tmp = 0;
}
}else{
no_memory = TRUE;
}
if(no_memory){
retval = FALSE;
}else{
retval = TRUE;
}
return retval;
}
void program_chunk(void){
osEvent event;
osStatus status;
main_controller_req_t *p_req;
main_controller_req_t req;
pdt_result_t result;
// !!!
uint8_t tmp;
// retrieve the data block from the message queue
event = osMessageGet(flash_queue, 0);
// !!!
tmp++;
/*
if(event.status == osEventMessage){
p_req = ((main_controller_req_t *)(event.value.p));
// copy the content of memory block in receiving pool
req = *p_req;
// free the memory in pool
status = osPoolFree(flash_pool, p_req);
// Normal (=000000) or Boot (=BOOTBL) mode?
if(*req.mode == 0 && *(req.mode + 1) == 0 && *(req.mode + 2) == 0 &&
*(req.mode + 3) == 0 && *(req.mode + 4) == 0 && *(req.mode + 5) == 0){
// Normal mode
// program chunk for the Slot_0 or Slot_1?
if(((req.flash_page_number >= 0x01) && (req.flash_page_number < MAX_AC_PAGE)) ||
((req.flash_page_number == MAX_AC_PAGE) && (req.flash_block_number <= MAX_AC_BLOCK))){
#ifdef APP_DEBUG
printf("AC programming!\r\n");
#endif
// yes - program the retrieved program chunk
result = pdt_app_program_chunk(req.data_block, 32);
// according to the result send the short flash write response message - page and block OK
send_short_flash_load_write_resp((result == PDT_RESULT_OK) ? TRUE : FALSE, FALSE, req.flash_page_number, req.flash_block_number);
// if unsuccessful programming
if(result != PDT_RESULT_OK){
// go into WAIT_TO_FLASH_LOAD_COMPLETE
SetLogicSignal(LGoWtFlshLdCmpl);
}
// program chunk for Motor Controller?
}else if(((req.flash_page_number == MAX_AC_PAGE) && (req.flash_block_number > MAX_AC_BLOCK && req.flash_block_number <= MAX_MC_BLOCK)) ||
((req.flash_page_number > MAX_AC_PAGE) && (req.flash_page_number <= MAX_MC_PAGE))){
#ifdef APP_DEBUG
printf("MC programming!\r\n");
#endif
// yes - program the retrieved program chunk
result = pdt_mc_update_internal_motor_controller_chunk(req.data_block, 32);
// according to the result send the short flash write response message - page and block OK
send_short_flash_load_write_resp((result == PDT_RESULT_OK) ? TRUE : FALSE, FALSE, req.flash_page_number, req.flash_block_number);
// end of the binary?
if((req.flash_page_number == NO_PAGES) && (req.flash_block_number == BLOCKS_IN_PAGE) && result == PDT_RESULT_OK){
result = pdt_mc_update_motor_controller();
// invoke SW reset
result = pdt_app_switch_application();
// if unsuccessful programming
}else if(result != PDT_RESULT_OK){
// go into WAIT_TO_FLASH_LOAD_COMPLETE
SetLogicSignal(LGoWtFlshLdCmpl);
}
// wrong destination address?
}else{
#ifdef APP_DEBUG
printf("Wrong destination address!\r\n");
#endif
// wrong data block destination
send_short_flash_load_write_resp(FALSE, TRUE, req.flash_page_number, req.flash_block_number);
// go into WAIT_TO_FLASH_LOAD_COMPLETE
SetLogicSignal(LGoWtFlshLdCmpl);
}
}
}
*/
}