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

rtx stack overflow due to apparent bug with mailbox implementation

I am using the CMSIS version of rtx.

Here is my code:

void status_led_task(void const * arg)
{
    bool b_flashing_state = false;

    uint16_t flashing_led_mask = 0;
    uint16_t current_led_mask;
    int current_state;

    osEvent event;
    mail_t * p_mail;

    init();

    while(1)
    {
        /* wait for a message or the desired flashing perid */
        event = osMailGet(g_mail_queue, osWaitForever);//STATUS_LED_FLASHING_PERIOD);

        if (event.status == osEventTimeout)
        {
            /* time to flash any status leds that are in the flashing state */
            if (b_flashing_state == true)
            {
                leds_on(flashing_led_mask);
            }
            else
            {
                leds_off(flashing_led_mask);
            }

            b_flashing_state = !b_flashing_state;
        }
        else if (event.status == osEventMail)
        {
            p_mail = event.value.p;
            current_led_mask = p_mail->led_num + STATUS_LED_GPIO_OFFSET;
            current_led_mask = (1 << current_led_mask);
            current_state = p_mail->state;
            osMailFree(g_mail_queue, p_mail);

            switch(current_state)
            {
                case LED_OFF:
                    /* disable flashing mode for this pin */
                    flashing_led_mask &= ~current_led_mask;
                    led_off(current_led_mask);
                    break;

                case LED_ON:
                    /* disable flashing mode for this pin */
                    flashing_led_mask &= ~current_led_mask;
                    led_on(current_led_mask);
                    break;

                case LED_FLASHING:
                    /* enable flashing mode for this pin */
                    flashing_led_mask |= current_led_mask;
                    break;
            }
        }
    }
}

As you can see this is a simple led driver. Another task sends messages to this task via a
mail queue. The message indicates a led number and a desired state. To handle any leds that
are in the flashing state, I have a timeout on my osMailGet() call. If a timeout occured I
toggle any leds in the flashing state, else if a message arrived, I put the indicated led into
the correct state.

My problem is this. You will notice above that I have commented out the timeout on the osMailGet() call. This essentially removes the flashing functionality. The reason I did this is because if the timeout condition is present then the task that sends the message to this task, will have a stack overflow very quickly after the first few messages. If I don't have a timeout and wait forever for messages then I dont' have any problems and I can run all day sending messages to this task, albeit without the flashing functionality.

Can anyone see anything wrong with the way I have implemented this code, or give me an understanding as to why having the timeout condition might be a problem. Frankly I am beginning to suspect a bug with the CMSIS port of RTX.

I will add that currently I am using a switch that I am manually pressing to send the messages to this led driver. The switch is being debounced by having to have 2 consecutive reads of the switch be the same, where the polling frequency is 25ms.

Thanks,

0