esp32: init task before timer

pull/26/head v1.4.2
midilab 1 year ago
parent 0a622830b3
commit 344ce3803a
  1. 19
      src/platforms/esp32.h

@ -14,12 +14,7 @@ TaskHandle_t taskHandle;
// mutex to protect the shared resource // mutex to protect the shared resource
SemaphoreHandle_t _mutex; SemaphoreHandle_t _mutex;
// mutex control for task // mutex control for task
#define ATOMIC(X) \ #define ATOMIC(X) xSemaphoreTake(_mutex, portMAX_DELAY); X; xSemaphoreGive(_mutex);
do { \
xSemaphoreTake(_mutex, portMAX_DELAY); \
X; \
xSemaphoreGive(_mutex); \
} while (0);
// forward declaration of uClockHandler // forward declaration of uClockHandler
void uClockHandler(); void uClockHandler();
@ -45,6 +40,12 @@ void clockTask(void *pvParameters)
void initTimer(uint32_t init_clock) void initTimer(uint32_t init_clock)
{ {
// initialize the mutex for shared resource access
_mutex = xSemaphoreCreateMutex();
// create the clockTask
xTaskCreate(clockTask, "clockTask", CLOCK_STACK_SIZE, NULL, 1, &taskHandle);
_uclockTimer = timerBegin(TIMER_ID, 80, true); _uclockTimer = timerBegin(TIMER_ID, 80, true);
// attach to generic uclock ISR // attach to generic uclock ISR
@ -55,12 +56,6 @@ void initTimer(uint32_t init_clock)
// activate it! // activate it!
timerAlarmEnable(_uclockTimer); timerAlarmEnable(_uclockTimer);
// initialize the mutex for shared resource access
_mutex = xSemaphoreCreateMutex();
// create the clockTask
xTaskCreate(clockTask, "clockTask", CLOCK_STACK_SIZE, NULL, 1, &taskHandle);
} }
void setTimer(uint32_t us_interval) void setTimer(uint32_t us_interval)

Loading…
Cancel
Save