Mercurial > pygar
view modules/bluespec/Pygar/core/audioCorePipeline.bsv @ 74:31fef269ae58 pygar svn.75
[svn r75] presentation for wednesdaty
author | rlm |
---|---|
date | Wed, 12 May 2010 02:25:34 -0400 |
parents | 44cc00df1168 |
children |
line wrap: on
line source
1 // The MIT License3 // Copyright (c) 2009 Massachusetts Institute of Technology5 // Permission is hereby granted, free of charge, to any person obtaining a copy6 // of this software and associated documentation files (the "Software"), to deal7 // in the Software without restriction, including without limitation the rights8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell9 // copies of the Software, and to permit persons to whom the Software is10 // furnished to do so, subject to the following conditions:12 // The above copyright notice and this permission notice shall be included in13 // all copies or substantial portions of the Software.15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN21 // THE SOFTWARE.23 // Author: Kermin Fleming kfleming@mit.edu25 import Connectable::*;26 import GetPut::*;27 import ClientServer::*;28 import FIFO::*;29 import SpecialFIFOs::*;30 import Vector::*;32 //AWB includes33 `include "asim/provides/low_level_platform_interface.bsh"34 `include "asim/provides/soft_connections.bsh"35 `include "asim/provides/common_services.bsh"37 //Local includes38 `include "asim/provides/audio_pipe_types.bsh" //provides Audio Pipeline interface39 `include "asim/provides/path_types.bsh"40 `include "asim/provides/core.bsh"41 `include "asim/provides/mixer.bsh"42 `include "asim/provides/processor_library.bsh"43 `include "asim/provides/fpga_components.bsh"44 `include "asim/dict/VDEV_SCRATCH.bsh"46 `include "asim/rrr/remote_client_stub_AUDIOCORERRR.bsh"47 `include "asim/rrr/remote_server_stub_AUDIOCORERRR.bsh"49 `define MAX_VOICES 251 module [CONNECTED_MODULE] mkConnectedApplication ();53 Vector#(`MAX_VOICES, Volume) channelVols = replicate(127);54 Mixer mixer <- mkMixer(`MAX_VOICES, channelVols); //should be max voices but 2 for now56 Reg#(Bit#(32)) cycle <- mkReg(0);57 Reg#(Bit#(32)) sampleCountIn <-mkReg(0);58 Reg#(Bit#(32)) sampleCountOut <-mkReg(0);59 Vector#(`MAX_VOICES, Reg#(Bit#(32))) pc <-replicateM(mkReg(0)); //tracks pcs from cores for debug purposes60 Vector#(`MAX_VOICES, Reg#(Bool)) channelFini <- replicateM(mkReg(False));62 // Services Samples63 ClientStub_AUDIOCORERRR client_stub <- mkClientStub_AUDIOCORERRR();65 //-----------------------------------------------------------66 // Debug port68 ServerStub_AUDIOCORERRR server_stub <- mkServerStub_AUDIOCORERRR();70 // Create Cores71 Vector#(`MAX_VOICES, Core) cores;72 for (Integer n = 0; n < `MAX_VOICES; n = n + 1)73 begin74 case (n)75 0 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYA);76 1 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYB);77 2 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYC);78 3 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYD);79 4 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYE);80 5 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYF);81 6 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYG);82 7 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYH);83 8 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYI);84 9 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYJ);85 10 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYK);86 11 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYL);87 12 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYM);88 13 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYN);89 14 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYO);90 15 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYP);91 16 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYQ);92 17 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYR);93 18 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYS);94 19 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYT);95 20 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYU);96 21 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYV);97 22 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYW);98 23 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYX);99 24 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYY);100 25 : cores[n] <- mkCore(`VDEV_SCRATCH_MEMORYZ);101 endcase102 end104 function Integer countFiniVoices();105 Integer count = 0;106 for (Integer i = 0; i < `MAX_VOICES; i = i + 1)107 if (channelFini[i]) count = count + 1;108 return count;109 endfunction111 // this is for the tracing112 rule printCycles;113 cycle <= cycle+1;114 $fdisplay(stderr, " => Cycle = %d", cycle);115 endrule117 // get the pc for trace purposes118 rule getPC;119 for (Integer i = 0; i < `MAX_VOICES; i = i + 1)120 begin121 let val <- cores[i].pc.get();122 pc[i] <= val;123 end124 endrule126 // Send to Mixer127 // Right now this is sorta retarded in that I pass from the output fifo into a new fifo128 // But I have to mod a bunch of things to fix this and I am not sure I understand129 // things well enough to do this quickly. So here it is as it is for now.130 rule mix;131 for (Integer i = 0; i < `MAX_VOICES; i = i + 1)132 begin133 let coreOut <- cores[i].sampleOutput.get();134 mixer.toMixer(AudioStream {voice : fromInteger(i), data:coreOut.data});135 end136 endrule138 rule feedOutput;139 let pipeOut <- mixer.mainOut.get();141 AudioProcessorControl endOfFileTag = EndOfFile;142 AudioProcessorControl sampleTag = Data;144 sampleCountOut <= sampleCountOut+1;146 $display("PIPE writes sample %d", sampleCountOut);147 case (pipeOut) matches148 tagged EndOfFile:149 begin150 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?);151 for (Integer i = 1; i < `MAX_VOICES; i = i+1) channelFini[i] <= False;152 //This will report conflict with153 //the other setting of channelFini at input except they are mutually154 //exclusive since this is only hit after all input finished155 end156 tagged Sample .sample:157 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample)));158 endcase159 endrule161 // Can generally just stick with the EOF but since I have two Cores no mixer...162 /*(* conservative_implicit_conditions *)163 rule sendTerminate;164 Bool done = True;165 for (Integer i = 1; i < 2; i = i+1)166 done = ac_fini[i] && done;168 if (done)169 client_stub.makeRequest_SendTerminate(zeroExtend(pack(1)));171 endrule172 */174 //***** SERVER Side *****175 // this requires me to switch the processor to handle this which I will do later.176 // When a file has finished, want the system to pass invalid audiostreams177 rule fillFinished;178 for (Integer i = 1; i < `MAX_VOICES; i = i+1)179 begin180 if (channelFini[i])181 cores[i].sampleInput.put(AudioStream {voice : fromInteger(i), data: tagged Invalid});182 end183 endrule185 (* conservative_implicit_conditions *)186 rule feedInput;187 let command <- server_stub.acceptRequest_SendUnprocessedStream();188 AudioProcessorControl ctrl = unpack(truncate(command.ctrl));190 VoiceId channel = unpack(truncate(command.channel));191 // $display("PIPE: Incoming sample to channel %x", channel);193 AudioProcessorUnit inSample;195 if(ctrl == EndOfFile)196 begin197 $display("lsp: PIPE received EOF ");198 inSample = tagged EndOfFile;199 channelFini[channel] <= True;200 end201 else202 begin203 // $display("lsp: PIPE received Data ");204 inSample = tagged Sample unpack(truncate(command.sample));205 end207 if (!channelFini[channel])208 cores[channel].sampleInput.put(AudioStream {voice: channel, data: tagged Valid inSample });209 else $display("PIPE ERROR: Trying to send to Stream officially done");211 endrule213 (* conservative_implicit_conditions *)214 rule handleCPUToHost;215 let req <- server_stub.acceptRequest_ReadCPUToHost();216 case (req)217 1: server_stub.sendResponse_ReadCPUToHost(cycle);218 2: server_stub.sendResponse_ReadCPUToHost(sampleCountIn);219 3: server_stub.sendResponse_ReadCPUToHost(sampleCountOut);220 4: server_stub.sendResponse_ReadCPUToHost(fromInteger(countFiniVoices()));221 default : if (req < 10 + `MAX_VOICES)222 server_stub.sendResponse_ReadCPUToHost(pc[req-10]);223 endcase224 endrule226 endmodule