mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
mibuild/sim: able to send ethernet frame from sim to server.py
This commit is contained in:
parent
0029b87628
commit
a64acdfa65
2 changed files with 38 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#include <netdb.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#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();
|
||||
|
|
Loading…
Reference in a new issue