FreeRTOS tickrate set to 250, CPU clock frequency set to 80MHZ in 'make menuconfig'
Code: Select all
#include "common.h"
#include "xtensa/core-macros.h"
#include "cct.h"
#include "sdkconfig.h"
#define CCT_TICKS_PER_US CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ
static uint32_t cctMarker;
void cct_SetMarker(void) {
cctMarker = XTHAL_GET_CCOUNT();
}
uint32_t cct_ElapsedTimeUs(void) {
uint32_t now = XTHAL_GET_CCOUNT();
return (cctMarker <= now ?
((now - cctMarker)+CCT_TICKS_PER_US/2)/CCT_TICKS_PER_US :
(now + (0xFFFFFFFF - cctMarker) + CCT_TICKS_PER_US/2)/CCT_TICKS_PER_US);
}
Code: Select all
xTaskCreatePinnedToCore(&imu_task, "imutask", 2048, NULL, 20, NULL, 0);
Code: Select all
ESP_LOGI(TAG, "imu task started");
ESP_LOGI(TAG, "portTICK_PERIOD_MS = %d", portTICK_PERIOD_MS);
ESP_LOGI(TAG, "CCT_TICKS_PER_US = %d", CCT_TICKS_PER_US);
cct_SetMarker();
vTaskDelay(4 / portTICK_PERIOD_MS);
uint32_t eus = cct_ElapsedTimeUs();
ESP_LOGI(TAG, "vTaskDelay(4ms) = cct %dus", eus);
Code: Select all
I (1518) main: imu task started
I (1518) main: portTICK_PERIOD_MS = 4
I (1526) main: CCT_TICKS_PER_US = 80
I (1534) main: vTaskDelay(4ms) = cct 1710us