Update esp32.h

Update for latest ESP32 timer specs
pull/45/head
Denis Melo 1 month ago committed by GitHub
parent c0196f31a2
commit d81f137b98
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      src/platforms/esp32.h

@ -9,6 +9,9 @@ hw_timer_t * _uclockTimer = NULL;
//portMUX_TYPE _uclockTimerMux = portMUX_INITIALIZER_UNLOCKED; //portMUX_TYPE _uclockTimerMux = portMUX_INITIALIZER_UNLOCKED;
//#define ATOMIC(X) portENTER_CRITICAL_ISR(&_uclockTimerMux); X; portEXIT_CRITICAL_ISR(&_uclockTimerMux); //#define ATOMIC(X) portENTER_CRITICAL_ISR(&_uclockTimerMux); X; portEXIT_CRITICAL_ISR(&_uclockTimerMux);
// for saving the initial clock sate
uint32_t _init_clock;
// FreeRTOS main clock task size in bytes // FreeRTOS main clock task size in bytes
#define CLOCK_STACK_SIZE 5*1024 // adjust for your needs, a sequencer with heavy serial handling should be large in size #define CLOCK_STACK_SIZE 5*1024 // adjust for your needs, a sequencer with heavy serial handling should be large in size
TaskHandle_t taskHandle; TaskHandle_t taskHandle;
@ -41,25 +44,34 @@ void clockTask(void *pvParameters)
void initTimer(uint32_t init_clock) void initTimer(uint32_t init_clock)
{ {
// save the initial clock value
_init_clock = init_clock;
// initialize the mutex for shared resource access // initialize the mutex for shared resource access
_mutex = xSemaphoreCreateMutex(); _mutex = xSemaphoreCreateMutex();
// create the clockTask // create the clockTask
xTaskCreate(clockTask, "clockTask", CLOCK_STACK_SIZE, NULL, 1, &taskHandle); xTaskCreate(clockTask, "clockTask", CLOCK_STACK_SIZE, NULL, 1, &taskHandle);
_uclockTimer = timerBegin(TIMER_ID, 80, true); //_uclockTimer = timerBegin(TIMER_ID, 80, true);
_uclockTimer = timerBegin(1000000); // Frequência de 1 MHz
// attach to generic uclock ISR // attach to generic uclock ISR
timerAttachInterrupt(_uclockTimer, &handlerISR, false); timerAttachInterrupt(_uclockTimer, &handlerISR);
//timerAttachInterrupt(_uclockTimer, &handlerISR, false);
// init clock tick time // init clock tick time
timerAlarmWrite(_uclockTimer, init_clock, true); //timerAlarmWrite(_uclockTimer, init_clock, true);
// activate it! // activate it!
timerAlarmEnable(_uclockTimer); //timerAlarmEnable(_uclockTimer);
// init and activate clock
timerAlarm(_uclockTimer, _init_clock, true, 0);
} }
void setTimer(uint32_t us_interval) void setTimer(uint32_t us_interval)
{ {
timerAlarmWrite(_uclockTimer, us_interval, true); //timerAlarmWrite(_uclockTimer, us_interval, true);
} timerAlarm(_uclockTimer, _init_clock, true, 0);
}

Loading…
Cancel
Save