To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

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