mibuild/sim: clean up (thanks sb)

This commit is contained in:
Florent Kermarrec 2015-03-10 16:41:52 +01:00
parent 555c444da2
commit 00e8616de2
2 changed files with 22 additions and 26 deletions

View File

@ -47,11 +47,7 @@ struct sim {
clock_t end; clock_t end;
float speed; float speed;
#ifndef WITH_SERIAL_PTY #ifdef WITH_SERIAL_PTY
char rx_serial_stb;
char rx_serial_data;
char rx_serial_presented;
#else
char serial_dev[64]; char serial_dev[64];
int serial_fd; int serial_fd;
unsigned char serial_rx_data; unsigned char serial_rx_data;
@ -106,7 +102,7 @@ int getch(void)
{ {
int r; int r;
unsigned char c; unsigned char c;
if ((r = read(0, &c, sizeof(c))) < 0) { if((r = read(0, &c, sizeof(c))) < 0) {
return r; return r;
} else { } else {
return c; return c;
@ -138,16 +134,16 @@ void eth_open(struct sim *s)
struct ifreq ifr; struct ifreq ifr;
s->eth_fd = open (s->eth_dev, O_RDWR); s->eth_fd = open (s->eth_dev, O_RDWR);
if(s->eth_fd < 0) { if(s->eth_fd < 0) {
fprintf (stderr, " Could not open dev %s\n", s->eth_dev); fprintf(stderr, " Could not open dev %s\n", s->eth_dev);
return; return;
} }
memset (&ifr, 0, sizeof(ifr)); memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI; ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy (ifr.ifr_name, s->eth_tap, IFNAMSIZ); strncpy(ifr.ifr_name, s->eth_tap, IFNAMSIZ);
if (ioctl (s->eth_fd, TUNSETIFF, (void *) &ifr) < 0) { if(ioctl(s->eth_fd, TUNSETIFF, (void *) &ifr) < 0) {
fprintf (stderr, " Could not set %s\n", s->eth_tap); fprintf(stderr, " Could not set %s\n", s->eth_tap);
close(s->eth_fd); close(s->eth_fd);
} }
return; return;
@ -155,7 +151,7 @@ void eth_open(struct sim *s)
int eth_close(struct sim *s) int eth_close(struct sim *s)
{ {
if (s->eth_fd < 0) if(s->eth_fd < 0)
close(s->eth_fd); close(s->eth_fd);
} }
@ -175,7 +171,7 @@ int eth_read(struct sim *s, unsigned char *buf)
fds[0].events = POLLIN; fds[0].events = POLLIN;
n = poll(fds, 1, 0); n = poll(fds, 1, 0);
if ((n > 0) && ((fds[0].revents & POLLIN) == POLLIN)) { if((n > 0) && ((fds[0].revents & POLLIN) == POLLIN)) {
len = read(s->eth_fd, buf, 1532); len = read(s->eth_fd, buf, 1532);
} else { } else {
len = 0; len = 0;
@ -193,7 +189,7 @@ int console_service(struct sim *s)
/* fpga --> console */ /* fpga --> console */
SERIAL_SOURCE_ACK = 1; SERIAL_SOURCE_ACK = 1;
if(SERIAL_SOURCE_STB == 1) { if(SERIAL_SOURCE_STB == 1) {
if (SERIAL_SOURCE_DATA == '\n') if(SERIAL_SOURCE_DATA == '\n')
putchar('\r'); putchar('\r');
putchar(SERIAL_SOURCE_DATA); putchar(SERIAL_SOURCE_DATA);
fflush(stdout); fflush(stdout);
@ -201,10 +197,10 @@ int console_service(struct sim *s)
/* console --> fpga */ /* console --> fpga */
SERIAL_SINK_STB = 0; SERIAL_SINK_STB = 0;
if (s->tick%(1000) == 0) { if(s->tick%(1000) == 0) {
if(kbhit()) { if(kbhit()) {
char c = getch(); char c = getch();
if (c == 27 && !kbhit()) { if(c == 27 && !kbhit()) {
printf("\r\n"); printf("\r\n");
return -1; return -1;
} else { } else {
@ -237,7 +233,7 @@ void console_open(struct sim *s)
int console_close(struct sim *s) int console_close(struct sim *s)
{ {
if (s->serial_fd < 0) if(s->serial_fd < 0)
close(s->serial_fd); close(s->serial_fd);
} }
@ -256,7 +252,7 @@ int console_read(struct sim *s, unsigned char *buf)
fds[0].events = POLLIN; fds[0].events = POLLIN;
n = poll(fds, 1, 0); n = poll(fds, 1, 0);
if ((n > 0) && ((fds[0].revents & POLLIN) == POLLIN)) { if((n > 0) && ((fds[0].revents & POLLIN) == POLLIN)) {
len = read(s->serial_fd, buf, 1); len = read(s->serial_fd, buf, 1);
} else { } else {
len = 0; len = 0;
@ -275,7 +271,7 @@ int console_service(struct sim *s)
/* console --> fpga */ /* console --> fpga */
SERIAL_SINK_STB = 0; SERIAL_SINK_STB = 0;
if (console_read(s, &(s->serial_rx_data))) if(console_read(s, &(s->serial_rx_data)))
{ {
SERIAL_SINK_STB = 1; SERIAL_SINK_STB = 1;
SERIAL_SINK_DATA = s->serial_rx_data; SERIAL_SINK_DATA = s->serial_rx_data;
@ -292,7 +288,7 @@ int ethernet_service(struct sim *s) {
s->eth_txbuffer[s->eth_txbuffer_len] = ETH_SOURCE_DATA; s->eth_txbuffer[s->eth_txbuffer_len] = ETH_SOURCE_DATA;
s->eth_txbuffer_len++; s->eth_txbuffer_len++;
} else { } else {
if (s->eth_last_source_stb) { if(s->eth_last_source_stb) {
eth_write(s, s->eth_txbuffer, s->eth_txbuffer_len); eth_write(s, s->eth_txbuffer, s->eth_txbuffer_len);
s->eth_txbuffer_len = 0; s->eth_txbuffer_len = 0;
} }
@ -300,12 +296,12 @@ int ethernet_service(struct sim *s) {
s->eth_last_source_stb = ETH_SOURCE_STB; s->eth_last_source_stb = ETH_SOURCE_STB;
/* tap --> fpga */ /* tap --> fpga */
if (s->eth_rxbuffer_len == 0) { if(s->eth_rxbuffer_len == 0) {
ETH_SINK_STB = 0; ETH_SINK_STB = 0;
s->eth_rxbuffer_pos = 0; s->eth_rxbuffer_pos = 0;
s->eth_rxbuffer_len = eth_read(s, s->eth_rxbuffer); s->eth_rxbuffer_len = eth_read(s, s->eth_rxbuffer);
} else { } else {
if (s->eth_rxbuffer_pos < MAX(s->eth_rxbuffer_len, 60)) { if(s->eth_rxbuffer_pos < MAX(s->eth_rxbuffer_len, 60)) {
ETH_SINK_STB = 1; ETH_SINK_STB = 1;
ETH_SINK_DATA = s->eth_rxbuffer[s->eth_rxbuffer_pos]; ETH_SINK_DATA = s->eth_rxbuffer[s->eth_rxbuffer_pos];
s->eth_rxbuffer_pos++; s->eth_rxbuffer_pos++;
@ -322,7 +318,7 @@ void sim_tick(struct sim *s)
{ {
SYS_CLK = s->tick%2; SYS_CLK = s->tick%2;
dut->eval(); dut->eval();
if (trace) if(trace)
tfp->dump(s->tick); tfp->dump(s->tick);
s->tick++; s->tick++;
} }
@ -373,9 +369,9 @@ int main(int argc, char **argv, char **env)
s.run = true; s.run = true;
while(s.run) { while(s.run) {
sim_tick(&s); sim_tick(&s);
if (SYS_CLK) { if(SYS_CLK) {
#ifdef WITH_SERIAL #ifdef WITH_SERIAL
if (console_service(&s) != 0) if(console_service(&s) != 0)
s.run = false; s.run = false;
#endif #endif
#ifdef WITH_ETH #ifdef WITH_ETH

View File

@ -95,7 +95,7 @@ make -j -C obj_dir/ -f Vdut.mk Vdut
build_script_file = "build_" + build_name + ".sh" build_script_file = "build_" + build_name + ".sh"
tools.write_to_file(build_script_file, build_script_contents, force_unix=True) tools.write_to_file(build_script_file, build_script_contents, force_unix=True)
_build_tb(platform, serial, os.path.join("../", sim_path,"dut_tb.cpp")) _build_tb(platform, serial, os.path.join("..", sim_path,"dut_tb.cpp"))
if verbose: if verbose:
r = subprocess.call(["bash", build_script_file]) r = subprocess.call(["bash", build_script_file])
else: else: