1 /* ---------------------------------------------------------------------------- 2 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2018. All rights reserved. 3 * Description: queue 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 1. Redistributions of source code must retain the above copyright notice, this list of 7 * conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 9 * of conditions and the following disclaimer in the documentation and/or other materials 10 * provided with the distribution. 11 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 12 * to endorse or promote products derived from this software without specific prior written 13 * permission. 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * --------------------------------------------------------------------------- */ 26 27 /** 28 * @defgroup los_queue Queue 29 * @ingroup kernel 30 */ 31 32 #ifndef _LOS_QUEUE_H 33 #define _LOS_QUEUE_H 34 35 #include "los_base.h" 36 #include "los_list.h" 37 38 #ifdef __cplusplus 39 #if __cplusplus 40 extern "C" { 41 #endif /* __cplusplus */ 42 #endif /* __cplusplus */ 43 44 /** 45 * @ingroup los_queue 46 * Queue error code: The maximum number of queue resources is configured to 0. 47 * 48 * Value: 0x02000600 49 * 50 * Solution: Configure the maximum number of queue resources to be greater than 0. If queue modules are not used, 51 * set the configuration item for the tailoring of the maximum number of queue resources to NO. 52 */ 53 #define LOS_ERRNO_QUEUE_MAXNUM_ZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x00) 54 55 /** 56 * @ingroup los_queue 57 * Queue error code: The queue block memory fails to be initialized. 58 * 59 * Value: 0x02000601 60 * 61 * Solution: Allocate the queue block bigger memory partition, or decrease the maximum number of queue resources. 62 */ 63 #define LOS_ERRNO_QUEUE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x01) 64 65 /** 66 * @ingroup los_queue 67 * Queue error code: The memory for queue creation fails to be requested. 68 * 69 * Value: 0x02000602 70 * 71 * Solution: Allocate more memory for queue creation, or decrease the queue length and the number of nodes 72 * in the queue to be created. 73 */ 74 #define LOS_ERRNO_QUEUE_CREATE_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x02) 75 76 /** 77 * @ingroup los_queue 78 * Queue error code: The size of the biggest message in the created queue is too big. 79 * 80 * Value: 0x02000603 81 * 82 * Solution: Change the size of the biggest message in the created queue. 83 */ 84 #define LOS_ERRNO_QUEUE_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x03) 85 86 /** 87 * @ingroup los_queue 88 * Queue error code: The upper limit of the number of created queues is exceeded. 89 * 90 * Value: 0x02000604 91 * 92 * Solution: Increase the configured number of resources for queues. 93 */ 94 #define LOS_ERRNO_QUEUE_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x04) 95 96 /** 97 * @ingroup los_queue 98 * Queue error code: Invalid queue. 99 * 100 * Value: 0x02000605 101 * 102 * Solution: Ensure that the passed-in queue ID is valid. 103 */ 104 #define LOS_ERRNO_QUEUE_NOT_FOUND LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x05) 105 106 /** 107 * @ingroup los_queue 108 * Queue error code: The task is forbidden to be blocked on a queue when the task is locked. 109 * 110 * Value: 0x02000606 111 * 112 * Solution: Unlock the task before using a queue. 113 */ 114 #define LOS_ERRNO_QUEUE_PEND_IN_LOCK LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x06) 115 116 /** 117 * @ingroup los_queue 118 * Queue error code: The time set for waiting to processing the queue expires. 119 * 120 * Value: 0x02000607 121 * 122 * Solution: Check whether the expiry time setting is appropriate. 123 */ 124 #define LOS_ERRNO_QUEUE_TIMEOUT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x07) 125 126 /** 127 * @ingroup los_queue 128 * Queue error code: The queue that blocks a task cannot be deleted. 129 * 130 * Value: 0x02000608 131 * 132 * Solution: Enable the task to obtain resources rather than be blocked on the queue. 133 */ 134 #define LOS_ERRNO_QUEUE_IN_TSKUSE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x08) 135 136 /** 137 * @ingroup los_queue 138 * Queue error code: The queue cannot be written during an interrupt when the time for waiting to 139 * processing the queue expires. 140 * 141 * Value: 0x02000609 142 * 143 * Solution: Set the expiry time to the never-waiting mode, or use asynchronous queues. 144 */ 145 #define LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x09) 146 147 /** 148 * @ingroup los_queue 149 * Queue error code: The queue is not created. 150 * 151 * Value: 0x0200060a 152 * 153 * Solution: Check whether the passed-in queue handle value is valid. 154 */ 155 #define LOS_ERRNO_QUEUE_NOT_CREATE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0a) 156 157 /** 158 * @ingroup los_queue 159 * Queue error code: Queue reading and writing are not synchronous. 160 * 161 * Value: 0x0200060b 162 * 163 * Solution: Synchronize queue reading with queue writing. 164 */ 165 #define LOS_ERRNO_QUEUE_IN_TSKWRITE LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0b) 166 167 /** 168 * @ingroup los_queue 169 * Queue error code: Parameters passed in during queue creation are null pointers. 170 * 171 * Value: 0x0200060c 172 * 173 * Solution: Ensure the passed-in parameters are not null pointers. 174 */ 175 #define LOS_ERRNO_QUEUE_CREAT_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0c) 176 177 /** 178 * @ingroup los_queue 179 * Queue error code: The queue length or message node size passed in during queue creation is 0. 180 * 181 * Value: 0x0200060d 182 * 183 * Solution: Pass in correct queue length and message node size. 184 */ 185 #define LOS_ERRNO_QUEUE_PARA_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0d) 186 187 /** 188 * @ingroup los_queue 189 * Queue error code: The handle of the queue is invalid. 190 * 191 * Value: 0x0200060e 192 * 193 * Solution: Check whether the passed-in queue handle value is valid. 194 */ 195 #define LOS_ERRNO_QUEUE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0e) 196 197 /** 198 * @ingroup los_queue 199 * Queue error code: The pointer passed in during queue reading is null. 200 * 201 * Value: 0x0200060f 202 * 203 * Solution: Check whether the passed-in pointer is null. 204 */ 205 #define LOS_ERRNO_QUEUE_READ_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x0f) 206 207 /** 208 * @ingroup los_queue 209 * Queue error code: The buffer size passed in during queue reading is 0. 210 * 211 * Value: 0x02000610 212 * 213 * Solution: Pass in a correct buffer size. 214 */ 215 #define LOS_ERRNO_QUEUE_READSIZE_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x10) 216 217 /** 218 * @ingroup los_queue 219 * Queue error code: The queue handle passed in during queue writing is invalid. 220 * 221 * Value: 0x02000611 222 * 223 * Solution: Check whether the passed-in queue handle value is valid. 224 */ 225 #define LOS_ERRNO_QUEUE_WRITE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x11) 226 227 /** 228 * @ingroup los_queue 229 * Queue error code: The pointer passed in during queue writing is null. 230 * 231 * Value: 0x02000612 232 * 233 * Solution: Check whether the passed-in pointer is null. 234 */ 235 #define LOS_ERRNO_QUEUE_WRITE_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x12) 236 237 /** 238 * @ingroup los_queue 239 * Queue error code: The buffer size passed in during queue writing is 0. 240 * 241 * Value: 0x02000613 242 * 243 * Solution: Pass in a correct buffer size. 244 */ 245 #define LOS_ERRNO_QUEUE_WRITESIZE_ISZERO LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x13) 246 247 /** 248 * @ingroup los_queue 249 * Queue error code: The buffer size passed in during queue writing is bigger than the queue size. 250 * 251 * Value: 0x02000615 252 * 253 * Solution: Decrease the buffer size, or use a queue in which nodes are bigger. 254 */ 255 #define LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x15) 256 257 /** 258 * @ingroup los_queue 259 * Queue error code: No free node is available during queue writing. 260 * 261 * Value: 0x02000616 262 * 263 * Solution: Ensure that free nodes are available before queue writing. 264 */ 265 #define LOS_ERRNO_QUEUE_ISFULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x16) 266 267 /** 268 * @ingroup los_queue 269 * Queue error code: The pointer passed in when the queue information is being obtained is null. 270 * 271 * Value: 0x02000617 272 * 273 * Solution: Check whether the passed-in pointer is null. 274 */ 275 #define LOS_ERRNO_QUEUE_PTR_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x17) 276 277 /** 278 * @ingroup los_queue 279 * Queue error code: The queue cannot be read during an interrupt 280 * when the time for waiting to processing the queue expires. 281 * 282 * Value: 0x02000618 283 * 284 * Solution: Set the expiry time to the never-waiting mode, or use asynchronous queues. 285 */ 286 #define LOS_ERRNO_QUEUE_READ_IN_INTERRUPT LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x18) 287 288 /** 289 * @ingroup los_queue 290 * Queue error code: The handle of the queue passed-in when the memory for the queue is being freed is invalid. 291 * 292 * Value: 0x02000619 293 * 294 * Solution: Check whether the passed-in queue handle value is valid. 295 */ 296 #define LOS_ERRNO_QUEUE_MAIL_HANDLE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x19) 297 298 /** 299 * @ingroup los_queue 300 * Queue error code: The pointer to the memory to be freed is null. 301 * 302 * Value: 0x0200061a 303 * 304 * Solution: Check whether the passed-in pointer is null. 305 */ 306 #define LOS_ERRNO_QUEUE_MAIL_PTR_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1a) 307 308 /** 309 * @ingroup los_queue 310 * Queue error code: The memory for the queue fails to be freed. 311 * 312 * Value: 0x0200061b 313 * 314 * Solution: Pass in correct input parameters. 315 */ 316 #define LOS_ERRNO_QUEUE_MAIL_FREE_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1b) 317 318 /** 319 * @ingroup los_queue 320 * Queue error code: No resource is in the queue that is being read when the 321 * time for waiting to processing the queue expires. 322 * 323 * Value: 0x0200061d 324 * 325 * Solution: Ensure that the queue contains messages when it is being read. 326 */ 327 #define LOS_ERRNO_QUEUE_ISEMPTY LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1d) 328 329 /** 330 * @ingroup los_queue 331 * Queue error code: The buffer size passed in during queue readding is smaller than the queue size. 332 * 333 * Value: 0x0200061f 334 * 335 * Solution: Increase the buffer size, or use a queue in which nodes are smaller. 336 */ 337 #define LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL LOS_ERRNO_OS_ERROR(LOS_MOD_QUE, 0x1f) 338 339 /** 340 * @ingroup los_queue 341 * Structure of the block for queue information query 342 */ 343 typedef struct tagQueueInfo { 344 UINT32 queueID; /**< Queue ID */ 345 UINT16 queueLen; /**< Queue length */ 346 UINT16 queueSize; /**< Node size */ 347 UINT16 queueHead; /**< Node head */ 348 UINT16 queueTail; /**< Node tail */ 349 UINT16 writableCnt; /**< Count of writable resources */ 350 UINT16 readableCnt; /**< Count of readable resources */ 351 UINT32 waitReadTask; /**< Resource reading task */ 352 UINT32 waitWriteTask; /**< Resource writing task */ 353 UINT32 waitMemTask; /**< Memory task */ 354 } QUEUE_INFO_S; 355 356 /** 357 * @ingroup los_queue 358 * @brief Create a message queue. 359 * 360 * @par Description: 361 * This API is used to create a message queue. 362 * @attention 363 * <ul> 364 * <li>Threre are LOSCFG_BASE_IPC_QUEUE_LIMIT queues available, change it's value when necessory.</li> 365 * </ul> 366 * @param queueName [IN] Message queue name. Reserved parameter, not used for now. 367 * @param len [IN] Queue length. The value range is [1,0xffff]. 368 * @param queueID [OUT] ID of the queue control structure that is successfully created. 369 * @param flags [IN] Queue mode. Reserved parameter, not used for now. 370 * @param maxMsgSize [IN] Node size. The value range is [1,0xffff-4]. 371 * 372 * @retval #LOS_OK The message queue is successfully created. 373 * @retval #LOS_ERRNO_QUEUE_CB_UNAVAILABLE The upper limit of the number of created queues is exceeded. 374 * @retval #LOS_ERRNO_QUEUE_CREATE_NO_MEMORY Insufficient memory for queue creation. 375 * @retval #LOS_ERRNO_QUEUE_CREAT_PTR_NULL Null pointer, queueID is NULL. 376 * @retval #LOS_ERRNO_QUEUE_PARA_ISZERO The queue length or message node size passed in during queue 377 * creation is 0. 378 * @retval #LOS_ERRNO_QUEUE_SIZE_TOO_BIG The parameter maxMsgSize is larger than 0xffff - 4. 379 * @par Dependency: 380 * <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul> 381 * @see LOS_QueueDelete 382 */ 383 extern UINT32 LOS_QueueCreate(const CHAR *queueName, 384 UINT16 len, 385 UINT32 *queueID, 386 UINT32 flags, 387 UINT16 maxMsgSize); 388 389 /** 390 * @ingroup los_queue 391 * @brief Read a queue. 392 * 393 * @par Description: 394 * This API is used to read data in a specified queue, and store the obtained data to the address specified 395 * by bufferAddr. The address and the size of the data to be read are defined by users. 396 * @attention 397 * <ul> 398 * <li>The specific queue should be created firstly.</li> 399 * <li>Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is read 400 * first.</li> 401 * <li>bufferAddr stores the obtained data.</li> 402 * <li>Do not read or write a queue in unblocking modes such as an interrupt.</li> 403 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li> 404 * <li>The argument timeOut is a relative time.</li> 405 * </ul> 406 * 407 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 408 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 409 * @param bufferAddr [OUT] Starting address that stores the obtained data. The starting address must not be 410 * null. 411 * @param bufferSize [IN/OUT] Where to maintain the buffer wantted-size before read, and the real-size after read. 412 * @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick). 413 * 414 * @retval #LOS_OK The queue is successfully read. 415 * @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid. 416 * @retval #LOS_ERRNO_QUEUE_READ_PTR_NULL The pointer passed in during queue reading is null. 417 * @retval #LOS_ERRNO_QUEUE_READSIZE_ISZERO The buffer size passed in during queue reading is 0. 418 * @retval #LOS_ERRNO_QUEUE_READ_IN_INTERRUPT The queue cannot be read during an interrupt when the time for 419 * waiting to processing the queue expires. 420 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue to be read is not created. 421 * @retval #LOS_ERRNO_QUEUE_ISEMPTY No resource is in the queue that is being read when the time for 422 * waiting to processing the queue expires. 423 * @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is 424 * locked. 425 * @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires. 426 * @retval #LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL The buffer size passed in during queue reading is less than 427 * the queue size. 428 * @par Dependency: 429 * <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul> 430 * @see LOS_QueueWriteCopy | LOS_QueueCreate 431 */ 432 extern UINT32 LOS_QueueReadCopy(UINT32 queueID, 433 VOID *bufferAddr, 434 UINT32 *bufferSize, 435 UINT32 timeOut); 436 437 /** 438 * @ingroup los_queue 439 * @brief Write data into a queue. 440 * 441 * @par Description: 442 * This API is used to write the data of the size specified by bufferSize and stored at the address specified by 443 * bufferAddr into a queue. 444 * @attention 445 * <ul> 446 * <li>The specific queue should be created firstly.</li> 447 * <li>Do not read or write a queue in unblocking modes such as interrupt.</li> 448 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li> 449 * <li>The data to be written is of the size specified by bufferSize and is stored at the address specified by 450 * BufferAddr.</li> 451 * <li>The argument timeOut is a relative time.</li> 452 * </ul> 453 * 454 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 455 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 456 * @param bufferAddr [IN] Starting address that stores the data to be written.The starting address must 457 * not be null. 458 * @param bufferSize [IN] Passed-in buffer size. The value range is [1,USHRT_MAX - sizeof(UINT32)]. 459 * @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick). 460 * 461 * @retval #LOS_OK The data is successfully written into the queue. 462 * @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid. 463 * @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null. 464 * @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0. 465 * @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time 466 * for waiting to processing the queue expires. 467 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created. 468 * @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than 469 * the queue size. 470 * @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing. 471 * @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when 472 * the task is locked. 473 * @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires. 474 * @par Dependency: 475 * <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul> 476 * @see LOS_QueueReadCopy | LOS_QueueCreate 477 */ 478 extern UINT32 LOS_QueueWriteCopy(UINT32 queueID, 479 VOID *bufferAddr, 480 UINT32 bufferSize, 481 UINT32 timeOut); 482 483 /** 484 * @ingroup los_queue 485 * @brief Read a queue. 486 * 487 * @par Description: 488 * This API is used to read the address of data in a specified queue, and store it to the address specified by 489 * bufferAddr. 490 * @attention 491 * <ul> 492 * <li>The specific queue should be created firstly.</li> 493 * <li>Queue reading adopts the fist in first out (FIFO) mode. The data that is first stored in the queue is 494 * read first.</li> 495 * <li>bufferAddr stores the obtained data address.</li> 496 * <li>Do not read or write a queue in unblocking modes such as an interrupt.</li> 497 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li> 498 * <li>The argument timeOut is a relative time.</li> 499 * <li>The bufferSize is not really used in LOS_QueueRead, because the interface is only used to 500 * obtain the address of data.</li> 501 * <li>The buffer which the bufferAddr pointing to must be greater than or equal to 4 bytes.</li> 502 * </ul> 503 * 504 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 505 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 506 * @param bufferAddr [OUT] Starting address that stores the obtained data. The starting address must 507 * not be null. 508 * @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff]. 509 * @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick). 510 * 511 * @retval #LOS_OK The queue is successfully read. 512 * @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid. 513 * @retval #LOS_ERRNO_QUEUE_READ_PTR_NULL The pointer passed in during queue reading is null. 514 * @retval #LOS_ERRNO_QUEUE_READSIZE_ISZERO The buffer size passed in during queue reading is 0. 515 * @retval #LOS_ERRNO_QUEUE_READ_IN_INTERRUPT The queue cannot be read during an interrupt when the time for 516 * waiting to processing the queue expires. 517 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue to be read is not created. 518 * @retval #LOS_ERRNO_QUEUE_ISEMPTY No resource is in the queue that is being read when the time for 519 * waiting to processing the queue expires. 520 * @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is 521 * locked. 522 * @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires. 523 * @par Dependency: 524 * <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul> 525 * @see LOS_QueueWrite | LOS_QueueCreate 526 */ 527 extern UINT32 LOS_QueueRead(UINT32 queueID, 528 VOID *bufferAddr, 529 UINT32 bufferSize, 530 UINT32 timeOut); 531 532 /** 533 * @ingroup los_queue 534 * @brief Write data into a queue. 535 * 536 * @par Description: 537 * This API is used to write the address of data specified by bufferAddr into a queue. 538 * @attention 539 * <ul> 540 * <li>The specific queue should be created firstly.</li> 541 * <li>Do not read or write a queue in unblocking modes such as an interrupt.</li> 542 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li> 543 * <li>The address of the data of the size specified by bufferSize and stored at the address specified by 544 * BufferAddr is to be written.</li> 545 * <li>The argument timeOut is a relative time.</li> 546 * <li>The bufferSize is not really used in LOS_QueueWrite, because the interface is only used to write the address 547 * of data specified by bufferAddr into a queue.</li> 548 * </ul> 549 * 550 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 551 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 552 * @param bufferAddr [IN] Starting address that stores the data to be written. The starting address 553 * must not be null. 554 * @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff]. 555 * @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick). 556 * 557 * @retval #LOS_OK The data is successfully written into the queue. 558 * @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid. 559 * @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null. 560 * @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0. 561 * @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for 562 * waiting to processing the queue expires. 563 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created. 564 * @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than 565 * the queue size. 566 * @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing. 567 * @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is 568 * locked. 569 * @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires. 570 * @par Dependency: 571 * <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul> 572 * @see LOS_QueueRead | LOS_QueueCreate 573 */ 574 extern UINT32 LOS_QueueWrite(UINT32 queueID, 575 VOID *bufferAddr, 576 UINT32 bufferSize, 577 UINT32 timeOut); 578 579 /** 580 * @ingroup los_queue 581 * @brief Write data into a queue header. 582 * 583 * @par Description: 584 * This API is used to write the data of the size specified by bufferSize and stored at the address specified by 585 * bufferAddr into a queue header. 586 * @attention 587 * <ul> 588 * <li>Do not read or write a queue in unblocking modes such as an interrupt.</li> 589 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li> 590 * <li>The address of the data of the size specified by bufferSize and stored at the address specified by 591 * BufferAddr is to be written.</li> 592 * <li>The argument timeOut is a relative time.</li> 593 * <li>LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be used. 594 * <li> 595 * </ul> 596 * 597 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 598 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 599 * @param bufferAddr [OUT] Starting address that stores the data to be written. The starting address 600 * must not be null. 601 * @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff]. 602 * @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick). 603 * 604 * @retval #LOS_OK The data is successfully written into the queue. 605 * @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid. 606 * @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null. 607 * @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0. 608 * @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for 609 * waiting to processing the queue expires. 610 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created. 611 * @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than 612 * the queue size. 613 * @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing. 614 * @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is 615 * locked. 616 * @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires. 617 * @par Dependency: 618 * <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul> 619 * @see LOS_QueueRead | LOS_QueueCreate 620 */ 621 extern UINT32 LOS_QueueWriteHead(UINT32 queueID, 622 VOID *bufferAddr, 623 UINT32 bufferSize, 624 UINT32 timeOut); 625 626 /** 627 * @ingroup los_queue 628 * @brief Write data into a queue header. 629 * 630 * @par Description: 631 * This API is used to write the data of the size specified by bufferSize and stored at the address specified by 632 * bufferAddr into a queue header. 633 * @attention 634 * <ul> 635 * <li>Do not read or write a queue in unblocking modes such as an interrupt.</li> 636 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li> 637 * <li>The address of the data of the size specified by bufferSize and stored at the address specified by 638 * BufferAddr is to be written.</li> 639 * <li>The argument timeOut is a relative time.</li> 640 * <li>LOS_QueueRead and LOS_QueueWriteHead are a set of interfaces, and the two groups of interfaces need to be 641 * used.<li> 642 * </ul> 643 * 644 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 645 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 646 * @param bufferAddr [OUT] Starting address that stores the data to be written. 647 * The starting address must not be null. 648 * @param bufferSize [IN] Passed-in buffer size, which must not be 0. The value range is [1,0xffffffff]. 649 * @param timeOut [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER](unit: Tick). 650 * 651 * @retval #LOS_OK The data is successfully written into the queue. 652 * @retval #LOS_ERRNO_QUEUE_INVALID The queue handle passed in during queue writing is invalid. 653 * @retval #LOS_ERRNO_QUEUE_WRITE_PTR_NULL The pointer passed in during queue writing is null. 654 * @retval #LOS_ERRNO_QUEUE_WRITESIZE_ISZERO The buffer size passed in during queue writing is 0. 655 * @retval #LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT The queue cannot be written during an interrupt when the time for 656 * waiting to processing the queue expires. 657 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue into which the data is written is not created. 658 * @retval #LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG The buffer size passed in during queue writing is bigger than 659 * the queue size. 660 * @retval #LOS_ERRNO_QUEUE_ISFULL No free node is available during queue writing. 661 * @retval #LOS_ERRNO_QUEUE_PEND_IN_LOCK The task is forbidden to be blocked on a queue when the task is 662 * locked. 663 * @retval #LOS_ERRNO_QUEUE_TIMEOUT The time set for waiting to processing the queue expires. 664 * @par Dependency: 665 * <ul><li>los_queue.h: The header file that contains the API declaration.</li></ul> 666 * @see LOS_QueueWrite | LOS_QueueWriteHead 667 */ 668 extern UINT32 LOS_QueueWriteHeadCopy(UINT32 queueID, 669 VOID *bufferAddr, 670 UINT32 bufferSize, 671 UINT32 timeOut); 672 673 /** 674 * @ingroup los_queue 675 * @brief Delete a queue. 676 * 677 * @par Description: 678 * This API is used to delete a queue. 679 * @attention 680 * <ul> 681 * <li>This API cannot be used to delete a queue that is not created.</li> 682 * <li>A synchronous queue fails to be deleted if any tasks are blocked on it, or some queues are being read or 683 * written.</li> 684 * </ul> 685 * 686 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 687 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 688 * 689 * @retval #LOS_OK The queue is successfully deleted. 690 * @retval #LOS_ERRNO_QUEUE_NOT_FOUND The queue cannot be found. 691 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue handle passed in when the queue is being deleted is 692 * incorrect. 693 * @retval #LOS_ERRNO_QUEUE_IN_TSKUSE The queue that blocks a task cannot be deleted. 694 * @retval #LOS_ERRNO_QUEUE_IN_TSKWRITE Queue reading and writing are not synchronous. 695 * @par Dependency: 696 * <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul> 697 * @see LOS_QueueCreate | LOS_QueueCreate 698 */ 699 extern UINT32 LOS_QueueDelete(UINT32 queueID); 700 701 /** 702 * @ingroup los_queue 703 * @brief Obtain queue information. 704 * 705 * @par Description: 706 * This API is used to obtain queue information. 707 * @attention 708 * <ul> 709 * <li>The specific queue should be created firstly.</li> 710 * </ul> 711 * @param queueID [IN] Queue ID created by LOS_QueueCreate. The value range is 712 * [1,LOSCFG_BASE_IPC_QUEUE_LIMIT]. 713 * @param queueInfo [OUT] The queue information to be read must not be null. 714 * 715 * @retval #LOS_OK The queue information is successfully obtained. 716 * @retval #LOS_ERRNO_QUEUE_PTR_NULL The pointer to the queue information to be obtained is null. 717 * @retval #LOS_ERRNO_QUEUE_INVALID The handle of the queue that is being read is invalid. 718 * @retval #LOS_ERRNO_QUEUE_NOT_CREATE The queue in which the information to be obtained is stored is 719 * not created. 720 * 721 * @par Dependency: 722 * <ul><li>los_queue.h: the header file that contains the API declaration.</li></ul> 723 * @see LOS_QueueCreate 724 */ 725 extern UINT32 LOS_QueueInfoGet(UINT32 queueID, QUEUE_INFO_S *queueInfo); 726 extern UINT32 LOS_QueueUsage(VOID); 727 728 #ifdef __cplusplus 729 #if __cplusplus 730 } 731 #endif /* __cplusplus */ 732 #endif /* __cplusplus */ 733 734 #endif /* _LOS_QUEUE_H */ 735