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