foxBMS  1.1.0
The foxBMS Battery Management System API Documentation
ftask_cfg.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_cfg.c
44  * @author foxBMS Team
45  * @date 2019-08-26 (date of creation)
46  * @updated 2021-07-23 (date of last update)
47  * @ingroup TASK_CONFIGURATION
48  * @prefix FTSK
49  *
50  * @brief Task configuration
51  * @details
52  */
53 
54 /*========== Includes =======================================================*/
55 #include "ftask_cfg.h"
56 
57 #include "HL_gio.h"
58 #include "HL_het.h"
59 
60 #include "adc.h"
61 #include "algorithm.h"
62 #include "bal.h"
63 #include "bms.h"
64 #include "can.h"
65 #include "database.h"
66 #include "diag.h"
67 #include "dma.h"
68 #include "fram.h"
69 #include "imd.h"
70 #include "interlock.h"
71 #include "meas.h"
72 #include "redundancy.h"
73 #include "sbc.h"
74 #include "sof.h"
75 #include "spi.h"
76 #include "sps.h"
77 #include "state_estimation.h"
78 #include "sys.h"
79 #include "sys_mon.h"
80 
81 /*========== Macros and Definitions =========================================*/
82 
83 /** counter value for 50ms in 10ms task */
84 #define TASK_10MS_COUNTER_FOR_50MS (5u)
85 
86 /** counter value for 1s in 100ms task */
87 #define TASK_100MS_COUNTER_FOR_1S (10u)
88 
89 /*========== Static Constant and Variable Definitions =======================*/
90 
91 /*========== Extern Constant and Variable Definitions =======================*/
92 
93 /**
94  * @brief Definition of the engine task
95  * @details Task is not delayed after the scheduler starts. This task must
96  * have the highest priority.
97  * @warning Do not change the configuration of this task. This will very
98  * likely break the system.
99  */
119 
120 /*========== Static Function Prototypes =====================================*/
121 
122 /*========== Static Function Implementations ================================*/
123 
124 /*========== Extern Function Implementations ================================*/
125 extern void FTSK_InitializeUserCodeEngine(void) {
126  /* Warning: Do not change the content of this function */
127  /* See function definition doxygen comment for details */
128  STD_RETURN_TYPE_e retval = DATA_Init();
129 
130  if (retval == E_NOT_OK) {
131  /* Fatal error! */
133  }
134 
135  retval = SYSM_Init();
136 
137  if (retval == E_NOT_OK) {
138  /* Fatal error! */
140  }
141 
142  /* Warning: Do not change the content of this function */
143  /* See function definition doxygen comment for details */
144 }
145 
146 extern void FTSK_RunUserCodeEngine(void) {
147  /* Warning: Do not change the content of this function */
148  /* See function definition doxygen comment for details */
149  DATA_Task(); /* Call database manager */
150  SYSM_CheckNotifications(); /* Check notifications from tasks */
151  /* Warning: Do not change the content of this function */
152  /* See function definition doxygen comment for details */
153 }
154 
156  /* user code */
158 
159  /* Set pin linked to debug LED as output */
160  hetREG1->DIR |= (uint32)((uint32)1U << 1U);
161 
162  /* Init Sys */
164 
165  /* Init FRAM */
166  FRAM_Initialize();
167 
168  /* This function operates under the assumption that it is called when
169  * the operating system is not yet running.
170  * In this state the return value of #SYS_SetStateRequest should
171  * always be #SYS_OK. Therefore we trap otherwise.
172  */
173  FAS_ASSERT(sys_retVal == SYS_OK);
174 }
175 
176 extern void FTSK_RunUserCodeCyclic1ms(void) {
177  /* Increment of operating system timer */
178  /* This must not be changed, add user code only below */
181  /* user code */
182  MEAS_Control();
184 }
185 
186 extern void FTSK_RunUserCodeCyclic10ms(void) {
187  static uint8_t cnt = 0;
188  /* user code */
190  BMS_Trigger();
191  ILCK_Trigger();
192  ADC_Control(); /* TODO: check for shared SPI */
193  SPS_Ctrl();
195  SOF_Calculation();
198  if (cnt == TASK_10MS_COUNTER_FOR_50MS) {
201  cnt = 0;
202  }
203  cnt++;
204 }
205 
206 extern void FTSK_RunUserCodeCyclic100ms(void) {
207  /* user code */
208  static uint8_t ftsk_cyclic100msCounter = 0;
209 
210  /** Perform SOC and SOE calculations only every 1s. Not suited if analog
211  * integration of current sensor is NOT used. Manual integration of current
212  * requires a higher frequency.
213  */
214  if (ftsk_cyclic100msCounter == TASK_100MS_COUNTER_FOR_1S) {
216  ftsk_cyclic100msCounter = 0;
217  }
218 
219  BAL_Trigger();
220  IMD_Trigger();
221 
222  ftsk_cyclic100msCounter++;
223 }
224 
226  /* user code */
227  static uint8_t ftsk_cyclicAlgorithm100msCounter = 0;
228 
230 
231  ftsk_cyclicAlgorithm100msCounter++;
232 }
233 
234 extern void FTSK_RunUserCodeIdle(void) {
235  /* user code */
236 }
237 
238 /*========== Externalized Static Function Implementations (Unit Test) =======*/
void ADC_Control(void)
determines which ADC is measured and stores result in database.
Definition: adc.c:211
Headers for the driver for the ADC module.
void ALGO_MainFunction(void)
handles the call of different algorithm functions when cycle time has expired
Definition: algorithm.c:111
void ALGO_MonitorExecutionTime(void)
monitors the calculation duration of the different algorithms
Definition: algorithm.c:143
Headers for the driver for the storage in the EEPROM memory.
Header for the driver for balancing.
void BAL_Trigger(void)
trigger function for the BAL driver state machine.
void BMS_Trigger(void)
trigger function for the SYS driver state machine.
Definition: bms.c:647
bms driver header
void CAN_MainFunction(void)
Calls the functions to drive the CAN interface. Makes the CAN timing checks and sends the periodic me...
Definition: can.c:237
void CAN_ReadRxBuffer(void)
Checks the data received per CAN. A receive buffer is used because CAN frames are received in an inte...
Definition: can.c:349
Header for the driver for the CAN module.
void DATA_Task(void)
trigger of database manager
Definition: database.c:155
STD_RETURN_TYPE_e DATA_Init(void)
Initialization of database manager.
Definition: database.c:105
Database module header.
Diagnosis driver header.
void DIAG_UpdateFlags(void)
update function for diagnosis flags
Definition: diag_cfg.c:222
Headers for the driver for the DMA module.
#define FAS_ASSERT(x)
Assertion macro that asserts that x is true.
Definition: fassert.h:237
#define FAS_TRAP
Define that evaluates to essential boolean false thus tripping an assert.
Definition: fassert.h:108
void FRAM_Initialize(void)
Initializes the addresses to be written in the FRAM.
Definition: fram.c:88
Header for the driver for the FRAM module.
enum STD_RETURN_TYPE STD_RETURN_TYPE_e
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic100ms
Task configuration of the cyclic 100 ms task.
Definition: ftask_cfg.c:109
void FTSK_InitializeUserCodeEngine(void)
Initializes the database.
Definition: ftask_cfg.c:125
void FTSK_RunUserCodeEngine(void)
Engine task for the database and the system monitoring module.
Definition: ftask_cfg.c:146
OS_TASK_DEFINITION_s ftsk_taskDefinitionEngine
Definition of the engine task.
Definition: ftask_cfg.c:100
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic1ms
Task configuration of the cyclic 1 ms task.
Definition: ftask_cfg.c:102
#define TASK_100MS_COUNTER_FOR_1S
Definition: ftask_cfg.c:87
void FTSK_RunUserCodeIdle(void)
Idle task.
Definition: ftask_cfg.c:234
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclicAlgorithm100ms
Task configuration of the cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:114
void FTSK_RunUserCodeCyclic100ms(void)
Cyclic 100 ms task.
Definition: ftask_cfg.c:206
void FTSK_InitializeUserCodePreCyclicTasks(void)
Initialization function before all tasks started.
Definition: ftask_cfg.c:155
void FTSK_RunUserCodeCyclic10ms(void)
Cyclic 10 ms task.
Definition: ftask_cfg.c:186
#define TASK_10MS_COUNTER_FOR_50MS
Definition: ftask_cfg.c:84
void FTSK_RunUserCodeCyclic1ms(void)
Cyclic 1 ms task.
Definition: ftask_cfg.c:176
OS_TASK_DEFINITION_s ftsk_taskDefinitionCyclic10ms
Task configuration of the cyclic 10 ms task.
Definition: ftask_cfg.c:107
void FTSK_RunUserCodeCyclicAlgorithm100ms(void)
Cyclic 100 ms task for algorithms.
Definition: ftask_cfg.c:225
Task configuration header.
#define FTSK_TASK_ENGINE_STACK_SIZE
Stack size of engine task.
Definition: ftask_cfg.h:64
#define FTSK_TASK_CYCLIC_1MS_CYCLE_TIME
Cycle time of 1ms task.
Definition: ftask_cfg.h:82
#define FTSK_TASK_ENGINE_CYCLE_TIME
Cycle time of engine task.
Definition: ftask_cfg.h:70
#define FTSK_TASK_CYCLIC_100MS_STACK_SIZE
Stack size of cyclic 100 ms task.
Definition: ftask_cfg.h:100
#define FTSK_TASK_CYCLIC_1MS_STACK_SIZE
Stack size of cyclic 1 ms task.
Definition: ftask_cfg.h:76
#define FTSK_TASK_CYCLIC_ALGORITHM_100MS_CYCLE_TIME
Cycle time of 100ms task for algorithms.
Definition: ftask_cfg.h:118
#define FTSK_TASK_CYCLIC_10MS_CYCLE_TIME
Cycle time of 10 ms task.
Definition: ftask_cfg.h:94
#define FTSK_TASK_CYCLIC_ALGORITHM_100MS_STACKSIZE
Stack size of cyclic 100 ms task for algorithms.
Definition: ftask_cfg.h:112
#define FTSK_TASK_CYCLIC_10MS_STACK_SIZE
Stack size of cyclic 10 ms task.
Definition: ftask_cfg.h:88
#define FTSK_TASK_CYCLIC_100MS_CYCLE_TIME
Cycle time of 100ms task.
Definition: ftask_cfg.h:106
#define FTSK_TASK_CYCLIC_100MS_PHASE
Phase of cyclic 100 ms task.
Definition: ftask_cfg.h:103
#define FTSK_TASK_CYCLIC_ALGORITHM_100MS_PHASE
Phase of cyclic 100 ms task for algorithms.
Definition: ftask_cfg.h:115
#define FTSK_TASK_CYCLIC_1MS_PHASE
Phase of cyclic 1ms task.
Definition: ftask_cfg.h:79
#define FTSK_TASK_CYCLIC_10MS_PHASE
Phase of cyclic 10 ms task.
Definition: ftask_cfg.h:91
#define FTSK_TASK_ENGINE_PHASE
Phase of engine task.
Definition: ftask_cfg.h:67
API header for the insulation monitoring device.
void IMD_Trigger(void)
trigger function for the IMD driver state machine.
Definition: no-imd.c:86
void ILCK_Trigger(void)
trigger function for the ILCK driver state machine.
Definition: interlock.c:320
Headers for the driver for the interlock.
void MEAS_Control(void)
Control function that is called from the task every 1ms.
Definition: meas.c:73
Headers for the driver for the measurements needed by the BMS (e.g., I,V,T).
volatile OS_TIMER_s os_timer
Definition: os.c:74
void OS_TriggerTimer(volatile OS_TIMER_s *timer)
Increments the system timer os_timer.
Definition: os.c:141
@ OS_PRIORITY_HIGH
Definition: os.h:82
@ OS_PRIORITY_NORMAL
Definition: os.h:80
@ OS_PRIORITY_REAL_TIME
Definition: os.h:86
@ OS_PRIORITY_ABOVE_HIGH
Definition: os.h:83
@ OS_PRIORITY_ABOVE_NORMAL
Definition: os.h:81
STD_RETURN_TYPE_e MRC_ValidatePackMeasurement(void)
Function to validate the measurements of pack values (string values, pack values)
Definition: redundancy.c:1102
STD_RETURN_TYPE_e MRC_ValidateMicMeasurement(void)
Function to validate the measurement between redundant measurement values for cell voltage and cell t...
Definition: redundancy.c:1069
Header fileS for handling redundancy between redundant cell voltage and cell temperature measurements...
void SBC_Trigger(SBC_STATE_s *pInstance)
trigger function for the SYS driver state machine.
Definition: sbc.c:236
SBC_STATE_s sbc_stateMcuSupervisor
Definition: sbc.c:75
Header for the driver for the SBC module.
void SOF_Calculation(void)
triggers SOF calculation
Definition: sof.c:358
Header for SOX module, responsible for current derating calculation.
Headers for the driver for the SPI module.
void SPS_Ctrl(void)
Control function for the CONT driver state machine.
Definition: sps.c:466
Headers for the driver for the smart power switches.
void SE_StateEstimations(void)
Main function to perform state estimations.
Header for state-estimation module responsible for the estimation of state-of-charge (SOC),...
struct for FreeRTOS task definition
Definition: os.h:116
SYS_RETURN_TYPE_e SYS_SetStateRequest(SYS_STATE_REQUEST_e stateRequest)
sets the current state request of the state variable sys_state.
Definition: sys.c:565
SYS_STATE_s sys_state
Definition: sys.c:92
STD_RETURN_TYPE_e SYS_Trigger(SYS_STATE_s *pSystemState)
tick function, call this to advance the state machine
Definition: sys.c:622
Sys driver header.
@ SYS_OK
Definition: sys.h:150
@ SYS_ILLEGAL_REQUEST
Definition: sys.h:153
enum SYS_RETURN_TYPE SYS_RETURN_TYPE_e
@ SYS_STATE_INIT_REQUEST
Definition: sys.h:143
void SYSM_CheckNotifications(void)
overall system monitoring
Definition: sys_mon.c:72
STD_RETURN_TYPE_e SYSM_Init(void)
initialization function for system monitoring
Definition: sys_mon_cfg.c:117