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