The RTOS abstraction layer provides simple RTOS services like threads, semaphores, mutexes, queues, and timers. It is not intended to be a full features RTOS interface, but the provide just enough support to allow for RTOS independent drivers and middleware. This allows middleware applications to be as portable as possible within ModusToolbox™. This library provides a unified API around the actual RTOS. This allows middleware libraries to be written once independent of the RTOS actually selected for the application. The abstraction layer provides access to all the standard RTOS resources listed in the feature section below.
While the primary purpose of the library is for middleware, the abstraction layer can be used by the application code. However, since this API does not provide all RTOS features and the application generally knows what RTOS is being used, this is typically an unnecessary overhead.
All the RTOS abstraction layer functions generally all work the same way. The basic process is:
NOTE: All these functions need a pointer, so it is generally best to declare these "shared" resources as static global variables within the file that they are used.
To use the RTOS Abstraction, simply include a reference to cyabs_rtos.h
and update the application's makefile to include the appropriate component. e.g. one of:
To enable all functionality when using with FreeRTOS, the following configuration options must be enabled in FreeRTOSConfig.h:
Enabling configSUPPORT_STATIC_ALLOCATION requires the application to provide implementations for vApplicationGetIdleTaskMemory
and vApplicationGetTimerTaskMemory
functions. Weak implementations for these functions are provided as a part of this library. These can be overridden by the application if custom implementations of these functions are desired.
This library provides an API vApplicationSleep
which can be used to enable tickless support in FreeRTOS. In order to enable tickless mode with this API, the following changes need to be made in FreeRTOSConfig.h
:
portSUPPRESS_TICKS_AND_SLEEP
implementation.#define
configUSE_TICKLESS_IDLE 2
portSUPPRESS_TICKS_AND_SLEEP
macro to vApplicationSleep
implementation.#define
portSUPPRESS_TICKS_AND_SLEEP( xIdleTime ) vApplicationSleep( xIdleTime )
In tickless mode vApplicationSleep
updates the number of RTOS ticks that have passed since the tick interrupt was stopped using vTaskStepTick
, taking into account the sleep/deepsleep latency.
The maximum tickless idle time can be calculated as follow:
MaxIdleTime = LPtimerDelay + latency
where: latency = PreSleepLatency + PostSleepLatency
, LPtimerDelay = xExpectedIdleTime - latency
.Note: The LPtimerDelay
represents the duration in which the IP is configured to Wake-up the device. Wake-up can happen before its expiration if one other configured interrupt triggers during this time.
xExpectedIdleTime <= latency
WFI is executed instead, and normal sleep is expected to be reached (SCR->SLEEPDEEP = 0).Functions cy_rtos_scheduler_suspend/cy_rtos_scheduler_resume can be called from ISR but calls need to be paired to restore the saved interrupt status correctly so a structure to save these values has been implemented. The size of this structure can be controlled with CY_RTOS_MAX_SUSPEND_NESTING. This macro is overridable and its default value is 3.
For further details on Low power support in FreeRTOS please refer to documentation here
The cy_rtos_event_* functions accept a 32-bit event as an argument. However, FreeRTOS requires 8-bits(configUSE_16_BIT_TICKS
== 1) or 24-bits (configUSE_16_BIT_TICKS
== 0) to run successfully. Hence the application should not reference these unsupported bits. Check the FreeRTOS implementation of eventEVENT_BITS_CONTROL_BYTES
in event_group.c for internal details.
No specific requirements exist
In order to port to a new environment, the file cyabs_rtos_impl.h must be provided with definitions of some basic types for the abstraction layer. The types expected to be defined are:
cy_thread_t
: typedef from underlying RTOS thread typecy_thread_arg_t
: typedef from the RTOS type that is passed to the entry function of a thread.cy_mutex_t
: typedef from the underlying RTOS mutex typecy_semaphore_t
: typedef from the underlying RTOS semaphore typecy_event_t
: typedef from the underlying RTOS event typecy_queue_t
: typedef from the underlying RTOS queue typecy_timer_callback_arg_t
: typedef from the RTOS type that is passed to the timer callback functioncy_timer_t
: typedef from the underlying RTOS timer typecy_time_t
: count of time in millisecondscy_rtos_error_t
: typedef from the underlying RTOS error typeThe enum cy_thread_priority_t
needs to have the following priority values defined and mapped to RTOS specific values:
CY_RTOS_PRIORITY_MIN
CY_RTOS_PRIORITY_LOW
CY_RTOS_PRIORITY_BELOWNORMAL
CY_RTOS_PRIORITY_NORMAL
CY_RTOS_PRIORITY_ABOVENORMAL
CY_RTOS_PRIORITY_HIGH
CY_RTOS_PRIORITY_REALTIME
CY_RTOS_PRIORITY_MAX
Finally, the following macros need to be defined for memory allocations:
CY_RTOS_MIN_STACK_SIZE
CY_RTOS_ALIGNMENT
CY_RTOS_ALIGNMENT_MASK
© Cypress Semiconductor Corporation (an Infineon company) or an affiliate of Cypress Semiconductor Corporation, 2019-2022.