]> cloudbase.mooo.com Git - avrcpm.git/blobdiff - avr/init.asm
Remove unsupported experimental ADC support
[avrcpm.git] / avr / init.asm
index 37b5a2209681252b92c8a0104d125abd6260d893..dcc945992e0a75553d25c80689a89832bf49d547 100644 (file)
@@ -1,7 +1,7 @@
 ;    Hardware initialisation, disk, mmc, timer, DRAM test
 ;
 ;    Copyright (C) 2010 Sprite_tm
-;    Copyright (C) 2010 Leo C.
+;    Copyright (C) 2010-2013 Leo C.
 ;
 ;    This file is part of avrcpm.
 ;
@@ -18,7 +18,7 @@
 ;    You should have received a copy of the GNU General Public License
 ;    along with avrcpm.  If not, see <http://www.gnu.org/licenses/>.
 ;
-;    $Id$
+;    $Id: init.asm 241 2015-12-10 09:38:25Z rapid $
 ;
 
 #define REFR_PRE    8           /* timer prescale factor  1/8 */
@@ -34,7 +34,8 @@ regval_tab:
 regval_tab_e:
 
 start:
-       ldi temp,low(RAMEND)    ; top of memory
+       ldi temp,low(RAMEND)    ; top of memory; vim:set ts=8 noet nowrap
+
        out SPL,temp            ; init stack pointer
        ldi temp,high(RAMEND)   ; top of memory
        out SPH,temp            ; init stack pointer
@@ -57,18 +58,23 @@ cp_l:       lpm     xh,z+
        outm8   WDTCSR,temp
        ldi temp,(1<<WDCE)
        outm8   WDTCSR,temp
-       
+
 ; - Setup Ports
 
-       ldi     temp,(1<<PUD)           ;disable pullups
-       outm8   P_PUD,temp
-       out     PORTD,_255              ;all pins high
+;      ldi     temp,(1<<PUD)           ;disable pullups
+;      outm8   P_PUD,temp
+       out     PORTD,_255              ;all pins high (enables pullup on input ports)
        out     PORTB,_255
        out     PORTC,_255
-       out     DDRD,_255               ; all outputs
-       out     DDRB,_255
-       out     DDRC,_255
-       cbi     P_RXD-1,RXD             ; RXD pin is input
+       out     DDRD,_255               ; PD all outputs
+#if I2C_SUPPORT
+       ldi     temp,~((1<<SCL)|(1<<SDA))
+       out     DDRC,temp
+#endif
+#if DRAM_8BIT
+       ldi     temp,~(1<<RXD)
+       out     DDRB,temp
+#endif
 
        outm8   TIMSK1,_0
        outm8   TIMSK2,_0
@@ -79,18 +85,28 @@ cp_l:       lpm     xh,z+
 
        ldiw    z,SRAM_START
        ldi     temp2,high(ramtop)
-clr_l:
+clr_loop:
        st      z+,_0
        cpi     zl,low(ramtop)
        cpc     zh,temp2
-       brne    clr_l
+       brne    clr_loop
+
+; - Fill unused RAM (stack)
+
+       ldi     temp2,high(RAMEND+1)
+       ldi     temp,SRAMFILL_VAL
+fill_loop:
+       st      z+,temp
+       cpi     zl,low(RAMEND+1)
+       cpc     zh,temp2
+       brne    fill_loop
 
 ; Init clock/timer system
 
 ; Init timer 1 as 1 ms system clock tick.
 
-       ldi     temp, low (F_CPU/1000)
-       ldi     temp2,high(F_CPU/1000)
+       ldi     temp, low (TC_1MS)
+       ldi     temp2,high(TC_1MS)
        outm8   OCR1BH,temp2
        outm8   OCR1BL,temp
        ldi     temp,(1<<ICNC1)|(1<<CS10)       ;Noise cancel, fall. edge, Normal Mode, clk/1
@@ -102,8 +118,8 @@ clr_l:
 ; - Init serial port
 
        rcall   uart_init
-       
-;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
+
+;Init timer2. Refresh-call should happen every (8ms/512) cycles.
 
        ldi     temp,REFR_CNT*2                 ; 2 cycles per int
        outm8   OCR2A,temp
@@ -119,7 +135,7 @@ clr_l:
 
        sei
 
-#if I2C
+#if I2C_SUPPORT
        rcall   i2c_init                        ; Init I2C master
        rcall   rtc_get
 #endif
@@ -132,10 +148,10 @@ clr_l:
 .endif
 
        rcall   printstr
