[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r6920 - in gnuradio/branches/developers/matt/u2f/firmw
From: |
eb |
Subject: |
[Commit-gnuradio] r6920 - in gnuradio/branches/developers/matt/u2f/firmware: . apps lib |
Date: |
Thu, 15 Nov 2007 08:39:13 -0700 (MST) |
Author: eb
Date: 2007-11-15 08:39:09 -0700 (Thu, 15 Nov 2007)
New Revision: 6920
Added:
gnuradio/branches/developers/matt/u2f/firmware/Makefile.common
gnuradio/branches/developers/matt/u2f/firmware/apps/
gnuradio/branches/developers/matt/u2f/firmware/apps/Makefile.am
gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds.c
gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds2.c
gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_test.c
gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_zero.c
gnuradio/branches/developers/matt/u2f/firmware/apps/eth.c
gnuradio/branches/developers/matt/u2f/firmware/apps/eth_test.c
gnuradio/branches/developers/matt/u2f/firmware/apps/gen_eth_packets.c
gnuradio/branches/developers/matt/u2f/firmware/apps/hello.c
gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_rx_test.c
gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_tx_test.c
gnuradio/branches/developers/matt/u2f/firmware/apps/rcv_eth_packets.c
gnuradio/branches/developers/matt/u2f/firmware/apps/test1.c
gnuradio/branches/developers/matt/u2f/firmware/apps/test_phy_comm.c
gnuradio/branches/developers/matt/u2f/firmware/apps/timer_test.c
gnuradio/branches/developers/matt/u2f/firmware/lib/
gnuradio/branches/developers/matt/u2f/firmware/lib/Makefile.am
gnuradio/branches/developers/matt/u2f/firmware/lib/bool.h
gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.c
gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.h
gnuradio/branches/developers/matt/u2f/firmware/lib/eeprom.c
gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.c
gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.h
gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.c
gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.h
gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac_regs.h
gnuradio/branches/developers/matt/u2f/firmware/lib/eth_phy.h
gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.c
gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.h
gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.c
gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.h
gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.c
gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.h
gnuradio/branches/developers/matt/u2f/firmware/lib/memory_map.h
gnuradio/branches/developers/matt/u2f/firmware/lib/microblaze.ld
gnuradio/branches/developers/matt/u2f/firmware/lib/pic.c
gnuradio/branches/developers/matt/u2f/firmware/lib/pic.h
gnuradio/branches/developers/matt/u2f/firmware/lib/spi.c
gnuradio/branches/developers/matt/u2f/firmware/lib/spi.h
gnuradio/branches/developers/matt/u2f/firmware/lib/stdint.h
gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.c
gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.h
gnuradio/branches/developers/matt/u2f/firmware/lib/wb16550.h
Removed:
gnuradio/branches/developers/matt/u2f/firmware/blink_leds.c
gnuradio/branches/developers/matt/u2f/firmware/blink_leds2.c
gnuradio/branches/developers/matt/u2f/firmware/bool.h
gnuradio/branches/developers/matt/u2f/firmware/buf_ram_test.c
gnuradio/branches/developers/matt/u2f/firmware/buf_ram_zero.c
gnuradio/branches/developers/matt/u2f/firmware/buffer_pool.c
gnuradio/branches/developers/matt/u2f/firmware/buffer_pool.h
gnuradio/branches/developers/matt/u2f/firmware/eeprom.c
gnuradio/branches/developers/matt/u2f/firmware/eth.c
gnuradio/branches/developers/matt/u2f/firmware/eth_driver.c
gnuradio/branches/developers/matt/u2f/firmware/eth_driver.h
gnuradio/branches/developers/matt/u2f/firmware/eth_mac.c
gnuradio/branches/developers/matt/u2f/firmware/eth_mac.h
gnuradio/branches/developers/matt/u2f/firmware/eth_mac_regs.h
gnuradio/branches/developers/matt/u2f/firmware/eth_phy.h
gnuradio/branches/developers/matt/u2f/firmware/eth_test.c
gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c
gnuradio/branches/developers/matt/u2f/firmware/hal_io.c
gnuradio/branches/developers/matt/u2f/firmware/hal_io.h
gnuradio/branches/developers/matt/u2f/firmware/hal_uart.c
gnuradio/branches/developers/matt/u2f/firmware/hal_uart.h
gnuradio/branches/developers/matt/u2f/firmware/hello.c
gnuradio/branches/developers/matt/u2f/firmware/i2c.c
gnuradio/branches/developers/matt/u2f/firmware/i2c.h
gnuradio/branches/developers/matt/u2f/firmware/ibs_rx_test.c
gnuradio/branches/developers/matt/u2f/firmware/ibs_tx_test.c
gnuradio/branches/developers/matt/u2f/firmware/memory_map.h
gnuradio/branches/developers/matt/u2f/firmware/microblaze.ld
gnuradio/branches/developers/matt/u2f/firmware/pic.c
gnuradio/branches/developers/matt/u2f/firmware/pic.h
gnuradio/branches/developers/matt/u2f/firmware/rcv_eth_packets.c
gnuradio/branches/developers/matt/u2f/firmware/spi.c
gnuradio/branches/developers/matt/u2f/firmware/spi.h
gnuradio/branches/developers/matt/u2f/firmware/stdint.h
gnuradio/branches/developers/matt/u2f/firmware/test1.c
gnuradio/branches/developers/matt/u2f/firmware/test_phy_comm.c
gnuradio/branches/developers/matt/u2f/firmware/timer_test.c
gnuradio/branches/developers/matt/u2f/firmware/u2_init.c
gnuradio/branches/developers/matt/u2f/firmware/u2_init.h
gnuradio/branches/developers/matt/u2f/firmware/wb16550.h
Modified:
gnuradio/branches/developers/matt/u2f/firmware/Makefile.am
gnuradio/branches/developers/matt/u2f/firmware/configure.ac
Log:
Rearranged firmware into lib and apps directories.
Modified: gnuradio/branches/developers/matt/u2f/firmware/Makefile.am
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/Makefile.am 2007-11-15
03:54:53 UTC (rev 6919)
+++ gnuradio/branches/developers/matt/u2f/firmware/Makefile.am 2007-11-15
15:39:09 UTC (rev 6920)
@@ -18,64 +18,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-#AM_CPPFLAGS = -DHAL_IO_USES_DBOARD_PINS
-AM_CPPFLAGS = -DHAL_IO_USES_UART
+include $(top_srcdir)/Makefile.common
-#AM_CFLAGS = -Wall -O2 -g -mxl-gp-opt -mxl-soft-div -mxl-soft-mul -msoft-float
-AM_CFLAGS = -Wall -O2 -g -mxl-soft-div -mxl-soft-mul -msoft-float
+SUBDIRS = lib apps
-LINKER_SCRIPT = microblaze.ld
-#AM_LDFLAGS = -Wl,-T$(LINKER_SCRIPT) -Wl,-defsym -Wl,_STACK_SIZE=4096
-AM_LDFLAGS = -Wl,-T$(LINKER_SCRIPT)
-
-
-%.bin : %
- mb-objcopy -O binary $< $@
-
-%.dump : %
- mb-objdump -DSC $< > $@
-
-%.rom : %.bin
- hexdump -v -e'1/1 "%.2X\n"' $< > $@
-
-
-.PRECIOUS : %.bin
-
-noinst_LIBRARIES = \
- libu2fw.a
-
-libu2fw_a_SOURCES = \
- buffer_pool.c \
- eth_driver.c \
- eth_mac.c \
- hal_io.c \
- hal_uart.c \
- i2c.c \
- pic.c \
- spi.c \
- u2_init.c
-
-LDADD = libu2fw.a
-
-noinst_PROGRAMS = \
- blink_leds \
- blink_leds2 \
- buf_ram_test \
- buf_ram_zero \
- eth_test \
- gen_eth_packets \
- hello \
- ibs_rx_test \
- ibs_tx_test \
- rcv_eth_packets \
- test1 \
- test_phy_comm \
- timer_test
-
-BINS = $(noinst_PROGRAMS:=.bin)
-ROMS = $(noinst_PROGRAMS:=.rom)
-DUMPS = $(noinst_PROGRAMS:=.dump)
-
-noinst_DATA = $(BINS) $(ROMS) $(DUMPS)
-
-CLEANFILES = $(ROMS) $(DUMPS) $(BINS)
Added: gnuradio/branches/developers/matt/u2f/firmware/Makefile.common
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/Makefile.common
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/Makefile.common
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,56 @@
+# -*- Makefile -*-
+#
+# Copyright 2007 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+STD_INCLUDES = -I$(top_srcdir)/lib
+
+#HAL_IO = -DHAL_IO_USES_DBOARD_PINS
+HAL_IO = -DHAL_IO_USES_UART
+
+AM_CPPFLAGS = $(HAL_IO) $(STD_INCLUDES)
+
+#AM_CFLAGS = -Wall -O2 -g -mxl-gp-opt -mxl-soft-div -mxl-soft-mul -msoft-float
+AM_CFLAGS = -Wall -O2 -g -mxl-soft-div -mxl-soft-mul -msoft-float
+
+LINKER_SCRIPT = $(top_srcdir)/lib/microblaze.ld
+#AM_LDFLAGS = -Wl,-T$(LINKER_SCRIPT) -Wl,-defsym -Wl,_STACK_SIZE=4096
+AM_LDFLAGS = -Wl,-T$(LINKER_SCRIPT)
+
+
+%.bin : %
+ mb-objcopy -O binary $< $@
+
+%.dump : %
+ mb-objdump -DSC $< > $@
+
+%.rom : %.bin
+ hexdump -v -e'1/1 "%.2X\n"' $< > $@
+
+
+.PRECIOUS : %.bin
+
+
+BINS = $(noinst_PROGRAMS:=.bin)
+ROMS = $(noinst_PROGRAMS:=.rom)
+DUMPS = $(noinst_PROGRAMS:=.dump)
+
+noinst_DATA = $(BINS) $(ROMS) $(DUMPS)
+
+CLEANFILES = $(ROMS) $(DUMPS) $(BINS)
Property changes on: gnuradio/branches/developers/matt/u2f/firmware/apps
___________________________________________________________________
Name: svn:ignore
+ *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
Added: gnuradio/branches/developers/matt/u2f/firmware/apps/Makefile.am
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/Makefile.am
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/Makefile.am
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,38 @@
+#
+# Copyright 2007 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+include $(top_srcdir)/Makefile.common
+
+LDADD = ../lib/libu2fw.a
+
+noinst_PROGRAMS = \
+ blink_leds \
+ blink_leds2 \
+ buf_ram_test \
+ buf_ram_zero \
+ eth_test \
+ gen_eth_packets \
+ hello \
+ ibs_rx_test \
+ ibs_tx_test \
+ rcv_eth_packets \
+ test1 \
+ test_phy_comm \
+ timer_test
Property changes on:
gnuradio/branches/developers/matt/u2f/firmware/apps/Makefile.am
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/blink_leds.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// check communication with ethernet PHY chip
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "hal_io.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+#include "pic.h"
+
+
+int
+main(void)
+{
+ int counter = 0;
+
+ u2_init();
+
+
+ while(1){
+ output_regs->leds = (counter++ & 0x3);
+ }
+
+ return 0;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds2.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/blink_leds2.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds2.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/blink_leds2.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,60 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// check communication with ethernet PHY chip
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "hal_io.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+#include "pic.h"
+
+
+// #define DELTA_T 50000000 // 0.5s (10ns per tick)
+#define DELTA_T 500 // 5 us (10ns per tick)
+
+static int led_state_1 = 0;
+volatile static int led_state_2 = 0;
+
+void
+timer_handler(unsigned irq)
+{
+ hal_set_timeout(DELTA_T); // schedule next timeout
+ led_state_2 ^= 0x2;
+}
+
+int
+main(void)
+{
+ u2_init();
+
+ //hal_puts("Setting up timer\n");
+ pic_register_handler(IRQ_TIMER, timer_handler);
+ hal_set_timeout(DELTA_T); // schedule next timeout
+
+ while(1){
+ led_state_1 ^= 0x1;
+ output_regs->leds = led_state_1 | led_state_2;
+ }
+
+ return 0;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_test.c
(from rev 6919, gnuradio/branches/developers/matt/u2f/firmware/buf_ram_test.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_test.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_test.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,130 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// check communication with ethernet PHY chip
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "hal_io.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+#include "pic.h"
+#include "bool.h"
+
+
+// Delay about one millisecond.
+//
+// Need 33,333 cycles at 33 MHz.
+// Each time around the loop is 10 cycles
+
+void
+delay_1ms(void)
+{
+ int i;
+ for (i = 0; i < 3333; i++){
+ asm volatile ("or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n");
+ }
+}
+
+// delay about ms milliseconds
+static void
+mdelay(int ms)
+{
+ int i;
+ for (i = 0; i < ms; i++)
+ delay_1ms();
+}
+
+static void
+write_bufs(void)
+{
+ int i, n;
+ int counter = 0;
+
+ for (n = 0; n < NBUFFERS; n++){
+ volatile int *p = buffer_ram(n);
+ for (i = 0; i < BUFFER_POOL_BUFFER_SIZE; i++)
+ p[i] = counter++;
+ }
+}
+
+// return number of errors detected
+static int
+check_bufs(void)
+{
+ int i, n;
+ int counter = 0;
+ int nerrors = 0;
+
+ for (n = 0; n < NBUFFERS; n++){
+ volatile int *p = buffer_ram(n);
+ for (i = 0; i < BUFFER_POOL_BUFFER_SIZE; i++, counter++){
+ int rd = p[i];
+ if (rd != counter){
+ hal_putc('b');
+ hal_putc(n + '0');
+ hal_putc('[');
+ hal_puthex16(i);
+ hal_puts("] exp: ");
+ hal_puthex32(counter);
+ hal_puts(" got: ");
+ hal_puthex32_nl(rd);
+ nerrors++;
+ }
+ }
+ }
+ return nerrors;
+}
+
+
+int
+main(void)
+{
+ u2_init();
+
+ output_regs->leds = 0;
+
+ if (!hwconfig_simulation_p())
+ mdelay(100);
+
+ output_regs->leds = 0x3;
+
+ if (!hwconfig_simulation_p())
+ mdelay(100);
+
+ output_regs->leds = 0;
+
+ write_bufs();
+ int nerrors = check_bufs();
+
+ if (nerrors == 0)
+ output_regs->leds = 0x3; // leds on -> PASS
+ else
+ output_regs->leds = 0x0; // leds off -> FAIL
+
+ return 0;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_zero.c
(from rev 6919, gnuradio/branches/developers/matt/u2f/firmware/buf_ram_zero.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_zero.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/buf_ram_zero.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,113 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// checks if all buffer reads return 0.
+
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "hal_io.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+#include "pic.h"
+#include "bool.h"
+
+
+// Delay about one millisecond.
+//
+// Need 33,333 cycles at 33 MHz.
+// Each time around the loop is 10 cycles
+
+void
+delay_1ms(void)
+{
+ int i;
+ for (i = 0; i < 3333; i++){
+ asm volatile ("or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n\
+ or r0, r0, r0\n");
+ }
+}
+
+// delay about ms milliseconds
+static void
+mdelay(int ms)
+{
+ int i;
+ for (i = 0; i < ms; i++)
+ delay_1ms();
+}
+
+static void
+write_bufs(void)
+{
+ int i, n;
+ int counter = 0;
+
+ for (n = 0; n < NBUFFERS; n++){
+ volatile int *p = buffer_ram(n);
+ for (i = 0; i < BUFFER_POOL_BUFFER_SIZE; i++)
+ p[i] = counter++;
+ }
+}
+
+// return number of errors detected
+static int
+check_bufs(void)
+{
+ int i, n;
+ int nerrors = 0;
+
+ for (n = 0; n < NBUFFERS; n++){
+ volatile int *p = buffer_ram(n);
+ for (i = 0; i < BUFFER_POOL_BUFFER_SIZE; i++)
+ if (p[i] != 0)
+ nerrors++;
+ }
+ return nerrors;
+}
+
+
+int
+main(void)
+{
+ u2_init();
+
+ output_regs->leds = 0;
+ mdelay(100);
+ output_regs->leds = 0x3;
+ mdelay(100);
+ output_regs->leds = 0;
+
+ write_bufs();
+ int nerrors = check_bufs();
+
+ if (nerrors == 0)
+ output_regs->leds = 0x3; // leds on -> PASS
+ else
+ output_regs->leds = 0x0; // leds off -> FAIL
+
+ return 0;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/eth.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/eth.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/eth.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/eth.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,41 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+
+int
+main(void)
+{
+ u2_init();
+
+
+
+ int i;
+
+ // Write to buffer 0
+ int *buf = (int *)(BUFFER_BASE + BUFFER_0);
+ for(i=0;i<BUFFER_SIZE;i++)
+ buf[i] = i;
+
+ hal_puts("Filled buffer 0\n");
+
+ // Write to buffer 1
+ int *buffer = (int *)(BUFFER_BASE + BUFFER_1);
+ for(i=0;i<BUFFER_SIZE;i++)
+ buf[i] = i + ((i^0xFFFF) << 16);
+
+ hal_puts("Filled buffer 1\n");
+
+ // Control LEDs
+ while(1) {
+ output_regs->leds = 0x00;
+ output_regs->leds = 0x01;
+ output_regs->leds = 0x00;
+ output_regs->leds = 0x01;
+ output_regs->leds = 0x01;
+ output_regs->leds = 0x01;
+ output_regs->leds = 0x03;
+ output_regs->leds = 0x02;
+ }
+
+ return 1;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/eth_test.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/eth_test.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/eth_test.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/eth_test.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,107 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+
+// Globals
+#define EMPTY 0
+#define FILLING 1
+#define FULL 2
+#define EMPTYING 3
+
+#define PORT 2 // ethernet = 2, serdes = 0
+int dsp_rx_buf, dsp_tx_buf, serdes_rx_buf, serdes_tx_buf;
+int dsp_rx_idle, dsp_tx_idle, serdes_rx_idle, serdes_tx_idle;
+
+int buffer_state[4];
+
+static void
+wait_until_status_nonzero(void)
+{
+ while (buffer_pool_status->status == 0)
+ ;
+}
+
+
+int
+main(void)
+{
+ int i;
+
+ u2_init();
+
+ // Write data to be sent into the first buffer
+ volatile unsigned int *buffer0 = buffer_ram(0);
+ volatile unsigned int *buffer1 = buffer_ram(1);
+
+
+ hal_puts("Starting to fill in RAM\n");
+ for(i=0;i<512;i++)
+ buffer0[i] = ((437+i)<<16) + 5395-i;
+ hal_puts("Filled in RAM\n");
+
+ // Set up receive buffer
+ bp_receive_to_buf(1, 2, 1, 0, 511); // Fill from ethernet
+ hal_puts("Set up RX buffer\n");
+
+
+ // Set up send buffer
+ bp_send_from_buf(0, 2, 1, 0, 20);
+ hal_puts("Set up TX Buffer\n");
+
+ while (buffer_pool_status->status != (BPS_DONE_0 | BPS_DONE_1))
+ ;
+
+ bp_clear_buf(0);
+ bp_clear_buf(1);
+
+ hal_puts("Both are done\n");
+
+ // Send a bunch, let them pile up in FIFO
+ bp_send_from_buf(0, 2, 1, 21, 80); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ hal_puts("First add'l TX done\n");
+ bp_send_from_buf(0, 2, 1, 81, 288); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 289, 292); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 293, 326); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 327, 399); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 400, 511); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ hal_puts("All add'l TX done\n");
+
+ bp_receive_to_buf(1, 2, 1, 21, 80); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ hal_puts("First add'l RX done\n");
+ bp_receive_to_buf(1, 2, 1, 81, 288); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 289, 292); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 293, 326); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 327, 399); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 400, 511); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ hal_puts("All add'l RX done\n");
+
+ for(i=0;i<512;i++)
+ if(buffer0[i] != buffer1[i]) {
+ hal_puts("ERROR at location: ");
+ hal_puthex_nl(i);
+ hal_puts("Value sent: ");
+ hal_puthex_nl(buffer0[i]);
+ hal_puts("Value rcvd: ");
+ hal_puthex_nl(buffer1[i]);
+ //break;
+ }
+
+ hal_puts("Done Testing\n");
+
+ hal_finish();
+ return 1;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/gen_eth_packets.c
(from rev 6919,
gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/gen_eth_packets.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/gen_eth_packets.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,353 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+#include "pic.h"
+#include "bool.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+
+typedef int intptr_t;
+typedef unsigned size_t;
+void exit(int status);
+
+// ----------------------------------------------------------------
+
+unsigned char dst_mac_addr[6] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+unsigned char src_mac_addr[6] = {
+ 0x00, 0x0A, 0x35, 0x98, 0x76, 0x54
+};
+
+#define U2_ETHERTYPE 0xBEEF
+
+
+typedef struct {
+ unsigned char dst_addr[6];
+ unsigned char src_addr[6];
+ unsigned short ethertype;
+} ethernet_hdr_t;
+
+typedef struct {
+ ethernet_hdr_t ehdr;
+ unsigned short pktno;
+ unsigned char data[];
+} ethernet_packet_t; // gives us 32-bit aligned packet
+
+
+// ----------------------------------------------------------------
+
+#define PACKET_SIZE 1500 // bytes
+#define ETH_DATA_RATE 1000000 // 1MB/s
+#define ETH_PACKET_RATE (ETH_DATA_RATE/PACKET_SIZE) // 13,3333
pkts/s
+
+#define TIMER_RATE 100000000 // 100 MHz clock
+
+static int timer_delta = TIMER_RATE/ETH_PACKET_RATE; // ticks between
interrupts
+
+static volatile bool send_packet_now = false; // timer handler sets this
+static volatile bool link_is_up = false; // eth handler sets this
+
+int packet_number = 0;
+
+// ----------------------------------------------------------------
+
+// debugging output on tx pins
+#define LS_MASK 0xE0000
+#define LS_1000 0x80000
+#define LS_100 0x40000
+#define LS_10 0x20000
+
+
+/*
+ * Called when eth phy state changes (w/ interrupts disabled)
+ */
+void
+link_changed_callback(int speed)
+{
+ int v = 0;
+ switch(speed){
+ case 10:
+ v = LS_10;
+ link_is_up = true;
+ break;
+
+ case 100:
+ v = LS_100;
+ link_is_up = true;
+ break;
+
+ case 1000:
+ v = LS_100;
+ link_is_up = true;
+ break;
+
+ default:
+ v = 0;
+ link_is_up = false;
+ break;
+ }
+
+ hal_gpio_set_tx(v, LS_MASK); /* set debug bits on d'board */
+
+ hal_puts("\neth link changed: speed = ");
+ hal_puthex16_nl(speed);
+}
+
+void
+timer_irq_handler(unsigned irq)
+{
+ hal_set_timeout(timer_delta); // schedule next timeout
+ send_packet_now = 1;
+}
+
+
+void
+buffer_irq_handler(unsigned irq)
+{
+ // FIXME
+}
+
+/*
+ * For copying to/from non-byte-adressable memory, such as
+ * the buffers
+ */
+void
+memcpy_wordaligned(void *dst, const void *src, size_t nbytes)
+{
+ if (((intptr_t) dst & 0x3)
+ || ((intptr_t) src & 0x3)
+ || (nbytes & 0x3))
+ exit(1); /* die! */
+
+ int *dp = (int *) dst;
+ int *sp = (int *) src;
+ unsigned nw = nbytes/4;
+
+ unsigned i;
+ for (i = 0; i < nw; i++)
+ dp[i] = sp[i];
+}
+
+
+static void
+init_packet(int *buf, const ethernet_packet_t *pkt, int bufnum)
+{
+ int i = 0;
+ int mark = ((bufnum & 0xff) << 24) | 0x005A0000;
+
+ for (i = 0; i < BUFFER_POOL_BUFFER_SIZE; i++){
+ buf[i] = mark | i;
+ mark ^= 0x00FF00000;
+ }
+
+ // copy header into buffer
+ memcpy_wordaligned(buf, pkt, sizeof(*pkt));
+}
+
+static void
+init_packets(void)
+{
+ int i;
+
+ ethernet_packet_t pkt __attribute__((aligned (4)));
+
+ for (i = 0; i < 6; i++){
+ pkt.ehdr.dst_addr[i] = dst_mac_addr[i];
+ pkt.ehdr.src_addr[i] = src_mac_addr[i];
+ }
+ pkt.ehdr.ethertype = U2_ETHERTYPE;
+
+ // fill ALL buffers for debugging
+ for (i = 0; i < 8; i++)
+ init_packet((void *)buffer_ram(i), &pkt, i);
+}
+
+static int led_counter = 0;
+
+int
+main(void)
+{
+ u2_init();
+
+ // setup tx gpio bits for GPIOM_FPGA_1 -- fpga debug output
+ hal_gpio_set_tx_mode(15, 0, GPIOM_FPGA_0);
+ hal_gpio_set_rx_mode(15, 0, GPIOM_FPGA_0); // no printing...
+
+ hal_puts("\ngen_eth_packets\n");
+
+ // Control LEDs
+ output_regs->leds = 0x00;
+
+ init_packets();
+
+ // pic_register_handler(IRQ_BUFFER, buffer_irq_handler); // poll for now
+ pic_register_handler(IRQ_TIMER, timer_irq_handler);
+ hal_set_timeout(timer_delta);
+
+ eth_driver_register_link_changed_callback(link_changed_callback);
+
+ eth_mac_init();
+ eth_driver_init();
+
+ // eth_mac->speed = 4; // FIXME hardcode mac speed to 1000
+
+ while(1){
+ if (link_is_up && send_packet_now){
+ send_packet_now = false;
+
+ // kick off the next packet
+ // FIXME set packet number in packet
+
+ bp_send_from_buf(0, PORT_ETH, 1, 0, 15);
+
+ while ((buffer_pool_status->status & (BPS_DONE_0|BPS_ERROR_0)) == 0)
+ ;
+ bp_clear_buf(0);
+
+ output_regs->leds = ((led_counter++) & 0x1) | (link_is_up ? 0x2 : 0x0);
+ }
+ }
+
+ hal_finish();
+ return 1;
+}
+
+#if 0
+void
+double_buffering(int port) {
+ unsigned int localstatus = buffer_pool_status->status;
+
+ if(localstatus & BPS_DONE_0) {
+ bp_clear_buf(0);
+ if(buffer_state[0] == FILLING) {
+ buffer_state[0] = FULL;
+ if(buffer_state[1] == EMPTY) {
+ bp_receive_to_buf(1, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[1] = FILLING;
+ }
+ else
+ dsp_rx_idle = 1;
+ if(serdes_tx_idle) {
+ serdes_tx_idle = 0;
+ bp_send_from_buf(0, port, 1, 10, 509); // SERDES_TX from buffer 0
+ buffer_state[0] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[0] = EMPTY;
+ if(dsp_rx_idle) {
+ dsp_rx_idle = 0;
+ bp_receive_to_buf(0, 1, 1, 10, 509); // DSP_RX to buffer 0, use 500
lines
+ buffer_state[0] = FILLING;
+ }
+ if(buffer_state[1] == FULL) {
+ bp_send_from_buf(1, port, 1, 10, 509); // SERDES_TX from buffer 1
+ buffer_state[1] = EMPTYING;
+ }
+ else
+ serdes_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 0\n");
+ }
+ if(localstatus & BPS_DONE_1) {
+ bp_clear_buf(1);
+ if(buffer_state[1] == FILLING) {
+ buffer_state[1] = FULL;
+ if(buffer_state[0] == EMPTY) {
+ bp_receive_to_buf(0, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[0] = FILLING;
+ }
+ else
+ dsp_rx_idle = 1;
+ if(serdes_tx_idle) {
+ serdes_tx_idle = 0;
+ bp_send_from_buf(1, port, 1, 10, 509); // SERDES_TX from buffer 1
+ buffer_state[1] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[1] = EMPTY;
+ if(dsp_rx_idle) {
+ dsp_rx_idle = 0;
+ bp_receive_to_buf(1, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[1] = FILLING;
+ }
+ if(buffer_state[0] == FULL) {
+ bp_send_from_buf(0, port, 1, 10, 509); // SERDES_TX from buffer 0
+ buffer_state[0] = EMPTYING;
+ }
+ else
+ serdes_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 1\n");
+ }
+ if(localstatus & BPS_DONE_2) {
+ bp_clear_buf(2);
+ if(buffer_state[2] == FILLING) {
+ buffer_state[2] = FULL;
+ if(buffer_state[3] == EMPTY) {
+ bp_receive_to_buf(3, port, 1, 5, 504); // SERDES_RX to buffer 3, use
500 lines
+ buffer_state[3] = FILLING;
+ }
+ else
+ serdes_rx_idle = 1;
+ if(dsp_tx_idle) {
+ dsp_tx_idle = 0;
+ bp_send_from_buf(2, 1, 1, 5, 504); // DSP_TX from buffer 2
+ buffer_state[2] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[2] = EMPTY;
+ if(serdes_rx_idle) {
+ serdes_rx_idle = 0;
+ bp_receive_to_buf(2, port, 1, 5, 504); // SERDES_RX to buffer 2
+ buffer_state[2] = FILLING;
+ }
+ if(buffer_state[3] == FULL) {
+ bp_send_from_buf(3, 1, 1, 5, 504); // DSP_TX from buffer 3
+ buffer_state[3] = EMPTYING;
+ }
+ else
+ dsp_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 2\n");
+ }
+ if(localstatus & BPS_DONE_3) {
+ bp_clear_buf(3);
+ if(buffer_state[3] == FILLING) {
+ buffer_state[3] = FULL;
+ if(buffer_state[2] == EMPTY) {
+ bp_receive_to_buf(2, port, 1, 5, 504); // SERDES_RX to buffer 2, use
500 lines
+ buffer_state[2] = FILLING;
+ }
+ else
+ serdes_rx_idle = 1;
+ if(dsp_tx_idle) {
+ dsp_tx_idle = 0;
+ bp_send_from_buf(3, 1, 1, 5, 504); // DSP_TX from buffer 3
+ buffer_state[3] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[3] = EMPTY;
+ if(serdes_rx_idle) {
+ serdes_rx_idle = 0;
+ bp_receive_to_buf(3, port, 1, 5, 504); // SERDES_RX to buffer 3
+ buffer_state[3] = FILLING;
+ }
+ if(buffer_state[2] == FULL) {
+ bp_send_from_buf(2, 1, 1, 5, 504); // DSP_TX from buffer 2
+ buffer_state[2] = EMPTYING;
+ }
+ else
+ dsp_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 3\n");
+ }
+}
+#endif
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/hello.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/hello.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/hello.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/hello.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,33 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "u2_init.h"
+#include "hal_io.h"
+
+int
+main(void)
+{
+ u2_init();
+
+ hal_puts("Hello World\r\n");
+
+ return 0;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_rx_test.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/ibs_rx_test.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_rx_test.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_rx_test.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,82 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+
+#define PORT 2 // ethernet = 2, serdes = 0
+int dsp_rx_buf, dsp_tx_buf, serdes_rx_buf, serdes_tx_buf;
+int dsp_rx_idle, dsp_tx_idle, serdes_rx_idle, serdes_tx_idle;
+
+int buffer_state[4];
+
+static void
+wait_until_status_nonzero(void)
+{
+ while (buffer_pool_status->status == 0)
+ ;
+}
+
+int
+main(void)
+{
+ int i;
+
+ u2_init();
+
+ output_regs->adc_ctrl = 0x0A;
+
+ dsp_rx_regs->freq = 0;
+ dsp_rx_regs->scale_i = 1;
+ dsp_rx_regs->scale_q = 1;
+ dsp_rx_regs->decim_rate = 7;
+
+ volatile unsigned int *buffer0 = buffer_ram(0);
+ volatile unsigned int *buffer1 = buffer_ram(1);
+ volatile unsigned int *buffer2 = buffer_ram(2);
+
+ hal_puts("Starting RX\n");
+ bp_clear_buf(0);
+ bp_receive_to_buf(0, 1, 1, 0, 99);
+
+ dsp_rx_regs->rx_command = (50 << 9) | 100; // Numlines, lines per frame
+ dsp_rx_regs->rx_time = 0x0c00;
+
+ dsp_rx_regs->rx_command = (137 << 9) | 50; // Numlines, lines per frame
+ dsp_rx_regs->rx_time = 0x0e00;
+
+ while (buffer_pool_status->status == 0)
+ ;
+ bp_clear_buf(0);
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 1, 1, 0, 99);
+ while (buffer_pool_status->status == 0)
+ ;
+ bp_clear_buf(2);
+ bp_receive_to_buf(2, 1, 1, 0, 99);
+ while (buffer_pool_status->status == 0)
+ ;
+
+ for(i=0;i<100;i++) {
+ hal_puthex(i);
+ hal_puts(" ");
+ hal_puthex_nl(buffer0[i]);
+ }
+ for(i=0;i<60;i++) {
+ hal_puthex(i);
+ hal_puts(" ");
+ hal_puthex_nl(buffer1[i]);
+ }
+ for(i=0;i<60;i++) {
+ hal_puthex(i);
+ hal_puts(" ");
+ hal_puthex_nl(buffer2[i]);
+ }
+ //while(timer_regs -> time < 0x6000)
+ // {}
+
+ hal_puts("Done\n");
+ hal_finish();
+
+ return 1;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_tx_test.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/ibs_tx_test.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_tx_test.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/ibs_tx_test.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,160 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+
+// Globals
+#define EMPTY 0
+#define FILLING 1
+#define FULL 2
+#define EMPTYING 3
+
+#define PORT 2 // ethernet = 2, serdes = 0
+int dsp_rx_buf, dsp_tx_buf, serdes_rx_buf, serdes_tx_buf;
+int dsp_rx_idle, dsp_tx_idle, serdes_rx_idle, serdes_tx_idle;
+
+int buffer_state[4];
+
+static void
+wait_until_status_nonzero(void)
+{
+ while (buffer_pool_status->status == 0)
+ ;
+}
+
+int
+main(void)
+{
+ int i;
+
+ u2_init();
+
+ dsp_tx_regs->freq = 0;
+ dsp_tx_regs->scale_i = 1;
+ dsp_tx_regs->scale_q = 1;
+ dsp_tx_regs->interp_rate = 7;
+
+ // Write data to be sent into the first buffer
+ volatile unsigned int *buffer0 = buffer_ram(0);
+ volatile unsigned int *buffer1 = buffer_ram(1);
+
+
+ hal_puts("Starting to fill in RAM\n");
+ for(i=0;i<512;i++)
+ buffer0[i] = i;
+ hal_puts("Filled in RAM\n");
+
+ buffer0[0] = 7; // start and end of buffer, send immediately
+ buffer0[1] = 0x0000; // start time
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 1, 1, 0, 9);
+ while (buffer_pool_status->status == 0)
+ ;
+ while(timer_regs -> time < 0x6000)
+ {}
+
+ buffer0[0] = 3; // start and end of buffer
+ buffer0[1] = 0x8000; // start time
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 1, 1, 0, 9);
+ while (buffer_pool_status->status == 0)
+ ;
+ while(timer_regs -> time < 0x8400)
+ {}
+
+ buffer0[0] = 3; // start and end of buffer
+ buffer0[1] = 0x8800; // start time
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 1, 1, 0, 9);
+ while (buffer_pool_status->status == 0)
+ ;
+ while(timer_regs -> time < 0x9000)
+ {}
+
+ buffer0[0] = 0x2; // not last
+ buffer0[1] = 0x9100; // start time
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 1, 1, 0, 9);
+ while (buffer_pool_status->status == 0)
+ ;
+ buffer0[0] = 0x1; // last
+ buffer0[1] = 0x0000; // start time
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 1, 1, 0, 9);
+ while (buffer_pool_status->status == 0)
+ ;
+
+
+ buffer0[0] = 0x3; // first and last
+ buffer0[1] = 0x8000; // Time in the past
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 1, 1, 0, 9);
+ while (buffer_pool_status->status == 0)
+ ;
+
+ /*
+ buffer0[0] = 0x2; // not last
+ buffer0[1] = 0x9600; // start time
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 1, 1, 0, 9);
+ while (buffer_pool_status->status == 0)
+ ;
+ */
+
+ while(timer_regs -> time < 0xa000)
+ {}
+
+ hal_puts("Done\n");
+
+ while(1)
+ {}
+ hal_finish();
+
+ // Send a bunch, let them pile up in FIFO
+ bp_send_from_buf(0, 2, 1, 21, 80); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ hal_puts("First add'l TX done\n");
+ bp_send_from_buf(0, 2, 1, 81, 288); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 289, 292); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 293, 326); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 327, 399); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ bp_send_from_buf(0, 2, 1, 400, 511); wait_until_status_nonzero();
+ bp_clear_buf(0);
+ hal_puts("All add'l TX done\n");
+
+ bp_receive_to_buf(1, 2, 1, 21, 80); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ hal_puts("First add'l RX done\n");
+ bp_receive_to_buf(1, 2, 1, 81, 288); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 289, 292); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 293, 326); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 327, 399); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ bp_receive_to_buf(1, 2, 1, 400, 511); wait_until_status_nonzero();
+ bp_clear_buf(1);
+ hal_puts("All add'l RX done\n");
+
+ for(i=0;i<512;i++)
+ if(buffer0[i] != buffer1[i]) {
+ hal_puts("ERROR at location: ");
+ hal_puthex_nl(i);
+ hal_puts("Value sent: ");
+ hal_puthex_nl(buffer0[i]);
+ hal_puts("Value rcvd: ");
+ hal_puthex_nl(buffer1[i]);
+ //break;
+ }
+
+ hal_puts("Done Testing\n");
+
+ hal_finish();
+ return 1;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/rcv_eth_packets.c
(from rev 6919,
gnuradio/branches/developers/matt/u2f/firmware/rcv_eth_packets.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/rcv_eth_packets.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/rcv_eth_packets.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,418 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+#include "pic.h"
+#include "bool.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+
+typedef int intptr_t;
+typedef unsigned size_t;
+void exit(int status);
+
+// ----------------------------------------------------------------
+
+unsigned char dst_mac_addr[6] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+unsigned char src_mac_addr[6] = {
+ 0x00, 0x0A, 0x35, 0x98, 0x76, 0x54
+};
+
+#define U2_ETHERTYPE 0xBEEF
+
+
+typedef struct {
+ unsigned char dst_addr[6];
+ unsigned char src_addr[6];
+ unsigned short ethertype;
+} ethernet_hdr_t;
+
+typedef struct {
+ ethernet_hdr_t ehdr;
+ unsigned short pktno;
+ unsigned char data[];
+} ethernet_packet_t; // gives us 32-bit aligned packet
+
+
+// ----------------------------------------------------------------
+
+#define PACKET_SIZE 1500 // bytes
+#define ETH_DATA_RATE 1000000 // 1MB/s
+#define ETH_PACKET_RATE (ETH_DATA_RATE/PACKET_SIZE) // 13,3333
pkts/s
+
+#define TIMER_RATE 100000000 // 100 MHz clock
+
+static int timer_delta = TIMER_RATE/ETH_PACKET_RATE; // ticks between
interrupts
+
+static volatile bool send_packet_now = false; // timer handler sets this
+static volatile bool link_is_up = false; // eth handler sets this
+
+int packet_number = 0;
+
+// ----------------------------------------------------------------
+
+// debugging output on tx pins
+#define LS_MASK 0xE0000
+#define LS_1000 0x80000
+#define LS_100 0x40000
+#define LS_10 0x20000
+
+
+/*
+ * Called when eth phy state changes (w/ interrupts disabled)
+ */
+void
+link_changed_callback(int speed)
+{
+ int v = 0;
+ switch(speed){
+ case 10:
+ v = LS_10;
+ link_is_up = true;
+ break;
+
+ case 100:
+ v = LS_100;
+ link_is_up = true;
+ break;
+
+ case 1000:
+ v = LS_100;
+ link_is_up = true;
+ break;
+
+ default:
+ v = 0;
+ link_is_up = false;
+ break;
+ }
+
+ hal_gpio_set_tx(v, LS_MASK); /* set debug bits on d'board */
+
+ hal_puts("\neth link changed: speed = ");
+ hal_puthex16_nl(speed);
+}
+
+void
+timer_irq_handler(unsigned irq)
+{
+ hal_set_timeout(timer_delta); // schedule next timeout
+ send_packet_now = 1;
+}
+
+
+void
+buffer_irq_handler(unsigned irq)
+{
+ // FIXME
+}
+
+/*
+ * For copying to/from non-byte-adressable memory, such as
+ * the buffers
+ */
+void
+memcpy_wordaligned(void *dst, const void *src, size_t nbytes)
+{
+ if (((intptr_t) dst & 0x3)
+ || ((intptr_t) src & 0x3)
+ || (nbytes & 0x3))
+ exit(1); /* die! */
+
+ int *dp = (int *) dst;
+ int *sp = (int *) src;
+ unsigned nw = nbytes/4;
+
+ unsigned i;
+ for (i = 0; i < nw; i++)
+ dp[i] = sp[i];
+}
+
+
+static void
+init_packet(int *buf, const ethernet_packet_t *pkt)
+{
+#if 1
+ // copy header into buffer
+ memcpy_wordaligned(buf, pkt, sizeof(*pkt));
+#else
+ buf[1] = 0xffff000A;
+ buf[2] = 0x35987654;
+ buf[3] = 0xBEEF0000;
+#endif
+
+ union {
+ int i;
+ char c[4];
+ } u;
+
+ int *p = (int *)((char *) buf + sizeof(*pkt));
+ int *end = buf + BUFFER_POOL_BUFFER_SIZE;
+
+ int i = 0;
+ for (; p < end; p++, i += 4){
+ u.c[0] = i;
+ u.c[1] = i+1;
+ u.c[2] = i+2;
+ u.c[3] = i+3;
+ *p = u.i;
+ }
+}
+
+static void
+init_packets(void)
+{
+ int i;
+
+ ethernet_packet_t pkt __attribute__((aligned (4)));
+
+ for (i = 0; i < 6; i++){
+ pkt.ehdr.dst_addr[i] = dst_mac_addr[i];
+ pkt.ehdr.src_addr[i] = src_mac_addr[i];
+ }
+ pkt.ehdr.ethertype = U2_ETHERTYPE;
+
+ init_packet((void *) buffer_ram(0), &pkt);
+ init_packet((void *) buffer_ram(1), &pkt);
+}
+
+void
+print_mac_addr(const char *addr) /* 6-bytes */
+{
+ hal_puthex8(addr[0]); hal_putc(':');
+ hal_puthex8(addr[1]); hal_putc(':');
+ hal_puthex8(addr[2]); hal_putc(':');
+ hal_puthex8(addr[3]); hal_putc(':');
+ hal_puthex8(addr[4]); hal_putc(':');
+ hal_puthex8(addr[5]);
+}
+
+
+int
+main(void)
+{
+ u2_init();
+
+ int prev_leds = -1;
+ int new_leds = 0x00;
+ output_regs->leds = 0x00;
+
+ int peak_hold_count = 0;
+
+ // setup tx gpio bits for GPIOM_FPGA_1 -- fpga debug output
+ hal_gpio_set_tx_mode(15, 0, GPIOM_FPGA_1);
+
+ hal_puts("\nrcv_eth_packets\n");
+
+ init_packets();
+
+ // pic_register_handler(IRQ_BUFFER, buffer_irq_handler); // poll for now
+
+ // FIXME turn off timer since I don't think MTS and MFS instructions are
implemented
+ // pic_register_handler(IRQ_TIMER, timer_irq_handler);
+ // hal_set_timeout(timer_delta);
+
+ eth_driver_register_link_changed_callback(link_changed_callback);
+
+ eth_mac_init();
+ eth_driver_init();
+
+ //eth_mac->speed = 4; // FIXME hardcode mac speed to 1000
+
+ // kick off a receive
+ bp_receive_to_buf(2, PORT_ETH, 1, 0, 511);
+
+ while(1){
+ ethernet_packet_t pkt __attribute__((aligned (4)));
+
+ new_leds = 0;
+ if (link_is_up)
+ new_leds = 0x2;
+
+ if ((buffer_pool_status->status & (BPS_DONE_2|BPS_ERROR_2)) != 0){
+ // we've got a packet!
+
+#if 0
+ // copy to stack buffer so we can byte address it
+ memcpy_wordaligned(&pkt, (void *)buffer_ram(2), sizeof(pkt));
+
+ hal_puts("Rx: src: ");
+ print_mac_addr(pkt.ehdr.dst_addr);
+ hal_puts(" dst: ");
+ print_mac_addr(pkt.ehdr.src_addr);
+ hal_puts(" ethtype: ");
+ hal_puthex16(pkt.ehdr.ethertype);
+ hal_puts(" len: ");
+ int len = (buffer_pool_status->last_line[2] + 1) * 4;
+ hal_puthex16_nl(len);
+#else
+ volatile int *bp = buffer_ram(2);
+ int i;
+ for (i = 0; i < 16; i++){
+ hal_puthex8(i);
+ hal_putc(':');
+ hal_puthex32_nl(bp[i]);
+ }
+#endif
+
+ // kick off next receive
+ bp_clear_buf(2);
+ bp_receive_to_buf(2, PORT_ETH, 1, 0, 511);
+
+ peak_hold_count = 2048 * 10;
+ }
+
+ if (peak_hold_count > 0){
+ peak_hold_count--;
+ new_leds |= 0x1;
+ }
+
+ if (new_leds != prev_leds){
+ prev_leds = new_leds;
+ output_regs->leds = new_leds;
+ }
+ }
+
+ hal_finish();
+ return 1;
+}
+
+#if 0
+void
+double_buffering(int port) {
+ unsigned int localstatus = buffer_pool_status->status;
+
+ if(localstatus & BPS_DONE_0) {
+ bp_clear_buf(0);
+ if(buffer_state[0] == FILLING) {
+ buffer_state[0] = FULL;
+ if(buffer_state[1] == EMPTY) {
+ bp_receive_to_buf(1, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[1] = FILLING;
+ }
+ else
+ dsp_rx_idle = 1;
+ if(serdes_tx_idle) {
+ serdes_tx_idle = 0;
+ bp_send_from_buf(0, port, 1, 10, 509); // SERDES_TX from buffer 0
+ buffer_state[0] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[0] = EMPTY;
+ if(dsp_rx_idle) {
+ dsp_rx_idle = 0;
+ bp_receive_to_buf(0, 1, 1, 10, 509); // DSP_RX to buffer 0, use 500
lines
+ buffer_state[0] = FILLING;
+ }
+ if(buffer_state[1] == FULL) {
+ bp_send_from_buf(1, port, 1, 10, 509); // SERDES_TX from buffer 1
+ buffer_state[1] = EMPTYING;
+ }
+ else
+ serdes_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 0\n");
+ }
+ if(localstatus & BPS_DONE_1) {
+ bp_clear_buf(1);
+ if(buffer_state[1] == FILLING) {
+ buffer_state[1] = FULL;
+ if(buffer_state[0] == EMPTY) {
+ bp_receive_to_buf(0, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[0] = FILLING;
+ }
+ else
+ dsp_rx_idle = 1;
+ if(serdes_tx_idle) {
+ serdes_tx_idle = 0;
+ bp_send_from_buf(1, port, 1, 10, 509); // SERDES_TX from buffer 1
+ buffer_state[1] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[1] = EMPTY;
+ if(dsp_rx_idle) {
+ dsp_rx_idle = 0;
+ bp_receive_to_buf(1, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[1] = FILLING;
+ }
+ if(buffer_state[0] == FULL) {
+ bp_send_from_buf(0, port, 1, 10, 509); // SERDES_TX from buffer 0
+ buffer_state[0] = EMPTYING;
+ }
+ else
+ serdes_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 1\n");
+ }
+ if(localstatus & BPS_DONE_2) {
+ bp_clear_buf(2);
+ if(buffer_state[2] == FILLING) {
+ buffer_state[2] = FULL;
+ if(buffer_state[3] == EMPTY) {
+ bp_receive_to_buf(3, port, 1, 5, 504); // SERDES_RX to buffer 3, use
500 lines
+ buffer_state[3] = FILLING;
+ }
+ else
+ serdes_rx_idle = 1;
+ if(dsp_tx_idle) {
+ dsp_tx_idle = 0;
+ bp_send_from_buf(2, 1, 1, 5, 504); // DSP_TX from buffer 2
+ buffer_state[2] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[2] = EMPTY;
+ if(serdes_rx_idle) {
+ serdes_rx_idle = 0;
+ bp_receive_to_buf(2, port, 1, 5, 504); // SERDES_RX to buffer 2
+ buffer_state[2] = FILLING;
+ }
+ if(buffer_state[3] == FULL) {
+ bp_send_from_buf(3, 1, 1, 5, 504); // DSP_TX from buffer 3
+ buffer_state[3] = EMPTYING;
+ }
+ else
+ dsp_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 2\n");
+ }
+ if(localstatus & BPS_DONE_3) {
+ bp_clear_buf(3);
+ if(buffer_state[3] == FILLING) {
+ buffer_state[3] = FULL;
+ if(buffer_state[2] == EMPTY) {
+ bp_receive_to_buf(2, port, 1, 5, 504); // SERDES_RX to buffer 2, use
500 lines
+ buffer_state[2] = FILLING;
+ }
+ else
+ serdes_rx_idle = 1;
+ if(dsp_tx_idle) {
+ dsp_tx_idle = 0;
+ bp_send_from_buf(3, 1, 1, 5, 504); // DSP_TX from buffer 3
+ buffer_state[3] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[3] = EMPTY;
+ if(serdes_rx_idle) {
+ serdes_rx_idle = 0;
+ bp_receive_to_buf(3, port, 1, 5, 504); // SERDES_RX to buffer 3
+ buffer_state[3] = FILLING;
+ }
+ if(buffer_state[2] == FULL) {
+ bp_send_from_buf(2, 1, 1, 5, 504); // DSP_TX from buffer 2
+ buffer_state[2] = EMPTYING;
+ }
+ else
+ dsp_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 3\n");
+ }
+}
+#endif
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/test1.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/test1.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/test1.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/test1.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,282 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+#include "pic.h"
+
+// Globals
+#define EMPTY 0
+#define FILLING 1
+#define FULL 2
+#define EMPTYING 3
+
+#define PORT 2 // ethernet = 2, serdes = 0
+int dsp_rx_buf, dsp_tx_buf, serdes_rx_buf, serdes_tx_buf;
+int dsp_rx_idle, dsp_tx_idle, serdes_rx_idle, serdes_tx_idle;
+
+int buffer_state[4];
+
+
+void double_buffering(int port);
+
+//
+// We register this in the secondary interrupt vector.
+// It's called on buffer manager interrupts
+//
+void
+buffer_irq_handler(unsigned irq)
+{
+ double_buffering(PORT);
+}
+
+int
+main(void)
+{
+ int i;
+
+ u2_init();
+
+ // Control LEDs
+ output_regs->leds = 0x02;
+
+ // Turn on ADCs
+ output_regs->adc_ctrl = 0x0A;
+
+ // Set up TX Chain
+ dsp_tx_regs->freq = 0;
+ dsp_tx_regs->scale_i = 1;
+ dsp_tx_regs->scale_q = 1;
+ dsp_tx_regs->interp_rate = 7;
+
+ // Set up RX Chain
+ dsp_rx_regs->freq = 0;
+ dsp_rx_regs->scale_i = 1;
+ dsp_rx_regs->scale_q = 1;
+ dsp_rx_regs->decim_rate = 7;
+
+ // Set up buffer control, using only 4 for now
+ for(i=0;i<4;i++)
+ buffer_state[i] = EMPTY;
+
+ // Set up DSP RX
+ buffer_state[0] = FILLING;
+ serdes_tx_idle = 1;
+ bp_receive_to_buf(0, 1, 1, 10, 509); // DSP_RX to buffer 0, use 500 lines
+
+ //dsp_rx_regs->run_rx = 1; // Start DSP_RX
+ hal_puts("Done DSP RX setup\n");
+
+ // Set up serdes RX
+ buffer_state[2] = FILLING;
+ dsp_tx_idle = 1;
+ bp_receive_to_buf(2, PORT, 1, 5, 504);
+
+ while (buffer_pool_status->status == 0) // wait for completion of DSP RX
+ ;
+
+ hal_puts("Done DSP TX setup\n");
+ //dsp_tx_regs->run_tx = 1;
+
+ // register interrupt handler
+ pic_register_handler(IRQ_BUFFER, buffer_irq_handler);
+
+ u2_infinite_loop();
+
+ hal_finish();
+ return 1;
+}
+
+void
+double_buffering(int port) {
+ unsigned int localstatus = buffer_pool_status->status;
+
+ if(localstatus & BPS_DONE_0) {
+ bp_clear_buf(0);
+ if(buffer_state[0] == FILLING) {
+ buffer_state[0] = FULL;
+ if(buffer_state[1] == EMPTY) {
+ bp_receive_to_buf(1, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[1] = FILLING;
+ }
+ else
+ dsp_rx_idle = 1;
+ if(serdes_tx_idle) {
+ serdes_tx_idle = 0;
+ bp_send_from_buf(0, port, 1, 10, 509); // SERDES_TX from buffer 0
+ buffer_state[0] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[0] = EMPTY;
+ if(dsp_rx_idle) {
+ dsp_rx_idle = 0;
+ bp_receive_to_buf(0, 1, 1, 10, 509); // DSP_RX to buffer 0, use 500
lines
+ buffer_state[0] = FILLING;
+ }
+ if(buffer_state[1] == FULL) {
+ bp_send_from_buf(1, port, 1, 10, 509); // SERDES_TX from buffer 1
+ buffer_state[1] = EMPTYING;
+ }
+ else
+ serdes_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 0\n");
+ }
+ if(localstatus & BPS_DONE_1) {
+ bp_clear_buf(1);
+ if(buffer_state[1] == FILLING) {
+ buffer_state[1] = FULL;
+ if(buffer_state[0] == EMPTY) {
+ bp_receive_to_buf(0, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[0] = FILLING;
+ }
+ else
+ dsp_rx_idle = 1;
+ if(serdes_tx_idle) {
+ serdes_tx_idle = 0;
+ bp_send_from_buf(1, port, 1, 10, 509); // SERDES_TX from buffer 1
+ buffer_state[1] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[1] = EMPTY;
+ if(dsp_rx_idle) {
+ dsp_rx_idle = 0;
+ bp_receive_to_buf(1, 1, 1, 10, 509); // DSP_RX to buffer 1, use 500
lines
+ buffer_state[1] = FILLING;
+ }
+ if(buffer_state[0] == FULL) {
+ bp_send_from_buf(0, port, 1, 10, 509); // SERDES_TX from buffer 0
+ buffer_state[0] = EMPTYING;
+ }
+ else
+ serdes_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 1\n");
+ }
+ if(localstatus & BPS_DONE_2) {
+ bp_clear_buf(2);
+ if(buffer_state[2] == FILLING) {
+ buffer_state[2] = FULL;
+ if(buffer_state[3] == EMPTY) {
+ bp_receive_to_buf(3, port, 1, 5, 504); // SERDES_RX to buffer 3, use
500 lines
+ buffer_state[3] = FILLING;
+ }
+ else
+ serdes_rx_idle = 1;
+ if(dsp_tx_idle) {
+ dsp_tx_idle = 0;
+ bp_send_from_buf(2, 1, 1, 5, 504); // DSP_TX from buffer 2
+ buffer_state[2] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[2] = EMPTY;
+ if(serdes_rx_idle) {
+ serdes_rx_idle = 0;
+ bp_receive_to_buf(2, port, 1, 5, 504); // SERDES_RX to buffer 2
+ buffer_state[2] = FILLING;
+ }
+ if(buffer_state[3] == FULL) {
+ bp_send_from_buf(3, 1, 1, 5, 504); // DSP_TX from buffer 3
+ buffer_state[3] = EMPTYING;
+ }
+ else
+ dsp_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 2\n");
+ }
+ if(localstatus & BPS_DONE_3) {
+ bp_clear_buf(3);
+ if(buffer_state[3] == FILLING) {
+ buffer_state[3] = FULL;
+ if(buffer_state[2] == EMPTY) {
+ bp_receive_to_buf(2, port, 1, 5, 504); // SERDES_RX to buffer 2, use
500 lines
+ buffer_state[2] = FILLING;
+ }
+ else
+ serdes_rx_idle = 1;
+ if(dsp_tx_idle) {
+ dsp_tx_idle = 0;
+ bp_send_from_buf(3, 1, 1, 5, 504); // DSP_TX from buffer 3
+ buffer_state[3] = EMPTYING;
+ }
+ }
+ else { // buffer was emptying
+ buffer_state[3] = EMPTY;
+ if(serdes_rx_idle) {
+ serdes_rx_idle = 0;
+ bp_receive_to_buf(3, port, 1, 5, 504); // SERDES_RX to buffer 3
+ buffer_state[3] = FILLING;
+ }
+ if(buffer_state[2] == FULL) {
+ bp_send_from_buf(2, 1, 1, 5, 504); // DSP_TX from buffer 2
+ buffer_state[2] = EMPTYING;
+ }
+ else
+ dsp_tx_idle = 1;
+ }
+ hal_puts("Int Proc'ed 3\n");
+ }
+}
+
+// Spare Code
+
+#if 0
+ // Set up LSDAC
+ int i = 0;
+ while(1) {
+ int command = (3 << 19) | (0 << 16) | (i & 0xffff);
+ spi_transact(SPI_TXONLY, SPI_SS_TX_DAC, command, 24, 1); // negate TX phase
+ i++;
+ }
+#endif
+
+#if 0
+ // Write to buffer 0
+ int *buf = (int *)(BUFFER_BASE + BUFFER_0);
+ hal_puthex_nl((int)buf);
+
+ for(i=0;i<BUFFER_SIZE;i++)
+ buf[i] = i;
+
+ hal_puts("Filled buffer 0\n");
+
+ // Write to buffer 1
+ buf = (int *)(BUFFER_BASE + BUFFER_1);
+ hal_puthex_nl((int)buf);
+ for(i=0;i<BUFFER_SIZE;i++)
+ buf[i] = i + ((i^0xFFFF) << 16);
+
+ hal_puts("Filled buffer 1\n");
+
+#endif
+
+#if 0
+ // rx SERDES into buffer #2 (buf,port,step,fl,ll)
+ bp_receive_to_buf(2, 0, 1, 10, 300);
+ hal_puts("SERDES RX buffer setup\n");
+
+ // send SERDES from buffer #0 (buf,port,step,fl,ll)
+ bp_send_from_buf(0, 0, 1, 20, 200);
+ hal_puts("SERDES TX buffer setup\n");
+
+#endif
+
+#if 0
+ // send to DACs from buffer #1
+ bp_send_from_buf(1 /*buf#*/, 1 /*port*/, 1 /*step*/, 20 /*fl*/, 250 /*ll*/);
+ hal_puts("DAC Buffer setup\n");
+#endif
+
+#if 0
+ //hal_puts("ENTER INT\n");
+ for(i=0;i<8;i++)
+ if(*status & (1<<i)) {
+ //hal_puts("Clearing buf ");
+ hal_puthex_nl(i);
+ bp_clear_buf(i);
+ }
+ //hal_puts("EXIT INT\n");
+#endif
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/test_phy_comm.c
(from rev 6919, gnuradio/branches/developers/matt/u2f/firmware/test_phy_comm.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/test_phy_comm.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/test_phy_comm.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,111 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// check communication with ethernet PHY chip
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "hal_io.h"
+#include "eth_driver.h"
+#include "eth_mac.h"
+#include "pic.h"
+
+
+#define DELTA_T 12500000 // .125s (10ns per tick)
+//#define DELTA_T 10000
+
+// debugging output on tx pins
+#define LS_MASK 0xE0000
+#define LS_1000 0x80000
+#define LS_100 0x40000
+#define LS_10 0x20000
+
+
+static volatile int led_link_up_flag = 0;
+
+/*
+ * Called when eth phy state changes (w/ interrupts disabled)
+ */
+void
+link_changed_callback(int speed)
+{
+ int v = 0;
+ switch(speed){
+ case 10:
+ v = LS_10;
+ led_link_up_flag = 0x2;
+ break;
+
+ case 100:
+ v = LS_100;
+ led_link_up_flag = 0x2;
+ break;
+
+ case 1000:
+ v = LS_100;
+ led_link_up_flag = 0x2;
+ break;
+
+ default:
+ v = 0;
+ led_link_up_flag = 0;
+ break;
+ }
+
+ hal_gpio_set_tx(v, LS_MASK); /* set debug bits on d'board */
+
+ hal_puts("\neth link changed: speed = ");
+ hal_puthex_nl(speed);
+}
+
+void
+timer_handler(unsigned irq)
+{
+ static int led_counter = 0;
+
+ hal_set_timeout(DELTA_T); // schedule next timeout
+ output_regs->leds = (led_counter++ & 0x1) | led_link_up_flag;
+}
+
+int
+main(void)
+{
+ u2_init();
+
+ hal_puts("\n test_phy_comm\n");
+
+ pic_register_handler(IRQ_TIMER, timer_handler);
+ hal_set_timeout(DELTA_T); // schedule timeout
+
+ hal_gpio_set_tx_mode(15, 13, GPIOM_OUTPUT);
+
+ eth_driver_register_link_changed_callback(link_changed_callback);
+
+ output_regs->phy_ctrl = 1; /* reset the eth PHY */
+ output_regs->phy_ctrl = 0;
+
+ eth_mac_init();
+ eth_driver_init();
+
+ u2_infinite_loop();
+
+ return 0;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/apps/timer_test.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/timer_test.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/apps/timer_test.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/apps/timer_test.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,40 @@
+#include "u2_init.h"
+#include "memory_map.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+#include "pic.h"
+
+
+#define DELTA_T 500 // 5 us (10ns per tick)
+
+
+void
+timer_handler(unsigned irq)
+{
+ int t = timer_regs->time;
+ timer_regs->time = t + DELTA_T;
+
+ hal_puts("Tick: ");
+ hal_puthex_nl(t);
+}
+
+int
+main(void)
+{
+ u2_init();
+
+ // setup timer
+
+ hal_puts("Setting up timer\n");
+ pic_register_handler(IRQ_TIMER, timer_handler);
+
+ int t = timer_regs->time;
+ timer_regs->time = t + DELTA_T;
+
+ u2_infinite_loop();
+
+ hal_puts("Done Testing\n");
+
+ hal_finish();
+ return 1;
+}
Deleted: gnuradio/branches/developers/matt/u2f/firmware/blink_leds.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/blink_leds2.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/bool.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/buf_ram_test.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/buf_ram_zero.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/buffer_pool.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/buffer_pool.h
Modified: gnuradio/branches/developers/matt/u2f/firmware/configure.ac
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/configure.ac 2007-11-15
03:54:53 UTC (rev 6919)
+++ gnuradio/branches/developers/matt/u2f/firmware/configure.ac 2007-11-15
15:39:09 UTC (rev 6920)
@@ -20,7 +20,7 @@
AC_INIT
AC_PREREQ(2.57)
dnl AM_CONFIG_HEADER(config.h)
-AC_CONFIG_SRCDIR([u2_init.c])
+AC_CONFIG_SRCDIR([lib/u2_init.c])
AM_INIT_AUTOMAKE(u2f,0.0svn)
@@ -35,7 +35,9 @@
dnl AC_PROG_RANLIB([mb-ranlib])
AC_CONFIG_FILES([\
- Makefile
+ Makefile \
+ apps/Makefile \
+ lib/Makefile \
])
AC_OUTPUT
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eeprom.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth_driver.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth_driver.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth_mac.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth_mac.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth_mac_regs.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth_phy.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/eth_test.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/gen_eth_packets.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/hal_io.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/hal_io.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/hal_uart.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/hal_uart.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/hello.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/i2c.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/i2c.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/ibs_rx_test.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/ibs_tx_test.c
Property changes on: gnuradio/branches/developers/matt/u2f/firmware/lib
___________________________________________________________________
Name: svn:ignore
+ *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
Added: gnuradio/branches/developers/matt/u2f/firmware/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/Makefile.am
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/Makefile.am
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,35 @@
+#
+# Copyright 2007 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+include $(top_srcdir)/Makefile.common
+
+noinst_LIBRARIES = \
+ libu2fw.a
+
+libu2fw_a_SOURCES = \
+ buffer_pool.c \
+ eth_driver.c \
+ eth_mac.c \
+ hal_io.c \
+ hal_uart.c \
+ i2c.c \
+ pic.c \
+ spi.c \
+ u2_init.c
Property changes on:
gnuradio/branches/developers/matt/u2f/firmware/lib/Makefile.am
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/bool.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/bool.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/bool.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/bool.h 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,29 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_BOOL_H
+#define INCLUDED_BOOL_H
+
+typedef int bool;
+#define true 1
+#define false 0
+
+#endif /* INCLUDED_BOOL_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/buffer_pool.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,12 @@
+#include "memory_map.h"
+#include "buffer_pool.h"
+#include "hal_io.h"
+
+void
+bp_init(void)
+{
+ bp_disable_port(PORT_SERDES);
+ bp_disable_port(PORT_DSP);
+ bp_disable_port(PORT_ETH);
+ bp_disable_port(PORT_RAM);
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.h (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/buffer_pool.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/buffer_pool.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,45 @@
+#ifndef INCLUDED_BUFFER_POOL_H
+#define INCLUDED_BUFFER_POOL_H
+
+#include "memory_map.h"
+
+// Buffer Pool Management
+
+void bp_init(void);
+
+static inline void
+bp_clear_buf(int bufnum)
+{
+ buffer_pool_ctrl->ctrl = BPC_BUFFER(bufnum) | BPC_PORT_NIL | BPC_CLR;
+}
+
+static inline void
+bp_disable_port(int portnum)
+{
+ // disable buffer connections to this port
+ buffer_pool_ctrl->ctrl = BPC_BUFFER_NIL | BPC_PORT(portnum);
+}
+
+static inline void
+bp_receive_to_buf(int bufnum, int port, int step, int fl, int ll)
+{
+ buffer_pool_ctrl->ctrl = (BPC_READ
+ | BPC_BUFFER(bufnum)
+ | BPC_PORT(port)
+ | BPC_STEP(step)
+ | BPC_FIRST_LINE(fl)
+ | BPC_LAST_LINE(ll));
+}
+
+static inline void
+bp_send_from_buf(int bufnum, int port, int step, int fl, int ll)
+{
+ buffer_pool_ctrl->ctrl = (BPC_WRITE
+ | BPC_BUFFER(bufnum)
+ | BPC_PORT(port)
+ | BPC_STEP(step)
+ | BPC_FIRST_LINE(fl)
+ | BPC_LAST_LINE(ll));
+}
+
+#endif
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/eeprom.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/eeprom.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/eeprom.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/eeprom.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,70 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+static const int EEPROM_PAGESIZE = 16;
+
+bool
+eeprom_write (int i2c_addr, int eeprom_offset, const void *buf, int len)
+{
+ unsigned char cmd[2];
+ const unsigned char *p = (unsigned char *) buf;
+
+ // The simplest thing that could possibly work:
+ // all writes are single byte writes.
+ //
+ // We could speed this up using the page write feature,
+ // but we write so infrequently, why bother...
+
+ while (len-- > 0){
+ cmd[0] = eeprom_offset++;
+ cmd[1] = *p++;
+ bool r = i2c_write (i2c_addr, cmd, sizeof (cmd));
+ mdelay (10); // delay 10ms worst case write time
+ if (!r)
+ return false;
+ }
+ return true;
+}
+
+bool
+eeprom_read (int i2c_addr, int eeprom_offset, void *buf, int len)
+{
+ unsigned char *p = (unsigned char *) buf;
+
+ // We setup a random read by first doing a "zero byte write".
+ // Writes carry an address. Reads use an implicit address.
+
+ unsigned char cmd[1];
+ cmd[0] = eeprom_offset;
+ if (!i2c_write (udh, i2c_addr, cmd, sizeof (cmd)))
+ return false;
+
+ while (len > 0){
+ // int n = std::min (len, MAX_EP0_PKTSIZE);
+ int n = len;
+ if (!i2c_read (i2c_addr, p, n))
+ return false;
+ len -= n;
+ p += n;
+ }
+ return true;
+}
+
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.c (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/eth_driver.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,201 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "eth_driver.h"
+#include "memory_map.h"
+#include "eth_phy.h"
+#include "eth_mac.h"
+#include "eth_mac_regs.h"
+#include "pic.h"
+#include "hal_io.h"
+
+static eth_driver_t ed_state;
+static ed_link_changed_callback_t ed_callback = 0;
+
+void
+eth_driver_register_link_changed_callback(ed_link_changed_callback_t
new_callback)
+{
+ ed_callback = new_callback;
+}
+
+
+static void
+ed_set_mac_speed(int speed)
+{
+ switch(speed){
+ case 10:
+ eth_mac->speed = 1;
+ break;
+ case 100:
+ eth_mac->speed = 2;
+ break;
+ case 1000:
+ eth_mac->speed = 4;
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+ed_link_up(int speed)
+{
+ // hal_puts("ed_link_up: "); hal_puthex16_nl(speed);
+
+ ed_set_mac_speed(speed);
+
+ if (ed_callback) // fire link changed callback
+ (*ed_callback)(speed);
+}
+
+static void
+ed_link_down(void)
+{
+ // hal_puts("ed_link_down\n");
+
+ if (ed_callback) // fire link changed callback
+ (*ed_callback)(0);
+}
+
+
+static void
+ed_link_speed_change(int speed)
+{
+ hal_puts("ed_link_speed_change: "); hal_puthex16_nl(speed);
+
+ ed_link_down();
+ ed_link_up(speed);
+}
+
+/*
+ * Read the PHY state register to determine link state and speed
+ */
+static void
+ed_check_phy_state(void)
+{
+ int lansr = eth_mac_miim_read(PHY_LINK_AN);
+ eth_link_state_t new_state = LS_UNKNOWN;
+ int new_speed = S_UNKNOWN;
+
+ hal_puts("LANSR: "); hal_puthex16_nl(lansr);
+
+ if (lansr & LANSR_LINK_GOOD){ // link's up
+ hal_puts_nl(" LINK_GOOD");
+
+ new_state = LS_UP;
+ switch (lansr & LANSR_SPEED_MASK){
+ case LANSR_SPEED_10:
+ new_speed = 10;
+ break;
+
+ case LANSR_SPEED_100:
+ new_speed = 100;
+ break;
+
+ case LANSR_SPEED_1000:
+ new_speed = 1000;
+ break;
+
+ default:
+ new_speed = S_UNKNOWN;
+ break;
+ }
+ }
+ else { // link's down
+ hal_puts_nl(" NOT LINK_GOOD");
+
+ new_state = LS_DOWN;
+ new_speed = S_UNKNOWN;
+ }
+
+ if (new_state != ed_state.link_state){
+ ed_state.link_state = new_state; // remember new state
+ if (new_state == LS_UP)
+ ed_link_up(new_speed);
+ else if (new_state == LS_DOWN)
+ ed_link_down();
+ }
+ else if (new_state == LS_UP && new_speed != ed_state.link_speed){
+ ed_state.link_speed = new_speed; // remember new speed
+ hal_puts_nl(" New Speed: "); hal_puthex_nl(new_speed);
+ ed_link_speed_change(new_speed);
+ }
+}
+
+/*
+ * This is fired when the ethernet PHY state changes
+ */
+static void
+eth_phy_irq_handler(unsigned irq)
+{
+ ed_check_phy_state();
+ eth_mac_miim_write(PHY_INT_CLEAR, ~0); // clear all ints
+}
+
+void
+eth_driver_init(void)
+{
+ ed_state.link_state = LS_UNKNOWN;
+ ed_state.link_speed = S_UNKNOWN;
+
+ // initialize MAC registers
+ eth_mac->tx_hwmark = 0x1e;
+ eth_mac->tx_lwmark = 0x19;
+ eth_mac->pause_frame_send_en = 1;
+ // eth_mac->pause_quanta_set = XXX;
+ eth_mac->tx_pause_en = 1;
+ // eth_mac->rx_hwmark = xxx;
+ // eth_mac->rx_lwmark = xxx;
+ eth_mac->crc_chk_en = 1;
+ eth_mac->rx_max_length = 2048;
+
+ // setup PHY to interrupt on changes
+
+ unsigned mask =
+ (PHY_INT_AN_CMPL // auto-neg completed
+ | PHY_INT_NO_LINK // no link after auto-neg
+ | PHY_INT_NO_HCD // no highest common denominator
+ | PHY_INT_MAS_SLA_ERR // couldn't resolve master/slave
+ | PHY_INT_PRL_DET_FLT // parallel detection fault
+ | PHY_INT_LNK_CNG // link established or broken
+ | PHY_INT_SPD_CNG // speed changed
+ );
+
+ hal_putc('$');
+
+ eth_mac_miim_write(PHY_INT_CLEAR, ~0); // clear all pending interrupts
+ eth_mac_miim_write(PHY_INT_MASK, mask); // enable the ones we want
+
+#if 0
+ unsigned read_back = eth_mac_miim_read(PHY_INT_MASK);
+
+ hal_puts("eth_driver: wr INT_MASK = ");
+ hal_puthex16_nl(mask);
+ hal_puts("eth_driver: rd INT_MASK = ");
+ hal_puthex16_nl(read_back);
+#endif
+
+ pic_register_handler(IRQ_PHY, eth_phy_irq_handler);
+
+ // FIXME not sure where we want to make the first check of the link state
+ ed_check_phy_state();
+}
+
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.h (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/eth_driver.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/eth_driver.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,48 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_ETH_DRIVER_H
+#define INCLUDED_ETH_DRIVER_H
+
+typedef void (*ed_link_changed_callback_t)(int speed);
+
+
+void eth_driver_init(void);
+
+/*!
+ * \brief Specify the function to call on link state changes.
+ *
+ * When the link comes up, speed is the link speed in Mbit/s.
+ * When the link goes down, speed is 0.
+ */
+void eth_driver_register_link_changed_callback(ed_link_changed_callback_t cb);
+
+
+typedef enum { LS_UNKNOWN, LS_DOWN, LS_UP } eth_link_state_t;
+
+#define S_UNKNOWN (-1) // unknown link speed
+
+typedef struct {
+ eth_link_state_t link_state;
+ int link_speed; // in Mb/s
+} eth_driver_t;
+
+#endif /* INCLUDED_ETH_DRIVER_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/eth_mac.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,93 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "eth_mac.h"
+#include "memory_map.h"
+#include "bool.h"
+#include "eth_phy.h" // for simulation constants
+
+#define PHY_ADDR 1
+
+void
+eth_mac_init(void)
+{
+ // FIXME more to do?
+
+ eth_mac->miimoder = 16; // divider from CPU clock (33MHz / 16 ~= 2MHz)
+}
+
+int
+eth_mac_read_rmon(int addr)
+{
+ int t;
+
+ eth_mac->rmon_rd_addr = addr;
+ eth_mac->rmon_rd_apply = 1;
+ while(eth_mac->rmon_rd_grant == 0)
+ ;
+
+ t = (eth_mac->rmon_rd_dout_hi << 16) | eth_mac->rmon_rd_dout_lo;
+ eth_mac->rmon_rd_apply = 0;
+ return t;
+}
+
+int
+eth_mac_miim_read(int addr)
+{
+ if (hwconfig_simulation_p()){
+ switch(addr){
+ case PHY_LINK_AN:
+ return LANSR_MASTER | LANSR_LINK_GOOD | LANSR_SPEED_1000;
+ default:
+ return 0;
+ }
+ }
+
+ int phy_addr = PHY_ADDR;
+ eth_mac->miiaddress = ((addr & 0x1f) << 8) | phy_addr;
+ eth_mac->miicommand = MIIC_RSTAT;
+
+ while((eth_mac->miistatus & MIIS_BUSY) != 0)
+ ;
+
+ return eth_mac->miirx_data;
+}
+
+void
+eth_mac_miim_write(int addr, int value)
+{
+ int phy_addr = PHY_ADDR;
+ eth_mac->miiaddress = ((addr & 0x1f) << 8) | phy_addr;
+ eth_mac->miitx_data = value;
+ eth_mac->miicommand = MIIC_WCTRLDATA;
+
+ while((eth_mac->miistatus & MIIS_BUSY) != 0)
+ ;
+}
+
+int
+eth_mac_miim_read_status(void)
+{
+ if (hwconfig_simulation_p())
+ return 0;
+
+ return eth_mac->miistatus;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/eth_mac.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,32 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_ETH_MAC_H
+#define INCLUDED_ETH_MAC_H
+
+void eth_mac_init(void);
+int eth_mac_read_rmon(int addr);
+int eth_mac_miim_read(int addr);
+void eth_mac_miim_write(int addr, int value);
+int eth_mac_miim_read_status(void);
+
+
+#endif /* INCLUDED_ETH_MAC_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac_regs.h (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/eth_mac_regs.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac_regs.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/eth_mac_regs.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,87 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_ETH_MAC_REGS_H
+#define INCLUDED_ETH_MAC_REGS_H
+
+/*
+ * See opencores.org 10_100_1000 Mbps Tri-mode Ethernet MAC Specification
+ *
+ * In reality, these are 16-bit regs, but are assigned
+ * on 32-bit boundaries. Because we're little endian,
+ * declaring them "int" works.
+ */
+typedef struct {
+ volatile int tx_hwmark;
+ volatile int tx_lwmark;
+ volatile int pause_frame_send_en;
+ volatile int pause_quanta_set;
+ volatile int ifg_set;
+ volatile int full_duplex;
+ volatile int max_retry;
+ volatile int mac_tx_add_en;
+ volatile int mac_tx_add_prom_data;
+ volatile int mac_tx_add_prom_add;
+ volatile int mac_tx_add_prom_wr;
+ volatile int tx_pause_en;
+ volatile int xoff_cpu;
+ volatile int xon_cpu;
+ volatile int mac_rx_add_chk_en;
+ volatile int mac_rx_add_prom_data;
+ volatile int mac_rx_add_prom_add;
+ volatile int mac_rx_add_prom_wr;
+ volatile int broadcast_filter_en;
+ volatile int broadcast_bucket_depth;
+ volatile int broadcast_bucket_interval;
+ volatile int rx_append_crc;
+ volatile int rx_hwmark;
+ volatile int rx_lwmark;
+ volatile int crc_chk_en;
+ volatile int rx_ifg_set;
+ volatile int rx_max_length;
+ volatile int rx_min_length;
+ volatile int rmon_rd_addr; // performance counter access
+ volatile int rmon_rd_apply;
+ volatile int rmon_rd_grant; // READONLY
+ volatile int rmon_rd_dout_lo; // READONLY
+ volatile int rmon_rd_dout_hi; // READONLY
+ volatile int line_loop_en;
+ volatile int speed;
+ volatile int miimoder;
+ volatile int miicommand;
+ volatile int miiaddress;
+ volatile int miitx_data;
+ volatile int miirx_data;
+ volatile int miistatus;
+} eth_mac_regs_t;
+
+// miicommand register
+#define MIIC_SCANSSTAT (1 << 0) // Scan status
+#define MIIC_RSTAT (1 << 1) // Read status
+#define MIIC_WCTRLDATA (1 << 2) // Write control data
+
+// miistatus register
+#define MIIS_LINKFAIL (1 << 0) // The link failed
+#define MIIS_BUSY (1 << 1) // The MII is busy (operation
in progress)
+#define MIIS_NVALID (1 << 2) // The data in the status
register is invalid
+ // This it is only valid when the
scan status is active.
+
+#endif /* INCLUDED_ETH_MAC_REGS_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/eth_phy.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/eth_phy.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/eth_phy.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/eth_phy.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,222 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* Much of this was extracted from the Linux e1000_hw.h file */
+
+#ifndef INCLUDED_ETH_PHY_H
+#define INCLUDED_ETH_PHY_H
+
+/* PHY 1000 MII Register/Bit Definitions */
+/* PHY Registers defined by IEEE */
+
+#define PHY_CTRL 0x00 /* Control Register */
+#define PHY_STATUS 0x01 /* Status Regiser */
+#define PHY_ID1 0x02 /* Phy Id Reg (word 1) */
+#define PHY_ID2 0x03 /* Phy Id Reg (word 2) */
+#define PHY_AUTONEG_ADV 0x04 /* Autoneg Advertisement */
+#define PHY_LP_ABILITY 0x05 /* Link Partner Ability (Base Page) */
+#define PHY_AUTONEG_EXP 0x06 /* Autoneg Expansion Reg */
+#define PHY_NEXT_PAGE_TX 0x07 /* Next Page TX */
+#define PHY_LP_NEXT_PAGE 0x08 /* Link Partner Next Page */
+#define PHY_1000T_CTRL 0x09 /* 1000Base-T Control Reg */
+#define PHY_1000T_STATUS 0x0A /* 1000Base-T Status Reg */
+#define PHY_EXT_STATUS 0x0F /* Extended Status Reg */
+
+/* PHY 1000 MII Register additions in DP83856 */
+/* The part implements 0x00 thru 0x1f; we use these. */
+
+#define PHY_LINK_AN 0x11 /* Link and Auto Negotiation Status Reg */
+#define PHY_INT_STATUS 0x14 /* Interupt Status Reg (RO) */
+#define PHY_INT_MASK 0x15 /* Interrupt Mask Reg (RW) */
+#define PHY_INT_CLEAR 0x17 /* Interrupt Clear Reg (RW) */
+
+
+/* Bit definitions for some of the registers above */
+
+/* PHY Control Register (PHY_CTRL) */
+#define MII_CR_SPEED_SELECT_MSB 0x0040 /* bits 6,13: 10=1000, 01=100, 00=10 */
+#define MII_CR_COLL_TEST_ENABLE 0x0080 /* Collision test enable */
+#define MII_CR_FULL_DUPLEX 0x0100 /* FDX =1, half duplex =0 */
+#define MII_CR_RESTART_AUTO_NEG 0x0200 /* Restart auto negotiation */
+#define MII_CR_ISOLATE 0x0400 /* Isolate PHY from MII */
+#define MII_CR_POWER_DOWN 0x0800 /* Power down */
+#define MII_CR_AUTO_NEG_EN 0x1000 /* Auto Neg Enable */
+#define MII_CR_SPEED_SELECT_LSB 0x2000 /* bits 6,13: 10=1000, 01=100, 00=10 */
+#define MII_CR_LOOPBACK 0x4000 /* 0 = normal, 1 = loopback */
+#define MII_CR_RESET 0x8000 /* 0 = normal, 1 = PHY reset */
+
+/* PHY Status Register (PHY_STATUS) */
+#define MII_SR_EXTENDED_CAPS 0x0001 /* Extended register capabilities */
+#define MII_SR_JABBER_DETECT 0x0002 /* Jabber Detected */
+#define MII_SR_LINK_STATUS 0x0004 /* Link Status 1 = link */
+#define MII_SR_AUTONEG_CAPS 0x0008 /* Auto Neg Capable */
+#define MII_SR_REMOTE_FAULT 0x0010 /* Remote Fault Detect */
+#define MII_SR_AUTONEG_COMPLETE 0x0020 /* Auto Neg Complete */
+#define MII_SR_PREAMBLE_SUPPRESS 0x0040 /* Preamble may be suppressed */
+#define MII_SR_EXTENDED_STATUS 0x0100 /* Ext. status info in Reg 0x0F */
+#define MII_SR_100T2_HD_CAPS 0x0200 /* 100T2 Half Duplex Capable */
+#define MII_SR_100T2_FD_CAPS 0x0400 /* 100T2 Full Duplex Capable */
+#define MII_SR_10T_HD_CAPS 0x0800 /* 10T Half Duplex Capable */
+#define MII_SR_10T_FD_CAPS 0x1000 /* 10T Full Duplex Capable */
+#define MII_SR_100X_HD_CAPS 0x2000 /* 100X Half Duplex Capable */
+#define MII_SR_100X_FD_CAPS 0x4000 /* 100X Full Duplex Capable */
+#define MII_SR_100T4_CAPS 0x8000 /* 100T4 Capable */
+
+/* Autoneg Advertisement Register (PHY_AUTONEG_ADV) */
+#define NWAY_AR_SELECTOR_FIELD 0x0001 /* indicates IEEE 802.3 CSMA/CD */
+#define NWAY_AR_10T_HD_CAPS 0x0020 /* 10T Half Duplex Capable */
+#define NWAY_AR_10T_FD_CAPS 0x0040 /* 10T Full Duplex Capable */
+#define NWAY_AR_100TX_HD_CAPS 0x0080 /* 100TX Half Duplex Capable */
+#define NWAY_AR_100TX_FD_CAPS 0x0100 /* 100TX Full Duplex Capable */
+#define NWAY_AR_100T4_CAPS 0x0200 /* 100T4 Capable */
+#define NWAY_AR_PAUSE 0x0400 /* Pause operation desired */
+#define NWAY_AR_ASM_DIR 0x0800 /* Asymmetric Pause Direction bit */
+#define NWAY_AR_REMOTE_FAULT 0x2000 /* Remote Fault detected */
+#define NWAY_AR_NEXT_PAGE 0x8000 /* Next Page ability supported */
+
+/* Link Partner Ability Register (Base Page) (PHY_LP_ABILITY) */
+#define NWAY_LPAR_SELECTOR_FIELD 0x0000 /* LP protocol selector field */
+#define NWAY_LPAR_10T_HD_CAPS 0x0020 /* LP is 10T Half Duplex Capable */
+#define NWAY_LPAR_10T_FD_CAPS 0x0040 /* LP is 10T Full Duplex Capable */
+#define NWAY_LPAR_100TX_HD_CAPS 0x0080 /* LP is 100TX Half Duplex Capable */
+#define NWAY_LPAR_100TX_FD_CAPS 0x0100 /* LP is 100TX Full Duplex Capable */
+#define NWAY_LPAR_100T4_CAPS 0x0200 /* LP is 100T4 Capable */
+#define NWAY_LPAR_PAUSE 0x0400 /* LP Pause operation desired */
+#define NWAY_LPAR_ASM_DIR 0x0800 /* LP Asymmetric Pause Direction bit */
+#define NWAY_LPAR_REMOTE_FAULT 0x2000 /* LP has detected Remote Fault */
+#define NWAY_LPAR_ACKNOWLEDGE 0x4000 /* LP has rx'd link code word */
+#define NWAY_LPAR_NEXT_PAGE 0x8000 /* Next Page ability supported */
+
+/* Autoneg Expansion Register (PHY_AUTONEG_EXP) */
+#define NWAY_ER_LP_NWAY_CAPS 0x0001 /* LP has Auto Neg Capability */
+#define NWAY_ER_PAGE_RXD 0x0002 /* LP is 10T Half Duplex Capable */
+#define NWAY_ER_NEXT_PAGE_CAPS 0x0004 /* LP is 10T Full Duplex Capable */
+#define NWAY_ER_LP_NEXT_PAGE_CAPS 0x0008 /* LP is 100TX Half Duplex Capable */
+#define NWAY_ER_PAR_DETECT_FAULT 0x0010 /* LP is 100TX Full Duplex Capable */
+
+/* Next Page TX Register (PHY_NEXT_PAGE_TX) */
+#define NPTX_MSG_CODE_FIELD 0x0001 /* NP msg code or unformatted data */
+#define NPTX_TOGGLE 0x0800 /* Toggles between exchanges
+ * of different NP
+ */
+#define NPTX_ACKNOWLDGE2 0x1000 /* 1 = will comply with msg
+ * 0 = cannot comply with msg
+ */
+#define NPTX_MSG_PAGE 0x2000 /* formatted(1)/unformatted(0) pg */
+#define NPTX_NEXT_PAGE 0x8000 /* 1 = addition NP will follow
+ * 0 = sending last NP
+ */
+
+/* Link Partner Next Page Register (PHY_LP_NEXT_PAGE) */
+#define LP_RNPR_MSG_CODE_FIELD 0x0001 /* NP msg code or unformatted data */
+#define LP_RNPR_TOGGLE 0x0800 /* Toggles between exchanges
+ * of different NP
+ */
+#define LP_RNPR_ACKNOWLDGE2 0x1000 /* 1 = will comply with msg
+ * 0 = cannot comply with msg
+ */
+#define LP_RNPR_MSG_PAGE 0x2000 /* formatted(1)/unformatted(0) pg */
+#define LP_RNPR_ACKNOWLDGE 0x4000 /* 1 = ACK / 0 = NO ACK */
+#define LP_RNPR_NEXT_PAGE 0x8000 /* 1 = addition NP will follow
+ * 0 = sending last NP
+ */
+
+/* 1000BASE-T Control Register (PHY_1000T_CTRL) */
+#define CR_1000T_ASYM_PAUSE 0x0080 /* Advertise asymmetric pause bit */
+#define CR_1000T_HD_CAPS 0x0100 /* Advertise 1000T HD capability */
+#define CR_1000T_FD_CAPS 0x0200 /* Advertise 1000T FD capability */
+#define CR_1000T_REPEATER_DTE 0x0400 /* 1=Repeater/switch device port */
+ /* 0=DTE device */
+#define CR_1000T_MS_VALUE 0x0800 /* 1=Configure PHY as Master */
+ /* 0=Configure PHY as Slave */
+#define CR_1000T_MS_ENABLE 0x1000 /* 1=Master/Slave manual config value
*/
+ /* 0=Automatic Master/Slave config */
+#define CR_1000T_TEST_MODE_NORMAL 0x0000 /* Normal Operation */
+#define CR_1000T_TEST_MODE_1 0x2000 /* Transmit Waveform test */
+#define CR_1000T_TEST_MODE_2 0x4000 /* Master Transmit Jitter test */
+#define CR_1000T_TEST_MODE_3 0x6000 /* Slave Transmit Jitter test */
+#define CR_1000T_TEST_MODE_4 0x8000 /* Transmitter Distortion test */
+
+/* 1000BASE-T Status Register (PHY_1000T_STATUS) */
+#define SR_1000T_IDLE_ERROR_CNT 0x00FF /* Num idle errors since last read */
+#define SR_1000T_ASYM_PAUSE_DIR 0x0100 /* LP asymmetric pause direction bit
*/
+#define SR_1000T_LP_HD_CAPS 0x0400 /* LP is 1000T HD capable */
+#define SR_1000T_LP_FD_CAPS 0x0800 /* LP is 1000T FD capable */
+#define SR_1000T_REMOTE_RX_STATUS 0x1000 /* Remote receiver OK */
+#define SR_1000T_LOCAL_RX_STATUS 0x2000 /* Local receiver OK */
+#define SR_1000T_MS_CONFIG_RES 0x4000 /* 1=Local TX is Master, 0=Slave */
+#define SR_1000T_MS_CONFIG_FAULT 0x8000 /* Master/Slave config fault */
+#define SR_1000T_REMOTE_RX_STATUS_SHIFT 12
+#define SR_1000T_LOCAL_RX_STATUS_SHIFT 13
+#define SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT 5
+#define FFE_IDLE_ERR_COUNT_TIMEOUT_20 20
+#define FFE_IDLE_ERR_COUNT_TIMEOUT_100 100
+
+/* Extended Status Register (PHY_EXT_STATUS) */
+#define IEEE_ESR_1000T_HD_CAPS 0x1000 /* 1000T HD capable */
+#define IEEE_ESR_1000T_FD_CAPS 0x2000 /* 1000T FD capable */
+#define IEEE_ESR_1000X_HD_CAPS 0x4000 /* 1000X HD capable */
+#define IEEE_ESR_1000X_FD_CAPS 0x8000 /* 1000X FD capable */
+
+#define PHY_TX_POLARITY_MASK 0x0100 /* register 10h bit 8 (polarity bit) */
+#define PHY_TX_NORMAL_POLARITY 0 /* register 10h bit 8 (normal polarity)
*/
+
+#define AUTO_POLARITY_DISABLE 0x0010 /* register 11h bit 4 */
+ /* (0=enable, 1=disable) */
+
+/* Link and Auto Negotiation Status Reg (PHY_LINK_AN) [READ-ONLY] */
+#define LANSR_MASTER 0x0001 /* 1=PHY is currently in master
mode */
+#define LANSR_FULL_DUPLEX 0x0002 /* 1=PHY is currently full duplex
*/
+#define LANSR_LINK_GOOD 0x0004 /* 1=a good link is established */
+#define LANSR_SPEED_MASK 0x0018
+#define LANSR_SPEED_10 0x0000 /* 10Mb/s */
+#define LANSR_SPEED_100 0x0008 /* 100Mb/s */
+#define LANSR_SPEED_1000 0x0010 /* 1000Mb/s */
+#define LANSR_SPEED_RSRVD 0x0018 /* reserved */
+#define LANSR_NON_COMP_MODE 0x0020 /* 1=detects only in non-compliant mode
*/
+#define LANSR_DEEP_LOOPBACK 0x0040 /* 1=the PHY operates in deep
loopback mode */
+#define LANSR_SHALLOW_LOOPBACK 0x0080 /* 1=the PHY operates in shallow
loopback mode */
+#define LANSR_RSRVD_8 0x0100 /* reserved */
+#define LANSR_FIFO_ERR 0x0200 /* 1=FIFO error occurred */
+#define LANSR_MDIX_XOVER 0x0400 /* 1=PHY's MDI is in cross-over
mode */
+#define LANSR_RSRVD_11 0x0800 /* resevered */
+#define LANSR_TP_POLARITY_REV 0xf000 /* Twisted pair polarity status
A:D([15:12]) 1=reversed */
+
+/* Interrupt status, mask and clear regs (PHY_INT_{STATUS,MASK,CLEAR}) */
+#define PHY_INT_RSRVD_0 0x0001 /* reserved */
+#define PHY_INT_RSRVD_1 0x0002 /* reserved */
+#define PHY_INT_RSRVD_2 0x0004 /* reserved */
+#define PHY_INT_REM_FLT_CNG 0x0008 /* Remote Fault Changed */
+#define PHY_INT_AN_CMPL 0x0010 /* Auto-negotiation completion */
+#define PHY_INT_NXT_PG_RCVD 0x0020 /* Next Page Received */
+#define PHY_INT_JABBER_CNG 0x0040 /* Jabber Changed */
+#define PHY_INT_NO_LINK 0x0080 /* No link after auto-negotiation
*/
+#define PHY_INT_NO_HCD 0x0100 /* AN couldn't determine highest common
denominator */
+#define PHY_INT_MAS_SLA_ERR 0x0200 /* Master / Slave Error: couldn't
resolve */
+#define PHY_INT_PRL_DET_FLT 0x0400 /* Parallel detection fault */
+#define PHY_INT_POL_CNG 0x0800 /* Polarity of any channel
changed */
+#define PHY_INT_MDIX_CNG 0x1000 /* MDIX changed. A pair swap
occurred. */
+#define PHY_INT_DPLX_CNG 0x2000 /* Duplex changed */
+#define PHY_INT_LNK_CNG 0x4000 /* Link changed (asserted when a
link is established or broken) */
+#define PHY_INT_SPD_CNG 0x8000 /* Speed changed */
+
+#endif /* INCLUDED_ETH_PHY_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/hal_io.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,252 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// conditionalized on HAL_IO_USES_DBOARD_PINS && HAL_IO_USES_UART
+
+#include "hal_io.h"
+#include "memory_map.h"
+#include "hal_uart.h"
+
+unsigned int
+hal_gpio_mode_mask(int high_bitno, int low_bitno, int mode)
+{
+ mode &= 0x3;
+ unsigned int t = 0;
+
+ int i;
+ for (i = 15; i >= 0; i--){
+ t <<= 2;
+ if (i <= high_bitno && i >= low_bitno)
+ t |= mode;
+ }
+ return t;
+}
+
+void
+hal_gpio_set_rx_mode(int high_bitno, int low_bitno, int mode)
+{
+ unsigned mask = hal_gpio_mode_mask(high_bitno, low_bitno, 0x3);
+ unsigned val = hal_gpio_mode_mask(high_bitno, low_bitno, mode);
+ int ei = hal_disable_ints();
+ gpio_base->rx_mode = (gpio_base->rx_mode & ~mask) | (val & mask);
+ hal_restore_ints(ei);
+}
+
+void
+hal_gpio_set_tx_mode(int high_bitno, int low_bitno, int mode)
+{
+ unsigned mask = hal_gpio_mode_mask(high_bitno, low_bitno, 0x3);
+ unsigned val = hal_gpio_mode_mask(high_bitno, low_bitno, mode);
+ int ei = hal_disable_ints();
+ gpio_base->tx_mode = (gpio_base->tx_mode & ~mask) | (val & mask);
+ hal_restore_ints(ei);
+}
+
+// in top 16-bits of io reg
+void
+hal_gpio_set_tx(int value, int mask)
+{
+ value <<= 16;
+ mask <<= 16;
+ int ei = hal_disable_ints();
+ gpio_base->io = (gpio_base->io & ~mask) | (value & mask);
+ hal_restore_ints(ei);
+}
+
+// in bottom 16-bits of io reg
+void
+hal_gpio_set_rx(int value, int mask)
+{
+ value &= 0xffff;
+ mask &= 0xffff;
+ int ei = hal_disable_ints();
+ gpio_base->io = (gpio_base->io & ~mask) | (value & mask);
+ hal_restore_ints(ei);
+}
+
+// ================================================================
+// primitives
+// ================================================================
+
+#if defined(HAL_IO_USES_DBOARD_PINS)
+//
+// Does i/o using high 9-bits of rx daughterboard pins.
+//
+// 1 1 1 1 1 1
+// 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+// | char |W| |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+//
+//
+// Asserts W when writing char
+//
+
+#define W 0x0080
+
+void
+hal_io_init(void)
+{
+ // make high 9 bits of tx daughterboard outputs
+ hal_gpio_set_rx_mode(15, 7, GPIOM_OUTPUT);
+
+ // and set them to zero
+ hal_gpio_set_rx(0x0000, 0xff80);
+}
+
+// %c
+inline void
+hal_putc(unsigned char s)
+{
+ hal_gpio_set_rx((s << 8) | W, 0xff80);
+ hal_gpio_set_rx(0, 0xff80);
+}
+
+void
+hal_finish(void)
+{
+ volatile unsigned long *p = (unsigned long *) 0xC2F0;
+ *p = 0;
+}
+
+#elif defined(HAL_IO_USES_UART)
+
+void
+hal_io_init(void)
+{
+ hal_uart_init();
+}
+
+// %c
+inline void
+hal_putc(unsigned char s)
+{
+ hal_uart_putc(s);
+}
+
+void
+hal_finish(void)
+{
+}
+
+
+#else // nop all i/o
+
+void
+hal_io_init(void)
+{
+}
+
+// %c
+inline void
+hal_putc(unsigned char s)
+{
+}
+
+void
+hal_finish(void)
+{
+}
+
+#endif
+
+// ================================================================
+// (slightly) higher level functions
+// ================================================================
+
+// \n
+inline void
+hal_newline(void)
+{
+ hal_putc('\n');
+}
+
+// %c\n
+inline void
+hal_putc_nl(unsigned char s)
+{
+ hal_putc(s);
+ hal_newline();
+}
+
+
+void
+hal_puts(const char *s)
+{
+ while (*s)
+ hal_putc(*s++);
+}
+
+void
+hal_puts_nl(const char *s)
+{
+ hal_puts(s);
+ hal_newline();
+}
+
+// %02x
+void
+hal_puthex8(unsigned long x)
+{
+ static const char hex[16] = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+ };
+ hal_putc(hex[(x >> 4) & 0xf]);
+ hal_putc(hex[x & 0xf]);
+}
+
+// %04x
+void
+hal_puthex16(unsigned long x)
+{
+ hal_puthex8(x >> 8);
+ hal_puthex8(x);
+}
+
+// %08x
+void
+hal_puthex32(unsigned long x)
+{
+ hal_puthex16(x >> 16);
+ hal_puthex16(x);
+}
+
+void
+hal_puthex8_nl(unsigned long x)
+{
+ hal_puthex8(x);
+ hal_newline();
+}
+
+void
+hal_puthex16_nl(unsigned long x)
+{
+ hal_puthex16(x);
+ hal_newline();
+}
+
+void
+hal_puthex32_nl(unsigned long x)
+{
+ hal_puthex32(x);
+ hal_newline();
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/hal_io.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/hal_io.h 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,108 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_HAL_IO_H
+#define INCLUDED_HAL_IO_H
+
+#include "memory_map.h"
+
+void hal_io_init(void);
+void hal_finish();
+
+void hal_putc(unsigned char s);
+void hal_putc_nl(unsigned char s); // adds \n
+void hal_puts(const char *);
+void hal_puts_nl(const char *s);
+void hal_puthex8(unsigned long x);
+void hal_puthex16(unsigned long x);
+void hal_puthex32(unsigned long x);
+void hal_puthex8_nl(unsigned long x);
+void hal_puthex16_nl(unsigned long x);
+void hal_puthex32_nl(unsigned long x);
+#define hal_puthex hal_puthex32
+#define hal_puthex_nl hal_puthex32_nl
+void hal_newline();
+
+
+void hal_gpio_set_rx_mode(int high_bitno, int low_bitno, int mode);
+void hal_gpio_set_tx_mode(int high_bitno, int low_bitno, int mode);
+
+void hal_gpio_set_tx(int value, int mask);
+void hal_gpio_set_rx(int value, int mask);
+
+static inline void
+hal_set_timeout(int delta_ticks)
+{
+ int t = timer_regs->time + delta_ticks;
+ if (t == 0) // kills timer
+ t = 1;
+ timer_regs->time = t;
+}
+
+/*!
+ * \brief Disable interrupts and return previous interrupt enable state.
+ * [Microblaze specific]
+ */
+static inline int
+hal_disable_ints(void)
+{
+ int result, t0;
+
+ asm volatile("mfs %0, rmsr \n\
+ andni %1, %0, 0x2 \n\
+ mts rmsr, %1"
+ : "=r" (result), "=r" (t0));
+ return result;
+}
+
+/*!
+ * \brief Enable interrupts and return previous interrupt enable state.
+ * [Microblaze specific]
+ */
+static inline int
+hal_enable_ints(void)
+{
+ int result, t0;
+
+ asm volatile("mfs %0, rmsr \n\
+ ori %1, %0, 0x2 \n\
+ mts rmsr, %1"
+ : "=r" (result), "=r" (t0));
+ return result;
+}
+
+/*!
+ * \brief Set interrupt enable state to \p prev_state.
+ * [Microblaze specific]
+ */
+static inline void
+hal_restore_ints(int prev_state)
+{
+ int t0, t1;
+ asm volatile("andi %0, %2, 0x2 \n\
+ mfs %1, rmsr \n\
+ andni %1, %1, 0x2 \n\
+ or %1, %1, %0 \n\
+ mts rmsr, %1"
+ : "=r" (t0), "=r"(t1) : "r" (prev_state));
+}
+
+#endif /* INCLUDED_HAL_IO_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/hal_uart.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,111 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "hal_uart.h"
+#include "hal_io.h"
+#include "wb16550.h"
+#include "memory_map.h"
+
+// First pass, no interrupts
+
+// Replaced with divisor.py which generates best divisor
+//#define CALC_DIVISOR(rate) (WISHBONE_CLK_RATE / ((rate) * 16))
+
+#define NSPEEDS 5
+#define MAX_WB_DIV 4
+
+static const uint16_t
+divisor_table[MAX_WB_DIV+1][NSPEEDS] = {
+ { 2, 2, 2, 2, 2}, // 0: can't happen
+ { 651, 326, 163, 109, 52}, // 1: 100 MHz
+ { 326, 163, 81, 54, 26 }, // 2: 50 MHz
+ { 217, 109, 54, 36, 17 }, // 3: 33.3333 MHz
+ { 163, 81, 41, 27, 13 }, // 4: 25 MHz
+};
+
+static hal_uart_config_t current_config;
+
+#define UART_LCR_8N1 (UART_LCR_WLEN8)
+
+#define u uart_regs
+
+void
+hal_uart_init(void)
+{
+ u->ier = 0; // no interrupts enabled
+ u->lcr = UART_LCR_8N1;
+ u->iir_fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8 | UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT;
+ u->iir_fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
+ u->mcr = 0;
+
+ hal_uart_config_t c;
+ c.speed = US_57600;
+ hal_uart_set_config(&c);
+}
+
+void
+hal_uart_set_config(const hal_uart_config_t *c)
+{
+ uint16_t divisor;
+
+ if (c->speed >= NSPEEDS)
+ return;
+
+ current_config = *c;
+
+ if (hwconfig_simulation_p()) // if we're simulating, go fast ;)
+ divisor = 2;
+ else {
+ int t = hwconfig_wishbone_divisor();
+ if (t > MAX_WB_DIV)
+ t = MAX_WB_DIV;
+ divisor = divisor_table[t][current_config.speed];
+ }
+
+ u->lcr = UART_LCR_8N1 | UART_LCR_DLAB; // enable access to divisor regs
+ u->ier = (divisor >> 8); // write MSB first
+ u->data = (divisor & 0xff); // then LSB
+ u->lcr = UART_LCR_8N1; // back to normal mode
+}
+
+void
+hal_uart_get_config(hal_uart_config_t *c)
+{
+ *c = current_config;
+}
+
+void
+hal_uart_putc(int ch)
+{
+ while ((u->lsr & UART_LSR_THRE) == 0) // wait for fifo to be empty
+ ;
+
+ u->data = ch;
+}
+
+int
+hal_uart_getc(void)
+{
+ while ((u->lsr & UART_LSR_DR) == 0) // wait for data to be ready
+ ;
+
+ return u->data;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/hal_uart.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/hal_uart.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,64 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_HAL_UART_H
+#define INCLUDED_HAL_UART_H
+
+
+/*!
+ * \brief one-time call to init
+ */
+void hal_uart_init(void);
+
+typedef enum {
+ US_9600,
+ US_19200,
+ US_38400,
+ US_57600,
+ US_115200,
+} hal_uart_speed_t;
+
+typedef struct {
+ hal_uart_speed_t speed;
+} hal_uart_config_t;
+
+/*!
+ * \brief Set uart parameters
+ * Default is 57,600 bps, 8N1.
+ */
+void hal_uart_set_config(const hal_uart_config_t *c);
+
+/*!
+ * \brief Get uart configuation.
+ */
+void hal_uart_get_config(hal_uart_config_t *c);
+
+/*!
+ * \brief Enqueue \p ch for output over serial port
+ */
+void hal_uart_putc(int ch);
+
+/*
+ * \brief Blocking read of next char from serial port
+ */
+int hal_uart_getc(void);
+
+
+#endif /* INCLUDED_HAL_UART_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/i2c.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,130 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "i2c.h"
+#include "memory_map.h"
+#include "stdint.h"
+
+#define MAX_WB_DIV 4 // maximum wishbone divisor (from 100 MHz MASTER_CLK)
+
+// prescaler divisor values for 100 kHz I2C [uses 5 * SCLK internally]
+
+#define PRESCALER(wb_div) (((MASTER_CLK_RATE/(wb_div)) / (5 * 100000)) - 1)
+
+static uint16_t prescaler_values[MAX_WB_DIV+1] = {
+ 0xffff, // 0: can't happen
+ PRESCALER(1), // 1: 100 MHz
+ PRESCALER(2), // 2: 50 MHz
+ PRESCALER(3), // 3: 33.333 MHz
+ PRESCALER(4), // 4: 25 MHz
+};
+
+void
+i2c_init(void)
+{
+ i2c_regs->ctrl = 0; // disable core
+
+ // setup prescaler depending on wishbone divisor
+ int wb_div = hwconfig_wishbone_divisor();
+ if (wb_div > MAX_WB_DIV)
+ wb_div = MAX_WB_DIV;
+
+ i2c_regs->prescaler_lo = prescaler_values[wb_div] & 0xff;
+ i2c_regs->prescaler_hi = (prescaler_values[wb_div] >> 8) & 0xff;
+
+ i2c_regs->ctrl = I2C_CTRL_EN; // enable core
+
+ // FIXME interrupt driven?
+}
+
+static inline void
+wait_for_xfer(void)
+{
+ while (i2c_regs->cmd_status & I2C_ST_TIP) // wait for xfer to complete
+ ;
+}
+
+static inline bool
+wait_chk_ack(void)
+{
+ wait_for_xfer();
+
+ if ((i2c_regs->cmd_status & I2C_ST_RXACK) != 0){ // target NAK'd
+ return false;
+ }
+ return true;
+}
+
+bool
+i2c_read (unsigned char i2c_addr, unsigned char *buf, unsigned int len)
+{
+ if (len == 0) // reading zero bytes always works
+ return true;
+
+ while (i2c_regs->cmd_status & I2C_ST_BUSY)
+ ;
+
+ i2c_regs->data = (i2c_addr << 1) | 1; // 7 bit address and read bit
(1)
+ // generate START and write addr
+ i2c_regs->cmd_status = I2C_CMD_WR | I2C_CMD_START;
+ if (!wait_chk_ack())
+ goto fail;
+
+ for (; len > 0; buf++, len--){
+ i2c_regs->cmd_status = I2C_CMD_RD | (len == 1 ? (I2C_CMD_NACK |
I2C_CMD_STOP) : 0);
+ wait_for_xfer();
+ *buf = i2c_regs->data;
+ }
+ return true;
+
+ fail:
+ i2c_regs->cmd_status = I2C_CMD_STOP; // generate STOP
+ return false;
+}
+
+
+bool
+i2c_write(unsigned char i2c_addr, const unsigned char *buf, unsigned int len)
+{
+ while (i2c_regs->cmd_status & I2C_ST_BUSY)
+ ;
+
+ i2c_regs->data = (i2c_addr << 1) | 0; // 7 bit address and write bit
(0)
+
+ // generate START and write addr (and maybe STOP)
+ i2c_regs->cmd_status = I2C_CMD_WR | I2C_CMD_START | (len == 0 ? I2C_CMD_STOP
: 0);
+ if (!wait_chk_ack())
+ goto fail;
+
+ for (; len > 0; buf++, len--){
+ i2c_regs->data = *buf;
+ i2c_regs->cmd_status = I2C_CMD_WR | (len == 1 ? I2C_CMD_STOP : 0);
+ if (!wait_chk_ack())
+ goto fail;
+ }
+ return true;
+
+ fail:
+ i2c_regs->cmd_status = I2C_CMD_STOP; // generate STOP
+ return false;
+}
+
+
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/i2c.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/i2c.h 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,41 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_I2C_H
+#define INCLUDED_I2C_H
+
+#include "bool.h"
+
+void i2c_init(void);
+bool i2c_read (unsigned char i2c_addr, unsigned char *buf, unsigned int len);
+bool i2c_write(unsigned char i2c_addr, const unsigned char *buf, unsigned int
len);
+
+
+// Write 24LC024 / 24LC025 EEPROM on motherboard or daughterboard.
+// Which EEPROM is determined by i2c_addr. See i2c_addr.h
+
+bool eeprom_write (int i2c_addr, int eeprom_offset, const void *buf, int len);
+
+// Read 24LC024 / 24LC025 EEPROM on motherboard or daughterboard.
+// Which EEPROM is determined by i2c_addr. See i2c_addr.h
+
+bool eeprom_read (int i2c_addr, int eeprom_offset, void *buf, int len);
+
+#endif /* INCLUDED_I2C_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/memory_map.h (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/memory_map.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/memory_map.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/memory_map.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,383 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_MEMORY_MAP_H
+#define INCLUDED_MEMORY_MAP_H
+
+#define MASTER_CLK_RATE 100000000 // 100 MHz
+
+
+////////////////////////////////////////////////////////////////
+//
+// Memory map for embedded wishbone bus
+//
+////////////////////////////////////////////////////////////////
+
+
+////////////////////////////////////////////////////////////////
+// Main RAM, Slave 0
+
+#define RAM_BASE 0x0000
+
+////////////////////////////////////////////////////////////////
+// Buffer Pool RAM, Slave 1
+//
+// The buffers themselves are located in Slave 1, Buffer Pool RAM.
+// The status registers are in Slave 5, Buffer Pool Status.
+// The control register is in Slave 7, Settings Bus.
+
+#define BUFFER_POOL_RAM_BASE 0x4000
+
+#define NBUFFERS 8
+#define BUFFER_POOL_BUFFER_SIZE 0x0200 // Buffer size in 32-bit lines
+
+#define buffer_pool_ram \
+ ((volatile unsigned int *) BUFFER_POOL_RAM_BASE)
+
+#define buffer_ram(n) (&buffer_pool_ram[(n) * BUFFER_POOL_BUFFER_SIZE])
+
+
+/////////////////////////////////////////////////////
+// SPI Core, Slave 2. See core docs for more info
+#define SPI_BASE 0x8000 // Base address (16-bit)
+
+// Register address offsets
+#define SPI_TXRX0 0x000
+#define SPI_TXRX1 0x004
+#define SPI_TXRX2 0x008
+#define SPI_TXRX3 0x00c
+#define SPI_CTRL 0x010
+#define SPI_DIV 0x014
+#define SPI_SS 0x018
+
+// Masks for controlling different peripherals
+#define SPI_SS_AD9510 1
+#define SPI_SS_AD9777 2
+#define SPI_SS_RX_DAC 4
+#define SPI_SS_RX_ADC 8
+#define SPI_SS_RX_DB 16
+#define SPI_SS_TX_DAC 32
+#define SPI_SS_TX_ADC 64
+#define SPI_SS_TX_DB 128
+
+// Masks for different parts of CTRL reg
+#define SPI_CTRL_ASS (1<<13)
+#define SPI_CTRL_IE (1<<12)
+#define SPI_CTRL_LSB (1<<11)
+#define SPI_CTRL_TXNEG (1<<10)
+#define SPI_CTRL_RXNEG (1<< 9)
+#define SPI_CTRL_GO_BSY (1<< 8)
+#define SPI_CTRL_CHAR_LEN 0x7F
+
+#define SPI_TXONLY 0
+#define SPI_TXRX 1
+
+////////////////////////////////////////////////
+// I2C, Slave 3
+// See Wishbone I2C-Master Core Specification.
+
+#define I2C_BASE 0x9000
+
+typedef struct {
+ volatile unsigned char prescaler_lo; // r/w
+ volatile unsigned char prescaler_hi; // r/w
+ volatile unsigned char ctrl; // r/w
+ volatile unsigned char data; // wr = transmit reg; rd =
receive reg
+ volatile unsigned char cmd_status; // wr = command reg; rd = status reg
+} i2c_regs_t;
+
+#define i2c_regs ((i2c_regs_t *) I2C_BASE)
+
+#define I2C_CTRL_EN (1 << 7) // core enable
+#define I2C_CTRL_IE (1 << 6) // interrupt enable
+
+//
+// STA, STO, RD, WR, and IACK bits are cleared automatically
+//
+#define I2C_CMD_START (1 << 7) // generate (repeated) start
condition
+#define I2C_CMD_STOP (1 << 6) // generate stop condition
+#define I2C_CMD_RD (1 << 5) // read from slave
+#define I2C_CMD_WR (1 << 4) // write to slave
+#define I2C_CMD_NACK (1 << 3) // when a rcvr, send ACK
(ACK=0) or NACK (ACK=1)
+#define I2C_CMD_RSVD_2 (1 << 2) // reserved
+#define I2C_CMD_RSVD_1 (1 << 1) // reserved
+#define I2C_CMD_IACK (1 << 0) // set to clear pending interrupt
+
+#define I2C_ST_RXACK (1 << 7) // Received acknowledgement from slave
(1 = NAK, 0 = ACK)
+#define I2C_ST_BUSY (1 << 6) // 1 after START signal
detected; 0 after STOP signal detected
+#define I2C_ST_AL (1 << 5) // Arbitration lost. 1 when
core lost arbitration
+#define I2C_ST_RSVD_4 (1 << 4) // reserved
+#define I2C_ST_RSVD_3 (1 << 3) // reserved
+#define I2C_ST_RSVD_2 (1 << 2) // reserved
+#define I2C_ST_TIP (1 << 1) // Transfer-in-progress
+#define I2C_ST_IP (1 << 0) // Interrupt pending
+
+
+////////////////////////////////////////////////
+// GPIO, Slave 4
+//
+// These go to the daughterboard i/o pins
+
+#define GPIO_BASE 0xA000
+
+typedef struct {
+ volatile unsigned int io; // tx data in high 16, rx in
low 16
+ volatile unsigned int rx_mode; // 16 2-bit fields
+ volatile unsigned int tx_mode; // 16 2-bit fields
+} gpio_regs_t;
+
+// each 2-bit mode field is layed out this way
+#define GPIOM_INPUT 0 // pin is an input, readable by proc through io reg
+#define GPIOM_OUTPUT 1 // pin is an output, writable by proc through
io reg
+#define GPIOM_FPGA_0 2 // pin is an output, writable from FPGA fabric
+#define GPIOM_FPGA_1 3 // pin is an output, writable from FPGA fabric
+
+#define gpio_base ((gpio_regs_t *) GPIO_BASE)
+
+///////////////////////////////////////////////////
+// Buffer Pool Status, Slave 5
+//
+// The buffers themselves are located in Slave 1, Buffer Pool RAM.
+// The status registers are in Slave 5, Buffer Pool Status.
+// The control register is in Slave 7, Settings Bus.
+
+#define BUFFER_POOL_STATUS_BASE 0xB000
+
+typedef struct {
+ volatile unsigned last_line[8]; // last line xfer'd in buffer
+ volatile unsigned status; // error and done flags
+ volatile unsigned hw_config; // see below
+} buffer_pool_status_t;
+
+#define buffer_pool_status ((buffer_pool_status_t *) BUFFER_POOL_STATUS_BASE)
+
+#define BPS_DONE_0 0x0001 // buffer 0 xfer is done
+#define BPS_DONE_1 0x0002 // buffer 1 xfer is done
+#define BPS_DONE_2 0x0004 // buffer 2 xfer is done
+#define BPS_DONE_3 0x0008 // buffer 3 xfer is done
+#define BPS_DONE_4 0x0010 // buffer 4 xfer is done
+#define BPS_DONE_5 0x0020 // buffer 5 xfer is done
+#define BPS_DONE_6 0x0040 // buffer 6 xfer is done
+#define BPS_DONE_7 0x0080 // buffer 7 xfer is done
+#define BPS_ERROR_0 0x0100 // buffer 0 xfer had error
+#define BPS_ERROR_1 0x0200 // buffer 1 xfer had error
+#define BPS_ERROR_2 0x0400 // buffer 2 xfer had error
+#define BPS_ERROR_3 0x0800 // buffer 3 xfer had error
+#define BPS_ERROR_4 0x1000 // buffer 4 xfer had error
+#define BPS_ERROR_5 0x2000 // buffer 5 xfer had error
+#define BPS_ERROR_6 0x4000 // buffer 6 xfer had error
+#define BPS_ERROR_7 0x8000 // buffer 7 xfer had error
+
+// The hw_config register
+
+#define HWC_SIMULATION 0x80000000
+#define HWC_WB_CLK_DIV_MASK 0x0000000f
+
+/*!
+ * \brief return non-zero if we're running under the simulator
+ */
+inline static int
+hwconfig_simulation_p(void)
+{
+ return buffer_pool_status->hw_config & HWC_SIMULATION;
+}
+
+/*!
+ * \brief Return Wishbone Clock divisor.
+ * The processor runs at the Wishbone Clock rate which is MASTER_CLK_RATE /
divisor.
+ */
+inline static int
+hwconfig_wishbone_divisor(void)
+{
+ return buffer_pool_status->hw_config & HWC_WB_CLK_DIV_MASK;
+}
+
+///////////////////////////////////////////////////
+// Ethernet Core, Slave 6
+
+#define ETH_BASE 0xC000
+
+#include "eth_mac_regs.h"
+
+#define eth_mac ((eth_mac_regs_t *) ETH_BASE)
+
+////////////////////////////////////////////////////
+// Settings Bus, Slave #7, Not Byte Addressable!
+//
+// Output-only from processor point-of-view.
+// 1KB of address space (== 256 32-bit write-only regs)
+
+
+#define MISC_OUTPUT_BASE 0xD000
+#define BUFFER_POOL_CTRL_BASE 0xD100
+#define DSP_TX_BASE 0xD200
+#define DSP_RX_BASE 0xD280
+
+#define LAST_SETTING_REG 0xD3FC // last valid setting register
+
+// --- buffer pool control regs ---
+
+typedef struct {
+ volatile unsigned int ctrl;
+} buffer_pool_ctrl_t;
+
+// buffer pool ports
+
+#define PORT_SERDES 0 // serial/deserializer
+#define PORT_DSP 1 // DSP tx or rx pipeline
+#define PORT_ETH 2 // ethernet tx or rx
+#define PORT_RAM 3 // RAM tx or rx
+
+// the buffer pool ctrl register fields
+
+#define BPC_BUFFER(n) (((n) & 0xf) << 28)
+#define BPC_BUFFER_MASK PBC_BUFFER(~0)
+#define BPC_BUFFER_0 BPC_BUFFER(0)
+#define BPC_BUFFER_1 BPC_BUFFER(1)
+#define BPC_BUFFER_2 BPC_BUFFER(2)
+#define BPC_BUFFER_3 BPC_BUFFER(3)
+#define BPC_BUFFER_4 BPC_BUFFER(4)
+#define BPC_BUFFER_5 BPC_BUFFER(5)
+#define BPC_BUFFER_6 BPC_BUFFER(6)
+#define BPC_BUFFER_7 BPC_BUFFER(7)
+#define BPC_BUFFER_NIL BPC_BUFFER(0x8) // disable
+
+#define BPC_PORT(n) (((n) & 0x7) << 25)
+#define BPC_PORT_MASK PBC_PORT(~0)
+#define BPC_PORT_SERDES BPC_PORT(PORT_SERDES)
+#define BPC_PORT_DSP BPC_PORT(PORT_DSP)
+#define BPC_PORT_ETH BPC_PORT(PORT_ETH)
+#define BPC_PORT_RAM BPC_PORT(PORT_RAM)
+#define BPC_PORT_NIL BPC_PORT(0x4) // disable
+
+#define BPC_CLR (1 << 24) // mutually excl commands
+#define BPC_READ (1 << 23)
+#define BPC_WRITE (1 << 22)
+
+#define BPC_STEP(step) (((step) & 0xf) << 18)
+#define BPC_STEP_MASK BPC_STEP(~0)
+#define BPC_LAST_LINE(line) (((line) & 0x1ff) << 9)
+#define BPC_LAST_LINE_MASK BPC_LAST_LINE(~0)
+#define BPC_FIRST_LINE(line) (((line) & 0x1ff) << 0)
+#define PBC_FIRST_LINE_MASK BPC_FIRST_LINE(~0)
+
+#define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE)
+
+// --- misc outputs ---
+
+typedef struct {
+ volatile unsigned long clk_ctrl;
+ volatile unsigned long serdes_ctrl;
+ volatile unsigned long adc_ctrl;
+ volatile unsigned long leds;
+ volatile unsigned long phy_ctrl; // LSB is reset line to eth phy
+} output_regs_t;
+
+#define SERDES_ENABLE 8
+#define SERDES_PRBSEN 4
+#define SERDES_LOOPEN 2
+#define SERDES_RXEN 1
+
+#define output_regs ((output_regs_t *) MISC_OUTPUT_BASE)
+
+// --- dsp tx regs ---
+
+typedef struct {
+ volatile int freq;
+ volatile short scale_i;
+ volatile short scale_q;
+ volatile int interp_rate;
+ volatile int clear_state;
+} dsp_tx_regs_t;
+
+#define dsp_tx_regs ((dsp_tx_regs_t *) DSP_TX_BASE)
+
+// --- dsp rx regs ---
+
+typedef struct {
+ volatile int freq;
+ volatile short scale_i;
+ volatile short scale_q;
+ volatile int decim_rate;
+ volatile int rx_time;
+ volatile int rx_command;
+} dsp_rx_regs_t;
+
+#define dsp_rx_regs ((dsp_rx_regs_t *) DSP_RX_BASE)
+
+///////////////////////////////////////////////////
+// Simple Programmable Interrupt Controller, Slave 8
+
+#define PIC_BASE 0xE000
+
+// Interrupt request lines
+// Bit numbers (LSB == 0) that correpond to interrupts into PIC
+
+#define IRQ_BUFFER 0 // buffer manager
+#define IRQ_TIMER 1
+#define IRQ_SPI 2
+#define IRQ_I2C 3
+#define IRQ_PHY 4 // ethernet PHY
+#define IRQ_UNDERRUN 5
+#define IRQ_OVERRUN 6
+#define IRQ_UART 7
+
+#define IRQ_TO_MASK(x) (1 << (x))
+
+#define PIC_BUFFER_INT IRQ_TO_MASK(IRQ_BUFFER)
+#define PIC_TIMER_INT IRQ_TO_MASK(IRQ_TIMER)
+#define PIC_SPI_INT IRQ_TO_MASK(IRQ_SPI)
+#define PIC_I2C_INT IRQ_TO_MASK(IRQ_I2C)
+#define PIC_PHY_INT IRQ_TO_MASK(IRQ_PHY)
+#define PIC_UNDERRUN_INT IRQ_TO_MASK(IRQ_UNDERRUN)
+#define PIC_OVERRUN_INT IRQ_TO_MASK(IRQ_OVERRUN)
+#define PIC_UART_INT IRQ_TO_MASK(IRQ_UART)
+
+
+typedef struct {
+ volatile int edge_enable; // mask: 1 -> edge triggered, 0 -> level
+ volatile int polarity; // mask: 1 -> rising edge
+ volatile int mask; // mask: 1 -> disabled
+ volatile int pending; // mask: 1 -> pending; write 1's to
clear pending ints
+} pic_regs_t;
+
+#define pic_regs ((pic_regs_t *) PIC_BASE)
+
+///////////////////////////////////////////////////
+// Timer, Slave 9
+
+#define TIMER_BASE 0xE800
+
+typedef struct {
+ volatile int time; // R: current, W: set time to interrupt
+} timer_regs_t;
+
+#define timer_regs ((timer_regs_t *) TIMER_BASE)
+
+///////////////////////////////////////////////////
+// UART, Slave 10
+// include "wb16650.h for registers
+
+#define UART_BASE 0xF000
+
+#define uart_regs ((wb16550_reg_t *) UART_BASE)
+
+#endif
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/microblaze.ld (from
rev 6919, gnuradio/branches/developers/matt/u2f/firmware/microblaze.ld)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/microblaze.ld
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/microblaze.ld
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,163 @@
+OUTPUT_FORMAT("elf32-microblaze", "", "")
+/*
SEARCH_DIR(/home/jwilliams/tmp/microblaze-toolchain-sources/release/lin/microblaze//lib);*/
+
+ENTRY(_start)
+
+MEMORY {
+ flatmem : ORIGIN = 0x0, LENGTH = 0x00004000 /* 16KB */
+}
+
+SECTIONS
+{
+ _TEXT_START_ADDR = DEFINED(_TEXT_START_ADDR) ? _TEXT_START_ADDR : 0x50;
+ .vectors.reset 0x0 : { *(.vectors.reset) } > flatmem
+ .vectors.sw_exception 0x8 : { *(.vectors.sw_exception) } > flatmem
+ .vectors.interrupt 0x10 : { *(.vectors.interrupt) } > flatmem
+ .vectors.hw_exception 0x20 : { *(.vectors.hw_exception) } >flatmem
+ . = _TEXT_START_ADDR;
+ _ftext = .;
+ .text : {
+ *(.text)
+ *(.text.*)
+ *(.gnu.linkonce.t.*)
+ } > flatmem
+ _etext = .;
+ .init : { KEEP (*(.init)) } > flatmem =0
+ .fini : { KEEP (*(.fini)) } > flatmem =0
+ PROVIDE (__CTOR_LIST__ = .);
+ PROVIDE (___CTOR_LIST__ = .);
+ .ctors :
+ {
+ /* gcc uses crtbegin.o to find the start of
+ the constructors, so we make sure it is
+ first. Because this is a wildcard, it
+ doesn't matter if the user does not
+ actually link against crtbegin.o; the
+ linker won't look for a file to match a
+ wildcard. The wildcard also means that it
+ doesn't matter which directory crtbegin.o
+ is in. */
+ KEEP (*crtbegin.o(.ctors))
+ /* We don't want to include the .ctor section from
+ from the crtend.o file until after the sorted ctors.
+ The .ctor section from the crtend file contains the
+ end of ctors marker and it must be last */
+ KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
+ KEEP (*(SORT(.ctors.*)))
+ KEEP (*(.ctors))
+ } > flatmem
+ PROVIDE (__CTOR_END__ = .);
+ PROVIDE (___CTOR_END__ = .);
+ PROVIDE (__DTOR_LIST__ = .);
+ PROVIDE (___DTOR_LIST__ = .);
+ .dtors :
+ {
+ KEEP (*crtbegin.o(.dtors))
+ KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
+ KEEP (*(SORT(.dtors.*)))
+ KEEP (*(.dtors))
+ } > flatmem
+ PROVIDE (__DTOR_END__ = .);
+ PROVIDE (___DTOR_END__ = .);
+ . = ALIGN(4);
+ _frodata = . ;
+ .rodata : {
+ *(.rodata)
+ *(.gnu.linkonce.r.*)
+ CONSTRUCTORS; /* Is this needed? */
+ } > flatmem
+ _erodata = .;
+ /* Alignments by 8 to ensure that _SDA2_BASE_ on a word boundary */
+ /* Note that .sdata2 and .sbss2 must be contiguous */
+ . = ALIGN(8);
+ _ssrw = .;
+ .sdata2 : {
+ *(.sdata2)
+ *(.gnu.linkonce.s2.*)
+ } > flatmem
+ . = ALIGN(4);
+ .sbss2 : {
+ PROVIDE (__sbss2_start = .);
+ *(.sbss2)
+ *(.gnu.linkonce.sb2.*)
+ PROVIDE (__sbss2_end = .);
+ } > flatmem
+ . = ALIGN(8);
+ _essrw = .;
+ _ssrw_size = _essrw - _ssrw;
+ PROVIDE (_SDA2_BASE_ = _ssrw + (_ssrw_size / 2 ));
+ . = ALIGN(4);
+ _fdata = .;
+ .data : {
+ *(.data)
+ *(.gnu.linkonce.d.*)
+ CONSTRUCTORS; /* Is this needed? */
+ } > flatmem
+ _edata = . ;
+ /* Added to handle pic code */
+ .got : {
+ *(.got)
+ } > flatmem
+ .got1 : {
+ *(.got1)
+ } > flatmem
+ .got2 : {
+ *(.got2)
+ } > flatmem
+ /* Added by Sathya to handle C++ exceptions */
+ .eh_frame : {
+ *(.eh_frame)
+ } > flatmem
+ .jcr : {
+ *(.jcr)
+ } > flatmem
+ .gcc_except_table : {
+ *(.gcc_except_table)
+ } > flatmem
+ /* Alignments by 8 to ensure that _SDA_BASE_ on a word boundary */
+ /* Note that .sdata and .sbss must be contiguous */
+ . = ALIGN(8);
+ _ssro = .;
+ .sdata : {
+ *(.sdata)
+ *(.gnu.linkonce.s.*)
+ } > flatmem
+ . = ALIGN(4);
+ .sbss : {
+ PROVIDE (__sbss_start = .);
+ *(.sbss)
+ *(.gnu.linkonce.sb.*)
+ PROVIDE (__sbss_end = .);
+ } > flatmem
+ . = ALIGN(8);
+ _essro = .;
+ _ssro_size = _essro - _ssro;
+ PROVIDE (_SDA_BASE_ = _ssro + (_ssro_size / 2 ));
+ . = ALIGN(4);
+ _fbss = .;
+ .bss : {
+ PROVIDE (__bss_start = .);
+ *(.bss)
+ *(.gnu.linkonce.b.*)
+ *(COMMON)
+ . = ALIGN(4);
+ PROVIDE (__bss_end = .);
+ _heap = .;
+ _HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x0;
+ _STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x800;
+ . += _HEAP_SIZE;
+ _heap_end = .;
+ . += _STACK_SIZE;
+ . = ALIGN(8);
+ _stack = .;
+ _end = .;
+ } > flatmem
+ .tdata : {
+ *(.tdata)
+ *(.gnu.linkonce.td.*)
+ } > flatmem
+ .tbss : {
+ *(.tbss)
+ *(.gnu.linkonce.tb.*)
+ } > flatmem
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/pic.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/pic.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/pic.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/pic.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,97 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "pic.h"
+#include "hal_io.h"
+#include "memory_map.h"
+
+
+#define NVECTORS 8
+
+/*
+ * Our secondary interrupt vector.
+ */
+irq_handler_t pic_vector[NVECTORS] = {
+ nop_handler,
+ nop_handler,
+ nop_handler,
+ nop_handler,
+ nop_handler,
+ nop_handler,
+ nop_handler,
+ nop_handler
+};
+
+
+void
+pic_init(void)
+{
+ // uP is level triggered
+
+ pic_regs->mask = ~0; // mask all interrupts
+ pic_regs->edge_enable = PIC_TIMER_INT | PIC_PHY_INT;
+ pic_regs->polarity = ~0 & ~PIC_PHY_INT; // rising edge
+ pic_regs->pending = ~0; // clear all pending ints
+}
+
+/*
+ * This magic gets pic_interrupt_handler wired into the
+ * system interrupt handler with the appropriate prologue and
+ * epilogue.
+ */
+void pic_interrupt_handler() __attribute__ ((interrupt_handler));
+
+void pic_interrupt_handler()
+{
+ // pending and not masked interrupts
+ int live = pic_regs->pending & ~pic_regs->mask;
+
+ // FIXME loop while there are interrupts to service.
+ // That will reduce our overhead.
+
+ // handle the first one set
+ int i;
+ int mask;
+ for (i=0, mask=1; i < NVECTORS; i++, mask <<= 1){
+ if (mask & live){ // handle this one
+ // hal_puthex_nl(i);
+ (*pic_vector[i])(i);
+ pic_regs->pending = mask; // clear pending interrupt
+ return;
+ }
+ }
+}
+
+void
+pic_register_handler(unsigned irq, irq_handler_t handler)
+{
+ if (irq >= NVECTORS)
+ return;
+ pic_vector[irq] = handler;
+
+ pic_regs->mask &= ~IRQ_TO_MASK(irq);
+}
+
+void
+nop_handler(unsigned irq)
+{
+ // nop
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/pic.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/pic.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/pic.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/pic.h 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,37 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_PIC_H
+#define INCLUDED_PIC_H
+
+typedef void (*irq_handler_t)(unsigned irq);
+
+void pic_init(void);
+void pic_register_handler(unsigned irq, irq_handler_t handler);
+
+void nop_handler(unsigned irq); // default handler does nothing
+
+// FIXME inline assembler
+int pic_disable_interrupts();
+int pic_enable_interrupts();
+void pic_restore_interrupts(int prev_status);
+
+
+#endif /* INCLUDED_PIC_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/spi.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/spi.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/spi.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/spi.c 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,56 @@
+#include "spi.h"
+#include "memory_map.h"
+
+void
+spi_init(void)
+{
+ volatile int *p;
+
+ // Set divider
+ p = (int *)(SPI_BASE+SPI_DIV);
+ *p = 0; // 0 = Div by 2, 1 = Div-by-4
+}
+
+void
+spi_wait(void)
+{
+ volatile int *p;
+ p = (int *)(SPI_BASE+SPI_CTRL);
+ while(*p & SPI_CTRL_GO_BSY)
+ {}
+}
+
+int
+spi_transact(int readback, int slave, int data, int length, int inv_tx)
+{
+ volatile int *p;
+ int flags;
+
+ if(inv_tx)
+ flags = SPI_CTRL_ASS | (SPI_CTRL_CHAR_LEN & length);
+ else
+ flags = SPI_CTRL_ASS | SPI_CTRL_TXNEG | (SPI_CTRL_CHAR_LEN & length);
+
+ spi_wait();
+
+ // Tell it which SPI device to access
+ p = (int *)(SPI_BASE+SPI_SS);
+ *p = slave & 0xFF;
+
+ // Data we will send
+ p = (int *)(SPI_BASE+SPI_TXRX0);
+ *p = data;
+
+ // Run it -- write once and rewrite with GO set
+ p = (int *)(SPI_BASE+SPI_CTRL);
+ *p = flags;
+ *p = flags | SPI_CTRL_GO_BSY;
+
+ if(readback) {
+ spi_wait();
+ p = (int *)(SPI_BASE+SPI_TXRX0);
+ return *p;
+ }
+ else
+ return 0;
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/spi.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/spi.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/spi.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/spi.h 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,24 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2006 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+void spi_init(void);
+void spi_wait(void);
+int spi_transact(int readback, int slave, int data, int length, int inv_tx);
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/stdint.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/stdint.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/stdint.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/stdint.h 2007-11-15
15:39:09 UTC (rev 6920)
@@ -0,0 +1,34 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef INCLUDED_STDINT_H
+#define INCLUDED_STDINT_H
+
+typedef char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
+typedef int int32_t;
+typedef unsigned int uint32_t;
+
+typedef int intptr_t;
+typedef unsigned int uintptr_t;
+
+#endif /* INCLUDED_STDINT_H */
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.c (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/u2_init.c)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.c
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.c
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,83 @@
+
+#include "u2_init.h"
+#include "memory_map.h"
+#include "spi.h"
+#include "pic.h"
+#include "hal_io.h"
+#include "buffer_pool.h"
+#include "hal_uart.h"
+#include "i2c.h"
+#include "bool.h"
+
+/*
+ * We ought to arrange for this to be called before main, but for now,
+ * we require that the user's main call u2_init as the first thing...
+ */
+bool
+u2_init(void)
+{
+ // Set GPIOs to inputs
+ hal_gpio_set_rx_mode(15, 0, GPIOM_INPUT);
+ hal_gpio_set_tx_mode(15, 0, GPIOM_INPUT);
+ gpio_base->io = 0x00000000;
+
+ hal_io_init();
+
+ // init spi, so that we can switch over to the high-speed clock
+ spi_init();
+
+ // Set up AD9510
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00004500, 24, 0); // CLK2 drives
distribution
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00003D80, 24, 0); // Turn on
output 1 (FPGA CLK), normal levels
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00004B80, 24, 0); // Bypass divider
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00005A01, 24, 0); // Update Regs
+
+ spi_wait();
+
+ // Allow for clock switchover
+ output_regs->clk_ctrl = 0x1C;
+
+
+#if 0
+ // Enable ADCs
+ output_regs->adc_ctrl = 0; // Power up and enable outputs
+#endif
+
+ // Enable clock to ADCs and DACs
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00003F80, 24, 0); // Turn on
output 3 (DAC CLK), normal levels
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00004180, 24, 0); // Turn on out 5
(ADC clk), CMOS
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00004F80, 24, 0); // Bypass Div #3
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00005380, 24, 0); // Bypass Div #5
+ spi_transact(SPI_TXONLY, SPI_SS_AD9510, 0x00005A01, 24, 0); // Update Regs
+
+ spi_transact(SPI_TXONLY, SPI_SS_AD9777, 0x00000004, 16, 0); // Single-R mode
+ //spi_transact(SPI_TXONLY, SPI_SS_AD9777, 0x00000140, 16, 0); //
+ //spi_transact(SPI_TXONLY, SPI_SS_AD9777, 0x00000301, 16, 0); // PLL =
+ //spi_transact(SPI_TXONLY, SPI_SS_AD9777, 0x00000480, 16, 0); // PLL on,
automatic
+
+
+ // Set up serdes
+ //output_regs->serdes_ctrl = (SERDES_ENABLE | SERDES_LOOPEN | SERDES_RXEN);
+ output_regs->serdes_ctrl = (SERDES_ENABLE | SERDES_RXEN);
+
+ pic_init(); // progammable interrupt controller
+ bp_init(); // buffer pool
+
+ hal_enable_ints();
+
+ return true;
+}
+
+
+// work around for microblaze CPU bug
+
+static int _not_done_ = 1;
+
+void
+u2_infinite_loop(void)
+{
+ while(_not_done_){
+ }
+ asm volatile ("or r0, r0, r0"); // FIXME CPU bug workaround
+ asm volatile ("or r0, r0, r0");
+}
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/u2_init.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/u2_init.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,9 @@
+/*!
+ * one-time init
+ */
+int u2_init(void);
+
+/*!
+ * infinte loop that works around CPU bug and allows interrupts to occur ;)
+ */
+void u2_infinite_loop(void);
Copied: gnuradio/branches/developers/matt/u2f/firmware/lib/wb16550.h (from rev
6919, gnuradio/branches/developers/matt/u2f/firmware/wb16550.h)
===================================================================
--- gnuradio/branches/developers/matt/u2f/firmware/lib/wb16550.h
(rev 0)
+++ gnuradio/branches/developers/matt/u2f/firmware/lib/wb16550.h
2007-11-15 15:39:09 UTC (rev 6920)
@@ -0,0 +1,100 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+// Wishbone National Semiconductor 16550A compatible UART
+
+#ifndef INCLUDED_WB16550_H
+#define INCLUDED_WB16550_H
+
+#include <stdint.h>
+
+typedef struct {
+ volatile uint8_t data; // 0 r/w: r: rx fifo, w: tx fifo (if DLAB: LSB of
divisor)
+ volatile uint8_t ier; // 1 r/w: Interrupt Enable Register (if DLAB: MSB
of divisor)
+ volatile uint8_t iir_fcr; // 2 r/w: r: Interrupt ID Register,
+ // w: Fifo Control Register
+ volatile uint8_t lcr; // 3 r/w: Line Control Register
+ volatile uint8_t mcr; // 4 w: Modem Control Register
+ volatile uint8_t lsr; // 5 r: Line Status Register
+ volatile uint8_t msr; // 6 r: Modem Status Register
+
+} wb16550_reg_t;
+
+#define UART_IER_RDI 0x01 // Enable received data interrupt
+#define UART_IER_THRI 0x02 // Enable transmitter holding reg empty
int.
+#define UART_IER_RLSI 0x04 // Enable receiver line status
interrupt
+#define UART_IER_MSI 0x08 // Enable modem status interrupt
+
+#define UART_IIR_NO_INT 0x01 // No interrupts pending
+#define UART_IIR_ID_MASK 0x06 // Mask for interrupt ID
+#define UART_IIR_MSI 0x00 // Modem status interrupt
+#define UART_IIR_THRI 0x02 // Tx holding register empty int
+#define UART_IIR_RDI 0x04 // Rx data available int
+#define UART_IIR_RLSI 0x06 // Receiver line status int
+
+#define UART_FCR_ENABLE_FIFO 0x01 // ignore, always enabled
+#define UART_FCR_CLEAR_RCVR 0x02 // Clear the RCVR FIFO
+#define UART_FCR_CLEAR_XMIT 0x04 // Clear the XMIT FIFO
+#define UART_FCR_TRIGGER_MASK 0xC0 // Mask for FIFO trigger range
+#define UART_FCR_TRIGGER_1 0x00 // Rx fifo trigger level: 1 byte
+#define UART_FCR_TRIGGER_4 0x40 // Rx fifo trigger level: 4 bytes
+#define UART_FCR_TRIGGER_8 0x80 // Rx fifo trigger level: 8 bytes
+#define UART_FCR_TRIGGER_14 0xC0 // Rx fifo trigger level: 14 bytes
+
+#define UART_LCR_DLAB 0x80 // Divisor latch access bit
+#define UART_LCR_SBC 0x40 // Set break control
+#define UART_LCR_SPAR 0x20 // Stick parity
+#define UART_LCR_EPAR 0x10 // Even parity select
+#define UART_LCR_PARITY 0x08 // Parity Enable
+#define UART_LCR_STOP 0x04 // Stop bits: 0=1 bit, 1=2 bits
+#define UART_LCR_WLEN5 0x00 // Wordlength: 5 bits
+#define UART_LCR_WLEN6 0x01 // Wordlength: 6 bits
+#define UART_LCR_WLEN7 0x02 // Wordlength: 7 bits
+#define UART_LCR_WLEN8 0x03 // Wordlength: 8 bits
+
+#define UART_MCR_LOOP 0x10 // Enable loopback test mode
+#define UART_MCR_OUT2n 0x08 // Out2 complement (loopback mode)
+#define UART_MCR_OUT1n 0x04 // Out1 complement (loopback mode)
+#define UART_MCR_RTSn 0x02 // RTS complement
+#define UART_MCR_DTRn 0x01 // DTR complement
+
+#define UART_LSR_TEMT 0x40 // Transmitter empty
+#define UART_LSR_THRE 0x20 // Transmit-hold-register empty
+#define UART_LSR_BI 0x10 // Break interrupt indicator
+#define UART_LSR_FE 0x08 // Frame error indicator
+#define UART_LSR_PE 0x04 // Parity error indicator
+#define UART_LSR_OE 0x02 // Overrun error indicator
+#define UART_LSR_DR 0x01 // Receiver data ready
+#define UART_LSR_BRK_ERROR_BITS 0x1E // BI, FE, PE, OE bits
+#define UART_LSR_ERROR 0x80 // At least 1 PE, FE or BI are in the fifo
+
+#define UART_MSR_DCD 0x80 // Data Carrier Detect
+#define UART_MSR_RI 0x40 // Ring Indicator
+#define UART_MSR_DSR 0x20 // Data Set Ready
+#define UART_MSR_CTS 0x10 // Clear to Send
+#define UART_MSR_DDCD 0x08 // Delta DCD
+#define UART_MSR_TERI 0x04 // Trailing edge ring indicator
+#define UART_MSR_DDSR 0x02 // Delta DSR
+#define UART_MSR_DCTS 0x01 // Delta CTS
+#define UART_MSR_ANY_DELTA 0x0F // Any of the delta bits!
+
+
+#endif // INCLUDED_WB16550_H
Deleted: gnuradio/branches/developers/matt/u2f/firmware/memory_map.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/microblaze.ld
Deleted: gnuradio/branches/developers/matt/u2f/firmware/pic.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/pic.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/rcv_eth_packets.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/spi.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/spi.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/stdint.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/test1.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/test_phy_comm.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/timer_test.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/u2_init.c
Deleted: gnuradio/branches/developers/matt/u2f/firmware/u2_init.h
Deleted: gnuradio/branches/developers/matt/u2f/firmware/wb16550.h
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r6920 - in gnuradio/branches/developers/matt/u2f/firmware: . apps lib,
eb <=