- 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
+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)
{
*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 "libsys.h"
#include "mips_gfx.h"
#include "screen.h"
#include "cop0.h"
#define USE_HW_BLITTER
+2 -1
View File
@@ -11,7 +11,8 @@
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include "libsys.h"
#include <libsys/libsys.h>
#include "ethernet.h"
#include "arp.h"
+1 -1
View File
@@ -4,7 +4,7 @@
// 21.12.2003, J. Ahrensfeld
//
// -------------------------------------------------------------------------
#include "libsys.h"
#include <libsys/libsys.h>
#include "ethernet.h"
#include "ipv4.h"
#include "udp.h"
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef DHCP_H
#define DHCP_H
#include "libsys.h"
#include <libsys/libsys.h>
#include "ethernet.h"
// -------------------------------------------------------------------------
+3 -1
View File
@@ -11,7 +11,9 @@
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include "libsys.h"
#include <libsys/libsys.h>
#include "emac.h"
#include "ethernet.h"
// -------------------------------------------------------------------------
+2 -1
View File
@@ -14,7 +14,8 @@
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include "libsys.h"
#include <libsys/gpio.h>
#define ETH_PACKET_MIN_SIZE 64
#define ETH_PACKET_MAX_SIZE 1500
+145
View File
@@ -0,0 +1,145 @@
#include <stdlib.h>
#include <libsys/libsys.h>
#include "fifo.h"
uint32_t fifo_alloc(fifo_t *pObj, uint32_t size)
{
pObj->pBuf = (uint8_t*)malloc(size);
if (!pObj->pBuf)
{
// printf ("fifo_alloc(): Error allocating memory!\n");
return -1;
}
// printf ("fifo_alloc(): pBuf at %8.8X\n", (uint32_t)pObj->pBuf);
pObj->size = size;
pObj->pPtr_wr = pObj->pBuf;
pObj->pPtr_rd = pObj->pBuf;
return 0;
}
uint32_t fifo_free(fifo_t *pObj)
{
if (pObj->pBuf)
free(pObj->pBuf);
return 0;
}
uint32_t fifo_flush(fifo_t *pObj)
{
pObj->pPtr_wr = pObj->pBuf;
pObj->pPtr_rd = pObj->pBuf;
return 0;
}
uint32_t fifo_is_empty(fifo_t *pObj)
{
return (pObj->pPtr_wr == pObj->pPtr_rd);
}
uint32_t fifo_is_full(fifo_t *pObj)
{
uint8_t *pNext, *pEnd;
pEnd = pObj->pBuf + pObj->size;
pNext = pObj->pPtr_wr + 1;
if (pNext == pEnd)
pNext = pObj->pBuf;
return (pNext == pObj->pPtr_rd);
}
uint32_t fifo_read(fifo_t *pObj, uint8_t *pData, uint32_t size, uint32_t timeout, uint32_t do_block)
{
uint32_t i;
uint32_t wait_4ever, timeout_cnt, cnt;
uint8_t *pEnd;
pEnd = pObj->pBuf + pObj->size;
wait_4ever = (timeout == 0);
cnt = 0;
while(size)
{
timeout_cnt = timeout;
while(fifo_is_empty(pObj))
{
if (!do_block)
return cnt;
if (!wait_4ever)
{
if (timeout_cnt)
{
timeout_cnt--;
sleep(1);
}
else
{
return cnt;
}
}
}
if (pData)
pData[cnt] = *(pObj->pPtr_rd);
cnt++;
pObj->pPtr_rd++;
if (pObj->pPtr_rd == pEnd)
pObj->pPtr_rd = pObj->pBuf;
size--;
}
return cnt;
}
uint32_t fifo_write(fifo_t *pObj, uint8_t *pData, uint32_t size, uint32_t timeout, uint32_t do_block)
{
uint32_t wait_4ever, timeout_cnt, cnt;
uint8_t *pEnd;
pEnd = pObj->pBuf + pObj->size;
wait_4ever = (timeout == 0);
cnt = 0;
while(size)
{
timeout_cnt = timeout;
while(fifo_is_full(pObj))
{
if (!do_block)
return cnt;
if (!wait_4ever)
{
if (timeout_cnt)
{
timeout_cnt--;
sleep(1);
}
else
{
return cnt;
}
}
}
if (pData)
*(pObj->pPtr_wr) = pData[cnt];
cnt++;
pObj->pPtr_wr++;
if (pObj->pPtr_wr == pEnd)
pObj->pPtr_wr = pObj->pBuf;
size--;
}
return cnt;
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef FIFO_H
#define FIFO_H
// ---------------------------------------------------------
// Constants
// ---------------------------------------------------------
#define FIFO_BLOCK 1
#define FIFO_NONBLOCK 0
// ---------------------------------------------------------
// Types
// ---------------------------------------------------------
typedef struct _sfifo_t
{
uint32_t size;
uint8_t *pBuf;
uint8_t * volatile pPtr_wr, * volatile pPtr_rd;
} fifo_t;
// ---------------------------------------------------------
// Functions
// ---------------------------------------------------------
uint32_t fifo_alloc(fifo_t *pObj, uint32_t size);
uint32_t fifo_free(fifo_t *pObj);
uint32_t fifo_flush(fifo_t *pObj);
uint32_t fifo_is_full(fifo_t *pObj);
uint32_t fifo_is_empty(fifo_t *pObj);
uint32_t fifo_read(fifo_t *pObj, uint8_t *pData, uint32_t size, uint32_t timeout, uint32_t do_block);
uint32_t fifo_write(fifo_t *pObj, uint8_t *pData, uint32_t size, uint32_t timeout, uint32_t do_block);
#endif // FIFO_H
+2 -2
View File
@@ -4,11 +4,11 @@
// 21.12.2003, J. Ahrensfeld
//
// -------------------------------------------------------------------------
#include "libsys.h"
#include <string.h>
#include <libsys/libsys.h>
#include "ethernet.h"
#include "ipv4.h"
#include "icmp.h"
#include "string.h"
// -------------------------------------------------------------------------
// Testing
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef ICMP_H
#define ICMP_H
#include "libsys.h"
#include <libsys/libsys.h>
#include "ethernet.h"
// -------------------------------------------------------------------------
+2 -2
View File
@@ -4,10 +4,10 @@
// 21.12.2003, J. Ahrensfeld
//
// -------------------------------------------------------------------------
#include "libsys.h"
#include <string.h>
#include <libsys/libsys.h>
#include "ethernet.h"
#include "ipv4.h"
#include "string.h"
#define IPV4_HEADER_SIZE 20
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef IPV4_H
#define IPV4_H
#include "libsys.h"
#include <libsys/libsys.h>
#include "ethernet.h"
// -------------------------------------------------------------------------
+2 -2
View File
@@ -1,7 +1,7 @@
/** *******************************************************************************
*
* 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.
*
@@ -34,7 +34,7 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include "libsys.h"
#include <libsys/libsys.h>
//#include "errno.h"
#include "marvell_88e1111.h"
+80 -89
View File
@@ -1,7 +1,7 @@
/** *******************************************************************************
*
* 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
* 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 <errno.h>
#include "libsys.h"
#include "gpio.h"
#include <libsys/libsys.h>
#include <libsys/gpio.h>
#include "mii-bitbang.h"
/*
@@ -56,42 +57,27 @@ static void mii_delay (void)
* 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_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);
gpio_set(&pObj->gpio_mdio_dir, GPIO_0_MDIO_MDIO);
}
/*
* mdio_mode_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_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);
}
gpio_clr(&pObj->gpio_mdio_dir, GPIO_0_MDIO_MDIO);
}
/*
* mdio_read:
* 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;
gpio_read_data(mii_gpio, GPIO_0_MASK_MDIO, GPIO_0_ALIGN_MDIO, &data);
// printf("MDIO read: 0x%x\n", data);
uint32_t data = gpio_read(&pObj->gpio_mdio_data);
return (data & GPIO_0_MDIO_MDIO) != 0;
}
@@ -99,80 +85,88 @@ static int mdio_read(gpio_if_t *mii_gpio)
* mdio_drive_bit:
* 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)
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
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:
* 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)
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
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:
* 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();
mdc_drive_bit(mii_gpio, 1);
mdc_drive_bit(pObj, 1);
mii_delay();
mdc_drive_bit(mii_gpio, 0);
mdc_drive_bit(pObj, 0);
}
/*
* mii_send_address:
* 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;
/*
* Send a 32 bit preamble of 1's
*/
mdio_mode_output(mii_gpio);
mdio_drive_bit(mii_gpio, 1); /* <<<<< */
mdio_mode_output(pObj);
mdio_drive_bit(pObj, 1); /* <<<<< */
for (i = 0; i < MII_PREABLE_BITS; i++) {
mdc_clk_1_0(mii_gpio);
mdc_clk_1_0(pObj);
}
/*
* send the start bit (01)
*/
mdio_drive_bit(mii_gpio, 0); /* <<<<< */
mdc_clk_1_0(mii_gpio);
mdio_drive_bit(mii_gpio, 1); /* <<<<< */
mdc_clk_1_0(mii_gpio);
mdio_drive_bit(pObj, 0); /* <<<<< */
mdc_clk_1_0(pObj);
mdio_drive_bit(pObj, 1); /* <<<<< */
mdc_clk_1_0(pObj);
/*
* send the opcode: read (10) write (10)
*/
mdio_drive_bit(mii_gpio, read); /* <<<<< */
mdc_clk_1_0(mii_gpio);
mdio_drive_bit(mii_gpio, !read); /* <<<<< */
mdc_clk_1_0(mii_gpio);
mdio_drive_bit(pObj, read); /* <<<<< */
mdc_clk_1_0(pObj);
mdio_drive_bit(pObj, !read); /* <<<<< */
mdc_clk_1_0(pObj);
/*
* send the PHY address
*/
for (i = 0; i < MII_5ADDRESS_BITS; i++) {
if (addr & FIFTH_BIT_0x10) {
mdio_drive_bit(mii_gpio, 1); /* <<<<< */
mdio_drive_bit(pObj, 1); /* <<<<< */
} 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;
}
@@ -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++) {
if (reg & FIFTH_BIT_0x10) {
mdio_drive_bit(mii_gpio, 1); /* <<<<< */
mdio_drive_bit(pObj, 1); /* <<<<< */
} 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;
}
@@ -196,7 +190,7 @@ static void mii_send_address (gpio_if_t *mii_gpio, int read, uint8_t addr, uint8
* MiiGpio_PhyRead:
* 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 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.
*/
mii_send_address(mii_gpio, MII_READ, PhyAddress, RegisterNum);
mii_send_address(pObj, MII_READ, PhyAddress, RegisterNum);
/*
* Set GPIO mode to read
*/
mdio_mode_input(mii_gpio);
mdc_clk_1_0(mii_gpio);
mdio_mode_input(pObj);
mdc_clk_1_0(pObj);
/*
* 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");
return -1;
@@ -227,13 +221,13 @@ uint32_t MiiGpio_PhyRead (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t Reg
regval = 0;
for (i = 0; i < MII_16REGISTER_BITS; i++)
{
mdc_clk_1_0(mii_gpio);
mdc_clk_1_0(pObj);
regval <<= 1;
regval |= mdio_read(mii_gpio);
regval |= mdio_read(pObj);
}
mdc_clk_1_0(mii_gpio);
mdc_clk_1_0(pObj);
return regval;
}
@@ -242,20 +236,20 @@ uint32_t MiiGpio_PhyRead (gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t Reg
* MiiGpio_PhyWrite:
* 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;
/*
* 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) */
mdio_drive_bit(mii_gpio, 1); /* <<<<< */
mdc_clk_1_0(mii_gpio);
mdio_drive_bit(mii_gpio, 0); /* <<<<< */
mdc_clk_1_0(mii_gpio);
mdio_drive_bit(pObj, 1); /* <<<<< */
mdc_clk_1_0(pObj);
mdio_drive_bit(pObj, 0); /* <<<<< */
mdc_clk_1_0(pObj);
/*
* 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)
{
mdio_drive_bit(mii_gpio, 1); /* <<<<< */
mdio_drive_bit(pObj, 1); /* <<<<< */
}
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;
}
mdio_mode_input(mii_gpio);
mdc_clk_1_0(mii_gpio);
mdio_mode_input(pObj);
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:
* 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
*/
// 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
*/
// GPIO_SetDataDirection(mii_gpio, MDC_MDIO_GPIO_CHANNEL, MDC_MDIO_MDIO_BIT);
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;
gpio_write(&pObj->gpio_mdio_dir, GPIO_0_MDIO_RST | GPIO_0_MDIO_MDC);
}
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
* 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
* 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 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 <stdlib.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);
void MiiGpio_PhyWrite(gpio_if_t *mii_gpio, uint32_t PhyAddress, uint32_t RegisterNum, uint16_t PhyData);
int MiiGpio_Init(gpio_if_t *mii_gpio);
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_Init(Mii_t *pObj);
void MiiGpio_Reset(Mii_t *pObj);
#endif
+1 -1
View File
@@ -7,7 +7,7 @@
#ifndef UDP_H
#define UDP_H
#include "libsys.h"
#include <libsys/libsys.h>
#include "ethernet.h"
// -------------------------------------------------------------------------
typedef struct _sUDP