#include #include #include static int busstate; static int nextbusstate; static int gnt; static unsigned long long clk; #define N 5 static struct master { int req; int fifofill; int trigger; int latval; int latcnt; int phase; unsigned long long step; /* fixed point 32 bit mantissa */ unsigned long long accu; } masters[N]; static void simulate(int i) { masters[i].fifofill+=masters[i].accu>>32; masters[i].accu&=0xffffffff; if(masters[i].fifofill>140) { fprintf(stderr,"%llu [%i dropped %i]\n",clk,i,masters[i].fifofill-140); masters[i].fifofill=140; } if(busstate==0 && gnt==i && masters[i].fifofill>=masters[i].trigger) { nextbusstate=1; masters[i].phase=1; } if(busstate==1) { switch(masters[i].phase) { case 1: masters[i].phase=2; masters[i].latval=masters[i].latcnt; fprintf(stderr,"%llu %i addr\n",clk,i); break; case 2: masters[i].fifofill--; fprintf(stderr,"%llu %i data, %i remaining\n",clk,i,masters[i].fifofill); } if(masters[i].latval>0) masters[i].latval--; if(masters[i].phase && (masters[i].fifofill==1 || (!masters[i].latval && gnt!=i))) nextbusstate=2; } if(busstate==2 && masters[i].phase) { masters[i].fifofill--; fprintf(stderr,"%llu %i final data, %i remaining\n",clk,i,masters[i].fifofill); if(gnt==i && masters[i].fifofill>=masters[i].trigger) { nextbusstate=1; masters[i].phase=1; } else { nextbusstate=0; masters[i].phase=0; } } masters[i].req=(masters[i].fifofill>=masters[i].trigger || (masters[i].phase && nextbusstate==1 && masters[i].fifofill>1)); masters[i].accu+=masters[i].step; } int main() { int i; unsigned long long idle; int wasactive; clk=idle=0; busstate=0; gnt=0; wasactive=0; srandom(time(0)); for(i=0;i