/**************************************************************************//**
 * @file     sys.h
 * @version  V1.00
 * $Revision: 2 $
 * $Date: 14/08/05 10:00a $
 * @brief    N572 Series SYS Header File
 *
 * @note
 * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
 ******************************************************************************/
 
#ifndef __SYS_H__
#define __SYS_H__

#ifdef __cplusplus
extern "C"
{
#endif

/** @addtogroup N572_Device_Driver N572 Device Driver
  @{
*/

/** @addtogroup N572_SYS_Driver SYS Driver
  @{
*/

/** @addtogroup N572_SYS_EXPORTED_CONSTANTS SYS Exported Constants
  @{
*/

/*---------------------------------------------------------------------------------------------------------*/
/*  RSTSTS constant definitions.                                                                            */
/*---------------------------------------------------------------------------------------------------------*/
#define  SYS_RSTSTS_PMURSTF       (0x1UL<<SYS_RSTSTS_PMURSTF_Pos)    /*!<Power wake up reset flag  \hideinitializer */
#define  SYS_RSTSTS_LVRF          (0x1UL<<SYS_RSTSTS_LVRF_Msk)       /*!<Low voltage reset flag  \hideinitializer */
#define  SYS_RSTSTS_WDTRF         (0x1UL<<SYS_RSTSTS_WDTRF_Msk)      /*!<Watch dog reset flag  \hideinitializer */
#define  SYS_RSTSTS_PINRF         (0x1UL<<SYS_RSTSTS_PINRF_Msk)      /*!<Pin reset flag  \hideinitializer */
#define  SYS_RSTSTS_PORF          (0x1UL<<SYS_RSTSTS_PORF_Pos)       /*!<Por reset flag  \hideinitializer */
#if( __CHIP_SERIES__ == __N572F065_SERIES__ )
#define  SYS_RSTSTS_MCURF         (0x1UL<<SYS_RSTSTS_MCURF_Pos)      /*!<MCU reset flag  \hideinitializer */
#endif
 	
/*---------------------------------------------------------------------------------------------------------*/
/*  Module Reset Control Resister constant definitions.                                                    */
/*---------------------------------------------------------------------------------------------------------*/
#define CHIP_RST    ((0x0<<24) | SYS_IPRST0_CHIPRST_Pos  ) /*!<Reset CHIP  \hideinitializer */
#define CPU_RST     ((0x0<<24) | SYS_IPRST0_CPURST_Pos   ) /*!<Reset CPU  \hideinitializer  */
#define GPIO_RST    ((0x4<<24) | SYS_IPRST1_GPIORST_Pos  ) /*!<Reset GPIO  \hideinitializer  */
#define TMR0_RST    ((0x4<<24) | SYS_IPRST1_TMR0RST_Pos  ) /*!<Reset TMR0  \hideinitializer  */
#define TMR1_RST    ((0x4<<24) | SYS_IPRST1_TMR1RST_Pos  ) /*!<Reset TMR1  \hideinitializer  */
#define TMR2_RST    ((0x4<<24) | SYS_IPRST1_TMR2RST_Pos  ) /*!<Reset TMR2  \hideinitializer  */
#define APU_RST     ((0x4<<24) | SYS_IPRST1_APURST_Pos   ) /*!<Reset APU  \hideinitializer  */
#define TMRF_RST    ((0x4<<24) | SYS_IPRST1_TMRFRST_Pos  ) /*!<Reset TMRF  \hideinitializer  */
#define SPI0_RST    ((0x4<<24) | SYS_IPRST1_SPI0RST_Pos  ) /*!<Reset SPI0  \hideinitializer  */
#define SPI1_RST    ((0x4<<24) | SYS_IPRST1_SPI1RST_Pos  ) /*!<Reset SPI1  \hideinitializer  */
#define PWM_RST     ((0x4<<24) | SYS_IPRST1_PWMRST_Pos   ) /*!<Reset PWM  \hideinitializer  */
#define ADC_RST     ((0x4<<24) | SYS_IPRST1_ADCRST_Pos   ) /*!<Reset ADC  \hideinitializer  */
#if( __CHIP_SERIES__ == __N572F065_SERIES__ )
#define USBD_RST    ((0x4<<24) | SYS_IPRST1_USBDRST_Pos  ) /*!<Reset USB  \hideinitializer  */
#endif

/*---------------------------------------------------------------------------------------------------------*/
/* IPRST0 constant definitions.                                                                            */
/*---------------------------------------------------------------------------------------------------------*/
#define SYS_IPRST0_RAMWS_1HCLK_WAIT    (0x0UL<<SYS_IPRST0_RAMWS_Pos)  /*!< Wait state control for CPU access RAM setting for 1 HCLK clock wait-state   \hideinitializer */     
#define SYS_IPRST0_RAMWS_ZERO_WAIT     (0x1UL<<SYS_IPRST0_RAMWS_Pos)  /*!< Wait state control for CPU access RAM setting for zero clock wait-state   \hideinitializer */     

#define SYS_IPRST0_CPUWS_1HCLK_WAIT    (0x0UL<<SYS_IPRST0_CPUWS_Pos)  /*!< CPU wait-state control for flash memory access setting for 1 HCLK clock wait-state   \hideinitializer */     
#define SYS_IPRST0_CPUWS_ZERO_WAIT     (0x1UL<<SYS_IPRST0_CPUWS_Pos)  /*!< CPU wait-state control for flash memory access setting for zero clock wait-state   \hideinitializer */     

/*---------------------------------------------------------------------------------------------------------*/
/*  BODCTL constant definitions.                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
#define SYS_BODCTL_BODVL_2_7V          (0x0UL<<SYS_BODCTL_BOD_VL_Pos)  /*!<Threshold voltage of BOD is selected 2.7V \hideinitializer */
#define SYS_BODCTL_BODVL_3_0V          (0x1UL<<SYS_BODCTL_BOD_VL_Pos)  /*!<Threshold voltage of BOD is selected 3.0V \hideinitializer */

/*---------------------------------------------------------------------------------------------------------*/
/*  GPIO Input Type Control Resister constant definitions.                                                 */
/*---------------------------------------------------------------------------------------------------------*/

// GPIOA
#define SYS_GPA_MFP_PA0_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+0))     /*!< GPA MFP schmitt setting for GPIOA0 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA1_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+1))     /*!< GPA MFP schmitt setting for GPIOA1 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA2_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+2))     /*!< GPA MFP schmitt setting for GPIOA2 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA3_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+3))     /*!< GPA MFP schmitt setting for GPIOA3 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA4_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+4))     /*!< GPA MFP schmitt setting for GPIOA4 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA5_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+5))     /*!< GPA MFP schmitt setting for GPIOA5 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA6_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+6))     /*!< GPA MFP schmitt setting for GPIOA6 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA7_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+7))     /*!< GPA MFP schmitt setting for GPIOA7 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA8_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+8))     /*!< GPA MFP schmitt setting for GPIOA8 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA9_SCHMITT        (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+9))     /*!< GPA MFP schmitt setting for GPIOA9 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA10_SCHMITT       (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+10))    /*!< GPA MFP schmitt setting for GPIOA10 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA11_SCHMITT       (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+11))    /*!< GPA MFP schmitt setting for GPIOA11 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA12_SCHMITT       (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+12))    /*!< GPA MFP schmitt setting for GPIOA12 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA13_SCHMITT       (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+13))    /*!< GPA MFP schmitt setting for GPIOA13 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA14_SCHMITT       (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+14))    /*!< GPA MFP schmitt setting for GPIOA14 input type   \hideinitializer */     
#define SYS_GPA_MFP_PA15_SCHMITT       (0x1UL<<(SYS_GPA_MFP_PAnTYPEn_Pos+15))    /*!< GPA MFP schmitt setting for GPIOA15 input type   \hideinitializer */     

// GPIOB
#define SYS_GPB_MFP_PB0_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+0))     /*!< GPB MFP schmitt setting for GPIOB0 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB1_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+1))     /*!< GPB MFP schmitt setting for GPIOB1 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB2_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+2))     /*!< GPB MFP schmitt setting for GPIOB2 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB3_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+3))     /*!< GPB MFP schmitt setting for GPIOB3 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB4_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+4))     /*!< GPB MFP schmitt setting for GPIOB4 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB5_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+5))     /*!< GPB MFP schmitt setting for GPIOB5 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB6_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+6))     /*!< GPB MFP schmitt setting for GPIOB6 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB7_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+7))     /*!< GPB MFP schmitt setting for GPIOB7 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB8_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+8))     /*!< GPB MFP schmitt setting for GPIOB8 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB9_SCHMITT        (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+9))     /*!< GPB MFP schmitt setting for GPIOB9 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB10_SCHMITT       (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+10))    /*!< GPB MFP schmitt setting for GPIOB10 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB11_SCHMITT       (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+11))    /*!< GPB MFP schmitt setting for GPIOB11 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB12_SCHMITT       (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+12))    /*!< GPB MFP schmitt setting for GPIOB12 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB13_SCHMITT       (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+13))    /*!< GPB MFP schmitt setting for GPIOB13 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB14_SCHMITT       (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+14))    /*!< GPB MFP schmitt setting for GPIOB14 input type   \hideinitializer */     
#define SYS_GPB_MFP_PB15_SCHMITT       (0x1UL<<(SYS_GPB_MFP_PBnTYPEn_Pos+15))    /*!< GPB MFP schmitt setting for GPIOB15 input type   \hideinitializer */     

/*---------------------------------------------------------------------------------------------------------*/
/*  Multi-Function constant definitions.                                                                   */
/*---------------------------------------------------------------------------------------------------------*/
/* How to use below #define?
Example 1: If user want to set PA.0 as SPI_MOSI0 in initial function,
           user can issue following command to achieve it.

           SYS->GPA_MFP  = (SYS->GPA_MFP & (~SYS_GPA_MFP_PA0MFP_Msk) ) | SYS_GPA_MFP_PA0MFP_SPI_SSB01  ;

*/
//GPA_MFP_PA0MFP
#define SYS_GPA_MFP_PA0MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA0MFP_Pos)           /*!< GPA_MFP PA0 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA0MFP_SPI_SSB01   (0x1UL<<SYS_GPA_MFP_PA0MFP_Pos)           /*!< GPA_MFP PA0 setting for SPI_SSB01   \hideinitializer */

//GPA_MFP_PA1MFP
#define SYS_GPA_MFP_PA1MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA1MFP_Pos)           /*!< GPA_MFP PA1 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA1MFP_SPI_SSB00   (0x1UL<<SYS_GPA_MFP_PA1MFP_Pos)           /*!< GPA_MFP PA1 setting for SPI_SSB01   \hideinitializer */

//GPA_MFP_PA2MFP
#define SYS_GPA_MFP_PA2MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA2MFP_Pos)           /*!< GPA_MFP PA2 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA2MFP_SPI_SCLK0   (0x1UL<<SYS_GPA_MFP_PA2MFP_Pos)           /*!< GPA_MFP PA2 setting for SPI_SCLK0   \hideinitializer */

//GPA_MFP_PA3MFP
#define SYS_GPA_MFP_PA3MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA3MFP_Pos)           /*!< GPA_MFP PA3 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA3MFP_SPI_MISO0   (0x1UL<<SYS_GPA_MFP_PA3MFP_Pos)           /*!< GPA_MFP PA3 setting for SPI_MISO0   \hideinitializer */

//GPA_MFP_PA4MFP
#define SYS_GPA_MFP_PA4MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA4MFP_Pos)           /*!< GPA_MFP PA4 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA4MFP_SPI_MOSI0   (0x1UL<<SYS_GPA_MFP_PA4MFP_Pos)           /*!< GPA_MFP PA4 setting for SPI_MOSI0   \hideinitializer */

//GPA_MFP_PA5MFP
#define SYS_GPA_MFP_PA5MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA5MFP_Pos)           /*!< GPA_MFP PA5 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA5MFP_TM0         (0x1UL<<SYS_GPA_MFP_PA5MFP_Pos)           /*!< GPA_MFP PA5 setting for TM0   \hideinitializer */

//GPA_MFP_PA6MFP
#define SYS_GPA_MFP_PA6MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA6MFP_Pos)           /*!< GPA_MFP PA6 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA6MFP_INT0        (0x1UL<<SYS_GPA_MFP_PA6MFP_Pos)           /*!< GPA_MFP PA6 setting for INT0   \hideinitializer */

//GPA_MFP_PA7MFP
#define SYS_GPA_MFP_PA7MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA7MFP_Pos)           /*!< GPA_MFP PA7 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA7MFP_STADC       (0x1UL<<SYS_GPA_MFP_PA7MFP_Pos)           /*!< GPA_MFP PA7 setting for STADC   \hideinitializer */

//GPA_MFP_PA8MFP
#define SYS_GPA_MFP_PA8MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA8MFP_Pos)           /*!< GPA_MFP PA8 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA8MFP_ADC0        (0x1UL<<SYS_GPA_MFP_PA8MFP_Pos)           /*!< GPA_MFP PA8 setting for ADC0   \hideinitializer */

//GPA_MFP_PA9MFP
#define SYS_GPA_MFP_PA9MFP_GPIO        (0x0UL<<SYS_GPA_MFP_PA9MFP_Pos)           /*!< GPA_MFP PA9 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA9MFP_ADC1        (0x1UL<<SYS_GPA_MFP_PA9MFP_Pos)           /*!< GPA_MFP PA9 setting for ADC1   \hideinitializer */

//GPA_MFP_PA10MFP
#define SYS_GPA_MFP_PA10MFP_GPIO       (0x0UL<<SYS_GPA_MFP_PA10MFP_Pos)          /*!< GPA_MFP PA10 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA10MFP_ADC2       (0x1UL<<SYS_GPA_MFP_PA10MFP_Pos)          /*!< GPA_MFP PA10 setting for ADC2   \hideinitializer */

//GPA_MFP_PA11MFP
#define SYS_GPA_MFP_PA11MFP_GPIO       (0x0UL<<SYS_GPA_MFP_PA11MFP_Pos)          /*!< GPA_MFP PA11 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA11MFP_ADC3       (0x1UL<<SYS_GPA_MFP_PA11MFP_Pos)          /*!< GPA_MFP PA11 setting for ADC3   \hideinitializer */

//GPA_MFP_PA12MFP
#define SYS_GPA_MFP_PA12MFP_GPIO       (0x0UL<<SYS_GPA_MFP_PA12MFP_Pos)          /*!< GPA_MFP PA12 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA12MFP_ADC4       (0x1UL<<SYS_GPA_MFP_PA12MFP_Pos)          /*!< GPA_MFP PA12 setting for ADC4   \hideinitializer */

//GPA_MFP_PA13MFP
#define SYS_GPA_MFP_PA13MFP_GPIO       (0x0UL<<SYS_GPA_MFP_PA13MFP_Pos)          /*!< GPA_MFP PA13 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA13MFP_ADC5       (0x1UL<<SYS_GPA_MFP_PA13MFP_Pos)          /*!< GPA_MFP PA13 setting for ADC5   \hideinitializer */

//GPA_MFP_PA14MFP
#define SYS_GPA_MFP_PA14MFP_GPIO       (0x0UL<<SYS_GPA_MFP_PA14MFP_Pos)          /*!< GPA_MFP PA14 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA14MFP_ADC6       (0x1UL<<SYS_GPA_MFP_PA14MFP_Pos)          /*!< GPA_MFP PA14 setting for ADC6   \hideinitializer */

//GPA_MFP_PA15MFP
#define SYS_GPA_MFP_PA15MFP_GPIO       (0x0UL<<SYS_GPA_MFP_PA15MFP_Pos)          /*!< GPA_MFP PA15 setting for GPIO   \hideinitializer */
#define SYS_GPA_MFP_PA15MFP_ADC7       (0x1UL<<SYS_GPA_MFP_PA15MFP_Pos)          /*!< GPA_MFP PA15 setting for ADC7   \hideinitializer */

//GPB_MFP_PB0MFP
#define SYS_GPB_MFP_PB0MFP_GPIO        (0x0UL<<SYS_GPB_MFP_PB0MFP_Pos)           /*!< GPB_MFP PB0 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB0MFP_SPI_SSB11   (0x1UL<<SYS_GPB_MFP_PB0MFP_Pos)           /*!< GPB_MFP PB0 setting for SPI_SSB11   \hideinitializer */

//GPB_MFP_PB1MFP
#define SYS_GPB_MFP_PB1MFP_GPIO        (0x0UL<<SYS_GPB_MFP_PB1MFP_Pos)           /*!< GPB_MFP PB1 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB1MFP_SPI_SSB10   (0x1UL<<SYS_GPB_MFP_PB1MFP_Pos)           /*!< GPB_MFP PB1 setting for SPI_SSB10   \hideinitializer */

//GPB_MFP_PB2MFP
#define SYS_GPB_MFP_PB2MFP_GPIO        (0x0UL<<SYS_GPB_MFP_PB2MFP_Pos)           /*!< GPB_MFP PB2 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB2MFP_SPI_SCLK1   (0x1UL<<SYS_GPB_MFP_PB2MFP_Pos)           /*!< GPB_MFP PB2 setting for SPI_SCLK1   \hideinitializer */

//GPB_MFP_PB3MFP
#define SYS_GPB_MFP_PB3MFP_GPIO        (0x0UL<<SYS_GPB_MFP_PB3MFP_Pos)           /*!< GPB_MFP PB3 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB3MFP_SPI_MISO1   (0x1UL<<SYS_GPB_MFP_PB3MFP_Pos)           /*!< GPB_MFP PB3 setting for SPI_MISO1   \hideinitializer */

//GPB_MFP_PB4MFP
#define SYS_GPB_MFP_PB4MFP_GPIO        (0x0UL<<SYS_GPB_MFP_PB4MFP_Pos)           /*!< GPB_MFP PB4 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB4MFP_SPI_MOSI1   (0x1UL<<SYS_GPB_MFP_PB4MFP_Pos)           /*!< GPB_MFP PB4 setting for SPI_MOSI1   \hideinitializer */

//GPB_MFP_PB8MFP
#define SYS_GPB_MFP_PB8MFP_GPIO        (0x0UL<<SYS_GPB_MFP_PB8MFP_Pos)           /*!< GPB_MFP PB8 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB8MFP_PWM0        (0x1UL<<SYS_GPB_MFP_PB8MFP_Pos)           /*!< GPB_MFP PB8 setting for PWM0   \hideinitializer */

//GPB_MFP_PB9MFP
#define SYS_GPB_MFP_PB9MFP_GPIO        (0x0UL<<SYS_GPB_MFP_PB9MFP_Pos)           /*!< GPB_MFP PB9 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB9MFP_PWM1        (0x1UL<<SYS_GPB_MFP_PB9MFP_Pos)           /*!< GPB_MFP PB9 setting for PWM1   \hideinitializer */

//GPB_MFP_PB10MFP
#define SYS_GPB_MFP_PB10MFP_GPIO       (0x0UL<<SYS_GPB_MFP_PB10MFP_Pos)          /*!< GPB_MFP PB10 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB10MFP_PWM2       (0x1UL<<SYS_GPB_MFP_PB10MFP_Pos)          /*!< GPB_MFP PB10 setting for PWM2   \hideinitializer */

//GPB_MFP_PB11MFP
#define SYS_GPB_MFP_PB11MFP_GPIO       (0x0UL<<SYS_GPB_MFP_PB11MFP_Pos)           /*!< GPB_MFP PB11 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB11MFP_PWM3       (0x1UL<<SYS_GPB_MFP_PB11MFP_Pos)           /*!< GPB_MFP PB11 setting for PWM3   \hideinitializer */

//GPB_MFP_PB12MFP
#define SYS_GPB_MFP_PB12MFP_GPIO       (0x0UL<<SYS_GPB_MFP_PB12MFP_Pos)           /*!< GPB_MFP PB12 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB12MFP_CPR0       (0x1UL<<SYS_GPB_MFP_PB12MFP_Pos)           /*!< GPB_MFP PB12 setting for CPR0   \hideinitializer */

//GPB_MFP_PB13MFP
#define SYS_GPB_MFP_PB13MFP_GPIO       (0x0UL<<SYS_GPB_MFP_PB13MFP_Pos)           /*!< GPB_MFP PB13 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB13MFP_IROUT      (0x1UL<<SYS_GPB_MFP_PB13MFP_Pos)           /*!< GPB_MFP PB13 setting for IROUT   \hideinitializer */

//GPB_MFP_PB14MFP
#define SYS_GPB_MFP_PB14MFP_GPIO       (0x0UL<<SYS_GPB_MFP_PB14MFP_Pos)           /*!< GPB_MFP PB14 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB14MFP_TM1        (0x1UL<<SYS_GPB_MFP_PB14MFP_Pos)           /*!< GPB_MFP PB14 setting for TM1   \hideinitializer */

//GPB_MFP_PB15MFP
#define SYS_GPB_MFP_PB15MFP_GPIO       (0x0UL<<SYS_GPB_MFP_PB15MFP_Pos)           /*!< GPB_MFP PB15 setting for GPIO   \hideinitializer */
#define SYS_GPB_MFP_PB15MFP_TM2        (0x1UL<<SYS_GPB_MFP_PB15MFP_Pos)           /*!< GPB_MFP PB15 setting for TM2   \hideinitializer */

/*@}*/ /* end of group N572_SYS_EXPORTED_CONSTANTS */

/** @addtogroup N572_SYS_EXPORTED_FUNCTIONS SYS Exported Functions
  @{
*/

#define SYS_IS_POR_RST()                   (SYS->RSTSTS & SYS_RSTSTS_PORF_Msk)    /*!< This macro get previous reset source is from Power-on Reset   \hideinitializer */
#define SYS_IS_PIN_RST()                   (SYS->RSTSTS & SYS_RSTSTS_PINRF_Msk)   /*!< This macro get previous reset source is from Pin reset   \hideinitializer */
#define SYS_IS_WDT_RST()                   (SYS->RSTSTS & SYS_RSTSTS_WDTRF_Msk)   /*!< This macro get previous reset source is from Watch dog reset   \hideinitializer */
#define SYS_IS_LV_RST()                    (SYS->RSTSTS & SYS_RSTSTS_LVRF_Msk)    /*!< This macro get previous reset source is from Lower voltage reset   \hideinitializer */
#define SYS_IS_PMU_RST()                   (SYS->RSTSTS & SYS_RSTSTS_PMURSTF_Msk) /*!< This macro get previous reset source is from Power manager unit reset   \hideinitializer */
#if( __CHIP_SERIES__ == __N572F065_SERIES__ )
#define SYS_IS_MCU_RST()                   (SYS->RSTSTS & SYS_RSTSTS_MCURF_Msk)   /*!< This macro get previous reset source is from Power manager unit reset   \hideinitializer */
#endif

#define SYS_CLEAR_RST_SOURCE(u32RSTSTS)    (SYS->RSTSTS = u32RSTSTS )             /*!< This macro clears reset source   \hideinitializer */

#define SYS_SET_RAM_WAIT_STATE(u32State)   SYS_SetRamWaitSate(u32State) 
#define SYS_SET_CPU_WAIT_STATE(u32State)   SYS_SetCpuWaiState(u32State) 
#define SYS_SET_RAM_CPU_WAIT_STATE(u32RamWaitState, u32CpuWaitState)   SYS_SetRamCpuWaitState(u32RamWaitState, u32CpuWaitState)

#define SYS_GET_BOD_OUTPUT()               (SYS->BODCTL & SYS_BODCTL_BOD_OUT_Msk)       /*!< This macro get Brown-out detector output status \hideinitializer */
#define SYS_DISABLE_LVR()                  SYS_DisableLVR()                             /*!< This macro disable Low-Voltage Reset function \hideinitializer */
#define SYS_ENABLE_LVR()                   SYS_EnableLVR()                              /*!< This macro enable Low-Voltage Reset function \hideinitializer */

#define SYS_DISABLE_POR()                  SYS_DisablePOR()                             /*!< This macro disable Power-on Reset function \hideinitializer */
#define SYS_ENABLE_POR()                   SYS_EnablePOR()                              /*!< This macro enable Power-on Reset function \hideinitializer */

#define SYS_SET_SCHMITT_GPIOA(u32Bit)      (SYS->GPA_MFP | u32Bit)                      /*!< This macro set GPIOA(0-15) schmitt mode   \hideinitializer */
#define SYS_CLR_SCHMITT_GPIOA()            (SYS->GPA_MFP & (~SYS_GPA_MFP_PAnTYPEn_Msk)) /*!< This macro clear all GPIOA pin schmitt mode   \hideinitializer */
#define SYS_SET_SCHMITT_GPIOB(u32Bit)      (SYS->GPB_MFP | u32Bit)                      /*!< This macro set GPIOB(0-15) schmitt mode   \hideinitializer */
#define SYS_CLR_SCHMITT_GPIOB()            (SYS->GPB_MFP & (~SYS_GPB_MFP_PBnTYPEn_Msk)) /*!< This macro clear all GPIOB pin schmitt mode   \hideinitializer */

#if( __CHIP_SERIES__ == __N572F072_SERIES__ )
#define SYS_ENABLE_GPIOA_HST()             (SYS->GPA_HS = 0x1F)                         /*!< This macro set GPIOA pin0~pin4 high speed transition for SPI0 up to 48MHz   \hideinitializer */
#define SYS_DISABLE_GPIOA_HST()            (SYS->GPA_HS = 0x00)                         /*!< This macro set GPIOA pin0~pin4 normal speed transition for SPI0 less than 15MHz.   \hideinitializer */
#endif

void SYS_EnableBOD(uint32_t u32BODLevel);
void SYS_DisableBOD(void);
void SYS_ClearResetSrc(uint32_t u32Src);
uint32_t SYS_GetResetSrc(void);
uint32_t SYS_IsRegLocked(void);
void SYS_LockReg(void);
void SYS_Lock(uint8_t u8Lock);
void SYS_UnlockReg(void);
uint8_t SYS_Unlock(void);
uint32_t SYS_ReadPDID(void);
void SYS_ResetChip(void);
void SYS_ResetCPU(void);
void SYS_ResetModule(uint32_t u32ModuleIndex);
void SYS_SetRamWaitSate(uint32_t u32RamWaitState);
void SYS_SetCpuWaiState(uint32_t u32CpuWaitState);
void SYS_SetRamCpuWaitState(uint32_t u32RamWaitState, uint32_t u32CpuWaitState);
void SYS_DisableLVR(void);
void SYS_EnableLVR(void);
void SYS_DisablePOR(void);
void SYS_EnablePOR(void);

/*@}*/ /* end of group N572_SYS_EXPORTED_FUNCTIONS */

/*@}*/ /* end of group N572_SYS_Driver */

/*@}*/ /* end of group N572_Device_Driver */


#ifdef __cplusplus
}
#endif

#endif //__SYS_H__

/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
