unified: Tweak msgq API parameters
- Reorders parameters where necessary - Adds alignment parameter to K_MSGQ_DEFINE() for buffer alignment - Renames parameters where necessary so they are more intuitive Change-Id: I0b53105c04109127897bf4790e6908082f82da4e Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
This commit is contained in:
parent
67be24909d
commit
1da807e7a8
5 changed files with 36 additions and 19 deletions
|
@ -73,10 +73,10 @@ that is capable of holding 10 items.
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
||||||
char my_msgq_buffer[10 * sizeof(data_item_type)];
|
char __aligned(4) my_msgq_buffer[10 * sizeof(data_item_type)];
|
||||||
struct k_msgq my_msgq;
|
struct k_msgq my_msgq;
|
||||||
|
|
||||||
k_msgq_init(&my_msgq, 10, sizeof(data_item_type), my_msgq_buffer);
|
k_msgq_init(&my_msgq, my_msgq_buffer, sizeof(data_item_type), 10);
|
||||||
|
|
||||||
Alternatively, a message queue can be defined and initialized at compile time
|
Alternatively, a message queue can be defined and initialized at compile time
|
||||||
by calling :c:macro:`K_MSGQ_DEFINE()`.
|
by calling :c:macro:`K_MSGQ_DEFINE()`.
|
||||||
|
@ -86,7 +86,7 @@ that the macro defines both the message queue and its buffer.
|
||||||
|
|
||||||
.. code-block:: c
|
.. code-block:: c
|
||||||
|
|
||||||
K_MSGQ_DEFINE(my_msgq, 10, sizeof(data_item_type));
|
K_MSGQ_DEFINE(my_msgq, sizeof(data_item_type), 10, 4);
|
||||||
|
|
||||||
Writing to a Message Queue
|
Writing to a Message Queue
|
||||||
==========================
|
==========================
|
||||||
|
|
|
@ -856,26 +856,43 @@ struct k_msgq {
|
||||||
_DEBUG_TRACING_KERNEL_OBJECTS_NEXT_PTR(k_msgq);
|
_DEBUG_TRACING_KERNEL_OBJECTS_NEXT_PTR(k_msgq);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define K_MSGQ_INITIALIZER(obj, q_depth, q_width, q_buffer) \
|
#define K_MSGQ_INITIALIZER(obj, q_buffer, q_msg_size, q_max_msgs) \
|
||||||
{ \
|
{ \
|
||||||
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
|
.wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \
|
||||||
.max_msgs = q_depth, \
|
.max_msgs = q_max_msgs, \
|
||||||
.msg_size = q_width, \
|
.msg_size = q_msg_size, \
|
||||||
.buffer_start = q_buffer, \
|
.buffer_start = q_buffer, \
|
||||||
.buffer_end = q_buffer + (q_depth * q_width), \
|
.buffer_end = q_buffer + (q_max_msgs * q_msg_size), \
|
||||||
.read_ptr = q_buffer, \
|
.read_ptr = q_buffer, \
|
||||||
.write_ptr = q_buffer, \
|
.write_ptr = q_buffer, \
|
||||||
.used_msgs = 0, \
|
.used_msgs = 0, \
|
||||||
_DEBUG_TRACING_KERNEL_OBJECTS_INIT \
|
_DEBUG_TRACING_KERNEL_OBJECTS_INIT \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define K_MSGQ_DEFINE(name, q_depth, q_width) \
|
/**
|
||||||
static char __noinit _k_fifo_buf_##name[(q_depth) * (q_width)]; \
|
* @brief Define a message queue
|
||||||
struct k_msgq name = \
|
*
|
||||||
K_MSGQ_INITIALIZER(name, q_depth, q_width, _k_fifo_buf_##name)
|
* This declares and initializes a message queue whose buffer is aligned to
|
||||||
|
* a @a q_align -byte boundary. The new message queue can be passed to the
|
||||||
|
* kernel's message queue functions.
|
||||||
|
*
|
||||||
|
* Note that for each of the mesages in the message queue to be aligned to
|
||||||
|
* @a q_align bytes, then @a q_msg_size must be a multiple of @a q_align.
|
||||||
|
*
|
||||||
|
* @param q_name Name of the message queue
|
||||||
|
* @param q_msg_size The size in bytes of each message
|
||||||
|
* @param q_max_msgs Maximum number of messages the queue can hold
|
||||||
|
* @param q_align Alignment of the message queue's buffer (power of 2)
|
||||||
|
*/
|
||||||
|
#define K_MSGQ_DEFINE(q_name, q_msg_size, q_max_msgs, q_align) \
|
||||||
|
static char __noinit __aligned(q_align) \
|
||||||
|
_k_fifo_buf_##q_name[(q_max_msgs) * (q_msg_size)]; \
|
||||||
|
struct k_msgq q_name = \
|
||||||
|
K_MSGQ_INITIALIZER(q_name, _k_fifo_buf_##q_name, \
|
||||||
|
q_msg_size, q_max_msgs)
|
||||||
|
|
||||||
extern void k_msgq_init(struct k_msgq *q, uint32_t msg_size,
|
extern void k_msgq_init(struct k_msgq *q, char *buffer,
|
||||||
uint32_t max_msgs, char *buffer);
|
uint32_t msg_size, uint32_t max_msgs);
|
||||||
extern int k_msgq_put(struct k_msgq *q, void *data, int32_t timeout);
|
extern int k_msgq_put(struct k_msgq *q, void *data, int32_t timeout);
|
||||||
extern int k_msgq_get(struct k_msgq *q, void *data, int32_t timeout);
|
extern int k_msgq_get(struct k_msgq *q, void *data, int32_t timeout);
|
||||||
extern void k_msgq_purge(struct k_msgq *q);
|
extern void k_msgq_purge(struct k_msgq *q);
|
||||||
|
|
|
@ -445,7 +445,7 @@ static inline int task_fifo_size_get(kfifo_t queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_FIFO(name, q_depth, q_width) \
|
#define DEFINE_FIFO(name, q_depth, q_width) \
|
||||||
K_MSGQ_DEFINE(_k_fifo_obj_##name, q_depth, q_width); \
|
K_MSGQ_DEFINE(_k_fifo_obj_##name, q_width, q_depth, 4); \
|
||||||
struct k_msgq * const name = &_k_fifo_obj_##name
|
struct k_msgq * const name = &_k_fifo_obj_##name
|
||||||
|
|
||||||
/* mailboxes */
|
/* mailboxes */
|
||||||
|
|
|
@ -33,14 +33,14 @@
|
||||||
* @brief Initialize a message queue.
|
* @brief Initialize a message queue.
|
||||||
*
|
*
|
||||||
* @param q Pointer to the message queue object.
|
* @param q Pointer to the message queue object.
|
||||||
|
* @param buffer Pointer to memory area that holds queued messages.
|
||||||
* @param msg_size Message size, in bytes.
|
* @param msg_size Message size, in bytes.
|
||||||
* @param max_msgs Maximum number of messages that can be queued.
|
* @param max_msgs Maximum number of messages that can be queued.
|
||||||
* @param buffer Pointer to memory area that holds queued messages.
|
|
||||||
*
|
*
|
||||||
* @return N/A
|
* @return N/A
|
||||||
*/
|
*/
|
||||||
void k_msgq_init(struct k_msgq *q, uint32_t msg_size, uint32_t max_msgs,
|
void k_msgq_init(struct k_msgq *q, char *buffer,
|
||||||
char *buffer)
|
uint32_t msg_size, uint32_t max_msgs)
|
||||||
{
|
{
|
||||||
q->msg_size = msg_size;
|
q->msg_size = msg_size;
|
||||||
q->max_msgs = max_msgs;
|
q->max_msgs = max_msgs;
|
||||||
|
|
|
@ -684,8 +684,8 @@ def kernel_main_c_fifos():
|
||||||
name = fifo[0]
|
name = fifo[0]
|
||||||
depth = fifo[1]
|
depth = fifo[1]
|
||||||
width = fifo[2]
|
width = fifo[2]
|
||||||
kernel_main_c_out("K_MSGQ_DEFINE(_k_fifo_obj_%s, %s, %s);\n" %
|
kernel_main_c_out("K_MSGQ_DEFINE(_k_fifo_obj_%s, %s, %s, 4);\n" %
|
||||||
(name, depth, width))
|
(name, width, depth))
|
||||||
|
|
||||||
|
|
||||||
def kernel_main_c_pipes():
|
def kernel_main_c_pipes():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue