1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
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 
11 #include <string.h>
12 
13 #include <atmel_start.h>
14 #include "peripheral_clk_config.h"
15 
16 #include <rtthread.h>
17 #include "board.h"
18 
19 #ifdef RT_USING_SERIAL
20 extern int rt_hw_uart_init(void);
21 #endif
22 
23 static struct io_descriptor* g_stdio;
24 
rt_hw_console_output(const char * str)25 void rt_hw_console_output(const char *str)
26 {
27     io_write(g_stdio, (uint8_t *)str, strlen(str));
28     while (TARGET_IO.stat != 0);
29 }
30 RTM_EXPORT(rt_hw_console_output);
31 
hw_board_init_usart(void)32 static inline void hw_board_init_usart(void)
33 {
34     usart_async_get_io_descriptor(&TARGET_IO, &g_stdio);
35     usart_async_enable(&TARGET_IO);
36 }
37 
38 /**
39  * This is the timer interrupt service routine.
40  *
41  */
SysTick_Handler(void)42 void SysTick_Handler(void)
43 {
44     /* enter interrupt */
45     rt_interrupt_enter();
46 
47     rt_tick_increase();
48 
49     /* leave interrupt */
50     rt_interrupt_leave();
51 }
52 
53 /**
54  * This function will initial SAME70 board.
55  */
rt_hw_board_init(void)56 void rt_hw_board_init(void)
57 {
58     /* Initializes MCU, drivers and middleware */
59     atmel_start_init();
60 
61     /* Disable the watchdog */
62     WDT->WDT_MR = WDT_MR_WDDIS;
63 
64     SCB_EnableICache();
65 
66     /* enable USART stdout module */
67     hw_board_init_usart();
68 
69     /* UART driver initialization is open by default */
70 #ifdef RT_USING_SERIAL
71     rt_hw_uart_init();
72 #endif
73 
74     /* init systick */
75     SysTick_Config(CONF_CPU_FREQUENCY / RT_TICK_PER_SECOND);
76 
77     /* set pend exception priority */
78     NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
79 
80 #ifdef RT_USING_HEAP
81     #if defined(__ARMCC_VERSION)
82         rt_system_heap_init((void*)&Image$$RW_IRAM1$$ZI$$Limit, (void*)HEAP_END);
83     #elif __ICCARM__
84         rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
85     #else
86         /* init memory system */
87         rt_system_heap_init((void*)&__bss_end, (void*)HEAP_END);
88     #endif
89 #endif
90 
91     /* Set the shell console output device */
92 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
93     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
94 #endif
95 
96 #ifdef RT_USING_COMPONENTS_INIT
97     rt_components_board_init();
98 #endif
99 }
100 
101 /*@}*/
102