Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/migen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 991572f4fe83
Choose a base ref
...
head repository: m-labs/migen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f4b060f6fea1
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 3, 2015

  1. 1
    Copy the full SHA
    5ec26a4 View commit details
  2. Copy the full SHA
    f4b060f View commit details
Showing with 29 additions and 23 deletions.
  1. +28 −22 mibuild/sim/console_tb.cpp
  2. +1 −1 mibuild/sim/server_tb.cpp
50 changes: 28 additions & 22 deletions mibuild/sim/console_tb.cpp
Original file line number Diff line number Diff line change
@@ -69,11 +69,18 @@ double sc_time_stamp()

Vdut* dut;
VerilatedVcdC* tfp;
unsigned int tick;

/* ios */

int console_service()
struct sim {
bool run;

unsigned int tick;
clock_t start;
clock_t end;
};

int console_service(struct sim *s)
{
/* fpga --> console */
SERIAL_SOURCE_ACK = 1;
@@ -86,7 +93,7 @@ int console_service()

/* console --> fpga */
SERIAL_SINK_STB = 0;
if (tick%(1000) == 0) {
if (s->tick%(1000) == 0) {
if(kbhit()) {
char c = getch();
if (c == 27 && !kbhit()) {
@@ -101,33 +108,31 @@ int console_service()
return 0;
}

void sim_tick()
void sim_tick(struct sim *s)
{
SYS_CLK = tick%2;
SYS_CLK = s->tick%2;
dut->eval();
if (trace)
tfp->dump(tick);
tick++;
tfp->dump(s->tick);
s->tick++;
}

void sim_init()
void sim_init(struct sim *s)
{
int i;
tick = 0;
s->tick = 0;
#ifdef SYS_RST
SYS_RST = 1;
SYS_CLK = 0;
for (i=0; i<8; i++)
sim_tick();
sim_tick(s);
SYS_RST = 0;
#endif
s->start = clock();
}

int main(int argc, char **argv, char **env)
{

clock_t start;
clock_t end;
float speed;

set_conio_terminal_mode();
@@ -140,19 +145,20 @@ int main(int argc, char **argv, char **env)
dut->trace(tfp, 99);
tfp->open("dut.vcd");

start = clock();
sim_init();
bool run = true;
while(run) {
sim_tick();
struct sim s;
sim_init(&s);

s.run = true;
while(s.run) {
sim_tick(&s);
if (SYS_CLK) {
if (console_service() != 0)
run = false;
if (console_service(&s) != 0)
s.run = false;
}
}
end = clock();
s.end = clock();

speed = (tick/2)/((end-start)/CLOCKS_PER_SEC);
speed = (s.tick/2)/((s.end-s.start)/CLOCKS_PER_SEC);

printf("average speed: %3.3f MHz\n\r", speed/1000000);

2 changes: 1 addition & 1 deletion mibuild/sim/server_tb.cpp
Original file line number Diff line number Diff line change
@@ -150,7 +150,6 @@ void sim_tick(struct sim *s)
if (trace)
tfp->dump(s->tick);
s->tick++;
s->end = clock();
}

void sim_init(struct sim *s)
@@ -193,6 +192,7 @@ int main(int argc, char **argv, char **env)
s.run = false;
}
}
s.end = clock();

tfp->close();
pthread_cancel(sim_receive_thread);