2007-11-19 23:14:14 +00:00
|
|
|
;
|
|
|
|
; Copyright (c) 2007, Adam Dunkels and Oliver Schmidt
|
|
|
|
; All rights reserved.
|
|
|
|
;
|
|
|
|
; Redistribution and use in source and binary forms, with or without
|
|
|
|
; modification, are permitted provided that the following conditions
|
|
|
|
; are met:
|
|
|
|
; 1. Redistributions of source code must retain the above copyright
|
|
|
|
; notice, this list of conditions and the following disclaimer.
|
|
|
|
; 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
; notice, this list of conditions and the following disclaimer in the
|
|
|
|
; documentation and/or other materials provided with the distribution.
|
|
|
|
; 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
; may be used to endorse or promote products derived from this software
|
|
|
|
; without specific prior written permission.
|
|
|
|
;
|
|
|
|
; THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
; ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
; SUCH DAMAGE.
|
|
|
|
;
|
|
|
|
; This file is part of the Contiki operating system.
|
|
|
|
;
|
|
|
|
; Author: Adam Dunkels <adam@sics.se>, Oliver Schmidt <ol.sc@web.de>
|
|
|
|
;
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
2014-06-09 21:14:11 +00:00
|
|
|
.macpack module
|
|
|
|
module_header _cs8900a
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
.byte $65, $74, $68 ; "eth"
|
|
|
|
.byte $01 ; Ethernet driver API version number
|
2013-01-30 22:39:01 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Ethernet address
|
|
|
|
mac: .byte $00, $0E, $3A ; OUI of Cirrus Logic
|
|
|
|
.byte $11, $11, $11
|
|
|
|
|
|
|
|
; Buffer attributes
|
|
|
|
bufaddr:.res 2 ; Address
|
|
|
|
bufsize:.res 2 ; Size
|
|
|
|
|
|
|
|
; Jump table.
|
2014-06-12 20:56:35 +00:00
|
|
|
jmp init
|
|
|
|
jmp poll
|
|
|
|
jmp send
|
|
|
|
jmp exit
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
2014-06-09 21:14:11 +00:00
|
|
|
.if DYN_DRV
|
2007-11-19 23:14:14 +00:00
|
|
|
|
2014-06-09 21:14:11 +00:00
|
|
|
.zeropage
|
2013-11-09 22:15:20 +00:00
|
|
|
sp: .res 2 ; Stack pointer (Do not trash !)
|
2007-11-19 23:14:14 +00:00
|
|
|
reg: .res 2 ; Address of rxtxreg
|
|
|
|
ptr: .res 2 ; Indirect addressing pointer
|
|
|
|
len: .res 2 ; Frame length
|
|
|
|
cnt: .res 2 ; Frame length counter
|
|
|
|
|
2014-06-09 21:14:11 +00:00
|
|
|
.else
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
reg := ptr1 ; Address of rxtxreg
|
|
|
|
ptr := ptr2 ; Indirect addressing pointer
|
|
|
|
len := ptr3 ; Frame length
|
|
|
|
cnt := ptr4 ; Frame length counter
|
|
|
|
|
|
|
|
.endif
|
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
.rodata
|
2013-01-30 22:39:01 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
fixup: .byte fixup02-fixup01, fixup03-fixup02, fixup04-fixup03
|
|
|
|
.byte fixup05-fixup04, fixup06-fixup05, fixup07-fixup06
|
|
|
|
.byte fixup08-fixup07, fixup09-fixup08, fixup10-fixup09
|
|
|
|
.byte fixup11-fixup10, fixup12-fixup11, fixup13-fixup12
|
|
|
|
.byte fixup14-fixup13, fixup15-fixup14, fixup16-fixup15
|
|
|
|
.byte fixup17-fixup16, fixup18-fixup17, fixup19-fixup18
|
|
|
|
.byte fixup20-fixup19, fixup21-fixup20, fixup22-fixup21
|
2014-06-12 20:56:35 +00:00
|
|
|
.byte fixup23-fixup22, fixup24-fixup23, fixup25-fixup24
|
|
|
|
.byte fixup26-fixup25
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
fixups = * - fixup
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
rxtxreg := $FF00 ; High byte patched at runtime
|
|
|
|
txcmd := $FF04 ; High byte patched at runtime
|
|
|
|
txlen := $FF06 ; High byte patched at runtime
|
2007-12-08 21:05:48 +00:00
|
|
|
isq := $FF08 ; High byte patched at runtime
|
2007-11-19 23:14:14 +00:00
|
|
|
packetpp := $FF0A ; High byte patched at runtime
|
|
|
|
ppdata := $FF0C ; High byte patched at runtime
|
|
|
|
|
|
|
|
.data
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
init:
|
|
|
|
; Save address of rxtxreg
|
|
|
|
sta reg
|
|
|
|
stx reg+1
|
|
|
|
|
|
|
|
; Start with first fixup location
|
|
|
|
lda #<(fixup01+1)
|
|
|
|
ldx #>(fixup01+1)
|
|
|
|
sta ptr
|
|
|
|
stx ptr+1
|
|
|
|
ldx #$FF
|
|
|
|
ldy #$00
|
|
|
|
|
|
|
|
; Fixup address at location
|
|
|
|
: lda reg
|
2007-11-24 12:57:09 +00:00
|
|
|
eor (ptr),y ; Use XOR to support C64 RR-Net
|
2007-11-19 23:14:14 +00:00
|
|
|
sta (ptr),y
|
|
|
|
iny
|
|
|
|
lda reg+1
|
|
|
|
sta (ptr),y
|
|
|
|
dey
|
2013-11-13 22:32:49 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Advance to next fixup location
|
|
|
|
inx
|
|
|
|
cpx #fixups
|
|
|
|
bcs :+
|
|
|
|
lda ptr
|
|
|
|
clc
|
|
|
|
adc fixup,x
|
|
|
|
sta ptr
|
|
|
|
bcc :-
|
|
|
|
inc ptr+1
|
|
|
|
bcs :- ; Always
|
|
|
|
|
2007-12-08 21:19:06 +00:00
|
|
|
; Activate C64 RR clockport in order to operate RR-Net
|
2007-12-08 21:05:48 +00:00
|
|
|
; - RR config register overlays CS8900A ISQ register
|
|
|
|
; - No need to distinguish as ISQ access doesn't hurt
|
|
|
|
:
|
|
|
|
fixup01:lda isq+1
|
|
|
|
ora #$01 ; Set clockport bit
|
|
|
|
fixup02:sta isq+1
|
|
|
|
|
2014-06-12 20:56:35 +00:00
|
|
|
; Check EISA registration number of Crystal Semiconductor
|
|
|
|
; PACKETPP = $0000, PPDATA == $630E ?
|
|
|
|
lda #$00
|
|
|
|
tax
|
|
|
|
jsr packetpp_ax
|
|
|
|
lda #$63^$0E
|
|
|
|
fixup03:eor ppdata
|
|
|
|
fixup04:eor ppdata+1
|
|
|
|
beq :+
|
|
|
|
sec
|
|
|
|
rts
|
|
|
|
|
|
|
|
; Initiate a chip-wide reset
|
|
|
|
; PACKETPP = $0114, PPDATA = $0040
|
|
|
|
: lda #$14
|
|
|
|
jsr packetpp_a1
|
|
|
|
ldy #$40
|
|
|
|
fixup05:sty ppdata
|
|
|
|
: jsr packetpp_a1
|
|
|
|
fixup06:ldy ppdata
|
|
|
|
and #$40
|
|
|
|
bne :-
|
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Accept valid unicast + broadcast frames
|
|
|
|
; PACKETPP = $0104, PPDATA = $0D05
|
|
|
|
lda #$04
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr packetpp_a1
|
2007-11-19 23:14:14 +00:00
|
|
|
lda #$05
|
|
|
|
ldx #$0D
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr ppdata_ax
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
; Set MAC address
|
|
|
|
; PACKETPP = $0158, PPDATA = MAC[0], MAC[1]
|
|
|
|
; PACKETPP = $015A, PPDATA = MAC[2], MAC[3]
|
2013-09-11 18:48:23 +00:00
|
|
|
; PACKETPP = $015C, PPDATA = MAC[4], MAC[5]
|
|
|
|
ldy #$58
|
|
|
|
: tya
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr packetpp_a1
|
2013-09-11 18:48:23 +00:00
|
|
|
lda mac-$58,y
|
|
|
|
ldx mac-$58+1,y
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr ppdata_ax
|
2013-09-11 18:48:23 +00:00
|
|
|
iny
|
|
|
|
iny
|
|
|
|
cpy #$58+6
|
|
|
|
bcc :-
|
|
|
|
|
|
|
|
; Turn on transmission and reception of frames
|
|
|
|
; PACKETPP = $0112, PPDATA = $00D3
|
|
|
|
lda #$12
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr packetpp_a1
|
2013-09-11 18:48:23 +00:00
|
|
|
lda #$D3
|
|
|
|
ldx #$00
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr ppdata_ax
|
2014-06-12 20:56:35 +00:00
|
|
|
txa
|
|
|
|
clc
|
2007-11-19 23:14:14 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
poll:
|
|
|
|
; Check receiver event register to see if there
|
|
|
|
; are any valid unicast frames avaliable
|
|
|
|
; PACKETPP = $0124, PPDATA & $0D00 ?
|
|
|
|
lda #$24
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr packetpp_a1
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup07:lda ppdata+1
|
2007-11-19 23:14:14 +00:00
|
|
|
and #$0D
|
2014-06-12 20:56:35 +00:00
|
|
|
beq :+
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
; Process the incoming frame
|
|
|
|
; --------------------------
|
|
|
|
|
|
|
|
; Read receiver event and discard it
|
|
|
|
; RXTXREG
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup08:ldx rxtxreg+1
|
|
|
|
fixup09:lda rxtxreg
|
2013-11-13 22:32:49 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Read frame length
|
|
|
|
; cnt = len = RXTXREG
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup10:ldx rxtxreg+1
|
|
|
|
fixup11:lda rxtxreg
|
2007-11-19 23:14:14 +00:00
|
|
|
sta len
|
|
|
|
stx len+1
|
|
|
|
sta cnt
|
|
|
|
stx cnt+1
|
|
|
|
|
|
|
|
; Adjust odd frame length
|
2013-09-11 18:48:23 +00:00
|
|
|
jsr adjustcnt
|
2007-11-19 23:14:14 +00:00
|
|
|
|
2013-01-30 22:39:01 +00:00
|
|
|
; Is bufsize < cnt ?
|
|
|
|
lda bufsize
|
2013-10-03 20:32:12 +00:00
|
|
|
cmp cnt
|
2013-01-30 22:39:01 +00:00
|
|
|
lda bufsize+1
|
|
|
|
sbc cnt+1
|
2014-06-12 20:56:35 +00:00
|
|
|
bcs :++
|
2013-01-30 22:39:01 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Yes, skip frame
|
2013-09-11 18:48:23 +00:00
|
|
|
jsr skipframe
|
2013-01-30 22:39:01 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; No frame ready
|
|
|
|
lda #$00
|
2014-06-12 20:56:35 +00:00
|
|
|
: tax
|
|
|
|
sec
|
2007-11-19 23:14:14 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Read bytes into buffer
|
2013-09-11 18:48:23 +00:00
|
|
|
: jsr adjustptr
|
|
|
|
:
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup12:lda rxtxreg
|
2007-11-19 23:14:14 +00:00
|
|
|
sta (ptr),y
|
|
|
|
iny
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup13:lda rxtxreg+1
|
2007-11-19 23:14:14 +00:00
|
|
|
sta (ptr),y
|
|
|
|
iny
|
2013-09-11 18:48:23 +00:00
|
|
|
bne :-
|
2007-11-19 23:14:14 +00:00
|
|
|
inc ptr+1
|
2007-11-29 21:56:55 +00:00
|
|
|
dex
|
2013-09-11 18:48:23 +00:00
|
|
|
bpl :-
|
2007-12-08 21:05:48 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Return frame length
|
|
|
|
lda len
|
|
|
|
ldx len+1
|
2014-06-12 20:56:35 +00:00
|
|
|
clc
|
2007-11-19 23:14:14 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
send:
|
|
|
|
; Save frame length
|
|
|
|
sta cnt
|
|
|
|
stx cnt+1
|
2013-01-30 22:39:01 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Transmit command
|
2013-09-11 18:48:23 +00:00
|
|
|
lda #$C9
|
2007-11-19 23:14:14 +00:00
|
|
|
ldx #$00
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup14:sta txcmd
|
|
|
|
fixup15:stx txcmd+1
|
2007-11-19 23:14:14 +00:00
|
|
|
lda cnt
|
|
|
|
ldx cnt+1
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup16:sta txlen
|
|
|
|
fixup17:stx txlen+1
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
; Adjust odd frame length
|
2013-09-11 18:48:23 +00:00
|
|
|
jsr adjustcnt
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
; 8 retries
|
2013-09-11 18:48:23 +00:00
|
|
|
ldy #$08
|
2013-01-30 22:39:01 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
; Check for avaliable buffer space
|
|
|
|
; PACKETPP = $0138, PPDATA & $0100 ?
|
|
|
|
: lda #$38
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr packetpp_a1
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup18:lda ppdata+1
|
2007-11-19 23:14:14 +00:00
|
|
|
and #$01
|
|
|
|
bne :+
|
|
|
|
|
|
|
|
; No space avaliable, skip a received frame
|
2013-09-11 18:48:23 +00:00
|
|
|
jsr skipframe
|
2007-11-19 23:14:14 +00:00
|
|
|
|
|
|
|
; And try again
|
|
|
|
dey
|
|
|
|
bne :-
|
2014-06-12 20:56:35 +00:00
|
|
|
sec
|
2007-11-19 23:14:14 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Send the frame
|
|
|
|
; --------------
|
|
|
|
|
|
|
|
; Write bytes from buffer
|
2013-09-11 18:48:23 +00:00
|
|
|
: jsr adjustptr
|
|
|
|
: lda (ptr),y
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup19:sta rxtxreg
|
2007-11-19 23:14:14 +00:00
|
|
|
iny
|
|
|
|
lda (ptr),y
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup20:sta rxtxreg+1
|
2007-11-19 23:14:14 +00:00
|
|
|
iny
|
2013-09-11 18:48:23 +00:00
|
|
|
bne :-
|
2007-11-19 23:14:14 +00:00
|
|
|
inc ptr+1
|
2007-11-29 21:56:55 +00:00
|
|
|
dex
|
2013-09-11 18:48:23 +00:00
|
|
|
bpl :-
|
2014-06-12 20:56:35 +00:00
|
|
|
clc
|
2007-11-19 23:14:14 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
exit:
|
|
|
|
rts
|
2013-01-30 22:39:01 +00:00
|
|
|
|
2007-11-19 23:14:14 +00:00
|
|
|
;---------------------------------------------------------------------
|
2013-09-11 18:48:23 +00:00
|
|
|
|
2013-11-13 22:32:49 +00:00
|
|
|
packetpp_a1:
|
2013-09-11 18:48:23 +00:00
|
|
|
ldx #$01
|
2014-06-12 20:56:35 +00:00
|
|
|
packetpp_ax:
|
|
|
|
fixup21:sta packetpp
|
|
|
|
fixup22:stx packetpp+1
|
2013-11-13 22:32:49 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
ppdata_ax:
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup23:sta ppdata
|
|
|
|
fixup24:stx ppdata+1
|
2013-09-11 18:48:23 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
skipframe:
|
|
|
|
; PACKETPP = $0102, PPDATA = PPDATA | $0040
|
|
|
|
lda #$02
|
2013-11-13 22:32:49 +00:00
|
|
|
jsr packetpp_a1
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup25:lda ppdata
|
2013-09-11 18:48:23 +00:00
|
|
|
ora #$40
|
2014-06-12 20:56:35 +00:00
|
|
|
fixup26:sta ppdata
|
2013-09-11 18:48:23 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
adjustcnt:
|
|
|
|
lsr
|
|
|
|
bcc :+
|
|
|
|
inc cnt
|
|
|
|
bne :+
|
|
|
|
inc cnt+1
|
|
|
|
: rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|
|
|
|
|
|
|
|
adjustptr:
|
|
|
|
lda cnt
|
2013-10-03 20:32:12 +00:00
|
|
|
ldx cnt+1
|
2013-09-11 18:48:23 +00:00
|
|
|
eor #$FF ; Two's complement part 1
|
|
|
|
tay
|
|
|
|
iny ; Two's complement part 2
|
|
|
|
sty reg
|
|
|
|
sec
|
|
|
|
lda bufaddr
|
|
|
|
sbc reg
|
|
|
|
sta ptr
|
|
|
|
lda bufaddr+1
|
|
|
|
sbc #$00
|
|
|
|
sta ptr+1
|
|
|
|
rts
|
|
|
|
|
|
|
|
;---------------------------------------------------------------------
|