This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Mailbox_post() inside HWI

Hi!

I want to do a mailbox_post inside a function which is called from a uart HWI. I set the mailbox_post timeout to zero but my programs ends when it's doing the mailbox_post() call. When i do the exact same mailbox_post() in a function it is working fine.

Thanks!

Orignial post:

I want to implement a mailbox in my code but it exits when doing mailbox stuff. So i tested the event example but this gives the same result.

When i run the program it prints some stuff and then exits to the loader_exit().

writing message id = 0 val = 'a' ...
writing message id = 1 val = 'b' ...
writing message id = 2 val = 'c' ...
Implicit posting of Event_Id_02
read id = 0 and val = 'a'.
Implicit posting of Event_Id_02
read id = 1 and val = 'b'.
writer done.
Implicit posting of Event_Id_02
read id = 2 and val = 'c'.
Explicit posting of Event_Id_00 and Implicit posting of Event_Id_01

I'm using TI-RTOS 2.16.01.14

Thanks!

  • Hi Ruben,
    The code exits because the reader task calls BIOS_exit() when it finishes. This causes the contents of the System buffer to be flushed to the console. Are you calling BIOS_exit() in your code?
    Best regards,
    Janet
  • My bad, the event example works. But my own program not.

    I call the Mailbox_post() funciton from a function which is called by a uart HWI. I set the Mailbox_post() timeout to zero.

  • Update:

    uart init:

    void uart_init()
    {
        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        GPIOPinConfigure(GPIO_PA0_U0RX);
        GPIOPinConfigure(GPIO_PA1_U0TX);
        SysCtlPeripheralReset(SYSCTL_PERIPH_UART0);
        GPIOPinTypeUART(GPIO_PORTA_BASE, (GPIO_PIN_0 | GPIO_PIN_1));
    
        UARTConfigSet(DBGCON_UART_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    
        Hwi_Params Hwi0Params;
        Hwi_Params_init(&Hwi0Params);
        Hwi_create(INT_UART0_TM4C129, uart0_isr, &Hwi0Params, NULL);
        UARTIntEnable(UART0_BASE, UART_IRUPT_MASK);
        IntEnable(INT_UART0);
    }

    uart0_isr:

    static void uart_isr(U32BIT baseaddr, void (*handler)(U8BIT c), void (*can_handler)(unsigned long))
    {
        U8BIT bt;
        unsigned long intstatus = UARTIntStatus(baseaddr, true);
    
        UARTIntClear(baseaddr, intstatus);
    
        while (UARTCharsAvail(baseaddr))
        {
            bt = (U8BIT) UARTCharGet(baseaddr);
    
            if (!(intstatus & UART_IRUPT_ERROR_MASK))       // Only handle when no errors
                handler(bt);
        }
    
        if ((intstatus & UART_IRUPT_ERROR_MASK))    // Forward error to application layer
            if (can_handler)
                can_handler(intstatus & UART_IRUPT_ERROR_MASK);
    }

    The mailbox_post() happens in the handler() function. but when the mailbox_post function is called the program ends with exit_loader()

  • Hi Ruben,
    It is ok to call Mailbox_post() in Hwi context as long as the timeout is 0. I don't see the code to your handler() function, but can you set a breakpoint there and confirm that you are passing a timeout of 0 to Mailbox_post()?
    Best regards,
    Janet
  • Yes i'm passing 0 to the mailbox_post funciton.

    I get it working now, i changed the mailbox_pend function. OLD situation when it is not working:

    Void debug_task(Void)
    {
       while (TRUE)
       {
            debug_main();
       }
    }

    void debug_main(void)
    {
    	char cmd_str;
    
    	if(Mailbox_pend(mailbox0, &cmd_str, BIOS_WAIT_FOREVER))
    	{
    				HandleDebugCmd(&cmd_str);
    	}
    }

    New situation WORKING:

    Void debug_task(Void)
    {
        debug_main();
    }

    void debug_main(void)
    {
    	while (TRUE)
    	{
    		char cmd_str;
    
    		if(Mailbox_pend(mailbox0, &cmd_str, BIOS_WAIT_FOREVER))
    		{
    					HandleDebugCmd(&cmd_str);
    		}
    	}
    }

    So i moved the while loop.. strange that it matters.

    I have now one problem left. When the mailbox_pend funciton gets a message my main task stops. The other tasks are doing fine. i have a look into that.

  • It shouldn't matter where the while loop is.
    I would look into your stack size. Try increasing the stack size to see if it changes anything.
    And why not move everything into debug_task?
  • Hi Ruben,
    I agree with Michel, that the location of the while () loop shouldn't matter. You can look at task stack usage in CCS using ROV (under the Tools menu).
    Best regards,
    Janet
  • Before the mailbox_pend() is done i can look into the ROV task section. After the mailbox_pend() function is getting it's data i cannot look into the ROV task Section. See screenshot:

  • well i found the "sollution", when i change the mailbox size from 96 to 48 the code is working.
    Only the strange problem with the position of the wile loop is not fixed.

    The most is working now :)
  • Hi Ruben,

    First of all, the fact that you cannot see the ROV task data means that your memory got corrupted.

    For your mailbox issue, you should look into your heap size. I suppose that you don't pass an array to store your messages when you initialize your mailbox. That means that data has to come from the heap (if you don't have enough memory available in the heap, it will crash).

    Second, try increasing your stack size because, like we mentioned before, the position of the while loop should not matter. The memory for your stack can come from your heap or a predefined array used for storage. I would recommend predefining an array because you won't have to worry about changing the heap size every time you have a new task or module.

    All those problems that you've been having are warning signs. You should not ignore these, because you will most likely have even more problems as your program grows.

    If you don't know how to change the sizes of the stack and heap, just ask. I haven't worked with CCS but I'm sure someone from TI will have the answer and be more than happy to help.

    Michel