mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Oct 28 11:17:30 2016 +0100
Revision:
149:156823d33999
This updates the lib to the mbed lib v128

NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**************************************************************************//**
<> 149:156823d33999 2 * @file sys.c
<> 149:156823d33999 3 * @version V3.00
<> 149:156823d33999 4 * $Revision: 12 $
<> 149:156823d33999 5 * $Date: 15/08/11 10:26a $
<> 149:156823d33999 6 * @brief M451 series SYS driver source file
<> 149:156823d33999 7 *
<> 149:156823d33999 8 * @note
<> 149:156823d33999 9 * Copyright (C) 2014~2015 Nuvoton Technology Corp. All rights reserved.
<> 149:156823d33999 10 *****************************************************************************/
<> 149:156823d33999 11
<> 149:156823d33999 12 #include "M451Series.h"
<> 149:156823d33999 13
<> 149:156823d33999 14 #ifdef __cplusplus
<> 149:156823d33999 15 extern "C"
<> 149:156823d33999 16 {
<> 149:156823d33999 17 #endif
<> 149:156823d33999 18
<> 149:156823d33999 19 /** @addtogroup Standard_Driver Standard Driver
<> 149:156823d33999 20 @{
<> 149:156823d33999 21 */
<> 149:156823d33999 22
<> 149:156823d33999 23 /** @addtogroup SYS_Driver SYS Driver
<> 149:156823d33999 24 @{
<> 149:156823d33999 25 */
<> 149:156823d33999 26
<> 149:156823d33999 27
<> 149:156823d33999 28 /** @addtogroup SYS_EXPORTED_FUNCTIONS SYS Exported Functions
<> 149:156823d33999 29 @{
<> 149:156823d33999 30 */
<> 149:156823d33999 31
<> 149:156823d33999 32 /**
<> 149:156823d33999 33 * @brief Clear reset source
<> 149:156823d33999 34 * @param[in] u32Src is system reset source. Including :
<> 149:156823d33999 35 * - \ref SYS_RSTSTS_CPURF_Msk
<> 149:156823d33999 36 * - \ref SYS_RSTSTS_SYSRF_Msk
<> 149:156823d33999 37 * - \ref SYS_RSTSTS_BODRF_Msk
<> 149:156823d33999 38 * - \ref SYS_RSTSTS_LVRF_Msk
<> 149:156823d33999 39 * - \ref SYS_RSTSTS_WDTRF_Msk
<> 149:156823d33999 40 * - \ref SYS_RSTSTS_PINRF_Msk
<> 149:156823d33999 41 * - \ref SYS_RSTSTS_PORF_Msk
<> 149:156823d33999 42 * @return None
<> 149:156823d33999 43 * @details This function clear the selected system reset source.
<> 149:156823d33999 44 */
<> 149:156823d33999 45 void SYS_ClearResetSrc(uint32_t u32Src)
<> 149:156823d33999 46 {
<> 149:156823d33999 47 SYS->RSTSTS |= u32Src;
<> 149:156823d33999 48 }
<> 149:156823d33999 49
<> 149:156823d33999 50 /**
<> 149:156823d33999 51 * @brief Get Brown-out detector output status
<> 149:156823d33999 52 * @param None
<> 149:156823d33999 53 * @retval 0 System voltage is higher than BOD_VL setting or BOD_EN is 0.
<> 149:156823d33999 54 * @retval 1 System voltage is lower than BOD_VL setting.
<> 149:156823d33999 55 * @details This function get Brown-out detector output status.
<> 149:156823d33999 56 */
<> 149:156823d33999 57 uint32_t SYS_GetBODStatus(void)
<> 149:156823d33999 58 {
<> 149:156823d33999 59 return ((SYS->BODCTL & SYS_BODCTL_BODOUT_Msk) >> SYS_BODCTL_BODOUT_Pos);
<> 149:156823d33999 60 }
<> 149:156823d33999 61
<> 149:156823d33999 62 /**
<> 149:156823d33999 63 * @brief Get reset status register value
<> 149:156823d33999 64 * @param None
<> 149:156823d33999 65 * @return Reset source
<> 149:156823d33999 66 * @details This function get the system reset status register value.
<> 149:156823d33999 67 */
<> 149:156823d33999 68 uint32_t SYS_GetResetSrc(void)
<> 149:156823d33999 69 {
<> 149:156823d33999 70 return (SYS->RSTSTS);
<> 149:156823d33999 71 }
<> 149:156823d33999 72
<> 149:156823d33999 73 /**
<> 149:156823d33999 74 * @brief Check if register is locked nor not
<> 149:156823d33999 75 * @param None
<> 149:156823d33999 76 * @retval 0 Write-protection function is disabled.
<> 149:156823d33999 77 * 1 Write-protection function is enabled.
<> 149:156823d33999 78 * @details This function check register write-protection bit setting.
<> 149:156823d33999 79 */
<> 149:156823d33999 80 uint32_t SYS_IsRegLocked(void)
<> 149:156823d33999 81 {
<> 149:156823d33999 82 return !(SYS->REGLCTL & 0x1);
<> 149:156823d33999 83 }
<> 149:156823d33999 84
<> 149:156823d33999 85 /**
<> 149:156823d33999 86 * @brief Get product ID
<> 149:156823d33999 87 * @param None
<> 149:156823d33999 88 * @return Product ID
<> 149:156823d33999 89 * @details This function get product ID.
<> 149:156823d33999 90 */
<> 149:156823d33999 91 uint32_t SYS_ReadPDID(void)
<> 149:156823d33999 92 {
<> 149:156823d33999 93 return SYS->PDID;
<> 149:156823d33999 94 }
<> 149:156823d33999 95
<> 149:156823d33999 96 /**
<> 149:156823d33999 97 * @brief Reset chip with chip reset
<> 149:156823d33999 98 * @param None
<> 149:156823d33999 99 * @return None
<> 149:156823d33999 100 * @details This function reset chip with chip reset.
<> 149:156823d33999 101 * The register write-protection function should be disabled before using this function.
<> 149:156823d33999 102 */
<> 149:156823d33999 103 void SYS_ResetChip(void)
<> 149:156823d33999 104 {
<> 149:156823d33999 105 SYS->IPRST0 |= SYS_IPRST0_CHIPRST_Msk;
<> 149:156823d33999 106 }
<> 149:156823d33999 107
<> 149:156823d33999 108 /**
<> 149:156823d33999 109 * @brief Reset chip with CPU reset
<> 149:156823d33999 110 * @param None
<> 149:156823d33999 111 * @return None
<> 149:156823d33999 112 * @details This function reset CPU with CPU reset.
<> 149:156823d33999 113 * The register write-protection function should be disabled before using this function.
<> 149:156823d33999 114 */
<> 149:156823d33999 115 void SYS_ResetCPU(void)
<> 149:156823d33999 116 {
<> 149:156823d33999 117 SYS->IPRST0 |= SYS_IPRST0_CPURST_Msk;
<> 149:156823d33999 118 }
<> 149:156823d33999 119
<> 149:156823d33999 120 /**
<> 149:156823d33999 121 * @brief Reset selected module
<> 149:156823d33999 122 * @param[in] u32ModuleIndex is module index. Including :
<> 149:156823d33999 123 * - \ref PDMA_RST
<> 149:156823d33999 124 * - \ref EBI_RST
<> 149:156823d33999 125 * - \ref USBH_RST
<> 149:156823d33999 126 * - \ref CRC_RST
<> 149:156823d33999 127 * - \ref GPIO_RST
<> 149:156823d33999 128 * - \ref TMR0_RST
<> 149:156823d33999 129 * - \ref TMR1_RST
<> 149:156823d33999 130 * - \ref TMR2_RST
<> 149:156823d33999 131 * - \ref TMR3_RST
<> 149:156823d33999 132 * - \ref ACMP01_RST
<> 149:156823d33999 133 * - \ref I2C0_RST
<> 149:156823d33999 134 * - \ref I2C1_RST
<> 149:156823d33999 135 * - \ref SPI0_RST
<> 149:156823d33999 136 * - \ref SPI1_RST
<> 149:156823d33999 137 * - \ref SPI2_RST
<> 149:156823d33999 138 * - \ref UART0_RST
<> 149:156823d33999 139 * - \ref UART1_RST
<> 149:156823d33999 140 * - \ref UART2_RST
<> 149:156823d33999 141 * - \ref UART3_RST
<> 149:156823d33999 142 * - \ref CAN0_RST
<> 149:156823d33999 143 * - \ref OTG_RST
<> 149:156823d33999 144 * - \ref USBD_RST
<> 149:156823d33999 145 * - \ref EADC_RST
<> 149:156823d33999 146 * - \ref SC0_RST
<> 149:156823d33999 147 * - \ref DAC_RST
<> 149:156823d33999 148 * - \ref PWM0_RST
<> 149:156823d33999 149 * - \ref PWM1_RST
<> 149:156823d33999 150 * - \ref TK_RST
<> 149:156823d33999 151 * @return None
<> 149:156823d33999 152 * @details This function reset selected module.
<> 149:156823d33999 153 */
<> 149:156823d33999 154 void SYS_ResetModule(uint32_t u32ModuleIndex)
<> 149:156823d33999 155 {
<> 149:156823d33999 156 /* Generate reset signal to the corresponding module */
<> 149:156823d33999 157 *(volatile uint32_t *)((uint32_t)&SYS->IPRST0 + (u32ModuleIndex >> 24)) |= 1 << (u32ModuleIndex & 0x00ffffff);
<> 149:156823d33999 158
<> 149:156823d33999 159 /* Release corresponding module from reset state */
<> 149:156823d33999 160 *(volatile uint32_t *)((uint32_t)&SYS->IPRST0 + (u32ModuleIndex >> 24)) &= ~(1 << (u32ModuleIndex & 0x00ffffff));
<> 149:156823d33999 161 }
<> 149:156823d33999 162
<> 149:156823d33999 163 /**
<> 149:156823d33999 164 * @brief Enable and configure Brown-out detector function
<> 149:156823d33999 165 * @param[in] i32Mode is reset or interrupt mode. Including :
<> 149:156823d33999 166 * - \ref SYS_BODCTL_BOD_RST_EN
<> 149:156823d33999 167 * - \ref SYS_BODCTL_BOD_INTERRUPT_EN
<> 149:156823d33999 168 * @param[in] u32BODLevel is Brown-out voltage level. Including :
<> 149:156823d33999 169 * - \ref SYS_BODCTL_BODVL_4_5V
<> 149:156823d33999 170 * - \ref SYS_BODCTL_BODVL_3_7V
<> 149:156823d33999 171 * - \ref SYS_BODCTL_BODVL_2_7V
<> 149:156823d33999 172 * - \ref SYS_BODCTL_BODVL_2_2V
<> 149:156823d33999 173 * @return None
<> 149:156823d33999 174 * @details This function configure Brown-out detector reset or interrupt mode, enable Brown-out function and set Brown-out voltage level.
<> 149:156823d33999 175 * The register write-protection function should be disabled before using this function.
<> 149:156823d33999 176 */
<> 149:156823d33999 177 void SYS_EnableBOD(int32_t i32Mode, uint32_t u32BODLevel)
<> 149:156823d33999 178 {
<> 149:156823d33999 179 /* Enable Brown-out Detector function */
<> 149:156823d33999 180 SYS->BODCTL |= SYS_BODCTL_BODEN_Msk;
<> 149:156823d33999 181
<> 149:156823d33999 182 /* Enable Brown-out interrupt or reset function */
<> 149:156823d33999 183 SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODRSTEN_Msk) | i32Mode;
<> 149:156823d33999 184
<> 149:156823d33999 185 /* Select Brown-out Detector threshold voltage */
<> 149:156823d33999 186 SYS->BODCTL = (SYS->BODCTL & ~SYS_BODCTL_BODVL_Msk) | u32BODLevel;
<> 149:156823d33999 187 }
<> 149:156823d33999 188
<> 149:156823d33999 189 /**
<> 149:156823d33999 190 * @brief Disable Brown-out detector function
<> 149:156823d33999 191 * @param None
<> 149:156823d33999 192 * @return None
<> 149:156823d33999 193 * @details This function disable Brown-out detector function.
<> 149:156823d33999 194 * The register write-protection function should be disabled before using this function.
<> 149:156823d33999 195 */
<> 149:156823d33999 196 void SYS_DisableBOD(void)
<> 149:156823d33999 197 {
<> 149:156823d33999 198 SYS->BODCTL &= ~SYS_BODCTL_BODEN_Msk;
<> 149:156823d33999 199 }
<> 149:156823d33999 200
<> 149:156823d33999 201
<> 149:156823d33999 202
<> 149:156823d33999 203 /*@}*/ /* end of group SYS_EXPORTED_FUNCTIONS */
<> 149:156823d33999 204
<> 149:156823d33999 205 /*@}*/ /* end of group SYS_Driver */
<> 149:156823d33999 206
<> 149:156823d33999 207 /*@}*/ /* end of group Standard_Driver */
<> 149:156823d33999 208
<> 149:156823d33999 209 #ifdef __cplusplus
<> 149:156823d33999 210 }
<> 149:156823d33999 211 #endif
<> 149:156823d33999 212
<> 149:156823d33999 213 /*** (C) COPYRIGHT 2014~2015 Nuvoton Technology Corp. ***/