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  * 2009-01-05     Bernard      first implementation
9  * 2018-03-15     flyingcys    add amebaz
10  */
11 #include <rtl8710b.h>
12 #include <stdint.h>
13 #include "board.h"
14 #include "drv_uart.h"
15 
16 #ifdef __ICCARM__
17 #pragma section="HEAP"
18 #define HEAP_BEGIN         (__segment_end("HEAP"))
19 #elif  defined(__GNUC__)
20 extern int __rtt_heap_start;
21 #define HEAP_BEGIN          (&__rtt_heap_start)
22 #else
23 #error "not support toolchain!!!"
24 #endif
25 
26 #define HEAP_END           (0x1002FFFF)
27 
28 #ifdef __GNUC__
__wrap_rtl_printf(const char * fmt,...)29 void __wrap_rtl_printf(const char *fmt, ...)
30 {
31     va_list args;
32     rt_size_t length;
33     static char rt_log_buf[RT_CONSOLEBUF_SIZE];
34 
35     va_start(args, fmt);
36     /* the return value of vsnprintf is the number of bytes that would be
37      * written to buffer had if the size of the buffer been sufficiently
38      * large excluding the terminating null byte. If the output string
39      * would be larger than the rt_log_buf, we have to adjust the output
40      * length. */
41     length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args);
42     if (length > RT_CONSOLEBUF_SIZE - 1)
43         length = RT_CONSOLEBUF_SIZE - 1;
44     rt_kprintf("%s", rt_log_buf);
45     va_end(args);
46 }
47 #endif
48 
49 /**
50  * This is the timer interrupt service routine.
51  *
52  */
SysTick_Handler(void)53 void SysTick_Handler(void)
54 {
55     /* enter interrupt */
56     rt_interrupt_enter();
57 
58     rt_tick_increase();
59 
60     /* leave interrupt */
61     rt_interrupt_leave();
62 }
63 
SysTick_Config(uint32_t ticks)64  uint32_t SysTick_Config(uint32_t ticks)
65 {
66   if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk)  return (1);      /* Reload value impossible */
67 
68   SysTick->LOAD  = ticks - 1;                                  /* set reload register */
69   NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Systick Interrupt */
70   SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
71   SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
72                    SysTick_CTRL_TICKINT_Msk   |
73                    SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
74   return (0);                                                  /* Function successful */
75 }
76 
77 /**
78  * This function will initial board.
79  */
rt_hw_board_init(void)80 void rt_hw_board_init(void)
81 {
82     extern uint32_t SystemCoreClock;
83     SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND);
84 
85 #ifdef RT_USING_HEAP
86         rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
87 #endif
88 
89 #ifdef RT_USING_COMPONENTS_INIT
90     rt_components_board_init();
91 #endif
92 
93 #ifdef RT_USING_SERIAL
94     rt_hw_uart_init();
95 #endif
96 
97 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
98     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
99 #endif
100 }
101 
102 /*@}*/
103