Skip to content

Commit

Permalink
Merge pull request ARMmbed#13034 from hugueskamba/hk_fix_sleep_tracing
Browse files Browse the repository at this point in the history
ST boards: Fix sleep tracing
  • Loading branch information
0xc0170 authored Jun 5, 2020
2 parents b21d5e8 + 5d94fd4 commit 0449825
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions rtos/source/TARGET_CORTEX/mbed_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void mbed_init(void)

void mbed_start(void)
{
mbed_rtos_init_singleton_mutex();
mbed_toolchain_init();
mbed_tfm_init();
mbed_main();
Expand Down
8 changes: 8 additions & 0 deletions rtos/source/TARGET_CORTEX/mbed_boot.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ void mbed_tfm_init(void);
*/
void mbed_main(void);

/**
* Create and Initialize a Singleton Mutex object.
*
* Precondition(s):
* - The RTOS has been started by a call to mbed_rtos_start
*/
void mbed_rtos_init_singleton_mutex(void);

/**@}*/
/**@}*/

Expand Down
18 changes: 11 additions & 7 deletions rtos/source/TARGET_CORTEX/mbed_rtos_rtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ mbed_rtos_storage_thread_t _main_obj __attribute__((section(".bss.os.thread.cb")

osMutexId_t singleton_mutex_id;
mbed_rtos_storage_mutex_t singleton_mutex_obj;
osMutexAttr_t singleton_mutex_attr;

void mbed_rtos_init()
{
Expand All @@ -47,11 +46,6 @@ void mbed_rtos_init()

MBED_NORETURN void mbed_rtos_start()
{
singleton_mutex_attr.name = "singleton_mutex";
singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj);
singleton_mutex_attr.cb_mem = &singleton_mutex_obj;

_main_thread_attr.stack_mem = _main_stack;
_main_thread_attr.stack_size = sizeof(_main_stack);
_main_thread_attr.cb_size = sizeof(_main_obj);
Expand All @@ -68,7 +62,6 @@ MBED_NORETURN void mbed_rtos_start()
tfm_ns_lock_init();
#endif // defined(TARGET_TFM) && defined(COMPONENT_NSPE)

singleton_mutex_id = osMutexNew(&singleton_mutex_attr);
osThreadId_t result = osThreadNew((osThreadFunc_t)mbed_start, NULL, &_main_thread_attr);
if ((void *)result == NULL) {
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INITIALIZATION_FAILED), "Pre main thread not created", &_main_thread_attr);
Expand All @@ -77,3 +70,14 @@ MBED_NORETURN void mbed_rtos_start()
osKernelStart();
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_INITIALIZATION_FAILED), "Failed to start RTOS");
}

void mbed_rtos_init_singleton_mutex(void)
{
const osMutexAttr_t singleton_mutex_attr = {
.name = "singleton_mutex",
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
.cb_size = sizeof(singleton_mutex_obj),
.cb_mem = &singleton_mutex_obj
};
singleton_mutex_id = osMutexNew(&singleton_mutex_attr);
}

0 comments on commit 0449825

Please sign in to comment.