Mesh on Core 1 and critical tasks on Core0
Posted: Fri Aug 21, 2020 7:30 am
Hello,
In my hobby project I am running Painlessmesh https://gitlab.com/painlessMesh/painles ... wikis/home, a wifi mesh network of 9x ESP32 modules. My loop function looks like below
HandleTelnet is used to read data from PuTTy instead of serial port, since I only use wireless methods to download software and perform debugging.
First : Since mesh.update() is placed inside void loop(), the mesh software will be run in Core 1 since loop will always run in core1.
Is the above statement correct?
Second: I have created Timers(4)-->Interrupts(4)-->Tasks(5) chain and pinned the interrupt handler and tasks on Core0 and have confirmed that these lines of code is always run on Core 0. This also should mean that, on core 0 there are only these 5 tasks that I have pinned to core 0 along with 1x idle task on core 0.
This is correct?
Note 0 : I use all the available 4 timers TG00,01,10,11
Note 1 : interrupts passes the notification directly to Task. Code for one of the interrupt is as below.
Note 2 : To use painlessmesh, Arduino IDE is used. Arduino IDE is also use for the Core0 code but only FreeRTOS methods are used and not Arduino libraries are used.
Below is the code for one of the interrupts.
The timer for the above interrupt is created as shown below.
The only line in my Void Setup() that kick-starts work on core 0 is the line app_main();
app_main(); function looks like below,
Third : When I test the mesh network and Core0 code seperately, i.e first run only mesh code and check that it works. Then run only the Core 0 code(Without mesh code) and check that it works, and yes it works as expected. As you see in the image below the digital outputs are fired precisely every 100us for a long time without large deviations. See image _ Core0_Tasks_No_mesh
Fourth : When I put these two codes together then Core0 tasks are disturbed very much and I no longer observe the fine digital outputs firing anymore. It seems that the Core0 tasks are somehow disturbed by painlessmesh mesh network. See image _Core0_Tasks_With_Mesh. This is where I need help. I need to create precise digital outputs and also be able to communicate with other ESP32 via wifi mesh
1. What can be disturbing the Core0 tasks?
2. Could painless mesh be using the same timers as I am using and might this be the cause of the strange behavior.
3. Is it better to use esp_timer_create() to create timers instead of how I do above ?
4. Is there a way to know, if Core0 also runs other hidden tasks that I am not aware of. like for example, a task that is run by painlessmesh?
5. Should I change my approach to get this right? (Like better coding methods, or use other functions, like Semaphores instead of task notifications, or using EnterCritical() Macros while in interrupts etc?)
Appreciate your help with this.
Thank you.
In my hobby project I am running Painlessmesh https://gitlab.com/painlessMesh/painles ... wikis/home, a wifi mesh network of 9x ESP32 modules. My loop function looks like below
HandleTelnet is used to read data from PuTTy instead of serial port, since I only use wireless methods to download software and perform debugging.
Code: Select all
void loop() {
handleTelnet();
mesh.update();
}
Is the above statement correct?
Second: I have created Timers(4)-->Interrupts(4)-->Tasks(5) chain and pinned the interrupt handler and tasks on Core0 and have confirmed that these lines of code is always run on Core 0. This also should mean that, on core 0 there are only these 5 tasks that I have pinned to core 0 along with 1x idle task on core 0.
This is correct?
Note 0 : I use all the available 4 timers TG00,01,10,11
Note 1 : interrupts passes the notification directly to Task. Code for one of the interrupt is as below.
Note 2 : To use painlessmesh, Arduino IDE is used. Arduino IDE is also use for the Core0 code but only FreeRTOS methods are used and not Arduino libraries are used.
Below is the code for one of the interrupts.
Code: Select all
static void IRAM_ATTR timer_tg01_isr(void *arg)
{
TIMERG0.int_clr_timers.t1 = 1;
TIMERG0.hw_timer[1].config.alarm_en = 1;
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
vTaskNotifyGiveFromISR(OnHandle_Hi, &xHigherPriorityTaskWoken );
portYIELD_FROM_ISR();
}
The timer for the above interrupt is created as shown below.
Code: Select all
void timer_tg01_initialise (int timer1_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
};
timer_init(TIMER_GROUP_0, TIMER_1, &config);
timer_set_counter_value(TIMER_GROUP_0, TIMER_1, 0);
timer_set_alarm_value(TIMER_GROUP_0, TIMER_1, timer1_period_us);
timer_enable_intr(TIMER_GROUP_0, TIMER_1);
timer_isr_register(TIMER_GROUP_0, TIMER_1, &timer_tg01_isr, NULL, 0, &s_timer01_handle);
timer_start(TIMER_GROUP_0, TIMER_1);
}
The only line in my Void Setup() that kick-starts work on core 0 is the line app_main();
app_main(); function looks like below,
Code: Select all
void app_main()
{
gpio_set_direction(GPIO_NUM_16, GPIO_MODE_OUTPUT);
gpio_set_direction(GPIO_NUM_17, GPIO_MODE_OUTPUT);
xTaskCreatePinnedToCore(timer_tg00_init_isr_Task, "timer_tg00_isr", 5000 , NULL, 6, &initialize_Hi, 0);
xTaskCreatePinnedToCore(timer_tg01_isr_Task, "timer_tg01_isr", 5000 , NULL, 5, &OnHandle_Hi, 0);
xTaskCreatePinnedToCore(timer_tg10_init_isr_Task, "timer_tg10_isr", 5000 , NULL, 6, &initialize_Lo, 0);
xTaskCreatePinnedToCore(timer_tg11_isr_Task, "timer_tg11_isr", 5000 , NULL, 5, &OnHandle_Lo, 0);
xTaskCreatePinnedToCore(zero_i_detect, "zero_i_detect", 1000 , NULL, 7, &zero_current, 0);
}
Fourth : When I put these two codes together then Core0 tasks are disturbed very much and I no longer observe the fine digital outputs firing anymore. It seems that the Core0 tasks are somehow disturbed by painlessmesh mesh network. See image _Core0_Tasks_With_Mesh. This is where I need help. I need to create precise digital outputs and also be able to communicate with other ESP32 via wifi mesh
1. What can be disturbing the Core0 tasks?
2. Could painless mesh be using the same timers as I am using and might this be the cause of the strange behavior.
3. Is it better to use esp_timer_create() to create timers instead of how I do above ?
4. Is there a way to know, if Core0 also runs other hidden tasks that I am not aware of. like for example, a task that is run by painlessmesh?
5. Should I change my approach to get this right? (Like better coding methods, or use other functions, like Semaphores instead of task notifications, or using EnterCritical() Macros while in interrupts etc?)
Appreciate your help with this.
Thank you.