1 | /*-------------------------------------------------------------------------+ |
---|
2 | | This file contains the ARM BSP startup package. It includes application, |
---|
3 | | board, and monitor specific initialization and configuration. The generic CPU |
---|
4 | | dependent initialization has been performed before this routine is invoked. |
---|
5 | +--------------------------------------------------------------------------+ |
---|
6 | | |
---|
7 | | Copyright (c) 2000 Canon Research Centre France SA. |
---|
8 | | Emmanuel Raguet, mailto:raguet@crf.canon.fr |
---|
9 | | |
---|
10 | | The license and distribution terms for this file may be |
---|
11 | | found in found in the file LICENSE in this distribution or at |
---|
12 | | http://www.rtems.com/license/LICENSE. |
---|
13 | | |
---|
14 | +--------------------------------------------------------------------------*/ |
---|
15 | |
---|
16 | |
---|
17 | #include <bsp.h> |
---|
18 | #include <rtems/libcsupport.h> |
---|
19 | #include <rtems/libio.h> |
---|
20 | #include <rtems/bspIo.h> |
---|
21 | #include <s3c2400.h> |
---|
22 | |
---|
23 | /*-------------------------------------------------------------------------+ |
---|
24 | | Global Variables |
---|
25 | +--------------------------------------------------------------------------*/ |
---|
26 | |
---|
27 | extern void *_sdram_size; |
---|
28 | extern void *_sdram_base; |
---|
29 | extern void *_bss_free_start; |
---|
30 | |
---|
31 | unsigned long free_mem_start; |
---|
32 | unsigned long free_mem_end; |
---|
33 | |
---|
34 | /* The original BSP configuration table from the application and our copy of it |
---|
35 | with some changes. */ |
---|
36 | |
---|
37 | extern rtems_configuration_table Configuration; |
---|
38 | rtems_configuration_table BSP_Configuration; |
---|
39 | |
---|
40 | rtems_cpu_table Cpu_table; /* CPU configuration table. */ |
---|
41 | char *rtems_progname = "RTEMS"; /* Program name - from main(). */ |
---|
42 | |
---|
43 | /*-------------------------------------------------------------------------+ |
---|
44 | | External Prototypes |
---|
45 | +--------------------------------------------------------------------------*/ |
---|
46 | extern void rtems_irq_mngt_init(void); |
---|
47 | void bsp_libc_init( void *, uint32_t, int ); |
---|
48 | void bsp_postdriver_hook(void); |
---|
49 | |
---|
50 | /*-------------------------------------------------------------------------+ |
---|
51 | | Function: bsp_pretasking_hook |
---|
52 | | Description: BSP pretasking hook. Called just before drivers are |
---|
53 | | initialized. Used to setup libc and install any BSP |
---|
54 | | extensions. NOTE: Must not use libc (to do io) from here, |
---|
55 | | since drivers are not yet initialized. |
---|
56 | | Global Variables: None. |
---|
57 | | Arguments: None. |
---|
58 | | Returns: Nothing. |
---|
59 | +--------------------------------------------------------------------------*/ |
---|
60 | void bsp_pretasking_hook(void) |
---|
61 | { |
---|
62 | uint32_t heap_start; |
---|
63 | uint32_t heap_size; |
---|
64 | |
---|
65 | /* |
---|
66 | * Set up the heap. |
---|
67 | */ |
---|
68 | heap_start = free_mem_start; |
---|
69 | heap_size = free_mem_end - free_mem_start; |
---|
70 | |
---|
71 | /* call rtems lib init - malloc stuff */ |
---|
72 | bsp_libc_init((void *)heap_start, heap_size, 0); |
---|
73 | |
---|
74 | #ifdef RTEMS_DEBUG |
---|
75 | |
---|
76 | rtems_debug_enable(RTEMS_DEBUG_ALL_MASK); |
---|
77 | |
---|
78 | #endif /* RTEMS_DEBUG */ |
---|
79 | |
---|
80 | } /* bsp_pretasking_hook */ |
---|
81 | |
---|
82 | void bsp_idle_task(void) |
---|
83 | { |
---|
84 | while(1){ |
---|
85 | asm volatile ("MCR p15,0,r0,c7,c0,4 \n"); |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | /*-------------------------------------------------------------------------+ |
---|
90 | | Function: bsp_start |
---|
91 | | Description: Called before main is invoked. |
---|
92 | | Global Variables: None. |
---|
93 | | Arguments: None. |
---|
94 | | Returns: Nothing. |
---|
95 | +--------------------------------------------------------------------------*/ |
---|
96 | void bsp_start_default( void ) |
---|
97 | { |
---|
98 | uint32_t cr; |
---|
99 | uint32_t pend,last; |
---|
100 | uint32_t REFCNT; |
---|
101 | int i; |
---|
102 | |
---|
103 | /* stop RTC */ |
---|
104 | rTICINT=0x0; |
---|
105 | |
---|
106 | /* stop watchdog,ADC and timers */ |
---|
107 | rWTCON=0x0; |
---|
108 | rTCON=0x0; |
---|
109 | rADCCON=0x0; |
---|
110 | |
---|
111 | /* disable interrupts */ |
---|
112 | rINTMOD=0x0; |
---|
113 | rINTMSK=BIT_ALLMSK; /* unmasked by drivers */ |
---|
114 | |
---|
115 | last=0; |
---|
116 | for(i=0; i<4; i++) { |
---|
117 | pend=rSRCPND; |
---|
118 | if(pend == 0 || pend == last) |
---|
119 | break; |
---|
120 | rSRCPND=pend; |
---|
121 | rINTPND=pend; |
---|
122 | last=pend; |
---|
123 | } |
---|
124 | |
---|
125 | /* setup clocks */ |
---|
126 | rCLKDIVN=M_CLKDIVN; |
---|
127 | rMPLLCON=((M_MDIV<<12)+(M_PDIV<<4)+M_SDIV); |
---|
128 | /* setup rREFRESH */ |
---|
129 | REFCNT=2048+1-(15.6*get_HCLK()/1000000); /* period=15.6 us, HCLK=66Mhz, (2048+1-15.6*66) */ |
---|
130 | rREFRESH=((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+(Tchr<<16)+REFCNT); |
---|
131 | |
---|
132 | /* set prescaler for timers 2,3,4 to 16(15+1) */ |
---|
133 | cr=rTCFG0 & 0xFFFF00FF; |
---|
134 | rTCFG0=(cr | (15<<8)); |
---|
135 | |
---|
136 | /* set prescaler for timers 0,1 to 1(0+1) */ |
---|
137 | cr=rTCFG0 & 0xFFFFFF00; |
---|
138 | rTCFG0=(cr | (0<<0)); |
---|
139 | |
---|
140 | /* Place RTEMS workspace at beginning of free memory. */ |
---|
141 | BSP_Configuration.work_space_start = (void *)&_bss_free_start; |
---|
142 | |
---|
143 | free_mem_start = ((uint32_t)&_bss_free_start + BSP_Configuration.work_space_size); |
---|
144 | |
---|
145 | free_mem_end = ((uint32_t)&_sdram_base + (uint32_t)&_sdram_size); |
---|
146 | |
---|
147 | /* |
---|
148 | * Init rtems exceptions management |
---|
149 | */ |
---|
150 | rtems_exception_init_mngt(); |
---|
151 | |
---|
152 | /* |
---|
153 | * Init rtems interrupt management |
---|
154 | */ |
---|
155 | rtems_irq_mngt_init(); |
---|
156 | /* |
---|
157 | * The following information is very useful when debugging. |
---|
158 | */ |
---|
159 | |
---|
160 | #if 0 |
---|
161 | printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size ); |
---|
162 | printk( "maximum_extensions = 0x%x\n", BSP_Configuration.maximum_extensions ); |
---|
163 | printk( "microseconds_per_tick = 0x%x\n", |
---|
164 | BSP_Configuration.microseconds_per_tick ); |
---|
165 | printk( "ticks_per_timeslice = 0x%x\n", |
---|
166 | BSP_Configuration.ticks_per_timeslice ); |
---|
167 | printk( "number_of_device_drivers = 0x%x\n", |
---|
168 | BSP_Configuration.number_of_device_drivers ); |
---|
169 | printk( "Device_driver_table = 0x%x\n", |
---|
170 | BSP_Configuration.Device_driver_table ); |
---|
171 | |
---|
172 | printk( "_heap_size = 0x%x\n", _heap_size ); |
---|
173 | /* printk( "_stack_size = 0x%x\n", _stack_size );*/ |
---|
174 | printk( "rtemsFreeMemStart = 0x%x\n", rtemsFreeMemStart ); |
---|
175 | printk( "work_space_start = 0x%x\n", BSP_Configuration.work_space_start ); |
---|
176 | printk( "work_space_size = 0x%x\n", BSP_Configuration.work_space_size ); |
---|
177 | #endif |
---|
178 | |
---|
179 | } |
---|
180 | |
---|
181 | /* |
---|
182 | * By making this a weak alias for bsp_start_default, a brave soul |
---|
183 | * can override the actual bsp_start routine used. |
---|
184 | */ |
---|
185 | |
---|
186 | void bsp_start (void) __attribute__ ((weak, alias("bsp_start_default"))); |
---|
187 | |
---|
188 | void bsp_reset(void) |
---|
189 | { |
---|
190 | rtems_interrupt_level level; |
---|
191 | rtems_interrupt_disable(level); |
---|
192 | printk("bsp_reset.....\n"); |
---|
193 | /* disable mmu, invalide i-cache and call swi #4 */ |
---|
194 | asm volatile("" |
---|
195 | "mrc p15,0,r0,c1,c0,0 \n" |
---|
196 | "bic r0,r0,#1 \n" |
---|
197 | "mcr p15,0,r0,c1,c0,0 \n" |
---|
198 | "nop \n" |
---|
199 | "nop \n" |
---|
200 | "nop \n" |
---|
201 | "nop \n" |
---|
202 | "nop \n" |
---|
203 | "mov r0,#0 \n" |
---|
204 | "MCR p15,0,r0,c7,c5,0 \n" |
---|
205 | "nop \n" |
---|
206 | "nop \n" |
---|
207 | "nop \n" |
---|
208 | "nop \n" |
---|
209 | "nop \n" |
---|
210 | "swi #4 " |
---|
211 | : |
---|
212 | : |
---|
213 | : "r0" |
---|
214 | ); |
---|
215 | /* we should be back in bios now */ |
---|
216 | } |
---|