adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001, Adam Dunkels. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 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. |
adamdunkels | fb24dff | 2004-09-12 14:07:30 +0000 | [diff] [blame] | 13 | * 3. The name of the author may not be used to endorse or promote |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 14 | * products derived from this software without specific prior |
| 15 | * written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 23 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | * This file is part of the C64 RealAudio server demo project. |
| 30 | * |
oliverschmidt | c8bfc02 | 2005-03-16 22:39:21 +0000 | [diff] [blame] | 31 | * $Id: cs8900a.c,v 1.13 2005/03/16 22:39:21 oliverschmidt Exp $ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 32 | * |
| 33 | */ |
| 34 | |
| 35 | /* cs8900a.c: device driver for the CS8900a chip in 8-bit mode. Mostly |
| 36 | written in 6502 assembler for speed. */ |
| 37 | |
| 38 | #include "cs8900a.h" |
| 39 | #include "uip.h" |
| 40 | #include "uip_arp.h" |
| 41 | |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 42 | extern u8_t *cs8900a_rxtxreg, |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 43 | *cs8900a_txcmd, |
| 44 | *cs8900a_txlen, |
| 45 | *cs8900a_packetpp, |
| 46 | *cs8900a_ppdata; |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 47 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 48 | static u16_t len; |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 49 | static u16_t cnt; |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 53 | #pragma optimize(push, off) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 54 | void |
| 55 | cs8900a_init(void) |
| 56 | { |
| 57 | /* Turn on transmission and reception of frames. */ |
| 58 | /* PACKETPP = 0x0112; |
| 59 | PPDATA = 0x00c0; */ |
| 60 | asm("lda #$12"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 61 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 62 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 63 | asm("sta %v+1", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 64 | asm("lda #$c0"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 65 | asm("sta %v", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 66 | asm("lda #$00"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 67 | asm("sta %v+1", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 68 | |
| 69 | /* Accept valid unicast+broadcast frames. */ |
| 70 | /* PACKETPP = 0x0104; |
| 71 | PPDATA = 0x0d05; */ |
| 72 | asm("lda #$04"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 73 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 74 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 75 | asm("sta %v+1", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 76 | asm("lda #$05"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 77 | asm("sta %v", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 78 | asm("lda #$0d"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 79 | asm("sta %v+1", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 80 | |
| 81 | /* Set MAC address. */ |
| 82 | /* PACKETPP = 0x0158; |
| 83 | PPDATA = (ETHADDR1 << 8) | (ETHADDR0); */ |
| 84 | asm("lda #$58"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 85 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 86 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 87 | asm("sta %v+1", cs8900a_packetpp); |
adamdunkels | 24b8329 | 2004-09-18 20:44:27 +0000 | [diff] [blame] | 88 | asm("lda %v", uip_ethaddr); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 89 | asm("sta %v", cs8900a_ppdata); |
adamdunkels | 24b8329 | 2004-09-18 20:44:27 +0000 | [diff] [blame] | 90 | asm("lda %v+1", uip_ethaddr); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 91 | asm("sta %v+1", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 92 | |
| 93 | /* PACKETPP = 0x015a; |
| 94 | PPDATA = (ETHADDR3 << 8) | (ETHADDR2); */ |
| 95 | asm("lda #$5a"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 96 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 97 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 98 | asm("sta %v+1", cs8900a_packetpp); |
adamdunkels | 24b8329 | 2004-09-18 20:44:27 +0000 | [diff] [blame] | 99 | asm("lda %v+2", uip_ethaddr); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 100 | asm("sta %v", cs8900a_ppdata); |
adamdunkels | 24b8329 | 2004-09-18 20:44:27 +0000 | [diff] [blame] | 101 | asm("lda %v+3", uip_ethaddr); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 102 | asm("sta %v+1", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 103 | |
| 104 | /* PACKETPP = 0x015c; |
| 105 | PPDATA = (ETHADDR5 << 8) | (ETHADDR4); */ |
| 106 | asm("lda #$5c"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 107 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 108 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 109 | asm("sta %v+1", cs8900a_packetpp); |
adamdunkels | 24b8329 | 2004-09-18 20:44:27 +0000 | [diff] [blame] | 110 | asm("lda %v+4", uip_ethaddr); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 111 | asm("sta %v", cs8900a_ppdata); |
adamdunkels | 24b8329 | 2004-09-18 20:44:27 +0000 | [diff] [blame] | 112 | asm("lda %v+5", uip_ethaddr); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 113 | asm("sta %v+1", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 114 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 115 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 116 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 117 | #pragma optimize(push, off) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 118 | void |
| 119 | cs8900a_send(void) |
| 120 | { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 121 | /* Transmit command. */ |
| 122 | asm("lda #$c0"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 123 | asm("sta %v", cs8900a_txcmd); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 124 | asm("lda #$00"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 125 | asm("sta %v+1", cs8900a_txcmd); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 126 | asm("lda %v", uip_len); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 127 | asm("sta %v", cs8900a_txlen); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 128 | asm("lda %v+1", uip_len); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 129 | asm("sta %v+1", cs8900a_txlen); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 130 | |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 131 | asm("ldy #8"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 132 | tryagain: |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 133 | /* Check for avaliable buffer space. */ |
| 134 | asm("lda #$38"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 135 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 136 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 137 | asm("sta %v+1", cs8900a_packetpp); |
| 138 | asm("lda %v+1", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 139 | asm("and #1"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 140 | asm("bne %g", send); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 141 | |
| 142 | /* No space avaliable, skip a received frame and try again. */ |
| 143 | asm("lda #$02"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 144 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 145 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 146 | asm("sta %v+1", cs8900a_packetpp); |
| 147 | asm("lda %v", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 148 | asm("ora #$40"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 149 | asm("sta %v", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 150 | |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 151 | asm("dey"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 152 | asm("bne %g", tryagain); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 153 | return; |
| 154 | |
| 155 | /* Send the frame. */ |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 156 | send: |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 157 | |
oliverschmidt | 4affe76 | 2005-02-23 22:43:00 +0000 | [diff] [blame] | 158 | /* First, send 14+40=54 bytes of header. */ |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 159 | asm("ldy #0"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 160 | sendloop1: |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 161 | asm("lda %v,y", uip_buf); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 162 | asm("sta %v", cs8900a_rxtxreg); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 163 | asm("iny"); |
| 164 | asm("lda %v,y", uip_buf); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 165 | asm("sta %v+1", cs8900a_rxtxreg); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 166 | asm("iny"); |
oliverschmidt | 4affe76 | 2005-02-23 22:43:00 +0000 | [diff] [blame] | 167 | asm("cpy #%b", UIP_LLH_LEN + UIP_TCPIP_HLEN); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 168 | asm("bne %g", sendloop1); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 169 | |
oliverschmidt | 4affe76 | 2005-02-23 22:43:00 +0000 | [diff] [blame] | 170 | if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | |
| 174 | /* Next, send rest of the packet. */ |
oliverschmidt | c8bfc02 | 2005-03-16 22:39:21 +0000 | [diff] [blame] | 175 | cnt = uip_len - (UIP_LLH_LEN + UIP_TCPIP_HLEN); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 176 | |
oliverschmidt | fcdbaec | 2005-03-13 21:16:30 +0000 | [diff] [blame] | 177 | asm("lda %v", cnt); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 178 | asm("lsr"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 179 | asm("bcc %g", noinc); |
oliverschmidt | fcdbaec | 2005-03-13 21:16:30 +0000 | [diff] [blame] | 180 | asm("inc %v", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 181 | asm("bne %g", noinc); |
oliverschmidt | fcdbaec | 2005-03-13 21:16:30 +0000 | [diff] [blame] | 182 | asm("inc %v+1", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 183 | noinc: |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 184 | |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 185 | asm("lda %v", uip_appdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 186 | asm("sta ptr1"); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 187 | asm("lda %v+1", uip_appdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 188 | asm("sta ptr1+1"); |
| 189 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 190 | asm("ldy #0"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 191 | sendloop2: |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 192 | asm("lda (ptr1),y"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 193 | asm("sta %v", cs8900a_rxtxreg); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 194 | asm("iny"); |
| 195 | asm("lda (ptr1),y"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 196 | asm("sta %v+1", cs8900a_rxtxreg); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 197 | asm("iny"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 198 | asm("bne %g", check); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 199 | asm("inc ptr1+1"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 200 | check: |
oliverschmidt | fcdbaec | 2005-03-13 21:16:30 +0000 | [diff] [blame] | 201 | asm("cpy %v", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 202 | asm("bne %g", sendloop2); |
oliverschmidt | fcdbaec | 2005-03-13 21:16:30 +0000 | [diff] [blame] | 203 | asm("dec %v+1", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 204 | asm("bpl %g", sendloop2); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 205 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 206 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 207 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 208 | #pragma optimize(push, off) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 209 | static void |
| 210 | skip_frame(void) |
| 211 | { |
| 212 | /* PACKETPP = 0x0102; |
| 213 | PPDATA = PPDATA | 0x0040; */ |
| 214 | asm("lda #$02"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 215 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 216 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 217 | asm("sta %v+1", cs8900a_packetpp); |
| 218 | asm("lda %v", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 219 | asm("ora #$40"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 220 | asm("sta %v", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 221 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 222 | #pragma optimize(pop) |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 223 | /*-----------------------------------------------------------------------------------*/ |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 224 | #pragma optimize(push, off) |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 225 | u16_t |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 226 | cs8900a_poll(void) |
| 227 | { |
| 228 | /* Check receiver event register to see if there are any valid |
| 229 | unicast frames avaliable. */ |
| 230 | /* PACKETPP = 0x0124; |
| 231 | if(PPDATA & 0x000d == 0x0000) { |
| 232 | return 0; |
| 233 | } |
| 234 | */ |
| 235 | asm("lda #$24"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 236 | asm("sta %v", cs8900a_packetpp); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 237 | asm("lda #$01"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 238 | asm("sta %v+1", cs8900a_packetpp); |
| 239 | asm("lda %v+1", cs8900a_ppdata); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 240 | asm("and #$0d"); |
| 241 | asm("cmp #$00"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 242 | asm("bne %g", noreturn); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 243 | /* No frame ready. */ |
| 244 | return 0; |
| 245 | |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 246 | noreturn: |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 247 | /* Process the incoming frame. */ |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 248 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 249 | /* Read receiver event and discard it. */ |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 250 | /* RXTXREG; */ |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 251 | asm("lda %v+1", cs8900a_rxtxreg); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 252 | asm("lda %v", cs8900a_rxtxreg); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 253 | |
| 254 | /* Read frame length. */ |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 255 | /* cnt = len = RXTXREG; */ |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 256 | asm("lda %v+1", cs8900a_rxtxreg); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 257 | asm("sta %v+1", len); |
| 258 | asm("sta %v+1", cnt); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 259 | asm("lda %v", cs8900a_rxtxreg); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 260 | asm("sta %v", len); |
| 261 | asm("sta %v", cnt); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 262 | |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 263 | asm("lsr"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 264 | asm("bcc %g", noinc); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 265 | asm("inc %v", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 266 | asm("bne %g", noinc); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 267 | asm("inc %v+1", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 268 | noinc: |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 269 | |
| 270 | if(cnt > UIP_BUFSIZE) { |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 271 | skip_frame(); |
| 272 | return 0; |
| 273 | } |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 274 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 275 | /* Read bytes into uip_buf. */ |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 276 | asm("lda #<%v", uip_buf); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 277 | asm("sta ptr1"); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 278 | asm("lda #>%v", uip_buf); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 279 | asm("sta ptr1+1"); |
| 280 | |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 281 | asm("ldy #0"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 282 | readloop: |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 283 | asm("lda %v", cs8900a_rxtxreg); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 284 | asm("sta (ptr1),y"); |
| 285 | asm("iny"); |
adamdunkels | cd49928 | 2003-07-30 22:40:36 +0000 | [diff] [blame] | 286 | asm("lda %v+1", cs8900a_rxtxreg); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 287 | asm("sta (ptr1),y"); |
| 288 | asm("iny"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 289 | asm("bne %g", check); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 290 | asm("inc ptr1+1"); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 291 | check: |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 292 | asm("cpy %v", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 293 | asm("bne %g", readloop); |
oliverschmidt | 9d2b0c2 | 2005-02-02 22:34:18 +0000 | [diff] [blame] | 294 | asm("dec %v+1", cnt); |
oliverschmidt | 815f57e | 2005-03-09 23:31:54 +0000 | [diff] [blame] | 295 | asm("bpl %g", readloop); |
adamdunkels | 7e4982c | 2003-03-19 16:26:18 +0000 | [diff] [blame] | 296 | return len; |
| 297 | } |
oliverschmidt | a8240ea | 2004-07-18 13:19:47 +0000 | [diff] [blame] | 298 | #pragma optimize(pop) |