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  * 2011-01-13     weety      first version
9  * 2015-05-02     ArdaFu     Port from AT91SAM9260 BSP
10  */
11 
12 #include <rtthread.h>
13 #include <rthw.h>
14 #include <timer0.h>
15 #include "board.h"
16 #include <mmu.h>
17 #include "interrupt.h"
18 
19 extern void rt_hw_interrupt_init(void);
20 extern void rt_hw_clock_init(void);
21 extern void rt_hw_uart_init(void);
22 
23 static struct mem_desc hw_mem_desc[] =
24 {
25     { 0x00000000, 0xFFFFFFFF, 0x00000000, RW_NCNB },/* None cached for 4G memory */
26 //  visual start, visual end, phy start , props
27     { 0x00000000, 0x000FFFFF, 0x20000000, RW_CB },  /* ISR Vector table */
28     { 0x00200000, 0x00001FFF, 0x40000000, RW_CB },  /* 8K cached SRAM 0/1 */
29     { 0x20000000, 0x21FFFFFF, 0x20000000, RW_CB },  /* 32M cached SDRAM */
30     { 0x90000000, 0x90001FFF, 0x40000000, RW_NCNB },/* 4K SRAM0 + 4k SRAM1 */
31     { 0xA0000000, 0xA1FFFFFF, 0x20000000, RW_NCNB },/* 32M none-cached SDRAM */
32 };
33 
34 /**
35  * This function will handle rtos timer
36  */
rt_systick_handler(int vector,void * param)37 static void rt_systick_handler(int vector, void *param)
38 {
39     uint32_t ir = inl(HW_TIMER0_IR);
40     if (ir & 1UL)
41         rt_tick_increase();
42     outl(ir, REG_SET(HW_TIMER0_IR));
43 }
44 
45 /**
46  * This function will init pit for system ticks
47  */
rt_hw_timer_init()48 static void rt_hw_timer_init()
49 {
50     hw_timer0_init();
51     /* install interrupt handler */
52     rt_hw_interrupt_install(INT_TIMER0, rt_systick_handler, RT_NULL, "SysTick");
53     rt_hw_interrupt_umask(INT_TIMER0);
54 
55 }
56 
57 /**
58  * This function will init at91sam9260 board
59  */
rt_hw_board_init(void)60 void rt_hw_board_init(void)
61 {
62     /* initialize mmu */
63     rt_hw_mmu_init(hw_mem_desc, sizeof(hw_mem_desc)/sizeof(hw_mem_desc[0]));
64     /* initialize hardware interrupt */
65     rt_hw_interrupt_init();
66 
67     /* initialize the system clock */
68     //rt_hw_clock_init(); //set each pll etc.
69 
70     /* initialize uart */
71     rt_hw_uart_init();
72     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
73 
74     /* initialize timer0 */
75     rt_hw_timer_init();
76 }
77