34 195 An 001 I3.0 Upgrading From FreeRTOS To SafeRTOS
34 195 An 001 I3.0 Upgrading From FreeRTOS To SafeRTOS
Copyright WITTENSTEIN high integrity systems Limited, date as document, all rights reserved.
CONTENTS .................................................................................................................................... 2
REFERENCED DOCUMENTS ....................................................................................................... 3
CHAPTER 1 INTRODUCTION.................................................................................................... 4
1.1 KEY DIFFERENCES ............................................................................................................. 5
CHAPTER 2 MEMORY ALLOCATION ....................................................................................... 6
2.1 MEMORY ALLOCATION SCHEME ........................................................................................... 7
2.2 CHANGES TO XTASKCREATE()............................................................................................. 7
2.3 CHANGES TO XQUEUECREATE() .......................................................................................... 8
2.4 CHANGES TO XSEMAPHORECREATEBINARY() ...................................................................... 9
2.5 CHANGES TO XSEMAPHORECREATECOUNTING() .................................................................. 9
2.6 CHANGES TO XTIMERCREATE() ......................................................................................... 10
2.7 CHANGES TO XEVENTGROUPCREATE() ............................................................................. 11
2.8 CHANGES TO XMUTEXCREATE() ........................................................................................ 11
2.9 CHANGES TO XSTREAMBUFFERCREATE() .......................................................................... 13
CHAPTER 3 FUNCTIONALITY ................................................................................................. 14
3.1 RESTRICTED FUNCTIONALITY ............................................................................................ 15
3.1.1 Co-routines .............................................................................................................. 15
3.1.2 Queue Sets.............................................................................................................. 15
3.1.3 Thread Local Storage .............................................................................................. 15
3.1.4 Task Tags ................................................................................................................ 15
3.1.5 Removed API Functions .......................................................................................... 15
CHAPTER 4 FUNCTION AND MACRO NAMES ...................................................................... 16
4.1 FUNCTION AND MACRO NAMES ......................................................................................... 17
CHAPTER 5 CONFIGURATION PARAMETERS ...................................................................... 45
5.1 CONFIGURATION MACROS ................................................................................................. 46
CHAPTER 6 ERROR REPORTING .......................................................................................... 51
6.1 SIDE EFFECTS OF INCREASED ERROR REPORTING ............................................................. 52
CHAPTER 7 MISCELLANEOUS ............................................................................................... 53
7.1 HEADER FILES.................................................................................................................. 54
7.2 HOOK FUNCTIONS ............................................................................................................ 54
7.3 DIRECTORY STRUCTURE ................................................................................................... 55
7.4 DELAY CONSTANTS .......................................................................................................... 55
7.5 TICK-LESS MODE .............................................................................................................. 56
INTRODUCTION
FreeRTOS and SAFERTOS share a similar usage model but are not direct drop-in replacements for
each other. This document highlights the areas requiring modification when moving an application
from FreeRTOS to SAFERTOS. These differences primarily arise from:
1. Memory allocation
Each task and queue created consumes a small amount of RAM. Under FreeRTOS the
required RAM is automatically dynamically allocated at run time. SAFERTOS does not permit
dynamic memory allocation so the required RAM must instead be statically allocated at
compile time, then manually passed into the create functions for the various kernel objects
(i.e. xTaskCreate(), xQueueCreate, xSemaphoreCreateBinary(),
xSemaphoreCreateCounting(), xTimerCreate(), xEventGroupCreate(), xMutexCreate(),
xEvtMplxCreate() and xStreamBufferCreate() API functions).
FreeRTOS contains very little in the way of API function input parameter checking. As a
result, many FreeRTOS API functions either just return a simple pass or fail result, or do not
return any status information at all.
SAFERTOS checks the validity of every appropriate input parameter. This means not only
do more SAFERTOS API functions return status information, but the status information
returned is also more detailed. The SAFERTOS function naming convention states that API
functions shall be prefixed with their return type – so changing the type returned by a function
also requires a small change to the function name.
SAFERTOS performs validity and consistency tests on its key internal data – calling an
application defined error hook function should such a test fail. FreeRTOS does not require
an equivalent hook function so one must be provided when upgrading to instead use
SAFERTOS.
4. Restricted Functionality
To facilitate the upgrade processes a small SAFERTOS demonstration project is provided for your
reference. This project is the SAFERTOS equivalent to a sub-set of the standard FreeRTOS
demonstration application – allowing the two to be compared.
MEMORY ALLOCATION
FreeRTOS projects must include implementations for the dynamic memory allocation functions
pvPortMalloc() and vPortFree(). The implementation would normally be contained within a file called
heap_1.c, heap_2.c, etc.
SAFERTOS does not permit any form of dynamic memory allocation so this file should be removed
from the project.
The lack of dynamic memory allocation necessitates that the SAFERTOS version of xTaskCreate()
requires more parameters than its FreeRTOS counterpart. In addition, a SAFERTOS product variant
may require additional parameters when creating a task if, for example, a Memory Protection Unit
(MPU) or Memory Management Unit (MMU) is supported. Consequently, the SAFERTOS version of
xTaskCreate() accepts just 2 parameters – pxTaskParameters which is a pointer to an
xTaskParameters structure and pxCreatedTask which is used to pass back the handle of the created
task. This is similar to the FreeRTOS API function xTaskCreateRestricted().
The members of the xTaskParameter structure are specific to each product variant and are
described fully in the SAFERTOS v9 User Manual [Reference 1]. As a minimum, all product variants
require the following members to be present:
1. pvTaskCode
2. pcTaskName
A descriptive name for the task. This is mainly used to facilitate debugging.
3. pxTCB
A pointer to a statically declared xTCB used by the kernel to hold the task data structures.
4. pcStackBuffer
A pointer to the statically declared buffer to be used by the kernel to hold the task stack. Care
must be taken to ensure that the stack buffer is aligned correctly.
5. uxStackDepthBytes
6. pvParameters
A pointer that will be used as the parameter for the task being created.
8. pvObject
Points to the instance of the C++ object that tracks this TCB structure.
Refer to the API reference section of the SAFERTOS v9 User Manual [Reference 1] for a full
description of the xTaskCreate() function, and the accompanying demo application for some usage
examples.
The lack of dynamic memory allocation and increased error checking necessitates that the
SAFERTOS version of xQueueCreate() requires three more parameters than its FreeRTOS
counterpart.
1. pcQueueMemory
Points to the statically declared buffer to be used by the kernel to hold the queue data
structures and storage area.
2. uxBufferLength
3. pxQueue
The FreeRTOS xQueueCreate() function returns either a handle to the created queue, or
NULL should the function be unable to create the queue for any reason. The application
needs therefore only check the return value against NULL to know whether a valid queue
handle was returned or not. The improved error detection and reporting provided by
SAFERTOS replaces this binary pass/fail return value with a set of descriptive status codes
– necessitating that the queue handle instead be passed out of the function using this new
reference parameter.
Refer to the API reference section in the SAFERTOS v9 User Manual [Reference 1] for a full
description and the accompanying demo application for some usage examples.
The lack of dynamic memory allocation and increased error checking necessitates that the
SAFERTOS version of xSemaphoreCreateBinary() requires different parameters to its FreeRTOS
counterpart.
1. pcSemaphoreBuffer
Points to the statically declared buffer to be used by the kernel to hold the semaphore data
structure. The buffer must have a size of portQUEUE_OVERHEAD_BYTES and be 8-byte
aligned.
2. pxSemaphore
It should also be noted that Binary Semaphores in SAFERTOS are created in the “given” state where
the count is equal to 1. This is unlike FreeRTOS, where Binary Semaphores are created in the empty
or “taken” state, where the count is equal to 0.
Refer to the API reference section in the SAFERTOS v9 User Manual [Reference 1] for a full
description and a list of the possible error codes returned by SAFERTOS. Refer to the accompanying
demo application for some usage examples.
The lack of dynamic memory allocation and increased error checking necessitates that the
SAFERTOS version of xSemaphoreCreateCounting() requires two more parameters than its
FreeRTOS counterpart.
1. pcSemaphoreBuffer
Points to the statically declared buffer to be used by the kernel to hold the semaphore data
structure. The buffer must have a size of portQUEUE_OVERHEAD_BYTES and be 8-byte
aligned.
2. pxSemaphore
Refer to the API reference section in the SAFERTOS v9 User Manual [Reference 1] for a full
description and a list of the possible error codes returned by SAFERTOS. Refer to the accompanying
demo application for some usage examples.
The lack of dynamic memory allocation and increased error checking necessitates that the
SAFERTOS version of xTimerCreate() requires more parameters than its FreeRTOS counterpart.
xTimerCreate() has a parameter, timerInitParameters, which is a struct containing all of the
information used to create the timer. The elements of this struct are as follows:
1. pcTimerName
2. xTimerPeriodInTicks
3. xIsPeriodic
4. xTimerID
Application specified tag for this timer. This is provided to allow multiple timers to be serviced
by a single callback function.
5. pxNewTimer
6. pxCallbackFunction
This should be a function pointer if the timer should call a function upon expiring. If this is
NULL, then task notifications shall be used instead.
7. pxTimerInstance
A pointer to the timer instance that this timer will belong to. The timers modules supports the
use of multiple timer instances (e.g. running at different priorities), specifying NULL is
advised and is used to refer to the default timer instance.
8. pvObject
A pointer to user defined data to be associated with this timer. Can be set to NULL if not
needed by the user application.
9. xTaskToNotify
Task handle used to directly notify a task (using the task notification feature) when a timer
expires. If this is NULL, the callback function shall be used instead.
Note that either pxCallbackFunction or xTaskToNotify must be NULL. Both cannot be non-NULL.
The lack of dynamic memory allocation and increased error checking necessitates that the
SAFERTOS version of xEventGroupCreate() requires two more parameters than its FreeRTOS
counterpart.
1. pxEventGroup
Points to the statically declared eventGroupType structure buffer to be used by the kernel to
hold the created event group.
2. pxEventGroupHandle
The FreeRTOS xEventGroupCreate() function returns either a handle to the created event
group, or NULL should the function be unable to create the event group because of
insufficient heap. The application needs therefore only check the return value against NULL
to know whether a valid event group handle was returned or not. The improved error detection
and reporting provided by SAFERTOS replaces this binary pass/fail return value with a set
of descriptive status codes – necessitating that the event group handle instead be passed
out of the function using this new reference parameter.
Refer to the API reference section in the SAFERTOS v9 User Manual [Reference 1] for a full
description and the accompanying demo application for some usage examples.
The lack of dynamic memory allocation and increased error checking necessitates that the
SAFERTOS function xMutexCreate() requires two more parameters than its FreeRTOS counterparts
(xSemaphoreCreateMutex() and xSemaphoreCreateRecursiveMutex()).
1. pcMutexBuffer
Points to the statically declared buffer to be used by the kernel to hold the data required to
manage the mutex.
2. pxMutex
Refer to the API reference section in the SAFERTOS v9 User Manual [Reference 1] for a full
description and the accompanying demo application for some usage examples.
The lack of dynamic memory allocation and increased error checking necessitates that the
SAFERTOS function xStreamBufferCreate() requires four more parameters than its FreeRTOS
counterpart of the same name.
1. pxStreamBufferHandle
2. uxIsMessageBuffer
A Boolean value used to determine if discretely sized messages or continuous data streams
are to be stored on the streambuffer.
3. pucStreamBufferStorageArea
Points to the statically declared buffer used by the kernel to store the data written to the
streambuffer.
4. pxStreamBuffer
Points to the statically declared buffer used by the kernel to store the streambuffer metadata.
The FreeRTOS xStreamBufferCreate() function returns either a handle to the created mutex,
or NULL should the function be unable to create the streambuffer. The application need
therefore only check the return value against NULL to know whether a valid mutex handle
was returned or not. The improved error detection and reporting provided by SAFERTOS
replaces this with a set of descriptive status codes – necessitating that the streambuffer
handle instead be passed out of the function using this new reference parameter.
Refer to the API reference section in the SAFERTOS v9 User Manual [Reference 1] for a full
description and the accompanying demo application for some usage examples.
FUNCTIONALITY
The SAFERTOS functionality has been restricted to include only the core components necessary.
This is standard practice for source code that is intended to undergo formal audit or certification as
it greatly reduces the test burden.
3.1.1 Co-routines
SAFERTOS does not provide an implementation of Queue Sets, but it implements the Event
Multiplex API, which supersedes the FreeRTOS Queue Sets functionality. In fact, Event Multiplex
objects are sets of events that include Queues and Queue-derived events (Semaphores and
Mutexes) as well as Task Notifications and Event Groups.
FreeRTOS allows associating each task with a configurable number of pointers to Thread Local
Storage (TLS) objects. It is also possible to set this number to zero, which will exclude this feature.
SAFERTOS always implements one TLS pointer, therefore the number is not configurable and
cannot be disabled.
FreeRTOS supports the possibility of assigning an application-defined tag to each task. Task tags
are a form of thread local storage with application-defined meaning. This is an optional feature for
advanced users.
SAFERTOS does not support task tags. However, it should be possible to use the TLS pointer
instead, depending on application requirements.
Refer to Table 4-1 for a FreeRTOS to SAFERTOS API function cross reference.
The SAFERTOS function naming convention requires each function name to be prefixed by a
character that describes its return type. In particular, functions that return a value of type
portBaseType are prefixed by an ‘x’, and functions that return a void are prefixed with a ‘v’. A greater
number of SAFERTOS functions than FreeRTOS functions return non void values, necessitating
that the prefixes assigned to these functions be updated accordingly.
Table 4-1 provides a cross reference between FreeRTOS API functions and macros, and their
SAFERTOS equivalents. This analysis was conducted using v10.5.1 of the FreeRTOS API and v9.4
of the SAFERTOS API.
portSWITCH_TO_USER_MODE() vMPUTaskExecuteInUnprivilegedMode() This API function is only provided for SAFERTOS product variants that
support use of an MPU.
taskENTER_CRITICAL() safertosapiENTER_CRITICAL()
taskEXIT_CRITICAL() safertosapiEXIT_CRITICAL()
vTaskAllocateMPURegions() xMPUSetTaskRegions() This API function is only provided for SAFERTOS product variants that
support use of an MPU.
xTaskCreateStatic() xTaskCreate() FreeRTOS provides this function to enable tasks to be created with a
statically allocated stack buffer. SAFERTOS tasks are by default
created with statically allocated stack buffers.
xTaskCreateRestricted() xTaskCreate() FreeRTOS only provides this API function for systems that include an
MPU implementation. The parameters supplied to the SAFERTOS
function are discussed within this application note.
xTaskGetCurrentTaskHandle() xTaskGetCurrentTaskHandle()
xTaskGetSchedulerState() xTaskIsSchedulerStarted() The SAFERTOS functions return pdTRUE if the scheduler has been
xTaskIsSchedulerStartedFromISR() started.
pvTaskGetThreadLocalStoragePointer() pvTaskTLSObjectGet() FreeRTOS provides for an array of TLS pointers, the size of which is
determined at compile time. SAFERTOS provides a single TLS object,
which is a void pointer that may be used to reference an arbitrary
structure defined, populated and maintained according to application
requirements.
xTaskGetTickCount() xTaskGetTickCount()
xTaskGetTickCountFromISR() xTaskGetTickCountFromISR()
xTaskNotifyGive() Not implemented. For SAFERTOS, use xTaskNotifySend() to implement the FreeRTOS
“lightweight semaphore” task notification use case if required.
ulTaskNotifyTake() Not implemented. For SAFERTOS, use xTaskNotifyWait() to implement the FreeRTOS
“lightweight semaphore” task notification use case if required.
xTaskNotifyWait() xTaskNotifyWait()
uxTaskPriorityGet() xTaskPriorityGet() Whereas the FreeRTOS version returns the priority, the SAFERTOS
version passes the priority out using a reference parameter. This is to
permit the return value to provide more detailed error reporting.
SAFERTOS returns pdPASS, errNULL_PARAMETER_SUPPLIED or
errINVALID_TASK_HANDLE.
xTaskResumeFromISR() Not implemented. This function is often misused under FreeRTOS and is considered
unsafe.
vTaskSetApplicationTaskTag() / Not implemented. For SAFERTOS, arbitrary thread local storage may be implemented
xTaskSetApplicationTaskTag() using the TLS object during task creation along with the
pvTaskTLSObjectGet() function. The TLS object may be used to
access thread (task) local storage structures of arbitrary size and
complexity according to application requirements.
vTaskSetThreadLocalStoragePointer() Not implemented. For SAFERTOS, arbitrary thread local storage may be implemented
using the TLS object during task creation along with the
pvTaskTLSObjectGet() function. The TLS object may be used to
access thread (task) local storage structures of arbitrary size and
complexity according to application requirements.
vTaskStartScheduler() xTaskStartScheduler() The SAFERTOS version requires a parameter that indicates whether
or not configuration checks should be performed before starting the
scheduler.
SAFERTOS also returns a number of error codes should it not be
possible to start the scheduler. The error codes
errNO_TASKS_CREATED and
errSCHEDULER_ALREADY_RUNNING are returned by all product
variants. Other error codes may be returned depending on the product
variant; refer to the SAFERTOS v9 User Manual [Reference 1].
vTaskStepTick() Not implemented. For internal use only, in SAFERTOS ports supporting ULPM.
taskYIELD() safertosapiYIELD()
portYIELD_FROM_ISR() / safertosapiYIELD_FROM_ISR() The SAFERTOS macro does not take an argument, unlike FreeRTOS.
portEND_SWITCHING_ISR() SAFERTOS will automatically determine whether a context switch is
necessary.
Queues API
xQueueCreate() xQueueCreate() The SAFERTOS version requires extra parameters as detailed within
this application note.
FreeRTOS returns the handle of the created queue, or NULL if the
queue could not be created; SAFERTOS returns pdPASS,
errINVALID_BYTE_ALIGNMENT, errINVALID_QUEUE_LENGTH,
errINVALID_BUFFER_SIZE or errNULL_PARAMETER_SUPPLIED.
xQueueCreateStatic() xQueueCreate() The SAFERTOS version requires parameters as detailed within this
application note.
FreeRTOS returns the handle of the created queue, or NULL if the
queue could not be created; SAFERTOS returns pdPASS,
errINVALID_BYTE_ALIGNMENT, errINVALID_QUEUE_LENGTH,
errINVALID_BUFFER_SIZE or errNULL_PARAMETER_SUPPLIED
vQueueDelete() Not implemented. The FreeRTOS version just frees the memory allocated to the queue,
whereas SAFERTOS does not dynamically allocate or free memory. It
is not considered safe to delete queues.
uxQueueMessagesWaiting() xQueueMessagesWaiting() Whereas the FreeRTOS version returns the number of messages, the
SAFERTOS version passes the number of messages out using a
reference parameter. This is to permit the return value to provide more
detailed error reporting. SAFERTOS returns pdPASS,
errNULL_PARAMETER_SUPPLIED or
errINVALID_QUEUE_HANDLE.
Semaphores API
xSemaphoreCreateMutex() xMutexCreate() The SAFERTOS version requires parameters as detailed within this
application note.
FreeRTOS returns the handle of the created mutex, or NULL if the
mutex could not be created; SAFERTOS returns pdPASS,
errQUEUE_ALREADY_IN_USE, errINVALID_BYTE_ALIGNMENT or
errNULL_PARAMETER_SUPPLIED
xSemaphoreCreateMutexStatic() xMutexCreate() The SAFERTOS version requires parameters as detailed within this
application note.
FreeRTOS returns the handle of the created mutex, or NULL if the
mutex could not be created; SAFERTOS returns pdPASS,
errQUEUE_ALREADY_IN_USE, errINVALID_BYTE_ALIGNMENT or
errNULL_PARAMETER_SUPPLIED
xSemaphoreCreateRecursiveMutex() xMutexCreate() The SAFERTOS version requires parameters as detailed within this
application note.
FreeRTOS returns the handle of the created mutex, or NULL if the
mutex could not be created; SAFERTOS returns pdPASS,
errQUEUE_ALREADY_IN_USE, errINVALID_BYTE_ALIGNMENT or
errNULL_PARAMETER_SUPPLIED
xSemaphoreCreateRecursiveMutexStatic( xMutexCreate() The SAFERTOS version requires parameters as detailed within this
) application note.
FreeRTOS returns the handle of the created mutex, or NULL if the
mutex could not be created; SAFERTOS returns pdPASS,
errQUEUE_ALREADY_IN_USE, errINVALID_BYTE_ALIGNMENT or
errNULL_PARAMETER_SUPPLIED
uxSemaphoreGetCount() xSemaphoreGetCountDepth() Whereas the FreeRTOS version returns the semaphore count, the
SAFERTOS version passes the count out using a reference
parameter. This is to permit the return value to provide more detailed
error reporting. SAFERTOS returns pdPASS,
errNULL_PARAMETER_SUPPLIED or errINVALID_QUEUE_HANDLE
xSemaphoreGiveRecursive() xMutexGive()
xSemaphoreTakeRecursive() xMutexTake()
xTimerCreate() xTimerCreate() FreeRTOS returns the timer handle or NULL; SAFERTOS returns
pdPASS, errINVALID_PARAMETERS, errINVALID_TIMER_HANDLE,
errNULL_PARAMETER_SUPPLIED, errTIMER_ALREADY_IN_USE,
errINVALID_TIMER_TASK_INSTANCE or a return code from
xTaskCreate().
xTimerCreateStatic() xTimerCreate() FreeRTOS returns the timer handle or NULL; SAFERTOS returns
pdPASS, errINVALID_PARAMETERS, errINVALID_TIMER_HANDLE,
errNULL_PARAMETER_SUPPLIED, errTIMER_ALREADY_IN_USE,
errINVALID_TIMER_TASK_INSTANCE or a return code from
xTaskCreate().
pcTimerGetName() Not implemented. For SAFERTOS, an arbitrary “timer local” storage object, present for
each software timer, may be initialized when a timer is created, and is
accessible via the pvTimerTLSObjectGet() function. This object is of
type void pointer and could be used to point to any arbitrary timer-
specific data structure, so timer names may be implemented as part of
such a structure, if required.
pvTimerGetTimerID() xTimerGetTimerID() FreeRTOS returns the timer ID, SAFERTOS returns pdPASS,
errNULL_PARAMETER_SUPPLIED or errINVALID_TIMER_HANDLE
vTimerSetTimerID() Not implemented. In SAFERTOS, the timer ID is set when the timer is created. Arbitrary
timer-specific storage may be implemented via the timer local storage
object, accessible using pvTimerTLSObjectGet ()
xEventGroupGetBits() xEventGroupGetBits() FreeRTOS returns the event group bits that are set, or NULL.
SAFERTOS returns pdPASS, errNULL_PARAMETER_SUPPLIED or
errINVALID_EVENT_GROUP_HANDLE
xEventGroupGetBitsFromISR() xEventGroupGetBitsFromISR() FreeRTOS returns the event group bits that are set, or NULL.
SAFERTOS returns pdPASS, errNULL_PARAMETER_SUPPLIED or
errINVALID_EVENT_GROUP_HANDLE
xEventGroupWaitBits() xEventGroupWaitBits() FreeRTOS returns the value of the event group at the time the function
returns. SAFERTOS returns pdPASS,
errSCHEDULER_IS_SUSPENDED,
errNULL_PARAMETER_SUPPLIED, errINVALID_PARAMETERS,
errINVALID_EVENT_GROUP_HANDLE,
errEVENT_GROUP_DELETED or
errEVENT_GROUP_BITS_NOT_SET
xStreamBufferBytesAvailable() xStreamBufferBytesAvailable() FreeRTOS returns the number of bytes available, SAFERTOS returns
the status code: pdPASS, errSB_NULL_HANDLE,
errSB_INVALID_HANDLE.
xStreamBufferReceive() xStreamBufferReceive() FreeRTOS returns the number of bytes read by the API function.
SAFERTOS instead returns pdPASS if the operation was successful,
or errSB_NULL_HANDLE, errSB_SMALL_BUFFER,
errSB_NOTIFICATION_TIMEOUT, errSB_INVALID_HANDLE,
errSCHEDULER_IS_NOT_RUNNING if the operation failed.
The number of bytes read is passed out using the parameter
puxTotalBytesRead.
xStreamBufferReceiveFromISR() xStreamBufferReceiveFromISR() FreeRTOS returns the number of bytes read by the API function.
SAFERTOS instead returns pdPASS if the operation was successful,
or errSB_NULL_HANDLE, errSB_SMALL_BUFFER,
errSB_INVALID_HANDLE, errSCHEDULER_IS_NOT_RUNNING if
the operation failed.
The number of bytes read is passed out using the parameter
puxTotalBytesRead.
xStreamBufferReset() xStreamBufferReset() FreeRTOS returns pdPASS or pdFAIL. SAFERTOS can also return
errSB_NULL_HANDLE, errSB_INVALID_HANDLE.
xStreamBufferSend() xStreamBufferSend() FreeRTOS returns pdPASS or pdFAIL. SAFERTOS can also return
errSB_NULL_HANDLE, errSB_INVALID_HANDLE,
errSB_SMALL_BUFFER, errSCHEDULER_IS_NOT_RUNNING,
errSB_NOTIFICATION_TIMEOUT.
FreeRTOS returns the number of bytes written to the streambuffer.
SAFERTOS passes this value out via the puxBytesWritten parameter.
xStreamBufferSendFromISR() xStreamBufferSendFromISR() FreeRTOS returns pdPASS or pdFAIL. SAFERTOS can also return
errSB_NULL_HANDLE, errSB_INVALID_HANDLE,
errSB_SMALL_BUFFER, errSCHEDULER_IS_NOT_RUNNING,
errSB_NOTIFICATION_TIMEOUT.
FreeRTOS returns the number of bytes written to the streambuffer.
SAFERTOS passes this value out via the puxBytesWritten parameter.
xStreamBufferSetTriggerLevel() xStreamBufferSetTriggerLevel() FreeRTOS returns whether the new trigger level has been met, as
pdTRUE or pdFALSE.
SAFERTOS returns pdPASS if no error has occurred, or an error
code: errSB_ZERO_TRIGGER, errSB_TRIGGER_TOO_HIGH,
errSB_INVALID_HANDLE, errSB_NULL_HANDLE.
SAFERTOS does not indicate whether the new trigger level has been
met.
xStreamBufferSpacesAvailable() xStreamBufferSpacesAvailable() FreeRTOS returns the number of bytes that can be written to the
stream buffer before the stream buffer would be full.
SAFERTOS returns a status code; pdPASS if the operation was
successful, otherwise it will return errSB_NULL_HANDLE or
errSB_INVALID_HANDLE.
SAFERTOS passes the number of bytes that can be written to the
stream buffer before the stream buffer would be full back via the
parameter puxSpace.
CONFIGURATION PARAMETERS
While FreeRTOS offers a large number of configuration parameters via the FreeRTOSConfig.h
header file, SAFERTOS implements a fixed configuration, with a restricted number of configuration
macros. These are listed on Table 5-1.
ERROR REPORTING
SAFERTOS functions generally return an error code or pdPASS, and those that need to have an
extra reference parameter in which to return data.
Care must be taken that application code is updated to correctly interpret the increased number of
function return values. For example, under FreeRTOS the code depicted by Listing 1 is valid because
xQueueSend() only returns one of two values indicating either success or failure. Under SAFERTOS
the code must be changed to that depicted by Listing 2 as only a value of pdPASS would indicate
success – whereas one of a number of values are used to indicate the cause of failure.
MISCELLANEOUS
In order for an application to call a SAFERTOS API function, the source file simply needs to include
the SafeRTOS_API.h header file – so long as the compiler can locate the other SAFERTOS header
files, the required header files will be automatically included.
The host application (the application that uses SAFERTOS) is required to provide an "Error Hook"
(or callback) function. In addition, the host application can optionally supply other hook functions: an
"Idle Hook", "Task Delete Hook", “System Call Hook” (or similar, depending on the specific port layer
used), "Tick Hook", a function to set up the tick interrupt timer and other architecture-specific hooks.
SAFERTOS calls the Error Hook function upon the detection of a fatal error – either a corruption
within the scheduler data structures or a potential stack overflow while performing a context switch.
The purpose of the Error Hook function is to allow the host application to place the system into a
‘safe state’.
Typically, SAFERTOS contains ‘weak’ definitions of optional hook functions, which can therefore be
overridden by alternative definitions in the host application. A pointers to the “System Call Hook”
function is passed to SAFERTOS as part of the xPORT_INIT_PARAMETERS structure referenced
in the call to xTaskInitializeScheduler(). Refer to the Architecture Variant SAFERTOS User Manual
[Reference 1] for a full description, and SafeRTOSConfig.c of the accompanying demonstration
application for further information.
NOTE: some FreeRTOS ports support a Task Switch Hook, which is called at every context switch.
This is not part of the official API for either FreeRTOS or SAFERTOS, and it is only supported on a
restricted number of SAFERTOS ports. Refer to the Architecture Variant SAFERTOS User Manual
[Reference 1] to confirm whether a Task Switch Hook is supported.
FreeRTOS has a directory, ‘include’ with all its .h files, contained within the kernel source directory.
SAFERTOS v9 has a more complex directory structure:
• SafeRTOS
o api – contains the files with the api related functionality of the portable layer. This is
where the SafeRTOS_API.h file is, which should be included by the host application
to use SAFERTOS;
o portable – contains the architecture and compiler specific code to support the
common files.
FreeRTOS does not have a semaphore, mutex .c or evtmplx.c file. SAFERTOS has semaphore.c,
mutex.c and evtmplx.c.
The safertosapiMAX_DELAY macro is defined as the maximum number of ticks that can be
expressed (e.g. on a 32-bit platform it is usually defined as 0xFFFFFFFF).
This means that, under SAFERTOS, task cannot block forever. The maximum block time is
determined by the size of portTickType. For example, on a 32-bit platform, this is equal to
4294967295 ticks; if the tick rate is 1 kHz, this value translates into about 49 days.
FreeRTOS includes the tick-less mode feature, which allows the system to enter a low-power mode
when no tasks are in the Ready state. The implementation of this feature is platform-specific and
should be implemented in the domain of the host application.
SAFERTOS includes some ports that implement tick-less mode, also called Ultra Low-Power Mode
(ULPM). On such ports the ULPM feature is always enabled, but it is possible to inhibit the transition
to low power mode. Check the architecture variant SAFERTOS v9 User Manual [Reference 1] for
more details.
User feedback is essential to the continued maintenance and development of SAFERTOS. Please
provide all software and documentation comments and suggestions to the most convenient contact
point listed below.
Website www.HighIntegritySystems.com