テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:8468a4403fea 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
jksoft 0:8468a4403fea 2 *
jksoft 0:8468a4403fea 3 * The information contained herein is property of Nordic Semiconductor ASA.
jksoft 0:8468a4403fea 4 * Terms and conditions of usage are described in detail in NORDIC
jksoft 0:8468a4403fea 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
jksoft 0:8468a4403fea 6 *
jksoft 0:8468a4403fea 7 * Licensees are granted free, non-transferable use of the information. NO
jksoft 0:8468a4403fea 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
jksoft 0:8468a4403fea 9 * the file.
jksoft 0:8468a4403fea 10 *
jksoft 0:8468a4403fea 11 */
jksoft 0:8468a4403fea 12
jksoft 0:8468a4403fea 13 /** @file
jksoft 0:8468a4403fea 14 *
jksoft 0:8468a4403fea 15 * @defgroup ble_flash_module Flash Manager
jksoft 0:8468a4403fea 16 * @{
jksoft 0:8468a4403fea 17 * @ingroup ble_sdk_lib
jksoft 0:8468a4403fea 18 * @brief Module for accessing flash memory.
jksoft 0:8468a4403fea 19 *
jksoft 0:8468a4403fea 20 * @details It contains functions for reading, writing and erasing one page in flash.
jksoft 0:8468a4403fea 21 *
jksoft 0:8468a4403fea 22 * The module uses the first 32 bits of the flash page to write a magic number in order to
jksoft 0:8468a4403fea 23 * determine if the page has been written or not.
jksoft 0:8468a4403fea 24 *
jksoft 0:8468a4403fea 25 * @note Be careful not to use a page number in the SoftDevice area (which currently occupies the
jksoft 0:8468a4403fea 26 * range 0 to 127), or in your application space! In both cases, this would end up
jksoft 0:8468a4403fea 27 * with a hard fault.
jksoft 0:8468a4403fea 28 */
jksoft 0:8468a4403fea 29
jksoft 0:8468a4403fea 30 #ifndef BLE_FLASH_H__
jksoft 0:8468a4403fea 31 #define BLE_FLASH_H__
jksoft 0:8468a4403fea 32
jksoft 0:8468a4403fea 33 #include <stdint.h>
jksoft 0:8468a4403fea 34 #include <stdbool.h>
jksoft 0:8468a4403fea 35 #include <nrf51.h>
jksoft 0:8468a4403fea 36
jksoft 0:8468a4403fea 37 #define BLE_FLASH_PAGE_SIZE ((uint16_t)NRF_FICR->CODEPAGESIZE) /**< Size of one flash page. */
jksoft 0:8468a4403fea 38 #define BLE_FLASH_MAGIC_NUMBER 0x45DE0000 /**< Magic value to identify if flash contains valid data. */
jksoft 0:8468a4403fea 39 #define BLE_FLASH_EMPTY_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
jksoft 0:8468a4403fea 40
jksoft 0:8468a4403fea 41
jksoft 0:8468a4403fea 42 /**@brief Macro for getting the end of the flash available for application.
jksoft 0:8468a4403fea 43 *
jksoft 0:8468a4403fea 44 * @details The result flash page number indicates the end boundary of the flash available
jksoft 0:8468a4403fea 45 * to the application. If a bootloader is used, the end will be the start of the
jksoft 0:8468a4403fea 46 * bootloader region. Otherwise, the end will be the size of the flash.
jksoft 0:8468a4403fea 47 */
jksoft 0:8468a4403fea 48 #define BLE_FLASH_PAGE_END \
jksoft 0:8468a4403fea 49 ((NRF_UICR->BOOTLOADERADDR != BLE_FLASH_EMPTY_MASK) \
jksoft 0:8468a4403fea 50 ? (NRF_UICR->BOOTLOADERADDR / BLE_FLASH_PAGE_SIZE) \
jksoft 0:8468a4403fea 51 : NRF_FICR->CODESIZE)
jksoft 0:8468a4403fea 52
jksoft 0:8468a4403fea 53 /**@brief Function for erasing the specified flash page, and then writes the given data to this page.
jksoft 0:8468a4403fea 54 *
jksoft 0:8468a4403fea 55 * @warning This operation blocks the CPU. DO NOT use while in a connection!
jksoft 0:8468a4403fea 56 *
jksoft 0:8468a4403fea 57 * @param[in] page_num Page number to update.
jksoft 0:8468a4403fea 58 * @param[in] p_in_array Pointer to a RAM area containing the elements to write in flash.
jksoft 0:8468a4403fea 59 * This area has to be 32 bits aligned.
jksoft 0:8468a4403fea 60 * @param[in] word_count Number of 32 bits words to write in flash.
jksoft 0:8468a4403fea 61 *
jksoft 0:8468a4403fea 62 * @return NRF_SUCCESS on successful flash write, otherwise an error code.
jksoft 0:8468a4403fea 63 */
jksoft 0:8468a4403fea 64 uint32_t ble_flash_page_write(uint8_t page_num, uint32_t * p_in_array, uint8_t word_count);
jksoft 0:8468a4403fea 65
jksoft 0:8468a4403fea 66 /**@brief Function for reading data from flash to RAM.
jksoft 0:8468a4403fea 67 *
jksoft 0:8468a4403fea 68 * @param[in] page_num Page number to read.
jksoft 0:8468a4403fea 69 * @param[out] p_out_array Pointer to a RAM area where the found data will be written.
jksoft 0:8468a4403fea 70 * This area has to be 32 bits aligned.
jksoft 0:8468a4403fea 71 * @param[out] p_word_count Number of 32 bits words read.
jksoft 0:8468a4403fea 72 *
jksoft 0:8468a4403fea 73 * @return NRF_SUCCESS on successful upload, NRF_ERROR_NOT_FOUND if no valid data has been found
jksoft 0:8468a4403fea 74 * in flash (first 32 bits not equal to the MAGIC_NUMBER+CRC).
jksoft 0:8468a4403fea 75 */
jksoft 0:8468a4403fea 76 uint32_t ble_flash_page_read(uint8_t page_num, uint32_t * p_out_array, uint8_t * p_word_count);
jksoft 0:8468a4403fea 77
jksoft 0:8468a4403fea 78 /**@brief Function for erasing a flash page.
jksoft 0:8468a4403fea 79 *
jksoft 0:8468a4403fea 80 * @note This operation blocks the CPU, so it should not be done while the radio is running!
jksoft 0:8468a4403fea 81 *
jksoft 0:8468a4403fea 82 * @param[in] page_num Page number to erase.
jksoft 0:8468a4403fea 83 *
jksoft 0:8468a4403fea 84 * @return NRF_SUCCESS on success, an error_code otherwise.
jksoft 0:8468a4403fea 85 */
jksoft 0:8468a4403fea 86 uint32_t ble_flash_page_erase(uint8_t page_num);
jksoft 0:8468a4403fea 87
jksoft 0:8468a4403fea 88 /**@brief Function for writing one word to flash.
jksoft 0:8468a4403fea 89 *
jksoft 0:8468a4403fea 90 * @note Flash location to be written must have been erased previously.
jksoft 0:8468a4403fea 91 *
jksoft 0:8468a4403fea 92 * @param[in] p_address Pointer to flash location to be written.
jksoft 0:8468a4403fea 93 * @param[in] value Value to write to flash.
jksoft 0:8468a4403fea 94 *
jksoft 0:8468a4403fea 95 * @return NRF_SUCCESS.
jksoft 0:8468a4403fea 96 */
jksoft 0:8468a4403fea 97 uint32_t ble_flash_word_write(uint32_t * p_address, uint32_t value);
jksoft 0:8468a4403fea 98
jksoft 0:8468a4403fea 99 /**@brief Function for writing a data block to flash.
jksoft 0:8468a4403fea 100 *
jksoft 0:8468a4403fea 101 * @note Flash locations to be written must have been erased previously.
jksoft 0:8468a4403fea 102 *
jksoft 0:8468a4403fea 103 * @param[in] p_address Pointer to start of flash location to be written.
jksoft 0:8468a4403fea 104 * @param[in] p_in_array Pointer to start of flash block to be written.
jksoft 0:8468a4403fea 105 * @param[in] word_count Number of words to be written.
jksoft 0:8468a4403fea 106 *
jksoft 0:8468a4403fea 107 * @return NRF_SUCCESS.
jksoft 0:8468a4403fea 108 */
jksoft 0:8468a4403fea 109 uint32_t ble_flash_block_write(uint32_t * p_address, uint32_t * p_in_array, uint16_t word_count);
jksoft 0:8468a4403fea 110
jksoft 0:8468a4403fea 111 /**@brief Function for computing pointer to start of specified flash page.
jksoft 0:8468a4403fea 112 *
jksoft 0:8468a4403fea 113 * @param[in] page_num Page number.
jksoft 0:8468a4403fea 114 * @param[out] pp_page_addr Pointer to start of flash page.
jksoft 0:8468a4403fea 115 *
jksoft 0:8468a4403fea 116 * @return NRF_SUCCESS.
jksoft 0:8468a4403fea 117 */
jksoft 0:8468a4403fea 118 uint32_t ble_flash_page_addr(uint8_t page_num, uint32_t ** pp_page_addr);
jksoft 0:8468a4403fea 119
jksoft 0:8468a4403fea 120 /**@brief Function for calculating a 16 bit CRC using the CRC-16-CCITT scheme.
jksoft 0:8468a4403fea 121 *
jksoft 0:8468a4403fea 122 * @param[in] p_data Pointer to data on which the CRC is to be calulated.
jksoft 0:8468a4403fea 123 * @param[in] size Number of bytes on which the CRC is to be calulated.
jksoft 0:8468a4403fea 124 * @param[in] p_crc Initial CRC value (if NULL, a preset value is used as the initial value).
jksoft 0:8468a4403fea 125 *
jksoft 0:8468a4403fea 126 * @return Calculated CRC.
jksoft 0:8468a4403fea 127 */
jksoft 0:8468a4403fea 128 uint16_t ble_flash_crc16_compute(uint8_t * p_data, uint16_t size, uint16_t * p_crc);
jksoft 0:8468a4403fea 129
jksoft 0:8468a4403fea 130 /**@brief Function for handling flashing module Radio Notification event.
jksoft 0:8468a4403fea 131 *
jksoft 0:8468a4403fea 132 * @note For flash writing to work safely while in a connection or while advertising, this function
jksoft 0:8468a4403fea 133 * MUST be called from the Radio Notification module's event handler (see
jksoft 0:8468a4403fea 134 * @ref ble_radio_notification for details).
jksoft 0:8468a4403fea 135 *
jksoft 0:8468a4403fea 136 * @param[in] radio_active TRUE if radio is active (or about to become active), FALSE otherwise.
jksoft 0:8468a4403fea 137 */
jksoft 0:8468a4403fea 138 void ble_flash_on_radio_active_evt(bool radio_active);
jksoft 0:8468a4403fea 139
jksoft 0:8468a4403fea 140 #endif // BLE_FLASH_H__
jksoft 0:8468a4403fea 141
jksoft 0:8468a4403fea 142 /** @} */