From 83b329cb71d53b3f50961c647590c6bffe36da4a Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Thu, 14 Mar 2019 13:36:02 +0200 Subject: [PATCH] RTOS API for bare metal Provide partial RTOS API for bare metal builds - things that can be done in a single threaded environment. Allows more code to work in both RTOS and bare metal builds without change, and in particular gives easy access to the ability to efficiently wait for something occurring in interrupt. Available in bare-metal: * ThisThread * osThreadFlagsSet to set flags on main thread (can be set from IRQ) * EventFlags (can be set from IRQ) * Semaphores (can be released from IRQ) * Mutex (dummy implementation) Not useful: * ConditionVariable (could only be signalled from 2nd thread) * RtosTimer (calls in a second thread context) * Thread Unimplemented: * Mail, Queue, MemoryPool Possible future work: * ConditionVariableCS to act as IRQ signalled ConditionVariable --- UNITTESTS/CMakeLists.txt | 3 + UNITTESTS/target_h/rtos/Mutex.h | 3 +- .../target_h/{ => rtos}/mbed_rtos1_types.h | 0 .../target_h/{ => rtos}/mbed_rtos_storage.h | 0 UNITTESTS/target_h/{ => rtos}/rtos.h | 0 mbed.h | 2 +- rtos/ConditionVariable.cpp | 4 + rtos/ConditionVariable.h | 6 +- rtos/EventFlags.cpp | 37 ++++++ rtos/EventFlags.h | 10 +- rtos/Kernel.cpp | 8 +- rtos/Kernel.h | 2 +- rtos/LICENSE.md | 1 - rtos/Mail.h | 14 ++- rtos/MemoryPool.h | 8 +- rtos/Mutex.cpp | 7 +- rtos/Mutex.h | 60 +++++++++- rtos/Queue.h | 10 +- rtos/RtosTimer.cpp | 4 + rtos/RtosTimer.h | 10 +- rtos/Semaphore.cpp | 84 ++++++++++++++ rtos/Semaphore.h | 12 +- rtos/TARGET_CORTEX/mbed_lib.json | 57 +++++++++ rtos/TARGET_CORTEX/mbed_rtos1_types.h | 28 ----- ...mbed_rtos_storage.h => mbed_rtx_storage.h} | 4 +- rtos/ThisThread.cpp | 109 +++++++++++++++++- rtos/ThisThread.h | 22 ++-- rtos/Thread.cpp | 4 + rtos/Thread.h | 10 +- rtos/mbed_lib.json | 59 +--------- rtos/mbed_rtos1_types.h | 30 +++++ rtos/mbed_rtos_storage.h | 28 +++++ rtos/mbed_rtos_types.h | 76 ++++++++++++ rtos/rtos.h | 2 +- rtos/rtos_handlers.h | 2 +- 35 files changed, 580 insertions(+), 136 deletions(-) rename UNITTESTS/target_h/{ => rtos}/mbed_rtos1_types.h (100%) rename UNITTESTS/target_h/{ => rtos}/mbed_rtos_storage.h (100%) rename UNITTESTS/target_h/{ => rtos}/rtos.h (100%) create mode 100644 rtos/TARGET_CORTEX/mbed_lib.json delete mode 100644 rtos/TARGET_CORTEX/mbed_rtos1_types.h rename rtos/TARGET_CORTEX/{mbed_rtos_storage.h => mbed_rtx_storage.h} (97%) create mode 100644 rtos/mbed_rtos1_types.h create mode 100644 rtos/mbed_rtos_storage.h create mode 100644 rtos/mbed_rtos_types.h diff --git a/UNITTESTS/CMakeLists.txt b/UNITTESTS/CMakeLists.txt index 41164268f80..875f024bedd 100644 --- a/UNITTESTS/CMakeLists.txt +++ b/UNITTESTS/CMakeLists.txt @@ -86,6 +86,9 @@ endif(COVERAGE) # UNIT TESTS #################### +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUNITTEST") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNITTEST") + # Set include dirs. set(unittest-includes-base "${PROJECT_SOURCE_DIR}/target_h" diff --git a/UNITTESTS/target_h/rtos/Mutex.h b/UNITTESTS/target_h/rtos/Mutex.h index 4f38c37fe0b..5a14ed47b49 100644 --- a/UNITTESTS/target_h/rtos/Mutex.h +++ b/UNITTESTS/target_h/rtos/Mutex.h @@ -18,7 +18,8 @@ #define __MUTEX_H__ #include -#include "cmsis_os2.h" +#include "mbed_rtos_types.h" +#include "mbed_rtos1_types.h" namespace rtos { diff --git a/UNITTESTS/target_h/mbed_rtos1_types.h b/UNITTESTS/target_h/rtos/mbed_rtos1_types.h similarity index 100% rename from UNITTESTS/target_h/mbed_rtos1_types.h rename to UNITTESTS/target_h/rtos/mbed_rtos1_types.h diff --git a/UNITTESTS/target_h/mbed_rtos_storage.h b/UNITTESTS/target_h/rtos/mbed_rtos_storage.h similarity index 100% rename from UNITTESTS/target_h/mbed_rtos_storage.h rename to UNITTESTS/target_h/rtos/mbed_rtos_storage.h diff --git a/UNITTESTS/target_h/rtos.h b/UNITTESTS/target_h/rtos/rtos.h similarity index 100% rename from UNITTESTS/target_h/rtos.h rename to UNITTESTS/target_h/rtos/rtos.h diff --git a/mbed.h b/mbed.h index e59813d11bf..4f6f6f60245 100644 --- a/mbed.h +++ b/mbed.h @@ -18,7 +18,7 @@ #include "platform/mbed_version.h" -#if MBED_CONF_RTOS_PRESENT +#if MBED_CONF_RTOS_API_PRESENT #include "rtos/rtos.h" #endif diff --git a/rtos/ConditionVariable.cpp b/rtos/ConditionVariable.cpp index cb3bf805a06..e1087fe0a76 100644 --- a/rtos/ConditionVariable.cpp +++ b/rtos/ConditionVariable.cpp @@ -26,6 +26,8 @@ #include "mbed_error.h" #include "mbed_assert.h" +#if MBED_CONF_RTOS_PRESENT + namespace rtos { ConditionVariable::Waiter::Waiter(): sem(0), prev(NULL), next(NULL), in_list(false) @@ -150,3 +152,5 @@ ConditionVariable::~ConditionVariable() } } + +#endif diff --git a/rtos/ConditionVariable.h b/rtos/ConditionVariable.h index 543efc7eb34..35ecbf57096 100644 --- a/rtos/ConditionVariable.h +++ b/rtos/ConditionVariable.h @@ -23,12 +23,14 @@ #define CONDITIONVARIABLE_H #include -#include "cmsis_os.h" +#include "rtos/mbed_rtos_types.h" #include "rtos/Mutex.h" #include "rtos/Semaphore.h" #include "platform/NonCopyable.h" +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) + namespace rtos { /** \addtogroup rtos */ /** @{*/ @@ -328,4 +330,6 @@ class ConditionVariable : private mbed::NonCopyable { } #endif +#endif + /** @}*/ diff --git a/rtos/EventFlags.cpp b/rtos/EventFlags.cpp index 1167d764ac5..5382ff94565 100644 --- a/rtos/EventFlags.cpp +++ b/rtos/EventFlags.cpp @@ -20,6 +20,8 @@ * SOFTWARE. */ #include "rtos/EventFlags.h" +#include "rtos/ThisThread.h" +#include "mbed_os_timer.h" #include #include "mbed_error.h" #include "mbed_assert.h" @@ -38,27 +40,43 @@ EventFlags::EventFlags(const char *name) void EventFlags::constructor(const char *name) { +#if MBED_CONF_RTOS_PRESENT osEventFlagsAttr_t attr = { 0 }; attr.name = name ? name : "application_unnamed_event_flags"; attr.cb_mem = &_obj_mem; attr.cb_size = sizeof(_obj_mem); _id = osEventFlagsNew(&attr); MBED_ASSERT(_id); +#else + _flags = 0; +#endif } uint32_t EventFlags::set(uint32_t flags) { +#if MBED_CONF_RTOS_PRESENT return osEventFlagsSet(_id, flags); +#else + return core_util_atomic_fetch_or_u32(&_flags, flags) | flags; +#endif } uint32_t EventFlags::clear(uint32_t flags) { +#if MBED_CONF_RTOS_PRESENT return osEventFlagsClear(_id, flags); +#else + return core_util_atomic_fetch_and_u32(&_flags, ~flags); +#endif } uint32_t EventFlags::get() const { +#if MBED_CONF_RTOS_PRESENT return osEventFlagsGet(_id); +#else + return core_util_atomic_load_u32(&_flags); +#endif } uint32_t EventFlags::wait_all(uint32_t flags, uint32_t millisec, bool clear) @@ -73,7 +91,9 @@ uint32_t EventFlags::wait_any(uint32_t flags, uint32_t millisec, bool clear) EventFlags::~EventFlags() { +#if MBED_CONF_RTOS_PRESENT osEventFlagsDelete(_id); +#endif } uint32_t EventFlags::wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool clear) @@ -82,7 +102,24 @@ uint32_t EventFlags::wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool opt |= osFlagsNoClear; } +#if MBED_CONF_RTOS_PRESENT return osEventFlagsWait(_id, flags, opt, millisec); +#else + rtos::internal::flags_check_capture check; + check.flags = &_flags; + check.options = opt; + check.flags_wanted = flags; + check.result = 0; + check.match = false; + mbed::internal::do_timed_sleep_relative_or_forever(millisec, rtos::internal::non_rtos_check_flags, &check); + if (check.match) { + return check.result; + } else if (millisec == 0) { + return osErrorResource; + } else { + return osErrorTimeout; + } +#endif } } diff --git a/rtos/EventFlags.h b/rtos/EventFlags.h index bac58ea5889..0c2798d4a90 100644 --- a/rtos/EventFlags.h +++ b/rtos/EventFlags.h @@ -23,9 +23,9 @@ #define EVENT_FLAG_H #include -#include "cmsis_os2.h" -#include "mbed_rtos1_types.h" -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos1_types.h" +#include "rtos/mbed_rtos_storage.h" #include "platform/NonCopyable.h" @@ -114,8 +114,12 @@ class EventFlags : private mbed::NonCopyable { private: void constructor(const char *name = NULL); uint32_t wait(uint32_t flags, uint32_t opt, uint32_t millisec, bool clear); +#if MBED_CONF_RTOS_PRESENT osEventFlagsId_t _id; mbed_rtos_storage_event_flags_t _obj_mem; +#else + uint32_t _flags; +#endif }; /** @}*/ diff --git a/rtos/Kernel.cpp b/rtos/Kernel.cpp index a620c0cf1fc..4751bee0538 100644 --- a/rtos/Kernel.cpp +++ b/rtos/Kernel.cpp @@ -20,16 +20,17 @@ * SOFTWARE. */ -#include "cmsis_os2.h" #include "rtos/Kernel.h" #include "rtos/rtos_idle.h" #include "rtos/rtos_handlers.h" #include "platform/mbed_critical.h" +#include "platform/mbed_os_timer.h" namespace rtos { uint64_t Kernel::get_ms_count() { +#if MBED_CONF_RTOS_PRESENT // CMSIS-RTOS 2.1.0 and 2.1.1 differ in the time type. We assume // our header at least matches the implementation, so we don't try looking // at the run-time version report. (There's no compile-time version report) @@ -61,8 +62,12 @@ uint64_t Kernel::get_ms_count() core_util_critical_section_exit(); return ret; } +#else + return mbed::internal::init_os_timer()->update_and_get_tick(); +#endif } +#if MBED_CONF_RTOS_PRESENT void Kernel::attach_idle_hook(void (*fptr)(void)) { rtos_attach_idle_hook(fptr); @@ -72,5 +77,6 @@ void Kernel::attach_thread_terminate_hook(void (*fptr)(osThreadId_t id)) { rtos_attach_thread_terminate_hook(fptr); } +#endif } diff --git a/rtos/Kernel.h b/rtos/Kernel.h index 851dfb688ed..5a73aadf408 100644 --- a/rtos/Kernel.h +++ b/rtos/Kernel.h @@ -23,7 +23,7 @@ #define KERNEL_H #include -#include "cmsis_os2.h" +#include "rtos/mbed_rtos_types.h" namespace rtos { /** \addtogroup rtos */ diff --git a/rtos/LICENSE.md b/rtos/LICENSE.md index a99cc40e786..01cb36ec62c 100644 --- a/rtos/LICENSE.md +++ b/rtos/LICENSE.md @@ -3,7 +3,6 @@ as can be found: LICENSE-apache-2.0.txt. Files licensed under MIT: -- TARGET_CORTEX/mbed_rtos1_types.h - TARGET_CORTEX/mbed_rtos_storage.h - TARGET_CORTEX/mbed_rtx_conf.h - TARGET_CORTEX/mbed_rtx_idle.cpp diff --git a/rtos/Mail.h b/rtos/Mail.h index dd105096816..85607dc45ed 100644 --- a/rtos/Mail.h +++ b/rtos/Mail.h @@ -25,11 +25,11 @@ #include #include -#include "Queue.h" -#include "MemoryPool.h" -#include "cmsis_os2.h" -#include "mbed_rtos_storage.h" -#include "mbed_rtos1_types.h" +#include "rtos/Queue.h" +#include "rtos/MemoryPool.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos_storage.h" +#include "rtos/mbed_rtos1_types.h" #include "platform/mbed_toolchain.h" #include "platform/NonCopyable.h" @@ -38,6 +38,8 @@ using namespace rtos; #endif +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) + namespace rtos { /** \addtogroup rtos */ /** @{*/ @@ -238,5 +240,5 @@ class Mail : private mbed::NonCopyable > { #endif - +#endif diff --git a/rtos/MemoryPool.h b/rtos/MemoryPool.h index 431b5d6894c..6764d122379 100644 --- a/rtos/MemoryPool.h +++ b/rtos/MemoryPool.h @@ -25,11 +25,12 @@ #include #include -#include "cmsis_os2.h" -#include "mbed_rtos1_types.h" -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos1_types.h" +#include "rtos/mbed_rtos_storage.h" #include "platform/NonCopyable.h" +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) namespace rtos { /** \addtogroup rtos */ /** @{*/ @@ -191,3 +192,4 @@ class MemoryPool : private mbed::NonCopyable > { } #endif +#endif diff --git a/rtos/Mutex.cpp b/rtos/Mutex.cpp index 24f3085cb9b..8316168b6cc 100644 --- a/rtos/Mutex.cpp +++ b/rtos/Mutex.cpp @@ -26,9 +26,11 @@ #include "mbed_error.h" #include "mbed_assert.h" +#if MBED_CONF_RTOS_PRESENT + namespace rtos { -Mutex::Mutex(): _count(0) +Mutex::Mutex() { constructor(); } @@ -40,6 +42,7 @@ Mutex::Mutex(const char *name) void Mutex::constructor(const char *name) { + _count = 0; osMutexAttr_t attr = { 0 }; attr.name = name ? name : "application_unnamed_mutex"; @@ -147,3 +150,5 @@ Mutex::~Mutex() } } + +#endif diff --git a/rtos/Mutex.h b/rtos/Mutex.h index a4955a54c66..aeddf02924f 100644 --- a/rtos/Mutex.h +++ b/rtos/Mutex.h @@ -23,9 +23,9 @@ #define MUTEX_H #include -#include "cmsis_os2.h" -#include "mbed_rtos1_types.h" -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos1_types.h" +#include "rtos/mbed_rtos_storage.h" #include "platform/NonCopyable.h" #include "platform/ScopedLock.h" @@ -56,6 +56,8 @@ typedef mbed::ScopedLock ScopedMutexLock; /** The Mutex class is used to synchronize the execution of threads. This is, for example, used to protect access to a shared resource. + In bare-metal builds, the Mutex class is a dummy, so lock() and unlock() are no-ops. + @note You cannot use member functions of this class in ISR context. If you require Mutex functionality within ISR handler, consider using @a Semaphore. @@ -88,7 +90,11 @@ class Mutex : private mbed::NonCopyable { @note This function treats RTOS errors as fatal system errors, so it can only return osOK. Use of the return value is deprecated, as the return is expected to become void in the future. */ - osStatus lock(void); +#if MBED_CONF_RTOS_PRESENT + osStatus lock(); +#else + void lock(); // Value return backwards compatibility not required for non-RTOS +#endif /** Wait until a Mutex becomes available. @@ -150,14 +156,18 @@ class Mutex : private mbed::NonCopyable { @note This function treats RTOS errors as fatal system errors, so it can only return osOK. Use of the return value is deprecated, as the return is expected to become void in the future. */ +#if MBED_CONF_RTOS_PRESENT osStatus unlock(); +#else + void unlock(); // Value return backwards compatibility not required for non-RTOS +#endif /** Get the owner the this mutex @return the current owner of this mutex. @note You cannot call this function from ISR context. */ - osThreadId get_owner(); + osThreadId_t get_owner(); /** Mutex destructor * @@ -166,13 +176,53 @@ class Mutex : private mbed::NonCopyable { ~Mutex(); private: +#if MBED_CONF_RTOS_PRESENT void constructor(const char *name = NULL); friend class ConditionVariable; osMutexId_t _id; mbed_rtos_storage_mutex_t _obj_mem; uint32_t _count; +#endif }; + +#if !MBED_CONF_RTOS_PRESENT +inline Mutex::Mutex() +{ +} + +inline Mutex::Mutex(const char *) +{ +} + +inline Mutex::~Mutex() +{ +} + +inline void Mutex::lock() +{ +} + +inline bool Mutex::trylock() +{ + return true; +} + +inline bool Mutex::trylock_for(uint32_t) +{ + return true; +} + +inline bool Mutex::trylock_until(uint64_t) +{ + return true; +} + +inline void Mutex::unlock() +{ +} +#endif + /** @}*/ /** @}*/ } diff --git a/rtos/Queue.h b/rtos/Queue.h index e31fb619d66..1ce8eb354aa 100644 --- a/rtos/Queue.h +++ b/rtos/Queue.h @@ -22,12 +22,14 @@ #ifndef QUEUE_H #define QUEUE_H -#include "cmsis_os2.h" -#include "mbed_rtos1_types.h" -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos1_types.h" +#include "rtos/mbed_rtos_storage.h" #include "platform/mbed_error.h" #include "platform/NonCopyable.h" +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) + namespace rtos { /** \addtogroup rtos */ /** @{*/ @@ -219,4 +221,6 @@ class Queue : private mbed::NonCopyable > { } // namespace rtos +#endif + #endif // QUEUE_H diff --git a/rtos/RtosTimer.cpp b/rtos/RtosTimer.cpp index 4639da035b4..4779f320ce0 100644 --- a/rtos/RtosTimer.cpp +++ b/rtos/RtosTimer.cpp @@ -26,6 +26,8 @@ #include +#if MBED_CONF_RTOS_PRESENT + namespace rtos { void RtosTimer::constructor(mbed::Callback func, os_timer_type type) @@ -54,3 +56,5 @@ RtosTimer::~RtosTimer() } } + +#endif diff --git a/rtos/RtosTimer.h b/rtos/RtosTimer.h index eb976cd0bd4..168687281b1 100644 --- a/rtos/RtosTimer.h +++ b/rtos/RtosTimer.h @@ -23,12 +23,14 @@ #define RTOS_TIMER_H #include -#include "cmsis_os2.h" -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos_storage.h" #include "platform/Callback.h" #include "platform/NonCopyable.h" #include "platform/mbed_toolchain.h" -#include "mbed_rtos1_types.h" +#include "rtos/mbed_rtos1_types.h" + +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) namespace rtos { /** \addtogroup rtos */ @@ -188,4 +190,4 @@ class RtosTimer : private mbed::NonCopyable { #endif - +#endif diff --git a/rtos/Semaphore.cpp b/rtos/Semaphore.cpp index 0c69c00272d..6887ac247f0 100644 --- a/rtos/Semaphore.cpp +++ b/rtos/Semaphore.cpp @@ -22,7 +22,9 @@ #include "rtos/Semaphore.h" #include "rtos/Kernel.h" #include "platform/mbed_assert.h" +#include "platform/mbed_critical.h" #include "platform/mbed_error.h" +#include "platform/mbed_os_timer.h" #include @@ -40,22 +42,51 @@ Semaphore::Semaphore(int32_t count, uint16_t max_count) void Semaphore::constructor(int32_t count, uint16_t max_count) { +#if MBED_CONF_RTOS_PRESENT osSemaphoreAttr_t attr = { 0 }; attr.cb_mem = &_obj_mem; attr.cb_size = sizeof(_obj_mem); _id = osSemaphoreNew(max_count, count, &attr); MBED_ASSERT(_id != NULL); +#else + _count = count; + _max_count = max_count; +#endif } +#if !MBED_CONF_RTOS_PRESENT +struct sem_wait_capture { + Semaphore *sem; + bool acquired; +}; + +bool Semaphore::semaphore_available(void *handle) +{ + sem_wait_capture *wait = static_cast(handle); + return wait->acquired = wait->sem->try_acquire(); +} +#endif + bool Semaphore::try_acquire() { +#if MBED_CONF_RTOS_PRESENT osStatus_t status = osSemaphoreAcquire(_id, 0); if (status != osOK && status != osErrorResource) { MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_SEMAPHORE_LOCK_FAILED), "Semaphore acquire failed", status); } return status == osOK; +#else + int32_t old_count = core_util_atomic_load_s32(&_count); + do { + if (old_count == 0) { + return false; + } + } while (!core_util_atomic_cas_s32(&_count, &old_count, old_count - 1)); + return true; +#endif } +#if MBED_CONF_RTOS_PRESENT /* To sidestep deprecation warnings */ int32_t Semaphore::_wait(uint32_t millisec) { @@ -71,14 +102,26 @@ int32_t Semaphore::_wait(uint32_t millisec) return -1; } } +#endif int32_t Semaphore::wait(uint32_t millisec) { +#if MBED_CONF_RTOS_PRESENT return _wait(millisec); +#else + sem_wait_capture capture = { this, false }; + mbed::internal::do_timed_sleep_relative_or_forever(millisec, semaphore_available, &capture); + if (capture.acquired) { + return core_util_atomic_load_s32(&_count) + 1; + } else { + return 0; + } +#endif } int32_t Semaphore::wait_until(uint64_t millisec) { +#if MBED_CONF_RTOS_PRESENT uint64_t now = Kernel::get_ms_count(); if (now >= millisec) { @@ -89,18 +132,36 @@ int32_t Semaphore::wait_until(uint64_t millisec) } else { return _wait(millisec - now); } +#else + sem_wait_capture capture = { this, false }; + mbed::internal::do_timed_sleep_absolute(millisec, semaphore_available, &capture); + if (capture.acquired) { + return core_util_atomic_load_s32(&_count) + 1; + } else { + return 0; + } +#endif } void Semaphore::acquire() { +#if MBED_CONF_RTOS_PRESENT osStatus_t status = osSemaphoreAcquire(_id, osWaitForever); if (status != osOK) { MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_SEMAPHORE_LOCK_FAILED), "Semaphore acquire failed", status); } +#else + sem_wait_capture capture = { this, false }; + mbed::internal::do_untimed_sleep(semaphore_available, &capture); + if (!capture.acquired) { + MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_SEMAPHORE_LOCK_FAILED), "Semaphore acquire failed"); + } +#endif } bool Semaphore::try_acquire_for(uint32_t millisec) { +#if MBED_CONF_RTOS_PRESENT osStatus_t status = osSemaphoreAcquire(_id, millisec); if (status == osOK) { return true; @@ -113,10 +174,16 @@ bool Semaphore::try_acquire_for(uint32_t millisec) MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_SEMAPHORE_LOCK_FAILED), "Semaphore acquire failed", status); } return false; +#else + sem_wait_capture capture = { this, false }; + mbed::internal::do_timed_sleep_relative_or_forever(millisec, semaphore_available, &capture); + return capture.acquired; +#endif } bool Semaphore::try_acquire_until(uint64_t millisec) { +#if MBED_CONF_RTOS_PRESENT uint64_t now = Kernel::get_ms_count(); if (now >= millisec) { @@ -127,16 +194,33 @@ bool Semaphore::try_acquire_until(uint64_t millisec) } else { return try_acquire_for(millisec - now); } +#else + sem_wait_capture capture = { this, false }; + mbed::internal::do_timed_sleep_absolute(millisec, semaphore_available, &capture); + return capture.acquired; +#endif } osStatus Semaphore::release(void) { +#if MBED_CONF_RTOS_PRESENT return osSemaphoreRelease(_id); +#else + int32_t old_count = core_util_atomic_load_s32(&_count); + do { + if (old_count == _max_count) { + return osErrorResource; + } + } while (!core_util_atomic_cas_s32(&_count, &old_count, old_count + 1)); +#endif + return osOK; } Semaphore::~Semaphore() { +#if MBED_CONF_RTOS_PRESENT osSemaphoreDelete(_id); +#endif } } diff --git a/rtos/Semaphore.h b/rtos/Semaphore.h index 9eaa116d054..8b89e7b48d3 100644 --- a/rtos/Semaphore.h +++ b/rtos/Semaphore.h @@ -23,9 +23,9 @@ #define SEMAPHORE_H #include -#include "cmsis_os2.h" -#include "mbed_rtos1_types.h" -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos1_types.h" +#include "rtos/mbed_rtos_storage.h" #include "platform/mbed_toolchain.h" #include "platform/NonCopyable.h" @@ -141,10 +141,16 @@ class Semaphore : private mbed::NonCopyable { private: void constructor(int32_t count, uint16_t max_count); +#if MBED_CONF_RTOS_PRESENT int32_t _wait(uint32_t millisec); osSemaphoreId_t _id; mbed_rtos_storage_semaphore_t _obj_mem; +#else + static bool semaphore_available(void *); + int32_t _count; + uint16_t _max_count; +#endif }; /** @}*/ /** @}*/ diff --git a/rtos/TARGET_CORTEX/mbed_lib.json b/rtos/TARGET_CORTEX/mbed_lib.json new file mode 100644 index 00000000000..aed253aba50 --- /dev/null +++ b/rtos/TARGET_CORTEX/mbed_lib.json @@ -0,0 +1,57 @@ +{ + "name": "rtos", + "config": { + "present": 1, + "main-thread-stack-size": { + "help": "The size of the main thread's stack", + "value": 4096 + }, + "timer-thread-stack-size": { + "help": "The size of the timer thread's stack", + "value": 768 + }, + "idle-thread-stack-size": { + "help": "The size of the idle thread's stack", + "value": 512 + }, + "thread-stack-size": { + "help": "The default stack size of new threads", + "value": 4096 + }, + "idle-thread-stack-size-tickless-extra": { + "help": "Additional size to add to the idle thread when a specific target or application implementation requires it or in case tickless is enabled and LPTICKER_DELAY_TICKS is used", + "value": 256 + }, + "idle-thread-stack-size-debug-extra": { + "help": "Additional size to add to the idle thread when code compilation optimisation is disabled", + "value": 0 + } + }, + "macros": ["_RTE_"], + "target_overrides": { + "*": { + "target.boot-stack-size": "0x400" + }, + "STM": { + "idle-thread-stack-size-debug-extra": 128 + }, + "STM32L1": { + "idle-thread-stack-size-debug-extra": 512 + }, + "MCU_NRF51": { + "target.boot-stack-size": "0x800" + }, + "MCU_NRF52840": { + "target.boot-stack-size": "0x800" + }, + "MCU_NRF52832": { + "target.boot-stack-size": "0x800" + }, + "MCU_NRF51_UNIFIED": { + "target.boot-stack-size": "0x800" + }, + "NUVOTON": { + "idle-thread-stack-size-debug-extra": 512 + } + } +} diff --git a/rtos/TARGET_CORTEX/mbed_rtos1_types.h b/rtos/TARGET_CORTEX/mbed_rtos1_types.h deleted file mode 100644 index e44fa25edb5..00000000000 --- a/rtos/TARGET_CORTEX/mbed_rtos1_types.h +++ /dev/null @@ -1,28 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2017 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef MBED_RTOS_RTX1_TYPES_H -#define MBED_RTOS_RTX1_TYPES_H - -#include "rtx4/cmsis_os.h" - -#endif diff --git a/rtos/TARGET_CORTEX/mbed_rtos_storage.h b/rtos/TARGET_CORTEX/mbed_rtx_storage.h similarity index 97% rename from rtos/TARGET_CORTEX/mbed_rtos_storage.h rename to rtos/TARGET_CORTEX/mbed_rtx_storage.h index 2a0338baedf..d14f78abc2e 100644 --- a/rtos/TARGET_CORTEX/mbed_rtos_storage.h +++ b/rtos/TARGET_CORTEX/mbed_rtx_storage.h @@ -19,8 +19,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef MBED_RTOS_STORAGE_H -#define MBED_RTOS_STORAGE_H +#ifndef MBED_RTX_STORAGE_H +#define MBED_RTX_STORAGE_H #ifdef __cplusplus extern "C" { diff --git a/rtos/ThisThread.cpp b/rtos/ThisThread.cpp index 0e3b89d4310..cd8af4eea82 100644 --- a/rtos/ThisThread.cpp +++ b/rtos/ThisThread.cpp @@ -23,39 +23,119 @@ #define __STDC_LIMIT_MACROS #include "rtos/ThisThread.h" +#include "platform/mbed_toolchain.h" #include "rtos/Kernel.h" -#include "rtos/rtos_idle.h" +#include "platform/CriticalSectionLock.h" #include "platform/mbed_assert.h" +#include "platform/mbed_critical.h" +#include "platform/mbed_os_timer.h" + +#if !MBED_CONF_RTOS_PRESENT +static uint32_t thread_flags; + +/* For the flags to be useful, need a way of setting them, but there's only the main + * thread, and that has no Thread object, so Thread class is not provided. Implement + * one CMSIS-RTOS function to provide access. + */ +extern "C" +uint32_t osThreadFlagsSet(osThreadId_t /*thread_id*/, uint32_t flags) +{ + return core_util_atomic_fetch_or_u32(&thread_flags, flags) | flags; +} +#endif namespace rtos { uint32_t ThisThread::flags_clear(uint32_t flags) { +#if MBED_CONF_RTOS_PRESENT flags = osThreadFlagsClear(flags); MBED_ASSERT(!(flags & osFlagsError)); +#else + flags = core_util_atomic_fetch_and_u32(&thread_flags, ~flags); +#endif return flags; } uint32_t ThisThread::flags_get() { +#if MBED_CONF_RTOS_PRESENT return osThreadFlagsGet(); +#else + return core_util_atomic_load_u32(&thread_flags); +#endif +} + +#if !MBED_CONF_RTOS_PRESENT +namespace internal { +bool non_rtos_check_flags(void *handle) +{ + flags_check_capture *check = static_cast(handle); + uint32_t cur_flags = core_util_atomic_load_u32(check->flags); + uint32_t set_flags; + do { + set_flags = cur_flags & check->flags_wanted; + check->result = set_flags; + if ((check->options & osFlagsWaitAll) ? set_flags == check->flags_wanted : set_flags != 0) { + if (check->options & osFlagsNoClear) { + break; + } + } else { + return false; + } + } while (!core_util_atomic_cas_u32(check->flags, &cur_flags, cur_flags & ~set_flags)); + check->match = true; + return true; +} } +#endif static uint32_t flags_wait_for(uint32_t flags, uint32_t millisec, bool clear, uint32_t options) { if (!clear) { options |= osFlagsNoClear; } +#if MBED_CONF_RTOS_PRESENT flags = osThreadFlagsWait(flags, options, millisec); if (flags & osFlagsError) { MBED_ASSERT((flags == osFlagsErrorTimeout && millisec != osWaitForever) || (flags == osFlagsErrorResource && millisec == 0)); flags = ThisThread::flags_get(); } +#else + rtos::internal::flags_check_capture check; + check.flags = &thread_flags; + check.options = options; + check.flags_wanted = flags; + check.result = 0; + mbed::internal::do_timed_sleep_relative_or_forever(millisec, rtos::internal::non_rtos_check_flags, &check); + flags = check.result; +#endif return flags; } +static uint32_t flags_wait(uint32_t flags, bool clear, uint32_t options) +{ +#if MBED_CONF_RTOS_PRESENT + return flags_wait_for(flags, osWaitForever, clear, options); +#else + /* Avoids pulling in timer if not used */ + if (!clear) { + options |= osFlagsNoClear; + } + rtos::internal::flags_check_capture check; + check.flags = &thread_flags; + check.options = options; + check.flags_wanted = flags; + check.result = 0; + mbed::internal::do_untimed_sleep(rtos::internal::non_rtos_check_flags, &check); + flags = check.result; + + return flags; +#endif +} + static uint32_t flags_wait_until(uint32_t flags, uint64_t millisec, bool clear, uint32_t options) { uint64_t now = Kernel::get_ms_count(); @@ -74,7 +154,7 @@ static uint32_t flags_wait_until(uint32_t flags, uint64_t millisec, bool clear, uint32_t ThisThread::flags_wait_all(uint32_t flags, bool clear) { - return flags_wait_for(flags, osWaitForever, clear, osFlagsWaitAll); + return flags_wait(flags, clear, osFlagsWaitAll); } uint32_t ThisThread::flags_wait_all_for(uint32_t flags, uint32_t millisec, bool clear) @@ -89,7 +169,7 @@ uint32_t ThisThread::flags_wait_all_until(uint32_t flags, uint64_t millisec, boo uint32_t ThisThread::flags_wait_any(uint32_t flags, bool clear) { - return flags_wait_for(flags, osWaitForever, clear, osFlagsWaitAny); + return flags_wait(flags, clear, osFlagsWaitAny); } uint32_t ThisThread::flags_wait_any_for(uint32_t flags, uint32_t millisec, bool clear) @@ -104,12 +184,18 @@ uint32_t ThisThread::flags_wait_any_until(uint32_t flags, uint64_t millisec, boo void ThisThread::sleep_for(uint32_t millisec) { +#if MBED_CONF_RTOS_PRESENT osStatus_t status = osDelay(millisec); MBED_ASSERT(status == osOK); +#else + // Undocumented, but osDelay(UINT32_MAX) does actually sleep forever + mbed::internal::do_timed_sleep_relative_or_forever(millisec); +#endif } void ThisThread::sleep_until(uint64_t millisec) { +#if MBED_CONF_RTOS_PRESENT // CMSIS-RTOS 2.1.0 had 64-bit time and osDelayUntil, but that's been revoked. // Limit ourselves to manual implementation assuming a >=32-bit osDelay. @@ -126,25 +212,42 @@ void ThisThread::sleep_until(uint64_t millisec) break; } } +#else + mbed::internal::do_timed_sleep_absolute(millisec); +#endif } void ThisThread::yield() { +#if MBED_CONF_RTOS_PRESENT osThreadYield(); +#else + asm("yield"); +#endif } osThreadId_t ThisThread::get_id() { +#if MBED_CONF_RTOS_PRESENT return osThreadGetId(); +#else + return (osThreadId_t) 1; // dummy non-0 value +#endif } const char *get_name() { +#if MBED_CONF_RTOS_PRESENT osThreadId_t id = osThreadGetId(); if (id == NULL) { return NULL; } return osThreadGetName(id); +#else + return NULL; +#endif } } + + diff --git a/rtos/ThisThread.h b/rtos/ThisThread.h index d566fb5397d..492ad881135 100644 --- a/rtos/ThisThread.h +++ b/rtos/ThisThread.h @@ -23,14 +23,7 @@ #define THIS_THREAD_H #include -#include "cmsis_os2.h" -#include "mbed_rtos1_types.h" -#include "mbed_rtos_storage.h" -#include "platform/Callback.h" -#include "platform/mbed_toolchain.h" -#include "platform/NonCopyable.h" -#include "rtos/Semaphore.h" -#include "rtos/Mutex.h" +#include "rtos/mbed_rtos_types.h" namespace rtos { /** \addtogroup rtos */ @@ -188,6 +181,19 @@ const char *get_name(); }; /** @}*/ /** @}*/ + +namespace internal { +struct flags_check_capture { + uint32_t *flags; + uint32_t options; + uint32_t flags_wanted; + uint32_t result; + bool match; +}; + +bool non_rtos_check_flags(void *handle); + +} } #endif diff --git a/rtos/Thread.cpp b/rtos/Thread.cpp index 40154afe00e..80827ab52dd 100644 --- a/rtos/Thread.cpp +++ b/rtos/Thread.cpp @@ -26,6 +26,8 @@ #include "platform/mbed_assert.h" #include "platform/mbed_error.h" +#if MBED_CONF_RTOS_PRESENT + #define ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos)) MBED_STATIC_ASSERT(ALIGN_UP(0, 8) == 0, "ALIGN_UP macro error"); MBED_STATIC_ASSERT(ALIGN_UP(1, 8) == 8, "ALIGN_UP macro error"); @@ -432,3 +434,5 @@ void Thread::_thunk(void *thread_ptr) } } + +#endif diff --git a/rtos/Thread.h b/rtos/Thread.h index 34da08aa244..f9e25d6f47a 100644 --- a/rtos/Thread.h +++ b/rtos/Thread.h @@ -23,15 +23,17 @@ #define THREAD_H #include -#include "cmsis_os2.h" -#include "mbed_rtos1_types.h" -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_types.h" +#include "rtos/mbed_rtos1_types.h" +#include "rtos/mbed_rtos_storage.h" #include "platform/Callback.h" #include "platform/mbed_toolchain.h" #include "platform/NonCopyable.h" #include "rtos/Semaphore.h" #include "rtos/Mutex.h" +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST) + namespace rtos { /** \addtogroup rtos */ /** @{*/ @@ -545,4 +547,4 @@ class Thread : private mbed::NonCopyable { } #endif - +#endif diff --git a/rtos/mbed_lib.json b/rtos/mbed_lib.json index aed253aba50..43fb3abb77b 100644 --- a/rtos/mbed_lib.json +++ b/rtos/mbed_lib.json @@ -1,57 +1,6 @@ { - "name": "rtos", - "config": { - "present": 1, - "main-thread-stack-size": { - "help": "The size of the main thread's stack", - "value": 4096 - }, - "timer-thread-stack-size": { - "help": "The size of the timer thread's stack", - "value": 768 - }, - "idle-thread-stack-size": { - "help": "The size of the idle thread's stack", - "value": 512 - }, - "thread-stack-size": { - "help": "The default stack size of new threads", - "value": 4096 - }, - "idle-thread-stack-size-tickless-extra": { - "help": "Additional size to add to the idle thread when a specific target or application implementation requires it or in case tickless is enabled and LPTICKER_DELAY_TICKS is used", - "value": 256 - }, - "idle-thread-stack-size-debug-extra": { - "help": "Additional size to add to the idle thread when code compilation optimisation is disabled", - "value": 0 - } - }, - "macros": ["_RTE_"], - "target_overrides": { - "*": { - "target.boot-stack-size": "0x400" - }, - "STM": { - "idle-thread-stack-size-debug-extra": 128 - }, - "STM32L1": { - "idle-thread-stack-size-debug-extra": 512 - }, - "MCU_NRF51": { - "target.boot-stack-size": "0x800" - }, - "MCU_NRF52840": { - "target.boot-stack-size": "0x800" - }, - "MCU_NRF52832": { - "target.boot-stack-size": "0x800" - }, - "MCU_NRF51_UNIFIED": { - "target.boot-stack-size": "0x800" - }, - "NUVOTON": { - "idle-thread-stack-size-debug-extra": 512 - } - } + "name": "rtos-api", + "config": { + "present": 1 + } } diff --git a/rtos/mbed_rtos1_types.h b/rtos/mbed_rtos1_types.h new file mode 100644 index 00000000000..e178b273c16 --- /dev/null +++ b/rtos/mbed_rtos1_types.h @@ -0,0 +1,30 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBED_RTOS_RTX1_TYPES_H +#define MBED_RTOS_RTX1_TYPES_H + +#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST) + +#include "cmsis_os.h" + +#else + +typedef int32_t osStatus; + +#endif + +#endif diff --git a/rtos/mbed_rtos_storage.h b/rtos/mbed_rtos_storage.h new file mode 100644 index 00000000000..58eb8f40628 --- /dev/null +++ b/rtos/mbed_rtos_storage.h @@ -0,0 +1,28 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBED_RTOS_STORAGE_H +#define MBED_RTOS_STORAGE_H + +#if MBED_CONF_RTOS_PRESENT || defined(UNITTEST) + +#include "mbed_rtx_storage.h" + +#endif + +#endif + +/** @}*/ diff --git a/rtos/mbed_rtos_types.h b/rtos/mbed_rtos_types.h new file mode 100644 index 00000000000..3584b6dece8 --- /dev/null +++ b/rtos/mbed_rtos_types.h @@ -0,0 +1,76 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2019, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef RTOS_TYPES_H_ +#define RTOS_TYPES_H_ + +#if MBED_CONF_RTOS_PRESENT || defined(DOXYGEN_ONLY) || defined(UNITTEST) +#include "cmsis_os2.h" +#else + +#ifdef __cplusplus +extern "C" { +#endif + +/* Minimal definitions for bare metal form of RTOS */ + +// Timeout value. +#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. + +// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait). +#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default). +#define osFlagsWaitAll 0x00000001U ///< Wait for all flags. +#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for. + +// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx). +#define osFlagsError 0x80000000U ///< Error indicator. +#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1). +#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2). +#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3). +#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4). +#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6). + +// Status code values returned by CMSIS-RTOS functions. +typedef enum { + osOK = 0, ///< Operation completed successfully. + osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits. + osErrorTimeout = -2, ///< Operation not completed within the timeout period. + osErrorResource = -3, ///< Resource not available. + osErrorParameter = -4, ///< Parameter error. + osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. + osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. + osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. +} osStatus_t; + + +// \details Thread ID identifies the thread. +typedef void *osThreadId_t; + +// Set the specified Thread Flags of a thread. +// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +// \param[in] flags specifies the flags of the thread that shall be set. +// \return thread flags after setting or error code if highest bit set. +uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags); + +#ifdef __cplusplus +} +#endif + +#endif + + + +#endif /* RTOS_TYPES_H_ */ diff --git a/rtos/rtos.h b/rtos/rtos.h index c2d4ad5a98b..b480d25dfcc 100644 --- a/rtos/rtos.h +++ b/rtos/rtos.h @@ -25,7 +25,7 @@ #ifndef RTOS_H #define RTOS_H -#include "mbed_rtos_storage.h" +#include "rtos/mbed_rtos_storage.h" #include "rtos/Kernel.h" #include "rtos/Thread.h" #include "rtos/ThisThread.h" diff --git a/rtos/rtos_handlers.h b/rtos/rtos_handlers.h index e3d474300f3..351682b12b6 100644 --- a/rtos/rtos_handlers.h +++ b/rtos/rtos_handlers.h @@ -25,7 +25,7 @@ #ifndef RTOS_HANDLERS_H #define RTOS_HANDLERS_H -#include "cmsis_os2.h" +#include "rtos/mbed_rtos_types.h" #ifdef __cplusplus extern "C" {