Skip to content

Commit

Permalink
rtos: permit configuration using KConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
joelguittet committed Jun 2, 2023
1 parent c73cd8b commit 5638002
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.5.0
27 changes: 27 additions & 0 deletions esp-idf/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,30 @@ menu "Mender client Configuration"
endif

endmenu

menu "Mender advanced Configuration"

config MENDER_RTOS_WORK_QUEUE_STACK_SIZE
int "Mender RTOS Work Queue Stack Size (kB)"
range 0 64
default 20
help
Mender RTOS work queue stack size, customize only if you have a deep understanding of the impacts! Default value is suitable for most applications.
The default TLS configuration of ESP-IDF v4.4.x allows to decrease the stack size down to 12kB.
The default stack size is 20kB because the default TLS configuration of ESP-IDF V5.x consumes more memory.

config MENDER_RTOS_WORK_QUEUE_PRIORITY
int "Mender RTOS Work Queue Priority"
range 0 24
default 5
help
Mender RTOS work queue priority, customize only if you have a deep understanding of the impacts! Default value is suitable for most applications.

config MENDER_RTOS_WORK_QUEUE_LENGTH
int "Mender RTOS Work Queue Length"
range 0 64
default 10
help
Mender RTOS work queue length, customize only if you have a deep understanding of the impacts! Default value is suitable for most applications.

endmenu
27 changes: 3 additions & 24 deletions platform/rtos/freertos/src/mender-rtos.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,6 @@
#include "mender-log.h"
#include "mender-rtos.h"

/**
* @brief Mender RTOS work queue stack
*/
#ifndef MENDER_RTOS_WORK_QUEUE_STACK_SIZE
#define MENDER_RTOS_WORK_QUEUE_STACK_SIZE (12 * 1024)
#endif /* MENDER_RTOS_WORK_QUEUE_STACK_SIZE */

/**
* @brief Mender RTOS work queue priority
*/
#ifndef MENDER_RTOS_WORK_QUEUE_PRIORITY
#define MENDER_RTOS_WORK_QUEUE_PRIORITY (5)
#endif /* MENDER_RTOS_WORK_QUEUE_PRIORITY */

/**
* @brief Mender RTOS work queue lenght
*/
#ifndef MENDER_RTOS_WORK_QUEUE_LENGTH
#define MENDER_RTOS_WORK_QUEUE_LENGTH (10)
#endif /* MENDER_RTOS_WORK_QUEUE_LENGTH */

