]> cloudbase.mooo.com Git - avrcpm.git/blame - avr/init.asm
* avr/dsk_fsys.asm
[avrcpm.git] / avr / init.asm
CommitLineData
6efd6291 1; Hardware initialisation, disk, mmc, timer, DRAM test
9c15f366
L
2;
3; Copyright (C) 2010 Sprite_tm
dc705dc0 4; Copyright (C) 2010-2013 Leo C.
9c15f366
L
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
29regval_tab:
30 .db 0,0
31 .db 0xFE,0xFC ; _RAS0 _CAS0
32 .db 0xF8,0xF4 ; _OE _WE
33 .db 255,0 ; _255 _0
34regval_tab_e:
35
36start:
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
46cp_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
825ecc9d
L
63; ldi temp,(1<<PUD) ;disable pullups
64; outm8 P_PUD,temp
65 out PORTD,_255 ;all pins high (enables pullup on input ports)
9c15f366
L
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)
82clr_l:
83 st z+,_0
84 cpi zl,low(ramtop)
85 cpc zh,temp2
86 brne clr_l
87
9c15f366
L
88; Init clock/timer system
89
90; Init timer 1 as 1 ms system clock tick.
91
92 ldi temp, low (F_CPU/1000)
93 ldi temp2,high(F_CPU/1000)
94 outm8 OCR1BH,temp2
95 outm8 OCR1BL,temp
96 ldi temp,(1<<ICNC1)|(1<<CS10) ;Noise cancel, fall. edge, Normal Mode, clk/1
97 outm8 TCCR1B,temp
98 inm8 temp,TIMSK1
99 ori temp,(1<<OCIE1B) ;Enable 1ms int.
100 outm8 TIMSK1,temp
101
102; - Init serial port
103
104 rcall uart_init
105
825ecc9d 106;Init timer2. Refresh-call should happen every (8ms/512) cycles.
9c15f366
L
107
108 ldi temp,REFR_CNT*2 ; 2 cycles per int
109 outm8 OCR2A,temp
110 inm8 temp,TCCR2A
111 ori temp,(1<<WGM21) ;CTC mode
112 outm8 TCCR2A,temp
113 inm8 temp,TCCR2B
114 ori temp,REFR_CS ;clk/REFR_PRE
115 outm8 TCCR2B,temp
116 inm8 temp,TIMSK2
117 ori temp, (1<<OCIE2A)
118 outm8 TIMSK2,temp
119
120 sei
121
dc705dc0 122#if I2C_SUPPORT
d8fa6a36
L
123 rcall i2c_init ; Init I2C master
124 rcall rtc_get
125#endif
126
9c15f366
L
127
128.if BOOTWAIT
129 ldi temp,10
b741422e 130 rcall delay_ms
9c15f366
L
131
132.endif
133
134 rcall printstr
135 .db 13,13,"CPM on an AVR, v"
136 db_version VMAJOR, VMINOR
5c8bb361 137 printstring " r" SVN_REVSTR " " TESTSTR
9c15f366
L
138
139.if MEMTEST
140 printnewline
141 printstring "Testing RAM: fill..."
142
143;Fill RAM
144 ldiw x,0
145ramtestw:
146 mov temp,xh
147 eor temp,xl
4675c141 148 rcall dram_write_pp
9c15f366
L
149 brcc ramtestw
150 printstring "wait..."
151
152 ldi temp2,8
153ramtestwl:
154 ldi temp,255
b741422e 155 rcall delay_ms
9c15f366
L
156 dec temp2
157 brne ramtestwl
158
159 printstring "reread..."
160
161;re-read RAM
162 ldiw x,0
fa9059af 163 clr temp3 ;Error counter
9c15f366
L
164ramtestr:
165 mem_read
fa9059af
L
166
167; ori temp,0x04 ;simulate error
168; andi temp,0xF7
169
9c15f366
L
170 mov temp2,xh
171 eor temp2,xl
172 cp temp,temp2
173 breq ramtestrok
fa9059af
L
174 tst temp3
175 brne ramtestr1
176 printnewline
177 printstring "Addr xx yy "
178ramtestr1:
179 printnewline
825ecc9d 180 mov zl,temp
fa9059af
L
181 movw temp,x
182 rcall printhexw
183 rcall printspace
9c15f366
L
184 mov temp,xh
185 eor temp,xl
fa9059af 186 mov temp2,temp
9c15f366 187 rcall printhex
fa9059af 188 rcall printspace
825ecc9d 189 mov temp,zl
fa9059af
L
190 rcall printhex
191 rcall printspace
192 mov temp,temp2
825ecc9d 193 eor temp,zl
fa9059af
L
194 and temp,temp2
195 rcall printxbits
196 rcall printspace
197 mov temp,temp2
825ecc9d 198 eor temp,zl
fa9059af
L
199 com temp2
200 and temp,temp2
201 rcall printxbits
202
203 inc temp3
204 cpi temp3,16 ;
205 brsh ramtestrex
9c15f366
L
206ramtestrok:
207 adiw xl,1
208 brcc ramtestr
fa9059af
L
209ramtestrex:
210 tst temp3 ;any errors?
211 breq ramtestend
212
213 printstring " System halted!"
214halted_loop:
215 rjmp halted_loop ;keep AVR in an endless loop
216
217ramtestend:
9c15f366
L
218
219.endif
220
221.if MEMFILL
222 ldiw x,0
223ramfillw:
224 ldi temp,MEMFILL_VAL
4675c141 225 rcall dram_write_pp
9c15f366
L
226 brcc ramfillw
227.endif
228
229
230;----------------------------------------------------------------------------
231
232boot_again:
233 printnewline
dd7aea8c 234 printstring "Initing mmc..."
64219415 235 printnewline
b741422e 236 lcall mgr_init_partitions
9c15f366
L
237
238 cbr temp,0x80
239 brne boot_ipl2
240 printstring "No bootable CP/M disk found! Please change MMC/SD-Card."
64219415 241 printnewline
9c15f366
L
242 ldi temp2,18
243boot_iplwl:
244 ldi temp,255
245 rcall delay_ms
246 dec temp2
247 brne boot_iplwl
248 rjmp boot_again
249
250
251boot_ipl2:
b741422e 252 lcall mgr_prnt_parttbl
9c15f366
L
253 printnewline
254 printstring "Partinit done."
dd7aea8c 255
2ccaac16
L
256; Init (de)blocking buffer
257
258 lcall dsk_inval_hostbuf
678fc0b0 259
4675c141 260; Read first sector of first CP/M partition (ipl)
9c15f366 261
92202636
L
262; Disk 0
263 sts seekdsk,_0
264; Track 0
265 sts seektrk,_0
266 sts seektrk+1,_0
267; Sector 0
268 sts seeksec,_0
269
dd7aea8c
L
270; Destination
271 ldiw x,IPLADDR
272 stsw dmaadr,x
273
2ccaac16
L
274 ldi temp,1<<READ_FUNC
275 lcall dskDoIt
9c15f366 276
dd7aea8c 277; lift off
b741422e 278 ljmp z80_init
9c15f366
L
279
280
fa9059af
L
281printspace:
282 push temp
283 ldi temp,' '
284 rcall uartputc
285 pop temp
286 ret
287
288printxbits:
289 push temp2
290 push temp3
291 mov temp2,temp
292 ldi temp3,8
293prntxb0:
294 ldi temp,'-'
295 lsl temp2
296 brcc prntxb1
297 ldi temp,'X'
298prntxb1:
299 rcall uartPutc
300 dec temp3
301 brne prntxb0
302 pop temp3
303 pop temp2
304 ret
305
306
307
308