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 Feb 02 07:30:07 2015 +0000
Revision:
459:397407b8d9f7
Parent:
308:29bf8b44dbf6
Child:
466:12a9a5f8fea0
Synchronized with git revision 9f80c904774a5f24198502d615ba9978c26616ab

Full URL: https://github.com/mbedmicro/mbed/commit/9f80c904774a5f24198502d615ba9978c26616ab/

Add a new target DELTA_DFCM_NNN40

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 85:e1a8e879a6a9 1 /* mbed Microcontroller Library
mbed_official 85:e1a8e879a6a9 2
mbed_official 459:397407b8d9f7 3 * Copyright (c) 2015 Nordic Semiconductor.
mbed_official 85:e1a8e879a6a9 4 *
mbed_official 85:e1a8e879a6a9 5 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 85:e1a8e879a6a9 6 * you may not use this file except in compliance with the License.
mbed_official 85:e1a8e879a6a9 7 * You may obtain a copy of the License at
mbed_official 85:e1a8e879a6a9 8 *
mbed_official 85:e1a8e879a6a9 9 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 85:e1a8e879a6a9 10 *
mbed_official 85:e1a8e879a6a9 11 * Unless required by applicable law or agreed to in writing, software
mbed_official 85:e1a8e879a6a9 12 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 85:e1a8e879a6a9 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 85:e1a8e879a6a9 14 * See the License for the specific language governing permissions and
mbed_official 85:e1a8e879a6a9 15 * limitations under the License.
mbed_official 85:e1a8e879a6a9 16 */
mbed_official 85:e1a8e879a6a9 17
mbed_official 85:e1a8e879a6a9 18
mbed_official 85:e1a8e879a6a9 19 #include <stdint.h>
mbed_official 85:e1a8e879a6a9 20 #include <stdbool.h>
mbed_official 85:e1a8e879a6a9 21 #include "nrf51822.h"
mbed_official 85:e1a8e879a6a9 22 #include "system_nrf51822.h"
mbed_official 85:e1a8e879a6a9 23
mbed_official 459:397407b8d9f7 24 #ifdef TARGET_DELTA_DFCM_NNN40
mbed_official 85:e1a8e879a6a9 25
mbed_official 459:397407b8d9f7 26 #define __SYSTEM_CLOCK (32000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 32MHz */
mbed_official 459:397407b8d9f7 27 #else
mbed_official 459:397407b8d9f7 28 #define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */
mbed_official 459:397407b8d9f7 29 #endif
mbed_official 85:e1a8e879a6a9 30
mbed_official 85:e1a8e879a6a9 31 static bool is_manual_peripheral_setup_needed(void);
mbed_official 85:e1a8e879a6a9 32 static bool is_disabled_in_debug_needed(void);
mbed_official 85:e1a8e879a6a9 33
mbed_official 85:e1a8e879a6a9 34
mbed_official 85:e1a8e879a6a9 35 #if defined ( __CC_ARM )
mbed_official 304:89b9c3a9a045 36 uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
mbed_official 85:e1a8e879a6a9 37 #elif defined ( __ICCARM__ )
mbed_official 85:e1a8e879a6a9 38 __root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
mbed_official 85:e1a8e879a6a9 39 #elif defined ( __GNUC__ )
mbed_official 85:e1a8e879a6a9 40 uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
mbed_official 85:e1a8e879a6a9 41 #endif
mbed_official 85:e1a8e879a6a9 42
mbed_official 85:e1a8e879a6a9 43 void SystemCoreClockUpdate(void)
mbed_official 85:e1a8e879a6a9 44 {
mbed_official 85:e1a8e879a6a9 45 SystemCoreClock = __SYSTEM_CLOCK;
mbed_official 85:e1a8e879a6a9 46 }
mbed_official 85:e1a8e879a6a9 47
mbed_official 85:e1a8e879a6a9 48 void SystemInit(void)
mbed_official 304:89b9c3a9a045 49 {
mbed_official 306:d33324c3b5a2 50 /* If desired, switch off the unused RAM to lower consumption by the use of RAMON register.
mbed_official 306:d33324c3b5a2 51 It can also be done in the application main() function. */
mbed_official 306:d33324c3b5a2 52
mbed_official 85:e1a8e879a6a9 53 // Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
mbed_official 85:e1a8e879a6a9 54 // to enable the use of peripherals" found at Product Anomaly document for your device found at
mbed_official 304:89b9c3a9a045 55 // https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
mbed_official 85:e1a8e879a6a9 56 // that do not need it is that the new peripherals in the second generation devices (LPCOMP for
mbed_official 85:e1a8e879a6a9 57 // example) will not be available.
mbed_official 306:d33324c3b5a2 58 if (is_manual_peripheral_setup_needed())
mbed_official 306:d33324c3b5a2 59 {
mbed_official 85:e1a8e879a6a9 60 *(uint32_t volatile *)0x40000504 = 0xC007FFDF;
mbed_official 85:e1a8e879a6a9 61 *(uint32_t volatile *)0x40006C18 = 0x00008000;
mbed_official 85:e1a8e879a6a9 62 }
mbed_official 304:89b9c3a9a045 63
mbed_official 85:e1a8e879a6a9 64 // Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
mbed_official 304:89b9c3a9a045 65 // register is incorrect" found at Product Anomaly document four your device found at
mbed_official 304:89b9c3a9a045 66 // https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed.
mbed_official 306:d33324c3b5a2 67 if (is_disabled_in_debug_needed())
mbed_official 306:d33324c3b5a2 68 {
mbed_official 85:e1a8e879a6a9 69 NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
mbed_official 85:e1a8e879a6a9 70 }
mbed_official 304:89b9c3a9a045 71
mbed_official 304:89b9c3a9a045 72 // Start the external 32khz crystal oscillator.
mbed_official 308:29bf8b44dbf6 73
mbed_official 459:397407b8d9f7 74 #ifdef TARGET_DELTA_DFCM_NNN40 || TARGET_HRM1017
mbed_official 308:29bf8b44dbf6 75 NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos);
mbed_official 308:29bf8b44dbf6 76 #else
mbed_official 304:89b9c3a9a045 77 NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
mbed_official 308:29bf8b44dbf6 78 #endif
mbed_official 304:89b9c3a9a045 79 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
mbed_official 304:89b9c3a9a045 80 NRF_CLOCK->TASKS_LFCLKSTART = 1;
mbed_official 85:e1a8e879a6a9 81
mbed_official 85:e1a8e879a6a9 82 // Wait for the external oscillator to start up.
mbed_official 304:89b9c3a9a045 83 while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {
mbed_official 85:e1a8e879a6a9 84 // Do nothing.
mbed_official 85:e1a8e879a6a9 85 }
mbed_official 85:e1a8e879a6a9 86 }
mbed_official 85:e1a8e879a6a9 87
mbed_official 304:89b9c3a9a045 88 static bool is_manual_peripheral_setup_needed(void)
mbed_official 85:e1a8e879a6a9 89 {
mbed_official 85:e1a8e879a6a9 90 if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
mbed_official 85:e1a8e879a6a9 91 {
mbed_official 85:e1a8e879a6a9 92 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x00) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 85:e1a8e879a6a9 93 {
mbed_official 85:e1a8e879a6a9 94 return true;
mbed_official 85:e1a8e879a6a9 95 }
mbed_official 85:e1a8e879a6a9 96 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x10) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 85:e1a8e879a6a9 97 {
mbed_official 85:e1a8e879a6a9 98 return true;
mbed_official 85:e1a8e879a6a9 99 }
mbed_official 85:e1a8e879a6a9 100 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 85:e1a8e879a6a9 101 {
mbed_official 85:e1a8e879a6a9 102 return true;
mbed_official 85:e1a8e879a6a9 103 }
mbed_official 85:e1a8e879a6a9 104 }
mbed_official 304:89b9c3a9a045 105
mbed_official 85:e1a8e879a6a9 106 return false;
mbed_official 85:e1a8e879a6a9 107 }
mbed_official 85:e1a8e879a6a9 108
mbed_official 304:89b9c3a9a045 109 static bool is_disabled_in_debug_needed(void)
mbed_official 85:e1a8e879a6a9 110 {
mbed_official 85:e1a8e879a6a9 111 if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
mbed_official 85:e1a8e879a6a9 112 {
mbed_official 85:e1a8e879a6a9 113 if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
mbed_official 85:e1a8e879a6a9 114 {
mbed_official 85:e1a8e879a6a9 115 return true;
mbed_official 85:e1a8e879a6a9 116 }
mbed_official 85:e1a8e879a6a9 117 }
mbed_official 304:89b9c3a9a045 118
mbed_official 85:e1a8e879a6a9 119 return false;
mbed_official 85:e1a8e879a6a9 120 }
mbed_official 85:e1a8e879a6a9 121