]>
Commit | Line | Data |
---|---|---|
1 | ; Hardware initialisation, disk, mmc, timer, DRAM test | |
2 | ; | |
3 | ; Copyright (C) 2010 Sprite_tm | |
4 | ; Copyright (C) 2010-2013 Leo C. | |
5 | ; | |
6 | ; This file is part of avrcpm. | |
7 | ; | |
8 | ; avrcpm is free software: you can redistribute it and/or modify it | |
9 | ; under the terms of the GNU General Public License as published by | |
10 | ; the Free Software Foundation, either version 3 of the License, or | |
11 | ; (at your option) any later version. | |
12 | ; | |
13 | ; avrcpm is distributed in the hope that it will be useful, | |
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | ; GNU General Public License for more details. | |
17 | ; | |
18 | ; You should have received a copy of the GNU General Public License | |
19 | ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>. | |
20 | ; | |
21 | ; $Id$ | |
22 | ; | |
23 | ||
24 | #define REFR_PRE 8 /* timer prescale factor 1/8 */ | |
25 | #define REFR_CS 0x02 /* timer clock select for 1/8 */ | |
26 | #define REFR_CNT F_CPU / REFR_RATE / REFR_PRE | |
27 | ||
28 | .cseg | |
29 | regval_tab: | |
30 | .db 0,0 | |
31 | .db 0xFE,0xFC ; _RAS0 _CAS0 | |
32 | .db 0xF8,0xF4 ; _OE _WE | |
33 | .db 255,0 ; _255 _0 | |
34 | regval_tab_e: | |
35 | ||
36 | start: | |
37 | ldi temp,low(RAMEND) ; top of memory; vim:set ts=8 noet nowrap | |
38 | ||
39 | out SPL,temp ; init stack pointer | |
40 | ldi temp,high(RAMEND) ; top of memory | |
41 | out SPH,temp ; init stack pointer | |
42 | ||
43 | ; - Load some registers with constant values | |
44 | ||
45 | ldiw z,regval_tab*2 | |
46 | ldiw y,0 | |
47 | cp_l: lpm xh,z+ | |
48 | st y+,xh | |
49 | cpi zl,low(regval_tab_e*2) | |
50 | brne cp_l | |
51 | ||
52 | ; - Kill wdt | |
53 | ||
54 | wdr | |
55 | out MCUSR,_0 | |
56 | ||
57 | ldi temp,(1<<WDCE) | (1<<WDE) | |
58 | outm8 WDTCSR,temp | |
59 | ldi temp,(1<<WDCE) | |
60 | outm8 WDTCSR,temp | |
61 | ||
62 | ; - Setup Ports | |
63 | ||
64 | ; ldi temp,(1<<PUD) ;disable pullups | |
65 | ; outm8 P_PUD,temp | |
66 | out PORTD,_255 ;all pins high (enables pullup on input ports) | |
67 | out PORTB,_255 | |
68 | out PORTC,_255 | |
69 | out DDRD,_255 ; all outputs | |
70 | out DDRB,_255 | |
71 | out DDRC,_255 | |
72 | cbi P_RXD-1,RXD ; RXD pin is input | |
73 | ||
74 | outm8 TIMSK1,_0 | |
75 | outm8 TIMSK2,_0 | |
76 | outm8 TCCR2A,_0 | |
77 | outm8 TCCR2B,_0 | |
78 | ||
79 | ; - Clear RAM | |
80 | ||
81 | ldiw z,SRAM_START | |
82 | ldi temp2,high(ramtop) | |
83 | clr_loop: | |
84 | st z+,_0 | |
85 | cpi zl,low(ramtop) | |
86 | cpc zh,temp2 | |
87 | brne clr_loop | |
88 | ||
89 | ; - Fill unused RAM (stack) | |
90 | ||
91 | ldi temp2,high(RAMEND+1) | |
92 | ldi temp,SRAMFILL_VAL | |
93 | fill_loop: | |
94 | st z+,temp | |
95 | cpi zl,low(RAMEND+1) | |
96 | cpc zh,temp2 | |
97 | brne fill_loop | |
98 | ||
99 | ; Init clock/timer system | |
100 | ||
101 | ; Init timer 1 as 1 ms system clock tick. | |
102 | ||
103 | ldi temp, low (F_CPU/1000) | |
104 | ldi temp2,high(F_CPU/1000) | |
105 | outm8 OCR1BH,temp2 | |
106 | outm8 OCR1BL,temp | |
107 | ldi temp,(1<<ICNC1)|(1<<CS10) ;Noise cancel, fall. edge, Normal Mode, clk/1 | |
108 | outm8 TCCR1B,temp | |
109 | inm8 temp,TIMSK1 | |
110 | ori temp,(1<<OCIE1B) ;Enable 1ms int. | |
111 | outm8 TIMSK1,temp | |
112 | ||
113 | ; - Init serial port | |
114 | ||
115 | rcall uart_init | |
116 | ||
117 | ;Init timer2. Refresh-call should happen every (8ms/512) cycles. | |
118 | ||
119 | ldi temp,REFR_CNT*2 ; 2 cycles per int | |
120 | outm8 OCR2A,temp | |
121 | inm8 temp,TCCR2A | |
122 | ori temp,(1<<WGM21) ;CTC mode | |
123 | outm8 TCCR2A,temp | |
124 | inm8 temp,TCCR2B | |
125 | ori temp,REFR_CS ;clk/REFR_PRE | |
126 | outm8 TCCR2B,temp | |
127 | inm8 temp,TIMSK2 | |
128 | ori temp, (1<<OCIE2A) | |
129 | outm8 TIMSK2,temp | |
130 | ||
131 | sei | |
132 | ||
133 | #if I2C_SUPPORT | |
134 | rcall i2c_init ; Init I2C master | |
135 | rcall rtc_get | |
136 | #endif | |
137 | ||
138 | ||
139 | .if BOOTWAIT | |
140 | ldi temp,10 | |
141 | rcall delay_ms | |
142 | ||
143 | .endif | |
144 | ||
145 | rcall printstr | |
146 | .db 13,13,"CPM on an AVR, v" | |
147 | db_version VMAJOR, VMINOR | |
148 | printstring " r" SVN_REVSTR " " TESTSTR | |
149 | ||
150 | .if MEMTEST | |
151 | printnewline | |
152 | printstring "Testing RAM: fill..." | |
153 | ||
154 | ;Fill RAM | |
155 | ldiw x,0 | |
156 | ramtestw: | |
157 | mov temp,xh | |
158 | eor temp,xl | |
159 | rcall dram_write_pp | |
160 | brcc ramtestw | |
161 | printstring "wait..." | |
162 | ||
163 | ldi temp2,8 | |
164 | ramtestwl: | |
165 | ldi temp,255 | |
166 | rcall delay_ms | |
167 | dec temp2 | |
168 | brne ramtestwl | |
169 | ||
170 | printstring "reread..." | |
171 | ||
172 | ;re-read RAM | |
173 | ldiw x,0 | |
174 | clr temp3 ;Error counter | |
175 | ramtestr: | |
176 | rcall dram_read | |
177 | ||
178 | ; ori temp,0x04 ;simulate error | |
179 | ; andi temp,0xF7 | |
180 | ||
181 | mov temp2,xh | |
182 | eor temp2,xl | |
183 | cp temp,temp2 | |
184 | breq ramtestrok | |
185 | tst temp3 | |
186 | brne ramtestr1 | |
187 | printnewline | |
188 | printstring "Addr xx yy " | |
189 | ramtestr1: | |
190 | printnewline | |
191 | mov zl,temp | |
192 | movw temp,x | |
193 | rcall printhexw | |
194 | rcall printspace | |
195 | mov temp,xh | |
196 | eor temp,xl | |
197 | mov temp2,temp | |
198 | rcall printhex | |
199 | rcall printspace | |
200 | mov temp,zl | |
201 | rcall printhex | |
202 | rcall printspace | |
203 | mov temp,temp2 | |
204 | eor temp,zl | |
205 | and temp,temp2 | |
206 | rcall printxbits | |
207 | rcall printspace | |
208 | mov temp,temp2 | |
209 | eor temp,zl | |
210 | com temp2 | |
211 | and temp,temp2 | |
212 | rcall printxbits | |
213 | ||
214 | inc temp3 | |
215 | cpi temp3,16 ; | |
216 | brsh ramtestrex | |
217 | ramtestrok: | |
218 | adiw xl,1 | |
219 | brcc ramtestr | |
220 | ramtestrex: | |
221 | tst temp3 ;any errors? | |
222 | breq ramtestend | |
223 | ||
224 | printstring " System halted!" | |
225 | halted_loop: | |
226 | rjmp halted_loop ;keep AVR in an endless loop | |
227 | ||
228 | printxbits: | |
229 | push temp2 | |
230 | push temp3 | |
231 | mov temp2,temp | |
232 | ldi temp3,8 | |
233 | prntxb0: | |
234 | ldi temp,'-' | |
235 | lsl temp2 | |
236 | brcc prntxb1 | |
237 | ldi temp,'X' | |
238 | prntxb1: | |
239 | rcall uartPutc | |
240 | dec temp3 | |
241 | brne prntxb0 | |
242 | pop temp3 | |
243 | pop temp2 | |
244 | ret | |
245 | ||
246 | ramtestend: | |
247 | ||
248 | .endif | |
249 | ||
250 | .if MEMFILL | |
251 | ldiw x,0 | |
252 | ldi temp,MEMFILL_VAL | |
253 | ramfillw: | |
254 | rcall dram_write_pp | |
255 | brcc ramfillw | |
256 | .endif | |
257 | ||
258 | ||
259 | ;---------------------------------------------------------------------------- | |
260 | ||
261 | boot_again: | |
262 | printnewline | |
263 | printstring "Initing mmc..." | |
264 | printnewline | |
265 | lcall mgr_init_partitions | |
266 | ||
267 | cbr temp,0x80 | |
268 | brne boot_ipl2 | |
269 | printstring "No bootable CP/M disk found! Please change MMC/SD-Card." | |
270 | printnewline | |
271 | ldi temp2,18 | |
272 | boot_iplwl: | |
273 | ldi temp,255 | |
274 | rcall delay_ms | |
275 | dec temp2 | |
276 | brne boot_iplwl | |
277 | rjmp boot_again | |
278 | ||
279 | ||
280 | boot_ipl2: | |
281 | lcall mgr_prnt_parttbl | |
282 | printnewline | |
283 | printstring "Partinit done." | |
284 | ||
285 | ; Init (de)blocking buffer | |
286 | ||
287 | lcall dsk_inval_hostbuf | |
288 | ||
289 | ; Read first sector of first CP/M partition (ipl) | |
290 | ||
291 | ldiw y,fsys_vars | |
292 | ||
293 | ; Disk 0 | |
294 | std y+o_seekdsk,_0 | |
295 | ; Track 0 | |
296 | std y+o_seektrk, _0 | |
297 | std y+o_seektrk+1,_0 | |
298 | ; Sector 0 | |
299 | std y+o_seeksec,_0 | |
300 | ||
301 | ; Destination | |
302 | ldiw x,IPLADDR | |
303 | std y+o_dmaadr+0,xl | |
304 | std y+o_dmaadr+1,xh | |
305 | ||
306 | ldi temp,1<<READ_FUNC | |
307 | lcall dskDoIt | |
308 | ||
309 | ; lift off | |
310 | ljmp z80_init | |
311 | ||
312 | ||
313 | ; vim:set ts=8 noet nowrap | |
314 |