mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32620C/mxc/clkman.c@186:707f6e361f3e, 2018-06-22 (annotated)
- Committer:
- Anna Bridge
- Date:
- Fri Jun 22 16:45:37 2018 +0100
- Revision:
- 186:707f6e361f3e
mbed-dev library. Release version 162
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anna Bridge |
186:707f6e361f3e | 1 | /******************************************************************************* |
Anna Bridge |
186:707f6e361f3e | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
Anna Bridge |
186:707f6e361f3e | 3 | * |
Anna Bridge |
186:707f6e361f3e | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
Anna Bridge |
186:707f6e361f3e | 5 | * copy of this software and associated documentation files (the "Software"), |
Anna Bridge |
186:707f6e361f3e | 6 | * to deal in the Software without restriction, including without limitation |
Anna Bridge |
186:707f6e361f3e | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
Anna Bridge |
186:707f6e361f3e | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
Anna Bridge |
186:707f6e361f3e | 9 | * Software is furnished to do so, subject to the following conditions: |
Anna Bridge |
186:707f6e361f3e | 10 | * |
Anna Bridge |
186:707f6e361f3e | 11 | * The above copyright notice and this permission notice shall be included |
Anna Bridge |
186:707f6e361f3e | 12 | * in all copies or substantial portions of the Software. |
Anna Bridge |
186:707f6e361f3e | 13 | * |
Anna Bridge |
186:707f6e361f3e | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
Anna Bridge |
186:707f6e361f3e | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Anna Bridge |
186:707f6e361f3e | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
Anna Bridge |
186:707f6e361f3e | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
Anna Bridge |
186:707f6e361f3e | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
Anna Bridge |
186:707f6e361f3e | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
Anna Bridge |
186:707f6e361f3e | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
Anna Bridge |
186:707f6e361f3e | 21 | * |
Anna Bridge |
186:707f6e361f3e | 22 | * Except as contained in this notice, the name of Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
Anna Bridge |
186:707f6e361f3e | 24 | * Products, Inc. Branding Policy. |
Anna Bridge |
186:707f6e361f3e | 25 | * |
Anna Bridge |
186:707f6e361f3e | 26 | * The mere transfer of this software does not imply any licenses |
Anna Bridge |
186:707f6e361f3e | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
Anna Bridge |
186:707f6e361f3e | 28 | * trademarks, maskwork rights, or any other form of intellectual |
Anna Bridge |
186:707f6e361f3e | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
Anna Bridge |
186:707f6e361f3e | 30 | * ownership rights. |
Anna Bridge |
186:707f6e361f3e | 31 | * |
Anna Bridge |
186:707f6e361f3e | 32 | * $Date: 2016-02-23 15:00:38 -0600 (Tue, 23 Feb 2016) $ |
Anna Bridge |
186:707f6e361f3e | 33 | * $Revision: 21448 $ |
Anna Bridge |
186:707f6e361f3e | 34 | * |
Anna Bridge |
186:707f6e361f3e | 35 | ******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 36 | #include "mxc_config.h" |
Anna Bridge |
186:707f6e361f3e | 37 | #include "mxc_assert.h" |
Anna Bridge |
186:707f6e361f3e | 38 | #include "clkman.h" |
Anna Bridge |
186:707f6e361f3e | 39 | #include "pwrseq_regs.h" |
Anna Bridge |
186:707f6e361f3e | 40 | |
Anna Bridge |
186:707f6e361f3e | 41 | /******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 42 | void CLKMAN_SetSystemClock(clkman_system_source_select_t select, clkman_system_scale_t scale) |
Anna Bridge |
186:707f6e361f3e | 43 | { |
Anna Bridge |
186:707f6e361f3e | 44 | MXC_CLKMAN->clk_ctrl = ((MXC_CLKMAN->clk_ctrl & ~MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT) | |
Anna Bridge |
186:707f6e361f3e | 45 | (MXC_V_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_96MHZ_RO)); |
Anna Bridge |
186:707f6e361f3e | 46 | |
Anna Bridge |
186:707f6e361f3e | 47 | switch(select) { |
Anna Bridge |
186:707f6e361f3e | 48 | case CLKMAN_SYSTEM_SOURCE_96MHZ: |
Anna Bridge |
186:707f6e361f3e | 49 | default: |
Anna Bridge |
186:707f6e361f3e | 50 | // Enable and select the 96MHz oscillator |
Anna Bridge |
186:707f6e361f3e | 51 | MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_ROEN_RUN); |
Anna Bridge |
186:707f6e361f3e | 52 | MXC_PWRSEQ->reg0 &= ~(MXC_F_PWRSEQ_REG0_PWR_OSC_SELECT); |
Anna Bridge |
186:707f6e361f3e | 53 | |
Anna Bridge |
186:707f6e361f3e | 54 | // Disable the 4MHz oscillator |
Anna Bridge |
186:707f6e361f3e | 55 | MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN; |
Anna Bridge |
186:707f6e361f3e | 56 | |
Anna Bridge |
186:707f6e361f3e | 57 | // Divide the system clock by the scale |
Anna Bridge |
186:707f6e361f3e | 58 | MXC_PWRSEQ->reg3 = ((MXC_PWRSEQ->reg3 & ~MXC_F_PWRSEQ_REG3_PWR_RO_DIV) | |
Anna Bridge |
186:707f6e361f3e | 59 | (scale << MXC_F_PWRSEQ_REG3_PWR_RO_DIV_POS)); |
Anna Bridge |
186:707f6e361f3e | 60 | |
Anna Bridge |
186:707f6e361f3e | 61 | break; |
Anna Bridge |
186:707f6e361f3e | 62 | case CLKMAN_SYSTEM_SOURCE_4MHZ: |
Anna Bridge |
186:707f6e361f3e | 63 | // Enable and select the 4MHz oscillator |
Anna Bridge |
186:707f6e361f3e | 64 | MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_RCEN_RUN); |
Anna Bridge |
186:707f6e361f3e | 65 | MXC_PWRSEQ->reg0 |= (MXC_F_PWRSEQ_REG0_PWR_OSC_SELECT); |
Anna Bridge |
186:707f6e361f3e | 66 | |
Anna Bridge |
186:707f6e361f3e | 67 | // Disable the 96MHz oscillator |
Anna Bridge |
186:707f6e361f3e | 68 | MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_ROEN_RUN; |
Anna Bridge |
186:707f6e361f3e | 69 | |
Anna Bridge |
186:707f6e361f3e | 70 | // 4MHz System source can only be divided down by a maximum factor of 8 |
Anna Bridge |
186:707f6e361f3e | 71 | MXC_ASSERT(scale <= CLKMAN_SYSTEM_SCALE_DIV_8); |
Anna Bridge |
186:707f6e361f3e | 72 | |
Anna Bridge |
186:707f6e361f3e | 73 | // Divide the system clock by the scale |
Anna Bridge |
186:707f6e361f3e | 74 | MXC_PWRSEQ->reg3 = ((MXC_PWRSEQ->reg3 & ~MXC_F_PWRSEQ_REG3_PWR_RC_DIV) | |
Anna Bridge |
186:707f6e361f3e | 75 | (scale << MXC_F_PWRSEQ_REG3_PWR_RC_DIV_POS)); |
Anna Bridge |
186:707f6e361f3e | 76 | break; |
Anna Bridge |
186:707f6e361f3e | 77 | } |
Anna Bridge |
186:707f6e361f3e | 78 | |
Anna Bridge |
186:707f6e361f3e | 79 | SystemCoreClockUpdate(); |
Anna Bridge |
186:707f6e361f3e | 80 | } |
Anna Bridge |
186:707f6e361f3e | 81 | |
Anna Bridge |
186:707f6e361f3e | 82 | /******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 83 | void CLKMAN_CryptoClockEnable(int enable) |
Anna Bridge |
186:707f6e361f3e | 84 | { |
Anna Bridge |
186:707f6e361f3e | 85 | if (enable) { |
Anna Bridge |
186:707f6e361f3e | 86 | /* Enable oscillator */ |
Anna Bridge |
186:707f6e361f3e | 87 | MXC_CLKMAN->clk_config |= MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_ENABLE; |
Anna Bridge |
186:707f6e361f3e | 88 | /* Un-gate clock to TPU modules */ |
Anna Bridge |
186:707f6e361f3e | 89 | MXC_CLKMAN->clk_ctrl |= MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE; |
Anna Bridge |
186:707f6e361f3e | 90 | } else { |
Anna Bridge |
186:707f6e361f3e | 91 | /* Gate clock off */ |
Anna Bridge |
186:707f6e361f3e | 92 | MXC_CLKMAN->clk_ctrl &= ~MXC_F_CLKMAN_CLK_CTRL_CRYPTO_CLOCK_ENABLE; |
Anna Bridge |
186:707f6e361f3e | 93 | /* Disable oscillator */ |
Anna Bridge |
186:707f6e361f3e | 94 | MXC_CLKMAN->clk_config &= ~MXC_F_CLKMAN_CLK_CONFIG_CRYPTO_ENABLE; |
Anna Bridge |
186:707f6e361f3e | 95 | } |
Anna Bridge |
186:707f6e361f3e | 96 | } |
Anna Bridge |
186:707f6e361f3e | 97 | |
Anna Bridge |
186:707f6e361f3e | 98 | /******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 99 | void CLKMAN_SetClkScale(clkman_clk_t clk, clkman_scale_t scale) |
Anna Bridge |
186:707f6e361f3e | 100 | { |
Anna Bridge |
186:707f6e361f3e | 101 | volatile uint32_t *clk_ctrl_reg; |
Anna Bridge |
186:707f6e361f3e | 102 | |
Anna Bridge |
186:707f6e361f3e | 103 | MXC_ASSERT(clk <= CLKMAN_CLK_MAX); |
Anna Bridge |
186:707f6e361f3e | 104 | MXC_ASSERT(scale != CLKMAN_SCALE_AUTO); |
Anna Bridge |
186:707f6e361f3e | 105 | |
Anna Bridge |
186:707f6e361f3e | 106 | if (clk < CLKMAN_CRYPTO_CLK_AES) { |
Anna Bridge |
186:707f6e361f3e | 107 | clk_ctrl_reg = &MXC_CLKMAN->sys_clk_ctrl_0_cm4 + clk; |
Anna Bridge |
186:707f6e361f3e | 108 | } else { |
Anna Bridge |
186:707f6e361f3e | 109 | clk_ctrl_reg = &MXC_CLKMAN->crypt_clk_ctrl_0_aes + (clk - CLKMAN_CRYPTO_CLK_AES); |
Anna Bridge |
186:707f6e361f3e | 110 | } |
Anna Bridge |
186:707f6e361f3e | 111 | |
Anna Bridge |
186:707f6e361f3e | 112 | *clk_ctrl_reg = scale; |
Anna Bridge |
186:707f6e361f3e | 113 | } |
Anna Bridge |
186:707f6e361f3e | 114 | |
Anna Bridge |
186:707f6e361f3e | 115 | /******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 116 | clkman_scale_t CLKMAN_GetClkScale(clkman_clk_t clk) |
Anna Bridge |
186:707f6e361f3e | 117 | { |
Anna Bridge |
186:707f6e361f3e | 118 | volatile uint32_t *clk_ctrl_reg; |
Anna Bridge |
186:707f6e361f3e | 119 | MXC_ASSERT(clk <= CLKMAN_CLK_MAX); |
Anna Bridge |
186:707f6e361f3e | 120 | |
Anna Bridge |
186:707f6e361f3e | 121 | if (clk < CLKMAN_CRYPTO_CLK_AES) { |
Anna Bridge |
186:707f6e361f3e | 122 | clk_ctrl_reg = &MXC_CLKMAN->sys_clk_ctrl_0_cm4 + clk; |
Anna Bridge |
186:707f6e361f3e | 123 | } else { |
Anna Bridge |
186:707f6e361f3e | 124 | clk_ctrl_reg = &MXC_CLKMAN->crypt_clk_ctrl_0_aes + (clk - CLKMAN_CRYPTO_CLK_AES); |
Anna Bridge |
186:707f6e361f3e | 125 | } |
Anna Bridge |
186:707f6e361f3e | 126 | |
Anna Bridge |
186:707f6e361f3e | 127 | return (clkman_scale_t)*clk_ctrl_reg; |
Anna Bridge |
186:707f6e361f3e | 128 | } |
Anna Bridge |
186:707f6e361f3e | 129 | |
Anna Bridge |
186:707f6e361f3e | 130 | /******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 131 | void CLKMAN_ClockGate(clkman_enable_clk_t clk, int enable) |
Anna Bridge |
186:707f6e361f3e | 132 | { |
Anna Bridge |
186:707f6e361f3e | 133 | if (enable) { |
Anna Bridge |
186:707f6e361f3e | 134 | MXC_CLKMAN->clk_ctrl |= clk; |
Anna Bridge |
186:707f6e361f3e | 135 | } else { |
Anna Bridge |
186:707f6e361f3e | 136 | MXC_CLKMAN->clk_ctrl &= ~clk; |
Anna Bridge |
186:707f6e361f3e | 137 | } |
Anna Bridge |
186:707f6e361f3e | 138 | } |
Anna Bridge |
186:707f6e361f3e | 139 | |
Anna Bridge |
186:707f6e361f3e | 140 | /******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 141 | int CLKMAN_WdtClkSelect(unsigned int idx, clkman_wdt_clk_select_t select) |
Anna Bridge |
186:707f6e361f3e | 142 | { |
Anna Bridge |
186:707f6e361f3e | 143 | MXC_ASSERT(idx < MXC_CFG_WDT_INSTANCES); |
Anna Bridge |
186:707f6e361f3e | 144 | |
Anna Bridge |
186:707f6e361f3e | 145 | if (select == CLKMAN_WDT_SELECT_DISABLED) { |
Anna Bridge |
186:707f6e361f3e | 146 | if (idx == 0) { |
Anna Bridge |
186:707f6e361f3e | 147 | MXC_CLKMAN->clk_ctrl &= ~MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE; |
Anna Bridge |
186:707f6e361f3e | 148 | } else if (idx == 1) { |
Anna Bridge |
186:707f6e361f3e | 149 | MXC_CLKMAN->clk_ctrl &= ~MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE; |
Anna Bridge |
186:707f6e361f3e | 150 | } else { |
Anna Bridge |
186:707f6e361f3e | 151 | return E_BAD_PARAM; |
Anna Bridge |
186:707f6e361f3e | 152 | } |
Anna Bridge |
186:707f6e361f3e | 153 | } else { |
Anna Bridge |
186:707f6e361f3e | 154 | if (idx == 0) { |
Anna Bridge |
186:707f6e361f3e | 155 | MXC_CLKMAN->clk_ctrl = (MXC_CLKMAN->clk_ctrl & ~MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT) | |
Anna Bridge |
186:707f6e361f3e | 156 | MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_ENABLE | |
Anna Bridge |
186:707f6e361f3e | 157 | ((select << MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT_POS) & MXC_F_CLKMAN_CLK_CTRL_WDT0_CLOCK_SELECT); |
Anna Bridge |
186:707f6e361f3e | 158 | } else if (idx == 1) { |
Anna Bridge |
186:707f6e361f3e | 159 | MXC_CLKMAN->clk_ctrl = (MXC_CLKMAN->clk_ctrl & ~MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT) | |
Anna Bridge |
186:707f6e361f3e | 160 | MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_ENABLE | |
Anna Bridge |
186:707f6e361f3e | 161 | ((select << MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT_POS) & MXC_F_CLKMAN_CLK_CTRL_WDT1_CLOCK_SELECT); |
Anna Bridge |
186:707f6e361f3e | 162 | } else { |
Anna Bridge |
186:707f6e361f3e | 163 | return E_BAD_PARAM; |
Anna Bridge |
186:707f6e361f3e | 164 | } |
Anna Bridge |
186:707f6e361f3e | 165 | } |
Anna Bridge |
186:707f6e361f3e | 166 | |
Anna Bridge |
186:707f6e361f3e | 167 | return E_NO_ERROR; |
Anna Bridge |
186:707f6e361f3e | 168 | } |
Anna Bridge |
186:707f6e361f3e | 169 | |
Anna Bridge |
186:707f6e361f3e | 170 | /******************************************************************************/ |
Anna Bridge |
186:707f6e361f3e | 171 | /* NOTE: CLKMAN_TrimRO() is implemented in system_max32XXX.c */ |
Anna Bridge |
186:707f6e361f3e | 172 | /******************************************************************************/ |