foxBMS - Unit Tests  1.4.0
The foxBMS Unit Tests API Documentation
os.h File Reference

Declaration of the OS wrapper interface. More...

#include "general.h"
Include dependency graph for os.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  OS_TIMER_s
 OS timer. More...
 
struct  OS_TASK_DEFINITION_s
 struct for FreeRTOS task definition More...
 

Enumerations

enum  OS_STD_RETURN_e { OS_SUCCESS , OS_FAIL }
 
enum  OS_PRIORITY_e {
  OS_PRIORITY_IDLE , OS_PRIORITY_LOW , OS_PRIORITY_BELOW_NORMAL , OS_PRIORITY_NORMAL ,
  OS_PRIORITY_ABOVE_NORMAL , OS_PRIORITY_HIGH , OS_PRIORITY_ABOVE_HIGH , OS_PRIORITY_VERY_HIGH ,
  OS_PRIORITY_BELOW_REALTIME , OS_PRIORITY_REAL_TIME
}
 typedef for thread priority. The higher the value, the higher the priority. More...
 
enum  OS_BOOT_STATE_e {
  OS_OFF , OS_INITIALIZE_SCHEDULER , OS_CREATE_QUEUES , OS_CREATE_TASKS ,
  OS_INIT_PRE_OS , OS_SCHEDULER_RUNNING , OS_ENGINE_RUNNING , OS_PRE_CYCLIC_INITIALIZATION_HAS_FINISHED ,
  OS_SYSTEM_RUNNING , OS_INIT_OS_FATALERROR_SCHEDULER , OS_INIT_OS_FATALERROR , OS_BOOT_STATE_MAX
}
 enum of OS boot states More...
 

Functions

void OS_InitializeScheduler (void)
 Initialization function for the scheduler. More...
 
void OS_StartScheduler (void)
 Starts the operating system scheduler. More...
 
void OS_InitializeOperatingSystem (void)
 Initialization the RTOS interface. More...
 
void vApplicationIdleHook (void)
 Hook function for the idle task. More...
 
void OS_EnterTaskCritical (void)
 Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR. More...
 
void OS_ExitTaskCritical (void)
 Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR. More...
 
void OS_IncrementTimer (void)
 Increments the system timer os_timer. More...
 
uint32_t OS_GetTickCount (void)
 Returns OS based system tick value. More...
 
void OS_DelayTaskUntil (uint32_t *pPreviousWakeTime, uint32_t milliseconds)
 Delay a task until a specified time. More...
 
void OS_MarkTaskAsRequiringFpuContext (void)
 Marks the current task as requiring FPU context. More...
 
OS_STD_RETURN_e OS_ReceiveFromQueue (OS_QUEUE xQueue, void *const pvBuffer, uint32_t ticksToWait)
 Receive an item from a queue. More...
 
OS_STD_RETURN_e OS_SendToBackOfQueue (OS_QUEUE xQueue, const void *const pvItemToQueue, uint32_t ticksToWait)
 Post an item to the back the provided queue. More...
 
OS_STD_RETURN_e OS_SendToBackOfQueueFromIsr (OS_QUEUE xQueue, const void *const pvItemToQueue, long *const pxHigherPriorityTaskWoken)
 Post an item to the back the provided queue during an ISR. More...
 
uint32_t OS_GetNumberOfStoredMessagesInQueue (OS_QUEUE xQueue)
 Check if messages are waiting for queue. More...
 
bool OS_CheckTimeHasPassed (uint32_t oldTimeStamp_ms, uint32_t timeToPass_ms)
 This function checks if timeToPass has passed since the last timestamp to now. More...
 
bool OS_CheckTimeHasPassedWithTimestamp (uint32_t oldTimeStamp_ms, uint32_t currentTimeStamp_ms, uint32_t timeToPass_ms)
 This function checks if timeToPass has passed since the last timestamp to now. More...
 
STD_RETURN_TYPE_e OS_CheckTimeHasPassedSelfTest (void)
 Does a self check if the OS_CheckTimeHasPassedWithTimestamp works as expected. More...
 
OS_TIMER_sTEST_OS_GetOsTimer ()
 

Variables

volatile OS_BOOT_STATE_e os_boot
 
uint32_t os_schedulerStartTime
 Scheduler "zero" time for task phase control. More...
 

Detailed Description

Declaration of the OS wrapper interface.

SPDX-License-Identifier: BSD-3-Clause

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:

  • ″This product uses parts of foxBMS®″
  • ″This product includes parts of foxBMS®″
  • ″This product is derived from foxBMS®″
Author
foxBMS Team
Date
2019-08-27 (date of creation)
Updated
2022-07-28 (date of last update)
Version
v1.4.0
Prefix
OS

This module describes the interface to different operating systems

Definition in file os.h.

Enumeration Type Documentation

◆ OS_BOOT_STATE_e

enum of OS boot states

Enumerator
OS_OFF 

system is off

OS_INITIALIZE_SCHEDULER 

state right before initializing the scheduler

OS_CREATE_QUEUES 

state right before queues are created

OS_CREATE_TASKS 

state right before tasks are created

OS_INIT_PRE_OS 

state right after tasks are created

OS_SCHEDULER_RUNNING 

scheduler is running

OS_ENGINE_RUNNING 

state right after scheduler is started and engine is initalized

OS_PRE_CYCLIC_INITIALIZATION_HAS_FINISHED 

state after the pre-cyclic init has finished

OS_SYSTEM_RUNNING 

system is running

OS_INIT_OS_FATALERROR_SCHEDULER 

error in scheduler

OS_INIT_OS_FATALERROR 

fatal error

OS_BOOT_STATE_MAX 

DO NOT CHANGE, MUST BE THE LAST ENTRY

Definition at line 100 of file os.h.

◆ OS_PRIORITY_e

typedef for thread priority. The higher the value, the higher the priority.

Enumerator
OS_PRIORITY_IDLE 

priority: idle (lowest)

OS_PRIORITY_LOW 

priority: low

OS_PRIORITY_BELOW_NORMAL 

priority: below normal

OS_PRIORITY_NORMAL 

priority: normal (default)

OS_PRIORITY_ABOVE_NORMAL 

priority: above normal

OS_PRIORITY_HIGH 

priority: high

OS_PRIORITY_ABOVE_HIGH 

priority: above high

OS_PRIORITY_VERY_HIGH 

priority: very high

OS_PRIORITY_BELOW_REALTIME 

priority: below realtime

OS_PRIORITY_REAL_TIME 

priority: realtime (highest)

Definition at line 86 of file os.h.

◆ OS_STD_RETURN_e

enum to encapsulate function returns from the OS-wrapper layer

Enumerator
OS_SUCCESS 

OS-dependent operation successful

OS_FAIL 

OS-dependent operation unsuccessful

Definition at line 77 of file os.h.

Function Documentation

◆ OS_CheckTimeHasPassed()

bool OS_CheckTimeHasPassed ( uint32_t  oldTimeStamp_ms,
uint32_t  timeToPass_ms 
)

This function checks if timeToPass has passed since the last timestamp to now.

This function retrieves the current time stamp with OS_GetTickCount(), compares it to the oldTimestamp_ms and checks if more or equal of timeToPass_ms timer increments have passed.

Parameters
[in]oldTimeStamp_mstimestamp that shall be compared to the current time in ms
[in]timeToPass_mstimer increments (in ms) that shall pass between oldTimeStamp_ms and now
Returns
true in the case that more than timeToPass_ms timer increments have passed, otherwise false

Definition at line 144 of file os.c.

Here is the call graph for this function:

◆ OS_CheckTimeHasPassedSelfTest()

STD_RETURN_TYPE_e OS_CheckTimeHasPassedSelfTest ( void  )

Does a self check if the OS_CheckTimeHasPassedWithTimestamp works as expected.

This functions tests some values with OS_CheckTimeHasPassedWithTimestamp(). It is intended to be side-effect free and to be callable any time to verify from the running program if this portion of the software is working as expected. returns STD_OK if the self check passes successfully, STD_NOT_OK otherwise

Definition at line 148 of file os.c.

Here is the call graph for this function:

◆ OS_CheckTimeHasPassedWithTimestamp()

bool OS_CheckTimeHasPassedWithTimestamp ( uint32_t  oldTimeStamp_ms,
uint32_t  currentTimeStamp_ms,
uint32_t  timeToPass_ms 
)

This function checks if timeToPass has passed since the last timestamp to now.

This function is passed the current time stamp as argument currentTimeStamp_ms, compares it to the oldTimestamp_ms and checks if more or equal of timeToPass_ms timer increments have passed.

Parameters
[in]oldTimeStamp_mstimestamp that shall be compared to the current time in ms
[in]currentTimeStamp_mstimestamp of the current time in ms
[in]timeToPass_mstimer increments (in ms) that shall pass between oldTimeStamp_ms and now
Returns
true in the case that more than timeToPass_ms timer increments have passed, otherwise false

Definition at line 118 of file os.c.

◆ OS_DelayTaskUntil()

void OS_DelayTaskUntil ( uint32_t *  pPreviousWakeTime,
uint32_t  milliseconds 
)

Delay a task until a specified time.

TODO

Parameters
pPreviousWakeTimePointer to a variable that holds the time at which the task was last unblocked. PreviousWakeTime must be initialized with the current time prior to its first use (PreviousWakeTime = OS_osSysTick()).
millisecondstime delay value in milliseconds

Definition at line 143 of file os_freertos.c.

◆ OS_EnterTaskCritical()

void OS_EnterTaskCritical ( void  )

Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.

checks the function context (task/thread mode or interrupt (handler) mode) and calls the corresponding enter-critical function

Definition at line 131 of file os_freertos.c.

◆ OS_ExitTaskCritical()

void OS_ExitTaskCritical ( void  )

Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.

Checks the function context (task/thread mode or interrupt (handler) mode) and calls the corresponding exit-critical function

