Mouse code for the MacroRat
mbed-dev/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/device/system_nrf52.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2015 Nordic Semiconductor ASA |
sahilmgandhi | 18:6a4db94011d3 | 3 | * All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 4 | * |
sahilmgandhi | 18:6a4db94011d3 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
sahilmgandhi | 18:6a4db94011d3 | 6 | * are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
sahilmgandhi | 18:6a4db94011d3 | 9 | * of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 10 | * |
sahilmgandhi | 18:6a4db94011d3 | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
sahilmgandhi | 18:6a4db94011d3 | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
sahilmgandhi | 18:6a4db94011d3 | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
sahilmgandhi | 18:6a4db94011d3 | 14 | * the documentation and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 15 | * |
sahilmgandhi | 18:6a4db94011d3 | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
sahilmgandhi | 18:6a4db94011d3 | 17 | * used to endorse or promote products derived from this software without specific prior |
sahilmgandhi | 18:6a4db94011d3 | 18 | * written permission. |
sahilmgandhi | 18:6a4db94011d3 | 19 | * |
sahilmgandhi | 18:6a4db94011d3 | 20 | * 4. This software, with or without modification, must only be used with a |
sahilmgandhi | 18:6a4db94011d3 | 21 | * Nordic Semiconductor ASA integrated circuit. |
sahilmgandhi | 18:6a4db94011d3 | 22 | * |
sahilmgandhi | 18:6a4db94011d3 | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
sahilmgandhi | 18:6a4db94011d3 | 24 | * engineered, decompiled, modified and/or disassembled. |
sahilmgandhi | 18:6a4db94011d3 | 25 | * |
sahilmgandhi | 18:6a4db94011d3 | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
sahilmgandhi | 18:6a4db94011d3 | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
sahilmgandhi | 18:6a4db94011d3 | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
sahilmgandhi | 18:6a4db94011d3 | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
sahilmgandhi | 18:6a4db94011d3 | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
sahilmgandhi | 18:6a4db94011d3 | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
sahilmgandhi | 18:6a4db94011d3 | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
sahilmgandhi | 18:6a4db94011d3 | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
sahilmgandhi | 18:6a4db94011d3 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
sahilmgandhi | 18:6a4db94011d3 | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 36 | * |
sahilmgandhi | 18:6a4db94011d3 | 37 | */ |
sahilmgandhi | 18:6a4db94011d3 | 38 | |
sahilmgandhi | 18:6a4db94011d3 | 39 | |
sahilmgandhi | 18:6a4db94011d3 | 40 | #include <stdint.h> |
sahilmgandhi | 18:6a4db94011d3 | 41 | #include <stdbool.h> |
sahilmgandhi | 18:6a4db94011d3 | 42 | #include "nrf.h" |
sahilmgandhi | 18:6a4db94011d3 | 43 | #include "system_nrf52.h" |
sahilmgandhi | 18:6a4db94011d3 | 44 | #include "nrf5x_lf_clk_helper.h" |
sahilmgandhi | 18:6a4db94011d3 | 45 | |
sahilmgandhi | 18:6a4db94011d3 | 46 | /*lint ++flb "Enter library region" */ |
sahilmgandhi | 18:6a4db94011d3 | 47 | |
sahilmgandhi | 18:6a4db94011d3 | 48 | #define __SYSTEM_CLOCK_64M (64000000UL) |
sahilmgandhi | 18:6a4db94011d3 | 49 | |
sahilmgandhi | 18:6a4db94011d3 | 50 | static bool errata_16(void); |
sahilmgandhi | 18:6a4db94011d3 | 51 | static bool errata_31(void); |
sahilmgandhi | 18:6a4db94011d3 | 52 | static bool errata_32(void); |
sahilmgandhi | 18:6a4db94011d3 | 53 | static bool errata_36(void); |
sahilmgandhi | 18:6a4db94011d3 | 54 | static bool errata_37(void); |
sahilmgandhi | 18:6a4db94011d3 | 55 | static bool errata_57(void); |
sahilmgandhi | 18:6a4db94011d3 | 56 | static bool errata_66(void); |
sahilmgandhi | 18:6a4db94011d3 | 57 | |
sahilmgandhi | 18:6a4db94011d3 | 58 | |
sahilmgandhi | 18:6a4db94011d3 | 59 | #if defined ( __CC_ARM ) |
sahilmgandhi | 18:6a4db94011d3 | 60 | uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M; |
sahilmgandhi | 18:6a4db94011d3 | 61 | #elif defined ( __ICCARM__ ) |
sahilmgandhi | 18:6a4db94011d3 | 62 | __root uint32_t SystemCoreClock = __SYSTEM_CLOCK_64M; |
sahilmgandhi | 18:6a4db94011d3 | 63 | #elif defined ( __GNUC__ ) |
sahilmgandhi | 18:6a4db94011d3 | 64 | uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK_64M; |
sahilmgandhi | 18:6a4db94011d3 | 65 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 66 | |
sahilmgandhi | 18:6a4db94011d3 | 67 | void SystemCoreClockUpdate(void) |
sahilmgandhi | 18:6a4db94011d3 | 68 | { |
sahilmgandhi | 18:6a4db94011d3 | 69 | SystemCoreClock = __SYSTEM_CLOCK_64M; |
sahilmgandhi | 18:6a4db94011d3 | 70 | } |
sahilmgandhi | 18:6a4db94011d3 | 71 | |
sahilmgandhi | 18:6a4db94011d3 | 72 | void SystemInit(void) |
sahilmgandhi | 18:6a4db94011d3 | 73 | { |
sahilmgandhi | 18:6a4db94011d3 | 74 | /* Workaround for Errata 16 "System: RAM may be corrupt on wakeup from CPU IDLE" found at the Errata document |
sahilmgandhi | 18:6a4db94011d3 | 75 | for your device located at https://infocenter.nordicsemi.com/ */ |
sahilmgandhi | 18:6a4db94011d3 | 76 | if (errata_16()){ |
sahilmgandhi | 18:6a4db94011d3 | 77 | *(volatile uint32_t *)0x4007C074 = 3131961357ul; |
sahilmgandhi | 18:6a4db94011d3 | 78 | } |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | /* Workaround for Errata 31 "CLOCK: Calibration values are not correctly loaded from FICR at reset" found at the Errata document |
sahilmgandhi | 18:6a4db94011d3 | 81 | for your device located at https://infocenter.nordicsemi.com/ */ |
sahilmgandhi | 18:6a4db94011d3 | 82 | if (errata_31()){ |
sahilmgandhi | 18:6a4db94011d3 | 83 | *(volatile uint32_t *)0x4000053C = ((*(volatile uint32_t *)0x10000244) & 0x0000E000) >> 13; |
sahilmgandhi | 18:6a4db94011d3 | 84 | } |
sahilmgandhi | 18:6a4db94011d3 | 85 | |
sahilmgandhi | 18:6a4db94011d3 | 86 | /* Workaround for Errata 32 "DIF: Debug session automatically enables TracePort pins" found at the Errata document |
sahilmgandhi | 18:6a4db94011d3 | 87 | for your device located at https://infocenter.nordicsemi.com/ */ |
sahilmgandhi | 18:6a4db94011d3 | 88 | if (errata_32()){ |
sahilmgandhi | 18:6a4db94011d3 | 89 | CoreDebug->DEMCR &= ~CoreDebug_DEMCR_TRCENA_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 90 | } |
sahilmgandhi | 18:6a4db94011d3 | 91 | |
sahilmgandhi | 18:6a4db94011d3 | 92 | /* Workaround for Errata 36 "CLOCK: Some registers are not reset when expected" found at the Errata document |
sahilmgandhi | 18:6a4db94011d3 | 93 | for your device located at https://infocenter.nordicsemi.com/ */ |
sahilmgandhi | 18:6a4db94011d3 | 94 | if (errata_36()){ |
sahilmgandhi | 18:6a4db94011d3 | 95 | NRF_CLOCK->EVENTS_DONE = 0; |
sahilmgandhi | 18:6a4db94011d3 | 96 | NRF_CLOCK->EVENTS_CTTO = 0; |
sahilmgandhi | 18:6a4db94011d3 | 97 | NRF_CLOCK->CTIV = 0; |
sahilmgandhi | 18:6a4db94011d3 | 98 | } |
sahilmgandhi | 18:6a4db94011d3 | 99 | |
sahilmgandhi | 18:6a4db94011d3 | 100 | /* Workaround for Errata 37 "RADIO: Encryption engine is slow by default" found at the Errata document |
sahilmgandhi | 18:6a4db94011d3 | 101 | for your device located at https://infocenter.nordicsemi.com/ */ |
sahilmgandhi | 18:6a4db94011d3 | 102 | if (errata_37()){ |
sahilmgandhi | 18:6a4db94011d3 | 103 | *(volatile uint32_t *)0x400005A0 = 0x3; |
sahilmgandhi | 18:6a4db94011d3 | 104 | } |
sahilmgandhi | 18:6a4db94011d3 | 105 | |
sahilmgandhi | 18:6a4db94011d3 | 106 | /* Workaround for Errata 57 "NFCT: NFC Modulation amplitude" found at the Errata document |
sahilmgandhi | 18:6a4db94011d3 | 107 | for your device located at https://infocenter.nordicsemi.com/ */ |
sahilmgandhi | 18:6a4db94011d3 | 108 | if (errata_57()){ |
sahilmgandhi | 18:6a4db94011d3 | 109 | *(volatile uint32_t *)0x40005610 = 0x00000005; |
sahilmgandhi | 18:6a4db94011d3 | 110 | *(volatile uint32_t *)0x40005688 = 0x00000001; |
sahilmgandhi | 18:6a4db94011d3 | 111 | *(volatile uint32_t *)0x40005618 = 0x00000000; |
sahilmgandhi | 18:6a4db94011d3 | 112 | *(volatile uint32_t *)0x40005614 = 0x0000003F; |
sahilmgandhi | 18:6a4db94011d3 | 113 | } |
sahilmgandhi | 18:6a4db94011d3 | 114 | |
sahilmgandhi | 18:6a4db94011d3 | 115 | /* Workaround for Errata 66 "TEMP: Linearity specification not met with default settings" found at the Errata document |
sahilmgandhi | 18:6a4db94011d3 | 116 | for your device located at https://infocenter.nordicsemi.com/ */ |
sahilmgandhi | 18:6a4db94011d3 | 117 | if (errata_66()){ |
sahilmgandhi | 18:6a4db94011d3 | 118 | NRF_TEMP->A0 = NRF_FICR->TEMP.A0; |
sahilmgandhi | 18:6a4db94011d3 | 119 | NRF_TEMP->A1 = NRF_FICR->TEMP.A1; |
sahilmgandhi | 18:6a4db94011d3 | 120 | NRF_TEMP->A2 = NRF_FICR->TEMP.A2; |
sahilmgandhi | 18:6a4db94011d3 | 121 | NRF_TEMP->A3 = NRF_FICR->TEMP.A3; |
sahilmgandhi | 18:6a4db94011d3 | 122 | NRF_TEMP->A4 = NRF_FICR->TEMP.A4; |
sahilmgandhi | 18:6a4db94011d3 | 123 | NRF_TEMP->A5 = NRF_FICR->TEMP.A5; |
sahilmgandhi | 18:6a4db94011d3 | 124 | NRF_TEMP->B0 = NRF_FICR->TEMP.B0; |
sahilmgandhi | 18:6a4db94011d3 | 125 | NRF_TEMP->B1 = NRF_FICR->TEMP.B1; |
sahilmgandhi | 18:6a4db94011d3 | 126 | NRF_TEMP->B2 = NRF_FICR->TEMP.B2; |
sahilmgandhi | 18:6a4db94011d3 | 127 | NRF_TEMP->B3 = NRF_FICR->TEMP.B3; |
sahilmgandhi | 18:6a4db94011d3 | 128 | NRF_TEMP->B4 = NRF_FICR->TEMP.B4; |
sahilmgandhi | 18:6a4db94011d3 | 129 | NRF_TEMP->B5 = NRF_FICR->TEMP.B5; |
sahilmgandhi | 18:6a4db94011d3 | 130 | NRF_TEMP->T0 = NRF_FICR->TEMP.T0; |
sahilmgandhi | 18:6a4db94011d3 | 131 | NRF_TEMP->T1 = NRF_FICR->TEMP.T1; |
sahilmgandhi | 18:6a4db94011d3 | 132 | NRF_TEMP->T2 = NRF_FICR->TEMP.T2; |
sahilmgandhi | 18:6a4db94011d3 | 133 | NRF_TEMP->T3 = NRF_FICR->TEMP.T3; |
sahilmgandhi | 18:6a4db94011d3 | 134 | NRF_TEMP->T4 = NRF_FICR->TEMP.T4; |
sahilmgandhi | 18:6a4db94011d3 | 135 | } |
sahilmgandhi | 18:6a4db94011d3 | 136 | |
sahilmgandhi | 18:6a4db94011d3 | 137 | /* Enable the FPU if the compiler used floating point unit instructions. __FPU_USED is a MACRO defined by the |
sahilmgandhi | 18:6a4db94011d3 | 138 | * compiler. Since the FPU consumes energy, remember to disable FPU use in the compiler if floating point unit |
sahilmgandhi | 18:6a4db94011d3 | 139 | * operations are not used in your code. */ |
sahilmgandhi | 18:6a4db94011d3 | 140 | #if (__FPU_USED == 1) |
sahilmgandhi | 18:6a4db94011d3 | 141 | SCB->CPACR |= (3UL << 20) | (3UL << 22); |
sahilmgandhi | 18:6a4db94011d3 | 142 | __DSB(); |
sahilmgandhi | 18:6a4db94011d3 | 143 | __ISB(); |
sahilmgandhi | 18:6a4db94011d3 | 144 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 145 | |
sahilmgandhi | 18:6a4db94011d3 | 146 | /* Configure NFCT pins as GPIOs if NFCT is not to be used in your code. If CONFIG_NFCT_PINS_AS_GPIOS is not defined, |
sahilmgandhi | 18:6a4db94011d3 | 147 | two GPIOs (see Product Specification to see which ones) will be reserved for NFC and will not be available as |
sahilmgandhi | 18:6a4db94011d3 | 148 | normal GPIOs. */ |
sahilmgandhi | 18:6a4db94011d3 | 149 | #if defined (CONFIG_NFCT_PINS_AS_GPIOS) |
sahilmgandhi | 18:6a4db94011d3 | 150 | if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) == (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)){ |
sahilmgandhi | 18:6a4db94011d3 | 151 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 152 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
sahilmgandhi | 18:6a4db94011d3 | 153 | NRF_UICR->NFCPINS &= ~UICR_NFCPINS_PROTECT_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 154 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
sahilmgandhi | 18:6a4db94011d3 | 155 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 156 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
sahilmgandhi | 18:6a4db94011d3 | 157 | NVIC_SystemReset(); |
sahilmgandhi | 18:6a4db94011d3 | 158 | } |
sahilmgandhi | 18:6a4db94011d3 | 159 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 160 | |
sahilmgandhi | 18:6a4db94011d3 | 161 | /* Configure GPIO pads as pPin Reset pin if Pin Reset capabilities desired. If CONFIG_GPIO_AS_PINRESET is not |
sahilmgandhi | 18:6a4db94011d3 | 162 | defined, pin reset will not be available. One GPIO (see Product Specification to see which one) will then be |
sahilmgandhi | 18:6a4db94011d3 | 163 | reserved for PinReset and not available as normal GPIO. */ |
sahilmgandhi | 18:6a4db94011d3 | 164 | #if defined (CONFIG_GPIO_AS_PINRESET) |
sahilmgandhi | 18:6a4db94011d3 | 165 | if (((NRF_UICR->PSELRESET[0] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos)) || |
sahilmgandhi | 18:6a4db94011d3 | 166 | ((NRF_UICR->PSELRESET[1] & UICR_PSELRESET_CONNECT_Msk) != (UICR_PSELRESET_CONNECT_Connected << UICR_PSELRESET_CONNECT_Pos))){ |
sahilmgandhi | 18:6a4db94011d3 | 167 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 168 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
sahilmgandhi | 18:6a4db94011d3 | 169 | NRF_UICR->PSELRESET[0] = 21; |
sahilmgandhi | 18:6a4db94011d3 | 170 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
sahilmgandhi | 18:6a4db94011d3 | 171 | NRF_UICR->PSELRESET[1] = 21; |
sahilmgandhi | 18:6a4db94011d3 | 172 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
sahilmgandhi | 18:6a4db94011d3 | 173 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 174 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} |
sahilmgandhi | 18:6a4db94011d3 | 175 | NVIC_SystemReset(); |
sahilmgandhi | 18:6a4db94011d3 | 176 | } |
sahilmgandhi | 18:6a4db94011d3 | 177 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 178 | |
sahilmgandhi | 18:6a4db94011d3 | 179 | /* Enable SWO trace functionality. If ENABLE_SWO is not defined, SWO pin will be used as GPIO (see Product |
sahilmgandhi | 18:6a4db94011d3 | 180 | Specification to see which one). */ |
sahilmgandhi | 18:6a4db94011d3 | 181 | #if defined (ENABLE_SWO) |
sahilmgandhi | 18:6a4db94011d3 | 182 | CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 183 | NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Serial << CLOCK_TRACECONFIG_TRACEMUX_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 184 | NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 185 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 186 | |
sahilmgandhi | 18:6a4db94011d3 | 187 | /* Enable Trace functionality. If ENABLE_TRACE is not defined, TRACE pins will be used as GPIOs (see Product |
sahilmgandhi | 18:6a4db94011d3 | 188 | Specification to see which ones). */ |
sahilmgandhi | 18:6a4db94011d3 | 189 | #if defined (ENABLE_TRACE) |
sahilmgandhi | 18:6a4db94011d3 | 190 | CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 191 | NRF_CLOCK->TRACECONFIG |= CLOCK_TRACECONFIG_TRACEMUX_Parallel << CLOCK_TRACECONFIG_TRACEMUX_Pos; |
sahilmgandhi | 18:6a4db94011d3 | 192 | NRF_P0->PIN_CNF[14] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 193 | NRF_P0->PIN_CNF[15] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 194 | NRF_P0->PIN_CNF[16] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 195 | NRF_P0->PIN_CNF[18] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 196 | NRF_P0->PIN_CNF[20] = (GPIO_PIN_CNF_DRIVE_H0H1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 197 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 198 | |
sahilmgandhi | 18:6a4db94011d3 | 199 | SystemCoreClockUpdate(); |
sahilmgandhi | 18:6a4db94011d3 | 200 | |
sahilmgandhi | 18:6a4db94011d3 | 201 | // Start the LF oscilator according to the mbed configuration (over the nrf5x_lf_clk_helper.h file) |
sahilmgandhi | 18:6a4db94011d3 | 202 | NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_TO_USE << CLOCK_LFCLKSRC_SRC_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 203 | NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; |
sahilmgandhi | 18:6a4db94011d3 | 204 | NRF_CLOCK->TASKS_LFCLKSTART = 1; |
sahilmgandhi | 18:6a4db94011d3 | 205 | |
sahilmgandhi | 18:6a4db94011d3 | 206 | // Wait for the external oscillator to start up. |
sahilmgandhi | 18:6a4db94011d3 | 207 | while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) { |
sahilmgandhi | 18:6a4db94011d3 | 208 | // Do nothing. |
sahilmgandhi | 18:6a4db94011d3 | 209 | } |
sahilmgandhi | 18:6a4db94011d3 | 210 | } |
sahilmgandhi | 18:6a4db94011d3 | 211 | |
sahilmgandhi | 18:6a4db94011d3 | 212 | |
sahilmgandhi | 18:6a4db94011d3 | 213 | static bool errata_16(void) |
sahilmgandhi | 18:6a4db94011d3 | 214 | { |
sahilmgandhi | 18:6a4db94011d3 | 215 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) |
sahilmgandhi | 18:6a4db94011d3 | 216 | { |
sahilmgandhi | 18:6a4db94011d3 | 217 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) |
sahilmgandhi | 18:6a4db94011d3 | 218 | { |
sahilmgandhi | 18:6a4db94011d3 | 219 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 220 | } |
sahilmgandhi | 18:6a4db94011d3 | 221 | } |
sahilmgandhi | 18:6a4db94011d3 | 222 | |
sahilmgandhi | 18:6a4db94011d3 | 223 | return false; |
sahilmgandhi | 18:6a4db94011d3 | 224 | } |
sahilmgandhi | 18:6a4db94011d3 | 225 | |
sahilmgandhi | 18:6a4db94011d3 | 226 | static bool errata_31(void) |
sahilmgandhi | 18:6a4db94011d3 | 227 | { |
sahilmgandhi | 18:6a4db94011d3 | 228 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) |
sahilmgandhi | 18:6a4db94011d3 | 229 | { |
sahilmgandhi | 18:6a4db94011d3 | 230 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) |
sahilmgandhi | 18:6a4db94011d3 | 231 | { |
sahilmgandhi | 18:6a4db94011d3 | 232 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 233 | } |
sahilmgandhi | 18:6a4db94011d3 | 234 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) |
sahilmgandhi | 18:6a4db94011d3 | 235 | { |
sahilmgandhi | 18:6a4db94011d3 | 236 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 237 | } |
sahilmgandhi | 18:6a4db94011d3 | 238 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50) |
sahilmgandhi | 18:6a4db94011d3 | 239 | { |
sahilmgandhi | 18:6a4db94011d3 | 240 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 241 | } |
sahilmgandhi | 18:6a4db94011d3 | 242 | } |
sahilmgandhi | 18:6a4db94011d3 | 243 | |
sahilmgandhi | 18:6a4db94011d3 | 244 | return false; |
sahilmgandhi | 18:6a4db94011d3 | 245 | } |
sahilmgandhi | 18:6a4db94011d3 | 246 | |
sahilmgandhi | 18:6a4db94011d3 | 247 | static bool errata_32(void) |
sahilmgandhi | 18:6a4db94011d3 | 248 | { |
sahilmgandhi | 18:6a4db94011d3 | 249 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) |
sahilmgandhi | 18:6a4db94011d3 | 250 | { |
sahilmgandhi | 18:6a4db94011d3 | 251 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) |
sahilmgandhi | 18:6a4db94011d3 | 252 | { |
sahilmgandhi | 18:6a4db94011d3 | 253 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 254 | } |
sahilmgandhi | 18:6a4db94011d3 | 255 | } |
sahilmgandhi | 18:6a4db94011d3 | 256 | |
sahilmgandhi | 18:6a4db94011d3 | 257 | return false; |
sahilmgandhi | 18:6a4db94011d3 | 258 | } |
sahilmgandhi | 18:6a4db94011d3 | 259 | |
sahilmgandhi | 18:6a4db94011d3 | 260 | static bool errata_36(void) |
sahilmgandhi | 18:6a4db94011d3 | 261 | { |
sahilmgandhi | 18:6a4db94011d3 | 262 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) |
sahilmgandhi | 18:6a4db94011d3 | 263 | { |
sahilmgandhi | 18:6a4db94011d3 | 264 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) |
sahilmgandhi | 18:6a4db94011d3 | 265 | { |
sahilmgandhi | 18:6a4db94011d3 | 266 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 267 | } |
sahilmgandhi | 18:6a4db94011d3 | 268 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) |
sahilmgandhi | 18:6a4db94011d3 | 269 | { |
sahilmgandhi | 18:6a4db94011d3 | 270 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 271 | } |
sahilmgandhi | 18:6a4db94011d3 | 272 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50) |
sahilmgandhi | 18:6a4db94011d3 | 273 | { |
sahilmgandhi | 18:6a4db94011d3 | 274 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 275 | } |
sahilmgandhi | 18:6a4db94011d3 | 276 | } |
sahilmgandhi | 18:6a4db94011d3 | 277 | |
sahilmgandhi | 18:6a4db94011d3 | 278 | return false; |
sahilmgandhi | 18:6a4db94011d3 | 279 | } |
sahilmgandhi | 18:6a4db94011d3 | 280 | |
sahilmgandhi | 18:6a4db94011d3 | 281 | static bool errata_37(void) |
sahilmgandhi | 18:6a4db94011d3 | 282 | { |
sahilmgandhi | 18:6a4db94011d3 | 283 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) |
sahilmgandhi | 18:6a4db94011d3 | 284 | { |
sahilmgandhi | 18:6a4db94011d3 | 285 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) |
sahilmgandhi | 18:6a4db94011d3 | 286 | { |
sahilmgandhi | 18:6a4db94011d3 | 287 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 288 | } |
sahilmgandhi | 18:6a4db94011d3 | 289 | } |
sahilmgandhi | 18:6a4db94011d3 | 290 | |
sahilmgandhi | 18:6a4db94011d3 | 291 | return false; |
sahilmgandhi | 18:6a4db94011d3 | 292 | } |
sahilmgandhi | 18:6a4db94011d3 | 293 | |
sahilmgandhi | 18:6a4db94011d3 | 294 | static bool errata_57(void) |
sahilmgandhi | 18:6a4db94011d3 | 295 | { |
sahilmgandhi | 18:6a4db94011d3 | 296 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) |
sahilmgandhi | 18:6a4db94011d3 | 297 | { |
sahilmgandhi | 18:6a4db94011d3 | 298 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) |
sahilmgandhi | 18:6a4db94011d3 | 299 | { |
sahilmgandhi | 18:6a4db94011d3 | 300 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 301 | } |
sahilmgandhi | 18:6a4db94011d3 | 302 | } |
sahilmgandhi | 18:6a4db94011d3 | 303 | |
sahilmgandhi | 18:6a4db94011d3 | 304 | return false; |
sahilmgandhi | 18:6a4db94011d3 | 305 | } |
sahilmgandhi | 18:6a4db94011d3 | 306 | |
sahilmgandhi | 18:6a4db94011d3 | 307 | static bool errata_66(void) |
sahilmgandhi | 18:6a4db94011d3 | 308 | { |
sahilmgandhi | 18:6a4db94011d3 | 309 | if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x6) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0)) |
sahilmgandhi | 18:6a4db94011d3 | 310 | { |
sahilmgandhi | 18:6a4db94011d3 | 311 | if (((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x50) |
sahilmgandhi | 18:6a4db94011d3 | 312 | { |
sahilmgandhi | 18:6a4db94011d3 | 313 | return true; |
sahilmgandhi | 18:6a4db94011d3 | 314 | } |
sahilmgandhi | 18:6a4db94011d3 | 315 | } |
sahilmgandhi | 18:6a4db94011d3 | 316 | |
sahilmgandhi | 18:6a4db94011d3 | 317 | return false; |
sahilmgandhi | 18:6a4db94011d3 | 318 | } |
sahilmgandhi | 18:6a4db94011d3 | 319 | |
sahilmgandhi | 18:6a4db94011d3 | 320 | |
sahilmgandhi | 18:6a4db94011d3 | 321 | /*lint --flb "Leave library region" */ |