OpenCores
URL https://opencores.org/ocsvn/fpga-cf/fpga-cf/trunk

Subversion Repositories fpga-cf

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /fpga-cf
    from Rev 9 to Rev 10
    Reverse comparison

Rev 9 → Rev 10

/trunk/release/genrp.ps1
1,5 → 1,5
# Generate Release Package for the FPGA Ethernet Platform
#Remove-Item fpgaep -recurse
Remove-Item fpgaep -recurse
New-Item .\fpgaep -ItemType directory
New-Item .\fpgaep\hdl -ItemType directory
New-Item .\fpgaep\hdl\boardsupport -ItemType directory
54,6 → 54,7
cp ..\hdl\topv5_simple.v .\fpgaep\hdl\toplevel
cp ..\hdl\topv5_sha1.v .\fpgaep\hdl\toplevel
cp ..\hdl\topv5_proto.v .\fpgaep\hdl\toplevel
cp ..\hdl\topv5_echo.v .\fpgaep\hdl\toplevel
cp ..\hdl\topv5_prototest.v .\fpgaep\hdl\toplevel
New-Item .\fpgaep\java -ItemType directory
cp ..\java\doc .\fpgaep\java -Recurse
65,7 → 66,7
cp ..\java\src\edu\byu\cc\plieber\fpgaenet\examples\SimpleOperations.java .\fpgaep\java\examples
cp ..\java\src\edu\byu\cc\plieber\fpgaenet\examples\ThroughputTest.java .\fpgaep\java\examples
New-Item .\fpgaep\java\fcp -ItemType directory
cp $home\jworkspace\FCP\src\edu\byu\cc\plieber\fpgaenet\fcp\* .\fpgaep\java\fcp -Exclude "FCPTest.java"
cp ..\java\src\edu\byu\cc\plieber\fpgaenet\fcp\* .\fpgaep\java\fcp -Exclude "FCPTest.java"
New-Item .\fpgaep\java\subapi -ItemType directory
cp ..\java\src\edu\byu\cc\plieber\fpgaenet\examples\SimpleInterface.java .\fpgaep\java\SubAPI
cp ..\java\src\edu\byu\cc\plieber\fpgaenet\icapif\IcapInterface.java .\fpgaep\java\SubAPI
/trunk/cpp/fcpprotocol.hpp
0,0 → 1,45
// fcpprotocol.hpp
 
#ifndef FCPPROTOCOL_HPP
#define FCPPROTOCOL_HPP
 
#include "rawethernet.hpp"
 
typedef unsigned char byte;
 
// FCP Commands
#define FCP_DATA_SND 0
#define FCP_ACK 1
#define FCP_CONNECT 2
#define FCP_CON_ACK 3
#define FCP_DATA_REQ 4
#define FCP_DATA_ACK 5
 
class FCPProtocol
{
private:
int snd_cur;
int last_ack;
RawEthernet *enet;
byte ip[4];
void wrapFCPUDPIP(byte *buffer, byte *data);
static const byte packet_con[];
static const byte ip_header[];
static const byte udp_header[];
byte buffer[1500];
byte sendbuf[1500];
void insertIPChecksum();
bool receiveFcpUdpIp(int len, byte *data);
public:
FCPProtocol ();
~FCPProtocol ();
bool connect(byte mac[], byte ip[]);
void disconnect(void);
bool sendData(int channel, byte data[], int len);
bool requestData(int channel, int len, byte *data);
bool connected();
void wrapFcpUdpIp(byte command, int channel, byte *data, int len);
};
 
#endif
/trunk/cpp/fcptest.cpp
0,0 → 1,54
// fcptest.cpp
 
#include "fcpprotocol.hpp"
 
#include <iostream>
#include <time.h>
#include <sys/time.h>
 
using namespace std;
 
