Nordic stack and drivers for the mbed BLE API

Dependents:   BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate writable_gatt ... more

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 638:c90ae1400bf2 1 /*
Vincent Coubard 638:c90ae1400bf2 2 * Copyright (c) Nordic Semiconductor ASA
Vincent Coubard 638:c90ae1400bf2 3 * All rights reserved.
Vincent Coubard 638:c90ae1400bf2 4 *
Vincent Coubard 638:c90ae1400bf2 5 * Redistribution and use in source and binary forms, with or without modification,
Vincent Coubard 638:c90ae1400bf2 6 * are permitted provided that the following conditions are met:
Vincent Coubard 638:c90ae1400bf2 7 *
Vincent Coubard 638:c90ae1400bf2 8 * 1. Redistributions of source code must retain the above copyright notice, this
Vincent Coubard 638:c90ae1400bf2 9 * list of conditions and the following disclaimer.
Vincent Coubard 638:c90ae1400bf2 10 *
Vincent Coubard 638:c90ae1400bf2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Vincent Coubard 638:c90ae1400bf2 12 * list of conditions and the following disclaimer in the documentation and/or
Vincent Coubard 638:c90ae1400bf2 13 * other materials provided with the distribution.
Vincent Coubard 638:c90ae1400bf2 14 *
Vincent Coubard 638:c90ae1400bf2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Vincent Coubard 638:c90ae1400bf2 16 * contributors to this software may be used to endorse or promote products
Vincent Coubard 638:c90ae1400bf2 17 * derived from this software without specific prior written permission.
Vincent Coubard 638:c90ae1400bf2 18 *
Vincent Coubard 638:c90ae1400bf2 19 *
Vincent Coubard 638:c90ae1400bf2 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Vincent Coubard 638:c90ae1400bf2 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 638:c90ae1400bf2 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 638:c90ae1400bf2 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Vincent Coubard 638:c90ae1400bf2 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 638:c90ae1400bf2 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 638:c90ae1400bf2 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Vincent Coubard 638:c90ae1400bf2 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 638:c90ae1400bf2 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 638:c90ae1400bf2 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 638:c90ae1400bf2 30 *
Vincent Coubard 638:c90ae1400bf2 31 */
Vincent Coubard 638:c90ae1400bf2 32
Vincent Coubard 638:c90ae1400bf2 33 /** @cond To make doxygen skip this file */
Vincent Coubard 638:c90ae1400bf2 34
Vincent Coubard 638:c90ae1400bf2 35 /** @file
Vincent Coubard 638:c90ae1400bf2 36 * This header contains defines with respect persistent storage that are specific to
Vincent Coubard 638:c90ae1400bf2 37 * persistent storage implementation and application use case.
Vincent Coubard 638:c90ae1400bf2 38 */
Vincent Coubard 638:c90ae1400bf2 39 #ifndef PSTORAGE_PL_H__
Vincent Coubard 638:c90ae1400bf2 40 #define PSTORAGE_PL_H__
Vincent Coubard 638:c90ae1400bf2 41
Vincent Coubard 638:c90ae1400bf2 42 #include <stdint.h>
Vincent Coubard 638:c90ae1400bf2 43 #include "nrf.h"
Vincent Coubard 638:c90ae1400bf2 44
Vincent Coubard 638:c90ae1400bf2 45 static __INLINE uint16_t pstorage_flash_page_size()
Vincent Coubard 638:c90ae1400bf2 46 {
Vincent Coubard 638:c90ae1400bf2 47 return (uint16_t)NRF_FICR->CODEPAGESIZE;
Vincent Coubard 638:c90ae1400bf2 48 }
Vincent Coubard 638:c90ae1400bf2 49
Vincent Coubard 638:c90ae1400bf2 50 #define PSTORAGE_FLASH_PAGE_SIZE pstorage_flash_page_size() /**< Size of one flash page. */
Vincent Coubard 638:c90ae1400bf2 51 #define PSTORAGE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
Vincent Coubard 638:c90ae1400bf2 52
Vincent Coubard 638:c90ae1400bf2 53 #ifdef NRF51
Vincent Coubard 638:c90ae1400bf2 54 #define BOOTLOADER_ADDRESS (NRF_UICR->BOOTLOADERADDR)
Vincent Coubard 638:c90ae1400bf2 55 #elif defined NRF52
Vincent Coubard 638:c90ae1400bf2 56 #define BOOTLOADER_ADDRESS (PSTORAGE_FLASH_EMPTY_MASK)
Vincent Coubard 638:c90ae1400bf2 57 #endif
Vincent Coubard 638:c90ae1400bf2 58
Vincent Coubard 638:c90ae1400bf2 59 static __INLINE uint32_t pstorage_flash_page_end()
Vincent Coubard 638:c90ae1400bf2 60 {
Vincent Coubard 638:c90ae1400bf2 61 uint32_t bootloader_addr = BOOTLOADER_ADDRESS;
Vincent Coubard 638:c90ae1400bf2 62
Vincent Coubard 638:c90ae1400bf2 63 return ((bootloader_addr != PSTORAGE_FLASH_EMPTY_MASK) ?
Vincent Coubard 638:c90ae1400bf2 64 (bootloader_addr/ PSTORAGE_FLASH_PAGE_SIZE) : NRF_FICR->CODESIZE);
Vincent Coubard 638:c90ae1400bf2 65 }
Vincent Coubard 638:c90ae1400bf2 66
Vincent Coubard 638:c90ae1400bf2 67 #define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end()
Vincent Coubard 638:c90ae1400bf2 68
Vincent Coubard 638:c90ae1400bf2 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. */
Vincent Coubard 638:c90ae1400bf2 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. */
Vincent Coubard 638:c90ae1400bf2 71
Vincent Coubard 638:c90ae1400bf2 72 #define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
Vincent Coubard 638:c90ae1400bf2 73 * PSTORAGE_FLASH_PAGE_SIZE) /**< Start address for persistent data, configurable according to system requirements. */
Vincent Coubard 638:c90ae1400bf2 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. */
Vincent Coubard 638:c90ae1400bf2 75 #define PSTORAGE_SWAP_ADDR PSTORAGE_DATA_END_ADDR /**< Top-most page is used as swap area for clear and update. */
Vincent Coubard 638:c90ae1400bf2 76
Vincent Coubard 638:c90ae1400bf2 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. */
Vincent Coubard 638:c90ae1400bf2 78 #define PSTORAGE_CMD_QUEUE_SIZE 2 /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */
Vincent Coubard 638:c90ae1400bf2 79
Vincent Coubard 638:c90ae1400bf2 80
Vincent Coubard 638:c90ae1400bf2 81 /** Abstracts persistently memory block identifier. */
Vincent Coubard 638:c90ae1400bf2 82 typedef uint32_t pstorage_block_t;
Vincent Coubard 638:c90ae1400bf2 83
Vincent Coubard 638:c90ae1400bf2 84 typedef struct
Vincent Coubard 638:c90ae1400bf2 85 {
Vincent Coubard 638:c90ae1400bf2 86 uint32_t module_id; /**< Module ID.*/
Vincent Coubard 638:c90ae1400bf2 87 pstorage_block_t block_id; /**< Block ID.*/
Vincent Coubard 638:c90ae1400bf2 88 } pstorage_handle_t;
Vincent Coubard 638:c90ae1400bf2 89
Vincent Coubard 638:c90ae1400bf2 90 typedef uint16_t pstorage_size_t; /** Size of length and offset fields. */
Vincent Coubard 638:c90ae1400bf2 91
Vincent Coubard 638:c90ae1400bf2 92 /**@brief Handles Flash Access Result Events. To be called in the system event dispatcher of the application. */
Vincent Coubard 638:c90ae1400bf2 93 void pstorage_sys_event_handler (uint32_t sys_evt);
Vincent Coubard 638:c90ae1400bf2 94
Vincent Coubard 638:c90ae1400bf2 95 #endif // PSTORAGE_PL_H__
Vincent Coubard 638:c90ae1400bf2 96
Vincent Coubard 638:c90ae1400bf2 97 /** @} */
Vincent Coubard 638:c90ae1400bf2 98 /** @endcond */