BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:a607cd9655d7 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
yihui 1:a607cd9655d7 2 *
yihui 1:a607cd9655d7 3 * The information contained herein is property of Nordic Semiconductor ASA.
yihui 1:a607cd9655d7 4 * Terms and conditions of usage are described in detail in NORDIC
yihui 1:a607cd9655d7 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
yihui 1:a607cd9655d7 6 *
yihui 1:a607cd9655d7 7 * Licensees are granted free, non-transferable use of the information. NO
yihui 1:a607cd9655d7 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
yihui 1:a607cd9655d7 9 * the file.
yihui 1:a607cd9655d7 10 *
yihui 1:a607cd9655d7 11 */
yihui 1:a607cd9655d7 12
yihui 1:a607cd9655d7 13 /** @file
yihui 1:a607cd9655d7 14 *
yihui 1:a607cd9655d7 15 * @defgroup ble_sdk_dtmlib_dtm DTM - Direct Test Mode
yihui 1:a607cd9655d7 16 * @{
yihui 1:a607cd9655d7 17 * @ingroup ble_sdk_lib
yihui 1:a607cd9655d7 18 * @brief Module for testing RF/PHY using DTM commands.
yihui 1:a607cd9655d7 19 */
yihui 1:a607cd9655d7 20
yihui 1:a607cd9655d7 21 #ifndef BLE_DTM_H__
yihui 1:a607cd9655d7 22 #define BLE_DTM_H__
yihui 1:a607cd9655d7 23
yihui 1:a607cd9655d7 24 #include <stdint.h>
yihui 1:a607cd9655d7 25 #include <stdbool.h>
yihui 1:a607cd9655d7 26
yihui 1:a607cd9655d7 27
yihui 1:a607cd9655d7 28 /**@brief Configuration parameters. */
yihui 1:a607cd9655d7 29 #define DEFAULT_TX_POWER RADIO_TXPOWER_TXPOWER_Pos4dBm /**< Default Transmission power using in the DTM module. */
yihui 1:a607cd9655d7 30 #define DEFAULT_TIMER NRF_TIMER0 /**< Default timer used for timing. */
yihui 1:a607cd9655d7 31 #define DEFAULT_TIMER_IRQn TIMER0_IRQn /**< IRQ used for timer. NOTE: MUST correspond to DEFAULT_TIMER. */
yihui 1:a607cd9655d7 32
yihui 1:a607cd9655d7 33 /**@brief BLE DTM command codes. */
yihui 1:a607cd9655d7 34 typedef uint32_t dtm_cmd_t; /**< DTM command type. */
yihui 1:a607cd9655d7 35
yihui 1:a607cd9655d7 36 #define LE_RESET 0 /**< DTM command: Reset device. */
yihui 1:a607cd9655d7 37 #define LE_RECEIVER_TEST 1 /**< DTM command: Start receive test. */
yihui 1:a607cd9655d7 38 #define LE_TRANSMITTER_TEST 2 /**< DTM command: Start transmission test. */
yihui 1:a607cd9655d7 39 #define LE_TEST_END 3 /**< DTM command: End test and send packet report. */
yihui 1:a607cd9655d7 40
yihui 1:a607cd9655d7 41 // Configuration options used as parameter 2
yihui 1:a607cd9655d7 42 // when cmd == LE_TRANSMITTER_TEST and payload == DTM_PKT_VENDORSPECIFIC
yihui 1:a607cd9655d7 43 // Configuration value, if any, is supplied in parameter 3
yihui 1:a607cd9655d7 44
yihui 1:a607cd9655d7 45 #define CARRIER_TEST 0 /**< Length=0 indicates a constant, unmodulated carrier until LE_TEST_END or LE_RESET */
yihui 1:a607cd9655d7 46 #define CARRIER_TEST_STUDIO 1 /**< nRFgo Studio uses value 1 in length field, to indicate a constant, unmodulated carrier until LE_TEST_END or LE_RESET */
yihui 1:a607cd9655d7 47 #define SET_TX_POWER 2 /**< Set transmission power, value -40..+4 dBm in steps of 4 */
yihui 1:a607cd9655d7 48 #define SELECT_TIMER 3 /**< Select on of the 16 MHz timers 0, 1 or 2 */
yihui 1:a607cd9655d7 49
yihui 1:a607cd9655d7 50 #define LE_PACKET_REPORTING_EVENT 0x8000 /**< DTM Packet reporting event, returned by the device to the tester. */
yihui 1:a607cd9655d7 51 #define LE_TEST_STATUS_EVENT_SUCCESS 0x0000 /**< DTM Status event, indicating success. */
yihui 1:a607cd9655d7 52 #define LE_TEST_STATUS_EVENT_ERROR 0x0001 /**< DTM Status event, indicating an error. */
yihui 1:a607cd9655d7 53
yihui 1:a607cd9655d7 54 #define DTM_PKT_PRBS9 0x00 /**< Bit pattern PRBS9. */
yihui 1:a607cd9655d7 55 #define DTM_PKT_0X0F 0x01 /**< Bit pattern 11110000 (LSB is the leftmost bit). */
yihui 1:a607cd9655d7 56 #define DTM_PKT_0X55 0x02 /**< Bit pattern 10101010 (LSB is the leftmost bit). */
yihui 1:a607cd9655d7 57 #define DTM_PKT_VENDORSPECIFIC 0xFFFFFFFF /**< Vendor specific. Nordic: Continuous carrier test, or configuration. */
yihui 1:a607cd9655d7 58
yihui 1:a607cd9655d7 59 /**@brief Return codes from dtm_cmd(). */
yihui 1:a607cd9655d7 60 #define DTM_SUCCESS 0x00 /**< Indicate that the DTM function completed with success. */
yihui 1:a607cd9655d7 61 #define DTM_ERROR_ILLEGAL_CHANNEL 0x01 /**< Physical channel number must be in the range 0..39. */
yihui 1:a607cd9655d7 62 #define DTM_ERROR_INVALID_STATE 0x02 /**< Sequencing error: Command is not valid now. */
yihui 1:a607cd9655d7 63 #define DTM_ERROR_ILLEGAL_LENGTH 0x03 /**< Payload size must be in the range 0..37. */
yihui 1:a607cd9655d7 64 #define DTM_ERROR_ILLEGAL_CONFIGURATION 0x04 /**< Parameter out of range (legal range is function dependent). */
yihui 1:a607cd9655d7 65 #define DTM_ERROR_UNINITIALIZED 0x05 /**< DTM module has not been initialized by the application. */
yihui 1:a607cd9655d7 66
yihui 1:a607cd9655d7 67 // Note: DTM_PKT_VENDORSPECIFIC, is not a packet type
yihui 1:a607cd9655d7 68 #define PACKET_TYPE_MAX DTM_PKT_0X55 /**< Highest value allowed as DTM Packet type. */
yihui 1:a607cd9655d7 69
yihui 1:a607cd9655d7 70 /** @brief BLE DTM event type. */
yihui 1:a607cd9655d7 71 typedef uint32_t dtm_event_t; /**< Type for handling DTM event. */
yihui 1:a607cd9655d7 72
yihui 1:a607cd9655d7 73 /** @brief BLE DTM frequency type. */
yihui 1:a607cd9655d7 74 typedef uint32_t dtm_freq_t; /**< Physical channel, valid range: 0..39. */
yihui 1:a607cd9655d7 75
yihui 1:a607cd9655d7 76 /**@brief BLE DTM packet types. */
yihui 1:a607cd9655d7 77 typedef uint32_t dtm_pkt_type_t; /**< Type for holding the requested DTM payload type.*/
yihui 1:a607cd9655d7 78
yihui 1:a607cd9655d7 79
yihui 1:a607cd9655d7 80 /**@brief Function for initializing or re-initializing DTM module
yihui 1:a607cd9655d7 81 *
yihui 1:a607cd9655d7 82 * @return DTM_SUCCESS on successful initialization of the DTM module.
yihui 1:a607cd9655d7 83 */
yihui 1:a607cd9655d7 84 uint32_t dtm_init(void);
yihui 1:a607cd9655d7 85
yihui 1:a607cd9655d7 86
yihui 1:a607cd9655d7 87 /**@brief Function for giving control to dtmlib for handling timer and radio events.
yihui 1:a607cd9655d7 88 * Will return to caller at 625us intervals or whenever another event than radio occurs
yihui 1:a607cd9655d7 89 * (such as UART input). Function will put MCU to sleep between events.
yihui 1:a607cd9655d7 90 *
yihui 1:a607cd9655d7 91 * @return Time counter, incremented every 625 us.
yihui 1:a607cd9655d7 92 */
yihui 1:a607cd9655d7 93 uint32_t dtm_wait(void);
yihui 1:a607cd9655d7 94
yihui 1:a607cd9655d7 95
yihui 1:a607cd9655d7 96 /**@brief Function for calling when a complete command has been prepared by the Tester.
yihui 1:a607cd9655d7 97 *
yihui 1:a607cd9655d7 98 * @param[in] cmd One of the DTM_CMD values (bits 14:15 in the 16-bit UART format).
yihui 1:a607cd9655d7 99 * @param[in] freq Phys. channel no - actual frequency = (2402 + freq * 2) MHz (bits 8:13 in
yihui 1:a607cd9655d7 100 * the 16-bit UART format).
yihui 1:a607cd9655d7 101 * @param[in] length Payload length, 0..37 (bits 2:7 in the 16-bit UART format).
yihui 1:a607cd9655d7 102 * @param[in] payload One of the DTM_PKT values (bits 0:1 in the 16-bit UART format).
yihui 1:a607cd9655d7 103 *
yihui 1:a607cd9655d7 104 * @return DTM_SUCCESS or one of the DTM_ERROR_ values
yihui 1:a607cd9655d7 105 */
yihui 1:a607cd9655d7 106 uint32_t dtm_cmd(dtm_cmd_t cmd, dtm_freq_t freq, uint32_t length, dtm_pkt_type_t payload);
yihui 1:a607cd9655d7 107
yihui 1:a607cd9655d7 108
yihui 1:a607cd9655d7 109 /**@brief Function for reading the result of a DTM command
yihui 1:a607cd9655d7 110 *
yihui 1:a607cd9655d7 111 * @param[out] p_dtm_event Pointer to buffer for 16 bit event code according to DTM standard.
yihui 1:a607cd9655d7 112 *
yihui 1:a607cd9655d7 113 * @return true: new event, false: no event since last call, this event has been read earlier
yihui 1:a607cd9655d7 114 */
yihui 1:a607cd9655d7 115 bool dtm_event_get(dtm_event_t * p_dtm_event);
yihui 1:a607cd9655d7 116
yihui 1:a607cd9655d7 117
yihui 1:a607cd9655d7 118 /**@brief Function for configuring the timer to use.
yihui 1:a607cd9655d7 119 *
yihui 1:a607cd9655d7 120 * @note Must be called when no DTM test is running.
yihui 1:a607cd9655d7 121 *
yihui 1:a607cd9655d7 122 * @param[in] new_timer Index (0..2) of timer to be used by the DTM library
yihui 1:a607cd9655d7 123 *
yihui 1:a607cd9655d7 124 * @return true: success, new timer was selected, false: parameter error
yihui 1:a607cd9655d7 125 */
yihui 1:a607cd9655d7 126 bool dtm_set_timer(uint32_t new_timer);
yihui 1:a607cd9655d7 127
yihui 1:a607cd9655d7 128
yihui 1:a607cd9655d7 129 /**@brief Function for configuring the transmit power.
yihui 1:a607cd9655d7 130 *
yihui 1:a607cd9655d7 131 * @note Must be called when no DTM test is running.
yihui 1:a607cd9655d7 132 *
yihui 1:a607cd9655d7 133 * @param[in] new_tx_power New output level, +4..-40, in steps of 4.
yihui 1:a607cd9655d7 134 *
yihui 1:a607cd9655d7 135 * @return true: tx power setting changed, false: parameter error
yihui 1:a607cd9655d7 136 */
yihui 1:a607cd9655d7 137 bool dtm_set_txpower(uint32_t new_tx_power);
yihui 1:a607cd9655d7 138
yihui 1:a607cd9655d7 139 #endif // BLE_DTM_H__
yihui 1:a607cd9655d7 140
yihui 1:a607cd9655d7 141 /** @} */