Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_sys.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /*************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file sys.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V1.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 15 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 14/10/06 1:06p $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief NUC472/NUC442 SYS driver source file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | |
sahilmgandhi | 18:6a4db94011d3 | 12 | #include "NUC472_442.h" |
sahilmgandhi | 18:6a4db94011d3 | 13 | /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver |
sahilmgandhi | 18:6a4db94011d3 | 14 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 15 | */ |
sahilmgandhi | 18:6a4db94011d3 | 16 | |
sahilmgandhi | 18:6a4db94011d3 | 17 | /** @addtogroup NUC472_442_SYS_Driver SYS Driver |
sahilmgandhi | 18:6a4db94011d3 | 18 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 19 | */ |
sahilmgandhi | 18:6a4db94011d3 | 20 | |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | /** @addtogroup NUC472_442_SYS_EXPORTED_FUNCTIONS SYS Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 23 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 24 | */ |
sahilmgandhi | 18:6a4db94011d3 | 25 | |
sahilmgandhi | 18:6a4db94011d3 | 26 | /** |
sahilmgandhi | 18:6a4db94011d3 | 27 | * @brief This function clear the selected system reset source |
sahilmgandhi | 18:6a4db94011d3 | 28 | * @param[in] u32RstSrc is system reset source. Including: |
sahilmgandhi | 18:6a4db94011d3 | 29 | * - \ref SYS_RSTSTS_PORF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 30 | * - \ref SYS_RSTSTS_PINRF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 31 | * - \ref SYS_RSTSTS_WDTRF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 32 | * - \ref SYS_RSTSTS_LVRF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 33 | * - \ref SYS_RSTSTS_BODRF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 34 | * - \ref SYS_RSTSTS_SYSRF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 35 | * - \ref SYS_RSTSTS_CPURF_Msk |
sahilmgandhi | 18:6a4db94011d3 | 36 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 37 | */ |
sahilmgandhi | 18:6a4db94011d3 | 38 | void SYS_ClearResetSrc(uint32_t u32RstSrc) |
sahilmgandhi | 18:6a4db94011d3 | 39 | { |
sahilmgandhi | 18:6a4db94011d3 | 40 | SYS->RSTSTS |= u32RstSrc; |
sahilmgandhi | 18:6a4db94011d3 | 41 | } |
sahilmgandhi | 18:6a4db94011d3 | 42 | |
sahilmgandhi | 18:6a4db94011d3 | 43 | /** |
sahilmgandhi | 18:6a4db94011d3 | 44 | * @brief This function get Brown-out detector output status |
sahilmgandhi | 18:6a4db94011d3 | 45 | * @return 0: System voltage is higher than BODVL setting or BODEN is 0. |
sahilmgandhi | 18:6a4db94011d3 | 46 | * 1: System voltage is lower than BODVL setting. |
sahilmgandhi | 18:6a4db94011d3 | 47 | * Note : If the BOD_EN is 0, this function always return 0. |
sahilmgandhi | 18:6a4db94011d3 | 48 | */ |
sahilmgandhi | 18:6a4db94011d3 | 49 | uint32_t SYS_GetBODStatus() |
sahilmgandhi | 18:6a4db94011d3 | 50 | { |
sahilmgandhi | 18:6a4db94011d3 | 51 | return (SYS->BODCTL & SYS_BODCTL_BODOUT_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 52 | } |
sahilmgandhi | 18:6a4db94011d3 | 53 | |
sahilmgandhi | 18:6a4db94011d3 | 54 | /** |
sahilmgandhi | 18:6a4db94011d3 | 55 | * @brief This function get the system reset source register value |
sahilmgandhi | 18:6a4db94011d3 | 56 | * @return Reset source |
sahilmgandhi | 18:6a4db94011d3 | 57 | */ |
sahilmgandhi | 18:6a4db94011d3 | 58 | uint32_t SYS_GetResetSrc(void) |
sahilmgandhi | 18:6a4db94011d3 | 59 | { |
sahilmgandhi | 18:6a4db94011d3 | 60 | return (SYS->RSTSTS); |
sahilmgandhi | 18:6a4db94011d3 | 61 | } |
sahilmgandhi | 18:6a4db94011d3 | 62 | |
sahilmgandhi | 18:6a4db94011d3 | 63 | /** |
sahilmgandhi | 18:6a4db94011d3 | 64 | * @brief This function check register write-protection bit setting |
sahilmgandhi | 18:6a4db94011d3 | 65 | * @return 0: Write-protection function is disabled. |
sahilmgandhi | 18:6a4db94011d3 | 66 | * 1: Write-protection function is enabled. |
sahilmgandhi | 18:6a4db94011d3 | 67 | */ |
sahilmgandhi | 18:6a4db94011d3 | 68 | uint32_t SYS_IsRegLocked(void) |
sahilmgandhi | 18:6a4db94011d3 | 69 | { |
sahilmgandhi | 18:6a4db94011d3 | 70 | return (SYS->REGLCTL & SYS_REGLCTL_REGLCTL_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 71 | } |
sahilmgandhi | 18:6a4db94011d3 | 72 | |
sahilmgandhi | 18:6a4db94011d3 | 73 | /** |
sahilmgandhi | 18:6a4db94011d3 | 74 | * @brief This function enable register write-protection function |
sahilmgandhi | 18:6a4db94011d3 | 75 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 76 | * @details To lock the protected register to forbid write access |
sahilmgandhi | 18:6a4db94011d3 | 77 | */ |
sahilmgandhi | 18:6a4db94011d3 | 78 | void SYS_LockReg(void) |
sahilmgandhi | 18:6a4db94011d3 | 79 | { |
sahilmgandhi | 18:6a4db94011d3 | 80 | SYS->REGLCTL = 0; |
sahilmgandhi | 18:6a4db94011d3 | 81 | } |
sahilmgandhi | 18:6a4db94011d3 | 82 | |
sahilmgandhi | 18:6a4db94011d3 | 83 | |
sahilmgandhi | 18:6a4db94011d3 | 84 | /** |
sahilmgandhi | 18:6a4db94011d3 | 85 | * @brief This function disable register write-protection function |
sahilmgandhi | 18:6a4db94011d3 | 86 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 87 | * @details To unlock the protected register to allow write access |
sahilmgandhi | 18:6a4db94011d3 | 88 | */ |
sahilmgandhi | 18:6a4db94011d3 | 89 | void SYS_UnlockReg(void) |
sahilmgandhi | 18:6a4db94011d3 | 90 | { |
sahilmgandhi | 18:6a4db94011d3 | 91 | while(SYS->REGLCTL != SYS_REGLCTL_REGLCTL_Msk) { |
sahilmgandhi | 18:6a4db94011d3 | 92 | SYS->REGLCTL = 0x59; |
sahilmgandhi | 18:6a4db94011d3 | 93 | SYS->REGLCTL = 0x16; |
sahilmgandhi | 18:6a4db94011d3 | 94 | SYS->REGLCTL = 0x88; |
sahilmgandhi | 18:6a4db94011d3 | 95 | } |
sahilmgandhi | 18:6a4db94011d3 | 96 | } |
sahilmgandhi | 18:6a4db94011d3 | 97 | |
sahilmgandhi | 18:6a4db94011d3 | 98 | /** |
sahilmgandhi | 18:6a4db94011d3 | 99 | * @brief This function get product ID. |
sahilmgandhi | 18:6a4db94011d3 | 100 | * @return Product ID |
sahilmgandhi | 18:6a4db94011d3 | 101 | */ |
sahilmgandhi | 18:6a4db94011d3 | 102 | uint32_t SYS_ReadPDID(void) |
sahilmgandhi | 18:6a4db94011d3 | 103 | { |
sahilmgandhi | 18:6a4db94011d3 | 104 | return SYS->PDID; |
sahilmgandhi | 18:6a4db94011d3 | 105 | } |
sahilmgandhi | 18:6a4db94011d3 | 106 | |
sahilmgandhi | 18:6a4db94011d3 | 107 | /** |
sahilmgandhi | 18:6a4db94011d3 | 108 | * @brief This function reset chip. |
sahilmgandhi | 18:6a4db94011d3 | 109 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 110 | */ |
sahilmgandhi | 18:6a4db94011d3 | 111 | void SYS_ResetChip(void) |
sahilmgandhi | 18:6a4db94011d3 | 112 | { |
sahilmgandhi | 18:6a4db94011d3 | 113 | SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 114 | } |
sahilmgandhi | 18:6a4db94011d3 | 115 | |
sahilmgandhi | 18:6a4db94011d3 | 116 | /** |
sahilmgandhi | 18:6a4db94011d3 | 117 | * @brief This function reset CPU. |
sahilmgandhi | 18:6a4db94011d3 | 118 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 119 | */ |
sahilmgandhi | 18:6a4db94011d3 | 120 | void SYS_ResetCPU(void) |
sahilmgandhi | 18:6a4db94011d3 | 121 | { |
sahilmgandhi | 18:6a4db94011d3 | 122 | SYS->IPRST0 |= SYS_IPRST0_CPURST_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 123 | } |
sahilmgandhi | 18:6a4db94011d3 | 124 | |
sahilmgandhi | 18:6a4db94011d3 | 125 | /** |
sahilmgandhi | 18:6a4db94011d3 | 126 | * @brief This function reset selected modules. |
sahilmgandhi | 18:6a4db94011d3 | 127 | * @param[in] u32ModuleIndex is module index. Including : |
sahilmgandhi | 18:6a4db94011d3 | 128 | * - \ref CHIP_RST |
sahilmgandhi | 18:6a4db94011d3 | 129 | * - \ref CPU_RST |
sahilmgandhi | 18:6a4db94011d3 | 130 | * - \ref PDMA_RST |
sahilmgandhi | 18:6a4db94011d3 | 131 | * - \ref EBI_RST |
sahilmgandhi | 18:6a4db94011d3 | 132 | * - \ref USBH_RST |
sahilmgandhi | 18:6a4db94011d3 | 133 | * - \ref EMAC_RST |
sahilmgandhi | 18:6a4db94011d3 | 134 | * - \ref SDH_RST |
sahilmgandhi | 18:6a4db94011d3 | 135 | * - \ref CRC_RST |
sahilmgandhi | 18:6a4db94011d3 | 136 | * - \ref CAP_RST |
sahilmgandhi | 18:6a4db94011d3 | 137 | * - \ref SPACC_RST |
sahilmgandhi | 18:6a4db94011d3 | 138 | * - \ref GPIO_RST |
sahilmgandhi | 18:6a4db94011d3 | 139 | * - \ref TMR0_RST |
sahilmgandhi | 18:6a4db94011d3 | 140 | * - \ref TMR1_RST |
sahilmgandhi | 18:6a4db94011d3 | 141 | * - \ref TMR2_RST |
sahilmgandhi | 18:6a4db94011d3 | 142 | * - \ref TMR3_RST |
sahilmgandhi | 18:6a4db94011d3 | 143 | * - \ref ACMP_RST |
sahilmgandhi | 18:6a4db94011d3 | 144 | * - \ref I2C0_RST |
sahilmgandhi | 18:6a4db94011d3 | 145 | * - \ref I2C1_RST |
sahilmgandhi | 18:6a4db94011d3 | 146 | * - \ref I2C2_RST |
sahilmgandhi | 18:6a4db94011d3 | 147 | * - \ref I2C3_RST |
sahilmgandhi | 18:6a4db94011d3 | 148 | * - \ref SPI0_RST |
sahilmgandhi | 18:6a4db94011d3 | 149 | * - \ref SPI1_RST |
sahilmgandhi | 18:6a4db94011d3 | 150 | * - \ref SPI2_RST |
sahilmgandhi | 18:6a4db94011d3 | 151 | * - \ref SPI3_RST |
sahilmgandhi | 18:6a4db94011d3 | 152 | * - \ref UART0_RST |
sahilmgandhi | 18:6a4db94011d3 | 153 | * - \ref UART1_RST |
sahilmgandhi | 18:6a4db94011d3 | 154 | * - \ref UART2_RST |
sahilmgandhi | 18:6a4db94011d3 | 155 | * - \ref UART3_RST |
sahilmgandhi | 18:6a4db94011d3 | 156 | * - \ref UART4_RST |
sahilmgandhi | 18:6a4db94011d3 | 157 | * - \ref UART5_RST |
sahilmgandhi | 18:6a4db94011d3 | 158 | * - \ref CAN0_RST |
sahilmgandhi | 18:6a4db94011d3 | 159 | * - \ref CAN1_RST |
sahilmgandhi | 18:6a4db94011d3 | 160 | * - \ref OTG_RST |
sahilmgandhi | 18:6a4db94011d3 | 161 | * - \ref USBD_RST |
sahilmgandhi | 18:6a4db94011d3 | 162 | * - \ref ADC_RST |
sahilmgandhi | 18:6a4db94011d3 | 163 | * - \ref I2S0_RST |
sahilmgandhi | 18:6a4db94011d3 | 164 | * - \ref I2S1_RST |
sahilmgandhi | 18:6a4db94011d3 | 165 | * - \ref PS2_RST |
sahilmgandhi | 18:6a4db94011d3 | 166 | * - \ref SC0_RST |
sahilmgandhi | 18:6a4db94011d3 | 167 | * - \ref SC1_RST |
sahilmgandhi | 18:6a4db94011d3 | 168 | * - \ref SC2_RST |
sahilmgandhi | 18:6a4db94011d3 | 169 | * - \ref SC3_RST |
sahilmgandhi | 18:6a4db94011d3 | 170 | * - \ref SC4_RST |
sahilmgandhi | 18:6a4db94011d3 | 171 | * - \ref SC5_RST |
sahilmgandhi | 18:6a4db94011d3 | 172 | * - \ref I2C4_RST |
sahilmgandhi | 18:6a4db94011d3 | 173 | * - \ref PWM0_RST |
sahilmgandhi | 18:6a4db94011d3 | 174 | * - \ref PWM1_RST |
sahilmgandhi | 18:6a4db94011d3 | 175 | * - \ref QEI0_RST |
sahilmgandhi | 18:6a4db94011d3 | 176 | * - \ref QEI1_RST |
sahilmgandhi | 18:6a4db94011d3 | 177 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 178 | */ |
sahilmgandhi | 18:6a4db94011d3 | 179 | void SYS_ResetModule(uint32_t u32ModuleIndex) |
sahilmgandhi | 18:6a4db94011d3 | 180 | { |
sahilmgandhi | 18:6a4db94011d3 | 181 | *(volatile uint32_t *)((uint32_t)&(SYS->IPRST0) + (u32ModuleIndex>>24)) |= 1<<(u32ModuleIndex & 0x00ffffff); |
sahilmgandhi | 18:6a4db94011d3 | 182 | *(volatile uint32_t *)((uint32_t)&(SYS->IPRST0) + (u32ModuleIndex>>24)) &= ~(1<<(u32ModuleIndex & 0x00ffffff)); |
sahilmgandhi | 18:6a4db94011d3 | 183 | } |
sahilmgandhi | 18:6a4db94011d3 | 184 | |
sahilmgandhi | 18:6a4db94011d3 | 185 | /** |
sahilmgandhi | 18:6a4db94011d3 | 186 | * @brief This function configure BOD function. |
sahilmgandhi | 18:6a4db94011d3 | 187 | * Configure BOD reset or interrupt mode and set Brown-out voltage level. |
sahilmgandhi | 18:6a4db94011d3 | 188 | * Enable Brown-out function |
sahilmgandhi | 18:6a4db94011d3 | 189 | * @param[in] i32Mode is reset or interrupt mode. Including : |
sahilmgandhi | 18:6a4db94011d3 | 190 | * - \ref SYS_BODCTL_BODRSTEN |
sahilmgandhi | 18:6a4db94011d3 | 191 | * - \ref SYS_BODCTL_BODINTEN |
sahilmgandhi | 18:6a4db94011d3 | 192 | * @param[in] u32BODLevel is Brown-out voltage level. Including : |
sahilmgandhi | 18:6a4db94011d3 | 193 | * - \ref SYS_BODCTL_BODVL_2_2V |
sahilmgandhi | 18:6a4db94011d3 | 194 | * - \ref SYS_BODCTL_BODVL_2_7V |
sahilmgandhi | 18:6a4db94011d3 | 195 | * - \ref SYS_BODCTL_BODVL_3_8V |
sahilmgandhi | 18:6a4db94011d3 | 196 | * - \ref SYS_BODCTL_BODVL_4_5V |
sahilmgandhi | 18:6a4db94011d3 | 197 | * |
sahilmgandhi | 18:6a4db94011d3 | 198 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 199 | */ |
sahilmgandhi | 18:6a4db94011d3 | 200 | void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel) |
sahilmgandhi | 18:6a4db94011d3 | 201 | { |
sahilmgandhi | 18:6a4db94011d3 | 202 | SYS->BODCTL &= ~(SYS_BODCTL_BODVL_Msk|SYS_BODCTL_BODRSTEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 203 | SYS->BODCTL |=(i32Mode|u32BODLevel|SYS_BODCTL_BODEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 204 | } |
sahilmgandhi | 18:6a4db94011d3 | 205 | |
sahilmgandhi | 18:6a4db94011d3 | 206 | /** |
sahilmgandhi | 18:6a4db94011d3 | 207 | * @brief This function disable BOD function. |
sahilmgandhi | 18:6a4db94011d3 | 208 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 209 | */ |
sahilmgandhi | 18:6a4db94011d3 | 210 | void SYS_DisableBOD(void) |
sahilmgandhi | 18:6a4db94011d3 | 211 | { |
sahilmgandhi | 18:6a4db94011d3 | 212 | SYS->BODCTL &= ~SYS_BODCTL_BODEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 213 | } |
sahilmgandhi | 18:6a4db94011d3 | 214 | |
sahilmgandhi | 18:6a4db94011d3 | 215 | |
sahilmgandhi | 18:6a4db94011d3 | 216 | |
sahilmgandhi | 18:6a4db94011d3 | 217 | /*@}*/ /* end of group NUC472_442_SYS_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 218 | |
sahilmgandhi | 18:6a4db94011d3 | 219 | /*@}*/ /* end of group NUC472_442_SYS_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 220 | |
sahilmgandhi | 18:6a4db94011d3 | 221 | /*@}*/ /* end of group NUC472_442_Device_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 222 | |
sahilmgandhi | 18:6a4db94011d3 | 223 | /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/ |
sahilmgandhi | 18:6a4db94011d3 | 224 |