4575 views|0 replies

336

Posts

2

Resources
The OP
 

[RT-Thread Reading Notes] Part 2 (2) Message Queues and Mailboxes [Copy link]

  This post was last edited by I Love Download on 2019-5-6 10:59
Here we will look at message queues and mailboxes together, because their mechanisms are similar, the only difference is the size of the content they carry.
Comparison between message queues and mailboxes:
1) The size of the message carried by the message queue is uncertain, it can be large or small according to the needs, while the mailbox is fixed to a 4-byte payload; therefore, the book introduces that mailboxes are a more efficient way of information transmission.
2) They are both commonly used IPC communication methods, which can be applied to communication between threads, interrupts and threads. 3) Information can be sent but not received in the interruption; The message queue is a buffer for flexible and fast message transmission in the operating system, and the content of the message transmission is relatively flexible. Chapter 18 focuses on the blocking mechanism, implementation method, and application method of the message queue. Regarding the message queue, I personally think that the following points are worth paying attention to: 1) Application scenario: Mainly used for sending messages of indefinite length, including message exchange between threads and message sending in interrupt service programs (specially pointed out that message reception cannot be used in interruption); 2) When using functions such as rt_ma_recv(), rt_mq_send(), and rt_mq_delete(), you must first create a message queue and operate according to the queue handle.
3) The queue can adopt FIFO mode and provide an emergency message mechanism to improve the real-time performance of the system.
4) When executing the rt_mq_recv() function, you must first apply for a buffer for message storage and pass the first address as a parameter to the function, otherwise an illegal address error will occur.
5) When receiving messages, the size of the buffer used to store messages must be larger than the size of the messages in the queue.
Mailboxes are used as efficient and fast information transmission in the operating system, reflecting the flexibility and efficiency of mailboxes.
The content of Chapter 23 focuses on the mailbox operation mechanism, implementation method, and application skills.
Regarding the mailbox, it is worth noting that
1) Application scenario: mainly used for fixed information (4 bytes) transmission, including between threads and in interrupt service routines;
2) When using functions such as rt_mb_recv(), rt_mb_send_wait(), rt_mb_send (), rt_mb_delete(), you must first create the mailbox rt_mb_create() and operate according to the mailbox handle.
3) The mailbox can use FIFO mode or priority queuing mode, and support asynchronous reading and writing.
4) Both sending and receiving emails support timeout processing.
5) Support one-to-many or many-to-one operation mode.
6) The book specifically mentions the use of mailboxes. Although the payload of a mailbox can only be 4 bytes, on 32-bit systems such as stm32, it can just pass a 32-bit pointer information, thus expanding the content of mailbox transmission while still being efficient.
This content was originally created by EEWORLD forum user I Love Download. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source.
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list