| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- /* Copyright (c) 2015, Nordic Semiconductor ASA
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * * Neither the name of Nordic Semiconductor ASA nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- /* NOTE: Template files (including this one) are application specific and therefore expected to
- be copied into the application project folder prior to its use! */
- #include <stdint.h>
- #include <stdbool.h>
- #include "nrf.h"
- #include "system_nrf51.h"
- /*lint ++flb "Enter library region" */
- #define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */
- static bool is_manual_peripheral_setup_needed(void);
- static bool is_disabled_in_debug_needed(void);
- static bool is_peripheral_domain_setup_needed(void);
- #if defined ( __CC_ARM )
- uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
- #elif defined ( __ICCARM__ )
- __root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
- #elif defined ( __GNUC__ )
- uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
- #endif
- void SystemCoreClockUpdate(void)
- {
- SystemCoreClock = __SYSTEM_CLOCK;
- }
- void SystemInit(void)
- {
- /* If desired, switch off the unused RAM to lower consumption by the use of RAMON register.
- It can also be done in the application main() function. */
- /* Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
- to enable the use of peripherals" found at Product Anomaly document for your device found at
- https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
- that do not need it is that the new peripherals in the second generation devices (LPCOMP for
- example) will not be available. */
- if (is_manual_peripheral_setup_needed())
- {
- *(uint32_t volatile *)0x40000504 = 0xC007FFDF;
- *(uint32_t volatile *)0x40006C18 = 0x00008000;
- }
- /* Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
- register is incorrect" found at Product Anomaly document for your device found at
- https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed. */
- if (is_disabled_in_debug_needed())
- {
- NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
- }
- /* Execute the following code to eliminate excessive current in sleep mode with RAM retention in nRF51802 devices,
- as indicated by PAN 76 "System: Excessive current in sleep mode with retention" found at Product Anomaly document
- for your device found at https://www.nordicsemi.com/. */
- if (is_peripheral_domain_setup_needed()){
- if (*(uint32_t volatile *)0x4006EC00 != 1){
- *(uint32_t volatile *)0x4006EC00 = 0x9375;
- while (*(uint32_t volatile *)0x4006EC00 != 1){
- }
- }
- *(uint32_t volatile *)0x4006EC14 = 0xC0;
- }
- }
- static bool is_manual_peripheral_setup_needed(void)
- {
- if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
- {
- if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x00) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
- {
- return true;
- }
- if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x10) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
- {
- return true;
- }
- if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
- {
- return true;
- }
- }
- return false;
- }
- static bool is_disabled_in_debug_needed(void)
- {
- if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
- {
- if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
- {
- return true;
- }
- }
- return false;
- }
- static bool is_peripheral_domain_setup_needed(void)
- {
- if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
- {
- if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0xA0) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
- {
- return true;
- }
- if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0xD0) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
- {
- return true;
- }
- }
- return false;
- }
- /*lint --flb "Leave library region" */
|