用gptimer_sed_raw_count()设定计数值为130,但定时中断间隔依然没有变化,初始化设置为156.程序后面用gptimer_get_raw_count读取设置后计数值既不是156,也不是130,而是在140上下变化比较随机的一个值。我的本意是在程序运行中可以根据需要修改定时中断的间隔时间。详见代码:
void uart_echo_task(void *pvParameters) {
uint8_t* data = (uint8_t*)malloc(BUF_SIZE);
if (data == NULL) {
ESP_LOGE("uart_echo_task", "Failed to allocate memory for RX buffer");
vTaskDelete(NULL); // 如果内存分配失败,则删除这个任务
}
while (1) {
// 持续读取数据
int len = uart_read_bytes(UART_NUM_1, data, BUF_SIZE, 20 / portTICK_PERIOD_MS);
if (len > 0) {
ESP_LOGI("uart_echo_task", "Received %d bytes: '%.*s'", len, len, data);
// 测试阶段或特定条件下发送确认或响应
if (data[0] == 'f') {
uart_write_bytes(UART_NUM_1, "Freq", 5);
esp_err_t err = gptimer_set_raw_count(timer_handle, 130);
if (err == ESP_OK) {
printf("GPTimer raw count set successfully.\n");
uint64_t count_value;
gptimer_get_raw_count(timer_handle, &count_value);
printf("NewCount_value:%llu.\n",count_value);
} else if (err == ESP_ERR_INVALID_ARG) {
printf("Failed to set GPTimer raw count due to invalid argument.\n");
} else {
printf("Failed to set GPTimer raw count due to other error.\n");
}
}
else if (data[0] == 'p') {
uart_write_bytes(UART_NUM_1, "Phase", 6);
}
// 将原始数据发送回
uart_write_bytes(UART_NUM_1, (const char *)data, len);
}
}
free(data);
}