int main(char ** argv, int argc)
{
 
FCPProtocol *fcp = new FCPProtocol();
bool r = fcp->connect((byte[]){0x01, 0x23, 0x45, 0x67, 0x89, 0xab},
(byte[]){192, 168, 1, 222});
cout << "Connected: " << r << endl;
struct timeval start, stop;
gettimeofday(&start, 0);
r = fcp->sendData(1, (byte[]){0x11}, 1);
gettimeofday(&stop, 0);
cout << "Latency Time: " << (long)(stop.tv_usec - start.tv_usec) << " us" << endl;
cout << "Data Sent: " << r << endl;
//byte data[] = {0, 0};
//r = fcp->requestData(1, 1, data);
//cout << "Data Received: " << r << endl;
//cout << "Value: " << (int)data[0] << endl;
cout << "Performing Speed Test..." << endl;
byte senddata[1024];
for (int j=0; j<1024; j++)
{
senddata[j] = (byte)(j/4);
}
gettimeofday(&start, 0);
for (int i=0; i<4096; i++)
{
senddata[1023] = i;
r = fcp->sendData(1,senddata, 1024);
if (!r) cout << "Send Error!" << endl;
}
gettimeofday(&stop, 0);
cout << "Throughput Time: " << (long)(stop.tv_usec - start.tv_usec) << " us" << endl;
 
cout << "Throughput: " << 32000000.0 / (long)(stop.tv_usec - start.tv_usec) << "Mb/s" << endl;
delete fcp;
}
/trunk/cpp/rawethernet.cpp
0,0 → 1,110
// rawethernet.cpp
 
#include "rawethernet.hpp"
 
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <arpa/inet.h>
 
#include <iostream>
#include <cstring>
 
using namespace std;
 
RawEthernet::RawEthernet()
{
this->protocol = 0x0800;
}
 
RawEthernet::~RawEthernet()
{
}
 
bool RawEthernet::connect(byte addr[])
{
struct sockaddr_ll socket_address;
socket_address.sll_family = AF_PACKET;
socket_address.sll_protocol = 0;//htons(ETH_P_IP); //0
socket_address.sll_ifindex = if_nametoindex("eth0");
socket_address.sll_hatype = 0;//ARPHRD_ETHER; //0
socket_address.sll_pkttype = 0;//PACKET_OTHERHOST; //0
socket_address.sll_halen = ETH_ALEN;
 
/*MAC - begin*/
socket_address.sll_addr[0] = addr[0];
socket_address.sll_addr[1] = addr[1];
socket_address.sll_addr[2] = addr[2];
socket_address.sll_addr[3] = addr[3];
socket_address.sll_addr[4] = addr[4];
socket_address.sll_addr[5] = addr[5];
/*MAC - end*/
socket_address.sll_addr[6] = 0x00;/*not used*/
socket_address.sll_addr[7] = 0x00;/*not used*/
return this->connect(&socket_address);
}
 
bool RawEthernet::connect(struct sockaddr_ll *socket_address)
{
this->socketid = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (this->socketid < 0)
{
cout << "Socket Error!" << endl;
perror("socket");
return false;
}
memcpy((void*)&(this->socket_address), socket_address, sizeof(struct sockaddr_ll));
if (bind(this->socketid, (struct sockaddr*)socket_address, sizeof(struct sockaddr_ll))<0)
{
cout << "Binding Error!" << endl;
perror("bind");
return false;
}
return true;
}
 
void RawEthernet::disconnect()
{
}
 
bool RawEthernet::sendData(byte data[], int len)
{
memcpy((void*)this->buffer, (void*)(this->socket_address.sll_addr), ETH_ALEN);
memcpy((void*)(this->buffer+ETH_ALEN), (void*)(this->src_mac), ETH_ALEN);
*((short*)&(this->buffer[ETH_ALEN+ETH_ALEN])) = htons(this->protocol);
memcpy((void*)(this->buffer+ETH_HLEN), (void*)data, len);
if (len < ETH_DATA_LEN)
{
memset((void*)(this->buffer+ETH_HLEN+len), 0, ETH_DATA_LEN-len);
}
int send_result = sendto(this->socketid, this->buffer, ETH_FRAME_LEN, 0,
(struct sockaddr*)&(this->socket_address), sizeof(struct sockaddr_ll));
if (send_result == -1)
{
cout << "Send Errer!" << endl;
perror("sendto");
return false;
}
return true;
}
 
