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

Can a RTX task mail itself?

Is it possible to for a task to send mail to itself?

example:

/* Wait for mail (actions) to arrive from other tasks */
WaitResult = os_mbx_wait(gsm_mailbox, (VOID**)&gsm_actionP, MS_TO_SYS_TICKS(GSM_TICK_PERIOD) );      /* Wait for the message to arrive. */
switch ( WaitResult )
{
        case OS_R_OK:
        case OS_R_MBX:                  /* message received in mailbox */
                gsm_perform_action();
                break;
        case OS_R_TMO:                  /* Timeout while waiting for message */

                os_mbx_send(gsm_mailbox, ActionPS, MS_TO_SYS_TICKS(TIMER_5_SEC) );  /* mail yourself*/
                break;
        default:                                                /* Unknown */
                break;
}

In this example I never get the mail.

Parents
  • nevermind, this seems to work:

    __task void mailMyself (void)
    {
            void *msg;
            OS_RESULT waitresult;
            os_mbx_init (mailbox1, sizeof(mailbox1));
    
            for (;;)
            {
                    waitresult = os_mbx_wait (mailbox1, &msg, 10);
                    if (waitresult == OS_R_TMO)
                    {
    
                            msg = (void*)malloc(2);
                            os_mbx_send (mailbox1, msg, 0xFFFF);
            }
                    else if( (waitresult == OS_R_OK) ||  (waitresult == OS_R_MBX) )
                    {
                            free (msg);
                    }
                    else
                    {
                            for(;;);
                    }
            }
    }
    

Reply
  • nevermind, this seems to work:

    __task void mailMyself (void)
    {
            void *msg;
            OS_RESULT waitresult;
            os_mbx_init (mailbox1, sizeof(mailbox1));
    
            for (;;)
            {
                    waitresult = os_mbx_wait (mailbox1, &msg, 10);
                    if (waitresult == OS_R_TMO)
                    {
    
                            msg = (void*)malloc(2);
                            os_mbx_send (mailbox1, msg, 0xFFFF);
            }
                    else if( (waitresult == OS_R_OK) ||  (waitresult == OS_R_MBX) )
                    {
                            free (msg);
                    }
                    else
                    {
                            for(;;);
                    }
            }
    }
    

Children