FREERTOS get system time
时间: 2024-05-09 19:20:25 浏览: 16
To get the system time in FreeRTOS, you can use the `xTaskGetTickCount()` function, which returns the number of ticks since the FreeRTOS scheduler started. You can then convert this value to seconds or milliseconds, depending on your needs.
Here's an example:
```c
#include "FreeRTOS.h"
#include "task.h"
void task(void *pvParameters) {
TickType_t ticks = xTaskGetTickCount();
// Convert ticks to milliseconds
uint32_t ms = ticks * portTICK_PERIOD_MS;
// Do something with the system time
// ...
vTaskDelete(NULL);
}
int main() {
// ...
xTaskCreate(task, "Task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
// ...
vTaskStartScheduler();
while (1) {
// ...
}
}
```
In this example, the `xTaskGetTickCount()` function is called in the `task` function, which is executed as a FreeRTOS task. The `TickType_t` data type is used to store the tick count, which is then converted to milliseconds using the `portTICK_PERIOD_MS` macro. Finally, the system time is used for some task-specific operation.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)