pull/1/head
tree 1 year ago
parent 4e5ee91f58
commit cc2b0861fe

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

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*实现环形缓冲区。环形缓冲区是一种循环使用固定大小存储空间的数据结构,常用于解决生产者-消费者问题*/
#include "los_ringbuf.h"
#ifdef __cplusplus
@ -33,7 +33,7 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//LOS_RingbufUsedSize获取环形缓冲区已使用的大小
UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf)
{
UINT32 size;
@ -56,6 +56,7 @@ UINT32 LOS_RingbufUsedSize(Ringbuf *ringbuf)
* |
* endIdx
*/
//OsRingbufWriteLinear线性写入数据到环形缓冲区
STATIC UINT32 OsRingbufWriteLinear(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
{
UINT32 cpSize;
@ -77,7 +78,7 @@ STATIC UINT32 OsRingbufWriteLinear(Ringbuf *ringbuf, const CHAR *buf, UINT32 siz
return cpSize;
}
//OsRingbufWriteLoop循环写入数据到环形缓冲区
STATIC UINT32 OsRingbufWriteLoop(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
{
UINT32 right, cpSize;
@ -105,7 +106,7 @@ STATIC UINT32 OsRingbufWriteLoop(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
return cpSize;
}
//LOS_RingbufWrite向环形缓冲区写入数据
UINT32 LOS_RingbufWrite(Ringbuf *ringbuf, const CHAR *buf, UINT32 size)
{
UINT32 cpSize = 0;
@ -130,7 +131,7 @@ EXIT:
LOS_SpinUnlockRestore(&ringbuf->lock, intSave);
return cpSize;
}
//OsRingbufReadLinear线性读取环形缓冲区中的数据
STATIC UINT32 OsRingbufReadLinear(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
{
UINT32 cpSize, remain;
@ -153,7 +154,7 @@ STATIC UINT32 OsRingbufReadLinear(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
return cpSize;
}
//OsRingbufReadLoop循环读取环形缓冲区中的数据
STATIC UINT32 OsRingbufReadLoop(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
{
UINT32 right, cpSize;
@ -179,7 +180,7 @@ STATIC UINT32 OsRingbufReadLoop(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
return cpSize;
}
//LOS_RingbufRead从环形缓冲区读取数据
UINT32 LOS_RingbufRead(Ringbuf *ringbuf, CHAR *buf, UINT32 size)
{
UINT32 cpSize;
@ -205,7 +206,7 @@ EXIT:
LOS_SpinUnlockRestore(&ringbuf->lock, intSave);
return cpSize;
}
//LOS_RingbufInit初始化环形缓冲区
UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size)
{
if ((ringbuf == NULL) || (fifo == NULL) ||
@ -221,7 +222,7 @@ UINT32 LOS_RingbufInit(Ringbuf *ringbuf, CHAR *fifo, UINT32 size)
ringbuf->status = RBUF_INITED;
return LOS_OK;
}
//LOS_RingbufReset重置环形缓冲区
VOID LOS_RingbufReset(Ringbuf *ringbuf)
{
UINT32 intSave;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*实现信号量的操作系统内核代码主要包括信号量的创建、删除、等待Pend和释放Post等操作*/
#include "los_sem_pri.h"
#include "los_sem_debug_pri.h"
#include "los_err_pri.h"
@ -49,7 +49,7 @@ STATIC_INLINE VOID OsSemNodeRecycle(LosSemCB *semNode)
semNode->semStat = LOS_UNUSED;
LOS_ListTailInsert(&g_unusedSemList, &semNode->semList);
}
//OsSemInit()函数:用于初始化信号量管理模块,包括申请创建信号量所需要的内存空间、将信号量结构体加入到未使用链表中等
LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
{
LosSemCB *semNode = NULL;
@ -74,7 +74,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSemInit(VOID)
}
return LOS_OK;
}
//OsSemCreate函数:用于创建一个信号量,并将其加入到已使用信号量列表中
//参数count表示信号量的初始值type表示信号量的类型计数信号量或二进制信号量semHandle用于返回创建的信号量的句柄
LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsSemCreate(UINT16 count, UINT8 type, UINT32 *semHandle)
{
UINT32 intSave;
@ -109,7 +110,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsSemCreate(UINT16 count, UINT8 type, UINT32
LOS_TRACE(SEM_CREATE, semCreated->semId, type, count);
return LOS_OK;
}
//LOS_SemCreate:对外部提供的接口函数,用于创建一个计数信号量
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle)
{
if (count > LOS_SEM_COUNT_MAX) {
@ -117,7 +118,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemCreate(UINT16 count, UINT32 *semHandle)
}
return OsSemCreate(count, OS_SEM_COUNTING, semHandle);
}
//LOS_BinarySemCreate:对外部提供的接口函数,用于创建一个二进制信号量
LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle)
{
if (count > OS_SEM_BINARY_COUNT_MAX) {
@ -125,7 +126,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_BinarySemCreate(UINT16 count, UINT32 *semHandle
}
return OsSemCreate(count, OS_SEM_BINARY, semHandle);
}
//OsSemStateVerify:用于验证信号量的状态是否有效
//参数semId表示要验证的信号量的IDsemNode是指向信号量控制块的指针
STATIC_INLINE UINT32 OsSemStateVerify(UINT32 semId, const LosSemCB *semNode)
{
#ifndef LOSCFG_RESOURCE_ID_NOT_USE_HIGH_BITS
@ -137,7 +139,8 @@ STATIC_INLINE UINT32 OsSemStateVerify(UINT32 semId, const LosSemCB *semNode)
}
return LOS_OK;
}
//OsSemGetCBWithCheck:用于根据信号量句柄获取信号量的控制块
//参数semHandle表示信号量的句柄semCB是一个指向指针的指针用于返回获取到的信号量控制块
STATIC UINT32 OsSemGetCBWithCheck(UINT32 semHandle, LosSemCB **semCB)
{
if (GET_SEM_INDEX(semHandle) >= (UINT32)KERNEL_SEM_LIMIT) {
@ -147,7 +150,7 @@ STATIC UINT32 OsSemGetCBWithCheck(UINT32 semHandle, LosSemCB **semCB)
*semCB = GET_SEM(semHandle);
return LOS_OK;
}
//LOS_SemDelete:用于删除指定句柄的信号量,如果有任务正在等待该信号量,则删除失败
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SemDelete(UINT32 semHandle)
{
UINT32 intSave;
@ -184,7 +187,7 @@ OUT:
LOS_TRACE(SEM_DELETE, semHandle, ret);
return ret;
}
//LOS_SemPend:用于等待Pend一个信号量如果信号量不可用则阻塞当前任务直到信号量可用或超时。timeout表示超时时间
LITE_OS_SEC_TEXT UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout)
{
UINT32 intSave;
@ -252,7 +255,7 @@ OUT:
SCHEDULER_UNLOCK(intSave);
return ret;
}
//LOS_SemPost:用于释放Post一个信号量使其变为可用状态并唤醒等待该信号量的任务中的第一个任务
LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
{
UINT32 intSave;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*嵌入式操作系统中与任务调度相关的排序链表管理代码。包括了对排序链表的初始化、向排序链表中添加节点、从排序链表中删除节点、获取下一个超时时间等操作*/
#include "los_sortlink_pri.h"
#include "los_memory.h"
#include "los_exc.h"
@ -39,7 +39,7 @@ extern "C" {
#define OS_INVALID_VALUE 0xFFFFFFFF
#ifdef LOSCFG_BASE_CORE_USE_MULTI_LIST
//OsSortLinkInit初始化排序链表为排序链表的头节点分配内存并进行初始化
LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
{
UINT32 size;
@ -60,7 +60,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
}
return LOS_OK;
}
//OsAdd2SortLink将一个节点添加到排序链表中根据节点的超时时间计算节点在排序链表中的位置然后插入到相应位置
LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
SortLinkList *listSorted = NULL;
@ -106,7 +106,7 @@ LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, So
LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode);
}
}
//OsCheckSortLink检查排序链表是否合法排除循环引用和无效节点
LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode)
{
LOS_DL_LIST *tmp = listNode->pstPrev;
@ -122,7 +122,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const
/* delete invalid sortlink node */
OsBackTrace();
}
//OsDeleteSortLink从排序链表中删除一个节点然后更新相邻节点的超时时间
LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
LOS_DL_LIST *listObject = NULL;
@ -141,7 +141,7 @@ LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader,
}
LOS_ListDelete(&sortList->sortLinkNode);
}
//OsCalcExpierTime根据当前的排序链表游标和节点的位置计算超时时间
LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 sortIndex, UINT16 curSortIndex)
{
UINT32 expireTime;
@ -154,7 +154,7 @@ LITE_OS_SEC_TEXT STATIC INLINE UINT32 OsCalcExpierTime(UINT32 rollNum, UINT32 so
expireTime = ((rollNum - 1) << OS_TSK_SORTLINK_LOGLEN) + sortIndex;
return expireTime;
}
//OsSortLinkGetNextExpireTime获取排序链表中下一个超时时间最小的节点的超时时间
LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
{
UINT16 cursor;
@ -184,7 +184,7 @@ LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sor
return expireTime;
}
//OsSortLinkUpdateExpireTime更新排序链表中所有节点的超时时间并更新游标
LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader)
{
SortLinkList *sortList = NULL;
@ -215,7 +215,7 @@ LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttr
}
sortLinkHeader->cursor = (sortLinkHeader->cursor + sleepTicks - 1) % OS_TSK_SORTLINK_LEN;
}
//OsSortLinkGetTargetExpireTime获取目标节点的超时时间
LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
const SortLinkList *targetSortList)
{
@ -235,7 +235,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttrib
}
#else /* LOSCFG_BASE_CORE_USE_SINGLE_LIST */
//OsSortLinkInit:初始化排序链表头部
LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
{
UINT32 size;
@ -252,7 +252,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader)
LOS_ListInit(listObject);
return LOS_OK;
}
//OsAdd2SortLink:向排序链表中添加元素
LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
SortLinkList *listSorted = NULL;
@ -286,7 +286,7 @@ LITE_OS_SEC_TEXT VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, So
LOS_ListTailInsert(&listSorted->sortLinkNode, &sortList->sortLinkNode);
}
}
//OsCheckSortLink:检查排序链表的有效性,用于内部调用
LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const LOS_DL_LIST *listNode)
{
LOS_DL_LIST *tmp = listNode->pstPrev;
@ -302,7 +302,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsCheckSortLink(const LOS_DL_LIST *listHead, const
/* delete invalid sortlink node */
OsBackTrace();
}
//OsDeleteSortLink:从排序链表中删除指定元素
LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList)
{
LOS_DL_LIST *listObject = NULL;
@ -319,7 +319,7 @@ LITE_OS_SEC_TEXT VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader,
}
LOS_ListDelete(&sortList->sortLinkNode);
}
//OsSortLinkGetNextExpireTime:获取排序链表中下一个到期的时间
LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader)
{
UINT32 expireTime = OS_INVALID_VALUE;
@ -333,7 +333,7 @@ LITE_OS_SEC_TEXT UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sor
}
return expireTime;
}
//OsSortLinkUpdateExpireTime:更新排序链表中到期时间
LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader)
{
SortLinkList *sortList = NULL;
@ -349,7 +349,7 @@ LITE_OS_SEC_TEXT VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttr
ROLLNUM_SUB(sortList->idxRollNum, sleepTicks - 1);
}
}
//OsSortLinkGetTargetExpireTime:获取指定排序链表元素的到期时间
LITE_OS_SEC_TEXT_MINOR UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
const SortLinkList *targetSortList)
{

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//栈
#include "securec.h"
#include "los_stackinfo_pri.h"
#ifdef LOSCFG_SHELL
@ -35,7 +35,7 @@
const StackInfo *g_stackInfo = NULL;
UINT32 g_stackNum;
//OsStackWaterLineGet:获取栈的使用情况
UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed)
{
UINT32 size;
@ -53,20 +53,20 @@ UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop,
return LOS_NOK;
}
}
//OsExcStackInfoReg:注册异常栈信息
VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum)
{
g_stackInfo = stackInfo;
g_stackNum = stackNum;
}
//OsStackInit:初始化任务栈
VOID OsStackInit(VOID *stacktop, UINT32 stacksize)
{
/* initialize the task stack, write magic num to stack top */
(VOID)memset_s(stacktop, stacksize, (INT32)OS_STACK_INIT, stacksize);
*((UINTPTR *)stacktop) = OS_STACK_MAGIC_WORD;
}
//OsGetStackInfo:获取栈信息
VOID OsGetStackInfo(const StackInfo **stackInfo, UINT32 *stackNum)
{
*stackInfo = g_stackInfo;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*软件定时器的实现,涉及软件定时器的创建、启动、停止、删除等操作*/
#include "los_swtmr_pri.h"
#include "los_sortlink_pri.h"
#include "los_queue_pri.h"
@ -52,6 +52,7 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_swtmrSpin);
* Description: Start Software Timer
* Input : swtmr --- Need to start software timer
*/
//OsSwtmrStart启动软件定时器
LITE_OS_SEC_TEXT VOID OsSwtmrStart(LosSwtmrCB *swtmr)
{
if ((swtmr->overrun == 0) && ((swtmr->mode == LOS_SWTMR_MODE_ONCE) ||
@ -75,13 +76,14 @@ LITE_OS_SEC_TEXT VOID OsSwtmrStart(LosSwtmrCB *swtmr)
* Description: Delete Software Timer
* Input : swtmr --- Need to delete software timer, When using, Ensure that it can't be NULL.
*/
//OsSwtmrDelete删除软件定时器
STATIC INLINE VOID OsSwtmrDelete(LosSwtmrCB *swtmr)
{
/* insert to free list */
LOS_ListTailInsert(&g_swtmrFreeList, &swtmr->sortList.sortLinkNode);
swtmr->state = OS_SWTMR_STATUS_UNUSED;
}
//OsSwtmrUpdate更新软件定时器
STATIC INLINE VOID OsSwtmrUpdate(LosSwtmrCB *swtmr)
{
if (swtmr->mode == LOS_SWTMR_MODE_ONCE) {
@ -101,6 +103,7 @@ STATIC INLINE VOID OsSwtmrUpdate(LosSwtmrCB *swtmr)
}
#ifndef LOSCFG_BASE_CORE_SWTMR_IN_ISR
//OsSwtmrTask软件定时器任务处理函数用于处理定时器超时事件
LITE_OS_SEC_TEXT VOID OsSwtmrTask(VOID)
{
UINT32 ret, swtmrHandlerQueue;
@ -136,7 +139,7 @@ BOOL IsSwtmrTask(UINT32 taskId)
return FALSE;
}
#endif
//OsSwtmrTaskCreate创建软件定时器任务
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
{
UINT32 ret, swtmrTaskId;
@ -161,7 +164,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrTaskCreate(VOID)
return ret;
}
#endif
//OsSwtmrInit软件定时器初始化
LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
{
UINT32 size;
@ -209,6 +212,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsSwtmrInit(VOID)
* Description: Tick interrupt interface module of software timer
* Return : LOS_OK on success or error code on failure
*/
//OsSwtmrScan扫描软件定时器
LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
{
SortLinkList *sortList = NULL;
@ -277,6 +281,7 @@ LITE_OS_SEC_TEXT VOID OsSwtmrScan(VOID)
* Description: Get next timeout
* Return : Count of the Timer list
*/
//OsSwtmrGetNextTimeout获取下一个超时时间
LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
{
return OsSortLinkGetNextExpireTime(&OsPercpuGet()->swtmrSortLink);
@ -286,6 +291,7 @@ LITE_OS_SEC_TEXT UINT32 OsSwtmrGetNextTimeout(VOID)
* Description: Stop of Software Timer interface
* Input : swtmr --- the software timer control handler
*/
//OsSwtmrStop停止软件定时器
LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(LosSwtmrCB *swtmr)
{
SortLinkAttribute *sortLinkHeader = NULL;
@ -309,6 +315,7 @@ LITE_OS_SEC_TEXT STATIC VOID OsSwtmrStop(LosSwtmrCB *swtmr)
* Description: Get next software timer expiretime
* Input : swtmr --- the software timer control handler
*/
//获取指定软件定时器的剩余时间
LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const LosSwtmrCB *swtmr)
{
SortLinkAttribute *sortLinkHeader = NULL;
@ -325,7 +332,7 @@ LITE_OS_SEC_TEXT STATIC UINT32 OsSwtmrTimeGet(const LosSwtmrCB *swtmr)
return OsSortLinkGetTargetExpireTime(sortLinkHeader, &swtmr->sortList);
}
//创建一个软件定时器
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
UINT8 mode,
SWTMR_PROC_FUNC handler,
@ -377,7 +384,7 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval,
return LOS_OK;
}
//启动一个软件定时器
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId)
{
LosSwtmrCB *swtmr = NULL;
@ -421,7 +428,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStart(UINT16 swtmrId)
LOS_TRACE(SWTMR_START, swtmr->timerId, swtmr->mode, swtmr->overrun, swtmr->interval, swtmr->expiry);
return ret;
}
//停止一个软件定时器
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId)
{
LosSwtmrCB *swtmr = NULL;
@ -461,7 +468,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrStop(UINT16 swtmrId)
LOS_TRACE(SWTMR_STOP, swtmr->timerId);
return ret;
}
//获取一个软件定时器的剩余时间
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick)
{
LosSwtmrCB *swtmr = NULL;
@ -502,7 +509,7 @@ LITE_OS_SEC_TEXT UINT32 LOS_SwtmrTimeGet(UINT16 swtmrId, UINT32 *tick)
SWTMR_UNLOCK(intSave);
return ret;
}
//删除一个软件定时器
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrId)
{
LosSwtmrCB *swtmr = NULL;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*时钟模块:主要包括系统时钟的初始化、时钟中断处理函数、获取系统tick数等功能*/
#include "los_tick_pri.h"
#include "los_swtmr_pri.h"
#include "los_task_pri.h"
@ -52,6 +52,7 @@ STATIC WAKEUPFROMINTHOOK g_tickWakeupHook = NULL;
/*
* Description : Tick interruption handler
*/
//OsTickHandler函数时钟中断处理函数用于处理时钟中断事件。
LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
{
UINT32 intSave;
@ -76,7 +77,7 @@ LITE_OS_SEC_TEXT VOID OsTickHandler(VOID)
OsSwtmrScan();
#endif
}
//OsTickInit初始化系统时钟
LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond)
{
if ((systemClock == 0) ||
@ -88,12 +89,12 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond
return LOS_OK;
}
//启动系统时钟
LITE_OS_SEC_TEXT_INIT VOID OsTickStart(VOID)
{
HalClockStart();
}
//LOS_TickCountGet函数获取系统tick数
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
{
UINT32 intSave;
@ -109,12 +110,12 @@ LITE_OS_SEC_TEXT_MINOR UINT64 LOS_TickCountGet(VOID)
return tick;
}
//LOS_CyclePerTickGet函数获取每个tick所对应的CPU周期数
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_CyclePerTickGet(VOID)
{
return g_sysClock / KERNEL_TICK_PER_SECOND;
}
//LOS_GetCpuCycle函数获取CPU周期数
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt)
{
UINT64 cycle;
@ -129,7 +130,7 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt)
/* get the low 32 bits */
*lowCnt = (UINT32)(cycle & 0xFFFFFFFFULL);
}
//LOS_CurrNanosec函数获取当前的纳秒数
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
{
UINT64 nanos;
@ -137,7 +138,7 @@ LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
nanos = HalClockGetCycles() * (OS_SYS_NS_PER_SECOND / OS_SYS_NS_PER_MS) / (g_sysClock / OS_SYS_NS_PER_MS);
return nanos;
}
//LOS_MS2Tick函数将毫秒转换为tick数
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec)
{
UINT64 delaySec;
@ -149,17 +150,17 @@ LITE_OS_SEC_TEXT_MINOR UINT32 LOS_MS2Tick(UINT32 millisec)
delaySec = (UINT64)millisec * KERNEL_TICK_PER_SECOND;
return (UINT32)((delaySec + OS_SYS_MS_PER_SECOND - 1) / OS_SYS_MS_PER_SECOND);
}
//LOS_Tick2MS函数将tick数转换为毫秒数
LITE_OS_SEC_TEXT_MINOR UINT32 LOS_Tick2MS(UINT32 tick)
{
return (UINT32)(((UINT64)tick * OS_SYS_MS_PER_SECOND) / KERNEL_TICK_PER_SECOND);
}
//LOS_Udelay函数微秒级延迟函数
LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs)
{
HalDelayUs(usecs);
}
//LOS_Mdelay函数毫秒级延迟函数
LITE_OS_SEC_TEXT_MINOR VOID LOS_Mdelay(UINT32 msecs)
{
UINT32 delayUs = (UINT32_MAX / OS_SYS_US_PER_MS) * OS_SYS_US_PER_MS;

Loading…
Cancel
Save