Nordic nrf51 sdk sources. Mirrored from https://github.com/ARMmbed/nrf51-sdk.
source/nordic_sdk/components/drivers_nrf/pstorage/config/pstorage_platform.h@11:53378d902308, 2016-04-07 (annotated)
- Committer:
- vcoubard
- Date:
- Thu Apr 07 17:37:29 2016 +0100
- Revision:
- 11:53378d902308
- Parent:
- 10:233fefd8162b
- Child:
- 19:47192cb9def7
Synchronized with git rev 82b18a5c
Author: Liyou Zhou
Porting some of the changes made to nordic files
from ble-nrf51822 module
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 10:233fefd8162b | 1 | /* |
vcoubard | 10:233fefd8162b | 2 | * Copyright (c) Nordic Semiconductor ASA |
vcoubard | 10:233fefd8162b | 3 | * All rights reserved. |
vcoubard | 10:233fefd8162b | 4 | * |
vcoubard | 10:233fefd8162b | 5 | * Redistribution and use in source and binary forms, with or without modification, |
vcoubard | 10:233fefd8162b | 6 | * are permitted provided that the following conditions are met: |
vcoubard | 10:233fefd8162b | 7 | * |
vcoubard | 10:233fefd8162b | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
vcoubard | 10:233fefd8162b | 9 | * list of conditions and the following disclaimer. |
vcoubard | 10:233fefd8162b | 10 | * |
vcoubard | 10:233fefd8162b | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
vcoubard | 10:233fefd8162b | 12 | * list of conditions and the following disclaimer in the documentation and/or |
vcoubard | 10:233fefd8162b | 13 | * other materials provided with the distribution. |
vcoubard | 10:233fefd8162b | 14 | * |
vcoubard | 10:233fefd8162b | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
vcoubard | 10:233fefd8162b | 16 | * contributors to this software may be used to endorse or promote products |
vcoubard | 10:233fefd8162b | 17 | * derived from this software without specific prior written permission. |
vcoubard | 10:233fefd8162b | 18 | * |
vcoubard | 10:233fefd8162b | 19 | * |
vcoubard | 10:233fefd8162b | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
vcoubard | 10:233fefd8162b | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
vcoubard | 10:233fefd8162b | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
vcoubard | 10:233fefd8162b | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
vcoubard | 10:233fefd8162b | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
vcoubard | 10:233fefd8162b | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
vcoubard | 10:233fefd8162b | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
vcoubard | 10:233fefd8162b | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
vcoubard | 10:233fefd8162b | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
vcoubard | 10:233fefd8162b | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
vcoubard | 10:233fefd8162b | 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 | |
Vincent Coubard |
0:f2542974c862 | 63 | #define PSTORAGE_MAX_APPLICATIONS 1 /**< Maximum number of applications that can be registered with the module, 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 | |
Vincent Coubard |
0:f2542974c862 | 66 | #define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_MAX_APPLICATIONS - 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 | 11:53378d902308 | 72 | #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 |
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 */ |