- refactored network

- fixed gpio_clr()

git-svn-id: http://moon:8086/svn/mips@206 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2021-11-23 22:00:29 +00:00
parent 30b0a4c619
commit 4dfb4b92ea
19 changed files with 194 additions and 168 deletions
+13 -2
View File
@@ -3,10 +3,12 @@ BOARD ?=ml402
include $(MIPS_HOME)/make/mips_app.mk include $(MIPS_HOME)/make/mips_app.mk
PROG-ml402 = $(addprefix $(BUILD_DIR)/, hello.elf testbench.elf test_irq.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf life.elf r3.elf gunzip.elf basic_math.elf jman_patches.elf jman_patchmeshes.elf jman_polys.elf test_hpi.elf test_vga.elf test_fft.elf flashtest.elf test_emac_sim.elf) PROG-ml402 = $(addprefix $(BUILD_DIR)/, hello.elf testbench.elf test_irq.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf life.elf r3.elf gunzip.elf basic_math.elf jman_patches.elf jman_patchmeshes.elf jman_polys.elf test_hpi.elf test_vga.elf test_fft.elf flashtest.elf test_emac.elf)
PROG-denano = $(addprefix $(BUILD_DIR)/, hello.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf testbench_denano.elf) PROG-denano = $(addprefix $(BUILD_DIR)/, hello.elf dhry.elf queens.elf stanford.elf paranoia.elf rmd160_test.elf Bessel.elf whet.elf phrasen.elf dttl.elf richards_benchmark.elf test_exception.elf testbench_denano.elf)
PROG-sim = $(addprefix $(BUILD_DIR)/, hello.elf test_exception_sim.elf test_emac_sim.elf) PROG-sim = $(addprefix $(BUILD_DIR)/, hello.elf test_exception_sim.elf test_emac_sim.elf)
PROG-ml402 = $(addprefix $(BUILD_DIR)/, test_emac.elf)
SRCS-network = $(addprefix common/network/, arp.c dhcp.c emac.c ethernet.c icmp.c ipv4.c marvell_88e1111.c mii-bitbang.c udp.c fifo.c)
all: $(PROG-$(BOARD)) all: $(PROG-$(BOARD))
$(BUILD_DIR): $(BUILD_DIR):
@@ -451,6 +453,15 @@ $(BUILD_DIR)/test_emac_sim.elf: $(BUILD_DIR) test_emac_sim.c common/network/emac
cat $@.srec | $(PACKHEX) > $@.pack cat $@.srec | $(PACKHEX) > $@.pack
$(OBJCOPY) -O ihex -I binary $@.flash.bin $@.hex $(OBJCOPY) -O ihex -I binary $@.flash.bin $@.hex
$(BUILD_DIR)/test_emac.elf: $(BUILD_DIR) test_emac.c $(network-SRCS)
$(CC) $(CFLAGS) -o $@ -Os test_emac.c $(SRCS-network) $(LIBS) >$@.map
$(OBJDUMP) -d $@ > $@.dis
$(OBJCOPY) $@ -O binary $@.bin
$(OBJCOPY) -O srec $@ $@.srec
$(FLASHGEN) $@.bin $(ENDIAN_FLAGS)
cat $@.srec | $(PACKHEX) > $@.pack
$(OBJCOPY) -O ihex -I binary $@.flash.bin $@.hex
$(BUILD_DIR)/mips_io.elf: $(BUILD_DIR) mips_io.c $(BUILD_DIR)/mips_io.elf: $(BUILD_DIR) mips_io.c
$(CC) $(CFLAGS) -o $@ mips_io.c $(LIBS) >$@.map $(CC) $(CFLAGS) -o $@ mips_io.c $(LIBS) >$@.map
$(OBJDUMP) -d $@ > $@.dis $(OBJDUMP) -d $@ > $@.dis
+1 -1
View File
@@ -28,7 +28,7 @@ void gpio_set(gpio_if_t *pObj, uint32_t value)
void gpio_clr(gpio_if_t *pObj, uint32_t value) void gpio_clr(gpio_if_t *pObj, uint32_t value)
{ {
*pObj->pBase &= ~((value | pObj->mask) << pObj->shift); *pObj->pBase &= ~((value & pObj->mask) << pObj->shift);
} }
// --------------------------------------------------------- // ---------------------------------------------------------
+2
View File
@@ -3,6 +3,8 @@
#include <string.h> #include <string.h>
#include "libsys.h" #include "libsys.h"
#include "mips_gfx.h" #include "mips_gfx.h"
#include "screen.h"
#include "cop0.h"
#define USE_HW_BLITTER #define USE_HW_BLITTER
+2 -1
View File
@@ -11,7 +11,8 @@
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include "libsys.h" #include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
#include "arp.h" #include "arp.h"
+1 -1
View File
@@ -4,7 +4,7 @@
// 21.12.2003, J. Ahrensfeld // 21.12.2003, J. Ahrensfeld
// //
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include "libsys.h" #include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
#include "ipv4.h" #include "ipv4.h"
#include "udp.h" #include "udp.h"
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef DHCP_H #ifndef DHCP_H
#define DHCP_H #define DHCP_H
#include "libsys.h" #include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
+3 -1
View File
@@ -11,7 +11,9 @@
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include "libsys.h"
#include <libsys/libsys.h>
#include "emac.h"
#include "ethernet.h" #include "ethernet.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
+2 -1
View File
@@ -14,7 +14,8 @@
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include "libsys.h"
#include <libsys/gpio.h>
#define ETH_PACKET_MIN_SIZE 64 #define ETH_PACKET_MIN_SIZE 64
#define ETH_PACKET_MAX_SIZE 1500 #define ETH_PACKET_MAX_SIZE 1500
+1 -1
View File
@@ -1,5 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include "libsys.h" #include <libsys/libsys.h>
#include "fifo.h" #include "fifo.h"
uint32_t fifo_alloc(fifo_t *pObj, uint32_t size) uint32_t fifo_alloc(fifo_t *pObj, uint32_t size)
+2 -2
View File
@@ -4,11 +4,11 @@
// 21.12.2003, J. Ahrensfeld // 21.12.2003, J. Ahrensfeld
// //
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include "libsys.h" #include <string.h>
#include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
#include "ipv4.h" #include "ipv4.h"
#include "icmp.h" #include "icmp.h"
#include "string.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Testing // Testing
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef ICMP_H #ifndef ICMP_H
#define ICMP_H #define ICMP_H
#include "libsys.h" #include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
+2 -2
View File
@@ -4,10 +4,10 @@
// 21.12.2003, J. Ahrensfeld // 21.12.2003, J. Ahrensfeld
// //
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include "libsys.h" #include <string.h>
#include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
#include "ipv4.h" #include "ipv4.h"
#include "string.h"
#define IPV4_HEADER_SIZE 20 #define IPV4_HEADER_SIZE 20
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef IPV4_H #ifndef IPV4_H
#define IPV4_H #define IPV4_H
#include "libsys.h" #include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
+2 -2
View File
@@ -1,7 +1,7 @@
/** ******************************************************************************* /** *******************************************************************************
* *
* Project: Robotics library for the Autonomous Robotics Development Platform * Project: Robotics library for the Autonomous Robotics Development Platform
* Port by: Jorge Sánchez de Nova jssdn (mail)_(at) kth.se * Port by: Jorge Snchez de Nova jssdn (mail)_(at) kth.se
* *
* NOTE: This code is based on the Xilinx XAPP1042. * NOTE: This code is based on the Xilinx XAPP1042.
* *
@@ -34,7 +34,7 @@
#include <signal.h> #include <signal.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include "libsys.h" #include <libsys/libsys.h>
//#include "errno.h" //#include "errno.h"
#include "marvell_88e1111.h" #include "marvell_88e1111.h"
+80 -89
View File
@@ -1,7 +1,7 @@
/** ******************************************************************************* /** *******************************************************************************
* *
* Project: Robotics library for the Autonomous Robotics Development Platform * Project: Robotics library for the Autonomous Robotics Development Platform
* Port by: Jorge Sánchez de Nova jssdn (mail)_(at) kth.se * Port by: Jorge Snchez de Nova jssdn (mail)_(at) kth.se
* *
* NOTE: This code is based on the Xilinx XAPP1042 which, as noted by Xilinx, is based in Linux Kernel's * NOTE: This code is based on the Xilinx XAPP1042 which, as noted by Xilinx, is based in Linux Kernel's
* drivers/net/fs_enet by Vitaly Bordug <vbordug@ru.mvista.com> and Pantelis Antoniou <panto@intracom.gr> * drivers/net/fs_enet by Vitaly Bordug <vbordug@ru.mvista.com> and Pantelis Antoniou <panto@intracom.gr>
@@ -35,8 +35,9 @@
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
#include "libsys.h" #include <libsys/libsys.h>
#include "gpio.h" #include <libsys/gpio.h>
#include "mii-bitbang.h" #include "mii-bitbang.h"
/* /*
@@ -56,42 +57,27 @@ static void mii_delay (void)
* set GPIO to OUTPUT * set GPIO to OUTPUT
*/ */
static void mdio_mode_output(gpio_if_t *mii_gpio) static void mdio_mode_output(Mii_t *pObj)
{ {
uint32_t dir; gpio_set(&pObj->gpio_mdio_dir, GPIO_0_MDIO_MDIO);
gpio_get_dir(mii_gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, &dir);
dir |= GPIO_0_MDIO_MDIO;
/* Set the direction for the MDIO signal to be output */
gpio_set_dir(mii_gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, dir);
} }
/* /*
* mdio_mode_input: * mdio_mode_input:
* set GPIO to INPUT * set GPIO to INPUT
*/ */
static void mdio_mode_input(gpio_if_t *mii_gpio) static void mdio_mode_input(Mii_t *pObj)
{ {
uint32_t dir; gpio_clr(&pObj->gpio_mdio_dir, GPIO_0_MDIO_MDIO);
}
gpio_get_dir(mii_gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, &dir);
dir &= ~GPIO_0_MDIO_MDIO;
// printf("MDIO dir: 0x%x\n", dir);
/* Set the direction for the MDIO signal to be input */
gpio_set_dir(mii_gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, dir);
}
/* /*
* mdio_read: * mdio_read:
* Read the value presently driven by the PHY on the MDIO GPIO * Read the value presently driven by the PHY on the MDIO GPIO
*/ */
static int mdio_read(gpio_if_t *mii_gpio) static int mdio_read(Mii_t *pObj)
{ {
uint32_t data; uint32_t data = gpio_read(&pObj->gpio_mdio_data);
gpio_read_data(mii_gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, &data);
// printf("MDIO read: 0x%x\n", data);
return (data & GPIO_0_MDIO_MDIO) != 0; return (data & GPIO_0_MDIO_MDIO) != 0;
} }
@@ -99,80 +85,88 @@ static int mdio_read(gpio_if_t *mii_gpio)
* mdio_drive_bit: * mdio_drive_bit:
* set the GPIO to drive the appropriate bit value on the MDIO pin * set the GPIO to drive the appropriate bit value on the MDIO pin
*/ */
static void mdio_drive_bit(gpio_if_t *mii_gpio, uint32_t value) static void mdio_drive_bit(Mii_t *pObj, uint32_t value)
{ {
if (value) if (value)
gpio_write(mii_gpio, GPIO_0_MDIO_MDIO, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, ~0); {
gpio_set(&pObj->gpio_mdio_data, GPIO_0_MDIO_MDIO);
}
else else
gpio_write(mii_gpio, GPIO_0_MDIO_MDIO, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, 0); {
gpio_clr(&pObj->gpio_mdio_data, GPIO_0_MDIO_MDIO);
}
} }
/* /*
* mdc_drive_bit: * mdc_drive_bit:
* Toggle the MDC GPIO to the appropriate bit. * Toggle the MDC GPIO to the appropriate bit.
*/ */
static void mdc_drive_bit(gpio_if_t *mii_gpio, uint32_t value) static void mdc_drive_bit(Mii_t *pObj, uint32_t value)
{ {
if (value) if (value)
gpio_write(mii_gpio, GPIO_0_MDIO_MDC, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, ~0); {
gpio_set(&pObj->gpio_mdio_data, GPIO_0_MDIO_MDC);
}
else else
gpio_write(mii_gpio, GPIO_0_MDIO_MDC, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, 0); {
gpio_clr(&pObj->gpio_mdio_data, GPIO_0_MDIO_MDC);
}
} }
/* /*
* mdc_clk_1_0: * mdc_clk_1_0:
* Drive the MII Data Clock 1->0 * Drive the MII Data Clock 1->0
*/ */
static void mdc_clk_1_0 (gpio_if_t *mii_gpio) static void mdc_clk_1_0 (Mii_t *pObj)
{ {
mii_delay(); mii_delay();
mdc_drive_bit(mii_gpio, 1); mdc_drive_bit(pObj, 1);
mii_delay(); mii_delay();
mdc_drive_bit(mii_gpio, 0); mdc_drive_bit(pObj, 0);
} }
/* /*
* mii_send_address: * mii_send_address:
* Transmit the preamble, phy address, and phy register number on the bus. * Transmit the preamble, phy address, and phy register number on the bus.
*/ */
static void mii_send_address (gpio_if_t *mii_gpio, int read, uint8_t addr, uint8_t reg) static void mii_send_address (Mii_t *pObj, int read, uint8_t addr, uint8_t reg)
{ {
int i; int i;
/* /*
* Send a 32 bit preamble of 1's * Send a 32 bit preamble of 1's
*/ */
mdio_mode_output(mii_gpio); mdio_mode_output(pObj);
mdio_drive_bit(mii_gpio, 1); /* <<<<< */ mdio_drive_bit(pObj, 1); /* <<<<< */
for (i = 0; i < MII_PREABLE_BITS; i++) { for (i = 0; i < MII_PREABLE_BITS; i++) {
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
} }
/* /*
* send the start bit (01) * send the start bit (01)
*/ */
mdio_drive_bit(mii_gpio, 0); /* <<<<< */ mdio_drive_bit(pObj, 0); /* <<<<< */
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
mdio_drive_bit(mii_gpio, 1); /* <<<<< */ mdio_drive_bit(pObj, 1); /* <<<<< */
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
/* /*
* send the opcode: read (10) write (10) * send the opcode: read (10) write (10)
*/ */
mdio_drive_bit(mii_gpio, read); /* <<<<< */ mdio_drive_bit(pObj, read); /* <<<<< */
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
mdio_drive_bit(mii_gpio, !read); /* <<<<< */ mdio_drive_bit(pObj, !read); /* <<<<< */
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
/* /*
* send the PHY address * send the PHY address
*/ */
for (i = 0; i < MII_5ADDRESS_BITS; i++) { for (i = 0; i < MII_5ADDRESS_BITS; i++) {
if (addr & FIFTH_BIT_0x10) { if (addr & FIFTH_BIT_0x10) {
mdio_drive_bit(mii_gpio, 1); /* <<<<< */ mdio_drive_bit(pObj, 1); /* <<<<< */
} else { } else {
mdio_drive_bit(mii_gpio, 0); /* <<<<< */ mdio_drive_bit(pObj, 0); /* <<<<< */
} }
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
addr <<= 1; addr <<= 1;
} }
@@ -182,11 +176,11 @@ static void mii_send_address (gpio_if_t *mii_gpio, int read, uint8_t addr, uint8
*/ */
for (i = 0; i < MII_5ADDRESS_BITS; i++) { for (i = 0; i < MII_5ADDRESS_BITS; i++) {
if (reg & FIFTH_BIT_0x10) { if (reg & FIFTH_BIT_0x10) {
mdio_drive_bit(mii_gpio, 1); /* <<<<< */ mdio_drive_bit(pObj, 1); /* <<<<< */
} else { } else {
mdio_drive_bit(mii_gpio, 0); /* <<<<< */ mdio_drive_bit(pObj, 0); /* <<<<< */
} }
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
reg <<= 1; reg <<= 1;
} }
@@ -196,7 +190,7 @@ static void mii_send_address (gpio_if_t *mii_gpio, int read, uint8_t addr, uint8
* MiiGpio_PhyRead: * MiiGpio_PhyRead:
* Read from an MII PHY register * Read from an MII PHY register
*/ */
uint32_t MiiGpio_PhyRead (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t RegisterNum) uint32_t MiiGpio_PhyRead (Mii_t *pObj, uint32_t PhyAddress, uint32_t RegisterNum)
{ {
uint16_t regval; uint16_t regval;
uint16_t i; uint16_t i;
@@ -204,18 +198,18 @@ uint32_t MiiGpio_PhyRead (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t Reg
/* /*
* Bang the PHY address and PHY register on the bus. * Bang the PHY address and PHY register on the bus.
*/ */
mii_send_address(mii_gpio, MII_READ, PhyAddress, RegisterNum); mii_send_address(pObj, MII_READ, PhyAddress, RegisterNum);
/* /*
* Set GPIO mode to read * Set GPIO mode to read
*/ */
mdio_mode_input(mii_gpio); mdio_mode_input(pObj);
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
/* /*
* check the turnaround bit * check the turnaround bit
*/ */
if (mdio_read(mii_gpio) != 0) if (mdio_read(pObj) != 0)
{ {
printf("ERROR: PHY not driving turnaround bit low.\n\r"); printf("ERROR: PHY not driving turnaround bit low.\n\r");
return -1; return -1;
@@ -227,13 +221,13 @@ uint32_t MiiGpio_PhyRead (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t Reg
regval = 0; regval = 0;
for (i = 0; i < MII_16REGISTER_BITS; i++) for (i = 0; i < MII_16REGISTER_BITS; i++)
{ {
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
regval <<= 1; regval <<= 1;
regval |= mdio_read(mii_gpio); regval |= mdio_read(pObj);
} }
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
return regval; return regval;
} }
@@ -242,20 +236,20 @@ uint32_t MiiGpio_PhyRead (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t Reg
* MiiGpio_PhyWrite: * MiiGpio_PhyWrite:
* Write to an MII PHY register * Write to an MII PHY register
*/ */
void MiiGpio_PhyWrite (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t RegisterNum, uint16_t PhyData) void MiiGpio_PhyWrite (Mii_t *pObj, uint32_t PhyAddress, uint32_t RegisterNum, uint16_t PhyData)
{ {
int i; int i;
/* /*
* Bang the PHY address and PHY register on the bus. * Bang the PHY address and PHY register on the bus.
*/ */
mii_send_address(mii_gpio, MII_WRITE, PhyAddress, RegisterNum); mii_send_address(pObj, MII_WRITE, PhyAddress, RegisterNum);
/* send the turnaround (10) */ /* send the turnaround (10) */
mdio_drive_bit(mii_gpio, 1); /* <<<<< */ mdio_drive_bit(pObj, 1); /* <<<<< */
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
mdio_drive_bit(mii_gpio, 0); /* <<<<< */ mdio_drive_bit(pObj, 0); /* <<<<< */
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
/* /*
* write 16 bits of register data, MSB first * write 16 bits of register data, MSB first
@@ -264,19 +258,19 @@ void MiiGpio_PhyWrite (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t Regist
{ {
if (PhyData & MSB_16BITS_0x8000) if (PhyData & MSB_16BITS_0x8000)
{ {
mdio_drive_bit(mii_gpio, 1); /* <<<<< */ mdio_drive_bit(pObj, 1); /* <<<<< */
} }
else else
{ {
mdio_drive_bit(mii_gpio, 0); /* <<<<< */ mdio_drive_bit(pObj, 0); /* <<<<< */
} }
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
PhyData <<= 1; PhyData <<= 1;
} }
mdio_mode_input(mii_gpio); mdio_mode_input(pObj);
mdc_clk_1_0(mii_gpio); mdc_clk_1_0(pObj);
} }
@@ -285,29 +279,26 @@ void MiiGpio_PhyWrite (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t Regist
* MiiGpio_Init: * MiiGpio_Init:
* Initialize GPIOs connected to PHY MDC and MDIO pins * Initialize GPIOs connected to PHY MDC and MDIO pins
*/ */
int MiiGpio_Init(gpio_if_t *mii_gpio) void MiiGpio_Init(Mii_t *pObj)
{ {
uint32_t Data;
int err;
if (mii_gpio == NULL) {
return -ENODEV;
}
/* /*
* Initialize the GPIO component * Initialize the GPIO component
*/ */
// Init GPIO MDIO
gpio_init(&pObj->gpio_mdio_data, SYS_GPIO_0_DATA, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO);
gpio_init(&pObj->gpio_mdio_dir, SYS_GPIO_0_DIR, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO);
//TODO: CHANGE! /*
err = gpio_init(mii_gpio, SYS_GPIO_0_BASE);
if( err < 0 )
return err;
/*
* Set the direction for MDC signals to be output * Set the direction for MDC signals to be output
*/ */
// GPIO_SetDataDirection(mii_gpio, MDC_MDIO_GPIO_CHANNEL, MDC_MDIO_MDIO_BIT); gpio_write(&pObj->gpio_mdio_dir, GPIO_0_MDIO_RST | GPIO_0_MDIO_MDC);
gpio_write(mii_gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, GPIO_DIR_OFFSET, GPIO_0_MDIO_RST | GPIO_0_MDIO_MDC); }
return 0;
void MiiGpio_Reset(Mii_t *pObj)
{
// Reset PHY
gpio_set(&pObj->gpio_mdio_data, GPIO_0_MDIO_RST);
sleep(1);
gpio_clr(&pObj->gpio_mdio_data, GPIO_0_MDIO_RST);
sleep(100);
} }
+12 -7
View File
@@ -4,7 +4,7 @@
/** ******************************************************************************* /** *******************************************************************************
* *
* Project: Robotics library for the Autonomous Robotics Development Platform * Project: Robotics library for the Autonomous Robotics Development Platform
* Port by: Jorge Sánchez de Nova jssdn (mail)_(at) kth.se * Port by: Jorge Snchez de Nova jssdn (mail)_(at) kth.se
* *
* NOTE: This code is based on the Xilinx XAPP1042 which, as noted by Xilinx, is based in Linux Kernel's * NOTE: This code is based on the Xilinx XAPP1042 which, as noted by Xilinx, is based in Linux Kernel's
* drivers/net/fs_enet by Vitaly Bordug <vbordug@ru.mvista.com> and Pantelis Antoniou <panto@intracom.gr> * drivers/net/fs_enet by Vitaly Bordug <vbordug@ru.mvista.com> and Pantelis Antoniou <panto@intracom.gr>
@@ -67,15 +67,20 @@
#define FIFTH_BIT_0x10 0x10 #define FIFTH_BIT_0x10 0x10
#define MSB_16BITS_0x8000 0x8000 #define MSB_16BITS_0x8000 0x8000
typedef struct _sMii_t
{
gpio_if_t gpio_mdio_data;
gpio_if_t gpio_mdio_dir;
} Mii_t;
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include "gpio.h" #include <libsys/gpio.h>
uint32_t MiiGpio_PhyRead(gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t RegisterNum); uint32_t MiiGpio_PhyRead(Mii_t *pObj, uint32_t PhyAddress, uint32_t RegisterNum);
void MiiGpio_PhyWrite(Mii_t *pObj, uint32_t PhyAddress, uint32_t RegisterNum, uint16_t PhyData);
void MiiGpio_PhyWrite(gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t RegisterNum, uint16_t PhyData); void MiiGpio_Init(Mii_t *pObj);
void MiiGpio_Reset(Mii_t *pObj);
int MiiGpio_Init(gpio_if_t *mii_gpio);
#endif #endif
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef UDP_H #ifndef UDP_H
#define UDP_H #define UDP_H
#include "libsys.h" #include <libsys/libsys.h>
#include "ethernet.h" #include "ethernet.h"
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
typedef struct _sUDP typedef struct _sUDP
+67 -54
View File
@@ -5,21 +5,33 @@
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include "libsys.h"
#include "fifo.h"
#include "emac.h"
#include "ethernet.h"
#include "arp.h"
#include "icmp.h"
#include "ipv4.h"
#include "udp.h"
#include "dhcp.h"
#include "gpio.h"
#include "mii-bitbang.h"
#include "marvell_88e1111.h"
gpio_if_t gpio; #include <libsys/libsys.h>
gpio_if_t mii_gpio; #include <libsys/gpio.h>
#include <libsys/irq.h>
#include <network/ethernet.h>
#include <network/emac.h>
#include <network/arp.h>
#include <network/icmp.h>
#include <network/ipv4.h>
#include <network/udp.h>
#include <network/dhcp.h>
#include <network/mii-bitbang.h>
#include <network/marvell_88e1111.h>
#include <network/fifo.h>
#include "board.h"
gpio_if_t gpio_led_data;
gpio_if_t gpio_led_dir;
gpio_if_t gpio_btn_data;
gpio_if_t gpio_btn_dir;
gpio_if_t gpio_mdio_data;
Mii_t mii;
#define BUFFER_SIZE (32*1024*1024) #define BUFFER_SIZE (32*1024*1024)
@@ -40,8 +52,6 @@ typedef struct _srx_descr_t
#define PHY_IDO_REG 2 #define PHY_IDO_REG 2
#define PHY_ID1_REG 3 #define PHY_ID1_REG 3
#define NOT_SIM 1
void Time_print(void) void Time_print(void)
{ {
time_t curr_date; time_t curr_date;
@@ -91,7 +101,7 @@ void handler6(void)
} }
} }
void mii_loopback_enable(gpio_if_t *pObj, uint16_t phy_id, uint32_t speed) void mii_loopback_enable(Mii_t *pMii, uint16_t phy_id, uint32_t speed)
{ {
uint16_t val; uint16_t val;
@@ -99,17 +109,17 @@ void mii_loopback_enable(gpio_if_t *pObj, uint16_t phy_id, uint32_t speed)
{ {
case MPHY_CONTROL_SPD_SEL_10: case MPHY_CONTROL_SPD_SEL_10:
val = MPHY_CONTROL_DUPLEX; val = MPHY_CONTROL_DUPLEX;
MiiGpio_PhyWrite(pObj, phy_id, MPHY_CONTROL_REG, val); MiiGpio_PhyWrite(pMii, phy_id, MPHY_CONTROL_REG, val);
break; break;
case MPHY_CONTROL_SPD_SEL_100: case MPHY_CONTROL_SPD_SEL_100:
val = MPHY_CONTROL_SPD_SEL_LSB | MPHY_CONTROL_DUPLEX; val = MPHY_CONTROL_SPD_SEL_LSB | MPHY_CONTROL_DUPLEX;
MiiGpio_PhyWrite(pObj, phy_id, MPHY_CONTROL_REG, val); MiiGpio_PhyWrite(pMii, phy_id, MPHY_CONTROL_REG, val);
break; break;
case MPHY_CONTROL_SPD_SEL_1000: case MPHY_CONTROL_SPD_SEL_1000:
val = MPHY_CONTROL_SPD_SEL_MSB | MPHY_CONTROL_DUPLEX; val = MPHY_CONTROL_SPD_SEL_MSB | MPHY_CONTROL_DUPLEX;
MiiGpio_PhyWrite(pObj, phy_id, MPHY_CONTROL_REG, val); MiiGpio_PhyWrite(pMii, phy_id, MPHY_CONTROL_REG, val);
break; break;
default: default:
@@ -117,17 +127,17 @@ void mii_loopback_enable(gpio_if_t *pObj, uint16_t phy_id, uint32_t speed)
} }
val = MiiGpio_PhyRead(&mii_gpio, phy_id, MPHY_CONTROL_REG); val = MiiGpio_PhyRead(pMii, phy_id, MPHY_CONTROL_REG);
val |= MPHY_CONTROL_RESET; val |= MPHY_CONTROL_RESET;
MiiGpio_PhyWrite(&mii_gpio, phy_id, MPHY_CONTROL_REG, val); MiiGpio_PhyWrite(pMii, phy_id, MPHY_CONTROL_REG, val);
val = MiiGpio_PhyRead(&mii_gpio, phy_id, MPHY_CONTROL_REG); val = MiiGpio_PhyRead(pMii, phy_id, MPHY_CONTROL_REG);
val |= MPHY_CONTROL_LOOPBACK; val |= MPHY_CONTROL_LOOPBACK;
MiiGpio_PhyWrite(&mii_gpio, phy_id, MPHY_CONTROL_REG, val); MiiGpio_PhyWrite(pMii, phy_id, MPHY_CONTROL_REG, val);
} }
void Phy_print_regs(gpio_if_t *pObj, uint16_t phy_id) void Phy_print_regs(Mii_t *pMii, uint16_t phy_id)
{ {
uint16_t i, j, val; uint16_t i, j, val;
@@ -136,7 +146,7 @@ void Phy_print_regs(gpio_if_t *pObj, uint16_t phy_id)
{ {
for (j=0; j < 8; j++) for (j=0; j < 8; j++)
{ {
printf("%02X: %04X ", i+j, MiiGpio_PhyRead(&mii_gpio, phy_id, i+j)); printf("%02X: %04X ", i+j, MiiGpio_PhyRead(pMii, phy_id, i+j));
} }
printf("\n"); printf("\n");
} }
@@ -211,7 +221,15 @@ int main()
setbuf(stdout, NULL); setbuf(stdout, NULL);
gpio_init(&gpio, SYS_GPIO_0_BASE); // Init GPIO BTN
gpio_init(&gpio_btn_data, SYS_GPIO_0_DATA, GPIO_0_MASK_BTN, GPIO_0_ALIGN_BTN);
gpio_init(&gpio_btn_dir, SYS_GPIO_0_DIR, GPIO_0_MASK_BTN, GPIO_0_ALIGN_BTN);
gpio_clr(&gpio_btn_dir, GPIO_0_MASK_BTN);
// Init GPIO LED
gpio_init(&gpio_led_data, SYS_GPIO_0_DATA, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED);
gpio_init(&gpio_led_dir, SYS_GPIO_0_DIR, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED);
gpio_set(&gpio_led_dir, GPIO_0_MASK_LED);
g_buf_start = (uint32_t*)malloc(BUFFER_SIZE); g_buf_start = (uint32_t*)malloc(BUFFER_SIZE);
g_pBuf_end = g_buf_start + BUFFER_SIZE/sizeof(uint32_t); g_pBuf_end = g_buf_start + BUFFER_SIZE/sizeof(uint32_t);
@@ -220,57 +238,52 @@ int main()
fifo_alloc(&rx_descr_fifo, sizeof(rx_descr_t)*BUFFER_SIZE/64); fifo_alloc(&rx_descr_fifo, sizeof(rx_descr_t)*BUFFER_SIZE/64);
// LED // LED
gpio_write(&gpio, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DIR_OFFSET, GPIO_0_MASK_LED); gpio_write(&gpio_led_data, 0);
gpio_write(&gpio, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DATA_OFFSET, 0);
// MDIO
gpio_write(&gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, GPIO_DIR_OFFSET, GPIO_0_MDIO_RST | GPIO_0_MDIO_MDC);
// Create PHY interface
MiiGpio_Init(&mii);
// Reset PHY // Reset PHY
gpio_write(&gpio, GPIO_0_MDIO_RST, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, 1); MiiGpio_Reset(&mii);
#if NOT_SIM
sleep(1); res = gpio_read(&gpio_led_dir);
gpio_write(&gpio, GPIO_0_MDIO_RST, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, 0);
sleep(100);
gpio_read(&gpio, ~0, 0, GPIO_DIR_OFFSET, &res);
printf("Dir = %08X\n", res); printf("Dir = %08X\n", res);
// while(1) // while(1)
{ {
gpio_read(&gpio, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DATA_OFFSET, &res); res = gpio_read(&gpio_led_data);
printf("LED-Data = %08X\n", res); printf("LED-Data = %08X\n", res);
gpio_write(&gpio, GPIO_0_MASK_LED, GPIO_0_ALIGN_LED, GPIO_DATA_OFFSET, res + 1); gpio_write(&gpio_led_data, res + 1);
gpio_read(&gpio, GPIO_0_MASK_BTN, GPIO_0_ALIGN_BTN, GPIO_DATA_OFFSET, &res);
res = gpio_read(&gpio_btn_data);
printf("Btn-Data = %08X\n", res); printf("Btn-Data = %08X\n", res);
gpio_read(&gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, GPIO_DATA_OFFSET, &res);
res = gpio_read(&gpio_mdio_data);
printf("MDIO-Data = %08X\n", res); printf("MDIO-Data = %08X\n", res);
sleep(100); sleep(100);
} }
#endif
MiiGpio_Init(&mii_gpio); // Phy_loopback_enable(&mii, PHY_ADDR, MPHY_CONTROL_SPD_SEL_100);
// Phy_loopback_enable(&mii_gpio, PHY_ADDR, MPHY_CONTROL_SPD_SEL_100);
// printf("Set loopback mode.\n\r"); // printf("Set loopback mode.\n\r");
/* set 100mbps and reset PHY */ /* set 100mbps and reset PHY */
phy_reg = 0x3300; phy_reg = 0x3300;
MiiGpio_PhyWrite(&mii_gpio, PHY_ADDR, 0, phy_reg | 0x8000); MiiGpio_PhyWrite(&mii, PHY_ADDR, 0, phy_reg | 0x8000);
/* wait for reset to complete */ /* wait for reset to complete */
while (MiiGpio_PhyRead(&mii_gpio, PHY_ADDR, 0) & 0x8000); while (MiiGpio_PhyRead(&mii, PHY_ADDR, 0) & 0x8000);
/* set auto negotiation */ /* set auto negotiation */
phy_reg = MiiGpio_PhyRead(&mii_gpio, PHY_ADDR, 0); phy_reg = MiiGpio_PhyRead(&mii, PHY_ADDR, 0);
MiiGpio_PhyWrite(&mii_gpio, PHY_ADDR, 0, phy_reg | 0x0200); MiiGpio_PhyWrite(&mii, PHY_ADDR, 0, phy_reg | 0x0200);
/* wait for auto negotiation to complete */ /* wait for auto negotiation to complete */
while (!(MiiGpio_PhyRead(&mii_gpio, PHY_ADDR, 1) & 0x0024)) while (!(MiiGpio_PhyRead(&mii, PHY_ADDR, 1) & 0x0024))
{ {
usleep(10000); usleep(10000);
} }
Phy_print_regs(&mii_gpio, PHY_ADDR); Phy_print_regs(&mii, PHY_ADDR);
EMAC_RX_reset(); EMAC_RX_reset();
EMAC_TX_reset(); EMAC_TX_reset();
@@ -335,7 +348,7 @@ int main()
printf("\n"); printf("\n");
} }
gpio_read(&gpio, GPIO_0_MASK_BTN, GPIO_0_ALIGN_BTN, GPIO_DATA_OFFSET, &res); res = gpio_read(&gpio_btn_data);
if (!res) if (!res)
continue; continue;