annotate modules/bluespec/Pygar/core/audioCorePipeline.bsv @ 68:44cc00df1168 pygar svn.69

[svn r69] runs separate eofs (I think)
author punk
date Wed, 12 May 2010 00:06:05 -0400
parents 9b4f237e77e1
children
rev   line source
punk@13 1 // The MIT License
punk@13 2
punk@13 3 // Copyright (c) 2009 Massachusetts Institute of Technology
punk@13 4
punk@13 5 // Permission is hereby granted, free of charge, to any person obtaining a copy
punk@13 6 // of this software and associated documentation files (the "Software"), to deal
punk@13 7 // in the Software without restriction, including without limitation the rights
punk@13 8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
punk@13 9 // copies of the Software, and to permit persons to whom the Software is
punk@13 10 // furnished to do so, subject to the following conditions:
punk@13 11
punk@13 12 // The above copyright notice and this permission notice shall be included in
punk@13 13 // all copies or substantial portions of the Software.
punk@13 14
punk@13 15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
punk@13 16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
punk@13 17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
punk@13 18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
punk@13 19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
punk@13 20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
punk@13 21 // THE SOFTWARE.
punk@13 22
punk@13 23 // Author: Kermin Fleming kfleming@mit.edu
punk@13 24
punk@13 25 import Connectable::*;
punk@13 26 import GetPut::*;
punk@13 27 import ClientServer::*;
punk@13 28 import FIFO::*;
punk@15 29 import SpecialFIFOs::*;
punk@52 30 import Vector::*;
punk@13 31
punk@13 32 //AWB includes
punk@13 33 `include "asim/provides/low_level_platform_interface.bsh"
punk@13 34 `include "asim/provides/soft_connections.bsh"
punk@13 35 `include "asim/provides/common_services.bsh"
punk@13 36
punk@13 37 //Local includes
punk@13 38 `include "asim/provides/audio_pipe_types.bsh" //provides Audio Pipeline interface
punk@33 39 `include "asim/provides/path_types.bsh"
punk@13 40 `include "asim/provides/core.bsh"
punk@43 41 `include "asim/provides/mixer.bsh"
punk@15 42 `include "asim/provides/processor_library.bsh"
punk@15 43 `include "asim/provides/fpga_components.bsh"
punk@51 44 `include "asim/dict/VDEV_SCRATCH.bsh"
punk@33 45
punk@13 46 `include "asim/rrr/remote_client_stub_AUDIOCORERRR.bsh"
punk@36 47 `include "asim/rrr/remote_server_stub_AUDIOCORERRR.bsh"
punk@13 48
punk@54 49 `define MAX_VOICES 2
punk@54 50
punk@13 51 module [CONNECTED_MODULE] mkConnectedApplication ();
punk@54 52
punk@54 53 Vector#(`MAX_VOICES, Volume) channelVols = replicate(127);
punk@54 54 Mixer mixer <- mkMixer(`MAX_VOICES, channelVols); //should be max voices but 2 for now
punk@68 55
punk@68 56 Reg#(Bit#(32)) cycle <- mkReg(0);
punk@68 57 Reg#(Bit#(32)) sampleCountIn <-mkReg(0);
punk@68 58 Reg#(Bit#(32)) sampleCountOut <-mkReg(0);
punk@68 59 Vector#(`MAX_VOICES, Reg#(Bit#(32))) pc <-replicateM(mkReg(0)); //tracks pcs from cores for debug purposes
punk@68 60 Vector#(`MAX_VOICES, Reg#(Bool)) channelFini <- replicateM(mkReg(False));
punk@33 61
punk@53 62 // Services Samples
punk@53 63 ClientStub_AUDIOCORERRR client_stub <- mkClientStub_AUDIOCORERRR();
punk@48 64
punk@36 65 //-----------------------------------------------------------
punk@36 66 // Debug port
punk@36 67
punk@36 68 ServerStub_AUDIOCORERRR server_stub <- mkServerStub_AUDIOCORERRR();
punk@36 69
punk@54 70 // Create Cores
punk@54 71 Vector#(`MAX_VOICES, Core) cores;
punk@54 72 for (Integer n = 0; n < `MAX_VOICES; n = n + 1)
punk@54 73 begin
punk@54 74 case (n)
punk@54 75 0 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYA);
punk@54 76 1 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYB);
punk@68 77 2 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYC);
punk@68 78 3 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYD);
punk@68 79 4 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYE);
punk@68 80 5 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYF);
punk@68 81 6 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYG);
punk@68 82 7 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYH);
punk@68 83 8 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYI);
punk@68 84 9 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYJ);
punk@68 85 10 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYK);
punk@68 86 11 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYL);
punk@68 87 12 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYM);
punk@68 88 13 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYN);
punk@68 89 14 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYO);
punk@68 90 15 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYP);
punk@68 91 16 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYQ);
punk@68 92 17 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYR);
punk@68 93 18 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYS);
punk@68 94 19 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYT);
punk@68 95 20 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYU);
punk@68 96 21 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYV);
punk@68 97 22 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYW);
punk@68 98 23 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYX);
punk@68 99 24 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYY);
punk@68 100 25 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYZ);
punk@54 101 endcase
punk@54 102 end
punk@68 103
punk@68 104 function Integer countFiniVoices();
punk@68 105 Integer count = 0;
punk@68 106 for (Integer i = 0; i < `MAX_VOICES; i = i + 1)
punk@68 107 if (channelFini[i]) count = count + 1;
punk@68 108 return count;
punk@68 109 endfunction
punk@68 110
punk@13 111 // this is for the tracing
punk@13 112 rule printCycles;
punk@13 113 cycle <= cycle+1;
punk@13 114 $fdisplay(stderr, " => Cycle = %d", cycle);
punk@13 115 endrule
punk@13 116
punk@68 117 // get the pc for trace purposes
punk@68 118 rule getPC;
punk@68 119 for (Integer i = 0; i < `MAX_VOICES; i = i + 1)
punk@68 120 begin
punk@68 121 let val <- cores[i].pc.get();
punk@68 122 pc[i] <= val;
punk@68 123 end
punk@68 124 endrule
punk@68 125
punk@53 126 // Send to Mixer
punk@53 127 // Right now this is sorta retarded in that I pass from the output fifo into a new fifo
punk@53 128 // But I have to mod a bunch of things to fix this and I am not sure I understand
punk@53 129 // things well enough to do this quickly. So here it is as it is for now.
punk@54 130 rule mix;
punk@54 131 for (Integer i = 0; i < `MAX_VOICES; i = i + 1)
punk@54 132 begin
punk@54 133 let coreOut <- cores[i].sampleOutput.get();
punk@68 134 mixer.toMixer(AudioStream {voice : fromInteger(i), data:coreOut.data});
punk@54 135 end
punk@68 136 endrule
punk@68 137
punk@48 138 rule feedOutput;
punk@53 139 let pipeOut <- mixer.mainOut.get();
punk@53 140
punk@13 141 AudioProcessorControl endOfFileTag = EndOfFile;
punk@13 142 AudioProcessorControl sampleTag = Data;
punk@13 143
punk@68 144 sampleCountOut <= sampleCountOut+1;
punk@53 145
punk@68 146 $display("PIPE writes sample %d", sampleCountOut);
punk@53 147 case (pipeOut) matches
punk@52 148 tagged EndOfFile:
punk@52 149 begin
punk@52 150 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?);
punk@68 151 for (Integer i = 1; i < `MAX_VOICES; i = i+1) channelFini[i] <= False;
punk@68 152 //This will report conflict with
punk@68 153 //the other setting of channelFini at input except they are mutually
punk@68 154 //exclusive since this is only hit after all input finished
punk@52 155 end
punk@52 156 tagged Sample .sample:
punk@52 157 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample)));
punk@25 158 endcase
punk@53 159 endrule
punk@13 160
punk@52 161 // Can generally just stick with the EOF but since I have two Cores no mixer...
punk@52 162 /*(* conservative_implicit_conditions *)
punk@52 163 rule sendTerminate;
punk@52 164 Bool done = True;
punk@52 165 for (Integer i = 1; i < 2; i = i+1)
punk@52 166 done = ac_fini[i] && done;
punk@52 167
punk@52 168 if (done)
punk@52 169 client_stub.makeRequest_SendTerminate(zeroExtend(pack(1)));
punk@52 170
punk@52 171 endrule
punk@52 172 */
punk@52 173
punk@36 174 //***** SERVER Side *****
punk@68 175 // this requires me to switch the processor to handle this which I will do later.
punk@68 176 // When a file has finished, want the system to pass invalid audiostreams
punk@68 177 rule fillFinished;
punk@68 178 for (Integer i = 1; i < `MAX_VOICES; i = i+1)
punk@68 179 begin
punk@68 180 if (channelFini[i])
punk@68 181 cores[i].sampleInput.put(AudioStream {voice : fromInteger(i), data: tagged Invalid});
punk@68 182 end
punk@68 183 endrule
punk@68 184
punk@52 185 (* conservative_implicit_conditions *)
punk@36 186 rule feedInput;
punk@36 187 let command <- server_stub.acceptRequest_SendUnprocessedStream();
punk@36 188 AudioProcessorControl ctrl = unpack(truncate(command.ctrl));
rlm@41 189
punk@52 190 VoiceId channel = unpack(truncate(command.channel));
punk@68 191 // $display("PIPE: Incoming sample to channel %x", channel);
rlm@41 192
punk@52 193 AudioProcessorUnit inSample;
punk@52 194
punk@52 195 if(ctrl == EndOfFile)
punk@52 196 begin
punk@43 197 $display("lsp: PIPE received EOF ");
punk@68 198 inSample = tagged EndOfFile;
punk@68 199 channelFini[channel] <= True;
punk@36 200 end
punk@36 201 else
punk@36 202 begin
punk@43 203 // $display("lsp: PIPE received Data ");
punk@52 204 inSample = tagged Sample unpack(truncate(command.sample));
punk@52 205 end
punk@52 206
punk@68 207 if (!channelFini[channel])
punk@68 208 cores[channel].sampleInput.put(AudioStream {voice: channel, data: tagged Valid inSample });
punk@68 209 else $display("PIPE ERROR: Trying to send to Stream officially done");
punk@52 210
punk@68 211 endrule
punk@68 212
punk@68 213 (* conservative_implicit_conditions *)
punk@68 214 rule handleCPUToHost;
punk@68 215 let req <- server_stub.acceptRequest_ReadCPUToHost();
punk@68 216 case (req)
punk@68 217 1: server_stub.sendResponse_ReadCPUToHost(cycle);
punk@68 218 2: server_stub.sendResponse_ReadCPUToHost(sampleCountIn);
punk@68 219 3: server_stub.sendResponse_ReadCPUToHost(sampleCountOut);
punk@68 220 4: server_stub.sendResponse_ReadCPUToHost(fromInteger(countFiniVoices()));
punk@68 221 default : if (req < 10 + `MAX_VOICES)
punk@68 222 server_stub.sendResponse_ReadCPUToHost(pc[req-10]);
punk@68 223 endcase
punk@68 224 endrule
punk@68 225
punk@13 226 endmodule