System Tick
时间: 2024-02-10 21:46:03 浏览: 25
System Tick(系统滴答)是指一种在微控制器中常用的系统定时器。在ARM Cortex-M微控制器中,它通常被称为SysTick定时器。它可以用来产生中断,并且可以用来实现精确的时间测量和延时。SysTick定时器通常由内部时钟源驱动,并且可以被配置为在不同的时间间隔内产生中断。例如,在一些应用中,SysTick定时器可以被配置为每个1毫秒产生一次中断,以便处理各种系统任务。
相关问题
FREERTOS get system time
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.
esp32 tick 延时函数
ESP32中的延时函数有两种:vTaskDelay()和delay()。
1. vTaskDelay()函数是FreeRTOS中的一个任务延时函数,它可以使当前任务进入阻塞状态并延时一段时间。使用该函数需要包含头文件 "freertos/FreeRTOS.h"。
示例代码如下:
```c
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void app_main(void)
{
vTaskDelay(1000 / portTICK_PERIOD_MS); // 延时1秒
}
```
2. delay()函数是ESP32官方库提供的一个延时函数,它可以以毫秒为单位进行延时。使用该函数需要包含头文件 "esp_system.h"。
示例代码如下:
```c
#include "esp_system.h"
void app_main(void)
{
delay(1000); // 延时1秒
}
```
使用vTaskDelay()函数时需要注意,它是一个阻塞函数,会阻塞当前任务的执行,所以在使用时需要确保当前任务是一个FreeRTOS任务。而delay()函数是一个非阻塞函数,可以在任何情况下使用。
另外,需要注意的是,上述两个延时函数都是按照当前系统的时钟周期进行延时计算的,所以需要根据实际情况进行调整。