commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r6880 - gnuradio/branches/developers/eb/eb_u2f/firmwar


From: eb
Subject: [Commit-gnuradio] r6880 - gnuradio/branches/developers/eb/eb_u2f/firmware
Date: Tue, 13 Nov 2007 12:25:29 -0700 (MST)

Author: eb
Date: 2007-11-13 12:25:27 -0700 (Tue, 13 Nov 2007)
New Revision: 6880

Added:
   gnuradio/branches/developers/eb/eb_u2f/firmware/divisors.py
   gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.c
   gnuradio/branches/developers/eb/eb_u2f/firmware/hello.c
   gnuradio/branches/developers/eb/eb_u2f/firmware/stdint.h
Modified:
   gnuradio/branches/developers/eb/eb_u2f/firmware/
   gnuradio/branches/developers/eb/eb_u2f/firmware/Makefile.am
   gnuradio/branches/developers/eb/eb_u2f/firmware/hal_io.c
   gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.h
   gnuradio/branches/developers/eb/eb_u2f/firmware/memory_map.h
   gnuradio/branches/developers/eb/eb_u2f/firmware/u2_init.c
Log:
basic uart driver ready for testing


Property changes on: gnuradio/branches/developers/eb/eb_u2f/firmware
___________________________________________________________________
Name: svn:ignore
   - *-stamp
*.a
*.bin
*.dump
*.log
*.rom
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

   + *-stamp
*.a
*.bin
*.dump
*.log
*.rom
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


Modified: gnuradio/branches/developers/eb/eb_u2f/firmware/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/Makefile.am 2007-11-13 
17:31:30 UTC (rev 6879)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/Makefile.am 2007-11-13 
19:25:27 UTC (rev 6880)
@@ -18,7 +18,8 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 
-AM_CPPFLAGS = -DHAL_IO_USES_DBOARD_PINS
+#AM_CPPFLAGS = -DHAL_IO_USES_DBOARD_PINS
+AM_CPPFLAGS = -DHAL_IO_USES_UART
 
 #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
@@ -48,6 +49,7 @@
        eth_driver.c \
        eth_mac.c \
        hal_io.c \
+       hal_uart.c \
        pic.c \
        spi.c \
        u2_init.c       
@@ -61,6 +63,7 @@
        buf_ram_zero \
        eth_test \
        gen_eth_packets \
+       hello \
        ibs_rx_test \
        ibs_tx_test \
        rcv_eth_packets \

Added: gnuradio/branches/developers/eb/eb_u2f/firmware/divisors.py
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/divisors.py                 
        (rev 0)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/divisors.py 2007-11-13 
