ble_dtm_hw_nrf52.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include "ble_dtm_hw.h"
  41. #include "ble_dtm.h"
  42. #include <stdbool.h>
  43. #include <string.h>
  44. #include "nrf.h"
  45. void dtm_turn_off_test()
  46. {
  47. }
  48. void dtm_constant_carrier()
  49. {
  50. NRF_RADIO->MODECNF0 = (RADIO_MODECNF0_RU_Default << RADIO_MODECNF0_RU_Pos) |
  51. (RADIO_MODECNF0_DTX_Center << RADIO_MODECNF0_DTX_Pos);
  52. }
  53. uint32_t dtm_radio_validate(uint32_t m_tx_power, uint8_t m_radio_mode)
  54. {
  55. // Initializing code below is quite generic - for BLE, the values are fixed, and expressions
  56. // are constant. Non-constant values are essentially set in radio_prepare().
  57. if (!(
  58. #if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(NRF52820_XXAA)
  59. m_tx_power == RADIO_TXPOWER_TXPOWER_Pos8dBm ||
  60. m_tx_power == RADIO_TXPOWER_TXPOWER_Pos7dBm ||
  61. m_tx_power == RADIO_TXPOWER_TXPOWER_Pos6dBm ||
  62. m_tx_power == RADIO_TXPOWER_TXPOWER_Pos5dBm ||
  63. #endif //defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(NRF52820_XXAA)
  64. m_tx_power == RADIO_TXPOWER_TXPOWER_Pos4dBm ||
  65. m_tx_power == RADIO_TXPOWER_TXPOWER_Pos3dBm ||
  66. #if defined(NRF52840_XXAA) || defined(NRF52833_XXAA) || defined(NRF52820_XXAA)
  67. m_tx_power == RADIO_TXPOWER_TXPOWER_Pos2dBm ||
  68. #endif //defined(NRF52840_XXAA) || defined(NRF52833_XXAA)A || defined(NRF52820_XXAA)
  69. m_tx_power == RADIO_TXPOWER_TXPOWER_0dBm ||
  70. m_tx_power == RADIO_TXPOWER_TXPOWER_Neg4dBm ||
  71. m_tx_power == RADIO_TXPOWER_TXPOWER_Neg8dBm ||
  72. m_tx_power == RADIO_TXPOWER_TXPOWER_Neg12dBm ||
  73. m_tx_power == RADIO_TXPOWER_TXPOWER_Neg16dBm ||
  74. m_tx_power == RADIO_TXPOWER_TXPOWER_Neg20dBm ||
  75. m_tx_power == RADIO_TXPOWER_TXPOWER_Neg30dBm ||
  76. m_tx_power == RADIO_TXPOWER_TXPOWER_Neg40dBm
  77. ) ||
  78. !(
  79. #if defined(NRF52840_XXAA) || defined(NRF52811_XXAA) || defined(NRF52833_XXAA) || defined(NRF52820_XXAA)
  80. m_radio_mode == RADIO_MODE_MODE_Ble_LR125Kbit ||
  81. m_radio_mode == RADIO_MODE_MODE_Ble_LR500Kbit ||
  82. #endif //defined(NRF52840_XXAA) || defined(NRF52811_XXAA) || defined(NRF52833_XXAA) || defined(NRF52820_XXAA)
  83. m_radio_mode == RADIO_MODE_MODE_Ble_1Mbit ||
  84. m_radio_mode == RADIO_MODE_MODE_Ble_2Mbit
  85. )
  86. )
  87. {
  88. return DTM_ERROR_ILLEGAL_CONFIGURATION;
  89. }
  90. return DTM_SUCCESS;
  91. }
  92. bool dtm_hw_set_timer(NRF_TIMER_Type ** mp_timer, IRQn_Type * m_timer_irq, uint32_t new_timer)
  93. {
  94. if (new_timer == 0)
  95. {
  96. *mp_timer = NRF_TIMER0;
  97. *m_timer_irq = TIMER0_IRQn;
  98. }
  99. else if (new_timer == 1)
  100. {
  101. *mp_timer = NRF_TIMER1;
  102. *m_timer_irq = TIMER1_IRQn;
  103. }
  104. else if (new_timer == 2)
  105. {
  106. *mp_timer = NRF_TIMER2;
  107. *m_timer_irq = TIMER2_IRQn;
  108. }
  109. #if !defined(NRF52810_XXAA) && !defined(NRF52811_XXAA)
  110. else if (new_timer == 3)
  111. {
  112. *mp_timer = NRF_TIMER3;
  113. *m_timer_irq = TIMER3_IRQn;
  114. }
  115. #if !defined(NRF52820_XXAA)
  116. else if (new_timer == 4)
  117. {
  118. *mp_timer = NRF_TIMER4;
  119. *m_timer_irq = TIMER4_IRQn;
  120. }
  121. #endif //!defined(NRF52820_XXAA)
  122. #endif //!defined(NRF52810_XXAA) && !defined(NRF52811_XXAA)
  123. else
  124. {
  125. // Parameter error: Only TIMER 0, 1, 2, 3 and 4 provided by nRF52
  126. return false;
  127. }
  128. // New timer has been selected:
  129. return true;
  130. }