Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
|
Data Structures | |
struct | k_msgq |
Message Queue Structure. More... | |
struct | k_msgq_attrs |
Message Queue Attributes. More... | |
Macros | |
#define | K_MSGQ_FLAG_ALLOC BIT(0) |
#define | K_MSGQ_DEFINE(q_name, q_msg_size, q_max_msgs, q_align) |
Statically define and initialize a message queue. | |
Functions | |
void | k_msgq_init (struct k_msgq *msgq, char *buffer, size_t msg_size, uint32_t max_msgs) |
Initialize a message queue. | |
int | k_msgq_alloc_init (struct k_msgq *msgq, size_t msg_size, uint32_t max_msgs) |
Initialize a message queue. | |
int | k_msgq_cleanup (struct k_msgq *msgq) |
Release allocated buffer for a queue. | |
int | k_msgq_put (struct k_msgq *msgq, const void *data, k_timeout_t timeout) |
Send a message to a message queue. | |
int | k_msgq_get (struct k_msgq *msgq, void *data, k_timeout_t timeout) |
Receive a message from a message queue. | |
int | k_msgq_peek (struct k_msgq *msgq, void *data) |
Peek/read a message from a message queue. | |
int | k_msgq_peek_at (struct k_msgq *msgq, void *data, uint32_t idx) |
Peek/read a message from a message queue at the specified index. | |
void | k_msgq_purge (struct k_msgq *msgq) |
Purge a message queue. | |
uint32_t | k_msgq_num_free_get (struct k_msgq *msgq) |
Get the amount of free space in a message queue. | |
void | k_msgq_get_attrs (struct k_msgq *msgq, struct k_msgq_attrs *attrs) |
Get basic attributes of a message queue. | |
uint32_t | k_msgq_num_used_get (struct k_msgq *msgq) |
Get the number of messages in a message queue. | |
#define K_MSGQ_DEFINE | ( | q_name, | |
q_msg_size, | |||
q_max_msgs, | |||
q_align ) |
#include <zephyr/kernel.h>
Statically define and initialize a message queue.
The message queue's ring buffer contains space for q_max_msgs messages, each of which is q_msg_size bytes long. Alignment of the message queue's ring buffer is not necessary, setting q_align to 1 is sufficient.
The message queue can be accessed outside the module where it is defined using:
q_name | Name of the message queue. |
q_msg_size | Message size (in bytes). |
q_max_msgs | Maximum number of messages that can be queued. |
q_align | Alignment of the message queue's ring buffer (power of 2). |
#define K_MSGQ_FLAG_ALLOC BIT(0) |
#include <zephyr/kernel.h>
#include <zephyr/kernel.h>
Initialize a message queue.
This routine initializes a message queue object, prior to its first use, allocating its internal ring buffer from the calling thread's resource pool.
Memory allocated for the ring buffer can be released by calling k_msgq_cleanup(), or if userspace is enabled and the msgq object loses all of its references.
msgq | Address of the message queue. |
msg_size | Message size (in bytes). |
max_msgs | Maximum number of messages that can be queued. |
int k_msgq_cleanup | ( | struct k_msgq * | msgq | ) |
#include <zephyr/kernel.h>
Release allocated buffer for a queue.
Releases memory allocated for the ring buffer.
msgq | message queue to cleanup |
0 | on success |
-EBUSY | Queue not empty |
|
isr-ok |
#include <zephyr/kernel.h>
Receive a message from a message queue.
This routine receives a message from message queue q in a "first in, first out" manner.
msgq | Address of the message queue. |
data | Address of area to hold the received message. |
timeout | Waiting period to receive the message, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Message received. |
-ENOMSG | Returned without waiting or queue purged. |
-EAGAIN | Waiting period timed out. |
void k_msgq_get_attrs | ( | struct k_msgq * | msgq, |
struct k_msgq_attrs * | attrs ) |
#include <zephyr/kernel.h>
Get basic attributes of a message queue.
This routine fetches basic attributes of message queue into attr argument.
msgq | Address of the message queue. |
attrs | pointer to message queue attribute structure. |
#include <zephyr/kernel.h>
Initialize a message queue.
This routine initializes a message queue object, prior to its first use.
The message queue's ring buffer must contain space for max_msgs messages, each of which is msg_size bytes long. Alignment of the message queue's ring buffer is not necessary.
msgq | Address of the message queue. |
buffer | Pointer to ring buffer that holds queued messages. |
msg_size | Message size (in bytes). |
max_msgs | Maximum number of messages that can be queued. |
#include <zephyr/kernel.h>
Get the amount of free space in a message queue.
This routine returns the number of unused entries in a message queue's ring buffer.
msgq | Address of the message queue. |
#include <zephyr/kernel.h>
Get the number of messages in a message queue.
This routine returns the number of messages in a message queue's ring buffer.
msgq | Address of the message queue. |
|
isr-ok |
#include <zephyr/kernel.h>
Peek/read a message from a message queue.
This routine reads a message from message queue q in a "first in, first out" manner and leaves the message in the queue.
msgq | Address of the message queue. |
data | Address of area to hold the message read from the queue. |
0 | Message read. |
-ENOMSG | Returned when the queue has no message. |
#include <zephyr/kernel.h>
Peek/read a message from a message queue at the specified index.
This routine reads a message from message queue at the specified index and leaves the message in the queue. k_msgq_peek_at(msgq, data, 0) is equivalent to k_msgq_peek(msgq, data)
msgq | Address of the message queue. |
data | Address of area to hold the message read from the queue. |
idx | Message queue index at which to peek |
0 | Message read. |
-ENOMSG | Returned when the queue has no message at index. |
void k_msgq_purge | ( | struct k_msgq * | msgq | ) |
#include <zephyr/kernel.h>
Purge a message queue.
This routine discards all unreceived messages in a message queue's ring buffer. Any threads that are blocked waiting to send a message to the message queue are unblocked and see an -ENOMSG error code.
msgq | Address of the message queue. |
|
isr-ok |
#include <zephyr/kernel.h>
Send a message to a message queue.
This routine sends a message to message queue q.
msgq | Address of the message queue. |
data | Pointer to the message. |
timeout | Waiting period to add the message, or one of the special values K_NO_WAIT and K_FOREVER. |
0 | Message sent. |
-ENOMSG | Returned without waiting or queue purged. |
-EAGAIN | Waiting period timed out. |