| Nano103 BSP V3.01.002 The Board Support Package for Nano103 Series

sys.c
Go to the documentation of this file.
1 /**************************************************************************/
13 #include "Nano103.h"
41 void SYS_ClearResetSrc(uint32_t u32Src)
42 {
43 SYS->RSTSTS |= u32Src;
44 }
45
53 uint32_t SYS_GetBODStatus(void)
54 {
55 return ((SYS->BODCTL & SYS_BODCTL_BODOUT_Msk) >> SYS_BODCTL_BODOUT_Pos);
56 }
57
63 uint32_t SYS_GetResetSrc(void)
64 {
65 return (SYS->RSTSTS);
66 }
67
74 uint32_t SYS_IsRegLocked(void)
75 {
76 return !(SYS->REGLCTL & SYS_REGLCTL_REGLCTL_Msk);
77 }
78
84 uint32_t SYS_ReadPDID(void)
85 {
86 return SYS->PDID;
87 }
88
94 void SYS_ResetChip(void)
95 {
96 SYS->IPRST1 |= SYS_IPRST1_CHIPRST_Msk;
97 }
98
104 void SYS_ResetCPU(void)
105 {
106 SYS->IPRST1 |= SYS_IPRST1_CPURST_Msk;
107 }
108
135 void SYS_ResetModule(uint32_t u32ModuleIndex)
136 {
137 *(volatile uint32_t *)((uint32_t)&(SYS->IPRST1) + (u32ModuleIndex>>24)) |= 1<<(u32ModuleIndex & 0x00ffffff);
138 *(volatile uint32_t *)((uint32_t)&(SYS->IPRST1) + (u32ModuleIndex>>24)) &= ~(1<<(u32ModuleIndex & 0x00ffffff));
139 }
140
166 void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
167 {
168 SYS->BODCTL = (SYS->BODCTL & ~0xFFFF) | SYS_BODCTL_BODEN_Msk | (i32Mode | u32BODLevel);
169 }
170
176 void SYS_DisableBOD(void)
177 {
178 SYS->BODCTL = SYS->BODCTL & ~(SYS_BODCTL_BODEN_Msk);
179 }
180
193 void SYS_EnableLPBOD(int32_t i32Mode, uint32_t u32BODLevel)
194 {
195 SYS->BODCTL = (SYS->BODCTL & ~0xFFFF) | SYS_BODCTL_LPBODEN_Msk | (i32Mode | u32BODLevel);
196 }
197
203 void SYS_DisableLPBOD(void)
204 {
205 SYS->BODCTL = SYS->BODCTL & ~(SYS_BODCTL_LPBODEN_Msk);
206 }
207
221 void SYS_EnableHIRC0Trim(uint32_t u32TrimSel,uint32_t u32TrimEnInt)
222 {
223 SYS->IRC0TIEN = (SYS->IRC0TIEN & ~(SYS_IRC0TIEN_TFAILIEN_Msk | SYS_IRC0TIEN_CLKEIEN_Msk)) | u32TrimEnInt;
224 SYS->IRC0TCTL = (SYS->IRC0TCTL & ~SYS_IRC0TCTL_FREQSEL_Msk)|u32TrimSel;
225 }
226
232 void SYS_DisableHIRC0Trim(void)
233 {
234 SYS->IRC0TCTL = 0;
235 }
236
247 void SYS_EnableHIRC1Trim(uint32_t u32TrimSel,uint32_t u32TrimEnInt)
248 {
249 SYS->IRC1TIEN = (SYS->IRC1TIEN & ~(SYS_IRC1TIEN_TFAILIEN_Msk | SYS_IRC1TIEN_CLKEIEN_Msk)) | u32TrimEnInt;
250 SYS->IRC1TCTL = (SYS->IRC1TCTL & ~SYS_IRC1TCTL_FREQSEL_Msk)|u32TrimSel;
251 }
252
258 void SYS_DisableHIRC1Trim(void)
259 {
260 SYS->IRC1TCTL = 0;
261 }
262
273 void SYS_EnableMIRCTrim(uint32_t u32TrimSel,uint32_t u32TrimEnInt)
274 {
275 SYS->MIRCTIEN = (SYS->MIRCTIEN & ~(SYS_MIRCTIEN_TFAILIEN_Msk | SYS_MIRCTIEN_CLKEIEN_Msk)) | u32TrimEnInt;
276 SYS->MIRCTCTL = (SYS->MIRCTCTL & ~SYS_MIRCTCTL_FREQSEL_Msk)|u32TrimSel;
277 }
278
284 void SYS_DisableMIRCTrim(void)
285 {
286 SYS->MIRCTCTL = 0;
287 }
288 /* end of group NANO103_SYS_EXPORTED_FUNCTIONS */
290 /* end of group NANO103_SYS_Driver */
292 /* end of group NANO103_Device_Driver */
294
295 /*** (C) COPYRIGHT 2015 Nuvoton Technology Corp. ***/
SYS_GetResetSrc
uint32_t SYS_GetResetSrc(void)
This function get the system reset source register value.
Definition: sys.c:63
SYS_MIRCTCTL_FREQSEL_Msk
#define SYS_MIRCTCTL_FREQSEL_Msk
Definition: Nano103.h:3698
SYS_ReadPDID
uint32_t SYS_ReadPDID(void)
This function get product ID.
Definition: sys.c:84
SYS_BODCTL_BODOUT_Pos
#define SYS_BODCTL_BODOUT_Pos
Definition: Nano103.h:3529
SYS_BODCTL_BODEN_Msk
#define SYS_BODCTL_BODEN_Msk
Definition: Nano103.h:3518
SYS_IRC1TIEN_TFAILIEN_Msk
#define SYS_IRC1TIEN_TFAILIEN_Msk
Definition: Nano103.h:3683
SYS_DisableHIRC1Trim
void SYS_DisableHIRC1Trim(void)
This function disable HIRC1 trim function.
Definition: sys.c:258
SYS_IPRST1_CHIPRST_Msk
#define SYS_IPRST1_CHIPRST_Msk
Definition: Nano103.h:3275
SYS_DisableLPBOD
void SYS_DisableLPBOD(void)
This function disable Low Power BOD function.
Definition: sys.c:203
SYS_MIRCTIEN_TFAILIEN_Msk
#define SYS_MIRCTIEN_TFAILIEN_Msk
Definition: Nano103.h:3710
SYS_IsRegLocked
uint32_t SYS_IsRegLocked(void)
This function check register write-protection bit setting.
Definition: sys.c:74
SYS_REGLCTL_REGLCTL_Msk
#define SYS_REGLCTL_REGLCTL_Msk
Definition: Nano103.h:3725
SYS_EnableBOD
void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
This function configure Normal BOD function. Configure BOD reset or interrupt mode and set Brown-out ...
Definition: sys.c:166
SYS_MIRCTIEN_CLKEIEN_Msk
#define SYS_MIRCTIEN_CLKEIEN_Msk
Definition: Nano103.h:3713
SYS_IRC0TIEN_TFAILIEN_Msk
#define SYS_IRC0TIEN_TFAILIEN_Msk
Definition: Nano103.h:3656
SYS_IRC1TIEN_CLKEIEN_Msk
#define SYS_IRC1TIEN_CLKEIEN_Msk
Definition: Nano103.h:3686
SYS_EnableHIRC1Trim
void SYS_EnableHIRC1Trim(uint32_t u32TrimSel, uint32_t u32TrimEnInt)
This function enable HIRC1 trim function.
Definition: sys.c:247
SYS_EnableHIRC0Trim
void SYS_EnableHIRC0Trim(uint32_t u32TrimSel, uint32_t u32TrimEnInt)
This function enable HIRC0 trim function.
Definition: sys.c:221
SYS_EnableMIRCTrim
void SYS_EnableMIRCTrim(uint32_t u32TrimSel, uint32_t u32TrimEnInt)
This function enable MIRC trim function.
Definition: sys.c:273
SYS_DisableHIRC0Trim
void SYS_DisableHIRC0Trim(void)
This function disable HIRC0 trim function.
Definition: sys.c:232
SYS_IRC0TIEN_CLKEIEN_Msk
#define SYS_IRC0TIEN_CLKEIEN_Msk
Definition: Nano103.h:3659
SYS_IPRST1_CPURST_Msk
#define SYS_IPRST1_CPURST_Msk
Definition: Nano103.h:3278
SYS_DisableBOD
void SYS_DisableBOD(void)
This function disable Normal BOD function.
Definition: sys.c:176
SYS_IRC0TCTL_FREQSEL_Msk
#define SYS_IRC0TCTL_FREQSEL_Msk
Definition: Nano103.h:3644
SYS_ResetCPU
void SYS_ResetCPU(void)
This function reset CPU.
Definition: sys.c:104
Nano103.h
NANO103 peripheral access layer header file. This file contains all the peripheral register's definit...
SYS_BODCTL_LPBODEN_Msk
#define SYS_BODCTL_LPBODEN_Msk
Definition: Nano103.h:3536
SYS_ClearResetSrc
void SYS_ClearResetSrc(uint32_t u32Src)
Clear reset source.
Definition: sys.c:41
SYS_ResetChip
void SYS_ResetChip(void)
This function reset chip.
Definition: sys.c:94
SYS
#define SYS
Pointer to SYS register structure.
Definition: Nano103.h:24883
SYS_ResetModule
void SYS_ResetModule(uint32_t u32ModuleIndex)
This function reset selected modules.
Definition: sys.c:135
SYS_EnableLPBOD
void SYS_EnableLPBOD(int32_t i32Mode, uint32_t u32BODLevel)
This function configure Low Power BOD function only valid in Power Down mode. Configure Low Power BOD...
Definition: sys.c:193
SYS_GetBODStatus
uint32_t SYS_GetBODStatus(void)
Get Brown-out detector output status.
Definition: sys.c:53
SYS_BODCTL_BODOUT_Msk
#define SYS_BODCTL_BODOUT_Msk
Definition: Nano103.h:3530
SYS_IRC1TCTL_FREQSEL_Msk
#define SYS_IRC1TCTL_FREQSEL_Msk
Definition: Nano103.h:3671
SYS_DisableMIRCTrim
void SYS_DisableMIRCTrim(void)
This function disable HIRC0 trim function.
Definition: sys.c:284