foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
os_freertos.c File Reference

FreeRTOS specific implementation of the tasks and resources used by the system. More...

#include "os.h"
#include "HL_sys_core.h"
#include "can_cbs_tx_crash-dump.h"
#include "ftask.h"
#include <stdint.h>
Include dependency graph for os_freertos.c:

Go to the source code of this file.

Functions

void OS_InitializeScheduler (void)
 Initialization function for the scheduler. More...
 
void OS_StartScheduler (void)
 Starts the operating system scheduler. More...
 
void vApplicationGetIdleTaskMemory (StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize)
 
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...
 
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_WaitForNotification (uint32_t *pNotifiedValue, uint32_t timeout)
 Wait for a notification. More...
 
OS_STD_RETURN_e OS_NotifyFromIsr (TaskHandle_t taskToNotify, uint32_t notifiedValue)
 Notify a task. More...
 
OS_STD_RETURN_e OS_WaitForNotificationIndexed (uint32_t indexToWaitOn, uint32_t *pNotifiedValue, uint32_t timeout)
 Wait for a notification, with index. More...
 
OS_STD_RETURN_e OS_NotifyIndexedFromIsr (TaskHandle_t taskToNotify, uint32_t indexToNotify, uint32_t notifiedValue)
 Notify a task, with index. More...
 
OS_STD_RETURN_e OS_ClearNotificationIndexed (uint32_t indexToClear)
 Clear pending notification of a task, with index. 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...
 

Detailed Description

FreeRTOS specific implementation of the tasks and resources used by the system.

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
2021-11-18 (date of creation)
Updated
2023-10-12 (date of last update)
Version
v1.6.0
Prefix
OS

Definition in file os_freertos.c.

Function Documentation

◆ OS_ClearNotificationIndexed()

OS_STD_RETURN_e OS_ClearNotificationIndexed ( uint32_t  indexToClear)

Clear pending notification of a task, with index.

This function needs to implement the wrapper to OS specific task notification clearing. It clears the pending notification for the calling task. This function must not be called from within an interrupt service routine (due to the FreeRTOS compatibility of the the wrapper). This function clears a pending notification corresponding to the index passed as parameter.

Parameters
indexToClearIndex of the notification to clear
Returns
OS_SUCCESS if a notification was pending, otherwise OS_FAIL

Definition at line 251 of file os_freertos.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 162 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 150 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 154 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 305 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 158 of file os_freertos.c.

◆ OS_InitializeScheduler()

void OS_InitializeScheduler ( void  )

Initialization function for the scheduler.

Definition at line 76 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 172 of file os_freertos.c.

◆ OS_NotifyFromIsr()

OS_STD_RETURN_e OS_NotifyFromIsr ( TaskHandle_t  taskToNotify,
uint32_t  notifiedValue 
)

Notify a task.

This function needs to implement the wrapper to OS specific task notification. This function is to be called from within an interrupt service routine (due to the FreeRTOS compatibility of the the wrapper). This function makes a notification to the task whose handle is is passed as parameter. Typically the notification is made in an interrupt. The value to notify is passed to the notified task.

Parameters
taskToNotifyHandle of task to notify.
notifiedValueValue to pass to the notified task
Returns
OS_SUCCESS if a notification was successfully made, otherwise OS_FAIL

Definition at line 192 of file os_freertos.c.

◆ OS_NotifyIndexedFromIsr()

OS_STD_RETURN_e OS_NotifyIndexedFromIsr ( TaskHandle_t  taskToNotify,
uint32_t  indexToNotify,
uint32_t  notifiedValue 
)

Notify a task, with index.

This function needs to implement the wrapper to OS specific task notification. This function is to be called from within an interrupt service routine (due to the FreeRTOS compatibility of the the wrapper). This function makes a notification with an index to the task whose handle is passed as parameter. Typically the notification is made in an interrupt. The value to notify and the index are passed to the notified task.

Parameters
taskToNotifyHandle of task to notify
indexToNotifyIndex to notify
notifiedValueValue to pass to the notified task
Returns
OS_SUCCESS if a notification was successfully made, otherwise OS_FAIL.

Definition at line 230 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 264 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 277 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 289 of file os_freertos.c.

◆ OS_StartScheduler()

void OS_StartScheduler ( void  )

Starts the operating system scheduler.

Definition at line 82 of file os_freertos.c.

◆ OS_WaitForNotification()

OS_STD_RETURN_e OS_WaitForNotification ( uint32_t *  pNotifiedValue,
uint32_t  timeout 
)

Wait for a notification.

This function needs to implement the wrapper to OS specific blocking task and waiting for notification. This function must not be called from within an interrupt service routine (due to the FreeRTOS compatibility of the the wrapper). This function blocks the current tasks and wait for a notification. Typically the notification is made in an interrupt. The notified value is passed by the notifying function. The tasks unblocks when the notification is received or when timeout milliseconds have passed.

Parameters
pNotifiedValueValue passed by the notify function
timeoutticks to wait before unblocking task if no notification is received
Returns
OS_SUCCESS if a notification was successfully received, otherwise OS_FAIL

Definition at line 176 of file os_freertos.c.

◆ OS_WaitForNotificationIndexed()

OS_STD_RETURN_e OS_WaitForNotificationIndexed ( uint32_t  indexToWaitOn,
uint32_t *  pNotifiedValue,
uint32_t  timeout 
)

Wait for a notification, with index.

This function needs to implement the wrapper to OS specific blocking task and waiting for notification. This function must not be called from within an interrupt service routine (due to the FreeRTOS compatibility of the the wrapper). This function blocks the current tasks and wait for a notification and a specific index. Typically the notification is made in an interrupt. The notified value and index are passed by the notifying function. The tasks unblocks when the notification is received or when timeout milliseconds have passed.

Parameters
indexToWaitOnindex to wait on
pNotifiedValueValue passed by the notify function
timeoutticks to wait before unblocking task if no notification is received
Returns
OS_SUCCESS if a notification was successfully received, otherwise OS_FAIL

Definition at line 210 of file os_freertos.c.

◆ vApplicationGetIdleTaskMemory()

void vApplicationGetIdleTaskMemory ( StaticTask_t **  ppxIdleTaskTCBBuffer,
StackType_t **  ppxIdleTaskStackBuffer,
uint32_t *  pulIdleTaskStackSize 
)

Buffer for the Idle Task's structure

Stack for the Idle task

Definition at line 88 of file os_freertos.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 124 of file os_freertos.c.

Here is the call graph for this function: