main.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * Copyright (c) 2014-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. /** @file
  41. *
  42. * @defgroup nrf_radio_test_example_main main.c
  43. * @{
  44. * @ingroup nrf_radio_test_example
  45. * @brief Radio Test Example application main file.
  46. *
  47. * This file contains the source code for a sample application that uses the NRF_RADIO and is controlled through the serial port.
  48. *
  49. */
  50. #include <stdint.h>
  51. #include <stdbool.h>
  52. #include <stdio.h>
  53. #include "bsp.h"
  54. #include "nrf.h"
  55. #include "radio_cmd.h"
  56. #include "app_uart.h"
  57. #include "app_error.h"
  58. #include "nordic_common.h"
  59. #include "nrf_drv_clock.h"
  60. #include "nrf_cli.h"
  61. #include "nrf_cli_uart.h"
  62. #include "nrf_log.h"
  63. #include "nrf_log_ctrl.h"
  64. #include "nrf_log_default_backends.h"
  65. #if defined(NRF21540_DRIVER_ENABLE) && (NRF21540_DRIVER_ENABLE == 1)
  66. #include "nrf21540.h"
  67. #endif
  68. NRF_CLI_UART_DEF(m_cli_uart_transport, 0, 64, 16);
  69. NRF_CLI_DEF(m_cli_uart,
  70. "uart_cli:~$ ",
  71. &m_cli_uart_transport.transport,
  72. '\r',
  73. CLI_EXAMPLE_LOG_QUEUE_SIZE);
  74. /**@brief Function for starting a command line interface that works on the UART transport layer.
  75. */
  76. static void cli_start(void)
  77. {
  78. ret_code_t ret;
  79. ret = nrf_cli_start(&m_cli_uart);
  80. APP_ERROR_CHECK(ret);
  81. }
  82. /**@brief Function for configuring UART for CLI.
  83. */
  84. static void cli_init(void)
  85. {
  86. ret_code_t ret;
  87. nrf_drv_uart_config_t uart_config = NRF_DRV_UART_DEFAULT_CONFIG;
  88. uart_config.pseltxd = TX_PIN_NUMBER;
  89. uart_config.pselrxd = RX_PIN_NUMBER;
  90. uart_config.hwfc = NRF_UART_HWFC_DISABLED;
  91. ret = nrf_cli_init(&m_cli_uart, &uart_config, true, true, NRF_LOG_SEVERITY_INFO);
  92. APP_ERROR_CHECK(ret);
  93. }
  94. /**@brief Function for initializing logging.
  95. */
  96. static void log_init(void)
  97. {
  98. ret_code_t err_code = NRF_LOG_INIT(app_timer_cnt_get);
  99. APP_ERROR_CHECK(err_code);
  100. }
  101. /** @brief Function for configuring all peripherals used in this example.
  102. */
  103. static void clock_init(void)
  104. {
  105. // Start 64 MHz crystal oscillator.
  106. NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
  107. NRF_CLOCK->TASKS_HFCLKSTART = 1;
  108. // Wait for the external oscillator to start up.
  109. while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
  110. {
  111. // Do nothing.
  112. }
  113. }
  114. /** @brief Function for the main application entry.
  115. */
  116. int main(void)
  117. {
  118. uint32_t err_code;
  119. log_init();
  120. err_code = nrf_drv_clock_init();
  121. APP_ERROR_CHECK(err_code);
  122. nrf_drv_clock_lfclk_request(NULL);
  123. err_code = app_timer_init();
  124. APP_ERROR_CHECK(err_code);
  125. clock_init();
  126. radio_cmd_init();
  127. cli_init();
  128. cli_start();
  129. #if defined(NRF21540_DRIVER_ENABLE) && (NRF21540_DRIVER_ENABLE == 1)
  130. //Initialization of nRF21540 front-end Bluetooth® range extender chip. Do not use if your hardware doesn't support it.
  131. err_code = nrf21540_init();
  132. APP_ERROR_CHECK(err_code);
  133. #endif
  134. NRF_LOG_RAW_INFO("Radio test example started.\r\n");
  135. while (true)
  136. {
  137. #if defined(NRF21540_DRIVER_ENABLE) && (NRF21540_DRIVER_ENABLE == 1)
  138. if (nrf21540_is_error())
  139. {
  140. //do something in case of nRF21540 error
  141. while(1);
  142. }
  143. #endif
  144. UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
  145. nrf_cli_process(&m_cli_uart);
  146. }
  147. }
  148. /** @} */