├── BSD-3clause-Nordic.txt ├── CHANGELOG.md ├── LICENSE ├── README.md ├── apache-2.0.txt ├── module.json ├── script ├── copyright_header.txt ├── pick_nrf51_files.py ├── replace_headers.py └── required_files.txt └── source ├── nordic_sdk └── components │ ├── ble │ ├── ble_radio_notification │ │ ├── ble_radio_notification.c │ │ └── ble_radio_notification.h │ ├── ble_services │ │ └── ble_dfu │ │ │ ├── ble_dfu.c │ │ │ └── ble_dfu.h │ ├── common │ │ ├── ble_advdata.c │ │ ├── ble_advdata.h │ │ ├── ble_conn_params.cpp │ │ ├── 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 │ ├── device_manager │ │ ├── config │ │ │ └── device_manager_cnfg.h │ │ ├── device_manager.h │ │ └── device_manager_peripheral.c │ └── peer_manager │ │ ├── id_manager.c │ │ ├── id_manager.h │ │ ├── peer_data.c │ │ ├── peer_data.h │ │ ├── peer_data_storage.c │ │ ├── peer_data_storage.h │ │ ├── peer_database.c │ │ ├── peer_database.h │ │ ├── peer_id.c │ │ ├── peer_id.h │ │ ├── peer_manager_types.h │ │ ├── pm_buffer.c │ │ ├── pm_buffer.h │ │ ├── pm_mutex.c │ │ └── pm_mutex.h │ ├── device │ ├── compiler_abstraction.h │ ├── nrf.h │ ├── nrf51.h │ ├── nrf51_bitfields.h │ └── nrf51_deprecated.h │ ├── drivers_nrf │ ├── ble_flash │ │ ├── ble_flash.c │ │ └── ble_flash.h │ ├── delay │ │ ├── nrf_delay.c │ │ └── nrf_delay.h │ ├── hal │ │ ├── nrf_ecb.c │ │ ├── nrf_ecb.h │ │ ├── nrf_gpio.h │ │ ├── nrf_gpiote.h │ │ ├── nrf_nvmc.c │ │ ├── nrf_nvmc.h │ │ ├── nrf_temp.h │ │ └── nrf_wdt.h │ └── pstorage │ │ ├── config │ │ └── pstorage_platform.h │ │ ├── pstorage.c │ │ └── pstorage.h │ ├── libraries │ ├── bootloader_dfu │ │ ├── bootloader.h │ │ ├── bootloader_types.h │ │ ├── bootloader_util.c │ │ ├── bootloader_util.h │ │ ├── dfu.h │ │ ├── dfu_app_handler.c │ │ ├── dfu_app_handler.h │ │ ├── dfu_bank_internal.h │ │ ├── dfu_ble_svc.h │ │ ├── dfu_ble_svc_internal.h │ │ ├── dfu_init.h │ │ ├── dfu_init_template.c │ │ ├── dfu_transport.h │ │ ├── dfu_types.h │ │ └── hci_transport │ │ │ └── hci_mem_pool_internal.h │ ├── crc16 │ │ ├── crc16.c │ │ └── crc16.h │ ├── experimental_section_vars │ │ └── section_vars.h │ ├── fds │ │ ├── fds.c │ │ ├── fds.h │ │ ├── fds_config.h │ │ └── fds_types_internal.h │ ├── fstorage │ │ ├── fstorage.c │ │ ├── fstorage.h │ │ ├── fstorage_config.h │ │ └── fstorage_nosd.c │ ├── hci │ │ ├── hci_mem_pool.c │ │ └── hci_mem_pool.h │ ├── scheduler │ │ ├── app_scheduler.c │ │ └── app_scheduler.h │ ├── timer │ │ └── app_timer.h │ └── util │ │ ├── app_error.c │ │ ├── app_error.h │ │ ├── app_util.h │ │ ├── app_util_platform.c │ │ ├── app_util_platform.h │ │ ├── common.h │ │ ├── nordic_common.h │ │ ├── nrf_assert.c │ │ ├── nrf_assert.h │ │ ├── sdk_common.h │ │ ├── sdk_errors.h │ │ ├── sdk_mapped_flags.c │ │ ├── sdk_mapped_flags.h │ │ └── sdk_os.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 │ └── s130 │ │ └── headers │ │ ├── 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 │ │ ├── nrf_ble.h │ │ ├── nrf_error.h │ │ ├── nrf_error_sdm.h │ │ ├── nrf_error_soc.h │ │ ├── nrf_mbr.h │ │ ├── nrf_sdm.h │ │ ├── nrf_soc.h │ │ ├── nrf_svc.h │ │ └── softdevice_assert.h │ └── toolchain │ ├── system_nrf51.c │ └── system_nrf51.h ├── prevent_bootloader_frame_pointer.cmake └── supress-warnings.cmake /BSD-3clause-Nordic.txt: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [v2.2.1](https://github.com/ARMmbed/nrf51-sdk/tree/v2.2.1) (2016-01-27) 4 | [Full Changelog](https://github.com/ARMmbed/nrf51-sdk/compare/v2.2.0...v2.2.1) 5 | 6 | **Closed issues:** 7 | 8 | - It's not possible to generate a debug build with nrf51-sdk 1.0.1 [\#11](https://github.com/ARMmbed/nrf51-sdk/issues/11) 9 | 10 | **Merged pull requests:** 11 | 12 | - Optimise to omit frame pointer even in a debug build [\#19](https://github.com/ARMmbed/nrf51-sdk/pull/19) ([LiyouZhou](https://github.com/LiyouZhou)) 13 | 14 | ## [v2.2.0](https://github.com/ARMmbed/nrf51-sdk/tree/v2.2.0) (2016-01-11) 15 | [Full Changelog](https://github.com/ARMmbed/nrf51-sdk/compare/v2.1.0...v2.2.0) 16 | 17 | **Closed issues:** 18 | 19 | - Update bootloader branch to sdk V10 [\#14](https://github.com/ARMmbed/nrf51-sdk/issues/14) 20 | 21 | **Merged pull requests:** 22 | 23 | - Add missing implementations for peer\_manager. [\#18](https://github.com/ARMmbed/nrf51-sdk/pull/18) ([pan-](https://github.com/pan-)) 24 | - Expose function in DM to calculate BLE hash [\#17](https://github.com/ARMmbed/nrf51-sdk/pull/17) ([andresag01](https://github.com/andresag01)) 25 | 26 | ## [v2.1.0](https://github.com/ARMmbed/nrf51-sdk/tree/v2.1.0) (2016-01-08) 27 | [Full Changelog](https://github.com/ARMmbed/nrf51-sdk/compare/v2.0.0...v2.1.0) 28 | 29 | **Merged pull requests:** 30 | 31 | - Add files from peer manager from nRF51 SDK 10.0.0 [\#15](https://github.com/ARMmbed/nrf51-sdk/pull/15) ([andresag01](https://github.com/andresag01)) 32 | 33 | ## [v2.0.0](https://github.com/ARMmbed/nrf51-sdk/tree/v2.0.0) (2016-01-07) 34 | [Full Changelog](https://github.com/ARMmbed/nrf51-sdk/compare/v1.0.1...v2.0.0) 35 | 36 | **Closed issues:** 37 | 38 | - nrf51-sdk generates warnings for old style declarations [\#10](https://github.com/ARMmbed/nrf51-sdk/issues/10) 39 | 40 | **Merged pull requests:** 41 | 42 | - Nordic sdk 10.0.0 [\#13](https://github.com/ARMmbed/nrf51-sdk/pull/13) ([LiyouZhou](https://github.com/LiyouZhou)) 43 | - Add ifdef to include correct mbed.h file in mbedOS [\#9](https://github.com/ARMmbed/nrf51-sdk/pull/9) ([andresag01](https://github.com/andresag01)) 44 | - Update files to Nordic sdk 9.0.0 [\#8](https://github.com/ARMmbed/nrf51-sdk/pull/8) ([LiyouZhou](https://github.com/LiyouZhou)) 45 | 46 | ## [v1.0.1](https://github.com/ARMmbed/nrf51-sdk/tree/v1.0.1) (2015-12-10) 47 | [Full Changelog](https://github.com/ARMmbed/nrf51-sdk/compare/v1.0.0...v1.0.1) 48 | 49 | **Closed issues:** 50 | 51 | - Need the ability to do version bump [\#1](https://github.com/ARMmbed/nrf51-sdk/issues/1) 52 | 53 | **Merged pull requests:** 54 | 55 | - Add GCC diagnostics to suppress unused-parameter warnings [\#7](https://github.com/ARMmbed/nrf51-sdk/pull/7) ([andresag01](https://github.com/andresag01)) 56 | 57 | ## [v1.0.0](https://github.com/ARMmbed/nrf51-sdk/tree/v1.0.0) (2015-12-02) 58 | [Full Changelog](https://github.com/ARMmbed/nrf51-sdk/compare/v0.0.1...v1.0.0) 59 | 60 | **Closed issues:** 61 | 62 | - Need to keep previous improvements while moving to nrf51-sdk [\#2](https://github.com/ARMmbed/nrf51-sdk/issues/2) 63 | 64 | **Merged pull requests:** 65 | 66 | - supress warnings for the sources in nRF51 SDK [\#6](https://github.com/ARMmbed/nrf51-sdk/pull/6) ([rgrover](https://github.com/rgrover)) 67 | 68 | ## [v0.0.1](https://github.com/ARMmbed/nrf51-sdk/tree/v0.0.1) (2015-12-01) 69 | [Full Changelog](https://github.com/ARMmbed/nrf51-sdk/compare/v8.1.0...v0.0.1) 70 | 71 | **Merged pull requests:** 72 | 73 | - Migrate changes from ble nrf51822 [\#4](https://github.com/ARMmbed/nrf51-sdk/pull/4) ([LiyouZhou](https://github.com/LiyouZhou)) 74 | 75 | ## [v8.1.0](https://github.com/ARMmbed/nrf51-sdk/tree/v8.1.0) (2015-11-17) 76 | 77 | 78 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Many of the files in this module have been inherited from the Nordic SDK for 2 | nRF51822; they come with a BSD-like license offered by Nordic for use in mbed. 3 | Some other files come from the mbed SDK, and are licensed under Apache-2.0. 4 | Unless specifically indicated otherwise in a file, files are licensed 5 | under the Apache 2.0 license, as can be found in: apache-2.0.txt. 6 | The BSD-like Nordic license can be found in BSD-3clause-Nordic.txt 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nrf51-sdk 2 | Module to contain files provided by the nordic nRF51 SDK. The latest version of this module uses files from Nordic SDK 10.0.0. The files are extracted from [here](https://developer.nordicsemi.com/nRF5_SDK/nRF51_SDK_v10.x.x/nRF51_SDK_10.0.0_dc26b5e.zip). 3 | 4 | ## Changes made to Nordic files 5 | The files are kept the same as much as possible to the Nordic SDK. Modifications are made in order to integrate with mbed. 6 | - ble/common/ble_conn_state.c: Preprocessor tests regarding S110, S120 or S130 macro should be replace by TARGET_MCU_NRF51_XXK_SXXX tests 7 | - `ble.h` in `source/nordic_sdk/components/softdevice/s130/headers/ble.h` has to be renamed `nrf_ble.h`. All files which include this file should be updated accordingly. 8 | 9 | 10 | ## Porting new versions of Nordic SDK 11 | A list of files currently requierd by mbed is maintained in [script/required_files.txt](https://github.com/ARMmbed/nrf51-sdk/blob/master/script/required_files.txt). [A python script](https://github.com/ARMmbed/nrf51-sdk/blob/master/script/pick_nrf51_files.py) is written to help porting from nordic sdk releases. **required_files.txt** is parsed to find a list of filenames. The script searches for these filenames in the sdk folder, and copy then into the yotta module mirroring the folder structure in the sdk. **extraIncludes** is automatically added to module.json to allow direct inclusion of noridc headers with just the filename. 12 | 13 | ### Script usage 14 | ``` 15 | python pick_nrf51_files.py [options] 16 | options: --purge : to delete all existing files and start again 17 | --dry-run : to list the files to be copied but not actually copy them 18 | ``` 19 | 20 | There are files in the sdk with the same filename but in different folder. This is dealt with by excluding certain directories. The excluded directories are listed in [pick_nrf51_files.py](https://github.com/ARMmbed/nrf51-sdk/blob/master/script/pick_nrf51_files.py). 21 | 22 | After running the script, the changes in [the previous section](#changes-made-to-nordic-files) will have to be applied manually again. 23 | 24 | Folder structure or even file name can change between releases of the nordic sdk, hence a degree of manual adjustment is needed when porting. 25 | 26 | ## Using Noridc Headers 27 | The nordic sdk is written in C and yotta modules support C++. If you are trying to include Nordic files in a cpp program, you need to use the `extern "C"` keyword around the includes. 28 | ```c 29 | extern "C" { 30 | #include "softdevice_handler.h" 31 | } 32 | ``` 33 | -------------------------------------------------------------------------------- /apache-2.0.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ARMmbed/nrf51-sdk/abf7875313726d9f3a5bc9483b43348692d92cd7/apache-2.0.txt -------------------------------------------------------------------------------- /module.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nrf51-sdk", 3 | "version": "2.4.0", 4 | "description": "Module to contain files provided by the nordic nRF51 SDK", 5 | "keywords": [ 6 | "nordic", 7 | "nrf51", 8 | "sdk" 9 | ], 10 | "author": "", 11 | "repository": { 12 | "url": "git@github.com:ARMmbed/nrf51-sdk.git", 13 | "type": "git" 14 | }, 15 | "license": "nordic", 16 | "targetDependencies": { 17 | "mbed-classic": { 18 | "mbed-classic": "~0.0.1" 19 | }, 20 | "mbed-os": { 21 | "mbed-drivers": "*" 22 | } 23 | }, 24 | "extraIncludes": [ 25 | "source/nordic_sdk/components/ble/ble_radio_notification", 26 | "source/nordic_sdk/components/ble/ble_services/ble_dfu", 27 | "source/nordic_sdk/components/ble/common", 28 | "source/nordic_sdk/components/ble/device_manager", 29 | "source/nordic_sdk/components/ble/device_manager/config", 30 | "source/nordic_sdk/components/ble/peer_manager", 31 | "source/nordic_sdk/components/device", 32 | "source/nordic_sdk/components/drivers_nrf/ble_flash", 33 | "source/nordic_sdk/components/drivers_nrf/delay", 34 | "source/nordic_sdk/components/drivers_nrf/hal", 35 | "source/nordic_sdk/components/drivers_nrf/pstorage", 36 | "source/nordic_sdk/components/drivers_nrf/pstorage/config", 37 | "source/nordic_sdk/components/libraries/bootloader_dfu", 38 | "source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport", 39 | "source/nordic_sdk/components/libraries/crc16", 40 | "source/nordic_sdk/components/libraries/hci", 41 | "source/nordic_sdk/components/libraries/scheduler", 42 | "source/nordic_sdk/components/libraries/timer", 43 | "source/nordic_sdk/components/libraries/util", 44 | "source/nordic_sdk/components/libraries/fds", 45 | "source/nordic_sdk/components/libraries/fstorage", 46 | "source/nordic_sdk/components/libraries/experimental_section_vars", 47 | "source/nordic_sdk/components/softdevice/common/softdevice_handler", 48 | "source/nordic_sdk/components/softdevice/s130/headers", 49 | "source/nordic_sdk/components/toolchain" 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /script/copyright_header.txt: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ -------------------------------------------------------------------------------- /script/pick_nrf51_files.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (c) 2015-2016 ARM Limited 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | import os, shutil, json, pprint, sys 19 | from collections import OrderedDict 20 | 21 | help_text = """ 22 | Usage: python {} [options] 23 | options: --purge : to delete all existing files and start again 24 | --dry-run : to list the files to be copied but not actually copy them 25 | """.format(os.path.basename(__file__)) 26 | 27 | # exclude path to avoid confusion over files of the same name 28 | exclude_path = ["examples", "SVD", "s110", "s120", "s210", "s310", "nrf_soc_nosd", "serialization/connectivity", 29 | 'components/libraries/hci/config', 'components/libraries/bootloader_dfu/ble_transport'] 30 | 31 | def find(name, path): 32 | paths = [] 33 | for root, dirs, files in os.walk(path): 34 | if True not in [x in root for x in exclude_path]: 35 | if name in files: 36 | paths.append(os.path.join(root, name)) 37 | 38 | if len(paths) == 0: 39 | print "-"*30 40 | print "Warning! No {} found!!!!".format(name) 41 | print "-"*30 42 | return None 43 | elif len(paths) > 1: 44 | print "-"*30 45 | print "Warning! More than one {} found!!!!".format(name) 46 | print paths 47 | print "-"*30 48 | return None 49 | else: 50 | return paths[0] 51 | 52 | def find_dir(dir_name, path): 53 | paths = [] 54 | for root, dirs, files in os.walk(path): 55 | if dir_name in root: 56 | for fn in files: 57 | paths.append(os.path.join(root, fn)) 58 | return paths 59 | 60 | if __name__ == "__main__": 61 | # define source and destination of copy 62 | arg_valid = True 63 | if len(sys.argv) not in [3, 4]: 64 | arg_valid = False 65 | else: 66 | src_folder = sys.argv[-2] 67 | yt_module_dir = sys.argv[-1] 68 | 69 | for d in [src_folder, yt_module_dir]: 70 | if not os.path.isdir(d): 71 | arg_valid = False 72 | print src_folder, "is not a folder" 73 | 74 | purge = ("--purge" in sys.argv) 75 | dry_run = ("--dry-run" in sys.argv) 76 | 77 | if not arg_valid: 78 | print help_text 79 | sys.exit(1) 80 | 81 | dst_folder = os.path.join(yt_module_dir, "source/nordic_sdk") 82 | 83 | # build a file_list from required_files.txt 84 | file_list = [] 85 | with open("required_files.txt", "r") as fd: 86 | for line in fd: 87 | line = line.strip() 88 | if line.startswith("D "): 89 | directory = line.split(" ")[-1] 90 | file_list += find_dir(directory, src_folder) 91 | elif not line.startswith("#") and line != '': 92 | fn = os.path.basename(line).strip() 93 | fn = find(fn, src_folder) 94 | file_list.append(fn) 95 | 96 | # remove everything from the destination folder 97 | if purge and not dry_run and os.path.exists(dst_folder): 98 | shutil.rmtree(dst_folder) 99 | 100 | # copy files 101 | extra_includes = [] 102 | for src in file_list: 103 | if src: 104 | rel_dst = os.path.relpath(src, src_folder) 105 | dst = os.path.join(dst_folder, rel_dst) 106 | print src, "->", dst 107 | 108 | directory = os.path.dirname(dst) 109 | if not os.path.exists(directory): 110 | print "Creating directory:", directory 111 | if not dry_run: 112 | os.makedirs(directory) 113 | if not os.path.isfile(dst): 114 | print "Copying file", dst 115 | if not dry_run: 116 | shutil.copyfile(src, dst) 117 | 118 | # build a list of extra includes to be added to module.json 119 | if dst.endswith(".h"): 120 | inc_rel_path = os.path.relpath(dst, yt_module_dir) 121 | inc_dir_path = os.path.dirname(inc_rel_path) 122 | if inc_dir_path not in extra_includes: 123 | extra_includes.append(inc_dir_path) 124 | 125 | # write extraIncludes in the module.json file 126 | mod_json = os.path.join(yt_module_dir, "module.json") 127 | print "-"*30 128 | print "Writing extra_includes to {}".format(mod_json) 129 | print "-"*30 130 | for n in sorted(extra_includes): 131 | print n 132 | 133 | if not dry_run: 134 | with open(mod_json, 'r+') as fd: 135 | jobj = json.loads(fd.read(), object_pairs_hook=OrderedDict) 136 | jobj['extraIncludes'] = sorted(extra_includes) 137 | jdump = json.dumps(jobj, indent=2, separators=(',', ': ')) 138 | fd.seek(0) 139 | fd.write(jdump) 140 | fd.write("\n") 141 | fd.truncate() 142 | -------------------------------------------------------------------------------- /script/replace_headers.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 ARM Limited 2 | # SPDX-License-Identifier: Apache-2.0 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | import os 17 | 18 | with open("copyright_header.txt", "r") as fd: 19 | header = fd.read() 20 | 21 | path = "../source/nordic_sdk" 22 | for root, dirs, files in os.walk(path): 23 | for fn in [os.path.join(root, x) for x in files]: 24 | with open(fn, "r+") as fd: 25 | print "+"*35 26 | print fn 27 | s = fd.read() 28 | start = s.find("/*") 29 | end = s.find("*/") 30 | copyright_str = s[start:end+2] 31 | if "copyright (c)" not in copyright_str.lower(): 32 | s = header + "\n\n" + s 33 | elif copyright_str is not header: 34 | s = s.replace(copyright_str, header) 35 | 36 | fd.seek(0) 37 | fd.write(s) 38 | fd.truncate() 39 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #include "ble_radio_notification.h" 34 | #include 35 | 36 | 37 | static bool m_radio_active = false; /**< Current radio state. */ 38 | static ble_radio_notification_evt_handler_t m_evt_handler = NULL; /**< Application event handler for handling Radio Notification events. */ 39 | 40 | 41 | void SWI1_IRQHandler(void) 42 | { 43 | m_radio_active = !m_radio_active; 44 | if (m_evt_handler != NULL) 45 | { 46 | m_evt_handler(m_radio_active); 47 | } 48 | } 49 | 50 | 51 | uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, 52 | nrf_radio_notification_distance_t distance, 53 | ble_radio_notification_evt_handler_t evt_handler) 54 | { 55 | uint32_t err_code; 56 | 57 | m_evt_handler = evt_handler; 58 | 59 | // Initialize Radio Notification software interrupt 60 | err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn); 61 | if (err_code != NRF_SUCCESS) 62 | { 63 | return err_code; 64 | } 65 | 66 | err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority); 67 | if (err_code != NRF_SUCCESS) 68 | { 69 | return err_code; 70 | } 71 | 72 | err_code = sd_nvic_EnableIRQ(SWI1_IRQn); 73 | if (err_code != NRF_SUCCESS) 74 | { 75 | return err_code; 76 | } 77 | 78 | // Configure the event 79 | return sd_radio_notification_cfg_set(NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH, distance); 80 | } 81 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/ble_radio_notification/ble_radio_notification.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup ble_radio_notification Radio Notification Event Handler 36 | * @{ 37 | * @ingroup ble_sdk_lib 38 | * @brief Module for propagating Radio Notification events to the application. 39 | */ 40 | 41 | #ifndef BLE_RADIO_NOTIFICATION_H__ 42 | #define BLE_RADIO_NOTIFICATION_H__ 43 | 44 | #include 45 | #include 46 | #include "nrf_soc.h" 47 | 48 | /**@brief Application radio notification event handler type. */ 49 | typedef void (*ble_radio_notification_evt_handler_t) (bool radio_active); 50 | 51 | /**@brief Function for initializing the Radio Notification module. 52 | * 53 | * @param[in] irq_priority Interrupt priority for the Radio Notification interrupt handler. 54 | * @param[in] distance The time from an Active event until the radio is activated. 55 | * @param[in] evt_handler Handler to be executed when a radio notification event has been 56 | * received. 57 | * 58 | * @return NRF_SUCCESS on successful initialization, otherwise an error code. 59 | */ 60 | uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, 61 | nrf_radio_notification_distance_t distance, 62 | ble_radio_notification_evt_handler_t evt_handler); 63 | 64 | #endif // BLE_RADIO_NOTIFICATION_H__ 65 | 66 | /** @} */ 67 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/common/ble_date_time.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /* Attention! 34 | * To maintain compliance with Nordic Semiconductor ASA's Bluetooth profile 35 | * qualification listings, this section of source code must not be modified. 36 | */ 37 | 38 | /** @file 39 | * @brief Contains definition of ble_date_time structure. 40 | */ 41 | 42 | /** @file 43 | * 44 | * @defgroup ble_sdk_srv_date_time BLE Date Time characteristic type 45 | * @{ 46 | * @ingroup ble_sdk_lib 47 | * @brief Definition of ble_date_time_t type. 48 | */ 49 | 50 | #ifndef BLE_DATE_TIME_H__ 51 | #define BLE_DATE_TIME_H__ 52 | 53 | #include 54 | 55 | /**@brief Date and Time structure. */ 56 | typedef struct 57 | { 58 | uint16_t year; 59 | uint8_t month; 60 | uint8_t day; 61 | uint8_t hours; 62 | uint8_t minutes; 63 | uint8_t seconds; 64 | } ble_date_time_t; 65 | 66 | static __INLINE uint8_t ble_date_time_encode(const ble_date_time_t * p_date_time, 67 | uint8_t * p_encoded_data) 68 | { 69 | uint8_t len = uint16_encode(p_date_time->year, p_encoded_data); 70 | 71 | p_encoded_data[len++] = p_date_time->month; 72 | p_encoded_data[len++] = p_date_time->day; 73 | p_encoded_data[len++] = p_date_time->hours; 74 | p_encoded_data[len++] = p_date_time->minutes; 75 | p_encoded_data[len++] = p_date_time->seconds; 76 | 77 | return len; 78 | } 79 | 80 | static __INLINE uint8_t ble_date_time_decode(ble_date_time_t * p_date_time, 81 | const uint8_t * p_encoded_data) 82 | { 83 | uint8_t len = sizeof(uint16_t); 84 | 85 | p_date_time->year = uint16_decode(p_encoded_data); 86 | p_date_time->month = p_encoded_data[len++]; 87 | p_date_time->day = p_encoded_data[len++]; 88 | p_date_time->hours = p_encoded_data[len++]; 89 | p_date_time->minutes = p_encoded_data[len++]; 90 | p_date_time->seconds = p_encoded_data[len++]; 91 | 92 | return len; 93 | } 94 | 95 | #endif // BLE_DATE_TIME_H__ 96 | 97 | /** @} */ 98 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/common/ble_gatt_db.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | #ifndef BLE_GATT_DB_H__ 35 | #define BLE_GATT_DB_H__ 36 | 37 | #include "stdint.h" 38 | #include "nrf_ble.h" 39 | #include "ble_gattc.h" 40 | 41 | #define BLE_GATT_DB_MAX_CHARS 4 /**< The maximum number of characteristics present in a service record. */ 42 | 43 | /**@brief Structure for holding the characteristic and the handle of its CCCD present on a server. 44 | */ 45 | typedef struct 46 | { 47 | ble_gattc_char_t characteristic; /**< Structure containing information about the characteristic. */ 48 | 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. */ 49 | } ble_gatt_db_char_t; 50 | 51 | /**@brief Structure for holding information about the service and the characteristics present on a 52 | * server. 53 | */ 54 | typedef struct 55 | { 56 | ble_uuid_t srv_uuid; /**< UUID of the service. */ 57 | uint8_t char_count; /**< Number of characteristics present in the service. */ 58 | ble_gattc_handle_range_t handle_range; /**< Service Handle Range. */ 59 | 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. */ 60 | } ble_gatt_db_srv_t; 61 | 62 | #endif /* BLE_GATT_DB_H__ */ 63 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/common/ble_sensor_location.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /* Attention! 34 | * To maintain compliance with Nordic Semiconductor ASA's Bluetooth profile 35 | * qualification listings, this section of source code must not be modified. 36 | */ 37 | 38 | #ifndef BLE_SENSOR_LOCATION_H__ 39 | #define BLE_SENSOR_LOCATION_H__ 40 | 41 | typedef enum { 42 | BLE_SENSOR_LOCATION_OTHER = 0 , /**<-- Other */ 43 | BLE_SENSOR_LOCATION_TOP_OF_SHOE = 1 , /**<-- Top of shoe */ 44 | BLE_SENSOR_LOCATION_IN_SHOE = 2 , /**<-- In shoe */ 45 | BLE_SENSOR_LOCATION_HIP = 3 , /**<-- Hip */ 46 | BLE_SENSOR_LOCATION_FRONT_WHEEL = 4 , /**<-- Front Wheel */ 47 | BLE_SENSOR_LOCATION_LEFT_CRANK = 5 , /**<-- Left Crank */ 48 | BLE_SENSOR_LOCATION_RIGHT_CRANK = 6 , /**<-- Right Crank */ 49 | BLE_SENSOR_LOCATION_LEFT_PEDAL = 7 , /**<-- Left Pedal */ 50 | BLE_SENSOR_LOCATION_RIGHT_PEDAL = 8 , /**<-- Right Pedal */ 51 | BLE_SENSOR_LOCATION_FRONT_HUB = 9 , /**<-- Front Hub */ 52 | BLE_SENSOR_LOCATION_REAR_DROPOUT = 10, /**<-- Rear Dropout */ 53 | BLE_SENSOR_LOCATION_CHAINSTAY = 11, /**<-- Chainstay */ 54 | BLE_SENSOR_LOCATION_REAR_WHEEL = 12, /**<-- Rear Wheel */ 55 | BLE_SENSOR_LOCATION_REAR_HUB = 13, /**<-- Rear Hub */ 56 | }ble_sensor_location_t; 57 | 58 | #define BLE_NB_MAX_SENSOR_LOCATIONS 14 59 | 60 | #endif // BLE_SENSOR_LOCATION_H__ 61 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/device_manager/config/device_manager_cnfg.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** 34 | * @file device_manager_cnfg.h 35 | * 36 | * @cond 37 | * @defgroup device_manager_cnfg Device Manager Configuration 38 | * @ingroup device_manager 39 | * @{ 40 | * 41 | * @brief Defines application specific configuration for Device Manager. 42 | * 43 | * @details All configurations that are specific to application have been defined 44 | * here. Application should configuration that best suits its requirements. 45 | */ 46 | 47 | #ifndef DEVICE_MANAGER_CNFG_H__ 48 | #define DEVICE_MANAGER_CNFG_H__ 49 | 50 | /** 51 | * @defgroup device_manager_inst Device Manager Instances 52 | * @{ 53 | */ 54 | /** 55 | * @brief Maximum applications that Device Manager can support. 56 | * 57 | * @details Maximum application that the Device Manager can support. 58 | * Currently only one application can be supported. 59 | * Minimum value : 1 60 | * Maximum value : 1 61 | * Dependencies : None. 62 | */ 63 | #define DEVICE_MANAGER_MAX_APPLICATIONS 1 64 | 65 | /** 66 | * @brief Maximum connections that Device Manager should simultaneously manage. 67 | * 68 | * @details Maximum connections that Device Manager should simultaneously manage. 69 | * Minimum value : 1 70 | * Maximum value : Maximum links supported by SoftDevice. 71 | * Dependencies : None. 72 | */ 73 | #define DEVICE_MANAGER_MAX_CONNECTIONS 1 74 | 75 | 76 | /** 77 | * @brief Maximum bonds that Device Manager should manage. 78 | * 79 | * @details Maximum bonds that Device Manager should manage. 80 | * Minimum value : 1 81 | * Maximum value : 254. 82 | * Dependencies : None. 83 | * @note In case of GAP Peripheral role, the Device Manager will accept bonding procedure 84 | * requests from peers even if this limit is reached, but bonding information will not 85 | * be stored. In such cases, application will be notified with DM_DEVICE_CONTEXT_FULL 86 | * as event result at the completion of the security procedure. 87 | */ 88 | #define DEVICE_MANAGER_MAX_BONDS 2 89 | 90 | 91 | /** 92 | * @brief Maximum Characteristic Client Descriptors used for GATT Server. 93 | * 94 | * @details Maximum Characteristic Client Descriptors used for GATT Server. 95 | * Minimum value : 1 96 | * Maximum value : 254. 97 | * Dependencies : None. 98 | */ 99 | #define DM_GATT_CCCD_COUNT 2 100 | 101 | 102 | /** 103 | * @brief Size of application context. 104 | * 105 | * @details Size of application context that Device Manager should manage for each bonded device. 106 | * Size had to be a multiple of word size. 107 | * Minimum value : 4. 108 | * Maximum value : 256. 109 | * Dependencies : Needed only if Application Context saving is used by the application. 110 | * @note If set to zero, its an indication that application context is not required to be managed 111 | * by the module. 112 | */ 113 | #define DEVICE_MANAGER_APP_CONTEXT_SIZE 0 114 | 115 | /* @} */ 116 | /* @} */ 117 | /** @endcond */ 118 | #endif // DEVICE_MANAGER_CNFG_H__ 119 | 120 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/peer_manager/peer_data.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | #ifndef PEER_DATA_H__ 35 | #define PEER_DATA_H__ 36 | 37 | #include 38 | #include "peer_manager_types.h" 39 | #include "fds.h" 40 | 41 | 42 | /** 43 | * @defgroup peer_data Peer Data 44 | * @ingroup peer_manager 45 | * @{ 46 | * @brief An internal module of @ref peer_manager. This module defines the structure of the data 47 | * that is managed by the @ref peer_manager. It also provides functions for parsing the data. 48 | */ 49 | 50 | 51 | /**@brief Function for enumerating the separate (non-contiguous) parts of the peer data. 52 | * 53 | * @param[in] p_peer_data The peer data to enumerate. 54 | * @param[out] p_chunks The resulting chunks. This must be an array of at least 2 elements. 55 | * @param[out] p_n_chunks The number of chunks. If this is 0, something went wrong. 56 | */ 57 | void peer_data_parts_get(pm_peer_data_const_t const * p_peer_data, fds_record_chunk_t * p_chunks, uint16_t * p_n_chunks); 58 | 59 | 60 | /**@brief Function for converting @ref pm_peer_data_flash_t into @ref pm_peer_data_t. 61 | * 62 | * @param[in] p_in_data The source data. 63 | * @param[out] p_out_data The target data structure. 64 | * 65 | * @retval NRF_SUCCESS Successful conversion. 66 | * @retval NRF_ERROR_NULL A parameter was NULL. 67 | * @retval NRF_ERROR_NO_MEM A buffer was not large enough. 68 | */ 69 | ret_code_t peer_data_deserialize(pm_peer_data_flash_t const * p_in_data, pm_peer_data_t * p_out_data); 70 | 71 | /** @} */ 72 | 73 | #endif /* PEER_DATA_H__ */ 74 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/peer_manager/peer_id.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | #include "peer_id.h" 35 | 36 | #include 37 | #include 38 | #include "sdk_errors.h" 39 | #include "peer_manager_types.h" 40 | #include "pm_mutex.h" 41 | 42 | 43 | typedef struct 44 | { 45 | uint8_t peer_ids[MUTEX_STORAGE_SIZE(PM_PEER_ID_N_AVAILABLE_IDS)]; /*< bitmap. */ 46 | } pi_t; 47 | 48 | 49 | static pi_t m_pi = {.peer_ids = {0}}; 50 | 51 | 52 | static void internal_state_reset(pi_t * p_pi) 53 | { 54 | memset(p_pi, 0, sizeof(pi_t)); 55 | } 56 | 57 | 58 | void peer_id_init(void) 59 | { 60 | internal_state_reset(&m_pi); 61 | pm_mutex_init(m_pi.peer_ids, PM_PEER_ID_N_AVAILABLE_IDS); 62 | } 63 | 64 | 65 | pm_peer_id_t peer_id_allocate(pm_peer_id_t peer_id) 66 | { 67 | pm_peer_id_t allocated_peer_id = PM_PEER_ID_INVALID; 68 | if (peer_id == PM_PEER_ID_INVALID) 69 | { 70 | allocated_peer_id = pm_mutex_lock_first_available(m_pi.peer_ids, PM_PEER_ID_N_AVAILABLE_IDS); 71 | if (allocated_peer_id == PM_PEER_ID_N_AVAILABLE_IDS) 72 | { 73 | allocated_peer_id = PM_PEER_ID_INVALID; 74 | } 75 | } 76 | else if (peer_id < PM_PEER_ID_N_AVAILABLE_IDS) 77 | { 78 | bool lock_success = pm_mutex_lock(m_pi.peer_ids, peer_id); 79 | allocated_peer_id = lock_success ? peer_id : PM_PEER_ID_INVALID; 80 | } 81 | return allocated_peer_id; 82 | } 83 | 84 | 85 | void peer_id_free(pm_peer_id_t peer_id) 86 | { 87 | if (peer_id < PM_PEER_ID_N_AVAILABLE_IDS) 88 | { 89 | pm_mutex_unlock(m_pi.peer_ids, peer_id); 90 | } 91 | } 92 | 93 | 94 | bool peer_id_is_allocated(pm_peer_id_t peer_id) 95 | { 96 | if (peer_id < PM_PEER_ID_N_AVAILABLE_IDS) 97 | { 98 | return pm_mutex_lock_status_get(m_pi.peer_ids, peer_id); 99 | } 100 | return false; 101 | } 102 | 103 | 104 | pm_peer_id_t peer_id_next_id_get(pm_peer_id_t prev_peer_id) 105 | { 106 | pm_peer_id_t i = (prev_peer_id == PM_PEER_ID_INVALID) ? 0 : (prev_peer_id + 1); 107 | for (; i < PM_PEER_ID_N_AVAILABLE_IDS; i++) 108 | { 109 | if (pm_mutex_lock_status_get(m_pi.peer_ids, i)) 110 | { 111 | return i; 112 | } 113 | } 114 | 115 | return PM_PEER_ID_INVALID; 116 | } 117 | 118 | 119 | uint32_t peer_id_n_ids(void) 120 | { 121 | uint32_t n_ids = 0; 122 | 123 | for (pm_peer_id_t i = 0; i < PM_PEER_ID_N_AVAILABLE_IDS; i++) 124 | { 125 | n_ids += pm_mutex_lock_status_get(m_pi.peer_ids, i); 126 | } 127 | 128 | return n_ids; 129 | } 130 | 131 | 132 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/peer_manager/peer_id.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | #ifndef PEER_ID_H__ 35 | #define PEER_ID_H__ 36 | 37 | 38 | #include "stdint.h" 39 | #include "sdk_errors.h" 40 | #include "ble_gap.h" 41 | #include "peer_manager_types.h" 42 | 43 | 44 | /** 45 | * @defgroup peer_id Peer IDs 46 | * @ingroup peer_manager 47 | * @{ 48 | * @brief An internal module of @ref peer_manager. This module keeps track of which peer IDs are in 49 | * use and which are free. 50 | */ 51 | 52 | 53 | /**@brief Function for initializing the module. 54 | */ 55 | void peer_id_init(void); 56 | 57 | 58 | /**@brief Function for claiming an unused peer ID. 59 | * 60 | * @param peer_id The peer ID to allocate. If this is @ref PM_PEER_ID_INVALID, the first available 61 | * will be allocated. 62 | * 63 | * @return The allocated peer ID. 64 | * @retval PM_PEER_ID_INVALID If no peer ID could be allocated or module is not initialized. 65 | */ 66 | pm_peer_id_t peer_id_allocate(pm_peer_id_t peer_id); 67 | 68 | 69 | /**@brief Function for freeing a peer ID and clearing all data associated with it in persistent 70 | * storage. 71 | * 72 | * @param[in] peer_id Peer ID to free. 73 | */ 74 | void peer_id_free(pm_peer_id_t peer_id); 75 | 76 | 77 | /**@brief Function for finding out whether a peer ID is in use. 78 | * 79 | * @param[in] peer_id The peer ID to inquire about. 80 | * 81 | * @retval true peer_id is in use. 82 | * @retval false peer_id is free, or the module is not initialized. 83 | */ 84 | bool peer_id_is_allocated(pm_peer_id_t peer_id); 85 | 86 | 87 | /**@brief Function for getting the next peer ID in the sequence of all used peer IDs. Can be 88 | * used to loop through all used peer IDs. 89 | * 90 | * @note @ref PM_PEER_ID_INVALID is considered to be before the first and after the last ordinary 91 | * peer ID. 92 | * 93 | * @param[in] prev_peer_id The previous peer ID. 94 | * 95 | * @return The next peer ID. 96 | * @return The first used peer ID if prev_peer_id was @ref PM_PEER_ID_INVALID. 97 | * @retval PM_PEER_ID_INVALID if prev_peer_id was the last ordinary peer ID or the module is 98 | * not initialized. 99 | */ 100 | pm_peer_id_t peer_id_next_id_get(pm_peer_id_t prev_peer_id); 101 | 102 | 103 | /**@brief Function for querying the number of valid peer IDs available. I.E the number of peers 104 | * in persistent storage. 105 | * 106 | * @return The number of valid peer IDs, or 0 if module is not initialized. 107 | */ 108 | uint32_t peer_id_n_ids(void); 109 | 110 | /** @} */ 111 | 112 | #endif /* PEER_ID_H__ */ 113 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/peer_manager/pm_buffer.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | #include "pm_buffer.h" 35 | 36 | #include 37 | #include 38 | #include "nrf_error.h" 39 | #include "pm_mutex.h" 40 | 41 | 42 | #define BUFFER_IS_VALID(p_buffer) ((p_buffer != NULL) \ 43 | && (p_buffer->p_memory != NULL) \ 44 | && (p_buffer->p_mutex != NULL)) 45 | 46 | 47 | 48 | ret_code_t pm_buffer_init(pm_buffer_t * p_buffer, 49 | uint8_t * p_buffer_memory, 50 | uint32_t buffer_memory_size, 51 | uint8_t * p_mutex_memory, 52 | uint32_t mutex_memory_size, 53 | uint32_t n_blocks, 54 | uint32_t block_size) 55 | { 56 | if ( (p_buffer != NULL) 57 | && (p_buffer_memory != NULL) 58 | && (p_mutex_memory != NULL) 59 | && (buffer_memory_size >= (n_blocks*block_size)) 60 | && (mutex_memory_size >= MUTEX_STORAGE_SIZE(n_blocks)) 61 | && (n_blocks != 0) 62 | && (block_size != 0)) 63 | { 64 | p_buffer->p_memory = p_buffer_memory; 65 | p_buffer->p_mutex = p_mutex_memory; 66 | p_buffer->n_blocks = n_blocks; 67 | p_buffer->block_size = block_size; 68 | pm_mutex_init(p_buffer->p_mutex, n_blocks); 69 | 70 | return NRF_SUCCESS; 71 | } 72 | else 73 | { 74 | return NRF_ERROR_INVALID_PARAM; 75 | } 76 | } 77 | 78 | 79 | uint8_t pm_buffer_block_acquire(pm_buffer_t * p_buffer, uint32_t n_blocks) 80 | { 81 | if (!BUFFER_IS_VALID(p_buffer)) 82 | { 83 | return ( BUFFER_INVALID_ID ); 84 | } 85 | 86 | uint8_t first_locked_mutex = BUFFER_INVALID_ID; 87 | 88 | for (uint8_t i = 0; i < p_buffer->n_blocks; i++) 89 | { 90 | if (pm_mutex_lock(p_buffer->p_mutex, i)) 91 | { 92 | if (first_locked_mutex == BUFFER_INVALID_ID) 93 | { 94 | first_locked_mutex = i; 95 | } 96 | if ((i - first_locked_mutex + 1) == n_blocks) 97 | { 98 | return first_locked_mutex; 99 | } 100 | } 101 | else if (first_locked_mutex != BUFFER_INVALID_ID) 102 | { 103 | for (uint8_t j = first_locked_mutex; j < i; j++) 104 | { 105 | pm_buffer_release(p_buffer, j); 106 | } 107 | first_locked_mutex = BUFFER_INVALID_ID; 108 | } 109 | } 110 | 111 | return ( BUFFER_INVALID_ID ); 112 | } 113 | 114 | 115 | uint8_t * pm_buffer_ptr_get(pm_buffer_t * p_buffer, uint8_t id) 116 | { 117 | if (!BUFFER_IS_VALID(p_buffer)) 118 | { 119 | return ( NULL ); 120 | } 121 | 122 | if ( (id != BUFFER_INVALID_ID) 123 | && pm_mutex_lock_status_get(p_buffer->p_mutex, id) ) 124 | { 125 | return ( &p_buffer->p_memory[id*p_buffer->block_size] ); 126 | } 127 | else 128 | { 129 | return ( NULL ); 130 | } 131 | } 132 | 133 | 134 | void pm_buffer_release(pm_buffer_t * p_buffer, uint8_t id) 135 | { 136 | if ( BUFFER_IS_VALID(p_buffer) 137 | && (id != BUFFER_INVALID_ID) 138 | && pm_mutex_lock_status_get(p_buffer->p_mutex, id)) 139 | { 140 | pm_mutex_unlock(p_buffer->p_mutex, id); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/peer_manager/pm_buffer.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | #ifndef BUFFER_H__ 35 | #define BUFFER_H__ 36 | 37 | #include 38 | #include "sdk_errors.h" 39 | #include "pm_mutex.h" 40 | 41 | 42 | /** 43 | * @defgroup pm_buffer Buffer 44 | * @ingroup peer_manager 45 | * @{ 46 | * @brief An internal module of @ref peer_manager. This module provides a simple buffer. 47 | */ 48 | 49 | 50 | #define BUFFER_INVALID_ID 0xFF 51 | 52 | #define PM_BUFFER_INIT(p_buffer, n_blocks, block_size, err_code) \ 53 | do \ 54 | { \ 55 | static uint8_t buffer_memory[(n_blocks) * (block_size)]; \ 56 | static uint8_t mutex_memory[MUTEX_STORAGE_SIZE(n_blocks)]; \ 57 | err_code = pm_buffer_init((p_buffer), \ 58 | buffer_memory, \ 59 | (n_blocks) * (block_size), \ 60 | mutex_memory, \ 61 | MUTEX_STORAGE_SIZE(n_blocks), \ 62 | (n_blocks), \ 63 | (block_size)); \ 64 | } while(0) 65 | 66 | 67 | typedef struct 68 | { 69 | uint8_t * p_memory; /**< The storage for all buffer entries. The size of the buffer must be n_blocks*block_size. */ 70 | uint8_t * p_mutex; /**< A mutex group with one mutex for each buffer entry. */ 71 | uint32_t n_blocks; /**< The number of allocatable blocks in the buffer. */ 72 | uint32_t block_size; /**< The size of each block in the buffer. */ 73 | } pm_buffer_t; 74 | 75 | /**@brief Function for initializing a buffer instance. 76 | * 77 | * @param[out] p_buffer The buffer instance to initialize. 78 | * @param[in] p_buffer_memory The memory this buffer will use. 79 | * @param[in] buffer_memory_size The size of p_buffer_memory. This must be at least 80 | * n_blocks*block_size. 81 | * @param[in] p_mutex_memory The memory for the mutexes. This must be at least 82 | * @ref MUTEX_STORAGE_SIZE(n_blocks). 83 | * @param[in] mutex_memory_size The size of p_mutex_memory. 84 | * @param[in] n_blocks The number of blocks in the buffer. 85 | * @param[in] block_size The size of each block. 86 | * 87 | * @retval NRF_SUCCESS Successfully initialized buffer instance. 88 | * @retval NRF_ERROR_INVALID_PARAM A parameter was 0 or NULL or a size was too small. 89 | */ 90 | ret_code_t pm_buffer_init(pm_buffer_t * p_buffer, 91 | uint8_t * p_buffer_memory, 92 | uint32_t buffer_memory_size, 93 | uint8_t * p_mutex_memory, 94 | uint32_t mutex_memory_size, 95 | uint32_t n_blocks, 96 | uint32_t block_size); 97 | 98 | 99 | /**@brief Function for acquiring a buffer block in a buffer. 100 | * 101 | * @param[in] p_buffer The buffer instance acquire from. 102 | * @param[in] n_blocks The number of contiguous blocks to acquire. 103 | * 104 | * @return The id of the acquired block, if successful. 105 | * @retval BUFFER_INVALID_ID If unsuccessful. 106 | */ 107 | uint8_t pm_buffer_block_acquire(pm_buffer_t * p_buffer, uint32_t n_blocks); 108 | 109 | 110 | /**@brief Function for getting a pointer to a specific buffer block. 111 | * 112 | * @param[in] p_buffer The buffer instance get from. 113 | * @param[in] id The id of the buffer to get the pointer for. 114 | * 115 | * @return A pointer to the buffer for the specified id, if the id is valid. 116 | * @retval NULL If the id is invalid. 117 | */ 118 | uint8_t * pm_buffer_ptr_get(pm_buffer_t * p_buffer, uint8_t id); 119 | 120 | 121 | /**@brief Function for releasing a buffer block. 122 | * 123 | * @param[in] p_buffer The buffer instance containing the block to release. 124 | * @param[in] id The id of the block to release. 125 | */ 126 | void pm_buffer_release(pm_buffer_t * p_buffer, uint8_t id); 127 | 128 | 129 | #endif // BUFFER_H__ 130 | 131 | /** 132 | * @} 133 | */ 134 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/peer_manager/pm_mutex.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | #include "pm_mutex.h" 35 | 36 | #include 37 | #include 38 | #include "nrf_error.h" 39 | #include "app_util_platform.h" 40 | 41 | 42 | 43 | /**@brief Locks the mutex defined by the mask. 44 | * 45 | * @param p_mutex pointer to the mutex storage. 46 | * @param mutex_mask the mask identifying the mutex position. 47 | * 48 | * @retval true if the mutex could be locked. 49 | * @retval false if the mutex was already locked. 50 | */ 51 | static bool lock_by_mask(uint8_t * p_mutex, uint8_t mutex_mask) 52 | { 53 | bool success = false; 54 | 55 | if ( (*p_mutex & mutex_mask) == 0 ) 56 | { 57 | CRITICAL_REGION_ENTER(); 58 | if ( (*p_mutex & mutex_mask) == 0 ) 59 | { 60 | *p_mutex |= mutex_mask; 61 | 62 | success = true; 63 | } 64 | CRITICAL_REGION_EXIT(); 65 | } 66 | 67 | return ( success ); 68 | } 69 | 70 | 71 | void pm_mutex_init(uint8_t * p_mutex, uint16_t mutex_size) 72 | { 73 | if (p_mutex != NULL) 74 | { 75 | memset(&p_mutex[0], 0, MUTEX_STORAGE_SIZE(mutex_size)); 76 | } 77 | } 78 | 79 | 80 | bool pm_mutex_lock(uint8_t * p_mutex, uint16_t mutex_id) 81 | { 82 | if (p_mutex != NULL) 83 | { 84 | return ( lock_by_mask(&(p_mutex[mutex_id >> 3]), (1 << (mutex_id & 0x07))) ); 85 | } 86 | else 87 | { 88 | return false; 89 | } 90 | } 91 | 92 | 93 | void pm_mutex_unlock(uint8_t * p_mutex, uint16_t mutex_id) 94 | { 95 | uint8_t mutex_base = mutex_id >> 3; 96 | uint8_t mutex_mask = (1 << (mutex_id & 0x07)); 97 | 98 | if ((p_mutex != NULL) 99 | && (p_mutex[mutex_base] & mutex_mask)) 100 | { 101 | CRITICAL_REGION_ENTER(); 102 | p_mutex[mutex_base] &= ~mutex_mask; 103 | CRITICAL_REGION_EXIT(); 104 | } 105 | } 106 | 107 | 108 | uint16_t pm_mutex_lock_first_available(uint8_t * p_mutex, uint16_t mutex_size) 109 | { 110 | if (p_mutex != NULL) 111 | { 112 | for ( uint16_t i = 0; i < mutex_size; i++ ) 113 | { 114 | if ( lock_by_mask(&(p_mutex[i >> 3]), 1 << (i & 0x07)) ) 115 | { 116 | return ( i ); 117 | } 118 | } 119 | } 120 | 121 | return ( mutex_size ); 122 | } 123 | 124 | 125 | bool pm_mutex_lock_status_get(uint8_t * p_mutex, uint16_t mutex_id) 126 | { 127 | if (p_mutex != NULL) 128 | { 129 | return ( (p_mutex[mutex_id >> 3] & (1 << (mutex_id & 0x07))) ); 130 | } 131 | else 132 | { 133 | return true; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/ble/peer_manager/pm_mutex.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | 34 | 35 | #ifndef MUTEX_H__ 36 | #define MUTEX_H__ 37 | 38 | 39 | #include 40 | #include 41 | 42 | /** 43 | * @defgroup pm_mutex Mutex 44 | * @ingroup peer_manager 45 | * @{ 46 | * @brief An internal module of @ref peer_manager. This module provides thread-safe mutexes. 47 | */ 48 | 49 | 50 | /**@brief Defines the storage size of a specified mutex group. 51 | * 52 | * @param number_of_mutexes the number of mutexes in the group. 53 | */ 54 | #define MUTEX_STORAGE_SIZE(number_of_mutexes) ((7 + (number_of_mutexes)) >> 3) 55 | 56 | 57 | /**@brief Initializes a mutex group. 58 | * 59 | * @param[in] p_mutex Pointer to the mutex group. See @ref MUTEX_STORAGE_SIZE(). 60 | * @param[in] mutex_size The size of the mutex group in number of mutexes. 61 | */ 62 | void pm_mutex_init(uint8_t * p_mutex, uint16_t mutex_size); 63 | 64 | 65 | /**@brief Locks the mutex specified by the bit id. 66 | * 67 | * @param[inout] p_mutex Pointer to the mutex group. 68 | * @param[in] mutex_bit_id The bit id of the mutex. 69 | * 70 | * @retval true if it was possible to lock the mutex. 71 | * @retval false otherwise. 72 | */ 73 | bool pm_mutex_lock(uint8_t * p_mutex, uint16_t mutex_bit_id); 74 | 75 | 76 | /**@brief Locks the first unlocked mutex within the mutex group. 77 | * 78 | * @param[in, out] p_mutex Pointer to the mutex group. 79 | * @param[in] mutex_size The size of the mutex group. 80 | * 81 | * @return The first unlocked mutex id in the group. 82 | * @retval group-size if there was no unlocked mutex available. 83 | */ 84 | uint16_t pm_mutex_lock_first_available(uint8_t * p_mutex, uint16_t mutex_size); 85 | 86 | 87 | /**@brief Unlocks the mutex specified by the bit id. 88 | * 89 | * @param[in, out] p_mutex Pointer to the mutex group. 90 | * @param[in] mutex_bit_id The bit id of the mutex. 91 | */ 92 | void pm_mutex_unlock(uint8_t * p_mutex, uint16_t mutex_bit_id); 93 | 94 | 95 | /**@brief Gets the locking status of the specified mutex. 96 | * 97 | * @param[in, out] p_mutex Pointer to the mutex group. 98 | * @param[in] mutex_bit_id The bit id of the mutex. 99 | * 100 | * @retval true if the mutex was locked. 101 | * @retval false otherwise. 102 | */ 103 | bool pm_mutex_lock_status_get(uint8_t * p_mutex, uint16_t mutex_bit_id); 104 | 105 | 106 | #endif // MUTEX_H__ 107 | 108 | /** @} */ 109 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/device/compiler_abstraction.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | #ifndef _COMPILER_ABSTRACTION_H 33 | #define _COMPILER_ABSTRACTION_H 34 | 35 | /*lint ++flb "Enter library region" */ 36 | 37 | #if defined ( __CC_ARM ) 38 | 39 | #ifndef __ASM 40 | #define __ASM __asm 41 | #endif 42 | 43 | #ifndef __INLINE 44 | #define __INLINE __inline 45 | #endif 46 | 47 | #ifndef __WEAK 48 | #define __WEAK __weak 49 | #endif 50 | 51 | #ifndef __ALIGN 52 | #define __ALIGN(n) __align(n) 53 | #endif 54 | 55 | #define GET_SP() __current_sp() 56 | 57 | #elif defined ( __ICCARM__ ) 58 | 59 | #ifndef __ASM 60 | #define __ASM __asm 61 | #endif 62 | 63 | #ifndef __INLINE 64 | #define __INLINE inline 65 | #endif 66 | 67 | #ifndef __WEAK 68 | #define __WEAK __weak 69 | #endif 70 | 71 | /* Not defined for IAR since it requires a new line to work, and C preprocessor does not allow that. */ 72 | #ifndef __ALIGN 73 | #define __ALIGN(n) 74 | #endif 75 | 76 | #define GET_SP() __get_SP() 77 | 78 | #elif defined ( __GNUC__ ) 79 | 80 | #ifndef __ASM 81 | #define __ASM __asm 82 | #endif 83 | 84 | #ifndef __INLINE 85 | #define __INLINE inline 86 | #endif 87 | 88 | #ifndef __WEAK 89 | #define __WEAK __attribute__((weak)) 90 | #endif 91 | 92 | #ifndef __ALIGN 93 | #define __ALIGN(n) __attribute__((aligned(n))) 94 | #endif 95 | 96 | #define GET_SP() gcc_current_sp() 97 | 98 | static inline unsigned int gcc_current_sp(void) 99 | { 100 | register unsigned sp __ASM("sp"); 101 | return sp; 102 | } 103 | 104 | #elif defined ( __TASKING__ ) 105 | 106 | #ifndef __ASM 107 | #define __ASM __asm 108 | #endif 109 | 110 | #ifndef __INLINE 111 | #define __INLINE inline 112 | #endif 113 | 114 | #ifndef __WEAK 115 | #define __WEAK __attribute__((weak)) 116 | #endif 117 | 118 | #ifndef __ALIGN 119 | #define __ALIGN(n) __align(n) 120 | #endif 121 | 122 | #define GET_SP() __get_MSP() 123 | 124 | #endif 125 | 126 | /*lint --flb "Leave library region" */ 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/device/nrf.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef NRF_H 34 | #define NRF_H 35 | 36 | #if defined(_WIN32) 37 | /* Do not include nrf51 specific files when building for PC host */ 38 | #elif defined(__unix) 39 | /* Do not include nrf51 specific files when building for PC host */ 40 | #elif defined(__APPLE__) 41 | /* Do not include nrf51 specific files when building for PC host */ 42 | #else 43 | 44 | /* Family selection for family includes. */ 45 | #if defined (NRF51) 46 | #include "nrf51.h" 47 | #include "nrf51_bitfields.h" 48 | #include "nrf51_deprecated.h" 49 | #elif defined (NRF52) 50 | #include "nrf52.h" 51 | #include "nrf52_bitfields.h" 52 | #include "nrf51_to_nrf52.h" 53 | #else 54 | #error "Device family must be defined. See nrf.h." 55 | #endif /* NRF51, NRF52 */ 56 | 57 | #include "compiler_abstraction.h" 58 | 59 | #endif /* _WIN32 || __unix || __APPLE__ */ 60 | 61 | #endif /* NRF_H */ 62 | 63 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/drivers_nrf/delay/nrf_delay.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #include 34 | #include "compiler_abstraction.h" 35 | #include "nrf.h" 36 | #include "nrf_delay.h" 37 | 38 | /*lint --e{438} "Variable not used" */ 39 | void nrf_delay_ms(uint32_t volatile number_of_ms) 40 | { 41 | while(number_of_ms != 0) 42 | { 43 | number_of_ms--; 44 | nrf_delay_us(999); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/drivers_nrf/hal/nrf_ecb.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** 34 | * @file 35 | * @brief Implementation of AES ECB driver 36 | */ 37 | 38 | 39 | //lint -e438 40 | 41 | #include 42 | #include 43 | #include 44 | #include "nrf.h" 45 | #include "nrf_ecb.h" 46 | 47 | static uint8_t ecb_data[48]; ///< ECB data structure for RNG peripheral to access. 48 | static uint8_t* ecb_key; ///< Key: Starts at ecb_data 49 | static uint8_t* ecb_cleartext; ///< Cleartext: Starts at ecb_data + 16 bytes. 50 | static uint8_t* ecb_ciphertext; ///< Ciphertext: Starts at ecb_data + 32 bytes. 51 | 52 | bool nrf_ecb_init(void) 53 | { 54 | ecb_key = ecb_data; 55 | ecb_cleartext = ecb_data + 16; 56 | ecb_ciphertext = ecb_data + 32; 57 | 58 | NRF_ECB->ECBDATAPTR = (uint32_t)ecb_data; 59 | return true; 60 | } 61 | 62 | 63 | bool nrf_ecb_crypt(uint8_t * dest_buf, const uint8_t * src_buf) 64 | { 65 | uint32_t counter = 0x1000000; 66 | if(src_buf != ecb_cleartext) 67 | { 68 | memcpy(ecb_cleartext,src_buf,16); 69 | } 70 | NRF_ECB->EVENTS_ENDECB = 0; 71 | NRF_ECB->TASKS_STARTECB = 1; 72 | while(NRF_ECB->EVENTS_ENDECB == 0) 73 | { 74 | counter--; 75 | if(counter == 0) 76 | { 77 | return false; 78 | } 79 | } 80 | NRF_ECB->EVENTS_ENDECB = 0; 81 | if(dest_buf != ecb_ciphertext) 82 | { 83 | memcpy(dest_buf,ecb_ciphertext,16); 84 | } 85 | return true; 86 | } 87 | 88 | void nrf_ecb_set_key(const uint8_t * key) 89 | { 90 | memcpy(ecb_key,key,16); 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/drivers_nrf/hal/nrf_ecb.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** 34 | * @file 35 | * @brief ECB driver API. 36 | */ 37 | 38 | #ifndef NRF_ECB_H__ 39 | #define NRF_ECB_H__ 40 | 41 | /** 42 | * @defgroup nrf_ecb AES ECB encryption 43 | * @{ 44 | * @ingroup nrf_drivers 45 | * @brief Driver for the AES Electronic Code Book (ECB) peripheral. 46 | * 47 | * To encrypt and decrypt data, the peripheral must first be powered on 48 | * using @ref nrf_ecb_init. Next, the key must be set using @ref nrf_ecb_set_key. 49 | */ 50 | 51 | #include 52 | 53 | /** 54 | * @brief Function for initializing and powering on the ECB peripheral. 55 | * 56 | * This function allocates memory for the ECBDATAPTR. 57 | * @retval true If initialization was successful. 58 | * @retval false If powering on failed. 59 | */ 60 | bool nrf_ecb_init(void); 61 | 62 | /** 63 | * @brief Function for encrypting and decrypting 16-byte data using current key. 64 | * 65 | * This function avoids unnecessary copying of data if the parameters point to the 66 | * correct locations in the ECB data structure. 67 | * 68 | * @param dst Result of encryption/decryption. 16 bytes will be written. 69 | * @param src Source with 16-byte data to be encrypted/decrypted. 70 | * 71 | * @retval true If the encryption operation completed. 72 | * @retval false If the encryption operation did not complete. 73 | */ 74 | bool nrf_ecb_crypt(uint8_t * dst, const uint8_t * src); 75 | 76 | /** 77 | * @brief Function for setting the key to be used for encryption and decryption. 78 | * 79 | * @param key Pointer to the key. 16 bytes will be read. 80 | */ 81 | void nrf_ecb_set_key(const uint8_t * key); 82 | 83 | #endif // NRF_ECB_H__ 84 | 85 | /** @} */ 86 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/drivers_nrf/hal/nrf_nvmc.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** 34 | *@file 35 | *@brief NMVC driver implementation 36 | */ 37 | 38 | #include "stdbool.h" 39 | #include "nrf.h" 40 | #include "nrf_nvmc.h" 41 | 42 | 43 | void nrf_nvmc_page_erase(uint32_t address) 44 | { 45 | // Enable erase. 46 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een; 47 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 48 | { 49 | } 50 | 51 | // Erase the page 52 | NRF_NVMC->ERASEPAGE = address; 53 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 54 | { 55 | } 56 | 57 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; 58 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 59 | { 60 | } 61 | } 62 | 63 | 64 | void nrf_nvmc_write_byte(uint32_t address, uint8_t value) 65 | { 66 | uint32_t byte_shift = address & (uint32_t)0x03; 67 | uint32_t address32 = address & ~byte_shift; // Address to the word this byte is in. 68 | uint32_t value32 = (*(uint32_t*)address32 & ~((uint32_t)0xFF << (byte_shift << (uint32_t)3))); 69 | value32 = value32 + ((uint32_t)value << (byte_shift << 3)); 70 | 71 | // Enable write. 72 | NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos); 73 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 74 | { 75 | } 76 | 77 | *(uint32_t*)address32 = value32; 78 | while(NRF_NVMC->READY == NVMC_READY_READY_Busy) 79 | { 80 | } 81 | 82 | NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos); 83 | { 84 | } 85 | } 86 | 87 | void nrf_nvmc_write_word(uint32_t address, uint32_t value) 88 | { 89 | // Enable write. 90 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; 91 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){ 92 | } 93 | 94 | *(uint32_t*)address = value; 95 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy){ 96 | } 97 | 98 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; 99 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 100 | { 101 | } 102 | } 103 | 104 | void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes) 105 | { 106 | uint32_t i; 107 | for(i=0;iCONFIG = NVMC_CONFIG_WEN_Wen; 119 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 120 | { 121 | } 122 | 123 | for(i=0;iREADY == NVMC_READY_READY_Busy) 127 | { 128 | } 129 | } 130 | 131 | NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; 132 | while (NRF_NVMC->READY == NVMC_READY_READY_Busy) 133 | { 134 | } 135 | } 136 | 137 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/drivers_nrf/hal/nrf_nvmc.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** 34 | * @file 35 | * @brief NMVC driver API. 36 | */ 37 | 38 | #ifndef NRF_NVMC_H__ 39 | #define NRF_NVMC_H__ 40 | 41 | #include 42 | 43 | 44 | /** 45 | * @defgroup nrf_nvmc Non-volatile memory controller 46 | * @{ 47 | * @ingroup nrf_drivers 48 | * @brief Driver for the NVMC peripheral. 49 | * 50 | * This driver allows writing to the non-volatile memory (NVM) regions 51 | * of the chip. In order to write to NVM the controller must be powered 52 | * on and the relevant page must be erased. 53 | * 54 | */ 55 | 56 | 57 | /** 58 | * @brief Erase a page in flash. This is required before writing to any 59 | * address in the page. 60 | * 61 | * @param address Start address of the page. 62 | */ 63 | void nrf_nvmc_page_erase(uint32_t address); 64 | 65 | 66 | /** 67 | * @brief Write a single byte to flash. 68 | * 69 | * The function reads the word containing the byte, and then 70 | * rewrites the entire word. 71 | * 72 | * @param address Address to write to. 73 | * @param value Value to write. 74 | */ 75 | void nrf_nvmc_write_byte(uint32_t address , uint8_t value); 76 | 77 | 78 | /** 79 | * @brief Write a 32-bit word to flash. 80 | * @param address Address to write to. 81 | * @param value Value to write. 82 | */ 83 | void nrf_nvmc_write_word(uint32_t address, uint32_t value); 84 | 85 | 86 | /** 87 | * @brief Write consecutive bytes to flash. 88 | * 89 | * @param address Address to write to. 90 | * @param src Pointer to data to copy from. 91 | * @param num_bytes Number of bytes in src to write. 92 | */ 93 | void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes); 94 | 95 | 96 | /** 97 | * @brief Write consecutive words to flash. 98 | * 99 | * @param address Address to write to. 100 | * @param src Pointer to data to copy from. 101 | * @param num_words Number of bytes in src to write. 102 | */ 103 | void nrf_nvmc_write_words(uint32_t address, const uint32_t * src, uint32_t num_words); 104 | 105 | 106 | #endif // NRF_NVMC_H__ 107 | /** @} */ 108 | 109 | 110 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/drivers_nrf/hal/nrf_temp.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef NRF_TEMP_H__ 34 | #define NRF_TEMP_H__ 35 | 36 | #include "nrf.h" 37 | 38 | /** 39 | * @defgroup nrf_temperature TEMP (temperature) abstraction 40 | * @{ 41 | * @ingroup nrf_drivers temperature_example 42 | * @brief Temperature module init and read functions. 43 | * 44 | */ 45 | 46 | /**@cond NO_DOXYGEN */ 47 | #define MASK_SIGN (0x00000200UL) 48 | #define MASK_SIGN_EXTENSION (0xFFFFFC00UL) 49 | 50 | /** 51 | * @brief Function for preparing the temp module for temperature measurement. 52 | * 53 | * This function initializes the TEMP module and writes to the hidden configuration register. 54 | */ 55 | static __INLINE void nrf_temp_init(void) 56 | { 57 | /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */ 58 | *(uint32_t *) 0x4000C504 = 0; 59 | } 60 | 61 | /** 62 | * @brief Function for reading temperature measurement. 63 | * 64 | * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value. 65 | */ 66 | static __INLINE int32_t nrf_temp_read(void) 67 | { 68 | /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */ 69 | return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP); 70 | } 71 | /**@endcond */ 72 | 73 | /** @} */ 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/drivers_nrf/pstorage/config/pstorage_platform.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @cond To make doxygen skip this file */ 34 | 35 | /** @file 36 | * This header contains defines with respect persistent storage that are specific to 37 | * persistent storage implementation and application use case. 38 | */ 39 | #ifndef PSTORAGE_PL_H__ 40 | #define PSTORAGE_PL_H__ 41 | 42 | #include 43 | #include "nrf.h" 44 | 45 | static __INLINE uint16_t pstorage_flash_page_size() 46 | { 47 | return (uint16_t)NRF_FICR->CODEPAGESIZE; 48 | } 49 | 50 | #define PSTORAGE_FLASH_PAGE_SIZE pstorage_flash_page_size() /**< Size of one flash page. */ 51 | #define PSTORAGE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */ 52 | 53 | #ifdef NRF51 54 | #define BOOTLOADER_ADDRESS (NRF_UICR->BOOTLOADERADDR) 55 | #elif defined NRF52 56 | #define BOOTLOADER_ADDRESS (PSTORAGE_FLASH_EMPTY_MASK) 57 | #endif 58 | 59 | static __INLINE uint32_t pstorage_flash_page_end() 60 | { 61 | uint32_t bootloader_addr = BOOTLOADER_ADDRESS; 62 | 63 | return ((bootloader_addr != PSTORAGE_FLASH_EMPTY_MASK) ? 64 | (bootloader_addr/ PSTORAGE_FLASH_PAGE_SIZE) : NRF_FICR->CODESIZE); 65 | } 66 | 67 | #define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end() 68 | 69 | #define PSTORAGE_NUM_OF_PAGES 1 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */ 70 | #define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */ 71 | 72 | #define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \ 73 | * PSTORAGE_FLASH_PAGE_SIZE) /**< Start address for persistent data, configurable according to system requirements. */ 74 | #define PSTORAGE_DATA_END_ADDR ((PSTORAGE_FLASH_PAGE_END - 1) * PSTORAGE_FLASH_PAGE_SIZE) /**< End address for persistent data, configurable according to system requirements. */ 75 | #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */ 76 | 77 | #define PSTORAGE_MAX_BLOCK_SIZE PSTORAGE_FLASH_PAGE_SIZE /**< Maximum size of block that can be registered with the module. Should be configured based on system requirements. And should be greater than or equal to the minimum size. */ 78 | #define PSTORAGE_CMD_QUEUE_SIZE 2 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */ 79 | 80 | 81 | /** Abstracts persistently memory block identifier. */ 82 | typedef uint32_t pstorage_block_t; 83 | 84 | typedef struct 85 | { 86 | uint32_t module_id; /**< Module ID.*/ 87 | pstorage_block_t block_id; /**< Block ID.*/ 88 | } pstorage_handle_t; 89 | 90 | typedef uint16_t pstorage_size_t; /** Size of length and offset fields. */ 91 | 92 | /**@brief Handles Flash Access Result Events. To be called in the system event dispatcher of the application. */ 93 | void pstorage_sys_event_handler (uint32_t sys_evt); 94 | 95 | #endif // PSTORAGE_PL_H__ 96 | 97 | /** @} */ 98 | /** @endcond */ 99 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/bootloader.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /**@file 34 | * 35 | * @defgroup nrf_bootloader Bootloader API. 36 | * @{ 37 | * 38 | * @brief Bootloader module interface. 39 | */ 40 | 41 | #ifndef BOOTLOADER_H__ 42 | #define BOOTLOADER_H__ 43 | 44 | #include 45 | #include 46 | #include "bootloader_types.h" 47 | #include 48 | 49 | /**@brief Function for initializing the Bootloader. 50 | * 51 | * @retval NRF_SUCCESS If bootloader was succesfully initialized. 52 | */ 53 | uint32_t bootloader_init(void); 54 | 55 | /**@brief Function for validating application region in flash. 56 | * 57 | * @param[in] app_addr Address to the region in flash where the application is stored. 58 | * 59 | * @retval true If Application region is valid. 60 | * @retval false If Application region is not valid. 61 | */ 62 | bool bootloader_app_is_valid(uint32_t app_addr); 63 | 64 | /**@brief Function for starting the Device Firmware Update. 65 | * 66 | * @retval NRF_SUCCESS If new application image was successfully transferred. 67 | */ 68 | uint32_t bootloader_dfu_start(void); 69 | 70 | /**@brief Function for exiting bootloader and booting into application. 71 | * 72 | * @details This function will disable SoftDevice and all interrupts before jumping to application. 73 | * The SoftDevice vector table base for interrupt forwarding will be set the application 74 | * address. 75 | * 76 | * @param[in] app_addr Address to the region where the application is stored. 77 | */ 78 | void bootloader_app_start(uint32_t app_addr); 79 | 80 | /**@brief Function for retrieving the bootloader settings. 81 | * 82 | * @param[out] p_settings A copy of the current bootloader settings is returned in the structure 83 | * provided. 84 | */ 85 | void bootloader_settings_get(bootloader_settings_t * const p_settings); 86 | 87 | /**@brief Function for processing DFU status update. 88 | * 89 | * @param[in] update_status DFU update status. 90 | */ 91 | void bootloader_dfu_update_process(dfu_update_status_t update_status); 92 | 93 | /**@brief Function getting state of SoftDevice update in progress. 94 | * After a successfull SoftDevice transfer the system restarts in orderto disable SoftDevice 95 | * and complete the update. 96 | * 97 | * @retval true A SoftDevice update is in progress. This indicates that second stage 98 | * of a SoftDevice update procedure can be initiated. 99 | * @retval false No SoftDevice update is in progress. 100 | */ 101 | bool bootloader_dfu_sd_in_progress(void); 102 | 103 | /**@brief Function for continuing the Device Firmware Update of a SoftDevice. 104 | * 105 | * @retval NRF_SUCCESS If the final stage of SoftDevice update was successful. 106 | */ 107 | uint32_t bootloader_dfu_sd_update_continue(void); 108 | 109 | /**@brief Function for finalizing the Device Firmware Update of a SoftDevice. 110 | * 111 | * @retval NRF_SUCCESS If the final stage of SoftDevice update was successful. 112 | */ 113 | uint32_t bootloader_dfu_sd_update_finalize(void); 114 | 115 | #endif // BOOTLOADER_H__ 116 | 117 | /**@} */ 118 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/bootloader_types.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /**@file 34 | * 35 | * @defgroup nrf_bootloader_types Types and definitions. 36 | * @{ 37 | * 38 | * @ingroup nrf_bootloader 39 | * 40 | * @brief Bootloader module type and definitions. 41 | */ 42 | 43 | #ifndef BOOTLOADER_TYPES_H__ 44 | #define BOOTLOADER_TYPES_H__ 45 | 46 | #include 47 | 48 | #define BOOTLOADER_DFU_START 0xB1 49 | 50 | #define BOOTLOADER_SVC_APP_DATA_PTR_GET 0x02 51 | 52 | /**@brief DFU Bank state code, which indicates wether the bank contains: A valid image, invalid image, or an erased flash. 53 | */ 54 | typedef enum 55 | { 56 | BANK_VALID_APP = 0x01, 57 | BANK_VALID_SD = 0xA5, 58 | BANK_VALID_BOOT = 0xAA, 59 | BANK_ERASED = 0xFE, 60 | BANK_INVALID_APP = 0xFF, 61 | } bootloader_bank_code_t; 62 | 63 | /**@brief Structure holding bootloader settings for application and bank data. 64 | */ 65 | typedef struct 66 | { 67 | bootloader_bank_code_t bank_0; /**< Variable to store if bank 0 contains a valid application. */ 68 | uint16_t bank_0_crc; /**< If bank is valid, this field will contain a valid CRC of the total image. */ 69 | bootloader_bank_code_t bank_1; /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */ 70 | uint32_t bank_0_size; /**< Size of active image in bank0 if present, otherwise 0. */ 71 | uint32_t sd_image_size; /**< Size of SoftDevice image in bank0 if bank_0 code is BANK_VALID_SD. */ 72 | uint32_t bl_image_size; /**< Size of Bootloader image in bank0 if bank_0 code is BANK_VALID_SD. */ 73 | uint32_t app_image_size; /**< Size of Application image in bank0 if bank_0 code is BANK_VALID_SD. */ 74 | uint32_t sd_image_start; /**< Location in flash where SoftDevice image is stored for SoftDevice update. */ 75 | } bootloader_settings_t; 76 | 77 | #endif // BOOTLOADER_TYPES_H__ 78 | 79 | /**@} */ 80 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/bootloader_util.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /**@file 34 | * 35 | * @defgroup nrf_bootloader_util Bootloader util API. 36 | * @{ 37 | * 38 | * @brief Bootloader util module interface. 39 | */ 40 | 41 | #ifndef BOOTLOADER_UTIL_H__ 42 | #define BOOTLOADER_UTIL_H__ 43 | 44 | #include 45 | #include "bootloader_types.h" 46 | 47 | /**@brief Function for starting the application (or bootloader) at the provided address. 48 | * 49 | * @param[in] start_addr Start address. 50 | * 51 | * @note This function will never retrun. Instead it will reset into the application of the 52 | * provided address. 53 | */ 54 | void bootloader_util_app_start(uint32_t start_addr); 55 | 56 | #endif // BOOTLOADER_UTIL_H__ 57 | 58 | /**@} */ 59 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/dfu_app_handler.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup nrf_dfu_app_handler DFU BLE packet handling in application 36 | * @{ 37 | * 38 | * @brief Handling of DFU BLE packets in the application. 39 | * 40 | * @details This module implements the handling of DFU packets for switching 41 | * from an application to the bootloader and start DFU mode. The DFU 42 | * packets are transmitted over BLE. 43 | * This module handles only the StartDFU packet, which allows a BLE 44 | * application to expose support for the DFU Service. 45 | * The actual DFU Service runs in a dedicated environment after a BLE 46 | * disconnect and reset of the \nRFXX device. 47 | * The host must reconnect and continue the update procedure with 48 | * access to the full DFU Service. 49 | * 50 | * @note The application must propagate DFU events to this module by calling 51 | * @ref dfu_app_on_dfu_evt from the @ref ble_dfu_evt_handler_t callback. 52 | */ 53 | 54 | #ifndef DFU_APP_HANDLER_H__ 55 | #define DFU_APP_HANDLER_H__ 56 | 57 | #include "ble_dfu.h" 58 | #include "nrf_svc.h" 59 | #include "bootloader_types.h" 60 | #include "device_manager.h" 61 | 62 | #define DFU_APP_ATT_TABLE_POS 0 /**< Position for the ATT table changed setting. */ 63 | #define DFU_APP_ATT_TABLE_CHANGED 1 /**< Value indicating that the ATT table might have changed. This value will be set in the application-specific context in Device Manager when entering DFU mode. */ 64 | 65 | /**@brief DFU application reset_prepare function. This function is a callback that allows the 66 | * application to prepare for an upcoming application reset. 67 | */ 68 | typedef void (*dfu_app_reset_prepare_t)(void); 69 | 70 | /**@brief Function for handling events from the DFU Service. 71 | * 72 | * @details The application must inject this function into the DFU Service or propagate DFU events 73 | * to the dfu_app_handler module by calling this function in the application-specific DFU event 74 | * handler. 75 | * 76 | * @param[in] p_dfu Pointer to the DFU Service structure to which the include event relates. 77 | * @param[in] p_evt Pointer to the DFU event. 78 | */ 79 | void dfu_app_on_dfu_evt(ble_dfu_t * p_dfu, ble_dfu_evt_t * p_evt); 80 | 81 | /**@brief Function for registering a function to prepare a reset. 82 | * 83 | * @details The provided function is executed before resetting the system into bootloader/DFU 84 | * mode. By registering this function, the caller is notified before the reset and can 85 | * thus prepare the application for reset. For example, the application can gracefully 86 | * disconnect any peers on BLE, turn of LEDS, ensure that all pending flash operations 87 | * have completed, and so on. 88 | * 89 | * @param[in] reset_prepare_func Function to be executed before a reset. 90 | */ 91 | void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func); 92 | 93 | /**@brief Function for setting the Device Manager application instance. 94 | * 95 | * @details This function allows to set the @ref dm_application_instance_t value that is returned by the 96 | * Device Manager when the application registers using @ref dm_register. 97 | * If this function is not called, it is not be possible to share bonding information 98 | * from the application to the bootloader/DFU when entering DFU mode. 99 | * 100 | * @param[in] app_instance Value for the application instance in use. 101 | */ 102 | void dfu_app_dm_appl_instance_set(dm_application_instance_t app_instance); 103 | 104 | #endif // DFU_APP_HANDLER_H__ 105 | 106 | /** @} */ 107 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/dfu_ble_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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup nrf_dfu_ble_svc DFU BLE SVC 36 | * @{ 37 | * 38 | * @brief DFU BLE SVC in bootloader. The DFU BLE SuperVisor Calls allow an application to execute 39 | * functions in the installed bootloader. 40 | * 41 | * @details This module implements handling of SuperVisor Calls in the bootloader. 42 | * SuperVisor Calls allow for an application to execute calls into the bootloader. 43 | * Currently, it is possible to exchange bonding information (like keys) from the 44 | * application to a bootloader supporting DFU OTA using BLE, so the update process can be 45 | * done through an already existing bond. 46 | * 47 | * @note The application must make sure that all SuperVisor Calls (SVC) are forwarded to the 48 | * bootloader to ensure correct behavior. Forwarding of SVCs to the bootloader is 49 | * done using the SoftDevice SVC @ref sd_softdevice_vector_table_base_set with the value 50 | * present in @c NRF_UICR->BOOTLOADERADDR. 51 | */ 52 | 53 | #ifndef DFU_BLE_SVC_H__ 54 | #define DFU_BLE_SVC_H__ 55 | 56 | #include "nrf_svc.h" 57 | #include 58 | #include "ble_gap.h" 59 | #include "nrf.h" 60 | #include "nrf_soc.h" 61 | #include "nrf_error_sdm.h" 62 | 63 | #define BOOTLOADER_SVC_BASE 0x0 /**< The number of the lowest SVC number reserved for the bootloader. */ 64 | #define SYSTEM_SERVICE_ATT_SIZE 8 /**< Size of the system service attribute length including CRC-16 at the end. */ 65 | 66 | /**@brief The SVC numbers used by the SVC functions in the SoC library. */ 67 | enum BOOTLOADER_SVCS 68 | { 69 | DFU_BLE_SVC_PEER_DATA_SET = BOOTLOADER_SVC_BASE, /**< SVC number for the setting of peer data call. */ 70 | BOOTLOADER_SVC_LAST 71 | }; 72 | 73 | /**@brief DFU Peer data structure. 74 | * 75 | * @details This structure contains peer data needed for connection to a bonded device during DFU. 76 | * The peer data must be provided by the application to the bootloader during buttonless 77 | * update. See @ref dfu_ble_svc_peer_data_set. It contains bond information about the 78 | * desired DFU peer. 79 | */ 80 | typedef struct 81 | { 82 | ble_gap_addr_t addr; /**< BLE GAP address of the device that initiated the DFU process. */ 83 | ble_gap_irk_t irk; /**< IRK of the device that initiated the DFU process if this device uses Private Resolvable Addresses. */ 84 | ble_gap_enc_key_t enc_key; /**< Encryption key structure containing encrypted diversifier and LTK for re-establishing the bond. */ 85 | uint8_t sys_serv_attr[SYSTEM_SERVICE_ATT_SIZE]; /**< System service attributes for restoring of Service Changed Indication setting in DFU mode. */ 86 | } dfu_ble_peer_data_t; 87 | 88 | /**@brief SVC Function for setting peer data containing address, IRK, and LTK to establish bonded 89 | * connection in DFU mode. 90 | * 91 | * @param[in] p_peer_data Pointer to the peer data containing keys for the connection. 92 | * 93 | * @retval NRF_ERROR_NULL If a NULL pointer was provided as argument. 94 | * @retval NRF_SUCCESS If the function completed successfully. 95 | */ 96 | SVCALL(DFU_BLE_SVC_PEER_DATA_SET, uint32_t, dfu_ble_svc_peer_data_set(dfu_ble_peer_data_t * p_peer_data)); 97 | 98 | #endif // DFU_BLE_SVC_H__ 99 | 100 | /** @} */ 101 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/dfu_ble_svc_internal.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup nrf_dfu_ble_svc_internal DFU BLE SVC internal 36 | * @{ 37 | * 38 | * @brief DFU BLE SVC internal functions in bootloader. The DFU BLE SuperVisor Calls allow an 39 | * application to execute functions in the installed bootloader. This interface provides 40 | * internal Bootloader DFU functions for retrieving data exchanged through SuperVisor Calls. 41 | * 42 | */ 43 | 44 | #ifndef DFU_BLE_SVC_INTERNAL_H__ 45 | #define DFU_BLE_SVC_INTERNAL_H__ 46 | 47 | #include 48 | #include "dfu_ble_svc.h" 49 | #include "ble_gap.h" 50 | 51 | /**@brief Internal bootloader/DFU function for retrieving peer data provided from application. 52 | * 53 | * @param[out] p_peer_data Peer data set by application to be used for DFU connection. 54 | * 55 | * @retval NRF_SUCCESS If peer data is valid and can be used for connection. 56 | * @retval NRF_ERROR_NULL If p_peer_data is a NULL pointer. 57 | * @retval NRF_ERROR_INVALID_DATA If peer data is not available or invalid. 58 | */ 59 | uint32_t dfu_ble_peer_data_get(dfu_ble_peer_data_t * p_peer_data); 60 | 61 | #endif // DFU_BLE_SVC_INTERNAL_H__ 62 | 63 | /** @} */ 64 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/dfu_transport.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /**@file 34 | * 35 | * @defgroup nrf_dfu_transport DFU transport API. 36 | * @{ 37 | * 38 | * @brief DFU transport module interface. 39 | */ 40 | 41 | #ifndef DFU_TRANSPORT_H__ 42 | #define DFU_TRANSPORT_H__ 43 | 44 | #include 45 | 46 | /**@brief Function for starting the update of Device Firmware. 47 | * 48 | * @retval NRF_SUCCESS Operation success. 49 | */ 50 | uint32_t dfu_transport_update_start(void); 51 | 52 | /**@brief Function for closing the transport layer. 53 | * 54 | * @retval NRF_SUCCESS Operation success. 55 | */ 56 | uint32_t dfu_transport_close(void); 57 | 58 | #endif // DFU_TRANSPORT_H__ 59 | 60 | /**@} */ 61 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/bootloader_dfu/hci_transport/hci_mem_pool_internal.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup memory_pool_internal Memory Pool Internal 36 | * @{ 37 | * @ingroup memory_pool 38 | * 39 | * @brief Memory pool internal definitions 40 | */ 41 | 42 | #ifndef MEM_POOL_INTERNAL_H__ 43 | #define MEM_POOL_INTERNAL_H__ 44 | 45 | #define TX_BUF_SIZE 4u /**< TX buffer size in bytes. */ 46 | #define RX_BUF_SIZE 32u /**< RX buffer size in bytes. */ 47 | 48 | #define RX_BUF_QUEUE_SIZE 8u /**< RX buffer element size. */ 49 | 50 | #endif // MEM_POOL_INTERNAL_H__ 51 | 52 | /** @} */ 53 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/crc16/crc16.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #include "crc16.h" 34 | #include 35 | 36 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc) 37 | { 38 | uint32_t i; 39 | uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc; 40 | 41 | for (i = 0; i < size; i++) 42 | { 43 | crc = (unsigned char)(crc >> 8) | (crc << 8); 44 | crc ^= p_data[i]; 45 | crc ^= (unsigned char)(crc & 0xff) >> 4; 46 | crc ^= (crc << 8) << 4; 47 | crc ^= ((crc & 0xff) << 4) << 1; 48 | } 49 | 50 | return crc; 51 | } 52 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/crc16/crc16.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup crc_compute CRC compute 36 | * @{ 37 | * @ingroup hci_transport 38 | * 39 | * @brief This module implements the CRC-16 calculation in the blocks. 40 | */ 41 | 42 | #ifndef CRC16_H__ 43 | #define CRC16_H__ 44 | 45 | #include 46 | 47 | /**@brief Function for calculating CRC-16 in blocks. 48 | * 49 | * Feed each consecutive data block into this function, along with the current value of p_crc as 50 | * returned by the previous call of this function. The first call of this function should pass NULL 51 | * as the initial value of the crc in p_crc. 52 | * 53 | * @param[in] p_data The input data block for computation. 54 | * @param[in] size The size of the input data block in bytes. 55 | * @param[in] p_crc The previous calculated CRC-16 value or NULL if first call. 56 | * 57 | * @return The updated CRC-16 value, based on the input supplied. 58 | */ 59 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc); 60 | 61 | #endif // CRC16_H__ 62 | 63 | /** @} */ 64 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/fds/fds_config.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef FDS_CONFIG_H__ 34 | #define FDS_CONFIG_H__ 35 | 36 | /** 37 | * @file fds_config.h 38 | * 39 | * @addtogroup flash_data_storage 40 | * @{ 41 | */ 42 | 43 | /**@brief Configures the size of the internal queue. */ 44 | #define FDS_CMD_QUEUE_SIZE (8) 45 | /**@brief Determines how many @ref fds_record_chunk_t structures can be buffered at any time. */ 46 | #define FDS_CHUNK_QUEUE_SIZE (8) 47 | 48 | /**@brief Configures the number of physical flash pages to use. Out of the total, one is reserved 49 | * for garbage collection, hence, two pages is the minimum: one for the application data 50 | * and one for the system. */ 51 | #define FDS_MAX_PAGES (2) 52 | /**@brief Configures the maximum number of callbacks which can be registred. */ 53 | #define FDS_MAX_USERS (10) 54 | 55 | /** Page tag definitions. */ 56 | #define FDS_PAGE_TAG_WORD_0_SWAP (0xA5A5A5A5) 57 | #define FDS_PAGE_TAG_WORD_0_VALID (0xA4A4A4A4) 58 | #define FDS_PAGE_TAG_WORD_1 (0xAABBCCDD) 59 | #define FDS_PAGE_TAG_WORD_2 (0xAABB01DD) /**< Includes version. */ 60 | #define FDS_PAGE_TAG_WORD_3 (0x1CEB00DA) 61 | #define FDS_PAGE_TAG_WORD_3_GC (0x1CEB00D8) 62 | 63 | /** @} */ 64 | 65 | #endif // FDS_CONFIG_H__ 66 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/fstorage/fstorage_config.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef FS_CONFIG_H__ 34 | #define FS_CONFIG_H__ 35 | 36 | #include 37 | #include "nrf.h" 38 | 39 | /** 40 | * @defgroup fstorage_config FStorage configuration 41 | * @ingroup fstorage 42 | * @{ 43 | * @brief FStorage configuration. 44 | */ 45 | 46 | 47 | /**@brief Macro for max number of operations in the fs cmd queue. 48 | */ 49 | #define FS_CMD_QUEUE_SIZE (8) 50 | 51 | 52 | /**@brief Macro for max number of retries for a flash command before it notifies as failed. 53 | */ 54 | #define FS_CMD_MAX_RETRIES (3) 55 | 56 | 57 | /**@brief Macro for the content of a flash address that has not been written to. 58 | */ 59 | #define FS_EMPTY_MASK (0xFFFFFFFF) 60 | 61 | 62 | /**@brief Macro for flash page size according to chip family 63 | */ 64 | #if defined (NRF51) 65 | #define FS_PAGE_SIZE (1024) 66 | #elif defined (NRF52) 67 | #define FS_PAGE_SIZE (4096) 68 | #else 69 | #error "Device family must be defined. See nrf.h." 70 | #endif 71 | 72 | 73 | /*@brief Macro for flash page size according to chip family 74 | */ 75 | #define FS_PAGE_SIZE_WORDS (FS_PAGE_SIZE/4) 76 | 77 | 78 | /**@brief Static inline function that provides last page address 79 | * 80 | * @note If there is a bootloader present the bootloader address read from UICR 81 | * will act as the page beyond the end of the available flash storage 82 | */ 83 | static __INLINE uint32_t fs_flash_page_end_addr() 84 | { 85 | uint32_t const bootloader_addr = NRF_UICR->NRFFW[0]; 86 | return ((bootloader_addr != FS_EMPTY_MASK) ? 87 | bootloader_addr : NRF_FICR->CODESIZE * FS_PAGE_SIZE); 88 | } 89 | 90 | 91 | /**@brief Macro for last page address 92 | * 93 | * @note If there is a bootloader present the bootloader address read from UICR 94 | * will act as the page beyond the end of the available flash storage 95 | */ 96 | #define FS_PAGE_END_ADDR fs_flash_page_end_addr() 97 | 98 | 99 | /**@brief Macro to describe the write 100 | * 101 | */ 102 | #if defined (NRF51) 103 | #define FS_MAX_WRITE_SIZE_WORDS (256) 104 | #elif defined (NRF52) 105 | #define FS_MAX_WRITE_SIZE_WORDS (1024) 106 | #else 107 | #error "Device family must be defined. see nrf.h" 108 | #endif 109 | 110 | /** @} */ 111 | 112 | #endif // FS_CONFIG_H__ 113 | 114 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/fstorage/fstorage_nosd.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/app_error.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup app_error Common application error handler 36 | * @{ 37 | * @ingroup app_common 38 | * 39 | * @brief Common application error handler. 40 | */ 41 | 42 | #include "nrf.h" 43 | #include "app_error.h" 44 | #include "compiler_abstraction.h" 45 | #include "nordic_common.h" 46 | #ifdef DEBUG 47 | #include "bsp.h" 48 | 49 | /* global error variables - in order to prevent removal by optimizers */ 50 | uint32_t m_error_code; 51 | uint32_t m_line_num; 52 | const uint8_t * m_p_file_name; 53 | #endif 54 | 55 | /**@brief Function for error handling, which is called when an error has occurred. 56 | * 57 | * @warning This handler is an example only and does not fit a final product. You need to analyze 58 | * how your product is supposed to react in case of error. 59 | * 60 | * @param[in] error_code Error code supplied to the handler. 61 | * @param[in] line_num Line number where the handler is called. 62 | * @param[in] p_file_name Pointer to the file name. 63 | * 64 | * Function is implemented as weak so that it can be overwritten by custom application error handler 65 | * when needed. 66 | */ 67 | 68 | /*lint -save -e14 */ 69 | __WEAK void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name) 70 | { 71 | // On assert, the system can only recover with a reset. 72 | #ifndef DEBUG 73 | NVIC_SystemReset(); 74 | #else 75 | 76 | #ifdef BSP_DEFINES_ONLY 77 | LEDS_ON(LEDS_MASK); 78 | #else 79 | UNUSED_VARIABLE(bsp_indication_set(BSP_INDICATE_FATAL_ERROR)); 80 | // This call can be used for debug purposes during application development. 81 | // @note CAUTION: Activating this code will write the stack to flash on an error. 82 | // This function should NOT be used in a final product. 83 | // It is intended STRICTLY for development/debugging purposes. 84 | // The flash write will happen EVEN if the radio is active, thus interrupting 85 | // any communication. 86 | // Use with care. Uncomment the line below to use. 87 | //ble_debug_assert_handler(error_code, line_num, p_file_name); 88 | #endif // BSP_DEFINES_ONLY 89 | 90 | // The following variable helps Keil keep the call stack visible, in addition, it can be set to 91 | // 0 in the debugger to continue executing code after the error check. 92 | volatile bool loop = true; 93 | UNUSED_VARIABLE(loop); 94 | 95 | m_error_code = error_code; 96 | m_line_num = line_num; 97 | m_p_file_name = p_file_name; 98 | 99 | UNUSED_VARIABLE(m_error_code); 100 | UNUSED_VARIABLE(m_line_num); 101 | UNUSED_VARIABLE(m_p_file_name); 102 | __disable_irq(); 103 | 104 | while(loop); 105 | #endif // DEBUG 106 | } 107 | /*lint -restore */ 108 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/app_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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * 35 | * @defgroup app_error Common application error handler 36 | * @{ 37 | * @ingroup app_common 38 | * 39 | * @brief Common application error handler and macros for utilizing a common error handler. 40 | */ 41 | 42 | #ifndef APP_ERROR_H__ 43 | #define APP_ERROR_H__ 44 | 45 | #include 46 | #include 47 | #include "nrf_error.h" 48 | 49 | /**@brief Function for error handling, which is called when an error has occurred. 50 | * 51 | * @param[in] error_code Error code supplied to the handler. 52 | * @param[in] line_num Line number where the handler is called. 53 | * @param[in] p_file_name Pointer to the file name. 54 | */ 55 | void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name); 56 | 57 | /**@brief Macro for calling error handler function. 58 | * 59 | * @param[in] ERR_CODE Error code supplied to the error handler. 60 | */ 61 | #ifdef DEBUG 62 | #define APP_ERROR_HANDLER(ERR_CODE) \ 63 | do \ 64 | { \ 65 | app_error_handler((ERR_CODE), __LINE__, (uint8_t*) __FILE__); \ 66 | } while (0) 67 | #else 68 | #define APP_ERROR_HANDLER(ERR_CODE) \ 69 | do \ 70 | { \ 71 | app_error_handler((ERR_CODE), 0, 0); \ 72 | } while (0) 73 | #endif 74 | /**@brief Macro for calling error handler function if supplied error code any other than NRF_SUCCESS. 75 | * 76 | * @param[in] ERR_CODE Error code supplied to the error handler. 77 | */ 78 | #define APP_ERROR_CHECK(ERR_CODE) \ 79 | do \ 80 | { \ 81 | const uint32_t LOCAL_ERR_CODE = (ERR_CODE); \ 82 | if (LOCAL_ERR_CODE != NRF_SUCCESS) \ 83 | { \ 84 | APP_ERROR_HANDLER(LOCAL_ERR_CODE); \ 85 | } \ 86 | } while (0) 87 | 88 | /**@brief Macro for calling error handler function if supplied boolean value is false. 89 | * 90 | * @param[in] BOOLEAN_VALUE Boolean value to be evaluated. 91 | */ 92 | #define APP_ERROR_CHECK_BOOL(BOOLEAN_VALUE) \ 93 | do \ 94 | { \ 95 | const uint32_t LOCAL_BOOLEAN_VALUE = (BOOLEAN_VALUE); \ 96 | if (!LOCAL_BOOLEAN_VALUE) \ 97 | { \ 98 | APP_ERROR_HANDLER(0); \ 99 | } \ 100 | } while (0) 101 | 102 | #endif // APP_ERROR_H__ 103 | 104 | /** @} */ 105 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/app_util_platform.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #include "app_util_platform.h" 34 | 35 | static uint32_t m_in_critical_region = 0; 36 | 37 | void critical_region_enter(void) 38 | { 39 | __disable_irq(); 40 | m_in_critical_region++; 41 | } 42 | 43 | void critical_region_exit(void) 44 | { 45 | m_in_critical_region--; 46 | if (m_in_critical_region == 0) 47 | { 48 | __enable_irq(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/common.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef COMMON_H 34 | #define COMMON_H 35 | 36 | /*lint ++flb "Enter library region" */ 37 | 38 | #include 39 | #include 40 | 41 | /* @file 42 | * @brief Common header file for generic macros and definitions 43 | * 44 | */ 45 | 46 | /* 47 | * GPIO glue macros, this can be used to define a pin number in source/header file and use that macro for pin 48 | * configuration using this expansion. 49 | * example: 50 | * #define RESET_PIN 8 51 | * NRF_GPIO->PINCNF(RESET_PIN) = XXX ; // Expanded NRF_GPIO->PIN_CNF[8] = XXX 52 | */ 53 | #define PINX_GLUE(x, y, z) x##y##_##z /*!< first level glue for pin macros */ 54 | #define PINCNF(p) PINX_GLUE(PIN,p,CNF) /*!< gpio configure pin number 'p' */ 55 | #define PINOUT(p) PINX_GLUE(PIN,p,OUT) /*!< gpio out pin number 'p' */ 56 | 57 | /*lint --flb "Leave library region" */ 58 | #endif 59 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/nordic_common.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * @brief Common defines and macros for firmware developed by Nordic Semiconductor. 35 | */ 36 | 37 | #ifndef NORDIC_COMMON_H__ 38 | #define NORDIC_COMMON_H__ 39 | 40 | /** The upper 8 bits of a 32 bit value */ 41 | //lint -emacro(572,MSB) // Suppress warning 572 "Excessive shift value" 42 | #define MSB(a) (((a) & 0xFF000000) >> 24) 43 | /** The lower 8 bits (of a 32 bit value) */ 44 | #define LSB(a) ((a) & 0x000000FF) 45 | 46 | /** The upper 8 bits of a 16 bit value */ 47 | //lint -emacro(572,MSB_16) // Suppress warning 572 "Excessive shift value" 48 | #define MSB_16(a) (((a) & 0xFF00) >> 8) 49 | /** The lower 8 bits (of a 16 bit value) */ 50 | #define LSB_16(a) ((a) & 0x00FF) 51 | 52 | /** Leaves the minimum of the two 32-bit arguments */ 53 | /*lint -emacro(506, MIN) */ /* Suppress "Constant value Boolean */ 54 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 55 | /** Leaves the maximum of the two 32-bit arguments */ 56 | /*lint -emacro(506, MAX) */ /* Suppress "Constant value Boolean */ 57 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) 58 | 59 | /** Concatenates two parameters. Useful as a second level of indirection, 60 | * when a parameter can be macro itself. */ 61 | #define CONCAT_2(p1, p2) p1##p2 62 | /** Concatenates three parameters. Useful as a second level of indirection, 63 | * when a parameter can be macro itself. */ 64 | #define CONCAT_3(p1, p2, p3) p1##p2##p3 65 | 66 | /**@brief Set a bit in the uint32 word. 67 | * 68 | * @param[in] W Word whose bit is being set. 69 | * @param[in] B Bit number in the word to be set. 70 | */ 71 | #define SET_BIT(W,B) ((W) |= (uint32_t)(1U << (B))) 72 | 73 | 74 | /**@brief Clears a bit in the uint32 word. 75 | * 76 | * @param[in] W Word whose bit is to be cleared. 77 | * @param[in] B Bit number in the word to be cleared. 78 | */ 79 | #define CLR_BIT(W, B) ((W) &= (~((uint32_t)1 << (B)))) 80 | 81 | 82 | /**@brief Checks if a bit is set. 83 | * 84 | * @param[in] W Word whose bit is to be checked. 85 | * @param[in] B Bit number in the word to be checked. 86 | * 87 | * @retval 1 if bit is set. 88 | * @retval 0 if bit is not set. 89 | */ 90 | #define IS_SET(W,B) (((W) >> (B)) & 1) 91 | 92 | #define BIT_0 0x01 /**< The value of bit 0 */ 93 | #define BIT_1 0x02 /**< The value of bit 1 */ 94 | #define BIT_2 0x04 /**< The value of bit 2 */ 95 | #define BIT_3 0x08 /**< The value of bit 3 */ 96 | #define BIT_4 0x10 /**< The value of bit 4 */ 97 | #define BIT_5 0x20 /**< The value of bit 5 */ 98 | #define BIT_6 0x40 /**< The value of bit 6 */ 99 | #define BIT_7 0x80 /**< The value of bit 7 */ 100 | #define BIT_8 0x0100 /**< The value of bit 8 */ 101 | #define BIT_9 0x0200 /**< The value of bit 9 */ 102 | #define BIT_10 0x0400 /**< The value of bit 10 */ 103 | #define BIT_11 0x0800 /**< The value of bit 11 */ 104 | #define BIT_12 0x1000 /**< The value of bit 12 */ 105 | #define BIT_13 0x2000 /**< The value of bit 13 */ 106 | #define BIT_14 0x4000 /**< The value of bit 14 */ 107 | #define BIT_15 0x8000 /**< The value of bit 15 */ 108 | #define BIT_16 0x00010000 /**< The value of bit 16 */ 109 | #define BIT_17 0x00020000 /**< The value of bit 17 */ 110 | #define BIT_18 0x00040000 /**< The value of bit 18 */ 111 | #define BIT_19 0x00080000 /**< The value of bit 19 */ 112 | #define BIT_20 0x00100000 /**< The value of bit 20 */ 113 | #define BIT_21 0x00200000 /**< The value of bit 21 */ 114 | #define BIT_22 0x00400000 /**< The value of bit 22 */ 115 | #define BIT_23 0x00800000 /**< The value of bit 23 */ 116 | #define BIT_24 0x01000000 /**< The value of bit 24 */ 117 | #define BIT_25 0x02000000 /**< The value of bit 25 */ 118 | #define BIT_26 0x04000000 /**< The value of bit 26 */ 119 | #define BIT_27 0x08000000 /**< The value of bit 27 */ 120 | #define BIT_28 0x10000000 /**< The value of bit 28 */ 121 | #define BIT_29 0x20000000 /**< The value of bit 29 */ 122 | #define BIT_30 0x40000000 /**< The value of bit 30 */ 123 | #define BIT_31 0x80000000 /**< The value of bit 31 */ 124 | 125 | #define UNUSED_VARIABLE(X) ((void)(X)) 126 | #define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X) 127 | 128 | #endif // NORDIC_COMMON_H__ 129 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/nrf_assert.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | #include "nrf_assert.h" 33 | 34 | #if defined(DEBUG_NRF) 35 | void assert_nrf_callback(uint16_t line_num, const uint8_t * file_name) 36 | { 37 | (void) file_name; /* Unused parameter */ 38 | (void) line_num; /* Unused parameter */ 39 | 40 | while (1) ; 41 | } 42 | #endif /* DEBUG_NRF */ 43 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/nrf_assert.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @file 34 | * @brief Utilities for verifying program logic 35 | */ 36 | 37 | #ifndef NRF_ASSERT_H_ 38 | #define NRF_ASSERT_H_ 39 | 40 | #include 41 | #include "compiler_abstraction.h" 42 | 43 | #if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) 44 | 45 | /** @brief Function for handling assertions. 46 | * 47 | * 48 | * @note 49 | * This function is called when an assertion has triggered. 50 | * 51 | * 52 | * @post 53 | * All hardware is put into an idle non-emitting state (in particular the radio is highly 54 | * important to switch off since the radio might be in a state that makes it send 55 | * packets continiously while a typical final infinit ASSERT loop is executing). 56 | * 57 | * 58 | * @param line_num The line number where the assertion is called 59 | * @param file_name Pointer to the file name 60 | */ 61 | void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name); 62 | 63 | /*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 64 | /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \ 65 | 66 | /** @brief Function for checking intended for production code. 67 | * 68 | * Check passes if "expr" evaluates to true. */ 69 | #define ASSERT(expr) \ 70 | if (expr) \ 71 | { \ 72 | } \ 73 | else \ 74 | { \ 75 | assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \ 76 | } 77 | #else 78 | #define ASSERT(expr) //!< Assert empty when disabled 79 | __WEAK void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name); 80 | #endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */ 81 | 82 | #endif /* NRF_ASSERT_H_ */ 83 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/sdk_common.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @cond */ 34 | /**@file 35 | * 36 | * @ingroup experimental_api 37 | * @defgroup sdk_common SDK Common Header 38 | * @breif All common headers needed for SDK examples will be included here so that application 39 | * developer does not have to include headers on him/herself. 40 | * @{ 41 | */ 42 | 43 | #ifndef SDK_COMMON_H__ 44 | #define SDK_COMMON_H__ 45 | 46 | #include 47 | #include 48 | #include 49 | #include "nordic_common.h" 50 | #include "compiler_abstraction.h" 51 | #include "sdk_os.h" 52 | #include "sdk_errors.h" 53 | #include "app_util.h" 54 | 55 | /** @} */ 56 | /** @endcond */ 57 | #endif // SDK_COMMON_H__ 58 | 59 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/libraries/util/sdk_os.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @cond */ 34 | /**@file 35 | * 36 | * @defgroup sdk_os SDK OS Abstraction 37 | * @ingroup experimental_api 38 | * @details In order to made SDK modules independent of use of an embedded OS, and permit 39 | * application with varied task architecture, SDK abstracts the OS specific 40 | * elements here in order to make all other modules agnostic to the OS or task 41 | * architecture. 42 | * @{ 43 | */ 44 | 45 | #ifndef SDK_OS_H__ 46 | #define SDK_OS_H__ 47 | 48 | #define SDK_MUTEX_DEFINE(X) 49 | #define SDK_MUTEX_INIT(X) 50 | #define SDK_MUTEX_LOCK(X) 51 | #define SDK_MUTEX_UNLOCK(X) 52 | 53 | /** 54 | * @defgroup os_data_type Data types. 55 | */ 56 | 57 | /** @} */ 58 | /** @endcond */ 59 | #endif // SDK_OS_H__ 60 | 61 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/common/softdevice_handler/ant_stack_handler_types.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /**@file 34 | * 35 | * @defgroup ant_stack_handler_types Types definitions for ANT support in SoftDevice handler. 36 | * @{ 37 | * @ingroup softdevice_handler 38 | * @brief This file contains the declarations of types required for ANT stack support. These 39 | * types will be defined when the preprocessor define ANT_STACK_SUPPORT_REQD is defined. 40 | */ 41 | 42 | #ifndef ANT_STACK_HANDLER_TYPES_H__ 43 | #define ANT_STACK_HANDLER_TYPES_H__ 44 | 45 | #ifdef ANT_STACK_SUPPORT_REQD 46 | 47 | #include 48 | 49 | #define ANT_STACK_EVT_MSG_BUF_SIZE 32 /**< Size of ANT event message buffer. This will be provided to the SoftDevice while fetching an event. */ 50 | #define ANT_STACK_EVT_STRUCT_SIZE (sizeof(ant_evt_t)) /**< Size of the @ref ant_evt_t structure. This will be used by the @ref softdevice_handler to internal event buffer size needed. */ 51 | 52 | /**@brief ANT stack event type. */ 53 | typedef struct 54 | { 55 | uint8_t channel; /**< Channel number. */ 56 | uint8_t event; /**< Event code. */ 57 | uint8_t evt_buffer[ANT_STACK_EVT_MSG_BUF_SIZE]; /**< Event message buffer. */ 58 | } ant_evt_t; 59 | 60 | /**@brief Application ANT stack event handler type. */ 61 | typedef void (*ant_evt_handler_t) (ant_evt_t * p_ant_evt); 62 | 63 | /**@brief Function for registering for ANT events. 64 | * 65 | * @details The application should use this function to register for receiving ANT events from 66 | * the SoftDevice. If the application does not call this function, then any ANT event 67 | * that may be generated by the SoftDevice will NOT be fetched. Once the application has 68 | * registered for the events, it is not possible to possible to cancel the registration. 69 | * However, it is possible to register a different function for handling the events at 70 | * any point of time. 71 | * 72 | * @param[in] ant_evt_handler Function to be called for each received ANT event. 73 | * 74 | * @retval NRF_SUCCESS Successful registration. 75 | * @retval NRF_ERROR_NULL Null pointer provided as input. 76 | */ 77 | uint32_t softdevice_ant_evt_handler_set(ant_evt_handler_t ant_evt_handler); 78 | 79 | #else 80 | 81 | // The ANT Stack support is not required. 82 | 83 | #define ANT_STACK_EVT_STRUCT_SIZE 0 /**< Since the ANT stack support is not required, this is equated to 0, so that the @ref softdevice_handler.h can compute the internal event buffer size without having to care for ANT events.*/ 84 | 85 | #endif // ANT_STACK_SUPPORT_REQD 86 | 87 | #endif // ANT_STACK_HANDLER_TYPES_H__ 88 | 89 | /** @} */ 90 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/common/softdevice_handler/ble_stack_handler_types.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /**@file 34 | * 35 | * @defgroup ble_stack_handler_types Types definitions for BLE support in SoftDevice handler. 36 | * @{ 37 | * @ingroup softdevice_handler 38 | * @brief This file contains the declarations of types required for BLE stack support. These 39 | * types will be defined when the preprocessor define BLE_STACK_SUPPORT_REQD is defined. 40 | */ 41 | 42 | #ifndef BLE_STACK_HANDLER_TYPES_H__ 43 | #define BLE_STACK_HANDLER_TYPES_H__ 44 | 45 | #define BLE_STACK_SUPPORT_REQD 46 | #ifdef BLE_STACK_SUPPORT_REQD 47 | 48 | #include 49 | #include "nrf_ble.h" 50 | #include "nrf_sdm.h" 51 | #include "app_error.h" 52 | #include "app_util.h" 53 | 54 | #define BLE_STACK_EVT_MSG_BUF_SIZE (sizeof(ble_evt_t) + (GATT_MTU_SIZE_DEFAULT)) /**< Size of BLE event message buffer. This will be provided to the SoftDevice while fetching an event. */ 55 | #define BLE_STACK_HANDLER_SCHED_EVT_SIZE 0 /**< The size of the scheduler event used by SoftDevice handler when passing BLE events using the @ref app_scheduler. */ 56 | 57 | /**@brief Application stack event handler type. */ 58 | typedef void (*ble_evt_handler_t) (ble_evt_t * p_ble_evt); 59 | 60 | /**@brief Function for registering for BLE events. 61 | * 62 | * @details The application should use this function to register for receiving BLE events from 63 | * the SoftDevice. If the application does not call this function, then any BLE event 64 | * that may be generated by the SoftDevice will NOT be fetched. Once the application has 65 | * registered for the events, it is not possible to cancel the registration. 66 | * However, it is possible to register a different function for handling the events at 67 | * any point of time. 68 | * 69 | * @param[in] ble_evt_handler Function to be called for each received BLE event. 70 | * 71 | * @retval NRF_SUCCESS Successful registration. 72 | * @retval NRF_ERROR_NULL Null pointer provided as input. 73 | */ 74 | uint32_t softdevice_ble_evt_handler_set(ble_evt_handler_t ble_evt_handler); 75 | 76 | #else 77 | 78 | #define BLE_STACK_EVT_MSG_BUF_SIZE 0 /**< Since the BLE stack support is not required, this is equated to 0, so that the @ref softdevice_handler.h can compute the internal event buffer size without having to care for BLE events.*/ 79 | #define BLE_STACK_HANDLER_SCHED_EVT_SIZE 0 80 | 81 | #endif // BLE_STACK_SUPPORT_REQD 82 | 83 | #endif // BLE_STACK_HANDLER_TYPES_H__ 84 | 85 | /** @} */ 86 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c: -------------------------------------------------------------------------------- 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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #include "softdevice_handler_appsh.h" 34 | #include "app_scheduler.h" 35 | #include 36 | 37 | void softdevice_evt_get(void * p_event_data, uint16_t event_size) 38 | { 39 | APP_ERROR_CHECK_BOOL(event_size == 0); 40 | intern_softdevice_events_execute(); 41 | } 42 | 43 | uint32_t softdevice_evt_schedule(void) 44 | { 45 | return app_sched_event_put(NULL, 0, softdevice_evt_get); 46 | } 47 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef SOFTDEVICE_HANDLER_APPSH_H 34 | #define SOFTDEVICE_HANDLER_APPSH_H 35 | 36 | #include "softdevice_handler.h" 37 | #include 38 | 39 | #define SOFTDEVICE_HANDLER_APPSH_INIT(CLOCK_SOURCE,USE_SCHEDULER) \ 40 | SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE,(USE_SCHEDULER) ? softdevice_evt_schedule : NULL) 41 | 42 | uint32_t softdevice_evt_schedule(void); 43 | 44 | #endif //SOFTDEVICE_HANDLER_APPSH_H 45 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/s130/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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** 34 | @addtogroup BLE_COMMON 35 | @{ 36 | @addtogroup nrf_error 37 | @{ 38 | @ingroup BLE_COMMON 39 | @} 40 | 41 | @defgroup ble_err General error codes 42 | @{ 43 | 44 | @brief General error code definitions for the BLE API. 45 | 46 | @ingroup BLE_COMMON 47 | */ 48 | #ifndef NRF_BLE_ERR_H__ 49 | #define NRF_BLE_ERR_H__ 50 | 51 | #include "nrf_error.h" 52 | 53 | /* @defgroup BLE_ERRORS Error Codes 54 | * @{ */ 55 | #define BLE_ERROR_NOT_ENABLED (NRF_ERROR_STK_BASE_NUM+0x001) /**< @ref sd_ble_enable has not been called. */ 56 | #define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */ 57 | #define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x003) /**< Invalid attribute handle. */ 58 | #define BLE_ERROR_NO_TX_BUFFERS (NRF_ERROR_STK_BASE_NUM+0x004) /**< Buffer capacity exceeded. */ 59 | #define BLE_ERROR_INVALID_ROLE (NRF_ERROR_STK_BASE_NUM+0x005) /**< Invalid role. */ 60 | /** @} */ 61 | 62 | 63 | /** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges 64 | * @brief Assignment of subranges for module specific error codes. 65 | * @note For specific error codes, see ble_.h or ble_error_.h. 66 | * @{ */ 67 | #define NRF_L2CAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */ 68 | #define NRF_GAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */ 69 | #define NRF_GATTC_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */ 70 | #define NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */ 71 | /** @} */ 72 | 73 | #endif 74 | 75 | 76 | /** 77 | @} 78 | @} 79 | */ 80 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/s130/headers/ble_ranges.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** 34 | @addtogroup BLE_COMMON 35 | @{ 36 | @defgroup ble_ranges Module specific SVC, event and option number subranges 37 | @{ 38 | 39 | @brief Definition of SVC, event and option number subranges for each API module. 40 | 41 | @note 42 | SVCs, event and option numbers are split into subranges for each API module. 43 | Each module receives its entire allocated range of SVC calls, whether implemented or not, 44 | but return BLE_ERROR_NOT_SUPPORTED for unimplemented or undefined calls in its range. 45 | 46 | Note that the symbols BLE__SVC_LAST is the end of the allocated SVC range, 47 | rather than the last SVC function call actually defined and implemented. 48 | 49 | Specific SVC, event and option values are defined in each module's ble_.h file, 50 | which defines names of each individual SVC code based on the range start value. 51 | */ 52 | 53 | #ifndef BLE_RANGES_H__ 54 | #define BLE_RANGES_H__ 55 | 56 | #define BLE_SVC_BASE 0x60 /**< Common BLE SVC base. */ 57 | #define BLE_SVC_LAST 0x6B /**< Total: 12. */ 58 | 59 | #define BLE_RESERVED_SVC_BASE 0x6C /**< Reserved BLE SVC base. */ 60 | #define BLE_RESERVED_SVC_LAST 0x6F /**< Total: 4. */ 61 | 62 | #define BLE_GAP_SVC_BASE 0x70 /**< GAP BLE SVC base. */ 63 | #define BLE_GAP_SVC_LAST 0x8F /**< Total: 32. */ 64 | 65 | #define BLE_GATTC_SVC_BASE 0x90 /**< GATTC BLE SVC base. */ 66 | #define BLE_GATTC_SVC_LAST 0x9F /**< Total: 32. */ 67 | 68 | #define BLE_GATTS_SVC_BASE 0xA0 /**< GATTS BLE SVC base. */ 69 | #define BLE_GATTS_SVC_LAST 0xAF /**< Total: 16. */ 70 | 71 | #define BLE_L2CAP_SVC_BASE 0xB0 /**< L2CAP BLE SVC base. */ 72 | #define BLE_L2CAP_SVC_LAST 0xBF /**< Total: 16. */ 73 | 74 | 75 | #define BLE_EVT_INVALID 0x00 /**< Invalid BLE Event. */ 76 | 77 | #define BLE_EVT_BASE 0x01 /**< Common BLE Event base. */ 78 | #define BLE_EVT_LAST 0x0F /**< Total: 15. */ 79 | 80 | #define BLE_GAP_EVT_BASE 0x10 /**< GAP BLE Event base. */ 81 | #define BLE_GAP_EVT_LAST 0x2F /**< Total: 32. */ 82 | 83 | #define BLE_GATTC_EVT_BASE 0x30 /**< GATTC BLE Event base. */ 84 | #define BLE_GATTC_EVT_LAST 0x4F /**< Total: 32. */ 85 | 86 | #define BLE_GATTS_EVT_BASE 0x50 /**< GATTS BLE Event base. */ 87 | #define BLE_GATTS_EVT_LAST 0x6F /**< Total: 32. */ 88 | 89 | #define BLE_L2CAP_EVT_BASE 0x70 /**< L2CAP BLE Event base. */ 90 | #define BLE_L2CAP_EVT_LAST 0x8F /**< Total: 32. */ 91 | 92 | 93 | #define BLE_OPT_INVALID 0x00 /**< Invalid BLE Option. */ 94 | 95 | #define BLE_OPT_BASE 0x01 /**< Common BLE Option base. */ 96 | #define BLE_OPT_LAST 0x1F /**< Total: 31. */ 97 | 98 | #define BLE_GAP_OPT_BASE 0x20 /**< GAP BLE Option base. */ 99 | #define BLE_GAP_OPT_LAST 0x3F /**< Total: 32. */ 100 | 101 | #define BLE_GATTC_OPT_BASE 0x40 /**< GATTC BLE Option base. */ 102 | #define BLE_GATTC_OPT_LAST 0x5F /**< Total: 32. */ 103 | 104 | #define BLE_GATTS_OPT_BASE 0x60 /**< GATTS BLE Option base. */ 105 | #define BLE_GATTS_OPT_LAST 0x7F /**< Total: 32. */ 106 | 107 | #define BLE_L2CAP_OPT_BASE 0x80 /**< L2CAP BLE Option base. */ 108 | #define BLE_L2CAP_OPT_LAST 0x9F /**< Total: 32. */ 109 | 110 | #endif /* BLE_RANGES_H__ */ 111 | 112 | /** 113 | @} 114 | @} 115 | */ 116 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/s130/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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /** 33 | @defgroup nrf_error SoftDevice Global Error Codes 34 | @{ 35 | 36 | @brief Global Error definitions 37 | */ 38 | 39 | /* Header guard */ 40 | #ifndef NRF_ERROR_H__ 41 | #define NRF_ERROR_H__ 42 | 43 | /** @defgroup NRF_ERRORS_BASE Error Codes Base number definitions 44 | * @{ */ 45 | #define NRF_ERROR_BASE_NUM (0x0) ///< Global error base 46 | #define NRF_ERROR_SDM_BASE_NUM (0x1000) ///< SDM error base 47 | #define NRF_ERROR_SOC_BASE_NUM (0x2000) ///< SoC error base 48 | #define NRF_ERROR_STK_BASE_NUM (0x3000) ///< STK error base 49 | /** @} */ 50 | 51 | #define NRF_SUCCESS (NRF_ERROR_BASE_NUM + 0) ///< Successful command 52 | #define NRF_ERROR_SVC_HANDLER_MISSING (NRF_ERROR_BASE_NUM + 1) ///< SVC handler is missing 53 | #define NRF_ERROR_SOFTDEVICE_NOT_ENABLED (NRF_ERROR_BASE_NUM + 2) ///< SoftDevice has not been enabled 54 | #define NRF_ERROR_INTERNAL (NRF_ERROR_BASE_NUM + 3) ///< Internal Error 55 | #define NRF_ERROR_NO_MEM (NRF_ERROR_BASE_NUM + 4) ///< No Memory for operation 56 | #define NRF_ERROR_NOT_FOUND (NRF_ERROR_BASE_NUM + 5) ///< Not found 57 | #define NRF_ERROR_NOT_SUPPORTED (NRF_ERROR_BASE_NUM + 6) ///< Not supported 58 | #define NRF_ERROR_INVALID_PARAM (NRF_ERROR_BASE_NUM + 7) ///< Invalid Parameter 59 | #define NRF_ERROR_INVALID_STATE (NRF_ERROR_BASE_NUM + 8) ///< Invalid state, operation disallowed in this state 60 | #define NRF_ERROR_INVALID_LENGTH (NRF_ERROR_BASE_NUM + 9) ///< Invalid Length 61 | #define NRF_ERROR_INVALID_FLAGS (NRF_ERROR_BASE_NUM + 10) ///< Invalid Flags 62 | #define NRF_ERROR_INVALID_DATA (NRF_ERROR_BASE_NUM + 11) ///< Invalid Data 63 | #define NRF_ERROR_DATA_SIZE (NRF_ERROR_BASE_NUM + 12) ///< Data size exceeds limit 64 | #define NRF_ERROR_TIMEOUT (NRF_ERROR_BASE_NUM + 13) ///< Operation timed out 65 | #define NRF_ERROR_NULL (NRF_ERROR_BASE_NUM + 14) ///< Null Pointer 66 | #define NRF_ERROR_FORBIDDEN (NRF_ERROR_BASE_NUM + 15) ///< Forbidden Operation 67 | #define NRF_ERROR_INVALID_ADDR (NRF_ERROR_BASE_NUM + 16) ///< Bad Memory Address 68 | #define NRF_ERROR_BUSY (NRF_ERROR_BASE_NUM + 17) ///< Busy 69 | 70 | #endif // NRF_ERROR_H__ 71 | 72 | /** 73 | @} 74 | */ 75 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/s130/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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /** 33 | @addtogroup nrf_sdm_api 34 | @{ 35 | @defgroup nrf_sdm_error SoftDevice Manager Error Codes 36 | @{ 37 | 38 | @brief Error definitions for the SDM API 39 | */ 40 | 41 | /* Header guard */ 42 | #ifndef NRF_ERROR_SDM_H__ 43 | #define NRF_ERROR_SDM_H__ 44 | 45 | #include "nrf_error.h" 46 | 47 | #define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN (NRF_ERROR_SDM_BASE_NUM + 0) ///< Unknown lfclk source. 48 | #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). 49 | #define NRF_ERROR_SDM_INCORRECT_CLENR0 (NRF_ERROR_SDM_BASE_NUM + 2) ///< Incorrect CLENR0 (can be caused by erronous SoftDevice flashing). 50 | 51 | #endif // NRF_ERROR_SDM_H__ 52 | 53 | /** 54 | @} 55 | @} 56 | */ 57 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/s130/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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /** 33 | @addtogroup nrf_soc_api 34 | @{ 35 | @defgroup nrf_soc_error SoC Library Error Codes 36 | @{ 37 | 38 | @brief Error definitions for the SoC library 39 | 40 | */ 41 | 42 | /* Header guard */ 43 | #ifndef NRF_ERROR_SOC_H__ 44 | #define NRF_ERROR_SOC_H__ 45 | 46 | #include "nrf_error.h" 47 | 48 | /* Mutex Errors */ 49 | #define NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN (NRF_ERROR_SOC_BASE_NUM + 0) ///< Mutex already taken 50 | 51 | /* NVIC errors */ 52 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE (NRF_ERROR_SOC_BASE_NUM + 1) ///< NVIC interrupt not available 53 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED (NRF_ERROR_SOC_BASE_NUM + 2) ///< NVIC interrupt priority not allowed 54 | #define NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 3) ///< NVIC should not return 55 | 56 | /* Power errors */ 57 | #define NRF_ERROR_SOC_POWER_MODE_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 4) ///< Power mode unknown 58 | #define NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 5) ///< Power POF threshold unknown 59 | #define NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 6) ///< Power off should not return 60 | 61 | /* Rand errors */ 62 | #define NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES (NRF_ERROR_SOC_BASE_NUM + 7) ///< RAND not enough values 63 | 64 | /* PPI errors */ 65 | #define NRF_ERROR_SOC_PPI_INVALID_CHANNEL (NRF_ERROR_SOC_BASE_NUM + 8) ///< Invalid PPI Channel 66 | #define NRF_ERROR_SOC_PPI_INVALID_GROUP (NRF_ERROR_SOC_BASE_NUM + 9) ///< Invalid PPI Group 67 | 68 | #endif // NRF_ERROR_SOC_H__ 69 | /** 70 | @} 71 | @} 72 | */ 73 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/s130/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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef NRF_SVC__ 34 | #define NRF_SVC__ 35 | 36 | #ifdef SVCALL_AS_NORMAL_FUNCTION 37 | #define SVCALL(number, return_type, signature) return_type signature 38 | #else 39 | 40 | #ifndef SVCALL 41 | #if defined (__CC_ARM) 42 | #define SVCALL(number, return_type, signature) return_type __svc(number) signature 43 | #elif defined (__GNUC__) 44 | #define SVCALL(number, return_type, signature) \ 45 | _Pragma("GCC diagnostic ignored \"-Wunused-function\"") \ 46 | _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"") \ 47 | _Pragma("GCC diagnostic push") \ 48 | _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \ 49 | __attribute__((naked)) static return_type signature \ 50 | { \ 51 | __asm( \ 52 | "svc %0\n" \ 53 | "bx r14" : : "I" ((uint32_t) number) : "r0" \ 54 | ); \ 55 | } \ 56 | _Pragma("GCC diagnostic pop") 57 | #elif defined (__ICCARM__) 58 | #define PRAGMA(x) _Pragma(#x) 59 | #define SVCALL(number, return_type, signature) \ 60 | PRAGMA(swi_number = number) \ 61 | __swi return_type signature; 62 | #else 63 | #define SVCALL(number, return_type, signature) return_type signature 64 | #endif 65 | #endif // SVCALL 66 | 67 | #endif // SVCALL_AS_NORMAL_FUNCTION 68 | #endif // NRF_SVC__ 69 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/softdevice/s130/headers/softdevice_assert.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | /** @brief Utilities for verifying program logic 34 | */ 35 | 36 | #ifndef SOFTDEVICE_ASSERT_H_ 37 | #define SOFTDEVICE_ASSERT_H_ 38 | 39 | #include 40 | 41 | /** @brief This function handles assertions. 42 | * 43 | * 44 | * @note 45 | * This function is called when an assertion has triggered. 46 | * 47 | * 48 | * @param line_num The line number where the assertion is called 49 | * @param file_name Pointer to the file name 50 | */ 51 | void assert_softdevice_callback(uint16_t line_num, const uint8_t *file_name); 52 | 53 | 54 | /*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 55 | /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \ 56 | /** @brief Check intended for production code 57 | * 58 | * Check passes if "expr" evaluates to true. */ 59 | #define ASSERT(expr) \ 60 | if (expr) \ 61 | { \ 62 | } \ 63 | else \ 64 | { \ 65 | assert_softdevice_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \ 66 | /*lint -unreachable */ \ 67 | } 68 | 69 | #endif /* SOFTDEVICE_ASSERT_H_ */ 70 | -------------------------------------------------------------------------------- /source/nordic_sdk/components/toolchain/system_nrf51.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 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | 33 | #ifndef SYSTEM_NRF51_H 34 | #define SYSTEM_NRF51_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #include 41 | 42 | 43 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 44 | 45 | /** 46 | * Initialize the system 47 | * 48 | * @param none 49 | * @return none 50 | * 51 | * @brief Setup the microcontroller system. 52 | * Initialize the System and update the SystemCoreClock variable. 53 | */ 54 | extern void SystemInit (void); 55 | 56 | /** 57 | * Update SystemCoreClock variable 58 | * 59 | * @param none 60 | * @return none 61 | * 62 | * @brief Updates the SystemCoreClock with current core Clock 63 | * retrieved from cpu registers. 64 | */ 65 | extern void SystemCoreClockUpdate (void); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* SYSTEM_NRF51_H */ 72 | -------------------------------------------------------------------------------- /source/prevent_bootloader_frame_pointer.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015 ARM Limited 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | message("omit frame pointer for bootloader startup asm") 16 | 17 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") 18 | set_source_files_properties( 19 | "${CMAKE_CURRENT_LIST_DIR}/nordic_sdk/components/libraries/bootloader_dfu/bootloader_util.c" 20 | PROPERTIES COMPILE_FLAGS -fomit-frame-pointer) 21 | endif() 22 | -------------------------------------------------------------------------------- /source/supress-warnings.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2015 ARM Limited 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | message("suppressing warnings from nrf51-sdk") 16 | 17 | if(CMAKE_C_COMPILER_ID STREQUAL "GNU") 18 | set_target_properties(nrf51-sdk 19 | PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-missing-field-initializers" 20 | ) 21 | endif() 22 | --------------------------------------------------------------------------------