1 /**
2   ******************************************************************************
3   * @file    tae32f53xx_ll_ecu.h
4   * @author  MCD Application Team
5   * @brief   Header file of ECU LL module
6   *
7   ******************************************************************************
8   * @attention
9   *
10   * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
11   * All rights reserved.</center></h2>
12   *
13   * This software is licensed by Tai-Action under BSD 3-Clause license,
14   * the "License"; You may not use this file except in compliance with the
15   * License. You may obtain a copy of the License at:
16   *                        opensource.org/licenses/BSD-3-Clause
17   *
18   ******************************************************************************
19   */
20 
21 /* Define to prevent recursive inclusion -------------------------------------*/
22 #ifndef _TAE32F53XX_LL_ECU_H_
23 #define _TAE32F53XX_LL_ECU_H_
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 /* Includes ------------------------------------------------------------------*/
30 #include "tae32f53xx_ll_def.h"
31 
32 
33 /** @addtogroup TAE32F53xx_LL_Driver
34   * @{
35   */
36 
37 /** @addtogroup ECU_LL
38   * @{
39   */
40 
41 
42 /* Exported constants --------------------------------------------------------*/
43 /** @defgroup ECU_LL_Exported_Constants ECU LL Exported Constants
44   * @brief    ECU LL Exported Constants
45   * @{
46   */
47 
48 /** @defgroup LL_ECU_ENABLE ECU enable define
49   * @brief    ECU Enable Bit Set and Bit Reset
50   * @{
51   */
52 #define ECU_DISABLE                         (0x00000000U)       /*!<ECU module disable          */
53 #define ECU_ENABLE                          (ECU_CON_ENABLE)    /*!<ECU module enable           */
54 /**
55   * @}
56   */
57 
58 /** @defgroup LL_ECU_IT_ENABLE ECU enable interrupt define
59   * @brief    ECU Interrupt Enable Bit Set and Bit Reset
60   * @{
61   */
62 #define ECU_IT_DISABLE                      (0x00000000U)       /*!<ECU module disable          */
63 #define ECU_IT_ENABLE                       (ECU_CON_INTEN)     /*!<ECU module interrupt enable */
64 /**
65   * @}
66   */
67 
68 /**
69   * @}
70   */
71 
72 
73 /* Exported types ------------------------------------------------------------*/
74 /** @defgroup ECU_LL_Exported_Types ECU LL Exported Types
75   * @brief    ECU LL Exported Types
76   * @{
77   */
78 
79 /** @defgroup LL_ECU_AVERAGE ECU average period define
80   * @brief  ECU Enumerate the number of periods to be averaged
81   * @{
82   */
83 typedef enum {
84     ECU_AVERAGE_DISABLE = 0x0,  /*!<Instead of averaging the results of the periodic data, one result is produced per period    */
85     ECU_AVERAGE_2PERIOD = ECU_CON_AVGSEL_0,                     /*!<Two cycles of data produce a result                         */
86     ECU_AVERAGE_4PERIOD = ECU_CON_AVGSEL_1,                     /*!<Four cycles of data produce a result                        */
87     ECU_AVERAGE_8PERIOD = ECU_CON_AVGSEL_1 | ECU_CON_AVGSEL_0,  /*!<Eight cycles of data produce a result                       */
88 } ECU_AverageETypedef;
89 /**
90   * @}
91   */
92 
93 /** @defgroup LL_ECU_ACPOWER_LEFT_SHIFT ECU active power left shift define
94   * @brief  ECU Enumerate the left shift number of active power
95   * @{
96   */
97 typedef enum {
98     ECU_ACPOWER_LEFT_SHIFT_DISABLE = 0x0,
99     ECU_ACPOWER_LEFT_SHIFT_1       = ECU_CON_ACSFT_0,
100     ECU_ACPOWER_LEFT_SHIFT_2       = ECU_CON_ACSFT_1,
101     ECU_ACPOWER_LEFT_SHIFT_3       = ECU_CON_ACSFT_1 | ECU_CON_ACSFT_0,
102     ECU_ACPOWER_LEFT_SHIFT_4       = ECU_CON_ACSFT_2,
103     ECU_ACPOWER_LEFT_SHIFT_5       = ECU_CON_ACSFT_2 | ECU_CON_ACSFT_0,
104     ECU_ACPOWER_LEFT_SHIFT_6       = ECU_CON_ACSFT_2 | ECU_CON_ACSFT_1,
105     ECU_ACPOWER_LEFT_SHIFT_7       = ECU_CON_ACSFT_2 | ECU_CON_ACSFT_1 | ECU_CON_ACSFT_0,
106     ECU_ACPOWER_LEFT_SHIFT_8       = ECU_CON_ACSFT_3,
107     ECU_ACPOWER_LEFT_SHIFT_9       = ECU_CON_ACSFT_3 | ECU_CON_ACSFT_0,
108     ECU_ACPOWER_LEFT_SHIFT_10      = ECU_CON_ACSFT_3 | ECU_CON_ACSFT_1,
109     ECU_ACPOWER_LEFT_SHIFT_11      = ECU_CON_ACSFT_3 | ECU_CON_ACSFT_1 | ECU_CON_ACSFT_0,
110     ECU_ACPOWER_LEFT_SHIFT_12      = ECU_CON_ACSFT_3 | ECU_CON_ACSFT_2,
111     ECU_ACPOWER_LEFT_SHIFT_13      = ECU_CON_ACSFT_3 | ECU_CON_ACSFT_2 | ECU_CON_ACSFT_0,
112     ECU_ACPOWER_LEFT_SHIFT_14      = ECU_CON_ACSFT_3 | ECU_CON_ACSFT_2 | ECU_CON_ACSFT_1,
113     ECU_ACPOWER_LEFT_SHIFT_15      = ECU_CON_ACSFT_3 | ECU_CON_ACSFT_2 | ECU_CON_ACSFT_1 | ECU_CON_ACSFT_0,
114     ECU_ACPOWER_LEFT_SHIFT_16      = ECU_CON_ACSFT_4,
115 } ECU_ACPowerLeftETypeDef;
116 /**
117   * @}
118   */
119 
120 /** @defgroup LL_ECU_APPOWER_RIGHT_SHIFT ECU apparent power right shift define
121   * @brief  ECU Enumerate the right shift number of the apparent power
122   * @{
123   */
124 typedef enum {
125     ECU_APPOWER_RIGHT_SHIFT_DISABLE = 0x0,
126     ECU_APPOWER_RIGHT_SHIFT_1       = ECU_CON_APSFT_0,
127     ECU_APPOWER_RIGHT_SHIFT_2       = ECU_CON_APSFT_1,
128     ECU_APPOWER_RIGHT_SHIFT_3       = ECU_CON_APSFT_1 | ECU_CON_APSFT_0,
129     ECU_APPOWER_RIGHT_SHIFT_4       = ECU_CON_APSFT_2,
130     ECU_APPOWER_RIGHT_SHIFT_5       = ECU_CON_APSFT_2 | ECU_CON_APSFT_0,
131     ECU_APPOWER_RIGHT_SHIFT_6       = ECU_CON_APSFT_2 | ECU_CON_APSFT_1,
132     ECU_APPOWER_RIGHT_SHIFT_7       = ECU_CON_APSFT_2 | ECU_CON_APSFT_1 | ECU_CON_APSFT_0,
133     ECU_APPOWER_RIGHT_SHIFT_8       = ECU_CON_APSFT_3,
134     ECU_APPOWER_RIGHT_SHIFT_9       = ECU_CON_APSFT_3 | ECU_CON_APSFT_0,
135     ECU_APPOWER_RIGHT_SHIFT_10      = ECU_CON_APSFT_3 | ECU_CON_APSFT_1,
136     ECU_APPOWER_RIGHT_SHIFT_11      = ECU_CON_APSFT_3 | ECU_CON_APSFT_1 | ECU_CON_APSFT_0,
137     ECU_APPOWER_RIGHT_SHIFT_12      = ECU_CON_APSFT_3 | ECU_CON_APSFT_2,
138     ECU_APPOWER_RIGHT_SHIFT_13      = ECU_CON_APSFT_3 | ECU_CON_APSFT_2 | ECU_CON_APSFT_0,
139     ECU_APPOWER_RIGHT_SHIFT_14      = ECU_CON_APSFT_3 | ECU_CON_APSFT_2 | ECU_CON_APSFT_1,
140     ECU_APPOWER_RIGHT_SHIFT_15      = ECU_CON_APSFT_3 | ECU_CON_APSFT_2 | ECU_CON_APSFT_1 | ECU_CON_APSFT_0,
141     ECU_APPOWER_RIGHT_SHIFT_16      = ECU_CON_APSFT_4,
142 } ECU_APPowerRightETypeDef;
143 /**
144   * @}
145   */
146 
147 /** @defgroup LL_ECU_PSR_DATSEL ECU data external event define
148   * @brief  ECU Enumerate data event selection to select from 16 events
149   * @note   These three types of events must be selected in the same ECR register in the same ADC and cannot be mixed
150   * @{
151   */
152 typedef enum {
153     /*!<ECU Data trigger from external peripheral : ADC0_ECR[0]->ADDR_DATA_FLAG */
154     ECU_PSR_DATSEL_ADC0_DTFLAG0          = 0x0,
155     /*!<ECU Data trigger from external peripheral : ADC0_ECR[1]->ADDR_DATA_FLAG */
156     ECU_PSR_DATSEL_ADC0_DTFLAG1          = ECU_PRC_DATSEL_0,
157     /*!<ECU Data trigger from external peripheral : ADC0_ECR[2]->ADDR_DATA_FLAG */
158     ECU_PSR_DATSEL_ADC0_DTFLAG2          = ECU_PRC_DATSEL_1,
159     /*!<ECU Data trigger from external peripheral : ADC0_ECR[3]->ADDR_DATA_FLAG */
160     ECU_PSR_DATSEL_ADC0_DTFLAG3          = ECU_PRC_DATSEL_1 | ECU_PRC_DATSEL_0,
161     /*!<ECU Data trigger from external peripheral : ADC1_ECR[0]->ADDR_DATA_FLAG */
162     ECU_PSR_DATSEL_ADC1_DTFLAG0          = ECU_PRC_DATSEL_2,
163     /*!<ECU Data trigger from external peripheral : ADC1_ECR[1]->ADDR_DATA_FLAG */
164     ECU_PSR_DATSEL_ADC1_DTFLAG1          = ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_0,
165     /*!<ECU Data trigger from external peripheral : ADC1_ECR[2]->ADDR_DATA_FLAG */
166     ECU_PSR_DATSEL_ADC1_DTFLAG2          = ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_1,
167     /*!<ECU Data trigger from external peripheral : ADC1_ECR[3]->ADDR_DATA_FLAG */
168     ECU_PSR_DATSEL_ADC1_DTFLAG3          = ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_1 | ECU_PRC_DATSEL_0,
169     /*!<ECU Data trigger from external peripheral : TIM0_OC                     */
170     ECU_PSR_DATSEL_TIM0_OC               = ECU_PRC_DATSEL_3,
171     /*!<ECU Data trigger from external peripheral : TIM1_OC                     */
172     ECU_PSR_DATSEL_TIM1_OC               = ECU_PRC_DATSEL_3 | ECU_PRC_DATSEL_0,
173     /*!<ECU Data trigger from external peripheral : TIM2_OC                     */
174     ECU_PSR_DATSEL_TIM2_OC               = ECU_PRC_DATSEL_3 | ECU_PRC_DATSEL_1,
175     /*!<ECU Data trigger from external peripheral : TIM3_OC                     */
176     ECU_PSR_DATSEL_TIM3_OC               = ECU_PRC_DATSEL_3 | ECU_PRC_DATSEL_1 | ECU_PRC_DATSEL_0,
177     /*!<ECU Data trigger from external peripheral : TIM4_OC                     */
178     ECU_PSR_DATSEL_TIM4_OC               = ECU_PRC_DATSEL_3 | ECU_PRC_DATSEL_2,
179     /*!<ECU Data trigger from external peripheral : TIM5_OC                     */
180     ECU_PSR_DATSEL_TIM5_OC               = ECU_PRC_DATSEL_3 | ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_0,
181     /*!<ECU Data trigger from external peripheral : TIM6_OC                     */
182     ECU_PSR_DATSEL_TIM6_OC               = ECU_PRC_DATSEL_3 | ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_1,
183     /*!<ECU Data trigger from external peripheral : TIM7_OC                     */
184     ECU_PSR_DATSEL_TIM7_OC               = ECU_PRC_DATSEL_3 | ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_1 | ECU_PRC_DATSEL_0,
185 } ECU_DataSelETypeDef;
186 /**
187   * @}
188   */
189 
190 /** @defgroup LL_ECU_PSR_ADRSEL ECU address external event define
191   * @brief  ECU Enumerate the address event (the channel for waveform data) to select from 16 events.
192   * @note   These three types of events must be selected in the same ECR register in the same ADC and cannot be mixed
193   * @{
194   */
195 typedef enum {
196     /*!<ECU Address trigger from external peripheral : ADC0_ECR[0]->ADDR_DATA_FLAG*/
197     ECU_PSR_ADRSEL_ADC0_ADFLAG0          = 0x0,
198     /*!<ECU Address trigger from external peripheral : ADC0_ECR[1]->ADDR_DATA_FLAG*/
199     ECU_PSR_ADRSEL_ADC0_ADFLAG1          = ECU_PRC_ADRSEL_0,
200     /*!<ECU Address trigger from external peripheral : ADC0_ECR[2]->ADDR_DATA_FLAG*/
201     ECU_PSR_ADRSEL_ADC0_ADFLAG2          = ECU_PRC_ADRSEL_1,
202     /*!<ECU Address trigger from external peripheral : ADC0_ECR[3]->ADDR_DATA_FLAG*/
203     ECU_PSR_ADRSEL_ADC0_ADFLAG3          = ECU_PRC_ADRSEL_1 | ECU_PRC_ADRSEL_0,
204     /*!<ECU Address trigger from external peripheral : ADC1_ECR[0]->ADDR_DATA_FLAG*/
205     ECU_PSR_ADRSEL_ADC1_ADFLAG0          = ECU_PRC_ADRSEL_2,
206     /*!<ECU Address trigger from external peripheral : ADC1_ECR[1]->ADDR_DATA_FLAG*/
207     ECU_PSR_ADRSEL_ADC1_ADFLAG1          = ECU_PRC_ADRSEL_2 | ECU_PRC_ADRSEL_0,
208     /*!<ECU Address trigger from external peripheral : ADC1_ECR[2]->ADDR_DATA_FLAG*/
209     ECU_PSR_ADRSEL_ADC1_ADFLAG2          = ECU_PRC_ADRSEL_2 | ECU_PRC_ADRSEL_1,
210     /*!<ECU Address trigger from external peripheral : ADC1_ECR[3]->ADDR_DATA_FLAG*/
211     ECU_PSR_ADRSEL_ADC1_ADFLAG3          = ECU_PRC_ADRSEL_2 | ECU_PRC_ADRSEL_1 | ECU_PRC_ADRSEL_0,
212     /*!<ECU Address trigger from external peripheral : TIM0_OC*/
213     ECU_PSR_ADRSEL_TIM0_OC               = ECU_PRC_ADRSEL_3,
214     /*!<ECU Address trigger from external peripheral : TIM1_OC*/
215     ECU_PSR_ADRSEL_TIM1_OC               = ECU_PRC_ADRSEL_3 | ECU_PRC_ADRSEL_0,
216     /*!<ECU Address trigger from external peripheral : TIM2_OC*/
217     ECU_PSR_ADRSEL_TIM2_OC               = ECU_PRC_ADRSEL_3 | ECU_PRC_ADRSEL_1,
218     /*!<ECU Address trigger from external peripheral : TIM3_OC*/
219     ECU_PSR_ADRSEL_TIM3_OC               = ECU_PRC_ADRSEL_3 | ECU_PRC_ADRSEL_1 | ECU_PRC_ADRSEL_0,
220     /*!<ECU Address trigger from external peripheral : TIM4_OC*/
221     ECU_PSR_ADRSEL_TIM4_OC               = ECU_PRC_ADRSEL_3 | ECU_PRC_ADRSEL_2,
222     /*!<ECU Address trigger from external peripheral : TIM5_OC*/
223     ECU_PSR_ADRSEL_TIM5_OC               = ECU_PRC_ADRSEL_3 | ECU_PRC_ADRSEL_2 | ECU_PRC_ADRSEL_0,
224     /*!<ECU Address trigger from external peripheral : TIM6_OC*/
225     ECU_PSR_ADRSEL_TIM6_OC               = ECU_PRC_ADRSEL_3 | ECU_PRC_ADRSEL_2 | ECU_PRC_ADRSEL_1,
226     /*!<ECU Address trigger from external peripheral : TIM7_OC*/
227     ECU_PSR_ADRSEL_TIM7_OC               = ECU_PRC_ADRSEL_3 | ECU_PRC_ADRSEL_2 | ECU_PRC_ADRSEL_1 | ECU_PRC_ADRSEL_0,
228 } ECU_AddrSelETypeDef;
229 /**
230   * @}
231   */
232 
233 /** @defgroup LL_ECU_PSR_CRSSEL ECU cross zero external event define
234   * @brief  ECU Enumerate zero crossing events (monitoring events for sinusoidal waveform zero crossing) and select from 16 events.
235   * @note   These three types of events must be selected in the same ECR register in the same ADC and cannot be mixed
236   * @{
237   */
238 typedef enum {
239     /*!<ECU Crossing zero signal trigger from external peripheral : ADC0_ECR[0]->PSRCU/PSRCD    */
240     ECU_PSR_CRSSEL_ADC0_PPFLAG0          = 0x0,
241     /*!<ECU Crossing zero signal trigger from external peripheral : ADC0_ECR[1]->PSRCU/PSRCD    */
242     ECU_PSR_CRSSEL_ADC0_PPFLAG1          = ECU_PRC_CRSSEL_0,
243     /*!<ECU Crossing zero signal trigger from external peripheral : ADC0_ECR[2]->PSRCU/PSRCD    */
244     ECU_PSR_CRSSEL_ADC0_PPFLAG2          = ECU_PRC_CRSSEL_1,
245     /*!<ECU Crossing zero signal trigger from external peripheral : ADC0_ECR[3]->PSRCU/PSRCD    */
246     ECU_PSR_CRSSEL_ADC0_PPFLAG3          = ECU_PRC_CRSSEL_1  | ECU_PRC_CRSSEL_0,
247     /*!<ECU Crossing zero signal trigger from external peripheral : ADC1_ECR[0]->PSRCU/PSRCD    */
248     ECU_PSR_CRSSEL_ADC1_PPFLAG0          = ECU_PRC_CRSSEL_2,
249     /*!<ECU Crossing zero signal trigger from external peripheral : ADC1_ECR[1]->PSRCU/PSRCD    */
250     ECU_PSR_CRSSEL_ADC1_PPFLAG1          = ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_0,
251     /*!<ECU Crossing zero signal trigger from external peripheral : ADC1_ECR[2]->PSRCU/PSRCD    */
252     ECU_PSR_CRSSEL_ADC1_PPFLAG2          = ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_1,
253     /*!<ECU Crossing zero signal trigger from external peripheral : ADC1_ECR[3]->PSRCU/PSRCD    */
254     ECU_PSR_CRSSEL_ADC1_PPFLAG3          = ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_1 | ECU_PRC_CRSSEL_0,
255     /*!<ECU Crossing zero signal trigger from external peripheral : TIM0_OC                     */
256     ECU_PSR_CRSSEL_TIM0_OC               = ECU_PRC_CRSSEL_3,
257     /*!<ECU Crossing zero signal trigger from external peripheral : TIM1_OC                     */
258     ECU_PSR_CRSSEL_TIM1_OC               = ECU_PRC_CRSSEL_3 | ECU_PRC_CRSSEL_0,
259     /*!<ECU Crossing zero signal trigger from external peripheral : TIM2_OC                     */
260     ECU_PSR_CRSSEL_TIM2_OC               = ECU_PRC_CRSSEL_3 | ECU_PRC_CRSSEL_1,
261     /*!<ECU Crossing zero signal trigger from external peripheral : TIM3_OC                     */
262     ECU_PSR_CRSSEL_TIM3_OC               = ECU_PRC_CRSSEL_3 | ECU_PRC_CRSSEL_1 | ECU_PRC_CRSSEL_0,
263     /*!<ECU Crossing zero signal trigger from external peripheral : TIM4_OC                     */
264     ECU_PSR_CRSSEL_TIM4_OC               = ECU_PRC_CRSSEL_3 | ECU_PRC_CRSSEL_2,
265     /*!<ECU Crossing zero signal trigger from external peripheral : TIM5_OC                     */
266     ECU_PSR_CRSSEL_TIM5_OC               = ECU_PRC_CRSSEL_3 | ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_0,
267     /*!<ECU Crossing zero signal trigger from external peripheral : TIM6_OC                     */
268     ECU_PSR_CRSSEL_TIM6_OC               = ECU_PRC_CRSSEL_3 | ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_1,
269     /*!<ECU Crossing zero signal trigger from external peripheral : TIM7_OC                     */
270     ECU_PSR_CRSSEL_TIM7_OC               = ECU_PRC_CRSSEL_3 | ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_1 | ECU_PRC_CRSSEL_0,
271 } ECU_CrossZeroSelETypeDef;
272 /**
273   * @}
274   */
275 
276 /**
277   * @brief ECU Init structure definition
278   */
279 typedef struct __ECU_InitTypeDef {
280     LL_FuncStatusETypeDef ModuleEnable;     /*!< Specifies ECU module enablement Bit.
281                                                 This parameter can be any value of @ref ENABLE or DISABLE*/
282 
283     LL_FuncStatusETypeDef InterruptEn;      /*!< Specifies ECU module enable interrupt.
284                                                 This parameter can be any value of @ref ENABLE or DISABLE */
285 
286     ECU_AverageETypedef AverageSel;         /*!< Setting the result requires averaging the data over several cycles.
287                                                 This parameter can be a value of @ref LL_ECU_AVERAGE */
288 
289     ECU_APPowerRightETypeDef APRightShift;  /*!< Set the number of right shifts of the ECU view Apparent power.
290                                                 This parameter can be a value of @ref LL_ECU_APPOWER_RIGHT_SHIFT */
291 
292     ECU_ACPowerLeftETypeDef ACLeftShift;    /*!< Set the number of left shift of active power and the maximum left shift is 16 bits.
293                                                 This parameter can be a value of @ref LL_ECU_ACPOWER_LEFT_SHIFT*/
294 
295     ECU_CrossZeroSelETypeDef CrossZeroSel;  /*!< Set zero crossing events (monitoring events for sinusoidal waveform zero crossing)
296                                                  and select from 16 events. This parameter can be a value of @ref LL_ECU_PSR_CRSSEL */
297 
298     ECU_AddrSelETypeDef AddressSel;         /*!< Set the address event (the channel for waveform data) to select from 16 events.
299                                                 This parameter can be a value of @ref LL_ECU_PSR_ADRSEL */
300 
301     ECU_DataSelETypeDef DataSel;            /*!< Set data event selection to select from 16 events.
302                                                 This parameter can be a value of @ref LL_ECU_PSR_DATSEL */
303 
304     uint32_t VStartAddr;                    /*!< Set the starting address for voltage (pingpong) data storage.*/
305 
306     uint32_t VOffsetAddr;                   /*!< Set voltage (pingpong) data to store offset address.*/
307 
308     uint32_t IStartAddr;                    /*!< Set the starting address for current (pingpong) data storage.*/
309 
310     uint32_t IOffsetAddr;                   /*!< Set current (pingpong) data to store offset address.*/
311 
312 } ECU_InitTypeDef;
313 
314 /**
315   * @}
316   */
317 
318 
319 /* Exported macro ------------------------------------------------------------*/
320 /** @defgroup ECU_LL_Exported_Macros ECU LL Exported Macros
321   * @brief    ECU LL Exported Macros
322   * @{
323   */
324 
325 /**
326   * @brief  Enable the ECU module.
327   * @param  __INSTANCE__ Specifies ECU peripheral
328   * @return None
329   */
330 #define __LL_ECU_MODULE_ENABLE(__INSTANCE__)                    SET_BIT((__INSTANCE__)->CON, ECU_CON_ENABLE)
331 
332 /**
333   * @brief  Disable the ECU module.
334   * @param  __INSTANCE__ Specifies ECU peripheral
335   * @return None
336   */
337 #define __LL_ECU_MODULE_DISABLE(__INSTANCE__)                   CLEAR_BIT((__INSTANCE__)->CON, ECU_CON_ENABLE)
338 
339 /**
340   * @brief  Get the ECU module states.
341   * @param  __INSTANCE__ Specifies ECU peripheral
342   * @return ENABLE : the module is enable
343   *         DISABLE : the module is disable
344   */
345 #define __LL_ECU_GET_STA(__INSTANCE__)              ((((__INSTANCE__)->CON & (ECU_CON_ENABLE)) == 0x1UL) ? ENABLE : DISABLE)
346 
347 /**
348   * @brief  Enable the specified ECU Calculate complete interrupt.
349   * @param  __INSTANCE__ Specifies ECU peripheral
350   * @return None
351   */
352 #define __LL_ECU_DONE_IT_ENABLE(__INSTANCE__)                   SET_BIT((__INSTANCE__)->CON, ECU_CON_INTEN)
353 
354 /**
355   * @brief  Disable the specified ECU Calculate complete interrupt.
356   * @param  __INSTANCE__ Specifies ECU peripheral
357   * @return None
358   */
359 #define __LL_ECU_DONE_IT_DISABLE(__INSTANCE__)                  CLEAR_BIT((__INSTANCE__)->CON, ECU_CON_INTEN)
360 
361 /**
362   * @brief  Check the ECU Calculate complete interrupts are enabled or disable.
363   * @param  __INSTANCE__ Specifies ECU peripheral
364   * @return SET : the interrupt is enable
365   *         RESET : the interrupt is disable
366   */
367 #define __LL_ECU_DONE_GET_IT(__INSTANCE__)                      ((((__INSTANCE__)->CON & (ECU_CON_INTEN)) == 0x02UL) ? SET : RESET)
368 
369 /**
370   * @brief  Check whether the specified ECU Calculate complete pending flag is set or not.
371   * @param  __INSTANCE__ Specifies ECU peripheral
372   * @return SET : the interrupt flag is set
373   *         RESET : the interrupt flag is reset
374   */
375 #define __LL_ECU_DONE_GET_FLAG(__INSTANCE__)                    ((((__INSTANCE__)->CON & (ECU_CON_INT)) == 0x8000UL) ? SET : RESET)
376 
377 /**
378   * @brief  Clear the specified  ECU Calculate complete pending flags.
379   * @param  __INSTANCE__ Specifies ECU peripheral
380   * @return None
381   */
382 #define __LL_ECU_DONE_CLEAR_FLAG(__INSTANCE__)                  SET_BIT((__INSTANCE__)->CON, ECU_CON_INT)
383 
384 /**
385   * @brief  Input data square enable, after the completion of the calculation automatically reset
386   * @param  __INSTANCE__ Specifies ECU peripheral
387   * @return None
388   */
389 #define __LL_ECU_SQRT_ENABLE(__INSTANCE__)                      SET_BIT((__INSTANCE__)->CON, ECU_CON_SQRT)
390 
391 /**
392   * @brief  Gets the square root completion flag
393   * @param  __INSTANCE__ Specifies ECU peripheral
394   * @return RESET That means the square root is complete
395   *         SET   That means the square root is not complete
396   */
397 #define __LL_ECU_SQRT_DONE_FLAG(__INSTANCE__)                   ((((__INSTANCE__)->CON & (ECU_CON_SQRT)) == 0x4000UL) ? SET : RESET)
398 
399 /**
400   * @brief  Sets the zero crossing event that needs to be selected
401   * @param  __INSTANCE__ Specifies ECU peripheral
402   * @param  __EVENT__ cross zero event as follow:
403   *         @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAF0
404   *         @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAG1
405   *         @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAG2
406   *         @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAG3
407   *         @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG0
408   *         @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG1
409   *         @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG2
410   *         @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG3
411   *         @arg @ref ECU_PSR_CRSSEL_TIM0_OC
412   *         @arg @ref ECU_PSR_CRSSEL_TIM1_OC
413   *         @arg @ref ECU_PSR_CRSSEL_TIM2_OC
414   *         @arg @ref ECU_PSR_CRSSEL_TIM3_OC
415   *         @arg @ref ECU_PSR_CRSSEL_TIM4_OC
416   *         @arg @ref ECU_PSR_CRSSEL_TIM5_OC
417   *         @arg @ref ECU_PSR_CRSSEL_TIM6_OC
418   *         @arg @ref ECU_PSR_CRSSEL_TIM7_OC
419   * @return None
420   */
421 #define __LL_ECU_CROSS_ZERO_EVENT(__INSTANCE__, __EVENT__)      MODIFY_REG((__INSTANCE__)->PRC, ECU_PRC_CRSSEL, __EVENT__)
422 
423 /**
424   * @brief  Sets the data event that needs to be selected
425   * @param  __INSTANCE__ Specifies ECU peripheral
426   * @param  __EVENT__ cross zero event as follow:
427   *         @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAF0
428   *         @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAG1
429   *         @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAG2
430   *         @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAG3
431   *         @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG0
432   *         @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG1
433   *         @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG2
434   *         @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG3
435   *         @arg @ref ECU_PSR_DATSEL_TIM0_OC
436   *         @arg @ref ECU_PSR_DATSEL_TIM1_OC
437   *         @arg @ref ECU_PSR_DATSEL_TIM2_OC
438   *         @arg @ref ECU_PSR_DATSEL_TIM3_OC
439   *         @arg @ref ECU_PSR_DATSEL_TIM4_OC
440   *         @arg @ref ECU_PSR_DATSEL_TIM5_OC
441   *         @arg @ref ECU_PSR_DATSEL_TIM6_OC
442   *         @arg @ref ECU_PSR_DATSEL_TIM7_OC
443   * @return None
444   */
445 #define __LL_ECU_DATA_FLAG_EVENT(__INSTANCE__, __EVENT__)       MODIFY_REG((__INSTANCE__)->PRC, ECU_PRC_DATSEL, __EVENT__)
446 
447 
448 /**
449   * @brief  Sets the addr_data flag event that needs to be selected
450   * @param  __INSTANCE__ Specifies ECU peripheral
451   * @param  __EVENT__ cross zero event as follow:
452   *         @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAF0
453   *         @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAG1
454   *         @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAG2
455   *         @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAG3
456   *         @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG0
457   *         @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG1
458   *         @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG2
459   *         @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG3
460   *         @arg @ref ECU_PSR_ADRSEL_TIM0_OC
461   *         @arg @ref ECU_PSR_ADRSEL_TIM1_OC
462   *         @arg @ref ECU_PSR_ADRSEL_TIM2_OC
463   *         @arg @ref ECU_PSR_ADRSEL_TIM3_OC
464   *         @arg @ref ECU_PSR_ADRSEL_TIM4_OC
465   *         @arg @ref ECU_PSR_ADRSEL_TIM5_OC
466   *         @arg @ref ECU_PSR_ADRSEL_TIM6_OC
467   *         @arg @ref ECU_PSR_ADRSEL_TIM7_OC
468   * @return None
469   */
470 #define __LL_ECU_ADDR_FLAG_EVENT(__INSTANCE__, __EVENT__)       MODIFY_REG((__INSTANCE__)->PRC, ECU_PRC_ADRSEL, __EVENT__)
471 
472 /**
473   * @brief  Get the average effective value of the voltage
474   * @param  __INSTANCE__ Specifies ECU peripheral
475   * @return The result of the voltage
476   */
477 #define __LL_ECU_GET_VRMS(__INSTANCE__)                         READ_BIT((__INSTANCE__)->V, ECU_V_VRMS)
478 
479 /**
480   * @brief  Get the average effective value of the current
481   * @param  __INSTANCE__ Specifies ECU peripheral
482   * @return The result of the current
483   */
484 #define __LL_ECU_GET_IRMS(__INSTANCE__)                         READ_BIT((__INSTANCE__)->I, ECU_I_IRMS)
485 
486 /**
487   * @brief  Get the average active power
488   * @param  __INSTANCE__ Specifies ECU peripheral
489   * @return The result of average active power
490   */
491 #define __LL_ECU_P_PAVG(__INSTANCE__)                           READ_REG((__INSTANCE__)->P)
492 
493 /**
494   * @brief  Get the average reactive power
495   * @param  __INSTANCE__ Specifies ECU peripheral
496   * @return The result of average reactive power
497   */
498 #define __LL_ECU_Q_QAVG(__INSTANCE__)                           READ_REG((__INSTANCE__)->Q)
499 
500 /**
501   * @brief  Get the apparent power value
502   * @param  __INSTANCE__ Specifies ECU peripheral
503   * @return The result of apparent power
504   */
505 #define __LL_ECU_S_SCAL(__INSTANCE__)                           READ_REG((__INSTANCE__)->S)
506 
507 /**
508   * @brief  Get the power factor value
509   * @param  __INSTANCE__ Specifies ECU peripheral
510   * @return The result of power factor
511   */
512 #define __LL_ECU_PF_PFCAL(__INSTANCE__)                         READ_REG((__INSTANCE__)->PF)
513 
514 /**
515   * @brief  Get the fundamental frequency value
516   * @param  __INSTANCE__ Specifies ECU peripheral
517   * @return The result of fundamental frequency
518   */
519 #define __LL_ECU_F_FCNT(__INSTANCE__)                           READ_BIT((__INSTANCE__)->F, ECU_F_FCNT)
520 
521 /**
522   * @}
523   */
524 
525 
526 /* Exported functions --------------------------------------------------------*/
527 /** @addtogroup ECU_LL_Exported_Functions
528   * @{
529   */
530 
531 /** @addtogroup ECU_LL_Exported_Functions_Group1
532   * @{
533   */
534 LL_StatusETypeDef LL_ECU_Init(ECU_TypeDef *Instance, ECU_InitTypeDef *ECU_Init);
535 LL_StatusETypeDef LL_ECU_DeInit(ECU_TypeDef *Instance);
536 void LL_ECU_MspInit(ECU_TypeDef *Instance);
537 void LL_ECU_MspDeInit(ECU_TypeDef *Instance);
538 /**
539   * @}
540   */
541 
542 /** @addtogroup ECU_LL_Exported_Functions_Group2
543   * @{
544   */
545 void LL_ECU_WriteSqrtInData(ECU_TypeDef *Instance, uint32_t SqrtValue);
546 uint32_t LL_ECU_ReadSqrtOutData(ECU_TypeDef *Instance);
547 /**
548   * @}
549   */
550 
551 /** @addtogroup ECU_LL_Exported_Functions_Interrupt
552   * @{
553   */
554 void LL_ECU_IRQHandler(ECU_TypeDef *Instance);
555 void LL_ECU_CalDoneCallback(ECU_TypeDef *Instance);
556 /**
557   * @}
558   */
559 
560 /**
561   * @}
562   */
563 
564 
565 /* Private types -------------------------------------------------------------*/
566 /* Private variables ---------------------------------------------------------*/
567 /* Private constants ---------------------------------------------------------*/
568 /* Private macros ------------------------------------------------------------*/
569 /** @defgroup ECU_LL_Private_Macros ECU LL Private Macros
570   * @brief    ECU LL Private Macros
571   * @{
572   */
573 
574 /**
575   * @brief  Judge is ECU enable/disable mode or not
576   * @param  __MODE__ mode to judge
577   * @retval 0 isn't ECU enable/disable mode
578   * @retval 1 is ECU enable/disable mode
579   */
580 #define IS_ECU_MODULE(__MODE__)                            \
581     (   ((__MODE__) == ECU_DISABLE)                        \
582         || ((__MODE__) == ECU_ENABLE)                      \
583     )
584 
585 /**
586   * @brief  Judge is ECU average or not
587   * @param  __AVERAGE__ average to judge
588   * @retval 0 isn't ECU average
589   * @retval 1 is ECU average
590   */
591 #define IS_ECU_AVERAGE(__AVERAGE__)                        \
592     (   ((__AVERAGE__) == ECU_AVERAGE_DISABLE)             \
593         || ((__AVERAGE__) == ECU_AVERAGE_2PERIOD)          \
594         || ((__AVERAGE__) == ECU_AVERAGE_4PERIOD)          \
595         || ((__AVERAGE__) == ECU_AVERAGE_8PERIOD)          \
596     )
597 
598 /**
599   * @brief  Judge is ECU acsft or not
600   * @param  __ACSFT__ acsft to judge
601   * @retval 0 isn't ECU acsft
602   * @retval 1 is ECU acsft
603   */
604 #define IS_ECU_ACSFT(__ACSFT__)                            \
605     (   ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_DISABLE)    \
606         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_1)       \
607         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_2)       \
608         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_3)       \
609         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_4)       \
610         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_5)       \
611         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_6)       \
612         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_7)       \
613         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_8)       \
614         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_9)       \
615         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_10)      \
616         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_11)      \
617         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_12)      \
618         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_13)      \
619         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_14)      \
620         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_15)      \
621         || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_16)      \
622     )
623 
624 /**
625   * @brief  Judge is ECU apsft or not
626   * @param  __APSFT__ apsft to judge
627   * @retval 0 isn't ECU apsft
628   * @retval 1 is ECU apsft
629   */
630 #define IS_ECU_APSFT(__APSFT__)                            \
631     (   ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_DISABLE)   \
632         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_1)      \
633         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_2)      \
634         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_3)      \
635         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_4)      \
636         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_5)      \
637         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_6)      \
638         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_7)      \
639         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_8)      \
640         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_9)      \
641         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_10)     \
642         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_11)     \
643         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_12)     \
644         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_13)     \
645         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_14)     \
646         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_15)     \
647         || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_16)     \
648     )
649 
650 /**
651   * @brief  Judge is ECU datsel or not
652   * @param  __DATSEL__ datsel to judge
653   * @retval 0 isn't ECU datsel
654   * @retval 1 is ECU datsel
655   */
656 #define IS_ECU_DATSEL(__DATSEL__)                          \
657     (   ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG0)      \
658         || ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG1)   \
659         || ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG2)   \
660         || ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG3)   \
661         || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG0)   \
662         || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG1)   \
663         || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG2)   \
664         || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG3)   \
665         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM0_OC)        \
666         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM1_OC)        \
667         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM2_OC)        \
668         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM3_OC)        \
669         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM4_OC)        \
670         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM5_OC)        \
671         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM6_OC)        \
672         || ((__DATSEL__) == ECU_PSR_DATSEL_TIM7_OC)        \
673     )
674 
675 /**
676   * @brief  Judge is ECU crssel or not
677   * @param  __CRSSEL__ crssel to judge
678   * @retval 0 isn't ECU crssel
679   * @retval 1 is ECU crssel
680   */
681 #define IS_ECU_CRSSEL(__CRSSEL__)                          \
682     (   ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG0)      \
683         || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG1)   \
684         || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG2)   \
685         || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG3)   \
686         || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG0)   \
687         || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG1)   \
688         || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG2)   \
689         || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG3)   \
690         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM0_OC)        \
691         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM1_OC)        \
692         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM2_OC)        \
693         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM3_OC)        \
694         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM4_OC)        \
695         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM5_OC)        \
696         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM6_OC)        \
697         || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM7_OC)        \
698     )
699 
700 /**
701   * @}
702   */
703 
704 
705 /* Private functions ---------------------------------------------------------*/
706 
707 
708 /**
709   * @}
710   */
711 
712 /**
713   * @}
714   */
715 
716 
717 #ifdef __cplusplus
718 }
719 #endif /* __cplusplus */
720 
721 
722 #endif /* _TAE32F53XX_LL_ECU_H_ */
723 
724 
725 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/
726 
727