发布网友 发布时间: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);
}
}