Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.

Dependents:   nRF51822 nRF51822

Committer:
vcoubard
Date:
Thu Apr 07 17:37:49 2016 +0100
Revision:
24:2aea0c1c57ee
Parent:
22:67a8d2c0bbbf
Child:
25:ad876954db55
Synchronized with git rev 709d3cdb
Author: Liyou Zhou
Change version number in README

Who changed what in which revision?

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