Definition at line 135 of file os_freertos.c.

◆ OS_GetNumberOfStoredMessagesInQueue()

uint32_t OS_GetNumberOfStoredMessagesInQueue ( OS_QUEUE  xQueue)

Check if messages are waiting for queue.

This function needs to implement the wrapper to OS specific queue posting.

Parameters
xQueuequeue handle that should be posted to.
Returns
number of message currently stored in xQueue

Definition at line 198 of file os_freertos.c.

◆ OS_GetTickCount()

uint32_t OS_GetTickCount ( void  )

Returns OS based system tick value.

TODO

Returns
time stamp in milliseconds, based on the operating system time.

Definition at line 139 of file os_freertos.c.

◆ OS_IncrementTimer()

void OS_IncrementTimer ( void  )

Increments the system timer os_timer.

The os_timer is a runtime-counter, counting the time since the last reset.

Definition at line 94 of file os.c.

◆ OS_InitializeOperatingSystem()

void OS_InitializeOperatingSystem ( void  )

Initialization the RTOS interface.

This function initializes the scheduler and then creates queues and tasks.

Definition at line 79 of file os.c.

Here is the call graph for this function:

◆ OS_InitializeScheduler()

void OS_InitializeScheduler ( void  )

Initialization function for the scheduler.

Definition at line 73 of file os_freertos.c.

◆ OS_MarkTaskAsRequiringFpuContext()

void OS_MarkTaskAsRequiringFpuContext ( void  )

Marks the current task as requiring FPU context.

In order to avoid corruption of the registers of the floating point unit during a task switch, every task that uses the FPU has to call this function at its start.

This instructs the underlying operating system to store the context of the FPU when switching a task.

This function has to be called from within a task.

Definition at line 153 of file os_freertos.c.

◆ OS_ReceiveFromQueue()

OS_STD_RETURN_e OS_ReceiveFromQueue ( OS_QUEUE  xQueue,
void *const  pvBuffer,
uint32_t  ticksToWait 
)

Receive an item from a queue.

This function needs to implement the wrapper to OS specific queue posting. The queue needs to be implement in a FreeRTOS compatible way. This function must not be called from within an interrupt service routine (due to the FreeRTOS compatibility of the the wrapper).

Parameters
xQueueFreeRTOS compatible queue handle that should be posted to
pvBufferPointer to the buffer into which the received item is posted to.
ticksToWaitticks to wait
Returns
OS_SUCCESS if an item was successfully received, otherwise OS_FAIL.

Definition at line 157 of file os_freertos.c.

◆ OS_SendToBackOfQueue()

OS_STD_RETURN_e OS_SendToBackOfQueue ( OS_QUEUE  xQueue,
const void *const  pvItemToQueue,
uint32_t  ticksToWait 
)

Post an item to the back the provided queue.

This function needs to implement the wrapper to OS specific queue posting. The queue needs to be implement in a FreeRTOS compatible way.

Parameters
xQueueFreeRTOS compatible queue handle that should be posted to.
pvItemToQueuePointer to the item to be posted in the queue.
ticksToWaitticks to wait
Returns
OS_SUCCESS if the item was successfully posted, otherwise OS_FAIL.

Definition at line 170 of file os_freertos.c.

◆ OS_SendToBackOfQueueFromIsr()

OS_STD_RETURN_e OS_SendToBackOfQueueFromIsr ( OS_QUEUE  xQueue,
const void *const  pvItemToQueue,
long *const  pxHigherPriorityTaskWoken 
)

Post an item to the back the provided queue during an ISR.

This function needs to implement the wrapper to OS specific queue posting.

Parameters
xQueuequeue handle that should be posted to.
pvItemToQueuePointer to the item to be posted in the queue.
pxHigherPriorityTaskWokenIndicates whether a context switch is required or not. If the parameter is a NULL_PTR, the context switch will happen at the next tick.
Returns
OS_SUCCESS if the item was successfully posted, otherwise OS_FAIL.

Definition at line 182 of file os_freertos.c.

◆ OS_StartScheduler()

void OS_StartScheduler ( void  )

Starts the operating system scheduler.

Definition at line 79 of file os_freertos.c.

◆ TEST_OS_GetOsTimer()

OS_TIMER_s* TEST_OS_GetOsTimer ( )

Definition at line 185 of file os.c.

◆ vApplicationIdleHook()

void vApplicationIdleHook ( void  )

Hook function for the idle task.

This is an FreeRTOS function an does not adhere to foxBMS function naming conventions

Definition at line 121 of file os_freertos.c.

Here is the call graph for this function:

Variable Documentation

◆ os_boot

volatile OS_BOOT_STATE_e os_boot
extern

boot state of the system

boot state of the OS

Definition at line 69 of file os.c.

◆ os_schedulerStartTime

uint32_t os_schedulerStartTime
extern

Scheduler "zero" time for task phase control.

timestamp of the scheduler start

Definition at line 71 of file os.c.