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
  • "Mailbox is a method of transferring data;(& as per what i have understood) the data can be transferred only by allocating it some memory temperorily, right?"¨

    Why do you ask this question, when you already have working code that sends the data using the pointer instead of allocating any memory for the pointer to point to? Haven't you already the answer to the question then? And I have also several times in previous posts covered the use of the pointer itself when the data you need to transfer is small enough that it fits in the pointer.

    Next thing - programs normally send mails of a single type to a single mailbox. So one mailbox for data from that serial port. Another mailbox if receiving CAN message. So the receiving end knows what to do with the mail based on which mailbox it was picked up from.

    Another alternative is to always tag each mail with a type. In the case of sending UART data in the pointer, you know that the data is 8 bit large. While the pointer is 32 bits. So 24 bits free for other information.

    Like:

    0x000000xx - received byte from UART0
    0x000001xx - received byte from UART0, but with parity error
    0x00000200 - framing error on UART0
    ...

    Another solution here is to not use the mailbox at all, in case the receiving end wants to listen to lots of events. It works just as well to use a standard circular buffer for the received data. So the ISR inserts received bytes into the circular buffer and then sents an event signalling "At least one character received and available from UART0". The receiving end can then listen for many different event flags, and based on found flags decide what action to perform.

    There are always many ways to skin a cat. The main goal is to not make everything too complex or too costly. Thinking about dynamic memory allocations inside the interrupt handler is a costly route.

    By the way - why do you always want to use non-descriptive variable names? Now you have renamed your mailbox to just "MailBox", removing that reference to UART0.

    And you have both an ISR and a task that both contains the name IRQHandler. With a name TASK_IRQHandler you are sending out a very mixed message if it is a task, or if it is an ISR.

    Next thing - why do you do "& READ_1BYTE" both before sending your mail and after having received the mail? Never perform code actions without knowing exactly what the line does and exactly why you need it.

Reply
  • "Mailbox is a method of transferring data;(& as per what i have understood) the data can be transferred only by allocating it some memory temperorily, right?"¨

    Why do you ask this question, when you already have working code that sends the data using the pointer instead of allocating any memory for the pointer to point to? Haven't you already the answer to the question then? And I have also several times in previous posts covered the use of the pointer itself when the data you need to transfer is small enough that it fits in the pointer.

    Next thing - programs normally send mails of a single type to a single mailbox. So one mailbox for data from that serial port. Another mailbox if receiving CAN message. So the receiving end knows what to do with the mail based on which mailbox it was picked up from.

    Another alternative is to always tag each mail with a type. In the case of sending UART data in the pointer, you know that the data is 8 bit large. While the pointer is 32 bits. So 24 bits free for other information.

    Like:

    0x000000xx - received byte from UART0
    0x000001xx - received byte from UART0, but with parity error
    0x00000200 - framing error on UART0
    ...

    Another solution here is to not use the mailbox at all, in case the receiving end wants to listen to lots of events. It works just as well to use a standard circular buffer for the received data. So the ISR inserts received bytes into the circular buffer and then sents an event signalling "At least one character received and available from UART0". The receiving end can then listen for many different event flags, and based on found flags decide what action to perform.

    There are always many ways to skin a cat. The main goal is to not make everything too complex or too costly. Thinking about dynamic memory allocations inside the interrupt handler is a costly route.

    By the way - why do you always want to use non-descriptive variable names? Now you have renamed your mailbox to just "MailBox", removing that reference to UART0.

    And you have both an ISR and a task that both contains the name IRQHandler. With a name TASK_IRQHandler you are sending out a very mixed message if it is a task, or if it is an ISR.

    Next thing - why do you do "& READ_1BYTE" both before sending your mail and after having received the mail? Never perform code actions without knowing exactly what the line does and exactly why you need it.

Children
No data