1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: OS Abstract Layer. 15 */ 16 17 /** 18 * @defgroup osal_msgqueue osal_msgqueue 19 */ 20 #ifndef __OSAL_MSGQUEUE_H__ 21 #define __OSAL_MSGQUEUE_H__ 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 #ifdef LOS_WAIT_FOREVER 30 #define OSAL_MSGQ_WAIT_FOREVER LOS_WAIT_FOREVER 31 #else 32 #define OSAL_MSGQ_WAIT_FOREVER 0xFFFFFFFF 33 #endif 34 35 #ifdef LOS_NO_WAIT 36 #define OSAL_MSGQ_NO_WAIT LOS_NO_WAIT 37 #else 38 #define OSAL_MSGQ_NO_WAIT 0 39 #endif 40 41 /** 42 * @ingroup osal_msgqueue 43 * @brief Create a message queue. 44 * 45 * @par Description: 46 * This API is used to create a message queue. 47 * 48 * @attention 49 * There are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessary. 50 * This function is defined only when LOSCFG_QUEUE_DYNAMIC_ALLOCATION is defined. 51 * The input parameter queue_id is used as an address in the FreeRtos system, 52 * and the input parameter queue_id is used as an integer in the LiteOS system. 53 * parameter queue_id is created by osal_msg_queue_create. 54 * 55 * @param name [in] Message queue name. Reserved parameter, not used for now. 56 * @param queue_len [in] Queue length. The value range is [1,0xffff]. 57 * @param queue_id [out] ID of the queue control structure that is successfully created. 58 * @param flags [in] Queue mode. Reserved parameter, not used for now. 59 * @param max_msgsize [in] Node size. The value range is [1,0xffff]. 60 * 61 * @return OSAL_SUCCESS/OSAL_FAILURE 62 * 63 * @par Support System: 64 * liteos freertos. 65 */ 66 int osal_msg_queue_create(const char *name, unsigned short queue_len, unsigned long *queue_id, unsigned int flags, 67 unsigned short max_msgsize); 68 69 /** 70 * @ingroup osal_msgqueue 71 * @brief Write data into a queue. 72 * 73 * @par Description: 74 * This API is used to write the data of the size specified by buffer_size and stored at the address specified by 75 * buffer_addr into a queue. 76 * 77 * @attention 78 * The specific queue should be created firstly. 79 * Do not read or write a queue in unblocking modes such as interrupt. 80 * This API cannot be called before the LiteOS is initialized. 81 * The data to be written is of the size specified by buffer_size and is stored at the address specified by buffer_addr. 82 * The argument timeout is a relative time. 83 * Do not call this API in software timer callback. 84 * The buffer_size parameter is not used in the freertos system and 85 * buffer length depends on the size transferred during creation. 86 * The input parameter queue_id is used as an address in the FreeRtos system, 87 * and the input parameter queue_id is used as an integer in the LiteOS system. 88 * parameter queue_id is created by osal_msg_queue_create. 89 * 90 * @param queue_id [in] Queue ID created by osal_msg_queue_create. 91 * @param buffer_addr [in] Starting address that stores the data to be written. 92 * The starting address must not be null. 93 * @param buffer_size [in] Passed-in buffer size. 94 * @param timeout [in] Expiry time. (unit: Tick). 95 * 96 * @return OSAL_SUCCESS/OSAL_FAILURE 97 * 98 * @par Support System: 99 * liteos freertos 100 * @par System Differ: The bufferSize of freertos does not support read/write of a specified size, 101 * only supports full storage and rounding. 102 */ 103 int osal_msg_queue_write_copy(unsigned long queue_id, void *buffer_addr, unsigned int buffer_size, 104 unsigned int timeout); 105 106 /** 107 * @ingroup osal_msgqueue 108 * @brief Read a queue. 109 * 110 * @par Description: 111 * This API is used to read data in a specified queue, and store the obtained data to the address specified 112 * by buffer_addr. The address and the size of the data to be read are defined by users. 113 * 114 * @attention 115 * The specific queue should be created firstly. 116 * Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is read first. 117 * buffer_addr stores the obtained data. 118 * Do not read or write a queue in unblocking modes such as an interrupt. 119 * This API cannot be called before the LiteOS is initialized. 120 * The argument timeout is a relative time. 121 * Do not call this API in software timer callback. 122 * The buffer_size parameter is not used in the freertos system and 123 * buffer length depends on the size transferred during creation. 124 * The input parameter queue_id is used as an address in the FreeRtos system, 125 * and the input parameter queue_id is used as an integer in the LiteOS system. 126 * parameter queue_id is created by osal_msg_queue_create. 127 * 128 * @param queue_id [in] Queue ID created by osal_msg_queue_create. 129 * @param buffer_addr [out] Starting address that stores the data to be written. 130 * The starting address must not be null. 131 * @param buffer_size [in/out] Where to maintain the buffer wanted-size before read, and the real-size after read. 132 * @param timeout [in] Expiry time. (unit: Tick). 133 * 134 * @return OSAL_SUCCESS/OSAL_FAILURE 135 * 136 * @par Support System: 137 * liteos freertos 138 * @par System Differ: The bufferSize of freertos does not support read/write of a specified size, 139 * only supports full storage and rounding. 140 */ 141 int osal_msg_queue_read_copy(unsigned long queue_id, void *buffer_addr, unsigned int *buffer_size, 142 unsigned int timeout); 143 144 /** 145 * @ingroup osal_msgqueue 146 * @brief Write data into a queue header. 147 * 148 * @par Description: 149 * This API is used to write the data of the size specified by bufferSize and stored at the address specified by 150 * buffer_addr into a queue header. 151 * 152 * @attention 153 * Do not read or write a queue in unblocking modes such as an interrupt. 154 * This API cannot be called before the LiteOS is initialized. 155 * The address of the data of the size specified by bufferSize and stored at the address specified 156 * by bufferAddr is to be written. 157 * The argument timeout is a relative time. 158 * Do not call this API in software timer callback. 159 * The buffer_size parameter is not used in the freertos system and 160 * buffer length depends on the size transferred during creation. 161 * The input parameter queue_id is used as an address in the FreeRtos system, 162 * and the input parameter queue_id is used as an integer in the LiteOS system. 163 * parameter queue_id is created by osal_msg_queue_create. 164 * 165 * @param queue_id [in] Queue ID created by osal_msg_queue_create. 166 * @param buffer_addr [out] Starting address that stores the data to be written. 167 * The starting address must not be null. 168 * @param buffer_size [in] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff]. 169 * @param timeout [in] Expiry time. (unit: Tick). 170 * 171 * @return OSAL_SUCCESS/OSAL_FAILURE 172 * 173 * @par Support System: 174 * liteos freertos 175 * @par System Differ: The bufferSize of freertos does not support read/write of a specified size, 176 * only supports full storage and rounding. 177 */ 178 int osal_msg_queue_write_head_copy(unsigned long queue_id, void *buffer_addr, unsigned int buffer_size, 179 unsigned int timeout); 180 181 /** 182 * @ingroup osal_msgqueue 183 * @brief Delete a queue. 184 * 185 * @par Description: 186 * This API is used to delete a queue. 187 * 188 * @attention 189 * This API cannot be used to delete a queue that is not created. 190 * A synchronous queue fails to be deleted if any tasks are blocked on it, or some queues are being read or written. 191 * The input parameter queue_id is used as an address in the FreeRtos system, 192 * and the input parameter queue_id is used as an integer in the LiteOS system. 193 * parameter queue_id is created by osal_msg_queue_create. 194 * 195 * @param queue_id [in] Queue ID created by osal_msg_queue_create.. 196 * 197 * @par Support System: 198 * liteos freertos 199 */ 200 void osal_msg_queue_delete(unsigned long queue_id); 201 202 /** 203 * @ingroup osal_msgqueue 204 * @brief Check whether the message queue is full. 205 * 206 * @par Description: 207 * This API is used to check whether the message queue is full. 208 * 209 * @attention 210 * The specific queue should be created firstly. 211 * The input parameter queue_id is used as an address in the FreeRtos system, 212 * and the input parameter queue_id is used as an integer in the LiteOS system. 213 * parameter queue_id is created by osal_msg_queue_create. 214 * 215 * @param queue_id [in] Queue ID created by osal_msg_queue_create. 216 * 217 * @return true/false 218 * 219 * @par Support System: 220 * liteos freertos 221 */ 222 int osal_msg_queue_is_full(unsigned long queue_id); 223 224 /** 225 * @ingroup osal_msgqueue 226 * @brief Obtains the number of messages in the current message queue. 227 * 228 * @par Description: 229 * This API is used to obtains the number of messages in the current message queue. 230 * 231 * @attention 232 * The input parameter queue_id is used as an address in the FreeRtos system, 233 * and the input parameter queue_id is used as an integer in the LiteOS system. 234 * parameter queue_id is created by osal_msg_queue_create. 235 * 236 * @param queue_id [in] Queue ID created by osal_msg_queue_create 237 * 238 * @return The number of messages in the current message queue. or OSAL_INVALID_MSG_NUM when get number failed. 239 * 240 * @par Support System: 241 * liteos freertos 242 */ 243 unsigned int osal_msg_queue_get_msg_num(unsigned long queue_id); 244 245 #ifdef __cplusplus 246 #if __cplusplus 247 } 248 #endif 249 #endif 250 #endif /* __OSAL_MSGQUEUE_H__ */ 251