M480 BSP  V3.05.001
The Board Support Package for M480 Series
sys.c
Go to the documentation of this file.
1 /**************************************************************************/
10 #include "NuMicro.h"
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
44 void SYS_ClearResetSrc(uint32_t u32Src)
45 {
46  SYS->RSTSTS |= u32Src;
47 }
48 
56 uint32_t SYS_GetBODStatus(void)
57 {
58  return ((SYS->BODCTL & SYS_BODCTL_BODOUT_Msk) >> SYS_BODCTL_BODOUT_Pos);
59 }
60 
67 uint32_t SYS_GetResetSrc(void)
68 {
69  return (SYS->RSTSTS);
70 }
71 
79 uint32_t SYS_IsRegLocked(void)
80 {
81  return SYS->REGLCTL & 1UL ? 0UL : 1UL;
82 }
83 
90 uint32_t SYS_ReadPDID(void)
91 {
92  return SYS->PDID;
93 }
94 
102 void SYS_ResetChip(void)
103 {
104  SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk;
105 }
106 
114 void SYS_ResetCPU(void)
115 {
116  SYS->IPRST0 |= SYS_IPRST0_CPURST_Msk;
117 }
118 
184 void SYS_ResetModule(uint32_t u32ModuleIndex)
185 {
186  uint32_t u32tmpVal = 0UL, u32tmpAddr = 0UL;
187 
188  /* Generate reset signal to the corresponding module */
189  u32tmpVal = (1UL << (u32ModuleIndex & 0x00ffffffUL));
190  u32tmpAddr = (uint32_t)&SYS->IPRST0 + ((u32ModuleIndex >> 24UL));
191  *(uint32_t *)u32tmpAddr |= u32tmpVal;
192 
193  /* Release corresponding module from reset state */
194  u32tmpVal = ~(1UL << (u32ModuleIndex & 0x00ffffffUL));
195  *(uint32_t *)u32tmpAddr &= u32tmpVal;
196 }
197 
216 void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
217 {
218  /* Enable Brown-out Detector function */
219  SYS->BODCTL |= SYS_BODCTL_BODEN_Msk;
220 
221  /* Enable Brown-out interrupt or reset function */
222  SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODRSTEN_Msk) | (uint32_t)i32Mode;
223 
224  /* Select Brown-out Detector threshold voltage */
225  SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODVL_Msk) | u32BODLevel;
226 }
227 
235 void SYS_DisableBOD(void)
236 {
237  SYS->BODCTL &= ~SYS_BODCTL_BODEN_Msk;
238 }
239 
249 void SYS_SetPowerLevel(uint32_t u32PowerLevel)
250 {
251  /* Set power voltage level */
252  SYS->PLCTL = (SYS->PLCTL & (~SYS_PLCTL_PLSEL_Msk)) | (u32PowerLevel);
253 }
254 
268 void SYS_SetVRef(uint32_t u32VRefCTL)
269 {
270  /* Set reference voltage */
271  SYS->VREFCTL = (SYS->VREFCTL & (~SYS_VREFCTL_VREFCTL_Msk)) | (u32VRefCTL);
272 }
273  /* end of group SYS_EXPORTED_FUNCTIONS */
275  /* end of group SYS_Driver */
277  /* end of group Standard_Driver */
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
#define SYS_IPRST0_CPURST_Msk
Definition: sys_reg.h:4858
#define SYS_VREFCTL_VREFCTL_Msk
Definition: sys_reg.h:5074
uint32_t SYS_GetBODStatus(void)
Get Brown-out detector output status.
Definition: sys.c:56
void SYS_SetVRef(uint32_t u32VRefCTL)
Set Reference Voltage.
Definition: sys.c:268
#define SYS_PLCTL_PLSEL_Msk
Definition: sys_reg.h:6037
#define SYS_BODCTL_BODEN_Msk
Definition: sys_reg.h:5038
void SYS_ResetChip(void)
Reset chip with chip reset.
Definition: sys.c:102
#define SYS_BODCTL_BODOUT_Pos
Definition: sys_reg.h:5049
void SYS_ResetModule(uint32_t u32ModuleIndex)
Reset selected module.
Definition: sys.c:184
uint32_t SYS_GetResetSrc(void)
Get reset status register value.
Definition: sys.c:67
#define SYS_IPRST0_CHIPRST_Msk
Definition: sys_reg.h:4855
void SYS_DisableBOD(void)
Disable Brown-out detector function.
Definition: sys.c:235
NuMicro peripheral access layer header file.
uint32_t SYS_ReadPDID(void)
Get product ID.
Definition: sys.c:90
#define SYS
Definition: M480.h:367
#define SYS_BODCTL_BODOUT_Msk
Definition: sys_reg.h:5050
uint32_t SYS_IsRegLocked(void)
Check if register is locked nor not.
Definition: sys.c:79
void SYS_ResetCPU(void)
Reset chip with CPU reset.
Definition: sys.c:114
#define SYS_BODCTL_BODRSTEN_Msk
Definition: sys_reg.h:5041
void SYS_SetPowerLevel(uint32_t u32PowerLevel)
Set Power Level.
Definition: sys.c:249
void SYS_ClearResetSrc(uint32_t u32Src)
Clear reset source.
Definition: sys.c:44
void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
Enable and configure Brown-out detector function.
Definition: sys.c:216
#define SYS_BODCTL_BODVL_Msk
Definition: sys_reg.h:5062