foxBMS  1.6.0
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-10-12 (date of last update)
47  * @version v1.6.0
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 /** Length of queue that is used in the can module for tracking unsent messages */
87 #define FTSK_CAN_TX_UNSENT_MESSAGES_QUEUE_LENGTH (5u)
88 /** Size of queue item that is used in the can driver */
89 #define FTSK_CAN_TX_UNSENT_MESSAGES_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(CAN_BUFFER_ELEMENT_s))
90 
91 #define FTSK_AFE_REQUEST_QUEUE_LENGTH (1u)
92 #define FTSK_AFE_REQUEST_QUEUE_ITEM_SIZE (sizeof(AFE_REQUEST_e))
93 
94 /** Length of queue that is used in the can module for receiving messages */
95 #define FTSK_RTC_QUEUE_LENGTH (1u)
96 /** Size of queue item that is used in the can driver */
97 #define FTSK_RTC_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(RTC_TIME_DATA_s))
98 
99 /** Length of queue that is used for I2C transmission over NXP slave */
100 #define FTSK_AFEI2C_QUEUE_LENGTH (1u)
101 /** Size of queue item that is used for I2C transmission over NXP slave */
102 #define FTSK_AFEI2C_QUEUE_ITEM_SIZE_IN_BYTES (sizeof(AFE_I2C_QUEUE_s))
103 
104 /*========== Extern Constant and Variable Declarations ======================*/
105 /** database queue */
106 extern OS_QUEUE ftsk_databaseQueue;
107 
108 /** queue for CAN based IMD devices */
109 extern OS_QUEUE ftsk_imdCanDataQueue;
110 
111 /** CAN driver data queue for RX messages */
112 extern OS_QUEUE ftsk_canRxQueue;
113 
114 /** CAN driver data queue for unsent TX messages */
115 extern OS_QUEUE ftsk_canTxUnsentMessagesQueue;
116 
117 /** handle of the AFE driver request queue */
118 extern OS_QUEUE ftsk_afeRequestQueue;
119 
120 /** handle of the rtc driver data queue */
121 extern OS_QUEUE ftsk_rtcSetTimeQueue;
122 
123 /** handle of the I2C transmission over NXP slave queue */
124 extern OS_QUEUE ftsk_afeToI2cQueue;
125 extern OS_QUEUE ftsk_afeFromI2cQueue;
126 
127 /** indicator whether the queues have successfully been initialized to be used
128  * in other parts of the software */
129 extern volatile bool ftsk_allQueuesCreated;
130 
131 /*========== Extern Function Prototypes =====================================*/
132 /**
133  * @brief Creates all queues
134  * @details Creates all queues. 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_CreateQueues(void);
139 
140 /**
141  * @brief Creates all tasks of the group
142  * @details Creates all tasks. Is called after the hardware is initialized
143  * and before the scheduler starts. Queues, Mutexes and Events are
144  * already initialized.
145  */
146 extern void FTSK_CreateTasks(void);
147 
148 /**
149  * @brief Database-Task
150  * @details The task manages the data exchange with the database and must have
151  * a higher task priority than any task using the database.
152  * @param pvParameters parameter for the to task
153  */
154 extern void FTSK_CreateTaskEngine(void *const pvParameters);
155 
156 /**
157  * @brief Creation of cyclic 1 ms task
158  * @details Then the Task is delayed by a phase as defined in
159  * ftsk_taskDefinitionCyclic1ms.phase (in milliseconds). After the
160  * phase delay, the cyclic execution starts, the entry time is saved
161  * in current_time. After one cycle, the Task is set to sleep until
162  * entry time + ftsk_taskDefinitionCyclic1ms.cycleTime (in
163  * milliseconds).
164  * @param pvParameters parameter for the to task
165  */
166 extern void FTSK_CreateTaskCyclic1ms(void *const pvParameters);
167 
168 /**
169  * @brief Creation of cyclic 10 ms task
170  * @details Task is delayed by a phase as defined in
171  * ftsk_taskDefinitionCyclic10ms.phase (in milliseconds). After
172  * the phase delay, the cyclic execution starts, the entry time is
173  * saved in current_time. After one cycle, the Task is set to sleep
174  * until entry time + ftsk_taskDefinitionCyclic10ms.cycleTime (in
175  * milliseconds).
176  * @param pvParameters parameter for the to task
177  */
178 extern void FTSK_CreateTaskCyclic10ms(void *const pvParameters);
179 
180 /**
181  * @brief Creation of cyclic 100 ms task
182  * @details Task is delayed by a phase as defined in
183  * ftsk_taskDefinitionCyclic100ms.phase (in milliseconds). After the
184  * phase delay, the cyclic execution starts, the entry time is saved
185  * in current_time. After one cycle, the Task is set to sleep until
186  * entry time + ftsk_taskDefinitionCyclic100ms.cycleTime (in
187  * milliseconds).
188  * @param pvParameters parameter for the to task
189  */
190 extern void FTSK_CreateTaskCyclic100ms(void *const pvParameters);
191 
192 /**
193  * @brief Creation of cyclic 100 ms algorithm task
194  * @details Task is delayed by a phase as defined in
195  * ftsk_taskDefinitionCyclicAlgorithm100ms.Phase (in milliseconds).
196  * After the phase delay, the cyclic execution starts, the entry time
197  * is saved in current_time. After one cycle, the Task is set to sleep
198  * until entry
199  * time + ftsk_taskDefinitionCyclicAlgorithm100ms.CycleTime (in
200  * milliseconds).
201  * @param pvParameters parameter for the to task
202  */
203 extern void FTSK_CreateTaskCyclicAlgorithm100ms(void *const pvParameters);
204 
205 /**
206  * @brief Creation of continuously running task for I2c
207  */
208 extern void FTSK_CreateTaskI2c(void *const pvParameters);
209 
210 /**
211  * @brief Creation of continuously running task for AFEs
212  * @param pvParameters parameter for the to task
213  */
214 extern void FTSK_CreateTaskAfe(void *const pvParameters);
215 
216 /*========== Externalized Static Functions Prototypes (Unit Test) ===========*/
217 #ifdef UNITY_UNIT_TEST
218 #endif
219 
220 #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
OS_QUEUE ftsk_canTxUnsentMessagesQueue
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.