1 /*
2  * Copyright (c) 2006-2020, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2020-11-24     WangHuachen  the first version
9  */
10 #include <rthw.h>
11 #include <rtthread.h>
12 #include <dfs_fs.h>
13 
14 #include "board.h"
15 #include "drv_timer.h"
16 
17 #define ITERS_PER_USEC  (XPAR_CPU_CORTEXR5_0_CPU_CLK_FREQ_HZ / 4000000)
rt_hw_us_delay(rt_uint32_t us)18 void rt_hw_us_delay(rt_uint32_t us)
19 {
20     __asm__ __volatile__ (
21         "push {r0,r1,r3} \n"
22         "mov r0, %[usec] \n"
23         "mov r1, %[iter] \n"
24         "1: \n"
25         "mov r3, r1 \n"
26         "2: \n"
27         "subs r3, r3, #0x1\n"
28         "bne 2b \n"
29         "subs r0, r0, #0x1 \n"
30         "bne 1b \n"
31         "pop {r0,r1,r3} \n"
32         ::[iter] "r" (ITERS_PER_USEC), [usec] "r" (us)
33         );
34 }
35 
36 #ifdef RT_USING_CONSOLE
37 
38 #include "drv_uart.h"
rt_hw_serial_putc(const char c)39 void rt_hw_serial_putc(const char c)
40 {
41     UART_Registers *uart = (UART_Registers *)XPAR_PSU_UART_0_BASEADDR;
42     if (c == '\n')
43         rt_hw_serial_putc('\r');
44 
45     while ((uart->SR) & UART_SR_TXFULL);
46     uart->FIFO = c;
47 }
rt_hw_console_output(const char * str)48 void rt_hw_console_output(const char *str)
49 {
50     while (*str)
51     {
52         rt_hw_serial_putc(*str++);
53     }
54 }
55 #endif
56 
57 /**
58  * This function will initialize beaglebone board
59  */
rt_hw_board_init(void)60 void rt_hw_board_init(void)
61 {
62     /* initialize hardware interrupt */
63     rt_hw_interrupt_init();
64     /* initialize system heap */
65 #ifdef RT_USING_HEAP
66     rt_system_heap_init(HEAP_BEGIN, HEAP_END);
67 #endif
68 
69 #ifdef RT_USING_COMPONENTS_INIT
70     rt_components_board_init();
71 #endif
72 
73 #ifdef RT_USING_CONSOLE
74     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
75 #endif
76 }