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 * 2006-03-24 Bernard first implementation
9 * 2006-05-05 Bernard add DATA_COUNT definition
10 * 2006-10-05 Alsor.Z for s3c2410x porting
11 * 2007-11-20 Yi.Qiu add lcd,touch,console
12 */
13
14 #include <rtthread.h>
15 #include <rthw.h>
16
17 #include "board.h"
18 #include "led.h"
19
20 /**
21 * @addtogroup mini2440
22 */
23 /*@{*/
24
25 #if defined(__CC_ARM)
26 extern int Image$$ER_ZI$$ZI$$Base;
27 extern int Image$$ER_ZI$$ZI$$Length;
28 extern int Image$$ER_ZI$$ZI$$Limit;
29 #elif (defined (__GNUC__))
30 rt_uint8_t _irq_stack_start[1024];
31 rt_uint8_t _fiq_stack_start[1024];
32 rt_uint8_t _undefined_stack_start[512];
33 rt_uint8_t _abort_stack_start[512];
34 rt_uint8_t _svc_stack_start[4096] rt_section(".nobss");
35 #endif
36
37 #if defined(__CC_ARM)
38 extern int Image$$RW_IRAM1$$ZI$$Limit;
39 #define HEAP_BEGIN ((void*)&Image$$RW_IRAM1$$ZI$$Limit)
40 #elif defined(__GNUC__)
41 extern int __bss_end;
42 #define HEAP_BEGIN (((void*)&__bss_end) + 0x1000)
43 #endif
44
45 #define HEAP_END (void*)(0x33F00000)
46
47
48 extern rt_uint32_t PCLK, FCLK, HCLK, UCLK;
49
50 extern void rt_hw_clock_init(void);
51 extern void rt_hw_mmu_init(void);
52
53 extern void rt_hw_get_clock(void);
54 extern void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn);
55 extern void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv);
56
57 /**
58 * This function will handle rtos timer
59 */
rt_timer_handler(int vector,void * param)60 static void rt_timer_handler(int vector, void *param)
61 {
62 rt_tick_increase();
63 }
64
65 /**
66 * This function will init timer4 for system ticks
67 */
rt_hw_timer_init(void)68 static void rt_hw_timer_init(void)
69 {
70 /* timer4, pre = 15+1 */
71 TCFG0 &= 0xffff00ff;
72 TCFG0 |= 15 << 8;
73 /* all are interrupt mode,set Timer 4 MUX 1/4 */
74 TCFG1 &= 0xfff0ffff;
75 TCFG1 |= 0x00010000;
76
77 TCNTB4 = (rt_int32_t)(PCLK / (4 *16* RT_TICK_PER_SECOND)) - 1;
78 /* manual update */
79 TCON = TCON & (~(0x0f<<20)) | (0x02<<20);
80 /* install interrupt handler */
81 rt_hw_interrupt_install(INTTIMER4, rt_timer_handler, RT_NULL, "tick");
82 rt_hw_interrupt_umask(INTTIMER4);
83
84 /* start timer4, reload */
85 TCON = TCON & (~(0x0f<<20)) | (0x05<<20);
86 }
87
88 /**
89 * This function will init s3ceb2410 board
90 */
rt_hw_board_init(void)91 void rt_hw_board_init(void)
92 {
93 rt_hw_cpu_icache_enable();
94 rt_hw_cpu_dcache_enable();
95
96 /* init hardware interrupt */
97 rt_hw_interrupt_init();
98
99 /* initialize the system clock */
100 rt_hw_clock_init();
101
102 /* Get the clock */
103 rt_hw_get_clock();
104
105 /* initialize led port */
106 rt_hw_led_init();
107
108 /* initialize mmu */
109 rt_hw_mmu_init();
110
111 /* initialize timer4 */
112 rt_hw_timer_init();
113
114 /* initialize system heap */
115 rt_system_heap_init(HEAP_BEGIN, HEAP_END);
116
117 rt_components_board_init();
118
119 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
120 rt_console_set_device("uart0");
121 #endif
122
123 }
124
125 /*@}*/
126