foxBMS-UnitTests  1.0.0
The foxBMS Unit Tests API Documentation
ftask.c
Go to the documentation of this file.
1 /**
2  *
3  * @copyright © 2010 - 2021, Fraunhofer-Gesellschaft zur Foerderung der
4  * angewandten Forschung e.V. All rights reserved.
5  *
6  * BSD 3-Clause License
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * We kindly request you to use one or more of the following phrases to refer
31  * to foxBMS in your hardware, software, documentation or advertising
32  * materials:
33  *
34  * ″This product uses parts of foxBMS®″
35  *
36  * ″This product includes parts of foxBMS®″
37  *
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 2020-01-21 (date of last update)
47  * @ingroup TASK
48  * @prefix FTSK
49  *
50  * @brief Implementation of engine task driver
51  * @details TODO
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "ftask.h"
56 
57 #include "FreeRTOS.h"
58 #include "stream_buffer.h"
59 
60 #include "database.h"
61 #include "sys_mon.h"
62 
63 /*========== Macros and Definitions =========================================*/
64 
65 /*========== Static Constant and Variable Definitions =======================*/
66 
67 /*========== Extern Constant and Variable Definitions =======================*/
68 
69 /********* Engine Task *****************************************************/
70 /** @brief Definition of task handle of the engine task */
71 static TaskHandle_t ftsk_taskHandleEngine;
72 
73 /** @brief Task Struct for #ftsk_taskHandleEngine */
74 static StaticTask_t ftsk_taskStructEngine;
75 
76 /** @brief Stack of #ftsk_taskHandleEngine */
78 
79 /********* Cyclic 1 ms Task *************************************************/
80 /** @brief Definition of task handle for the cyclic 1 ms task */
81 static TaskHandle_t ftsk_taskHandleCyclic1ms;
82 
83 /** @brief Task Struct for #ftsk_taskHandleCyclic1ms */
84 static StaticTask_t ftsk_taskStructCyclic1ms;
85 
86 /** @brief Stack of #ftsk_taskHandleCyclic1ms */
88 
89 /********* Cyclic 10 ms Task ************************************************/
90 /** @brief Definition of task handle for the cyclic 10 ms task */
91 static TaskHandle_t ftsk_taskHandleCyclic10ms;
92 
93 /** @brief Task Struct for #ftsk_taskHandleCyclic10ms */
94 static StaticTask_t ftsk_taskStructCyclic10ms;
95 
96 /** @brief Stack of #ftsk_taskHandleCyclic10ms */
98 
99 /********* Cyclic 100 ms Task ***********************************************/
100 /** @brief Definition of task handle for the cyclic 100 ms task */
101 static TaskHandle_t ftsk_taskHandleCyclic100ms;
102 
103 /** @brief Task Struct for #ftsk_taskHandleCyclic100ms */
104 static StaticTask_t ftsk_taskStructCyclic100ms;
105 
106 /** @brief Stack of #ftsk_taskHandleCyclic100ms */
108 
109 /********* Cyclic 100 ms Task for Algorithms ********************************/
110 /** @brief Definition of task handle for the cyclic 100 ms task for algorithms */
112 
113 /** @brief Task Struct for #ftsk_taskHandleCyclicAlgorithm100ms */
115 
116 /** @brief Stack of #ftsk_taskHandleCyclicAlgorithm100ms */
118 
119 /*========== Static Function Prototypes =====================================*/
120 static void FTSK_TaskCreatorEngine(void);
121 static void FTSK_TaskCreatorCyclic1ms(void);
122 static void FTSK_TaskCreatorCyclic10ms(void);
123 static void FTSK_TaskCreatorCyclic100ms(void);
124 static void FTSK_TaskCreatorCyclicAlgorithm100ms(void);
125 
126 /*========== Static Function Implementations ================================*/
127 
128 /*========== Extern Function Implementations ================================*/
129 void FTSK_CreateQueues(void) {
130 }
131 
132 void FTSK_CreateMutexes(void) {
133 }
134 
135 void FTSK_CreateEvents(void) {
136 }
137 
138 void FTSK_CreateTasks(void) {
139  ftsk_taskHandleEngine = xTaskCreateStatic(
140  (TaskFunction_t)FTSK_TaskCreatorEngine,
141  (const portCHAR *)"FTSK_TaskCreatorEngine",
143  NULL,
147  /* Trap if initialization failed */
149 
150  /* Cyclic Task 1ms */
151  ftsk_taskHandleCyclic1ms = xTaskCreateStatic(
152  (TaskFunction_t)FTSK_TaskCreatorCyclic1ms,
153  (const portCHAR *)"FTSK_TaskCreatorCyclic1ms",
155  NULL,
159  /* Trap if initialization failed */
161 
162  /* Cyclic Task 10ms */
163  ftsk_taskHandleCyclic10ms = xTaskCreateStatic(
164  (TaskFunction_t)FTSK_TaskCreatorCyclic10ms,
165  (const portCHAR *)"FTSK_TaskCreatorCyclic10ms",
167  NULL,
171  /* Trap if initialization failed */
173 
174  /* Cyclic Task 100ms */
175  ftsk_taskHandleCyclic100ms = xTaskCreateStatic(
176  (TaskFunction_t)FTSK_TaskCreatorCyclic100ms,
177  (const portCHAR *)"FTSK_TaskCreatorCyclic100ms",
179  NULL,
183  /* Trap if initialization failed */
185 
186  /* Cyclic Task 100ms for algorithms */
187  ftsk_taskHandleCyclicAlgorithm100ms = xTaskCreateStatic(
188  (TaskFunction_t)FTSK_TaskCreatorCyclicAlgorithm100ms,
189  (const portCHAR *)"FTSK_TaskCreator_Cyclic_Algorithm_100ms",
191  NULL,
195  /* Trap if initialization failed */
197 }
198 
199 /**
200  * @brief Database-Task
201  * @details The task manages the data exchange with the database and must have a
202  * higher task priority than any task using the database.
203  * @ingroup API_OS
204  */
205 /* tell compiler this function is a task, context save not necessary */
206 #pragma TASK(FTSK_TaskCreatorEngine)
211 
213  while (1) {
214  /* notify system monitoring that task will be called */
216  /* user code implemention */
218  /* notify system monitoring that task has been called */
220  }
221 }
222 
223 /**
224  * @brief Creation of cyclic 1 ms engine task
225  * @details The Task calls OsStartUp() in the very beginning, this is the first
226  * active Task. Then the Task is delayed by a phase as defined in
227  * ftsk_tskdef_cyclic_1ms.phase (in milliseconds). After the phase
228  * delay, the cyclic execution starts, the entry time is saved in
229  * current_time. After one cycle, the Task is set to sleep until entry
230  * time + ftsk_tskdef_cyclic_1ms.cycleTime (in milliseconds).
231  */
232 /* tell compiler this function is a task, context save not necessary */
233 #pragma TASK(FTSK_TaskCreatorCyclic1ms)
235  uint32_t current_time = 0;
236 
237  while (os_boot != OS_ENGINE_RUNNING) {
238  }
239 
242 
244  current_time = OS_GetTickCount();
245  while (1) {
246  /* notify system monitoring that task will be called */
248  /* user code implementation */
250  /* notify system monitoring that task has been called */
252  /* task statistics */
254  }
255 }
256 
257 /**
258  * @brief Creation of cyclic 10 ms engine task
259  * @details Task is delayed by a phase as defined in
260  * ftsk_tskdef_cyclic_10ms.phase (in milliseconds). After the phase
261  * delay, the cyclic execution starts, the entry time is saved in
262  * current_time. After one cycle, the Task is set to sleep until entry
263  * time + ftsk_tskdef_cyclic_10ms.cycleTime (in milliseconds).
264  */
265 /* tell compiler this function is a task, context save not necessary */
266 #pragma TASK(FTSK_TaskCreatorCyclic10ms)
268  uint32_t current_time = 0;
269 
271  }
272 
274  current_time = OS_GetTickCount();
275  while (1) {
276  /* notify system monitoring that task will be called */
278  /* user code implementation */
280  /* notify system monitoring that task has been called */
282  /* task statistics */
284  }
285 }
286 
287 /**
288  * @brief Creation of cyclic 100 ms engine task
289  * @details Task is delayed by a phase as defined in
290  * ftsk_tskdef_cyclic_100ms.phase (in milliseconds). After the phase
291  * delay, the cyclic execution starts, the entry time is saved in
292  * current_time. After one cycle, the Task is set to sleep until entry
293  * time + ftsk_tskdef_cyclic_100ms.cycleTime (in milliseconds).
294  */
295 /* tell compiler this function is a task, context save not necessary */
296 #pragma TASK(FTSK_TaskCreatorCyclic100ms)
298  uint32_t current_time = 0;
299 
301  }
302 
304  current_time = OS_GetTickCount();
305  while (1) {
306  /* notify system monitoring that task will be called */
308  /* user code implementation */
310  /* notify system monitoring that task has been called */
312  /* task statistics */
314  }
315 }
316 
317 /**
318  * @brief Creation of cyclic 100 ms algorithm task
319  * @details Task is delayed by a phase as defined in
320  * ftsk_taskDefinitionCyclicAlgorithm100ms.Phase (in milliseconds). After
321  * the phase delay, the cyclic execution starts, the entry time is
322  * saved in current_time. After one cycle, the Task is set to sleep
323  * until entry time + ftsk_taskDefinitionCyclicAlgorithm100ms.CycleTime
324  * (in milliseconds).
325  */
326 /* tell compiler this function is a task, context save not necessary */
327 #pragma TASK(FTSK_TaskCreatorCyclicAlgorithm100ms)
329  uint32_t current_time = 0;
330 
332  }
333 
336  current_time = OS_GetTickCount();
337  while (1) {
338  /* notify system monitoring that task will be called */
340  /* user code implementation */
342  /* notify system monitoring that task has been called */
344  /* task statistics */
346  }
347 }
348 
349 /*========== Externalized Static Function Implementations (Unit Test) =======*/
ftsk_stackSizeCyclic1ms
static StackType_t ftsk_stackSizeCyclic1ms[FTSK_TSK_CYCLIC_1MS_STACK_SIZE]
Stack of ftsk_taskHandleCyclic1ms.
Definition: ftask.c:87
OS_TASK_DEFINITION::cycleTime
uint32_t cycleTime
Definition: os.h:120
FTSK_TSK_CYCLIC_ALGORITHM_100MS_STACKSIZE
#define FTSK_TSK_CYCLIC_ALGORITHM_100MS_STACKSIZE
Stack size of cyclic 100 ms task for algorithms.
Definition: ftask_cfg.h:112
OS_SYSTEM_RUNNING
@ OS_SYSTEM_RUNNING
Definition: os.h:100
OS_SCHEDULER_RUNNING
@ OS_SCHEDULER_RUNNING
Definition: os.h:97
ftsk_taskStructCyclic1ms
static StaticTask_t ftsk_taskStructCyclic1ms
Task Struct for ftsk_taskHandleCyclic1ms.
Definition: ftask.c:84
ftsk_taskHandleCyclic10ms
static TaskHandle_t ftsk_taskHandleCyclic10ms
Definition of task handle for the cyclic 10 ms task.
Definition: ftask.c:91
FTSK_UserCodeCyclic100ms
void FTSK_UserCodeCyclic100ms(void)
Cyclic 100 ms task.
Definition: ftask_cfg.c:199
FTSK_UserCodeEngine
void FTSK_UserCodeEngine(void)
Engine task for the database and the system monitoring module.
Definition: ftask_cfg.c:136
OS_TASK_DEFINITION::stackSize
uint16_t stackSize
Definition: os.h:122
OS_DelayTaskUntil
void OS_DelayTaskUntil(uint32_t *pPreviousWakeTime, uint32_t milliseconds)
Delay a task until a specified time.
Definition: os.c:196
FTSK_UserCodeEngineInit
void FTSK_UserCodeEngineInit(void)
Initializes the database.
Definition: ftask_cfg.c:115
ftsk_taskStructCyclic10ms
static StaticTask_t ftsk_taskStructCyclic10ms
Task Struct for ftsk_taskHandleCyclic10ms.
Definition: ftask.c:94
FTSK_TaskCreatorCyclic10ms
static void FTSK_TaskCreatorCyclic10ms(void)
Creation of cyclic 10 ms engine task.
Definition: ftask.c:267
ftsk_taskDefinitionCyclic100ms
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic100ms
Task configuration of the cyclic 100 ms task.
Definition: ftask_cfg.c:99
sys_mon.h
TODO.
FTSK_UserCodeCyclic10ms
void FTSK_UserCodeCyclic10ms(void)
Cyclic 10 ms task.
Definition: ftask_cfg.c:179
FTSK_UserCodeCyclicAlgorithm100ms
void FTSK_UserCodeCyclicAlgorithm100ms(void)
Cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:211
ftsk_stackSizeCyclic100ms
static StackType_t ftsk_stackSizeCyclic100ms[FTSK_TSK_CYCLIC_100MS_STACK_SIZE]
Stack of ftsk_taskHandleCyclic100ms.
Definition: ftask.c:107
os_schedulerStartTime
uint32_t os_schedulerStartTime
Scheduler "zero" time for task phase control.
Definition: os.c:72
ftsk_taskStructCyclic100ms
static StaticTask_t ftsk_taskStructCyclic100ms
Task Struct for ftsk_taskHandleCyclic100ms.
Definition: ftask.c:104
ftsk_stackSizeCyclicAlgorithm100ms
static StackType_t ftsk_stackSizeCyclicAlgorithm100ms[FTSK_TSK_CYCLIC_ALGORITHM_100MS_STACKSIZE]
Stack of ftsk_taskHandleCyclicAlgorithm100ms.
Definition: ftask.c:117
FTSK_TSK_CYCLIC_100MS_STACK_SIZE
#define FTSK_TSK_CYCLIC_100MS_STACK_SIZE
Stack size of cyclic 100 ms task.
Definition: ftask_cfg.h:100
ftsk_taskDefinitionCyclic1ms
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic1ms
Task configuration of the cyclic 1 ms task.
Definition: ftask_cfg.c:95
OS_TASK_DEFINITION::phase
uint32_t phase
Definition: os.h:119
FTSK_TaskCreatorCyclicAlgorithm100ms
static void FTSK_TaskCreatorCyclicAlgorithm100ms(void)
Creation of cyclic 100 ms algorithm task.
Definition: ftask.c:328
ftsk_taskDefinitionEngine
OS_TASK_DEFINITION_s ftsk_taskDefinitionEngine
Definition of the engine task.
Definition: ftask_cfg.c:93
FTSK_CreateEvents
void FTSK_CreateEvents(void)
Creates all events of the group.
Definition: ftask.c:135
OS_TASK_DEFINITION::priority
UBaseType_t priority
Definition: os.h:121
FAS_ASSERT
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:233
OS_GetTickCount
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os.c:182
FTSK_TaskCreatorCyclic1ms
static void FTSK_TaskCreatorCyclic1ms(void)
Creation of cyclic 1 ms engine task.
Definition: ftask.c:234
SYSM_TASK_ID_CYCLIC_100ms
@ SYSM_TASK_ID_CYCLIC_100ms
Definition: sys_mon_cfg.h:76
ftask.h
Header of task driver implementation.
FTSK_CreateMutexes
void FTSK_CreateMutexes(void)
Creates all mutexes.
Definition: ftask.c:132
SYSM_TASK_ID_CYCLIC_10ms
@ SYSM_TASK_ID_CYCLIC_10ms
Definition: sys_mon_cfg.h:75
ftsk_taskStructCyclicAlgorithm100ms
static StaticTask_t ftsk_taskStructCyclicAlgorithm100ms
Task Struct for ftsk_taskHandleCyclicAlgorithm100ms.
Definition: ftask.c:114
ftsk_stackSizeEngine
static StackType_t ftsk_stackSizeEngine[FTSK_TSK_ENGINE_STACK_SIZE]
Stack of ftsk_taskHandleEngine.
Definition: ftask.c:77
ftsk_taskHandleCyclicAlgorithm100ms
static TaskHandle_t ftsk_taskHandleCyclicAlgorithm100ms
Definition of task handle for the cyclic 100 ms task for algorithms.
Definition: ftask.c:111
SYSM_TASK_ID_ENGINE
@ SYSM_TASK_ID_ENGINE
Definition: sys_mon_cfg.h:73
ftsk_taskDefinitionCyclicAlgorithm100ms
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclicAlgorithm100ms
Task configuration of the cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:104
FTSK_TSK_CYCLIC_1MS_STACK_SIZE
#define FTSK_TSK_CYCLIC_1MS_STACK_SIZE
Stack size of cyclic 1 ms task.
Definition: ftask_cfg.h:76
ftsk_taskHandleCyclic1ms
static TaskHandle_t ftsk_taskHandleCyclic1ms
Definition of task handle for the cyclic 1 ms task.
Definition: ftask.c:81
SYSM_TASK_ID_CYCLIC_1ms
@ SYSM_TASK_ID_CYCLIC_1ms
Definition: sys_mon_cfg.h:74
OS_ENGINE_RUNNING
@ OS_ENGINE_RUNNING
Definition: os.h:98
ftsk_taskHandleEngine
static TaskHandle_t ftsk_taskHandleEngine
Definition of task handle of the engine task.
Definition: ftask.c:71
OS_PRECYCLIC_INIT_HAS_FINISHED
@ OS_PRECYCLIC_INIT_HAS_FINISHED
Definition: os.h:99
ftsk_stackSizeCyclic10ms
static StackType_t ftsk_stackSizeCyclic10ms[FTSK_TSK_CYCLIC_10MS_STACK_SIZE]
Stack of ftsk_taskHandleCyclic10ms.
Definition: ftask.c:97
FTSK_TSK_CYCLIC_10MS_STACK_SIZE
#define FTSK_TSK_CYCLIC_10MS_STACK_SIZE
Stack size of cyclic 10 ms task.
Definition: ftask_cfg.h:88
database.h
Database module header.
ftsk_taskStructEngine
static StaticTask_t ftsk_taskStructEngine
Task Struct for ftsk_taskHandleEngine.
Definition: ftask.c:74
FTSK_UserCodePreCyclicTasksInitialization
void FTSK_UserCodePreCyclicTasksInitialization(void)
Initialization function before all tasks started.
Definition: ftask_cfg.c:145
os_boot
volatile OS_BOOT_STATE_e os_boot
Definition: os.c:68
ftsk_taskHandleCyclic100ms
static TaskHandle_t ftsk_taskHandleCyclic100ms
Definition of task handle for the cyclic 100 ms task.
Definition: ftask.c:101
FTSK_UserCodeCyclic1ms
void FTSK_UserCodeCyclic1ms(void)
Cyclic 1 ms task.
Definition: ftask_cfg.c:169
FTSK_CreateTasks
void FTSK_CreateTasks(void)
Creates all tasks of the group.
Definition: ftask.c:138
FTSK_TaskCreatorEngine
static void FTSK_TaskCreatorEngine(void)
Database-Task.
Definition: ftask.c:207
FTSK_TaskCreatorCyclic100ms
static void FTSK_TaskCreatorCyclic100ms(void)
Creation of cyclic 100 ms engine task.
Definition: ftask.c:297
FTSK_CreateQueues
void FTSK_CreateQueues(void)
Creates all queues.
Definition: ftask.c:129
ftsk_taskDefinitionCyclic10ms
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic10ms
Task configuration of the cyclic 10 ms task.
Definition: ftask_cfg.c:97
SYSM_NOTIFY_ENTER
@ SYSM_NOTIFY_ENTER
Definition: sys_mon.h:62
SYSM_Notify
void SYSM_Notify(SYSM_TASK_ID_e tsk_id, SYSM_NOTIFY_TYPE_e state, uint32_t time)
Sets needed bits to indicate that a task is running.
Definition: sys_mon.c:104
SYSM_NOTIFY_EXIT
@ SYSM_NOTIFY_EXIT
Definition: sys_mon.h:63
SYSM_TASK_ID_CYCLIC_ALGORITHM_100ms
@ SYSM_TASK_ID_CYCLIC_ALGORITHM_100ms
Definition: sys_mon_cfg.h:77
FTSK_TSK_ENGINE_STACK_SIZE
#define FTSK_TSK_ENGINE_STACK_SIZE
Stack size of engine task.
Definition: ftask_cfg.h:64