mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Tue Nov 08 17:45:16 2016 +0000
Revision:
151:02e0a0aed4ec
This updates the lib to the mbed lib v129

Who changed what in which revision?

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