1 ; Hardware initialisation, disk, mmc, timer, DRAM test
3 ; Copyright (C) 2010 Sprite_tm
4 ; Copyright (C) 2010-2013 Leo C.
6 ; This file is part of avrcpm.
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.
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.
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/>.
21 ; $Id: init.asm 241 2015-12-10 09:38:25Z rapid $
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
31 .db 0xFE,0xFC ; _RAS0 _CAS0
32 .db 0xF8,0xF4 ; _OE _WE
37 ldi temp,low(RAMEND) ; top of memory; vim:set ts=8 noet nowrap
39 out SPL,temp ; init stack pointer
40 ldi temp,high(RAMEND) ; top of memory
41 out SPH,temp ; init stack pointer
43 ; - Load some registers with constant values
49 cpi zl,low(regval_tab_e*2)
57 ldi temp,(1<<WDCE) | (1<<WDE)
64 ; ldi temp,(1<<PUD) ;disable pullups
66 out PORTD,_255 ;all pins high (enables pullup on input ports)
69 out DDRD,_255 ; PD all outputs
71 ldi temp,~((1<<SCL)|(1<<SDA))
87 ldi temp2,high(ramtop)
94 ; - Fill unused RAM (stack)
96 ldi temp2,high(RAMEND+1)
104 ; Init clock/timer system
106 ; Init timer 1 as 1 ms system clock tick.
108 ldi temp, low (TC_1MS)
109 ldi temp2,high(TC_1MS)
112 ldi temp,(1<<ICNC1)|(1<<CS10) ;Noise cancel, fall. edge, Normal Mode, clk/1
115 ori temp,(1<<OCIE1B) ;Enable 1ms int.
122 ;Init timer2. Refresh-call should happen every (8ms/512) cycles.
124 ldi temp,REFR_CNT*2 ; 2 cycles per int
127 ori temp,(1<<WGM21) ;CTC mode
130 ori temp,REFR_CS ;clk/REFR_PRE
133 ori temp, (1<<OCIE2A)
139 rcall i2c_init ; Init I2C master
153 makestring "CPM on an AVR, v" VERS_STR " r" SVN_REVSTR TESTSTR
157 printstring "Testing RAM: fill..."
166 printstring "wait..."
175 printstring "reread..."
179 clr temp3 ;Error counter
183 ; ori temp,0x04 ;simulate error
184 ; andi temp,0xF7 ;another error
193 printstring "Addr xx yy "
226 tst temp3 ;any errors?
229 printstring " System halted!"
231 rjmp halted_loop ;keep AVR in an endless loop
264 ;----------------------------------------------------------------------------
268 printstring "Initing mmc..."
270 lcall mgr_init_partitions
274 printstring "No bootable CP/M disk found! Please change MMC/SD-Card."
286 lcall mgr_prnt_parttbl
288 printstring "Partinit done."
290 ; Init (de)blocking buffer
292 lcall dsk_inval_hostbuf
294 ; Read first sector of first CP/M partition (ipl)
311 ldi temp,1<<READ_FUNC
318 ; vim:set ts=8 noet nowrap