内核对象

内核对象包括信号量、互斥信号量、消息队列和事件标志组

UCOSIII中允许任务同时等待多个信号量和多个消息队列

主结构体

typedef struct os_pend_data OS_PEND_DATA;
struct os_pend_data {
OS_PEND_DATA *PrevPtr;
OS_PEND_DATA *NextPtr;
OS_TCB *TCBPtr;
OS_PEND_OBJ *PendObjPtr;
OS_PEND_OBJ *RdyObjPtr;
void *RdyMsgPtr;
OS_MSG_SIZE RdyMsgSize;
CPU_TS RdyTS;
};

API函数

OS_OBJ_QTY OSPendMulti (OS_PEND_DATA *p_pend_data_tbl,
OS_OBJ_QTY tbl_size,
OS_TICK timeout,
OS_OPT opt,
OS_ERR *p_err);

应用举例

#define CORE_OBJ_NUM    3   //内核对象个数,一共3个:2个信号量和一个消息队列
OS_SEM Test_Sem1; //信号量1
OS_SEM Test_Sem2; //信号量2
OS_Q Test_Q; //消息队列 void task1(void *p_arg)
{
while(1)
{
OSSemPost(&Test_Sem1,OS_OPT_POST_1,&err);//发送信号量1
printf("task1 OSSemPost Test_Sem1 here\r\n"); OSSemPost(&Test_Sem2,OS_OPT_POST_1,&err);//发送信号量2
printf("task1 OSSemPost Test_Sem2 here\r\n"); msg_num++;
sprintf((char*)pbuf,"ALIENTEK %d",msg_num);
//发送消息
OSQPost((OS_Q* )&Test_Q,
(void* )pbuf,
(OS_MSG_SIZE)10,
(OS_OPT )OS_OPT_POST_FIFO,
(OS_ERR* )&err);
printf("task1 OSSemPost Test_Q here\r\n"); OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_PERIODIC,&err);
}
} void task2(void *p_arg)
{
OS_OBJ_QTY index;
OS_PEND_DATA pend_multi_tbl[CORE_OBJ_NUM]; pend_multi_tbl[0].PendObjPtr=(OS_PEND_OBJ*)&Test_Sem1;
pend_multi_tbl[1].PendObjPtr=(OS_PEND_OBJ*)&Test_Sem2;
pend_multi_tbl[2].PendObjPtr=(OS_PEND_OBJ*)&Test_Q; while(1)
{
index=OSPendMulti((OS_PEND_DATA* )pend_multi_tbl,
(OS_OBJ_QTY )CORE_OBJ_NUM, //内核数量
(OS_TICK )0,
(OS_OPT )OS_OPT_PEND_BLOCKING,
(OS_ERR* )&err);
printf("task2 OSPendMulti index %d\r\n", index); OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_PERIODIC,&err); //延时1s
}
}

实验现象

UCOSIII等待多个内核对象-LMLPHP

05-23 02:30