bool RawEthernet::requestData(int len, byte *data)
{
int length = recvfrom(this->socketid, this->buffer, ETH_FRAME_LEN, 0, NULL, NULL);
if (length == -1)
{
cout << "Receive Error!" << endl;
perror("recvfrom");
return false;
}
if (ntohs(*((short*)(&this->buffer[12]))) != this->protocol) return false;
memcpy((void*)data, (void*)(this->buffer+14), len);
return true;
}
 
const byte RawEthernet::src_mac[] = {0x0, 0x1b, 0x21, 0x82, 0xaf, 0xad};// len=8
/trunk/cpp/fcpprotocol.cpp
0,0 → 1,136
// fcpprotocol.cpp
 
#include "fcpprotocol.hpp"
#include "rawethernet.hpp"
 
#include <iostream>
#include <cstring>
#include <arpa/inet.h>
 
using namespace std;
 
FCPProtocol::FCPProtocol()
{
this->snd_cur = 0;
this->last_ack = 0;
this->enet = new RawEthernet();
}
 
FCPProtocol::~FCPProtocol()
{
delete this->enet;
}
 
bool FCPProtocol::connect(byte mac[], byte ip[])
{
if (!this->enet->connect(mac)) return false;
memcpy((void*)this->ip, (void*)ip, 4);
// send connection request
memcpy((void*)this->buffer, (void*)this->packet_con, 34);
memcpy((void*)(this->buffer+16), (void*)ip, 4);
if (!this->enet->sendData(this->buffer, 34)) return false;
// receive conack
if (!this->receiveFcpUdpIp(1500, this->buffer)) return false;
if (this->buffer[28] != (byte)0x1) return false;
memcpy((void*)(this->sendbuf+16), (void*)this->ip, 4);
this->snd_cur = 1;
this->last_ack = 0;
return true;
}
 
void FCPProtocol::disconnect()
{
this->enet->disconnect();
this->snd_cur = 0;
this->last_ack = 0;
}
 
bool FCPProtocol::sendData(int channel, byte data[], int len)
{
// wrap in packet
this->wrapFcpUdpIp(FCP_DATA_SND, channel, data, len);
// send packet
if (!this->enet->sendData(this->buffer, len+34)) return false;
// receive ack
if (!this->receiveFcpUdpIp(1500, this->buffer)) return false;
int seq = (int) ntohs(*((short*)&this->buffer[30]));
if ((seq != this->snd_cur) || (this->buffer[28] != 1)) return false;
this->last_ack = seq;
this->snd_cur = seq+1;
//this->snd_cur++;
return true;
}
 
bool FCPProtocol::requestData(int channel, int len, byte *data)
{
// send data request
wrapFcpUdpIp(FCP_DATA_REQ, channel, NULL, len);
if (!this->enet->sendData(this->buffer, 34)) return false;
// receive data response
if (!this->receiveFcpUdpIp(1500, this->buffer)) return false;
int seq = (int) ntohs(*((short*)&this->buffer[30]));
if ((seq != this->snd_cur) || (this->buffer[28] != 5)) return false;
this->last_ack = seq;
this->snd_cur = seq+1;
memcpy((void*)data, (void*)(&this->buffer[34]), len);
return true;
}
 
bool FCPProtocol::connected()
{
return (this->snd_cur > 0);
}
 
