/* This module loads the fifo -------------------------- This module reads a file with recirculation data into the fifo. It waits for the Go signal before it does anything. It loads the fifo with characters from the file Input_file. If EOF is reached it closes the file. */ #module Fifo_Loader (Din0,Din1,Din2,Din3,Din4,Din5,Din6,Din7,Din8 ,Wrbar,FFbar,Go,Phi1H,Phi2H) #memory int eofflag; int s; FILE *fd_in,*fd_out; #memory end #function (FFbar,Go,Phi1H,Phi2H) int i; /* sample the Go and FFbar signals */ if ( (VAL(Phi1H) == HIGH) ){ NEW_VAL(Wrbar, 0,HIGH); /* this is not an exact simulation */ } /* read and write the data into fifo */ if ( (VAL(Go) == HIGH) && (VAL(Phi2H) == HIGH) && (VAL(FFbar) == HIGH) && (eofflag == 0) ){ if ( (s = fgetc(fd_in)) != EOF ){ fprintf(fd_out," input is %c\n", s) ; if ( s & 1 ) NEW_VAL(Din0, 1, HIGH); else NEW_VAL(Din0, 1,LOW); if ( s & (1 << 1)) NEW_VAL(Din1, 1, HIGH); else NEW_VAL(Din1, 1,LOW); if ( s & (1 << 2)) NEW_VAL(Din2, 1, HIGH); else NEW_VAL(Din2, 1,LOW); if ( s & (1 << 3)) NEW_VAL(Din3, 1, HIGH); else NEW_VAL(Din3, 1,LOW); if ( s & (1 << 4)) NEW_VAL(Din4, 1, HIGH); else NEW_VAL(Din4, 1,LOW); if ( s & (1 << 5)) NEW_VAL(Din5, 1, HIGH); else NEW_VAL(Din5, 1,LOW); if ( s & (1 << 6)) NEW_VAL(Din6, 1, HIGH); else NEW_VAL(Din6, 1,LOW); if ( s & (1 << 7)) NEW_VAL(Din7, 1, HIGH); else NEW_VAL(Din7, 1,LOW); } NEW_VAL(Din8, 1, LOW); NEW_VAL(Wrbar, 1,LOW); /* write into fifo */ } else{ lprintf(stdout,"\n EOF INPUT FILE \n"); fprintf(fd_out,"\n EOF INPUT FILE \n"); fclose(fd_in); fclose(fd_out); eofflag = 1; } /* else do nothing */ #function end #init begin int i,j; /* always keep the write signal high */ NEW_VAL(Wrbar,0,HIGH); eofflag = 0; /* did we reach EOF yet? */ if ( (fd_in = fopen("Input_file","r")) == NULL){ lprintf(stdout,"Could not open Input_file %s\n",instance->name); } if ( (fd_out = fopen("FIFO.log","w")) == NULL){ lprintf(stdout,"Could not open FIFO.log %s\n",instance->name); } #init end #module end