From a64acdfa6542e29b000aaa51091a4b46fba46dff Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Fri, 6 Mar 2015 12:49:56 +0100 Subject: [PATCH] mibuild/sim: able to send ethernet frame from sim to server.py --- mibuild/sim/server.py | 9 +++++++-- mibuild/sim/server_tb.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/mibuild/sim/server.py b/mibuild/sim/server.py index d21cdc21..ea8bb03c 100644 --- a/mibuild/sim/server.py +++ b/mibuild/sim/server.py @@ -11,7 +11,8 @@ messages= { "EXIT": 0, "ACK": 1, "ERROR": 2, - "UART": 3 + "UART": 3, + "ETHERNET": 4 } class PacketTooLarge(Exception): @@ -80,7 +81,11 @@ def read(): if packet[0] == messages["UART"]: c = bytes(chr(packet[1]).encode('utf-8')) os.write(server.serial, c) - + elif packet[0] == messages["ETHERNET"]: + print("received ethernet") + for d in packet[1:]: + print("{:02X}".format(d), end="") + print("") elif packet[0] == messages["ACK"]: server.ack = True diff --git a/mibuild/sim/server_tb.cpp b/mibuild/sim/server_tb.cpp index f93e2962..5203a7aa 100644 --- a/mibuild/sim/server_tb.cpp +++ b/mibuild/sim/server_tb.cpp @@ -19,6 +19,9 @@ #include #include +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define MIN(a,b) (((a)<(b))?(a):(b)) + int trace = 0; vluint64_t main_time = 0; @@ -38,7 +41,8 @@ enum { MESSAGE_EXIT = 0, MESSAGE_ACK, MESSAGE_ERROR, - MESSAGE_UART + MESSAGE_UART, + MESSAGE_ETH }; struct sim { @@ -58,6 +62,12 @@ struct sim { char rx_serial_presented; }; +unsigned char eth_txbuffer[1532]; +unsigned char eth_rxbuffer[1532]; +int eth_txbuffer_len = 0; +int eth_rxbuffer_len = 0; +int eth_rxbuffer_pos = 0; + int sim_connect(struct sim *s, const char *sockaddr) { struct sockaddr_un addr; @@ -143,6 +153,25 @@ int console_service(struct sim *s) return 0; } +int eth_last_source_stb = 0; + +int ethernet_service(struct sim *s) { + /* fpga --> ethernet tap */ + ETH_SOURCE_ACK = 1; + if(ETH_SOURCE_STB == 1) { + eth_txbuffer[eth_txbuffer_len] = ETH_SOURCE_DATA; + eth_txbuffer_len++; + } else { + if (eth_last_source_stb) { + s->txbuffer[0] = MESSAGE_ETH; + memcpy(s->txbuffer+1, eth_txbuffer, eth_txbuffer_len); + sim_send(s, s->txbuffer, eth_txbuffer_len+1); + eth_txbuffer_len = 0; + } + } + eth_last_source_stb = ETH_SOURCE_STB; +} + void sim_tick(struct sim *s) { SYS_CLK = s->tick%2; @@ -190,6 +219,7 @@ int main(int argc, char **argv, char **env) if (SYS_CLK) { if (console_service(&s) != 0) s.run = false; + ethernet_service(&s); } } s.end = clock(); -- 2.30.2