sys.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /**************************************************************************//**
  2. * @file SYS.h
  3. * @version V2.1
  4. * $Revision: 10 $
  5. * $Date: 14/02/05 1:17p $
  6. * @brief M051 Series Global Control and Clock Control Driver Header File
  7. *
  8. * @note
  9. * Copyright (C) 2011 Nuvoton Technology Corp. All rights reserved.
  10. *
  11. ******************************************************************************/
  12. #ifndef __SYS_H__
  13. #define __SYS_H__
  14. #include "M051Series.h"
  15. #ifdef __cplusplus
  16. extern "C"
  17. {
  18. #endif
  19. /** @addtogroup M051_Device_Driver M051 Device Driver
  20. @{
  21. */
  22. /** @addtogroup M051_SYS_Driver SYS Driver
  23. @{
  24. */
  25. /** @addtogroup M051_SYS_EXPORTED_CONSTANTS SYS Exported Constants
  26. @{
  27. */
  28. /*---------------------------------------------------------------------------------------------------------*/
  29. /* Module Reset Control Resister constant definitions. */
  30. /*---------------------------------------------------------------------------------------------------------*/
  31. #define CHIP_RST ((0x0<<24) | SYS_IPRSTC1_CPU_RST_Pos ) /*!< CPU reset is one of the SYS_ResetModule parameter */
  32. #define CPU_RST ((0x0<<24) | SYS_IPRSTC1_CHIP_RST_Pos ) /*!< CHIP reset is one of the SYS_ResetModule parameter */
  33. #define EBI_RST ((0x0<<24) | SYS_IPRSTC1_EBI_RST_Pos ) /*!< EBI reset is one of the SYS_ResetModule parameter */
  34. #define HDIV_RST ((0x0<<24) | SYS_IPRSTC1_HDIV_RST_Pos ) /*!< HDIV reset is one of the SYS_ResetModule parameter */
  35. #define GPIO_RST ((0x4<<24) | SYS_IPRSTC2_GPIO_RST_Pos ) /*!< GPIO reset is one of the SYS_ResetModule parameter */
  36. #define TMR0_RST ((0x4<<24) | SYS_IPRSTC2_TMR0_RST_Pos ) /*!< TMR0 reset is one of the SYS_ResetModule parameter */
  37. #define TMR1_RST ((0x4<<24) | SYS_IPRSTC2_TMR1_RST_Pos ) /*!< TMR1 reset is one of the SYS_ResetModule parameter */
  38. #define TMR2_RST ((0x4<<24) | SYS_IPRSTC2_TMR2_RST_Pos ) /*!< TMR2 reset is one of the SYS_ResetModule parameter */
  39. #define TMR3_RST ((0x4<<24) | SYS_IPRSTC2_TMR3_RST_Pos ) /*!< TMR3 reset is one of the SYS_ResetModule parameter */
  40. #define I2C0_RST ((0x4<<24) | SYS_IPRSTC2_I2C0_RST_Pos ) /*!< I2C0 reset is one of the SYS_ResetModule parameter */
  41. #define I2C1_RST ((0x4<<24) | SYS_IPRSTC2_I2C1_RST_Pos ) /*!< I2C1 reset is one of the SYS_ResetModule parameter */
  42. #define SPI0_RST ((0x4<<24) | SYS_IPRSTC2_SPI0_RST_Pos ) /*!< SPI0 reset is one of the SYS_ResetModule parameter */
  43. #define SPI1_RST ((0x4<<24) | SYS_IPRSTC2_SPI1_RST_Pos ) /*!< SPI1 reset is one of the SYS_ResetModule parameter */
  44. #define UART0_RST ((0x4<<24) | SYS_IPRSTC2_UART0_RST_Pos ) /*!< UART0 reset is one of the SYS_ResetModule parameter */
  45. #define UART1_RST ((0x4<<24) | SYS_IPRSTC2_UART1_RST_Pos ) /*!< UART1 reset is one of the SYS_ResetModule parameter */
  46. #define PWM03_RST ((0x4<<24) | SYS_IPRSTC2_PWM03_RST_Pos ) /*!< PWM03 reset is one of the SYS_ResetModule parameter */
  47. #define PWM47_RST ((0x4<<24) | SYS_IPRSTC2_PWM47_RST_Pos ) /*!< PWM47 reset is one of the SYS_ResetModule parameter */
  48. #define ACMP01_RST ((0x4<<24) | SYS_IPRSTC2_ACMP01_RST_Pos ) /*!< ACMP01 reset is one of the SYS_ResetModule parameter */
  49. #define ACMP23_RST ((0x4<<24) | SYS_IPRSTC2_ACMP23_RST_Pos ) /*!< ACMP23 reset is one of the SYS_ResetModule parameter */
  50. #define ADC_RST ((0x4<<24) | SYS_IPRSTC2_ADC_RST_Pos ) /*!< ADC reset is one of the SYS_ResetModule parameter */
  51. /*---------------------------------------------------------------------------------------------------------*/
  52. /* Brown Out Detector Threshold Voltage Selection constant definitions. */
  53. /*---------------------------------------------------------------------------------------------------------*/
  54. #define SYS_BODCR_BOD_RST_EN (1UL<<SYS_BODCR_BOD_RSTEN_Pos) /*!< Brown-out Reset Enable */
  55. #define SYS_BODCR_BOD_INTERRUPT_EN (0UL<<SYS_BODCR_BOD_RSTEN_Pos) /*!< Brown-out Interrupt Enable */
  56. #define SYS_BODCR_BOD_VL_4_4V (3UL<<SYS_BODCR_BOD_VL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 4.4V */
  57. #define SYS_BODCR_BOD_VL_3_7V (2UL<<SYS_BODCR_BOD_VL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 3.7V */
  58. #define SYS_BODCR_BOD_VL_2_7V (1UL<<SYS_BODCR_BOD_VL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 2.7V */
  59. #define SYS_BODCR_BOD_VL_2_2V (0UL<<SYS_BODCR_BOD_VL_Pos) /*!< Setting Brown Out Detector Threshold Voltage as 2.2V */
  60. /*---------------------------------------------------------------------------------------------------------*/
  61. /* Multi-Function constant definitions. */
  62. /*---------------------------------------------------------------------------------------------------------*/
  63. #define SYS_MFP_TYPE_Msk(bit) (1UL << ((bit) +16))
  64. #define SYS_MFP_ALT_Msk(bit) (1UL << ((bit) + 8))
  65. #define SYS_MFP_MFP_Msk(bit) (1UL << ((bit) ))
  66. #define SYS_MFP_P00_GPIO 0x00000000UL /*!< P0_MFP pin 0 setting for GPIO */
  67. #define SYS_MFP_P00_AD0 0x00000001UL /*!< P0_MFP pin 0 setting for AD0 */
  68. #define SYS_MFP_P00_CTS1 0x00000100UL /*!< P0_MFP pin 0 setting for CTS1 */
  69. #define SYS_MFP_P00_TXD1 0x00000101UL /*!< P0_MFP pin 0 setting for TXD1 */
  70. #define SYS_MFP_P00_ACMP3_P 0x01000000UL /*!< P0_MFP pin 0 setting for ACMP3_P */
  71. #define SYS_MFP_P00_Msk 0x01000101UL /*!< P0_MFP pin 0 mask */
  72. #define SYS_MFP_P01_GPIO 0x00000000UL /*!< P0_MFP pin 1 setting for GPIO */
  73. #define SYS_MFP_P01_AD1 0x00000002UL /*!< P0_MFP pin 1 setting for AD1 */
  74. #define SYS_MFP_P01_RTS1 0x00000200UL /*!< P0_MFP pin 1 setting for RTS1 */
  75. #define SYS_MFP_P01_RXD1 0x00000202UL /*!< P0_MFP pin 1 setting for RXD1 */
  76. #define SYS_MFP_P01_ACMP3_N 0x02000000UL /*!< P0_MFP pin 1 setting for ACMP3_N */
  77. #define SYS_MFP_P01_Msk 0x02000202UL /*!< P0_MFP pin 1 mask */
  78. #define SYS_MFP_P02_GPIO 0x00000000UL /*!< P0_MFP pin 2 setting for GPIO */
  79. #define SYS_MFP_P02_AD2 0x00000004UL /*!< P0_MFP pin 2 setting for AD2 */
  80. #define SYS_MFP_P02_CTS0 0x00000400UL /*!< P0_MFP pin 2 setting for CTS0 */
  81. #define SYS_MFP_P02_TXD0 0x00000404UL /*!< P0_MFP pin 2 setting for TXD0 */
  82. #define SYS_MFP_P02_Msk 0x00000404UL /*!< P0_MFP pin 2 mask */
  83. #define SYS_MFP_P03_GPIO 0x00000000UL /*!< P0_MFP pin 3 setting for GPIO */
  84. #define SYS_MFP_P03_AD3 0x00000008UL /*!< P0_MFP pin 3 setting for AD3 */
  85. #define SYS_MFP_P03_RTS0 0x00000800UL /*!< P0_MFP pin 3 setting for RTS0 */
  86. #define SYS_MFP_P03_RXD0 0x00000808UL /*!< P0_MFP pin 3 setting for RXD0 */
  87. #define SYS_MFP_P03_Msk 0x00000808UL /*!< P0_MFP pin 3 mask */
  88. #define SYS_MFP_P04_GPIO 0x00000000UL /*!< P0_MFP pin 4 setting for GPIO */
  89. #define SYS_MFP_P04_AD4 0x00000010UL /*!< P0_MFP pin 4 setting for AD4 */
  90. #define SYS_MFP_P04_SPISS1 0x00001000UL /*!< P0_MFP pin 4 setting for SPISS1 */
  91. #define SYS_MFP_P04_Msk 0x00001010UL /*!< P0_MFP pin 4 mask */
  92. #define SYS_MFP_P05_GPIO 0x00000000UL /*!< P0_MFP pin 5 setting for GPIO */
  93. #define SYS_MFP_P05_AD5 0x00000020UL /*!< P0_MFP pin 5 setting for AD5 */
  94. #define SYS_MFP_P05_MOSI_1 0x00002000UL /*!< P0_MFP pin 5 setting for MOSI_1 */
  95. #define SYS_MFP_P05_Msk 0x00002020UL /*!< P0_MFP pin 5 mask */
  96. #define SYS_MFP_P06_GPIO 0x00000000UL /*!< P0_MFP pin 6 setting for GPIO */
  97. #define SYS_MFP_P06_AD6 0x00000040UL /*!< P0_MFP pin 6 setting for AD6 */
  98. #define SYS_MFP_P06_MISO_1 0x00004000UL /*!< P0_MFP pin 6 setting for MISO_1 */
  99. #define SYS_MFP_P06_Msk 0x00004040UL /*!< P0_MFP pin 6 mask */
  100. #define SYS_MFP_P07_GPIO 0x00000000UL /*!< P0_MFP pin 7 setting for GPIO */
  101. #define SYS_MFP_P07_AD7 0x00000080UL /*!< P0_MFP pin 7 setting for AD7 */
  102. #define SYS_MFP_P07_SPICLK1 0x00008000UL /*!< P0_MFP pin 7 setting for SPICLK1 */
  103. #define SYS_MFP_P07_Msk 0x00008080UL /*!< P0_MFP pin 7 mask */
  104. #define SYS_MFP_P10_GPIO 0x00000000UL /*!< P1_MFP pin 0 setting for GPIO */
  105. #define SYS_MFP_P10_AIN0 0x00000001UL /*!< P1_MFP pin 0 setting for AIN0 */
  106. #define SYS_MFP_P10_T2 0x00000100UL /*!< P1_MFP pin 0 setting for T2 */
  107. #define SYS_MFP_P10_nWRL 0x00000101UL /*!< P1_MFP pin 0 setting for nWRL */
  108. #define SYS_MFP_P10_Msk 0x00000101UL /*!< P1_MFP pin 0 mask */
  109. #define SYS_MFP_P11_GPIO 0x00000000UL /*!< P1_MFP pin 1 setting for GPIO */
  110. #define SYS_MFP_P11_AIN1 0x00000002UL /*!< P1_MFP pin 1 setting for AIN1 */
  111. #define SYS_MFP_P11_T3 0x00000200UL /*!< P1_MFP pin 1 setting for T3 */
  112. #define SYS_MFP_P11_nWRH 0x00000202UL /*!< P1_MFP pin 1 setting for nWRH */
  113. #define SYS_MFP_P11_Msk 0x00000202UL /*!< P1_MFP pin 1 mask */
  114. #define SYS_MFP_P12_GPIO 0x00000000UL /*!< P1_MFP pin 2 setting for GPIO */
  115. #define SYS_MFP_P12_AIN2 0x00000004UL /*!< P1_MFP pin 2 setting for AIN2 */
  116. #define SYS_MFP_P12_RXD1 0x00000400UL /*!< P1_MFP pin 2 setting for RXD1 */
  117. #define SYS_MFP_P12_Msk 0x00000404UL /*!< P1_MFP pin 2 mask */
  118. #define SYS_MFP_P13_GPIO 0x00000000UL /*!< P1_MFP pin 3 setting for GPIO */
  119. #define SYS_MFP_P13_AIN3 0x00000008UL /*!< P1_MFP pin 3 setting for AIN3 */
  120. #define SYS_MFP_P13_TXD1 0x00000800UL /*!< P1_MFP pin 3 setting for TXD1 */
  121. #define SYS_MFP_P13_Msk 0x00000808UL /*!< P1_MFP pin 3 mask */
  122. #define SYS_MFP_P14_GPIO 0x00000000UL /*!< P1_MFP pin 4 setting for GPIO */
  123. #define SYS_MFP_P14_AIN4 0x00000010UL /*!< P1_MFP pin 4 setting for AIN4 */
  124. #define SYS_MFP_P14_SPISS0 0x00001000UL /*!< P1_MFP pin 4 setting for SPISS0 */
  125. #define SYS_MFP_P14_CPN0 0x00001010UL /*!< P1_MFP pin 4 setting for CPN0 */
  126. #define SYS_MFP_P14_ACMP0_N 0x00001010UL /*!< P1_MFP pin 4 setting for ACMP0_N */
  127. #define SYS_MFP_P14_Msk 0x00001010UL /*!< P1_MFP pin 4 mask */
  128. #define SYS_MFP_P15_GPIO 0x00000000UL /*!< P1_MFP pin 5 setting for GPIO */
  129. #define SYS_MFP_P15_AIN5 0x00000020UL /*!< P1_MFP pin 5 setting for AIN5 */
  130. #define SYS_MFP_P15_MOSI_0 0x00002000UL /*!< P1_MFP pin 5 setting for MOSI_0 */
  131. #define SYS_MFP_P15_CPP0 0x00002020UL /*!< P1_MFP pin 5 setting for CPP0 */
  132. #define SYS_MFP_P15_ACMP0_P 0x00002020UL /*!< P1_MFP pin 5 setting for ACMP0_P */
  133. #define SYS_MFP_P15_Msk 0x00002020UL /*!< P1_MFP pin 5 mask */
  134. #define SYS_MFP_P16_GPIO 0x00000000UL /*!< P1_MFP pin 6 setting for GPIO */
  135. #define SYS_MFP_P16_AIN6 0x00000040UL /*!< P1_MFP pin 6 setting for AIN6 */
  136. #define SYS_MFP_P16_MISO_0 0x00004000UL /*!< P1_MFP pin 6 setting for MISO_0 */
  137. #define SYS_MFP_P16_ACMP2_N 0x00004040UL /*!< P1_MFP pin 6 setting for ACMP2_N */
  138. #define SYS_MFP_P16_Msk 0x00004040UL /*!< P1_MFP pin 6 mask */
  139. #define SYS_MFP_P17_GPIO 0x00000000UL /*!< P1_MFP pin 7 setting for GPIO */
  140. #define SYS_MFP_P17_AIN7 0x00000080UL /*!< P1_MFP pin 7 setting for AIN7 */
  141. #define SYS_MFP_P17_SPICLK0 0x00008000UL /*!< P1_MFP pin 7 setting for SPICLK0 */
  142. #define SYS_MFP_P17_ACMP2_P 0x00008080UL /*!< P1_MFP pin 7 setting for ACMP2_P */
  143. #define SYS_MFP_P17_Msk 0x00008080UL /*!< P1_MFP pin 7 mask */
  144. #define SYS_MFP_P20_GPIO 0x00000000UL /*!< P2_MFP pin 0 setting for GPIO */
  145. #define SYS_MFP_P20_AD8 0x00000001UL /*!< P2_MFP pin 0 setting for AD8 */
  146. #define SYS_MFP_P20_PWM0 0x00000100UL /*!< P2_MFP pin 0 setting for PWM0 */
  147. #define SYS_MFP_P20_Msk 0x00000101UL /*!< P2_MFP pin 0 mask */
  148. #define SYS_MFP_P21_GPIO 0x00000000UL /*!< P2_MFP pin 1 setting for GPIO */
  149. #define SYS_MFP_P21_AD9 0x00000002UL /*!< P2_MFP pin 1 setting for AD9 */
  150. #define SYS_MFP_P21_PWM1 0x00000200UL /*!< P2_MFP pin 1 setting for PWM1 */
  151. #define SYS_MFP_P21_Msk 0x00000202UL /*!< P2_MFP pin 1 mask */
  152. #define SYS_MFP_P22_GPIO 0x00000000UL /*!< P2_MFP pin 2 setting for GPIO */
  153. #define SYS_MFP_P22_AD10 0x00000004UL /*!< P2_MFP pin 2 setting for AD10 */
  154. #define SYS_MFP_P22_PWM2 0x00000400UL /*!< P2_MFP pin 2 setting for PWM2 */
  155. #define SYS_MFP_P22_Msk 0x00000404UL /*!< P2_MFP pin 2 mask */
  156. #define SYS_MFP_P23_GPIO 0x00000000UL /*!< P2_MFP pin 3 setting for GPIO */
  157. #define SYS_MFP_P23_AD11 0x00000008UL /*!< P2_MFP pin 3 setting for AD11 */
  158. #define SYS_MFP_P23_PWM3 0x00000800UL /*!< P2_MFP pin 3 setting for PWM3 */
  159. #define SYS_MFP_P23_Msk 0x00000808UL /*!< P2_MFP pin 3 mask */
  160. #define SYS_MFP_P24_GPIO 0x00000000UL /*!< P2_MFP pin 4 setting for GPIO */
  161. #define SYS_MFP_P24_AD12 0x00000010UL /*!< P2_MFP pin 4 setting for AD12 */
  162. #define SYS_MFP_P24_PWM4 0x00001000UL /*!< P2_MFP pin 4 setting for PWM4 */
  163. #define SYS_MFP_P24_SCL1 0x00001010UL /*!< P2_MFP pin 4 setting for SCL1 */
  164. #define SYS_MFP_P24_Msk 0x00001010UL /*!< P2_MFP pin 4 mask */
  165. #define SYS_MFP_P25_GPIO 0x00000000UL /*!< P2_MFP pin 5 setting for GPIO */
  166. #define SYS_MFP_P25_AD13 0x00000020UL /*!< P2_MFP pin 5 setting for AD13 */
  167. #define SYS_MFP_P25_PWM5 0x00002000UL /*!< P2_MFP pin 5 setting for PWM5 */
  168. #define SYS_MFP_P25_SDA1 0x00002020UL /*!< P2_MFP pin 5 setting for SDA1 */
  169. #define SYS_MFP_P25_Msk 0x00002020UL /*!< P2_MFP pin 5 mask */
  170. #define SYS_MFP_P26_GPIO 0x00000000UL /*!< P2_MFP pin 6 setting for GPIO */
  171. #define SYS_MFP_P26_AD14 0x00000040UL /*!< P2_MFP pin 6 setting for AD14 */
  172. #define SYS_MFP_P26_PWM6 0x00004000UL /*!< P2_MFP pin 6 setting for PWM6 */
  173. #define SYS_MFP_P26_CPO1 0x00004040UL /*!< P2_MFP pin 6 setting for CPO1 */
  174. #define SYS_MFP_P26_ACMP1_O 0x00004040UL /*!< P2_MFP pin 6 setting for ACMP1_O */
  175. #define SYS_MFP_P26_Msk 0x00004040UL /*!< P2_MFP pin 6 mask */
  176. #define SYS_MFP_P27_GPIO 0x00000000UL /*!< P2_MFP pin 7 setting for GPIO */
  177. #define SYS_MFP_P27_AD15 0x00000080UL /*!< P2_MFP pin 7 setting for AD15 */
  178. #define SYS_MFP_P27_PWM7 0x00008000UL /*!< P2_MFP pin 7 setting for PWM7 */
  179. #define SYS_MFP_P27_Msk 0x00008080UL /*!< P2_MFP pin 7 mask */
  180. #define SYS_MFP_P30_GPIO 0x00000000UL /*!< P3_MFP pin 0 setting for GPIO */
  181. #define SYS_MFP_P30_RXD0 0x00000001UL /*!< P3_MFP pin 0 setting for RXD0 */
  182. #define SYS_MFP_P30_CPN1 0x00000100UL /*!< P3_MFP pin 0 setting for CPN1 */
  183. #define SYS_MFP_P30_ACMP1_N 0x00000100UL /*!< P3_MFP pin 0 setting for ACMP1_N */
  184. #define SYS_MFP_P30_Msk 0x00000101UL /*!< P3_MFP pin 0 mask */
  185. #define SYS_MFP_P31_GPIO 0x00000000UL /*!< P3_MFP pin 1 setting for GPIO */
  186. #define SYS_MFP_P31_TXD0 0x00000002UL /*!< P3_MFP pin 1 setting for TXD0 */
  187. #define SYS_MFP_P31_CPP1 0x00000200UL /*!< P3_MFP pin 1 setting for CPP1 */
  188. #define SYS_MFP_P31_ACMP1_P 0x00000200UL /*!< P3_MFP pin 1 setting for ACMP1_P */
  189. #define SYS_MFP_P31_Msk 0x00000202UL /*!< P3_MFP pin 1 mask */
  190. #define SYS_MFP_P32_GPIO 0x00000000UL /*!< P3_MFP pin 2 setting for GPIO */
  191. #define SYS_MFP_P32_INT0 0x00000004UL /*!< P3_MFP pin 2 setting for /INT0 */
  192. #define SYS_MFP_P32_T0EX 0x00000400UL /*!< P3_MFP pin 2 setting for T0EX */
  193. #define SYS_MFP_P32_Msk 0x00000404UL /*!< P3_MFP pin 2 mask */
  194. #define SYS_MFP_P33_GPIO 0x00000000UL /*!< P3_MFP pin 3 setting for GPIO */
  195. #define SYS_MFP_P33_INT1 0x00000008UL /*!< P3_MFP pin 3 setting for /INT1 */
  196. #define SYS_MFP_P33_MCLK 0x00000800UL /*!< P3_MFP pin 3 setting for MCLK */
  197. #define SYS_MFP_P33_T1EX 0x00000808UL /*!< P3_MFP pin 3 setting for T1EX */
  198. #define SYS_MFP_P33_Msk 0x00000808UL /*!< P3_MFP pin 3 mask */
  199. #define SYS_MFP_P34_GPIO 0x00000000UL /*!< P3_MFP pin 4 setting for GPIO */
  200. #define SYS_MFP_P34_T0 0x00000010UL /*!< P3_MFP pin 4 setting for T0 */
  201. #define SYS_MFP_P34_SDA0 0x00001000UL /*!< P3_MFP pin 4 setting for SDA0 */
  202. #define SYS_MFP_P34_Msk 0x00001010UL /*!< P3_MFP pin 4 mask */
  203. #define SYS_MFP_P35_GPIO 0x00000000UL /*!< P3_MFP pin 5 setting for GPIO */
  204. #define SYS_MFP_P35_T1 0x00000020UL /*!< P3_MFP pin 5 setting for T1 */
  205. #define SYS_MFP_P35_SCL0 0x00002000UL /*!< P3_MFP pin 5 setting for SCL0 */
  206. #define SYS_MFP_P35_CKO 0x00002020UL /*!< P3_MFP pin 5 setting for CKO */
  207. #define SYS_MFP_P35_Msk 0x00002020UL /*!< P3_MFP pin 5 mask */
  208. #define SYS_MFP_P36_GPIO 0x00000000UL /*!< P3_MFP pin 6 setting for GPIO */
  209. #define SYS_MFP_P36_nWR 0x00000040UL /*!< P3_MFP pin 6 setting for nWR */
  210. #define SYS_MFP_P36_CKO 0x00004000UL /*!< P3_MFP pin 6 setting for CKO */
  211. #define SYS_MFP_P36_CPO0 0x00004040UL /*!< P3_MFP pin 6 setting for CPO0 */
  212. #define SYS_MFP_P36_ACMP0_O 0x00004040UL /*!< P3_MFP pin 6 setting for ACMP0_O */
  213. #define SYS_MFP_P36_Msk 0x00004040UL /*!< P3_MFP pin 6 mask */
  214. #define SYS_MFP_P37_GPIO 0x00000000UL /*!< P3_MFP pin 7 setting for GPIO */
  215. #define SYS_MFP_P37_nRD 0x00000080UL /*!< P3_MFP pin 7 setting for nWR */
  216. #define SYS_MFP_P37_Msk 0x00008080UL /*!< P3_MFP pin 7 mask */
  217. #define SYS_MFP_P40_GPIO 0x00000000UL /*!< P4_MFP pin 0 setting for GPIO */
  218. #define SYS_MFP_P40_PWM0 0x00000001UL /*!< P4_MFP pin 0 setting for PWM0 */
  219. #define SYS_MFP_P40_T2EX 0x00000100UL /*!< P4_MFP pin 0 setting for T2EX */
  220. #define SYS_MFP_P40_Msk 0x00000101UL /*!< P4_MFP pin 0 mask */
  221. #define SYS_MFP_P41_GPIO 0x00000000UL /*!< P4_MFP pin 1 setting for GPIO */
  222. #define SYS_MFP_P41_PWM1 0x00000002UL /*!< P4_MFP pin 1 setting for PWM1 */
  223. #define SYS_MFP_P41_T3EX 0x00000200UL /*!< P4_MFP pin 1 setting for T3EX */
  224. #define SYS_MFP_P41_Msk 0x00000202UL /*!< P4_MFP pin 1 mask */
  225. #define SYS_MFP_P42_GPIO 0x00000000UL /*!< P4_MFP pin 2 setting for GPIO */
  226. #define SYS_MFP_P42_PWM2 0x00000004UL /*!< P4_MFP pin 2 setting for PWM2 */
  227. #define SYS_MFP_P42_Msk 0x00000404UL /*!< P4_MFP pin 2 mask */
  228. #define SYS_MFP_P43_GPIO 0x00000000UL /*!< P4_MFP pin 3 setting for GPIO */
  229. #define SYS_MFP_P43_PWM3 0x00000008UL /*!< P4_MFP pin 3 setting for PWM3 */
  230. #define SYS_MFP_P43_Msk 0x00000808UL /*!< P4_MFP pin 3 mask */
  231. #define SYS_MFP_P44_GPIO 0x00000000UL /*!< P4_MFP pin 4 setting for GPIO */
  232. #define SYS_MFP_P44_nCS 0x00000010UL /*!< P4_MFP pin 4 setting for nCS */
  233. #define SYS_MFP_P44_SCL1 0x00001000UL /*!< P4_MFP pin 4 setting for SCL1 */
  234. #define SYS_MFP_P44_Msk 0x00001010UL /*!< P4_MFP pin 4 mask */
  235. #define SYS_MFP_P45_GPIO 0x00000000UL /*!< P4_MFP pin 5 setting for GPIO */
  236. #define SYS_MFP_P45_ALE 0x00000020UL /*!< P4_MFP pin 5 setting for ALE */
  237. #define SYS_MFP_P45_SDA1 0x00002000UL /*!< P4_MFP pin 5 setting for SDA1 */
  238. #define SYS_MFP_P45_Msk 0x00002020UL /*!< P4_MFP pin 5 mask */
  239. #define SYS_MFP_P46_GPIO 0x00000000UL /*!< P4_MFP pin 6 setting for GPIO */
  240. #define SYS_MFP_P46_ICE_CLK 0x00000040UL /*!< P4_MFP pin 6 setting for ICE_CLK */
  241. #define SYS_MFP_P46_Msk 0x00004040UL /*!< P4_MFP pin 6 mask */
  242. #define SYS_MFP_P47_GPIO 0x00000000UL /*!< P4_MFP pin 7 setting for GPIO */
  243. #define SYS_MFP_P47_ICE_DAT 0x00000080UL /*!< P4_MFP pin 7 setting for ICE_DAT */
  244. #define SYS_MFP_P47_Msk 0x00008080UL /*!< P4_MFP pin 7 mask */
  245. /*@}*/ /* end of group M051_SYS_EXPORTED_CONSTANTS */
  246. /** @addtogroup M051_SYS_EXPORTED_FUNCTIONS SYS Exported Functions
  247. @{
  248. */
  249. /**
  250. * @brief This macro clear Brown-out interrupt flag.
  251. * @return None
  252. */
  253. #define SYS_CLEAR_BOD_INT_FLAG() (SYS->BODCR |= SYS_BODCR_BOD_INTF_Msk)
  254. /**
  255. * @brief This macro set Brown-out detect to normal mode.
  256. * @return None
  257. */
  258. #define SYS_CLEAR_BOD_LPM() (SYS->BODCR &= ~SYS_BODCR_BOD_LPM_Msk)
  259. /**
  260. * @brief This macro disable Brown-out detect function.
  261. * @return None
  262. */
  263. #define SYS_DISABLE_BOD() (SYS->BODCR &= ~SYS_BODCR_BOD_EN_Msk)
  264. /**
  265. * @brief This macro enable Brown-out detect function.
  266. * @return None
  267. */
  268. #define SYS_ENABLE_BOD() (SYS->BODCR |= SYS_BODCR_BOD_EN_Msk)
  269. /**
  270. * @brief This macro get Brown-out detect interrupt flag.
  271. * @return 0: Brown-out detect interrupt flag is not set.
  272. * 1: Brown-out detect interrupt flag is set.
  273. */
  274. #define SYS_GET_BOD_INT_FLAG() ((SYS->BODCR & SYS_BODCR_BOD_INTF_Msk)>>SYS_BODCR_BOD_INTF_Pos)
  275. /**
  276. * @brief This macro get Brown-out detector output status.
  277. * @return 0: System voltage is higher than BOD_VL setting or BOD_EN is 0.
  278. * 1: System voltage is lower than BOD_VL setting.
  279. * @details If the BOD_EN is 0, this function always return 0.
  280. */
  281. #define SYS_GET_BOD_OUTPUT() ((SYS->BODCR & SYS_BODCR_BOD_OUT_Msk)>>SYS_BODCR_BOD_OUT_Msk)
  282. /**
  283. * @brief This macro enable Brown-out detect interrupt function.
  284. * @return None
  285. */
  286. #define SYS_DISABLE_BOD_RST() (SYS->BODCR &= ~SYS_BODCR_BOD_RSTEN_Msk)
  287. /**
  288. * @brief This macro enable Brown-out detect reset function.
  289. * @return None
  290. */
  291. #define SYS_ENABLE_BOD_RST() (SYS->BODCR |= SYS_BODCR_BOD_RSTEN_Msk)
  292. /**
  293. * @brief This macro set Brown-out detect to low power mode.
  294. * @return None
  295. */
  296. #define SYS_SET_BOD_LPM() (SYS->BODCR |= SYS_BODCR_BOD_LPM_Msk)
  297. /**
  298. * @brief This macro set Brown-out detect voltage level.
  299. * @param u32Level is Brown-out voltage level. Including :
  300. * - \ref SYS_BODCR_BOD_VL_4_4V
  301. * - \ref SYS_BODCR_BOD_VL_3_7V
  302. * - \ref SYS_BODCR_BOD_VL_2_7V
  303. * - \ref SYS_BODCR_BOD_VL_2_2V
  304. * @return None
  305. */
  306. #define SYS_SET_BOD_LEVEL(u32Level) (SYS->BODCR = (SYS->BODCR & ~SYS_BODCR_BOD_VL_Msk) | u32Level)
  307. /**
  308. * @brief This macro get previous reset source is from Brown-out detect reset.
  309. * @return 0: Previous reset source is not from Brown-out detect reset
  310. * 1: Previous reset source is from Brown-out detect reset
  311. */
  312. #define SYS_IS_BOD_RST() (SYS->RSTSRC & SYS_RSTSRC_RSTS_BOD_Msk)
  313. /**
  314. * @brief This macro get previous reset source is from Low-Voltage-Reset.
  315. * @return 0: Previous reset source is not from CPU reset
  316. * 1: Previous reset source is from CPU reset
  317. */
  318. #define SYS_IS_CPU_RST() (SYS->RSTSRC & SYS_RSTSRC_RSTS_CPU_Msk)
  319. /**
  320. * @brief This macro get previous reset source is from Power-on Reset.
  321. * @return 0: Previous reset source is not from Low-Voltage-Reset
  322. * 1: Previous reset source is from Low-Voltage-Reset
  323. */
  324. #define SYS_IS_POR_RST() (SYS->RSTSRC & SYS_RSTSRC_RSTS_POR_Msk)
  325. /**
  326. * @brief This macro get previous reset source is from reset pin reset.
  327. * @return 0: Previous reset source is not from Power-on Reset
  328. * 1: Previous reset source is from Power-on Reset
  329. */
  330. #define SYS_IS_RSTPIN_RST() (SYS->RSTSRC & SYS_RSTSRC_RSTS_RESET_Msk)
  331. /**
  332. * @brief This macro get previous reset source is from system reset.
  333. * @return 0: Previous reset source is not from reset pin reset
  334. * 1: Previous reset source is from reset pin reset
  335. */
  336. #define SYS_IS_SYSTEM_RST() (SYS->RSTSRC & SYS_RSTSRC_RSTS_MCU_Msk)
  337. /**
  338. * @brief This macro get previous reset source is from window watch dog reset.
  339. * @return 0: Previous reset source is not from reset system reset
  340. * 1: Previous reset source is from reset system reset
  341. */
  342. #define SYS_IS_WDT_RST() (SYS->RSTSRC & SYS_RSTSRC_RSTS_WDT_Msk)
  343. /**
  344. * @brief This macro disable Low-Voltage-Reset function.
  345. * @return None
  346. */
  347. #define SYS_DISABLE_LVR() (SYS->BODCR &= ~SYS_BODCR_LVR_EN_Msk)
  348. /**
  349. * @brief This macro enable Low-Voltage-Reset function.
  350. * @return None
  351. */
  352. #define SYS_ENABLE_LVR() (SYS->BODCR |= SYS_BODCR_LVR_EN_Msk)
  353. /**
  354. * @brief This macro disable Power-on Reset function.
  355. * @return None
  356. */
  357. #define SYS_DISABLE_POR() (SYS->PORCR = 0x5AA5)
  358. /**
  359. * @brief This macro enable Power-on Reset function.
  360. * @return None
  361. */
  362. #define SYS_ENABLE_POR() (SYS->PORCR = 0)
  363. /**
  364. * @brief This macro clear reset source flag.
  365. * @param u32RstSrc is reset source.
  366. * @return None
  367. */
  368. #define SYS_CLEAR_RST_SOURCE(u32RstSrc) (SYS->RSTSRC | u32RstSrc )
  369. /**
  370. * @brief This function enable register write-protection function
  371. * @return None
  372. * @details To lock the protected register to forbid write access
  373. */
  374. static __INLINE void SYS_LockReg(void)
  375. {
  376. SYS->REGWRPROT = 0;
  377. }
  378. /**
  379. * @brief This function disable register write-protection function
  380. * @return None
  381. * @details To unlock the protected register to allow write access
  382. */
  383. static __INLINE void SYS_UnlockReg(void)
  384. {
  385. while(SYS->REGWRPROT != SYS_REGWRPROT_REGPROTDIS_Msk)
  386. {
  387. SYS->REGWRPROT = 0x59;
  388. SYS->REGWRPROT = 0x16;
  389. SYS->REGWRPROT = 0x88;
  390. }
  391. }
  392. void SYS_ClearResetSrc(uint32_t u32Src);
  393. uint32_t SYS_GetBODStatus(void);
  394. uint32_t SYS_GetResetSrc(void);
  395. uint32_t SYS_IsRegLocked(void);
  396. uint32_t SYS_ReadPDID(void);
  397. void SYS_ResetChip(void);
  398. void SYS_ResetCPU(void);
  399. void SYS_ResetModule(uint32_t u32ModuleIndex);
  400. void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel);
  401. void SYS_DisableBOD(void);
  402. /*@}*/ /* end of group M051_SYS_EXPORTED_FUNCTIONS */
  403. /*@}*/ /* end of group M051_SYS_Driver */
  404. /*@}*/ /* end of group M051_Device_Driver */
  405. #ifdef __cplusplus
  406. }
  407. #endif
  408. #endif //__SYS_H__