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

Continuation of thread 22624....application of mailbox

hey guys,
after a lot of guidance & iterations, i a code that typecast the data as pointer and pass it via mailbox.
all was well upto one year. but yesterday, while testing, i found out that i receive a 0x00 from uart, which i dnt get into my rx_buf.

Just wanted to bring into notice this cautionary remark.

Parents
  • The mailbox functions are just designed to distribute a pointer between sender and receiver. They don't care about the contents of the pointer.

    When you move large data, then you have some form of array or pool of mails of a suitable type and send the pointer to that mail. And the receiver releases the mail back to the pool to be reused.

    But a character is so small that it fits in the memory needed for a pointer. So the program do not need to invest in a pool of "character mails" and have the sender allocate a "character mail" and send the pointer to this single-character mail. And the receiver need not pick up a pointer to a one-character mail, process the single character and then release this single-character mail back to the pool. One important thing here is that allocating and releasing mails from the memory pool requires a lock mechanism which adds to the amount of work needed.

    In short - you get a bit smaller code that consumes less memory and less CPU time. This obviously assuming that the UART sends one character at a time.

    If using the FIFO functionality of the UART, then it might be more efficient to actually use a pool of mails - but each mail being able to store a character count, and multiple characters - maybe as many as one FIFO length. So the UART can allocate a single mail, and then clear out the receive FIFO and then post this single mail with maybe 1-16 characters.

    In the end, it's a question of figuring out what is best matching the program needs. There are seldom just one possible solution.

Reply
  • The mailbox functions are just designed to distribute a pointer between sender and receiver. They don't care about the contents of the pointer.

    When you move large data, then you have some form of array or pool of mails of a suitable type and send the pointer to that mail. And the receiver releases the mail back to the pool to be reused.

    But a character is so small that it fits in the memory needed for a pointer. So the program do not need to invest in a pool of "character mails" and have the sender allocate a "character mail" and send the pointer to this single-character mail. And the receiver need not pick up a pointer to a one-character mail, process the single character and then release this single-character mail back to the pool. One important thing here is that allocating and releasing mails from the memory pool requires a lock mechanism which adds to the amount of work needed.

    In short - you get a bit smaller code that consumes less memory and less CPU time. This obviously assuming that the UART sends one character at a time.

    If using the FIFO functionality of the UART, then it might be more efficient to actually use a pool of mails - but each mail being able to store a character count, and multiple characters - maybe as many as one FIFO length. So the UART can allocate a single mail, and then clear out the receive FIFO and then post this single mail with maybe 1-16 characters.

    In the end, it's a question of figuring out what is best matching the program needs. There are seldom just one possible solution.

Children
No data