本帖最后由 suxilong 于 2019-3-7 19:05 编辑
有个需求,想实现, 让一个任务等待一个信号量,信号量来了解除阻塞,处理消息。然后等待下一个信号量的到来
但是一直到尾 都打印 “GIVE NG”
#include "FreeRTOS.h"
#include "semphr.h"
#include "projdefs.h"
#include "timers.h"
static TaskHandle_t task_handles;
TimerHandle_t timer_hadles;
SemaphoreHandle_t run_semaphore;
static void timer_generate(void)
{
//10ms 跑一次 给出一下信号
if(xSemaphoreGive( run_semaphore ) != pdTRUE)
{
OUT_LOG_I("GIVE NG");
}
}
void task(void)
{
// 创建信息量
run_semaphore = xSemaphoreCreateBinary();
if( run_semaphore != NULL )
{
OUT_LOG_I("run_semaphore ok");
}
for (;;)
{
//等待信号量到来
if( xSemaphoreTake( run_semaphore, portMAX_DELAY ) == pdTRUE )
{
Msg_Process();
}
else
{
OUT_LOG_I("=====semaphore not get====");
}
}
}
void task_create(void)
{
OUT_LOG_I("task create");
xTaskCreate(task,"task",640,NULL,1,&task_handles);
//每10ms产生一个信号量
timer_hadles = xTimerCreate("timer", TIMER_BASE/portTICK_PERIOD_MS, pdTRUE, NULL, timer_generate);
xTimerStart(timer_hadles, 0);
}
|