SG RFID nRF51822 fork

Fork of nRF51822 by Nordic Semiconductor

Committer:
soumi_ghsoh
Date:
Wed Apr 01 22:06:35 2015 +0000
Revision:
100:030804500597
Parent:
37:c29c330d942c
TAG read with multiple instances of RX complete IRQ; Imp changes: reduced RX wait time, Vin=3V/AGC ON, RX_IN2(main) , RX_IN1(aux)

Who changed what in which revision?

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