Skip to content

Commit 81ee4a5

Browse files
committed
Export FreeRTOS task-related constants to header file. See cesanta/mongoose-os#554
1 parent bee6008 commit 81ee4a5

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

include/mgos_freertos.h

+27
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,35 @@
2323
#include "queue.h"
2424
#include "task.h"
2525

26+
#include "mongoose.h"
2627
#include "mgos_init.h"
2728

29+
#ifndef MGOS_TASK_STACK_SIZE_BYTES
30+
#define MGOS_TASK_STACK_SIZE_BYTES 8192
31+
#endif
32+
33+
#ifndef MGOS_TASK_PRIORITY
34+
#define MGOS_TASK_PRIORITY 5
35+
#endif
36+
37+
#ifndef MGOS_TASK_QUEUE_LENGTH
38+
#define MGOS_TASK_QUEUE_LENGTH 32
39+
#endif
40+
41+
#ifndef MGOS_MONGOOSE_MAX_POLL_SLEEP_MS
42+
#define MGOS_MONGOOSE_MAX_POLL_SLEEP_MS 1000
43+
#endif
44+
45+
#ifndef MGOS_EARLY_WDT_TIMEOUT
46+
#define MGOS_EARLY_WDT_TIMEOUT 30 /* seconds */
47+
#endif
48+
49+
#if CS_PLATFORM == CS_P_ESP32
50+
#define MGOS_TASK_STACK_SIZE_UNIT 1
51+
#else
52+
#define MGOS_TASK_STACK_SIZE_UNIT sizeof(portSTACK_TYPE)
53+
#endif
54+
2855
#ifdef __cplusplus
2956
extern "C" {
3057
#endif

src/mgos_freertos.c

+3-25
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,6 @@
3939
#include "mgos_uart_internal.h"
4040
#include "mgos_utils.h"
4141

42-
#ifndef MGOS_TASK_STACK_SIZE_BYTES
43-
#define MGOS_TASK_STACK_SIZE_BYTES 8192
44-
#endif
45-
46-
#ifndef MGOS_TASK_PRIORITY
47-
#define MGOS_TASK_PRIORITY 5
48-
#endif
49-
50-
#ifndef MGOS_TASK_QUEUE_LENGTH
51-
#define MGOS_TASK_QUEUE_LENGTH 32
52-
#endif
53-
54-
#ifndef MGOS_MONGOOSE_MAX_POLL_SLEEP_MS
55-
#define MGOS_MONGOOSE_MAX_POLL_SLEEP_MS 1000
56-
#endif
57-
58-
#ifndef MGOS_EARLY_WDT_TIMEOUT
59-
#define MGOS_EARLY_WDT_TIMEOUT 30 /* seconds */
60-
#endif
61-
6242
extern const char *build_version, *build_id;
6343
extern const char *mg_build_version, *mg_build_id;
6444

@@ -82,7 +62,6 @@ static portMUX_TYPE s_poll_spinlock = portMUX_INITIALIZER_UNLOCKED;
8262
{ \
8363
if (should_yield) portYIELD_FROM_ISR(); \
8464
}
85-
#define STACK_SIZE_UNIT 1
8665
#else
8766
#define ENTER_CRITICAL() portENTER_CRITICAL()
8867
#define EXIT_CRITICAL() portEXIT_CRITICAL()
@@ -92,7 +71,6 @@ static portMUX_TYPE s_poll_spinlock = portMUX_INITIALIZER_UNLOCKED;
9271
#define EXIT_CRITICAL_NO_ISR(from_isr) \
9372
if (!from_isr) portEXIT_CRITICAL()
9473
#define YIELD_FROM_ISR(should_yield) portYIELD_FROM_ISR(should_yield)
95-
#define STACK_SIZE_UNIT sizeof(portSTACK_TYPE)
9674
#endif
9775

9876
static IRAM void mgos_mg_poll_cb(void *arg) {
@@ -283,11 +261,11 @@ void mgos_freertos_run_mgos_task(bool start_scheduler) {
283261
// This is to avoid difficulties with interrupt allocation / deallocation:
284262
// https://docs.espressif.com/projects/esp-idf/en/stable/api-reference/system/intr_alloc.html#multicore-issues
285263
xTaskCreateStaticPinnedToCore(
286-
mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / STACK_SIZE_UNIT, NULL,
264+
mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / MGOS_TASK_STACK_SIZE_UNIT, NULL,
287265
MGOS_TASK_PRIORITY, mgos_task_stack, &mgos_task_tcb, 1);
288266
#else
289267
xTaskCreateStatic(mgos_task, "mgos",
290-
MGOS_TASK_STACK_SIZE_BYTES / STACK_SIZE_UNIT, NULL,
268+
MGOS_TASK_STACK_SIZE_BYTES / MGOS_TASK_STACK_SIZE_UNIT, NULL,
291269
MGOS_TASK_PRIORITY, mgos_task_stack, &mgos_task_tcb);
292270
#endif
293271
if (start_scheduler) {
@@ -307,7 +285,7 @@ void mgos_freertos_run_mgos_task(bool start_scheduler) {
307285
s_mgos_mux = xSemaphoreCreateRecursiveMutex();
308286
s_mg_poll_timer = xTimerCreate("mg_poll", 10, pdFALSE /* reload */, 0,
309287
mgos_mg_poll_timer_cb);
310-
xTaskCreate(mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / STACK_SIZE_UNIT,
288+
xTaskCreate(mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / MGOS_TASK_STACK_SIZE_UNIT,
311289
NULL, MGOS_TASK_PRIORITY, NULL);
312290
if (start_scheduler) {
313291
vTaskStartScheduler();

0 commit comments

Comments
 (0)