ucos-ii示例6:消息量集测试

来源:互联网 发布:淘宝平台费用是多少 编辑:程序博客网 时间:2024/05/20 07:32


ucos-ii示例6:消息量集测试


本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.


环境:

主机:WIN8

开发环境:MDK4.72

ucgui版本:3.90

ucos版本:ucos-ii

mcu: stm32f103VE


说明:

本示例中task2设置信号量集的最后2位为1,task1读取最后2位,发现是1则显示


源码:

#define TASK_STK_SIZE512/**********************************************************************静态函数**********************************************************************/static void task_start(void *pdata);static void task1(void *pdata);static void task2(void *pdata);/**********************************************************************静态变量**********************************************************************//**********************************************************************任务堆栈空间**********************************************************************/static OS_STK Task_Start_Stk[TASK_STK_SIZE];static OS_STK Task1_Stk[TASK_STK_SIZE];static OS_STK Task2_Stk[TASK_STK_SIZE];/**********************************************************************信号量集**********************************************************************/OS_FLAG_GRP *Semaphore;/**********************************************************************消息队列数组**********************************************************************/void *Msg_Group[10];char Msg_Arr[10][30];uint8_t Index_Msg_Arr = 0;/**********************************************************************函数**********************************************************************/int main(void){//初始化内核OSInit();//创建任务OSTaskCreate(task_start,(void *)0,Task_Start_Stk + TASK_STK_SIZE - 1,10);//启动任务OSStart();}/**********************************************************************任务函数**********************************************************************/static void task_start(void *pdata){uint8_t err = 0;//载入世界world_load();//设置背景色GUI_SetBkColor(0xb07c17);GUI_Clear();GUI_SetColor(GUI_BLACK);//信号量集初始化为0Semaphore = OSFlagCreate((OS_FLAGS)0,&err);//新建任务OSTaskCreate(task1,(void *)0,Task1_Stk + TASK_STK_SIZE - 1,11);OSTaskCreate(task2,(void *)0,Task2_Stk + TASK_STK_SIZE - 1,12);while(1){OSTimeDlyHMSM(0,0,3,0);}}static void task1(void *pdata){char str[30] = {0};uint8_t err = 0;while(1){//等待信号集满足条件OSFlagPend(Semaphore,(OS_FLAGS)0x3,OS_FLAG_WAIT_SET_ALL | OS_FLAG_CONSUME,0,&err);//显示sprintf(str,"task1 time:%ds",OSTimeGet());GUI_DispStringHCenterAt(str, 120, 5);WM_Exec();OSTimeDlyHMSM(0,0,1,0);}}static void task2(void *pdata){char str[30] = {0};uint8_t err = 0;while(1){//将末两位置1OSFlagPost(Semaphore,(OS_FLAGS)0x3,OS_FLAG_SET,&err);//将最后1位置1//OSFlagPost(Semaphore,(OS_FLAGS)0x1,OS_FLAG_SET,&err);//显示sprintf(str,"task2 time:%ds",OSTimeGet());GUI_DispStringHCenterAt(str, 120, 20);WM_Exec();OSTimeDlyHMSM(0,0,3,0);}}


0 0
原创粉丝点击