| Line | |
|---|
| 1 | #include <systemc> |
|---|
| 2 | #include <signal.h> |
|---|
| 3 | #include <sys/time.h> |
|---|
| 4 | #include <cstdlib> |
|---|
| 5 | #include <cstdarg> |
|---|
| 6 | |
|---|
| 7 | #include "topcell_.h" |
|---|
| 8 | |
|---|
| 9 | bool stop; |
|---|
| 10 | void run(sc_core::sc_signal<bool> &resetn) |
|---|
| 11 | { |
|---|
| 12 | #ifdef SYSTEMCASS |
|---|
| 13 | sc_core::sc_start(0); |
|---|
| 14 | resetn = false; |
|---|
| 15 | sc_core::sc_start(1); |
|---|
| 16 | resetn = true; |
|---|
| 17 | #else |
|---|
| 18 | sc_core::sc_start(sc_core::sc_time(0, sc_core::SC_NS)); |
|---|
| 19 | resetn = false; |
|---|
| 20 | sc_core::sc_start(sc_core::sc_time(1, sc_core::SC_NS)); |
|---|
| 21 | resetn = true; |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | #ifdef SOCVIEW |
|---|
| 25 | debug(); |
|---|
| 26 | #else |
|---|
| 27 | const char *t = getenv("STATS_EVERY"); |
|---|
| 28 | if ( t ) { |
|---|
| 29 | int delta = atoi(t); |
|---|
| 30 | while (!stop) { |
|---|
| 31 | struct timezone tz; |
|---|
| 32 | struct timeval end, begin, tp; |
|---|
| 33 | gettimeofday( &begin, &tz ); |
|---|
| 34 | #ifdef SYSTEMCASS |
|---|
| 35 | sc_core::sc_start(delta); |
|---|
| 36 | #else |
|---|
| 37 | sc_core::sc_start(sc_core::sc_time(delta, sc_core::SC_NS)); |
|---|
| 38 | #endif |
|---|
| 39 | gettimeofday( &end, &tz ); |
|---|
| 40 | timersub( &end, &begin, &tp ); |
|---|
| 41 | long ms = (tp.tv_sec*1000+tp.tv_usec/1000); |
|---|
| 42 | std::cout << std::dec << delta << " cycles in " << ms << " ms: " << ((double)delta*1000/ms) << " Hz" << std::endl; |
|---|
| 43 | } |
|---|
| 44 | } else { |
|---|
| 45 | sc_core::sc_start(); |
|---|
| 46 | } |
|---|
| 47 | #endif |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | int _main(int argc, char **argv) |
|---|
| 51 | { |
|---|
| 52 | sc_core::sc_signal<bool> resetn; |
|---|
| 53 | sc_core::sc_clock clock; |
|---|
| 54 | |
|---|
| 55 | topcell_ top0("top0"); |
|---|
| 56 | |
|---|
| 57 | top0.p_resetn(resetn); |
|---|
| 58 | top0.p_clock(clock); |
|---|
| 59 | |
|---|
| 60 | run(resetn); |
|---|
| 61 | |
|---|
| 62 | return 0; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | void quit(int) |
|---|
| 66 | { |
|---|
| 67 | sc_core::sc_stop(); |
|---|
| 68 | stop = true; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | int sc_main (int argc, char *argv[]) |
|---|
| 72 | { |
|---|
| 73 | signal(SIGINT, quit); |
|---|
| 74 | atexit(sc_core::sc_stop); |
|---|
| 75 | stop = false; |
|---|
| 76 | |
|---|
| 77 | try { |
|---|
| 78 | return _main(argc, argv); |
|---|
| 79 | } catch (std::exception &e) { |
|---|
| 80 | std::cout << e.what() << std::endl; |
|---|
| 81 | } catch (...) { |
|---|
| 82 | std::cout << "Unknown exception occured" << std::endl; |
|---|
| 83 | throw; |
|---|
| 84 | } |
|---|
| 85 | return 1; |
|---|
| 86 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.