foxBMS  1.4.1
The foxBMS Battery Management System API Documentation
ftask.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2022, 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 2022-10-27 (date of last update)
47  * @version v1.4.1
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 /*========== Macros and Definitions =========================================*/
61 
62 /*========== Static Constant and Variable Definitions =======================*/
63 
64 /*========== Extern Constant and Variable Definitions =======================*/
65 
66 /*========== Static Function Prototypes =====================================*/
67 
68 /*========== Static Function Implementations ================================*/
69 
70 /*========== Extern Function Implementations ================================*/
71 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
72  * that this function is a task, context save not necessary */
73 #pragma TASK(FTSK_CreateTaskEngine)
74 extern void FTSK_CreateTaskEngine(void *const pvParameters) {
75  FAS_ASSERT(pvParameters == NULL_PTR);
80 
81  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
82  * loop for the user code (see www.freertos.org/a00125.html)*/
83  while (true) {
84  /* notify system monitoring that task will be called */
86  /* user code implementation */
88  /* notify system monitoring that task has been called */
90  }
91 }
92 
93 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
94  * that this function is a task, context save not necessary */
95 #pragma TASK(FTSK_CreateTaskCyclic1ms)
96 extern void FTSK_CreateTaskCyclic1ms(void *const pvParameters) {
97  FAS_ASSERT(pvParameters == NULL_PTR);
99  uint32_t currentTimeCreateTaskCyclic1ms = 0;
100 
101  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: start cyclic 1ms task only when engine task is running */
102  while (os_boot != OS_ENGINE_RUNNING) {
103  }
104 
107 
108  /* cycle time (1ms) equals the minimum tick time (1ms),
109  * therefore it is not possible to configure a phase for this task */
110  currentTimeCreateTaskCyclic1ms = OS_GetTickCount();
111  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
112  * loop for the user code (see www.freertos.org/a00125.html)*/
113  while (true) {
114  /* notify system monitoring that task will be called */
116  /* user code implementation */
118  /* notify system monitoring that task has been called */
120  /* let task sleep until it is due again */
121  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic1ms, ftsk_taskDefinitionCyclic1ms.cycleTime);
122  }
123 }
124 
125 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
126  compiler that this function is a task, context save not necessary */
127 #pragma TASK(FTSK_CreateTaskCyclic10ms)
128 extern void FTSK_CreateTaskCyclic10ms(void *const pvParameters) {
129  FAS_ASSERT(pvParameters == NULL_PTR);
131  uint32_t currentTimeCreateTaskCyclic10ms = 0;
132 
133  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
134  pre-cyclic initialization sequence */
136  }
137 
139  currentTimeCreateTaskCyclic10ms = OS_GetTickCount();
140  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
141  * loop for the user code (see www.freertos.org/a00125.html)*/
142  while (true) {
143  /* notify system monitoring that task will be called */
145  /* user code implementation */
147  /* notify system monitoring that task has been called */
149  /* let task sleep until it is due again */
150  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic10ms, ftsk_taskDefinitionCyclic10ms.cycleTime);
151  }
152 }
153 
154 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
155  compiler that this function is a task, context save not necessary */
156 #pragma TASK(FTSK_CreateTaskCyclic100ms)
157 extern void FTSK_CreateTaskCyclic100ms(void *const pvParameters) {
158  FAS_ASSERT(pvParameters == NULL_PTR);
160  uint32_t currentTimeCreateTaskCyclic100ms = 0;
161 
162  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
163  pre-cyclic initialization sequence */
165  }
166 
168  currentTimeCreateTaskCyclic100ms = OS_GetTickCount();
169  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
170  * loop for the user code (see www.freertos.org/a00125.html)*/
171  while (true) {
172  /* notify system monitoring that task will be called */
174  /* user code implementation */
176  /* notify system monitoring that task has been called */
178  /* let task sleep until it is due again */
179  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic100ms, ftsk_taskDefinitionCyclic100ms.cycleTime);
180  }
181 }
182 
183 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
184  compiler that this function is a task, context save not necessary */
185 #pragma TASK(FTSK_CreateTaskCyclicAlgorithm100ms)
186 extern void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters) {
187  FAS_ASSERT(pvParameters == NULL_PTR);
189  uint32_t currentTimeCreateTaskCyclicAlgorithms100ms = 0;
190 
191  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
192  pre-cyclic initialization sequence */
194  }
195 
198  currentTimeCreateTaskCyclicAlgorithms100ms = OS_GetTickCount();
199  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
200  * loop for the user code (see www.freertos.org/a00125.html)*/
201  while (true) {
202  /* notify system monitoring that task will be called */
204  /* user code implementation */
206  /* notify system monitoring that task has been called */
208  /* let task sleep until it is due again */
210  &currentTimeCreateTaskCyclicAlgorithms100ms, ftsk_taskDefinitionCyclicAlgorithm100ms.cycleTime);
211  }
212 }
213 
214 /* AXIVION Next Codeline Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS
215  compiler tell compiler this function is a task, context save not necessary */
216 #pragma TASK(FTSK_CreateTaskAfe)
217 extern void FTSK_CreateTaskAfe(void *const pvParameters) {
218  FAS_ASSERT(pvParameters == NULL_PTR);
220 
221  /* AXIVION Next Codeline Style Generic-NoEmptyLoops: wait until the 1ms cyclic task setup has finished the
222  pre-cyclic initialization sequence */
224  }
225 
226  /* AXIVION Next Codeline Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
227  * loop for the user code (see www.freertos.org/a00125.html)*/
228  while (true) {
229  /* user code implementation */
231  }
232 }
233 
234 /*========== Externalized Static Function Implementations (Unit Test) =======*/
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:252
#define NULL_PTR
Null pointer.
Definition: fstd_types.h:76
void FTSK_CreateTaskEngine(void *const pvParameters)
Database-Task.
Definition: ftask.c:74
void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters)
Creation of cyclic 100 ms algorithm task.
Definition: ftask.c:186
void FTSK_CreateTaskCyclic100ms(void *const pvParameters)
Creation of cyclic 100 ms task.
Definition: ftask.c:157
void FTSK_CreateTaskCyclic10ms(void *const pvParameters)
Creation of cyclic 10 ms task.
Definition: ftask.c:128
void FTSK_CreateTaskAfe(void *const pvParameters)
Creation of continuously running task for AFEs.
Definition: ftask.c:217
void FTSK_CreateTaskCyclic1ms(void *const pvParameters)
Creation of cyclic 1 ms task.
Definition: ftask.c:96
Header of task driver implementation.
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic100ms
Task configuration of the cyclic 100 ms task.
Definition: ftask_cfg.c:124
void FTSK_RunUserCodeAfe(void)
Continuously running task for AFEs.
Definition: ftask_cfg.c:286
void FTSK_InitializeUserCodeEngine(void)
Initializes the database.
Definition: ftask_cfg.c:148
void FTSK_RunUserCodeEngine(void)
Engine task for the database and the system monitoring module.
Definition: ftask_cfg.c:177
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic1ms
Task configuration of the cyclic 1 ms task.
Definition: ftask_cfg.c:112
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclicAlgorithm100ms
Task configuration of the cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:130
void FTSK_RunUserCodeCyclic100ms(void)
Cyclic 100 ms task.
Definition: ftask_cfg.c:257
void FTSK_InitializeUserCodePreCyclicTasks(void)
Initialization function before all tasks started.
Definition: ftask_cfg.c:186
void FTSK_RunUserCodeCyclic10ms(void)
Cyclic 10 ms task.
Definition: ftask_cfg.c:230
void FTSK_RunUserCodeCyclic1ms(void)
Cyclic 1 ms task.
Definition: ftask_cfg.c:218
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic10ms
Task configuration of the cyclic 10 ms task.
Definition: ftask_cfg.c:118
void FTSK_RunUserCodeCyclicAlgorithm100ms(void)
Cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:277
uint32_t os_schedulerStartTime
Scheduler "zero" time for task phase control.
Definition: os.c:71
volatile OS_BOOT_STATE_e os_boot
Definition: os.c:69
@ OS_SCHEDULER_RUNNING
Definition: os.h:106
@ OS_PRE_CYCLIC_INITIALIZATION_HAS_FINISHED
Definition: os.h:108
@ OS_ENGINE_RUNNING
Definition: os.h:107
@ OS_SYSTEM_RUNNING
Definition: os.h:109
void OS_DelayTaskUntil(uint32_t *pPreviousWakeTime, uint32_t milliseconds)
Delay a task until a specified time.
Definition: os_freertos.c:143
void OS_MarkTaskAsRequiringFpuContext(void)
Marks the current task as requiring FPU context.
Definition: os_freertos.c:153
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:139
uint32_t cycleTime
Definition: os.h:130
uint32_t phase
Definition: os.h:129
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:183
system monitoring module
@ SYSM_NOTIFY_ENTER
Definition: sys_mon.h:65
@ SYSM_NOTIFY_EXIT
Definition: sys_mon.h:66
@ SYSM_TASK_ID_CYCLIC_10ms
Definition: sys_mon_cfg.h:76
@ SYSM_TASK_ID_CYCLIC_ALGORITHM_100ms
Definition: sys_mon_cfg.h:78
@ SYSM_TASK_ID_CYCLIC_100ms
Definition: sys_mon_cfg.h:77
@ SYSM_TASK_ID_CYCLIC_1ms
Definition: sys_mon_cfg.h:75
@ SYSM_TASK_ID_ENGINE
Definition: sys_mon_cfg.h:74