Advertisement
Guest User

Untitled

a guest
Mar 26th, 2016
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. /* Copyright (c) 2014 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.  
  13. /** @file
  14. *
  15. * @defgroup bsp_example_main main.c
  16. * @{
  17. * @ingroup bsp_example
  18. * @brief BSP Example Application main file.
  19. *
  20. */
  21.  
  22. #include <stdbool.h>
  23. #include <stdint.h>
  24. #include "boards.h"
  25. #include "bsp.h"
  26. #include "app_timer.h"
  27. #include "nordic_common.h"
  28. #include "nrf_error.h"
  29. #include "nrf_gpio.h"
  30. #include <inttypes.h>
  31.  
  32. #define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
  33. #define APP_TIMER_OP_QUEUE_SIZE 2 /**< Size of timer operation queues. */
  34.  
  35. #define BUTTON_PREV_ID 0 /**< Button used to switch the state. */
  36. #define BUTTON_NEXT_ID 1 /**< Button used to switch the state. */
  37.  
  38. #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
  39. #define UART_RX_BUF_SIZE 1 /**< UART RX buffer size. */
  40.  
  41. #define PORT_NUM 3
  42.  
  43. bsp_indication_t actual_state = BSP_INDICATE_FIRST; /**< Currently indicated state. */
  44.  
  45. const char * indications_list[] = BSP_INDICATIONS_LIST;
  46.  
  47.  
  48. static void gpio_init(void)
  49. {
  50. nrf_gpio_cfg_input(PORT_NUM, NRF_GPIO_PIN_NOPULL);
  51. }
  52.  
  53. void uart_error_handle(app_uart_evt_t * p_event)
  54. {
  55. // No implementation needed.
  56. }
  57.  
  58. /**@brief Function for handling bsp events.
  59. */
  60. void bsp_evt_handler(bsp_event_t evt)
  61. {
  62. uint32_t err_code;
  63. switch (evt)
  64. {
  65. case BSP_EVENT_KEY_0:
  66.  
  67. if (actual_state != BSP_INDICATE_FIRST)
  68. actual_state--;
  69. else
  70. actual_state = BSP_INDICATE_LAST;
  71. break;
  72.  
  73. case BSP_EVENT_KEY_1:
  74.  
  75. if (actual_state != BSP_INDICATE_LAST)
  76. actual_state++;
  77. else
  78. actual_state = BSP_INDICATE_FIRST;
  79. break;
  80.  
  81. default:
  82. return; // no implementation needed
  83. }
  84.  
  85. err_code = bsp_indication_text_set(actual_state, indications_list[actual_state]);
  86. APP_ERROR_CHECK(err_code);
  87.  
  88. uint32_t pin_value = 0;
  89. uint8_t port_value = 0;
  90. pin_value = nrf_gpio_pin_read(PORT_NUM);
  91. port_value = nrf_gpio_port_read(PORT_NUM);
  92. printf("pin value: %zu\n\r", pin_value);
  93. printf("port value: %zu\n\r", port_value);
  94. printf("port value: %" PRIu8 " \n\r", port_value);
  95. }
  96.  
  97.  
  98. /**@brief Function for initializing low frequency clock.
  99. */
  100. void clock_initialization()
  101. {
  102. NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
  103. NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
  104. NRF_CLOCK->TASKS_LFCLKSTART = 1;
  105.  
  106. while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
  107. {
  108. // Do nothing.
  109. }
  110. }
  111.  
  112.  
  113. /**@brief Function for initializing bsp module.
  114. */
  115. void bsp_configuration()
  116. {
  117. uint32_t err_code;
  118.  
  119. err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
  120. APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
  121. bsp_evt_handler);
  122. APP_ERROR_CHECK(err_code);
  123.  
  124. // err_code = bsp_buttons_enable( (1 << BUTTON_PREV_ID) | (1 << BUTTON_NEXT_ID) );
  125. // APP_ERROR_CHECK(err_code);
  126. }
  127.  
  128.  
  129. /**@brief Function for initializing the UART.
  130. */
  131. static void uart_init(void)
  132. {
  133. uint32_t err_code;
  134.  
  135.  
  136. const app_uart_comm_params_t comm_params =
  137. {
  138. RX_PIN_NUMBER,
  139. TX_PIN_NUMBER,
  140. RTS_PIN_NUMBER,
  141. CTS_PIN_NUMBER,
  142. APP_UART_FLOW_CONTROL_DISABLED,
  143. false,
  144. UART_BAUDRATE_BAUDRATE_Baud115200
  145. };
  146.  
  147. APP_UART_FIFO_INIT(&comm_params,
  148. UART_RX_BUF_SIZE,
  149. UART_TX_BUF_SIZE,
  150. uart_error_handle,
  151. APP_IRQ_PRIORITY_LOW,
  152. err_code);
  153.  
  154. APP_ERROR_CHECK(err_code);
  155. }
  156.  
  157.  
  158. /**
  159. * @brief Function for application main entry.
  160. */
  161. int main(void)
  162. {
  163. uint32_t err_code = NRF_SUCCESS;
  164.  
  165. clock_initialization();
  166. APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
  167. gpio_init();
  168. uart_init();
  169. bsp_configuration();
  170.  
  171. err_code = bsp_indication_text_set(actual_state,indications_list[actual_state]);
  172. APP_ERROR_CHECK(err_code);
  173.  
  174. printf("In main\n\r");
  175.  
  176. uint32_t pin_value = 0;
  177. uint8_t port_value = 0;
  178. pin_value = nrf_gpio_pin_read(PORT_NUM);
  179. port_value = nrf_gpio_port_read(PORT_NUM);
  180. printf("pin value: %zu\n\r", pin_value);
  181. printf("port value: %zu\n\r", port_value);
  182. printf("port value: %" PRIu8 " \n\r", port_value);
  183.  
  184. while (true)
  185. {
  186. // no implementation needed
  187. }
  188. }
  189.  
  190.  
  191. /** @} */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement