mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon May 11 08:15:07 2015 +0100
Revision:
538:3c6246291cdb
Parent:
515:7467ef1f4ad8
Child:
572:c6226b743616
Synchronized with git revision 77b4a7bc786dd2baf633cc7140deb6b0d6ec4463

Full URL: https://github.com/mbedmicro/mbed/commit/77b4a7bc786dd2baf633cc7140deb6b0d6ec4463/

MAX32600MBED,MAXWSNENV - addressed low-power ticker corner cases

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 507:d4fc7603a669 1 /*******************************************************************************
mbed_official 507:d4fc7603a669 2 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
mbed_official 507:d4fc7603a669 3 *
mbed_official 507:d4fc7603a669 4 * Permission is hereby granted, free of charge, to any person obtaining a
mbed_official 507:d4fc7603a669 5 * copy of this software and associated documentation files (the "Software"),
mbed_official 507:d4fc7603a669 6 * to deal in the Software without restriction, including without limitation
mbed_official 507:d4fc7603a669 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
mbed_official 507:d4fc7603a669 8 * and/or sell copies of the Software, and to permit persons to whom the
mbed_official 507:d4fc7603a669 9 * Software is furnished to do so, subject to the following conditions:
mbed_official 507:d4fc7603a669 10 *
mbed_official 507:d4fc7603a669 11 * The above copyright notice and this permission notice shall be included
mbed_official 507:d4fc7603a669 12 * in all copies or substantial portions of the Software.
mbed_official 507:d4fc7603a669 13 *
mbed_official 507:d4fc7603a669 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
mbed_official 507:d4fc7603a669 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
mbed_official 507:d4fc7603a669 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
mbed_official 507:d4fc7603a669 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
mbed_official 507:d4fc7603a669 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
mbed_official 507:d4fc7603a669 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
mbed_official 507:d4fc7603a669 20 * OTHER DEALINGS IN THE SOFTWARE.
mbed_official 507:d4fc7603a669 21 *
mbed_official 507:d4fc7603a669 22 * Except as contained in this notice, the name of Maxim Integrated
mbed_official 507:d4fc7603a669 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
mbed_official 507:d4fc7603a669 24 * Products, Inc. Branding Policy.
mbed_official 507:d4fc7603a669 25 *
mbed_official 507:d4fc7603a669 26 * The mere transfer of this software does not imply any licenses
mbed_official 507:d4fc7603a669 27 * of trade secrets, proprietary technology, copyrights, patents,
mbed_official 507:d4fc7603a669 28 * trademarks, maskwork rights, or any other form of intellectual
mbed_official 507:d4fc7603a669 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
mbed_official 507:d4fc7603a669 30 * ownership rights.
mbed_official 507:d4fc7603a669 31 *******************************************************************************
mbed_official 507:d4fc7603a669 32 */
mbed_official 507:d4fc7603a669 33
mbed_official 507:d4fc7603a669 34 #include "max32610.h"
mbed_official 507:d4fc7603a669 35 #include "clkman_regs.h"
mbed_official 507:d4fc7603a669 36 #include "pwrman_regs.h"
mbed_official 507:d4fc7603a669 37 #include "ioman_regs.h"
mbed_official 507:d4fc7603a669 38 #include "trim_regs.h"
mbed_official 507:d4fc7603a669 39 #include "flc_regs.h"
mbed_official 507:d4fc7603a669 40 #include "pwrseq_regs.h"
mbed_official 507:d4fc7603a669 41 #include "dac_regs.h"
mbed_official 507:d4fc7603a669 42 #include "icc_regs.h"
mbed_official 507:d4fc7603a669 43
mbed_official 507:d4fc7603a669 44 /* Application developer should override where necessary with different external HFX source */
mbed_official 507:d4fc7603a669 45 #ifndef __SYSTEM_HFX
mbed_official 507:d4fc7603a669 46 #define __SYSTEM_HFX 24000000
mbed_official 507:d4fc7603a669 47 #endif
mbed_official 507:d4fc7603a669 48
mbed_official 507:d4fc7603a669 49 uint32_t SystemCoreClock = 24000000;
mbed_official 507:d4fc7603a669 50
mbed_official 507:d4fc7603a669 51 void SystemCoreClockUpdate(void)
mbed_official 507:d4fc7603a669 52 {
mbed_official 507:d4fc7603a669 53 switch ((MXC_CLKMAN->clk_ctrl & MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT) >> MXC_F_CLKMAN_CLK_CTRL_SYSTEM_SOURCE_SELECT_POS) {
mbed_official 507:d4fc7603a669 54 case MXC_E_CLKMAN_SYSTEM_SOURCE_SELECT_24MHZ_RO_DIV_8:
mbed_official 507:d4fc7603a669 55 SystemCoreClock = 3000000;
mbed_official 507:d4fc7603a669 56 break;
mbed_official 507:d4fc7603a669 57 case MXC_E_CLKMAN_SYSTEM_SOURCE_SELECT_24MHZ_RO:
mbed_official 507:d4fc7603a669 58 case MXC_E_CLKMAN_SYSTEM_SOURCE_SELECT_PLL_48MHZ_DIV_2:
mbed_official 507:d4fc7603a669 59 SystemCoreClock = 24000000;
mbed_official 507:d4fc7603a669 60 break;
mbed_official 507:d4fc7603a669 61 case MXC_E_CLKMAN_SYSTEM_SOURCE_SELECT_HFX:
mbed_official 507:d4fc7603a669 62 SystemCoreClock = __SYSTEM_HFX;
mbed_official 507:d4fc7603a669 63 break;
mbed_official 507:d4fc7603a669 64 }
mbed_official 507:d4fc7603a669 65
mbed_official 507:d4fc7603a669 66 uint32_t shift = MXC_CLKMAN->clk_ctrl_0_system;
mbed_official 507:d4fc7603a669 67 if (shift) {
mbed_official 507:d4fc7603a669 68 SystemCoreClock = SystemCoreClock >> (shift - 1);
mbed_official 507:d4fc7603a669 69 }
mbed_official 507:d4fc7603a669 70 }
mbed_official 507:d4fc7603a669 71
mbed_official 507:d4fc7603a669 72 /* power seq registers */
mbed_official 507:d4fc7603a669 73 static void set_pwr_regs(void)
mbed_official 507:d4fc7603a669 74 {
mbed_official 507:d4fc7603a669 75 uint32_t dac2trim = MXC_DAC2->reg & 0xff00ffff;
mbed_official 507:d4fc7603a669 76 uint32_t dac3trim = MXC_DAC3->reg & 0xff00ffff;
mbed_official 507:d4fc7603a669 77 dac2trim = dac2trim + MXC_TRIM->trim_reg_36;
mbed_official 507:d4fc7603a669 78 dac3trim = dac3trim + MXC_TRIM->trim_reg_37;
mbed_official 507:d4fc7603a669 79 MXC_PWRSEQ->reg5 = MXC_TRIM->trim_reg_13;
mbed_official 507:d4fc7603a669 80 MXC_PWRSEQ->reg6 = MXC_TRIM->trim_reg_14;
mbed_official 507:d4fc7603a669 81 MXC_DAC0->trm = MXC_TRIM->trim_reg_34;
mbed_official 507:d4fc7603a669 82 MXC_DAC1->trm = MXC_TRIM->trim_reg_35;
mbed_official 507:d4fc7603a669 83 MXC_DAC2->reg = dac2trim;
mbed_official 507:d4fc7603a669 84 MXC_DAC3->reg = dac3trim;
mbed_official 507:d4fc7603a669 85 }
mbed_official 507:d4fc7603a669 86
mbed_official 507:d4fc7603a669 87 void ICC_Enable(void)
mbed_official 507:d4fc7603a669 88 {
mbed_official 507:d4fc7603a669 89 /* clock gater must be 'on' not 'dynamic' for cache control */
mbed_official 507:d4fc7603a669 90 uint32_t temp = MXC_CLKMAN->clk_gate_ctrl0;
mbed_official 507:d4fc7603a669 91 temp &= ~MXC_F_CLKMAN_CLK_GATE_CTRL0_ICACHE_CLK_GATER;
mbed_official 507:d4fc7603a669 92 temp |= (MXC_E_CLKMAN_CLK_GATE_ON << MXC_F_CLKMAN_CLK_GATE_CTRL0_ICACHE_CLK_GATER_POS);
mbed_official 507:d4fc7603a669 93 MXC_CLKMAN->clk_gate_ctrl0 = temp;
mbed_official 507:d4fc7603a669 94
mbed_official 507:d4fc7603a669 95
mbed_official 507:d4fc7603a669 96 /* invalidate, wait, enable */
mbed_official 507:d4fc7603a669 97 MXC_ICC->invdt_all = 0xFFFF;
mbed_official 507:d4fc7603a669 98 while(!(MXC_ICC->ctrl_stat & MXC_F_ICC_CTRL_STAT_READY));
mbed_official 507:d4fc7603a669 99 MXC_ICC->ctrl_stat |= MXC_F_ICC_CTRL_STAT_ENABLE;
mbed_official 507:d4fc7603a669 100
mbed_official 507:d4fc7603a669 101 /* must invalidate a second time for proper use */
mbed_official 507:d4fc7603a669 102 MXC_ICC->invdt_all = 1;
mbed_official 507:d4fc7603a669 103
mbed_official 507:d4fc7603a669 104 /* clock gater 'dynamic' safe again */
mbed_official 507:d4fc7603a669 105 temp = MXC_CLKMAN->clk_gate_ctrl0;
mbed_official 507:d4fc7603a669 106 temp &= ~MXC_F_CLKMAN_CLK_GATE_CTRL0_ICACHE_CLK_GATER;
mbed_official 507:d4fc7603a669 107 temp |= (MXC_E_CLKMAN_CLK_GATE_DYNAMIC << MXC_F_CLKMAN_CLK_GATE_CTRL0_ICACHE_CLK_GATER_POS);
mbed_official 507:d4fc7603a669 108 MXC_CLKMAN->clk_gate_ctrl0 = temp;
mbed_official 507:d4fc7603a669 109 }
mbed_official 507:d4fc7603a669 110
mbed_official 507:d4fc7603a669 111 // This function to be implemented by the hal
mbed_official 515:7467ef1f4ad8 112 extern void low_level_init(void);
mbed_official 507:d4fc7603a669 113
mbed_official 507:d4fc7603a669 114 void SystemInit(void)
mbed_official 507:d4fc7603a669 115 {
mbed_official 507:d4fc7603a669 116 set_pwr_regs();
mbed_official 507:d4fc7603a669 117
mbed_official 507:d4fc7603a669 118 // Turn off PADX
mbed_official 507:d4fc7603a669 119 MXC_IOMAN->padx_control = 0x00000441;
mbed_official 507:d4fc7603a669 120
mbed_official 538:3c6246291cdb 121 // Enable instruction cache
mbed_official 507:d4fc7603a669 122 ICC_Enable();
mbed_official 507:d4fc7603a669 123
mbed_official 507:d4fc7603a669 124 low_level_init();
mbed_official 507:d4fc7603a669 125
mbed_official 507:d4fc7603a669 126 // Clear IO Active
mbed_official 507:d4fc7603a669 127 MXC_PWRMAN->pwr_rst_ctrl = (MXC_F_PWRMAN_PWR_RST_CTRL_FLASH_ACTIVE |
mbed_official 507:d4fc7603a669 128 MXC_F_PWRMAN_PWR_RST_CTRL_SRAM_ACTIVE);
mbed_official 507:d4fc7603a669 129
mbed_official 507:d4fc7603a669 130 // Set WUD Clear
mbed_official 507:d4fc7603a669 131 MXC_PWRMAN->pwr_rst_ctrl = (MXC_F_PWRMAN_PWR_RST_CTRL_FLASH_ACTIVE |
mbed_official 507:d4fc7603a669 132 MXC_F_PWRMAN_PWR_RST_CTRL_SRAM_ACTIVE |
mbed_official 507:d4fc7603a669 133 MXC_F_PWRMAN_PWR_RST_CTRL_WUD_CLEAR);
mbed_official 507:d4fc7603a669 134
mbed_official 507:d4fc7603a669 135 // Set IO Active
mbed_official 507:d4fc7603a669 136 MXC_PWRMAN->pwr_rst_ctrl = (MXC_F_PWRMAN_PWR_RST_CTRL_FLASH_ACTIVE |
mbed_official 507:d4fc7603a669 137 MXC_F_PWRMAN_PWR_RST_CTRL_SRAM_ACTIVE |
mbed_official 507:d4fc7603a669 138 MXC_F_PWRMAN_PWR_RST_CTRL_IO_ACTIVE |
mbed_official 507:d4fc7603a669 139 MXC_F_PWRMAN_PWR_RST_CTRL_PULLUPS_ENABLED);
mbed_official 507:d4fc7603a669 140
mbed_official 538:3c6246291cdb 141 // Clear the first boot flag. Use low_level_init() if special handling is required.
mbed_official 538:3c6246291cdb 142 MXC_PWRSEQ->reg0 &= ~MXC_F_PWRSEQ_REG0_PWR_FIRST_BOOT;
mbed_official 538:3c6246291cdb 143
mbed_official 538:3c6246291cdb 144 // Enable the regulator
mbed_official 507:d4fc7603a669 145 MXC_PWRSEQ->reg0 |= MXC_F_PWRSEQ_REG0_PWR_CHZYEN_RUN;
mbed_official 507:d4fc7603a669 146
mbed_official 538:3c6246291cdb 147 // Mask all wakeups
mbed_official 538:3c6246291cdb 148 MXC_PWRSEQ->msk_flags = 0xFFFFFFFF;
mbed_official 538:3c6246291cdb 149
mbed_official 538:3c6246291cdb 150 // Set systick to the RTC input 32.768kHz clock, not system clock; this is needed to keep JTAG alive during sleep
mbed_official 507:d4fc7603a669 151 MXC_CLKMAN->clk_ctrl |= MXC_F_CLKMAN_CLK_CTRL_RTOS_MODE;
mbed_official 507:d4fc7603a669 152
mbed_official 507:d4fc7603a669 153 SystemCoreClockUpdate();
mbed_official 507:d4fc7603a669 154 }