board.c 2.0 KB

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