The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_NRF51_DK/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/drivers_nrf/ble_flash/ble_flash.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2012 Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 3 * All rights reserved.
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * 1. Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
AnnaBridge 143:86740a56073b 12 * integrated circuit in a product or a software update for such product, must reproduce
AnnaBridge 143:86740a56073b 13 * the above copyright notice, this list of conditions and the following disclaimer in
AnnaBridge 143:86740a56073b 14 * the documentation and/or other materials provided with the distribution.
AnnaBridge 143:86740a56073b 15 *
AnnaBridge 143:86740a56073b 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
AnnaBridge 143:86740a56073b 17 * used to endorse or promote products derived from this software without specific prior
AnnaBridge 143:86740a56073b 18 * written permission.
AnnaBridge 143:86740a56073b 19 *
AnnaBridge 143:86740a56073b 20 * 4. This software, with or without modification, must only be used with a
AnnaBridge 143:86740a56073b 21 * Nordic Semiconductor ASA integrated circuit.
AnnaBridge 143:86740a56073b 22 *
AnnaBridge 143:86740a56073b 23 * 5. Any software provided in binary or object form under this license must not be reverse
AnnaBridge 143:86740a56073b 24 * engineered, decompiled, modified and/or disassembled.
AnnaBridge 143:86740a56073b 25 *
AnnaBridge 143:86740a56073b 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 36 *
AnnaBridge 143:86740a56073b 37 */
AnnaBridge 143:86740a56073b 38
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40 /** @file
AnnaBridge 143:86740a56073b 41 *
AnnaBridge 143:86740a56073b 42 * @defgroup ble_flash_module Flash Manager
AnnaBridge 143:86740a56073b 43 * @{
AnnaBridge 143:86740a56073b 44 * @ingroup ble_sdk_lib
AnnaBridge 143:86740a56073b 45 * @brief Module for accessing flash memory.
AnnaBridge 143:86740a56073b 46 *
AnnaBridge 143:86740a56073b 47 * @details It contains functions for reading, writing and erasing one page in flash.
AnnaBridge 143:86740a56073b 48 *
AnnaBridge 143:86740a56073b 49 * The module uses the first 32 bits of the flash page to write a magic number in order to
AnnaBridge 143:86740a56073b 50 * determine if the page has been written or not.
AnnaBridge 143:86740a56073b 51 *
AnnaBridge 143:86740a56073b 52 * @note Be careful not to use a page number in the SoftDevice area (which currently occupies the
AnnaBridge 143:86740a56073b 53 * range 0 to 127), or in your application space! In both cases, this would end up
AnnaBridge 143:86740a56073b 54 * with a hard fault.
AnnaBridge 143:86740a56073b 55 */
AnnaBridge 143:86740a56073b 56
AnnaBridge 143:86740a56073b 57 #ifndef BLE_FLASH_H__
AnnaBridge 143:86740a56073b 58 #define BLE_FLASH_H__
AnnaBridge 143:86740a56073b 59
AnnaBridge 143:86740a56073b 60 #include <stdint.h>
AnnaBridge 143:86740a56073b 61 #include <stdbool.h>
AnnaBridge 143:86740a56073b 62 #include "nrf.h"
AnnaBridge 143:86740a56073b 63
AnnaBridge 143:86740a56073b 64 #define BLE_FLASH_PAGE_SIZE ((uint16_t)NRF_FICR->CODEPAGESIZE) /**< Size of one flash page. */
AnnaBridge 143:86740a56073b 65 #define BLE_FLASH_MAGIC_NUMBER 0x45DE0000 /**< Magic value to identify if flash contains valid data. */
AnnaBridge 143:86740a56073b 66 #define BLE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
AnnaBridge 143:86740a56073b 67
AnnaBridge 143:86740a56073b 68
AnnaBridge 143:86740a56073b 69 /**@brief Macro for getting the end of the flash available for application.
AnnaBridge 143:86740a56073b 70 *
AnnaBridge 143:86740a56073b 71 * @details The result flash page number indicates the end boundary of the flash available
AnnaBridge 143:86740a56073b 72 * to the application. If a bootloader is used, the end will be the start of the
AnnaBridge 143:86740a56073b 73 * bootloader region. Otherwise, the end will be the size of the flash.
AnnaBridge 143:86740a56073b 74 */
AnnaBridge 143:86740a56073b 75 #define BLE_FLASH_PAGE_END \
AnnaBridge 143:86740a56073b 76 ((NRF_UICR->NRFFW[0] != BLE_FLASH_EMPTY_MASK) \
AnnaBridge 143:86740a56073b 77 ? (NRF_UICR->NRFFW[0] / BLE_FLASH_PAGE_SIZE) \
AnnaBridge 143:86740a56073b 78 : NRF_FICR->CODESIZE)
AnnaBridge 143:86740a56073b 79
AnnaBridge 143:86740a56073b 80 /**@brief Function for erasing the specified flash page, and then writes the given data to this page.
AnnaBridge 143:86740a56073b 81 *
AnnaBridge 143:86740a56073b 82 * @warning This operation blocks the CPU. DO NOT use while in a connection!
AnnaBridge 143:86740a56073b 83 *
AnnaBridge 143:86740a56073b 84 * @param[in] page_num Page number to update.
AnnaBridge 143:86740a56073b 85 * @param[in] p_in_array Pointer to a RAM area containing the elements to write in flash.
AnnaBridge 143:86740a56073b 86 * This area has to be 32 bits aligned.
AnnaBridge 143:86740a56073b 87 * @param[in] word_count Number of 32 bits words to write in flash.
AnnaBridge 143:86740a56073b 88 *
AnnaBridge 143:86740a56073b 89 * @return NRF_SUCCESS on successful flash write, otherwise an error code.
AnnaBridge 143:86740a56073b 90 */
AnnaBridge 143:86740a56073b 91 uint32_t ble_flash_page_write(uint8_t page_num, uint32_t * p_in_array, uint8_t word_count);
AnnaBridge 143:86740a56073b 92
AnnaBridge 143:86740a56073b 93 /**@brief Function for reading data from flash to RAM.
AnnaBridge 143:86740a56073b 94 *
AnnaBridge 143:86740a56073b 95 * @param[in] page_num Page number to read.
AnnaBridge 143:86740a56073b 96 * @param[out] p_out_array Pointer to a RAM area where the found data will be written.
AnnaBridge 143:86740a56073b 97 * This area has to be 32 bits aligned.
AnnaBridge 143:86740a56073b 98 * @param[out] p_word_count Number of 32 bits words read.
AnnaBridge 143:86740a56073b 99 *
AnnaBridge 143:86740a56073b 100 * @return NRF_SUCCESS on successful upload, NRF_ERROR_NOT_FOUND if no valid data has been found
AnnaBridge 143:86740a56073b 101 * in flash (first 32 bits not equal to the MAGIC_NUMBER+CRC).
AnnaBridge 143:86740a56073b 102 */
AnnaBridge 143:86740a56073b 103 uint32_t ble_flash_page_read(uint8_t page_num, uint32_t * p_out_array, uint8_t * p_word_count);
AnnaBridge 143:86740a56073b 104
AnnaBridge 143:86740a56073b 105 /**@brief Function for erasing a flash page.
AnnaBridge 143:86740a56073b 106 *
AnnaBridge 143:86740a56073b 107 * @note This operation blocks the CPU, so it should not be done while the radio is running!
AnnaBridge 143:86740a56073b 108 *
AnnaBridge 143:86740a56073b 109 * @param[in] page_num Page number to erase.
AnnaBridge 143:86740a56073b 110 *
AnnaBridge 143:86740a56073b 111 * @return NRF_SUCCESS on success, an error_code otherwise.
AnnaBridge 143:86740a56073b 112 */
AnnaBridge 143:86740a56073b 113 uint32_t ble_flash_page_erase(uint8_t page_num);
AnnaBridge 143:86740a56073b 114
AnnaBridge 143:86740a56073b 115 /**@brief Function for writing one word to flash.
AnnaBridge 143:86740a56073b 116 *
AnnaBridge 143:86740a56073b 117 * @note Flash location to be written must have been erased previously.
AnnaBridge 143:86740a56073b 118 *
AnnaBridge 143:86740a56073b 119 * @param[in] p_address Pointer to flash location to be written.
AnnaBridge 143:86740a56073b 120 * @param[in] value Value to write to flash.
AnnaBridge 143:86740a56073b 121 *
AnnaBridge 143:86740a56073b 122 * @return NRF_SUCCESS.
AnnaBridge 143:86740a56073b 123 */
AnnaBridge 143:86740a56073b 124 uint32_t ble_flash_word_write(uint32_t * p_address, uint32_t value);
AnnaBridge 143:86740a56073b 125
AnnaBridge 143:86740a56073b 126 /**@brief Function for writing a data block to flash.
AnnaBridge 143:86740a56073b 127 *
AnnaBridge 143:86740a56073b 128 * @note Flash locations to be written must have been erased previously.
AnnaBridge 143:86740a56073b 129 *
AnnaBridge 143:86740a56073b 130 * @param[in] p_address Pointer to start of flash location to be written.
AnnaBridge 143:86740a56073b 131 * @param[in] p_in_array Pointer to start of flash block to be written.
AnnaBridge 143:86740a56073b 132 * @param[in] word_count Number of words to be written.
AnnaBridge 143:86740a56073b 133 *
AnnaBridge 143:86740a56073b 134 * @return NRF_SUCCESS.
AnnaBridge 143:86740a56073b 135 */
AnnaBridge 143:86740a56073b 136 uint32_t ble_flash_block_write(uint32_t * p_address, uint32_t * p_in_array, uint16_t word_count);
AnnaBridge 143:86740a56073b 137
AnnaBridge 143:86740a56073b 138 /**@brief Function for computing pointer to start of specified flash page.
AnnaBridge 143:86740a56073b 139 *
AnnaBridge 143:86740a56073b 140 * @param[in] page_num Page number.
AnnaBridge 143:86740a56073b 141 * @param[out] pp_page_addr Pointer to start of flash page.
AnnaBridge 143:86740a56073b 142 *
AnnaBridge 143:86740a56073b 143 * @return NRF_SUCCESS.
AnnaBridge 143:86740a56073b 144 */
AnnaBridge 143:86740a56073b 145 uint32_t ble_flash_page_addr(uint8_t page_num, uint32_t ** pp_page_addr);
AnnaBridge 143:86740a56073b 146
AnnaBridge 143:86740a56073b 147 /**@brief Function for calculating a 16 bit CRC using the CRC-16-CCITT scheme.
AnnaBridge 143:86740a56073b 148 *
AnnaBridge 143:86740a56073b 149 * @param[in] p_data Pointer to data on which the CRC is to be calulated.
AnnaBridge 143:86740a56073b 150 * @param[in] size Number of bytes on which the CRC is to be calulated.
AnnaBridge 143:86740a56073b 151 * @param[in] p_crc Initial CRC value (if NULL, a preset value is used as the initial value).
AnnaBridge 143:86740a56073b 152 *
AnnaBridge 143:86740a56073b 153 * @return Calculated CRC.
AnnaBridge 143:86740a56073b 154 */
AnnaBridge 143:86740a56073b 155 uint16_t ble_flash_crc16_compute(uint8_t * p_data, uint16_t size, uint16_t * p_crc);
AnnaBridge 143:86740a56073b 156
AnnaBridge 143:86740a56073b 157 /**@brief Function for handling flashing module Radio Notification event.
AnnaBridge 143:86740a56073b 158 *
AnnaBridge 143:86740a56073b 159 * @note For flash writing to work safely while in a connection or while advertising, this function
AnnaBridge 143:86740a56073b 160 * MUST be called from the Radio Notification module's event handler (see
AnnaBridge 143:86740a56073b 161 * @ref ble_radio_notification for details).
AnnaBridge 143:86740a56073b 162 *
AnnaBridge 143:86740a56073b 163 * @param[in] radio_active TRUE if radio is active (or about to become active), FALSE otherwise.
AnnaBridge 143:86740a56073b 164 */
AnnaBridge 143:86740a56073b 165 void ble_flash_on_radio_active_evt(bool radio_active);
AnnaBridge 143:86740a56073b 166
AnnaBridge 143:86740a56073b 167 #endif // BLE_FLASH_H__
AnnaBridge 143:86740a56073b 168
AnnaBridge 143:86740a56073b 169 /** @} */