Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_clk.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file clk.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V1.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 35 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 16/03/04 3:42p $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief NUC472/NUC442 CLK 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_CLK_Driver CLK Driver |
sahilmgandhi | 18:6a4db94011d3 | 18 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 19 | */ |
sahilmgandhi | 18:6a4db94011d3 | 20 | |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | /** @addtogroup NUC472_442_CLK_EXPORTED_FUNCTIONS CLK Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 23 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 24 | */ |
sahilmgandhi | 18:6a4db94011d3 | 25 | |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | /** |
sahilmgandhi | 18:6a4db94011d3 | 28 | * @brief Disable frequency output function |
sahilmgandhi | 18:6a4db94011d3 | 29 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 30 | * @details This function disable frequency output function. |
sahilmgandhi | 18:6a4db94011d3 | 31 | */ |
sahilmgandhi | 18:6a4db94011d3 | 32 | void CLK_DisableCKO(void) |
sahilmgandhi | 18:6a4db94011d3 | 33 | { |
sahilmgandhi | 18:6a4db94011d3 | 34 | /* Disable CKO clock source */ |
sahilmgandhi | 18:6a4db94011d3 | 35 | CLK->APBCLK0 &= (~CLK_APBCLK0_CLKOCKEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 36 | } |
sahilmgandhi | 18:6a4db94011d3 | 37 | |
sahilmgandhi | 18:6a4db94011d3 | 38 | /** |
sahilmgandhi | 18:6a4db94011d3 | 39 | * @brief This function enable frequency divider module clock, |
sahilmgandhi | 18:6a4db94011d3 | 40 | * enable frequency divider clock function and configure frequency divider. |
sahilmgandhi | 18:6a4db94011d3 | 41 | * @param[in] u32ClkSrc is frequency divider function clock source |
sahilmgandhi | 18:6a4db94011d3 | 42 | * - \ref CLK_CLKSEL1_CLKOSEL_HXT |
sahilmgandhi | 18:6a4db94011d3 | 43 | * - \ref CLK_CLKSEL1_CLKOSEL_LXT |
sahilmgandhi | 18:6a4db94011d3 | 44 | * - \ref CLK_CLKSEL1_CLKOSEL_HCLK |
sahilmgandhi | 18:6a4db94011d3 | 45 | * - \ref CLK_CLKSEL1_CLKOSEL_HIRC |
sahilmgandhi | 18:6a4db94011d3 | 46 | * @param[in] u32ClkDiv is system reset source |
sahilmgandhi | 18:6a4db94011d3 | 47 | * @param[in] u32ClkDivBy1En is frequency divided by one enable. |
sahilmgandhi | 18:6a4db94011d3 | 48 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 49 | * |
sahilmgandhi | 18:6a4db94011d3 | 50 | * @details Output selected clock to CKO. The output clock frequency is divided by u32ClkDiv. |
sahilmgandhi | 18:6a4db94011d3 | 51 | * The formula is: |
sahilmgandhi | 18:6a4db94011d3 | 52 | * CKO frequency = (Clock source frequency) / 2^(u32ClkDiv + 1) |
sahilmgandhi | 18:6a4db94011d3 | 53 | * This function is just used to set CKO clock. |
sahilmgandhi | 18:6a4db94011d3 | 54 | * User must enable I/O for CKO clock output pin by themselves. |
sahilmgandhi | 18:6a4db94011d3 | 55 | */ |
sahilmgandhi | 18:6a4db94011d3 | 56 | void CLK_EnableCKO(uint32_t u32ClkSrc, uint32_t u32ClkDiv, uint32_t u32ClkDivBy1En) |
sahilmgandhi | 18:6a4db94011d3 | 57 | { |
sahilmgandhi | 18:6a4db94011d3 | 58 | /* CKO = clock source / 2^(u32ClkDiv + 1) */ |
sahilmgandhi | 18:6a4db94011d3 | 59 | CLK->CLKOCTL = CLK_CLKOCTL_CLKOEN_Msk | u32ClkDiv | u32ClkDivBy1En<<CLK_CLKOCTL_DIV1EN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 60 | |
sahilmgandhi | 18:6a4db94011d3 | 61 | /* Enable CKO clock source */ |
sahilmgandhi | 18:6a4db94011d3 | 62 | CLK->APBCLK0 |= CLK_APBCLK0_CLKOCKEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 63 | |
sahilmgandhi | 18:6a4db94011d3 | 64 | /* Select CKO clock source */ |
sahilmgandhi | 18:6a4db94011d3 | 65 | CLK->CLKSEL1 = (CLK->CLKSEL1 & (~CLK_CLKSEL1_CLKOSEL_Msk)) | u32ClkSrc; |
sahilmgandhi | 18:6a4db94011d3 | 66 | } |
sahilmgandhi | 18:6a4db94011d3 | 67 | |
sahilmgandhi | 18:6a4db94011d3 | 68 | /** |
sahilmgandhi | 18:6a4db94011d3 | 69 | * @brief Enter to Power-down mode |
sahilmgandhi | 18:6a4db94011d3 | 70 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 71 | * @details This function let system enter to Power-down mode. |
sahilmgandhi | 18:6a4db94011d3 | 72 | */ |
sahilmgandhi | 18:6a4db94011d3 | 73 | void CLK_PowerDown(void) |
sahilmgandhi | 18:6a4db94011d3 | 74 | { |
sahilmgandhi | 18:6a4db94011d3 | 75 | SCB->SCR = SCB_SCR_SLEEPDEEP_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 76 | CLK->PWRCTL |= (CLK_PWRCTL_PDEN_Msk | CLK_PWRCTL_PDWKDLY_Msk ); |
sahilmgandhi | 18:6a4db94011d3 | 77 | __WFI(); |
sahilmgandhi | 18:6a4db94011d3 | 78 | } |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | /** |
sahilmgandhi | 18:6a4db94011d3 | 81 | * @brief Enter to Idle mode. |
sahilmgandhi | 18:6a4db94011d3 | 82 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 83 | * @details This function let system enter to Idle mode. |
sahilmgandhi | 18:6a4db94011d3 | 84 | */ |
sahilmgandhi | 18:6a4db94011d3 | 85 | void CLK_Idle(void) |
sahilmgandhi | 18:6a4db94011d3 | 86 | { |
sahilmgandhi | 18:6a4db94011d3 | 87 | /* Set the processor uses sleep as its low power mode */ |
sahilmgandhi | 18:6a4db94011d3 | 88 | SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 89 | |
sahilmgandhi | 18:6a4db94011d3 | 90 | /* Set chip in idle mode because of WFI command */ |
sahilmgandhi | 18:6a4db94011d3 | 91 | CLK->PWRCTL &= ~(CLK_PWRCTL_PDEN_Msk ); |
sahilmgandhi | 18:6a4db94011d3 | 92 | |
sahilmgandhi | 18:6a4db94011d3 | 93 | /* Chip enter idle mode after CPU run WFI instruction */ |
sahilmgandhi | 18:6a4db94011d3 | 94 | __WFI(); |
sahilmgandhi | 18:6a4db94011d3 | 95 | } |
sahilmgandhi | 18:6a4db94011d3 | 96 | |
sahilmgandhi | 18:6a4db94011d3 | 97 | |
sahilmgandhi | 18:6a4db94011d3 | 98 | /** |
sahilmgandhi | 18:6a4db94011d3 | 99 | * @brief This function get PCLK frequency. The frequency unit is Hz. |
sahilmgandhi | 18:6a4db94011d3 | 100 | * @return PCLK frequency |
sahilmgandhi | 18:6a4db94011d3 | 101 | */ |
sahilmgandhi | 18:6a4db94011d3 | 102 | uint32_t CLK_GetPCLKFreq(void) |
sahilmgandhi | 18:6a4db94011d3 | 103 | { |
sahilmgandhi | 18:6a4db94011d3 | 104 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 105 | if(CLK->CLKSEL0 & CLK_CLKSEL0_PCLKSEL_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 106 | return SystemCoreClock/2; |
sahilmgandhi | 18:6a4db94011d3 | 107 | else |
sahilmgandhi | 18:6a4db94011d3 | 108 | return SystemCoreClock; |
sahilmgandhi | 18:6a4db94011d3 | 109 | } |
sahilmgandhi | 18:6a4db94011d3 | 110 | |
sahilmgandhi | 18:6a4db94011d3 | 111 | /** |
sahilmgandhi | 18:6a4db94011d3 | 112 | * @brief Get external high speed crystal clock frequency |
sahilmgandhi | 18:6a4db94011d3 | 113 | * @return External high frequency crystal frequency |
sahilmgandhi | 18:6a4db94011d3 | 114 | * @details This function get external high frequency crystal frequency. The frequency unit is Hz. |
sahilmgandhi | 18:6a4db94011d3 | 115 | */ |
sahilmgandhi | 18:6a4db94011d3 | 116 | uint32_t CLK_GetHXTFreq(void) |
sahilmgandhi | 18:6a4db94011d3 | 117 | { |
sahilmgandhi | 18:6a4db94011d3 | 118 | if(CLK->PWRCTL & CLK_PWRCTL_HXTEN_Msk ) |
sahilmgandhi | 18:6a4db94011d3 | 119 | return __HXT; |
sahilmgandhi | 18:6a4db94011d3 | 120 | else |
sahilmgandhi | 18:6a4db94011d3 | 121 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 122 | } |
sahilmgandhi | 18:6a4db94011d3 | 123 | |
sahilmgandhi | 18:6a4db94011d3 | 124 | /** |
sahilmgandhi | 18:6a4db94011d3 | 125 | * @brief Get external low speed crystal clock frequency |
sahilmgandhi | 18:6a4db94011d3 | 126 | * @return External low speed crystal clock frequency |
sahilmgandhi | 18:6a4db94011d3 | 127 | * @details This function get external low frequency crystal frequency. The frequency unit is Hz. |
sahilmgandhi | 18:6a4db94011d3 | 128 | */ |
sahilmgandhi | 18:6a4db94011d3 | 129 | uint32_t CLK_GetLXTFreq(void) |
sahilmgandhi | 18:6a4db94011d3 | 130 | { |
sahilmgandhi | 18:6a4db94011d3 | 131 | if(CLK->PWRCTL & CLK_PWRCTL_LXTEN_Msk ) |
sahilmgandhi | 18:6a4db94011d3 | 132 | return __LXT; |
sahilmgandhi | 18:6a4db94011d3 | 133 | else |
sahilmgandhi | 18:6a4db94011d3 | 134 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 135 | } |
sahilmgandhi | 18:6a4db94011d3 | 136 | |
sahilmgandhi | 18:6a4db94011d3 | 137 | |
sahilmgandhi | 18:6a4db94011d3 | 138 | /** |
sahilmgandhi | 18:6a4db94011d3 | 139 | * @brief Get HCLK frequency |
sahilmgandhi | 18:6a4db94011d3 | 140 | * @return HCLK frequency |
sahilmgandhi | 18:6a4db94011d3 | 141 | * @details This function get HCLK frequency. The frequency unit is Hz. |
sahilmgandhi | 18:6a4db94011d3 | 142 | */ |
sahilmgandhi | 18:6a4db94011d3 | 143 | uint32_t CLK_GetHCLKFreq(void) |
sahilmgandhi | 18:6a4db94011d3 | 144 | { |
sahilmgandhi | 18:6a4db94011d3 | 145 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 146 | return SystemCoreClock; |
sahilmgandhi | 18:6a4db94011d3 | 147 | } |
sahilmgandhi | 18:6a4db94011d3 | 148 | |
sahilmgandhi | 18:6a4db94011d3 | 149 | /** |
sahilmgandhi | 18:6a4db94011d3 | 150 | * @brief Get CPU frequency |
sahilmgandhi | 18:6a4db94011d3 | 151 | * @return CPU frequency |
sahilmgandhi | 18:6a4db94011d3 | 152 | * @details This function get CPU frequency. The frequency unit is Hz. |
sahilmgandhi | 18:6a4db94011d3 | 153 | */ |
sahilmgandhi | 18:6a4db94011d3 | 154 | uint32_t CLK_GetCPUFreq(void) |
sahilmgandhi | 18:6a4db94011d3 | 155 | { |
sahilmgandhi | 18:6a4db94011d3 | 156 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 157 | return SystemCoreClock; |
sahilmgandhi | 18:6a4db94011d3 | 158 | } |
sahilmgandhi | 18:6a4db94011d3 | 159 | |
sahilmgandhi | 18:6a4db94011d3 | 160 | /** |
sahilmgandhi | 18:6a4db94011d3 | 161 | * @brief This function get PLL frequency. The frequency unit is Hz. |
sahilmgandhi | 18:6a4db94011d3 | 162 | * @return PLL frequency |
sahilmgandhi | 18:6a4db94011d3 | 163 | */ |
sahilmgandhi | 18:6a4db94011d3 | 164 | uint32_t CLK_GetPLLClockFreq(void) |
sahilmgandhi | 18:6a4db94011d3 | 165 | { |
sahilmgandhi | 18:6a4db94011d3 | 166 | uint32_t u32Freq =0, u32PLLSrc; |
sahilmgandhi | 18:6a4db94011d3 | 167 | uint32_t u32NO,u32NF,u32NR,u32PllReg; |
sahilmgandhi | 18:6a4db94011d3 | 168 | |
sahilmgandhi | 18:6a4db94011d3 | 169 | u32PllReg = CLK->PLLCTL; |
sahilmgandhi | 18:6a4db94011d3 | 170 | |
sahilmgandhi | 18:6a4db94011d3 | 171 | if(u32PllReg & (CLK_PLLCTL_PD_Msk | CLK_PLLCTL_OE_Msk)) |
sahilmgandhi | 18:6a4db94011d3 | 172 | return 0; /* PLL is in power down mode or fix low */ |
sahilmgandhi | 18:6a4db94011d3 | 173 | |
sahilmgandhi | 18:6a4db94011d3 | 174 | if(u32PllReg & CLK_PLLCTL_PLLSRC_Msk) |
sahilmgandhi | 18:6a4db94011d3 | 175 | u32PLLSrc = __HIRC; |
sahilmgandhi | 18:6a4db94011d3 | 176 | else |
sahilmgandhi | 18:6a4db94011d3 | 177 | u32PLLSrc = __HXT; |
sahilmgandhi | 18:6a4db94011d3 | 178 | |
sahilmgandhi | 18:6a4db94011d3 | 179 | u32NO=(u32PllReg & CLK_PLLCTL_OUTDV_Msk)>>CLK_PLLCTL_OUTDV_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 180 | switch(u32NO) { |
sahilmgandhi | 18:6a4db94011d3 | 181 | case 0: |
sahilmgandhi | 18:6a4db94011d3 | 182 | u32NO=1; |
sahilmgandhi | 18:6a4db94011d3 | 183 | break; |
sahilmgandhi | 18:6a4db94011d3 | 184 | case 1: |
sahilmgandhi | 18:6a4db94011d3 | 185 | case 2: |
sahilmgandhi | 18:6a4db94011d3 | 186 | u32NO=2; |
sahilmgandhi | 18:6a4db94011d3 | 187 | break; |
sahilmgandhi | 18:6a4db94011d3 | 188 | case 3: |
sahilmgandhi | 18:6a4db94011d3 | 189 | u32NO=4; |
sahilmgandhi | 18:6a4db94011d3 | 190 | break; |
sahilmgandhi | 18:6a4db94011d3 | 191 | } |
sahilmgandhi | 18:6a4db94011d3 | 192 | |
sahilmgandhi | 18:6a4db94011d3 | 193 | u32NF = (u32PllReg & CLK_PLLCTL_FBDIV_Msk) + 2; |
sahilmgandhi | 18:6a4db94011d3 | 194 | u32NR = ( (u32PllReg & CLK_PLLCTL_INDIV_Msk)>>CLK_PLLCTL_INDIV_Pos ) + 2; |
sahilmgandhi | 18:6a4db94011d3 | 195 | |
sahilmgandhi | 18:6a4db94011d3 | 196 | /* u32PLLSrc is shifted 2 bits to avoid overflow */ |
sahilmgandhi | 18:6a4db94011d3 | 197 | u32Freq = (((u32PLLSrc >> 2) * u32NF) / (u32NR * u32NO) << 2); |
sahilmgandhi | 18:6a4db94011d3 | 198 | return u32Freq; |
sahilmgandhi | 18:6a4db94011d3 | 199 | } |
sahilmgandhi | 18:6a4db94011d3 | 200 | |
sahilmgandhi | 18:6a4db94011d3 | 201 | /** |
sahilmgandhi | 18:6a4db94011d3 | 202 | * @brief Set HCLK frequency |
sahilmgandhi | 18:6a4db94011d3 | 203 | * @param[in] u32Hclk is HCLK frequency |
sahilmgandhi | 18:6a4db94011d3 | 204 | * @return HCLK frequency |
sahilmgandhi | 18:6a4db94011d3 | 205 | * @details This function set HCLK frequency. The frequency unit is Hz. The range of u32Hclk is 24 MHz ~ 96 MHz. |
sahilmgandhi | 18:6a4db94011d3 | 206 | */ |
sahilmgandhi | 18:6a4db94011d3 | 207 | uint32_t CLK_SetCoreClock(uint32_t u32Hclk) |
sahilmgandhi | 18:6a4db94011d3 | 208 | { |
sahilmgandhi | 18:6a4db94011d3 | 209 | uint32_t u32ClkSrc,u32NR, u32NF,u32Register; |
sahilmgandhi | 18:6a4db94011d3 | 210 | u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLKSEL_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 211 | |
sahilmgandhi | 18:6a4db94011d3 | 212 | if(u32Hclk < FREQ_24MHZ) |
sahilmgandhi | 18:6a4db94011d3 | 213 | u32Hclk =FREQ_24MHZ; |
sahilmgandhi | 18:6a4db94011d3 | 214 | |
sahilmgandhi | 18:6a4db94011d3 | 215 | if(CLK->PWRCTL & CLK_PWRCTL_HXTEN_Msk) { |
sahilmgandhi | 18:6a4db94011d3 | 216 | u32Register = 0<<CLK_PLLCTL_PLLSRC_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 217 | u32ClkSrc = __HXT; |
sahilmgandhi | 18:6a4db94011d3 | 218 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 219 | u32Register = 1<<CLK_PLLCTL_PLLSRC_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 220 | u32ClkSrc = __HIRC; |
sahilmgandhi | 18:6a4db94011d3 | 221 | } |
sahilmgandhi | 18:6a4db94011d3 | 222 | |
sahilmgandhi | 18:6a4db94011d3 | 223 | if(u32Hclk<FREQ_50MHZ) { |
sahilmgandhi | 18:6a4db94011d3 | 224 | u32Hclk <<=2; |
sahilmgandhi | 18:6a4db94011d3 | 225 | u32Register |= (0x3<<CLK_PLLCTL_OUTDV_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 226 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 227 | u32Hclk <<=1; |
sahilmgandhi | 18:6a4db94011d3 | 228 | u32Register |= (0x1<<CLK_PLLCTL_OUTDV_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 229 | } |
sahilmgandhi | 18:6a4db94011d3 | 230 | u32NF = u32Hclk / 1000000; |
sahilmgandhi | 18:6a4db94011d3 | 231 | u32NR = u32ClkSrc / 1000000; |
sahilmgandhi | 18:6a4db94011d3 | 232 | while( u32NR>(0xF+2) || u32NF>(0xFF+2) ) { |
sahilmgandhi | 18:6a4db94011d3 | 233 | u32NR = u32NR>>1; |
sahilmgandhi | 18:6a4db94011d3 | 234 | u32NF = u32NF>>1; |
sahilmgandhi | 18:6a4db94011d3 | 235 | } |
sahilmgandhi | 18:6a4db94011d3 | 236 | CLK->PLLCTL = u32Register | ((u32NR - 2)<<9) | (u32NF - 2) ; |
sahilmgandhi | 18:6a4db94011d3 | 237 | CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 238 | |
sahilmgandhi | 18:6a4db94011d3 | 239 | CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_PLL,CLK_CLKDIV0_HCLK(1)); |
sahilmgandhi | 18:6a4db94011d3 | 240 | |
sahilmgandhi | 18:6a4db94011d3 | 241 | /* Update System Core Clock */ |
sahilmgandhi | 18:6a4db94011d3 | 242 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 243 | |
sahilmgandhi | 18:6a4db94011d3 | 244 | return SystemCoreClock; |
sahilmgandhi | 18:6a4db94011d3 | 245 | } |
sahilmgandhi | 18:6a4db94011d3 | 246 | |
sahilmgandhi | 18:6a4db94011d3 | 247 | /** |
sahilmgandhi | 18:6a4db94011d3 | 248 | * @brief This function set HCLK clock source and HCLK clock divider |
sahilmgandhi | 18:6a4db94011d3 | 249 | * @param[in] u32ClkSrc is HCLK clock source. Including : |
sahilmgandhi | 18:6a4db94011d3 | 250 | * - \ref CLK_CLKSEL0_HCLKSEL_HXT |
sahilmgandhi | 18:6a4db94011d3 | 251 | * - \ref CLK_CLKSEL0_HCLKSEL_LXT |
sahilmgandhi | 18:6a4db94011d3 | 252 | * - \ref CLK_CLKSEL0_HCLKSEL_PLL |
sahilmgandhi | 18:6a4db94011d3 | 253 | * - \ref CLK_CLKSEL0_HCLKSEL_LIRC |
sahilmgandhi | 18:6a4db94011d3 | 254 | * - \ref CLK_CLKSEL0_HCLKSEL_HIRC |
sahilmgandhi | 18:6a4db94011d3 | 255 | * @param[in] u32ClkDiv is HCLK clock divider. Including : |
sahilmgandhi | 18:6a4db94011d3 | 256 | * - \ref CLK_CLKDIV0_HCLK(x) |
sahilmgandhi | 18:6a4db94011d3 | 257 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 258 | */ |
sahilmgandhi | 18:6a4db94011d3 | 259 | void CLK_SetHCLK(uint32_t u32ClkSrc, uint32_t u32ClkDiv) |
sahilmgandhi | 18:6a4db94011d3 | 260 | { |
sahilmgandhi | 18:6a4db94011d3 | 261 | CLK->CLKDIV0 = (CLK->CLKDIV0 & ~CLK_CLKDIV0_HCLKDIV_Msk) | u32ClkDiv; |
sahilmgandhi | 18:6a4db94011d3 | 262 | CLK->CLKSEL0 = (CLK->CLKSEL0 & ~CLK_CLKSEL0_HCLKSEL_Msk) | u32ClkSrc; |
sahilmgandhi | 18:6a4db94011d3 | 263 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 264 | } |
sahilmgandhi | 18:6a4db94011d3 | 265 | |
sahilmgandhi | 18:6a4db94011d3 | 266 | /** |
sahilmgandhi | 18:6a4db94011d3 | 267 | * @brief This function set selected module clock source and module clock divider |
sahilmgandhi | 18:6a4db94011d3 | 268 | * @param[in] u32ModuleIdx is module index. |
sahilmgandhi | 18:6a4db94011d3 | 269 | * @param[in] u32ClkSrc is module clock source. |
sahilmgandhi | 18:6a4db94011d3 | 270 | * @param[in] u32ClkDiv is module clock divider. |
sahilmgandhi | 18:6a4db94011d3 | 271 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 272 | * @details Valid parameter combinations listed in following table: |
sahilmgandhi | 18:6a4db94011d3 | 273 | * |
sahilmgandhi | 18:6a4db94011d3 | 274 | * |Module index |Clock source |Divider | |
sahilmgandhi | 18:6a4db94011d3 | 275 | * | :------------------- | :------------------------------- | :------------------------- | |
sahilmgandhi | 18:6a4db94011d3 | 276 | * |\ref PDMA_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 277 | * |\ref ISP_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 278 | * |\ref EBI_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 279 | * |\ref USBH_MODULE |\ref CLK_CLKSEL0_USBHSEL_PLL |\ref CLK_CLKDIV0_USB(x) | |
sahilmgandhi | 18:6a4db94011d3 | 280 | * |\ref USBH_MODULE |\ref CLK_CLKSEL0_USBHSEL_PLL2 |\ref CLK_CLKDIV0_USB(x) | |
sahilmgandhi | 18:6a4db94011d3 | 281 | * |\ref EMAC_MODULE | x |\ref CLK_CLKDIV3_EMAC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 282 | * |\ref SDH_MODULE |\ref CLK_CLKSEL0_SDHSEL_HXT |\ref CLK_CLKDIV0_SDH(x) | |
sahilmgandhi | 18:6a4db94011d3 | 283 | * |\ref SDH_MODULE |\ref CLK_CLKSEL0_SDHSEL_PLL |\ref CLK_CLKDIV0_SDH(x) | |
sahilmgandhi | 18:6a4db94011d3 | 284 | * |\ref SDH_MODULE |\ref CLK_CLKSEL0_SDHSEL_HCLK |\ref CLK_CLKDIV0_SDH(x) | |
sahilmgandhi | 18:6a4db94011d3 | 285 | * |\ref SDH_MODULE |\ref CLK_CLKSEL0_SDHSEL_HIRC |\ref CLK_CLKDIV0_SDH(x) | |
sahilmgandhi | 18:6a4db94011d3 | 286 | * |\ref CRC_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 287 | * |\ref CAP_MODULE |\ref CLK_CLKSEL0_CAPSEL_HXT |\ref CLK_CLKDIV3_CAP(x) | |
sahilmgandhi | 18:6a4db94011d3 | 288 | * |\ref CAP_MODULE |\ref CLK_CLKSEL0_CAPSEL_PLL2 |\ref CLK_CLKDIV3_CAP(x) | |
sahilmgandhi | 18:6a4db94011d3 | 289 | * |\ref CAP_MODULE |\ref CLK_CLKSEL0_CAPSEL_HCLK |\ref CLK_CLKDIV3_CAP(x) | |
sahilmgandhi | 18:6a4db94011d3 | 290 | * |\ref CAP_MODULE |\ref CLK_CLKSEL0_CAPSEL_HIRC |\ref CLK_CLKDIV3_CAP(x) | |
sahilmgandhi | 18:6a4db94011d3 | 291 | * |\ref SEN_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 292 | * |\ref USBD_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 293 | * |\ref CRPT_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 294 | * |\ref ECAP1_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 295 | * |\ref ECAP0_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 296 | * |\ref EADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_HXT |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 297 | * |\ref EADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_PLL |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 298 | * |\ref EADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_PCLK |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 299 | * |\ref EADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_HIRC |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 300 | * |\ref OPA_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 301 | * |\ref QEI1_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 302 | * |\ref QEI0_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 303 | * |\ref PWM1CH45_MODULE |\ref CLK_CLKSEL2_PWM1CH45SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 304 | * |\ref PWM1CH45_MODULE |\ref CLK_CLKSEL2_PWM1CH45SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 305 | * |\ref PWM1CH45_MODULE |\ref CLK_CLKSEL2_PWM1CH45SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 306 | * |\ref PWM1CH45_MODULE |\ref CLK_CLKSEL2_PWM1CH45SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 307 | * |\ref PWM1CH45_MODULE |\ref CLK_CLKSEL2_PWM1CH45SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 308 | * |\ref PWM1CH23_MODULE |\ref CLK_CLKSEL2_PWM1CH23SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 309 | * |\ref PWM1CH23_MODULE |\ref CLK_CLKSEL2_PWM1CH23SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 310 | * |\ref PWM1CH23_MODULE |\ref CLK_CLKSEL2_PWM1CH23SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 311 | * |\ref PWM1CH23_MODULE |\ref CLK_CLKSEL2_PWM1CH23SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 312 | * |\ref PWM1CH23_MODULE |\ref CLK_CLKSEL2_PWM1CH23SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 313 | * |\ref PWM1CH01_MODULE |\ref CLK_CLKSEL2_PWM1CH01SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 314 | * |\ref PWM1CH01_MODULE |\ref CLK_CLKSEL2_PWM1CH01SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 315 | * |\ref PWM1CH01_MODULE |\ref CLK_CLKSEL2_PWM1CH01SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 316 | * |\ref PWM1CH01_MODULE |\ref CLK_CLKSEL2_PWM1CH01SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 317 | * |\ref PWM1CH01_MODULE |\ref CLK_CLKSEL2_PWM1CH01SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 318 | * |\ref PWM0CH45_MODULE |\ref CLK_CLKSEL2_PWM0CH45SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 319 | * |\ref PWM0CH45_MODULE |\ref CLK_CLKSEL2_PWM0CH45SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 320 | * |\ref PWM0CH45_MODULE |\ref CLK_CLKSEL2_PWM0CH45SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 321 | * |\ref PWM0CH45_MODULE |\ref CLK_CLKSEL2_PWM0CH45SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 322 | * |\ref PWM0CH45_MODULE |\ref CLK_CLKSEL2_PWM0CH45SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 323 | * |\ref PWM0CH23_MODULE |\ref CLK_CLKSEL2_PWM0CH23SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 324 | * |\ref PWM0CH23_MODULE |\ref CLK_CLKSEL2_PWM0CH23SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 325 | * |\ref PWM0CH23_MODULE |\ref CLK_CLKSEL2_PWM0CH23SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 326 | * |\ref PWM0CH23_MODULE |\ref CLK_CLKSEL2_PWM0CH23SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 327 | * |\ref PWM0CH23_MODULE |\ref CLK_CLKSEL2_PWM0CH23SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 328 | * |\ref PWM0CH01_MODULE |\ref CLK_CLKSEL2_PWM0CH01SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 329 | * |\ref PWM0CH01_MODULE |\ref CLK_CLKSEL2_PWM0CH01SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 330 | * |\ref PWM0CH01_MODULE |\ref CLK_CLKSEL2_PWM0CH01SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 331 | * |\ref PWM0CH01_MODULE |\ref CLK_CLKSEL2_PWM0CH01SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 332 | * |\ref PWM0CH01_MODULE |\ref CLK_CLKSEL2_PWM0CH01SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 333 | * |\ref I2C4_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 334 | * |\ref SC5_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 335 | * |\ref SC4_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 336 | * |\ref SC3_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 337 | * |\ref SC2_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 338 | * |\ref SC5_MODULE |\ref CLK_CLKSEL3_SC5SEL_HXT |\ref CLK_CLKDIV2_SC5(x) | |
sahilmgandhi | 18:6a4db94011d3 | 339 | * |\ref SC5_MODULE |\ref CLK_CLKSEL3_SC5SEL_PLL |\ref CLK_CLKDIV2_SC5(x) | |
sahilmgandhi | 18:6a4db94011d3 | 340 | * |\ref SC5_MODULE |\ref CLK_CLKSEL3_SC5SEL_PCLK |\ref CLK_CLKDIV2_SC5(x) | |
sahilmgandhi | 18:6a4db94011d3 | 341 | * |\ref SC5_MODULE |\ref CLK_CLKSEL3_SC5SEL_HIRC |\ref CLK_CLKDIV2_SC5(x) | |
sahilmgandhi | 18:6a4db94011d3 | 342 | * |\ref SC4_MODULE |\ref CLK_CLKSEL3_SC4SEL_HXT |\ref CLK_CLKDIV2_SC4(x) | |
sahilmgandhi | 18:6a4db94011d3 | 343 | * |\ref SC4_MODULE |\ref CLK_CLKSEL3_SC4SEL_PLL |\ref CLK_CLKDIV2_SC4(x) | |
sahilmgandhi | 18:6a4db94011d3 | 344 | * |\ref SC4_MODULE |\ref CLK_CLKSEL3_SC4SEL_PCLK |\ref CLK_CLKDIV2_SC4(x) | |
sahilmgandhi | 18:6a4db94011d3 | 345 | * |\ref SC4_MODULE |\ref CLK_CLKSEL3_SC4SEL_HIRC |\ref CLK_CLKDIV2_SC4(x) | |
sahilmgandhi | 18:6a4db94011d3 | 346 | * |\ref SC3_MODULE |\ref CLK_CLKSEL3_SC3SEL_HXT |\ref CLK_CLKDIV1_SC3(x) | |
sahilmgandhi | 18:6a4db94011d3 | 347 | * |\ref SC3_MODULE |\ref CLK_CLKSEL3_SC3SEL_PLL |\ref CLK_CLKDIV1_SC3(x) | |
sahilmgandhi | 18:6a4db94011d3 | 348 | * |\ref SC3_MODULE |\ref CLK_CLKSEL3_SC3SEL_PCLK |\ref CLK_CLKDIV1_SC3(x) | |
sahilmgandhi | 18:6a4db94011d3 | 349 | * |\ref SC3_MODULE |\ref CLK_CLKSEL3_SC3SEL_HIRC |\ref CLK_CLKDIV1_SC3(x) | |
sahilmgandhi | 18:6a4db94011d3 | 350 | * |\ref SC2_MODULE |\ref CLK_CLKSEL3_SC2SEL_HXT |\ref CLK_CLKDIV1_SC2(x) | |
sahilmgandhi | 18:6a4db94011d3 | 351 | * |\ref SC2_MODULE |\ref CLK_CLKSEL3_SC2SEL_PLL |\ref CLK_CLKDIV1_SC2(x) | |
sahilmgandhi | 18:6a4db94011d3 | 352 | * |\ref SC2_MODULE |\ref CLK_CLKSEL3_SC2SEL_PCLK |\ref CLK_CLKDIV1_SC2(x) | |
sahilmgandhi | 18:6a4db94011d3 | 353 | * |\ref SC2_MODULE |\ref CLK_CLKSEL3_SC2SEL_HIRC |\ref CLK_CLKDIV1_SC2(x) | |
sahilmgandhi | 18:6a4db94011d3 | 354 | * |\ref SC1_MODULE |\ref CLK_CLKSEL3_SC1SEL_HXT |\ref CLK_CLKDIV1_SC1(x) | |
sahilmgandhi | 18:6a4db94011d3 | 355 | * |\ref SC1_MODULE |\ref CLK_CLKSEL3_SC1SEL_PLL |\ref CLK_CLKDIV1_SC1(x) | |
sahilmgandhi | 18:6a4db94011d3 | 356 | * |\ref SC1_MODULE |\ref CLK_CLKSEL3_SC1SEL_PCLK |\ref CLK_CLKDIV1_SC1(x) | |
sahilmgandhi | 18:6a4db94011d3 | 357 | * |\ref SC1_MODULE |\ref CLK_CLKSEL3_SC1SEL_HIRC |\ref CLK_CLKDIV1_SC1(x) | |
sahilmgandhi | 18:6a4db94011d3 | 358 | * |\ref SC0_MODULE |\ref CLK_CLKSEL3_SC0SEL_HXT |\ref CLK_CLKDIV1_SC0(x) | |
sahilmgandhi | 18:6a4db94011d3 | 359 | * |\ref SC0_MODULE |\ref CLK_CLKSEL3_SC0SEL_PLL |\ref CLK_CLKDIV1_SC0(x) | |
sahilmgandhi | 18:6a4db94011d3 | 360 | * |\ref SC0_MODULE |\ref CLK_CLKSEL3_SC0SEL_PCLK |\ref CLK_CLKDIV1_SC0(x) | |
sahilmgandhi | 18:6a4db94011d3 | 361 | * |\ref SC0_MODULE |\ref CLK_CLKSEL3_SC0SEL_HIRC |\ref CLK_CLKDIV1_SC0(x) | |
sahilmgandhi | 18:6a4db94011d3 | 362 | * |\ref PS2_MODULE |\ref CLK_CLKSEL3_I2S1SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 363 | * |\ref I2S1_MODULE |\ref CLK_CLKSEL3_I2S1SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 364 | * |\ref I2S1_MODULE |\ref CLK_CLKSEL3_I2S1SEL_PLL | x | |
sahilmgandhi | 18:6a4db94011d3 | 365 | * |\ref I2S1_MODULE |\ref CLK_CLKSEL3_I2S1SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 366 | * |\ref I2S1_MODULE |\ref CLK_CLKSEL3_I2S1SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 367 | * |\ref I2S0_MODULE |\ref CLK_CLKSEL3_I2S0SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 368 | * |\ref I2S0_MODULE |\ref CLK_CLKSEL3_I2S0SEL_PLL | x | |
sahilmgandhi | 18:6a4db94011d3 | 369 | * |\ref I2S0_MODULE |\ref CLK_CLKSEL3_I2S0SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 370 | * |\ref I2S0_MODULE |\ref CLK_CLKSEL3_I2S0SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 371 | * |\ref ADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_HXT |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 372 | * |\ref ADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_PLL |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 373 | * |\ref ADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_PCLK |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 374 | * |\ref ADC_MODULE |\ref CLK_CLKSEL1_ADCSEL_HIRC |\ref CLK_CLKDIV0_ADC(x) | |
sahilmgandhi | 18:6a4db94011d3 | 375 | * |\ref OTG_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 376 | * |\ref CAN1_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 377 | * |\ref CAN0_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 378 | * |\ref UART5_MODULE |\ref CLK_CLKSEL1_UARTSEL_HXT |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 379 | * |\ref UART5_MODULE |\ref CLK_CLKSEL1_UARTSEL_PLL |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 380 | * |\ref UART5_MODULE |\ref CLK_CLKSEL1_UARTSEL_HIRC |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 381 | * |\ref UART4_MODULE |\ref CLK_CLKSEL1_UARTSEL_HXT |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 382 | * |\ref UART4_MODULE |\ref CLK_CLKSEL1_UARTSEL_PLL |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 383 | * |\ref UART4_MODULE |\ref CLK_CLKSEL1_UARTSEL_HIRC |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 384 | * |\ref UART3_MODULE |\ref CLK_CLKSEL1_UARTSEL_HXT |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 385 | * |\ref UART3_MODULE |\ref CLK_CLKSEL1_UARTSEL_PLL |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 386 | * |\ref UART3_MODULE |\ref CLK_CLKSEL1_UARTSEL_HIRC |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 387 | * |\ref UART2_MODULE |\ref CLK_CLKSEL1_UARTSEL_HXT |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 388 | * |\ref UART2_MODULE |\ref CLK_CLKSEL1_UARTSEL_PLL |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 389 | * |\ref UART2_MODULE |\ref CLK_CLKSEL1_UARTSEL_HIRC |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 390 | * |\ref UART1_MODULE |\ref CLK_CLKSEL1_UARTSEL_HXT |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 391 | * |\ref UART1_MODULE |\ref CLK_CLKSEL1_UARTSEL_PLL |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 392 | * |\ref UART1_MODULE |\ref CLK_CLKSEL1_UARTSEL_HIRC |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 393 | * |\ref UART0_MODULE |\ref CLK_CLKSEL1_UARTSEL_HXT |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 394 | * |\ref UART0_MODULE |\ref CLK_CLKSEL1_UARTSEL_PLL |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 395 | * |\ref UART0_MODULE |\ref CLK_CLKSEL1_UARTSEL_HIRC |\ref CLK_CLKDIV0_UART(x) | |
sahilmgandhi | 18:6a4db94011d3 | 396 | * |\ref SPI3_MODULE |\ref CLK_CLKSEL1_SPI3SEL_PLL | x | |
sahilmgandhi | 18:6a4db94011d3 | 397 | * |\ref SPI3_MODULE |\ref CLK_CLKSEL1_SPI3SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 398 | * |\ref SPI2_MODULE |\ref CLK_CLKSEL1_SPI2SEL_PLL | x | |
sahilmgandhi | 18:6a4db94011d3 | 399 | * |\ref SPI2_MODULE |\ref CLK_CLKSEL1_SPI2SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 400 | * |\ref SPI1_MODULE |\ref CLK_CLKSEL1_SPI1SEL_PLL | x | |
sahilmgandhi | 18:6a4db94011d3 | 401 | * |\ref SPI1_MODULE |\ref CLK_CLKSEL1_SPI1SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 402 | * |\ref SPI0_MODULE |\ref CLK_CLKSEL1_SPI0SEL_PLL | x | |
sahilmgandhi | 18:6a4db94011d3 | 403 | * |\ref SPI0_MODULE |\ref CLK_CLKSEL1_SPI0SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 404 | * |\ref I2C3_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 405 | * |\ref I2C2_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 406 | * |\ref I2C1_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 407 | * |\ref I2C0_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 408 | * |\ref ACMP_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 409 | * |\ref CLKO_MODULE |\ref CLK_CLKSEL1_CLKOSEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 410 | * |\ref CLKO_MODULE |\ref CLK_CLKSEL1_CLKOSEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 411 | * |\ref CLKO_MODULE |\ref CLK_CLKSEL1_CLKOSEL_HCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 412 | * |\ref CLKO_MODULE |\ref CLK_CLKSEL1_CLKOSEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 413 | * |\ref TMR3_MODULE |\ref CLK_CLKSEL1_TMR3SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 414 | * |\ref TMR3_MODULE |\ref CLK_CLKSEL1_TMR3SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 415 | * |\ref TMR3_MODULE |\ref CLK_CLKSEL1_TMR3SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 416 | * |\ref TMR3_MODULE |\ref CLK_CLKSEL1_TMR3SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 417 | * |\ref TMR3_MODULE |\ref CLK_CLKSEL1_TMR3SEL_EXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 418 | * |\ref TMR3_MODULE |\ref CLK_CLKSEL1_TMR3SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 419 | * |\ref TMR2_MODULE |\ref CLK_CLKSEL1_TMR2SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 420 | * |\ref TMR2_MODULE |\ref CLK_CLKSEL1_TMR2SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 421 | * |\ref TMR2_MODULE |\ref CLK_CLKSEL1_TMR2SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 422 | * |\ref TMR2_MODULE |\ref CLK_CLKSEL1_TMR2SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 423 | * |\ref TMR2_MODULE |\ref CLK_CLKSEL1_TMR2SEL_EXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 424 | * |\ref TMR2_MODULE |\ref CLK_CLKSEL1_TMR2SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 425 | * |\ref TMR1_MODULE |\ref CLK_CLKSEL1_TMR1SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 426 | * |\ref TMR1_MODULE |\ref CLK_CLKSEL1_TMR1SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 427 | * |\ref TMR1_MODULE |\ref CLK_CLKSEL1_TMR1SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 428 | * |\ref TMR1_MODULE |\ref CLK_CLKSEL1_TMR1SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 429 | * |\ref TMR1_MODULE |\ref CLK_CLKSEL1_TMR1SEL_EXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 430 | * |\ref TMR1_MODULE |\ref CLK_CLKSEL1_TMR1SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 431 | * |\ref TMR0_MODULE |\ref CLK_CLKSEL1_TMR0SEL_HXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 432 | * |\ref TMR0_MODULE |\ref CLK_CLKSEL1_TMR0SEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 433 | * |\ref TMR0_MODULE |\ref CLK_CLKSEL1_TMR0SEL_PCLK | x | |
sahilmgandhi | 18:6a4db94011d3 | 434 | * |\ref TMR0_MODULE |\ref CLK_CLKSEL1_TMR0SEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 435 | * |\ref TMR0_MODULE |\ref CLK_CLKSEL1_TMR0SEL_EXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 436 | * |\ref TMR0_MODULE |\ref CLK_CLKSEL1_TMR0SEL_HIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 437 | * |\ref RTC_MODULE | x | x | |
sahilmgandhi | 18:6a4db94011d3 | 438 | * |\ref WWDT_MODULE |\ref CLK_CLKSEL1_WWDTSEL_HCLK_DIV2048 | x | |
sahilmgandhi | 18:6a4db94011d3 | 439 | * |\ref WWDT_MODULE |\ref CLK_CLKSEL1_WWDTSEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 440 | * |\ref WDT_MODULE |\ref CLK_CLKSEL1_WDTSEL_LXT | x | |
sahilmgandhi | 18:6a4db94011d3 | 441 | * |\ref WDT_MODULE |\ref CLK_CLKSEL1_WDTSEL_HCLK_DIV2048 | x | |
sahilmgandhi | 18:6a4db94011d3 | 442 | * |\ref WDT_MODULE |\ref CLK_CLKSEL1_WDTSEL_LIRC | x | |
sahilmgandhi | 18:6a4db94011d3 | 443 | * |
sahilmgandhi | 18:6a4db94011d3 | 444 | */ |
sahilmgandhi | 18:6a4db94011d3 | 445 | |
sahilmgandhi | 18:6a4db94011d3 | 446 | void CLK_SetModuleClock(uint32_t u32ModuleIdx, uint32_t u32ClkSrc, uint32_t u32ClkDiv) |
sahilmgandhi | 18:6a4db94011d3 | 447 | { |
sahilmgandhi | 18:6a4db94011d3 | 448 | uint32_t u32tmp=0,u32sel=0,u32div=0; |
sahilmgandhi | 18:6a4db94011d3 | 449 | |
sahilmgandhi | 18:6a4db94011d3 | 450 | if(MODULE_CLKDIV_Msk(u32ModuleIdx)!=MODULE_NoMsk) { |
sahilmgandhi | 18:6a4db94011d3 | 451 | u32div =(uint32_t)&CLK->CLKDIV0+((MODULE_CLKDIV(u32ModuleIdx))*4); |
sahilmgandhi | 18:6a4db94011d3 | 452 | u32tmp = *(volatile uint32_t *)(u32div); |
sahilmgandhi | 18:6a4db94011d3 | 453 | u32tmp = ( u32tmp & ~(MODULE_CLKDIV_Msk(u32ModuleIdx)<<MODULE_CLKDIV_Pos(u32ModuleIdx)) ) | u32ClkDiv; |
sahilmgandhi | 18:6a4db94011d3 | 454 | *(volatile uint32_t *)(u32div) = u32tmp; |
sahilmgandhi | 18:6a4db94011d3 | 455 | } |
sahilmgandhi | 18:6a4db94011d3 | 456 | |
sahilmgandhi | 18:6a4db94011d3 | 457 | if(MODULE_CLKSEL_Msk(u32ModuleIdx)!=MODULE_NoMsk) { |
sahilmgandhi | 18:6a4db94011d3 | 458 | u32sel = (uint32_t)&CLK->CLKSEL0+((MODULE_CLKSEL(u32ModuleIdx))*4); |
sahilmgandhi | 18:6a4db94011d3 | 459 | u32tmp = *(volatile uint32_t *)(u32sel); |
sahilmgandhi | 18:6a4db94011d3 | 460 | u32tmp = ( u32tmp & ~(MODULE_CLKSEL_Msk(u32ModuleIdx)<<MODULE_CLKSEL_Pos(u32ModuleIdx)) ) | u32ClkSrc; |
sahilmgandhi | 18:6a4db94011d3 | 461 | *(volatile uint32_t *)(u32sel) = u32tmp; |
sahilmgandhi | 18:6a4db94011d3 | 462 | } |
sahilmgandhi | 18:6a4db94011d3 | 463 | } |
sahilmgandhi | 18:6a4db94011d3 | 464 | |
sahilmgandhi | 18:6a4db94011d3 | 465 | /** |
sahilmgandhi | 18:6a4db94011d3 | 466 | * @brief This function enable clock source |
sahilmgandhi | 18:6a4db94011d3 | 467 | * @param u32ClkMask is clock source mask. Including: |
sahilmgandhi | 18:6a4db94011d3 | 468 | * - \ref CLK_PWRCTL_HXTEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 469 | * - \ref CLK_PWRCTL_LXTEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 470 | * - \ref CLK_PWRCTL_HIRCEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 471 | * - \ref CLK_PWRCTL_LIRCEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 472 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 473 | */ |
sahilmgandhi | 18:6a4db94011d3 | 474 | void CLK_EnableXtalRC(uint32_t u32ClkMask) |
sahilmgandhi | 18:6a4db94011d3 | 475 | { |
sahilmgandhi | 18:6a4db94011d3 | 476 | CLK->PWRCTL |= u32ClkMask; |
sahilmgandhi | 18:6a4db94011d3 | 477 | } |
sahilmgandhi | 18:6a4db94011d3 | 478 | |
sahilmgandhi | 18:6a4db94011d3 | 479 | /** |
sahilmgandhi | 18:6a4db94011d3 | 480 | * @brief This function disable clock source |
sahilmgandhi | 18:6a4db94011d3 | 481 | * @param u32ClkMask is clock source mask. Including: |
sahilmgandhi | 18:6a4db94011d3 | 482 | * - \ref CLK_PWRCTL_HXTEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 483 | * - \ref CLK_PWRCTL_LXTEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 484 | * - \ref CLK_PWRCTL_HIRCEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 485 | * - \ref CLK_PWRCTL_LIRCEN_Msk |
sahilmgandhi | 18:6a4db94011d3 | 486 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 487 | */ |
sahilmgandhi | 18:6a4db94011d3 | 488 | void CLK_DisableXtalRC(uint32_t u32ClkMask) |
sahilmgandhi | 18:6a4db94011d3 | 489 | { |
sahilmgandhi | 18:6a4db94011d3 | 490 | CLK->PWRCTL &= ~u32ClkMask; |
sahilmgandhi | 18:6a4db94011d3 | 491 | } |
sahilmgandhi | 18:6a4db94011d3 | 492 | |
sahilmgandhi | 18:6a4db94011d3 | 493 | /** |
sahilmgandhi | 18:6a4db94011d3 | 494 | * @brief This function enable module clock |
sahilmgandhi | 18:6a4db94011d3 | 495 | * @param[in] u32ModuleIdx is module index. Including : |
sahilmgandhi | 18:6a4db94011d3 | 496 | * - \ref PDMA_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 497 | * - \ref ISP_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 498 | * - \ref EBI_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 499 | * - \ref USBH_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 500 | * - \ref EMAC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 501 | * - \ref SDH_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 502 | * - \ref CRC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 503 | * - \ref CAP_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 504 | * - \ref USBD_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 505 | * - \ref CRPT_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 506 | * - \ref WDT_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 507 | * - \ref WWDT_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 508 | * - \ref RTC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 509 | * - \ref TMR0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 510 | * - \ref TMR1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 511 | * - \ref TMR2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 512 | * - \ref TMR3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 513 | * - \ref CLKO_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 514 | * - \ref ACMP_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 515 | * - \ref I2C0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 516 | * - \ref I2C1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 517 | * - \ref I2C2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 518 | * - \ref I2C3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 519 | * - \ref SPI0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 520 | * - \ref SPI1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 521 | * - \ref SPI2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 522 | * - \ref SPI3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 523 | * - \ref UART0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 524 | * - \ref UART1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 525 | * - \ref UART2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 526 | * - \ref UART3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 527 | * - \ref UART4_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 528 | * - \ref UART5_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 529 | * - \ref CAN0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 530 | * - \ref CAN1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 531 | * - \ref OTG_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 532 | * - \ref ADC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 533 | * - \ref I2S0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 534 | * - \ref I2S1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 535 | * - \ref PS2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 536 | * - \ref SC0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 537 | * - \ref SC1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 538 | * - \ref SC2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 539 | * - \ref SC3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 540 | * - \ref SC4_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 541 | * - \ref SC5_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 542 | * - \ref I2C4_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 543 | * - \ref PWM0CH01_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 544 | * - \ref PWM0CH23_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 545 | * - \ref PWM0CH45_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 546 | * - \ref PWM1CH01_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 547 | * - \ref PWM1CH23_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 548 | * - \ref PWM1CH45_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 549 | * - \ref QEI0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 550 | * - \ref QEI1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 551 | * - \ref ECAP0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 552 | * - \ref ECAP1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 553 | * - \ref EPWM0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 554 | * - \ref EPWM1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 555 | * - \ref OPA_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 556 | * - \ref EADC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 557 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 558 | */ |
sahilmgandhi | 18:6a4db94011d3 | 559 | void CLK_EnableModuleClock(uint32_t u32ModuleIdx) |
sahilmgandhi | 18:6a4db94011d3 | 560 | { |
sahilmgandhi | 18:6a4db94011d3 | 561 | *(volatile uint32_t *)((uint32_t)&CLK->AHBCLK+(MODULE_APBCLK(u32ModuleIdx)*4)) |= 1<<MODULE_IP_EN_Pos(u32ModuleIdx); |
sahilmgandhi | 18:6a4db94011d3 | 562 | } |
sahilmgandhi | 18:6a4db94011d3 | 563 | |
sahilmgandhi | 18:6a4db94011d3 | 564 | /** |
sahilmgandhi | 18:6a4db94011d3 | 565 | * @brief This function disable module clock |
sahilmgandhi | 18:6a4db94011d3 | 566 | * @param[in] u32ModuleIdx is module index. Including : |
sahilmgandhi | 18:6a4db94011d3 | 567 | * - \ref PDMA_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 568 | * - \ref ISP_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 569 | * - \ref EBI_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 570 | * - \ref USBH_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 571 | * - \ref EMAC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 572 | * - \ref SDH_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 573 | * - \ref CRC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 574 | * - \ref CAP_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 575 | * - \ref USBD_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 576 | * - \ref CRPT_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 577 | * - \ref WDT_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 578 | * - \ref WWDT_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 579 | * - \ref RTC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 580 | * - \ref TMR0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 581 | * - \ref TMR1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 582 | * - \ref TMR2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 583 | * - \ref TMR3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 584 | * - \ref CLKO_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 585 | * - \ref ACMP_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 586 | * - \ref I2C0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 587 | * - \ref I2C1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 588 | * - \ref I2C2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 589 | * - \ref I2C3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 590 | * - \ref SPI0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 591 | * - \ref SPI1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 592 | * - \ref SPI2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 593 | * - \ref SPI3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 594 | * - \ref UART0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 595 | * - \ref UART1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 596 | * - \ref UART2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 597 | * - \ref UART3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 598 | * - \ref UART4_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 599 | * - \ref UART5_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 600 | * - \ref CAN0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 601 | * - \ref CAN1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 602 | * - \ref OTG_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 603 | * - \ref ADC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 604 | * - \ref I2S0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 605 | * - \ref I2S1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 606 | * - \ref PS2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 607 | * - \ref SC0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 608 | * - \ref SC1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 609 | * - \ref SC2_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 610 | * - \ref SC3_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 611 | * - \ref SC4_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 612 | * - \ref SC5_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 613 | * - \ref I2C4_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 614 | * - \ref PWM0CH01_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 615 | * - \ref PWM0CH23_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 616 | * - \ref PWM0CH45_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 617 | * - \ref PWM1CH01_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 618 | * - \ref PWM1CH23_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 619 | * - \ref PWM1CH45_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 620 | * - \ref QEI0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 621 | * - \ref QEI1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 622 | * - \ref ECAP0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 623 | * - \ref ECAP1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 624 | * - \ref EPWM0_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 625 | * - \ref EPWM1_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 626 | * - \ref OPA_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 627 | * - \ref EADC_MODULE |
sahilmgandhi | 18:6a4db94011d3 | 628 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 629 | */ |
sahilmgandhi | 18:6a4db94011d3 | 630 | void CLK_DisableModuleClock(uint32_t u32ModuleIdx) |
sahilmgandhi | 18:6a4db94011d3 | 631 | { |
sahilmgandhi | 18:6a4db94011d3 | 632 | *(volatile uint32_t *)((uint32_t)&CLK->AHBCLK+(MODULE_APBCLK(u32ModuleIdx)*4)) &= ~(1<<MODULE_IP_EN_Pos(u32ModuleIdx)); |
sahilmgandhi | 18:6a4db94011d3 | 633 | } |
sahilmgandhi | 18:6a4db94011d3 | 634 | |
sahilmgandhi | 18:6a4db94011d3 | 635 | /** |
sahilmgandhi | 18:6a4db94011d3 | 636 | * @brief This function set PLL frequency |
sahilmgandhi | 18:6a4db94011d3 | 637 | * @param[in] u32PllClkSrc is PLL clock source. Including : |
sahilmgandhi | 18:6a4db94011d3 | 638 | * - \ref CLK_PLLCTL_PLLSRC_HIRC |
sahilmgandhi | 18:6a4db94011d3 | 639 | * - \ref CLK_PLLCTL_PLLSRC_HXT |
sahilmgandhi | 18:6a4db94011d3 | 640 | * @param[in] u32PllFreq is PLL frequency |
sahilmgandhi | 18:6a4db94011d3 | 641 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 642 | */ |
sahilmgandhi | 18:6a4db94011d3 | 643 | uint32_t CLK_EnablePLL(uint32_t u32PllClkSrc, uint32_t u32PllFreq) |
sahilmgandhi | 18:6a4db94011d3 | 644 | { |
sahilmgandhi | 18:6a4db94011d3 | 645 | uint32_t u32PllSrcClk, u32NR, u32NF, u32NO, u32CLK_SRC; |
sahilmgandhi | 18:6a4db94011d3 | 646 | uint32_t u32Tmp, u32Tmp2, u32Tmp3, u32Min, u32MinNF, u32MinNR; |
sahilmgandhi | 18:6a4db94011d3 | 647 | |
sahilmgandhi | 18:6a4db94011d3 | 648 | /* Disable PLL first to avoid unstable when setting PLL */ |
sahilmgandhi | 18:6a4db94011d3 | 649 | CLK_DisablePLL(); |
sahilmgandhi | 18:6a4db94011d3 | 650 | |
sahilmgandhi | 18:6a4db94011d3 | 651 | /* PLL source clock is from HXT */ |
sahilmgandhi | 18:6a4db94011d3 | 652 | if(u32PllClkSrc == CLK_PLLCTL_PLLSRC_HXT) { |
sahilmgandhi | 18:6a4db94011d3 | 653 | /* Enable HXT clock */ |
sahilmgandhi | 18:6a4db94011d3 | 654 | CLK->PWRCTL |= CLK_PWRCTL_HXTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 655 | |
sahilmgandhi | 18:6a4db94011d3 | 656 | /* Wait for HXT clock ready */ |
sahilmgandhi | 18:6a4db94011d3 | 657 | CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 658 | |
sahilmgandhi | 18:6a4db94011d3 | 659 | /* Select PLL source clock from HXT */ |
sahilmgandhi | 18:6a4db94011d3 | 660 | u32CLK_SRC = CLK_PLLCTL_PLLSRC_HXT; |
sahilmgandhi | 18:6a4db94011d3 | 661 | u32PllSrcClk = __HXT; |
sahilmgandhi | 18:6a4db94011d3 | 662 | |
sahilmgandhi | 18:6a4db94011d3 | 663 | /* u32NR start from 2 */ |
sahilmgandhi | 18:6a4db94011d3 | 664 | u32NR = 2; |
sahilmgandhi | 18:6a4db94011d3 | 665 | } |
sahilmgandhi | 18:6a4db94011d3 | 666 | |
sahilmgandhi | 18:6a4db94011d3 | 667 | /* PLL source clock is from HIRC */ |
sahilmgandhi | 18:6a4db94011d3 | 668 | else { |
sahilmgandhi | 18:6a4db94011d3 | 669 | /* Enable HIRC clock */ |
sahilmgandhi | 18:6a4db94011d3 | 670 | CLK->PWRCTL |= CLK_PWRCTL_HIRCEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 671 | |
sahilmgandhi | 18:6a4db94011d3 | 672 | /* Wait for HIRC clock ready */ |
sahilmgandhi | 18:6a4db94011d3 | 673 | CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 674 | |
sahilmgandhi | 18:6a4db94011d3 | 675 | /* Select PLL source clock from HIRC */ |
sahilmgandhi | 18:6a4db94011d3 | 676 | u32CLK_SRC = CLK_PLLCTL_PLLSRC_HIRC; |
sahilmgandhi | 18:6a4db94011d3 | 677 | u32PllSrcClk = __HIRC; |
sahilmgandhi | 18:6a4db94011d3 | 678 | |
sahilmgandhi | 18:6a4db94011d3 | 679 | /* u32NR start from 4 when FIN = 22.1184MHz to avoid calculation overflow */ |
sahilmgandhi | 18:6a4db94011d3 | 680 | u32NR = 4; |
sahilmgandhi | 18:6a4db94011d3 | 681 | } |
sahilmgandhi | 18:6a4db94011d3 | 682 | |
sahilmgandhi | 18:6a4db94011d3 | 683 | /* Select "NO" according to request frequency */ |
sahilmgandhi | 18:6a4db94011d3 | 684 | if((u32PllFreq <= FREQ_500MHZ) && (u32PllFreq > FREQ_250MHZ)) { |
sahilmgandhi | 18:6a4db94011d3 | 685 | u32NO = 0; |
sahilmgandhi | 18:6a4db94011d3 | 686 | } else if((u32PllFreq <= FREQ_250MHZ) && (u32PllFreq > FREQ_125MHZ)) { |
sahilmgandhi | 18:6a4db94011d3 | 687 | u32NO = 1; |
sahilmgandhi | 18:6a4db94011d3 | 688 | u32PllFreq = u32PllFreq << 1; |
sahilmgandhi | 18:6a4db94011d3 | 689 | } else if((u32PllFreq <= FREQ_125MHZ) && (u32PllFreq >= FREQ_50MHZ)) { |
sahilmgandhi | 18:6a4db94011d3 | 690 | u32NO = 3; |
sahilmgandhi | 18:6a4db94011d3 | 691 | u32PllFreq = u32PllFreq << 2; |
sahilmgandhi | 18:6a4db94011d3 | 692 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 693 | /* Wrong frequency request. Just return default setting. */ |
sahilmgandhi | 18:6a4db94011d3 | 694 | goto lexit; |
sahilmgandhi | 18:6a4db94011d3 | 695 | } |
sahilmgandhi | 18:6a4db94011d3 | 696 | |
sahilmgandhi | 18:6a4db94011d3 | 697 | /* Find best solution */ |
sahilmgandhi | 18:6a4db94011d3 | 698 | u32Min = (uint32_t) - 1; |
sahilmgandhi | 18:6a4db94011d3 | 699 | u32MinNR = 0; |
sahilmgandhi | 18:6a4db94011d3 | 700 | u32MinNF = 0; |
sahilmgandhi | 18:6a4db94011d3 | 701 | for(; u32NR <= 33; u32NR++) { |
sahilmgandhi | 18:6a4db94011d3 | 702 | u32Tmp = u32PllSrcClk / u32NR; |
sahilmgandhi | 18:6a4db94011d3 | 703 | if((u32Tmp > 1600000) && (u32Tmp < 16000000)) { |
sahilmgandhi | 18:6a4db94011d3 | 704 | for(u32NF = 2; u32NF <= 513; u32NF++) { |
sahilmgandhi | 18:6a4db94011d3 | 705 | u32Tmp2 = u32Tmp * u32NF; |
sahilmgandhi | 18:6a4db94011d3 | 706 | if((u32Tmp2 >= 200000000) && (u32Tmp2 <= 500000000)) { |
sahilmgandhi | 18:6a4db94011d3 | 707 | u32Tmp3 = (u32Tmp2 > u32PllFreq) ? u32Tmp2 - u32PllFreq : u32PllFreq - u32Tmp2; |
sahilmgandhi | 18:6a4db94011d3 | 708 | if(u32Tmp3 < u32Min) { |
sahilmgandhi | 18:6a4db94011d3 | 709 | u32Min = u32Tmp3; |
sahilmgandhi | 18:6a4db94011d3 | 710 | u32MinNR = u32NR; |
sahilmgandhi | 18:6a4db94011d3 | 711 | u32MinNF = u32NF; |
sahilmgandhi | 18:6a4db94011d3 | 712 | |
sahilmgandhi | 18:6a4db94011d3 | 713 | /* Break when get good results */ |
sahilmgandhi | 18:6a4db94011d3 | 714 | if(u32Min == 0) |
sahilmgandhi | 18:6a4db94011d3 | 715 | break; |
sahilmgandhi | 18:6a4db94011d3 | 716 | } |
sahilmgandhi | 18:6a4db94011d3 | 717 | } |
sahilmgandhi | 18:6a4db94011d3 | 718 | } |
sahilmgandhi | 18:6a4db94011d3 | 719 | } |
sahilmgandhi | 18:6a4db94011d3 | 720 | } |
sahilmgandhi | 18:6a4db94011d3 | 721 | |
sahilmgandhi | 18:6a4db94011d3 | 722 | /* Enable and apply new PLL setting. */ |
sahilmgandhi | 18:6a4db94011d3 | 723 | CLK->PLLCTL = u32CLK_SRC | (u32NO << 14) | ((u32MinNR - 2) << 9) | (u32MinNF - 2); |
sahilmgandhi | 18:6a4db94011d3 | 724 | |
sahilmgandhi | 18:6a4db94011d3 | 725 | /* Wait for PLL clock stable */ |
sahilmgandhi | 18:6a4db94011d3 | 726 | CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 727 | |
sahilmgandhi | 18:6a4db94011d3 | 728 | /* Return actual PLL output clock frequency */ |
sahilmgandhi | 18:6a4db94011d3 | 729 | return u32PllSrcClk / ((u32NO + 1) * u32MinNR) * u32MinNF; |
sahilmgandhi | 18:6a4db94011d3 | 730 | |
sahilmgandhi | 18:6a4db94011d3 | 731 | lexit: |
sahilmgandhi | 18:6a4db94011d3 | 732 | |
sahilmgandhi | 18:6a4db94011d3 | 733 | /* Apply default PLL setting and return */ |
sahilmgandhi | 18:6a4db94011d3 | 734 | if(u32PllClkSrc == CLK_PLLCTL_PLLSRC_HXT) |
sahilmgandhi | 18:6a4db94011d3 | 735 | CLK->PLLCTL = CLK_PLLCTL_84MHz_HXT; /* 84MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 736 | else |
sahilmgandhi | 18:6a4db94011d3 | 737 | CLK->PLLCTL = CLK_PLLCTL_50MHz_HIRC; /* 50MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 738 | |
sahilmgandhi | 18:6a4db94011d3 | 739 | /* Wait for PLL clock stable */ |
sahilmgandhi | 18:6a4db94011d3 | 740 | CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 741 | |
sahilmgandhi | 18:6a4db94011d3 | 742 | return CLK_GetPLLClockFreq(); |
sahilmgandhi | 18:6a4db94011d3 | 743 | } |
sahilmgandhi | 18:6a4db94011d3 | 744 | |
sahilmgandhi | 18:6a4db94011d3 | 745 | /** |
sahilmgandhi | 18:6a4db94011d3 | 746 | * @brief This function disable PLL |
sahilmgandhi | 18:6a4db94011d3 | 747 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 748 | */ |
sahilmgandhi | 18:6a4db94011d3 | 749 | void CLK_DisablePLL(void) |
sahilmgandhi | 18:6a4db94011d3 | 750 | { |
sahilmgandhi | 18:6a4db94011d3 | 751 | CLK->PLLCTL |= CLK_PLLCTL_PD_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 752 | } |
sahilmgandhi | 18:6a4db94011d3 | 753 | |
sahilmgandhi | 18:6a4db94011d3 | 754 | /** |
sahilmgandhi | 18:6a4db94011d3 | 755 | * @brief This function set SysTick clock source |
sahilmgandhi | 18:6a4db94011d3 | 756 | * @param[in] u32ClkSrc is SysTick clock source. Including : |
sahilmgandhi | 18:6a4db94011d3 | 757 | * - \ref CLK_CLKSEL0_STCLKSEL_HXT |
sahilmgandhi | 18:6a4db94011d3 | 758 | * - \ref CLK_CLKSEL0_STCLKSEL_LXT |
sahilmgandhi | 18:6a4db94011d3 | 759 | * - \ref CLK_CLKSEL0_STCLKSEL_HXT_DIV2 |
sahilmgandhi | 18:6a4db94011d3 | 760 | * - \ref CLK_CLKSEL0_STCLKSEL_HCLK_DIV2 |
sahilmgandhi | 18:6a4db94011d3 | 761 | * - \ref CLK_CLKSEL0_STCLKSEL_HIRC_DIV2 |
sahilmgandhi | 18:6a4db94011d3 | 762 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 763 | */ |
sahilmgandhi | 18:6a4db94011d3 | 764 | void CLK_SetSysTickClockSrc(uint32_t u32ClkSrc) |
sahilmgandhi | 18:6a4db94011d3 | 765 | { |
sahilmgandhi | 18:6a4db94011d3 | 766 | CLK->CLKSEL0 = (CLK->CLKSEL0 & ~CLK_CLKSEL0_STCLKSEL_Msk) | u32ClkSrc ; |
sahilmgandhi | 18:6a4db94011d3 | 767 | } |
sahilmgandhi | 18:6a4db94011d3 | 768 | /** |
sahilmgandhi | 18:6a4db94011d3 | 769 | * @brief This function execute delay function. |
sahilmgandhi | 18:6a4db94011d3 | 770 | * @param[in] us Delay time. The Max value is 2^24 / CPU Clock(MHz). Ex: |
sahilmgandhi | 18:6a4db94011d3 | 771 | * 50MHz => 335544us, 48MHz => 349525us, 28MHz => 699050us ... |
sahilmgandhi | 18:6a4db94011d3 | 772 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 773 | * @details Use the SysTick to generate the delay time and the UNIT is in us. |
sahilmgandhi | 18:6a4db94011d3 | 774 | * The SysTick clock source is from HCLK, i.e the same as system core clock. |
sahilmgandhi | 18:6a4db94011d3 | 775 | */ |
sahilmgandhi | 18:6a4db94011d3 | 776 | void CLK_SysTickDelay(uint32_t us) |
sahilmgandhi | 18:6a4db94011d3 | 777 | { |
sahilmgandhi | 18:6a4db94011d3 | 778 | SysTick->LOAD = us * CyclesPerUs; |
sahilmgandhi | 18:6a4db94011d3 | 779 | SysTick->VAL = (0x00); |
sahilmgandhi | 18:6a4db94011d3 | 780 | SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 781 | |
sahilmgandhi | 18:6a4db94011d3 | 782 | /* Waiting for down-count to zero */ |
sahilmgandhi | 18:6a4db94011d3 | 783 | while((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0); |
sahilmgandhi | 18:6a4db94011d3 | 784 | SysTick->CTRL = 0 ; |
sahilmgandhi | 18:6a4db94011d3 | 785 | } |
sahilmgandhi | 18:6a4db94011d3 | 786 | |
sahilmgandhi | 18:6a4db94011d3 | 787 | /** |
sahilmgandhi | 18:6a4db94011d3 | 788 | * @brief This function check selected clock source status |
sahilmgandhi | 18:6a4db94011d3 | 789 | * @param[in] u32ClkMask is selected clock source. Including |
sahilmgandhi | 18:6a4db94011d3 | 790 | * - \ref CLK_STATUS_CLKSFAIL_Msk |
sahilmgandhi | 18:6a4db94011d3 | 791 | * - \ref CLK_STATUS_HIRCSTB_Msk |
sahilmgandhi | 18:6a4db94011d3 | 792 | * - \ref CLK_STATUS_LIRCSTB_Msk |
sahilmgandhi | 18:6a4db94011d3 | 793 | * - \ref CLK_STATUS_PLLSTB_Msk |
sahilmgandhi | 18:6a4db94011d3 | 794 | * - \ref CLK_STATUS_LXTSTB_Msk |
sahilmgandhi | 18:6a4db94011d3 | 795 | * - \ref CLK_STATUS_HXTSTB_Msk |
sahilmgandhi | 18:6a4db94011d3 | 796 | * |
sahilmgandhi | 18:6a4db94011d3 | 797 | * @return 0 clock is not stable |
sahilmgandhi | 18:6a4db94011d3 | 798 | * 1 clock is stable |
sahilmgandhi | 18:6a4db94011d3 | 799 | * |
sahilmgandhi | 18:6a4db94011d3 | 800 | * @details To wait for clock ready by specified CLKSTATUS bit or timeout (~300ms) |
sahilmgandhi | 18:6a4db94011d3 | 801 | */ |
sahilmgandhi | 18:6a4db94011d3 | 802 | uint32_t CLK_WaitClockReady(uint32_t u32ClkMask) |
sahilmgandhi | 18:6a4db94011d3 | 803 | { |
sahilmgandhi | 18:6a4db94011d3 | 804 | int32_t i32TimeOutCnt = 2160000; |
sahilmgandhi | 18:6a4db94011d3 | 805 | |
sahilmgandhi | 18:6a4db94011d3 | 806 | while((CLK->STATUS & u32ClkMask) != u32ClkMask) { |
sahilmgandhi | 18:6a4db94011d3 | 807 | if(i32TimeOutCnt-- <= 0) |
sahilmgandhi | 18:6a4db94011d3 | 808 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 809 | } |
sahilmgandhi | 18:6a4db94011d3 | 810 | |
sahilmgandhi | 18:6a4db94011d3 | 811 | return 1; |
sahilmgandhi | 18:6a4db94011d3 | 812 | } |
sahilmgandhi | 18:6a4db94011d3 | 813 | |
sahilmgandhi | 18:6a4db94011d3 | 814 | /** |
sahilmgandhi | 18:6a4db94011d3 | 815 | * @brief Enable System Tick counter |
sahilmgandhi | 18:6a4db94011d3 | 816 | * @param[in] u32ClkSrc is System Tick clock source. Including: |
sahilmgandhi | 18:6a4db94011d3 | 817 | * - \ref CLK_CLKSEL0_STCLKSEL_HXT |
sahilmgandhi | 18:6a4db94011d3 | 818 | * - \ref CLK_CLKSEL0_STCLKSEL_LXT |
sahilmgandhi | 18:6a4db94011d3 | 819 | * - \ref CLK_CLKSEL0_STCLKSEL_HXT_DIV2 |
sahilmgandhi | 18:6a4db94011d3 | 820 | * - \ref CLK_CLKSEL0_STCLKSEL_HCLK_DIV2 |
sahilmgandhi | 18:6a4db94011d3 | 821 | * - \ref CLK_CLKSEL0_STCLKSEL_HIRC_DIV2 |
sahilmgandhi | 18:6a4db94011d3 | 822 | * - \ref CLK_CLKSEL0_STCLKSEL_HCLK |
sahilmgandhi | 18:6a4db94011d3 | 823 | * @param[in] u32Count is System Tick reload value. It could be 0~0xFFFFFF. |
sahilmgandhi | 18:6a4db94011d3 | 824 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 825 | * @details This function set System Tick clock source, reload value, enable System Tick counter and interrupt. \n |
sahilmgandhi | 18:6a4db94011d3 | 826 | * The register write-protection function should be disabled before using this function. |
sahilmgandhi | 18:6a4db94011d3 | 827 | */ |
sahilmgandhi | 18:6a4db94011d3 | 828 | void CLK_EnableSysTick(uint32_t u32ClkSrc, uint32_t u32Count) |
sahilmgandhi | 18:6a4db94011d3 | 829 | { |
sahilmgandhi | 18:6a4db94011d3 | 830 | /* Set System Tick counter disabled */ |
sahilmgandhi | 18:6a4db94011d3 | 831 | SysTick->CTRL = 0; |
sahilmgandhi | 18:6a4db94011d3 | 832 | |
sahilmgandhi | 18:6a4db94011d3 | 833 | /* Set System Tick clock source */ |
sahilmgandhi | 18:6a4db94011d3 | 834 | if( u32ClkSrc == CLK_CLKSEL0_STCLKSEL_HCLK ) |
sahilmgandhi | 18:6a4db94011d3 | 835 | SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 836 | else |
sahilmgandhi | 18:6a4db94011d3 | 837 | CLK->CLKSEL0 = (CLK->CLKSEL0 & ~CLK_CLKSEL0_STCLKSEL_Msk) | u32ClkSrc; |
sahilmgandhi | 18:6a4db94011d3 | 838 | |
sahilmgandhi | 18:6a4db94011d3 | 839 | /* Set System Tick reload value */ |
sahilmgandhi | 18:6a4db94011d3 | 840 | SysTick->LOAD = u32Count; |
sahilmgandhi | 18:6a4db94011d3 | 841 | |
sahilmgandhi | 18:6a4db94011d3 | 842 | /* Clear System Tick current value and counter flag */ |
sahilmgandhi | 18:6a4db94011d3 | 843 | SysTick->VAL = 0; |
sahilmgandhi | 18:6a4db94011d3 | 844 | |
sahilmgandhi | 18:6a4db94011d3 | 845 | /* Set System Tick interrupt enabled and counter enabled */ |
sahilmgandhi | 18:6a4db94011d3 | 846 | SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 847 | } |
sahilmgandhi | 18:6a4db94011d3 | 848 | |
sahilmgandhi | 18:6a4db94011d3 | 849 | /** |
sahilmgandhi | 18:6a4db94011d3 | 850 | * @brief Disable System Tick counter |
sahilmgandhi | 18:6a4db94011d3 | 851 | * @param None |
sahilmgandhi | 18:6a4db94011d3 | 852 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 853 | * @details This function disable System Tick counter. |
sahilmgandhi | 18:6a4db94011d3 | 854 | */ |
sahilmgandhi | 18:6a4db94011d3 | 855 | void CLK_DisableSysTick(void) |
sahilmgandhi | 18:6a4db94011d3 | 856 | { |
sahilmgandhi | 18:6a4db94011d3 | 857 | /* Set System Tick counter disabled */ |
sahilmgandhi | 18:6a4db94011d3 | 858 | SysTick->CTRL = 0; |
sahilmgandhi | 18:6a4db94011d3 | 859 | } |
sahilmgandhi | 18:6a4db94011d3 | 860 | |
sahilmgandhi | 18:6a4db94011d3 | 861 | /*@}*/ /* end of group NUC472_442_CLK_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 862 | |
sahilmgandhi | 18:6a4db94011d3 | 863 | /*@}*/ /* end of group NUC472_442_CLK_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 864 | |
sahilmgandhi | 18:6a4db94011d3 | 865 | /*@}*/ /* end of group NUC472_442_Device_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 866 | |
sahilmgandhi | 18:6a4db94011d3 | 867 | /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/ |
sahilmgandhi | 18:6a4db94011d3 | 868 |