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.
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(;;); } } }
Why mail yourself? If you get a timeout, then its because the mail box is empty. And if you mail yourself when the mail box is empty, then it will contain a single mail - yours. So when you look for mails you will directly get your mail, and directly after look for mails again and get stuck waiting on an empty mb.
And if there is all the time mails in the mailbox from other threads, then you will never get a timeout, so will never add your mail to yourself. So you will not activate what event you intended to trig with your own mail.
What is the actual problem you are trying to solve? A kind of round-robin scheduling of other actions?
A mail consumer normally solves its own problems either at the timeout time, or before deciding to look for more mails, so I'm very much confused about your design plans.