Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
ble_flash.h
00001 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is property of Nordic Semiconductor ASA. 00004 * Terms and conditions of usage are described in detail in NORDIC 00005 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 */ 00012 00013 /** @file 00014 * 00015 * @defgroup ble_flash_module Flash Manager 00016 * @{ 00017 * @ingroup ble_sdk_lib 00018 * @brief Module for accessing flash memory. 00019 * 00020 * @details It contains functions for reading, writing and erasing one page in flash. 00021 * 00022 * The module uses the first 32 bits of the flash page to write a magic number in order to 00023 * determine if the page has been written or not. 00024 * 00025 * @note Be careful not to use a page number in the SoftDevice area (which currently occupies the 00026 * range 0 to 127), or in your application space! In both cases, this would end up 00027 * with a hard fault. 00028 */ 00029 00030 #ifndef BLE_FLASH_H__ 00031 #define BLE_FLASH_H__ 00032 00033 #include <stdint.h> 00034 #include <stdbool.h> 00035 #include <nrf51.h> 00036 #include "nordic_global.h" 00037 00038 #define BLE_FLASH_PAGE_SIZE ((uint16_t)NRF_FICR->CODEPAGESIZE) /**< Size of one flash page. */ 00039 #define BLE_FLASH_MAGIC_NUMBER 0x45DE0000 /**< Magic value to identify if flash contains valid data. */ 00040 #define BLE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */ 00041 00042 00043 /**@brief Macro for getting the end of the flash available for application. 00044 * 00045 * @details The result flash page number indicates the end boundary of the flash available 00046 * to the application. If a bootloader is used, the end will be the start of the 00047 * bootloader region. Otherwise, the end will be the size of the flash. 00048 */ 00049 #define BLE_FLASH_PAGE_END \ 00050 ((NRF_UICR->BOOTLOADERADDR != BLE_FLASH_EMPTY_MASK) \ 00051 ? (NRF_UICR->BOOTLOADERADDR / BLE_FLASH_PAGE_SIZE) \ 00052 : NRF_FICR->CODESIZE) 00053 00054 /**@brief Function for erasing the specified flash page, and then writes the given data to this page. 00055 * 00056 * @warning This operation blocks the CPU. DO NOT use while in a connection! 00057 * 00058 * @param[in] page_num Page number to update. 00059 * @param[in] p_in_array Pointer to a RAM area containing the elements to write in flash. 00060 * This area has to be 32 bits aligned. 00061 * @param[in] word_count Number of 32 bits words to write in flash. 00062 * 00063 * @return NRF_SUCCESS on successful flash write, otherwise an error code. 00064 */ 00065 uint32_t ble_flash_page_write(uint8_t page_num, uint32_t * p_in_array, uint8_t word_count); 00066 00067 /**@brief Function for reading data from flash to RAM. 00068 * 00069 * @param[in] page_num Page number to read. 00070 * @param[out] p_out_array Pointer to a RAM area where the found data will be written. 00071 * This area has to be 32 bits aligned. 00072 * @param[out] p_word_count Number of 32 bits words read. 00073 * 00074 * @return NRF_SUCCESS on successful upload, NRF_ERROR_NOT_FOUND if no valid data has been found 00075 * in flash (first 32 bits not equal to the MAGIC_NUMBER+CRC). 00076 */ 00077 uint32_t ble_flash_page_read(uint8_t page_num, uint32_t * p_out_array, uint8_t * p_word_count); 00078 00079 /**@brief Function for erasing a flash page. 00080 * 00081 * @note This operation blocks the CPU, so it should not be done while the radio is running! 00082 * 00083 * @param[in] page_num Page number to erase. 00084 * 00085 * @return NRF_SUCCESS on success, an error_code otherwise. 00086 */ 00087 uint32_t ble_flash_page_erase(uint8_t page_num); 00088 00089 /**@brief Function for writing one word to flash. 00090 * 00091 * @note Flash location to be written must have been erased previously. 00092 * 00093 * @param[in] p_address Pointer to flash location to be written. 00094 * @param[in] value Value to write to flash. 00095 * 00096 * @return NRF_SUCCESS. 00097 */ 00098 uint32_t ble_flash_word_write(uint32_t * p_address, uint32_t value); 00099 00100 /**@brief Function for writing a data block to flash. 00101 * 00102 * @note Flash locations to be written must have been erased previously. 00103 * 00104 * @param[in] p_address Pointer to start of flash location to be written. 00105 * @param[in] p_in_array Pointer to start of flash block to be written. 00106 * @param[in] word_count Number of words to be written. 00107 * 00108 * @return NRF_SUCCESS. 00109 */ 00110 uint32_t ble_flash_block_write(uint32_t * p_address, uint32_t * p_in_array, uint16_t word_count); 00111 00112 /**@brief Function for computing pointer to start of specified flash page. 00113 * 00114 * @param[in] page_num Page number. 00115 * @param[out] pp_page_addr Pointer to start of flash page. 00116 * 00117 * @return NRF_SUCCESS. 00118 */ 00119 uint32_t ble_flash_page_addr(uint8_t page_num, uint32_t ** pp_page_addr); 00120 00121 /**@brief Function for calculating a 16 bit CRC using the CRC-16-CCITT scheme. 00122 * 00123 * @param[in] p_data Pointer to data on which the CRC is to be calulated. 00124 * @param[in] size Number of bytes on which the CRC is to be calulated. 00125 * @param[in] p_crc Initial CRC value (if NULL, a preset value is used as the initial value). 00126 * 00127 * @return Calculated CRC. 00128 */ 00129 uint16_t ble_flash_crc16_compute(uint8_t * p_data, uint16_t size, uint16_t * p_crc); 00130 00131 /**@brief Function for handling flashing module Radio Notification event. 00132 * 00133 * @note For flash writing to work safely while in a connection or while advertising, this function 00134 * MUST be called from the Radio Notification module's event handler (see 00135 * @ref ble_radio_notification for details). 00136 * 00137 * @param[in] radio_active TRUE if radio is active (or about to become active), FALSE otherwise. 00138 */ 00139 void ble_flash_on_radio_active_evt(bool radio_active); 00140 00141 #endif // BLE_FLASH_H__ 00142 00143 /** @} */
Generated on Tue Jul 12 2022 19:00:52 by
