2 ; Copyright (c) 2003-2007, Adam Dunkels, Josef Soucek and Oliver Schmidt
5 ; Redistribution and use in source and binary forms, with or without
6 ; modification, are permitted provided that the following conditions
8 ; 1. Redistributions of source code must retain the above copyright
9 ; notice, this list of conditions and the following disclaimer.
10 ; 2. Redistributions in binary form must reproduce the above copyright
11 ; notice, this list of conditions and the following disclaimer in the
12 ; documentation and/or other materials provided with the distribution.
13 ; 3. Neither the name of the Institute nor the names of its contributors
14 ; may be used to endorse or promote products derived from this software
15 ; without specific prior written permission.
17 ; THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 ; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 ; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ; ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 ; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 ; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 ; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 ; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 ; This file is part of the Contiki operating system.
31 ; Author: Adam Dunkels <adam@sics.se>, Josef Soucek <josef.soucek@ide64.org>,
32 ; Oliver Schmidt <ol.sc@web.de>
34 ; $Id: lan91c96.S,v 1.2 2007/12/01 20:23:11 oliverschmidt Exp $
36 ;---------------------------------------------------------------------
41 .byte $65, $74, $68 ; "eth"
42 .byte $01 ; Ethernet driver API version number
45 mac: .byte $00, $80, $0F ; OUI of Standard Microsystems
49 bufaddr:.res 2 ; Address
58 ;---------------------------------------------------------------------
62 sp: .res 2 ; Stack pointer (Do not trash !)
63 reg: .res 2 ; Address of register base
64 ptr: .res 2 ; Indirect addressing pointer
65 len: .res 2 ; Frame length
67 ;---------------------------------------------------------------------
69 .segment "EXTZP": zeropage
71 ; Empty segment to avoid linker warnings
73 ;---------------------------------------------------------------------
77 fixup: .byte fixup02-fixup01, fixup03-fixup02, fixup04-fixup03
78 .byte fixup05-fixup04, fixup06-fixup05, fixup07-fixup06
79 .byte fixup08-fixup07, fixup09-fixup08, fixup10-fixup09
80 .byte fixup11-fixup10, fixup12-fixup11, fixup13-fixup12
81 .byte fixup14-fixup13, fixup15-fixup14, fixup16-fixup15
82 .byte fixup17-fixup16, fixup18-fixup17, fixup19-fixup18
83 .byte fixup20-fixup19, fixup21-fixup20, fixup22-fixup21
84 .byte fixup23-fixup22, fixup24-fixup23, fixup25-fixup24
85 .byte fixup26-fixup25, fixup27-fixup26, fixup28-fixup27
86 .byte fixup29-fixup28, fixup30-fixup29, fixup31-fixup30
87 .byte fixup32-fixup31, fixup33-fixup32, fixup34-fixup33
88 .byte fixup35-fixup34, fixup36-fixup35, fixup37-fixup36
89 .byte fixup38-fixup37, fixup39-fixup38, fixup40-fixup39
90 .byte fixup41-fixup40, fixup42-fixup41
94 ;---------------------------------------------------------------------
96 ethbsr := $FF0E ; Bank select register R/W (2B)
99 ethtcr := $FF00 ; Transmition control register R/W (2B)
100 ethephsr := $FF02 ; EPH status register R/O (2B)
101 ethrcr := $FF04 ; Receive control register R/W (2B)
102 ethecr := $FF06 ; Counter register R/O (2B)
103 ethmir := $FF08 ; Memory information register R/O (2B)
104 ethmcr := $FF0A ; Memory Config. reg. +0 R/W +1 R/O (2B)
107 ethcr := $FF00 ; Configuration register R/W (2B)
108 ethbar := $FF02 ; Base address register R/W (2B)
109 ethiar := $FF04 ; Individual address register R/W (6B)
110 ethgpr := $FF0A ; General address register R/W (2B)
111 ethctr := $FF0C ; Control register R/W (2B)
114 ethmmucr := $FF00 ; MMU command register W/O (1B)
115 ethautotx := $FF01 ; AUTO TX start register R/W (1B)
116 ethpnr := $FF02 ; Packet number register R/W (1B)
117 etharr := $FF03 ; Allocation result register R/O (1B)
118 ethfifo := $FF04 ; FIFO ports register R/O (2B)
119 ethptr := $FF06 ; Pointer register R/W (2B)
120 ethdata := $FF08 ; Data register R/W (4B)
121 ethist := $FF0C ; Interrupt status register R/O (1B)
122 ethack := $FF0C ; Interrupt acknowledge register W/O (1B)
123 ethmsk := $FF0D ; Interrupt mask register R/W (1B)
126 ethmt := $FF00 ; Multicast table R/W (8B)
127 ethmgmt := $FF08 ; Management interface R/W (2B)
128 ethrev := $FF0A ; Revision register R/W (2B)
129 ethercv := $FF0C ; Early RCV register R/W (2B)
133 ;---------------------------------------------------------------------
136 ; Save address of register base
140 ; Start with first fixup location
148 ; Fixup address at location
157 ; Advance to next fixup location
173 lda #%10000000 ; Software reset
181 : cmp ($FF,x) ; 6 cycles
182 cmp ($FF,x) ; 6 cycles
185 ; 17 * 256 = 4352 -> 4,4 ms
187 ; Enable transmit and receive
188 lda #%10000001 ; Enable transmit TXENA, PAD_EN
189 ldx #%00000011 ; Enable receive, strip CRC ???
197 ora #%00010000 ; No wait (IOCHRDY)
200 lda #%00001001 ; Auto release
221 lda #%00000000 ; No interrupts
225 ;---------------------------------------------------------------------
229 and #%00000001 ; RCV INT
232 ; No packet available
236 ; Process the incoming packet
237 ; ---------------------------
240 ldx #%11100000 ; RCV, AUTO INCR., READ
244 ; Last word contains 'last data byte' and $60 or 'fill byte' and $40
245 fixup21:lda ethdata ; Status word
246 fixup22:lda ethdata ; Need high byte only
248 ; Move ODDFRM bit into carry:
249 ; - Even packet length -> carry clear -> subtract 6 bytes
250 ; - Odd packet length -> carry set -> subtract 5 bytes
257 ; The packet contains 3 extra words
258 fixup23:lda ethdata ; Total number of bytes
259 sbc #$05 ; Actually 5 or 6 depending on carry
274 ; Remove and release RX packet from the FIFO
278 ; No packet available
283 ; Read bytes into buffer
301 ; Remove and release RX packet from the FIFO
305 ; Return packet length
310 ;---------------------------------------------------------------------
317 ; Allocate memory for TX
325 ; Wait for allocation ready
328 and #%00001000 ; ALLOC INT
331 ; Shouldn't we do something here to actively free memory,
332 ; maybe removing and releasing an RX packet from the FIFO ???
339 ; Acknowledge interrupt, is it necessary ???
348 ldx #%01000000 ; AUTO INCR.
352 ; Status written by CSMA
357 ; Check packet length parity:
358 ; - Even packet length -> carry set -> add 6 bytes
359 ; - Odd packet length -> carry clear -> add 5 bytes
364 ; The packet contains 3 extra words
366 adc #$05 ; Actually 5 or 6 depending on carry
375 ; Write bytes from buffer
392 ; Odd packet length ?
403 fixup40:sta ethdata ; Fill byte
405 fixup41:sta ethdata ; Control byte
408 lda #%11000000 ; ENQUEUE PACKET - transmit packet
412 ;---------------------------------------------------------------------
417 ;---------------------------------------------------------------------