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