├── .cargo └── config ├── .gitignore ├── .gitmodules ├── Cargo.toml ├── Dockerfile ├── LICENSE ├── README.md ├── SETUP.md ├── bindings.h ├── build.rs ├── examples ├── ble_app_template.rs ├── blinky.rs └── logging.rs ├── extract-features.py ├── nRF5-sdk ├── components │ ├── ble │ │ ├── ble_advertising │ │ │ ├── ble_advertising.c │ │ │ └── ble_advertising.h │ │ ├── common │ │ │ ├── ble_advdata.c │ │ │ ├── ble_advdata.h │ │ │ ├── ble_conn_params.c │ │ │ ├── ble_conn_params.h │ │ │ ├── ble_conn_state.c │ │ │ ├── ble_conn_state.h │ │ │ ├── ble_date_time.h │ │ │ ├── ble_gatt_db.h │ │ │ ├── ble_sensor_location.h │ │ │ ├── ble_srv_common.c │ │ │ └── ble_srv_common.h │ │ ├── nrf_ble_gatt │ │ │ ├── nrf_ble_gatt.c │ │ │ └── nrf_ble_gatt.h │ │ └── peer_manager │ │ │ ├── gatt_cache_manager.c │ │ │ ├── gatt_cache_manager.h │ │ │ ├── gatts_cache_manager.c │ │ │ ├── gatts_cache_manager.h │ │ │ ├── id_manager.c │ │ │ ├── id_manager.h │ │ │ ├── peer_data_storage.c │ │ │ ├── peer_data_storage.h │ │ │ ├── peer_database.c │ │ │ ├── peer_database.h │ │ │ ├── peer_id.c │ │ │ ├── peer_id.h │ │ │ ├── peer_manager.c │ │ │ ├── peer_manager.h │ │ │ ├── peer_manager_internal.h │ │ │ ├── peer_manager_types.h │ │ │ ├── pm_buffer.c │ │ │ ├── pm_buffer.h │ │ │ ├── pm_mutex.c │ │ │ ├── pm_mutex.h │ │ │ ├── security_dispatcher.c │ │ │ ├── security_dispatcher.h │ │ │ ├── security_manager.c │ │ │ └── security_manager.h │ ├── boards │ │ ├── boards.c │ │ ├── boards.h │ │ └── pca10040.h │ ├── device │ │ ├── compiler_abstraction.h │ │ ├── nrf.h │ │ ├── nrf51_to_nrf52.h │ │ ├── nrf52.h │ │ ├── nrf52832_peripherals.h │ │ ├── nrf52_bitfields.h │ │ └── nrf52_name_change.h │ ├── drivers_nrf │ │ ├── clock │ │ │ ├── nrf_drv_clock.c │ │ │ └── nrf_drv_clock.h │ │ ├── common │ │ │ ├── nrf_drv_common.c │ │ │ └── nrf_drv_common.h │ │ ├── delay │ │ │ └── nrf_delay.h │ │ ├── gpiote │ │ │ ├── nrf_drv_gpiote.c │ │ │ └── nrf_drv_gpiote.h │ │ ├── hal │ │ │ ├── nrf_clock.h │ │ │ ├── nrf_comp.h │ │ │ ├── nrf_ecb.c │ │ │ ├── nrf_ecb.h │ │ │ ├── nrf_egu.h │ │ │ ├── nrf_gpio.h │ │ │ ├── nrf_gpiote.h │ │ │ ├── nrf_i2s.h │ │ │ ├── nrf_lpcomp.h │ │ │ ├── nrf_nvmc.c │ │ │ ├── nrf_nvmc.h │ │ │ ├── nrf_pdm.h │ │ │ ├── nrf_peripherals.h │ │ │ ├── nrf_power.h │ │ │ ├── nrf_ppi.h │ │ │ ├── nrf_pwm.h │ │ │ ├── nrf_qdec.h │ │ │ ├── nrf_qspi.h │ │ │ ├── nrf_rng.h │ │ │ ├── nrf_rtc.h │ │ │ ├── nrf_saadc.c │ │ │ ├── nrf_saadc.h │ │ │ ├── nrf_spi.h │ │ │ ├── nrf_spim.h │ │ │ ├── nrf_spis.h │ │ │ ├── nrf_systick.h │ │ │ ├── nrf_temp.h │ │ │ ├── nrf_timer.h │ │ │ ├── nrf_twi.h │ │ │ ├── nrf_twim.h │ │ │ ├── nrf_twis.h │ │ │ ├── nrf_uart.h │ │ │ ├── nrf_uarte.h │ │ │ ├── nrf_usbd.h │ │ │ └── nrf_wdt.h │ │ └── uart │ │ │ ├── nrf_drv_uart.c │ │ │ └── nrf_drv_uart.h │ ├── libraries │ │ ├── bsp │ │ │ ├── bsp.c │ │ │ ├── bsp.h │ │ │ ├── bsp_btn_ant.h │ │ │ ├── bsp_btn_ble.c │ │ │ ├── bsp_btn_ble.h │ │ │ ├── bsp_config.h │ │ │ ├── bsp_nfc.c │ │ │ └── bsp_nfc.h │ │ ├── button │ │ │ ├── app_button.c │ │ │ └── app_button.h │ │ ├── crc16 │ │ │ ├── crc16.c │ │ │ └── crc16.h │ │ ├── experimental_section_vars │ │ │ ├── nrf_section.h │ │ │ ├── nrf_section_iter.c │ │ │ └── nrf_section_iter.h │ │ ├── fds │ │ │ ├── fds.c │ │ │ ├── fds.h │ │ │ └── fds_internal_defs.h │ │ ├── fstorage │ │ │ ├── fstorage.c │ │ │ ├── fstorage.h │ │ │ ├── fstorage_internal_defs.h │ │ │ └── fstorage_nosd.c │ │ ├── hardfault │ │ │ ├── hardfault.h │ │ │ ├── hardfault_implementation.c │ │ │ ├── nrf51 │ │ │ │ └── handler │ │ │ │ │ ├── hardfault_handler_gcc.c │ │ │ │ │ ├── hardfault_handler_iar.c │ │ │ │ │ └── hardfault_handler_keil.c │ │ │ └── nrf52 │ │ │ │ └── handler │ │ │ │ ├── hardfault_handler_gcc.c │ │ │ │ ├── hardfault_handler_iar.c │ │ │ │ └── hardfault_handler_keil.c │ │ ├── log │ │ │ ├── nrf_log.h │ │ │ ├── nrf_log_backend.h │ │ │ ├── nrf_log_ctrl.h │ │ │ └── src │ │ │ │ ├── nrf_log_backend_serial.c │ │ │ │ ├── nrf_log_ctrl_internal.h │ │ │ │ ├── nrf_log_frontend.c │ │ │ │ └── nrf_log_internal.h │ │ ├── scheduler │ │ │ ├── app_scheduler.c │ │ │ ├── app_scheduler.h │ │ │ └── app_scheduler_serconn.c │ │ ├── sensorsim │ │ │ ├── sensorsim.c │ │ │ └── sensorsim.h │ │ ├── strerror │ │ │ ├── nrf_strerror.c │ │ │ └── nrf_strerror.h │ │ ├── timer │ │ │ ├── app_timer.c │ │ │ └── app_timer.h │ │ └── util │ │ │ ├── app_error.c │ │ │ ├── app_error.h │ │ │ ├── app_error_weak.c │ │ │ ├── app_error_weak.h │ │ │ ├── app_util.h │ │ │ ├── app_util_bds.h │ │ │ ├── app_util_platform.c │ │ │ ├── app_util_platform.h │ │ │ ├── nordic_common.h │ │ │ ├── nrf_assert.c │ │ │ ├── nrf_assert.h │ │ │ ├── nrf_bitmask.h │ │ │ ├── sdk_common.h │ │ │ ├── sdk_errors.h │ │ │ ├── sdk_macros.h │ │ │ ├── sdk_mapped_flags.c │ │ │ ├── sdk_mapped_flags.h │ │ │ ├── sdk_os.h │ │ │ └── sdk_resources.h │ ├── softdevice │ │ ├── common │ │ │ └── softdevice_handler │ │ │ │ ├── ant_stack_handler_types.h │ │ │ │ ├── ble_stack_handler_types.h │ │ │ │ ├── softdevice_handler.c │ │ │ │ ├── softdevice_handler.h │ │ │ │ ├── softdevice_handler_appsh.c │ │ │ │ └── softdevice_handler_appsh.h │ │ └── s132 │ │ │ └── headers │ │ │ ├── ble.h │ │ │ ├── ble_err.h │ │ │ ├── ble_gap.h │ │ │ ├── ble_gatt.h │ │ │ ├── ble_gattc.h │ │ │ ├── ble_gatts.h │ │ │ ├── ble_hci.h │ │ │ ├── ble_l2cap.h │ │ │ ├── ble_ranges.h │ │ │ ├── ble_types.h │ │ │ ├── nrf52 │ │ │ └── nrf_mbr.h │ │ │ ├── nrf_error.h │ │ │ ├── nrf_error_sdm.h │ │ │ ├── nrf_error_soc.h │ │ │ ├── nrf_nvic.h │ │ │ ├── nrf_sd_def.h │ │ │ ├── nrf_sdm.h │ │ │ ├── nrf_soc.h │ │ │ └── nrf_svc.h │ └── toolchain │ │ ├── cmsis │ │ └── include │ │ │ ├── cmsis_gcc.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cmFunc.h │ │ │ ├── core_cmInstr.h │ │ │ └── core_cmSimd.h │ │ ├── gcc │ │ └── gcc_startup_nrf52.S │ │ ├── system_nrf52.c │ │ └── system_nrf52.h └── external │ └── segger_rtt │ ├── RTT_Syscalls_GCC.c │ ├── RTT_Syscalls_IAR.c │ ├── RTT_Syscalls_KEIL.c │ ├── SEGGER_RTT.c │ ├── SEGGER_RTT.h │ ├── SEGGER_RTT_Conf.h │ ├── SEGGER_RTT_printf.c │ └── license │ └── license.txt ├── nrf52dk-sys.ld ├── nrf5x_common.ld ├── shims ├── sdk_config.h ├── shimmy.c └── shims.h └── src ├── lang_items.rs ├── lib.rs └── macros.rs /.cargo/config: -------------------------------------------------------------------------------- 1 | 2 | [target.thumbv7em-none-eabihf] 3 | rustflags = [ 4 | "-C", "link-arg=-mthumb", 5 | "-C", "link-arg=-Tnrf52dk-sys.ld", 6 | "-C", "link-arg=-mcpu=cortex-m4", 7 | "-C", "link-arg=--specs=nano.specs", 8 | 9 | "-C", "link-arg=-Wl,--gc-sections", 10 | "-C", "link-arg=-Wl,--start-group", 11 | "-C", "link-arg=-Wl,--end-group", 12 | "-C", "link-arg=-Wl,--build-id=none", 13 | 14 | "-C", "link-arg=-mabi=aapcs", 15 | "-C", "link-arg=-mfloat-abi=hard", 16 | "-C", "link-arg=-mfpu=fpv4-sp-d16", 17 | ] 18 | 19 | [build] 20 | target = "thumbv7em-none-eabihf" 21 | incremental = false 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | target 3 | *.o 4 | *.d 5 | *.hex 6 | *.elf 7 | *.a 8 | *.bk 9 | *.gdbinit 10 | .vscode 11 | *.swp 12 | 13 | # Libraries should not check in Cargo.lock 14 | Cargo.lock 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesmunns/nrf52dk-sys/13b2a30cb16949b414a3625dd7464326a2019018/.gitmodules -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nrf52dk-sys" 3 | version = "0.2.0" 4 | authors = ["James Munns "] 5 | build = "build.rs" 6 | license = "MIT" 7 | repository = "https://github.com/jamesmunns/nrf52dk-sys" 8 | description = "nrf52 support using the nRF5-SDK and SoftDevice S132" 9 | 10 | [dependencies] 11 | cortex-m = "0.1.6" 12 | r0 = "0.2.0" 13 | 14 | [build-dependencies] 15 | gcc = "0.3.46" 16 | 17 | [profile.dev] 18 | panic = "abort" 19 | lto = true 20 | 21 | [profile.release] 22 | panic = "abort" 23 | lto = true 24 | 25 | [features] 26 | default = ["APP_SCHEDULER","APP_TIMER","BLE_ADVERTISING","BUTTON","CLOCK","CRC16","FDS","FSTORAGE","GPIOTE","NRF_BLE_GATT","NRF_LOG","NRF_STRERROR","PEER_MANAGER","UART","UART0"] 27 | APP_GPIOTE = [] 28 | APP_PWM = [] 29 | APP_SCHEDULER = [] 30 | APP_TIMER = [] 31 | APP_TWI = [] 32 | APP_UART = [] 33 | APP_USBD = [] 34 | APP_USBD_CLASS_AUDIO = ["APP_USBD"] 35 | APP_USBD_CLASS_CDC_ACM = ["APP_USBD"] 36 | APP_USBD_CLASS_HID = ["APP_USBD"] 37 | APP_USBD_CLASS_MSC = ["APP_USBD"] 38 | APP_USBD_HID_GENERIC = ["APP_USBD"] 39 | APP_USBD_HID_KBD = ["APP_USBD"] 40 | APP_USBD_HID_MOUSE = ["APP_USBD"] 41 | BLE_ADVERTISING = [] 42 | BLE_ANCS_C = [] 43 | BLE_ANS_C = [] 44 | BLE_BAS = [] 45 | BLE_BAS_C = ["BLE_BAS"] 46 | BLE_CSCS = [] 47 | BLE_CTS_C = [] 48 | BLE_DIS = [] 49 | BLE_DTM = [] 50 | BLE_GLS = [] 51 | BLE_HIDS = [] 52 | BLE_HRS = [] 53 | BLE_HRS_C = ["BLE_HRS"] 54 | BLE_HTS = [] 55 | BLE_IAS = [] 56 | BLE_IAS_C = ["BLE_IAS"] 57 | BLE_LBS = [] 58 | BLE_LBS_C = ["BLE_LBS"] 59 | BLE_LLS = [] 60 | BLE_NUS = [] 61 | BLE_NUS_C = ["BLE_NUS"] 62 | BLE_RACP = [] 63 | BLE_RSCS = [] 64 | BLE_RSCS_C = ["BLE_RSCS"] 65 | BLE_TPS = [] 66 | BUTTON = [] 67 | CLOCK = [] 68 | COMP = [] 69 | CRC16 = [] 70 | CRC32 = [] 71 | ECC = [] 72 | EGU = [] 73 | FDS = [] 74 | FSTORAGE = [] 75 | GPIOTE = [] 76 | HARDFAULT_HANDLER = [] 77 | HCI_MEM_POOL = [] 78 | HCI_SLIP = [] 79 | HCI_TRANSPORT = [] 80 | I2S = [] 81 | LED_SOFTBLINK = [] 82 | LOW_POWER_PWM = [] 83 | LPCOMP = [] 84 | MEM_MANAGER = [] 85 | NRF_BLE_GATT = [] 86 | NRF_BLE_QWR = [] 87 | NRF_CSENSE = [] 88 | NRF_DRV_CSENSE = [] 89 | NRF_LOG = [] 90 | NRF_QUEUE = [] 91 | NRF_STRERROR = [] 92 | PDM = [] 93 | PEER_MANAGER = [] 94 | PERIPHERAL_RESOURCE_SHARING = [] 95 | POWER = [] 96 | PPI = [] 97 | PWM = [] 98 | PWM0 = ["PWM"] 99 | PWM1 = ["PWM"] 100 | PWM2 = ["PWM"] 101 | PWM_NRF52_ANOMALY_109_WORKAROUND = ["PWM"] 102 | QDEC = [] 103 | RNG = [] 104 | RTC = [] 105 | RTC0 = ["RTC"] 106 | RTC1 = ["RTC"] 107 | RTC2 = ["RTC"] 108 | SAADC = [] 109 | SLIP = [] 110 | SPI = [] 111 | SPI0 = ["SPI"] 112 | SPI1 = ["SPI"] 113 | SPI2 = ["SPI"] 114 | SPIM_NRF52_ANOMALY_109_WORKAROUND = ["SPI"] 115 | SPIS = ["SPI"] 116 | SPIS0 = ["SPI"] 117 | SPIS1 = ["SPI"] 118 | SPIS2 = ["SPI"] 119 | SPIS_NRF52_ANOMALY_109_WORKAROUND = ["SPI"] 120 | TIMER = [] 121 | TIMER0 = ["TIMER"] 122 | TIMER1 = ["TIMER"] 123 | TIMER2 = ["TIMER"] 124 | TIMER3 = ["TIMER"] 125 | TIMER4 = ["TIMER"] 126 | TWI = [] 127 | TWI0 = ["TWI"] 128 | TWI1 = ["TWI"] 129 | TWIM_NRF52_ANOMALY_109_WORKAROUND = ["TWI"] 130 | TWIS = ["TWI"] 131 | TWIS0 = ["TWI"] 132 | TWIS1 = ["TWI"] 133 | UART = [] 134 | UART0 = ["UART"] 135 | USBD = [] 136 | WDT = [] 137 | 138 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:jessie 2 | 3 | # Install OS dependencies: 4 | # - curl/wget: obtain other installers 5 | # - build-essential: contains lots of useful tools 6 | # - git-core: needed to pull project source 7 | # - software-prop...: needed to add clang repo 8 | # - libc6-dev-i386: 32 bit headers 9 | RUN apt-get update && \ 10 | apt-get install -y \ 11 | wget \ 12 | curl \ 13 | build-essential \ 14 | git-core \ 15 | software-properties-common \ 16 | libc6-dev-i386 17 | 18 | # Install Clang v3.9 for bindgen 19 | RUN add-apt-repository "deb http://apt.llvm.org/jessie/ llvm-toolchain-jessie-3.9 main" && \ 20 | wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ 21 | apt-get update && \ 22 | apt-get install -y llvm-3.9-dev libclang-3.9-dev clang-3.9 23 | 24 | # Install GCC6.1 arm-none-eabi 25 | RUN wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/6_1-2017q1/gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2 \ 26 | -O /gcc.tar.bz2 27 | 28 | RUN tar xf /gcc.tar.bz2 29 | ENV PATH="/gcc-arm-none-eabi-6-2017-q1-update/bin:${PATH}" 30 | 31 | # Install rust 32 | RUN curl https://sh.rustup.rs -sSf > install_rust.sh 33 | RUN /bin/bash /install_rust.sh -y --default-toolchain nightly-2017-11-15 34 | ENV PATH="/root/.cargo/bin:${PATH}" 35 | 36 | # Use Xargo for cross platform building 37 | RUN cargo install xargo --vers 0.3.8 38 | 39 | # Use Bindgen as a binary to generate headers 40 | RUN cargo install bindgen --vers 0.31.3 41 | 42 | # Add the rust-src component so we can build `core` 43 | RUN rustup component add rust-src 44 | 45 | # Pull down the latest code/submodules 46 | RUN git clone --recursive https://github.com/jamesmunns/nrf52dk-sys --branch wez_pr 47 | 48 | # Move to the git repo 49 | WORKDIR /nrf52dk-sys 50 | 51 | CMD ["xargo", "build", "--example", "ble_app_template", "--quiet"] 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Anthony James Munns 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /SETUP.md: -------------------------------------------------------------------------------- 1 | # Installation Instructions 2 | 3 | The following will discuss in more detail what needs to be installed, and why. I suggest following these steps in this order. 4 | 5 | This guide will be written against a clean debian jessie installation. Steps should be similar for other linux distributions, as well as OSX. If these steps do not work for you, please let me know! If you found a fix or would like to add more specific steps for other operating systems (especially OSX or Windows), please open a pull request! 6 | 7 | ## 1. General Prerequisites 8 | 9 | These items are required for subsequent steps. 10 | 11 | ```bash 12 | apt-get update 13 | apt-get install -y wget curl build-essential git-core software-properties-common libc6-dev-i386 14 | ``` 15 | 16 | ## 2. Clang/LLVM 17 | 18 | Clang/LLVM is used by `bindgen` to generate the Rust bindings to C code. If your system already has it installed, or the package manager offers it, please make sure you have version 3.9. Other versions are not tested, and are unlikely to work. 19 | 20 | ```bash 21 | # Add the repository and the necessary keys 22 | add-apt-repository "deb http://apt.llvm.org/jessie/ llvm-toolchain-jessie-3.9 main" 23 | wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 24 | 25 | # Update repositories and install Clang/LLVM 26 | apt-get update 27 | apt-get install -y llvm-3.9-dev libclang-3.9-dev clang-3.9 28 | ``` 29 | 30 | ## 3. arm-none-eabi-gcc (and friends) 31 | 32 | The embedded flavor of GCC is necessary to compile the existing C code, link together the C and Rust code, as well as flash and debug our software. 33 | 34 | We will manually download and install GCC, as the the debian apt repos contain an older version which will not work for our purposes. 35 | 36 | ```bash 37 | # obtain installer 38 | wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/6_1-2017q1/gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2 39 | 40 | # unzip 41 | tar xf gcc-arm-none-eabi-6-2017-q1-update-linux.tar.bz2 42 | 43 | # Move to a sane location (you may pick a different location) 44 | sudo mv ./gcc-arm-none-eabi-6-2017-q1-update /opt 45 | 46 | # Add this GCC to your path (this path must match the above path) 47 | # NOTE: if you want to make this permanent, add this line to the 48 | # end of your rc file (example: ~/.zshrc or ~/.bashrc) 49 | export PATH=/opt/gcc-arm-none-eabi-6-2017-q1-update/bin 50 | ``` 51 | 52 | ## 4a. Clean install of Rust 53 | 54 | If you already have Rust installed, please skip ahead to step 4b. 55 | 56 | This step will install Rust and set the default toolchain to the nightly. 57 | 58 | Note: After performing this step, you may need to open a new terminal window for Rust to be added to your path. 59 | 60 | ```bash 61 | curl https://sh.rustup.rs -sSf > install_rust.sh 62 | /bin/bash /install_rust.sh -y --default-toolchain nightly-2017-06-12 63 | ``` 64 | 65 | ## 4b. Rustup already installed 66 | 67 | If you already have Rust installed via Rustup, you only need to install the correct toolchain version. 68 | 69 | ```bash 70 | rustup install nightly-2017-06-12 71 | rustup default nightly-2017-06-12 72 | ``` 73 | 74 | ## 5. Install Xargo and Bindgen 75 | 76 | Xargo makes compiling embedded crates easier. Bindgen automatically generates Rust bindings from C/C++ code. 77 | 78 | ```bash 79 | cargo install xargo --vers 0.3.8 80 | cargo install bindgen --vers 0.31.3 81 | ``` 82 | 83 | ## 6. Install Rust Core Source 84 | 85 | It is necessary to rebuild the `core` component of Rust for our target. Don't worry, `xargo` takes care of this, we just need to provide it Rust's source code. 86 | 87 | ```bash 88 | rustup component add rust-src 89 | ``` 90 | 91 | ## 7. Download the `nrf52dk-sys` repo, and build an example 92 | 93 | You made it! Now to verify the install went well, lets checkout the `nrf52dk-sys` crate, and build one of the examples. 94 | 95 | ```bash 96 | git clone --recursive https://github.com/jamesmunns/nrf52dk-sys 97 | cd nrf52dk-sys 98 | xargo build --example blinky 99 | ``` 100 | 101 | If everything went well, the last lines on your terminal should look like this: 102 | 103 | ```text 104 | Compiling nrf52dk-sys v0.1.1 (file:///nrf52dk-sys) 105 | Finished dev [unoptimized + debuginfo] target(s) in 25.48 secs 106 | ``` 107 | 108 | ## 8. Install nRF52 specific components 109 | 110 | The above steps verify you can compile your firmware. Before interacting with actual hardware, you will need to download the following components. Instructions for what to do with these are on the [Main README](./README.md). 111 | 112 | * [Nordic Download](http://www.nordicsemi.com/eng/nordic/Products/nRF52832/S132-SD-v4/58803) 113 | * [JLink Download](https://www.segger.com/downloads/jlink) 114 | -------------------------------------------------------------------------------- /bindings.h: -------------------------------------------------------------------------------- 1 | // Make sure that nrf doesn't think we are compiling for a PC 2 | #if defined(_WIN32) 3 | #undef _WIN32 4 | #endif 5 | #if defined(__unix) 6 | #undef __unix 7 | #endif 8 | #if defined(__APPLE__) 9 | #undef __APPLE__ 10 | #endif 11 | 12 | // Generate bindings for these files 13 | // These items were pulled from the template Makefile, in this order 14 | #include "app_error.h" 15 | #include "app_timer.h" 16 | #include "ble.h" 17 | #include "ble_advdata.h" 18 | #include "ble_advertising.h" 19 | #include "ble_conn_params.h" 20 | #include "ble_conn_state.h" 21 | #include "ble_hci.h" 22 | #include "ble_srv_common.h" 23 | #include "boards.h" 24 | #include "bsp_btn_ble.h" 25 | #include "fds.h" 26 | #include "fstorage.h" 27 | #include "id_manager.h" 28 | #include "nordic_common.h" 29 | #include "nrf.h" 30 | #include "nrf_ble_gatt.h" 31 | #include "nrf_gpio.h" 32 | #include "nrf_log.h" 33 | #include "nrf_log_ctrl.h" 34 | #include "peer_manager.h" 35 | #include "sensorsim.h" 36 | #include "softdevice_handler.h" 37 | 38 | // We have to go deeper 39 | #include "ble_stack_handler_types.h" 40 | 41 | #include "ble_advdata.h" 42 | #include "bsp.h" 43 | 44 | // More examples 45 | #include "nrf_delay.h" 46 | #include "shims.h" -------------------------------------------------------------------------------- /examples/blinky.rs: -------------------------------------------------------------------------------- 1 | // Based on nRF5-sdk/examples/peripheral/blinky/main.c 2 | #![no_std] 3 | #![no_main] 4 | #![feature(asm)] 5 | 6 | extern crate nrf52dk_sys; 7 | use nrf52dk_sys as nrf; 8 | 9 | #[no_mangle] 10 | pub unsafe extern "C" fn main() { 11 | nrf::bsp_board_leds_init(); 12 | 13 | loop { 14 | for led in 0..nrf::LEDS_NUMBER { 15 | nrf::bsp_board_led_invert(led); 16 | nrf::_nrf_delay_ms(500); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/logging.rs: -------------------------------------------------------------------------------- 1 | // Based on nRF5-sdk/examples/peripheral/blinky/main.c 2 | #![no_std] 3 | #![no_main] 4 | #![feature(asm)] 5 | 6 | #[macro_use] 7 | extern crate nrf52dk_sys; 8 | use nrf52dk_sys as nrf; 9 | 10 | #[no_mangle] 11 | pub unsafe extern "C" fn main() { 12 | nrf::bsp_board_leds_init(); 13 | nrf::check(nrf::nrf_log_init(None)).unwrap(); 14 | nrf::check(nrf::app_timer_init()).unwrap(); 15 | 16 | loop { 17 | for led in 0..nrf::LEDS_NUMBER { 18 | nrf::bsp_board_led_invert(led); 19 | nrf::_nrf_delay_ms(500); 20 | log_str("INFO: this is a test\r\n\x00"); 21 | nrf::sd_app_evt_wait(); 22 | process_log(); 23 | } 24 | } 25 | } 26 | 27 | unsafe fn process_log() { 28 | loop { 29 | nrf::sd_app_evt_wait(); 30 | let x = nrf::nrf_log_frontend_dequeue(); 31 | if !x { 32 | break; 33 | } 34 | } 35 | } 36 | 37 | unsafe fn log_str(foo: &'static str) { 38 | nrf::nrf_log_frontend_std_0(nrf::NRF_LOG_LEVEL_INFO as u8, foo.as_ptr()); 39 | } 40 | 41 | // NRF_LOG_PROCESS() 42 | // NRF_LOG_INTERNAL_PROCESS() 43 | // nrf_log_frontend_dequeue() 44 | 45 | // NRF_LOG_INTERNAL_FLUSH 46 | 47 | // NRF_LOG_INFO 48 | // NRF_LOG_INTERNAL_INFO( __VA_ARGS__) 49 | // LOG_INTERNAL(NRF_LOG_LEVEL_INFO, LOG_INFO_PREFIX, __VA_ARGS__); 50 | // LOG_INTERNAL_X(NUM_VA_ARGS_LESS_1( \ 51 | // __VA_ARGS__), type, prefix, __VA_ARGS__) 52 | // CONCAT_2(LOG_INTERNAL_, N) (__VA_ARGS__) 53 | // nrf_log_frontend_std_0(type, prefix str) 54 | -------------------------------------------------------------------------------- /extract-features.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import os 3 | import re 4 | import sys 5 | 6 | # Find all the possible features defined in sdk_config.h 7 | 8 | pattern = re.compile(r"#define\s+(\S+)_ENABLED\s+(\d)") 9 | 10 | features = {} 11 | 12 | with open("shims/sdk_config.h") as f: 13 | for line in f.readlines(): 14 | m = pattern.match(line) 15 | if m: 16 | feature = m.group(1) 17 | if feature.endswith("_LOG"): 18 | continue 19 | enabled = True if m.group(2) == "1" else False 20 | features[feature] = enabled 21 | 22 | # Some features aren't referenced by the cut down sdk_config.h 23 | # that we're including here, so emit entries for them now. 24 | features['NRF_LOG'] = False 25 | 26 | # Some features are things like TIMER0 and depend on TIMER. 27 | # To identify these deps, we find TIMER and then see if it 28 | # is the prefix of any others. If so, record the dep. 29 | feature_deps = {} 30 | for feature in features.keys(): 31 | for k in features.keys(): 32 | if k != feature and k.startswith(feature): 33 | feature_deps[k] = feature 34 | 35 | defaults = [] 36 | feature_names = sorted(features.keys()) 37 | for feature in feature_names: 38 | if features[feature]: 39 | defaults.append(feature) 40 | 41 | print("[features]") 42 | print("default = [%s]" % ','.join('"%s"' % f for f in defaults)) 43 | 44 | def deps(feature): 45 | if feature in feature_deps: 46 | return '"%s"' % feature_deps[feature] 47 | return "" 48 | 49 | for feature in feature_names: 50 | print("%s = [%s]" % (feature, deps(feature))) 51 | -------------------------------------------------------------------------------- /nRF5-sdk/components/ble/common/ble_date_time.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesmunns/nrf52dk-sys/13b2a30cb16949b414a3625dd7464326a2019018/nRF5-sdk/components/ble/common/ble_date_time.h -------------------------------------------------------------------------------- /nRF5-sdk/components/ble/common/ble_gatt_db.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /**@file 41 | * 42 | * @defgroup ble_sdk_lib_gatt_db GATT Database Service Structure 43 | * @{ 44 | * @ingroup ble_sdk_lib 45 | */ 46 | 47 | #ifndef BLE_GATT_DB_H__ 48 | #define BLE_GATT_DB_H__ 49 | 50 | #include 51 | #include "ble.h" 52 | #include "ble_gattc.h" 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | #define BLE_GATT_DB_MAX_CHARS 5 /**< The maximum number of characteristics present in a service record. */ 59 | 60 | /**@brief Structure for holding the characteristic and the handle of its CCCD present on a server. 61 | */ 62 | typedef struct 63 | { 64 | ble_gattc_char_t characteristic; /**< Structure containing information about the characteristic. */ 65 | uint16_t cccd_handle; /**< CCCD Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a CCCD is not present at the server. */ 66 | uint16_t ext_prop_handle; /**< Extended Properties Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if an Extended Properties descriptor is not present at the server. */ 67 | uint16_t user_desc_handle; /**< User Description Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a User Description descriptor is not present at the server. */ 68 | uint16_t report_ref_handle; /**< Report Reference Handle value for this characteristic. This will be set to BLE_GATT_HANDLE_INVALID if a Report Reference descriptor is not present at the server. */ 69 | } ble_gatt_db_char_t; 70 | 71 | /**@brief Structure for holding information about the service and the characteristics present on a 72 | * server. 73 | */ 74 | typedef struct 75 | { 76 | ble_uuid_t srv_uuid; /**< UUID of the service. */ 77 | uint8_t char_count; /**< Number of characteristics present in the service. */ 78 | ble_gattc_handle_range_t handle_range; /**< Service Handle Range. */ 79 | ble_gatt_db_char_t charateristics[BLE_GATT_DB_MAX_CHARS]; /**< Array of information related to the characteristics present in the service. This list can extend further than one. */ 80 | } ble_gatt_db_srv_t; 81 | 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* BLE_GATT_DB_H__ */ 88 | 89 | /** @} */ 90 | -------------------------------------------------------------------------------- /nRF5-sdk/components/ble/common/ble_sensor_location.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesmunns/nrf52dk-sys/13b2a30cb16949b414a3625dd7464326a2019018/nRF5-sdk/components/ble/common/ble_sensor_location.h -------------------------------------------------------------------------------- /nRF5-sdk/components/ble/common/ble_srv_common.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesmunns/nrf52dk-sys/13b2a30cb16949b414a3625dd7464326a2019018/nRF5-sdk/components/ble/common/ble_srv_common.c -------------------------------------------------------------------------------- /nRF5-sdk/components/ble/peer_manager/pm_mutex.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(PEER_MANAGER) 42 | #include "pm_mutex.h" 43 | 44 | #include 45 | #include 46 | #include "nrf_error.h" 47 | #include "app_util_platform.h" 48 | 49 | 50 | 51 | /**@brief Locks the mutex defined by the mask. 52 | * 53 | * @param p_mutex pointer to the mutex storage. 54 | * @param mutex_mask the mask identifying the mutex position. 55 | * 56 | * @retval true if the mutex could be locked. 57 | * @retval false if the mutex was already locked. 58 | */ 59 | static bool lock_by_mask(uint8_t * p_mutex, uint8_t mutex_mask) 60 | { 61 | bool success = false; 62 | 63 | if ( (*p_mutex & mutex_mask) == 0 ) 64 | { 65 | CRITICAL_REGION_ENTER(); 66 | if ( (*p_mutex & mutex_mask) == 0 ) 67 | { 68 | *p_mutex |= mutex_mask; 69 | 70 | success = true; 71 | } 72 | CRITICAL_REGION_EXIT(); 73 | } 74 | 75 | return ( success ); 76 | } 77 | 78 | 79 | void pm_mutex_init(uint8_t * p_mutex, uint16_t mutex_size) 80 | { 81 | if (p_mutex != NULL) 82 | { 83 | memset(&p_mutex[0], 0, MUTEX_STORAGE_SIZE(mutex_size)); 84 | } 85 | } 86 | 87 | 88 | bool pm_mutex_lock(uint8_t * p_mutex, uint16_t mutex_id) 89 | { 90 | if (p_mutex != NULL) 91 | { 92 | return ( lock_by_mask(&(p_mutex[mutex_id >> 3]), (1 << (mutex_id & 0x07))) ); 93 | } 94 | else 95 | { 96 | return false; 97 | } 98 | } 99 | 100 | 101 | void pm_mutex_unlock(uint8_t * p_mutex, uint16_t mutex_id) 102 | { 103 | uint8_t mutex_base = mutex_id >> 3; 104 | uint8_t mutex_mask = (1 << (mutex_id & 0x07)); 105 | 106 | if ((p_mutex != NULL) 107 | && (p_mutex[mutex_base] & mutex_mask)) 108 | { 109 | CRITICAL_REGION_ENTER(); 110 | p_mutex[mutex_base] &= ~mutex_mask; 111 | CRITICAL_REGION_EXIT(); 112 | } 113 | } 114 | 115 | 116 | uint16_t pm_mutex_lock_first_available(uint8_t * p_mutex, uint16_t mutex_size) 117 | { 118 | if (p_mutex != NULL) 119 | { 120 | for ( uint16_t i = 0; i < mutex_size; i++ ) 121 | { 122 | if ( lock_by_mask(&(p_mutex[i >> 3]), 1 << (i & 0x07)) ) 123 | { 124 | return ( i ); 125 | } 126 | } 127 | } 128 | 129 | return ( mutex_size ); 130 | } 131 | 132 | 133 | bool pm_mutex_lock_status_get(uint8_t * p_mutex, uint16_t mutex_id) 134 | { 135 | if (p_mutex != NULL) 136 | { 137 | return ( (p_mutex[mutex_id >> 3] & (1 << (mutex_id & 0x07))) ); 138 | } 139 | else 140 | { 141 | return true; 142 | } 143 | } 144 | #endif // NRF_MODULE_ENABLED(PEER_MANAGER) 145 | -------------------------------------------------------------------------------- /nRF5-sdk/components/ble/peer_manager/pm_mutex.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef MUTEX_H__ 41 | #define MUTEX_H__ 42 | 43 | 44 | #include 45 | #include 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /** 52 | * @cond NO_DOXYGEN 53 | * @defgroup pm_mutex Mutex 54 | * @ingroup peer_manager 55 | * @{ 56 | * @brief An internal module of @ref peer_manager. This module provides thread-safe mutexes. 57 | */ 58 | 59 | 60 | /**@brief Defines the storage size of a specified mutex group. 61 | * 62 | * @param number_of_mutexes the number of mutexes in the group. 63 | */ 64 | #define MUTEX_STORAGE_SIZE(number_of_mutexes) ((7 + (number_of_mutexes)) >> 3) 65 | 66 | 67 | /**@brief Initializes a mutex group. 68 | * 69 | * @param[in] p_mutex Pointer to the mutex group. See @ref MUTEX_STORAGE_SIZE(). 70 | * @param[in] mutex_size The size of the mutex group in number of mutexes. 71 | */ 72 | void pm_mutex_init(uint8_t * p_mutex, uint16_t mutex_size); 73 | 74 | 75 | /**@brief Locks the mutex specified by the bit id. 76 | * 77 | * @param[inout] p_mutex Pointer to the mutex group. 78 | * @param[in] mutex_bit_id The bit id of the mutex. 79 | * 80 | * @retval true if it was possible to lock the mutex. 81 | * @retval false otherwise. 82 | */ 83 | bool pm_mutex_lock(uint8_t * p_mutex, uint16_t mutex_bit_id); 84 | 85 | 86 | /**@brief Locks the first unlocked mutex within the mutex group. 87 | * 88 | * @param[in, out] p_mutex Pointer to the mutex group. 89 | * @param[in] mutex_size The size of the mutex group. 90 | * 91 | * @return The first unlocked mutex id in the group. 92 | * @retval group-size if there was no unlocked mutex available. 93 | */ 94 | uint16_t pm_mutex_lock_first_available(uint8_t * p_mutex, uint16_t mutex_size); 95 | 96 | 97 | /**@brief Unlocks the mutex specified by the bit id. 98 | * 99 | * @param[in, out] p_mutex Pointer to the mutex group. 100 | * @param[in] mutex_bit_id The bit id of the mutex. 101 | */ 102 | void pm_mutex_unlock(uint8_t * p_mutex, uint16_t mutex_bit_id); 103 | 104 | 105 | /**@brief Gets the locking status of the specified mutex. 106 | * 107 | * @param[in, out] p_mutex Pointer to the mutex group. 108 | * @param[in] mutex_bit_id The bit id of the mutex. 109 | * 110 | * @retval true if the mutex was locked. 111 | * @retval false otherwise. 112 | */ 113 | bool pm_mutex_lock_status_get(uint8_t * p_mutex, uint16_t mutex_bit_id); 114 | 115 | 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif // MUTEX_H__ 122 | 123 | /** @} 124 | * @endcond 125 | */ 126 | -------------------------------------------------------------------------------- /nRF5-sdk/components/device/nrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2010 - 2017, Nordic Semiconductor ASA 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form, except as embedded into a Nordic 14 | Semiconductor ASA integrated circuit in a product or a software update for 15 | such product, must reproduce the above copyright notice, this list of 16 | conditions and the following disclaimer in the documentation and/or other 17 | materials provided with the distribution. 18 | 19 | 3. Neither the name of Nordic Semiconductor ASA nor the names of its 20 | contributors may be used to endorse or promote products derived from this 21 | software without specific prior written permission. 22 | 23 | 4. This software, with or without modification, must only be used with a 24 | Nordic Semiconductor ASA integrated circuit. 25 | 26 | 5. Any software provided in binary form under this license must not be reverse 27 | engineered, decompiled, modified and/or disassembled. 28 | 29 | THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 30 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 31 | OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 | DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 33 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 35 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 38 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | 40 | */ 41 | 42 | #ifndef NRF_H 43 | #define NRF_H 44 | 45 | /* MDK version */ 46 | #define MDK_MAJOR_VERSION 8 47 | #define MDK_MINOR_VERSION 12 48 | #define MDK_MICRO_VERSION 0 49 | 50 | /* Redefine "old" too-generic name NRF52 to NRF52832_XXAA to keep backwards compatibility. */ 51 | #if defined (NRF52) 52 | #ifndef NRF52832_XXAA 53 | #define NRF52832_XXAA 54 | #endif 55 | #endif 56 | 57 | /* Define NRF52_SERIES for common use in nRF52 series devices. */ 58 | #if defined (NRF52832_XXAA) || defined (NRF52840_XXAA) 59 | #ifndef NRF52_SERIES 60 | #define NRF52_SERIES 61 | #endif 62 | #endif 63 | 64 | 65 | #if defined(_WIN32) 66 | /* Do not include nrf specific files when building for PC host */ 67 | #elif defined(__unix) 68 | /* Do not include nrf specific files when building for PC host */ 69 | #elif defined(__APPLE__) 70 | /* Do not include nrf specific files when building for PC host */ 71 | #else 72 | 73 | /* Device selection for device includes. */ 74 | #if defined (NRF51) 75 | #include "nrf51.h" 76 | #include "nrf51_bitfields.h" 77 | #include "nrf51_deprecated.h" 78 | #elif defined (NRF52840_XXAA) 79 | #include "nrf52840.h" 80 | #include "nrf52840_bitfields.h" 81 | #include "nrf51_to_nrf52840.h" 82 | #include "nrf52_to_nrf52840.h" 83 | #elif defined (NRF52832_XXAA) 84 | #include "nrf52.h" 85 | #include "nrf52_bitfields.h" 86 | #include "nrf51_to_nrf52.h" 87 | #include "nrf52_name_change.h" 88 | #else 89 | #error "Device must be defined. See nrf.h." 90 | #endif /* NRF51, NRF52832_XXAA, NRF52840_XXAA */ 91 | 92 | #include "compiler_abstraction.h" 93 | 94 | #endif /* _WIN32 || __unix || __APPLE__ */ 95 | 96 | #endif /* NRF_H */ 97 | 98 | -------------------------------------------------------------------------------- /nRF5-sdk/components/device/nrf52_name_change.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2010 - 2017, Nordic Semiconductor ASA 4 | 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form, except as embedded into a Nordic 14 | Semiconductor ASA integrated circuit in a product or a software update for 15 | such product, must reproduce the above copyright notice, this list of 16 | conditions and the following disclaimer in the documentation and/or other 17 | materials provided with the distribution. 18 | 19 | 3. Neither the name of Nordic Semiconductor ASA nor the names of its 20 | contributors may be used to endorse or promote products derived from this 21 | software without specific prior written permission. 22 | 23 | 4. This software, with or without modification, must only be used with a 24 | Nordic Semiconductor ASA integrated circuit. 25 | 26 | 5. Any software provided in binary form under this license must not be reverse 27 | engineered, decompiled, modified and/or disassembled. 28 | 29 | THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 30 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 31 | OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 32 | DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 33 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 34 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 35 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 38 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | 40 | */ 41 | 42 | #ifndef NRF52_NAME_CHANGE_H 43 | #define NRF52_NAME_CHANGE_H 44 | 45 | /*lint ++flb "Enter library region */ 46 | 47 | /* This file is given to prevent your SW from not compiling with the updates made to nrf52.h and 48 | * nrf52_bitfields.h. The macros defined in this file were available previously. Do not use these 49 | * macros on purpose. Use the ones defined in nrf52.h and nrf52_bitfields.h instead. 50 | */ 51 | 52 | /* I2S */ 53 | /* Several enumerations changed case. Adding old macros to keep compilation compatibility. */ 54 | #define I2S_ENABLE_ENABLE_DISABLE I2S_ENABLE_ENABLE_Disabled 55 | #define I2S_ENABLE_ENABLE_ENABLE I2S_ENABLE_ENABLE_Enabled 56 | #define I2S_CONFIG_MODE_MODE_MASTER I2S_CONFIG_MODE_MODE_Master 57 | #define I2S_CONFIG_MODE_MODE_SLAVE I2S_CONFIG_MODE_MODE_Slave 58 | #define I2S_CONFIG_RXEN_RXEN_DISABLE I2S_CONFIG_RXEN_RXEN_Disabled 59 | #define I2S_CONFIG_RXEN_RXEN_ENABLE I2S_CONFIG_RXEN_RXEN_Enabled 60 | #define I2S_CONFIG_TXEN_TXEN_DISABLE I2S_CONFIG_TXEN_TXEN_Disabled 61 | #define I2S_CONFIG_TXEN_TXEN_ENABLE I2S_CONFIG_TXEN_TXEN_Enabled 62 | #define I2S_CONFIG_MCKEN_MCKEN_DISABLE I2S_CONFIG_MCKEN_MCKEN_Disabled 63 | #define I2S_CONFIG_MCKEN_MCKEN_ENABLE I2S_CONFIG_MCKEN_MCKEN_Enabled 64 | #define I2S_CONFIG_SWIDTH_SWIDTH_8BIT I2S_CONFIG_SWIDTH_SWIDTH_8Bit 65 | #define I2S_CONFIG_SWIDTH_SWIDTH_16BIT I2S_CONFIG_SWIDTH_SWIDTH_16Bit 66 | #define I2S_CONFIG_SWIDTH_SWIDTH_24BIT I2S_CONFIG_SWIDTH_SWIDTH_24Bit 67 | #define I2S_CONFIG_ALIGN_ALIGN_LEFT I2S_CONFIG_ALIGN_ALIGN_Left 68 | #define I2S_CONFIG_ALIGN_ALIGN_RIGHT I2S_CONFIG_ALIGN_ALIGN_Right 69 | #define I2S_CONFIG_FORMAT_FORMAT_ALIGNED I2S_CONFIG_FORMAT_FORMAT_Aligned 70 | #define I2S_CONFIG_CHANNELS_CHANNELS_STEREO I2S_CONFIG_CHANNELS_CHANNELS_Stereo 71 | #define I2S_CONFIG_CHANNELS_CHANNELS_LEFT I2S_CONFIG_CHANNELS_CHANNELS_Left 72 | #define I2S_CONFIG_CHANNELS_CHANNELS_RIGHT I2S_CONFIG_CHANNELS_CHANNELS_Right 73 | 74 | /* LPCOMP */ 75 | /* Corrected typo in RESULT register. */ 76 | #define LPCOMP_RESULT_RESULT_Bellow LPCOMP_RESULT_RESULT_Below 77 | 78 | /*lint --flb "Leave library region" */ 79 | 80 | #endif /* NRF52_NAME_CHANGE_H */ 81 | 82 | -------------------------------------------------------------------------------- /nRF5-sdk/components/drivers_nrf/hal/nrf_ecb.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** 41 | * @file 42 | * @brief Implementation of AES ECB driver 43 | */ 44 | 45 | 46 | //lint -e438 47 | 48 | #include 49 | #include 50 | #include 51 | #include "nrf.h" 52 | #include "nrf_ecb.h" 53 | 54 | static uint8_t ecb_data[48]; ///< ECB data structure for RNG peripheral to access. 55 | static uint8_t* ecb_key; ///< Key: Starts at ecb_data 56 | static uint8_t* ecb_cleartext; ///< Cleartext: Starts at ecb_data + 16 bytes. 57 | static uint8_t* ecb_ciphertext; ///< Ciphertext: Starts at ecb_data + 32 bytes. 58 | 59 | bool nrf_ecb_init(void) 60 | { 61 | ecb_key = ecb_data; 62 | ecb_cleartext = ecb_data + 16; 63 | ecb_ciphertext = ecb_data + 32; 64 | 65 | NRF_ECB->ECBDATAPTR = (uint32_t)ecb_data; 66 | return true; 67 | } 68 | 69 | 70 | bool nrf_ecb_crypt(uint8_t * dest_buf, const uint8_t * src_buf) 71 | { 72 | uint32_t counter = 0x1000000; 73 | if (src_buf != ecb_cleartext) 74 | { 75 | memcpy(ecb_cleartext,src_buf,16); 76 | } 77 | NRF_ECB->EVENTS_ENDECB = 0; 78 | NRF_ECB->TASKS_STARTECB = 1; 79 | while (NRF_ECB->EVENTS_ENDECB == 0) 80 | { 81 | counter--; 82 | if (counter == 0) 83 | { 84 | return false; 85 | } 86 | } 87 | NRF_ECB->EVENTS_ENDECB = 0; 88 | if (dest_buf != ecb_ciphertext) 89 | { 90 | memcpy(dest_buf,ecb_ciphertext,16); 91 | } 92 | return true; 93 | } 94 | 95 | void nrf_ecb_set_key(const uint8_t * key) 96 | { 97 | memcpy(ecb_key,key,16); 98 | } 99 | 100 | 101 | -------------------------------------------------------------------------------- /nRF5-sdk/components/drivers_nrf/hal/nrf_ecb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** 41 | * @file 42 | * @brief ECB driver API. 43 | */ 44 | 45 | #ifndef NRF_ECB_H__ 46 | #define NRF_ECB_H__ 47 | 48 | /** 49 | * @defgroup nrf_ecb AES ECB encryption 50 | * @{ 51 | * @ingroup nrf_drivers 52 | * @brief Driver for the AES Electronic Code Book (ECB) peripheral. 53 | * 54 | * To encrypt data, the peripheral must first be powered on 55 | * using @ref nrf_ecb_init. Next, the key must be set using @ref nrf_ecb_set_key. 56 | */ 57 | 58 | #include 59 | 60 | #ifdef __cplusplus 61 | extern "C" { 62 | #endif 63 | 64 | /** 65 | * @brief Function for initializing and powering on the ECB peripheral. 66 | * 67 | * This function allocates memory for the ECBDATAPTR. 68 | * @retval true If initialization was successful. 69 | * @retval false If powering on failed. 70 | */ 71 | bool nrf_ecb_init(void); 72 | 73 | /** 74 | * @brief Function for encrypting 16-byte data using current key. 75 | * 76 | * This function avoids unnecessary copying of data if the parameters point to the 77 | * correct locations in the ECB data structure. 78 | * 79 | * @param dst Result of encryption, 16 bytes will be written. 80 | * @param src Source with 16-byte data to be encrypted. 81 | * 82 | * @retval true If the encryption operation completed. 83 | * @retval false If the encryption operation did not complete. 84 | */ 85 | bool nrf_ecb_crypt(uint8_t * dst, const uint8_t * src); 86 | 87 | /** 88 | * @brief Function for setting the key to be used for encryption. 89 | * 90 | * @param key Pointer to the key. 16 bytes will be read. 91 | */ 92 | void nrf_ecb_set_key(const uint8_t * key); 93 | 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif // NRF_ECB_H__ 100 | 101 | /** @} */ 102 | -------------------------------------------------------------------------------- /nRF5-sdk/components/drivers_nrf/hal/nrf_nvmc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** 41 | * @file 42 | * @brief NMVC driver API. 43 | */ 44 | 45 | #ifndef NRF_NVMC_H__ 46 | #define NRF_NVMC_H__ 47 | 48 | #include 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | 55 | /** 56 | * @defgroup nrf_nvmc Non-volatile memory controller 57 | * @{ 58 | * @ingroup nrf_drivers 59 | * @brief Driver for the NVMC peripheral. 60 | * 61 | * This driver allows writing to the non-volatile memory (NVM) regions 62 | * of the chip. In order to write to NVM the controller must be powered 63 | * on and the relevant page must be erased. 64 | * 65 | */ 66 | 67 | 68 | /** 69 | * @brief Erase a page in flash. This is required before writing to any 70 | * address in the page. 71 | * 72 | * @param address Start address of the page. 73 | */ 74 | void nrf_nvmc_page_erase(uint32_t address); 75 | 76 | 77 | /** 78 | * @brief Write a single byte to flash. 79 | * 80 | * The function reads the word containing the byte, and then 81 | * rewrites the entire word. 82 | * 83 | * @param address Address to write to. 84 | * @param value Value to write. 85 | */ 86 | void nrf_nvmc_write_byte(uint32_t address , uint8_t value); 87 | 88 | 89 | /** 90 | * @brief Write a 32-bit word to flash. 91 | * @param address Address to write to. 92 | * @param value Value to write. 93 | */ 94 | void nrf_nvmc_write_word(uint32_t address, uint32_t value); 95 | 96 | 97 | /** 98 | * @brief Write consecutive bytes to flash. 99 | * 100 | * @param address Address to write to. 101 | * @param src Pointer to data to copy from. 102 | * @param num_bytes Number of bytes in src to write. 103 | */ 104 | void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes); 105 | 106 | 107 | /** 108 | * @brief Write consecutive words to flash. 109 | * 110 | * @param address Address to write to. 111 | * @param src Pointer to data to copy from. 112 | * @param num_words Number of bytes in src to write. 113 | */ 114 | void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words); 115 | 116 | 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif // NRF_NVMC_H__ 123 | /** @} */ 124 | 125 | 126 | -------------------------------------------------------------------------------- /nRF5-sdk/components/drivers_nrf/hal/nrf_peripherals.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef NRF_PERIPHERALS_H 41 | #define NRF_PERIPHERALS_H 42 | 43 | /*lint ++flb "Enter library region */ 44 | 45 | #ifdef NRF51422 46 | #include "nrf51422_peripherals.h" 47 | #endif 48 | 49 | #ifdef NRF51802 50 | #include "nrf51802_peripherals.h" 51 | #endif 52 | 53 | #ifdef NRF51822 54 | #include "nrf51822_peripherals.h" 55 | #endif 56 | 57 | #ifdef NRF52832_XXAA 58 | #include "nrf52832_peripherals.h" 59 | #endif 60 | 61 | #ifdef NRF52840_XXAA 62 | #include "nrf52840_peripherals.h" 63 | #endif 64 | 65 | 66 | /*lint --flb "Leave library region" */ 67 | 68 | #endif /* NRF_PERIPHERALS_H */ 69 | 70 | -------------------------------------------------------------------------------- /nRF5-sdk/components/drivers_nrf/hal/nrf_saadc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** 41 | * @file 42 | * @brief SAADC HAL implementation 43 | */ 44 | #include "sdk_config.h" 45 | #if SAADC_ENABLED 46 | #include "nrf_saadc.h" 47 | 48 | void nrf_saadc_channel_init(uint8_t channel, nrf_saadc_channel_config_t const * const config) 49 | { 50 | NRF_SAADC->CH[channel].CONFIG = 51 | ((config->resistor_p << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk) 52 | | ((config->resistor_n << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk) 53 | | ((config->gain << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk) 54 | | ((config->reference << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk) 55 | | ((config->acq_time << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk) 56 | | ((config->mode << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk) 57 | | ((config->burst << SAADC_CH_CONFIG_BURST_Pos) & SAADC_CH_CONFIG_BURST_Msk); 58 | nrf_saadc_channel_input_set(channel, config->pin_p, config->pin_n); 59 | return; 60 | } 61 | #endif //SAADC_ENABLED 62 | 63 | -------------------------------------------------------------------------------- /nRF5-sdk/components/drivers_nrf/hal/nrf_temp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef NRF_TEMP_H__ 41 | #define NRF_TEMP_H__ 42 | 43 | #include "nrf.h" 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /** 50 | * @defgroup nrf_temperature TEMP (temperature) abstraction 51 | * @{ 52 | * @ingroup nrf_drivers temperature_example 53 | * @brief Temperature module init and read functions. 54 | * 55 | */ 56 | 57 | /**@cond NO_DOXYGEN */ 58 | #define MASK_SIGN (0x00000200UL) 59 | #define MASK_SIGN_EXTENSION (0xFFFFFC00UL) 60 | 61 | /** 62 | * @brief Function for preparing the temp module for temperature measurement. 63 | * 64 | * This function initializes the TEMP module and writes to the hidden configuration register. 65 | */ 66 | static __INLINE void nrf_temp_init(void) 67 | { 68 | /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */ 69 | *(uint32_t *) 0x4000C504 = 0; 70 | } 71 | 72 | /** 73 | * @brief Function for reading temperature measurement. 74 | * 75 | * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value. 76 | */ 77 | static __INLINE int32_t nrf_temp_read(void) 78 | { 79 | /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */ 80 | return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP); 81 | } 82 | /**@endcond */ 83 | 84 | /** @} */ 85 | 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/bsp/bsp_btn_ant.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /**@file 41 | * 42 | * @defgroup bsp_btn_ant BSP: ANT Button Module 43 | * @{ 44 | * @ingroup bsp 45 | * 46 | * @brief Module for controlling ANT behavior through button actions. 47 | * 48 | * @details The application must propagate ANT events to the ANT Button Module. 49 | * Based on these events, the ANT Button Module configures the Board Support Package 50 | * to generate BSP events for certain button actions. These BSP events should then be 51 | * handled by the application's BSP event handler. 52 | * 53 | */ 54 | 55 | #ifndef BSP_BTN_ANT_H__ 56 | #define BSP_BTN_ANT_H__ 57 | 58 | #include 59 | #include "ant_stack_handler_types.h" 60 | 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | 65 | /**@brief Function for initializing the ANT Button Module. 66 | * 67 | * Before calling this function, the BSP module must be initialized with buttons. 68 | * 69 | * @retval NRF_SUCCESS If initialization was successful. Otherwise, a propagated error code is 70 | * returned. 71 | */ 72 | uint32_t bsp_btn_ant_init(void); 73 | 74 | /**@brief Function for setting up wakeup buttons before going into sleep mode. 75 | * 76 | * @retval NRF_SUCCESS If the buttons were prepared successfully. Otherwise, a propagated error 77 | * code is returned. 78 | */ 79 | uint32_t bsp_btn_ant_sleep_mode_prepare(void); 80 | 81 | /**@brief Function for handling the application's ANT stack events. 82 | * 83 | * @details This function handles all events from the ANT stack that are of interest to this module. 84 | * 85 | * @param[in] p_ant_evt ANT stack event. 86 | */ 87 | void bsp_btn_ant_on_ant_evt(ant_evt_t * p_ant_evt); 88 | 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | 94 | #endif /* BSP_BTN_ANT_H__ */ 95 | 96 | /** @} */ 97 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/bsp/bsp_btn_ble.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /**@file 41 | * 42 | * @defgroup bsp_btn_ble BSP: BLE Button Module 43 | * @{ 44 | * @ingroup bsp 45 | * 46 | * @brief Module for controlling BLE behavior through button actions. 47 | * 48 | * @details The application must propagate BLE events to the BLE Button Module. 49 | * Based on these events, the BLE Button Module configures the Board Support Package 50 | * to generate BSP events for certain button actions. These BSP events should then be 51 | * handled by the application's BSP event handler. 52 | * 53 | */ 54 | 55 | #ifndef BSP_BTN_BLE_H__ 56 | #define BSP_BTN_BLE_H__ 57 | 58 | #include 59 | #include "ble.h" 60 | #include "bsp.h" 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | /**@brief BLE Button Module error handler type. */ 67 | typedef void (*bsp_btn_ble_error_handler_t) (uint32_t nrf_error); 68 | 69 | /**@brief Function for initializing the BLE Button Module. 70 | * 71 | * Before calling this function, the BSP module must be initialized with buttons. 72 | * 73 | * @param[out] error_handler Error handler to call in case of internal errors in BLE Button 74 | * Module. 75 | * @param[out] p_startup_bsp_evt If not a NULL pointer, the value is filled with an event 76 | * (or BSP_EVENT_NOTHING) derived from the buttons pressed on 77 | * startup. For example, if the bond delete wakeup button was pressed 78 | * to wake up the device, *p_startup_bsp_evt is set to 79 | * @ref BSP_EVENT_CLEAR_BONDING_DATA. 80 | * 81 | * @retval NRF_SUCCESS If initialization was successful. Otherwise, a propagated error code is 82 | * returned. 83 | */ 84 | uint32_t bsp_btn_ble_init(bsp_btn_ble_error_handler_t error_handler, bsp_event_t * p_startup_bsp_evt); 85 | 86 | /**@brief Function for setting up wakeup buttons before going into sleep mode. 87 | * 88 | * @retval NRF_SUCCESS If the buttons were prepared successfully. Otherwise, a propagated error 89 | * code is returned. 90 | */ 91 | uint32_t bsp_btn_ble_sleep_mode_prepare(void); 92 | 93 | /**@brief Function for handling the application's BLE stack events. 94 | * 95 | * @details This function handles all events from the BLE stack that are of interest to this module. 96 | * 97 | * @param[in] p_ble_evt BLE stack event. 98 | */ 99 | void bsp_btn_ble_on_ble_evt(ble_evt_t * p_ble_evt); 100 | 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* BSP_BTN_BLE_H__ */ 107 | 108 | /** @} */ 109 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/bsp/bsp_nfc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "bsp_nfc.h" 41 | #include "bsp.h" 42 | #include "nrf.h" 43 | #include "app_util_platform.h" 44 | 45 | #ifndef BSP_SIMPLE 46 | #define BTN_ACTION_SLEEP BSP_BUTTON_ACTION_RELEASE /**< Button action used to put the application into sleep mode. */ 47 | 48 | ret_code_t bsp_nfc_btn_init(uint32_t sleep_button) 49 | { 50 | uint32_t err_code = bsp_event_to_button_action_assign(sleep_button, 51 | BTN_ACTION_SLEEP, 52 | BSP_EVENT_SLEEP); 53 | return err_code; 54 | } 55 | 56 | ret_code_t bsp_nfc_btn_deinit(uint32_t sleep_button) 57 | { 58 | uint32_t err_code = bsp_event_to_button_action_assign(sleep_button, 59 | BTN_ACTION_SLEEP, 60 | BSP_EVENT_DEFAULT); 61 | return err_code; 62 | } 63 | 64 | ret_code_t bsp_nfc_sleep_mode_prepare(void) 65 | { 66 | #if defined(NFCT_PRESENT) 67 | // Check if peripheral is not used. 68 | CRITICAL_REGION_ENTER(); 69 | #ifdef NRF52832_XXAA 70 | if ((*(uint32_t *)0x40005410 & 0x07) == 0) 71 | #else 72 | if ((NRF_NFCT->NFCTAGSTATE & NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) 73 | == NFCT_NFCTAGSTATE_NFCTAGSTATE_Disabled) 74 | #endif // NRF52832_XXAA 75 | { 76 | NRF_NFCT->TASKS_SENSE = 1; 77 | } 78 | CRITICAL_REGION_EXIT(); 79 | return NRF_SUCCESS; 80 | #else 81 | return NRF_ERROR_NOT_SUPPORTED; 82 | #endif 83 | } 84 | #endif //BSP_SIMPLE 85 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/bsp/bsp_nfc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /**@file 41 | * 42 | * @defgroup bsp_nfc NFC BSP Module 43 | * @{ 44 | * @ingroup bsp 45 | * 46 | * @brief Module for setting the NFCT peripheral as a wakeup source. 47 | * 48 | * @details The application must notify this module before going into System OFF mode. 49 | * Based on this notification, the NFC BSP Module sets the NFCT peripheral as a wakeup source 50 | * through the Board Support Package. Additionally, any BSP Button can be configured to 51 | * generate BSP sleep events. This module is applicable only if NFCT is used exclusively for 52 | * wakeup. If NFCT is used for a different purpose, this module cannot be used. 53 | */ 54 | 55 | #ifndef BSP_NFC_H__ 56 | #define BSP_NFC_H__ 57 | 58 | #include 59 | #include "sdk_errors.h" 60 | 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | 65 | /**@brief Function for initializing the NFC Button Module. 66 | * 67 | * Before calling this function, the BSP module must be initialized with buttons. The chosen 68 | * button is used to generate @ref BSP_EVENT_SLEEP events. 69 | * 70 | * @param[in] sleep_button Button ID used to generate @ref BSP_EVENT_SLEEP event. 71 | * 72 | * @retval NRF_SUCCESS If initialization was successful. Otherwise, a propagated error 73 | * code is returned. 74 | */ 75 | ret_code_t bsp_nfc_btn_init(uint32_t sleep_button); 76 | 77 | /**@brief Function for deinitializing the NFC Button Module. 78 | * 79 | * Before calling this function, the BSP module must be initialized with buttons. The chosen 80 | * button is used to generate default @ref BSP_EVENT_DEFAULT events. 81 | * 82 | * @param[in] sleep_button Button ID used to restore default event generation. 83 | * 84 | * @retval NRF_SUCCESS If initialization was successful. Otherwise, a propagated error 85 | * code is returned. 86 | */ 87 | ret_code_t bsp_nfc_btn_deinit(uint32_t sleep_button); 88 | 89 | /**@brief Function for setting up NFCT peripheral as wake-up source. 90 | * 91 | * This function must be called before going into System OFF mode. 92 | * 93 | * @note This function is only applicable if NFCT is used exclusively for wakeup. 94 | * If NFCT is used for a different purpose, this function cannot be used. 95 | * 96 | * @retval NRF_SUCCESS If NFCT peripheral was prepared successfully. Otherwise, 97 | * a propagated error code is returned. 98 | */ 99 | ret_code_t bsp_nfc_sleep_mode_prepare(void); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* BSP_NFC_H__ */ 106 | 107 | /** @} */ 108 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/crc16/crc16.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(CRC16) 42 | #include "crc16.h" 43 | 44 | #include 45 | 46 | uint16_t crc16_compute(uint8_t const * p_data, uint32_t size, uint16_t const * p_crc) 47 | { 48 | uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc; 49 | 50 | for (uint32_t i = 0; i < size; i++) 51 | { 52 | crc = (uint8_t)(crc >> 8) | (crc << 8); 53 | crc ^= p_data[i]; 54 | crc ^= (uint8_t)(crc & 0xFF) >> 4; 55 | crc ^= (crc << 8) << 4; 56 | crc ^= ((crc & 0xFF) << 4) << 1; 57 | } 58 | 59 | return crc; 60 | } 61 | #endif //NRF_MODULE_ENABLED(CRC16) 62 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/crc16/crc16.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** @file 41 | * 42 | * @defgroup crc16 CRC16 compute 43 | * @{ 44 | * @ingroup hci_transport 45 | * 46 | * @brief This module implements CRC-16-CCITT (polynomial 0x1021) with 0xFFFF initial value. 47 | * The data can be passed in multiple blocks. 48 | */ 49 | 50 | #ifndef CRC16_H__ 51 | #define CRC16_H__ 52 | 53 | #include 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | /**@brief Function for calculating CRC-16 in blocks. 60 | * 61 | * Feed each consecutive data block into this function, along with the current value of p_crc as 62 | * returned by the previous call of this function. The first call of this function should pass NULL 63 | * as the initial value of the crc in p_crc. 64 | * 65 | * @param[in] p_data The input data block for computation. 66 | * @param[in] size The size of the input data block in bytes. 67 | * @param[in] p_crc The previous calculated CRC-16 value or NULL if first call. 68 | * 69 | * @return The updated CRC-16 value, based on the input supplied. 70 | */ 71 | uint16_t crc16_compute(uint8_t const * p_data, uint32_t size, uint16_t const * p_crc); 72 | 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif // CRC16_H__ 79 | 80 | /** @} */ 81 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/experimental_section_vars/nrf_section_iter.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(NRF_SECTION_ITER) 42 | 43 | #include "nrf_section_iter.h" 44 | 45 | #if !defined(__GNUC__) 46 | static void nrf_section_iter_item_set(nrf_section_iter_t * p_iter) 47 | { 48 | ASSERT(p_iter != NULL); 49 | ASSERT(p_iter->p_set != NULL); 50 | ASSERT(p_iter->p_section != NULL); 51 | while (true) 52 | { 53 | if (p_iter->p_section == p_iter->p_set->p_last) 54 | { 55 | // End of the section set. 56 | p_iter->p_item = NULL; 57 | return; 58 | } 59 | 60 | if (p_iter->p_section->p_start != p_iter->p_section->p_end) 61 | { 62 | // Not empty section. 63 | p_iter->p_item = p_iter->p_section->p_start; 64 | return; 65 | } 66 | 67 | // Next section. 68 | p_iter->p_section++; 69 | } 70 | } 71 | #endif 72 | 73 | void nrf_section_iter_init(nrf_section_iter_t * p_iter, nrf_section_set_t const * p_set) 74 | { 75 | ASSERT(p_iter != NULL); 76 | ASSERT(p_set != NULL); 77 | 78 | p_iter->p_set = p_set; 79 | 80 | #if defined(__GNUC__) 81 | p_iter->p_item = p_iter->p_set->section.p_start; 82 | if (p_iter->p_item == p_iter->p_set->section.p_end) 83 | { 84 | p_iter->p_item = NULL; 85 | } 86 | #else 87 | p_iter->p_section = p_set->p_first; 88 | nrf_section_iter_item_set(p_iter); 89 | #endif 90 | } 91 | 92 | void nrf_section_iter_next(nrf_section_iter_t * p_iter) 93 | { 94 | ASSERT(p_iter != NULL); 95 | ASSERT(p_iter->p_set != NULL); 96 | 97 | if (p_iter->p_item == NULL) 98 | { 99 | return; 100 | } 101 | 102 | p_iter->p_item = (void *)((size_t)(p_iter->p_item) + p_iter->p_set->item_size); 103 | 104 | #if defined(__GNUC__) 105 | if (p_iter->p_item == p_iter->p_set->section.p_end) 106 | { 107 | p_iter->p_item = NULL; 108 | } 109 | 110 | #else 111 | ASSERT(p_iter->p_section != NULL); 112 | // If current section ended? 113 | if (p_iter->p_item == p_iter->p_section->p_end) 114 | { 115 | p_iter->p_section++; 116 | nrf_section_iter_item_set(p_iter); 117 | } 118 | #endif 119 | } 120 | #endif // NRF_MODULE_ENABLED(NRF_SECTION_ITER) 121 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/fstorage/fstorage_nosd.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/hardfault.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef HARDFAULT_H__ 41 | #define HARDFAULT_H__ 42 | #include 43 | #include 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | /** 49 | * @defgroup hardfault_default HardFault exception 50 | * @{ 51 | * @brief Default HardFault exception implementation. 52 | * @ingroup app_common 53 | */ 54 | 55 | /** 56 | * @brief Contents of the stack. 57 | * 58 | * This structure is used to re-create the stack layout after a HardFault exception was raised. 59 | */ 60 | typedef struct HardFault_stack 61 | { 62 | uint32_t r0; ///< R0 register. 63 | uint32_t r1; ///< R1 register. 64 | uint32_t r2; ///< R2 register. 65 | uint32_t r3; ///< R3 register. 66 | uint32_t r12; ///< R12 register. 67 | uint32_t lr; ///< Link register. 68 | uint32_t pc; ///< Program counter. 69 | uint32_t psr; ///< Program status register. 70 | } HardFault_stack_t; 71 | 72 | /** 73 | * @brief Function for processing HardFault exceptions. 74 | * 75 | * An application that needs to process HardFault exceptions should provide an implementation of this function. 76 | * It will be called from the HardFault handler. 77 | * If no implementation is provided, the library uses a default one, which just restarts the MCU. 78 | * 79 | * @note If the DEBUG_NRF macro is defined, the software breakpoint is set just before the call 80 | * to this function. 81 | * 82 | * @param p_stack Pointer to the stack bottom. 83 | * This pointer might be NULL if the HardFault was called when the main stack was 84 | * the active stack and a stack overrun is detected. 85 | * In such a situation, the stack pointer is reinitialized to the default position, 86 | * and the stack content is lost. 87 | */ 88 | void HardFault_process(HardFault_stack_t * p_stack); 89 | 90 | /** @} */ 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* HARDFAULT_H__ */ 97 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/hardfault_implementation.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 42 | #include "hardfault.h" 43 | #include "nrf.h" 44 | #include "compiler_abstraction.h" 45 | #include "app_util_platform.h" 46 | #ifdef SOFTDEVICE_PRESENT 47 | #include "nrf_soc.h" 48 | #endif 49 | #define NRF_LOG_MODULE_NAME "HARDFAULT" 50 | #include "nrf_log.h" 51 | #include "nrf_log_ctrl.h" 52 | #if defined(DEBUG_NRF) 53 | /** 54 | * @brief Pointer to the last received stack pointer. 55 | * 56 | * This pointer is set in the debug version of the HardFault handler. 57 | * It helps to debug HardFault reasons. 58 | */ 59 | volatile HardFault_stack_t * HardFault_p_stack; 60 | #endif 61 | 62 | /*lint -save -e14 */ 63 | __WEAK void HardFault_process(HardFault_stack_t * p_stack) 64 | { 65 | // Restart the system by default 66 | NVIC_SystemReset(); 67 | } 68 | /*lint -restore */ 69 | 70 | void HardFault_c_handler(uint32_t * p_stack_address) 71 | { 72 | NRF_LOG_ERROR("Hardfault PC:%x\r\n", ((HardFault_stack_t *)p_stack_address)->pc); 73 | NRF_LOG_FINAL_FLUSH(); 74 | #if defined(DEBUG_NRF) 75 | HardFault_p_stack = (HardFault_stack_t *)p_stack_address; 76 | (void)HardFault_p_stack; 77 | 78 | // Debugger detection is only possible on NRF52 (Cortex-M4), on NRF51 79 | // (Cortex-M0) the processor has no access to CoreDebug registers. 80 | #if __CORTEX_M == 0x04 81 | // C_DEBUGEN == 1 -> Debugger Connected 82 | if (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) 83 | { 84 | /* Generate breakpoint if debugger is connected */ 85 | NRF_BREAKPOINT; 86 | } 87 | #endif // __CORTEX_M == 0x04 88 | #endif // DEBUG_NRF 89 | HardFault_process((HardFault_stack_t *)p_stack_address); 90 | } 91 | #endif //NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 92 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/nrf51/handler/hardfault_handler_gcc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 42 | #include 43 | #include "compiler_abstraction.h" 44 | 45 | void HardFault_Handler(void) __attribute__(( naked )); 46 | 47 | void HardFault_Handler(void) 48 | { 49 | __ASM volatile( 50 | " .syntax unified \n" 51 | 52 | " ldr r0, =0xFFFFFFFD \n" 53 | " cmp r0, lr \n" 54 | " bne HardFault_Handler_ChooseMSP \n" 55 | /* Reading PSP into R0 */ 56 | " mrs r0, PSP \n" 57 | " b HardFault_Handler_Continue \n" 58 | "HardFault_Handler_ChooseMSP: \n" 59 | /* Reading MSP into R0 */ 60 | " mrs r0, MSP \n" 61 | /* ----------------------------------------------------------------- 62 | * If we have selected MSP check if we may use stack safetly. 63 | * If not - reset the stack to the initial value. */ 64 | " ldr r1, =__StackTop \n" 65 | " ldr r2, =__StackLimit \n" 66 | 67 | /* MSP is in the range of the stack area */ 68 | " cmp r0, r1 \n" 69 | " bhi HardFault_MoveSP \n" 70 | " cmp r0, r2 \n" 71 | " bhi HardFault_Handler_Continue \n" 72 | /* ----------------------------------------------------------------- */ 73 | "HardFault_MoveSP: \n" 74 | " mov SP, r1 \n" 75 | " movs r0, #0 \n" 76 | 77 | "HardFault_Handler_Continue: \n" 78 | " ldr r3, =HardFault_c_handler \n" 79 | " bx r3 \n" 80 | 81 | " .align \n" 82 | ); 83 | } 84 | #endif //NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 85 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/nrf51/handler/hardfault_handler_iar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 42 | #include 43 | #include "compiler_abstraction.h" 44 | 45 | #pragma section = "CSTACK" 46 | extern void HardFault_c_handler( uint32_t * ); 47 | 48 | __stackless void HardFault_Handler(void); 49 | 50 | __stackless void HardFault_Handler(void) 51 | { 52 | __ASM volatile( 53 | " ldr r0, 100f \n" 54 | " cmp r0, lr \n" 55 | " bne 1f \n" 56 | /* Reading PSP into R0 */ 57 | " mrs r0, PSP \n" 58 | " b 3f \n" 59 | "1: \n" 60 | /* Reading MSP into R0 */ 61 | " mrs r0, MSP \n" 62 | /* ----------------------------------------------------------------- 63 | * If we have selected MSP check if we may use stack safetly. 64 | * If not - reset the stack to the initial value. */ 65 | " ldr r1, 101f \n" 66 | " ldr r2, 102f \n" 67 | 68 | /* MSP is in the range of the stack area */ 69 | " cmp r0, r1 \n" 70 | " bhi 2f \n" 71 | " cmp r0, r2 \n" 72 | " bhi 3f \n" 73 | /* ----------------------------------------------------------------- */ 74 | "2: \n" 75 | " mov SP, r1 \n" 76 | " movs r0, #0 \n" 77 | 78 | "3: \n" 79 | " ldr r3, 103f \n" 80 | " bx r3 \n" 81 | 82 | "100: \n" 83 | " DC32 0xFFFFFFFD \n" 84 | "101: \n" 85 | " DC32 %c0 \n" 86 | "102: \n" 87 | " DC32 %c1 \n" 88 | "103: \n" 89 | " DC32 %c2 \n" 90 | : /* Outputs */ 91 | : /* Inputs */ 92 | "i"(__section_end("CSTACK")), 93 | "i"(__section_begin("CSTACK")), 94 | "i"(&HardFault_c_handler) 95 | ); 96 | } 97 | #endif //NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 98 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/nrf51/handler/hardfault_handler_keil.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 42 | #include 43 | #include "compiler_abstraction.h" 44 | 45 | 46 | //lint -save -e27 47 | 48 | __ASM void HardFault_Handler(void) 49 | { 50 | PRESERVE8 51 | EXTERN HardFault_c_handler 52 | EXTERN |STACK$$Base| 53 | EXTERN |STACK$$Limit| 54 | 55 | ldr r0, =0xFFFFFFFD 56 | cmp r0, lr 57 | bne HardFault_Handler_ChooseMSP 58 | /* Reading PSP into R0 */ 59 | mrs r0, PSP 60 | b HardFault_Handler_Continue 61 | HardFault_Handler_ChooseMSP 62 | /* Reading MSP into R0 */ 63 | mrs r0, MSP 64 | /* ----------------------------------------------------------------- 65 | * If we have selected MSP, check if we may use stack safely. 66 | * If not - reset the stack to the initial value. */ 67 | ldr r1, =|STACK$$Limit| 68 | ldr r2, =|STACK$$Base| 69 | 70 | /* MSP is in the range of the stack area */ 71 | cmp r0, r1 72 | bhi HardFault_MoveSP 73 | cmp r0, r2 74 | bhi HardFault_Handler_Continue 75 | /* ----------------------------------------------------------------- */ 76 | HardFault_MoveSP 77 | mov SP, r1 78 | movs r0, #0 79 | 80 | HardFault_Handler_Continue 81 | ldr r3, =HardFault_c_handler 82 | bx r3 83 | 84 | ALIGN 85 | } 86 | 87 | //lint -restore 88 | #endif //NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 89 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 42 | #include 43 | #include "compiler_abstraction.h" 44 | 45 | void HardFault_Handler(void) __attribute__(( naked )); 46 | 47 | void HardFault_Handler(void) 48 | { 49 | __ASM volatile( 50 | " ldr r3, =HardFault_c_handler \n" 51 | " tst lr, #4 \n" 52 | 53 | /* PSP is quite simple and does not require additional handler */ 54 | " itt ne \n" 55 | " mrsne r0, psp \n" 56 | /* Jump to the handler, do not store LR - returning from handler just exits exception */ 57 | " bxne r3 \n" 58 | 59 | /* Processing MSP requires stack checking */ 60 | " mrs r0, msp \n" 61 | 62 | " ldr r1, =__StackTop \n" 63 | " ldr r2, =__StackLimit \n" 64 | 65 | /* MSP is in the range of the stack area */ 66 | " cmp r0, r1 \n" 67 | " bhi HardFault_MoveSP \n" 68 | " cmp r0, r2 \n" 69 | " bhi HardFault_Handler_Continue \n" 70 | 71 | "HardFault_MoveSP: \n" 72 | " mov sp, r1 \n" 73 | " mov r0, #0 \n" 74 | 75 | "HardFault_Handler_Continue: \n" 76 | " bx r3 \n" 77 | 78 | " .align \n" 79 | ); 80 | } 81 | #endif //NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 82 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/nrf52/handler/hardfault_handler_iar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 42 | #include 43 | #include "compiler_abstraction.h" 44 | 45 | #pragma section = "CSTACK" 46 | extern void HardFault_c_handler( uint32_t * ); 47 | 48 | __stackless void HardFault_Handler(void); 49 | 50 | __stackless void HardFault_Handler(void) 51 | { 52 | __ASM volatile( 53 | " ldr.n r3, 103f \n" 54 | " tst lr, #4 \n" 55 | 56 | /* PSP is quite simple and does not require additional handler */ 57 | " itt ne \n" 58 | " mrsne r0, psp \n" 59 | /* Jump to the handler, do not store LR - returning from handler just exits exception */ 60 | " bxne r3 \n" 61 | 62 | /* Processing MSP requires stack checking */ 63 | " mrs r0, msp \n" 64 | 65 | " ldr.n r1, 101f \n" 66 | " ldr.n r2, 102f \n" 67 | 68 | /* MSP is in the range of the stack area */ 69 | " cmp r0, r1 \n" 70 | " bhi.n 1f \n" 71 | " cmp r0, r2 \n" 72 | " bhi.n 2f \n" 73 | 74 | "1: \n" 75 | " mov sp, r1 \n" 76 | " mov r0, #0 \n" 77 | 78 | "2: \n" 79 | " bx r3 \n" 80 | /* Data alignment if required */ 81 | " nop \n" 82 | 83 | "101: \n" 84 | " DC32 %c0 \n" 85 | "102: \n" 86 | " DC32 %c1 \n" 87 | "103: \n" 88 | " DC32 %c2 \n" 89 | : /* Outputs */ 90 | : /* Inputs */ 91 | "i"(__section_end("CSTACK")), 92 | "i"(__section_begin("CSTACK")), 93 | "i"(&HardFault_c_handler) 94 | ); 95 | } 96 | #endif //NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 97 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/hardfault/nrf52/handler/hardfault_handler_keil.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sdk_common.h" 41 | #if NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 42 | #include 43 | #include "compiler_abstraction.h" 44 | 45 | 46 | //lint -save -e27 47 | 48 | __ASM void HardFault_Handler(void) 49 | { 50 | PRESERVE8 51 | EXTERN HardFault_c_handler 52 | EXTERN |STACK$$Base| 53 | EXTERN |STACK$$Limit| 54 | 55 | ldr r3, =HardFault_c_handler 56 | tst lr, #4 57 | 58 | /* PSP is quite simple and does not require additional handler */ 59 | itt ne 60 | mrsne r0, psp 61 | /* Jump to the handler, do not store LR - returning from handler just exits exception */ 62 | bxne r3 63 | 64 | /* Processing MSP requires stack checking */ 65 | mrs r0, msp 66 | 67 | ldr r1, =|STACK$$Limit| 68 | ldr r2, =|STACK$$Base| 69 | 70 | /* MSP is in the range of the stack area */ 71 | cmp r0, r1 72 | bhi HardFault_MoveSP 73 | cmp r0, r2 74 | bhi HardFault_Handler_Continue 75 | 76 | HardFault_MoveSP 77 | mov sp, r1 78 | mov r0, #0 79 | 80 | HardFault_Handler_Continue 81 | bx r3 82 | 83 | ALIGN 84 | } 85 | 86 | //lint -restore 87 | #endif //NRF_MODULE_ENABLED(HARDFAULT_HANDLER) 88 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/log/nrf_log_backend.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /**@file 41 | * @addtogroup nrf_log Logger module 42 | * @ingroup app_common 43 | * 44 | * @defgroup nrf_log_backend Backend of nrf_log 45 | * @{ 46 | * @ingroup nrf_log 47 | * @brief The nrf_log backend interface. 48 | */ 49 | 50 | 51 | #ifndef NRF_LOG_BACKEND_H__ 52 | #define NRF_LOG_BACKEND_H__ 53 | 54 | #include "nrf_log_ctrl.h" 55 | #include "sdk_errors.h" 56 | #include 57 | 58 | /** 59 | * @brief Function for initializing the logger backend. 60 | * 61 | * param blocking Set true if handler functions should block until completion. 62 | * 63 | * @return NRF_SUCCESS after successful initialization, error code otherwise. 64 | */ 65 | ret_code_t nrf_log_backend_init(bool blocking); 66 | 67 | /** 68 | * @brief Function for returning a pointer to a function for handling standard 69 | * log entries (@ref NRF_LOG_ERROR, etc.). 70 | * 71 | * @return Pointer to a handler. 72 | */ 73 | nrf_log_std_handler_t nrf_log_backend_std_handler_get(void); 74 | 75 | /** 76 | * @brief Function for returning a pointer to a function for handling 77 | * hexdumps (@ref NRF_LOG_HEXDUMP_ERROR, etc.). 78 | * 79 | * @return Pointer to a handler. 80 | */ 81 | nrf_log_hexdump_handler_t nrf_log_backend_hexdump_handler_get(void); 82 | 83 | /** 84 | * @brief Function for blocking reading of a byte from the backend. 85 | * 86 | * @return Byte. 87 | */ 88 | uint8_t nrf_log_backend_getchar(void); 89 | #endif // NRF_LOG_BACKEND_H__ 90 | /** @} */ 91 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/log/src/nrf_log_ctrl_internal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef NRF_LOG_CTRL_INTERNAL_H 41 | #define NRF_LOG_CTRL_INTERNAL_H 42 | /** 43 | * @cond (NODOX) 44 | * @defgroup nrf_log_ctrl_internal Auxiliary internal types declarations 45 | * @{ 46 | * @internal 47 | */ 48 | 49 | #include "sdk_common.h" 50 | #if NRF_MODULE_ENABLED(NRF_LOG) 51 | #include "app_util_platform.h" 52 | 53 | #define NRF_LOG_INTERNAL_INIT(timestamp_func) \ 54 | nrf_log_init(timestamp_func) 55 | 56 | #if (NRF_LOG_DEFERRED == 0) 57 | #define NRF_LOG_INTERNAL_PROCESS() false 58 | #define NRF_LOG_INTERNAL_FLUSH() 59 | #define NRF_LOG_INTERNAL_FINAL_FLUSH() 60 | #else 61 | #define NRF_LOG_INTERNAL_PROCESS() nrf_log_frontend_dequeue() 62 | #define NRF_LOG_INTERNAL_FLUSH() \ 63 | do { \ 64 | while (NRF_LOG_INTERNAL_PROCESS()); \ 65 | } while(0) 66 | 67 | #if NRF_LOG_BACKEND_SERIAL_USES_RTT 68 | #define NRF_LOG_INTERNAL_BACKEND_FINAL NRF_BREAKPOINT_COND 69 | #else 70 | #define NRF_LOG_INTERNAL_BACKEND_FINAL 71 | #endif 72 | 73 | #define NRF_LOG_INTERNAL_FINAL_FLUSH() \ 74 | do { \ 75 | (void)nrf_log_blocking_backend_set(); \ 76 | NRF_LOG_INTERNAL_FLUSH(); \ 77 | NRF_LOG_INTERNAL_BACKEND_FINAL; \ 78 | } while(0) 79 | 80 | #endif 81 | 82 | #define NRF_LOG_INTERNAL_HANDLERS_SET(default_handler, bytes_handler) \ 83 | nrf_log_handlers_set(default_handler, bytes_handler) 84 | 85 | #else // NRF_MODULE_ENABLED(NRF_LOG) 86 | #define NRF_LOG_INTERNAL_PROCESS() false 87 | #define NRF_LOG_INTERNAL_FLUSH() 88 | #define NRF_LOG_INTERNAL_INIT(timestamp_func) NRF_SUCCESS 89 | #define NRF_LOG_INTERNAL_HANDLERS_SET(default_handler, bytes_handler) \ 90 | UNUSED_PARAMETER(default_handler); UNUSED_PARAMETER(bytes_handler) 91 | #define NRF_LOG_INTERNAL_FINAL_FLUSH() 92 | #endif // NRF_MODULE_ENABLED(NRF_LOG) 93 | 94 | /** @} 95 | * @endcond 96 | */ 97 | #endif // NRF_LOG_CTRL_INTERNAL_H 98 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/sensorsim/sensorsim.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2012 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "sensorsim.h" 41 | 42 | 43 | void sensorsim_init(sensorsim_state_t * p_state, 44 | const sensorsim_cfg_t * p_cfg) 45 | { 46 | if (p_cfg->start_at_max) 47 | { 48 | p_state->current_val = p_cfg->max; 49 | p_state->is_increasing = false; 50 | } 51 | else 52 | { 53 | p_state->current_val = p_cfg->min; 54 | p_state->is_increasing = true; 55 | } 56 | } 57 | 58 | 59 | uint32_t sensorsim_measure(sensorsim_state_t * p_state, 60 | const sensorsim_cfg_t * p_cfg) 61 | { 62 | if (p_state->is_increasing) 63 | { 64 | sensorsim_increment(p_state, p_cfg); 65 | } 66 | else 67 | { 68 | sensorsim_decrement(p_state, p_cfg); 69 | } 70 | return p_state->current_val; 71 | } 72 | 73 | void sensorsim_increment(sensorsim_state_t * p_state, 74 | const sensorsim_cfg_t * p_cfg) 75 | { 76 | if (p_cfg->max - p_state->current_val > p_cfg->incr) 77 | { 78 | p_state->current_val += p_cfg->incr; 79 | } 80 | else 81 | { 82 | p_state->current_val = p_cfg->max; 83 | p_state->is_increasing = false; 84 | } 85 | } 86 | 87 | 88 | void sensorsim_decrement(sensorsim_state_t * p_state, 89 | const sensorsim_cfg_t * p_cfg) 90 | { 91 | if (p_state->current_val - p_cfg->min > p_cfg->incr) 92 | { 93 | p_state->current_val -= p_cfg->incr; 94 | } 95 | else 96 | { 97 | p_state->current_val = p_cfg->min; 98 | p_state->is_increasing = true; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/strerror/nrf_strerror.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | 41 | /** 42 | * @defgroup nrf_strerror Error code to string converter 43 | * @ingroup app_common 44 | * 45 | * @brief Module for converting error code into a printable string. 46 | * @{ 47 | */ 48 | #ifndef NRF_STRERROR_H__ 49 | #define NRF_STRERROR_H__ 50 | 51 | #include "sdk_errors.h" 52 | 53 | /** 54 | * @brief Function for getting a printable error string. 55 | * 56 | * @param code Error code to convert. 57 | * 58 | * @note This function cannot fail. 59 | * For the function that may fail with error translation, see @ref nrf_strerror_find. 60 | * 61 | * @return Pointer to the printable string. 62 | * If the string is not found, 63 | * it returns a simple string that says that the error is unknown. 64 | */ 65 | char const * nrf_strerror_get(ret_code_t code); 66 | 67 | /** 68 | * @brief Function for finding a printable error string. 69 | * 70 | * This function gets the error string in the same way as @ref nrf_strerror_get, 71 | * but if the string is not found, it returns NULL. 72 | * 73 | * @param code Error code to convert. 74 | * @return Pointer to the printable string. 75 | * If the string is not found, NULL is returned. 76 | */ 77 | char const * nrf_strerror_find(ret_code_t code); 78 | 79 | /** @} */ 80 | 81 | #endif /* NRF_STRERROR_H__ */ 82 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/util/app_error_weak.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "app_error.h" 41 | 42 | //#define NRF_LOG_MODULE_NAME "APP_ERROR" 43 | #include "nrf_log.h" 44 | #include "nrf_log_ctrl.h" 45 | /*lint -save -e14 */ 46 | 47 | /** 48 | * Function is implemented as weak so that it can be overwritten by custom application error handler 49 | * when needed. 50 | */ 51 | __WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info) 52 | { 53 | NRF_LOG_ERROR("Fatal\r\n"); 54 | NRF_LOG_FINAL_FLUSH(); 55 | // On assert, the system can only recover with a reset. 56 | #ifndef DEBUG 57 | NRF_LOG_INFO("Hit weak handler\r\n"); 58 | NVIC_SystemReset(); 59 | #else 60 | app_error_save_and_stop(id, pc, info); 61 | #endif // DEBUG 62 | } 63 | 64 | /*lint -restore */ 65 | 66 | 67 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/util/app_error_weak.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef APP_ERROR_WEAK_H__ 41 | #define APP_ERROR_WEAK_H__ 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /** @file 48 | * 49 | * @defgroup app_error Common application error handler 50 | * @{ 51 | * @ingroup app_common 52 | * 53 | * @brief Common application error handler. 54 | */ 55 | 56 | /**@brief Callback function for errors, asserts, and faults. 57 | * 58 | * @details This function is called every time an error is raised in app_error, nrf_assert, or 59 | * in the SoftDevice. Information about the error can be found in the @p info 60 | * parameter. 61 | * 62 | * See also @ref nrf_fault_handler_t for more details. 63 | * 64 | * @note The function is implemented as weak so that it can be redefined by a custom error 65 | * handler when needed. 66 | * 67 | * @param[in] id Fault identifier. See @ref NRF_FAULT_IDS. 68 | * @param[in] pc The program counter of the instruction that triggered the fault, or 0 if 69 | * unavailable. 70 | * @param[in] info Optional additional information regarding the fault. The value of the @p id 71 | * parameter dictates how to interpret this parameter. Refer to the documentation 72 | * for each fault identifier (@ref NRF_FAULT_IDS and @ref APP_ERROR_FAULT_IDS) for 73 | * details about interpreting @p info. 74 | */ 75 | void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info); 76 | 77 | 78 | /** @} */ 79 | 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | #endif // APP_ERROR_WEAK_H__ 86 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/util/app_util_platform.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "app_util_platform.h" 41 | 42 | #ifdef SOFTDEVICE_PRESENT 43 | /* Global nvic state instance, required by nrf_nvic.h */ 44 | nrf_nvic_state_t nrf_nvic_state; 45 | #endif 46 | 47 | static uint32_t m_in_critical_region = 0; 48 | 49 | void app_util_disable_irq(void) 50 | { 51 | __disable_irq(); 52 | m_in_critical_region++; 53 | } 54 | 55 | void app_util_enable_irq(void) 56 | { 57 | m_in_critical_region--; 58 | if (m_in_critical_region == 0) 59 | { 60 | __enable_irq(); 61 | } 62 | } 63 | 64 | void app_util_critical_region_enter(uint8_t *p_nested) 65 | { 66 | #if __CORTEX_M == (0x04U) 67 | ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get()) 68 | #endif 69 | 70 | #if defined(SOFTDEVICE_PRESENT) 71 | /* return value can be safely ignored */ 72 | (void) sd_nvic_critical_region_enter(p_nested); 73 | #else 74 | app_util_disable_irq(); 75 | #endif 76 | } 77 | 78 | void app_util_critical_region_exit(uint8_t nested) 79 | { 80 | #if __CORTEX_M == (0x04U) 81 | ASSERT(APP_LEVEL_PRIVILEGED == privilege_level_get()) 82 | #endif 83 | 84 | #if defined(SOFTDEVICE_PRESENT) 85 | /* return value can be safely ignored */ 86 | (void) sd_nvic_critical_region_exit(nested); 87 | #else 88 | app_util_enable_irq(); 89 | #endif 90 | } 91 | 92 | 93 | uint8_t privilege_level_get(void) 94 | { 95 | #if __CORTEX_M == (0x00U) || defined(_WIN32) || defined(__unix) || defined(__APPLE__) 96 | /* the Cortex-M0 has no concept of privilege */ 97 | return APP_LEVEL_PRIVILEGED; 98 | #elif __CORTEX_M == (0x04U) 99 | uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ; 100 | if (0 == isr_vector_num) 101 | { 102 | /* Thread Mode, check nPRIV */ 103 | int32_t control = __get_CONTROL(); 104 | return control & CONTROL_nPRIV_Msk ? APP_LEVEL_UNPRIVILEGED : APP_LEVEL_PRIVILEGED; 105 | } 106 | else 107 | { 108 | /* Handler Mode, always privileged */ 109 | return APP_LEVEL_PRIVILEGED; 110 | } 111 | #endif 112 | } 113 | 114 | 115 | uint8_t current_int_priority_get(void) 116 | { 117 | uint32_t isr_vector_num = __get_IPSR() & IPSR_ISR_Msk ; 118 | if (isr_vector_num > 0) 119 | { 120 | int32_t irq_type = ((int32_t)isr_vector_num - EXTERNAL_INT_VECTOR_OFFSET); 121 | return (NVIC_GetPriority((IRQn_Type)irq_type) & 0xFF); 122 | } 123 | else 124 | { 125 | return APP_IRQ_PRIORITY_THREAD; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/util/nrf_assert.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2006 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "nrf_assert.h" 41 | #include "app_error.h" 42 | #include "nordic_common.h" 43 | 44 | __WEAK void assert_nrf_callback(uint16_t line_num, const uint8_t * file_name) 45 | { 46 | assert_info_t assert_info = 47 | { 48 | .line_num = line_num, 49 | .p_file_name = file_name, 50 | }; 51 | app_error_fault_handler(NRF_FAULT_ID_SDK_ASSERT, 0, (uint32_t)(&assert_info)); 52 | 53 | UNUSED_VARIABLE(assert_info); 54 | } 55 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/util/sdk_common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** @cond */ 41 | /**@file 42 | * 43 | * @ingroup experimental_api 44 | * @defgroup sdk_common SDK Common Header 45 | * @brief All common headers needed for SDK examples will be included here so that application 46 | * developer does not have to include headers on him/herself. 47 | * @{ 48 | */ 49 | 50 | #ifndef SDK_COMMON_H__ 51 | #define SDK_COMMON_H__ 52 | 53 | #include 54 | #include 55 | #include 56 | #include "sdk_config.h" 57 | #include "nordic_common.h" 58 | #include "compiler_abstraction.h" 59 | #include "sdk_os.h" 60 | #include "sdk_errors.h" 61 | #include "app_util.h" 62 | #include "sdk_macros.h" 63 | 64 | #ifdef __cplusplus 65 | extern "C" { 66 | #endif 67 | 68 | 69 | /** @} */ 70 | /** @endcond */ 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif // SDK_COMMON_H__ 77 | 78 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/util/sdk_os.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2013 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** @cond */ 41 | /**@file 42 | * 43 | * @defgroup sdk_os SDK OS Abstraction 44 | * @ingroup experimental_api 45 | * @details In order to made SDK modules independent of use of an embedded OS, and permit 46 | * application with varied task architecture, SDK abstracts the OS specific 47 | * elements here in order to make all other modules agnostic to the OS or task 48 | * architecture. 49 | * @{ 50 | */ 51 | 52 | #ifndef SDK_OS_H__ 53 | #define SDK_OS_H__ 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | #define SDK_MUTEX_DEFINE(X) 60 | #define SDK_MUTEX_INIT(X) 61 | #define SDK_MUTEX_LOCK(X) 62 | #define SDK_MUTEX_UNLOCK(X) 63 | 64 | /** 65 | * @defgroup os_data_type Data types. 66 | */ 67 | 68 | /** @} */ 69 | /** @endcond */ 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif // SDK_OS_H__ 76 | 77 | -------------------------------------------------------------------------------- /nRF5-sdk/components/libraries/util/sdk_resources.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | /** @file 41 | * @brief Definition file for resource usage by SoftDevice, ESB and Gazell. 42 | */ 43 | 44 | #ifndef APP_RESOURCES_H__ 45 | #define APP_RESOURCES_H__ 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | #ifdef SOFTDEVICE_PRESENT 52 | #include "nrf_sd_def.h" 53 | #else 54 | #define SD_PPI_RESTRICTED 0uL /**< 1 if PPI peripheral is restricted, 0 otherwise. */ 55 | #define SD_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by SotfDevice (not available to th spplication). */ 56 | #define SD_PPI_GROUPS_USED 0uL /**< PPI groups utilized by SotfDevice (not available to th spplication). */ 57 | #define SD_TIMERS_USED 0uL /**< Timers used by SoftDevice. */ 58 | #define SD_SWI_USED 0uL /**< Software interrupts used by SoftDevice. */ 59 | #endif 60 | 61 | #ifdef GAZELL_PRESENT 62 | #include "nrf_gzll_resources.h" 63 | #else 64 | #define GZLL_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by Gazell (not available to th spplication). */ 65 | #define GZLL_TIMERS_USED 0uL /**< Timers used by Gazell. */ 66 | #define GZLL_SWI_USED 0uL /**< Software interrupts used by Gazell */ 67 | #endif 68 | 69 | #ifdef ESB_PRESENT 70 | #include "nrf_esb_resources.h" 71 | #else 72 | #define ESB_PPI_CHANNELS_USED 0uL /**< PPI channels utilized by ESB (not available to th spplication). */ 73 | #define ESB_TIMERS_USED 0uL /**< Timers used by ESB. */ 74 | #define ESB_SWI_USED 0uL /**< Software interrupts used by ESB */ 75 | #endif 76 | 77 | #define NRF_PPI_CHANNELS_USED (SD_PPI_CHANNELS_USED | GZLL_PPI_CHANNELS_USED | ESB_PPI_CHANNELS_USED) 78 | #define NRF_PPI_GROUPS_USED (SD_PPI_GROUPS_USED) 79 | #define NRF_SWI_USED (SD_SWI_USED | GZLL_SWI_USED | ESB_SWI_USED) 80 | #define NRF_TIMERS_USED (SD_TIMERS_USED | GZLL_TIMERS_USED | ESB_TIMERS_USED) 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif // APP_RESOURCES_H__ 87 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #include "softdevice_handler_appsh.h" 41 | #include "app_scheduler.h" 42 | #include 43 | 44 | void softdevice_evt_get(void * p_event_data, uint16_t event_size) 45 | { 46 | APP_ERROR_CHECK_BOOL(event_size == 0); 47 | intern_softdevice_events_execute(); 48 | } 49 | 50 | uint32_t softdevice_evt_schedule(void) 51 | { 52 | return app_sched_event_put(NULL, 0, softdevice_evt_get); 53 | } 54 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef SOFTDEVICE_HANDLER_APPSH_H 41 | #define SOFTDEVICE_HANDLER_APPSH_H 42 | 43 | #include "softdevice_handler.h" 44 | #include 45 | 46 | #define SOFTDEVICE_HANDLER_APPSH_INIT(CLOCK_SOURCE,USE_SCHEDULER) \ 47 | SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE,(USE_SCHEDULER) ? softdevice_evt_schedule : NULL) 48 | 49 | uint32_t softdevice_evt_schedule(void); 50 | 51 | #endif //SOFTDEVICE_HANDLER_APPSH_H 52 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/s132/headers/ble_err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Nordic Semiconductor ASA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 16 | * contributors to this software may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * 4. This software must only be used in a processor manufactured by Nordic 20 | * Semiconductor ASA, or in a processor manufactured by a third party that 21 | * is used in combination with a processor manufactured by Nordic Semiconductor. 22 | * 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | */ 36 | 37 | /** 38 | @addtogroup BLE_COMMON 39 | @{ 40 | @addtogroup nrf_error 41 | @{ 42 | @ingroup BLE_COMMON 43 | @} 44 | 45 | @defgroup ble_err General error codes 46 | @{ 47 | 48 | @brief General error code definitions for the BLE API. 49 | 50 | @ingroup BLE_COMMON 51 | */ 52 | #ifndef NRF_BLE_ERR_H__ 53 | #define NRF_BLE_ERR_H__ 54 | 55 | #include "nrf_error.h" 56 | 57 | #ifdef __cplusplus 58 | extern "C" { 59 | #endif 60 | 61 | /* @defgroup BLE_ERRORS Error Codes 62 | * @{ */ 63 | #define BLE_ERROR_NOT_ENABLED (NRF_ERROR_STK_BASE_NUM+0x001) /**< @ref sd_ble_enable has not been called. */ 64 | #define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */ 65 | #define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x003) /**< Invalid attribute handle. */ 66 | #define BLE_ERROR_INVALID_ROLE (NRF_ERROR_STK_BASE_NUM+0x004) /**< Invalid role. */ 67 | /** @} */ 68 | 69 | 70 | /** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges 71 | * @brief Assignment of subranges for module specific error codes. 72 | * @note For specific error codes, see ble_.h or ble_error_.h. 73 | * @{ */ 74 | #define NRF_L2CAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */ 75 | #define NRF_GAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */ 76 | #define NRF_GATTC_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */ 77 | #define NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */ 78 | /** @} */ 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #endif 84 | 85 | 86 | /** 87 | @} 88 | @} 89 | */ 90 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/s132/headers/ble_l2cap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Nordic Semiconductor ASA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 16 | * contributors to this software may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * 4. This software must only be used in a processor manufactured by Nordic 20 | * Semiconductor ASA, or in a processor manufactured by a third party that 21 | * is used in combination with a processor manufactured by Nordic Semiconductor. 22 | * 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | */ 36 | 37 | /** 38 | @addtogroup BLE_L2CAP Logical Link Control and Adaptation Protocol (L2CAP) 39 | @{ 40 | @brief Definitions and prototypes for the L2CAP interface. 41 | */ 42 | 43 | #ifndef BLE_L2CAP_H__ 44 | #define BLE_L2CAP_H__ 45 | 46 | #include "ble_types.h" 47 | #include "ble_ranges.h" 48 | #include "ble_err.h" 49 | #include "nrf_svc.h" 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | /**@addtogroup BLE_L2CAP_DEFINES Defines 56 | * @{ */ 57 | 58 | /** @} */ 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #endif // BLE_L2CAP_H__ 64 | 65 | /** 66 | @} 67 | */ 68 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/s132/headers/nrf_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Nordic Semiconductor ASA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 16 | * contributors to this software may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * 4. This software must only be used in a processor manufactured by Nordic 20 | * Semiconductor ASA, or in a processor manufactured by a third party that 21 | * is used in combination with a processor manufactured by Nordic Semiconductor. 22 | * 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | */ 36 | /** 37 | @defgroup nrf_error SoftDevice Global Error Codes 38 | @{ 39 | 40 | @brief Global Error definitions 41 | */ 42 | 43 | /* Header guard */ 44 | #ifndef NRF_ERROR_H__ 45 | #define NRF_ERROR_H__ 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | /** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions 52 | * @{ */ 53 | #define NRF_ERROR_BASE_NUM (0x0) ///< Global error base 54 | #define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base 55 | #define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base 56 | #define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base 57 | /** @} */ 58 | 59 | #define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command 60 | #define NRF_ERROR_SVC_HANDLER_MISSING (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing 61 | #define NRF_ERROR_SOFTDEVICE_NOT_ENABLED (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled 62 | #define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error 63 | #define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for operation 64 | #define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not found 65 | #define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not supported 66 | #define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< Invalid Parameter 67 | #define NRF_ERROR_INVALID_STATE (NRF_ERROR_BASE_NUM + 8) ///< Invalid state, operation disallowed in this state 68 | #define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid Length 69 | #define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags 70 | #define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data 71 | #define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< Invalid Data size 72 | #define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out 73 | #define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer 74 | #define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation 75 | #define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address 76 | #define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy 77 | #define NRF_ERROR_CONN_COUNT (NRF_ERROR_BASE_NUM + 18) ///< Maximum connection count exceeded. 78 | #define NRF_ERROR_RESOURCES (NRF_ERROR_BASE_NUM + 19) ///< Not enough resources for operation 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #endif // NRF_ERROR_H__ 84 | 85 | /** 86 | @} 87 | */ 88 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/s132/headers/nrf_error_sdm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Nordic Semiconductor ASA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 16 | * contributors to this software may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * 4. This software must only be used in a processor manufactured by Nordic 20 | * Semiconductor ASA, or in a processor manufactured by a third party that 21 | * is used in combination with a processor manufactured by Nordic Semiconductor. 22 | * 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | */ 36 | /** 37 | @addtogroup nrf_sdm_api 38 | @{ 39 | @defgroup nrf_sdm_error SoftDevice Manager Error Codes 40 | @{ 41 | 42 | @brief Error definitions for the SDM API 43 | */ 44 | 45 | /* Header guard */ 46 | #ifndef NRF_ERROR_SDM_H__ 47 | #define NRF_ERROR_SDM_H__ 48 | 49 | #include "nrf_error.h" 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | #define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN (NRF_ERROR_SDM_BASE_NUM + 0) ///< Unknown LFCLK source. 56 | #define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1) ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts). 57 | #define NRF_ERROR_SDM_INCORRECT_CLENR0 (NRF_ERROR_SDM_BASE_NUM + 2) ///< Incorrect CLENR0 (can be caused by erroneous SoftDevice flashing). 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | #endif // NRF_ERROR_SDM_H__ 63 | 64 | /** 65 | @} 66 | @} 67 | */ 68 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/s132/headers/nrf_error_soc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Nordic Semiconductor ASA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 16 | * contributors to this software may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * 4. This software must only be used in a processor manufactured by Nordic 20 | * Semiconductor ASA, or in a processor manufactured by a third party that 21 | * is used in combination with a processor manufactured by Nordic Semiconductor. 22 | * 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | */ 36 | /** 37 | @addtogroup nrf_soc_api 38 | @{ 39 | @defgroup nrf_soc_error SoC Library Error Codes 40 | @{ 41 | 42 | @brief Error definitions for the SoC library 43 | 44 | */ 45 | 46 | /* Header guard */ 47 | #ifndef NRF_ERROR_SOC_H__ 48 | #define NRF_ERROR_SOC_H__ 49 | 50 | #include "nrf_error.h" 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | /* Mutex Errors */ 56 | #define NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN (NRF_ERROR_SOC_BASE_NUM + 0) ///< Mutex already taken 57 | 58 | /* NVIC errors */ 59 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE (NRF_ERROR_SOC_BASE_NUM + 1) ///< NVIC interrupt not available 60 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED (NRF_ERROR_SOC_BASE_NUM + 2) ///< NVIC interrupt priority not allowed 61 | #define NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 3) ///< NVIC should not return 62 | 63 | /* Power errors */ 64 | #define NRF_ERROR_SOC_POWER_MODE_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 4) ///< Power mode unknown 65 | #define NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 5) ///< Power POF threshold unknown 66 | #define NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 6) ///< Power off should not return 67 | 68 | /* Rand errors */ 69 | #define NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES (NRF_ERROR_SOC_BASE_NUM + 7) ///< RAND not enough values 70 | 71 | /* PPI errors */ 72 | #define NRF_ERROR_SOC_PPI_INVALID_CHANNEL (NRF_ERROR_SOC_BASE_NUM + 8) ///< Invalid PPI Channel 73 | #define NRF_ERROR_SOC_PPI_INVALID_GROUP (NRF_ERROR_SOC_BASE_NUM + 9) ///< Invalid PPI Group 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | #endif // NRF_ERROR_SOC_H__ 79 | /** 80 | @} 81 | @} 82 | */ 83 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/s132/headers/nrf_sd_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef NRF_SD_DEF_H__ 41 | #define NRF_SD_DEF_H__ 42 | 43 | #include 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #define SD_PPI_CHANNELS_USED 0xFFFE0000uL /**< PPI channels utilized by SotfDevice (not available to the application). */ 50 | #define SD_PPI_GROUPS_USED 0x0000000CuL /**< PPI groups utilized by SoftDevice (not available to the application). */ 51 | #define SD_TIMERS_USED 0x00000001uL /**< Timers used by SoftDevice. */ 52 | #define SD_SWI_USED 0x0000003CuL /**< Software interrupts used by SoftDevice */ 53 | 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif /* NRF_SD_DEF_H__ */ 60 | -------------------------------------------------------------------------------- /nRF5-sdk/components/softdevice/s132/headers/nrf_svc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Nordic Semiconductor ASA 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this 12 | * list of conditions and the following disclaimer in the documentation and/or 13 | * other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 16 | * contributors to this software may be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * 4. This software must only be used in a processor manufactured by Nordic 20 | * Semiconductor ASA, or in a processor manufactured by a third party that 21 | * is used in combination with a processor manufactured by Nordic Semiconductor. 22 | * 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 28 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 31 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | */ 36 | 37 | #ifndef NRF_SVC__ 38 | #define NRF_SVC__ 39 | 40 | #include "stdint.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #ifdef SVCALL_AS_NORMAL_FUNCTION 47 | #define SVCALL(number, return_type, signature) return_type signature 48 | #else 49 | 50 | #ifndef SVCALL 51 | #if defined (__CC_ARM) 52 | #define SVCALL(number, return_type, signature) return_type __svc(number) signature 53 | #elif defined (__GNUC__) 54 | #ifdef __cplusplus 55 | #define GCC_CAST_CPP (uint16_t) 56 | #else 57 | #define GCC_CAST_CPP 58 | #endif 59 | #define SVCALL(number, return_type, signature) \ 60 | _Pragma("GCC diagnostic push") \ 61 | _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \ 62 | __attribute__((weak)) \ 63 | __attribute__((naked)) \ 64 | __attribute__((unused)) \ 65 | return_type signature \ 66 | { \ 67 | __asm( \ 68 | "svc %0\n" \ 69 | "bx r14" : : "I" (GCC_CAST_CPP number) : "r0" \ 70 | ); \ 71 | } \ 72 | _Pragma("GCC diagnostic pop") 73 | 74 | #elif defined (__ICCARM__) 75 | #define PRAGMA(x) _Pragma(#x) 76 | #define SVCALL(number, return_type, signature) \ 77 | PRAGMA(swi_number = (number)) \ 78 | __swi return_type signature; 79 | #else 80 | #define SVCALL(number, return_type, signature) return_type signature 81 | #endif 82 | #endif // SVCALL 83 | 84 | #endif // SVCALL_AS_NORMAL_FUNCTION 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | #endif // NRF_SVC__ 90 | -------------------------------------------------------------------------------- /nRF5-sdk/components/toolchain/cmsis/include/core_cmFunc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmFunc.h 3 | * @brief CMSIS Cortex-M Core Function Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | #if defined ( __ICCARM__ ) 35 | #pragma system_include /* treat file as system include file for MISRA check */ 36 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 37 | #pragma clang system_header /* treat file as system include file */ 38 | #endif 39 | 40 | #ifndef __CORE_CMFUNC_H 41 | #define __CORE_CMFUNC_H 42 | 43 | 44 | /* ########################### Core Function Access ########################### */ 45 | /** \ingroup CMSIS_Core_FunctionInterface 46 | \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions 47 | @{ 48 | */ 49 | 50 | /*------------------ RealView Compiler -----------------*/ 51 | #if defined ( __CC_ARM ) 52 | #include "cmsis_armcc.h" 53 | 54 | /*------------------ ARM Compiler V6 -------------------*/ 55 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 56 | #include "cmsis_armcc_V6.h" 57 | 58 | /*------------------ GNU Compiler ----------------------*/ 59 | #elif defined ( __GNUC__ ) 60 | #include "cmsis_gcc.h" 61 | 62 | /*------------------ ICC Compiler ----------------------*/ 63 | #elif defined ( __ICCARM__ ) 64 | #include 65 | 66 | /*------------------ TI CCS Compiler -------------------*/ 67 | #elif defined ( __TMS470__ ) 68 | #include 69 | 70 | /*------------------ TASKING Compiler ------------------*/ 71 | #elif defined ( __TASKING__ ) 72 | /* 73 | * The CMSIS functions have been implemented as intrinsics in the compiler. 74 | * Please use "carm -?i" to get an up to date list of all intrinsics, 75 | * Including the CMSIS ones. 76 | */ 77 | 78 | /*------------------ COSMIC Compiler -------------------*/ 79 | #elif defined ( __CSMC__ ) 80 | #include 81 | 82 | #endif 83 | 84 | /*@} end of CMSIS_Core_RegAccFunctions */ 85 | 86 | #endif /* __CORE_CMFUNC_H */ 87 | -------------------------------------------------------------------------------- /nRF5-sdk/components/toolchain/cmsis/include/core_cmInstr.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmInstr.h 3 | * @brief CMSIS Cortex-M Core Instruction Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMINSTR_H 42 | #define __CORE_CMINSTR_H 43 | 44 | 45 | /* ########################## Core Instruction Access ######################### */ 46 | /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface 47 | Access to dedicated instructions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ 86 | 87 | #endif /* __CORE_CMINSTR_H */ 88 | -------------------------------------------------------------------------------- /nRF5-sdk/components/toolchain/cmsis/include/core_cmSimd.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmSimd.h 3 | * @brief CMSIS Cortex-M SIMD Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMSIMD_H 42 | #define __CORE_CMSIMD_H 43 | 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | 48 | 49 | /* ################### Compiler specific Intrinsics ########################### */ 50 | /** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics 51 | Access to dedicated SIMD instructions 52 | @{ 53 | */ 54 | 55 | /*------------------ RealView Compiler -----------------*/ 56 | #if defined ( __CC_ARM ) 57 | #include "cmsis_armcc.h" 58 | 59 | /*------------------ ARM Compiler V6 -------------------*/ 60 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 61 | #include "cmsis_armcc_V6.h" 62 | 63 | /*------------------ GNU Compiler ----------------------*/ 64 | #elif defined ( __GNUC__ ) 65 | #include "cmsis_gcc.h" 66 | 67 | /*------------------ ICC Compiler ----------------------*/ 68 | #elif defined ( __ICCARM__ ) 69 | #include 70 | 71 | /*------------------ TI CCS Compiler -------------------*/ 72 | #elif defined ( __TMS470__ ) 73 | #include 74 | 75 | /*------------------ TASKING Compiler ------------------*/ 76 | #elif defined ( __TASKING__ ) 77 | /* 78 | * The CMSIS functions have been implemented as intrinsics in the compiler. 79 | * Please use "carm -?i" to get an up to date list of all intrinsics, 80 | * Including the CMSIS ones. 81 | */ 82 | 83 | /*------------------ COSMIC Compiler -------------------*/ 84 | #elif defined ( __CSMC__ ) 85 | #include 86 | 87 | #endif 88 | 89 | /*@} end of group CMSIS_SIMD_intrinsics */ 90 | 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* __CORE_CMSIMD_H */ 97 | -------------------------------------------------------------------------------- /nRF5-sdk/components/toolchain/system_nrf52.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2009-2017 ARM Limited. All rights reserved. 4 | 5 | SPDX-License-Identifier: Apache-2.0 6 | 7 | Licensed under the Apache License, Version 2.0 (the License); you may 8 | not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an AS IS BASIS, WITHOUT 15 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | 19 | NOTICE: This file has been modified by Nordic Semiconductor ASA. 20 | 21 | */ 22 | 23 | #ifndef SYSTEM_NRF52_H 24 | #define SYSTEM_NRF52_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #include 31 | 32 | 33 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 34 | 35 | /** 36 | * Initialize the system 37 | * 38 | * @param none 39 | * @return none 40 | * 41 | * @brief Setup the microcontroller system. 42 | * Initialize the System and update the SystemCoreClock variable. 43 | */ 44 | extern void SystemInit (void); 45 | 46 | /** 47 | * Update SystemCoreClock variable 48 | * 49 | * @param none 50 | * @return none 51 | * 52 | * @brief Updates the SystemCoreClock with current core Clock 53 | * retrieved from cpu registers. 54 | */ 55 | extern void SystemCoreClockUpdate (void); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* SYSTEM_NRF52_H */ 62 | -------------------------------------------------------------------------------- /nRF5-sdk/external/segger_rtt/SEGGER_RTT_Conf.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER MICROCONTROLLER GmbH & Co. KG * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 2014 - 2015 SEGGER Microcontroller GmbH & Co. KG * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | ---------------------------------------------------------------------- 12 | File : SEGGER_RTT_Conf.h 13 | Purpose : Implementation of SEGGER real-time transfer (RTT) which 14 | allows real-time communication on targets which support 15 | debugger memory accesses while the CPU is running. 16 | ---------------------------END-OF-HEADER------------------------------ 17 | */ 18 | 19 | #ifndef SEGGER_RTT_CONF_H 20 | #define SEGGER_RTT_CONF_H 21 | #include "sdk_config.h" 22 | #include "compiler_abstraction.h" 23 | #include "app_util_platform.h" 24 | #ifdef __ICCARM__ 25 | #include 26 | #endif 27 | 28 | /********************************************************************* 29 | * 30 | * Defines, configurable 31 | * 32 | ********************************************************************** 33 | */ 34 | #define SEGGER_RTT_MAX_NUM_UP_BUFFERS SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS // Max. number of up-buffers (T->H) available on this target (Default: 2) 35 | #define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS // Max. number of down-buffers (H->T) available on this target (Default: 2) 36 | 37 | //Up Buffer size is set based on RTT configuration and nrf_log configuration. Larger buffer setting is used. 38 | #if defined(NRF_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE) && NRF_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE > SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 39 | #define BUFFER_SIZE_UP NRF_LOG_BACKEND_RTT_OUTPUT_BUFFER_SIZE // Size of the buffer for terminal output of target, up to host (Default: 1k) 40 | #else 41 | #define BUFFER_SIZE_UP SEGGER_RTT_CONFIG_BUFFER_SIZE_UP // Size of the buffer for terminal output of target, up to host (Default: 1k) 42 | #endif 43 | 44 | #define BUFFER_SIZE_DOWN SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN // Size of the buffer for terminal input to target from host (Usually keyboard input) (Default: 16) 45 | 46 | #define SEGGER_RTT_PRINTF_BUFFER_SIZE (64u) // Size of buffer for RTT printf to bulk-send chars via RTT (Default: 64) 47 | 48 | #define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_CONFIG_DEFAULT_MODE // Mode for preinitialized terminal channel (buffer 0) 49 | 50 | // 51 | // Target is not allowed to perform other RTT operations while string still has not been stored completely. 52 | // Otherwise we would probably end up with a mixed string in the buffer. 53 | // If using RTT from within interrupts, multiple tasks or multi processors, define the SEGGER_RTT_LOCK() and SEGGER_RTT_UNLOCK() function here. 54 | // 55 | /********************************************************************* 56 | * 57 | * RTT lock configuration for SEGGER Embedded Studio, 58 | * Rowley CrossStudio and GCC 59 | */ 60 | 61 | #define SEGGER_RTT_LOCK(SavedState) \ 62 | SavedState = 0; \ 63 | CRITICAL_REGION_ENTER() 64 | 65 | #define SEGGER_RTT_UNLOCK(SavedState) \ 66 | (void)SavedState; \ 67 | CRITICAL_REGION_EXIT() 68 | 69 | /*************************** End of file ****************************/ 70 | #endif // SEGGER_RTT_CONF_H 71 | -------------------------------------------------------------------------------- /nRF5-sdk/external/segger_rtt/license/license.txt: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER MICROCONTROLLER GmbH & Co. KG * 3 | * Solutions for real time microcontroller applications * 4 | ********************************************************************** 5 | * * 6 | * (c) 2014 - 2015 SEGGER Microcontroller GmbH & Co. KG * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * All rights reserved. * 13 | * * 14 | * * This software may in its unmodified form be freely redistributed * 15 | * in source form. * 16 | * * The source code may be modified, provided the source code * 17 | * retains the above copyright notice, this list of conditions and * 18 | * the following disclaimer. * 19 | * * Modified versions of this software in source or linkable form * 20 | * may not be distributed without prior consent of SEGGER. * 21 | * * This software may only be used for communication with SEGGER * 22 | * J-Link debug probes. * 23 | * * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 25 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 26 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 27 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 28 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 29 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 31 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 32 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 35 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 36 | * DAMAGE. * 37 | * * 38 | ********************************************************************** 39 | -------------------------------------------------------------------------------- /nrf52dk-sys.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x1f000, LENGTH = 0x61000 9 | RAM (rwx) : ORIGIN = 0x20001fc0, LENGTH = 0xe040 10 | } 11 | 12 | SECTIONS 13 | { 14 | .fs_data : 15 | { 16 | PROVIDE(__start_fs_data = .); 17 | KEEP(*(.fs_data)) 18 | PROVIDE(__stop_fs_data = .); 19 | } > RAM 20 | } INSERT AFTER .data; 21 | 22 | SECTIONS 23 | { 24 | .pwr_mgmt_data : 25 | { 26 | PROVIDE(__start_pwr_mgmt_data = .); 27 | KEEP(*(SORT(.pwr_mgmt_data*))) 28 | PROVIDE(__stop_pwr_mgmt_data = .); 29 | } > FLASH 30 | } INSERT AFTER .text 31 | 32 | INCLUDE "nrf5x_common.ld" 33 | -------------------------------------------------------------------------------- /shims/shimmy.c: -------------------------------------------------------------------------------- 1 | /* NOTE: 2 | * 3 | * This include forces the SVCALL macro to be rendered and compiled here. 4 | * This works for now, but we should probably switch to a rust macro similar 5 | * to how ble400 handles SVCALL. 6 | */ 7 | #include "nrf_svc.h" 8 | #include "../bindings.h" 9 | 10 | /* NOTE: 11 | * 12 | * This section renders the static inline nrf_delay_(us|ms) so it is 13 | * usable with Rust 14 | */ 15 | #include "nrf_delay.h" 16 | #include "nrf_sdm.h" 17 | #include "shims.h" 18 | 19 | void _nrf_delay_ms(uint32_t number_of_ms) { nrf_delay_ms(number_of_ms); } 20 | 21 | nrf_clock_lf_cfg_t _NRF_CLOCK_LFCLKSRC() { 22 | return (nrf_clock_lf_cfg_t)NRF_CLOCK_LFCLKSRC; 23 | } 24 | -------------------------------------------------------------------------------- /shims/shims.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* nrf_delay shim */ 4 | #include "nrf_sdm.h" 5 | 6 | nrf_clock_lf_cfg_t _NRF_CLOCK_LFCLKSRC(); 7 | void _nrf_delay_ms(uint32_t number_of_ms); 8 | -------------------------------------------------------------------------------- /src/lang_items.rs: -------------------------------------------------------------------------------- 1 | /// Default panic handler 2 | #[linkage = "weak"] 3 | #[lang = "panic_fmt"] 4 | unsafe extern "C" fn panic_fmt( 5 | _args: ::core::fmt::Arguments, 6 | _file: &'static str, 7 | _line: u32, 8 | ) -> ! { 9 | hprint!("panicked at '"); 10 | match () { 11 | #[cfg(feature = "semihosting")] 12 | () => { 13 | ::cortex_m_semihosting::io::write_fmt(_args); 14 | } 15 | #[cfg(not(feature = "semihosting"))] 16 | () => {} 17 | } 18 | hprintln!("', {}:{}", _file, _line); 19 | 20 | bkpt!(); 21 | 22 | loop {} 23 | } 24 | 25 | /// Lang item required to make the normal `main` work in applications 26 | // This is how the `start` lang item works: 27 | // When `rustc` compiles a binary crate, it creates a `main` function that looks 28 | // like this: 29 | // 30 | // ``` 31 | // #[export_name = "main"] 32 | // pub extern "C" fn rustc_main(argc: isize, argv: *const *const u8) -> isize { 33 | // start(main) 34 | // } 35 | // ``` 36 | // 37 | // Where `start` is this function and `main` is the binary crate's `main` 38 | // function. 39 | // 40 | // The final piece is that the entry point of our program, the reset handler, 41 | // has to call `rustc_main`. That's covered by the `reset_handler` function in 42 | // `src/exceptions.rs` 43 | #[lang = "start"] 44 | extern "C" fn start(main: fn(), _argc: isize, _argv: *const *const u8) -> isize { 45 | main(); 46 | 47 | 0 48 | } 49 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Based on `cortex-m-template` 2 | //! 3 | //! https://github.com/japaric/cortex-m-template 4 | 5 | // #![deny(missing_docs)] 6 | #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] 7 | // #![deny(warnings)] 8 | #![feature(asm)] 9 | #![feature(lang_items)] 10 | #![feature(linkage)] 11 | #![feature(macro_reexport)] 12 | #![feature(naked_functions)] 13 | #![no_std] 14 | 15 | #[macro_reexport(bkpt)] 16 | #[macro_use] 17 | extern crate cortex_m; 18 | #[cfg(feature = "semihosting")] 19 | #[macro_reexport(hprint, hprintln)] 20 | #[macro_use] 21 | extern crate cortex_m_semihosting; 22 | extern crate r0; 23 | 24 | #[macro_use] 25 | mod macros; 26 | 27 | mod lang_items; 28 | 29 | /// Copied from https://github.com/rust-lang/rust/blob/master/src/libstd/os/raw.rs 30 | pub mod ctypes { 31 | // Unconditional 32 | pub type c_schar = u8; 33 | pub type c_uchar = u8; 34 | pub type c_short = i16; 35 | pub type c_ushort = u16; 36 | pub type c_int = i32; 37 | pub type c_uint = u32; 38 | pub type c_longlong = i64; 39 | pub type c_ulonglong = u64; 40 | #[repr(u8)] 41 | pub enum c_void { 42 | #[doc(hidden)] __variant1, 43 | #[doc(hidden)] __variant2, 44 | } 45 | 46 | // Non-Windows 47 | pub type c_long = i32; 48 | pub type c_ulong = u32; 49 | 50 | // Unsure about this one… In doubt, align cfg(all(target_os = "linux", target_arch = "arm")) 51 | pub type c_char = u8; 52 | } 53 | 54 | pub fn check(ec: u32) -> Result<(), ()> { 55 | match ec { 56 | 0 => Ok(()), 57 | _ => Err(()), 58 | } 59 | } 60 | 61 | // We cannot use code gen here because bindgen created __va_list twice. Could 62 | // we be double-defining things in C? 63 | #[repr(C)] 64 | #[derive(Debug)] 65 | pub struct __va_list { 66 | pub __ap: *mut ctypes::c_void, 67 | } 68 | 69 | // Our own type alias to i8. We cannot use the generated code here, because 70 | // bindgen yields a u8, and we have require constants. 71 | pub type IRQn_Type = i8; 72 | 73 | pub const IRQn_Type_Reset_IRQn: IRQn_Type = -15; 74 | pub const IRQn_Type_NonMaskableInt_IRQn: IRQn_Type = -14; 75 | pub const IRQn_Type_HardFault_IRQn: IRQn_Type = -13; 76 | pub const IRQn_Type_MemoryManagement_IRQn: IRQn_Type = -12; 77 | pub const IRQn_Type_BusFault_IRQn: IRQn_Type = -11; 78 | pub const IRQn_Type_UsageFault_IRQn: IRQn_Type = -10; 79 | pub const IRQn_Type_SVCall_IRQn: IRQn_Type = -5; 80 | pub const IRQn_Type_DebugMonitor_IRQn: IRQn_Type = -4; 81 | pub const IRQn_Type_PendSV_IRQn: IRQn_Type = -2; 82 | pub const IRQn_Type_SysTick_IRQn: IRQn_Type = -1; 83 | pub const IRQn_Type_POWER_CLOCK_IRQn: IRQn_Type = 0; 84 | pub const IRQn_Type_RADIO_IRQn: IRQn_Type = 1; 85 | pub const IRQn_Type_UARTE0_UART0_IRQn: IRQn_Type = 2; 86 | pub const IRQn_Type_SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn: IRQn_Type = 3; 87 | pub const IRQn_Type_SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn: IRQn_Type = 4; 88 | pub const IRQn_Type_NFCT_IRQn: IRQn_Type = 5; 89 | pub const IRQn_Type_GPIOTE_IRQn: IRQn_Type = 6; 90 | pub const IRQn_Type_SAADC_IRQn: IRQn_Type = 7; 91 | pub const IRQn_Type_TIMER0_IRQn: IRQn_Type = 8; 92 | pub const IRQn_Type_TIMER1_IRQn: IRQn_Type = 9; 93 | pub const IRQn_Type_TIMER2_IRQn: IRQn_Type = 10; 94 | pub const IRQn_Type_RTC0_IRQn: IRQn_Type = 11; 95 | pub const IRQn_Type_TEMP_IRQn: IRQn_Type = 12; 96 | pub const IRQn_Type_RNG_IRQn: IRQn_Type = 13; 97 | pub const IRQn_Type_ECB_IRQn: IRQn_Type = 14; 98 | pub const IRQn_Type_CCM_AAR_IRQn: IRQn_Type = 15; 99 | pub const IRQn_Type_WDT_IRQn: IRQn_Type = 16; 100 | pub const IRQn_Type_RTC1_IRQn: IRQn_Type = 17; 101 | pub const IRQn_Type_QDEC_IRQn: IRQn_Type = 18; 102 | pub const IRQn_Type_COMP_LPCOMP_IRQn: IRQn_Type = 19; 103 | pub const IRQn_Type_SWI0_EGU0_IRQn: IRQn_Type = 20; 104 | pub const IRQn_Type_SWI1_EGU1_IRQn: IRQn_Type = 21; 105 | pub const IRQn_Type_SWI2_EGU2_IRQn: IRQn_Type = 22; 106 | pub const IRQn_Type_SWI3_EGU3_IRQn: IRQn_Type = 23; 107 | pub const IRQn_Type_SWI4_EGU4_IRQn: IRQn_Type = 24; 108 | pub const IRQn_Type_SWI5_EGU5_IRQn: IRQn_Type = 25; 109 | pub const IRQn_Type_TIMER3_IRQn: IRQn_Type = 26; 110 | pub const IRQn_Type_TIMER4_IRQn: IRQn_Type = 27; 111 | pub const IRQn_Type_PWM0_IRQn: IRQn_Type = 28; 112 | pub const IRQn_Type_PDM_IRQn: IRQn_Type = 29; 113 | pub const IRQn_Type_MWU_IRQn: IRQn_Type = 32; 114 | pub const IRQn_Type_PWM1_IRQn: IRQn_Type = 33; 115 | pub const IRQn_Type_PWM2_IRQn: IRQn_Type = 34; 116 | pub const IRQn_Type_SPIM2_SPIS2_SPI2_IRQn: IRQn_Type = 35; 117 | pub const IRQn_Type_RTC2_IRQn: IRQn_Type = 36; 118 | pub const IRQn_Type_I2S_IRQn: IRQn_Type = 37; 119 | pub const IRQn_Type_FPU_IRQn: IRQn_Type = 38; 120 | 121 | include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 122 | -------------------------------------------------------------------------------- /src/macros.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(feature = "semihosting"))] 2 | #[macro_export] 3 | macro_rules! hprint { 4 | ($($arg:tt)*) => (); 5 | } 6 | 7 | #[cfg(not(feature = "semihosting"))] 8 | #[macro_export] 9 | macro_rules! hprintln { 10 | ($($arg:tt)*) => (); 11 | } 12 | --------------------------------------------------------------------------------