|
我想在task 中take 信号量,另外 用个timer 定时10ms give 一下信号,
但是信号一直give 失败, task 里面也一直 take 不到信号
- #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);
- }
复制代码
后面我使用 tasknotify 的函数去实现,但是 也是没反应
在 config 中 开了#define configUSE_TASK_NOTIFICATIONS 1
但是就是一直阻塞没有进入Msg_Process();
- #include "FreeRTOS.h"
- #include "semphr.h"
- #include "projdefs.h"
- #include "timers.h"
- #include "task.h"
- static TaskHandle_t task_handles;
- TimerHandle_t timer_hadles;
- static void timer_generate(void)
- {
- //10ms
- xTaskNotifyGive( task_handles );
- }
- void task(void)
- {
- for (;;)
- {
- //阻塞等待 notify
- ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
- Msg_Process();
- }
- }
- void task_create(void)
- {
- OUT_LOG_I("task create");
- xTaskCreate(task,"task",640,NULL,1,&task_handles);
- //每10ms notify 一下
- timer_hadles = xTimerCreate("timer", TIMER_BASE/portTICK_PERIOD_MS, pdTRUE, NULL, timer_generate);
- xTimerStart(timer_hadles, 0);
- }
复制代码
请问如何实现 这个要求呢?
|
|