board.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c)
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Email Notes
  8. * 2019-07-16 Kevin.Liu kevin.liu.mchp@gmail.com First Release
  9. */
  10. #include <string.h>
  11. #include <atmel_start.h>
  12. #include "peripheral_clk_config.h"
  13. #include <rtthread.h>
  14. #include "board.h"
  15. #ifdef RT_USING_SERIAL
  16. extern int rt_hw_uart_init(void);
  17. #endif
  18. static struct io_descriptor* g_stdio;
  19. void rt_hw_console_output(const char *str)
  20. {
  21. io_write(g_stdio, (uint8_t *)str, strlen(str));
  22. while (TARGET_IO.stat != 0);
  23. }
  24. RTM_EXPORT(rt_hw_console_output);
  25. static inline void hw_board_init_usart(void)
  26. {
  27. usart_async_get_io_descriptor(&TARGET_IO, &g_stdio);
  28. usart_async_enable(&TARGET_IO);
  29. }
  30. /**
  31. * This is the timer interrupt service routine.
  32. *
  33. */
  34. void SysTick_Handler(void)
  35. {
  36. /* enter interrupt */
  37. rt_interrupt_enter();
  38. rt_tick_increase();
  39. /* leave interrupt */
  40. rt_interrupt_leave();
  41. }
  42. /**
  43. * This function will initial SAME70 board.
  44. */
  45. void rt_hw_board_init(void)
  46. {
  47. /* Initializes MCU, drivers and middleware */
  48. atmel_start_init();
  49. /* Disable the watchdog */
  50. WDT->WDT_MR = WDT_MR_WDDIS;
  51. SCB_EnableICache();
  52. /* enable USART stdout module */
  53. hw_board_init_usart();
  54. /* UART driver initialization is open by default */
  55. #ifdef RT_USING_SERIAL
  56. rt_hw_uart_init();
  57. #endif
  58. /* init systick */
  59. SysTick_Config(CONF_CPU_FREQUENCY / RT_TICK_PER_SECOND);
  60. /* set pend exception priority */
  61. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  62. #ifdef RT_USING_HEAP
  63. #if defined(__ARMCC_VERSION)
  64. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)HEAP_END);
  65. #elif __ICCARM__
  66. rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
  67. #else
  68. /* init memory system */
  69. rt_system_heap_init((void*)&__bss_end, (void*)HEAP_END);
  70. #endif
  71. #endif
  72. /* Set the shell console output device */
  73. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  74. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  75. #endif
  76. #ifdef RT_USING_COMPONENTS_INIT
  77. rt_components_board_init();
  78. #endif
  79. }
  80. /*@}*/