有用FreeRTOS的朋友吗,怎样精确定时调用一个task

发布网友 发布时间:2022-04-20 14:39

我来回答

1个回答

热心网友 时间:2023-07-21 22:20

vTaskDelay很难实现的,不过有个vTaskDelayUntill可以满足。如下面的例子:
static void vTempTask(void* pvParameters)
{
uint8_t msb;
uint16_t samplecount = 0;
uint16_t xLastWakeTime = xTaskGetTickCount();
/* The display period is 1000 ticks, about 1s */
const uint16_t xWakePeriod = 1000;
/* Initialize the uart port, and the temperature sensor */
uart0_init(UART0_CONFIG_1MHZ_115200);
ds1722_init();
ds1722_set_res(8);
ds1722_sample_cont();
/* Infinite loop */
while(1)
{
/* Read the sensor and increment the sample count */
msb = ds1722_read_MSB();
samplecount++;
/* Print the result on the uart port */
printf("Sample #%u: temperature = %u C\r\n", samplecount, msb);
/* Block until xWakePeriod ticks since previous call */
vTaskDelayUntil(&xLastWakeTime, xWakePeriod);
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com