[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7354 - in usrp2/trunk/firmware: apps lib
From: |
eb |
Subject: |
[Commit-gnuradio] r7354 - in usrp2/trunk/firmware: apps lib |
Date: |
Fri, 4 Jan 2008 21:45:31 -0700 (MST) |
Author: eb
Date: 2008-01-04 21:45:31 -0700 (Fri, 04 Jan 2008)
New Revision: 7354
Added:
usrp2/trunk/firmware/lib/ethernet.c
usrp2/trunk/firmware/lib/ethernet.h
Removed:
usrp2/trunk/firmware/lib/eth_driver.c
usrp2/trunk/firmware/lib/eth_driver.h
Modified:
usrp2/trunk/firmware/apps/app_common.c
usrp2/trunk/firmware/apps/blink_leds2.c
usrp2/trunk/firmware/apps/gen_eth_packets.c
usrp2/trunk/firmware/apps/gen_pause_frames.c
usrp2/trunk/firmware/apps/rcv_eth_packets.c
usrp2/trunk/firmware/apps/rx_only.c
usrp2/trunk/firmware/apps/test_phy_comm.c
usrp2/trunk/firmware/apps/test_serdes.c
usrp2/trunk/firmware/apps/tx_only.c
usrp2/trunk/firmware/apps/tx_standalone.c
usrp2/trunk/firmware/lib/Makefile.am
usrp2/trunk/firmware/lib/eth_mac.c
usrp2/trunk/firmware/lib/eth_mac.h
Log:
s/eth_driver/ethernet/g; now do mac_init in ethernet_init
Modified: usrp2/trunk/firmware/apps/app_common.c
===================================================================
--- usrp2/trunk/firmware/apps/app_common.c 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/apps/app_common.c 2008-01-05 04:45:31 UTC (rev
7354)
@@ -23,7 +23,7 @@
#include "app_common.h"
#include "buffer_pool.h"
#include "memcpy_wa.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include <string.h>
@@ -69,7 +69,7 @@
r->opcode = OP_ID_REPLY;
r->len = sizeof(op_id_reply_t);
r->rid_mbz = 0; // FIXME
- memcpy(&r->addr, eth_mac_addr(), 6);
+ memcpy(&r->addr, ethernet_mac_addr(), 6);
r->hw_rev = 0x0000; // FIXME
for (i = 0; i < sizeof(r->serial_no); i++)
r->serial_no[i] = '0'; // FIXME
Modified: usrp2/trunk/firmware/apps/blink_leds2.c
===================================================================
--- usrp2/trunk/firmware/apps/blink_leds2.c 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/apps/blink_leds2.c 2008-01-05 04:45:31 UTC (rev
7354)
@@ -22,8 +22,6 @@
#include "u2_init.h"
#include "memory_map.h"
#include "hal_io.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
#include "pic.h"
Modified: usrp2/trunk/firmware/apps/gen_eth_packets.c
===================================================================
--- usrp2/trunk/firmware/apps/gen_eth_packets.c 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/apps/gen_eth_packets.c 2008-01-05 04:45:31 UTC (rev
7354)
@@ -25,8 +25,7 @@
#include "buffer_pool.h"
#include "pic.h"
#include "bool.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include "usrp2_eth_packet.h"
#include "memcpy_wa.h"
@@ -170,10 +169,9 @@
pic_register_handler(IRQ_TIMER, timer_irq_handler);
hal_set_timeout(timer_delta);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_register_link_changed_callback(link_changed_callback);
- eth_mac_init();
- eth_driver_init();
+ ethernet_init();
// eth_mac->speed = 4; // FIXME hardcode mac speed to 1000
Modified: usrp2/trunk/firmware/apps/gen_pause_frames.c
===================================================================
--- usrp2/trunk/firmware/apps/gen_pause_frames.c 2008-01-05 04:36:07 UTC
(rev 7353)
+++ usrp2/trunk/firmware/apps/gen_pause_frames.c 2008-01-05 04:45:31 UTC
(rev 7354)
@@ -22,8 +22,7 @@
#include "buffer_pool.h"
#include "pic.h"
#include "bool.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include "u2_eth_packet.h"
#include "memcpy_wa.h"
@@ -167,10 +166,9 @@
pic_register_handler(IRQ_TIMER, timer_irq_handler);
hal_set_timeout(timer_delta);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_register_link_changed_callback(link_changed_callback);
- eth_mac_init();
- eth_driver_init();
+ ethernet_init();
eth_mac->pause_frame_send_en = 1;
eth_mac->pause_quanta_set = 16384 / 512;
Modified: usrp2/trunk/firmware/apps/rcv_eth_packets.c
===================================================================
--- usrp2/trunk/firmware/apps/rcv_eth_packets.c 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/apps/rcv_eth_packets.c 2008-01-05 04:45:31 UTC (rev
7354)
@@ -25,8 +25,7 @@
#include "buffer_pool.h"
#include "pic.h"
#include "bool.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include "usrp2_eth_packet.h"
#include "memcpy_wa.h"
@@ -168,10 +167,9 @@
// pic_register_handler(IRQ_TIMER, timer_irq_handler);
// hal_set_timeout(timer_delta);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_register_link_changed_callback(link_changed_callback);
- eth_mac_init();
- eth_driver_init();
+ ethernet_init();
//eth_mac->speed = 4; // FIXME hardcode mac speed to 1000
Modified: usrp2/trunk/firmware/apps/rx_only.c
===================================================================
--- usrp2/trunk/firmware/apps/rx_only.c 2008-01-05 04:36:07 UTC (rev 7353)
+++ usrp2/trunk/firmware/apps/rx_only.c 2008-01-05 04:45:31 UTC (rev 7354)
@@ -26,8 +26,7 @@
#include "buffer_pool.h"
#include "pic.h"
#include "bool.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include "usrp2_eth_packet.h"
#include "memcpy_wa.h"
@@ -234,10 +233,9 @@
//pic_register_handler(IRQ_TIMER, timer_irq_handler);
//hal_set_timeout(timer_delta);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_register_link_changed_callback(link_changed_callback);
- eth_mac_init();
- eth_driver_init();
+ ethernet_init();
// initialize double buffering state machine for DSP RX -> Ethernet
dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0,
Modified: usrp2/trunk/firmware/apps/test_phy_comm.c
===================================================================
--- usrp2/trunk/firmware/apps/test_phy_comm.c 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/apps/test_phy_comm.c 2008-01-05 04:45:31 UTC (rev
7354)
@@ -20,8 +20,7 @@
#include "u2_init.h"
#include "memory_map.h"
#include "hal_io.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "pic.h"
#include "nonstdio.h"
@@ -98,15 +97,15 @@
hal_gpio_set_tx_mode(15, 13, GPIOM_OUTPUT);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_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();
+ ethernet_init();
- u2_infinite_loop();
+ while(1)
+ ;
return 0;
}
Modified: usrp2/trunk/firmware/apps/test_serdes.c
===================================================================
--- usrp2/trunk/firmware/apps/test_serdes.c 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/apps/test_serdes.c 2008-01-05 04:45:31 UTC (rev
7354)
@@ -22,8 +22,7 @@
#include "buffer_pool.h"
#include "pic.h"
#include "bool.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include "usrp2_eth_packet.h"
#include "memcpy_wa.h"
@@ -162,10 +161,9 @@
pic_register_handler(IRQ_TIMER, timer_irq_handler);
hal_set_timeout(timer_delta);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_register_link_changed_callback(link_changed_callback);
- eth_mac_init();
- eth_driver_init();
+ ethernet_init();
// eth_mac->speed = 4; // FIXME hardcode mac speed to 1000
int i = 0;
Modified: usrp2/trunk/firmware/apps/tx_only.c
===================================================================
--- usrp2/trunk/firmware/apps/tx_only.c 2008-01-05 04:36:07 UTC (rev 7353)
+++ usrp2/trunk/firmware/apps/tx_only.c 2008-01-05 04:45:31 UTC (rev 7354)
@@ -26,8 +26,7 @@
#include "buffer_pool.h"
#include "pic.h"
#include "bool.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include "usrp2_eth_packet.h"
#include "memcpy_wa.h"
@@ -237,10 +236,9 @@
//pic_register_handler(IRQ_TIMER, timer_irq_handler);
//hal_set_timeout(timer_delta);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_register_link_changed_callback(link_changed_callback);
- eth_mac_init();
- eth_driver_init();
+ ethernet_init();
// initialize double buffering state machine for ethernet -> DSP Tx
Modified: usrp2/trunk/firmware/apps/tx_standalone.c
===================================================================
--- usrp2/trunk/firmware/apps/tx_standalone.c 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/apps/tx_standalone.c 2008-01-05 04:45:31 UTC (rev
7354)
@@ -26,8 +26,7 @@
#include "buffer_pool.h"
#include "pic.h"
#include "bool.h"
-#include "eth_driver.h"
-#include "eth_mac.h"
+#include "ethernet.h"
#include "nonstdio.h"
#include "usrp2_eth_packet.h"
#include "memcpy_wa.h"
@@ -177,58 +176,7 @@
putstr("\nirq: overrun\n");
}
-
static void
-start_rx_cmd(const u2_mac_addr_t *host)
-{
- // printf("start_rx_cmd\n");
- // hal_toggle_leds(0x2);
-
- host_mac_addr = *host; // remember who we're sending to
-
- /*
- * Construct ethernet header and word0 and preload into two buffers
- */
- u2_eth_packet_t pkt;
- memset(&pkt, 0, sizeof(pkt));
- pkt.ehdr.dst = *host;
- pkt.ehdr.ethertype = U2_ETHERTYPE;
- u2p_set_word0(&pkt.fixed, 0, 0);
- // DSP RX will fill in timestamp
-
- memcpy_wordaligned(buffer_ram(DSP_RX_BUF_0), &pkt, sizeof(pkt));
- memcpy_wordaligned(buffer_ram(DSP_RX_BUF_1), &pkt, sizeof(pkt));
-
-
- // setup RX DSP regs
- dsp_rx_regs->clear_state = 1; // reset
- dsp_rx_regs->freq = 0;
- dsp_rx_regs->scale_iq = (1 << 16) | 1;
- dsp_rx_regs->decim_rate = 63; // register gets N - 1
-
- uint32_t cmd = MK_RX_CMD(10000 * DSP_RX_SAMPLES_PER_FRAME,
DSP_RX_SAMPLES_PER_FRAME);
- // printf("rx_command = "); puthex32_nl(cmd);
- dsp_rx_regs->rx_command = cmd;
-
- // kick off the state machine
- dbsm_start(&dsp_rx_sm);
-
- // dsp_rx_regs->rx_time = 1; // timer_regs->time + 10000;
- dsp_rx_regs->rx_time = T_NOW; // start NOW!
-
- // FIXME need to arrange to add additional stuff to cmd queue
-}
-
-
-static void
-stop_rx_cmd(void)
-{
- dsp_rx_regs->clear_state = 1; // FIXME need to flush cmd queue
- bp_clear_buf(DSP_RX_BUF_0);
- bp_clear_buf(DSP_RX_BUF_1);
-}
-
-static void
start_tx_transfers(void)
{
bp_clear_buf(DSP_TX_BUF_0); // FIXME, really goes in state machine
@@ -272,104 +220,7 @@
SEND_CONST_TO_DSP_TX(); // send constant buffer to DSP TX
}
-static void
-set_reply_hdr(u2_eth_packet_t *reply_pkt, u2_eth_packet_t const *cmd_pkt)
-{
- reply_pkt->ehdr.dst = cmd_pkt->ehdr.src;
- reply_pkt->ehdr.ethertype = U2_ETHERTYPE;
- reply_pkt->ehdr._pad = 0;
- u2p_set_word0(&reply_pkt->fixed, 0, CONTROL_CHAN);
- reply_pkt->fixed.timestamp = timer_regs->time;
-}
-static void
-handle_control_chan_frame(int bufno, u2_eth_packet_t *pkt, size_t len)
-{
- static unsigned char payload[64] _AL4;
- static unsigned char reply[sizeof(u2_eth_packet_t) + sizeof(u2_subpkt_t)]
_AL4;
- unsigned char *s = &reply[sizeof(u2_eth_packet_t)];
- size_t reply_len = 0;
- int i;
-
- // FIXME copy as needed...
- // copy 64 bytes of payload into stack buffer
- memcpy_wordaligned(payload,
- (unsigned char *) buffer_ram(bufno) +
sizeof(u2_eth_packet_t),
- sizeof(payload));
-
- unsigned char *p = payload;
- int opcode = p[0];
-
- switch(opcode){
- case OP_ID:
- memset(reply, 0, sizeof(reply));
- set_reply_hdr((u2_eth_packet_t *) reply, pkt);
- {
- op_id_reply_t *r = (op_id_reply_t *) s;
- reply_len = sizeof(u2_eth_packet_t) + sizeof(op_id_reply_t);
- if (reply_len < 64)
- reply_len = 64;
- r->opcode = OP_ID_REPLY;
- r->len = sizeof(op_id_reply_t);
- r->rid_mbz = 0; // FIXME
- memcpy(&r->addr, eth_mac_addr(), 6);
- r->hw_rev = 0x0000; // FIXME
- for (i = 0; i < sizeof(r->serial_no); i++)
- r->serial_no[i] = '0'; // FIXME
-
- // r->fpga_md5sum = ; // FIXME
- // r->sw_md5sum = ; // FIXME
- }
-
- // FIXME need to see if ethernet tx is busy
-
- // copy reply into CPU_TX_BUF
- memcpy_wordaligned(buffer_ram(CPU_TX_BUF), reply, reply_len);
-
- bp_send_from_buf(CPU_TX_BUF, PORT_ETH, 1, 0, reply_len / 4);
- break;
-
- case OP_START_RX:
- start_rx_cmd(&pkt->ehdr.src);
- break;
-
- case OP_STOP_RX:
- stop_rx_cmd();
- break;
-
- default:
- break;
- }
-}
-
-static void
-handle_rcvd_eth_frame(int bufno)
-{
- u2_eth_packet_t pkt;
- size_t byte_len = (buffer_pool_status->last_line[bufno] - 1) * 4;
-
- hal_toggle_leds(0x1);
-
- // inspect rcvd frame and figure out what do do.
-
- // copy first part of frame to stack buffer so we can byte address it
- memcpy_wordaligned(&pkt, buffer_ram(bufno), sizeof(pkt));
-
- if (pkt.ehdr.ethertype != U2_ETHERTYPE)
- return; // ignore, probably bogus PAUSE frame from MAC
-
- int chan = u2p_chan(&pkt.fixed);
- switch (chan){
- case CONTROL_CHAN:
- handle_control_chan_frame(bufno, &pkt, byte_len);
- break;
-
- case 0: // to Tx DSP
- default:
- break;
- }
-}
-
void
buffer_irq_handler(unsigned irq)
{
@@ -391,21 +242,6 @@
hal_toggle_leds(0x1);
}
-#if 0
- // FIXME probably ought to round-robin the check for done
-
- if (status & BPS_DONE(CPU_RX_BUF)){ // we've rcvd a frame from ethernet
- bp_clear_buf(CPU_RX_BUF);
- handle_rcvd_eth_frame(CPU_RX_BUF);
- bp_receive_to_buf(CPU_RX_BUF, PORT_ETH, 1, 0, 255);
- }
-
- if (status & BPS_DONE(CPU_TX_BUF)){
- bp_clear_buf(CPU_TX_BUF);
- }
-
- dbsm_process_status(&dsp_rx_sm, status);
-#endif
}
int
@@ -431,10 +267,9 @@
//pic_register_handler(IRQ_TIMER, timer_irq_handler);
//hal_set_timeout(timer_delta);
- eth_driver_register_link_changed_callback(link_changed_callback);
+ ethernet_register_link_changed_callback(link_changed_callback);
- eth_mac_init();
- eth_driver_init();
+ ethernet_init();
// initialize double buffering state machine for DSP RX -> Ethernet
dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0,
Modified: usrp2/trunk/firmware/lib/Makefile.am
===================================================================
--- usrp2/trunk/firmware/lib/Makefile.am 2008-01-05 04:36:07 UTC (rev
7353)
+++ usrp2/trunk/firmware/lib/Makefile.am 2008-01-05 04:45:31 UTC (rev
7354)
@@ -25,7 +25,7 @@
buffer_pool.c \
dbsm.c \
eeprom.c \
- eth_driver.c \
+ ethernet.c \
eth_mac.c \
hal_io.c \
hal_uart.c \
Deleted: usrp2/trunk/firmware/lib/eth_driver.c
Deleted: usrp2/trunk/firmware/lib/eth_driver.h
Modified: usrp2/trunk/firmware/lib/eth_mac.c
===================================================================
--- usrp2/trunk/firmware/lib/eth_mac.c 2008-01-05 04:36:07 UTC (rev 7353)
+++ usrp2/trunk/firmware/lib/eth_mac.c 2008-01-05 04:45:31 UTC (rev 7354)
@@ -26,6 +26,7 @@
#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
@@ -135,7 +136,7 @@
}
const unsigned char *
-eth_mac_addr(void)
+_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 04:36:07 UTC (rev 7353)
+++ usrp2/trunk/firmware/lib/eth_mac.h 2008-01-05 04:45:31 UTC (rev 7354)
@@ -25,6 +25,6 @@
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
+const unsigned char *_eth_mac_addr(void); // FIXME move to eth_driver
#endif /* INCLUDED_ETH_MAC_H */
Copied: usrp2/trunk/firmware/lib/ethernet.c (from rev 7346,
usrp2/trunk/firmware/lib/eth_driver.c)
===================================================================
--- usrp2/trunk/firmware/lib/ethernet.c (rev 0)
+++ usrp2/trunk/firmware/lib/ethernet.c 2008-01-05 04:45:31 UTC (rev 7354)
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ethernet.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"
+#include "nonstdio.h"
+
+#define VERBOSE 0
+
+static ethernet_t ed_state;
+static ethernet_link_changed_callback_t ed_callback = 0;
+
+void
+ethernet_register_link_changed_callback(ethernet_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)
+{
+ // putstr("ed_link_up: "); puthex16_nl(speed);
+
+ ed_set_mac_speed(speed);
+
+ if (ed_callback) // fire link changed callback
+ (*ed_callback)(speed);
+}
+
+static void
+ed_link_down(void)
+{
+ // putstr("ed_link_down\n");
+
+ if (ed_callback) // fire link changed callback
+ (*ed_callback)(0);
+}
+
+
+static void
+ed_link_speed_change(int 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;
+
+ if (VERBOSE){
+ putstr("LANSR: ");
+ puthex16_nl(lansr);
+ }
+
+ if (lansr & LANSR_LINK_GOOD){ // link's up
+ if (VERBOSE)
+ puts(" 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
+ if (VERBOSE)
+ puts(" 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
+ 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
+ethernet_init(void)
+{
+ // FIXME get MAC address from EEPROM
+ eth_mac_init();
+
+ 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
+ );
+
+ putchar('$');
+
+ 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);
+
+ putstr("ethernet: wr INT_MASK = ");
+ puthex16_nl(mask);
+ putstr("ethernet: rd INT_MASK = ");
+ 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();
+}
+
+const char *
+ethernet_mac_addr(void)
+{
+ return _eth_mac_addr(); // FIXME guts should be here
+}
Copied: usrp2/trunk/firmware/lib/ethernet.h (from rev 7346,
usrp2/trunk/firmware/lib/eth_driver.h)
===================================================================
--- usrp2/trunk/firmware/lib/ethernet.h (rev 0)
+++ usrp2/trunk/firmware/lib/ethernet.h 2008-01-05 04:45:31 UTC (rev 7354)
@@ -0,0 +1,54 @@
+/* -*- c -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This program 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 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_ETHERNET_H
+#define INCLUDED_ETHERNET_H
+
+typedef void (*ethernet_link_changed_callback_t)(int speed);
+
+
+/*!
+ * \brief one time call to initialize ethernet
+ */
+void ethernet_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 ethernet_register_link_changed_callback(ethernet_link_changed_callback_t
cb);
+
+/*!
+ * \returns 6-byte ethernet MAC address
+ */
+const char *ethernet_mac_addr(void);
+
+
+
+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
+} ethernet_t;
+
+#endif /* INCLUDED_ETHERNET_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7354 - in usrp2/trunk/firmware: apps lib,
eb <=