]>
Commit | Line | Data |
---|---|---|
1 | ; Various functions: init, (RAM) disk, mmc, timer | |
2 | ; | |
3 | ; Copyright (C) 2010 Sprite_tm | |
4 | ; Copyright (C) 2010 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 | |
38 | out SPL,temp ; init stack pointer | |
39 | ldi temp,high(RAMEND) ; top of memory | |
40 | out SPH,temp ; init stack pointer | |
41 | ||
42 | ; - Load some registers with constant values | |
43 | ||
44 | ldiw z,regval_tab*2 | |
45 | ldiw y,0 | |
46 | cp_l: lpm xh,z+ | |
47 | st y+,xh | |
48 | cpi zl,low(regval_tab_e*2) | |
49 | brne cp_l | |
50 | ||
51 | ; - Kill wdt | |
52 | ||
53 | wdr | |
54 | out MCUSR,_0 | |
55 | ||
56 | ldi temp,(1<<WDCE) | (1<<WDE) | |
57 | outm8 WDTCSR,temp | |
58 | ldi temp,(1<<WDCE) | |
59 | outm8 WDTCSR,temp | |
60 | ||
61 | ; - Setup Ports | |
62 | ||
63 | ldi temp,(1<<PUD) ;disable pullups | |
64 | outm8 P_PUD,temp | |
65 | out PORTD,_255 ;all pins high | |
66 | out PORTB,_255 | |
67 | out PORTC,_255 | |
68 | out DDRD,_255 ; all outputs | |
69 | out DDRB,_255 | |
70 | out DDRC,_255 | |
71 | cbi P_RXD-1,RXD ; RXD pin is input | |
72 | ||
73 | outm8 TIMSK1,_0 | |
74 | outm8 TIMSK2,_0 | |
75 | outm8 TCCR2A,_0 | |
76 | outm8 TCCR2B,_0 | |
77 | ||
78 | ; - Clear RAM | |
79 | ||
80 | ldiw z,SRAM_START | |
81 | ldi temp2,high(ramtop) | |
82 | clr_l: | |
83 | st z+,_0 | |
84 | cpi zl,low(ramtop) | |
85 | cpc zh,temp2 | |
86 | brne clr_l | |
87 | ||
88 | ||
89 | ; Init clock/timer system | |
90 | ||
91 | ; Init timer 1 as 1 ms system clock tick. | |
92 | ||
93 | ldi temp, low (F_CPU/1000) | |
94 | ldi temp2,high(F_CPU/1000) | |
95 | outm8 OCR1BH,temp2 | |
96 | outm8 OCR1BL,temp | |
97 | ldi temp,(1<<ICNC1)|(1<<CS10) ;Noise cancel, fall. edge, Normal Mode, clk/1 | |
98 | outm8 TCCR1B,temp | |
99 | inm8 temp,TIMSK1 | |
100 | ori temp,(1<<OCIE1B) ;Enable 1ms int. | |
101 | outm8 TIMSK1,temp | |
102 | ||
103 | ; - Init serial port | |
104 | ||
105 | rcall uart_init | |
106 | ||
107 | ;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles. | |
108 | ||
109 | ldi temp,REFR_CNT*2 ; 2 cycles per int | |
110 | outm8 OCR2A,temp | |
111 | inm8 temp,TCCR2A | |
112 | ori temp,(1<<WGM21) ;CTC mode | |
113 | outm8 TCCR2A,temp | |
114 | inm8 temp,TCCR2B | |
115 | ori temp,REFR_CS ;clk/REFR_PRE | |
116 | outm8 TCCR2B,temp | |
117 | inm8 temp,TIMSK2 | |
118 | ori temp, (1<<OCIE2A) | |
119 | outm8 TIMSK2,temp | |
120 | ||
121 | sei | |
122 | ||
123 | ||
124 | .if BOOTWAIT | |
125 | ldi temp,10 | |
126 | rcall delay_ms | |
127 | ||
128 | .endif | |
129 | ||
130 | rcall printstr | |
131 | .db 13,13,"CPM on an AVR, v" | |
132 | db_version VMAJOR, VMINOR | |
133 | printstring " r" SVN_REVSTR | |
134 | ||
135 | .if MEMTEST | |
136 | printnewline | |
137 | printstring "Testing RAM: fill..." | |
138 | ||
139 | ;Fill RAM | |
140 | ldiw x,0 | |
141 | ramtestw: | |
142 | mov temp,xh | |
143 | eor temp,xl | |
144 | rcall dram_write_pp | |
145 | brcc ramtestw | |
146 | printstring "wait..." | |
147 | ||
148 | ldi temp2,8 | |
149 | ramtestwl: | |
150 | ldi temp,255 | |
151 | rcall delay_ms | |
152 | dec temp2 | |
153 | brne ramtestwl | |
154 | ||
155 | printstring "reread..." | |
156 | ||
157 | ;re-read RAM | |
158 | ldiw x,0 | |
159 | clr temp3 ;Error counter | |
160 | ramtestr: | |
161 | mem_read | |
162 | ||
163 | ; ori temp,0x04 ;simulate error | |
164 | ; andi temp,0xF7 | |
165 | ||
166 | mov temp2,xh | |
167 | eor temp2,xl | |
168 | cp temp,temp2 | |
169 | breq ramtestrok | |
170 | tst temp3 | |
171 | brne ramtestr1 | |
172 | printnewline | |
173 | printstring "Addr xx yy " | |
174 | ramtestr1: | |
175 | printnewline | |
176 | mov temp4,temp | |
177 | movw temp,x | |
178 | rcall printhexw | |
179 | rcall printspace | |
180 | mov temp,xh | |
181 | eor temp,xl | |
182 | mov temp2,temp | |
183 | rcall printhex | |
184 | rcall printspace | |
185 | mov temp,temp4 | |
186 | rcall printhex | |
187 | rcall printspace | |
188 | mov temp,temp2 | |
189 | eor temp,temp4 | |
190 | and temp,temp2 | |
191 | rcall printxbits | |
192 | rcall printspace | |
193 | mov temp,temp2 | |
194 | eor temp,temp4 | |
195 | com temp2 | |
196 | and temp,temp2 | |
197 | rcall printxbits | |
198 | ||
199 | inc temp3 | |
200 | cpi temp3,16 ; | |
201 | brsh ramtestrex | |
202 | ramtestrok: | |
203 | adiw xl,1 | |
204 | brcc ramtestr | |
205 | ramtestrex: | |
206 | tst temp3 ;any errors? | |
207 | breq ramtestend | |
208 | ||
209 | printstring " System halted!" | |
210 | halted_loop: | |
211 | rjmp halted_loop ;keep AVR in an endless loop | |
212 | ||
213 | ramtestend: | |
214 | ||
215 | .endif | |
216 | ||
217 | .if MEMFILL | |
218 | ldiw x,0 | |
219 | ramfillw: | |
220 | ldi temp,MEMFILL_VAL | |
221 | rcall dram_write_pp | |
222 | brcc ramfillw | |
223 | .endif | |
224 | ||
225 | ||
226 | ;---------------------------------------------------------------------------- | |
227 | ||
228 | boot_again: | |
229 | printnewline | |
230 | printstring "Initing mmc..." | |
231 | printnewline | |
232 | lcall mgr_init_partitions | |
233 | ||
234 | cbr temp,0x80 | |
235 | brne boot_ipl2 | |
236 | printstring "No bootable CP/M disk found! Please change MMC/SD-Card." | |
237 | printnewline | |
238 | ldi temp2,18 | |
239 | boot_iplwl: | |
240 | ldi temp,255 | |
241 | rcall delay_ms | |
242 | dec temp2 | |
243 | brne boot_iplwl | |
244 | rjmp boot_again | |
245 | ||
246 | ||
247 | boot_ipl2: | |
248 | lcall mgr_prnt_parttbl | |
249 | printnewline | |
250 | printstring "Partinit done." | |
251 | ||
252 | lcall dsk_inval_hostbuf ;init (de)blocking buffer | |
253 | ||
254 | ; Read first sector of first CP/M partition (ipl) | |
255 | ||
256 | ; Disk 0 | |
257 | sts seekdsk,_0 | |
258 | ; Track 0 | |
259 | sts seektrk,_0 | |
260 | sts seektrk+1,_0 | |
261 | ; Sector 0 | |
262 | sts seeksec,_0 | |
263 | ||
264 | ; Destination | |
265 | ldiw x,IPLADDR | |
266 | stsw dmaadr,x | |
267 | ||
268 | lcall dsk_read | |
269 | ||
270 | ; lift off | |
271 | ljmp z80_init | |
272 | ||
273 | ||
274 | printspace: | |
275 | push temp | |
276 | ldi temp,' ' | |
277 | rcall uartputc | |
278 | pop temp | |
279 | ret | |
280 | ||
281 | printxbits: | |
282 | push temp2 | |
283 | push temp3 | |
284 | mov temp2,temp | |
285 | ldi temp3,8 | |
286 | prntxb0: | |
287 | ldi temp,'-' | |
288 | lsl temp2 | |
289 | brcc prntxb1 | |
290 | ldi temp,'X' | |
291 | prntxb1: | |
292 | rcall uartPutc | |
293 | dec temp3 | |
294 | brne prntxb0 | |
295 | pop temp3 | |
296 | pop temp2 | |
297 | ret | |
298 | ||
299 | ||
300 | ||
301 |