foxBMS - Unit Tests  1.2.1
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 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 2021-12-01 (date of last update)
47  * @ingroup TASK
48  * @prefix FTSK
49  *
50  * @brief Implementation of OS-independent task creators
51  * @details TODO
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "ftask.h"
56 
57 #include "sys_mon.h"
58 
59 /*========== Macros and Definitions =========================================*/
60 
61 /*========== Static Constant and Variable Definitions =======================*/
62 
63 /*========== Extern Constant and Variable Definitions =======================*/
64 
65 /*========== Static Function Prototypes =====================================*/
66 
67 /*========== Static Function Implementations ================================*/
68 
69 /*========== Extern Function Implementations ================================*/
70 /* AXIVION Next Line Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
71  * that this function is a task, context save not necessary */
72 #pragma TASK(FTSK_CreateTaskEngine)
73 extern void FTSK_CreateTaskEngine(void *const pvParameters) {
74  FAS_ASSERT(pvParameters == NULL_PTR);
79 
80  /* AXIVION Next Line Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
81  * loop for the user code (see www.freertos.org/a00125.html)*/
82  while (true) {
83  /* notify system monitoring that task will be called */
85  /* user code implemention */
87  /* notify system monitoring that task has been called */
89  }
90 }
91 
92 /* AXIVION Next Line Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
93  * that this function is a task, context save not necessary */
94 #pragma TASK(FTSK_CreateTaskCyclic1ms)
95 extern void FTSK_CreateTaskCyclic1ms(void *const pvParameters) {
96  FAS_ASSERT(pvParameters == NULL_PTR);
98  uint32_t currentTimeCreateTaskCyclic1ms = 0;
99 
100  while (os_boot != OS_ENGINE_RUNNING) {
101  }
102 
105 
106  /* cycle time (1ms) equals the minimum tick time (1ms),
107  * therefore it is not possible to configure a phase for this task */
108  currentTimeCreateTaskCyclic1ms = OS_GetTickCount();
109  /* AXIVION Next Line Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
110  * loop for the user code (see www.freertos.org/a00125.html)*/
111  while (true) {
112  /* notify system monitoring that task will be called */
114  /* user code implementation */
116  /* notify system monitoring that task has been called */
118  /* let task sleep until it is due again */
119  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic1ms, ftsk_taskDefinitionCyclic1ms.cycleTime);
120  }
121 }
122 
123 /* AXIVION Next Line Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
124  * that this function is a task, context save not necessary */
125 #pragma TASK(FTSK_CreateTaskCyclic10ms)
126 extern void FTSK_CreateTaskCyclic10ms(void *const pvParameters) {
127  FAS_ASSERT(pvParameters == NULL_PTR);
129  uint32_t currentTimeCreateTaskCyclic10ms = 0;
130 
132  }
133 
135  currentTimeCreateTaskCyclic10ms = OS_GetTickCount();
136  /* AXIVION Next Line Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
137  * loop for the user code (see www.freertos.org/a00125.html)*/
138  while (true) {
139  /* notify system monitoring that task will be called */
141  /* user code implementation */
143  /* notify system monitoring that task has been called */
145  /* let task sleep until it is due again */
146  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic10ms, ftsk_taskDefinitionCyclic10ms.cycleTime);
147  }
148 }
149 
150 /* AXIVION Next Line Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
151  * that this function is a task, context save not necessary */
152 #pragma TASK(FTSK_CreateTaskCyclic100ms)
153 extern void FTSK_CreateTaskCyclic100ms(void *const pvParameters) {
154  FAS_ASSERT(pvParameters == NULL_PTR);
156  uint32_t currentTimeCreateTaskCyclic100ms = 0;
157 
159  }
160 
162  currentTimeCreateTaskCyclic100ms = OS_GetTickCount();
163  /* AXIVION Next Line Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
164  * loop for the user code (see www.freertos.org/a00125.html)*/
165  while (true) {
166  /* notify system monitoring that task will be called */
168  /* user code implementation */
170  /* notify system monitoring that task has been called */
172  /* let task sleep until it is due again */
173  OS_DelayTaskUntil(&currentTimeCreateTaskCyclic100ms, ftsk_taskDefinitionCyclic100ms.cycleTime);
174  }
175 }
176 
177 /* AXIVION Next Line Style MisraC2012Directive-1.1 MisraC2012-1.2 FaultDetection-DeadBranches: tell the CCS compiler
178  * that this function is a task, context save not necessary */
179 #pragma TASK(FTSK_CreateTaskCyclicAlgorithm100ms)
180 extern void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters) {
181  FAS_ASSERT(pvParameters == NULL_PTR);
183  uint32_t currentTimeCreateTaskCyclicAlgorithms100ms = 0;
184 
186  }
187 
190  currentTimeCreateTaskCyclicAlgorithms100ms = OS_GetTickCount();
191  /* AXIVION Next Line Style MisraC2012-2.2 FaultDetection-DeadBranches: FreeRTOS task setup requires an infinite
192  * loop for the user code (see www.freertos.org/a00125.html)*/
193  while (true) {
194  /* notify system monitoring that task will be called */
196  /* user code implementation */
198  /* notify system monitoring that task has been called */
200  /* let task sleep until it is due again */
202  &currentTimeCreateTaskCyclicAlgorithms100ms, ftsk_taskDefinitionCyclicAlgorithm100ms.cycleTime);
203  }
204 }
205 
206 /*========== Externalized Static Function Implementations (Unit Test) =======*/
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:235
#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.
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic100ms
Task configuration of the cyclic 100 ms task.
Definition: ftask_cfg.c:123
void FTSK_InitializeUserCodeEngine(void)
Initializes the database.
Definition: ftask_cfg.c:141
void FTSK_RunUserCodeEngine(void)
Engine task for the database and the system monitoring module.
Definition: ftask_cfg.c:162
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
void FTSK_RunUserCodeCyclic100ms(void)
Cyclic 100 ms task.
Definition: ftask_cfg.c:238
void FTSK_InitializeUserCodePreCyclicTasks(void)
Initialization function before all tasks started.
Definition: ftask_cfg.c:171
void FTSK_RunUserCodeCyclic10ms(void)
Cyclic 10 ms task.
Definition: ftask_cfg.c:216
void FTSK_RunUserCodeCyclic1ms(void)
Cyclic 1 ms task.
Definition: ftask_cfg.c:206
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic10ms
Task configuration of the cyclic 10 ms task.
Definition: ftask_cfg.c:117
void FTSK_RunUserCodeCyclicAlgorithm100ms(void)
Cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:258
uint32_t os_schedulerStartTime
Scheduler "zero" time for task phase control.
Definition: os.c:70
volatile OS_BOOT_STATE_e os_boot
Definition: os.c:68
@ OS_PRECYCLIC_INIT_HAS_FINISHED
Definition: os.h:106
@ OS_SCHEDULER_RUNNING
Definition: os.h:104
@ OS_ENGINE_RUNNING
Definition: os.h:105
@ OS_SYSTEM_RUNNING
Definition: os.h:107
void OS_DelayTaskUntil(uint32_t *pPreviousWakeTime, uint32_t milliseconds)
Delay a task until a specified time.
Definition: os_freertos.c:133
void OS_MarkTaskAsRequiringFpuContext(void)
Marks the current task as requiring FPU context.
Definition: os_freertos.c:159
uint32_t OS_GetTickCount(void)
Returns OS based system tick value.
Definition: os_freertos.c:129
uint32_t cycleTime
Definition: os.h:128
uint32_t phase
Definition: os.h:127
void SYSM_Notify(SYSM_TASK_ID_e taskId, 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_ENTER
Definition: sys_mon.h:62
@ SYSM_NOTIFY_EXIT
Definition: sys_mon.h:63
@ SYSM_TASK_ID_CYCLIC_10ms
Definition: sys_mon_cfg.h:75
@ SYSM_TASK_ID_CYCLIC_ALGORITHM_100ms
Definition: sys_mon_cfg.h:77
@ SYSM_TASK_ID_CYCLIC_100ms
Definition: sys_mon_cfg.h:76
@ SYSM_TASK_ID_CYCLIC_1ms
Definition: sys_mon_cfg.h:74
@ SYSM_TASK_ID_ENGINE
Definition: sys_mon_cfg.h:73