foxBMS - Unit Tests  1.2.1
The foxBMS Unit Tests API Documentation
ftask_freertos.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3. Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * We kindly request you to use one or more of the following phrases to refer to
34  * foxBMS in your hardware, software, documentation or advertising materials:
35  *
36  * - ″This product uses parts of foxBMS®″
37  * - ″This product includes parts of foxBMS®″
38  * - ″This product is derived from foxBMS®″
39  *
40  */
41 
42 /**
43  * @file ftask_freertos.c
44  * @author foxBMS Team
45  * @date 2019-08-27 (date of creation)
46  * @updated 2021-12-01 (date of last update)
47  * @ingroup TASK
48  * @prefix FTSK
49  *
50  * @brief OS specific, i.e., FreeRTOS specfific, creation of the tasks
51  * @details TODO
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "can_cfg.h"
56 
57 #include "FreeRTOS.h"
58 #include "task.h"
59 
60 #include "database.h"
61 #include "ftask.h"
62 
63 /*========== Macros and Definitions =========================================*/
64 
65 /*========== Static Constant and Variable Definitions =======================*/
66 
67 /*========== Extern Constant and Variable Definitions =======================*/
68 volatile bool ftsk_allQueuesCreated = false;
69 
70 QueueHandle_t ftsk_databaseQueue = NULL_PTR;
71 
73 
74 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE can-documentation-rx-queue-handle-start-include */
75 QueueHandle_t ftsk_canRxQueue = NULL_PTR;
76 /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE can-documentation-rx-queue-handle-stop-include */
77 
78 /*========== Static Function Prototypes =====================================*/
79 
80 /*========== Static Function Implementations ================================*/
81 
82 /*========== Extern Function Implementations ================================*/
83 
84 extern void FTSK_CreateQueues(void) {
85  /**
86  * @brief size of storage area for the database queue
87  * @details The array that is used for the queue's storage area.
88  * This must be at least
89  * #FTSK_DATABASE_QUEUE_LENGTH * #FTSK_DATABASE_QUEUE_ITEM_SIZE
90  */
91  static uint8_t ftsk_databaseQueueStorageArea[FTSK_DATABASE_QUEUE_LENGTH * FTSK_DATABASE_QUEUE_ITEM_SIZE] = {0};
92  static StaticQueue_t ftsk_databaseQueueStructure = {0}; /*!< structure for static database queue */
93 
94  /* Create a queue capable of containing a pointer of type DATA_QUEUE_MESSAGE_s
95  Data of Messages are passed by pointer as they contain a lot of data. */
96  ftsk_databaseQueue = xQueueCreateStatic(
99  ftsk_databaseQueueStorageArea,
100  &ftsk_databaseQueueStructure);
102  vQueueAddToRegistry(ftsk_databaseQueue, "Database Queue");
103 
104  /**
105  * @brief size of storage area for the IMD queue
106  * @details The array that is used for the queue's storage area.
107  * This must be at least
108  * #FTSK_IMD_QUEUE_LENGTH * #FTSK_IMD_QUEUE_ITEM_SIZE
109  */
111  static StaticQueue_t ftsk_imdQueueStructure = {0}; /*!< structure for static data queue */
112 
113  ftsk_imdCanDataQueue = xQueueCreateStatic(
115  vQueueAddToRegistry(ftsk_imdCanDataQueue, "IMD CAN Data Queue");
117 
118  /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE can-documentation-rx-queue-vars-start-include */
119  static StaticQueue_t ftsk_canRxQueueStructure = {0}; /*!< structure for static data queue */
120  /**
121  * @brief size of storage area for the CAN Rx queue
122  * @details The array that is used for the queue's storage area.
123  * This must be at least
124  * #FTSK_CAN_RX_QUEUE_LENGTH * #FTSK_CAN_RX_QUEUE_ITEM_SIZE
125  */
127  /* INCLUDE MARKER FOR THE DOCUMENTATION; DO NOT MOVE can-documentation-rx-queue-vars-stop-include */
128 
129  ftsk_canRxQueue = xQueueCreateStatic(
131  vQueueAddToRegistry(ftsk_canRxQueue, "CAN Receive Queue");
133 
135  ftsk_allQueuesCreated = true;
137 }
138 
139 extern void FTSK_CreateTasks(void) {
140  /* Engine Task */
141  static StaticTask_t ftsk_taskEngine = {0};
142  static StackType_t ftsk_stackSizeEngine[FTSK_TASK_ENGINE_STACK_SIZE] = {0};
143 
144  const TaskHandle_t ftsk_taskHandleEngine = xTaskCreateStatic(
145  (TaskFunction_t)FTSK_CreateTaskEngine,
146  (const portCHAR *)"TaskEngine",
149  (UBaseType_t)ftsk_taskDefinitionEngine.priority,
150  ftsk_stackSizeEngine,
151  &ftsk_taskEngine);
152  FAS_ASSERT(ftsk_taskHandleEngine != NULL); /* Trap if initialization failed */
153 
154  /* Cyclic Task 1ms */
155  static StaticTask_t ftsk_taskCyclic1ms = {0};
156  static StackType_t ftsk_stackSizeCyclic1ms[FTSK_TASK_CYCLIC_1MS_STACK_SIZE] = {0};
157 
158  const TaskHandle_t ftsk_taskHandleCyclic1ms = xTaskCreateStatic(
159  (TaskFunction_t)FTSK_CreateTaskCyclic1ms,
160  (const portCHAR *)"TaskCyclic1ms",
164  ftsk_stackSizeCyclic1ms,
165  &ftsk_taskCyclic1ms);
166  FAS_ASSERT(ftsk_taskHandleCyclic1ms != NULL); /* Trap if initialization failed */
167 
168  /* Cyclic Task 10ms */
169  static StaticTask_t ftsk_taskCyclic10ms = {0};
170  static StackType_t ftsk_stackSizeCyclic10ms[FTSK_TASK_CYCLIC_10MS_STACK_SIZE] = {0};
171 
172  const TaskHandle_t ftsk_taskHandleCyclic10ms = xTaskCreateStatic(
173  (TaskFunction_t)FTSK_CreateTaskCyclic10ms,
174  (const portCHAR *)"TaskCyclic10ms",
178  ftsk_stackSizeCyclic10ms,
179  &ftsk_taskCyclic10ms);
180  FAS_ASSERT(ftsk_taskHandleCyclic10ms != NULL); /* Trap if initialization failed */
181 
182  /* Cyclic Task 100ms */
183  static StaticTask_t ftsk_taskCyclic100ms = {0};
184  static StackType_t ftsk_stackSizeCyclic100ms[FTSK_TASK_CYCLIC_100MS_STACK_SIZE] = {0};
185 
186  const TaskHandle_t ftsk_taskHandleCyclic100ms = xTaskCreateStatic(
187  (TaskFunction_t)FTSK_CreateTaskCyclic100ms,
188  (const portCHAR *)"TaskCyclic100ms",
192  ftsk_stackSizeCyclic100ms,
193  &ftsk_taskCyclic100ms);
194  FAS_ASSERT(ftsk_taskHandleCyclic100ms != NULL); /* Trap if initialization failed */
195 
196  /* Cyclic Task 100ms for algorithms */
197  static StaticTask_t ftsk_taskCyclicAlgorithm100ms = {0};
198  static StackType_t ftsk_stackSizeCyclicAlgorithm100ms[FTSK_TASK_CYCLIC_ALGORITHM_100MS_STACKSIZE] = {0};
199 
200  const TaskHandle_t ftsk_taskHandleCyclicAlgorithm100ms = xTaskCreateStatic(
201  (TaskFunction_t)FTSK_CreateTaskCyclicAlgorithm100ms,
202  (const portCHAR *)"TaskCyclicAlgorithm100ms",
206  ftsk_stackSizeCyclicAlgorithm100ms,
207  &ftsk_taskCyclicAlgorithm100ms);
208  FAS_ASSERT(ftsk_taskHandleCyclicAlgorithm100ms != NULL); /* Trap if initialization failed */
209 }
210 
211 /*========== Externalized Static Function Implementations (Unit Test) =======*/
Headers for the configuration for the CAN module.
Database module header.
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:235
#define NULL
NULL definition.
Definition: fstd_types.h:65
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:75
void FTSK_CreateTaskEngine(void *const pvParameters)
Database-Task.
Definition: ftask.c:73
void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters)
Creation of cyclic 100 ms algorithm task.
Definition: ftask.c:180
void FTSK_CreateTaskCyclic100ms(void *const pvParameters)
Creation of cyclic 100 ms task.
Definition: ftask.c:153
void FTSK_CreateTaskCyclic10ms(void *const pvParameters)
Creation of cyclic 10 ms task.
Definition: ftask.c:126
void FTSK_CreateTaskCyclic1ms(void *const pvParameters)
Creation of cyclic 1 ms task.
Definition: ftask.c:95
Header of task driver implementation.
#define FTSK_DATABASE_QUEUE_LENGTH
Definition: ftask.h:65
#define FTSK_CAN_RX_QUEUE_LENGTH
Definition: ftask.h:76
#define FTSK_IMD_QUEUE_ITEM_SIZE
Definition: ftask.h:73
#define FTSK_CAN_RX_QUEUE_ITEM_SIZE
Definition: ftask.h:78
#define FTSK_DATABASE_QUEUE_ITEM_SIZE
Definition: ftask.h:68
#define FTSK_IMD_QUEUE_LENGTH
Definition: ftask.h:71
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic100ms
Task configuration of the cyclic 100 ms task.
Definition: ftask_cfg.c:123
OS_TASK_DEFINITION_s ftsk_taskDefinitionEngine
Definition of the engine task.
Definition: ftask_cfg.c:105
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic1ms
Task configuration of the cyclic 1 ms task.
Definition: ftask_cfg.c:111
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclicAlgorithm100ms
Task configuration of the cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:129
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic10ms
Task configuration of the cyclic 10 ms task.
Definition: ftask_cfg.c:117
#define FTSK_TASK_ENGINE_STACK_SIZE
Stack size of engine task.
Definition: ftask_cfg.h:64
#define FTSK_TASK_CYCLIC_100MS_STACK_SIZE
Stack size of cyclic 100 ms task.
Definition: ftask_cfg.h:109
#define FTSK_TASK_CYCLIC_1MS_STACK_SIZE
Stack size of cyclic 1 ms task.
Definition: ftask_cfg.h:79
#define FTSK_TASK_CYCLIC_ALGORITHM_100MS_STACKSIZE
Stack size of cyclic 100 ms task for algorithms.
Definition: ftask_cfg.h:124
#define FTSK_TASK_CYCLIC_10MS_STACK_SIZE
Stack size of cyclic 10 ms task.
Definition: ftask_cfg.h:94
volatile bool ftsk_allQueuesCreated
QueueHandle_t ftsk_databaseQueue
void FTSK_CreateTasks(void)
Creates all tasks of the group.
QueueHandle_t ftsk_canRxQueue
void FTSK_CreateQueues(void)
Creates all queues.
QueueHandle_t ftsk_imdCanDataQueue
void OS_ExitTaskCritical(void)
Exit Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:125
void OS_EnterTaskCritical(void)
Enter Critical interface function for use in FreeRTOS-Tasks and FreeRTOS-ISR.
Definition: os_freertos.c:121
OS_PRIORITY_e priority
Definition: os.h:126
void * pvParameters
Definition: os.h:130
uint16_t stackSize
Definition: os.h:129
static uint8_t ftsk_imdQueueStorageArea[FTSK_IMD_QUEUE_LENGTH *FTSK_IMD_QUEUE_ITEM_SIZE]
static StaticQueue_t ftsk_canRxQueueStructure
static StaticQueue_t ftsk_imdQueueStructure
static uint8_t ftsk_canRxQueueStorageArea[FTSK_CAN_RX_QUEUE_LENGTH *FTSK_CAN_RX_QUEUE_ITEM_SIZE]