19:25:27 UTC (rev 6880)
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+speeds = (9600, 19200, 38400, 57600, 119200)
+
+master_clk = 100e6
+wb_clk = master_clk / 3
+
+def divisor(speed):
+    div0 = wb_clk // (speed * 16)
+    div1 = div0 + 1
+    actual0 = actual_speed(div0)
+    actual1 = actual_speed(div1)
+    if abs(actual0 - speed) < abs(actual1 - speed):
+        return div0
+    else:
+        return div1
+
+def actual_speed(divisor):
+    return (wb_clk // divisor) / 16
+
+def doit(speed):
+    div = divisor(speed)
+    actual = actual_speed(div)
+    rel_error = (actual - speed) / speed
+    print "target: %6d  divisor: %6d  actual: %11.4f  %6.3f%%" % (speed, div, 
actual, rel_error*100)
+
+def main():
+    print "wb_clk = %f" % (wb_clk,)
+    for s in speeds:
+        doit(s)
+
+if __name__ == '__main__':
+    main()
+    


Property changes on: gnuradio/branches/developers/eb/eb_u2f/firmware/divisors.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Modified: gnuradio/branches/developers/eb/eb_u2f/firmware/hal_io.c
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/hal_io.c    2007-11-13 
17:31:30 UTC (rev 6879)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/hal_io.c    2007-11-13 
19:25:27 UTC (rev 6880)
@@ -19,7 +19,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-// conditionalized on HAL_IO_USES_DBOARD_PINS
+// conditionalized on HAL_IO_USES_DBOARD_PINS && HAL_IO_USES_UART
 
 #include "hal_io.h"
 #include "memory_map.h"
@@ -85,6 +85,7 @@
 //                             primitives
 // ================================================================
 
+#if defined(HAL_IO_USES_DBOARD_PINS)
 //
 // Does i/o using high 9-bits of rx daughterboard pins.
 //
@@ -97,7 +98,6 @@
 // 
 // Asserts W when writing char
 //
-#if defined(HAL_IO_USES_DBOARD_PINS)
 
 #define W      0x0080
 
@@ -126,6 +126,27 @@
   *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

Added: gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.c
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.c                  
        (rev 0)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.c  2007-11-13 
19:25:27 UTC (rev 6880)
@@ -0,0 +1,104 @@
+/* -*- 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
+
+static const uint16_t
+divisor_table[NSPEEDS] = {     // KLUDGE fragile
+#if   WISHBONE_CLK_RATE == 25000000
+  163,  81, 41, 27, 13
+#elif WISHBONE_CLK_RATE == 33333333
+  217, 109, 54, 36, 17
+#elif WISHBONE_CLK_RATE == 50000000
+  326, 163, 81, 54, 26
+#else
+#error "Unexpected WISHBONE_CLK_RATE"
+#endif
+};
+
+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)
+{
+  if (c->speed >= NSPEEDS)
+    return;
+
+  current_config = *c;
+
+  uint16_t divisor = divisor_table[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;
+}


Property changes on: gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.h
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.h  2007-11-13 
17:31:30 UTC (rev 6879)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/hal_uart.h  2007-11-13 
19:25:27 UTC (rev 6880)
@@ -22,6 +22,11 @@
 #define INCLUDED_HAL_UART_H
 
 
+/*!
+ * \brief one-time call to init
+ */
+void hal_uart_init(void);
+
 typedef enum {
   US_9600,
   US_19200,

Added: gnuradio/branches/developers/eb/eb_u2f/firmware/hello.c
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/hello.c                     
        (rev 0)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/hello.c     2007-11-13 
19:25:27 UTC (rev 6880)
@@ -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;
+}


Property changes on: gnuradio/branches/developers/eb/eb_u2f/firmware/hello.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: gnuradio/branches/developers/eb/eb_u2f/firmware/memory_map.h
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/memory_map.h        
2007-11-13 17:31:30 UTC (rev 6879)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/memory_map.h        
2007-11-13 19:25:27 UTC (rev 6880)
@@ -22,6 +22,10 @@
 #ifndef INCLUDED_MEMORY_MAP_H
 #define INCLUDED_MEMORY_MAP_H
 
+#define MASTER_CLK_RATE        100000000               // 100 MHz
+#define WISHBONE_CLK_RATE      (MASTER_CLK_RATE / 3)   // 33.333 MHz
+
+
 ////////////////////////////////////////////////////////////////
 //
 //         Memory map for embedded wishbone bus

Added: gnuradio/branches/developers/eb/eb_u2f/firmware/stdint.h
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/stdint.h                    
        (rev 0)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/stdint.h    2007-11-13 
19:25:27 UTC (rev 6880)
@@ -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 */


Property changes on: gnuradio/branches/developers/eb/eb_u2f/firmware/stdint.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: gnuradio/branches/developers/eb/eb_u2f/firmware/u2_init.c
===================================================================
--- gnuradio/branches/developers/eb/eb_u2f/firmware/u2_init.c   2007-11-13 
17:31:30 UTC (rev 6879)
+++ gnuradio/branches/developers/eb/eb_u2f/firmware/u2_init.c   2007-11-13 
19:25:27 UTC (rev 6880)
@@ -5,6 +5,7 @@
 #include "pic.h"
 #include "hal_io.h"
 #include "buffer_pool.h"
+#include "hal_uart.h"
 
 /*
  * We ought to arrange for this to be called before main, but for now,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]