更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_queue_pri.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _LOS_QUEUE_PRI_H
33#define _LOS_QUEUE_PRI_H
34
35#include "los_queue.h"
36
37#ifdef __cplusplus
38#if __cplusplus
39extern "C" {
40#endif /* __cplusplus */
41#endif /* __cplusplus */
42/**
43 * @brief @note_pic
44 * @verbatim
45 鸿蒙对消息队列图
46 |<-----消息内容区,有2个消息---->|
47+------------+------------------------------------------------------------+
48| | |---------------|---------------| |
49| | |---------------|---------------| |
50| | |---------------|---------------| |
51+-------------------------------------------------------------------------+
52| | ^ ^ |
53|<消息大小> | | | |
54| | |head |tail |
55| + +任务读消息 +任务写消息 |
56| |
57| |
58+<-------------+ 队列长度,消息点个数, +------------->+
59 * @endverbatim
60 */
61
62typedef enum {
63 OS_QUEUE_READ = 0, ///< 读队列
64 OS_QUEUE_WRITE = 1, ///< 写队列
67
68typedef enum {
69 OS_QUEUE_HEAD = 0, ///< 队列头部标识
70 OS_QUEUE_TAIL = 1 ///< 队列尾部标识
72
73#define OS_QUEUE_OPERATE_TYPE(ReadOrWrite, HeadOrTail) (((UINT32)(HeadOrTail) << 1) | (ReadOrWrite))
74#define OS_QUEUE_READ_WRITE_GET(type) ((type) & 0x01U)
75#define OS_QUEUE_READ_HEAD (OS_QUEUE_READ | (OS_QUEUE_HEAD << 1))
76#define OS_QUEUE_READ_TAIL (OS_QUEUE_READ | (OS_QUEUE_TAIL << 1))
77#define OS_QUEUE_WRITE_HEAD (OS_QUEUE_WRITE | (OS_QUEUE_HEAD << 1))
78#define OS_QUEUE_WRITE_TAIL (OS_QUEUE_WRITE | (OS_QUEUE_TAIL << 1))
79#define OS_QUEUE_OPERATE_GET(type) ((type) & 0x03U)
80#define OS_QUEUE_IS_READ(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_READ)
81#define OS_QUEUE_IS_WRITE(type) (OS_QUEUE_READ_WRITE_GET(type) == OS_QUEUE_WRITE)
82
83/**
84 * @ingroup los_queue
85 * Queue information block structure
86 * @attention 读写队列分离
87 */
88typedef struct {
89 UINT8 *queueHandle; /**< Pointer to a queue handle | 队列消息内存空间的指针*/
90 UINT16 queueState; /**< Queue state | 队列状态*/
91 UINT16 queueLen; /**< Queue length | 队列中消息节点个数,即队列长度,由创建时确定,不再改变*/
92 UINT16 queueSize; /**< Node size | 消息节点大小,由创建时确定,不再改变,即定义了每个消息长度的上限.*/
93 UINT32 queueID; /**< queueID | 队列ID*/
94 UINT16 queueHead; /**< Node head | 消息头节点位置(数组下标)*/
95 UINT16 queueTail; /**< Node tail | 消息尾节点位置(数组下标)*/
96 UINT16 readWriteableCnt[OS_QUEUE_N_RW]; /**< Count of readable or writable resources, 0:readable, 1:writable
97 | 队列中可写或可读消息数,0表示可读,1表示可写*/
98 LOS_DL_LIST readWriteList[OS_QUEUE_N_RW]; /**< the linked list to be read or written, 0:readlist, 1:writelist
99 | 挂的都是等待读/写消息的任务链表,0表示读消息的链表,1表示写消息的任务链表*/
100 LOS_DL_LIST memList; /**< Pointer to the memory linked list | 内存块链表*/
101} LosQueueCB;
102
103/* queue state */
104/**
105 * @ingroup los_queue
106 * Message queue state: not in use.
107 */
108#define OS_QUEUE_UNUSED 0 ///< 队列没有使用
109
110/**
111 * @ingroup los_queue
112 * Message queue state: used.
113 */
114#define OS_QUEUE_INUSED 1 ///< 队列被使用
115
116/**
117 * @ingroup los_queue
118 * Not in use.
119 */
120#define OS_QUEUE_WAIT_FOR_POOL 1
121
122/**
123 * @ingroup los_queue
124 * Normal message queue.
125 */
126#define OS_QUEUE_NORMAL 0
127
128/**
129 * @ingroup los_queue
130 * Queue information control block
131 */
132extern LosQueueCB *g_allQueue;
133
134/**
135 * @ingroup los_queue
136 * COUNT | INDEX split bit
137 */
138#define QUEUE_SPLIT_BIT 16
139/**
140 * @ingroup los_queue
141 * Set the queue id
142 */
143#define SET_QUEUE_ID(count, queueID) (((count) << QUEUE_SPLIT_BIT) | (queueID))
144
145/**
146 * @ingroup los_queue
147 * get the queue index
148 */
149#define GET_QUEUE_INDEX(queueID) ((queueID) & ((1U << QUEUE_SPLIT_BIT) - 1))
150
151/**
152 * @ingroup los_queue
153 * get the queue count
154 */
155#define GET_QUEUE_COUNT(queueID) ((queueID) >> QUEUE_SPLIT_BIT)
156
157/**
158 * @ingroup los_queue
159 * Obtain a handle of the queue that has a specified ID.
160 *
161 */
162#define GET_QUEUE_HANDLE(queueID) (((LosQueueCB *)g_allQueue) + GET_QUEUE_INDEX(queueID))
163
164/**
165 * @ingroup los_queue
166 * Obtain the head node in a queue doubly linked list.
167 */
168#define GET_QUEUE_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosQueueCB, readWriteList[OS_QUEUE_WRITE])
169
170/**
171 * @ingroup los_queue
172 * @brief Alloc a stationary memory for a mail.
173 *
174 * @par Description:
175 * This API is used to alloc a stationary memory for a mail according to queueID.
176 * @attention
177 * <ul>
178 * <li>Do not alloc memory in unblocking modes such as interrupt.</li>
179 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
180 * <li>The argument timeout is a relative time.</li>
181 * </ul>
182 *
183 * @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
184 * @param mailPool [IN] The memory poll that stores the mail.
185 * @param timeout [IN] Expiry time. The value range is [0,LOS_WAIT_FOREVER].
186 *
187 * @retval #NULL The memory allocation is failed.
188 * @retval #pMem The address of alloc memory.
189 * @par Dependency:
190 * <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
191 * @see OsQueueMailFree
192 */
193extern VOID *OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeout);
194
195/**
196 * @ingroup los_queue
197 * @brief Free a stationary memory of a mail.
198 *
199 * @par Description:
200 * This API is used to free a stationary memory for a mail according to queueID.
201 * @attention
202 * <ul>
203 * <li>This API cannot be called before the Huawei LiteOS is initialized.</li>
204 * </ul>
205 *
206 * @param queueID [IN] Queue ID. The value range is [1,LOSCFG_BASE_IPC_QUEUE_LIMIT].
207 * @param mailPool [IN] The mail memory poll address.
208 * @param mailMem [IN] The mail memory block address.
209 *
210 * @retval #LOS_OK 0x00000000: The memory free successfully.
211 * @retval #OS_ERRNO_QUEUE_MAIL_HANDLE_INVALID 0x02000619: The handle of the queue passed-in when the memory
212 * for the queue is being freed is invalid.
213 * @retval #OS_ERRNO_QUEUE_MAIL_PTR_INVALID 0x0200061a: The pointer to the memory to be freed is null.
214 * @retval #OS_ERRNO_QUEUE_MAIL_FREE_ERROR 0x0200061b: The memory for the queue fails to be freed.
215 * @par Dependency:
216 * <ul><li>los_queue_pri.h: the header file that contains the API declaration.</li></ul>
217 * @see OsQueueMailAlloc
218 */
219extern UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem);
220
221extern UINT32 OsQueueInit(VOID);
222
223#ifdef __cplusplus
224#if __cplusplus
225}
226#endif /* __cplusplus */
227#endif /* __cplusplus */
228
229#endif /* _LOS_QUEUE_PRI_H */
VOID * OsQueueMailAlloc(UINT32 queueID, VOID *mailPool, UINT32 timeout)
Alloc a stationary memory for a mail.
LosQueueCB * g_allQueue
消息队列池
Definition: los_queue.c:98
UINT32 OsQueueMailFree(UINT32 queueID, VOID *mailPool, VOID *mailMem)
Free a stationary memory of a mail.
UINT32 OsQueueInit(VOID)
Definition: los_queue.c:105
QueueHeadTail
Definition: los_queue_pri.h:68
@ OS_QUEUE_TAIL
队列尾部标识
Definition: los_queue_pri.h:70
@ OS_QUEUE_HEAD
队列头部标识
Definition: los_queue_pri.h:69
QueueReadWrite
@note_pic
Definition: los_queue_pri.h:62
@ OS_QUEUE_N_RW
Definition: los_queue_pri.h:65
@ OS_QUEUE_WRITE
写队列
Definition: los_queue_pri.h:64
@ OS_QUEUE_READ
读队列
Definition: los_queue_pri.h:63
unsigned short UINT16
Definition: los_typedef.h:56
unsigned char UINT8
Definition: los_typedef.h:55
unsigned int UINT32
Definition: los_typedef.h:57
UINT16 queueHead
Definition: los_queue_pri.h:94
UINT16 queueLen
Definition: los_queue_pri.h:91
UINT16 queueTail
Definition: los_queue_pri.h:95
LOS_DL_LIST memList
UINT16 queueSize
Definition: los_queue_pri.h:92
UINT16 queueState
Definition: los_queue_pri.h:90
UINT8 * queueHandle
Definition: los_queue_pri.h:89
UINT32 queueID
Definition: los_queue_pri.h:93