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
Deprecate wait() in favour of acquire(), try_acquire(),
try_acquire_for() and try_acquire_until().
Brings Semaphore more into line with CMSIS-RTOS 2 (which uses "acquire"),
itself (as it has "release"), and other classes having "try", "try for"
and "try until".
Also steps away from vague "wait" term - the primary operation here is
to acquire the semaphore, and this will of course sleep.
Non-Secure threads can access secure calls only when tz_module attribute is set
as 1(OS_SECURE_CALLABLE_THREAD), while thread creation.
Hence adding tz_module as an argument to ctor.
Call to osThreadTerminate is guarded by local_id check, to avoid parameter error fault when deleting or terminating Thread object that was not started.
Ensure both the stack and stack size used in the Thread class are
aligned to 8 bytes. This prevents the runtime error
"Thread 0 error -11: Unknown" due to incorrect stack alignment.
Make calls to cmsis-os to get thread state, stack size, and max stack
usage rather than accessing internal RTX data directly. Wrap RTX5
specific code in OS_BACKEND_RTX5.
Also refactor the code to use mbed types rather than RTX types:
os_timer_t -> mbed_rtos_storage_timer_t
os_event_flags_t -> mbed_rtos_storage_event_flags_t
osRtxMutex_t -> mbed_rtos_storage_thread_t
Calling Thread::start multiple times leads to undefined behavior since
the Thread class was not designed to handle being restarted. Return an
error code if Thread::start is called a second time to prevent this
behavior.