This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTOS osMessagePut usage problem

It takes me several days for debbuging ,but didn't work.

when the para 'timeout' of osMessagePut(id,info,timeout) is not set to 0,
then the program crashes with info 'OS_ERROR_MBX_OVF' , which means mailbox overflow.
But with timeout setting to 0,everything seems ok.

It really confuses me. Can anyone help me ? Thanks a lot!

The main frame of my program is as follows
(it is from mdk example 'CAN_Ex', basically not changed much )

osPoolDef(rlcan_mpool, 80, CAN_msg);
osMessageQDef(rlcan_msgq_tx, 20, CAN_msg);

/* Thread1, used to send can message */
while(1)
{
        ...
        /* check if  hardware is free for send */
        if (CAN_hw_tx_empty (ctrl) == CAN_OK)
        {
                CAN_hw_wr (ctrl, msg);     /* Send message */
        }
        else
        {
                ptrmsg = osPoolAlloc(rlcan_mpool);

                  /* for timeout is not 0, it crashes after ISR getting about 16 messages */
                result = osMessagePut(rlcan_msgq_tx, ptrmsg, 10);
                if (result != osOK) osPoolFree(rlcan_mpool, ptrmsg);
        }
        osDelay (500);
}


/* ISR, interrupt generates after msg sending succeeds */

void CAN0_ORed_Message_buffer_IRQHandler (void)
{
        ...
        iflag1 = CANc->IFLAG1; //iflag1 will be set if  msg sending succeeds

        while(iflag1)
        {
                iflag1 = 0;

                 /* it crashes after getting about 16 messages */
                 evt = osMessageGet(rlcan_msgq_tx[CTRL0], 0);
                if (evt.status == osEventMessage)
                {
                        CAN_hw_wr (CTRL,evt.value.p);  /* Send message */
                        osPoolFree(rlcan_mpool, evt.value.p);
                }
                iflag1 = CANc->IFLAG1; //check whether iflag1 is set again
        }
}

Parents
  • The "timeout" arguments specified in the "RTX_CAN.h" and "RTX_CAN.c" for a few functions such as CAN_ERROR CAN_send(); CAN_ERROR CAN_request(); CAN_ERROR CAN_set(); CAN_ERROR CAN_receive() have a wrong data type "uint16_t". They should be "uint32_t".
    This might be the reason for this issue. Please download the attached example project again via the following link:
    http://www.keil.com/support/docs/3714.htm
    This attached example project has just been updated to fix this bug on the 5th of Jun. 15.

    Please let me know if this helps. Thx!

Reply
  • The "timeout" arguments specified in the "RTX_CAN.h" and "RTX_CAN.c" for a few functions such as CAN_ERROR CAN_send(); CAN_ERROR CAN_request(); CAN_ERROR CAN_set(); CAN_ERROR CAN_receive() have a wrong data type "uint16_t". They should be "uint32_t".
    This might be the reason for this issue. Please download the attached example project again via the following link:
    http://www.keil.com/support/docs/3714.htm
    This attached example project has just been updated to fix this bug on the 5th of Jun. 15.

    Please let me know if this helps. Thx!

Children