changeset 68:44cc00df1168 pygar svn.69

[svn r69] runs separate eofs (I think)
author punk
date Wed, 12 May 2010 00:06:05 -0400
parents 0ede0715dbd6
children 5c963ab14143
files modules/bluespec/Pygar/core/AudioCoreSystem.cpp modules/bluespec/Pygar/core/Mixer.bsv modules/bluespec/Pygar/core/Processor.bsv modules/bluespec/Pygar/core/ProcessorSystem.dic modules/bluespec/Pygar/core/audioCore.bsv modules/bluespec/Pygar/core/audioCorePipeline.bsv
diffstat 6 files changed, 227 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/modules/bluespec/Pygar/core/AudioCoreSystem.cpp	Tue May 11 23:23:21 2010 -0400
     1.2 +++ b/modules/bluespec/Pygar/core/AudioCoreSystem.cpp	Wed May 12 00:06:05 2010 -0400
     1.3 @@ -10,10 +10,13 @@
     1.4  
     1.5  using namespace std;
     1.6  
     1.7 +#define NUM_VOICES 2
     1.8 +
     1.9  pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock;
    1.10  pthread_cond_t  CONNECTED_APPLICATION_CLASS::cond;
    1.11  sem_t CONNECTED_APPLICATION_CLASS::throttle;
    1.12  
    1.13 +
    1.14  // constructor
    1.15  CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :
    1.16     
    1.17 @@ -72,6 +75,7 @@
    1.18    UINT16 sample;
    1.19    UINT16 sample1;
    1.20  
    1.21 +  Bool fileFini[NUM_VOICES] = {false, false};
    1.22    //rlm: not sure if normal ints are ok here; using UINT16 because I know it works
    1.23    UINT16 channel0 = 0;
    1.24    UINT16 channel1 = 1;
    1.25 @@ -80,7 +84,7 @@
    1.26    int sleepCount = 0;
    1.27    int result = 0;
    1.28  
    1.29 -  bool coreFin = false; 
    1.30 +  int numcCoreFin = 0; 
    1.31  
    1.32    printf("SendSide Main\n");
    1.33    fflush(stdout); 
    1.34 @@ -108,19 +112,9 @@
    1.35  
    1.36    //rlm: here we read both files. later refactor into a function.
    1.37    // also, this will terminate when the FIRST file reaches its end.
    1.38 -  while( (fread(&sample, 2, 1, inputFile)) || (fread(&sample1, 2 , 1, inputFile1))) 
    1.39 -  { /*
    1.40 -    printf("hi\n");
    1.41 -     if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) 
    1.42 -     {
    1.43 -       sleepCount++;
    1.44 -     }
    1.45 -     else if (!coreFin && result == 1) 
    1.46 -       {
    1.47 -	 printf("\n***SOFT_CORE PASSED***\n");
    1.48 -	 coreFin = true;
    1.49 -       }
    1.50 -    */
    1.51 +  while( !feof(inputFile) || !feof(inputFile1))
    1.52 +  { 
    1.53 +
    1.54       sem_wait(&throttle);
    1.55   
    1.56       if(count%1000 == 0)
    1.57 @@ -128,22 +122,36 @@
    1.58       count++;
    1.59      
    1.60      //rlm: two files.
    1.61 -    // clientStub->SendUnprocessedStream( Data,(UINT32)sample);
    1.62 -     clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample);
    1.63 -     clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);
    1.64 -  } 
    1.65 +
    1.66 +     if (!fileFini[0])
    1.67 +       {
    1.68 +	 if (fread(&sample, 2, 1, inputFile))
    1.69 +	   clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample);
    1.70 +	 else{
    1.71 +	   fileFini[0] = true;
    1.72 +	   numCoreFini++;
    1.73 +	   if (numCoreFini >= NUM_VOICES)  //  Need lock on last eof
    1.74 +	     // Need to put lock here to prevent potential race condition
    1.75 +	     pthread_mutex_lock(&lock);
    1.76 +	   clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);
    1.77 +	 }
    1.78 +       }
    1.79 +     if !fileFini[1])
    1.80 +       {
    1.81 +	 if (fread(&sample1, 2 , 1, inputFile1)) 	       
    1.82 +	   clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);
    1.83 +	 else{
    1.84 +	   fileFini[1] = true;
    1.85 +	   numCoreFini++;
    1.86 +	   if (numCoreFini >= NUM_VOICES)  //  Need lock on last eof
    1.87 +	     // Need to put lock here to prevent potential race condition
    1.88 +	     pthread_mutex_lock(&lock);
    1.89 +	   clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0);
    1.90 +	 }
    1.91 +       } 
    1.92 +  }
    1.93  
    1.94    printf("main: out of loop\n");
    1.95 -
    1.96 -  // Need to put lock here to prevent potential race condition
    1.97 -  pthread_mutex_lock(&lock);
    1.98 -
    1.99 -  //rlm: have to send end-files to both voices.  
   1.100 -  // all of these operations wil eventually be moved into functions.
   1.101 -  //clientStub->SendUnprocessedStream(EndOfFile,0);
   1.102 -  clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);
   1.103 -  clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0);
   1.104 -
   1.105    printf("main: wait for end of file\n");
   1.106  
   1.107    pthread_cond_wait(&cond, &lock);
     2.1 --- a/modules/bluespec/Pygar/core/Mixer.bsv	Tue May 11 23:23:21 2010 -0400
     2.2 +++ b/modules/bluespec/Pygar/core/Mixer.bsv	Wed May 12 00:06:05 2010 -0400
     2.3 @@ -69,14 +69,17 @@
     2.4     
     2.5     rule processSample(!isAudioFini(voiceFini));  //implicit on all voiceFifos having data
     2.6        FixedPoint#(32,32) sum = 0;  //this should allow 16 voices at 16 bits without messing up
     2.7 +      Integer numValid = 0;
     2.8        for (Integer i = 0; i < numVoices; i = i+1)
     2.9  	 begin
    2.10  	    if (voicesIn[i].first() matches tagged Valid .data)
    2.11  	      begin
    2.12  		 case (data) matches
    2.13  		    tagged Sample .sample :
    2.14 -	               sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8); 
    2.15 -	            //shifting right 8 to divide by 256
    2.16 +		       begin //shifting right 8 to divide by 256
    2.17 +			  sum = sum + ((fromInt(sample) * fromInt(scalars[i])) >> 8); 
    2.18 +			  numValid = numValid + 1;
    2.19 +		       end
    2.20  		    tagged EndOfFile :
    2.21  		       voiceFini[i] <= True;
    2.22  		 endcase
    2.23 @@ -84,16 +87,12 @@
    2.24  	    else voiceFini[i] <= True;
    2.25  	    voicesIn[i].deq();
    2.26  	 end
    2.27 -      
    2.28 -       masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> numVoices)));
    2.29 +       if (numValid > 0)  // If nothing is valid, don't send anything
    2.30 +	  masterFifo.enq(tagged Sample truncate(fxptGetInt(sum >> numVoices)));
    2.31     endrule
    2.32   
    2.33    // Internal connections
    2.34  
    2.35 -//   method Action loadMixerFifos(AudioStream voiceInput);
    2.36 -//      voicesIn[voiceInput.voice].enq(voiceInput.data);
    2.37 -//   endmethod
    2.38 - 
    2.39     method Action toMixer(AudioStream streamIn);
    2.40  	 voicesIn[streamIn.voice].enq(streamIn.data);
    2.41     endmethod
     3.1 --- a/modules/bluespec/Pygar/core/Processor.bsv	Tue May 11 23:23:21 2010 -0400
     3.2 +++ b/modules/bluespec/Pygar/core/Processor.bsv	Wed May 12 00:06:05 2010 -0400
     3.3 @@ -37,7 +37,6 @@
     3.4  import ProcTypes::*;
     3.5  import BRegFile::*;
     3.6  import BranchPred::*;
     3.7 -//import PathTypes::*;  This is only there to force the debugging
     3.8  
     3.9  //AWB includes
    3.10  `include "asim/provides/low_level_platform_interface.bsh"
    3.11 @@ -57,6 +56,7 @@
    3.12  // pipeline
    3.13  
    3.14  `include "asim/provides/audio_pipe_types.bsh"
    3.15 +`include "asim/provides/path_types.bsh"
    3.16  
    3.17  //interface CPUToHost;
    3.18  //  method Bit#(32) cpuToHost(int req);
    3.19 @@ -71,12 +71,12 @@
    3.20    // Interface for enabling/disabling statistics on the rest of the core
    3.21    interface Get#(Bool) statsEn_get;
    3.22  
    3.23 -//  // Interface to host
    3.24 -//  interface CPUToHost tohost;
    3.25 +  // Interface to host
    3.26 +  interface Get#(Bit#(32)) pcCount;
    3.27  
    3.28    // Interface to Audio Pipeline
    3.29 -  interface Get#(AudioProcessorUnit) sampleOutput;
    3.30 -  interface Put#(AudioProcessorUnit) sampleInput;
    3.31 +  interface Get#(AudioStream) sampleOutput;
    3.32 +  interface Put#(AudioStream) sampleInput;
    3.33  	
    3.34  endinterface
    3.35  
    3.36 @@ -179,6 +179,8 @@
    3.37  
    3.38      endcase
    3.39  endfunction
    3.40 +
    3.41 +
    3.42  //-----------------------------------------------------------
    3.43  // Reference processor
    3.44  //-----------------------------------------------------------
    3.45 @@ -213,6 +215,9 @@
    3.46     Reg#(Bool)     cp0_statsEn  <- mkReg(False);
    3.47     Reg#(Bool)     cp0_audioEOF <- mkReg(False);  // Register to let code that EOF is reached
    3.48     Reg#(Bool)     cp0_progComp <- mkReg(False);  // Register to let processor know that the program is complete (as this terminates)
    3.49 + 
    3.50 +   Reg#(Bool)     code_bypass  <- mkReg(True);   // Register to enable passing invalid packets once all valid ones are passed OUT 
    3.51 +                                                 // (this becomes false at first valid packet) 
    3.52      
    3.53     // Memory request/response state
    3.54     
    3.55 @@ -223,9 +228,9 @@
    3.56     FIFO#(DataResp) dataRespQ   <- mkFIFO();
    3.57  
    3.58     // Audio I/O
    3.59 -   FIFO#(AudioProcessorUnit) inAudioFifo <- mkSizedFIFO(512);
    3.60 -   FIFO#(AudioProcessorUnit) outAudioFifo <- mkFIFO;
    3.61 -
    3.62 +   FIFO#(AudioStream) inAudioFifo  <- mkSizedFIFO(512);
    3.63 +   FIFO#(AudioStream) outAudioFifo <- mkFIFO;
    3.64 +   Reg#(VoiceId)      channel      <-mkReg(0);  // Set based on the reading the incoming data.  Not entirely sure I like this.  What if the program generates samples?
    3.65  
    3.66     // Statistics state (2010)
    3.67     //   Reg#(Stat) num_cycles <- mkReg(0);
    3.68 @@ -239,6 +244,20 @@
    3.69     //STAT num_inst <- mkStatCounter(`STATS_PROCESSOR_INST_COUNT);
    3.70  
    3.71     //-----------------------------------------------------------
    3.72 +   // Internal Functions
    3.73 +
    3.74 +   function Bool stallMTCO_MFCO(Instr inst);
    3.75 +      case(inst) matches
    3.76 +	 tagged MTC0 .it : 
    3.77 +	    begin
    3.78 +	       case (it.cop0dst)
    3.79 +		  5'd26 : return cp0_progComp;  // If true, processor service sendEnd which clears it.
    3.80 +	       endcase
    3.81 +	    end
    3.82 +      endcase					
    3.83 +   endfunction
    3.84 +   
    3.85 +   //-----------------------------------------------------------
    3.86     // Rules
    3.87  
    3.88     (* descending_urgency = "exec, pcgen" *)
    3.89 @@ -273,7 +292,8 @@
    3.90     rule exec (instRespQ.first() matches tagged LoadResp.ld
    3.91  	      &&& (ld.tag == epoch)
    3.92  	      &&& unpack(ld.data) matches .inst
    3.93 -              &&& !stall(inst, wbQ));
    3.94 +              &&& !stall(inst, wbQ)
    3.95 +	      &&& !stallMTCO_MFCO(inst));
    3.96  
    3.97        // Some abbreviations
    3.98        let sext = signExtend;
    3.99 @@ -301,6 +321,7 @@
   3.100        traceTiny("mkProc", "exInstTiny",inst);
   3.101        traceFull("mkProc", "exInstFull",inst);
   3.102  
   3.103 +//      $display("PROCESSOR: Exec Fires");
   3.104        case ( inst ) matches
   3.105  
   3.106  	 // -- Memory Ops ------------------------------------------------      
   3.107 @@ -553,7 +574,8 @@
   3.108  	       5'd10 : cp0_statsEn <= unpack(truncate(val_rsrc1));
   3.109  	       5'd21 : cp0_tohost  <= truncate(val_rsrc1);
   3.110  	       5'd26 : cp0_progComp <= unpack(truncate(val_rsrc1)); //states audio program completed and termination okay
   3.111 - 	       5'd27 : outAudioFifo.enq(tagged Sample unpack(truncate(val_rsrc1)));  //Bit size is 16 not 32 
   3.112 + 	       5'd27 : outAudioFifo.enq(AudioStream {voice: channel, data: tagged Valid
   3.113 +									   tagged Sample unpack(truncate(val_rsrc1)) });  //Bit size is 16 not 32
   3.114  	       default :
   3.115  	       $display( " RTL-ERROR : %m : Illegal MTC0 cop0dst register!" );
   3.116  	    endcase
   3.117 @@ -569,26 +591,35 @@
   3.118                 5'd20 : wbQ.enq(tagged WB_ALU {dest:it.rdst, data:cp0_fromhost });
   3.119                 5'd21 : wbQ.enq(tagged WB_ALU {dest:it.rdst, data:cp0_tohost   });
   3.120  	       5'd25 : begin
   3.121 -//			  $display( "**** EOF Requested");
   3.122 -			  let sample = inAudioFifo.first();
   3.123 -			  case (sample) matches
   3.124 -			     tagged EndOfFile :
   3.125 -				begin
   3.126 -				   $display("PROCESSOR sent toC EOF");
   3.127 -				   wbQ.enq(tagged WB_ALU {dest:it.rdst, data:zext(pack(True)) });  // Reading clears bit
   3.128 -				   inAudioFifo.deq;
   3.129 -			        end
   3.130 -			     tagged Sample .data:
   3.131 -				   wbQ.enq(tagged WB_ALU {dest:it.rdst, data:zext(pack(False)) });  // Reading clears bit
   3.132 -			  endcase
   3.133 +//			  $display( "**** EOF Requested\n ");  //Should never run if inAudioFifo.first not valid
   3.134 +			  let stream = inAudioFifo.first();
   3.135 +			  if (stream.data matches tagged Valid .sample)
   3.136 +			    begin
   3.137 +			       case (sample) matches
   3.138 +				  tagged EndOfFile :
   3.139 +				     begin
   3.140 +					$display("PROCESSOR sent toC EOF");
   3.141 +					wbQ.enq(tagged WB_ALU {dest:it.rdst, data:zext(pack(True)) });  // Reading clears bit
   3.142 +					inAudioFifo.deq;
   3.143 +			              end
   3.144 +				   tagged Sample .audio:
   3.145 +				      wbQ.enq(tagged WB_ALU {dest:it.rdst, data:zext(pack(False)) });  // Reading clears bit
   3.146 +			       endcase
   3.147 +			       code_bypass <= False;
   3.148 +			    end
   3.149 +			  else $display("PROCESSOR code trying to read Invalid Audio Stream");
   3.150  		       end
   3.151  	       5'd28 : begin
   3.152  			  $display( "***** Reqesting Sample");
   3.153 -			  let sample = inAudioFifo.first();        // is this going to cause perf. delay?
   3.154 -			  if (sample matches tagged Sample .audio) // if it is EOF another rule sets the cp0_audioEOF  
   3.155 -	     		     wbQ.enq(tagged WB_ALU {dest:it.rdst, data:zext(pack(audio)) });  // do I need pack?
   3.156 -			  else $display ( "Audio File EOF Reached.  Invalid sample request.");
   3.157 -			  inAudioFifo.deq();
   3.158 +			  let stream = inAudioFifo.first();        // is this going to cause perf. delay?
   3.159 +			  if (stream.data matches tagged Valid .sample)
   3.160 +			    begin			  
   3.161 +			       if (sample matches tagged Sample .audio) // if it is EOF another rule sets the cp0_audioEOF  
   3.162 +	     			 wbQ.enq(tagged WB_ALU {dest:it.rdst, data:zext(pack(audio)) });  // do I need pack?
   3.163 +			       else $display ( "Audio File EOF Reached.  Invalid sample request.");
   3.164 +			       inAudioFifo.deq();
   3.165 +			    end
   3.166 +			  else $display("PROCESSOR code trying to read Invalid Audio Stream");
   3.167  		       end
   3.168                default : 
   3.169                  $display( " RTL-ERROR : %m : Illegal MFC0 cop0src register!" );
   3.170 @@ -645,14 +676,13 @@
   3.171   //     num_cycles.incr();
   3.172   // endrule
   3.173  
   3.174 -/*
   3.175 - // for now, we don't do anything.
   3.176 -  rule connectAudioReqResp;
   3.177 -    $display("rlm: PROCESSOR copies a datum\n");
   3.178 +  rule bypass (code_bypass &&& 
   3.179 +	      !cp0_progComp &&&   //never fires at the same time as sendEnd where it is enabled
   3.180 +              inAudioFifo.first().data matches tagged Invalid) ;
   3.181      outAudioFifo.enq(inAudioFifo.first());
   3.182      inAudioFifo.deq;
   3.183    endrule
   3.184 -*/
   3.185 +
   3.186  /*
   3.187    rule flagAudioEnd (inAudioFifo.first() matches tagged EndOfFile);
   3.188       $display (" PROCESSOR End Audio Flag Set ");
   3.189 @@ -660,10 +690,12 @@
   3.190       inAudioFifo.deq;
   3.191    endrule
   3.192  */
   3.193 +  (* descending_urgency = "sendProcEnd, exec" *)
   3.194    rule sendProcEnd (cp0_progComp);
   3.195       $display (" PROCESSOR Says Program Complete ");
   3.196 -     outAudioFifo.enq(tagged EndOfFile);
   3.197 -     cp0_progComp <= False;  //only send one.  And functions to reset
   3.198 +     outAudioFifo.enq(AudioStream {voice: channel, data: tagged Valid tagged EndOfFile });  //  Only send one
   3.199 +     cp0_progComp <= False;               //  And functions to reset
   3.200 +     code_bypass <= True;                 //  Enable Bypass so that invalids get thru
   3.201    endrule
   3.202  
   3.203     
   3.204 @@ -696,6 +728,7 @@
   3.205     
   3.206    interface Get sampleOutput = fifoToGet(outAudioFifo);
   3.207    interface Put sampleInput = fifoToPut(inAudioFifo);
   3.208 +  interface Get pcCount = toGet(asReg(pc));
   3.209  
   3.210  endmodule
   3.211  
     4.1 --- a/modules/bluespec/Pygar/core/ProcessorSystem.dic	Tue May 11 23:23:21 2010 -0400
     4.2 +++ b/modules/bluespec/Pygar/core/ProcessorSystem.dic	Wed May 12 00:06:05 2010 -0400
     4.3 @@ -1,4 +1,26 @@
     4.4  def VDEV.SCRATCH.MEMORYA     "program.0/program.vmh";
     4.5  def VDEV.SCRATCH.MEMORYB     "program.0/program.vmh";
     4.6 -
     4.7 -
     4.8 +def VDEV.SCRATCH.MEMORYC     "program.0/program.vmh";
     4.9 +def VDEV.SCRATCH.MEMORYD     "program.0/program.vmh";
    4.10 +def VDEV.SCRATCH.MEMORYE     "program.0/program.vmh";
    4.11 +def VDEV.SCRATCH.MEMORYF     "program.0/program.vmh";
    4.12 +def VDEV.SCRATCH.MEMORYG     "program.0/program.vmh";
    4.13 +def VDEV.SCRATCH.MEMORYH     "program.0/program.vmh";
    4.14 +def VDEV.SCRATCH.MEMORYI     "program.0/program.vmh";
    4.15 +def VDEV.SCRATCH.MEMORYJ     "program.0/program.vmh";
    4.16 +def VDEV.SCRATCH.MEMORYK     "program.0/program.vmh";
    4.17 +def VDEV.SCRATCH.MEMORYL     "program.0/program.vmh";
    4.18 +def VDEV.SCRATCH.MEMORYM     "program.0/program.vmh";
    4.19 +def VDEV.SCRATCH.MEMORYN     "program.0/program.vmh";
    4.20 +def VDEV.SCRATCH.MEMORYO     "program.0/program.vmh";
    4.21 +def VDEV.SCRATCH.MEMORYP     "program.0/program.vmh";
    4.22 +def VDEV.SCRATCH.MEMORYQ     "program.0/program.vmh";
    4.23 +def VDEV.SCRATCH.MEMORYR     "program.0/program.vmh";
    4.24 +def VDEV.SCRATCH.MEMORYS     "program.0/program.vmh";
    4.25 +def VDEV.SCRATCH.MEMORYT     "program.0/program.vmh";
    4.26 +def VDEV.SCRATCH.MEMORYU     "program.0/program.vmh";
    4.27 +def VDEV.SCRATCH.MEMORYV     "program.0/program.vmh";
    4.28 +def VDEV.SCRATCH.MEMORYW     "program.0/program.vmh";
    4.29 +def VDEV.SCRATCH.MEMORYX     "program.0/program.vmh";
    4.30 +def VDEV.SCRATCH.MEMORYY     "program.0/program.vmh";
    4.31 +def VDEV.SCRATCH.MEMORYZ     "program.0/program.vmh";
    4.32 \ No newline at end of file
     5.1 --- a/modules/bluespec/Pygar/core/audioCore.bsv	Tue May 11 23:23:21 2010 -0400
     5.2 +++ b/modules/bluespec/Pygar/core/audioCore.bsv	Wed May 12 00:06:05 2010 -0400
     5.3 @@ -40,6 +40,7 @@
     5.4  `include "asim/provides/data_cache.bsh"
     5.5  `include "asim/provides/processor.bsh"
     5.6  `include "asim/provides/audio_pipe_types.bsh"
     5.7 +`include "asim/provides/path_types.bsh"
     5.8  
     5.9  // Scratchpad includes
    5.10  `include "asim/provides/scratchpad_memory.bsh"
    5.11 @@ -48,17 +49,15 @@
    5.12  
    5.13  interface Core;
    5.14  
    5.15 -   interface Get#(AudioProcessorUnit) sampleOutput;
    5.16 -   interface Put#(AudioProcessorUnit) sampleInput;
    5.17 +   interface Get#(AudioStream) sampleOutput;
    5.18 +   interface Put#(AudioStream) sampleInput;
    5.19  	 
    5.20 -//   interface CPUToHost tohost;
    5.21 +   interface Get#(Bit#(32)) pc;
    5.22     
    5.23  endinterface
    5.24  
    5.25  module   [CONNECTED_MODULE]  mkCore#(Integer prog) ( Core );
    5.26 -   
    5.27 -
    5.28 -  // Instantiate the modules
    5.29 +     // Instantiate the modules
    5.30  
    5.31    Proc proc <- mkProc();
    5.32    ICache#(InstReq,InstResp) icache <- mkInstCache();
    5.33 @@ -108,6 +107,6 @@
    5.34     interface sampleOutput = proc.sampleOutput;
    5.35     interface sampleInput = proc.sampleInput;
    5.36  
    5.37 -//   interface CPUToHost tohost = proc.tohost;
    5.38 +   interface pc = proc.pcCount;
    5.39  
    5.40  endmodule
     6.1 --- a/modules/bluespec/Pygar/core/audioCorePipeline.bsv	Tue May 11 23:23:21 2010 -0400
     6.2 +++ b/modules/bluespec/Pygar/core/audioCorePipeline.bsv	Wed May 12 00:06:05 2010 -0400
     6.3 @@ -50,19 +50,18 @@
     6.4  
     6.5  module [CONNECTED_MODULE] mkConnectedApplication ();
     6.6  
     6.7 - //  Core core <- mkCore(`VDEV_SCRATCH_MEMORYA);
     6.8 - //  Core anotherCore <- mkCore(`VDEV_SCRATCH_MEMORYB);
     6.9     Vector#(`MAX_VOICES, Volume) channelVols = replicate(127);
    6.10     Mixer mixer <- mkMixer(`MAX_VOICES, channelVols); //should be max voices but 2 for now
    6.11 -   
    6.12 -   Reg#(int) cycle <- mkReg(0);
    6.13 -   Reg#(int) sampleCount <-mkReg(0);
    6.14 -   Vector#(2, Reg#(Bool)) ac_fini <- replicateM(mkReg(False));
    6.15 +
    6.16 +   Reg#(Bit#(32)) cycle <- mkReg(0);
    6.17 +   Reg#(Bit#(32)) sampleCountIn <-mkReg(0);
    6.18 +   Reg#(Bit#(32)) sampleCountOut <-mkReg(0);
    6.19 +   Vector#(`MAX_VOICES, Reg#(Bit#(32))) pc <-replicateM(mkReg(0)); //tracks pcs from cores for debug purposes
    6.20 +   Vector#(`MAX_VOICES, Reg#(Bool)) channelFini <- replicateM(mkReg(False));
    6.21  
    6.22     // Services Samples 
    6.23     ClientStub_AUDIOCORERRR client_stub <- mkClientStub_AUDIOCORERRR();   
    6.24    
    6.25 -
    6.26     //-----------------------------------------------------------
    6.27     // Debug port
    6.28     
    6.29 @@ -75,15 +74,55 @@
    6.30  	 case (n)
    6.31  	    0 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYA);
    6.32  	    1 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYB);
    6.33 +	    2 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYC);
    6.34 +	    3 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYD);
    6.35 +	    4 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYE);
    6.36 +	    5 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYF);
    6.37 +	    6 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYG);
    6.38 +	    7 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYH);
    6.39 +	    8 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYI);
    6.40 +	    9 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYJ);
    6.41 +	    10 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYK);
    6.42 +	    11 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYL);
    6.43 +	    12 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYM);
    6.44 +	    13 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYN);
    6.45 +	    14 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYO);
    6.46 +	    15 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYP);
    6.47 +	    16 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYQ);
    6.48 +	    17 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYR);
    6.49 +	    18 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYS);
    6.50 +	    19 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYT);
    6.51 +	    20 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYU);
    6.52 +	    21 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYV);
    6.53 +	    22 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYW);
    6.54 +	    23 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYX);
    6.55 +	    24 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYY);
    6.56 +	    25 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYZ);
    6.57  	 endcase
    6.58       end
    6.59 -   
    6.60 +
    6.61 +   function Integer countFiniVoices();
    6.62 +      Integer count = 0;
    6.63 +      for (Integer i = 0; i < `MAX_VOICES; i = i + 1)
    6.64 +	if (channelFini[i]) count = count + 1;
    6.65 +      return count;
    6.66 +   endfunction
    6.67 +      
    6.68    // this is for the tracing
    6.69    rule printCycles;
    6.70      cycle <= cycle+1;
    6.71      $fdisplay(stderr, " => Cycle = %d", cycle);
    6.72    endrule
    6.73  
    6.74 +  // get the pc for trace purposes
    6.75 +   rule getPC;
    6.76 +     for (Integer i = 0; i < `MAX_VOICES; i = i + 1)
    6.77 +	begin
    6.78 +	   let val <- cores[i].pc.get(); 
    6.79 +	   pc[i] <= val;
    6.80 +	end 
    6.81 +   endrule
    6.82 +
    6.83    // Send to Mixer
    6.84    // Right now this is sorta retarded in that I pass from the output fifo into a new fifo
    6.85    // But I have to mod a bunch of things to fix this and I am not sure I understand
    6.86 @@ -92,28 +131,27 @@
    6.87        for (Integer i = 0; i < `MAX_VOICES; i = i + 1)
    6.88          begin
    6.89  	   let coreOut <- cores[i].sampleOutput.get();
    6.90 -	   mixer.toMixer(AudioStream {voice : fromInteger(i), data: tagged Valid coreOut});
    6.91 +	   mixer.toMixer(AudioStream {voice : fromInteger(i), data:coreOut.data});
    6.92  	end
    6.93 -      
    6.94 -//     let coreOut <- core.sampleOutput.get();
    6.95 -//    mixer.toMixer(AudioStream {voice : 0, data : tagged Valid coreOut});
    6.96 -//    mixer.toMixer(AudioStream {voice : 1, data : tagged Valid anotherOut});
    6.97 -  endrule
    6.98 -
    6.99 +   endrule
   6.100 +   
   6.101    rule feedOutput;
   6.102       let pipeOut <- mixer.mainOut.get();
   6.103       
   6.104       AudioProcessorControl endOfFileTag = EndOfFile;
   6.105       AudioProcessorControl sampleTag = Data;
   6.106  
   6.107 -     sampleCount <= sampleCount+1;
   6.108 +     sampleCountOut <= sampleCountOut+1;
   6.109       
   6.110 -     $display("PIPE writes sample %d", sampleCount);
   6.111 +     $display("PIPE writes sample %d", sampleCountOut);
   6.112       case (pipeOut) matches
   6.113  	tagged EndOfFile:
   6.114  	   begin
   6.115  	      client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?);
   6.116 -	      ac_fini[0] <= True;
   6.117 +	      for (Integer i = 1; i < `MAX_VOICES; i = i+1) channelFini[i] <= False; 
   6.118 +	            //This will report conflict with
   6.119 +		    //the other setting of channelFini at input except they are mutually
   6.120 +		    //exclusive since this is only hit after all input finished
   6.121  	   end
   6.122         tagged Sample .sample:
   6.123  	  client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample)));
   6.124 @@ -134,31 +172,55 @@
   6.125  */
   6.126  
   6.127     //*****  SERVER Side  *****
   6.128 -
   6.129 +  // this requires me to switch the processor to handle this which I will do later.
   6.130 +   // When a file has finished, want the system to pass invalid audiostreams
   6.131 +   rule fillFinished;
   6.132 +      for (Integer i = 1; i < `MAX_VOICES; i = i+1)
   6.133 +	 begin
   6.134 +	    if (channelFini[i])
   6.135 +	       cores[i].sampleInput.put(AudioStream {voice : fromInteger(i), data: tagged Invalid});
   6.136 +	 end
   6.137 +   endrule
   6.138 +   
   6.139     (* conservative_implicit_conditions *)
   6.140     rule feedInput;
   6.141       let command <- server_stub.acceptRequest_SendUnprocessedStream();
   6.142       AudioProcessorControl ctrl = unpack(truncate(command.ctrl));
   6.143  
   6.144       VoiceId channel = unpack(truncate(command.channel));
   6.145 -//      $display("rlm: %x", test);
   6.146 +//     $display("PIPE: Incoming sample to channel %x", channel);
   6.147  	   
   6.148       AudioProcessorUnit inSample;
   6.149        
   6.150       if(ctrl == EndOfFile)
   6.151         begin
   6.152  	   $display("lsp: PIPE received EOF   ");
   6.153 -	   inSample = tagged EndOfFile;
   6.154 -//           core.sampleInput.put(tagged EndOfFile);
   6.155 +	  inSample = tagged EndOfFile;
   6.156 +          channelFini[channel] <= True;
   6.157         end
   6.158       else 
   6.159  	begin
   6.160  //	   $display("lsp: PIPE received Data   ");
   6.161 -//           core.sampleInput.put(tagged Sample unpack(truncate(command.sample)));	   
   6.162             inSample = tagged Sample unpack(truncate(command.sample));
   6.163  	end
   6.164  
   6.165 -      cores[channel].sampleInput.put(inSample);
   6.166 +      if (!channelFini[channel])
   6.167 +	 cores[channel].sampleInput.put(AudioStream {voice: channel, data: tagged Valid inSample });
   6.168 +      else $display("PIPE ERROR: Trying to send to Stream officially done");
   6.169        
   6.170 -   endrule     
   6.171 +   endrule
   6.172 +
   6.173 +   (* conservative_implicit_conditions *)
   6.174 +   rule handleCPUToHost;
   6.175 +      let req <- server_stub.acceptRequest_ReadCPUToHost();
   6.176 +      case (req) 
   6.177 +	 1: server_stub.sendResponse_ReadCPUToHost(cycle);
   6.178 +	 2: server_stub.sendResponse_ReadCPUToHost(sampleCountIn);
   6.179 +	 3: server_stub.sendResponse_ReadCPUToHost(sampleCountOut);
   6.180 +	 4: server_stub.sendResponse_ReadCPUToHost(fromInteger(countFiniVoices()));
   6.181 +	 default : if (req < 10 + `MAX_VOICES) 
   6.182 +		      server_stub.sendResponse_ReadCPUToHost(pc[req-10]);  
   6.183 +      endcase
   6.184 +  endrule
   6.185 +
   6.186  endmodule