/**************************************************************************//** * @file sys.h * @version V1.0 * @brief M2L31 series SYS driver header file * * SPDX-License-Identifier: Apache-2.0 * @copyright (C) 2023 Nuvoton Technology Corp. All rights reserved. ******************************************************************************/ #ifndef __SYS_H__ #define __SYS_H__ #ifdef __cplusplus extern "C" { #endif /** @addtogroup Standard_Driver Standard Driver @{ */ /** @addtogroup SYS_Driver SYS Driver @{ */ /** @addtogroup SYS_EXPORTED_CONSTANTS SYS Exported Constants @{ */ /*---------------------------------------------------------------------------------------------------------*/ /* Module Reset Control Resister constant definitions. */ /*---------------------------------------------------------------------------------------------------------*/ #define CHIP_RST ((0UL<<24) | SYS_IPRST0_CHIPRST_Pos) /*!< Reset CHIP \hideinitializer */ #define CPU_RST ((0UL<<24) | SYS_IPRST0_CPURST_Pos) /*!< Reset CPU \hideinitializer */ #define PDMA0_RST ((0UL<<24) | SYS_IPRST0_PDMA0RST_Pos) /*!< Reset PDMA0 \hideinitializer */ #define EBI_RST ((0UL<<24) | SYS_IPRST0_EBIRST_Pos) /*!< Reset EBI \hideinitializer */ #define USBH_RST ((0UL<<24) | SYS_IPRST0_USBHRST_Pos) /*!< Reset USBH \hideinitializer */ #define CRC_RST ((0UL<<24) | SYS_IPRST0_CRCRST_Pos) /*!< Reset CRC \hideinitializer */ #define CRPT_RST ((0UL<<24) | SYS_IPRST0_CRPTRST_Pos) /*!< Reset CRPT \hideinitializer */ #define CANFD0_RST ((0UL<<24) | SYS_IPRST0_CANFD0RST_Pos) /*!< Reset CANFD0 \hideinitializer */ #define CANFD1_RST ((0UL<<24) | SYS_IPRST0_CANFD1RST_Pos) /*!< Reset CANFD1 \hideinitializer */ #define GPIO_RST ((4UL<<24) | SYS_IPRST1_GPIORST_Pos) /*!< Reset GPIO \hideinitializer */ #define TMR0_RST ((4UL<<24) | SYS_IPRST1_TMR0RST_Pos) /*!< Reset TMR0 \hideinitializer */ #define TMR1_RST ((4UL<<24) | SYS_IPRST1_TMR1RST_Pos) /*!< Reset TMR1 \hideinitializer */ #define TMR2_RST ((4UL<<24) | SYS_IPRST1_TMR2RST_Pos) /*!< Reset TMR2 \hideinitializer */ #define TMR3_RST ((4UL<<24) | SYS_IPRST1_TMR3RST_Pos) /*!< Reset TMR3 \hideinitializer */ #define ACMP01_RST ((4UL<<24) | SYS_IPRST1_ACMP01RST_Pos) /*!< Reset ACMP01 \hideinitializer */ #define I2C0_RST ((4UL<<24) | SYS_IPRST1_I2C0RST_Pos) /*!< Reset I2C0 \hideinitializer */ #define I2C1_RST ((4UL<<24) | SYS_IPRST1_I2C1RST_Pos) /*!< Reset I2C1 \hideinitializer */ #define I2C2_RST ((4UL<<24) | SYS_IPRST1_I2C2RST_Pos) /*!< Reset I2C2 \hideinitializer */ #define I2C3_RST ((4UL<<24) | SYS_IPRST1_I2C3RST_Pos) /*!< Reset I2C3 \hideinitializer */ #define QSPI0_RST ((4UL<<24) | SYS_IPRST1_QSPI0RST_Pos) /*!< Reset QSPI0 \hideinitializer */ #define SPI0_RST ((4UL<<24) | SYS_IPRST1_SPI0RST_Pos) /*!< Reset SPI0 \hideinitializer */ #define SPI1_RST ((4UL<<24) | SYS_IPRST1_SPI1RST_Pos) /*!< Reset SPI1 \hideinitializer */ #define SPI2_RST ((4UL<<24) | SYS_IPRST1_SPI2RST_Pos) /*!< Reset SPI2 \hideinitializer */ #define UART0_RST ((4UL<<24) | SYS_IPRST1_UART0RST_Pos) /*!< Reset UART0 \hideinitializer */ #define UART1_RST ((4UL<<24) | SYS_IPRST1_UART1RST_Pos) /*!< Reset UART1 \hideinitializer */ #define UART2_RST ((4UL<<24) | SYS_IPRST1_UART2RST_Pos) /*!< Reset UART2 \hideinitializer */ #define UART3_RST ((4UL<<24) | SYS_IPRST1_UART3RST_Pos) /*!< Reset UART3 \hideinitializer */ #define UART4_RST ((4UL<<24) | SYS_IPRST1_UART4RST_Pos) /*!< Reset UART4 \hideinitializer */ #define UART5_RST ((4UL<<24) | SYS_IPRST1_UART5RST_Pos) /*!< Reset UART5 \hideinitializer */ #define UART6_RST ((4UL<<24) | SYS_IPRST1_UART6RST_Pos) /*!< Reset UART6 \hideinitializer */ #define UART7_RST ((4UL<<24) | SYS_IPRST1_UART7RST_Pos) /*!< Reset UART7 \hideinitializer */ #define OTG_RST ((4UL<<24) | SYS_IPRST1_OTGRST_Pos) /*!< Reset OTG \hideinitializer */ #define USBD_RST ((4UL<<24) | SYS_IPRST1_USBDRST_Pos) /*!< Reset USBD \hideinitializer */ #define EADC0_RST ((4UL<<24) | SYS_IPRST1_EADC0RST_Pos) /*!< Reset EADC0 \hideinitializer */ #define TRNG_RST ((4UL<<24) | SYS_IPRST1_TRNGRST_Pos) /*!< Reset TRNG \hideinitializer */ #define SPI3_RST ((8UL<<24) | SYS_IPRST2_SPI3RST_Pos) /*!< Reset SPI3 \hideinitializer */ #define USCI0_RST ((8UL<<24) | SYS_IPRST2_USCI0RST_Pos) /*!< Reset USCI0 \hideinitializer */ #define USCI1_RST ((8UL<<24) | SYS_IPRST2_USCI1RST_Pos) /*!< Reset USCI1 \hideinitializer */ #define WWDT_RST ((8UL<<24) | SYS_IPRST2_WWDTRST_Pos) /*!< Reset WWDT \hideinitializer */ #define DAC_RST ((8UL<<24) | SYS_IPRST2_DACRST_Pos) /*!< Reset DAC \hideinitializer */ #define EPWM0_RST ((8UL<<24) | SYS_IPRST2_EPWM0RST_Pos) /*!< Reset EPWM0 \hideinitializer */ #define EPWM1_RST ((8UL<<24) | SYS_IPRST2_EPWM1RST_Pos) /*!< Reset EPWM1 \hideinitializer */ #define EQEI0_RST ((8UL<<24) | SYS_IPRST2_EQEI0RST_Pos) /*!< Reset EQEI0 \hideinitializer */ #define EQEI1_RST ((8UL<<24) | SYS_IPRST2_EQEI1RST_Pos) /*!< Reset EQEI1 \hideinitializer */ #define TK_RST ((8UL<<24) | SYS_IPRST2_TKRST_Pos) /*!< Reset TK \hideinitializer */ #define ECAP0_RST ((8UL<<24) | SYS_IPRST2_ECAP0RST_Pos) /*!< Reset ECAP0 \hideinitializer */ #define ECAP1_RST ((8UL<<24) | SYS_IPRST2_ECAP1RST_Pos) /*!< Reset ECAP1 \hideinitializer */ #define ACMP2_RST ((0x18UL<<24) | SYS_IPRST3_ACMP2RST_Pos) /*!< Reset ACMP2 \hideinitializer */ #define PWM0_RST ((0x18UL<<24) | SYS_IPRST3_PWM0RST_Pos) /*!< Reset PWM0 \hideinitializer */ #define PWM1_RST ((0x18UL<<24) | SYS_IPRST3_PWM1RST_Pos) /*!< Reset PWM1 \hideinitializer */ #define UTCPD0_RST ((0x18UL<<24) | SYS_IPRST3_UTCPD0RST_Pos) /*!< Reset UTCPD0 \hideinitializer */ #define LPPDMA0_RST ((0x80UL<<24) | LPSCC_IPRST0_LPPDMA0RST_Pos) /*!< Reset LPPDMA0 \hideinitializer */ #define LPGPIO_RST ((0x80UL<<24) | LPSCC_IPRST0_LPGPIORST_Pos) /*!< Reset LPGPIO \hideinitializer */ #define LPSRAM_RST ((0x80UL<<24) | LPSCC_IPRST0_LPSRAMRST_Pos) /*!< Reset LPSRAM \hideinitializer */ #define WDT_RST ((0x80UL<<24) | LPSCC_IPRST0_WDTRST_Pos) /*!< Reset WDT \hideinitializer */ #define LPSPI0_RST ((0x80UL<<24) | LPSCC_IPRST0_LPSPI0RST_Pos) /*!< Reset LPSPI0 \hideinitializer */ #define LPI2C0_RST ((0x80UL<<24) | LPSCC_IPRST0_LPI2C0RST_Pos) /*!< Reset LPI2C0 \hideinitializer */ #define LPUART0_RST ((0x80UL<<24) | LPSCC_IPRST0_LPUART0RST_Pos) /*!< Reset LPUART0 \hideinitializer */ #define LPTMR0_RST ((0x80UL<<24) | LPSCC_IPRST0_LPTMR0RST_Pos) /*!< Reset LPTMR0 \hideinitializer */ #define LPTMR1_RST ((0x80UL<<24) | LPSCC_IPRST0_LPTMR1RST_Pos) /*!< Reset LPTMR1 \hideinitializer */ #define TTMR0_RST ((0x80UL<<24) | LPSCC_IPRST0_TTMR0RST_Pos) /*!< Reset TTMR0 \hideinitializer */ #define TTMR1_RST ((0x80UL<<24) | LPSCC_IPRST0_TTMR1RST_Pos) /*!< Reset TTMR1 \hideinitializer */ #define LPADC0_RST ((0x80UL<<24) | LPSCC_IPRST0_LPADC0RST_Pos) /*!< Reset LPADC0 \hideinitializer */ #define OPA_RST ((0x80UL<<24) | LPSCC_IPRST0_OPARST_Pos) /*!< Reset OPA \hideinitializer */ /*---------------------------------------------------------------------------------------------------------*/ /* Brown Out Detector Threshold Voltage Selection constant definitions. */ /*---------------------------------------------------------------------------------------------------------*/ #define SYS_BODCTL_BOD_RST_EN (1UL << SYS_BODCTL_BODRSTEN_Pos) /*!< Brown-out Reset Enable \hideinitializer */ #define SYS_BODCTL_BOD_INTERRUPT_EN (0UL << SYS_BODCTL_BODRSTEN_Pos) /*!< Brown-out Interrupt Enable \hideinitializer */ #define SYS_BODCTL_BODVL_3_0V (15UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 3.0V \hideinitializer */ #define SYS_BODCTL_BODVL_2_8V (14UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 2.8V \hideinitializer */ #define SYS_BODCTL_BODVL_2_6V (13UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 2.6V \hideinitializer */ #define SYS_BODCTL_BODVL_2_4V (12UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 2.4V \hideinitializer */ #define SYS_BODCTL_BODVL_2_2V (11UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 2.2V \hideinitializer */ #define SYS_BODCTL_BODVL_2_0V (10UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 2.0V \hideinitializer */ #define SYS_BODCTL_BODVL_1_8V (9UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 1.8V \hideinitializer */ #define SYS_BODCTL_BODVL_1_6V (8UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 1.6V \hideinitializer */ #define SYS_BODCTL_BODVL_1_5V (0UL << SYS_BODCTL_BODVL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 1.5V \hideinitializer */ #define SYS_BODCTL_LVRDGSEL_0HCLK (0x0UL<GPA_MFPL = (SYS->GPA_MFPL & (~SYS_GPA_MFPL_PA0MFP_Msk) ) | SYS_GPA_MFPL_PA0_MFP_SC0_CLK ; */ /* PA.0 MFP */ #define SYS_GPA_MFP0_PA0MFP_GPIO (0x0UL<BODCTL |= SYS_BODCTL_BODIF_Msk) /** * @brief Set Brown-out detector function to normal mode * @param None * @return None * @details This macro set Brown-out detector to normal mode. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_CLEAR_BOD_LPM() (SYS->BODCTL &= ~SYS_BODCTL_BODLPM_Msk) /** * @brief Disable Brown-out detector function * @param None * @return None * @details This macro disable Brown-out detector function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_DISABLE_BOD() (SYS->BODCTL &= ~SYS_BODCTL_BODEN_Msk) /** * @brief Enable Brown-out detector function * @param None * @return None * @details This macro enable Brown-out detector function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_ENABLE_BOD() (SYS->BODCTL |= SYS_BODCTL_BODEN_Msk) /** * @brief Get Brown-out detector interrupt flag * @param None * @retval 0 Brown-out detect interrupt flag is not set. * @retval >=1 Brown-out detect interrupt flag is set. * @details This macro get Brown-out detector interrupt flag. * \hideinitializer */ #define SYS_GET_BOD_INT_FLAG() (SYS->BODCTL & SYS_BODCTL_BODIF_Msk) /** * @brief Get Brown-out detector status * @param None * @retval 0 System voltage is higher than BOD threshold voltage setting or BOD function is disabled. * @retval >=1 System voltage is lower than BOD threshold voltage setting. * @details This macro get Brown-out detector output status. * If the BOD function is disabled, this function always return 0. * \hideinitializer */ #define SYS_GET_BOD_OUTPUT() (SYS->BODCTL & SYS_BODCTL_BODOUT_Msk) /** * @brief Enable Brown-out detector interrupt function * @param None * @return None * @details This macro enable Brown-out detector interrupt function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_DISABLE_BOD_RST() (SYS->BODCTL &= ~SYS_BODCTL_BODRSTEN_Msk) /** * @brief Enable Brown-out detector reset function * @param None * @return None * @details This macro enable Brown-out detect reset function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_ENABLE_BOD_RST() (SYS->BODCTL |= SYS_BODCTL_BODRSTEN_Msk) /** * @brief Set Brown-out detector function low power mode * @param None * @return None * @details This macro set Brown-out detector to low power mode. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_SET_BOD_LPM() (SYS->BODCTL |= SYS_BODCTL_BODLPM_Msk) /** * @brief Set Brown-out detector voltage level * @param[in] u32Level is Brown-out voltage level. Including : * - \ref SYS_BODCTL_BODVL_3_0V * - \ref SYS_BODCTL_BODVL_2_8V * - \ref SYS_BODCTL_BODVL_2_6V * - \ref SYS_BODCTL_BODVL_2_4V * - \ref SYS_BODCTL_BODVL_2_2V * - \ref SYS_BODCTL_BODVL_2_0V * - \ref SYS_BODCTL_BODVL_1_8V * - \ref SYS_BODCTL_BODVL_1_6V * - \ref SYS_BODCTL_BODVL_1_5V * @return None * @details This macro set Brown-out detector voltage level. * The write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_SET_BOD_LEVEL(u32Level) (SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODVL_Msk) | (u32Level)) /** * @brief Get reset source is from Brown-out detector reset * @param None * @retval 0 Previous reset source is not from Brown-out detector reset * @retval >=1 Previous reset source is from Brown-out detector reset * @details This macro get previous reset source is from Brown-out detect reset or not. * \hideinitializer */ #define SYS_IS_BOD_RST() (SYS->RSTSTS & SYS_RSTSTS_BODRF_Msk) /** * @brief Get reset source is from CPU reset * @param None * @retval 0 Previous reset source is not from CPU reset * @retval >=1 Previous reset source is from CPU reset * @details This macro get previous reset source is from CPU reset. * \hideinitializer */ #define SYS_IS_CPU_RST() (SYS->RSTSTS & SYS_RSTSTS_CPURF_Msk) /** * @brief Get reset source is from LVR Reset * @param None * @retval 0 Previous reset source is not from Low-Voltage-Reset * @retval >=1 Previous reset source is from Low-Voltage-Reset * @details This macro get previous reset source is from Low-Voltage-Reset. * \hideinitializer */ #define SYS_IS_LVR_RST() (SYS->RSTSTS & SYS_RSTSTS_LVRF_Msk) /** * @brief Get reset source is from Power-on Reset * @param None * @retval 0 Previous reset source is not from Power-on Reset * @retval >=1 Previous reset source is from Power-on Reset * @details This macro get previous reset source is from Power-on Reset. * \hideinitializer */ #define SYS_IS_POR_RST() (SYS->RSTSTS & SYS_RSTSTS_PORF_Msk) /** * @brief Get reset source is from reset pin reset * @param None * @retval 0 Previous reset source is not from reset pin reset * @retval >=1 Previous reset source is from reset pin reset * @details This macro get previous reset source is from reset pin reset. * \hideinitializer */ #define SYS_IS_RSTPIN_RST() (SYS->RSTSTS & SYS_RSTSTS_PINRF_Msk) /** * @brief Get reset source is from system reset * @param None * @retval 0 Previous reset source is not from system reset * @retval >=1 Previous reset source is from system reset * @details This macro get previous reset source is from system reset. * \hideinitializer */ #define SYS_IS_SYSTEM_RST() (SYS->RSTSTS & SYS_RSTSTS_SYSRF_Msk) /** * @brief Get reset source is from window watch dog reset * @param None * @retval 0 Previous reset source is not from window watch dog reset * @retval >=1 Previous reset source is from window watch dog reset * @details This macro get previous reset source is from window watch dog reset. * \hideinitializer */ #define SYS_IS_WDT_RST() (SYS->RSTSTS & SYS_RSTSTS_WDTRF_Msk) /** * @brief Disable Low-Voltage-Reset function * @param None * @return None * @details This macro disable Low-Voltage-Reset function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_DISABLE_LVR() (SYS->BODCTL &= ~SYS_BODCTL_LVREN_Msk) /** * @brief Enable Low-Voltage-Reset function * @param None * @return None * @details This macro enable Low-Voltage-Reset function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_ENABLE_LVR() (SYS->BODCTL |= SYS_BODCTL_LVREN_Msk) /** * @brief Disable Power-on Reset function * @param None * @return None * @details This macro disable Power-on Reset function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_DISABLE_POR() (SYS->PORDISAN = 0x5AA5) /** * @brief Enable Power-on Reset function * @param None * @return None * @details This macro enable Power-on Reset function. * The register write-protection function should be disabled before using this macro. * \hideinitializer */ #define SYS_ENABLE_POR() (SYS->PORDISAN = 0) /** * @brief Clear reset source flag * @param[in] u32RstSrc is reset source. Including : * - \ref SYS_RSTSTS_PORF_Msk * - \ref SYS_RSTSTS_PINRF_Msk * - \ref SYS_RSTSTS_WDTRF_Msk * - \ref SYS_RSTSTS_LVRF_Msk * - \ref SYS_RSTSTS_BODRF_Msk * - \ref SYS_RSTSTS_SYSRF_Msk * - \ref SYS_RSTSTS_HRESETRF_Msk * - \ref SYS_RSTSTS_CPURF_Msk * - \ref SYS_RSTSTS_CPULKRF_Msk * @return None * @details This macro clear reset source flag. * \hideinitializer */ #define SYS_CLEAR_RST_SOURCE(u32RstSrc) ((SYS->RSTSTS) = (u32RstSrc) ) /*---------------------------------------------------------------------------------------------------------*/ /* static inline functions */ /*---------------------------------------------------------------------------------------------------------*/ /* Declare these inline functions here to avoid MISRA C 2004 rule 8.1 error */ __STATIC_INLINE void SYS_UnlockReg(void); __STATIC_INLINE void SYS_LockReg(void); /** * @brief Disable register write-protection function * @param None * @return None * @details This function disable register write-protection function. * To unlock the protected register to allow write access. */ __STATIC_INLINE void SYS_UnlockReg(void) { do { SYS->REGLCTL = 0x59UL; SYS->REGLCTL = 0x16UL; SYS->REGLCTL = 0x88UL; } while(SYS->REGLCTL == 0UL); } /** * @brief Enable register write-protection function * @param None * @return None * @details This function is used to enable register write-protection function. * To lock the protected register to forbid write access. */ __STATIC_INLINE void SYS_LockReg(void) { SYS->REGLCTL = 0UL; } void SYS_ClearResetSrc(uint32_t u32Src); uint32_t SYS_GetBODStatus(void); uint32_t SYS_GetResetSrc(void); uint32_t SYS_IsRegLocked(void); uint32_t SYS_ReadPDID(void); void SYS_ResetChip(void); void SYS_ResetCPU(void); void SYS_ResetModule(uint32_t u32ModuleIndex); void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel); void SYS_DisableBOD(void); int32_t SYS_SetPowerLevel(uint32_t u32PowerLevel); void SYS_SetVRef(uint32_t u32VRefCTL); int32_t SYS_SetSSRAMPowerMode(uint32_t u32SRAMSel, uint32_t u32PowerMode); /*@}*/ /* end of group SYS_EXPORTED_FUNCTIONS */ /*@}*/ /* end of group SYS_Driver */ /*@}*/ /* end of group Standard_Driver */ #ifdef __cplusplus } #endif #endif /* __SYS_H__ */ /*** (C) COPYRIGHT 2023 Nuvoton Technology Corp. ***/