foxBMS  1.5.1
The foxBMS Battery Management System API Documentation
ftask.h
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.h
44  * @author foxBMS Team
45  * @date 2019-08-27 (date of creation)
46  * @updated 2023-02-23 (date of last update)
47  * @version v1.5.1
48  * @ingroup TASK
49  * @prefix FTSK
50  *
51  * @brief Header of task driver implementation
52  * @details Declares the functions that are need to needed to initialize the
53  * operating system. This includes queues, mutexes, events and tasks.
54  */
55 
56 #ifndef FOXBMS__FTASK_H_
57 #define FOXBMS__FTASK_H_
58 
59 /*========== Includes =======================================================*/
60 #include "can_cfg.h"
61 #include "ftask_cfg.h"
62 
63 #include "database.h"
64 #include "os.h"
65 #include "rtc.h"
66 
67 #include <stdint.h>
68 
69 /*========== Macros and Definitions =========================================*/
70 /** Length of queue that is used in the database */
71 #define FTSK_DATABASE_QUEUE_LENGTH (1u)
72 
73 /** Size of queue item that is used in the database */
74 #define FTSK_DATABASE_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(DATA_QUEUE_MESSAGE_s))
75 
76 /** Length of queue that is used in the insulation measurement device (IMD) */
77 #define FTSK_IMD_QUEUE_LENGTH (5u)
78 /** Size of queue item that is used in the IMD driver */
79 #define FTSK_IMD_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(CAN_BUFFER_ELEMENT_s))
80 
81 /** Length of queue that is used in the can module for receiving messages */
82 #define FTSK_CAN_RX_QUEUE_LENGTH (50u)
83 /** Size of queue item that is used in the can driver */
84 #define FTSK_CAN_RX_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(CAN_BUFFER_ELEMENT_s))
85 
86 #define FTSK_AFE_REQUEST_QUEUE_LENGTH (1u)
87 #define FTSK_AFE_REQUEST_QUEUE_ITEM_SIZE (sizeof(AFE_REQUEST_e))
88 
89 /** Length of queue that is used in the can module for receiving messages */
90 #define FTSK_RTC_QUEUE_LENGTH (1u)
91 /** Size of queue item that is used in the can driver */
92 #define FTSK_RTC_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(RTC_TIME_DATA_s))
93 
94 /** Length of queue that is used for I2C transmission over NXP slave */
95 #define FTSK_AFEI2C_QUEUE_LENGTH (1u)
96 /** Size of queue item that is used for I2C transmission over NXP slave */
97 #define FTSK_AFEI2C_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(AFE_I2C_QUEUE_s))
98 
99 /*========== Extern Constant and Variable Declarations ======================*/
100 /** database queue */
101 extern OS_QUEUE ftsk_databaseQueue;
102 
103 /** queue for CAN based IMD devices */
104 extern OS_QUEUE ftsk_imdCanDataQueue;
105 
106 /** CAN driver data queue for RX messages */
107 extern OS_QUEUE ftsk_canRxQueue;
108 
109 /** handle of the AFE driver request queue */
110 extern OS_QUEUE ftsk_afeRequestQueue;
111 
112 /** handle of the rtc driver data queue */
113 extern OS_QUEUE ftsk_rtcSetTimeQueue;
114 
115 /** handle of the I2C transmission over NXP slave queue */
116 extern OS_QUEUE ftsk_afeToI2cQueue;
117 extern OS_QUEUE ftsk_afeFromI2cQueue;
118 
119 /** indicator whether the queues have successfully been initialized to be used
120  * in other parts of the software */
121 extern volatile bool ftsk_allQueuesCreated;
122 
123 /*========== Extern Function Prototypes =====================================*/
124 /**
125  * @brief Creates all queues
126  * @details Creates all queues. Is called after the hardware is initialized
127  * and before the scheduler starts. Queues, Mutexes and Events are
128  * already initialized.
129  */
130 extern void FTSK_CreateQueues(void);
131 
132 /**
133  * @brief Creates all tasks of the group
134  * @details Creates all tasks. Is called after the hardware is initialized
135  * and before the scheduler starts. Queues, Mutexes and Events are
136  * already initialized.
137  */
138 extern void FTSK_CreateTasks(void);
139 
140 /**
141  * @brief Database-Task
142  * @details The task manages the data exchange with the database and must have
143  * a higher task priority than any task using the database.
144  * @param pvParameters parameter for the to task
145  */
146 extern void FTSK_CreateTaskEngine(void *const pvParameters);
147 
148 /**
149  * @brief Creation of cyclic 1 ms task
150  * @details Then the Task is delayed by a phase as defined in
151  * ftsk_taskDefinitionCyclic1ms.phase (in milliseconds). After the
152  * phase delay, the cyclic execution starts, the entry time is saved
153  * in current_time. After one cycle, the Task is set to sleep until
154  * entry time + ftsk_taskDefinitionCyclic1ms.cycleTime (in
155  * milliseconds).
156  * @param pvParameters parameter for the to task
157  */
158 extern void FTSK_CreateTaskCyclic1ms(void *const pvParameters);
159 
160 /**
161  * @brief Creation of cyclic 10 ms task
162  * @details Task is delayed by a phase as defined in
163  * ftsk_taskDefinitionCyclic10ms.phase (in milliseconds). After
164  * the phase delay, the cyclic execution starts, the entry time is
165  * saved in current_time. After one cycle, the Task is set to sleep
166  * until entry time + ftsk_taskDefinitionCyclic10ms.cycleTime (in
167  * milliseconds).
168  * @param pvParameters parameter for the to task
169  */
170 extern void FTSK_CreateTaskCyclic10ms(void *const pvParameters);
171 
172 /**
173  * @brief Creation of cyclic 100 ms task
174  * @details Task is delayed by a phase as defined in
175  * ftsk_taskDefinitionCyclic100ms.phase (in milliseconds). After the
176  * phase delay, the cyclic execution starts, the entry time is saved
177  * in current_time. After one cycle, the Task is set to sleep until
178  * entry time + ftsk_taskDefinitionCyclic100ms.cycleTime (in
179  * milliseconds).
180  * @param pvParameters parameter for the to task
181  */
182 extern void FTSK_CreateTaskCyclic100ms(void *const pvParameters);
183 
184 /**
185  * @brief Creation of cyclic 100 ms algorithm task
186  * @details Task is delayed by a phase as defined in
187  * ftsk_taskDefinitionCyclicAlgorithm100ms.Phase (in milliseconds).
188  * After the phase delay, the cyclic execution starts, the entry time
189  * is saved in current_time. After one cycle, the Task is set to sleep
190  * until entry
191  * time + ftsk_taskDefinitionCyclicAlgorithm100ms.CycleTime (in
192  * milliseconds).
193  * @param pvParameters parameter for the to task
194  */
195 extern void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters);
196 
197 /**
198  * @brief Creation of continuously running task for I2c
199  */
200 extern void FTSK_CreateTaskI2c(void *const pvParameters);
201 
202 /**
203  * @brief Creation of continuously running task for AFEs
204  * @param pvParameters parameter for the to task
205  */
206 extern void FTSK_CreateTaskAfe(void *const pvParameters);
207 
208 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
209 #ifdef UNITY_UNIT_TEST
210 #endif
211 
212 #endif /* FOXBMS__FTASK_H_ */
Headers for the configuration for the CAN module.
Database module header.
void FTSK_CreateTaskEngine(void *const pvParameters)
Database-Task.
Definition: ftask.c:76
OS_QUEUE ftsk_afeFromI2cQueue
void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters)
Creation of cyclic 100 ms algorithm task.
Definition: ftask.c:188
OS_QUEUE ftsk_rtcSetTimeQueue
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
OS_QUEUE ftsk_imdCanDataQueue
volatile bool ftsk_allQueuesCreated
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
OS_QUEUE ftsk_afeToI2cQueue
void FTSK_CreateTasks(void)
Creates all tasks of the group.
OS_QUEUE ftsk_canRxQueue
OS_QUEUE ftsk_afeRequestQueue
OS_QUEUE ftsk_databaseQueue
void FTSK_CreateQueues(void)
Creates all queues.
void FTSK_CreateTaskI2c(void *const pvParameters)
Creation of continuously running task for I2c.
Definition: ftask.c:219
Task configuration header.
Declaration of the OS wrapper interface.
Header file of the RTC driver.