I have a program that has a timer interrupt with each tick is 1us. The timer interrupt triggers xSemphoreGiveFromISR to ADS1256_Collect task that simply toggles a GPIO (see code below)
The below is the code:
Code: Select all
#include <stddef.h>
#include "esp_intr_alloc.h"
#include "esp_attr.h"
#include "driver/timer.h"
#include "esp_log.h"
#include "esp_err.h"
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_system.h"
#include <stdlib.h>
#include <string.h>
#include "driver/spi_master.h"
#include "soc/gpio_struct.h"
#include "rom/ets_sys.h"
#include <time.h>
#include <errno.h>
#include "driver/gpio.h"
#include "esp_log.h"
#include "freertos/semphr.h"
static bool FLAG = 0;
SemaphoreHandle_t xSemaphore = NULL;
static intr_handle_t s_timer_handle;
static void timer_isr(void* spi)
{
// This resets the timer interrupt -- don't mess with this unless you
// know what you're doing or want to break things
TIMERG0.int_clr_timers.t0 = 1;
TIMERG0.hw_timer[0].config.alarm_en = 1;
xSemaphoreGiveFromISR(xSemaphore, NULL);
}
void ADS1256_Collect(spi_device_handle_t spi) {
uint8_t mux[6] = {0x08,0x18,0x28,0x38,0x48,0x58};
uint8_t i =0; uint8_t reg = 0; uint8_t cmd = 0; uint8_t data = 0;
for (;;) {
//wait for the notification from the ISR
if(xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE) {
if(FLAG == 0){
gpio_set_level(5, 1); FLAG = 1;
}
else{
gpio_set_level(5,0); FLAG = 0;
}
}
}
}
// This is going to set up a hardware interrupt. Again, don't mess with this
// unless you want to break things, or you know what you're doing.
void init_timer(int timer_period_us) {
timer_config_t config = {
.alarm_en = true,
.counter_en = false,
.intr_type = TIMER_INTR_LEVEL,
.counter_dir = TIMER_COUNT_UP,
.auto_reload = true,
.divider = 80 /* 1 us per tic */
};
timer_init(TIMER_GROUP_0, TIMER_0, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, timer_period_us);
timer_enable_intr(TIMER_GROUP_0, TIMER_0);
timer_isr_register(TIMER_GROUP_0, TIMER_0, &timer_isr, NULL, 0, &s_timer_handle);
timer_start(TIMER_GROUP_0, TIMER_0);
}
void app_main(void)
{
gpio_set_direction(5, GPIO_MODE_OUTPUT);
gpio_set_level(5, 0);
xSemaphore = xSemaphoreCreateBinary();
xTaskCreate(ADS1256_Collect, "ADS1256_Collect", 2048, NULL, 10, NULL);
init_timer(10000);
}
Why is this happening and how can I speed up the timer interrupt trigger? Maybe 200Hz.
Thank you