1
0

board.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-29 supperthomas first version
  9. * 2020-04-29 supperthomas fix component init
  10. *
  11. */
  12. #include <rtthread.h>
  13. #include <rthw.h>
  14. #include <nrfx_systick.h>
  15. #include "board.h"
  16. #include "drv_uart.h"
  17. #include <nrfx_clock.h>
  18. /**
  19. * This is the timer interrupt service routine.
  20. *
  21. */
  22. void SysTick_Handler(void)
  23. {
  24. /* enter interrupt */
  25. rt_interrupt_enter();
  26. rt_tick_increase();
  27. /* leave interrupt */
  28. rt_interrupt_leave();
  29. }
  30. static void clk_event_handler(nrfx_clock_evt_type_t event){}
  31. void SysTick_Configuration(void)
  32. {
  33. nrfx_clock_init(clk_event_handler);
  34. nrfx_clock_enable();
  35. nrfx_clock_lfclk_start();
  36. /* Set interrupt priority */
  37. NVIC_SetPriority(SysTick_IRQn, 0xf);
  38. /* Configure SysTick to interrupt at the requested rate. */
  39. nrf_systick_load_set(SystemCoreClock / RT_TICK_PER_SECOND);
  40. nrf_systick_val_clear();
  41. nrf_systick_csr_set(NRF_SYSTICK_CSR_CLKSOURCE_CPU | NRF_SYSTICK_CSR_TICKINT_ENABLE
  42. | NRF_SYSTICK_CSR_ENABLE);
  43. }
  44. void rt_hw_board_init(void)
  45. {
  46. rt_hw_interrupt_enable(0);
  47. SysTick_Configuration();
  48. #if defined(RT_USING_HEAP)
  49. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  50. #endif
  51. #ifdef RT_USING_SERIAL
  52. rt_hw_uart_init();
  53. #endif
  54. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  55. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  56. #endif
  57. #ifdef RT_USING_COMPONENTS_INIT
  58. rt_components_board_init();
  59. #endif
  60. #ifdef BSP_USING_SOFTDEVICE
  61. extern uint32_t Image$$RW_IRAM1$$Base;
  62. uint32_t const *const m_ram_start = &Image$$RW_IRAM1$$Base;
  63. if ((uint32_t)m_ram_start == 0x20000000)
  64. {
  65. rt_kprintf("\r\n using softdevice the RAM couldn't be %p,please use the templete from package\r\n", m_ram_start);
  66. while (1);
  67. }
  68. else
  69. {
  70. rt_kprintf("\r\n using softdevice the RAM at %p\r\n", m_ram_start);
  71. }
  72. #endif
  73. }