/**************************************************************************//** * @file sys.h * @version V1.00 * $Revision: 17 $ * $Date: 15/06/24 1:11p $ * @brief Nano100 Series system control header file. * * @note * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved. *****************************************************************************/ #ifndef __SYS_H__ #define __SYS_H__ #ifdef __cplusplus extern "C" { #endif /** @addtogroup NANO100_Device_Driver NANO100 Device Driver @{ */ /** @addtogroup NANO100_SYS_Driver SYS Driver @{ */ /** @addtogroup NANO100_SYS_EXPORTED_CONSTANTS SYS Exported Constants @{ */ /*---------------------------------------------------------------------------------------------------------*/ /* Module Reset Control Resister constant definitions. */ /*---------------------------------------------------------------------------------------------------------*/ #define CHIP_RST ((0x0<<24) | SYS_IPRST_CTL1_CPU_RST_Pos ) /*!< CPU reset is one of the SYS_ResetModule parameter */ #define CPU_RST ((0x0<<24) | SYS_IPRST_CTL1_CHIP_RST_Pos ) /*!< CHIP reset is one of the SYS_ResetModule parameter */ #define DMA_RST ((0x0<<24) | SYS_IPRST_CTL1_DMA_RST_Pos ) /*!< DMA reset is one of the SYS_ResetModule parameter */ #define EBI_RST ((0x0<<24) | SYS_IPRST_CTL1_EBI_RST_Pos ) /*!< EBI reset is one of the SYS_ResetModule parameter */ #define SC1_RST ((0x4<<24) | SYS_IPRST_CTL2_SC1_RST_Pos ) /*!< SmartCard1 reset is one of the SYS_ResetModule parameter */ #define SC0_RST ((0x4<<24) | SYS_IPRST_CTL2_SC0_RST_Pos ) /*!< SmartCard0 reset is one of the SYS_ResetModule parameter */ #define I2S_RST ((0x4<<24) | SYS_IPRST_CTL2_I2S_RST_Pos ) /*!< I2S reset is one of the SYS_ResetModule parameter */ #define ADC_RST ((0x4<<24) | SYS_IPRST_CTL2_ADC_RST_Pos ) /*!< ADC reset is one of the SYS_ResetModule parameter */ #define USBD_RST ((0x4<<24) | SYS_IPRST_CTL2_USBD_RST_Pos ) /*!< USBD reset is one of the SYS_ResetModule parameter */ #define DAC_RST ((0x4<<24) | SYS_IPRST_CTL2_DAC_RST_Pos ) /*!< DAC reset is one of the SYS_ResetModule parameter */ #define PWM1_RST ((0x4<<24) | SYS_IPRST_CTL2_PWM1_RST_Pos ) /*!< PWM1 reset is one of the SYS_ResetModule parameter */ #define PWM0_RST ((0x4<<24) | SYS_IPRST_CTL2_PWM0_RST_Pos ) /*!< PWM0 reset is one of the SYS_ResetModule parameter */ #define UART1_RST ((0x4<<24) | SYS_IPRST_CTL2_UART1_RST_Pos ) /*!< UART1 reset is one of the SYS_ResetModule parameter */ #define UART0_RST ((0x4<<24) | SYS_IPRST_CTL2_UART0_RST_Pos ) /*!< UART0 reset is one of the SYS_ResetModule parameter */ #define SPI2_RST ((0x4<<24) | SYS_IPRST_CTL2_SPI2_RST_Pos ) /*!< SPI2 reset is one of the SYS_ResetModule parameter */ #define SPI1_RST ((0x4<<24) | SYS_IPRST_CTL2_SPI1_RST_Pos ) /*!< SPI1 reset is one of the SYS_ResetModule parameter */ #define SPI0_RST ((0x4<<24) | SYS_IPRST_CTL2_SPI0_RST_Pos ) /*!< SPI0 reset is one of the SYS_ResetModule parameter */ #define I2C1_RST ((0x4<<24) | SYS_IPRST_CTL2_I2C1_RST_Pos ) /*!< I2C1 reset is one of the SYS_ResetModule parameter */ #define I2C0_RST ((0x4<<24) | SYS_IPRST_CTL2_I2C0_RST_Pos ) /*!< I2C0 reset is one of the SYS_ResetModule parameter */ #define TMR3_RST ((0x4<<24) | SYS_IPRST_CTL2_TMR3_RST_Pos ) /*!< Timer3 reset is one of the SYS_ResetModule parameter */ #define TMR2_RST ((0x4<<24) | SYS_IPRST_CTL2_TMR2_RST_Pos ) /*!< Timer2 reset is one of the SYS_ResetModule parameter */ #define TMR1_RST ((0x4<<24) | SYS_IPRST_CTL2_TMR1_RST_Pos ) /*!< Timer1 reset is one of the SYS_ResetModule parameter */ #define TMR0_RST ((0x4<<24) | SYS_IPRST_CTL2_TMR0_RST_Pos ) /*!< Timer0 reset is one of the SYS_ResetModule parameter */ #define GPIO_RST ((0x4<<24) | SYS_IPRST_CTL2_GPIO_RST_Pos ) /*!< GPIO reset is one of the SYS_ResetModule parameter */ /*---------------------------------------------------------------------------------------------------------*/ /* Multi-Function constant definitions. */ /*---------------------------------------------------------------------------------------------------------*/ /********************* Bit definition of VREFCTL register **********************/ #define SYS_VREFCTL_BGP_EN SYS_VREFCTL_BGP_EN_Msk /*!BODSTS |= SYS_BODSTS_BOD_INT_Msk) /** * @brief Disable Brown-out 2.5V detector function * @param None * @return None * @details This macro disable Brown-out 2.5V detector function. */ #define SYS_DISABLE_BOD25() (SYS->BODCTL &= ~SYS_BODCTL_BOD25_EN_Msk) /** * @brief Enable Brown-out 2.5V detector function * @param None * @return None * @details This macro enable Brown-out 2.5V detector function. */ #define SYS_ENABLE_BOD25() (SYS->BODCTL |= SYS_BODCTL_BOD25_EN_Msk) /** * @brief Disable Brown-out 2.0V detector function * @param None * @return None * @details This macro disable Brown-out 2.0V detector function. */ #define SYS_DISABLE_BOD20() (SYS->BODCTL &= ~SYS_BODCTL_BOD20_EN_Msk) /** * @brief Enable Brown-out 2.0V detector function * @param None * @return None * @details This macro enable Brown-out 2.0V detector function. */ #define SYS_ENABLE_BOD20() (SYS->BODCTL |= SYS_BODCTL_BOD20_EN_Msk) /** * @brief Disable Brown-out 1.7V detector function * @param None * @return None * @details This macro disable Brown-out 1.7V detector function. */ #define SYS_DISABLE_BOD17() (SYS->BODCTL &= ~SYS_BODCTL_BOD17_EN_Msk) /** * @brief Enable Brown-out 1.7V detector function * @param None * @return None * @details This macro enable Brown-out 1.7V detector function. */ #define SYS_ENABLE_BOD17() (SYS->BODCTL |= SYS_BODCTL_BOD17_EN_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. */ #define SYS_GET_BOD_INT_FLAG() (SYS->BODSTS & SYS_BODSTS_BOD_INT_Msk) /** * @brief Get Brown-out 2.5V detector status * @param None * @retval 0 System voltage is higher than 2.5V setting or BOD_EN is 0. * @retval >=1 System voltage is lower than 2.5V setting. * @details This macro get Brown-out detector output status. * If the BOD_EN is 0, this function always return 0. */ #define SYS_GET_BOD25_OUTPUT() (SYS->BODSTS & SYS_BODSTS_BOD25_drop_Msk) /** * @brief Get Brown-out 2.0V detector status * @param None * @retval 0 System voltage is higher than 2.0V setting or BOD_EN is 0. * @retval >=1 System voltage is lower than 2.0V setting. * @details This macro get Brown-out detector output status. * If the BOD_EN is 0, this function always return 0. */ #define SYS_GET_BOD20_OUTPUT() (SYS->BODSTS & SYS_BODSTS_BOD20_drop_Msk) /** * @brief Get Brown-out 1.7V detector status * @param None * @retval 0 System voltage is higher than 1.7V setting or BOD_EN is 0. * @retval >=1 System voltage is lower than 1.7V setting. * @details This macro get Brown-out detector output status. * If the BOD_EN is 0, this function always return 0. */ #define SYS_GET_BOD17_OUTPUT() (SYS->BODSTS & SYS_BODSTS_BOD17_drop_Msk) /** * @brief Disable Brown-out 2.5V detector interrupt function * @param None * @return None * @details This macro enable Brown-out detector interrupt function. */ #define SYS_DISABLE_BOD25_RST() (SYS->BODCTL &= ~SYS_BODCTL_BOD25_RST_EN_Msk) /** * @brief Enable Brown-out 2.5V detector reset function * @param None * @return None * @details This macro enable Brown-out detect reset function. */ #define SYS_ENABLE_BOD25_RST() (SYS->BODCTL |= SYS_BODCTL_BOD25_RST_EN_Msk) /** * @brief Disable Brown-out 2.0V detector interrupt function * @param None * @return None * @details This macro enable Brown-out detector interrupt function. */ #define SYS_DISABLE_BOD20_RST() (SYS->BODCTL &= ~SYS_BODCTL_BOD20_RST_EN_Msk) /** * @brief Enable Brown-out 2.0V detector reset function * @param None * @return None * @details This macro enable Brown-out detect reset function. */ #define SYS_ENABLE_BOD20_RST() (SYS->BODCTL |= SYS_BODCTL_BOD20_RST_EN_Msk) /** * @brief Disable Brown-out 1.7V detector interrupt function * @param None * @return None * @details This macro enable Brown-out detector interrupt function. */ #define SYS_DISABLE_BOD17_RST() (SYS->BODCTL &= ~SYS_BODCTL_BOD17_RST_EN_Msk) /** * @brief Enable Brown-out 1.7V detector reset function * @param None * @return None * @details This macro enable Brown-out detect reset function. */ #define SYS_ENABLE_BOD17_RST() (SYS->BODCTL |= SYS_BODCTL_BOD17_RST_EN_Msk) /** * @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. */ #define SYS_IS_BOD_RST() (SYS->RST_SRC & SYS_RST_SRC_RSTS_BOD_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. */ #define SYS_IS_CPU_RST() (SYS->RST_SRC & SYS_RST_SRC_RSTS_CPU_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. */ #define SYS_IS_POR_RST() (SYS->RST_SRC & SYS_RST_SRC_RSTS_POR_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. */ #define SYS_IS_RSTPIN_RST() (SYS->RST_SRC & SYS_RST_SRC_RSTS_PAD_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. */ #define SYS_IS_SYSTEM_RST() (SYS->RST_SRC & SYS_RST_SRC_RSTS_SYS_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. */ #define SYS_IS_WDT_RST() (SYS->RST_SRC & SYS_RST_SRC_RSTS_WDT_Msk) /** * @brief Disable Power-on Reset function * @param None * @return None * @details This macro disable Power-on Reset function. */ #define SYS_DISABLE_POR() (SYS->PORCTL = 0x5AA5) /** * @brief Enable Power-on Reset function * @param None * @return None * @details This macro enable Power-on Reset function. */ #define SYS_ENABLE_POR() (SYS->PORCTL = 0) /** * @brief Clear reset source flag * @param[in] u32RstSrc is reset source. Including: * - \ref SYS_RST_SRC_RSTS_POR_Msk * - \ref SYS_RST_SRC_RSTS_PAD_Msk * - \ref SYS_RST_SRC_RSTS_WDT_Msk * - \ref SYS_RST_SRC_RSTS_BOD_Msk * - \ref SYS_RST_SRC_RSTS_SYS_Msk * - \ref SYS_RST_SRC_RSTS_CPU_Msk * @return None * @details This macro clear reset source flag. */ #define SYS_CLEAR_RST_SOURCE(u32RstSrc) (SYS->RST_SRC = u32RstSrc ) /** * @brief Get HIRC trim status * @param None * @retval BIT0 HIRC Frequency Lock * @retval BIT1 Trim Failure Interrupt * @retval BIT2 LXT Clock error * @details This macro get HIRC trim interrupt status register. */ #define SYS_GET_IRCTRIM_INT_FLAG() (SYS->IRCTRIMINT) /** * @brief Clear HIRC trim flag * @param[in] u32IRCTrimFlg is HIRC trim flags. Including: * - \ref SYS_IRCTRIMINT_FAIL_INT * - \ref SYS_IRCTRIMINT_32KERR_INT * @return None * @details This macro clear HIRC trim flag. */ #define SYS_CLEAR_IRCTRIM_INT_FLAG(u32IRCTrimFlg) (SYS->IRCTRIMINT = u32IRCTrimFlg ) /** * @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) { while(SYS->RegLockAddr != SYS_RegLockAddr_RegUnLock_Msk) { SYS->RegLockAddr = 0x59; SYS->RegLockAddr = 0x16; SYS->RegLockAddr = 0x88; } } /** * @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->RegLockAddr = 0; } 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); void SYS_EnableIRCTrim(uint32_t u32TrimSel,uint32_t u32TrimEnInt); void SYS_DisableIRCTrim(void); /*@}*/ /* end of group NANO100_SYS_EXPORTED_FUNCTIONS */ /*@}*/ /* end of group NANO100_SYS_Driver */ /*@}*/ /* end of group NANO100_Device_Driver */ #ifdef __cplusplus } #endif #endif //__SYS_H__ /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/