Initial revision
diff --git a/contiki-cpc/uip/cs8900a.c b/contiki-cpc/uip/cs8900a.c
new file mode 100644
index 0000000..44915eb
--- /dev/null
+++ b/contiki-cpc/uip/cs8900a.c
@@ -0,0 +1,368 @@
+/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 C64 RealAudio server demo project.
+ *
+ * $Id: cs8900a.c,v 1.1 2006/04/17 15:02:39 kthacker Exp $
+ *
+ */
+
+/* cs8900a.c: device driver for the CS8900a chip in 8-bit mode. Mostly
+ written in 6502 assembler for speed. */
+
+#include "cs8900a.h"
+#include "uip.h"
+#include "uip_arp.h"
+
+/*#define UIP_ETHADDR0 0x00
+#define UIP_ETHADDR1 0x00
+#define UIP_ETHADDR2 0x00
+#define UIP_ETHADDR3 0x64
+#define UIP_ETHADDR4 0x64
+#define UIP_ETHADDR5 0x64*/
+
+extern u8_t *cs8900a_rxtxreg,
+ *cs8900a_txcmd,
+ *cs8900a_txlen,
+ *cs8900a_packetpp,
+ *cs8900a_ppdata;
+
+static u16_t len;
+static u8_t r;
+
+
+/*-----------------------------------------------------------------------------------*/
+#pragma optimize(push, off)
+void
+cs8900a_init(void)
+{
+ /* Turn on transmission and reception of frames. */
+ /* PACKETPP = 0x0112;
+ PPDATA = 0x00c0; */
+ asm("lda #$12");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda #$c0");
+ asm("sta %v", cs8900a_ppdata);
+ asm("lda #$00");
+ asm("sta %v+1", cs8900a_ppdata);
+
+ /* Accept valid unicast+broadcast frames. */
+ /* PACKETPP = 0x0104;
+ PPDATA = 0x0d05; */
+ asm("lda #$04");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda #$05");
+ asm("sta %v", cs8900a_ppdata);
+ asm("lda #$0d");
+ asm("sta %v+1", cs8900a_ppdata);
+
+ /* Set MAC address. */
+ /* PACKETPP = 0x0158;
+ PPDATA = (ETHADDR1 << 8) | (ETHADDR0); */
+ asm("lda #$58");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda %v", uip_ethaddr);
+ asm("sta %v", cs8900a_ppdata);
+ asm("lda %v+1", uip_ethaddr);
+ asm("sta %v+1", cs8900a_ppdata);
+
+ /* PACKETPP = 0x015a;
+ PPDATA = (ETHADDR3 << 8) | (ETHADDR2); */
+ asm("lda #$5a");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda %v+2", uip_ethaddr);
+ asm("sta %v", cs8900a_ppdata);
+ asm("lda %v+3", uip_ethaddr);
+ asm("sta %v+1", cs8900a_ppdata);
+
+ /* PACKETPP = 0x015c;
+ PPDATA = (ETHADDR5 << 8) | (ETHADDR4); */
+ asm("lda #$5c");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda %v+4", uip_ethaddr);
+ asm("sta %v", cs8900a_ppdata);
+ asm("lda %v+5", uip_ethaddr);
+ asm("sta %v+1", cs8900a_ppdata);
+
+}
+#pragma optimize(pop)
+/*-----------------------------------------------------------------------------------*/
+#pragma optimize(push, off)
+void
+cs8900a_send(void)
+{
+ if(uip_len > UIP_BUFSIZE) {
+ asm("inc $d020");
+ return;
+ }
+
+ /* Transmit command. */
+ asm("lda #$c0");
+ asm("sta %v", cs8900a_txcmd);
+ asm("lda #$00");
+ asm("sta %v+1", cs8900a_txcmd);
+ asm("lda _uip_len");
+ asm("sta %v", cs8900a_txlen);
+#if UIP_BUFSIZE > 255
+ asm("lda _uip_len+1");
+#else
+ asm("lda #0");
+#endif
+ asm("sta %v+1", cs8900a_txlen);
+
+ asm("ldx #8");
+ asm("tryagain:");
+ /* Check for avaliable buffer space. */
+ asm("lda #$38");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda %v+1", cs8900a_ppdata);
+ asm("and #1");
+ asm("bne send");
+
+ /* No space avaliable, skip a received frame and try again. */
+ asm("lda #$02");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda %v", cs8900a_ppdata);
+ asm("ora #$40");
+ asm("sta %v", cs8900a_ppdata);
+
+ asm("dex");
+ asm("bne tryagain");
+
+ asm("bailout:");
+ return;
+
+ /* Send the frame. */
+ asm("send:");
+
+
+ /* First, send 40+14=54 bytes of header. */
+
+ asm("ldx #54");
+ asm("ldy #0");
+ asm("sendloop1:");
+ asm("lda _uip_buf,y");
+ asm("sta %v", cs8900a_rxtxreg);
+ asm("lda _uip_buf+1,y");
+ asm("sta %v+1", cs8900a_rxtxreg);
+ asm("iny");
+ asm("iny");
+ asm("dex");
+ asm("dex");
+ asm("bne sendloop1");
+
+ if(uip_len <= 54) {
+ return;
+ }
+
+ /* Next, send rest of the packet. */
+
+ uip_len -= 54;
+
+
+ asm("lda ptr1");
+ asm("pha");
+ asm("lda ptr1+1");
+ asm("pha");
+
+ asm("lda _uip_appdata");
+ asm("sta ptr1");
+ asm("lda _uip_appdata+1");
+ asm("sta ptr1+1");
+
+ asm("sendloop2:");
+ asm("lda _uip_len");
+ asm("tax");
+ asm("and #1");
+ asm("beq noinc");
+ asm("inx");
+ asm("noinc:");
+#if UIP_BUFSIZE > 255
+ asm("lda _uip_len+1");
+#else
+ asm("lda #0");
+#endif
+ asm("beq nozero");
+ asm("ldx #0");
+ asm("nozero:");
+ asm("ldy #0");
+ asm("sendloop:");
+ asm("lda (ptr1),y");
+ asm("sta %v", cs8900a_rxtxreg);
+ asm("iny");
+ asm("lda (ptr1),y");
+ asm("sta %v+1", cs8900a_rxtxreg);
+ asm("iny");
+ asm("dex");
+ asm("dex");
+ asm("bne sendloop");
+ asm("inc ptr1+1");
+#if UIP_BUFSIZE > 255
+ asm("dec _uip_len+1");
+ asm("bpl sendloop2");
+#endif
+
+ asm("pla");
+ asm("sta ptr1+1");
+ asm("pla");
+ asm("sta ptr1");
+}
+#pragma optimize(pop)
+/*-----------------------------------------------------------------------------------*/
+#pragma optimize(push, off)
+static void
+skip_frame(void)
+{
+ /* PACKETPP = 0x0102;
+ PPDATA = PPDATA | 0x0040; */
+ asm("lda #$02");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda %v", cs8900a_ppdata);
+ asm("ora #$40");
+ asm("sta %v", cs8900a_ppdata);
+}
+#pragma optimize(pop)
+/*-----------------------------------------------------------------------------------*/
+#pragma optimize(push, off)
+u8_t
+cs8900a_poll(void)
+{
+ /* Check receiver event register to see if there are any valid
+ unicast frames avaliable. */
+ /* PACKETPP = 0x0124;
+ if(PPDATA & 0x000d == 0x0000) {
+ return 0;
+ }
+ */
+ asm("lda #$24");
+ asm("sta %v", cs8900a_packetpp);
+ asm("lda #$01");
+ asm("sta %v+1", cs8900a_packetpp);
+ asm("lda %v+1", cs8900a_ppdata);
+ asm("and #$0d");
+ asm("cmp #$00");
+ asm("bne noreturn");
+ /* No frame ready. */
+ return 0;
+
+ asm("noreturn:");
+ /* Process the incoming frame. */
+
+ /* Read receiver event and discard it. */
+ /* dummy = RXTXREG; */
+
+ asm("lda %v+1", cs8900a_rxtxreg);
+ asm("sta _len+1");
+ asm("lda %v", cs8900a_rxtxreg);
+ asm("sta _len");
+
+ /* Read frame length. */
+ /* len = uip_len = RXTXREG; */
+ asm("lda %v+1", cs8900a_rxtxreg);
+ asm("sta _len+1");
+ asm("sta _uip_len+1");
+ asm("lda %v", cs8900a_rxtxreg);
+ asm("sta _len");
+ asm("sta _uip_len");
+
+
+ if(len > UIP_BUFSIZE) {
+ skip_frame();
+ return 0;
+ }
+
+ /* Read bytes into uip_buf. */
+ asm("lda ptr1");
+ asm("pha");
+ asm("lda ptr1+1");
+ asm("pha");
+
+ asm("lda #<_uip_buf");
+ asm("sta ptr1");
+ asm("lda #>_uip_buf");
+ asm("sta ptr1+1");
+
+ asm("lda _len+1");
+ asm("beq read256");
+
+ /* Read first 256*n bytes. */
+ asm("ldy #0");
+ asm("read256loop:");
+ asm("lda %v", cs8900a_rxtxreg);
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("lda %v+1", cs8900a_rxtxreg);
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("bne read256loop");
+ asm("inc ptr1+1");
+
+ asm("dec _len+1");
+ asm("bne read256loop");
+
+ /* Read last 255 or less bytes. */
+ asm("read256:");
+ asm("lda _len");
+ asm("lsr");
+ asm("bcc noinc");
+ asm("inc _len");
+ asm("noinc:");
+ asm("ldy #$0");
+ asm("readloop:");
+ asm("lda %v", cs8900a_rxtxreg);
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("lda %v+1", cs8900a_rxtxreg);
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("cpy _len");
+ asm("bne readloop");
+
+ asm("pla");
+ asm("sta ptr1+1");
+ asm("pla");
+ asm("sta ptr1");
+ return len;
+}
+#pragma optimize(pop)
diff --git a/contiki-cpc/uip/cs8900a.h b/contiki-cpc/uip/cs8900a.h
new file mode 100644
index 0000000..dab0ea6
--- /dev/null
+++ b/contiki-cpc/uip/cs8900a.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * 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>
+ *
+ * $Id: cs8900a.h,v 1.1 2006/04/17 15:02:39 kthacker Exp $
+ */
+#ifndef __CS8900A_H__
+#define __CS8900A_H__
+
+#include "uip_arch.h"
+
+void cs8900a_init(void);
+void cs8900a_send(void);
+u8_t cs8900a_poll(void);
+
+#endif /* __CS8900A_H__ */
diff --git a/contiki-cpc/uip/eth64-drv.c b/contiki-cpc/uip/eth64-drv.c
new file mode 100644
index 0000000..db79c85
--- /dev/null
+++ b/contiki-cpc/uip/eth64-drv.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2001-2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: eth64-drv.c,v 1.1 2006/04/17 15:02:39 kthacker Exp $
+ *
+ */
+
+#include "packet-service.h"
+
+#include "lan91c96.h"
+
+#include "uip_arp.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct uip_eth_addr addr =
+ {{0x00,0x0d,0x60,0x80,0x3d,0xb9}};
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": ETH64", EK_PRIO_NORMAL,
+ eventhandler, pollhandler, (void *)&state);
+
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(eth64_drv_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ uip_arp_out();
+ lan91c96_send();
+}
+/*---------------------------------------------------------------------------*/
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ uip_setethaddr(addr);
+ lan91c96_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ek_replace((struct ek_proc *)data, NULL);
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ek_exit();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+
+ /* Poll Ethernet device to see if there is a frame avaliable. */
+ uip_len = lan91c96_poll();
+ if(uip_len > 0) {
+ /* A frame was avaliable (and is now read into the uip_buf), so
+ we process it. */
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+ uip_arp_ipin();
+ uip_len -= sizeof(struct uip_eth_hdr);
+ tcpip_input();
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin();
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if(uip_len > 0) {
+ lan91c96_send();
+ }
+ }
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/eth64-dsc.c b/contiki-cpc/uip/eth64-dsc.c
new file mode 100644
index 0000000..4c11d7e
--- /dev/null
+++ b/contiki-cpc/uip/eth64-dsc.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 desktop environment
+ *
+ * $Id: eth64-dsc.c,v 1.1 2006/04/17 15:02:39 kthacker Exp $
+ *
+ */
+
+#include "dsc.h"
+
+extern struct ctk_icon lan91c96_icon;
+/*-----------------------------------------------------------------------------------*/
+DSC(lan91c96_dsc,
+ "IDE64/ETH64 driver",
+ "lan91c96.drv",
+ lan91c96_init,
+ &lan91c96_icon);
+/*-----------------------------------------------------------------------------------*/
+#if CTK_CONF_ICON_BITMAPS
+static unsigned char lan91c96icon_bitmap[3*3*8] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+};
+#endif /* CTK_CONF_ICON_BITMAPS */
+
+#if CTK_CONF_ICON_TEXTMAPS
+static char lan91c96icon_textmap[9] = {
+ 'I', 'D', 'E',
+ ' ', '6', '4',
+ 'E', 'T', 'H'
+};
+#endif /* CTK_CONF_ICON_TEXTMAPS */
+
+static struct ctk_icon lan91c96_icon =
+ {CTK_ICON("ETH64 driver", lan91c96icon_bitmap, lan91c96icon_textmap)};
+/*-----------------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/eth64-dump-drv.c b/contiki-cpc/uip/eth64-dump-drv.c
new file mode 100644
index 0000000..af1243e
--- /dev/null
+++ b/contiki-cpc/uip/eth64-dump-drv.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2001-2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: eth64-dump-drv.c,v 1.1 2006/04/17 15:02:39 kthacker Exp $
+ *
+ */
+
+#include "packet-service.h"
+
+#include "lan91c96.h"
+
+#include "uip_arp.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct uip_eth_addr addr =
+ {{0x00,0x0d,0x60,0x80,0x3d,0xb9}};
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": ETH64", EK_PRIO_NORMAL,
+ eventhandler, pollhandler, (void *)&state);
+
+#include "tcpdump.h"
+#include <string.h>
+#include "ctk.h"
+
+#define DUMP_WIDTH 38
+#define DUMP_HEIGHT 20
+static struct ctk_window window;
+static char dump[DUMP_WIDTH * DUMP_HEIGHT];
+static struct ctk_label dumplabel =
+ {CTK_LABEL(0, 0, DUMP_WIDTH, DUMP_HEIGHT, dump)};
+static void
+dump_packet(void)
+{
+ memcpy(dump, &dump[DUMP_WIDTH], DUMP_WIDTH * (DUMP_HEIGHT - 1));
+ tcpdump_print(&dump[DUMP_WIDTH * (DUMP_HEIGHT - 1)], DUMP_WIDTH);
+ CTK_WIDGET_REDRAW(&dumplabel);
+}
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(tfe_dump_drv_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ uip_arp_out();
+ lan91c96_send();
+ dump_packet();
+}
+/*---------------------------------------------------------------------------*/
+
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ ctk_window_new(&window, DUMP_WIDTH, DUMP_HEIGHT, "TFE dump");
+ CTK_WIDGET_ADD(&window, &dumplabel);
+ ctk_window_open(&window);
+ uip_setethaddr(addr);
+ lan91c96_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ctk_window_close(&window);
+ ek_replace((struct ek_proc *)data, NULL);
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ctk_window_close(&window);
+ ek_exit();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+
+ /* Poll Ethernet device to see if there is a frame avaliable. */
+ uip_len = lan91c96_poll();
+ if(uip_len > 0) {
+ /* A frame was avaliable (and is now read into the uip_buf), so
+ we process it. */
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+ uip_arp_ipin();
+ uip_len -= sizeof(struct uip_eth_hdr);
+ dump_packet();
+ tcpip_input();
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin();
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if(uip_len > 0) {
+ lan91c96_send();
+ }
+ }
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/lan91c96.c b/contiki-cpc/uip/lan91c96.c
new file mode 100644
index 0000000..d830eb0
--- /dev/null
+++ b/contiki-cpc/uip/lan91c96.c
@@ -0,0 +1,486 @@
+/*
+ * uIP lan91c96 (smc9194) driver
+ * Based on cs8900a driver, copyrighted (c) 2001, by Adam Dunkels
+ * Copyright (c) 2003, Josef Soucek
+ * All rights reserved.
+ *
+ * Ethernet card for Commodore 64, based on lan91c96 chip
+ * is a device created by IDE64 Project team.
+ * More information: http://ide64.come.to
+ *
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * $Id: lan91c96.c,v 1.1 2006/04/17 15:02:40 kthacker Exp $
+ *
+ */
+
+#define UIP_ETHADDR0 0x00
+#define UIP_ETHADDR1 0x0d
+#define UIP_ETHADDR2 0x60
+#define UIP_ETHADDR3 0x80
+#define UIP_ETHADDR4 0x3d
+#define UIP_ETHADDR5 0xb9
+
+#include "lan91c96.h"
+#include "uip.h"
+#include "uip_arp.h"
+
+#include <stdio.h>
+
+// #define DEBUG
+
+#define ETHBASE 0xde10
+
+#define ETHBSR ETHBASE+0x0e //Bank select register R/W (2B)
+
+/* Register bank 0 */
+
+#define ETHTCR ETHBASE //Transmition control register R/W (2B)
+#define ETHEPHSR ETHBASE+2 //EPH status register R/O (2B)
+#define ETHRCR ETHBASE+4 //Receive control register R/W (2B)
+#define ETHECR ETHBASE+6 //Counter register R/O (2B)
+#define ETHMIR (ETHBASE+8) //Memory information register R/O (2B)
+#define ETHMCR ETHBASE+0x0a //Memory Config. reg. +0 R/W +1 R/O (2B)
+
+/* Register bank 1 */
+
+#define ETHCR ETHBASE //Configuration register R/W (2B)
+#define ETHBAR ETHBASE+2 //Base address register R/W (2B)
+#define ETHIAR ETHBASE+4 //Individual address register R/W (6B)
+#define ETHGPR ETHBASE+0x0a //General address register R/W (2B)
+#define ETHCTR ETHBASE+0x0c //Control register R/W (2B)
+
+/* Register bank 2 */
+
+#define ETHMMUCR ETHBASE //MMU command register W/O (1B)
+#define ETHAUTOTX ETHBASE+1 //AUTO TX start register R/W (1B)
+#define ETHPNR ETHBASE+2 //Packet number register R/W (1B)
+#define ETHARR ETHBASE+3 //Allocation result register R/O (1B)
+#define ETHFIFO ETHBASE+4 //FIFO ports register R/O (2B)
+#define ETHPTR ETHBASE+6 //Pointer register R/W (2B)
+#define ETHDATA ETHBASE+8 //Data register R/W (4B)
+#define ETHIST (ETHBASE+0x0c) //Interrupt status register R/O (1B)
+#define ETHACK ETHBASE+0x0c //Interrupt acknowledge register W/O (1B)
+#define ETHMSK ETHBASE+0x0d //Interrupt mask register R/W (1B)
+
+/* Register bank 3 */
+
+#define ETHMT ETHBASE //Multicast table R/W (8B)
+#define ETHMGMT ETHBASE+8 //Management interface R/W (2B)
+#define ETHREV ETHBASE+0x0a //Revision register R/W (2B)
+#define ETHERCV ETHBASE+0x0c //Early RCV register R/W (2B)
+
+#define BANK(num) asm("lda #%b",num); asm("sta %w",ETHBSR);
+
+#ifdef DEBUG
+static void print_packet(u8_t *, u16_t);
+#endif
+
+static u8_t packet_status;
+static u16_t packet_length;
+
+extern u16_t uip_len;
+
+
+#pragma optimize(push, off)
+void lan91c96_init(void)
+{
+ /* Check if high byte is 0x33 */
+ asm("lda %w", ETHBSR+1);
+ asm("cmp #$33");
+ asm("beq @L1");
+
+ asm("inc $d021"); // Error
+
+ asm("@L1:");
+
+ /* Reset ETH card */
+ BANK(0);
+ asm("lda #%%10000000"); //Software reset
+ asm("sta %w", ETHRCR+1);
+
+ asm("lda #0");
+ asm("sta %w", ETHRCR);
+ asm("sta %w", ETHRCR+1);
+
+ /* delay */
+ asm("ldx #0");
+ asm("@L2:");
+ asm("cmp ($ff,x)"); //6 cycles
+ asm("cmp ($ff,x)"); //6 cycles
+ asm("dex"); //2 cycles
+ asm("bne @L2"); //3 cycles
+ //17*256=4352 => 4,4 ms
+
+ /* Enable transmit and receive */
+ asm("lda #%%10000001"); //Enable transmit TXENA, PAD_EN
+ asm("sta %w", ETHTCR);
+ asm("lda #%%00000011"); //Enable receive, strip CRC ???
+ asm("sta %w", ETHRCR+1);
+
+ BANK(1);
+ asm("lda %w", ETHCR+1);
+ asm("ora #%%00010000"); //No wait (IOCHRDY)
+ asm("sta %w", ETHCR+1);
+
+ asm("lda #%%00001001"); //Auto release
+ asm("sta %w", ETHCTR+1);
+
+ /* Set MAC address */
+ asm("lda #%b", (unsigned)UIP_ETHADDR0);
+ asm("sta %w", ETHIAR);
+ asm("lda #%b", (unsigned)UIP_ETHADDR1);
+ asm("sta %w", ETHIAR+1);
+ asm("lda #%b", (unsigned)UIP_ETHADDR2);
+ asm("sta %w", ETHIAR+2);
+ asm("lda #%b", (unsigned)UIP_ETHADDR3);
+ asm("sta %w", ETHIAR+3);
+ asm("lda #%b", (unsigned)UIP_ETHADDR4);
+ asm("sta %w", ETHIAR+4);
+ asm("lda #%b", (unsigned)UIP_ETHADDR5);
+ asm("sta %w", ETHIAR+5);
+
+ BANK(2);
+ asm("lda #%%00001111"); //RCV INT, ALLOC INT, TX INT, TX EMPTY
+ asm("sta %w", ETHMSK);
+}
+#pragma optimize(pop)
+
+
+#pragma optimize(push, off)
+#if UIP_BUFSIZE > 255
+u16_t lan91c96_poll(void)
+#else
+u8_t lan91c96_poll(void)
+#endif
+{
+ // #######
+// BANK(0);
+// printf("RAM: %d ", ((*(unsigned int *)ETHMIR) & 0xff00));
+// BANK(2);
+ // #######
+
+ asm("lda %w", ETHIST);
+ asm("and #%%00000001"); //RCV INT
+ asm("bne @L1");
+
+ /* No packet available */
+ return 0;
+
+ asm("@L1:");
+
+ #ifdef DEBUG
+ printf("RCV: IRQ\n");
+ #endif
+
+ asm("lda #0");
+ asm("sta %w", ETHPTR);
+ asm("lda #%%11100000"); //RCV,AUTO INCR.,READ
+ asm("sta %w", ETHPTR+1);
+
+ asm("lda %w", ETHDATA); //Status word
+ asm("lda %w", ETHDATA);
+ asm("sta _packet_status"); //High byte only
+
+ asm("lda %w", ETHDATA); //Total number of bytes
+ asm("sta _packet_length");
+ asm("lda %w", ETHDATA);
+ asm("sta _packet_length+1");
+
+ /* Last word contain 'last data byte' and 0x60 */
+ /* or 'fill byte' and 0x40 */
+
+ packet_length -= 6; //The packet contains 3 extra words
+
+ asm("lda _packet_status");
+ asm("and #$10");
+ asm("beq @L2");
+
+ packet_length++;
+
+ #ifdef DEBUG
+ printf("RCV: odd number of bytes\n");
+ #endif
+
+ asm("@L2:");
+
+ #ifdef DEBUG
+ printf("RCV: L:%d ST-HIGH:0x%02x ",packet_length,packet_status);
+ #endif
+
+ if (packet_length > UIP_BUFSIZE)
+ {
+ /* Remove and release RX packet from FIFO*/
+ asm("lda #%%10000000");
+ asm("sta %w", ETHMMUCR);
+
+ #ifdef DEBUG
+ printf("RCV: UIP_BUFSIZE exceeded - packet dropped!\n");
+ #endif
+
+ return 0;
+ }
+
+ asm("lda #<_uip_buf");
+ asm("sta ptr1");
+ asm("lda #>_uip_buf");
+ asm("sta ptr1+1");
+
+ asm("ldy #0");
+ asm("ldx _packet_length+1");
+ asm("beq @RE1"); //packet_length < 256
+
+ asm("@RL1:");
+ asm("lda %w", ETHDATA);
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("bne @RL1");
+ asm("inc ptr1+1");
+ asm("dex");
+ asm("bne @RL1");
+
+ asm("@RE1:");
+ asm("lda %w", ETHDATA);
+ asm("sta (ptr1),y");
+ asm("iny");
+ asm("cpy _packet_length");
+ asm("bne @RE1");
+
+ /* Remove and release RX packet from FIFO*/
+ asm("lda #%%10000000");
+ asm("sta %w", ETHMMUCR);
+
+ #ifdef DEBUG
+// print_packet(uip_buf, packet_length);
+ #endif
+
+ return packet_length;
+}
+#pragma optimize(pop)
+
+/* First 40+14 (IP nad TCP header) is send from uip_buf */
+/* than data from uip_appdata */
+
+#pragma optimize(push, off)
+void lan91c96_send(void)
+{
+ #ifdef DEBUG
+ printf("SND: send packet\n");
+ #endif
+
+ #if UIP_BUFSIZE > 255
+ asm("lda _uip_len+1");
+ #else
+ asm("lda #0");
+ #endif
+ asm("ora #%%00100000"); //Allocate memory for TX
+ asm("sta %w", ETHMMUCR);
+
+ asm("ldx #8"); //Wait...
+ asm("@L1:"); //Wait for allocation ready
+ asm("lda %w", ETHIST);
+ asm("and #%%00001000"); //ALLOC INT
+ asm("bne @X1");
+ asm("dex");
+ asm("bne @L1");
+
+ #ifdef DEBUG
+ printf("SND: ERR: memory alloc timeout\n");
+ #endif
+
+ return;
+
+ asm("@X1:");
+ #ifdef DEBUG
+ printf("SND: packet memory allocated\n");
+ #endif
+
+ asm("lda #%%00001000"); //Acknowledge int, is it necessary ???
+ asm("sta %w", ETHACK);
+
+ asm("lda %w", ETHARR);
+ asm("sta %w", ETHPNR); //Set packet address
+
+ asm("lda #0");
+ asm("sta %w", ETHPTR);
+ asm("lda #%%01000000"); //AUTO INCR.
+ asm("sta %w", ETHPTR+1);
+
+ #ifdef DEBUG
+ printf("SND: L:%d ", uip_len);
+ #endif
+
+ asm("lda #0"); //Status written by CSMA
+ asm("sta %w", ETHDATA);
+ asm("sta %w", ETHDATA);
+
+ asm("lda _uip_len");
+ asm("and #$01");
+ asm("beq @SD1");
+
+ packet_length=uip_len+5;
+ asm("jmp @LC1");
+
+ asm("@SD1:");
+
+ packet_length=uip_len+6; //+6 for status word, length and ctl byte
+
+ asm("@LC1:");
+
+// printf("SND: L:%d ", packet_length);
+
+ asm("lda _packet_length");
+ asm("sta %w", ETHDATA);
+ asm("lda _packet_length+1");
+ asm("sta %w", ETHDATA);
+
+ #ifdef DEBUG
+// print_packet(uip_buf, uip_len);
+ #endif
+
+ /* Send 40+14=54 bytes of header */
+
+ if(uip_len <= 54) {
+
+ #ifdef DEBUG
+ printf("SND: short packet sent.\n");
+ #endif
+
+ asm("ldx _uip_len");
+ asm("ldy #0");
+ asm("@WL1:");
+ asm("lda _uip_buf,y");
+ asm("sta %w", ETHDATA);
+ asm("iny");
+ asm("dex");
+ asm("bne @WL1");
+
+ } else {
+
+ asm("ldx #54");
+ asm("ldy #0");
+ asm("@WL2:");
+ asm("lda _uip_buf,y");
+ asm("sta %w", ETHDATA);
+ asm("iny");
+ asm("dex");
+ asm("bne @WL2");
+
+ uip_len -= 54;
+
+ asm("lda _uip_appdata"); //uip_appdata is pointer
+ asm("sta ptr1");
+ asm("lda _uip_appdata+1");
+ asm("sta ptr1+1");
+
+ asm("ldy #0");
+ #if UIP_BUFSIZE > 255
+ asm("ldx _uip_len+1");
+ #else
+ asm("ldx #0");
+ #endif
+ asm("beq @RE1"); //packet_length < 256
+
+ asm("@RL1:");
+ asm("lda (ptr1),y");
+ asm("sta %w", ETHDATA);
+ asm("iny");
+ asm("bne @RL1");
+ asm("inc ptr1+1");
+ asm("dex");
+ asm("bne @RL1");
+
+ asm("@RE1:");
+ asm("lda (ptr1),y");
+ asm("sta %w", ETHDATA);
+ asm("iny");
+ asm("cpy _uip_len");
+ asm("bne @RE1");
+
+ }
+
+ asm("lda _uip_len");
+ asm("and #$01");
+ asm("beq @R3");
+
+ asm("lda #%%00100000");
+ asm("sta %w", ETHDATA); //Control byte
+
+ asm("lda #%%11000000"); //ENQUEUE PACKET - transmit packet
+ asm("sta %w", ETHMMUCR);
+
+// printf("\n## %02x", *(unsigned char *)ETHIST);
+
+ return;
+
+ asm("@R3:");
+
+ asm("lda #0");
+ asm("sta %w", ETHDATA); //Fill byte
+ asm("sta %w", ETHDATA); //Control byte
+
+ asm("lda #%%11000000"); //ENQUEUE PACKET - transmit packet
+ asm("sta %w", ETHMMUCR);
+
+// printf("\n## %02x\n", *(unsigned char *)ETHIST);
+ return;
+}
+#pragma optimize(pop)
+
+#ifdef DEBUG
+static void print_packet(u8_t *buf, u16_t length)
+{
+ int i;
+ int remainder;
+ int lines;
+ u8_t a;
+ int cur;
+ int address=0;
+
+ printf("\nPacket of length %d \n", length );
+
+ lines = length / 8;
+ remainder = length % 8;
+
+ for ( i = 0; i < lines ; i ++ ) {
+ printf(":%04x ", address=i*8);
+
+ for ( cur = 0; cur < 8; cur ++ ) {
+ a = *(buf ++ );
+ printf("%02x ", a);
+ }
+ printf("\n");
+ }
+
+ printf(":%04x ", address+8);
+
+ for ( i = 0; i < remainder ; i++ ) {
+ a = *(buf ++ );
+ printf("%02x ", a);
+ }
+ printf("\n");
+}
+#endif /* DEBUG */
+
diff --git a/contiki-cpc/uip/lan91c96.h b/contiki-cpc/uip/lan91c96.h
new file mode 100644
index 0000000..774e182
--- /dev/null
+++ b/contiki-cpc/uip/lan91c96.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * 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>
+ *
+ * $Id: lan91c96.h,v 1.1 2006/04/17 15:02:40 kthacker Exp $
+ */
+
+#ifndef _LAN91C96_H
+#define _LAN91C96_H
+
+#include "uip_arch.h"
+
+void lan91c96_init(void);
+void lan91c96_done(void);
+void lan91c96_send(void);
+#if UIP_BUFSIZE > 255
+u16_t lan91c96_poll(void);
+#else
+u8_t lan91c96_poll(void);
+#endif
+
+/* End of lan91c96.h */
+#endif
+
diff --git a/contiki-cpc/uip/rrnet-drv-asm.S b/contiki-cpc/uip/rrnet-drv-asm.S
new file mode 100644
index 0000000..595c00c
--- /dev/null
+++ b/contiki-cpc/uip/rrnet-drv-asm.S
@@ -0,0 +1,17 @@
+
+;---------------------------------------------------------------------
+ .export _cs8900a_rxtxreg
+ .export _cs8900a_txcmd
+ .export _cs8900a_txlen
+ .export _cs8900a_packetpp
+ .export _cs8900a_ppdata
+
+
+;---------------------------------------------------------------------
+
+ _cs8900a_rxtxreg = $de08
+ _cs8900a_txcmd = $de0c
+ _cs8900a_txlen = $de0e
+ _cs8900a_packetpp = $de02
+ _cs8900a_ppdata = $de04
+
diff --git a/contiki-cpc/uip/rrnet-drv.c b/contiki-cpc/uip/rrnet-drv.c
new file mode 100644
index 0000000..0d800ca
--- /dev/null
+++ b/contiki-cpc/uip/rrnet-drv.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2001-2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: rrnet-drv.c,v 1.1 2006/04/17 15:02:40 kthacker Exp $
+ *
+ */
+
+#include "packet-service.h"
+
+#include "cs8900a.h"
+
+#include "uip_arp.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct uip_eth_addr addr =
+ {{0x00,0x00,0x00,0x64,0x64,0x64}};
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": RR-net", EK_PRIO_NORMAL,
+ eventhandler, pollhandler, (void *)&state);
+
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(rrnet_drv_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ uip_arp_out();
+ cs8900a_send();
+}
+/*---------------------------------------------------------------------------*/
+#pragma optimize(push, off)
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ uip_setethaddr(addr);
+ asm("lda #1");
+ asm("ora $de01");
+ asm("sta $de01");
+ cs8900a_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ek_replace((struct ek_proc *)data, NULL);
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ek_exit();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+#pragma optimize(pop)
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+
+ /* Poll Ethernet device to see if there is a frame avaliable. */
+ uip_len = cs8900a_poll();
+ if(uip_len > 0) {
+ /* A frame was avaliable (and is now read into the uip_buf), so
+ we process it. */
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+ uip_arp_ipin();
+ uip_len -= sizeof(struct uip_eth_hdr);
+ tcpip_input();
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin();
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if(uip_len > 0) {
+ cs8900a_send();
+ }
+ }
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/rrnet-dsc.c b/contiki-cpc/uip/rrnet-dsc.c
new file mode 100644
index 0000000..b8f6875
--- /dev/null
+++ b/contiki-cpc/uip/rrnet-dsc.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 desktop environment
+ *
+ * $Id: rrnet-dsc.c,v 1.1 2006/04/17 15:02:40 kthacker Exp $
+ *
+ */
+
+#include "dsc.h"
+
+extern struct ctk_icon rrnet_icon;
+/*-----------------------------------------------------------------------------------*/
+DSC(rrnet_dsc,
+ "RR-Net driver",
+ "rrnet.drv",
+ rrnet_init,
+ &rrnet_icon);
+/*-----------------------------------------------------------------------------------*/
+#if CTK_CONF_ICON_BITMAPS
+static unsigned char rrneticon_bitmap[3*3*8] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+};
+#endif /* CTK_CONF_ICON_BITMAPS */
+
+#if CTK_CONF_ICON_TEXTMAPS
+static char rrneticon_textmap[9] = {
+ 'R', 'R', '-',
+ 'N', 'e', 't',
+ 'D', 'R', 'V'
+};
+#endif /* CTK_CONF_ICON_TEXTMAPS */
+
+static struct ctk_icon rrnet_icon =
+ {CTK_ICON("RR-Net driver", rrneticon_bitmap, rrneticon_textmap)};
+/*-----------------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/rrnet-dump-drv.c b/contiki-cpc/uip/rrnet-dump-drv.c
new file mode 100644
index 0000000..4748cde
--- /dev/null
+++ b/contiki-cpc/uip/rrnet-dump-drv.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2001-2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: rrnet-dump-drv.c,v 1.1 2006/04/17 15:02:40 kthacker Exp $
+ *
+ */
+
+#include "packet-service.h"
+
+#include "cs8900a.h"
+
+#include "uip_arp.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct uip_eth_addr addr =
+ {{0x00,0x00,0x00,0x64,0x64,0x64}};
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": RR-net", EK_PRIO_NORMAL,
+ eventhandler, pollhandler, (void *)&state);
+
+#include "tcpdump.h"
+#include <string.h>
+#include "ctk.h"
+
+#define DUMP_WIDTH 38
+#define DUMP_HEIGHT 20
+static struct ctk_window window;
+static char dump[DUMP_WIDTH * DUMP_HEIGHT];
+static struct ctk_label dumplabel =
+ {CTK_LABEL(0, 0, DUMP_WIDTH, DUMP_HEIGHT, dump)};
+static void
+dump_packet(void)
+{
+ memcpy(dump, &dump[DUMP_WIDTH], DUMP_WIDTH * (DUMP_HEIGHT - 1));
+ tcpdump_print(&dump[DUMP_WIDTH * (DUMP_HEIGHT - 1)], DUMP_WIDTH);
+ CTK_WIDGET_REDRAW(&dumplabel);
+}
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(rrnet_dump_drv_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ uip_arp_out();
+ cs8900a_send();
+ dump_packet();
+}
+/*---------------------------------------------------------------------------*/
+#pragma optimize(push, off)
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ ctk_window_new(&window, DUMP_WIDTH, DUMP_HEIGHT, "RR-Net dump");
+ CTK_WIDGET_ADD(&window, &dumplabel);
+ ctk_window_open(&window);
+ uip_setethaddr(addr);
+ asm("lda #1");
+ asm("ora $de01");
+ asm("sta $de01");
+ cs8900a_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ctk_window_close(&window);
+ ek_replace((struct ek_proc *)data, NULL);
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ctk_window_close(&window);
+ ek_exit();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+#pragma optimize(pop)
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+
+ /* Poll Ethernet device to see if there is a frame avaliable. */
+ uip_len = cs8900a_poll();
+ if(uip_len > 0) {
+ dump_packet();
+ /* A frame was avaliable (and is now read into the uip_buf), so
+ we process it. */
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+ uip_arp_ipin();
+ uip_len -= sizeof(struct uip_eth_hdr);
+ tcpip_input();
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin();
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if(uip_len > 0) {
+ cs8900a_send();
+ }
+ }
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/rs232dev-ss.c b/contiki-cpc/uip/rs232dev-ss.c
new file mode 100644
index 0000000..7800bb1
--- /dev/null
+++ b/contiki-cpc/uip/rs232dev-ss.c
@@ -0,0 +1,248 @@
+/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: rs232dev-ss.c,v 1.1 2006/04/17 15:02:41 kthacker Exp $
+ *
+ */
+
+/*
+ * This is a generic implementation of the SLIP protocol over an RS232
+ * (serial) device. While initially intented for the C64, the code can
+ * easily be ported to other platforms as well.
+ *
+ * Huge thanks to Ullrich von Bassewitz <uz@cc65.org> of cc65 fame for
+ * and endless supply of bugfixes, insightsful comments and
+ * suggestions, and improvements to this code!
+ */
+
+#include "rs232silversurfer.h"
+#include <time.h>
+#include <string.h>
+
+ /* This will include the system specific header files as well */
+#if defined(__CBM__)
+# include <cbm.h>
+#elif defined(__ATARI__)
+# include <atari.h>
+#endif
+
+#include "uip.h"
+
+#define SLIP_END 0300
+#define SLIP_ESC 0333
+#define SLIP_ESC_END 0334
+#define SLIP_ESC_ESC 0335
+
+
+#define SIO_RECV(c) while(rs232_get(&c) == RS_ERR_NO_DATA)
+#define SIO_POLL(c) (rs232_get(&c) != RS_ERR_NO_DATA)
+#define SIO_SEND(c) while(rs232_put(c) == RS_ERR_OVERFLOW)
+
+#define MAX_SIZE (UIP_BUFSIZE - UIP_LLH_LEN)
+
+static u8_t slip_buf[MAX_SIZE + 2];
+
+#if MAX_SIZE > 255
+static u16_t len, tmplen;
+#else
+static u8_t len, tmplen;
+#endif /* MAX_SIZE > 255 */
+
+#if 1
+#define printf(x)
+#else
+#include <stdio.h>
+#endif
+
+
+/*-----------------------------------------------------------------------------------*/
+static void
+rs232_err(char err)
+{
+ switch(err) {
+ case RS_ERR_OK:
+ printf("RS232 OK\n");
+ break;
+ case RS_ERR_NOT_INITIALIZED:
+ printf("RS232 not initialized\n");
+ break;
+ case RS_ERR_BAUD_TOO_FAST:
+ printf("RS232 baud too fast\n");
+ break;
+ case RS_ERR_BAUD_NOT_AVAIL:
+ printf("RS232 baud rate not available\n");
+ break;
+ case RS_ERR_NO_DATA:
+ printf("RS232 nothing to read\n");
+ break;
+ case RS_ERR_OVERFLOW:
+ printf("RS232 overflow\n");
+ break;
+ }
+
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_send():
+ *
+ * Sends the packet in the uip_buf and uip_appdata buffers. The first
+ * 40 bytes of the packet (the IP and TCP headers) are read from the
+ * uip_buf buffer, and the following bytes (the application data) are
+ * read from the uip_appdata buffer.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+rs232dev_send(void)
+{
+#if MAX_SIZE > 255
+ u16_t i;
+#else
+ u8_t i;
+#endif /* MAX_SIZE > 255 */
+ u8_t *ptr;
+ u8_t c;
+
+ SIO_SEND(SLIP_END);
+
+ ptr = &uip_buf[UIP_LLH_LEN];
+ for(i = 0; i < uip_len; ++i) {
+ if(i == 40) {
+ ptr = uip_appdata;
+ }
+ c = *ptr++;
+ switch(c) {
+ case SLIP_END:
+ SIO_SEND(SLIP_ESC);
+ SIO_SEND(SLIP_ESC_END);
+ break;
+ case SLIP_ESC:
+ SIO_SEND(SLIP_ESC);
+ SIO_SEND(SLIP_ESC_ESC);
+ break;
+ default:
+ SIO_SEND(c);
+ break;
+ }
+ }
+ SIO_SEND(SLIP_END);
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_poll():
+ *
+ * Read all avaliable bytes from the RS232 interface into the slip_buf
+ * buffer. If no more bytes are avaliable, it returns with 0 to
+ * indicate that no packet was immediately ready. When a full packet
+ * has been read into the buffer, the packet is copied into the
+ * uip_buf buffer and the length of the packet is returned.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+#if MAX_SIZE > 255
+u16_t
+#else
+u8_t
+#endif /* MAX_SIZE > 255 */
+rs232dev_poll(void)
+{
+ u8_t c;
+ static u8_t lastc;
+
+ while(SIO_POLL(c)) {
+ /* printf("c %x\n", c);*/
+ switch(c) {
+ case SLIP_ESC:
+ lastc = c;
+ break;
+
+ case SLIP_END:
+ lastc = c;
+ /* End marker found, we copy our input buffer to the uip_buf
+ buffer and return the size of the packet we copied. */
+ memcpy(&uip_buf[UIP_LLH_LEN], slip_buf, len);
+ tmplen = len;
+ len = 0;
+ return tmplen;
+
+ default:
+ if(lastc == SLIP_ESC) {
+ lastc = c;
+ /* Previous read byte was an escape byte, so this byte will be
+ interpreted differently from others. */
+ switch(c) {
+ case SLIP_ESC_END:
+ c = SLIP_END;
+ break;
+ case SLIP_ESC_ESC:
+ c = SLIP_ESC;
+ break;
+ }
+ } else {
+ lastc = c;
+ }
+
+
+ slip_buf[len] = c;
+ ++len;
+
+ if(len > MAX_SIZE) {
+ len = 0;
+ }
+
+ break;
+ }
+ }
+ return 0;
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_init():
+ *
+ * Initializes the RS232 device and sets the parameters of the device.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+rs232dev_init(void)
+{
+ char err;
+
+ err = rs232_init(0);
+ rs232_err(err);
+ err = rs232_params(RS_BAUD_9600 | RS_BITS_8 | RS_STOP_1, RS_PAR_NONE);
+ rs232_err(err);
+
+ len = 0;
+
+ return;
+}
+/*-----------------------------------------------------------------------------------*/
+
diff --git a/contiki-cpc/uip/rs232dev.c b/contiki-cpc/uip/rs232dev.c
new file mode 100644
index 0000000..2e2db52
--- /dev/null
+++ b/contiki-cpc/uip/rs232dev.c
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: rs232dev.c,v 1.1 2006/04/17 15:02:41 kthacker Exp $
+ *
+ */
+
+/*
+ * This is a generic implementation of the SLIP protocol over an RS232
+ * (serial) device. While initially intented for the C64, the code can
+ * easily be ported to other platforms as well.
+ *
+ * Huge thanks to Ullrich von Bassewitz <uz@cc65.org> of cc65 fame for
+ * and endless supply of bugfixes, insightsful comments and
+ * suggestions, and improvements to this code!
+ */
+
+#include <serial.h>
+#include <time.h>
+#include <string.h>
+
+ /* This will include the system specific header files as well */
+#if defined(__CBM__)
+# include <cbm.h>
+#elif defined(__ATARI__)
+# include <atari.h>
+#endif
+
+#include "uip.h"
+
+#define SLIP_END 0300
+#define SLIP_ESC 0333
+#define SLIP_ESC_END 0334
+#define SLIP_ESC_ESC 0335
+
+
+#define SIO_RECV(c) while(ser_get(&c) == SER_ERR_NO_DATA)
+#define SIO_POLL(c) (ser_get(&c) != SER_ERR_NO_DATA)
+#define SIO_SEND(c) ser_put(c)
+
+#define MAX_SIZE (UIP_BUFSIZE - UIP_LLH_LEN)
+
+static u8_t slip_buf[MAX_SIZE + 2];
+
+static u16_t len, tmplen;
+
+static char loaded = 0;
+
+#if 1
+#define printf(x)
+#else
+#include <stdio.h>
+#endif
+
+
+/*-----------------------------------------------------------------------------------*/
+/*static void
+rs232_err(char err)
+{
+ switch(err) {
+ case RS_ERR_OK:
+ printf("RS232 OK\n");
+ break;
+ case RS_ERR_NOT_INITIALIZED:
+ printf("RS232 not initialized\n");
+ break;
+ case RS_ERR_BAUD_TOO_FAST:
+ printf("RS232 baud too fast\n");
+ break;
+ case RS_ERR_BAUD_NOT_AVAIL:
+ printf("RS232 baud rate not available\n");
+ break;
+ case RS_ERR_NO_DATA:
+ printf("RS232 nothing to read\n");
+ break;
+ case RS_ERR_OVERFLOW:
+ printf("RS232 overflow\n");
+ break;
+ }
+}*/
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_send():
+ *
+ * Sends the packet in the uip_buf and uip_appdata buffers. The first
+ * 40 bytes of the packet (the IP and TCP headers) are read from the
+ * uip_buf buffer, and the following bytes (the application data) are
+ * read from the uip_appdata buffer.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+rs232dev_send(void)
+{
+ u16_t i;
+ u8_t *ptr;
+ u8_t c;
+
+ SIO_SEND(SLIP_END);
+
+ ptr = &uip_buf[UIP_LLH_LEN];
+ for(i = 0; i < uip_len; ++i) {
+ if(i == 40) {
+ ptr = uip_appdata;
+ }
+ c = *ptr++;
+ switch(c) {
+ case SLIP_END:
+ SIO_SEND(SLIP_ESC);
+ SIO_SEND(SLIP_ESC_END);
+ break;
+ case SLIP_ESC:
+ SIO_SEND(SLIP_ESC);
+ SIO_SEND(SLIP_ESC_ESC);
+ break;
+ default:
+ SIO_SEND(c);
+ break;
+ }
+ }
+ SIO_SEND(SLIP_END);
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_poll():
+ *
+ * Read all avaliable bytes from the RS232 interface into the slip_buf
+ * buffer. If no more bytes are avaliable, it returns with 0 to
+ * indicate that no packet was immediately ready. When a full packet
+ * has been read into the buffer, the packet is copied into the
+ * uip_buf buffer and the length of the packet is returned.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+u16_t
+rs232dev_poll(void)
+{
+ u8_t c;
+ static u8_t lastc;
+
+ if(loaded == 0) {
+ return 0;
+ }
+
+ while(SIO_POLL(c)) {
+
+ switch(c) {
+ case SLIP_ESC:
+ lastc = c;
+ break;
+
+ case SLIP_END:
+ lastc = c;
+ /* End marker found, we copy our input buffer to the uip_buf
+ buffer and return the size of the packet we copied. */
+ memcpy(&uip_buf[UIP_LLH_LEN], slip_buf, len);
+ tmplen = len;
+ len = 0;
+ return tmplen;
+
+ default:
+ if(lastc == SLIP_ESC) {
+ lastc = c;
+ /* Previous read byte was an escape byte, so this byte will be
+ interpreted differently from others. */
+ switch(c) {
+ case SLIP_ESC_END:
+ c = SLIP_END;
+ break;
+ case SLIP_ESC_ESC:
+ c = SLIP_ESC;
+ break;
+ }
+ } else {
+ lastc = c;
+ }
+
+ slip_buf[len] = c;
+ ++len;
+
+ if(len > MAX_SIZE) {
+ len = 0;
+ }
+
+ break;
+ }
+ }
+ return 0;
+}
+/*-----------------------------------------------------------------------------------*/
+/*
+ * rs232dev_init():
+ *
+ * Initializes the RS232 device and sets the parameters of the device.
+ *
+ */
+/*-----------------------------------------------------------------------------------*/
+void
+rs232dev_init(void)
+{
+ char err;
+ struct ser_params p;
+
+ err = ser_load_driver("c64-swlink.ser");
+
+ if(err != SER_ERR_OK) {
+ asm("inc $d020");
+ return;
+ }
+
+ p.baudrate = SER_BAUD_9600;
+ p.databits = SER_BITS_8;
+ p.stopbits = SER_STOP_1;
+ p.parity = SER_PAR_NONE;
+ p.handshake = SER_HS_HW;
+
+ err = ser_open(&p);
+
+ if(err != SER_ERR_OK) {
+ asm("inc $d020");
+ return;
+ }
+
+
+ loaded = 1;
+
+ /* err = rs232_init(0); */
+ /* rs232_err(err);*/
+ /* err = rs232_params(RS_BAUD_9600 | RS_BITS_8 | RS_STOP_1, RS_PAR_NONE);*/
+ /* rs232_err(err);*/
+
+ len = 0;
+
+ return;
+}
+/*-----------------------------------------------------------------------------------*/
+void
+rs232dev_unload(void)
+{
+ if(loaded){
+ ser_unload();
+ }
+}
+/*-----------------------------------------------------------------------------------*/
+
diff --git a/contiki-cpc/uip/rs232dev.h b/contiki-cpc/uip/rs232dev.h
new file mode 100644
index 0000000..af71b33
--- /dev/null
+++ b/contiki-cpc/uip/rs232dev.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: rs232dev.h,v 1.1 2006/04/17 15:02:41 kthacker Exp $
+ *
+ */
+
+#ifndef __RS232DEV_H__
+#define __RS232DEV_H__
+
+#include "uip.h"
+
+void rs232dev_init(void);
+u8_t rs232dev_read(void);
+void rs232dev_send(void);
+
+u16_t rs232dev_poll(void);
+
+void rs232dev_unload(void);
+
+#endif /* __RS232DEV_H__ */
diff --git a/contiki-cpc/uip/rs232silversurfer.S b/contiki-cpc/uip/rs232silversurfer.S
new file mode 100644
index 0000000..89bbf9d
--- /dev/null
+++ b/contiki-cpc/uip/rs232silversurfer.S
@@ -0,0 +1,329 @@
+ ;; The following code is written and is copyrighted by
+ ;; Groepaz/Hitmen
+
+ ;; Small changes by Adam Dunkels (renamed ss232 -> rs232)
+
+;----------------------------------------------------------------------------------------------
+; silver surfer polling mode driver for cc65
+; - work from here to create a full featured driver with interupts.
+; gpz fixed 20020828: fatal bug fixed in _rs232_params
+;----------------------------------------------------------------------------------------------
+
+rs16550base = $de08
+
+fifo_rxd = rs16550base+$00 ;8 (r)
+fifo_txd = rs16550base+$00 ;8 (w)
+
+fifo_dll = rs16550base+$00 ;8 (r/w)
+fifo_dlm = rs16550base+$01 ;9 (r/w)
+
+fifo_ier = rs16550base+$01 ;9
+
+fifo_fcr = rs16550base+$02 ;a (w)
+fifo_iir = rs16550base+$02 ;a (r)
+fifo_lcr = rs16550base+$03 ;b
+fifo_mcr = rs16550base+$04 ;c
+fifo_lsr = rs16550base+$05 ;d
+fifo_msr = rs16550base+$06 ;e (r)
+fifo_scratch = rs16550base+$07 ;f (r/w)
+
+
+
+ .export _rs232_init
+ .export _rs232_done
+ .export _rs232_params
+ .export _rs232_put
+ .export _rs232_get
+
+ .importzp ptr1, ptr2
+ .import popa, popax
+
+;----------------------------------------------------------------------------------------------
+; Error codes. Beware: The codes must match the codes in the C header file
+
+ErrNotInitialized = $01
+ErrBaudTooFast = $02
+ErrBaudNotAvail = $03
+ErrNoData = $04
+ErrOverflow = $05
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_init (char hacked);
+;/* Initialize the serial port, install the interrupt handler. The parameter
+; * has no effect for now and should be set to 0.
+; */
+;----------------------------------------------------------------------------------------------
+
+ .code
+
+_rs232_init:
+ ; enable ssurfer-port
+ lda $de01
+ ora #$01
+ sta $de01
+
+ ; disable nmi's from ssurfer
+ lda #%00000000
+ sta fifo_ier
+
+ ; activate dtr
+ lda #%00000001
+ sta fifo_mcr
+
+ lda #$00 ; ok
+ tax
+ rts
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_done (void);
+;/* Close the port, deinstall the interrupt hander. You MUST call this function
+; * before terminating the program, otherwise the machine may crash later. If
+; * in doubt, install an exit handler using atexit(). The function will do
+; * nothing, if it was already called.
+; */
+;----------------------------------------------------------------------------------------------
+
+_rs232_done:
+ ; disable nmi's from ssurfer
+ lda #%00000000
+ sta fifo_ier
+
+ ; deactivate dtr
+ sta fifo_mcr
+
+ ; disable ssurfer-port
+ lda $de01
+ and #$fe
+ sta $de01
+
+ lda #$00 ; ok
+ tax
+ rts
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
+;/* Set the port parameters. Use a combination of the #defined values above. */
+;----------------------------------------------------------------------------------------------
+
+ .data
+
+_rs232_baudrates:
+
+ .word (7372800 / ( 50 * 16))
+ .word (7372800 / ( 110 * 16))
+ .word (7372800 / ( 269 * 8))
+ .word (7372800 / ( 300 * 16))
+ .word (7372800 / ( 600 * 16))
+ .word (7372800 / ( 1200 * 16))
+ .word (7372800 / ( 2400 * 16))
+ .word (7372800 / ( 4800 * 16))
+ .word (7372800 / ( 9600 * 16))
+ .word (7372800 / ( 19200 * 16))
+ .word (7372800 / ( 38400 * 16))
+ .word (7372800 / ( 57600 * 16))
+ .word (7372800 / ( 115200 * 16))
+ .word (7372800 / ( 230400 * 16))
+
+ .bss
+
+_rs232_tmp1:
+ .res 1
+
+ .code
+
+_rs232_params:
+
+ sta _rs232_tmp1 ; save parity
+
+ ; reset fifo
+ lda #%10000111
+ sta fifo_fcr
+
+ ; that delay thing really needed ?!
+ ; (original datasheet mentions a delay here)
+ ; ldy #$00
+ ; dey
+ ; bny *-1
+
+ ; set dlab
+ lda #%10000011 ; we assmume 8n1
+ sta fifo_lcr
+
+ jsr popa
+ tay ; save param
+
+ ; set baudrate
+ clc
+ lsr a
+ lsr a
+ lsr a
+ lsr a
+ asl a
+ tax
+ lda _rs232_baudrates,x
+ sta fifo_dll
+ lda _rs232_baudrates+1,x
+ sta fifo_dlm
+
+ tya ; param
+ and #$0f
+ ora _rs232_tmp1 ; parity
+
+ ; reset dlab
+ sta fifo_lcr
+
+ lda #$00 ; ok
+ tax
+ rts
+
+;----------------------------------------------------------------------------------------------
+; check if byte available, returns AKKU=0 if none
+
+ss_getlsr:
+ lda fifo_lsr
+ and #$01
+ rts
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_get (char* b);
+;/* Get a character from the serial port. If no characters are available, the
+; * function will return RS_ERR_NO_DATA, so this is not a fatal error.
+; */
+;----------------------------------------------------------------------------------------------
+; get byte (non blocking, returns byte in A or CARRY=1 - error)
+
+_rs232_get:
+ sta ptr1
+ stx ptr1+1
+
+ jsr ss_getlsr ; check if byte available
+; bne sk32 ; yes
+ bne sk33 ; yes
+
+ ; activate rts
+ lda #%00000011
+ sta fifo_mcr
+sk32:
+
+ ; deactivate rts
+; lda #%00000001
+; sta fifo_mcr
+
+ jsr ss_getlsr ; check if byte available
+ bne sk33 ; yes
+
+ ; deactivate rts
+ lda #%00000001
+ sta fifo_mcr
+
+ lda #ErrNoData ; no data
+ ldx #0
+ rts
+sk33:
+ ; deactivate rts
+ lda #%00000001
+ sta fifo_mcr
+
+ ; get byte
+ ldy #$00
+ lda fifo_rxd
+ sta (ptr1),y
+
+ lda #0 ; ok
+ tax
+ rts
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_put (char b);
+;/* Send a character via the serial port. There is a transmit buffer, but
+; * transmitting is not done via interrupt. The function returns
+; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
+; */
+;----------------------------------------------------------------------------------------------
+
+_rs232_put:
+ tax
+ ; transmit buf ready?
+ lda fifo_lsr
+ and #%00100000
+ bne @sk1
+@sk2:
+ lda #ErrOverflow ; overflow
+ ldx #$00
+ rts
+@sk1:
+ ; reciever ready?
+ lda fifo_msr
+ and #%00010000
+ beq @sk2
+
+ stx fifo_txd
+
+ lda #$00 ; ok
+ tax
+ rts
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_pause (void);
+;/* Assert flow control and disable interrupts. */
+;----------------------------------------------------------------------------------------------
+
+_rs232_pause:
+ ; activate rts
+ lda #%00000011
+ sta fifo_mcr
+
+ lda #$00 ; ok
+ tax
+ rts
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_unpause (void);
+;/* Re-enable interrupts and release flow control */
+;----------------------------------------------------------------------------------------------
+
+_rs232_unpause:
+ ; deactivate rts
+ lda #%00000001
+ sta fifo_mcr
+
+ lda #$00 ; ok
+ tax
+ rts
+
+;----------------------------------------------------------------------------------------------
+;unsigned char __fastcall__ rs232_status (unsigned char* status,
+; unsigned char* errors);
+;/* Return the serial port status. */
+;----------------------------------------------------------------------------------------------
+
+_rs232_status:
+ sta ptr2
+ stx ptr2+1
+ jsr popax
+ sta ptr1
+ stx ptr1+1
+
+ ldy #$00
+
+ ; Get status
+ lda fifo_iir
+ and #%00000001
+ sta _rs232_tmp1
+ lda fifo_msr
+ lsr a
+ and #%01010000
+ ora _rs232_tmp1
+ sta _rs232_tmp1
+ lda fifo_lsr
+ and #%00101110
+ ora _rs232_tmp1
+ sta (ptr1),y
+
+ ; Get errors
+ lda #$00 ; ok
+ sta (ptr2),y
+
+ lda #$00 ; ok
+ tax
+ rts
diff --git a/contiki-cpc/uip/rs232silversurfer.h b/contiki-cpc/uip/rs232silversurfer.h
new file mode 100644
index 0000000..9e9a49f
--- /dev/null
+++ b/contiki-cpc/uip/rs232silversurfer.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2003, Groepaz/Hitmen.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ * rs232silversurfer.h
+ *
+ * Groepaz/Hitmen, 16.12.2001
+ *
+ * This defines for the SilverSurver (16c550 UART) what Ullrichs rs232 module
+ * defines for the Swithlink/Turbo232
+ *
+ * this driver operates in polling mode only atm !
+ *
+ */
+
+#ifndef _RS232silversurfer_H
+#define _RS232silversurfer_H
+
+/*****************************************************************************/
+/* Data */
+/*****************************************************************************/
+
+/* Baudrate settings */
+#define RS_BAUD_50 0x00
+#define RS_BAUD_110 0x10
+#define RS_BAUD_134_5 0x20
+#define RS_BAUD_300 0x30
+#define RS_BAUD_600 0x40
+#define RS_BAUD_1200 0x50
+#define RS_BAUD_2400 0x60
+#define RS_BAUD_4800 0x70
+#define RS_BAUD_9600 0x80
+#define RS_BAUD_19200 0x90
+#define RS_BAUD_38400 0xa0
+#define RS_BAUD_57600 0xb0
+#define RS_BAUD_115200 0xc0
+#define RS_BAUD_230400 0xd0
+
+/* Stop bit settings */
+#define RS_STOP_1 0x00
+#define RS_STOP_2 0x04
+
+/* Data bit settings */
+#define RS_BITS_5 0x00
+#define RS_BITS_6 0x01
+#define RS_BITS_7 0x02
+#define RS_BITS_8 0x03
+
+/* Parity settings */
+#define RS_PAR_NONE 0x00
+#define RS_PAR_ODD 0x28
+#define RS_PAR_EVEN 0x38
+#define RS_PAR_MARK 0x48
+#define RS_PAR_SPACE 0x48
+
+/* Bit masks to mask out things from the status returned by rs232_status */
+#define RS_STATUS_IRQ 0x01 /* (iir) IRQ condition */
+#define RS_STATUS_OVERRUN 0x02 /* (lsr) Overrun error */
+#define RS_STATUS_PE 0x04 /* (lsr) Parity error */
+#define RS_STATUS_FE 0x08 /* (lsr) Framing error */
+#define RS_STATUS_DSR 0x10 /* (msr>>1) NOT data set ready */
+#define RS_STATUS_THRE 0x20 /* (lsr) Transmit holding reg. empty */
+#define RS_STATUS_DCD 0x40 /* (msr>>1) NOT data carrier detect */
+#define RS_STATUS_RDRF 0x80 /* Receiver data register full */
+
+/* Error codes returned by all functions */
+#define RS_ERR_OK 0x00 /* Not an error - relax */
+#define RS_ERR_NOT_INITIALIZED 0x01 /* Module not initialized */
+#define RS_ERR_BAUD_TOO_FAST 0x02 /* Cannot handle baud rate */
+#define RS_ERR_BAUD_NOT_AVAIL 0x03 /* Baud rate not available */
+#define RS_ERR_NO_DATA 0x04 /* Nothing to read */
+#define RS_ERR_OVERFLOW 0x05 /* No room in send buffer */
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+unsigned char __fastcall__ rs232_init (char hacked);
+/* Initialize the serial port, install the interrupt handler. The parameter
+ * has no effect for now and should be set to 0.
+ */
+
+unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
+/* Set the port parameters. Use a combination of the #defined values above. */
+
+unsigned char __fastcall__ rs232_done (void);
+/* Close the port, deinstall the interrupt hander. You MUST call this function
+ * before terminating the program, otherwise the machine may crash later. If
+ * in doubt, install an exit handler using atexit(). The function will do
+ * nothing, if it was already called.
+ */
+
+unsigned char __fastcall__ rs232_get (char* b);
+/* Get a character from the serial port. If no characters are available, the
+ * function will return RS_ERR_NO_DATA, so this is not a fatal error.
+ */
+
+unsigned char __fastcall__ rs232_put (char b);
+/* Send a character via the serial port. There is a transmit buffer, but
+ * transmitting is not done via interrupt. The function returns
+ * RS_ERR_OVERFLOW if there is no space left in the transmit buffer.
+ */
+
+unsigned char __fastcall__ rs232_pause (void);
+/* Assert flow control and disable interrupts. */
+
+unsigned char __fastcall__ rs232_unpause (void);
+/* Re-enable interrupts and release flow control */
+
+unsigned char __fastcall__ rs232_status (unsigned char* status,
+ unsigned char* errors);
+/* Return the serial port status. */
+
+/* End of rs232silversurfer.h */
+#endif
+
+
+
diff --git a/contiki-cpc/uip/slip-drv.c b/contiki-cpc/uip/slip-drv.c
new file mode 100644
index 0000000..4eb0205
--- /dev/null
+++ b/contiki-cpc/uip/slip-drv.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
+ *
+ * $Id: slip-drv.c,v 1.1 2006/04/17 15:02:42 kthacker Exp $
+ *
+ */
+
+#include "contiki.h"
+#include "rs232dev.h"
+
+#include "packet-service.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": SLIP", EK_PRIO_HIGH,
+ eventhandler, pollhandler, (void *)&state);
+
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(tapdev_service_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ rs232dev_send();
+}
+/*---------------------------------------------------------------------------*/
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ rs232dev_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ek_replace((struct ek_proc *)data, NULL);
+ rs232dev_unload();
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ek_exit();
+ rs232dev_unload();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+ uip_len = rs232dev_poll();
+ if(uip_len > 0) {
+ tcpip_input();
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/slip-dsc.c b/contiki-cpc/uip/slip-dsc.c
new file mode 100644
index 0000000..60b0fc5
--- /dev/null
+++ b/contiki-cpc/uip/slip-dsc.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 desktop environment
+ *
+ * $Id: slip-dsc.c,v 1.1 2006/04/17 15:02:42 kthacker Exp $
+ *
+ */
+
+#include "dsc.h"
+
+extern struct ctk_icon slip_icon;
+/*-----------------------------------------------------------------------------------*/
+DSC(slip_dsc,
+ "SLIP driver",
+ "slip.drv",
+ slip_init,
+ &slip_icon);
+/*-----------------------------------------------------------------------------------*/
+#if CTK_CONF_ICON_BITMAPS
+static unsigned char slipicon_bitmap[3*3*8] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+};
+#endif /* CTK_CONF_ICON_BITMAPS */
+
+#if CTK_CONF_ICON_TEXTMAPS
+static char slipicon_textmap[9] = {
+ 'R', 'S', ' ',
+ '2', '3', '2',
+ '/', 'I', 'P'
+};
+#endif /* CTK_CONF_ICON_TEXTMAPS */
+
+static struct ctk_icon slip_icon =
+ {CTK_ICON("SLIP driver", slipicon_bitmap, slipicon_textmap)};
+/*-----------------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/slip-dump-drv.c b/contiki-cpc/uip/slip-dump-drv.c
new file mode 100644
index 0000000..63b4def
--- /dev/null
+++ b/contiki-cpc/uip/slip-dump-drv.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
+ *
+ * $Id: slip-dump-drv.c,v 1.1 2006/04/17 15:02:42 kthacker Exp $
+ *
+ */
+
+#include "contiki.h"
+#include "rs232dev.h"
+
+#include "packet-service.h"
+
+#include "tcpdump.h"
+#include <string.h>
+#include "ctk.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": SLIP", EK_PRIO_HIGH,
+ eventhandler, pollhandler, (void *)&state);
+
+#define DUMP_WIDTH 38
+#define DUMP_HEIGHT 20
+static struct ctk_window window;
+static char dump[DUMP_WIDTH * DUMP_HEIGHT];
+static struct ctk_label dumplabel =
+ {CTK_LABEL(0, 0, DUMP_WIDTH, DUMP_HEIGHT, dump)};
+static void
+dump_packet(void)
+{
+ memcpy(dump, &dump[DUMP_WIDTH], DUMP_WIDTH * (DUMP_HEIGHT - 1));
+ tcpdump_print(&dump[DUMP_WIDTH * (DUMP_HEIGHT - 1)], DUMP_WIDTH);
+ CTK_WIDGET_REDRAW(&dumplabel);
+}
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(slip_service_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ rs232dev_send();
+ dump_packet();
+}
+/*---------------------------------------------------------------------------*/
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ ctk_window_new(&window, DUMP_WIDTH, DUMP_HEIGHT, "SLIP dump");
+ CTK_WIDGET_ADD(&window, &dumplabel);
+ ctk_window_open(&window);
+ rs232dev_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ctk_window_close(&window);
+ ek_replace((struct ek_proc *)data, NULL);
+ rs232dev_unload();
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ctk_window_close(&window);
+ ek_exit();
+ rs232dev_unload();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+ uip_len = rs232dev_poll();
+ if(uip_len > 0) {
+ dump_packet();
+ tcpip_input();
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/tfe-drv-asm.S b/contiki-cpc/uip/tfe-drv-asm.S
new file mode 100644
index 0000000..d31c320
--- /dev/null
+++ b/contiki-cpc/uip/tfe-drv-asm.S
@@ -0,0 +1,17 @@
+
+;---------------------------------------------------------------------
+ .export _cs8900a_rxtxreg
+ .export _cs8900a_txcmd
+ .export _cs8900a_txlen
+ .export _cs8900a_packetpp
+ .export _cs8900a_ppdata
+
+
+;---------------------------------------------------------------------
+
+ _cs8900a_rxtxreg = $de00
+ _cs8900a_txcmd = $de04
+ _cs8900a_txlen = $de06
+ _cs8900a_packetpp = $de0a
+ _cs8900a_ppdata = $de0c
+
diff --git a/contiki-cpc/uip/tfe-drv.c b/contiki-cpc/uip/tfe-drv.c
new file mode 100644
index 0000000..d7255b0
--- /dev/null
+++ b/contiki-cpc/uip/tfe-drv.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2001-2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: tfe-drv.c,v 1.1 2006/04/17 15:02:42 kthacker Exp $
+ *
+ */
+
+#include "packet-service.h"
+
+#include "cs8900a.h"
+
+#include "uip_arp.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct uip_eth_addr addr =
+ {{0x00,0x0d,0x60,0x64,0x64,0x64}};
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": TFE", EK_PRIO_NORMAL,
+ eventhandler, pollhandler, (void *)&state);
+
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(tfe_drv_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ uip_arp_out();
+ cs8900a_send();
+}
+/*---------------------------------------------------------------------------*/
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ uip_setethaddr(addr);
+ cs8900a_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ek_replace((struct ek_proc *)data, NULL);
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ek_exit();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+
+ /* Poll Ethernet device to see if there is a frame avaliable. */
+ uip_len = cs8900a_poll();
+ if(uip_len > 0) {
+ /* A frame was avaliable (and is now read into the uip_buf), so
+ we process it. */
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+ uip_arp_ipin();
+ uip_len -= sizeof(struct uip_eth_hdr);
+ tcpip_input();
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin();
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if(uip_len > 0) {
+ cs8900a_send();
+ }
+ }
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/tfe-dsc.c b/contiki-cpc/uip/tfe-dsc.c
new file mode 100644
index 0000000..4170400
--- /dev/null
+++ b/contiki-cpc/uip/tfe-dsc.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2003, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 desktop environment
+ *
+ * $Id: tfe-dsc.c,v 1.1 2006/04/17 15:02:42 kthacker Exp $
+ *
+ */
+
+#include "dsc.h"
+
+extern struct ctk_icon tfe_icon;
+/*-----------------------------------------------------------------------------------*/
+DSC(tfe_dsc,
+ "The Final Ethernet driver",
+ "tfe.drv",
+ tfe_init,
+ &tfe_icon);
+/*-----------------------------------------------------------------------------------*/
+#if CTK_CONF_ICON_BITMAPS
+static unsigned char tfeicon_bitmap[3*3*8] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+};
+#endif /* CTK_CONF_ICON_BITMAPS */
+
+#if CTK_CONF_ICON_TEXTMAPS
+static char tfeicon_textmap[9] = {
+ 'T', 'C', 'P',
+ '/', 'I', 'P',
+ 'T', 'F', 'E'
+};
+#endif /* CTK_CONF_ICON_TEXTMAPS */
+
+static struct ctk_icon tfe_icon =
+ {CTK_ICON("TFE driver", tfeicon_bitmap, tfeicon_textmap)};
+/*-----------------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/tfe-dump-drv.c b/contiki-cpc/uip/tfe-dump-drv.c
new file mode 100644
index 0000000..e992141
--- /dev/null
+++ b/contiki-cpc/uip/tfe-dump-drv.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2001-2004, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: tfe-dump-drv.c,v 1.1 2006/04/17 15:02:42 kthacker Exp $
+ *
+ */
+
+#include "packet-service.h"
+
+#include "cs8900a.h"
+
+#include "uip_arp.h"
+
+static void output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen);
+
+static const struct uip_eth_addr addr =
+ {{0x00,0x00,0x00,0x64,0x64,0x64}};
+
+static const struct packet_service_state state =
+ {
+ PACKET_SERVICE_VERSION,
+ output
+ };
+
+EK_EVENTHANDLER(eventhandler, ev, data);
+EK_POLLHANDLER(pollhandler);
+EK_PROCESS(proc, PACKET_SERVICE_NAME ": TFE", EK_PRIO_NORMAL,
+ eventhandler, pollhandler, (void *)&state);
+
+#include "tcpdump.h"
+#include <string.h>
+#include "ctk.h"
+
+#define DUMP_WIDTH 38
+#define DUMP_HEIGHT 20
+static struct ctk_window window;
+static char dump[DUMP_WIDTH * DUMP_HEIGHT];
+static struct ctk_label dumplabel =
+ {CTK_LABEL(0, 0, DUMP_WIDTH, DUMP_HEIGHT, dump)};
+static void
+dump_packet(void)
+{
+ memcpy(dump, &dump[DUMP_WIDTH], DUMP_WIDTH * (DUMP_HEIGHT - 1));
+ tcpdump_print(&dump[DUMP_WIDTH * (DUMP_HEIGHT - 1)], DUMP_WIDTH);
+ CTK_WIDGET_REDRAW(&dumplabel);
+}
+/*---------------------------------------------------------------------------*/
+LOADER_INIT_FUNC(tfe_dump_drv_init, arg)
+{
+ arg_free(arg);
+ ek_service_start(PACKET_SERVICE_NAME, &proc);
+}
+/*---------------------------------------------------------------------------*/
+static void
+output(u8_t *hdr, u16_t hdrlen, u8_t *data, u16_t datalen)
+{
+ uip_arp_out();
+ cs8900a_send();
+ dump_packet();
+}
+/*---------------------------------------------------------------------------*/
+
+EK_EVENTHANDLER(eventhandler, ev, data)
+{
+ switch(ev) {
+ case EK_EVENT_INIT:
+ case EK_EVENT_REPLACE:
+ ctk_window_new(&window, DUMP_WIDTH, DUMP_HEIGHT, "TFE dump");
+ CTK_WIDGET_ADD(&window, &dumplabel);
+ ctk_window_open(&window);
+ uip_setethaddr(addr);
+ cs8900a_init();
+ break;
+ case EK_EVENT_REQUEST_REPLACE:
+ ctk_window_close(&window);
+ ek_replace((struct ek_proc *)data, NULL);
+ LOADER_UNLOAD();
+ break;
+ case EK_EVENT_REQUEST_EXIT:
+ ctk_window_close(&window);
+ ek_exit();
+ LOADER_UNLOAD();
+ break;
+ default:
+ break;
+ }
+}
+
+/*---------------------------------------------------------------------------*/
+EK_POLLHANDLER(pollhandler)
+{
+#define BUF ((struct uip_eth_hdr *)&uip_buf[0])
+
+ /* Poll Ethernet device to see if there is a frame avaliable. */
+ uip_len = cs8900a_poll();
+ if(uip_len > 0) {
+ dump_packet();
+ /* A frame was avaliable (and is now read into the uip_buf), so
+ we process it. */
+ if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
+ uip_arp_ipin();
+ uip_len -= sizeof(struct uip_eth_hdr);
+ tcpip_input();
+ } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
+ uip_arp_arpin();
+ /* If the above function invocation resulted in data that
+ should be sent out on the network, the global variable
+ uip_len is set to a value > 0. */
+ if(uip_len > 0) {
+ cs8900a_send();
+ }
+ }
+ }
+
+}
+/*---------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/uip_arch.c b/contiki-cpc/uip/uip_arch.c
new file mode 100644
index 0000000..5edd6c2
--- /dev/null
+++ b/contiki-cpc/uip/uip_arch.c
@@ -0,0 +1,526 @@
+/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: uip_arch.c,v 1.1 2006/04/17 15:02:43 kthacker Exp $
+ *
+ */
+
+
+#include "uip.h"
+#include "uip_arch.h"
+
+#define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
+#define IP_PROTO_TCP 6
+#define IP_PROTO_UDP 17
+
+/*-----------------------------------------------------------------------------------*/
+/*#pragma optimize(push, off) */
+void
+uip_add32(u8_t *op32, u16_t op16)
+{
+#if 0
+ asm("ldy #3");
+ asm("jsr ldaxysp");
+ asm("sta ptr1");
+ asm("stx ptr1+1");
+ asm("ldy #0");
+ asm("lda (sp),y");
+ asm("ldy #3");
+ asm("clc");
+ asm("adc (ptr1),y");
+ asm("sta _uip_acc32+3");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("ldy #1");
+ asm("adc (sp),y");
+ asm("sta _uip_acc32+2");
+ asm("ldy #1");
+ asm("lda (ptr1),y");
+ asm("adc #0");
+ asm("sta _uip_acc32+1");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("adc #0");
+ asm("sta _uip_acc32+0");
+#endif
+}
+/*#pragma optimize(pop)*/
+/*-----------------------------------------------------------------------------------*/
+static u16_t chksum_ptr, chksum_len, chksum_tmp;
+static u8_t chksum_protocol;
+static u16_t chksum(void);
+/*-----------------------------------------------------------------------------------*/
+/*#pragma optimize(push, off) */
+u16_t
+chksum(void) {
+
+#if 0
+ asm("lda #0");
+ asm("sta tmp1");
+ asm("sta tmp1+1");
+ asm("lda _chksum_ptr");
+ asm("sta ptr1");
+ asm("lda _chksum_ptr+1");
+ asm("sta ptr1+1");
+
+
+ asm("lda _chksum_len+1");
+ asm("beq chksumlast");
+
+
+ /* If checksum is > 256, do the first runs. */
+ asm("ldy #0");
+ asm("clc");
+ asm("chksumloop_256:");
+ asm("lda (ptr1),y");
+ asm("adc tmp1");
+ asm("sta tmp1");
+ asm("iny");
+ asm("lda (ptr1),y");
+ asm("adc tmp1+1");
+ asm("sta tmp1+1");
+ asm("iny");
+ asm("bne chksumloop_256");
+ asm("inc ptr1+1");
+ asm("dec _chksum_len+1");
+ asm("bne chksumloop_256");
+
+ asm("chksum_endloop_256:");
+ asm("lda tmp1");
+ asm("adc #0");
+ asm("sta tmp1");
+ asm("lda tmp1+1");
+ asm("adc #0");
+ asm("sta tmp1+1");
+ asm("bcs chksum_endloop_256");
+
+ asm("chksumlast:");
+ asm("lda _chksum_len");
+ asm("lsr");
+ asm("bcc chksum_noodd");
+ asm("ldy _chksum_len");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("clc");
+ asm("adc tmp1");
+ asm("sta tmp1");
+ asm("bcc noinc1");
+ asm("inc tmp1+1");
+ asm("bne noinc1");
+ asm("inc tmp1");
+ asm("noinc1:");
+ asm("dec _chksum_len");
+
+ asm("chksum_noodd:");
+ asm("clc");
+ asm("php");
+ asm("ldy _chksum_len");
+ asm("chksum_loop1:");
+ asm("cpy #0");
+ asm("beq chksum_loop1_end");
+ asm("plp");
+ asm("dey");
+ asm("dey");
+ asm("lda (ptr1),y");
+ asm("adc tmp1");
+ asm("sta tmp1");
+ asm("iny");
+ asm("lda (ptr1),y");
+ asm("adc tmp1+1");
+ asm("sta tmp1+1");
+ asm("dey");
+ asm("php");
+ asm("jmp chksum_loop1");
+ asm("chksum_loop1_end:");
+ asm("plp");
+
+ asm("chksum_endloop:");
+ asm("lda tmp1");
+ asm("adc #0");
+ asm("sta tmp1");
+ asm("lda tmp1+1");
+ asm("adc #0");
+ asm("sta tmp1+1");
+ asm("bcs chksum_endloop");
+
+ asm("lda tmp1");
+ asm("ldx tmp1+1");
+#endif
+}
+/*#pragma optimize(pop)*/
+/*-----------------------------------------------------------------------------------*/
+u16_t
+uip_chksum(u16_t *buf, u16_t len)
+{
+ /* unsigned long sum;
+
+ sum = 0;
+
+ chksum_ptr = (u16_t)buf;
+ while(len >= 256) {
+ chksum_len = 256;
+ sum += chksum();
+ len -= 256;
+ chksum_ptr += 256;
+ }
+
+ if(len < 256) {
+ chksum_len = len;
+ sum += chksum();
+ }
+
+ while((sum >> 16) != 0) {
+ sum = (sum >> 16) + (sum & 0xffff);
+ }
+
+ return sum;*/
+
+ chksum_len = len;
+ chksum_ptr = (u16_t)buf;
+ return chksum();
+}
+/*-----------------------------------------------------------------------------------*/
+u16_t
+uip_ipchksum(void)
+{
+ chksum_ptr = (u16_t)uip_buf + UIP_LLH_LEN;
+ chksum_len = 20;
+ return chksum();
+}
+/*-----------------------------------------------------------------------------------*/
+/*#pragma optimize(push, off) */
+static u16_t
+transport_chksum(u8_t protocol)
+{
+ chksum_protocol = protocol;
+ chksum_ptr = (u16_t)&uip_buf[20 + UIP_LLH_LEN];
+ chksum_len = 20;
+ chksum_tmp = chksum();
+
+ chksum_ptr = (u16_t)uip_appdata;
+
+#if 0
+ asm("lda _uip_buf+3+%b", UIP_LLH_LEN);
+ asm("sec");
+ asm("sbc #40");
+ asm("sta _chksum_len");
+ asm("lda _uip_buf+2+%b", UIP_LLH_LEN);
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+ asm("jsr %v", chksum);
+
+ asm("clc");
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("txa");
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+
+ /* Fold carry */
+ /* asm("bcc noinc");
+ asm("inc _chksum_tmp");
+ asm("noinc:");*/
+
+ asm("tcpchksum_loop1:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop1");
+
+
+ asm("lda _uip_buf+3+%b", UIP_LLH_LEN);
+ asm("sec");
+ asm("sbc #20");
+ asm("sta _chksum_len");
+ asm("lda _uip_buf+2+%b", UIP_LLH_LEN);
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+
+ asm("ldy #$0c");
+ asm("clc");
+ asm("php");
+ asm("tcpchksum_loop2:");
+ asm("plp");
+ asm("lda _uip_buf+%b,y", UIP_LLH_LEN);
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("iny");
+ asm("lda _uip_buf+%b,y", UIP_LLH_LEN);
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+ asm("iny");
+ asm("php");
+ asm("cpy #$14");
+ asm("bne tcpchksum_loop2");
+
+ asm("plp");
+
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc %v", chksum_protocol);
+ asm("sta _chksum_tmp+1");
+
+
+ asm("lda _chksum_tmp");
+ asm("adc _chksum_len+1");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc _chksum_len");
+ asm("sta _chksum_tmp+1");
+
+
+
+ asm("tcpchksum_loop3:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop3");
+#endif
+
+ return chksum_tmp;
+}
+/*#pragma optimize(pop)*/
+
+/*-----------------------------------------------------------------------------------*/
+u16_t
+uip_tcpchksum(void)
+{
+ return transport_chksum(IP_PROTO_TCP);
+#if 0
+ chksum_ptr = (u16_t)&uip_buf[20 + UIP_LLH_LEN];
+ chksum_len = 20;
+ chksum_tmp = chksum();
+
+ chksum_ptr = (u16_t)uip_appdata;
+ asm("lda _uip_buf+3+%b", UIP_LLH_LEN);
+ asm("sec");
+ asm("sbc #40");
+ asm("sta _chksum_len");
+ asm("lda _uip_buf+2+%b", UIP_LLH_LEN);
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+ asm("jsr %v", chksum);
+
+ asm("clc");
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("txa");
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+
+ /* Fold carry */
+ /* asm("bcc noinc");
+ asm("inc _chksum_tmp");
+ asm("noinc:");*/
+
+ asm("tcpchksum_loop1:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop1");
+
+
+ asm("lda _uip_buf+3+%b", UIP_LLH_LEN);
+ asm("sec");
+ asm("sbc #20");
+ asm("sta _chksum_len");
+ asm("lda _uip_buf+2+%b", UIP_LLH_LEN);
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+
+ asm("ldy #$0c");
+ asm("clc");
+ asm("php");
+ asm("tcpchksum_loop2:");
+ asm("plp");
+ asm("lda _uip_buf+%b,y", UIP_LLH_LEN);
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("iny");
+ asm("lda _uip_buf+%b,y", UIP_LLH_LEN);
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+ asm("iny");
+ asm("php");
+ asm("cpy #$14");
+ asm("bne tcpchksum_loop2");
+
+ asm("plp");
+
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #6"); /* IP_PROTO_TCP */
+ asm("sta _chksum_tmp+1");
+
+
+ asm("lda _chksum_tmp");
+ asm("adc _chksum_len+1");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc _chksum_len");
+ asm("sta _chksum_tmp+1");
+
+
+
+ asm("tcpchksum_loop3:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop3");
+
+
+ return chksum_tmp;
+#endif
+}
+
+/*-----------------------------------------------------------------------------------*/
+#if UIP_UDP_CHECKSUMS
+u16_t
+uip_udpchksum(void)
+{
+ return transport_chksum(IP_PROTO_UDP);
+#if 0
+ chksum_ptr = (u16_t)&uip_buf[20 + UIP_LLH_LEN];
+ chksum_len = 20;
+ chksum_tmp = chksum();
+
+ chksum_ptr = (u16_t)uip_appdata;
+ asm("lda _uip_buf+3+%b", UIP_LLH_LEN);
+ asm("sec");
+ asm("sbc #40");
+ asm("sta _chksum_len");
+ asm("lda _uip_buf+2+%b", UIP_LLH_LEN);
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+ asm("jsr %v", chksum);
+
+ asm("clc");
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("txa");
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+
+ /* Fold carry */
+ /* asm("bcc noinc");
+ asm("inc _chksum_tmp");
+ asm("noinc:");*/
+
+ asm("tcpchksum_loop1:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop1");
+
+
+ asm("lda _uip_buf+3+%b", UIP_LLH_LEN);
+ asm("sec");
+ asm("sbc #20");
+ asm("sta _chksum_len");
+ asm("lda _uip_buf+2+%b", UIP_LLH_LEN);
+ asm("sbc #0");
+ asm("sta _chksum_len+1");
+
+
+ asm("ldy #$0c");
+ asm("clc");
+ asm("php");
+ asm("tcpchksum_loop2:");
+ asm("plp");
+ asm("lda _uip_buf+%b,y", UIP_LLH_LEN);
+ asm("adc _chksum_tmp");
+ asm("sta _chksum_tmp");
+ asm("iny");
+ asm("lda _uip_buf+%b,y", UIP_LLH_LEN);
+ asm("adc _chksum_tmp+1");
+ asm("sta _chksum_tmp+1");
+ asm("iny");
+ asm("php");
+ asm("cpy #$14");
+ asm("bne tcpchksum_loop2");
+
+ asm("plp");
+
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #17"); /* IP_PROTO_UDP */
+ asm("sta _chksum_tmp+1");
+
+
+ asm("lda _chksum_tmp");
+ asm("adc _chksum_len+1");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc _chksum_len");
+ asm("sta _chksum_tmp+1");
+
+
+
+ asm("tcpchksum_loop3:");
+ asm("lda _chksum_tmp");
+ asm("adc #0");
+ asm("sta _chksum_tmp");
+ asm("lda _chksum_tmp+1");
+ asm("adc #0");
+ asm("sta _chksum_tmp+1");
+ asm("bcs tcpchksum_loop3");
+
+
+ return chksum_tmp;
+#endif
+}
+#endif /* UIP_UDP_CHECKSUMS */
+/*-----------------------------------------------------------------------------------*/
diff --git a/contiki-cpc/uip/uip_arch.h b/contiki-cpc/uip/uip_arch.h
new file mode 100644
index 0000000..9d1c03b
--- /dev/null
+++ b/contiki-cpc/uip/uip_arch.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2001, Adam Dunkels.
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 uIP TCP/IP stack.
+ *
+ * $Id: uip_arch.h,v 1.1 2006/04/17 15:02:43 kthacker Exp $
+ *
+ */
+
+#ifndef __UIP_ARCH_H__
+#define __UIP_ARCH_H__
+
+#include "uip.h"
+
+void uip_add_rcv_nxt(u16_t n);
+void uip_add32(u8_t *op32, u16_t op16);
+
+u16_t uip_chksum(u16_t *data, u16_t len);
+u16_t uip_ipchksum(void);
+u16_t uip_tcpchksum(void);
+
+#endif /* __UIP_ARCH_H__ */