(OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
当满足如上条件时,即版本大于251,FLAG使能,最大FLAG值大于0时,开启FLAG初始化
FLAG相关的函数全都放在OS_FLAG.C的文件中,其功能和信号量等类似,是用来任务间通信的
代码如下
- /*
- *********************************************************************************************************
- * INITIALIZE THE EVENT FLAG MODULE
- *
- * Description: This function is called by uC/OS-II to initialize the event flag module. Your application
- * MUST NOT call this function. In other words, this function is internal to uC/OS-II.
- *
- * Arguments : none
- *
- * Returns : none
- *
- * WARNING : You MUST NOT call this function from your code. This is an INTERNAL function to uC/OS-II.
- *********************************************************************************************************
- */
- void OS_FlagInit (void)
- {
- #if OS_MAX_FLAGS == 1
- OSFlagFreeList = (OS_FLAG_GRP *)&OSFlagTbl[0]; /* Only ONE event flag */
- OSFlagFreeList->OSFlagType = OS_EVENT_TYPE_UNUSED;
- OSFlagFreeList->OSFlagWaitList = (void *)0;
- OSFlagFreeList->OSFlagFlags = (OS_FLAGS)0;
- #if OS_FLAG_NAME_SIZE > 1
- OSFlagFreeList->OSFlagName[0] = '?';
- OSFlagFreeList->OSFlagName[1] = OS_ASCII_NUL;
- #endif
- #endif
- #if OS_MAX_FLAGS >= 2
- INT16U i;
- OS_FLAG_GRP *pgrp1;
- OS_FLAG_GRP *pgrp2;
- OS_MemClr((INT8U *)&OSFlagTbl[0], sizeof(OSFlagTbl)); /* Clear the flag group table */
- pgrp1 = &OSFlagTbl[0];
- pgrp2 = &OSFlagTbl[1];
- for (i = 0; i < (OS_MAX_FLAGS - 1); i++) { /* Init. list of free EVENT FLAGS */
- pgrp1->OSFlagType = OS_EVENT_TYPE_UNUSED;
- pgrp1->OSFlagWaitList = (void *)pgrp2;
- #if OS_FLAG_NAME_SIZE > 1
- pgrp1->OSFlagName[0] = '?'; /* Unknown name */
- pgrp1->OSFlagName[1] = OS_ASCII_NUL;
- #endif
- pgrp1++;
- pgrp2++;
- }
- pgrp1->OSFlagType = OS_EVENT_TYPE_UNUSED;
- pgrp1->OSFlagWaitList = (void *)0;
- #if OS_FLAG_NAME_SIZE > 1
- pgrp1->OSFlagName[0] = '?'; /* Unknown name */
- pgrp1->OSFlagName[1] = OS_ASCII_NUL;
- #endif
- OSFlagFreeList = &OSFlagTbl[0];
- #endif
- }
OSFlagTbl[0]这是一个由数据结构
- typedef struct os_flag_grp { /* Event Flag Group */
- INT8U OSFlagType; /* Should be set to OS_EVENT_TYPE_FLAG */
- void *OSFlagWaitList; /* Pointer to first NODE of task waiting on event flag */
- OS_FLAGS OSFlagFlags; /* 8, 16 or 32 bit flags */
- #if OS_FLAG_NAME_SIZE > 1
- INT8U OSFlagName[OS_FLAG_NAME_SIZE];
- #endif
- } OS_FLAG_GRP;
构成的数组,这个数据结构构成一个OS_FLAG_GRP
包含 OSFlagType这个标志类型
void *OSFlagWaitList指针指向flag的等待任务队列的头
OSFlagFlags;这个是OS_FLAG的比特位设置,可以设置为8-16-32位。
OSFlagName[OS_FLAG_NAME_SIZE]字符串可以设置为标志名。
初始化的流程:如果最大标志值为1那么只初始化一个节点,一个OS_FLAG_GRP数据结构的初始化就完成了
如果标志位最大值大于等于2,那么就用到两个指针来初始化每一个节点。
先设置两个指向数据结构OS_FLAG_GRP的指针,分别指向下标为0和1的节点,对第一个进行初始化
将第一个指针指向的等待队列指针赋值下一个节点的地址,就构成了一个链表。
但是为什么使用指针不使用下标呢?
附加一个常用的内存初始化函数
- /*
- *********************************************************************************************************
- * CLEAR A SECTION OF MEMORY
- *
- * Description: This function is called by other uC/OS-II services to clear a contiguous block of RAM.
- *
- * Arguments : pdest is the start of the RAM to clear (i.e. write 0x00 to)
- *
- * size is the number of bytes to clear.
- *
- * Returns : none
- *
- * Notes : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
- * 2) Note that we can only clear up to 64K bytes of RAM. This is not an issue because none
- * of the uses of this function gets close to this limit.
- * 3) The clear is done one byte at a time since this will work on any processor irrespective
- * of the alignment of the destination.
- *********************************************************************************************************
- */
- void OS_MemClr (INT8U *pdest, INT16U size)
- {
- while (size > 0) {
- *pdest++ = (INT8U)0;
- size--;
- }
- }
内存的初始化也是用指针实现的,有一些函数如ralloc是否可以代替?有什么不同?
阅读(2515) | 评论(0) | 转发(0) |