/**
* @brief Work context
*/
Expand Down Expand Up @@ -90,16 +69,16 @@ mender_err_t
mender_rtos_init(void) {

/* Create and start work queue */
if (NULL == (mender_rtos_work_queue_handle = xQueueCreate(MENDER_RTOS_WORK_QUEUE_LENGTH, sizeof(mender_rtos_work_context_t *)))) {
if (NULL == (mender_rtos_work_queue_handle = xQueueCreate(CONFIG_MENDER_RTOS_WORK_QUEUE_LENGTH, sizeof(mender_rtos_work_context_t *)))) {
mender_log_error("Unable to create work queue");
return MENDER_FAIL;
}
if (pdPASS
!= xTaskCreate(mender_rtos_work_queue_thread,
"mender",
(configSTACK_DEPTH_TYPE)(MENDER_RTOS_WORK_QUEUE_STACK_SIZE / sizeof(configSTACK_DEPTH_TYPE)),
(configSTACK_DEPTH_TYPE)(CONFIG_MENDER_RTOS_WORK_QUEUE_STACK_SIZE * 1024 / sizeof(configSTACK_DEPTH_TYPE)),
NULL,
MENDER_RTOS_WORK_QUEUE_PRIORITY,
CONFIG_MENDER_RTOS_WORK_QUEUE_PRIORITY,
NULL)) {
mender_log_error("Unable to create work queue thread");
return MENDER_FAIL;
Expand Down
26 changes: 10 additions & 16 deletions platform/rtos/zephyr/src/mender-rtos.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,6 @@
#include "mender-log.h"
#include "mender-rtos.h"

/**
* @brief Mender RTOS work queue stack
*/
#ifndef MENDER_RTOS_WORK_QUEUE_STACK_SIZE
#define MENDER_RTOS_WORK_QUEUE_STACK_SIZE (12 * 1024)
#endif /* MENDER_RTOS_WORK_QUEUE_STACK_SIZE */
K_THREAD_STACK_DEFINE(mender_rtos_work_queue_stack, MENDER_RTOS_WORK_QUEUE_STACK_SIZE);

/**
* @brief Mender RTOS work queue priority
*/
#ifndef MENDER_RTOS_WORK_QUEUE_PRIORITY
#define MENDER_RTOS_WORK_QUEUE_PRIORITY (5)
#endif /* MENDER_RTOS_WORK_QUEUE_PRIORITY */

/**
* @brief Work context
*/
Expand All @@ -54,6 +39,11 @@ typedef struct {
struct k_work work_handle; /**< Work handle used to execute the work function */
} mender_rtos_work_context_t;

/**
* @brief Mender RTOS work queue stack
*/
K_THREAD_STACK_DEFINE(mender_rtos_work_queue_stack, CONFIG_MENDER_RTOS_WORK_QUEUE_STACK_SIZE * 1024);

/**
* @brief Function used to handle work context timer when it expires
* @param handle Timer handler
Expand All @@ -76,7 +66,11 @@ mender_rtos_init(void) {

/* Create and start work queue */
k_work_queue_init(&mender_rtos_work_queue_handle);
k_work_queue_start(&mender_rtos_work_queue_handle, mender_rtos_work_queue_stack, MENDER_RTOS_WORK_QUEUE_STACK_SIZE, MENDER_RTOS_WORK_QUEUE_PRIORITY, NULL);
k_work_queue_start(&mender_rtos_work_queue_handle,
mender_rtos_work_queue_stack,
CONFIG_MENDER_RTOS_WORK_QUEUE_STACK_SIZE * 1024,
CONFIG_MENDER_RTOS_WORK_QUEUE_PRIORITY,
NULL);

return MENDER_OK;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ if(CONFIG_MENDER_MCU_CLIENT_HTTP_TYPE MATCHES "zephyr")
add_compile_definitions(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
add_compile_definitions(CONFIG_MENDER_HTTP_CA_CERTIFICATE_TAG=1)
endif()
if(CONFIG_MENDER_MCU_CLIENT_RTOS_TYPE MATCHES "freertos")
add_compile_definitions(CONFIG_MENDER_RTOS_WORK_QUEUE_STACK_SIZE=20)
add_compile_definitions(CONFIG_MENDER_RTOS_WORK_QUEUE_PRIORITY=5)
add_compile_definitions(CONFIG_MENDER_RTOS_WORK_QUEUE_LENGTH=10)
endif()
if(CONFIG_MENDER_MCU_CLIENT_RTOS_TYPE MATCHES "zephyr")
add_compile_definitions(CONFIG_MENDER_RTOS_WORK_QUEUE_STACK_SIZE=12)
add_compile_definitions(CONFIG_MENDER_RTOS_WORK_QUEUE_PRIORITY=5)
endif()

# Add sources
file(GLOB_RECURSE SOURCES_TEMP "${CMAKE_CURRENT_LIST_DIR}/src/*.c")
Expand Down
14 changes: 14 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ if MENDER_MCU_CLIENT

endif

config MENDER_RTOS_WORK_QUEUE_STACK_SIZE
int "Mender RTOS Work Queue Stack Size (kB)"
range 0 64
default 12
help
Mender RTOS work queue stack size, customize only if you have a deep understanding of the impacts! Default value is suitable for most applications.

config MENDER_RTOS_WORK_QUEUE_PRIORITY
int "Mender RTOS Work Queue Priority"
range 0 128
default 5
help
Mender RTOS work queue priority, customize only if you have a deep understanding of the impacts! Default value is suitable for most applications.

module = MENDER
module-str = Log Level for mender
module-help = Enables logging for mender code.
Expand Down

0 comments on commit 5638002

Please sign in to comment.