project for nrf51822 qfab

Dependencies:   eddystone_URL mbed

Fork of eddystone_URL by vo dung

Committer:
jksoft
Date:
Wed Nov 12 02:40:34 2014 +0000
Revision:
0:76dfa9657d9d
????????

Who changed what in which revision?

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