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:
Wed Jul 29 09:45:09 2015 +0100
Revision:
598:2d5fc5624619
Parent:
501:36015dec7d16
Child:
603:3c75ef011213
Synchronized with git revision e87fec7b35d45d8663318a40a4a9fb58f91d0237

Full URL: https://github.com/mbedmicro/mbed/commit/e87fec7b35d45d8663318a40a4a9fb58f91d0237/

Microbit addition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 501:36015dec7d16 1 /* Copyright (c) 2013, Nordic Semiconductor ASA
mbed_official 501:36015dec7d16 2 * All rights reserved.
mbed_official 501:36015dec7d16 3 *
mbed_official 501:36015dec7d16 4 * Redistribution and use in source and binary forms, with or without
mbed_official 501:36015dec7d16 5 * modification, are permitted provided that the following conditions are met:
mbed_official 501:36015dec7d16 6 *
mbed_official 501:36015dec7d16 7 * * Redistributions of source code must retain the above copyright notice, this
mbed_official 501:36015dec7d16 8 * list of conditions and the following disclaimer.
mbed_official 501:36015dec7d16 9 *
mbed_official 501:36015dec7d16 10 * * Redistributions in binary form must reproduce the above copyright notice,
mbed_official 501:36015dec7d16 11 * this list of conditions and the following disclaimer in the documentation
mbed_official 501:36015dec7d16 12 * and/or other materials provided with the distribution.
mbed_official 501:36015dec7d16 13 *
mbed_official 501:36015dec7d16 14 * * Neither the name of Nordic Semiconductor ASA nor the names of its
mbed_official 501:36015dec7d16 15 * contributors may be used to endorse or promote products derived from
mbed_official 501:36015dec7d16 16 * this software without specific prior written permission.
mbed_official 501:36015dec7d16 17 *
mbed_official 501:36015dec7d16 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 501:36015dec7d16 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 501:36015dec7d16 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 501:36015dec7d16 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 501:36015dec7d16 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 501:36015dec7d16 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 501:36015dec7d16 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 501:36015dec7d16 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 501:36015dec7d16 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 501:36015dec7d16 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 501:36015dec7d16 28 *
mbed_official 501:36015dec7d16 29 */
mbed_official 501:36015dec7d16 30
mbed_official 501:36015dec7d16 31 /* NOTE: Template files (including this one) are application specific and therefore expected to
mbed_official 501:36015dec7d16 32 be copied into the application project folder prior to its use! */
mbed_official 501:36015dec7d16 33
mbed_official 501:36015dec7d16 34 #include <stdint.h>
mbed_official 501:36015dec7d16 35 #include <stdbool.h>
mbed_official 501:36015dec7d16 36 #include "nrf.h"
mbed_official 501:36015dec7d16 37 #include "system_nrf51.h"
mbed_official 501:36015dec7d16 38
mbed_official 501:36015dec7d16 39 /*lint ++flb "Enter library region" */
mbed_official 501:36015dec7d16 40
mbed_official 501:36015dec7d16 41 #define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */
mbed_official 501:36015dec7d16 42
mbed_official 501:36015dec7d16 43 static bool is_manual_peripheral_setup_needed(void);
mbed_official 501:36015dec7d16 44 static bool is_disabled_in_debug_needed(void);
mbed_official 501:36015dec7d16 45
mbed_official 501:36015dec7d16 46
mbed_official 501:36015dec7d16 47 #if defined ( __CC_ARM )
mbed_official 501:36015dec7d16 48 uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
mbed_official 501:36015dec7d16 49 #elif defined ( __ICCARM__ )
mbed_official 501:36015dec7d16 50 __root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
mbed_official 501:36015dec7d16 51 #elif defined ( __GNUC__ )
mbed_official 501:36015dec7d16 52 uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
mbed_official 501:36015dec7d16 53 #endif
mbed_official 501:36015dec7d16 54
mbed_official 501:36015dec7d16 55 void SystemCoreClockUpdate(void)
mbed_official 501:36015dec7d16 56 {
mbed_official 501:36015dec7d16 57 SystemCoreClock = __SYSTEM_CLOCK;
mbed_official 501:36015dec7d16 58 }
mbed_official 501:36015dec7d16 59
mbed_official 501:36015dec7d16 60 void SystemInit(void)
mbed_official 501:36015dec7d16 61 {
mbed_official 501:36015dec7d16 62 /* If desired, switch off the unused RAM to lower consumption by the use of RAMON register.
mbed_official 501:36015dec7d16 63 It can also be done in the application main() function. */
mbed_official 501:36015dec7d16 64
mbed_official 501:36015dec7d16 65 /* Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
mbed_official 501:36015dec7d16 66 to enable the use of peripherals" found at Product Anomaly document for your device found at
mbed_official 501:36015dec7d16 67 https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
mbed_official 501:36015dec7d16 68 that do not need it is that the new peripherals in the second generation devices (LPCOMP for
mbed_official 501:36015dec7d16 69 example) will not be available. */
mbed_official 501:36015dec7d16 70 if (is_manual_peripheral_setup_needed())
mbed_official 501:36015dec7d16 71 {
mbed_official 501:36015dec7d16 72 *(uint32_t volatile *)0x40000504 = 0xC007FFDF;
mbed_official 501:36015dec7d16 73 *(uint32_t volatile *)0x40006C18 = 0x00008000;
mbed_official 501:36015dec7d16 74 }
mbed_official 501:36015dec7d16 75
mbed_official 501:36015dec7d16 76 /* Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
mbed_official 501:36015dec7d16 77 register is incorrect" found at Product Anomaly document four your device found at
mbed_official 501:36015dec7d16 78 https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed. */
mbed_official 501:36015dec7d16 79 if (is_disabled_in_debug_needed())
mbed_official 501:36015dec7d16 80 {
mbed_official 501:36015dec7d16 81 NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
mbed_official 501:36015dec7d16 82 }
mbed_official 501:36015dec7d16 83
mbed_official 501:36015dec7d16 84 // Start the external 32khz crystal oscillator.
mbed_official 501:36015dec7d16 85
mbed_official 598:2d5fc5624619 86 /* for Nordic devices without an external LF crystal */
mbed_official 598:2d5fc5624619 87 #if defined(TARGET_NRF_LFCLK_RC)
mbed_official 501:36015dec7d16 88 NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
mbed_official 501:36015dec7d16 89 #else
mbed_official 501:36015dec7d16 90 NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
mbed_official 501:36015dec7d16 91 #endif
mbed_official 501:36015dec7d16 92 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
mbed_official 501:36015dec7d16 93 NRF_CLOCK->TASKS_LFCLKSTART = 1;
mbed_official 501:36015dec7d16 94
mbed_official 501:36015dec7d16 95 // Wait for the external oscillator to start up.
mbed_official 501:36015dec7d16 96 while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
mbed_official 501:36015dec7d16 97 // Do nothing.
mbed_official 501:36015dec7d16 98 }
mbed_official 501:36015dec7d16 99 }
mbed_official 501:36015dec7d16 100
mbed_official 501:36015dec7d16 101 static bool is_manual_peripheral_setup_needed(void)
mbed_official 501:36015dec7d16 102 {
mbed_official 501:36015dec7d16 103 if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
mbed_official 501:36015dec7d16 104 {
mbed_official 501:36015dec7d16 105 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x00) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 501:36015dec7d16 106 {
mbed_official 501:36015dec7d16 107 return true;
mbed_official 501:36015dec7d16 108 }
mbed_official 501:36015dec7d16 109 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x10) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 501:36015dec7d16 110 {
mbed_official 501:36015dec7d16 111 return true;
mbed_official 501:36015dec7d16 112 }
mbed_official 501:36015dec7d16 113 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 501:36015dec7d16 114 {
mbed_official 501:36015dec7d16 115 return true;
mbed_official 501:36015dec7d16 116 }
mbed_official 501:36015dec7d16 117 }
mbed_official 501:36015dec7d16 118
mbed_official 501:36015dec7d16 119 return false;
mbed_official 501:36015dec7d16 120 }
mbed_official 501:36015dec7d16 121
mbed_official 501:36015dec7d16 122 static bool is_disabled_in_debug_needed(void)
mbed_official 501:36015dec7d16 123 {
mbed_official 501:36015dec7d16 124 if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
mbed_official 501:36015dec7d16 125 {
mbed_official 501:36015dec7d16 126 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 501:36015dec7d16 127 {
mbed_official 501:36015dec7d16 128 return true;
mbed_official 501:36015dec7d16 129 }
mbed_official 501:36015dec7d16 130 }
mbed_official 501:36015dec7d16 131
mbed_official 501:36015dec7d16 132 return false;
mbed_official 501:36015dec7d16 133 }
mbed_official 501:36015dec7d16 134
mbed_official 501:36015dec7d16 135 /*lint --flb "Leave library region" */