]> cloudbase.mooo.com Git - avrcpm.git/blame - avr/init.asm
* cpm/ipl.mac
[avrcpm.git] / avr / init.asm
CommitLineData
9c15f366 1; Various functions: init, (RAM) disk, mmc, timer
9c15f366
L
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
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
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)
82clr_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
b741422e 126 rcall delay_ms
9c15f366
L
127
128.endif
129
130 rcall printstr
131 .db 13,13,"CPM on an AVR, v"
132 db_version VMAJOR, VMINOR
133
134.if MEMTEST
135 printnewline
136 printstring "Testing RAM: fill..."
137
138;Fill RAM
139 ldiw x,0
140ramtestw:
141 mov temp,xh
142 eor temp,xl
4675c141 143 rcall dram_write_pp
9c15f366
L
144 brcc ramtestw
145 printstring "wait..."
146
147 ldi temp2,8
148ramtestwl:
149 ldi temp,255
b741422e 150 rcall delay_ms
9c15f366
L
151 dec temp2
152 brne ramtestwl
153
154 printstring "reread..."
155
156;re-read RAM
157 ldiw x,0
158 clr temp3
159ramtestr:
160 mem_read
161 mov temp2,xh
162 eor temp2,xl
163 cp temp,temp2
164 breq ramtestrok
165 push temp
166 cpi temp3,0 ;if first error
167 brne ramtest2
168 inc temp3
169 ldi temp,10 ;newline
170 rcall uartPutc
171ramtest2:
172 ldi temp,13 ;return
173 rcall uartPutc
174 pop temp
175 rcall printhex
176 ldi temp,'<'
177 rcall uartPutc
178 mov temp,xh
179 eor temp,xl
180 rcall printhex
181 ldi temp,'@'
182 rcall uartPutc
183 movw temp,x
184 rcall printhexw
185ramtestrok:
186 adiw xl,1
187 brcc ramtestr
188
189.endif
190
191.if MEMFILL
192 ldiw x,0
193ramfillw:
194 ldi temp,MEMFILL_VAL
4675c141 195 rcall dram_write_pp
9c15f366
L
196 brcc ramfillw
197.endif
198
199
200;----------------------------------------------------------------------------
201
202boot_again:
203 printnewline
dd7aea8c 204 printstring "Initing mmc..."
64219415 205 printnewline
b741422e 206 lcall mgr_init_partitions
9c15f366
L
207
208 cbr temp,0x80
209 brne boot_ipl2
210 printstring "No bootable CP/M disk found! Please change MMC/SD-Card."
64219415 211 printnewline
9c15f366
L
212 ldi temp2,18
213boot_iplwl:
214 ldi temp,255
215 rcall delay_ms
216 dec temp2
217 brne boot_iplwl
218 rjmp boot_again
219
220
221boot_ipl2:
b741422e 222 lcall mgr_prnt_parttbl
9c15f366
L
223 printnewline
224 printstring "Partinit done."
dd7aea8c 225
dd7aea8c 226 lcall dsk_inval_hostbuf ;init (de)blocking buffer
678fc0b0 227
4675c141 228; Read first sector of first CP/M partition (ipl)
9c15f366 229
92202636
L
230; Disk 0
231 sts seekdsk,_0
232; Track 0
233 sts seektrk,_0
234 sts seektrk+1,_0
235; Sector 0
236 sts seeksec,_0
237
dd7aea8c
L
238; Destination
239 ldiw x,IPLADDR
240 stsw dmaadr,x
241
242 lcall dsk_read
9c15f366 243
dd7aea8c 244; lift off
b741422e 245 ljmp z80_init
9c15f366
L
246
247