]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Nuvoton_Code/StdDriver/src/bpwm.c
Add Cortex M23 GCC and IAR ports. Add demo projects for Nuvoton NuMaker-PFM-2351.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC / Nuvoton_Code / StdDriver / src / bpwm.c
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Nuvoton_Code/StdDriver/src/bpwm.c b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Nuvoton_Code/StdDriver/src/bpwm.c
new file mode 100644 (file)
index 0000000..4399e23
--- /dev/null
@@ -0,0 +1,694 @@
+/**************************************************************************//**\r
+ * @file     bpwm.c\r
+ * @version  V1.00\r
+ * @brief    M2351 series BPWM driver source file\r
+ *\r
+ * @note\r
+ * Copyright (C) 2017 Nuvoton Technology Corp. All rights reserved.\r
+*****************************************************************************/\r
+#include "NuMicro.h"\r
+\r
+/** @addtogroup Standard_Driver Standard Driver\r
+  @{\r
+*/\r
+\r
+/** @addtogroup BPWM_Driver BPWM Driver\r
+  @{\r
+*/\r
+\r
+\r
+/** @addtogroup BPWM_EXPORTED_FUNCTIONS BPWM Exported Functions\r
+  @{\r
+*/\r
+\r
+/**\r
+ * @brief Configure BPWM capture and get the nearest unit time.\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32UnitTimeNsec The unit time of counter\r
+ * @param[in] u32CaptureEdge The condition to latch the counter. This parameter is not used\r
+ * @return The nearest unit time in nano second.\r
+ * @details This function is used to Configure BPWM capture and get the nearest unit time.\r
+ */\r
+uint32_t BPWM_ConfigCaptureChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32UnitTimeNsec, uint32_t u32CaptureEdge)\r
+{\r
+    uint32_t u32PWMClockSrc;\r
+    uint32_t u32NearestUnitTimeNsec;\r
+    uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;\r
+    uint8_t u8BreakLoop = 0U;\r
+\r
+    /* clock source is from PCLK */\r
+    if((((uint32_t)bpwm) == BPWM0_BASE) || (((uint32_t)bpwm) == BPWM0_BASE + NS_OFFSET))\r
+    {\r
+        u32PWMClockSrc = CLK_GetPCLK0Freq();\r
+    }\r
+    else/* if((bpwm == BPWM1)||(bpwm == BPWM1_NS)) */\r
+    {\r
+        u32PWMClockSrc = CLK_GetPCLK1Freq();\r
+    }\r
+\r
+    u32PWMClockSrc /= 1000UL;\r
+    for(u32Prescale = 1U; u32Prescale <= 0x1000UL; u32Prescale++)\r
+    {\r
+        u32NearestUnitTimeNsec = (1000000UL * u32Prescale) / u32PWMClockSrc;\r
+        if(u32NearestUnitTimeNsec < u32UnitTimeNsec)\r
+        {\r
+            if(u32Prescale == 0x1000U)\r
+            {\r
+                /* limit to the maximum unit time(nano second) */\r
+                u8BreakLoop = 1U;\r
+            }\r
+            if(!((1000000UL * (u32Prescale + 1UL) > (u32NearestUnitTimeNsec * u32PWMClockSrc))))\r
+            {\r
+                u8BreakLoop = 1U;\r
+            }\r
+        }\r
+        else\r
+        {\r
+            u8BreakLoop = 1U;\r
+        }\r
+        if(u8BreakLoop)\r
+        {\r
+            break;\r
+        }\r
+    }\r
+\r
+    /* convert to real register value */\r
+    u32Prescale = u32Prescale - 1U;\r
+    /* all channels share a prescaler */\r
+    BPWM_SET_PRESCALER(bpwm, u32ChannelNum, u32Prescale);\r
+\r
+    /* set BPWM to down count type(edge aligned) */\r
+    (bpwm)->CTL1 = (1UL);\r
+\r
+    BPWM_SET_CNR(bpwm, u32ChannelNum, u32CNR);\r
+\r
+    return (u32NearestUnitTimeNsec);\r
+}\r
+\r
+/**\r
+ * @brief This function Configure BPWM generator and get the nearest frequency in edge aligned(up counter type) auto-reload mode\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32Frequency Target generator frequency\r
+ * @param[in] u32DutyCycle Target generator duty cycle percentage. Valid range are between 0 ~ 100. 10 means 10%, 20 means 20%...\r
+ * @return Nearest frequency clock in nano second\r
+ * @note Since all channels shares a prescaler. Call this API to configure BPWM frequency may affect\r
+ *       existing frequency of other channel.\r
+ * @note This function is used for initial stage.\r
+ *       To change duty cycle later, it should get the configured period value and calculate the new comparator value.\r
+ */\r
+uint32_t BPWM_ConfigOutputChannel(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Frequency, uint32_t u32DutyCycle)\r
+{\r
+    uint32_t u32PWMClockSrc;\r
+    uint32_t i;\r
+    uint32_t u32Prescale = 1U, u32CNR = 0xFFFFU;\r
+\r
+    /* clock source is from PCLK */\r
+    if(((uint32_t)bpwm == BPWM0_BASE) || ((uint32_t)bpwm == BPWM0_BASE + NS_OFFSET))\r
+    {\r
+        u32PWMClockSrc = CLK_GetPCLK0Freq();\r
+    }\r
+    else/* if((bpwm == BPWM1)||(bpwm == BPWM1_NS)) */\r
+    {\r
+        u32PWMClockSrc = CLK_GetPCLK1Freq();\r
+    }\r
+\r
+    for(u32Prescale = 1U; u32Prescale < 0xFFFU; u32Prescale++)/* prescale could be 0~0xFFF */\r
+    {\r
+        i = (u32PWMClockSrc / u32Frequency) / u32Prescale;\r
+        /* If target value is larger than CNR, need to use a larger prescaler */\r
+        if(i <= (0x10000U))\r
+        {\r
+            u32CNR = i;\r
+            break;\r
+        }\r
+    }\r
+    /* Store return value here 'cos we're gonna change u32Prescale & u32CNR to the real value to fill into register */\r
+    i = u32PWMClockSrc / (u32Prescale * u32CNR);\r
+\r
+    /* convert to real register value */\r
+    u32Prescale = u32Prescale - 1U;\r
+    /* all channels share a prescaler */\r
+    BPWM_SET_PRESCALER(bpwm, u32ChannelNum, u32Prescale);\r
+    /* set BPWM to up counter type(edge aligned) */\r
+    (bpwm)->CTL1 = BPWM_UP_COUNTER;\r
+\r
+    u32CNR = u32CNR - 1U;\r
+    BPWM_SET_CNR(bpwm, u32ChannelNum, u32CNR);\r
+    BPWM_SET_CMR(bpwm, u32ChannelNum, u32DutyCycle * (u32CNR + 1UL) / 100UL);\r
+\r
+\r
+    (bpwm)->WGCTL0 = ((bpwm)->WGCTL0 & ~((BPWM_WGCTL0_PRDPCTL0_Msk | BPWM_WGCTL0_ZPCTL0_Msk) << (u32ChannelNum << 1))) | \\r
+                     (BPWM_OUTPUT_HIGH << (u32ChannelNum << 1UL << BPWM_WGCTL0_ZPCTL0_Pos));\r
+    (bpwm)->WGCTL1 = ((bpwm)->WGCTL1 & ~((BPWM_WGCTL1_CMPDCTL0_Msk | BPWM_WGCTL1_CMPUCTL0_Msk) << (u32ChannelNum << 1))) | \\r
+                     (BPWM_OUTPUT_LOW << (u32ChannelNum << 1UL << BPWM_WGCTL1_CMPUCTL0_Pos));\r
+\r
+    return(i);\r
+}\r
+\r
+/**\r
+ * @brief Start BPWM module\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelMask Combination of enabled channels. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to start BPWM module.\r
+ * @note All channels share one counter.\r
+ */\r
+void BPWM_Start(BPWM_T *bpwm, uint32_t u32ChannelMask)\r
+{\r
+    (bpwm)->CNTEN = BPWM_CNTEN_CNTEN0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Stop BPWM module\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelMask Combination of enabled channels. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to stop BPWM module.\r
+ * @note All channels share one period.\r
+ */\r
+void BPWM_Stop(BPWM_T *bpwm, uint32_t u32ChannelMask)\r
+{\r
+    (bpwm)->PERIOD = 0UL;\r
+}\r
+\r
+/**\r
+ * @brief Stop BPWM generation immediately by clear channel enable bit\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelMask Combination of enabled channels. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to stop BPWM generation immediately by clear channel enable bit.\r
+ * @note All channels share one counter.\r
+ */\r
+void BPWM_ForceStop(BPWM_T *bpwm, uint32_t u32ChannelMask)\r
+{\r
+    (bpwm)->CNTEN &= ~BPWM_CNTEN_CNTEN0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Enable selected channel to trigger ADC\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32Condition The condition to trigger ADC. Combination of following conditions:\r
+ *                  - \ref BPWM_TRIGGER_ADC_EVEN_ZERO_POINT\r
+ *                  - \ref BPWM_TRIGGER_ADC_EVEN_PERIOD_POINT\r
+ *                  - \ref BPWM_TRIGGER_ADC_EVEN_ZERO_OR_PERIOD_POINT\r
+ *                  - \ref BPWM_TRIGGER_ADC_EVEN_CMP_UP_COUNT_POINT\r
+ *                  - \ref BPWM_TRIGGER_ADC_EVEN_CMP_DOWN_COUNT_POINT\r
+ *                  - \ref BPWM_TRIGGER_ADC_ODD_CMP_UP_COUNT_POINT\r
+ *                  - \ref BPWM_TRIGGER_ADC_ODD_CMP_DOWN_COUNT_POINT\r
+ * @return None\r
+ * @details This function is used to enable selected channel to trigger ADC\r
+ */\r
+void BPWM_EnableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)\r
+{\r
+    if(u32ChannelNum < 4UL)\r
+    {\r
+        (bpwm)->EADCTS0 &= ~((BPWM_EADCTS0_TRGSEL0_Msk) << (u32ChannelNum << 3));\r
+        (bpwm)->EADCTS0 |= ((BPWM_EADCTS0_TRGEN0_Msk | u32Condition) << (u32ChannelNum << 3));\r
+    }\r
+    else\r
+    {\r
+        (bpwm)->EADCTS1 &= ~((BPWM_EADCTS1_TRGSEL4_Msk) << ((u32ChannelNum - 4UL) << 3));\r
+        (bpwm)->EADCTS1 |= ((BPWM_EADCTS1_TRGEN4_Msk | u32Condition) << ((u32ChannelNum - 4UL) << 3));\r
+    }\r
+}\r
+\r
+/**\r
+ * @brief Disable selected channel to trigger ADC\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~3\r
+ * @return None\r
+ * @details This function is used to disable selected channel to trigger ADC\r
+ */\r
+void BPWM_DisableADCTrigger(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    if(u32ChannelNum < 4UL)\r
+    {\r
+        (bpwm)->EADCTS0 &= ~(BPWM_EADCTS0_TRGEN0_Msk << (u32ChannelNum << 3));\r
+    }\r
+    else\r
+    {\r
+        (bpwm)->EADCTS1 &= ~(BPWM_EADCTS1_TRGEN4_Msk << ((u32ChannelNum - 4UL) << 3));\r
+    }\r
+}\r
+\r
+/**\r
+ * @brief Clear selected channel trigger ADC flag\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32Condition This parameter is not used\r
+ * @return None\r
+ * @details This function is used to clear selected channel trigger ADC flag\r
+ */\r
+void BPWM_ClearADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Condition)\r
+{\r
+    (bpwm)->STATUS = (BPWM_STATUS_EADCTRG0_Msk << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Get selected channel trigger ADC flag\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @retval 0 The specified channel trigger ADC to start of conversion flag is not set\r
+ * @retval 1 The specified channel trigger ADC to start of conversion flag is set\r
+ * @details This function is used to get BPWM trigger ADC to start of conversion flag for specified channel\r
+ */\r
+uint32_t BPWM_GetADCTriggerFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    return (((bpwm)->STATUS & (BPWM_STATUS_EADCTRG0_Msk << u32ChannelNum)) ? 1UL : 0UL);\r
+}\r
+\r
+/**\r
+ * @brief Enable capture of selected channel(s)\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.\r
+ *                           Bit 0 is channel 0, bit 1 is channel 1...\r
+ * @return None\r
+ * @details This function is used to enable capture of selected channel(s)\r
+ */\r
+void BPWM_EnableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)\r
+{\r
+    (bpwm)->CAPINEN |= u32ChannelMask;\r
+    (bpwm)->CAPCTL |= u32ChannelMask;\r
+}\r
+\r
+/**\r
+ * @brief Disable capture of selected channel(s)\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.\r
+ *                           Bit 0 is channel 0, bit 1 is channel 1...\r
+ * @return None\r
+ * @details This function is used to disable capture of selected channel(s)\r
+ */\r
+void BPWM_DisableCapture(BPWM_T *bpwm, uint32_t u32ChannelMask)\r
+{\r
+    (bpwm)->CAPINEN &= ~u32ChannelMask;\r
+    (bpwm)->CAPCTL &= ~u32ChannelMask;\r
+}\r
+\r
+/**\r
+ * @brief Enables BPWM output generation of selected channel(s)\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel.\r
+ *                           Set bit 0 to 1 enables channel 0 output, set bit 1 to 1 enables channel 1 output...\r
+ * @return None\r
+ * @details This function is used to enables BPWM output generation of selected channel(s)\r
+ */\r
+void BPWM_EnableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)\r
+{\r
+    (bpwm)->POEN |= u32ChannelMask;\r
+}\r
+\r
+/**\r
+ * @brief Disables BPWM output generation of selected channel(s)\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelMask Combination of enabled channels. Each bit corresponds to a channel\r
+ *                           Set bit 0 to 1 disables channel 0 output, set bit 1 to 1 disables channel 1 output...\r
+ * @return None\r
+ * @details This function is used to disables BPWM output generation of selected channel(s)\r
+ */\r
+void BPWM_DisableOutput(BPWM_T *bpwm, uint32_t u32ChannelMask)\r
+{\r
+    (bpwm)->POEN &= ~u32ChannelMask;\r
+}\r
+\r
+/**\r
+ * @brief Enable capture interrupt of selected channel.\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32Edge Rising or falling edge to latch counter.\r
+ *              - \ref BPWM_CAPTURE_INT_RISING_LATCH\r
+ *              - \ref BPWM_CAPTURE_INT_FALLING_LATCH\r
+ * @return None\r
+ * @details This function is used to enable capture interrupt of selected channel.\r
+ */\r
+void BPWM_EnableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)\r
+{\r
+    (bpwm)->CAPIEN |= (u32Edge << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Disable capture interrupt of selected channel.\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32Edge Rising or falling edge to latch counter.\r
+ *              - \ref BPWM_CAPTURE_INT_RISING_LATCH\r
+ *              - \ref BPWM_CAPTURE_INT_FALLING_LATCH\r
+ * @return None\r
+ * @details This function is used to disable capture interrupt of selected channel.\r
+ */\r
+void BPWM_DisableCaptureInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)\r
+{\r
+    (bpwm)->CAPIEN &= ~(u32Edge << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Clear capture interrupt of selected channel.\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32Edge Rising or falling edge to latch counter.\r
+ *              - \ref BPWM_CAPTURE_INT_RISING_LATCH\r
+ *              - \ref BPWM_CAPTURE_INT_FALLING_LATCH\r
+ * @return None\r
+ * @details This function is used to clear capture interrupt of selected channel.\r
+ */\r
+void BPWM_ClearCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32Edge)\r
+{\r
+    (bpwm)->CAPIF = (u32Edge << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Get capture interrupt of selected channel.\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @retval 0 No capture interrupt\r
+ * @retval 1 Rising edge latch interrupt\r
+ * @retval 2 Falling edge latch interrupt\r
+ * @retval 3 Rising and falling latch interrupt\r
+ * @details This function is used to get capture interrupt of selected channel.\r
+ */\r
+uint32_t BPWM_GetCaptureIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    uint32_t u32CapIf = 0UL;\r
+\r
+    u32CapIf = ((((bpwm)->CAPIF & (BYTE1_Msk << u32ChannelNum)) ? 1UL : 0UL) << 1);\r
+    u32CapIf |= (((bpwm)->CAPIF & (BYTE0_Msk << u32ChannelNum)) ? 1UL : 0UL);\r
+    return u32CapIf;\r
+}\r
+/**\r
+ * @brief Enable duty interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32IntDutyType Duty interrupt type, could be either\r
+ *              - \ref BPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP\r
+ *              - \ref BPWM_DUTY_INT_UP_COUNT_MATCH_CMP\r
+ * @return None\r
+ * @details This function is used to enable duty interrupt of selected channel.\r
+ */\r
+void BPWM_EnableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32IntDutyType)\r
+{\r
+    (bpwm)->INTEN |= (u32IntDutyType << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Disable duty interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @return None\r
+ * @details This function is used to disable duty interrupt of selected channel\r
+ */\r
+void BPWM_DisableDutyInt(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->INTEN &= ~((BPWM_DUTY_INT_DOWN_COUNT_MATCH_CMP | BPWM_DUTY_INT_UP_COUNT_MATCH_CMP) << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Clear duty interrupt flag of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @return None\r
+ * @details This function is used to clear duty interrupt flag of selected channel\r
+ */\r
+void BPWM_ClearDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->INTSTS = (BYTE2_Msk | BYTE3_Msk) << u32ChannelNum;\r
+}\r
+\r
+/**\r
+ * @brief Get duty interrupt flag of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @return Duty interrupt flag of specified channel\r
+ * @retval 0 Duty interrupt did not occur\r
+ * @retval 1 Duty interrupt occurred\r
+ * @details This function is used to get duty interrupt flag of selected channel\r
+ */\r
+uint32_t BPWM_GetDutyIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    return ((((bpwm)->INTSTS & ((BYTE2_Msk | BYTE3_Msk) << u32ChannelNum))) ? 1UL : 0UL);\r
+}\r
+\r
+/**\r
+ * @brief Enable period interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @param[in] u32IntPeriodType Period interrupt type. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to enable period interrupt of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_EnablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum,  uint32_t u32IntPeriodType)\r
+{\r
+    (bpwm)->INTEN |= BPWM_INTEN_PIEN0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Disable period interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to disable period interrupt of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_DisablePeriodInt(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->INTEN &= ~BPWM_INTEN_PIEN0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Clear period interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to clear period interrupt of selected channel\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_ClearPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->INTSTS = BPWM_INTSTS_PIF0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Get period interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return Period interrupt flag of specified channel\r
+ * @retval 0 Period interrupt did not occur\r
+ * @retval 1 Period interrupt occurred\r
+ * @details This function is used to get period interrupt of selected channel\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+uint32_t BPWM_GetPeriodIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    return (((bpwm)->INTSTS & BPWM_INTSTS_PIF0_Msk) ? 1UL : 0UL);\r
+}\r
+\r
+/**\r
+ * @brief Enable zero interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to enable zero interrupt of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_EnableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->INTEN |= BPWM_INTEN_ZIEN0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Disable zero interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to disable zero interrupt of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_DisableZeroInt(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->INTEN &= ~BPWM_INTEN_ZIEN0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Clear zero interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to clear zero interrupt of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_ClearZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->INTSTS = BPWM_INTSTS_ZIF0_Msk;\r
+}\r
+\r
+/**\r
+ * @brief Get zero interrupt of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return zero interrupt flag of specified channel\r
+ * @retval 0 zero interrupt did not occur\r
+ * @retval 1 zero interrupt occurred\r
+ * @details This function is used to get zero interrupt of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+uint32_t BPWM_GetZeroIntFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    return (((bpwm)->INTSTS & BPWM_INTSTS_ZIF0_Msk) ? 1UL : 0UL);\r
+}\r
+\r
+/**\r
+ * @brief Enable load mode of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32LoadMode BPWM counter loading mode.\r
+ *              - \ref BPWM_LOAD_MODE_IMMEDIATE\r
+ *              - \ref BPWM_LOAD_MODE_CENTER\r
+ * @return None\r
+ * @details This function is used to enable load mode of selected channel.\r
+ */\r
+void BPWM_EnableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)\r
+{\r
+    (bpwm)->CTL0 |= (u32LoadMode << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Disable load mode of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. Valid values are between 0~5\r
+ * @param[in] u32LoadMode BPWM counter loading mode.\r
+ *              - \ref BPWM_LOAD_MODE_IMMEDIATE\r
+ *              - \ref BPWM_LOAD_MODE_CENTER\r
+ * @return None\r
+ * @details This function is used to disable load mode of selected channel.\r
+ */\r
+void BPWM_DisableLoadMode(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32LoadMode)\r
+{\r
+    (bpwm)->CTL0 &= ~(u32LoadMode << u32ChannelNum);\r
+}\r
+\r
+/**\r
+ * @brief Set BPWM clock source\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @param[in] u32ClkSrcSel BPWM external clock source.\r
+ *              - \ref BPWM_CLKSRC_BPWM_CLK\r
+ *              - \ref BPWM_CLKSRC_TIMER0\r
+ *              - \ref BPWM_CLKSRC_TIMER1\r
+ *              - \ref BPWM_CLKSRC_TIMER2\r
+ *              - \ref BPWM_CLKSRC_TIMER3\r
+ * @return None\r
+ * @details This function is used to set BPWM clock source.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_SetClockSource(BPWM_T *bpwm, uint32_t u32ChannelNum, uint32_t u32ClkSrcSel)\r
+{\r
+    (bpwm)->CLKSRC = (u32ClkSrcSel);\r
+}\r
+\r
+/**\r
+ * @brief Get the time-base counter reached its maximum value flag of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return Count to max interrupt flag of specified channel\r
+ * @retval 0 Count to max interrupt did not occur\r
+ * @retval 1 Count to max interrupt occurred\r
+ * @details This function is used to get the time-base counter reached its maximum value flag of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+uint32_t BPWM_GetWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    return (((bpwm)->STATUS & BPWM_STATUS_CNTMAX0_Msk) ? 1UL : 0UL);\r
+}\r
+\r
+/**\r
+ * @brief Clear the time-base counter reached its maximum value flag of selected channel\r
+ * @param[in] bpwm The pointer of the specified BPWM module\r
+ *                - BPWM0 : BPWM Group 0\r
+ *                - BPWM1 : BPWM Group 1\r
+ * @param[in] u32ChannelNum BPWM channel number. This parameter is not used.\r
+ * @return None\r
+ * @details This function is used to clear the time-base counter reached its maximum value flag of selected channel.\r
+ * @note All channels share channel 0's setting.\r
+ */\r
+void BPWM_ClearWrapAroundFlag(BPWM_T *bpwm, uint32_t u32ChannelNum)\r
+{\r
+    (bpwm)->STATUS = BPWM_STATUS_CNTMAX0_Msk;\r
+}\r
+\r
+\r
+/*@}*/ /* end of group BPWM_EXPORTED_FUNCTIONS */\r
+\r
+/*@}*/ /* end of group BPWM_Driver */\r
+\r
+/*@}*/ /* end of group Standard_Driver */\r
+\r
+/*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/\r