高级会员

- 积分
- 566
- 金钱
- 566
- 注册时间
- 2016-9-28
- 在线时间
- 158 小时
|
1. 声明变量
satic uint8_t ucVar[5] = {0};
QueueHandle_t xQueue;
2. 创建消息队列, 消息个数为:1
static void AppTask_xQueueObject (void)
{
xQueue = xQueueCreate(1, sizeof(uint8_t));
if( xQueue != NULL )
{
printf(" Create xQueue: sucess \r\n");
}
}
3. 创建两个Task,一个用于发送消息,一个用于监听消息
void vTask1( void *pvParameters )
{
uint8_t ucRecieve = 0;
while(1)
{
if( xQueue != NULL )
{
xQueueReceive( xQueue, &ucRecieve, portMAX_DELAY);
if( ucRecieve == 1 ) //判断是否收到响应消息
{
printf(" Task2 is running, ucRecieve = %d\r\n", ucRecieve);
}
}
}
}
void vTask2( void *pvParameters )
{
portTickType xLastWakeTime;
const portTickType xFrequency = 100;
ucVar[0] = 1;
/* 获取系统当前时间 */
xLastWakeTime = xTaskGetTickCount();
while(1)
{
vTaskDelayUntil( &xLastWakeTime, xFrequency );
xQueueSend( xQueue, ( void * ) &ucVar[0], ( portTickType ) 10 );
}
}
|
|