void FCPProtocol::wrapFcpUdpIp(byte command, int channel, byte *data, int len)
{
memcpy((void*)(this->buffer), (void*)this->ip_header, 20);
memcpy((void*)(this->buffer+16), (void*)ip, 4);
*((short*)&buffer[2]) = htons(34+len);
//*** insert IP header checksum
memcpy((void*)(this->buffer+20), (void*)this->udp_header, 8);
*((short*)&buffer[24]) = htons(len+14);
buffer[26] = 0;
buffer[27] = 0;
buffer[28] = command;
buffer[29] = (byte)channel;
*((short*)&(this->buffer[30])) = htons(this->snd_cur);
*((short*)&(this->buffer[32])) = htons(len);
if (len > 0 && data != NULL)
memcpy((void*)(this->buffer+34), (void*)data, len);
this->insertIPChecksum();
}
 
void FCPProtocol::insertIPChecksum()
{
int sum = 0;
short* buf = (short*)this->buffer;
for (int i=0; i<20; i++)
{
sum += (int) ntohs(buf[i]);
if (sum > 0xffff)
{
sum = (sum & 0xffff) + 1;
}
}
buf[5] = ~htons((short)sum&0xffff);
}
 
bool FCPProtocol::receiveFcpUdpIp(int len, byte *data)
{
for (int i=0; i<20; i++)
{
if (!this->enet->requestData(len, data)) return false;
if (data[9] != 0x11) continue;
if (ntohs(*((short*)(data+20))) != 0x3001) continue;
if (ntohs(*((short*)(data+22))) != 0x3000) continue;
return true;
}
return false;
}
 
const byte FCPProtocol::packet_con[] = {//0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x45, 0, 0, 34/*len*/, 0, 0, 0, 0, 0x80, 0x11, 0, 0, 0xc0, 0xa8, 1, 0x66, 0, 0, 0, 0,
0x30, 0, 0x30, 1, 0, 0x0e, 0, 0,
0x02, 0, 0, 0, 0, 0};// len=34
const byte FCPProtocol::ip_header[] = {0x45, 0, 0, 34, 0, 0, 0, 0, 0x80, 0x11, 0, 0, 0xc0, 0xa8, 1, 0x66, 0, 0, 0, 0};// len=20
const byte FCPProtocol::udp_header[] = {0x30, 0, 0x30, 1, 0, 0x06, 0, 0};// len=8
/trunk/cpp/rawethernet.hpp
0,0 → 1,31
// rawethernet.hpp
 
#ifndef RAWETHERNET_HPP
#define RAWETHERNET_HPP
 
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
 
typedef unsigned char byte;
 
class RawEthernet
{
private:
byte buffer[1514];
static const byte src_mac[];
int socketid;
struct sockaddr_ll socket_address;
public:
RawEthernet ();
~RawEthernet ();
bool connect(byte addr[]);
bool connect(struct sockaddr_ll *socket_address);
void disconnect(void);
bool sendData(byte data[], int len);
bool requestData(int len, byte *data);
short protocol;
};
 
#endif
/trunk/hdl/topv5_echo.v
0,0 → 1,298
// Top Module
 
module top
(
// SGMII Interface - EMAC0
TXP_0,
TXN_0,
RXP_0,
RXN_0,
 
// SGMII MGT Clock buffer inputs
MGTCLK_N,
MGTCLK_P,
 
// reset for ethernet phy
PHY_RESET_0,
 
// GTP link status
GTP_READY,
 
// Asynchronous Reset
RESET,
 
// LED Status
LEDS,
// DIP Switch
DIP,
// CPU RESET
RESET_CPU
);
 
//-----------------------------------------------------------------------------
// Port Declarations
//-----------------------------------------------------------------------------
 
// SGMII Interface - EMAC0
output TXP_0;
output TXN_0;
input RXP_0;
input RXN_0;
// SGMII MGT Clock buffer inputs
input MGTCLK_N;
input MGTCLK_P;
 
// reset for ethernet phy
output PHY_RESET_0;
 
// GTP link status
output GTP_READY;
 
// Asynchronous Reset
input RESET;
 
// LED Status
output [7:0] LEDS;
// DIP Switches
input [7:0] DIP;
// CPU RESET
input RESET_CPU;
//-----------------------------------------------------------------------------
 
 
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
// User Signals
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
reg [7:0] DIP_r;
wire reset_cpu_p;
wire reset_cpu_i;
reg [7:0] LEDr;
 
