ble_dtm.h 6.9 KB

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