M480 BSP V3.05.005
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
13extern "C"
14{
15#endif
16
44void SYS_ClearResetSrc(uint32_t u32Src)
45{
46 SYS->RSTSTS |= u32Src;
47}
48
56uint32_t SYS_GetBODStatus(void)
57{
58 return ((SYS->BODCTL & SYS_BODCTL_BODOUT_Msk) >> SYS_BODCTL_BODOUT_Pos);
59}
60
67uint32_t SYS_GetResetSrc(void)
68{
69 return (SYS->RSTSTS);
70}
71
79uint32_t SYS_IsRegLocked(void)
80{
81 return SYS->REGLCTL & 1UL ? 0UL : 1UL;
82}
83
90uint32_t SYS_ReadPDID(void)
91{
92 return SYS->PDID;
93}
94
103{
104 SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk;
105}
106
114void SYS_ResetCPU(void)
115{
116 SYS->IPRST0 |= SYS_IPRST0_CPURST_Msk;
117}
118
184void 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 *(volatile uint32_t *)u32tmpAddr |= u32tmpVal;
192
193 /* Release corresponding module from reset state */
194 u32tmpVal = ~(1UL << (u32ModuleIndex & 0x00ffffffUL));
195 *(volatile uint32_t *)u32tmpAddr &= u32tmpVal;
196}
197
216void 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
236{
237 SYS->BODCTL &= ~SYS_BODCTL_BODEN_Msk;
238}
239
249void SYS_SetPowerLevel(uint32_t u32PowerLevel)
250{
251 /* Set power voltage level */
252 SYS->PLCTL = (SYS->PLCTL & (~SYS_PLCTL_PLSEL_Msk)) | (u32PowerLevel);
253}
254
268void 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. ***/
NuMicro peripheral access layer header file.
#define SYS
Definition: M480.h:367
#define SYS_IPRST0_CPURST_Msk
Definition: sys_reg.h:4858
#define SYS_BODCTL_BODEN_Msk
Definition: sys_reg.h:5038
#define SYS_IPRST0_CHIPRST_Msk
Definition: sys_reg.h:4855
#define SYS_BODCTL_BODOUT_Pos
Definition: sys_reg.h:5049
#define SYS_BODCTL_BODOUT_Msk
Definition: sys_reg.h:5050
void SYS_ResetCPU(void)
Reset chip with CPU reset.
Definition: sys.c:114
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
uint32_t SYS_GetResetSrc(void)
Get reset status register value.
Definition: sys.c:67
void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
Enable and configure Brown-out detector function.
Definition: sys.c:216
void SYS_ResetModule(uint32_t u32ModuleIndex)
Reset selected module.
Definition: sys.c:184
uint32_t SYS_ReadPDID(void)
Get product ID.
Definition: sys.c:90
void SYS_SetPowerLevel(uint32_t u32PowerLevel)
Set Power Level.
Definition: sys.c:249
void SYS_DisableBOD(void)
Disable Brown-out detector function.
Definition: sys.c:235
uint32_t SYS_IsRegLocked(void)
Check if register is locked nor not.
Definition: sys.c:79
void SYS_ClearResetSrc(uint32_t u32Src)
Clear reset source.
Definition: sys.c:44
void SYS_ResetChip(void)
Reset chip with chip reset.
Definition: sys.c:102