board.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. static uint8_t board_info[16] = "Microchip SAME54";
  20. void rt_hw_console_output(const char *str)
  21. {
  22. io_write(g_stdio, (uint8_t *)str, strlen(str));
  23. while (TARGET_IO.stat != 0);
  24. }
  25. RTM_EXPORT(rt_hw_console_output);
  26. static inline void hw_board_init_usart(void)
  27. {
  28. usart_async_get_io_descriptor(&TARGET_IO, &g_stdio);
  29. usart_async_enable(&TARGET_IO);
  30. io_write(g_stdio, board_info, 16);
  31. }
  32. /**
  33. * This is the timer interrupt service routine.
  34. *
  35. */
  36. void SysTick_Handler(void)
  37. {
  38. /* enter interrupt */
  39. rt_interrupt_enter();
  40. rt_tick_increase();
  41. /* leave interrupt */
  42. rt_interrupt_leave();
  43. }
  44. /**
  45. * This function will initial SAME54 board.
  46. */
  47. void rt_hw_board_init(void)
  48. {
  49. /* Initializes MCU, drivers and middleware */
  50. atmel_start_init();
  51. /* enable USART stdout module */
  52. hw_board_init_usart();
  53. /* UART driver initialization is open by default */
  54. #ifdef RT_USING_SERIAL
  55. rt_hw_uart_init();
  56. #endif
  57. /* init systick */
  58. SysTick_Config(CONF_CPU_FREQUENCY / RT_TICK_PER_SECOND);
  59. /* set pend exception priority */
  60. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  61. #ifdef RT_USING_HEAP
  62. #if defined(__ARMCC_VERSION)
  63. rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)HEAP_END);
  64. #elif __ICCARM__
  65. rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
  66. #else
  67. /* init memory system */
  68. rt_system_heap_init((void*)&__bss_end, (void*)HEAP_END);
  69. #endif
  70. #endif
  71. /* Set the shell console output device */
  72. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  73. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  74. #endif
  75. #ifdef RT_USING_COMPONENTS_INIT
  76. rt_components_board_init();
  77. #endif
  78. }
  79. /*@}*/