[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7363 - in usrp2/trunk/firmware: apps include lib
From: |
eb |
Subject: |
[Commit-gnuradio] r7363 - in usrp2/trunk/firmware: apps include lib |
Date: |
Sat, 5 Jan 2008 15:32:37 -0700 (MST) |
Author: eb
Date: 2008-01-05 15:32:37 -0700 (Sat, 05 Jan 2008)
New Revision: 7363
Modified:
usrp2/trunk/firmware/apps/app_common.c
usrp2/trunk/firmware/apps/test_i2c.c
usrp2/trunk/firmware/include/usrp2_eth_packet.h
usrp2/trunk/firmware/include/usrp2_i2c_addr.h
usrp2/trunk/firmware/lib/eth_mac.c
usrp2/trunk/firmware/lib/eth_mac.h
usrp2/trunk/firmware/lib/ethernet.c
usrp2/trunk/firmware/lib/ethernet.h
Log:
firmware to support u2_burn_mac_addr
Modified: usrp2/trunk/firmware/apps/app_common.c
===================================================================
--- usrp2/trunk/firmware/apps/app_common.c 2008-01-05 22:31:56 UTC (rev
7362)
+++ usrp2/trunk/firmware/apps/app_common.c 2008-01-05 22:32:37 UTC (rev
7363)
@@ -29,6 +29,13 @@
volatile bool link_is_up = false; // eth handler sets this
+static void
+burn_mac_addr(const op_burn_mac_addr_t *p)
+{
+ bool ok = ethernet_set_mac_addr(&p->addr);
+ // FIXME generate a rely from new addr?
+}
+
void
set_reply_hdr(u2_eth_packet_t *reply_pkt, u2_eth_packet_t const *cmd_pkt)
{
@@ -66,7 +73,7 @@
r->opcode = OP_ID_REPLY;
r->len = sizeof(op_id_reply_t);
r->rid_mbz = 0; // FIXME
- memcpy(&r->addr, ethernet_mac_addr(), 6);
+ r->addr = *ethernet_mac_addr();
r->hw_rev = 0x0000; // FIXME
for (i = 0; i < sizeof(r->serial_no); i++)
r->serial_no[i] = '0'; // FIXME
@@ -91,6 +98,10 @@
stop_rx_cmd();
break;
+ case OP_BURN_MAC_ADDR:
+ burn_mac_addr((op_burn_mac_addr_t *) p);
+ break;
+
default:
break;
}
Modified: usrp2/trunk/firmware/apps/test_i2c.c
===================================================================
--- usrp2/trunk/firmware/apps/test_i2c.c 2008-01-05 22:31:56 UTC (rev
7362)
+++ usrp2/trunk/firmware/apps/test_i2c.c 2008-01-05 22:32:37 UTC (rev
7363)
@@ -78,14 +78,14 @@
memset(buf, 0, sizeof(buf));
for (i = 0; i < len; i++)
buf[i] = i;
- ok = eeprom_write(I2C_ADDR_BOOT, offset, buf, len);
+ ok = eeprom_write(I2C_ADDR_MBOARD, offset, buf, len);
ASSERT_TRUE(ok);
// now try to read it back
offset = 31;
len = 8;
memset(buf, 0, sizeof(buf));
- ok = eeprom_read(I2C_ADDR_BOOT, offset, buf, len);
+ ok = eeprom_read(I2C_ADDR_MBOARD, offset, buf, len);
ASSERT_TRUE(ok);
// check result
Modified: usrp2/trunk/firmware/include/usrp2_eth_packet.h
===================================================================
--- usrp2/trunk/firmware/include/usrp2_eth_packet.h 2008-01-05 22:31:56 UTC
(rev 7362)
+++ usrp2/trunk/firmware/include/usrp2_eth_packet.h 2008-01-05 22:32:37 UTC
(rev 7363)
@@ -160,6 +160,7 @@
#define OP_WRITE_REG_MASKED 6
#define OP_READ_REG 7
#define OP_READ_REG_REPLY 8
+#define OP_BURN_MAC_ADDR 9
typedef struct {
uint8_t opcode;
@@ -208,6 +209,11 @@
uint16_t mbz;
} op_stop_rx_t;
+typedef struct {
+ uint8_t opcode;
+ uint8_t len;
+ u2_mac_addr_t addr;
+} op_burn_mac_addr_t;
// union of all of them
@@ -217,6 +223,7 @@
op_id_reply_t op_id_reply;
op_start_rx_t op_start_rx;
op_stop_rx_t op_stop_rx;
+ op_burn_mac_addr_t op_burn_mac_addr;
} u2_subpkt_t;
Modified: usrp2/trunk/firmware/include/usrp2_i2c_addr.h
===================================================================
--- usrp2/trunk/firmware/include/usrp2_i2c_addr.h 2008-01-05 22:31:56 UTC
(rev 7362)
+++ usrp2/trunk/firmware/include/usrp2_i2c_addr.h 2008-01-05 22:32:37 UTC
(rev 7363)
@@ -27,23 +27,26 @@
#define I2C_DEV_EEPROM 0x50 // 24LC02[45]: 7-bits 1010xxx
-#define I2C_ADDR_BOOT (I2C_DEV_EEPROM | 0x0)
+#define I2C_ADDR_MBOARD (I2C_DEV_EEPROM | 0x0)
#define I2C_ADDR_TX_A (I2C_DEV_EEPROM | 0x4)
#define I2C_ADDR_RX_A (I2C_DEV_EEPROM | 0x5)
-// FIXME the BOOT EEPROM is not yet defined for the U2
-// format of FX2 BOOT EEPROM
-// 00: 0xC0 code for ``Read IDs from EEPROM''
-// 01: 0xFE USB Vendor ID (LSB)
-// 02: 0xFF USB Vendor ID (MSB)
-// 03: 0x02 USB Product ID (LSB)
-// 04: 0x00 USB Product ID (MSB)
-// 05: 0x01 USB Device ID (LSB) // rev1
-// 06: 0x00 USB Device ID (MSB) // 0 = unconfig'd (no firmware)
-// 07: 0x00 option byte
+// format of USRP2 motherboard rom
+// 00: 0x00 h/w rev (LSB)
+// 01: 0x00 h/w rev (MSB)
+// 02: 0x00 MAC addr 0
+// 03: 0x50 MAC addr 1
+// 04: 0xC2 MAC addr 2
+// 05: 0x85 MAC addr 3
+// 06: 0x3. MAC addr 4
+// 07: 0x.. MAC addr 5
+#define MBOARD_REV_LSB 0x00
+#define MBOARD_REV_MSB 0x01
+#define MBOARD_MAC_ADDR 0x02
+
// format of daughterboard EEPROM
// 00: 0xDB code for ``I'm a daughterboard''
// 01: .. Daughterboard ID (LSB)
Modified: usrp2/trunk/firmware/lib/eth_mac.c
===================================================================
--- usrp2/trunk/firmware/lib/eth_mac.c 2008-01-05 22:31:56 UTC (rev 7362)
+++ usrp2/trunk/firmware/lib/eth_mac.c 2008-01-05 22:32:37 UTC (rev 7363)
@@ -25,26 +25,16 @@
#define PHY_ADDR 1
-// FIXME extract src_mac_addr from EEPROM
-// FIXME move functionality to ethernet.c
-
-static unsigned char src_mac_addr[6] = {
- 0x00, 0x0A, 0x35, 0x98, 0x76, 0x54
-};
-
-void
-eth_mac_init()
+void
+eth_mac_set_addr(const u2_mac_addr_t *src)
{
int i;
- // FIXME more to do?
- eth_mac->miimoder = 16; // divider from CPU clock (33MHz / 16 ~= 2MHz)
-
// tell mac our source address and enable automatic insertion on Tx.
eth_mac->mac_tx_add_prom_wr = 0; // just in case
for (i = 0; i < 6; i++){
eth_mac->mac_tx_add_prom_add = i;
- eth_mac->mac_tx_add_prom_data = src_mac_addr[i];
+ eth_mac->mac_tx_add_prom_data = src->addr[i];
eth_mac->mac_tx_add_prom_wr = 1;
mdelay(1);
eth_mac->mac_tx_add_prom_wr = 0;
@@ -56,16 +46,23 @@
eth_mac->mac_rx_add_prom_wr = 0; // just in case
for (i = 0; i < 6; i++){
eth_mac->mac_rx_add_prom_add = i;
- eth_mac->mac_rx_add_prom_data = src_mac_addr[i];
+ eth_mac->mac_rx_add_prom_data = src->addr[i];
eth_mac->mac_rx_add_prom_wr = 1;
mdelay(1);
eth_mac->mac_rx_add_prom_wr = 0;
mdelay(1);
}
// eth_mac->mac_rx_add_chk_en = 1; // FIXME enable when everything's working
+}
- eth_mac->tx_pause_en = 1; // pay attn to pause frames sent to us
+void
+eth_mac_init(const u2_mac_addr_t *src)
+{
+ eth_mac->miimoder = 16; // divider from CPU clock (33MHz / 16 ~= 2MHz)
+
+ eth_mac_set_addr(src);
+
// set rx flow control high and low water marks
// unsigned int lwmark = (2*2048 + 64)/4; // 2 * 2048-byte frames + 1 *
64-byte pause frame
// eth_mac->fc_hwmark = lwmark + 2048/4; // plus a 2048-byte frame
@@ -73,8 +70,9 @@
eth_mac->fc_lwmark = 400; // there is currently 1024 lines in the
fifo
eth_mac->fc_hwmark = 800;
- eth_mac->pause_quanta_set = 38; // a bit more than 1 max frame
16kb/512 + fudge
- eth_mac->pause_frame_send_en = 1; // enable sending pause frames
+ eth_mac->tx_pause_en = 1; // pay attn to pause frames sent to us
+ eth_mac->pause_quanta_set = 38; // a bit more than 1 max frame 16kb/512
+ fudge
+ eth_mac->pause_frame_send_en = 1; // enable sending pause frames
}
int
@@ -134,9 +132,3 @@
return eth_mac->miistatus;
}
-
-const unsigned char *
-_eth_mac_addr(void)
-{
- return src_mac_addr;
-}
Modified: usrp2/trunk/firmware/lib/eth_mac.h
===================================================================
--- usrp2/trunk/firmware/lib/eth_mac.h 2008-01-05 22:31:56 UTC (rev 7362)
+++ usrp2/trunk/firmware/lib/eth_mac.h 2008-01-05 22:32:37 UTC (rev 7363)
@@ -19,12 +19,14 @@
#ifndef INCLUDED_ETH_MAC_H
#define INCLUDED_ETH_MAC_H
-void eth_mac_init(void);
+#include "usrp2_mac_addr.h"
+
+void eth_mac_init(const u2_mac_addr_t *src);
+
+void eth_mac_set_addr(const u2_mac_addr_t *src);
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);
-const unsigned char *_eth_mac_addr(void); // FIXME move to eth_driver
-
#endif /* INCLUDED_ETH_MAC_H */
Modified: usrp2/trunk/firmware/lib/ethernet.c
===================================================================
--- usrp2/trunk/firmware/lib/ethernet.c 2008-01-05 22:31:56 UTC (rev 7362)
+++ usrp2/trunk/firmware/lib/ethernet.c 2008-01-05 22:32:37 UTC (rev 7363)
@@ -23,7 +23,11 @@
#include "pic.h"
#include "hal_io.h"
#include "nonstdio.h"
+#include "bool.h"
+#include "i2c.h"
+#include "usrp2_i2c_addr.h"
+
#define VERBOSE 0
static ethernet_t ed_state;
@@ -155,7 +159,7 @@
ethernet_init(void)
{
// FIXME get MAC address from EEPROM
- eth_mac_init();
+ eth_mac_init(ethernet_mac_addr());
ed_state.link_state = LS_UNKNOWN;
ed_state.link_speed = S_UNKNOWN;
@@ -198,8 +202,50 @@
eth_mac_miim_write(PHY_CTRL, t | MII_CR_RESTART_AUTO_NEG);
}
-const char *
+static bool
+unprogrammed(const u2_mac_addr_t *t)
+{
+ int i;
+ bool all_zeros = true;
+ bool all_ones = true;
+ for (i = 0; i < 6; i++){
+ all_zeros &= t->addr[i] == 0x00;
+ all_ones &= t->addr[i] == 0xff;
+ }
+ return all_ones | all_zeros;
+}
+
+static int8_t src_addr_initialized = false;
+static u2_mac_addr_t src_addr = {{
+ 0x00, 0x50, 0xC2, 0x85, 0x3f, 0xff
+ }};
+
+const u2_mac_addr_t *
ethernet_mac_addr(void)
{
- return _eth_mac_addr(); // FIXME guts should be here
+ if (!src_addr_initialized){ // fetch from eeprom
+ src_addr_initialized = true;
+ u2_mac_addr_t tmp;
+ bool ok = eeprom_read(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, &tmp.addr[0], 6);
+ if (!ok || unprogrammed(&tmp)){
+ // use the default
+ }
+ else
+ src_addr = tmp;
+ }
+
+ return &src_addr;
}
+
+bool
+ethernet_set_mac_addr(const u2_mac_addr_t *t)
+{
+ bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, &t->addr[0], 6);
+ if (ok){
+ src_addr = *t;
+ src_addr_initialized = true;
+ eth_mac_set_addr(t);
+ }
+
+ return ok;
+}
Modified: usrp2/trunk/firmware/lib/ethernet.h
===================================================================
--- usrp2/trunk/firmware/lib/ethernet.h 2008-01-05 22:31:56 UTC (rev 7362)
+++ usrp2/trunk/firmware/lib/ethernet.h 2008-01-05 22:32:37 UTC (rev 7363)
@@ -19,6 +19,9 @@
#ifndef INCLUDED_ETHERNET_H
#define INCLUDED_ETHERNET_H
+#include "usrp2_mac_addr.h"
+#include "bool.h"
+
typedef void (*ethernet_link_changed_callback_t)(int speed);
@@ -36,12 +39,17 @@
void ethernet_register_link_changed_callback(ethernet_link_changed_callback_t
cb);
/*!
- * \returns 6-byte ethernet MAC address
+ * \returns ethernet MAC address
*/
-const char *ethernet_mac_addr(void);
+const u2_mac_addr_t *ethernet_mac_addr(void);
+/*!
+ * \brief write mac address to eeprom and begin using it
+ */
+bool ethernet_set_mac_addr(const u2_mac_addr_t *t);
+
typedef enum { LS_UNKNOWN, LS_DOWN, LS_UP } eth_link_state_t;
#define S_UNKNOWN (-1) // unknown link speed
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7363 - in usrp2/trunk/firmware: apps include lib,
eb <=