Skip to content

Commit a43c7c6

Browse files
committed
feat: Allow configuration of espnow_main task core affinity, priority, and stack size
Closes #147
1 parent 26313ea commit a43c7c6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/espnow/include/espnow.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ typedef struct {
9696
bool sec_data : 1; /**< Enable or disable security data */
9797
uint32_t reserved2 : 18; /**< Reserved */
9898
} receive_enable; /**< Set 1 to enable receiving the corresponding ESP-NOW data type */
99+
struct {
100+
uint32_t stack_size_bytes; /**< Task stack size in bytes. Increase this if you perform more work in the callbacks. */
101+
int32_t core_id; /**< Task core ID, tskNO_AFFINITY means not pinned to a core. */
102+
uint8_t priority; /**< Task priority, tskIDLE_PRIORITY is the lowest priority */
103+
} task_config; /**< Task configuration for the espnow_main task. */
99104
} espnow_config_t;
100105

101106
#define ESPNOW_INIT_CONFIG_DEFAULT() { \
@@ -124,6 +129,11 @@ typedef struct {
124129
.sec_data = 0, \
125130
.reserved2 = 0, \
126131
}, \
132+
.task_config = { \
133+
.stack_size_bytes = 4096, \
134+
.priority = tskIDLE_PRIORITY + 1, \
135+
.core_id = tskNO_AFFINITY, \
136+
}, \
127137
}
128138

129139
/**

src/espnow/src/espnow.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,12 @@ esp_err_t espnow_init(const espnow_config_t *config)
10941094
ESP_LOGI(TAG, "mac: " MACSTR ", version: %d", MAC2STR(ESPNOW_ADDR_SELF), ESPNOW_VERSION);
10951095

10961096
ESP_LOGI(TAG, "Enable main task");
1097-
xTaskCreate(espnow_main_task, "espnow_main", 4096, NULL, tskIDLE_PRIORITY + 1, NULL);
1097+
xTaskCreatePinnedToCore(espnow_main_task, "espnow_main",
1098+
g_espnow_config->task_config.stack_size_bytes,
1099+
NULL,
1100+
g_espnow_config->task_config.priority,
1101+
NULL,
1102+
g_espnow_config->task_config.core_id);
10981103

10991104
return ESP_OK;
11001105
}

0 commit comments

Comments
 (0)