IBUF cpu_reset_ibuf (.I(RESET_CPU), .O(reset_cpu_i));
assign reset_cpu_p = ~reset_cpu_i;
 
 
//-----------------------------------------------------------------------------
// Ethernet Platform Instance
//-----------------------------------------------------------------------------
 
wire in_src_rdy_usr;
wire out_dst_rdy_usr;
wire [7:0] in_data_usr;
wire in_sof_usr;
wire in_eof_usr;
wire in_dst_rdy_usr;
wire out_src_rdy_usr;
wire [7:0] out_data_usr;
wire out_sof_usr;
wire out_eof_usr;
wire [3:0] outport_usr;
wire [3:0] inport_usr;
wire clk_local;
wire rst_local;
 
 
enetplatform enet_inst
(
.TXP_0(TXP_0),
.TXN_0(TXN_0),
.RXP_0(RXP_0),
.RXN_0(RXN_0),
.MGTCLK_N(MGTCLK_N),
.MGTCLK_P(MGTCLK_P),
.PHY_RESET_0(PHY_RESET_0),
.GTP_READY(GTP_READY),
.RESET(RESET),
.RESET_CPU(reset_cpu_p),
.in_src_rdy_usr(in_src_rdy_usr),
.out_dst_rdy_usr(out_dst_rdy_usr),
.in_data_usr(in_data_usr),
.in_sof_usr(in_sof_usr),
.in_eof_usr(in_eof_usr),
.in_dst_rdy_usr(in_dst_rdy_usr),
.out_src_rdy_usr(out_src_rdy_usr),
.out_data_usr(out_data_usr),
.out_sof_usr(out_sof_usr),
.out_eof_usr(out_eof_usr),
.outport_usr(outport_usr),
.inport_usr(inport_usr),
.clk_local(clk_local),
.rst_local(rst_local)
);
 
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
 
 
 
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
// Channel Routing
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
wire ch1_in_sof;
wire ch1_in_eof;
wire ch1_in_src_rdy;
wire ch1_in_dst_rdy;
wire [7:0] ch1_in_data;
wire ch1_out_sof;
wire ch1_out_eof;
wire ch1_out_src_rdy;
wire ch1_out_dst_rdy;
wire [7:0] ch1_out_data;
wire ch1_wen;
wire ch1_ren;
 
wire ch2_in_sof;
wire ch2_in_eof;
wire ch2_in_src_rdy;
wire ch2_in_dst_rdy;
wire [7:0] ch2_in_data;
wire ch2_out_sof;
wire ch2_out_eof;
wire ch2_out_src_rdy;
wire ch2_out_dst_rdy;
wire [7:0] ch2_out_data;
wire ch2_wen;
wire ch2_ren;
 
channelif2 channelif_inst
(
.in_sof(out_sof_usr),
.in_eof(out_eof_usr),
.in_src_rdy(out_src_rdy_usr),
.in_dst_rdy(out_dst_rdy_usr),
.in_data(out_data_usr),
.inport_addr(outport_usr),
.out_sof(in_sof_usr),
.out_eof(in_eof_usr),
.out_src_rdy(in_src_rdy_usr),
.out_dst_rdy(in_dst_rdy_usr),
.out_data(in_data_usr),
.outport_addr(inport_usr),
.wenables(),
.renables(),
.ch1_in_sof(ch1_in_sof),
.ch1_in_eof(ch1_in_eof),
.ch1_in_src_rdy(ch1_in_src_rdy),
.ch1_in_dst_rdy(ch1_in_dst_rdy),
.ch1_in_data(ch1_in_data),
.ch1_out_sof(ch1_out_sof),
.ch1_out_eof(ch1_out_eof),
.ch1_out_src_rdy(ch1_out_src_rdy),
.ch1_out_dst_rdy(ch1_out_dst_rdy),
.ch1_out_data(ch1_out_data),
.ch1_wen(ch1_wen),
.ch1_ren(ch1_ren),
.ch2_in_sof(ch2_in_sof),
.ch2_in_eof(ch2_in_eof),
.ch2_in_src_rdy(ch2_in_src_rdy),
.ch2_in_dst_rdy(ch2_in_dst_rdy),
.ch2_in_data(ch2_in_data),
.ch2_out_sof(ch2_out_sof),
.ch2_out_eof(ch2_out_eof),
.ch2_out_src_rdy(ch2_out_src_rdy),
.ch2_out_dst_rdy(ch2_out_dst_rdy),
.ch2_out_data(ch2_out_data),
.ch2_wen(ch2_wen),
.ch2_ren(ch2_ren)
);
 
 
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
// User Logic
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
wire ch2_out_dst_rdy_l;
reg [19:0] counter;
wire [19:0] new_counter;
 
