Optimize event loop resource size

The event loop queue and  task stack size is optimized to be determined by config factors.

Fixes #1083
This commit is contained in:
2025-08-22 15:06:37 +03:00
parent fb4f34e895
commit e73c205e3d

View File

@@ -22,6 +22,26 @@
#include "relay_chn_core.h"
/*
Determine the event loop's queue and task stack sizes depending on
the configuration and memory requirements
*/
#if RELAY_CHN_ENABLE_TILTING == 1
#define EVENT_QUEUE_BASE_SIZE 32
#define EVENT_QUEUE_SIZE_BY_CHN 24
#define TASK_STACK_BASE_SIZE 4096
#else
#define EVENT_QUEUE_BASE_SIZE 16
#define EVENT_QUEUE_SIZE_BY_CHN 12
#define TASK_STACK_BASE_SIZE 2048
#endif
#define RELAY_CHN_EVENT_LOOP_QUEUE_SIZE \
(EVENT_QUEUE_BASE_SIZE + (EVENT_QUEUE_SIZE_BY_CHN * RELAY_CHN_COUNT))
#define RELAY_CHN_EVENT_LOOP_TASK_STACK_SIZE \
(TASK_STACK_BASE_SIZE + (RELAY_CHN_EVENT_LOOP_QUEUE_SIZE * RELAY_CHN_COUNT))
static const char *TAG = "RELAY_CHN_CORE";
@@ -99,10 +119,10 @@ esp_err_t relay_chn_init_timer(relay_chn_ctl_t *chn_ctl)
static esp_err_t relay_chn_create_event_loop()
{
esp_event_loop_args_t loop_args = {
.queue_size = RELAY_CHN_COUNT * 8,
.queue_size = RELAY_CHN_EVENT_LOOP_QUEUE_SIZE,
.task_name = "relay_chn_event_loop",
.task_priority = ESP_TASKD_EVENT_PRIO - 1,
.task_stack_size = 2048,
.task_stack_size = RELAY_CHN_EVENT_LOOP_TASK_STACK_SIZE,
.task_core_id = tskNO_AFFINITY
};
esp_err_t ret = esp_event_loop_create(&loop_args, &relay_chn_event_loop);