问下,当使用API 函数 OSSemPost()会引发任务调度吗?在原子哥的同时等待多个内核对象的实验中发现当发送信号量时并没有立即引发任务调度,而是在延时函数发生调度的,记得刚开始的时候原子哥讲过 OSSemPost()是会引发任务调度,请问这个怎么解释?
void task1_task(void *p_arg)
{
u8 key;
OS_ERR err;
u8 num;
u8 *pbuf;
static u8 msg_num;
pbuf=mymalloc(SRAMIN,10); //申请内存
while(1)
{
key = KEY_Scan(0); //扫描按键
switch(key)
{
case KEY1_PRES:
OSSemPost(&Test_Sem1,OS_OPT_POST_1,&err);//发送信号量1
break;
case KEY0_PRES:
OSSemPost(&Test_Sem2,OS_OPT_POST_1,&err);//发送信号量2
//break ;
case WKUP_PRES:
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);
break;
}
num++;
if(num==50)
{
num=0;
LED0=~LED0;
}
OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_PERIODIC,&err); //延时10ms
}
}
//等待多个内核对象的任务函数
void multi_task(void *p_arg)
{
u8 num;
OS_ERR err;
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);
LCD_ShowNum(147,111,index,1,16); //显示当前有几个内核对象准备好了
num++;
LCD_Fill(6,131,233,313,lcd_discolor[num%14]); //刷屏
LED1 = ~LED1;
OSTimeDlyHMSM(0,0,1,0,OS_OPT_TIME_PERIODIC,&err); //延时1s
}
}
|