updates

Fork of nrf51-sdk by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pstorage_platform.h Source File

pstorage_platform.h

00001 /*
00002  * Copyright (c) Nordic Semiconductor ASA
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without modification,
00006  * are permitted provided that the following conditions are met:
00007  *
00008  *   1. Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  *
00011  *   2. Redistributions in binary form must reproduce the above copyright notice, this
00012  *   list of conditions and the following disclaimer in the documentation and/or
00013  *   other materials provided with the distribution.
00014  *
00015  *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
00016  *   contributors to this software may be used to endorse or promote products
00017  *   derived from this software without specific prior written permission.
00018  *
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00024  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00027  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  */
00032 
00033  /** @cond To make doxygen skip this file */
00034 
00035 /** @file
00036  *  This header contains defines with respect persistent storage that are specific to
00037  *  persistent storage implementation and application use case.
00038  */
00039 #ifndef PSTORAGE_PL_H__
00040 #define PSTORAGE_PL_H__
00041 
00042 #include <stdint.h>
00043 #include "nrf.h"
00044 
00045 static __INLINE uint16_t pstorage_flash_page_size()
00046 {
00047   return (uint16_t)NRF_FICR->CODEPAGESIZE;
00048 }
00049 
00050 #define PSTORAGE_FLASH_PAGE_SIZE     pstorage_flash_page_size()          /**< Size of one flash page. */
00051 #define PSTORAGE_FLASH_EMPTY_MASK    0xFFFFFFFF                          /**< Bit mask that defines an empty address in flash. */
00052 
00053 #ifdef NRF51
00054 #define BOOTLOADER_ADDRESS           (NRF_UICR->BOOTLOADERADDR)
00055 #elif defined NRF52
00056 #define BOOTLOADER_ADDRESS           (PSTORAGE_FLASH_EMPTY_MASK)
00057 #endif 
00058 
00059 static __INLINE uint32_t pstorage_flash_page_end()
00060 {
00061    uint32_t bootloader_addr = BOOTLOADER_ADDRESS;
00062   
00063    return ((bootloader_addr != PSTORAGE_FLASH_EMPTY_MASK) ?
00064            (bootloader_addr/ PSTORAGE_FLASH_PAGE_SIZE) : NRF_FICR->CODESIZE);
00065 }
00066 
00067 #define PSTORAGE_FLASH_PAGE_END     pstorage_flash_page_end()
00068 
00069 #define PSTORAGE_NUM_OF_PAGES       1                                                           /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */
00070 #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. */
00071 
00072 #define PSTORAGE_DATA_START_ADDR    ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
00073                                     * PSTORAGE_FLASH_PAGE_SIZE)                                 /**< Start address for persistent data, configurable according to system requirements. */
00074 #define PSTORAGE_DATA_END_ADDR      ((PSTORAGE_FLASH_PAGE_END - 1) * PSTORAGE_FLASH_PAGE_SIZE)  /**< End address for persistent data, configurable according to system requirements. */
00075 #define PSTORAGE_SWAP_ADDR          PSTORAGE_DATA_END_ADDR                                      /**< Top-most page is used as swap area for clear and update. */
00076 
00077 #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. */
00078 #define PSTORAGE_CMD_QUEUE_SIZE     2                                                           /**< Maximum number of flash access commands that can be maintained by the module for all applications. Configurable. */
00079 
00080 
00081 /** Abstracts persistently memory block identifier. */
00082 typedef uint32_t pstorage_block_t;
00083 
00084 typedef struct
00085 {
00086     uint32_t            module_id;      /**< Module ID.*/
00087     pstorage_block_t    block_id;       /**< Block ID.*/
00088 } pstorage_handle_t;
00089 
00090 typedef uint16_t pstorage_size_t;      /** Size of length and offset fields. */
00091 
00092 /**@brief Handles Flash Access Result Events. To be called in the system event dispatcher of the application. */
00093 void pstorage_sys_event_handler (uint32_t sys_evt);
00094 
00095 #endif // PSTORAGE_PL_H__
00096 
00097 /** @} */
00098 /** @endcond */