[STM32F1] 关于UCOSII任务间通信的疑问,

[复制链接]
 楼主| wang12zhe 发表于 2014-7-20 15:30 | 显示全部楼层 |阅读模式
本帖最后由 wang12zhe 于 2014-7-20 15:32 编辑

void Task_BEEP(void *p_arg)
{

   (void)p_arg;
    while(1)
    {
    LED1(ON);
    OSTimeDlyHMSM(0,0,0,uLED1Time);
    LED1(OFF);
    OSTimeDlyHMSM(0,0,0,uLED1Time);
     

    BEEP(BEEP_OFF);        
   OSSemPend(Fun_Semp,10,&err);  //???óD?o?á?
                        
             BEEP(BEEP_ON);
             OSTimeDlyHMSM(0,0,1,500);

               BEEP(BEEP_OFF);        
              OSTimeDlyHMSM(0,0,1,500);

  }         
}


关于UCOSII任务间通信的疑问,
以信号量为例,代码如上,
   OSSemPend(Fun_Semp,10,&err);  
                        
             BEEP(BEEP_ON);
             OSTimeDlyHMSM(0,0,1,500);

               BEEP(BEEP_OFF);        
              OSTimeDlyHMSM(0,0,1,500);

获取信号量的超时时间为10,当因超时退出后会怎么执行呢,
是直接切换到更高优先级任务呢,还是接续执行本任务下边的代码呢
运行后没有发生信号量,蜂鸣器也会相,

是不是需要加一个判断,像这样
                        if(OS_NO_ERR==err)
                        {                                
                                        BEEP(BEEP_ON);
                                        OSTimeDlyHMSM(0,0,1,500);

                                        BEEP(BEEP_OFF);        
                                        OSTimeDlyHMSM(0,0,1,500);
                        }
lapeno 发表于 2014-7-20 21:00 | 显示全部楼层
*********************************************************************************************************
*                                           PEND ON SEMAPHORE
*
* Description: This function waits for a semaphore.
*
* Arguments  : pevent        is a pointer to the event control block associated with the desired
*                            semaphore.
*
*              timeout       is an optional timeout period (in clock ticks).  If non-zero, your task will
*                            wait for the resource up to the amount of time specified by this argument.
*                            If you specify 0, however, your task will wait forever at the specified
*                            semaphore or, until the resource becomes available (or the event occurs).
*
*              perr          is a pointer to where an error message will be deposited.  Possible error
*                            messages are:
*
*                            OS_ERR_NONE         The call was successful and your task owns the resource
*                                                or, the event you are waiting for occurred.
*                            OS_ERR_TIMEOUT      The semaphore was not received within the specified
*                                                'timeout'.
*                            OS_ERR_PEND_ABORT   The wait on the semaphore was aborted.
*                            OS_ERR_EVENT_TYPE   If you didn't pass a pointer to a semaphore.
*                            OS_ERR_PEND_ISR     If you called this function from an ISR and the result
*                                                would lead to a suspension.
*                            OS_ERR_PEVENT_NULL  If 'pevent' is a NULL pointer.
*                            OS_ERR_PEND_LOCKED  If you called this function when the scheduler is locked
*
* Returns    : none
楼主可根据函数的返回值来判断.
比如:OS_ERR_NONE,表示等待的信号发生了.OS_ERR_TIMEOUT表示信号未发生,超时了.

 楼主| wang12zhe 发表于 2014-7-21 12:28 | 显示全部楼层
lapeno 发表于 2014-7-20 21:00
**************************************************************************************************** ...

首先很感谢你的回复,
其次,我看资料的时候有这样一段话,




TT截图未命名.bmp

我有疑问的地方就是
   OSSemPend(Fun_Semp,10,&err);        
             BEEP(BEEP_ON);
             OSTimeDlyHMSM(0,0,1,500);
               BEEP(BEEP_OFF);        
              OSTimeDlyHMSM(0,0,1,500);如果任务等待时间超时后,下面的BEEP相关操作会执行吗?
根据我的理解应该不会得到执行,但测试发现却执行了。











lapeno 发表于 2014-7-22 07:33 | 显示全部楼层
加上你这个判断就不会BEEP了,不加的话超时后当然会继续往下执行。
if(OS_NO_ERR==err)
                        {                                
                                        BEEP(BEEP_ON);
                                        OSTimeDlyHMSM(0,0,1,500);

                                        BEEP(BEEP_OFF);        
                                        OSTimeDlyHMSM(0,0,1,500);
                        }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

101

主题

205

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部