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