MINI58_BSP V3.01.005
The Board Support Package for Mini58 Series MCU
sys.h
Go to the documentation of this file.
1/**************************************************************************/
12#ifndef __SYS_H__
13#define __SYS_H__
14
15#ifdef __cplusplus
16extern "C"
17{
18#endif
19
31/*---------------------------------------------------------------------------------------------------------*/
32/* Module Reset Control Resister constant definitions. */
33/*---------------------------------------------------------------------------------------------------------*/
34#define ADC_RST ((0x4<<24) | SYS_IPRST1_ADCRST_Pos )
35#define ACMP_RST ((0x4<<24) | SYS_IPRST1_ACMPRST_Pos )
36#define PWM0_RST ((0x4<<24) | SYS_IPRST1_PWM0RST_Pos )
37#define UART0_RST ((0x4<<24) | SYS_IPRST1_UART0RST_Pos )
38#define UART1_RST ((0x4<<24) | SYS_IPRST1_UART1RST_Pos )
39#define SPI0_RST ((0x4<<24) | SYS_IPRST1_SPI0RST_Pos )
40#define I2C0_RST ((0x4<<24) | SYS_IPRST1_I2C0RST_Pos )
41#define I2C1_RST ((0x4<<24) | SYS_IPRST1_I2C1RST_Pos )
42#define TMR1_RST ((0x4<<24) | SYS_IPRST1_TMR1RST_Pos )
43#define TMR0_RST ((0x4<<24) | SYS_IPRST1_TMR0RST_Pos )
44#define GPIO_RST ((0x4<<24) | SYS_IPRST1_GPIORST_Pos )
47/*---------------------------------------------------------------------------------------------------------*/
48/* Brown Out Detector Threshold Voltage Selection constant definitions. */
49/*---------------------------------------------------------------------------------------------------------*/
50#define SYS_BODCTL_BOD_RST_EN (1UL<<SYS_BODCTL_BODRSTEN_Pos)
51#define SYS_BODCTL_BOD_INTERRUPT_EN (0UL<<SYS_BODCTL_BODRSTEN_Pos)
52#define SYS_BODCTL_BODVL_4_4V (3UL<<SYS_BODCTL_BODVL_Pos)
53#define SYS_BODCTL_BODVL_3_7V (2UL<<SYS_BODCTL_BODVL_Pos)
54#define SYS_BODCTL_BODVL_2_7V (1UL<<SYS_BODCTL_BODVL_Pos)
55#define SYS_BODCTL_BODVL_2_2V (0UL<<SYS_BODCTL_BODVL_Pos)
58/*---------------------------------------------------------------------------------------------------------*/
59/* Multi-Function constant definitions. */
60/*---------------------------------------------------------------------------------------------------------*/
61#define SYS_MFP_TYPE_Msk(bit) (1UL << ((bit) +16))
62#define SYS_MFP_ALT_Msk(bit) (1UL << ((bit) + 8))
63#define SYS_MFP_MFP_Msk(bit) (1UL << ((bit) ))
65#define SYS_MFP_P00_GPIO 0x00000000UL
66#define SYS_MFP_P00_UART0_nCTS 0x00000100UL
67#define SYS_MFP_P00_UART0_TXD 0x00000101UL
68#define SYS_MFP_P00_Msk 0x00000101UL
70#define SYS_MFP_P01_GPIO 0x00000000UL
71#define SYS_MFP_P01_SPI0_SS 0x00000002UL
72#define SYS_MFP_P01_UART0_nRTS 0x00000200UL
73#define SYS_MFP_P01_UART0_RXD 0x00000202UL
74#define SYS_MFP_P01_Msk 0x00000202UL
76#define SYS_MFP_P04_GPIO 0x00000000UL
77#define SYS_MFP_P04_PWM0_CH5 0x00001010UL
78#define SYS_MFP_P04_SPI0_SS 0x00001000UL
79#define SYS_MFP_P04_Msk 0x00001010UL
81#define SYS_MFP_P05_GPIO 0x00000000UL
82#define SYS_MFP_P05_PWM0_CH4 0x00002020UL
83#define SYS_MFP_P05_SPI0_MOSI 0x00002000UL
84#define SYS_MFP_P05_Msk 0x00002020UL
86#define SYS_MFP_P06_GPIO 0x00000000UL
87#define SYS_MFP_P06_PWM0_CH1 0x00004040UL
88#define SYS_MFP_P06_SPI0_MISO 0x00004000UL
89#define SYS_MFP_P06_Msk 0x00004040UL
91#define SYS_MFP_P07_GPIO 0x00000000UL
92#define SYS_MFP_P07_PWM0_CH0 0x00008080UL
93#define SYS_MFP_P07_SPI0_CLK 0x00008000UL
94#define SYS_MFP_P07_Msk 0x00008080UL
96#define SYS_MFP_P10_ACMP0_P1 0x00000101UL
97#define SYS_MFP_P10_ADC_CH1 0x00000001UL
98#define SYS_MFP_P10_GPIO 0x00000000UL
99#define SYS_MFP_P10_Msk 0x00000101UL
101#define SYS_MFP_P12_ACMP0_P2 0x00000404UL
102#define SYS_MFP_P12_ADC_CH2 0x00000004UL
103#define SYS_MFP_P12_GPIO 0x00000000UL
104#define SYS_MFP_P12_UART0_RXD 0x00000400UL
105#define SYS_MFP_P12_PWM0_CH0 0x04000000UL
106#define SYS_MFP_P12_Msk 0x04000404UL
108#define SYS_MFP_P13_ACMP0_P3 0x00000808UL
109#define SYS_MFP_P13_ADC_CH3 0x00000008UL
110#define SYS_MFP_P13_GPIO 0x00000000UL
111#define SYS_MFP_P13_UART0_TXD 0x00000800UL
112#define SYS_MFP_P13_PWM0_CH1 0x08000000UL
113#define SYS_MFP_P13_Msk 0x08000808UL
115#define SYS_MFP_P14_ACMP0_N 0x00001010UL
116#define SYS_MFP_P14_ADC_CH4 0x00000010UL
117#define SYS_MFP_P14_GPIO 0x00000000UL
118#define SYS_MFP_P14_UART1_RXD 0x00001000UL
119#define SYS_MFP_P14_PWM0_CH4 0x10000000UL
120#define SYS_MFP_P14_Msk 0x10001010UL
122#define SYS_MFP_P15_ACMP0_P0 0x00002020UL
123#define SYS_MFP_P15_ADC_CH5 0x00000020UL
124#define SYS_MFP_P15_GPIO 0x00000000UL
125#define SYS_MFP_P15_UART1_TXD 0x00002000UL
126#define SYS_MFP_P15_Msk 0x00002020UL
128#define SYS_MFP_P22_GPIO 0x00000000UL
129#define SYS_MFP_P22_I2C1_SCL 0x00000404UL
130#define SYS_MFP_P22_PWM0_CH0 0x00000400UL
131#define SYS_MFP_P22_Msk 0x00000404UL
133#define SYS_MFP_P23_GPIO 0x00000000UL
134#define SYS_MFP_P23_I2C1_SDA 0x00000808UL
135#define SYS_MFP_P23_PWM0_CH1 0x00000800UL
136#define SYS_MFP_P23_Msk 0x00000808UL
138#define SYS_MFP_P24_GPIO 0x00000000UL
139#define SYS_MFP_P24_PWM0_CH2 0x00001000UL
140#define SYS_MFP_P24_UART1_RXD 0x00000010UL
141#define SYS_MFP_P24_Msk 0x00001010UL
143#define SYS_MFP_P25_GPIO 0x00000000UL
144#define SYS_MFP_P25_PWM0_CH3 0x00002000UL
145#define SYS_MFP_P25_UART1_TXD 0x00000020UL
146#define SYS_MFP_P25_Msk 0x00002020UL
148#define SYS_MFP_P26_ACMP1_O 0x00004040UL
149#define SYS_MFP_P26_GPIO 0x00000000UL
150#define SYS_MFP_P26_PWM0_CH4 0x00004000UL
151#define SYS_MFP_P26_Msk 0x00004040UL
153#define SYS_MFP_P30_ACMP1_N 0x00000100UL
154#define SYS_MFP_P30_ADC_CH6 0x00000101UL
155#define SYS_MFP_P30_GPIO 0x00000000UL
156#define SYS_MFP_P30_Msk 0x00000101UL
158#define SYS_MFP_P31_ACMP1_P0 0x00000200UL
159#define SYS_MFP_P31_ADC_CH7 0x00000202UL
160#define SYS_MFP_P31_GPIO 0x00000000UL
161#define SYS_MFP_P31_Msk 0x00000202UL
163#define SYS_MFP_P32_GPIO 0x00000000UL
164#define SYS_MFP_P32_INT0 0x00000004UL
165#define SYS_MFP_P32_STADC 0x00000404UL
166#define SYS_MFP_P32_TM0_EXT 0x00000400UL
167#define SYS_MFP_P32_ACMP1_P1 0x04000000UL
168#define SYS_MFP_P32_Msk 0x04000404UL
170#define SYS_MFP_P34_ACMP1_P2 0x00001010UL
171#define SYS_MFP_P34_GPIO 0x00000000UL
172#define SYS_MFP_P34_I2C0_SDA 0x00001000UL
173#define SYS_MFP_P34_TM0_CNT_OUT 0x00000010UL
174#define SYS_MFP_P34_Msk 0x00001010UL
176#define SYS_MFP_P35_ACMP1_P3 0x00002020UL
177#define SYS_MFP_P35_GPIO 0x00000000UL
178#define SYS_MFP_P35_I2C0_SCL 0x00002000UL
179#define SYS_MFP_P35_TM1_CNT_OUT 0x00000020UL
180#define SYS_MFP_P35_Msk 0x00002020UL
182#define SYS_MFP_P36_ACMP0_O 0x00004040UL
183#define SYS_MFP_P36_CLKO 0x00004000UL
184#define SYS_MFP_P36_GPIO 0x00000000UL
185#define SYS_MFP_P36_TM1_EXT 0x00000040UL
186#define SYS_MFP_P36_Msk 0x00004040UL
188#define SYS_MFP_P46_GPIO 0x00000000UL
189#define SYS_MFP_P46_ICE_CLK 0x00000040UL
190#define SYS_MFP_P46_UART1_RXD 0x00004000UL
191#define SYS_MFP_P46_Msk 0x00004040UL
193#define SYS_MFP_P47_GPIO 0x00000000UL
194#define SYS_MFP_P47_ICE_DAT 0x00000080UL
195#define SYS_MFP_P47_UART1_TXD 0x00008000UL
196#define SYS_MFP_P47_Msk 0x00008080UL
198#define SYS_MFP_P50_GPIO 0x00000000UL
199#define SYS_MFP_P50_I2C1_SDA 0x00000100UL
200#define SYS_MFP_P50_UART0_TXD 0x00000101UL
201#define SYS_MFP_P50_XT1_IN 0x00000001UL
202#define SYS_MFP_P50_Msk 0x00000101UL
204#define SYS_MFP_P51_GPIO 0x00000000UL
205#define SYS_MFP_P51_I2C1_SCL 0x00000200UL
206#define SYS_MFP_P51_UART0_RXD 0x00000202UL
207#define SYS_MFP_P51_XT1_OUT 0x00000002UL
208#define SYS_MFP_P51_Msk 0x00000202UL
210#define SYS_MFP_P52_GPIO 0x00000000UL
211#define SYS_MFP_P52_INT1 0x00000004UL
212#define SYS_MFP_P52_Msk 0x00000404UL
214#define SYS_MFP_P53_ADC_CH0 0x00000008UL
215#define SYS_MFP_P53_GPIO 0x00000000UL
216#define SYS_MFP_P53_Msk 0x00000808UL
218#define SYS_MFP_P54_GPIO 0x00000000UL
219#define SYS_MFP_P54_Msk 0x00001010UL
221#define SYS_MFP_P55_GPIO 0x00000000UL
222#define SYS_MFP_P55_Msk 0x00002020UL /* end of group Mini58_SYS_EXPORTED_CONSTANTS */
226
236#define SYS_CLEAR_BOD_INT_FLAG() (SYS->BODCTL |= SYS_BODCTL_BODIF_Msk)
237
245#define SYS_CLEAR_BOD_LPM() (SYS->BODCTL &= ~SYS_BODCTL_BODLPM_Msk)
246
254#define SYS_DISABLE_BOD() (SYS->BODCTL = (SYS->BODCTL &~(SYS_BODCTL_BODVL_Msk|SYS_BODCTL_BODEN_Msk))|SYS_BODCTL_BODVL_Msk)
255
263#define SYS_ENABLE_BOD() (SYS->BODCTL = (SYS->BODCTL | SYS_BODCTL_BODEN_Msk))
264
272#define SYS_GET_BOD_INT_FLAG() (SYS->BODCTL & SYS_BODCTL_BODIF_Msk)
273
282#define SYS_GET_BOD_OUTPUT() (SYS->BODCTL & SYS_BODCTL_BODOUT_Msk)
283
291#define SYS_DISABLE_BOD_RST() (SYS->BODCTL &= ~SYS_BODCTL_BODRSTEN_Msk)
292
300#define SYS_ENABLE_BOD_RST() (SYS->BODCTL |= SYS_BODCTL_BODRSTEN_Msk)
301
309#define SYS_SET_BOD_LPM() (SYS->BODCTL |= SYS_BODCTL_BODLPM_Msk)
310
322#define SYS_SET_BOD_LEVEL(u32Level) (SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODVL_Msk) | (u32Level))
323
331#define SYS_IS_BOD_RST() (SYS->RSTSTS & SYS_RSTSTS_BODRF_Msk)
332
340#define SYS_IS_CPU_RST() (SYS->RSTSTS & SYS_RSTSTS_CPURF_Msk)
341
349#define SYS_IS_POR_RST() (SYS->RSTSTS & SYS_RSTSTS_PORF_Msk)
350
358#define SYS_IS_RSTPIN_RST() (SYS->RSTSTS & SYS_RSTSTS_PINRF_Msk)
359
367#define SYS_IS_SYSTEM_RST() (SYS->RSTSTS & SYS_RSTSTS_SYSRF_Msk)
368
376#define SYS_IS_WDT_RST() (SYS->RSTSTS & SYS_RSTSTS_WDTRF_Msk)
377
385#define SYS_DISABLE_POR() (SYS->PORCTL = 0x5AA5)
386
394#define SYS_ENABLE_POR() (SYS->PORCTL = 0)
395
409#define SYS_CLEAR_RST_SOURCE(u32RstSrc) ((SYS->RSTSTS) = (u32RstSrc) )
410
411
419__STATIC_INLINE void SYS_UnlockReg(void)
420{
421 do
422 {
423 SYS->REGLCTL = 0x59;
424 SYS->REGLCTL = 0x16;
425 SYS->REGLCTL = 0x88;
426 }
427 while(SYS->REGLCTL == 0);
428}
429
437__STATIC_INLINE void SYS_LockReg(void)
438{
439 SYS->REGLCTL = 0;
440}
441
442void SYS_ClearResetSrc(uint32_t u32Src);
443uint32_t SYS_GetBODStatus(void);
444uint32_t SYS_GetResetSrc(void);
445uint32_t SYS_IsRegLocked(void);
446uint32_t SYS_ReadPDID(void);
447void SYS_ResetChip(void);
448void SYS_ResetCPU(void);
449void SYS_ResetModule(uint32_t u32ModuleIndex);
450void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel);
451void SYS_DisableBOD(void);
452 /* end of group Mini58_SYS_EXPORTED_FUNCTIONS */
454 /* end of group Mini58_SYS_Driver */
456 /* end of group Mini58_Device_Driver */
458
459#ifdef __cplusplus
460}
461#endif
462
463#endif //__SYS_H__
464
465/*** (C) COPYRIGHT 2022 Nuvoton Technology Corp. ***/
#define SYS
Pointer to SYS register structure.
void SYS_ResetCPU(void)
This function reset CPU.
Definition: sys.c:88
uint32_t SYS_GetBODStatus(void)
This function get Brown-out detector output status.
Definition: sys.c:42
__STATIC_INLINE void SYS_LockReg(void)
Enable register write-protection function.
Definition: sys.h:437
uint32_t SYS_GetResetSrc(void)
This function get the system reset source register value.
Definition: sys.c:51
void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
This function configure BOD function. Configure BOD reset or interrupt mode and set Brown-out voltage...
Definition: sys.c:129
void SYS_ResetModule(uint32_t u32ModuleIndex)
This function reset selected modules.
Definition: sys.c:109
uint32_t SYS_ReadPDID(void)
This function get product ID.
Definition: sys.c:70
void SYS_DisableBOD(void)
This function disable BOD function.
Definition: sys.c:140
uint32_t SYS_IsRegLocked(void)
This function check register write-protection bit setting.
Definition: sys.c:61
__STATIC_INLINE void SYS_UnlockReg(void)
Disable register write-protection function.
Definition: sys.h:419
void SYS_ClearResetSrc(uint32_t u32Src)
This function clear the selected system reset source.
Definition: sys.c:31
void SYS_ResetChip(void)
This function reset chip.
Definition: sys.c:79