Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export FreeRTOS task-related constants to header file. #2

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions include/mgos_freertos.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,35 @@
#include "queue.h"
#include "task.h"

#include "mongoose.h"
#include "mgos_init.h"

#ifndef MGOS_TASK_STACK_SIZE_BYTES
#define MGOS_TASK_STACK_SIZE_BYTES 8192
#endif

#ifndef MGOS_TASK_PRIORITY
#define MGOS_TASK_PRIORITY 5
#endif

#ifndef MGOS_TASK_QUEUE_LENGTH
#define MGOS_TASK_QUEUE_LENGTH 32
#endif

#ifndef MGOS_MONGOOSE_MAX_POLL_SLEEP_MS
#define MGOS_MONGOOSE_MAX_POLL_SLEEP_MS 1000
#endif

#ifndef MGOS_EARLY_WDT_TIMEOUT
#define MGOS_EARLY_WDT_TIMEOUT 30 /* seconds */
#endif

#if CS_PLATFORM == CS_P_ESP32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave this in the source file, it not really tunable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about the MGOS_EARLY_WDT_TIMEOUT or CS_PLATFORM ?

It's not meant to be tuned... I just want to be able to know the value...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STACK_SIZE_UNIT. it's not really a tunable, it is hardcoded in freertos port and we just have to deal with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS_PLATFORM is needed to determine STACK_SIZE_UNIT, which i need.
But i don't really need MGOS_EARLY_WDT_TIMEOUT, but is there reason to conceal it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, you need STACK_SIZE_UNIT for your code... fair enough.
then let's keep it public, but please rename it to MGOS_TASK_STACK_SIZE_UNIT

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my module i have code similar to this from mgos_freertos.c and it does need STACK_SIZE_UNIT see:

xTaskCreateStatic(mgos_task, "mgos",
                   MGOS_TASK_STACK_SIZE_BYTES / STACK_SIZE_UNIT, NULL,
                    MGOS_TASK_PRIORITY, mgos_task_stack, &mgos_task_tcb);  

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename it to MGOS_TASK_STACK_SIZE_UNIT

should have seen this coming :) i have pushed fixed version now.

#define MGOS_TASK_STACK_SIZE_UNIT 1
#else
#define MGOS_TASK_STACK_SIZE_UNIT sizeof(portSTACK_TYPE)
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
28 changes: 3 additions & 25 deletions src/mgos_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,6 @@
#include "mgos_uart_internal.h"
#include "mgos_utils.h"

#ifndef MGOS_TASK_STACK_SIZE_BYTES
#define MGOS_TASK_STACK_SIZE_BYTES 8192
#endif

#ifndef MGOS_TASK_PRIORITY
#define MGOS_TASK_PRIORITY 5
#endif

#ifndef MGOS_TASK_QUEUE_LENGTH
#define MGOS_TASK_QUEUE_LENGTH 32
#endif

#ifndef MGOS_MONGOOSE_MAX_POLL_SLEEP_MS
#define MGOS_MONGOOSE_MAX_POLL_SLEEP_MS 1000
#endif

#ifndef MGOS_EARLY_WDT_TIMEOUT
#define MGOS_EARLY_WDT_TIMEOUT 30 /* seconds */
#endif

extern const char *build_version, *build_id;
extern const char *mg_build_version, *mg_build_id;

Expand All @@ -82,7 +62,6 @@ static portMUX_TYPE s_poll_spinlock = portMUX_INITIALIZER_UNLOCKED;
{ \
if (should_yield) portYIELD_FROM_ISR(); \
}
#define STACK_SIZE_UNIT 1
#else
#define ENTER_CRITICAL() portENTER_CRITICAL()
#define EXIT_CRITICAL() portEXIT_CRITICAL()
Expand All @@ -92,7 +71,6 @@ static portMUX_TYPE s_poll_spinlock = portMUX_INITIALIZER_UNLOCKED;
#define EXIT_CRITICAL_NO_ISR(from_isr) \
if (!from_isr) portEXIT_CRITICAL()
#define YIELD_FROM_ISR(should_yield) portYIELD_FROM_ISR(should_yield)
#define STACK_SIZE_UNIT sizeof(portSTACK_TYPE)
#endif

static IRAM void mgos_mg_poll_cb(void *arg) {
Expand Down Expand Up @@ -283,11 +261,11 @@ void mgos_freertos_run_mgos_task(bool start_scheduler) {
// This is to avoid difficulties with interrupt allocation / deallocation:
// https://docs.espressif.com/projects/esp-idf/en/stable/api-reference/system/intr_alloc.html#multicore-issues
xTaskCreateStaticPinnedToCore(
mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / STACK_SIZE_UNIT, NULL,
mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / MGOS_TASK_STACK_SIZE_UNIT, NULL,
MGOS_TASK_PRIORITY, mgos_task_stack, &mgos_task_tcb, 1);
#else
xTaskCreateStatic(mgos_task, "mgos",
MGOS_TASK_STACK_SIZE_BYTES / STACK_SIZE_UNIT, NULL,
MGOS_TASK_STACK_SIZE_BYTES / MGOS_TASK_STACK_SIZE_UNIT, NULL,
MGOS_TASK_PRIORITY, mgos_task_stack, &mgos_task_tcb);
#endif
if (start_scheduler) {
Expand All @@ -307,7 +285,7 @@ void mgos_freertos_run_mgos_task(bool start_scheduler) {
s_mgos_mux = xSemaphoreCreateRecursiveMutex();
s_mg_poll_timer = xTimerCreate("mg_poll", 10, pdFALSE /* reload */, 0,
mgos_mg_poll_timer_cb);
xTaskCreate(mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / STACK_SIZE_UNIT,
xTaskCreate(mgos_task, "mgos", MGOS_TASK_STACK_SIZE_BYTES / MGOS_TASK_STACK_SIZE_UNIT,
NULL, MGOS_TASK_PRIORITY, NULL);
if (start_scheduler) {
vTaskStartScheduler();
Expand Down