|
|
@ -25,7 +25,7 @@
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* --------------------------------------------------------------------------- */
|
|
|
|
* --------------------------------------------------------------------------- */
|
|
|
|
//队列
|
|
|
|
//实现了一个基于轻量级操作系统的队列管理模块,提供了队列的创建、读写、删除以及信息获取等功能
|
|
|
|
#include "los_queue_pri.h"
|
|
|
|
#include "los_queue_pri.h"
|
|
|
|
#include "los_queue_debug_pri.h"
|
|
|
|
#include "los_queue_debug_pri.h"
|
|
|
|
#include "los_task_pri.h"
|
|
|
|
#include "los_task_pri.h"
|
|
|
@ -53,6 +53,7 @@ LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_freeQueueList;
|
|
|
|
* Description : queue initial
|
|
|
|
* Description : queue initial
|
|
|
|
* Return : LOS_OK on success or error code on failure
|
|
|
|
* Return : LOS_OK on success or error code on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
//初始化队列,返回成功或失败错误码
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosQueueCB *queueNode = NULL;
|
|
|
|
LosQueueCB *queueNode = NULL;
|
|
|
@ -78,7 +79,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsQueueInit(VOID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//OsQueueCreateParameterCheck函数用于检查创建队列时传入的参数是否合法
|
|
|
|
STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queueId, UINT16 maxMsgSize)
|
|
|
|
STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queueId, UINT16 maxMsgSize)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (queueId == NULL) {
|
|
|
|
if (queueId == NULL) {
|
|
|
@ -94,7 +95,7 @@ STATIC INLINE UINT32 OsQueueCreateParameterCheck(UINT16 len, const UINT32 *queue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//OsQueueCreateInternal函数用于创建队列,包括在队列控制块中记录队列长度、消息大小等信息
|
|
|
|
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsQueueCreateInternal(UINT16 len, UINT32 *queueId, UINT16 msgSize,
|
|
|
|
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsQueueCreateInternal(UINT16 len, UINT32 *queueId, UINT16 msgSize,
|
|
|
|
UINT8 *queue, UINT8 queueMemType)
|
|
|
|
UINT8 *queue, UINT8 queueMemType)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -165,7 +166,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreateStatic(const CHAR *queueName,
|
|
|
|
return OsQueueCreateInternal(len, queueId, msgSize, queueMem, OS_QUEUE_ALLOC_STATIC);
|
|
|
|
return OsQueueCreateInternal(len, queueId, msgSize, queueMem, OS_QUEUE_ALLOC_STATIC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//创建队列
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len, UINT32 *queueId,
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len, UINT32 *queueId,
|
|
|
|
UINT32 flags, UINT16 maxMsgSize)
|
|
|
|
UINT32 flags, UINT16 maxMsgSize)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -198,7 +199,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueCreate(const CHAR *queueName, UINT16 len,
|
|
|
|
|
|
|
|
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//OsQueueReadParameterCheck和OsQueueWriteParameterCheck分别用于检查读和写操作的参数合法性
|
|
|
|
LITE_OS_SEC_TEXT STATIC UINT32 OsQueueReadParameterCheck(UINT32 queueId, const VOID *bufferAddr,
|
|
|
|
LITE_OS_SEC_TEXT STATIC UINT32 OsQueueReadParameterCheck(UINT32 queueId, const VOID *bufferAddr,
|
|
|
|
const UINT32 *bufferSize, UINT32 timeout)
|
|
|
|
const UINT32 *bufferSize, UINT32 timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -248,7 +249,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsQueueWriteParameterCheck(UINT32 queueId, const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//实现了队列的读取和写入操作,并对可能出现的错误进行了处理
|
|
|
|
STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize)
|
|
|
|
STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UINT8 *queueNode = NULL;
|
|
|
|
UINT8 *queueNode = NULL;
|
|
|
@ -296,7 +297,7 @@ STATIC UINT32 OsQueueBufferOperate(LosQueueCB *queueCB, UINT32 operateType, VOID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//用于处理队列操作函数 OsQueueBufferOperate 返回的错误码,使得在发生错误时能够打印相应的错误信息
|
|
|
|
STATIC VOID OsQueueBufferOperateErrProcess(UINT32 errorCode)
|
|
|
|
STATIC VOID OsQueueBufferOperateErrProcess(UINT32 errorCode)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (errorCode) {
|
|
|
|
switch (errorCode) {
|
|
|
@ -336,7 +337,7 @@ STATIC UINT32 OsQueueOperateParamCheck(const LosQueueCB *queueCB, UINT32 queueId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LOS_OK;
|
|
|
|
return LOS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//OsQueueOperate:实现了对队列的操作,包括参数检查、任务挂起与唤醒以及错误处理等功能
|
|
|
|
STATIC UINT32 OsQueueOperate(UINT32 queueId, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout)
|
|
|
|
STATIC UINT32 OsQueueOperate(UINT32 queueId, UINT32 operateType, VOID *bufferAddr, UINT32 *bufferSize, UINT32 timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosQueueCB *queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueId);
|
|
|
|
LosQueueCB *queueCB = (LosQueueCB *)GET_QUEUE_HANDLE(queueId);
|
|
|
@ -400,7 +401,7 @@ QUEUE_END:
|
|
|
|
OsQueueBufferOperateErrProcess(errorCode);
|
|
|
|
OsQueueBufferOperateErrProcess(errorCode);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueReadCopy:从队列中读取数据,通过参数检查后调用OsQueueOperate函数进行实际的读取操作
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId,
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
UINT32 *bufferSize,
|
|
|
|
UINT32 *bufferSize,
|
|
|
@ -417,7 +418,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueReadCopy(UINT32 queueId,
|
|
|
|
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD);
|
|
|
|
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_READ, OS_QUEUE_HEAD);
|
|
|
|
return OsQueueOperate(queueId, operateType, bufferAddr, bufferSize, timeout);
|
|
|
|
return OsQueueOperate(queueId, operateType, bufferAddr, bufferSize, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueWriteHeadCopy:向队列的头部写入数据,通过参数检查后调用OsQueueOperate函数进行实际的写入操作
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId,
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
UINT32 bufferSize,
|
|
|
|
UINT32 bufferSize,
|
|
|
@ -434,7 +435,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHeadCopy(UINT32 queueId,
|
|
|
|
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD);
|
|
|
|
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_HEAD);
|
|
|
|
return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout);
|
|
|
|
return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueWriteCopy:向队列的尾部写入数据,通过参数检查后调用OsQueueOperate函数进行实际的写入操作
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId,
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
UINT32 bufferSize,
|
|
|
|
UINT32 bufferSize,
|
|
|
@ -451,12 +452,12 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteCopy(UINT32 queueId,
|
|
|
|
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL);
|
|
|
|
operateType = OS_QUEUE_OPERATE_TYPE(OS_QUEUE_WRITE, OS_QUEUE_TAIL);
|
|
|
|
return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout);
|
|
|
|
return OsQueueOperate(queueId, operateType, bufferAddr, &bufferSize, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueRead:从队列中读取数据的简化接口,直接调用LOS_QueueReadCopy函数
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueRead(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return LOS_QueueReadCopy(queueId, bufferAddr, &bufferSize, timeout);
|
|
|
|
return LOS_QueueReadCopy(queueId, bufferAddr, &bufferSize, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueWrite:向队列中写入数据的简化接口,先进行参数检查,然后调用LOS_QueueWriteCopy函数
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32 bufferSize, UINT32 timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bufferAddr == NULL) {
|
|
|
|
if (bufferAddr == NULL) {
|
|
|
@ -465,7 +466,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWrite(UINT32 queueId, VOID *bufferAddr, UINT32
|
|
|
|
bufferSize = sizeof(CHAR *);
|
|
|
|
bufferSize = sizeof(CHAR *);
|
|
|
|
return LOS_QueueWriteCopy(queueId, &bufferAddr, bufferSize, timeout);
|
|
|
|
return LOS_QueueWriteCopy(queueId, &bufferAddr, bufferSize, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueWriteHead:向队列头部写入数据的简化接口,先进行参数检查,然后调用LOS_QueueWriteHeadCopy函数
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId,
|
|
|
|
LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
VOID *bufferAddr,
|
|
|
|
UINT32 bufferSize,
|
|
|
|
UINT32 bufferSize,
|
|
|
@ -477,7 +478,8 @@ LITE_OS_SEC_TEXT UINT32 LOS_QueueWriteHead(UINT32 queueId,
|
|
|
|
bufferSize = sizeof(CHAR *);
|
|
|
|
bufferSize = sizeof(CHAR *);
|
|
|
|
return LOS_QueueWriteHeadCopy(queueId, &bufferAddr, bufferSize, timeout);
|
|
|
|
return LOS_QueueWriteHeadCopy(queueId, &bufferAddr, bufferSize, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueDelete:删除队列的函数
|
|
|
|
|
|
|
|
//首先检查队列是否存在,如果存在则检查是否有任务正在使用队列或者队列中还有未释放的内存块,如果满足条件则释放队列所占用的资源
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueId)
|
|
|
|
LITE_OS_SEC_TEXT_INIT UINT32 LOS_QueueDelete(UINT32 queueId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LosQueueCB *queueCB = NULL;
|
|
|
|
LosQueueCB *queueCB = NULL;
|
|
|
@ -537,7 +539,7 @@ QUEUE_END:
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
SCHEDULER_UNLOCK(intSave);
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//LOS_QueueInfoGet:获取指定队列的相关信息,包括队列ID、队列长度、队列大小、队列头尾指针、等待读取和写入的任务数等
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueId, QUEUE_INFO_S *queueInfo)
|
|
|
|
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_QueueInfoGet(UINT32 queueId, QUEUE_INFO_S *queueInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
UINT32 intSave;
|
|
|
|
UINT32 intSave;
|
|
|
@ -595,6 +597,9 @@ QUEUE_END:
|
|
|
|
* : timeout --- Expiry time. The value range is [0,LOS_WAIT_FOREVER]
|
|
|
|
* : timeout --- Expiry time. The value range is [0,LOS_WAIT_FOREVER]
|
|
|
|
* Return : pointer if success otherwise NULL
|
|
|
|
* Return : pointer if success otherwise NULL
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
//OsQueueMailAlloc函数用来从邮件池中分配一个邮件内存块
|
|
|
|
|
|
|
|
//如果没有可用的内存块,则根据超时时间挂起当前任务,并将其加入到等待内存块的任务链表中
|
|
|
|
|
|
|
|
//当有内存块可用时,会将任务从任务链表中移除,并返回分配的内存块指针
|
|
|
|
LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueId, VOID *mailPool, UINT32 timeout)
|
|
|
|
LITE_OS_SEC_TEXT VOID *OsQueueMailAlloc(UINT32 queueId, VOID *mailPool, UINT32 timeout)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
VOID *mem = NULL;
|
|
|
|
VOID *mem = NULL;
|
|
|
@ -663,6 +668,8 @@ END:
|
|
|
|
* : mailMem --- The mail memory block address
|
|
|
|
* : mailMem --- The mail memory block address
|
|
|
|
* Return : LOS_OK on success or error code on failure
|
|
|
|
* Return : LOS_OK on success or error code on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
//OsQueueMailFree函数用来释放指定的邮件内存块,并将其加入到邮件池的空闲链表中
|
|
|
|
|
|
|
|
//如果有任务在等待内存块,则会从任务链表中唤醒一个任务,并将其从任务链表中移除
|
|
|
|
LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueId, VOID *mailPool, VOID *mailMem)
|
|
|
|
LITE_OS_SEC_TEXT UINT32 OsQueueMailFree(UINT32 queueId, VOID *mailPool, VOID *mailMem)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
VOID *mem = NULL;
|
|
|
|
VOID *mem = NULL;
|
|
|
|