-       .db     13,13,"CPM on an AVR, v"
-       db_version VMAJOR, VMINOR
-       printstring " r" SVN_REVSTR
-               
+       .db     '\r', '\r'
+version_string:
+       makestring "CPM on an AVR, v" VERS_STR " r" SVN_REVSTR TESTSTR
+
 .if MEMTEST
        printnewline
        printstring "Testing RAM: fill..."
@@ -162,10 +178,10 @@ ramtestwl:
        ldiw    x,0
        clr     temp3                   ;Error counter
 ramtestr:
-       mem_read
+       rcall   dram_read
 
 ;      ori     temp,0x04               ;simulate error
-;      andi    temp,0xF7
+;      andi    temp,0xF7               ;another error
 
        mov     temp2,xh
        eor     temp2,xl
@@ -177,7 +193,7 @@ ramtestr:
        printstring "Addr xx yy "
 ramtestr1:
        printnewline
-       mov     temp4,temp
+       mov     zl,temp
        movw    temp,x
        rcall   printhexw
        rcall   printspace
@@ -186,16 +202,16 @@ ramtestr1:
        mov     temp2,temp
        rcall   printhex
        rcall   printspace
-       mov     temp,temp4
+       mov     temp,zl
        rcall   printhex
        rcall   printspace
        mov     temp,temp2
-       eor     temp,temp4
+       eor     temp,zl
        and     temp,temp2
        rcall   printxbits
        rcall   printspace
        mov     temp,temp2
-       eor     temp,temp4
+       eor     temp,zl
        com     temp2
        and     temp,temp2
        rcall   printxbits
@@ -208,20 +224,38 @@ ramtestrok:
        brcc    ramtestr
 ramtestrex:
        tst     temp3                   ;any errors?
-       breq    ramtestend      
+       breq    ramtestend
 
        printstring " System halted!"
 halted_loop:
        rjmp    halted_loop             ;keep AVR in an endless loop
 
+printxbits:
+       push    temp2
+       push    temp3
+       mov     temp2,temp
+       ldi     temp3,8
+prntxb0:
+       ldi     temp,'-'
+       lsl     temp2
+       brcc    prntxb1
+       ldi     temp,'X'
+prntxb1:
+       rcall   uartPutc
+       dec     temp3
+       brne    prntxb0
+       pop     temp3
+       pop     temp2
+       ret
+
 ramtestend:
 
 .endif
 
 .if MEMFILL
        ldiw    x,0
+       ldi     temp,MEMFILL_VAL
 ramfillw:
-       ldi temp,MEMFILL_VAL
        rcall   dram_write_pp
        brcc ramfillw
 .endif
@@ -246,60 +280,39 @@ boot_iplwl:
        dec     temp2
        brne    boot_iplwl
        rjmp    boot_again
-       
+
 
 boot_ipl2:
        lcall   mgr_prnt_parttbl
        printnewline
        printstring "Partinit done."
-       
-       lcall   dsk_inval_hostbuf       ;init (de)blocking buffer
+
+; Init (de)blocking buffer
+
+       lcall   dsk_inval_hostbuf
 
 ; Read first sector of first CP/M partition (ipl)
 
+       ldiw    y,fsys_vars
+
 ;      Disk 0
-       sts     seekdsk,_0
+       std     y+o_seekdsk,_0
 ;      Track 0
-       sts     seektrk,_0
-       sts     seektrk+1,_0
+       std     y+o_seektrk,  _0
+       std     y+o_seektrk+1,_0
 ;      Sector 0
-       sts     seeksec,_0
+       std     y+o_seeksec,_0
 
 ;      Destination
        ldiw    x,IPLADDR
-       stsw    dmaadr,x
-       
-       lcall   dsk_read
+       std     y+o_dmaadr+0,xl
+       std     y+o_dmaadr+1,xh
+
+       ldi     temp,1<<READ_FUNC
+       lcall   dskDoIt
 
 ;      lift off
        ljmp z80_init
 
 
-printspace:
-       push    temp
-       ldi     temp,' '
-       rcall   uartputc
-       pop     temp
-       ret
-
-printxbits:
-       push    temp2
-       push    temp3
-       mov     temp2,temp
-       ldi     temp3,8
-prntxb0:
-       ldi     temp,'-'
-       lsl     temp2
-       brcc    prntxb1
-       ldi     temp,'X'
-prntxb1:
-       rcall   uartPutc
-       dec     temp3
-       brne    prntxb0
-       pop     temp3
-       pop     temp2
-       ret
-
-
-
-
+; vim:set ts=8 noet nowrap