(uC/OS-II学习笔记) 事件标志……
原文出处:
http://www.cnblogs.com/hebaichuanyeah/
uC/OS-II事件标志数据结构
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_EN > 0u INT8U *OSFlagName; #endif } OS_FLAG_GRP;
事件标志,相对于事件块,是个多输入多输出的结构。通过.OSFlagFlags相应位和OSFlagNodeFlags筛选出目标输入。
程序 建立5个任务。
OS_STK Task1_Stk[512]; OS_STK Task2_Stk[512]; OS_STK Task3_Stk[512]; OS_STK Task4_Stk[512]; OS_STK Task5_Stk[512]; void main() { OSInit(); OSTaskCreate(Task_Accept , (void *)0,&Task1_Stk[511],5); OSTaskCreate(Task_Girl, (void *)0,&Task2_Stk[511],6); OSTaskCreate(Task_Woo, (void *)0,&Task3_Stk[511],7); OSTaskCreate(Task_Responsibility, (void *)0,&Task4_Stk[511],8); OSTaskCreate(Task_Meet, (void *)0,&Task5_Stk[511],9); OSStart(); }
程序,事件标志&&任务调度
void Task_Accept(void *pdata) { U8 err; U32 Count; char EDN[] = "She accepted me, and we fell in love. "; #if OS_CRITICAL_METHOD == 3 //关中断的方法为3 OS_CPU_SR cpu_sr; #endif OS_ENTER_CRITICAL(); OS_CPU_SysTickInit(100000000/OS_TICKS_PER_SEC); OS_EXIT_CRITICAL(); OSStatInit(); //统计任务 优先级最低 UART4_Init(115200); pdata = pdata; MyFlag = OSFlagCreate(0,&err); while(1) { if(OSFlagPend(MyFlag,(OS_FLAGS)12,OS_FLAG_WAIT_SET_AND,0,&err) == 12) { for(Count=0;EDN[Count];Count++) Uart4_SendByte(EDN[Count]); for(Count=0;Count<100;Count++) Uart4_SendByte(' '); OSTaskSuspend(5); } else OSTimeDly(1); } } void Task_Girl(void *pdata) { U32 Days = 0; U32 Count; U8 err; char Girl_Think[]="Girl thinks:perhaps,he is a nice guy "; pdata = pdata; while(1) { if(OSFlagPend(MyFlag,(OS_FLAGS)1,OS_FLAG_WAIT_SET_AND,0,&err) == 1) { if(Days >= 5) { for(Count=0;Girl_Think[Count];Count++) Uart4_SendByte(Girl_Think[Count]); for(Count=0;Count<100;Count++) Uart4_SendByte(' '); OSFlagPost(MyFlag,(OS_FLAGS)8,OS_FLAG_SET,&err); OSTaskSuspend(6); //OSTimeDly(100); } else { Days++; OSTimeDly(100); } } else OSTimeDly(1); } } void Task_Woo(void *pdata) { U16 Days=0; U16 Count; U8 err; char Woo_str[]= " I fell in love with this girl.I decide,I should be woo this girl desperately. "; pdata = pdata; while(1) { if(OSFlagPend(MyFlag,(OS_FLAGS)3,OS_FLAG_WAIT_SET_AND,0,&err) == 3) { if(Days >= 5) { for(Count=0;Woo_str[Count];Count++) Uart4_SendByte(Woo_str[Count]); for(Count=0;Count<100;Count++) Uart4_SendByte(' '); OSFlagPost(MyFlag,(OS_FLAGS)4,OS_FLAG_SET,&err); OSTaskSuspend(7); } else { Days++; OSTimeDly(100); } } else OSTimeDly(1); } } void Task_Responsibility(void *pdata) { U16 Days = 0; U16 Count; U8 err; char Responsibility_str[]= " I feel,I have the ability to shoulder the responsibility of protecting a girl. "; pdata = pdata; while(1) { if(Days>=10) { for(Count=0;Responsibility_str[Count];Count++) Uart4_SendByte(Responsibility_str[Count]); for(Count=0;Count<100;Count++) Uart4_SendByte(' '); OSFlagPost(MyFlag,0x02,OS_FLAG_SET,&err); OSTaskSuspend(8); } else Days++; OSTimeDly(100); } } void Task_Meet(void *pdata) { U16 Days = 0; U16 Count; U8 err; char Meetstr[]= " Today,I met a pretty girl. "; pdata = pdata; while(1) { if(Days>=10) { for(Count=0;Meetstr[Count];Count++) Uart4_SendByte(Meetstr[Count]); for(Count=0;Count<100;Count++) Uart4_SendByte(' '); OSFlagPost(MyFlag,0x01,OS_FLAG_SET,&err); OSTaskSuspend(9); } else Days++; OSTimeDly(100); } }