/** ****************************************************************************** * @file tae32f53xx_ll_ecu.h * @author MCD Application Team * @brief Header file of ECU LL module * ****************************************************************************** * @attention * *

© Copyright (c) 2020 Tai-Action. * All rights reserved.

* * This software is licensed by Tai-Action under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef _TAE32F53XX_LL_ECU_H_ #define _TAE32F53XX_LL_ECU_H_ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /* Includes ------------------------------------------------------------------*/ #include "tae32f53xx_ll_def.h" /** @addtogroup TAE32F53xx_LL_Driver * @{ */ /** @addtogroup ECU_LL * @{ */ /* Exported constants --------------------------------------------------------*/ /** @defgroup ECU_LL_Exported_Constants ECU LL Exported Constants * @brief ECU LL Exported Constants * @{ */ /** @defgroup LL_ECU_ENABLE ECU enable define * @brief ECU Enable Bit Set and Bit Reset * @{ */ #define ECU_DISABLE (0x00000000U) /*!ADDR_DATA_FLAG */ ECU_PSR_DATSEL_ADC0_DTFLAG0 = 0x0, /*!ADDR_DATA_FLAG */ ECU_PSR_DATSEL_ADC0_DTFLAG1 = ECU_PRC_DATSEL_0, /*!ADDR_DATA_FLAG */ ECU_PSR_DATSEL_ADC0_DTFLAG2 = ECU_PRC_DATSEL_1, /*!ADDR_DATA_FLAG */ ECU_PSR_DATSEL_ADC0_DTFLAG3 = ECU_PRC_DATSEL_1 | ECU_PRC_DATSEL_0, /*!ADDR_DATA_FLAG */ ECU_PSR_DATSEL_ADC1_DTFLAG0 = ECU_PRC_DATSEL_2, /*!ADDR_DATA_FLAG */ ECU_PSR_DATSEL_ADC1_DTFLAG1 = ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_0, /*!ADDR_DATA_FLAG */ ECU_PSR_DATSEL_ADC1_DTFLAG2 = ECU_PRC_DATSEL_2 | ECU_PRC_DATSEL_1, /*!ADDR_DATA_FLAG */ ECU_P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PFLAG1 = ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_0, /*!PSRCU/PSRCD */ ECU_PSR_CRSSEL_ADC1_PPFLAG2 = ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_1, /*!PSRCU/PSRCD */ ECU_PSR_CRSSEL_ADC1_PPFLAG3 = ECU_PRC_CRSSEL_2 | ECU_PRC_CRSSEL_1 | ECU_PRC_CRSSEL_0, /*!CON, ECU_CON_ENABLE) /** * @brief Disable the ECU module. * @param __INSTANCE__ Specifies ECU peripheral * @return None */ #define __LL_ECU_MODULE_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CON, ECU_CON_ENABLE) /** * @brief Get the ECU module states. * @param __INSTANCE__ Specifies ECU peripheral * @return ENABLE : the module is enable * DISABLE : the module is disable */ #define __LL_ECU_GET_STA(__INSTANCE__) ((((__INSTANCE__)->CON & (ECU_CON_ENABLE)) == 0x1UL) ? ENABLE : DISABLE) /** * @brief Enable the specified ECU Calculate complete interrupt. * @param __INSTANCE__ Specifies ECU peripheral * @return None */ #define __LL_ECU_DONE_IT_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CON, ECU_CON_INTEN) /** * @brief Disable the specified ECU Calculate complete interrupt. * @param __INSTANCE__ Specifies ECU peripheral * @return None */ #define __LL_ECU_DONE_IT_DISABLE(__INSTANCE__) CLEAR_BIT((__INSTANCE__)->CON, ECU_CON_INTEN) /** * @brief Check the ECU Calculate complete interrupts are enabled or disable. * @param __INSTANCE__ Specifies ECU peripheral * @return SET : the interrupt is enable * RESET : the interrupt is disable */ #define __LL_ECU_DONE_GET_IT(__INSTANCE__) ((((__INSTANCE__)->CON & (ECU_CON_INTEN)) == 0x02UL) ? SET : RESET) /** * @brief Check whether the specified ECU Calculate complete pending flag is set or not. * @param __INSTANCE__ Specifies ECU peripheral * @return SET : the interrupt flag is set * RESET : the interrupt flag is reset */ #define __LL_ECU_DONE_GET_FLAG(__INSTANCE__) ((((__INSTANCE__)->CON & (ECU_CON_INT)) == 0x8000UL) ? SET : RESET) /** * @brief Clear the specified ECU Calculate complete pending flags. * @param __INSTANCE__ Specifies ECU peripheral * @return None */ #define __LL_ECU_DONE_CLEAR_FLAG(__INSTANCE__) SET_BIT((__INSTANCE__)->CON, ECU_CON_INT) /** * @brief Input data square enable, after the completion of the calculation automatically reset * @param __INSTANCE__ Specifies ECU peripheral * @return None */ #define __LL_ECU_SQRT_ENABLE(__INSTANCE__) SET_BIT((__INSTANCE__)->CON, ECU_CON_SQRT) /** * @brief Gets the square root completion flag * @param __INSTANCE__ Specifies ECU peripheral * @return RESET That means the square root is complete * SET That means the square root is not complete */ #define __LL_ECU_SQRT_DONE_FLAG(__INSTANCE__) ((((__INSTANCE__)->CON & (ECU_CON_SQRT)) == 0x4000UL) ? SET : RESET) /** * @brief Sets the zero crossing event that needs to be selected * @param __INSTANCE__ Specifies ECU peripheral * @param __EVENT__ cross zero event as follow: * @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAF0 * @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAG1 * @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAG2 * @arg @ref ECU_PSR_CRSSEL_ADC0_PPFLAG3 * @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG0 * @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG1 * @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG2 * @arg @ref ECU_PSR_CRSSEL_ADC1_PPFLAG3 * @arg @ref ECU_PSR_CRSSEL_TIM0_OC * @arg @ref ECU_PSR_CRSSEL_TIM1_OC * @arg @ref ECU_PSR_CRSSEL_TIM2_OC * @arg @ref ECU_PSR_CRSSEL_TIM3_OC * @arg @ref ECU_PSR_CRSSEL_TIM4_OC * @arg @ref ECU_PSR_CRSSEL_TIM5_OC * @arg @ref ECU_PSR_CRSSEL_TIM6_OC * @arg @ref ECU_PSR_CRSSEL_TIM7_OC * @return None */ #define __LL_ECU_CROSS_ZERO_EVENT(__INSTANCE__, __EVENT__) MODIFY_REG((__INSTANCE__)->PRC, ECU_PRC_CRSSEL, __EVENT__) /** * @brief Sets the data event that needs to be selected * @param __INSTANCE__ Specifies ECU peripheral * @param __EVENT__ cross zero event as follow: * @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAF0 * @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAG1 * @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAG2 * @arg @ref ECU_PSR_DATSEL_ADC0_PPFLAG3 * @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG0 * @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG1 * @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG2 * @arg @ref ECU_PSR_DATSEL_ADC1_PPFLAG3 * @arg @ref ECU_PSR_DATSEL_TIM0_OC * @arg @ref ECU_PSR_DATSEL_TIM1_OC * @arg @ref ECU_PSR_DATSEL_TIM2_OC * @arg @ref ECU_PSR_DATSEL_TIM3_OC * @arg @ref ECU_PSR_DATSEL_TIM4_OC * @arg @ref ECU_PSR_DATSEL_TIM5_OC * @arg @ref ECU_PSR_DATSEL_TIM6_OC * @arg @ref ECU_PSR_DATSEL_TIM7_OC * @return None */ #define __LL_ECU_DATA_FLAG_EVENT(__INSTANCE__, __EVENT__) MODIFY_REG((__INSTANCE__)->PRC, ECU_PRC_DATSEL, __EVENT__) /** * @brief Sets the addr_data flag event that needs to be selected * @param __INSTANCE__ Specifies ECU peripheral * @param __EVENT__ cross zero event as follow: * @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAF0 * @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAG1 * @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAG2 * @arg @ref ECU_PSR_ADRSEL_ADC0_PPFLAG3 * @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG0 * @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG1 * @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG2 * @arg @ref ECU_PSR_ADRSEL_ADC1_PPFLAG3 * @arg @ref ECU_PSR_ADRSEL_TIM0_OC * @arg @ref ECU_PSR_ADRSEL_TIM1_OC * @arg @ref ECU_PSR_ADRSEL_TIM2_OC * @arg @ref ECU_PSR_ADRSEL_TIM3_OC * @arg @ref ECU_PSR_ADRSEL_TIM4_OC * @arg @ref ECU_PSR_ADRSEL_TIM5_OC * @arg @ref ECU_PSR_ADRSEL_TIM6_OC * @arg @ref ECU_PSR_ADRSEL_TIM7_OC * @return None */ #define __LL_ECU_ADDR_FLAG_EVENT(__INSTANCE__, __EVENT__) MODIFY_REG((__INSTANCE__)->PRC, ECU_PRC_ADRSEL, __EVENT__) /** * @brief Get the average effective value of the voltage * @param __INSTANCE__ Specifies ECU peripheral * @return The result of the voltage */ #define __LL_ECU_GET_VRMS(__INSTANCE__) READ_BIT((__INSTANCE__)->V, ECU_V_VRMS) /** * @brief Get the average effective value of the current * @param __INSTANCE__ Specifies ECU peripheral * @return The result of the current */ #define __LL_ECU_GET_IRMS(__INSTANCE__) READ_BIT((__INSTANCE__)->I, ECU_I_IRMS) /** * @brief Get the average active power * @param __INSTANCE__ Specifies ECU peripheral * @return The result of average active power */ #define __LL_ECU_P_PAVG(__INSTANCE__) READ_REG((__INSTANCE__)->P) /** * @brief Get the average reactive power * @param __INSTANCE__ Specifies ECU peripheral * @return The result of average reactive power */ #define __LL_ECU_Q_QAVG(__INSTANCE__) READ_REG((__INSTANCE__)->Q) /** * @brief Get the apparent power value * @param __INSTANCE__ Specifies ECU peripheral * @return The result of apparent power */ #define __LL_ECU_S_SCAL(__INSTANCE__) READ_REG((__INSTANCE__)->S) /** * @brief Get the power factor value * @param __INSTANCE__ Specifies ECU peripheral * @return The result of power factor */ #define __LL_ECU_PF_PFCAL(__INSTANCE__) READ_REG((__INSTANCE__)->PF) /** * @brief Get the fundamental frequency value * @param __INSTANCE__ Specifies ECU peripheral * @return The result of fundamental frequency */ #define __LL_ECU_F_FCNT(__INSTANCE__) READ_BIT((__INSTANCE__)->F, ECU_F_FCNT) /** * @} */ /* Exported functions --------------------------------------------------------*/ /** @addtogroup ECU_LL_Exported_Functions * @{ */ /** @addtogroup ECU_LL_Exported_Functions_Group1 * @{ */ LL_StatusETypeDef LL_ECU_Init(ECU_TypeDef *Instance, ECU_InitTypeDef *ECU_Init); LL_StatusETypeDef LL_ECU_DeInit(ECU_TypeDef *Instance); void LL_ECU_MspInit(ECU_TypeDef *Instance); void LL_ECU_MspDeInit(ECU_TypeDef *Instance); /** * @} */ /** @addtogroup ECU_LL_Exported_Functions_Group2 * @{ */ void LL_ECU_WriteSqrtInData(ECU_TypeDef *Instance, uint32_t SqrtValue); uint32_t LL_ECU_ReadSqrtOutData(ECU_TypeDef *Instance); /** * @} */ /** @addtogroup ECU_LL_Exported_Functions_Interrupt * @{ */ void LL_ECU_IRQHandler(ECU_TypeDef *Instance); void LL_ECU_CalDoneCallback(ECU_TypeDef *Instance); /** * @} */ /** * @} */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @defgroup ECU_LL_Private_Macros ECU LL Private Macros * @brief ECU LL Private Macros * @{ */ /** * @brief Judge is ECU enable/disable mode or not * @param __MODE__ mode to judge * @retval 0 isn't ECU enable/disable mode * @retval 1 is ECU enable/disable mode */ #define IS_ECU_MODULE(__MODE__) \ ( ((__MODE__) == ECU_DISABLE) \ || ((__MODE__) == ECU_ENABLE) \ ) /** * @brief Judge is ECU average or not * @param __AVERAGE__ average to judge * @retval 0 isn't ECU average * @retval 1 is ECU average */ #define IS_ECU_AVERAGE(__AVERAGE__) \ ( ((__AVERAGE__) == ECU_AVERAGE_DISABLE) \ || ((__AVERAGE__) == ECU_AVERAGE_2PERIOD) \ || ((__AVERAGE__) == ECU_AVERAGE_4PERIOD) \ || ((__AVERAGE__) == ECU_AVERAGE_8PERIOD) \ ) /** * @brief Judge is ECU acsft or not * @param __ACSFT__ acsft to judge * @retval 0 isn't ECU acsft * @retval 1 is ECU acsft */ #define IS_ECU_ACSFT(__ACSFT__) \ ( ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_DISABLE) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_1) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_2) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_3) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_4) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_5) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_6) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_7) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_8) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_9) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_10) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_11) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_12) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_13) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_14) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_15) \ || ((__ACSFT__) == ECU_ACPOWER_LEFT_SHIFT_16) \ ) /** * @brief Judge is ECU apsft or not * @param __APSFT__ apsft to judge * @retval 0 isn't ECU apsft * @retval 1 is ECU apsft */ #define IS_ECU_APSFT(__APSFT__) \ ( ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_DISABLE) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_1) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_2) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_3) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_4) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_5) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_6) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_7) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_8) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_9) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_10) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_11) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_12) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_13) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_14) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_15) \ || ((__APSFT__) == ECU_APPOWER_RIGHT_SHIFT_16) \ ) /** * @brief Judge is ECU datsel or not * @param __DATSEL__ datsel to judge * @retval 0 isn't ECU datsel * @retval 1 is ECU datsel */ #define IS_ECU_DATSEL(__DATSEL__) \ ( ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG0) \ || ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG1) \ || ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG2) \ || ((__DATSEL__) == ECU_PSR_DATSEL_ADC0_DTFLAG3) \ || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG0) \ || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG1) \ || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG2) \ || ((__DATSEL__) == ECU_PSR_DATSEL_ADC1_DTFLAG3) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM0_OC) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM1_OC) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM2_OC) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM3_OC) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM4_OC) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM5_OC) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM6_OC) \ || ((__DATSEL__) == ECU_PSR_DATSEL_TIM7_OC) \ ) /** * @brief Judge is ECU crssel or not * @param __CRSSEL__ crssel to judge * @retval 0 isn't ECU crssel * @retval 1 is ECU crssel */ #define IS_ECU_CRSSEL(__CRSSEL__) \ ( ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG0) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG1) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG2) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC0_PPFLAG3) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG0) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG1) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG2) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_ADC1_PPFLAG3) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM0_OC) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM1_OC) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM2_OC) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM3_OC) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM4_OC) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM5_OC) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM6_OC) \ || ((__CRSSEL__) == ECU_PSR_CRSSEL_TIM7_OC) \ ) /** * @} */ /* Private functions ---------------------------------------------------------*/ /** * @} */ /** * @} */ #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* _TAE32F53XX_LL_ECU_H_ */ /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/