1 /**
2 * @file os_queue.h
3 * @author ALLWINNERTECH IOT WLAN Team
4 */
5
6 /*
7 * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the
17 * distribution.
18 * 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #ifndef _KERNEL_OS_FREERTOS_OS_QUEUE_H_
36 #define _KERNEL_OS_FREERTOS_OS_QUEUE_H_
37
38 #include "_os_common.h"
39 #include "queue.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /**
46 * @brief Queue object definition
47 */
48 typedef struct OS_Queue {
49 QueueHandle_t handle;
50 } OS_Queue_t;
51
52 OS_Status OS_QueueCreate(OS_Queue_t *queue, uint32_t queueLen, uint32_t itemSize);
53 OS_Status OS_QueueDelete(OS_Queue_t *queue);
54 OS_Status OS_QueueSend(OS_Queue_t *queue, const void *item, OS_Time_t waitMS);
55 OS_Status OS_QueueReceive(OS_Queue_t *queue, void *item, OS_Time_t waitMS);
56
57 /**
58 * @brief Check whether the queue object is valid or not
59 * @param[in] queue Pointer to the queue object
60 * @return 1 on valid, 0 on invalid
61 */
OS_QueueIsValid(OS_Queue_t * queue)62 static __always_inline int OS_QueueIsValid(OS_Queue_t *queue)
63 {
64 return (queue->handle != OS_INVALID_HANDLE);
65 }
66
67 /**
68 * @brief Set the queue object to invalid state
69 * @param[in] queue Pointer to the queue object
70 * @return None
71 */
OS_QueueSetInvalid(OS_Queue_t * queue)72 static __always_inline void OS_QueueSetInvalid(OS_Queue_t *queue)
73 {
74 queue->handle = OS_INVALID_HANDLE;
75 }
76
77 /**
78 * @brief Create and initialize a message queue object
79 * @note A message queue is a queue with each data item can store a pointer.
80 * The size of each data item (message) is equal to sizeof(void *).
81 * @param[in] queue Pointer to the message queue object
82 * @param[in] queueLen The maximum number of items that the message queue can
83 * hold at any one time.
84 * @retval OS_Status, OS_OK on success
85 */
OS_MsgQueueCreate(OS_Queue_t * queue,uint32_t queueLen)86 static __always_inline OS_Status OS_MsgQueueCreate(OS_Queue_t *queue, uint32_t queueLen)
87 {
88 return OS_QueueCreate(queue, queueLen, sizeof(void *));
89 }
90
91 /**
92 * @brief Delete the message queue object
93 * @param[in] queue Pointer to the message queue object
94 * @retval OS_Status, OS_OK on success
95 */
OS_MsgQueueDelete(OS_Queue_t * queue)96 static __always_inline OS_Status OS_MsgQueueDelete(OS_Queue_t *queue)
97 {
98 return OS_QueueDelete(queue);
99 }
100
101 /**
102 * @brief Send (write) a message to the back of the message queue
103 * @param[in] queue Pointer to the message queue object
104 * @param[in] msg A message, which is a pointer, to be copied into the queue
105 * @param[in] waitMS The maximum amount of time the thread should remain in the
106 * blocked state to wait for space to become available on the
107 * message queue, should the message queue already be full.
108 * OS_WAIT_FOREVER for waiting forever, zero for no waiting.
109 * @retval OS_Status, OS_OK on success
110 */
OS_MsgQueueSend(OS_Queue_t * queue,void * msg,OS_Time_t waitMS)111 static __always_inline OS_Status OS_MsgQueueSend(OS_Queue_t *queue, void *msg, OS_Time_t waitMS)
112 {
113 return OS_QueueSend(queue, &msg, waitMS);
114 }
115
116 /**
117 * @brief Receive (read) a message from the message queue
118 * @param[in] queue Pointer to the message queue object
119 * @param[in] msg Pointer to the message buffer into which the received message
120 * will be copied. A message is a pointer.
121 * @param[in] waitMS The maximum amount of time the thread should remain in the
122 * blocked state to wait for message to become available on
123 * the message queue, should the message queue already be
124 * empty.
125 * OS_WAIT_FOREVER for waiting forever, zero for no waiting.
126 * @retval OS_Status, OS_OK on success
127 */
OS_MsgQueueReceive(OS_Queue_t * queue,void ** msg,OS_Time_t waitMS)128 static __always_inline OS_Status OS_MsgQueueReceive(OS_Queue_t *queue, void **msg, OS_Time_t waitMS)
129 {
130 return OS_QueueReceive(queue, msg, waitMS);
131 }
132
133 #ifdef __cplusplus
134 }
135 #endif
136
137 #endif /* _KERNEL_OS_FREERTOS_OS_QUEUE_H_ */
138