always @(posedge clk_local or posedge rst_local)
begin
if (rst_local)
begin
counter <= 0;
end
else if (ch2_out_sof)
begin
counter <= 20'hfffff;
end
else if (counter > 0)
begin
counter <= new_counter;
end
end
 
assign new_counter = counter - 1;
 
assign ch2_out_dst_rdy = (counter > 0) & (counter < 1048500) & ch2_out_dst_rdy_l;
 
port_fifo pf_channel_2 (
.rst(rst_local),
.in_clk(clk_local),
.out_clk(clk_local),
.in_data ( ch2_out_data ), // Inport
.in_sof ( ch2_out_sof ), // Inport
.in_eof ( ch2_out_eof ), // Inport
.in_src_rdy ( ch2_out_src_rdy ), // Inport
.in_dst_rdy ( ch2_out_dst_rdy_l ), // Inport
 
// Outputs:
.out_data ( ch2_in_data ), // Outport
.out_sof ( ch2_in_sof ), // Outport
.out_eof ( ch2_in_eof ), // Outport
.out_src_rdy ( ch2_in_src_rdy ), // Outport
.out_dst_rdy ( ch2_in_dst_rdy ) // Outport
);
 
wire [7:0] LEDnext;
 
assign LEDS = LEDr;
always @(posedge clk_local)
begin
DIP_r <= DIP;
end
 
always @(posedge clk_local)
begin
if (rst_local)
LEDr <= 0;
else if (ch1_wen & ch1_out_src_rdy)
LEDr <= LEDnext;
end
 
 
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
// Channel Assignments
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
assign ch1_in_sof = 1;
assign ch1_in_eof = 1;
assign ch1_in_src_rdy = 1;
assign ch1_out_dst_rdy = 1;
assign ch1_in_data = DIP_r;
assign LEDnext = ch1_out_data;
 
 
 
 
endmodule
/trunk/hdl/topv5_prototest.v
246,6 → 246,19
wire ch5_wen;
wire ch5_ren;
 
wire ch5_in_sof_l;
wire ch5_in_eof_l;
wire ch5_in_src_rdy_l;
wire ch5_in_dst_rdy_l;
wire [7:0] ch5_in_data_l;
wire ch5_out_sof_l;
wire ch5_out_eof_l;
wire ch5_out_src_rdy_l;
wire ch5_out_dst_rdy_l;
wire [7:0] ch5_out_data_l;
wire ch5_wen_l;
wire ch5_ren_l;
 
wire ch6_in_sof;
wire ch6_in_eof;
wire ch6_in_src_rdy;
408,9 → 421,9
//-------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------
 
port_sha1 pr_channel_5 (
port_md5 md5_channel_5 (
.clk(clk_controlled),
.rst(rst_local),
.rst(usr_rst),
.wen ( 1 ),
.ren ( 1 ),
.in_data ( ch5_out_data_l ), // Inport
464,7 → 477,7
);
 
 
port_sha1 pr_channel_6 (
port_sha1 sha1_channel_6 (
.clk(clk_local),
.rst(rst_local),
.wen ( ch6_wen ),

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.