创建一个任务:
OSTaskCreate((OS_TCB * )&Main_TaskTCB,
(CPU_CHAR * )"Main task",
(OS_TASK_PTR )main_task,
(void * )0,
(OS_PRIO )MAIN_TASK_PRIO,
(CPU_STK * )&MAIN_TASK_STK[0],
(CPU_STK_SIZE)MAIN_STK_SIZE/10,
(CPU_STK_SIZE)MAIN_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )0,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
创建一个定时器 :OS_TMR tmr1;
OSTmrCreate((OS_TMR *)&tmr1,
(CPU_CHAR *)"tmr1",
(OS_TICK )0,
(OS_TICK )50,
(OS_OPT )OS_OPT_TMR_PERIODIC,
(OS_TMR_CALLBACK_PTR)tmr1_callback,
(void *)0,
(OS_ERR *)&err);
定时器回调函数:
void tmr1_callback(void *p_tmr,void *p_arg)
创建一个互斥信号量:OS_MUTEX TEST_MUTEX;
创建一个信号量: OS_SEM MY_SEM;
请求信号量:OSSemPend(&MY_SEM,0,OS_OPT_PEND_BLOCKING,0,&err);
memcpy(share_resource,task2_str,sizeof(task2_str));
发送信号量:OSSemPost (&MY_SEM,OS_OPT_POST_1,&err);
OSSemPost发送一次信号量MY_SEM.Ctr++;
OSSemPend请求一次信号量MY_SEM.Ctr--;当OSSemPend请求一次后,当再次运行到到该函数时,如果没有OSSemPost则阻塞到该地方,
任务内嵌信号量:
请求信号量: OSTaskSemPend(0,OS_OPT_PEND_BLOCKING,0,&err);
发送信号量: OSTaskSemPost(&Task2_TaskTCB,OS_OPT_POST_NONE,&err);
创建一个消息队列 :OS_Q DATA_Msg;
消息队列剩余的个数:(总的-用的)DATA_Msg.MsgQ.NbrEntriesSize-DATA_Msg.MsgQ.NbrEntries
发送消息:
OSQPost((OS_Q* )&KEY_Msg,
(void* )&key,
(OS_MSG_SIZE)1,
(OS_OPT )OS_OPT_POST_FIFO,
(OS_ERR* )&err);
请求消息:
key=OSQPend((OS_Q* )&KEY_Msg,
(OS_TICK )0,
(OS_OPT )OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE* )&size,
(CPU_TS* )0,
(OS_ERR* )&err);
事件标志组:
#define KEY0_FLAG 0x01
#define KEY1_FLAG 0x02
#define KEYFLAGS_VALUE 0X00
OS_FLAG_GRP EventFlags;
flags_num=OSFlagPost((OS_FLAG_GRP*)&EventFlags,
(OS_FLAGS )KEY0_FLAG,
(OS_OPT )OS_OPT_POST_FLAG_SET,
(OS_ERR* )&err);
flags_num=OSFlagPost((OS_FLAG_GRP*)&EventFlags,
(OS_FLAGS )KEY1_FLAG,
(OS_OPT )OS_OPT_POST_FLAG_SET,
(OS_ERR* )&err);
OSFlagPend((OS_FLAG_GRP*)&EventFlags,
(OS_FLAGS )KEY0_FLAG+KEY1_FLAG,
(OS_TICK )0,
(OS_OPT )OS_OPT_PEND_FLAG_SET_ALL+OS_OPT_PEND_FLAG_CONSUME,
(CPU_TS* )0,
(OS_ERR* )&err);