board.c 2.0 KB

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