foxBMS  1.6.0
The foxBMS Battery Management System API Documentation
ftask.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2023, 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.c
44  * @author foxBMS Team
45  * @date 2019-08-27 (date of creation)
46  * @updated 2023-10-12 (date of last update)
47  * @version v1.6.0
48  * @ingroup TASK
49  * @prefix FTSK
50  *
51  * @brief Implementation of OS-independent task creators
52  * @details TODO
53  */
54 
55 /*========== Includes =======================================================*/
56 #include "ftask.h"
57 
58 #include "sys_mon.h"
59 
60 #include <stdint.h>
61 
62 /*========== Macros and Definitions =========================================*/
63 
64 /*========== Static Constant and Variable Definitions =======================*/
65 
66 /*========== Extern Constant and Variable Definitions =======================*/
67 
68 /*========== Static Function Prototypes =====================================*/
69 
70 /*========== Static Function Implementations ================================*/
71 
72 /*========== Extern Function Implementations ================================*/
73 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
74  * that this function is a task, context save not necessary */
75 #pragma TASK(FTSK_CreateTaskEngine)
76 extern void FTSK_CreateTaskEngine(void *const pvParameters) {
77  FAS_ASSERT(pvParameters == NULL_PTR);
82 
83  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
84  * loop for the user code (see www.freertos.org/a00125.html)*/
85  while (true) {
86  /* notify system monitoring that task will be called */
88  /* user code implementation */
90  /* notify system monitoring that task has been called */
92  }
93 }
94 
95 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
96  * that this function is a task, context save not necessary */
97 #pragma TASK(FTSK_CreateTaskCyclic1ms)
98 extern void FTSK_CreateTaskCyclic1ms(void *const pvParameters) {
99  FAS_ASSERT(pvParameters == NULL_PTR);
101  uint32_t currentTimeCreateTaskCyclic1ms = 0;
102 
103  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: start cyclic 1ms task only when engine task is running */
104  while (os_boot != OS_ENGINE_RUNNING) {
105  }
106 
109 
110  /* cycle time (1ms) equals the minimum tick time (1ms),
111  * therefore it is not possible to configure a phase for this task */
112  currentTimeCreateTaskCyclic1ms = OS_GetTickCount();
113  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
114  * loop for the user code (see www.freertos.org/a00125.html)*/
115  while (true) {
116  /* notify system monitoring that task will be called */
118  /* user code implementation */
120  /* notify system monitoring that task has been called */
122  /* let task sleep until it is due again */
123  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic1ms, ftsk_taskDefinitionCyclic1ms.cycleTime);
124  }
125 }
126 
127 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
128  compiler that this function is a task, context save not necessary */
129 #pragma TASK(FTSK_CreateTaskCyclic10ms)
130 extern void FTSK_CreateTaskCyclic10ms(void *const pvParameters) {
131  FAS_ASSERT(pvParameters == NULL_PTR);
133  uint32_t currentTimeCreateTaskCyclic10ms = 0;
134 
135  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
136  pre-cyclic initialization sequence */
138  }
139 
141  currentTimeCreateTaskCyclic10ms = OS_GetTickCount();
142  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
143  * loop for the user code (see www.freertos.org/a00125.html)*/
144  while (true) {
145  /* notify system monitoring that task will be called */
147  /* user code implementation */
149  /* notify system monitoring that task has been called */
151  /* let task sleep until it is due again */
152  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic10ms, ftsk_taskDefinitionCyclic10ms.cycleTime);
153  }
154 }
155 
156 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
157  compiler that this function is a task, context save not necessary */
158 #pragma TASK(FTSK_CreateTaskCyclic100ms)
159 extern void FTSK_CreateTaskCyclic100ms(void *const pvParameters) {
160  FAS_ASSERT(pvParameters == NULL_PTR);
162  uint32_t currentTimeCreateTaskCyclic100ms = 0;
163 
164  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
165  pre-cyclic initialization sequence */
167  }
168 
170  currentTimeCreateTaskCyclic100ms = OS_GetTickCount();
171  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
172  * loop for the user code (see www.freertos.org/a00125.html)*/
173  while (true) {
174  /* notify system monitoring that task will be called */
176  /* user code implementation */
178  /* notify system monitoring that task has been called */
180  /* let task sleep until it is due again */
181  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic100ms, ftsk_taskDefinitionCyclic100ms.cycleTime);
182  }
183 }
184 
185 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
186  compiler that this function is a task, context save not necessary */
187 #pragma TASK(FTSK_CreateTaskCyclicAlgorithm100ms)
188 extern void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters) {
189  FAS_ASSERT(pvParameters == NULL_PTR);
191  uint32_t currentTimeCreateTaskCyclicAlgorithms100ms = 0;
192 
193  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
194  pre-cyclic initialization sequence */
196  }
197 
200  currentTimeCreateTaskCyclicAlgorithms100ms = OS_GetTickCount();
201  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
202  * loop for the user code (see www.freertos.org/a00125.html)*/
203  while (true) {
204  /* notify system monitoring that task will be called */
206  /* user code implementation */
208  /* notify system monitoring that task has been called */
210  /* let task sleep until it is due again */
212  &currentTimeCreateTaskCyclicAlgorithms100ms, ftsk_taskDefinitionCyclicAlgorithm100ms.cycleTime);
213  }
214 }
215 
216 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
217  compiler tell compiler this function is a task, context save not necessary */
218 #pragma TASK(FTSK_CreateTaskI2c)
219 extern void FTSK_CreateTaskI2c(void *const pvParameters) {
220  FAS_ASSERT(pvParameters == NULL_PTR);
222 
223  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
224  pre-cyclic initialization sequence */
226  }
227 
228  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
229  * loop for the user code (see www.freertos.org/a00125.html)*/
230  while (true) {
231  /* user code implementation */
233  }
234 }
235 
236 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
237  compiler tell compiler this function is a task, context save not necessary */
238 #pragma TASK(FTSK_CreateTaskAfe)
239 extern void FTSK_CreateTaskAfe(void *const pvParameters) {
240  FAS_ASSERT(pvParameters == NULL_PTR);
242 
243  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
244  pre-cyclic initialization sequence */
246  }
247 
248  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
249  * loop for the user code (see www.freertos.org/a00125.html)*/
250  while (true) {
251  /* user code implementation */
253  }
254 }
255 
256 /*========== Externalized Static Function Implementations (Unit Test) =======*/
257 #ifdef UNITY_UNIT_TEST
258 #endif
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:255
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:77
void FTSK_CreateTaskEngine(void *const pvParameters)
Database-Task.
Definition: ftask.c:76
void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters)
Creation of cyclic 100 ms algorithm task.
Definition: ftask.c:188
void FTSK_CreateTaskCyclic100ms(void *const pvParameters)
Creation of cyclic 100 ms task.
Definition: ftask.c:159
void FTSK_CreateTaskCyclic10ms(void *const pvParameters)
Creation of cyclic 10 ms task.
Definition: ftask.c:130
void FTSK_CreateTaskAfe(void *const pvParameters)
Creation of continuously running task for AFEs.
Definition: ftask.c:239
void FTSK_CreateTaskCyclic1ms(void *const pvParameters)
Creation of cyclic 1 ms task.
Definition: ftask.c:98
void FTSK_CreateTaskI2c(void *const pvParameters)
Creation of continuously running task for I2c.
Definition: ftask.c:219
Header of task driver implementation.
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic100ms
Task configuration of the cyclic 100 ms task.
Definition: ftask_cfg.c:127
void FTSK_RunUserCodeAfe(void)
Continuously running task for AFEs.
Definition: ftask_cfg.c:301
void FTSK_InitializeUserCodeEngine(void)
Initializes the database.
Definition: ftask_cfg.c:157
void FTSK_RunUserCodeEngine(void)
Engine task for the database and the system monitoring module.
Definition: ftask_cfg.c:184
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic1ms
Task configuration of the cyclic 1 ms task.
Definition: ftask_cfg.c:115
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclicAlgorithm100ms
Task configuration of the cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:133
void FTSK_RunUserCodeCyclic100ms(void)
Cyclic 100 ms task.
Definition: ftask_cfg.c:263
void FTSK_RunUserCodeI2c(void)
Continuously running task for I2C.
Definition: ftask_cfg.c:292
void FTSK_InitializeUserCodePreCyclicTasks(void)
Initialization function before all tasks started.
Definition: ftask_cfg.c:193
void FTSK_RunUserCodeCyclic10ms(void)
Cyclic 10 ms task.
Definition: ftask_cfg.c:237
void FTSK_RunUserCodeCyclic1ms(void)
Cyclic 1 ms task.
Definition: ftask_cfg.c:225
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic10ms
Task configuration of the cyclic 10 ms task.
Definition: ftask_cfg.c:121
void FTSK_RunUserCodeCyclicAlgorithm100ms(void)
Cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:283
uint32_t os_schedulerStartTime
Scheduler "zero" time for task phase control.
Definition: os.c:76
volatile OS_BOOT_STATE_e os_boot
Definition: os.c:74
@ OS_SCHEDULER_RUNNING
Definition: os.h:114
@ OS_PRE_CYCLIC_INITIALIZATION_HAS_FINISHED
Definition: os.h:116
@ OS_ENGINE_RUNNING
Definition: os.h:115
@ OS_SYSTEM_RUNNING
Definition: os.h:117
void OS_DelayTaskUntil(uint32_t *pPreviousWakeTime, uint32_t milliseconds)
Delay a task until a specified time.
Definition: os_freertos.c:162
void OS_MarkTaskAsRequiringFpuContext(void)
Marks the current task as requiring FPU context.
Definition: os_freertos.c:172
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:158
uint32_t cycleTime
Definition: os.h:138
uint32_t phase
Definition: os.h:137
void SYSM_Notify(SYSM_TASK_ID_e taskId, SYSM_NOTIFY_TYPE_e state, uint32_t timestamp)
Sets needed bits to indicate that a task is running.
Definition: sys_mon.c:185
system monitoring module
@ SYSM_NOTIFY_ENTER
Definition: sys_mon.h:67
@ SYSM_NOTIFY_EXIT
Definition: sys_mon.h:68
@ SYSM_TASK_ID_CYCLIC_10ms
Definition: sys_mon_cfg.h:77
@ SYSM_TASK_ID_CYCLIC_ALGORITHM_100ms
Definition: sys_mon_cfg.h:79
@ SYSM_TASK_ID_CYCLIC_100ms
Definition: sys_mon_cfg.h:78
@ SYSM_TASK_ID_CYCLIC_1ms
Definition: sys_mon_cfg.h:76
@ SYSM_TASK_ID_ENGINE
Definition: sys_mon_cfg.h:75