Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
m480_sys.c
00001 /**************************************************************************//** 00002 * @file sys.c 00003 * @version V1.00 00004 * @brief M480 series SYS driver source file 00005 * 00006 * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without modification, 00009 * are permitted provided that the following conditions are met: 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 3. Neither the name of Nuvoton Technology Corp. nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00026 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 *****************************************************************************/ 00030 00031 #include "NuMicro.h" 00032 00033 #ifdef __cplusplus 00034 extern "C" 00035 { 00036 #endif 00037 00038 /** @addtogroup Standard_Driver Standard Driver 00039 @{ 00040 */ 00041 00042 /** @addtogroup SYS_Driver SYS Driver 00043 @{ 00044 */ 00045 00046 00047 /** @addtogroup SYS_EXPORTED_FUNCTIONS SYS Exported Functions 00048 @{ 00049 */ 00050 00051 /** 00052 * @brief Clear reset source 00053 * @param[in] u32Src is system reset source. Including : 00054 * - \ref SYS_RSTSTS_CPULKRF_Msk 00055 * - \ref SYS_RSTSTS_CPURF_Msk 00056 * - \ref SYS_RSTSTS_SYSRF_Msk 00057 * - \ref SYS_RSTSTS_BODRF_Msk 00058 * - \ref SYS_RSTSTS_LVRF_Msk 00059 * - \ref SYS_RSTSTS_WDTRF_Msk 00060 * - \ref SYS_RSTSTS_PINRF_Msk 00061 * - \ref SYS_RSTSTS_PORF_Msk 00062 * @return None 00063 * @details This function clear the selected system reset source. 00064 */ 00065 void SYS_ClearResetSrc(uint32_t u32Src) 00066 { 00067 SYS->RSTSTS |= u32Src; 00068 } 00069 00070 /** 00071 * @brief Get Brown-out detector output status 00072 * @param None 00073 * @retval 0 System voltage is higher than BODVL setting or BODEN is 0. 00074 * @retval 1 System voltage is lower than BODVL setting. 00075 * @details This function get Brown-out detector output status. 00076 */ 00077 uint32_t SYS_GetBODStatus(void) 00078 { 00079 return ((SYS->BODCTL & SYS_BODCTL_BODOUT_Msk) >> SYS_BODCTL_BODOUT_Pos); 00080 } 00081 00082 /** 00083 * @brief Get reset status register value 00084 * @param None 00085 * @return Reset source 00086 * @details This function get the system reset status register value. 00087 */ 00088 uint32_t SYS_GetResetSrc(void) 00089 { 00090 return (SYS->RSTSTS); 00091 } 00092 00093 /** 00094 * @brief Check if register is locked nor not 00095 * @param None 00096 * @retval 0 Write-protection function is disabled. 00097 * 1 Write-protection function is enabled. 00098 * @details This function check register write-protection bit setting. 00099 */ 00100 uint32_t SYS_IsRegLocked(void) 00101 { 00102 return SYS->REGLCTL & 1UL ? 0UL : 1UL; 00103 } 00104 00105 /** 00106 * @brief Get product ID 00107 * @param None 00108 * @return Product ID 00109 * @details This function get product ID. 00110 */ 00111 uint32_t SYS_ReadPDID(void) 00112 { 00113 return SYS->PDID; 00114 } 00115 00116 /** 00117 * @brief Reset chip with chip reset 00118 * @param None 00119 * @return None 00120 * @details This function reset chip with chip reset. 00121 * The register write-protection function should be disabled before using this function. 00122 */ 00123 void SYS_ResetChip(void) 00124 { 00125 SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk; 00126 } 00127 00128 /** 00129 * @brief Reset chip with CPU reset 00130 * @param None 00131 * @return None 00132 * @details This function reset CPU with CPU reset. 00133 * The register write-protection function should be disabled before using this function. 00134 */ 00135 void SYS_ResetCPU(void) 00136 { 00137 SYS->IPRST0 |= SYS_IPRST0_CPURST_Msk; 00138 } 00139 00140 /** 00141 * @brief Reset selected module 00142 * @param[in] u32ModuleIndex is module index. Including : 00143 * - \ref PDMA_RST 00144 * - \ref EBI_RST 00145 * - \ref EMAC_RST 00146 * - \ref SDH0_RST 00147 * - \ref CRC_RST 00148 * - \ref HSUSBD_RST 00149 * - \ref CRPT_RST 00150 * - \ref SPIM_RST 00151 * - \ref USBH_RST 00152 * - \ref SDH1_RST 00153 * - \ref GPIO_RST 00154 * - \ref TMR0_RST 00155 * - \ref TMR1_RST 00156 * - \ref TMR2_RST 00157 * - \ref TMR3_RST 00158 * - \ref ACMP01_RST 00159 * - \ref I2C0_RST 00160 * - \ref I2C1_RST 00161 * - \ref I2C2_RST 00162 * - \ref QSPI0_RST 00163 * - \ref SPI0_RST 00164 * - \ref SPI1_RST 00165 * - \ref SPI2_RST 00166 * - \ref UART0_RST 00167 * - \ref UART1_RST 00168 * - \ref UART2_RST 00169 * - \ref UART3_RST 00170 * - \ref UART4_RST 00171 * - \ref UART5_RST 00172 * - \ref CAN0_RST 00173 * - \ref CAN1_RST 00174 * - \ref USBD_RST 00175 * - \ref EADC_RST 00176 * - \ref I2S0_RST 00177 * - \ref SC0_RST 00178 * - \ref SC1_RST 00179 * - \ref SC2_RST 00180 * - \ref SPI3_RST 00181 * - \ref USCI0_RST 00182 * - \ref USCI1_RST 00183 * - \ref DAC_RST 00184 * - \ref EPWM0_RST 00185 * - \ref EPWM1_RST 00186 * - \ref BPWM0_RST 00187 * - \ref BPWM1_RST 00188 * - \ref QEI0_RST 00189 * - \ref QEI1_RST 00190 * - \ref ECAP0_RST 00191 * - \ref ECAP1_RST 00192 * - \ref OPA_RST 00193 * @return None 00194 * @details This function reset selected module. 00195 */ 00196 void SYS_ResetModule(uint32_t u32ModuleIndex) 00197 { 00198 uint32_t u32tmpVal = 0UL, u32tmpAddr = 0UL; 00199 /* Generate reset signal to the corresponding module */ 00200 u32tmpVal = (1UL << (u32ModuleIndex & 0x00ffffffUL)); 00201 u32tmpAddr = (uint32_t)&SYS->IPRST0 + ((u32ModuleIndex >> 24UL)); 00202 *(uint32_t *)u32tmpAddr |= u32tmpVal; 00203 /* Release corresponding module from reset state */ 00204 u32tmpVal = ~(1UL << (u32ModuleIndex & 0x00ffffffUL)); 00205 *(uint32_t *)u32tmpAddr &= u32tmpVal; 00206 } 00207 00208 /** 00209 * @brief Enable and configure Brown-out detector function 00210 * @param[in] i32Mode is reset or interrupt mode. Including : 00211 * - \ref SYS_BODCTL_BOD_RST_EN 00212 * - \ref SYS_BODCTL_BOD_INTERRUPT_EN 00213 * @param[in] u32BODLevel is Brown-out voltage level. Including : 00214 * - \ref SYS_BODCTL_BODVL_3_0V 00215 * - \ref SYS_BODCTL_BODVL_2_8V 00216 * - \ref SYS_BODCTL_BODVL_2_6V 00217 * - \ref SYS_BODCTL_BODVL_2_4V 00218 * - \ref SYS_BODCTL_BODVL_2_2V 00219 * - \ref SYS_BODCTL_BODVL_2_0V 00220 * - \ref SYS_BODCTL_BODVL_1_8V 00221 * - \ref SYS_BODCTL_BODVL_1_6V 00222 * @return None 00223 * @details This function configure Brown-out detector reset or interrupt mode, enable Brown-out function and set Brown-out voltage level. 00224 * The register write-protection function should be disabled before using this function. 00225 */ 00226 void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel) 00227 { 00228 /* Enable Brown-out Detector function */ 00229 SYS->BODCTL |= SYS_BODCTL_BODEN_Msk; 00230 /* Enable Brown-out interrupt or reset function */ 00231 SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODRSTEN_Msk) | (uint32_t)i32Mode; 00232 /* Select Brown-out Detector threshold voltage */ 00233 SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODVL_Msk) | u32BODLevel; 00234 } 00235 00236 /** 00237 * @brief Disable Brown-out detector function 00238 * @param None 00239 * @return None 00240 * @details This function disable Brown-out detector function. 00241 * The register write-protection function should be disabled before using this function. 00242 */ 00243 void SYS_DisableBOD(void) 00244 { 00245 SYS->BODCTL &= ~SYS_BODCTL_BODEN_Msk; 00246 } 00247 00248 /** 00249 * @brief Set Power Level 00250 * @param[in] u32PowerLevel is power level setting. Including : 00251 * - \ref SYS_PLCTL_PLSEL_PL0 00252 * - \ref SYS_PLCTL_PLSEL_PL1 00253 * @return None 00254 * @details This function select power level. 00255 * The register write-protection function should be disabled before using this function. 00256 */ 00257 void SYS_SetPowerLevel(uint32_t u32PowerLevel) 00258 { 00259 /* Set power voltage level */ 00260 SYS->PLCTL = (SYS->PLCTL & (~SYS_PLCTL_PLSEL_Msk)) | (u32PowerLevel); 00261 } 00262 00263 /*@}*/ /* end of group SYS_EXPORTED_FUNCTIONS */ 00264 00265 /*@}*/ /* end of group SYS_Driver */ 00266 00267 /*@}*/ /* end of group Standard_Driver */ 00268 00269 #ifdef __cplusplus 00270 } 00271 #endif 00272 00273 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
Generated on Tue Jul 12 2022 15:37:20 by
