diff --git a/liteeth/software/libuip/Makefile b/liteeth/software/libuip/Makefile new file mode 100644 index 0000000..cc69877 --- /dev/null +++ b/liteeth/software/libuip/Makefile @@ -0,0 +1,76 @@ +# XXX remove this +MSCDIR=../../../../misoc +include $(MSCDIR)/software/common.mak + +UIPDIR=../uip +LIBUIPDIR=../libuip + +CFLAGS += $(CPPFLAGS) -I. \ + -I$(UIPDIR) \ + -I$(UIPDIR)/net \ + -I$(UIPDIR)/net\ip \ + -I$(UIPDIR)/net\ipv4 \ + -Wno-char-subscripts \ + -fno-strict-aliasing -fpack-struct + +#See here for-fno-strict-aliasing -fpack-struct: +#http://sourceforge.net/p/contiki/mailman/message/28002063/ + +CCDEP=$(CC) + +UIPCOREOBJS=$(UIPDIR)/net/ip/dhcpc.o \ + $(UIPDIR)/net/ip/psock.o \ + $(UIPDIR)/net/ip/resolv.o \ + $(UIPDIR)/net/ip/simple-udp.o \ + $(UIPDIR)/net/ip/slipdev.o \ + $(UIPDIR)/net/ip/tcpip.o \ + $(UIPDIR)/net/ip/tcp-socket.o \ + $(UIPDIR)/net/ip/udp-socket.o \ + $(UIPDIR)/net/ip/uip-debug.o \ + $(UIPDIR)/net/ip/uiplib.o \ + $(UIPDIR)/net/ip/uip-packetqueue.o \ + $(UIPDIR)/net/ip/uip-split.o \ + $(UIPDIR)/net/ip/uip-udp-packet.o \ + $(UIPDIR)/net/ipv4/uaodv.o \ + $(UIPDIR)/net/ipv4/uaodv-rt.o \ + $(UIPDIR)/net/ipv4/uip.o \ + $(UIPDIR)/net/ipv4/uip_arp.o \ + $(UIPDIR)/net/ipv4/uip-fw.o \ + $(UIPDIR)/net/ipv4/uip-fw-drv.o \ + $(UIPDIR)/net/ipv4/uip-neighbor.o \ + $(UIPDIR)/net/ipv4/uip-over-mesh.o \ + $(UIPDIR)/net/linkaddr.o \ + $(UIPDIR)/net/nbr-table.o \ + $(UIPDIR)/net/netstack.o \ + $(UIPDIR)/net/packetbuf.o \ + $(UIPDIR)/net/queuebuf.o \ + $(UIPDIR)/sys/process.o \ + $(UIPDIR)/sys/etimer.o \ + $(UIPDIR)/sys/timer.o \ + $(UIPDIR)/lib/list.o + +UIPARCHOBJS=clock-arch.o \ + rtimer-arch.o \ + liteethmac-drv.o + +UIPOBJS=$(UIPCOREOBJS) $(UIPARCHOBJS) +OBJS_LIB+=$(UIPOBJS) + +UIPLIB=libuip.a + +all: $(UIPLIB) + +.PHONY: all compile clean + +%.o: %.c + $(compile-dep) + +%.o: %.S + $(assemble) + +clean: + rm -f $(UIPOBJS) $(UIPOBJS:.o=.d) libuip.a + +libuip.a: $(UIPOBJS) + $(AR) clr libuip.a $(UIPOBJS) + $(RANLIB) libuip.a diff --git a/liteeth/software/libuip/clock-arch.c b/liteeth/software/libuip/clock-arch.c new file mode 100644 index 0000000..6d7357f --- /dev/null +++ b/liteeth/software/libuip/clock-arch.c @@ -0,0 +1,29 @@ +// This file is Copyright (c) 2015 Florent Kermarrec +// License: BSD + +#include "contiki-conf.h" +#include "clock-arch.h" +#include + +/*-----------------------------------------------------------------------------------*/ +void clock_init(void) +{ + timer0_en_write(0); + timer0_load_write(0xffffffff); + timer0_reload_write(0xffffffff); + timer0_en_write(1); +} + +/*---------------------------------------------------------------------------*/ +clock_time_t clock_time(void) +{ + unsigned int freq; + unsigned int prescaler; + clock_time_t ticks; + + freq = identifier_frequency_read(); + prescaler = freq/CLOCK_CONF_SECOND; + timer0_update_value_write(1); + ticks = (0xffffffff - timer0_value_read())/prescaler; + return ticks; +} diff --git a/liteeth/software/libuip/clock-arch.h b/liteeth/software/libuip/clock-arch.h new file mode 100644 index 0000000..3b8d3a2 --- /dev/null +++ b/liteeth/software/libuip/clock-arch.h @@ -0,0 +1,10 @@ +// This file is Copyright (c) 2015 Florent Kermarrec +// License: BSD + +#ifndef __CLOCK_ARCH_H__ +#define __CLOCK_ARCH_H__ + +void clock_init(void); +clock_time_t clock_time(void); + +#endif /* __CLOCK_ARCH_H__ */ diff --git a/liteeth/software/libuip/contiki-conf.h b/liteeth/software/libuip/contiki-conf.h new file mode 100644 index 0000000..afd22e6 --- /dev/null +++ b/liteeth/software/libuip/contiki-conf.h @@ -0,0 +1,38 @@ +#ifndef CONTIKI_CONF_H__ +#define CONTIKI_CONF_H__ + +#include +#include + +#define CCIF +#define CLIF + +#define NETSTACK_CONF_WITH_IPV4 1 +#define WITH_ASCII 1 + +#define CLOCK_CONF_SECOND 128 + +typedef unsigned char u8_t; +typedef unsigned short u16_t; +typedef unsigned int u32_t; +typedef char s8_t; +typedef short s16_t; +typedef int s32_t; + +typedef unsigned int clock_time_t; +typedef unsigned int uip_stats_t; + +#ifndef BV +#define BV(x) (1<<(x)) +#endif + +/* uIP configuration */ +#define UIP_CONF_BYTE_ORDER UIP_BIG_ENDIAN +#define UIP_CONF_LLH_LEN 14 +#define UIP_CONF_BROADCAST 1 +#define UIP_CONF_LOGGING 1 +#define UIP_CONF_BUFFER_SIZE 116 + +#define UIP_CONF_TCP_FORWARD 1 + +#endif /* CONTIKI_CONF_H__ */ diff --git a/liteeth/software/libuip/liteethmac-drv.c b/liteeth/software/libuip/liteethmac-drv.c new file mode 100644 index 0000000..f9c1b67 --- /dev/null +++ b/liteeth/software/libuip/liteethmac-drv.c @@ -0,0 +1,90 @@ +// This file is Copyright (c) 2015 Florent Kermarrec +// License: BSD + +#include "net/ip/uip.h" +#include "net/ip/uipopt.h" +#include "liteethmac-drv.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) + +typedef union { + unsigned char raw[1514]; +} ethernet_buffer; + +static unsigned int rxslot; +static unsigned int rxlen; +static ethernet_buffer *rxbuffer; +static ethernet_buffer *rxbuffer0; +static ethernet_buffer *rxbuffer1; +static unsigned int txslot; +static unsigned int txlen; +static ethernet_buffer *txbuffer; +static ethernet_buffer *txbuffer0; +static ethernet_buffer *txbuffer1; + +void liteethmac_init(void) +{ + ethmac_sram_reader_ev_pending_write(ETHMAC_EV_SRAM_READER); + ethmac_sram_writer_ev_pending_write(ETHMAC_EV_SRAM_WRITER); + + rxbuffer0 = (ethernet_buffer *)ETHMAC_RX0_BASE; + rxbuffer1 = (ethernet_buffer *)ETHMAC_RX1_BASE; + txbuffer0 = (ethernet_buffer *)ETHMAC_TX0_BASE; + txbuffer1 = (ethernet_buffer *)ETHMAC_TX1_BASE; + + rxslot = 0; + txslot = 0; + + rxbuffer = rxbuffer0; + txbuffer = txbuffer0; +} + +uint16_t liteethmac_poll(void) +{ + if(ethmac_sram_writer_ev_pending_read() & ETHMAC_EV_SRAM_WRITER) { + rxslot = ethmac_sram_writer_slot_read(); + rxlen = ethmac_sram_writer_length_read(); + if (rxslot) + rxbuffer = rxbuffer1; + else + rxbuffer = rxbuffer0; + memcpy(uip_buf, rxbuffer, rxlen); + uip_len = rxlen; + ethmac_sram_writer_ev_pending_write(ETHMAC_EV_SRAM_WRITER); + return rxlen; + } + return 0; +} + +void liteethmac_send(void) +{ + txlen = uip_len; + memset(txbuffer, 0, 60); + txlen = MIN(txlen, 1514); + memcpy(txbuffer, uip_buf, txlen); + txlen = MAX(txlen, 60); + ethmac_sram_reader_slot_write(txslot); + ethmac_sram_reader_length_write(txlen); + while(!(ethmac_sram_reader_ready_read())); + ethmac_sram_reader_start_write(1); + + txslot = (txslot+1)%2; + if (txslot) + txbuffer = txbuffer1; + else + txbuffer = txbuffer0; +} + +void liteethmac_exit(void) +{ +} diff --git a/liteeth/software/libuip/liteethmac-drv.h b/liteeth/software/libuip/liteethmac-drv.h new file mode 100644 index 0000000..973cf0a --- /dev/null +++ b/liteeth/software/libuip/liteethmac-drv.h @@ -0,0 +1,11 @@ +// This file is Copyright (c) 2015 Florent Kermarrec +// License: BSD +#ifndef __LITEETHMAC_H__ +#define __LITEETHMAC_H__ + +void liteethmac_init(void); +uint16_t liteethmac_poll(void); +void liteethmac_send(void); +void liteethmac_exit(void); + +#endif /* __LITEETHMAC_H__ */ diff --git a/liteeth/software/libuip/rtimer-arch.c b/liteeth/software/libuip/rtimer-arch.c new file mode 100644 index 0000000..f91ecf0 --- /dev/null +++ b/liteeth/software/libuip/rtimer-arch.c @@ -0,0 +1,38 @@ +#include "contiki.h" + +#include +#include + +#include + +#define RTIMER_DEBUG + +void rtimer_callback(void) +{ +#ifdef RTIMER_DEBUG + printf("XXX rtimer_callback"); +#endif + rtimer_run_next(); +} + +void rtimer_arch_init(void) +{ +#ifdef RTIMER_DEBUG + printf("XXX rtimer_arch_init"); +#endif +} + +rtimer_clock_t rtimer_arch_now(void) +{ +#ifdef RTIMER_DEBUG + printf("XXX rtimer_arch_now"); +#endif + return 0; +} + +void rtimer_arch_schedule(rtimer_clock_t t) +{ +#ifdef RTIMER_DEBUG + printf("XXX rtimer_arch_schedule"); +#endif +} diff --git a/liteeth/software/libuip/rtimer-arch.h b/liteeth/software/libuip/rtimer-arch.h new file mode 100644 index 0000000..fd4cf25 --- /dev/null +++ b/liteeth/software/libuip/rtimer-arch.h @@ -0,0 +1,16 @@ +#ifndef RTIMER_ARCH_H_ +#define RTIMER_ARCH_H_ + +#include "contiki-conf.h" + +#include + +void rtimer_callback(void); +void rtimer_arch_init(void); +rtimer_clock_t rtimer_arch_now(void); +void rtimer_arch_schedule(rtimer_clock_t t); +#define RTIMER_ARCH_SECOND 312500 + +#endif + +/** @} */