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

Application of Mailbox

How are the functions _init_box & _declare_box different from os_mbx_init & os_mbx_declare.
I am studying the their application and usage but am finding it quite confusing.

googled but cant find relevant results. havent come across any article that explains the memory allocation related to mailbox.

Am i correct in implementing mailbox in isr?

Parents
  • void UART0_IRQHandler(void)
    {
            uint8_t interrupt_status, line_status;
            uint8_t *ptr;
    
            interrupt_status = 0x07 & (LPC_UART0->IIR >> 1);
    
            if(interrupt_status == UART_RDA)
            {
                    ptr = calloc(1,sizeof(uint8_t));
                    *ptr = LPC_UART0->RBR && READ_1BYTE;
    
                    isr_evt_set(EVT_UART0, TID_IRQHandler);
                    isr_mbx_send(MSG_UART0, ptr);
            }
    
            if(interrupt_status == UART_THRE)
            {
                    line_status = LPC_UART0->LSR;
            }
    
    }
    

    the allocated memory is freed [using free()] in the task where it receives the message.

Reply
  • void UART0_IRQHandler(void)
    {
            uint8_t interrupt_status, line_status;
            uint8_t *ptr;
    
            interrupt_status = 0x07 & (LPC_UART0->IIR >> 1);
    
            if(interrupt_status == UART_RDA)
            {
                    ptr = calloc(1,sizeof(uint8_t));
                    *ptr = LPC_UART0->RBR && READ_1BYTE;
    
                    isr_evt_set(EVT_UART0, TID_IRQHandler);
                    isr_mbx_send(MSG_UART0, ptr);
            }
    
            if(interrupt_status == UART_THRE)
            {
                    line_status = LPC_UART0->LSR;
            }
    
    }
    

    the allocated memory is freed [using free()] in the task where it receives the message.

Children
  • Are you sure you can call calloc from within an interrupt service routine?

  • I haven't come across any article that talks about dynamic memory allocation, (and hence calloc, malloc) in the ISR. Will study these functions in more detail.

    But then, Per had suggested doing 1 byte transfer without allocating memory.

    Kindly refer to " sending single characters from a UART ISR doesn't require you to allocate any memory for a mailbox" post and let me know whats wrong in the implementation.

  • Allocating 1-byte memory blocks?

    And allocating using a traditional heap implementation in an ISR?

    And allocating without checking if you got any memory block or not?

    Lots of bad things to think twice about. 1 byte is the smallest addressable object (unless playing with 8051 chips or similar that happens to have bit objects). So why use a 4 byte pointer to point at a (probably 32 byte large with book-keeping information and rounded to a suitable minimum block size) memory block containing a single character received from the UART? Does it sound like a good transport mechanism? If this is a 32-bit ARM processor, that pointer was already 4 bytes - four times larger than the character you received from the UART. Doesn't that make you think about the possibilities? Sometimes pointer abuse isn't really abuse but the only practical route.