I try to synchronize a task with an interruption of a timer at 125us by using a semaphore (xSemaphoreGiveFromISR). The task is executed every 125us as expected until I add WIFI to my project.
Code: Select all
void SensorTask(void* pvParameter)
{
ESP_LOGI(Tag, "Start Sensor Task");
// Attempt to create a semaphore
Timer125usSemaphore = xSemaphoreCreateBinary();
timer_start(TIMER_GROUP_0, 0);
while (1)
{
if (Timer125usSemaphore != NULL)
{
if (xSemaphoreTake(Timer125usSemaphore, 0) == pdTRUE)
{
Leds_RunTask();
Sensors_RunTask();
}
}
FeedWatchdog();
}
}
void IRAM_ATTR timer_group0_isr(void* para)
{
static BaseType_t higherPriorityTaskWoken = pdFALSE;
int timer_idx = (int) para;
// Retrieve the interrupt status and the counter value
// from the timer that reported the interrupt
uint32_t intr_status = TIMERG0.int_st_timers.val;
TIMERG0.hw_timer[timer_idx].update = 1;
// After the alarm has been triggered, we need enable it again, so it is triggered the next time
TIMERG0.hw_timer[timer_idx].config.alarm_en = TIMER_ALARM_EN;
// Clear the interrupt and update the alarm time for the timer with without reload
if ((intr_status & BIT(timer_idx)) && timer_idx == TIMER_1)
{
TIMERG0.int_clr_timers.t1 = 1;
xSemaphoreGiveFromISR(Timer125usSemaphore, &higherPriorityTaskWoken);
if (higherPriorityTaskWoken != pdFALSE)
{
portYIELD_FROM_ISR();
}
}
}
Code: Select all
void WIFI_Init(void)
{
EventGroup = xEventGroupCreate();
// Initialize the TCP Stack
tcpip_adapter_init();
// Initialize the system event handler
ESP_ERROR_CHECK(esp_event_loop_init(EventHandler, NULL));
// Configure the WIFI
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config =
{
.sta =
{
.ssid = CONFIG_WIFI_SSID,
.password = CONFIG_WIFI_PASSWORD
},
};
// WIFI as Station Mode (connect to another wifi)
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
// Configure RAM as the WIFI parameters storage
//ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
ESP_ERROR_CHECK(esp_wifi_connect());
}
Thanks