テスト用
Fork of nRF51822 by
nordic/nrf-sdk/ble/ble_dtm.h@69:936d81c963fe, 2014-09-26 (annotated)
- Committer:
- Rohit Grover
- Date:
- Fri Sep 26 14:46:19 2014 +0100
- Revision:
- 69:936d81c963fe
- Parent:
- 37:c29c330d942c
Release 0.2.1
=============
Features
~~~~~~~~
- Turn on the service-changed characteristic by default.
Bugfixes
~~~~~~~~
- Raised the maximum number of supported characteristics/descriptors to 24
(was 10 previously). We're beginning to find services like Device-
Information with several characteristics populated.
Compatibility
~~~~~~~~~~~~~
Works with 0.2.0 of BLE_API.
Who changed what in which revision?
User | Revision | Line number | New 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_sdk_dtmlib_dtm DTM - Direct Test Mode |
bogdanm | 0:eff01767de02 | 16 | * @{ |
bogdanm | 0:eff01767de02 | 17 | * @ingroup ble_sdk_lib |
bogdanm | 0:eff01767de02 | 18 | * @brief Module for testing RF/PHY using DTM commands. |
bogdanm | 0:eff01767de02 | 19 | */ |
bogdanm | 0:eff01767de02 | 20 | |
bogdanm | 0:eff01767de02 | 21 | #ifndef BLE_DTM_H__ |
bogdanm | 0:eff01767de02 | 22 | #define BLE_DTM_H__ |
bogdanm | 0:eff01767de02 | 23 | |
bogdanm | 0:eff01767de02 | 24 | #include <stdint.h> |
bogdanm | 0:eff01767de02 | 25 | #include <stdbool.h> |
bogdanm | 0:eff01767de02 | 26 | |
bogdanm | 0:eff01767de02 | 27 | |
bogdanm | 0:eff01767de02 | 28 | /**@brief Configuration parameters. */ |
bogdanm | 0:eff01767de02 | 29 | #define DEFAULT_TX_POWER RADIO_TXPOWER_TXPOWER_Pos4dBm /**< Default Transmission power using in the DTM module. */ |
bogdanm | 0:eff01767de02 | 30 | #define DEFAULT_TIMER NRF_TIMER0 /**< Default timer used for timing. */ |
bogdanm | 0:eff01767de02 | 31 | #define DEFAULT_TIMER_IRQn TIMER0_IRQn /**< IRQ used for timer. NOTE: MUST correspond to DEFAULT_TIMER. */ |
bogdanm | 0:eff01767de02 | 32 | |
bogdanm | 0:eff01767de02 | 33 | /**@brief BLE DTM command codes. */ |
bogdanm | 0:eff01767de02 | 34 | typedef uint32_t dtm_cmd_t; /**< DTM command type. */ |
bogdanm | 0:eff01767de02 | 35 | |
bogdanm | 0:eff01767de02 | 36 | #define LE_RESET 0 /**< DTM command: Reset device. */ |
bogdanm | 0:eff01767de02 | 37 | #define LE_RECEIVER_TEST 1 /**< DTM command: Start receive test. */ |
bogdanm | 0:eff01767de02 | 38 | #define LE_TRANSMITTER_TEST 2 /**< DTM command: Start transmission test. */ |
bogdanm | 0:eff01767de02 | 39 | #define LE_TEST_END 3 /**< DTM command: End test and send packet report. */ |
bogdanm | 0:eff01767de02 | 40 | |
bogdanm | 0:eff01767de02 | 41 | // Configuration options used as parameter 2 |
bogdanm | 0:eff01767de02 | 42 | // when cmd == LE_TRANSMITTER_TEST and payload == DTM_PKT_VENDORSPECIFIC |
bogdanm | 0:eff01767de02 | 43 | // Configuration value, if any, is supplied in parameter 3 |
bogdanm | 0:eff01767de02 | 44 | |
bogdanm | 0:eff01767de02 | 45 | #define CARRIER_TEST 0 /**< Length=0 indicates a constant, unmodulated carrier until LE_TEST_END or LE_RESET */ |
bogdanm | 0:eff01767de02 | 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 */ |
bogdanm | 0:eff01767de02 | 47 | #define SET_TX_POWER 2 /**< Set transmission power, value -40..+4 dBm in steps of 4 */ |
bogdanm | 0:eff01767de02 | 48 | #define SELECT_TIMER 3 /**< Select on of the 16 MHz timers 0, 1 or 2 */ |
bogdanm | 0:eff01767de02 | 49 | |
bogdanm | 0:eff01767de02 | 50 | #define LE_PACKET_REPORTING_EVENT 0x8000 /**< DTM Packet reporting event, returned by the device to the tester. */ |
bogdanm | 0:eff01767de02 | 51 | #define LE_TEST_STATUS_EVENT_SUCCESS 0x0000 /**< DTM Status event, indicating success. */ |
bogdanm | 0:eff01767de02 | 52 | #define LE_TEST_STATUS_EVENT_ERROR 0x0001 /**< DTM Status event, indicating an error. */ |
bogdanm | 0:eff01767de02 | 53 | |
bogdanm | 0:eff01767de02 | 54 | #define DTM_PKT_PRBS9 0x00 /**< Bit pattern PRBS9. */ |
bogdanm | 0:eff01767de02 | 55 | #define DTM_PKT_0X0F 0x01 /**< Bit pattern 11110000 (LSB is the leftmost bit). */ |
bogdanm | 0:eff01767de02 | 56 | #define DTM_PKT_0X55 0x02 /**< Bit pattern 10101010 (LSB is the leftmost bit). */ |
bogdanm | 0:eff01767de02 | 57 | #define DTM_PKT_VENDORSPECIFIC 0xFFFFFFFF /**< Vendor specific. Nordic: Continuous carrier test, or configuration. */ |
bogdanm | 0:eff01767de02 | 58 | |
bogdanm | 0:eff01767de02 | 59 | /**@brief Return codes from dtm_cmd(). */ |
bogdanm | 0:eff01767de02 | 60 | #define DTM_SUCCESS 0x00 /**< Indicate that the DTM function completed with success. */ |
bogdanm | 0:eff01767de02 | 61 | #define DTM_ERROR_ILLEGAL_CHANNEL 0x01 /**< Physical channel number must be in the range 0..39. */ |
bogdanm | 0:eff01767de02 | 62 | #define DTM_ERROR_INVALID_STATE 0x02 /**< Sequencing error: Command is not valid now. */ |
bogdanm | 0:eff01767de02 | 63 | #define DTM_ERROR_ILLEGAL_LENGTH 0x03 /**< Payload size must be in the range 0..37. */ |
bogdanm | 0:eff01767de02 | 64 | #define DTM_ERROR_ILLEGAL_CONFIGURATION 0x04 /**< Parameter out of range (legal range is function dependent). */ |
bogdanm | 0:eff01767de02 | 65 | #define DTM_ERROR_UNINITIALIZED 0x05 /**< DTM module has not been initialized by the application. */ |
bogdanm | 0:eff01767de02 | 66 | |
bogdanm | 0:eff01767de02 | 67 | // Note: DTM_PKT_VENDORSPECIFIC, is not a packet type |
bogdanm | 0:eff01767de02 | 68 | #define PACKET_TYPE_MAX DTM_PKT_0X55 /**< Highest value allowed as DTM Packet type. */ |
bogdanm | 0:eff01767de02 | 69 | |
bogdanm | 0:eff01767de02 | 70 | /** @brief BLE DTM event type. */ |
bogdanm | 0:eff01767de02 | 71 | typedef uint32_t dtm_event_t; /**< Type for handling DTM event. */ |
bogdanm | 0:eff01767de02 | 72 | |
bogdanm | 0:eff01767de02 | 73 | /** @brief BLE DTM frequency type. */ |
bogdanm | 0:eff01767de02 | 74 | typedef uint32_t dtm_freq_t; /**< Physical channel, valid range: 0..39. */ |
bogdanm | 0:eff01767de02 | 75 | |
bogdanm | 0:eff01767de02 | 76 | /**@brief BLE DTM packet types. */ |
bogdanm | 0:eff01767de02 | 77 | typedef uint32_t dtm_pkt_type_t; /**< Type for holding the requested DTM payload type.*/ |
bogdanm | 0:eff01767de02 | 78 | |
bogdanm | 0:eff01767de02 | 79 | |
bogdanm | 0:eff01767de02 | 80 | /**@brief Function for initializing or re-initializing DTM module |
bogdanm | 0:eff01767de02 | 81 | * |
bogdanm | 0:eff01767de02 | 82 | * @return DTM_SUCCESS on successful initialization of the DTM module. |
bogdanm | 0:eff01767de02 | 83 | */ |
bogdanm | 0:eff01767de02 | 84 | uint32_t dtm_init(void); |
bogdanm | 0:eff01767de02 | 85 | |
bogdanm | 0:eff01767de02 | 86 | |
bogdanm | 0:eff01767de02 | 87 | /**@brief Function for giving control to dtmlib for handling timer and radio events. |
bogdanm | 0:eff01767de02 | 88 | * Will return to caller at 625us intervals or whenever another event than radio occurs |
bogdanm | 0:eff01767de02 | 89 | * (such as UART input). Function will put MCU to sleep between events. |
bogdanm | 0:eff01767de02 | 90 | * |
bogdanm | 0:eff01767de02 | 91 | * @return Time counter, incremented every 625 us. |
bogdanm | 0:eff01767de02 | 92 | */ |
bogdanm | 0:eff01767de02 | 93 | uint32_t dtm_wait(void); |
bogdanm | 0:eff01767de02 | 94 | |
bogdanm | 0:eff01767de02 | 95 | |
bogdanm | 0:eff01767de02 | 96 | /**@brief Function for calling when a complete command has been prepared by the Tester. |
bogdanm | 0:eff01767de02 | 97 | * |
bogdanm | 0:eff01767de02 | 98 | * @param[in] cmd One of the DTM_CMD values (bits 14:15 in the 16-bit UART format). |
bogdanm | 0:eff01767de02 | 99 | * @param[in] freq Phys. channel no - actual frequency = (2402 + freq * 2) MHz (bits 8:13 in |
bogdanm | 0:eff01767de02 | 100 | * the 16-bit UART format). |
bogdanm | 0:eff01767de02 | 101 | * @param[in] length Payload length, 0..37 (bits 2:7 in the 16-bit UART format). |
bogdanm | 0:eff01767de02 | 102 | * @param[in] payload One of the DTM_PKT values (bits 0:1 in the 16-bit UART format). |
bogdanm | 0:eff01767de02 | 103 | * |
bogdanm | 0:eff01767de02 | 104 | * @return DTM_SUCCESS or one of the DTM_ERROR_ values |
bogdanm | 0:eff01767de02 | 105 | */ |
bogdanm | 0:eff01767de02 | 106 | uint32_t dtm_cmd(dtm_cmd_t cmd, dtm_freq_t freq, uint32_t length, dtm_pkt_type_t payload); |
bogdanm | 0:eff01767de02 | 107 | |
bogdanm | 0:eff01767de02 | 108 | |
bogdanm | 0:eff01767de02 | 109 | /**@brief Function for reading the result of a DTM command |
bogdanm | 0:eff01767de02 | 110 | * |
bogdanm | 0:eff01767de02 | 111 | * @param[out] p_dtm_event Pointer to buffer for 16 bit event code according to DTM standard. |
bogdanm | 0:eff01767de02 | 112 | * |
bogdanm | 0:eff01767de02 | 113 | * @return true: new event, false: no event since last call, this event has been read earlier |
bogdanm | 0:eff01767de02 | 114 | */ |
bogdanm | 0:eff01767de02 | 115 | bool dtm_event_get(dtm_event_t * p_dtm_event); |
bogdanm | 0:eff01767de02 | 116 | |
bogdanm | 0:eff01767de02 | 117 | |
bogdanm | 0:eff01767de02 | 118 | /**@brief Function for configuring the timer to use. |
bogdanm | 0:eff01767de02 | 119 | * |
bogdanm | 0:eff01767de02 | 120 | * @note Must be called when no DTM test is running. |
bogdanm | 0:eff01767de02 | 121 | * |
bogdanm | 0:eff01767de02 | 122 | * @param[in] new_timer Index (0..2) of timer to be used by the DTM library |
bogdanm | 0:eff01767de02 | 123 | * |
bogdanm | 0:eff01767de02 | 124 | * @return true: success, new timer was selected, false: parameter error |
bogdanm | 0:eff01767de02 | 125 | */ |
bogdanm | 0:eff01767de02 | 126 | bool dtm_set_timer(uint32_t new_timer); |
bogdanm | 0:eff01767de02 | 127 | |
bogdanm | 0:eff01767de02 | 128 | |
bogdanm | 0:eff01767de02 | 129 | /**@brief Function for configuring the transmit power. |
bogdanm | 0:eff01767de02 | 130 | * |
bogdanm | 0:eff01767de02 | 131 | * @note Must be called when no DTM test is running. |
bogdanm | 0:eff01767de02 | 132 | * |
bogdanm | 0:eff01767de02 | 133 | * @param[in] new_tx_power New output level, +4..-40, in steps of 4. |
bogdanm | 0:eff01767de02 | 134 | * |
bogdanm | 0:eff01767de02 | 135 | * @return true: tx power setting changed, false: parameter error |
bogdanm | 0:eff01767de02 | 136 | */ |
bogdanm | 0:eff01767de02 | 137 | bool dtm_set_txpower(uint32_t new_tx_power); |
bogdanm | 0:eff01767de02 | 138 | |
bogdanm | 0:eff01767de02 | 139 | #endif // BLE_DTM_H__ |
bogdanm | 0:eff01767de02 | 140 | |
bogdanm | 0:eff01767de02 | 141 | /** @} */ |