1 /**************************************************************************//**
\r
4 * @brief M2351 series System Manager (SYS) driver source file
\r
7 * Copyright (C) 2016 Nuvoton Technology Corp. All rights reserved.
\r
8 *****************************************************************************/
\r
10 /** @addtogroup Standard_Driver Standard Driver
\r
14 /** @addtogroup SYS_Driver SYS Driver
\r
19 /** @addtogroup SYS_EXPORTED_FUNCTIONS SYS Exported Functions
\r
24 * @brief Clear reset source
\r
25 * @param[in] u32Src is system reset source. Including :
\r
26 * - \ref SYS_RSTSTS_CPULKRF_Msk
\r
27 * - \ref SYS_RSTSTS_CPURF_Msk
\r
28 * - \ref SYS_RSTSTS_SYSRF_Msk
\r
29 * - \ref SYS_RSTSTS_BODRF_Msk
\r
30 * - \ref SYS_RSTSTS_LVRF_Msk
\r
31 * - \ref SYS_RSTSTS_WDTRF_Msk
\r
32 * - \ref SYS_RSTSTS_PINRF_Msk
\r
33 * - \ref SYS_RSTSTS_PORF_Msk
\r
35 * @details This function clear the selected system reset source.
\r
37 void SYS_ClearResetSrc(uint32_t u32Src)
\r
39 SYS->RSTSTS = u32Src;
\r
43 * @brief Get Brown-out detector output status
\r
45 * @retval 0 System voltage is higher than BODVL setting or BODEN is 0.
\r
46 * @retval 1 System voltage is lower than BODVL setting.
\r
47 * @details This function get Brown-out detector output status.
\r
49 uint32_t SYS_GetBODStatus(void)
\r
51 return ((SYS->BODCTL & SYS_BODCTL_BODOUT_Msk) >> SYS_BODCTL_BODOUT_Pos);
\r
55 * @brief Get reset status register value
\r
57 * @return Reset source
\r
58 * @details This function get the system reset status register value.
\r
60 uint32_t SYS_GetResetSrc(void)
\r
62 return (SYS->RSTSTS);
\r
66 * @brief Check if register is locked nor not
\r
68 * @retval 0 Write-protection function is disabled.
\r
69 * 1 Write-protection function is enabled.
\r
70 * @details This function check register write-protection bit setting.
\r
72 uint32_t SYS_IsRegLocked(void)
\r
74 return SYS->REGLCTL & 1UL ? 0UL : 1UL;
\r
78 * @brief Get product ID
\r
80 * @return Product ID
\r
81 * @details This function get product ID.
\r
83 uint32_t SYS_ReadPDID(void)
\r
89 * @brief Reset chip with chip reset
\r
92 * @details This function reset chip with chip reset.
\r
93 * The register write-protection function should be disabled before using this function.
\r
95 void SYS_ResetChip(void)
\r
97 SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk;
\r
101 * @brief Reset chip with CPU reset
\r
104 * @details This function reset CPU with CPU reset.
\r
105 * The register write-protection function should be disabled before using this function.
\r
107 void SYS_ResetCPU(void)
\r
109 SYS->IPRST0 |= SYS_IPRST0_CPURST_Msk;
\r
113 * @brief Reset selected module
\r
114 * @param[in] u32ModuleIndex is module index. Including :
\r
127 * - \ref ACMP01_RST
\r
163 * @details This function reset selected module.
\r
165 void SYS_ResetModule(uint32_t u32ModuleIndex)
\r
167 uint32_t u32TmpVal = 0UL, u32TmpAddr = 0UL;
\r
169 /* Generate reset signal to the corresponding module */
\r
170 u32TmpVal = (1UL << (u32ModuleIndex & 0x00ffffffUL));
\r
171 u32TmpAddr = (uint32_t)&SYS->IPRST0 + ((u32ModuleIndex >> 24UL));
\r
172 *(uint32_t *)u32TmpAddr |= u32TmpVal;
\r
174 /* Release corresponding module from reset state */
\r
175 u32TmpVal = ~(1UL << (u32ModuleIndex & 0x00ffffffUL));
\r
176 *(uint32_t *)u32TmpAddr &= u32TmpVal;
\r
180 * @brief Enable and configure Brown-out detector function
\r
181 * @param[in] i32Mode is reset or interrupt mode. Including :
\r
182 * - \ref SYS_BODCTL_BOD_RST_EN
\r
183 * - \ref SYS_BODCTL_BOD_INTERRUPT_EN
\r
184 * @param[in] u32BODLevel is Brown-out voltage level. Including :
\r
185 * - \ref SYS_BODCTL_BODVL_1_6V
\r
186 * - \ref SYS_BODCTL_BODVL_1_8V
\r
187 * - \ref SYS_BODCTL_BODVL_2_0V
\r
188 * - \ref SYS_BODCTL_BODVL_2_2V
\r
189 * - \ref SYS_BODCTL_BODVL_2_4V
\r
190 * - \ref SYS_BODCTL_BODVL_2_6V
\r
191 * - \ref SYS_BODCTL_BODVL_2_8V
\r
192 * - \ref SYS_BODCTL_BODVL_3_0V
\r
194 * @details This function configure Brown-out detector reset or interrupt mode, enable Brown-out function and set Brown-out voltage level.
\r
195 * The register write-protection function should be disabled before using this function.
\r
197 void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
\r
199 /* Enable Brown-out Detector function */
\r
200 SYS->BODCTL |= SYS_BODCTL_BODEN_Msk;
\r
202 /* Enable Brown-out interrupt or reset function */
\r
203 SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODRSTEN_Msk) | (uint32_t)i32Mode;
\r
205 /* Select Brown-out Detector threshold voltage */
\r
206 SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODVL_Msk) | u32BODLevel;
\r
210 * @brief Disable Brown-out detector function
\r
213 * @details This function disable Brown-out detector function.
\r
214 * The register write-protection function should be disabled before using this function.
\r
216 void SYS_DisableBOD(void)
\r
218 SYS->BODCTL &= ~SYS_BODCTL_BODEN_Msk;
\r
223 * @brief Set Power Level
\r
224 * @param[in] u32PowerLevel is power level setting. Including :
\r
225 * - \ref SYS_PLCTL_PLSEL_PL0
\r
226 * - \ref SYS_PLCTL_PLSEL_PL1
\r
228 * @details This function select power level.
\r
229 * The register write-protection function should be disabled before using this function.
\r
231 void SYS_SetPowerLevel(uint32_t u32PowerLevel)
\r
233 /* Set power voltage level */
\r
234 SYS->PLCTL = (SYS->PLCTL & (~SYS_PLCTL_PLSEL_Msk)) | (u32PowerLevel);
\r
239 * @brief Set Main Voltage Regulator Type
\r
240 * @param[in] u32PowerRegulator is main voltage regulator type. Including :
\r
241 * - \ref SYS_PLCTL_MVRS_LDO
\r
242 * - \ref SYS_PLCTL_MVRS_DCDC
\r
243 * @retval 0 main voltage regulator type setting is not finished
\r
244 * @retval 1 main voltage regulator type setting is finished
\r
245 * @details This function set main voltage regulator type.
\r
246 * The main voltage regulator type setting to DCDC cannot finished if the inductor is not detected.
\r
247 * The register write-protection function should be disabled before using this function.
\r
249 uint32_t SYS_SetPowerRegulator(uint32_t u32PowerRegulator)
\r
251 int32_t i32TimeOutCnt = 400;
\r
252 uint32_t u32Ret = 1U;
\r
253 uint32_t u32PowerRegStatus;
\r
255 /* Get main voltage regulator type status */
\r
256 u32PowerRegStatus = SYS->PLSTS & SYS_PLSTS_CURMVR_Msk;
\r
258 /* Set main voltage regulator type */
\r
259 if((u32PowerRegulator == SYS_PLCTL_MVRS_DCDC) && (u32PowerRegStatus == SYS_PLSTS_CURMVR_LDO))
\r
262 /* Set main voltage regulator type to DCDC if status is LDO */
\r
263 SYS->PLCTL |= SYS_PLCTL_MVRS_Msk;
\r
265 /* Wait induction detection and main voltage regulator type change ready */
\r
266 while((SYS->PLSTS & SYS_PLSTS_CURMVR_Msk) != SYS_PLSTS_CURMVR_DCDC)
\r
268 if(i32TimeOutCnt-- <= 0)
\r
270 u32Ret = 0U; /* Main voltage regulator type change time-out */
\r
276 else if(u32PowerRegulator == SYS_PLCTL_MVRS_LDO)
\r
279 /* Set main voltage regulator type to LDO if status is DCDC */
\r
280 SYS->PLCTL &= (~SYS_PLCTL_MVRS_Msk);
\r
282 /* Wait main voltage regulator type change ready */
\r
283 while((SYS->PLSTS & SYS_PLSTS_CURMVR_Msk) != SYS_PLSTS_CURMVR_LDO)
\r
285 if(i32TimeOutCnt-- <= 0)
\r
287 u32Ret = 0U; /* Main voltage regulator type change time-out */
\r
294 /* Clear main voltage regulator type change error flag */
\r
295 if(SYS->PLSTS & SYS_PLSTS_MVRCERR_Msk)
\r
297 SYS->PLSTS = SYS_PLSTS_MVRCERR_Msk;
\r
305 * @brief Set System SRAM Power Mode
\r
306 * @param[in] u32SRAMSel is SRAM region selection. Including :
\r
307 * - \ref SYS_SRAMPCTL_SRAM0PM0_Msk
\r
308 * - \ref SYS_SRAMPCTL_SRAM0PM1_Msk
\r
309 * - \ref SYS_SRAMPCTL_SRAM0PM2_Msk
\r
310 * - \ref SYS_SRAMPCTL_SRAM0PM3_Msk
\r
311 * - \ref SYS_SRAMPCTL_SRAM1PM0_Msk
\r
312 * - \ref SYS_SRAMPCTL_SRAM1PM1_Msk
\r
313 * - \ref SYS_SRAMPCTL_SRAM1PM2_Msk
\r
314 * - \ref SYS_SRAMPCTL_SRAM1PM3_Msk
\r
315 * @param[in] u32PowerMode is SRAM power mode. Including :
\r
316 * - \ref SYS_SRAMPCTL_SRAM_NORMAL
\r
317 * - \ref SYS_SRAMPCTL_SRAM_RETENTION
\r
318 * - \ref SYS_SRAMPCTL_SRAM_POWER_SHUT_DOWN
\r
320 * @details This function set system SRAM power mode.
\r
321 * The register write-protection function should be disabled before using this function.
\r
323 void SYS_SetSSRAMPowerMode(uint32_t u32SRAMSel, uint32_t u32PowerMode)
\r
325 uint32_t u32SRAMSelPos = 8UL;
\r
327 /* Get system SRAM power mode setting position */
\r
328 while(u32SRAMSelPos < 24UL)
\r
330 if(u32SRAMSel & (1 << u32SRAMSelPos))
\r
340 /* Set system SRAM power mode setting */
\r
341 SYS->SRAMPCTL = (SYS->SRAMPCTL & (~u32SRAMSel)) | (u32PowerMode << u32SRAMSelPos);
\r
345 * @brief Set Peripheral SRAM Power Mode
\r
346 * @param[in] u32SRAMSel is SRAM region selection. Including :
\r
347 * - \ref SYS_SRAMPPCT_CAN_Msk
\r
348 * - \ref SYS_SRAMPPCT_USBD_Msk
\r
349 * - \ref SYS_SRAMPPCT_PDMA0_Msk
\r
350 * - \ref SYS_SRAMPPCT_PDMA1_Msk
\r
351 * - \ref SYS_SRAMPPCT_FMC_Msk
\r
352 * @param[in] u32PowerMode is SRAM power mode. Including :
\r
353 * - \ref SYS_SRAMPPCT_SRAM_NORMAL
\r
354 * - \ref SYS_SRAMPPCT_SRAM_RETENTION
\r
355 * - \ref SYS_SRAMPPCT_SRAM_POWER_SHUT_DOWN
\r
357 * @details This function set peripheral SRAM power mode.
\r
358 * The register write-protection function should be disabled before using this function.
\r
360 void SYS_SetPSRAMPowerMode(uint32_t u32SRAMSel, uint32_t u32PowerMode)
\r
362 uint32_t u32SRAMSelPos = 0UL;
\r
364 /* Get peripheral SRAM power mode setting position */
\r
365 while(u32SRAMSelPos < 10UL)
\r
367 if(u32SRAMSel & (1 << u32SRAMSelPos))
\r
377 /* Set peripheral SRAM power mode setting */
\r
378 SYS->SRAMPPCT = (SYS->SRAMPPCT & (~u32SRAMSel)) | (u32PowerMode << u32SRAMSelPos);
\r
382 /*@}*/ /* end of group SYS_EXPORTED_FUNCTIONS */
\r
384 /*@}*/ /* end of group SYS_Driver */
\r
386 /*@}*/ /* end of group Standard_Driver */
\r
388 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
\r