view 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
line wrap: on
line source
1 // The MIT License
3 // Copyright (c) 2009 Massachusetts Institute of Technology
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // 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 IN
21 // THE SOFTWARE.
23 // Author: Kermin Fleming kfleming@mit.edu
25 import Connectable::*;
26 import GetPut::*;
27 import ClientServer::*;
28 import FIFO::*;
29 import SpecialFIFOs::*;
30 import Vector::*;
32 //AWB includes
33 `include "asim/provides/low_level_platform_interface.bsh"
34 `include "asim/provides/soft_connections.bsh"
35 `include "asim/provides/common_services.bsh"
37 //Local includes
38 `include "asim/provides/audio_pipe_types.bsh" //provides Audio Pipeline interface
39 `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 2
51 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 now
56 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 purposes
60 Vector#(`MAX_VOICES, Reg#(Bool)) channelFini <- replicateM(mkReg(False));
62 // Services Samples
63 ClientStub_AUDIOCORERRR client_stub <- mkClientStub_AUDIOCORERRR();
65 //-----------------------------------------------------------
66 // Debug port
68 ServerStub_AUDIOCORERRR server_stub <- mkServerStub_AUDIOCORERRR();
70 // Create Cores
71 Vector#(`MAX_VOICES, Core) cores;
72 for (Integer n = 0; n < `MAX_VOICES; n = n + 1)
73 begin
74 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 endcase
102 end
104 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 endfunction
111 // this is for the tracing
112 rule printCycles;
113 cycle <= cycle+1;
114 $fdisplay(stderr, " => Cycle = %d", cycle);
115 endrule
117 // get the pc for trace purposes
118 rule getPC;
119 for (Integer i = 0; i < `MAX_VOICES; i = i + 1)
120 begin
121 let val <- cores[i].pc.get();
122 pc[i] <= val;
123 end
124 endrule
126 // Send to Mixer
127 // Right now this is sorta retarded in that I pass from the output fifo into a new fifo
128 // But I have to mod a bunch of things to fix this and I am not sure I understand
129 // 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 begin
133 let coreOut <- cores[i].sampleOutput.get();
134 mixer.toMixer(AudioStream {voice : fromInteger(i), data:coreOut.data});
135 end
136 endrule
138 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) matches
148 tagged EndOfFile:
149 begin
150 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 with
153 //the other setting of channelFini at input except they are mutually
154 //exclusive since this is only hit after all input finished
155 end
156 tagged Sample .sample:
157 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample)));
158 endcase
159 endrule
161 // 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 endrule
172 */
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 audiostreams
177 rule fillFinished;
178 for (Integer i = 1; i < `MAX_VOICES; i = i+1)
179 begin
180 if (channelFini[i])
181 cores[i].sampleInput.put(AudioStream {voice : fromInteger(i), data: tagged Invalid});
182 end
183 endrule
185 (* 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 begin
197 $display("lsp: PIPE received EOF ");
198 inSample = tagged EndOfFile;
199 channelFini[channel] <= True;
200 end
201 else
202 begin
203 // $display("lsp: PIPE received Data ");
204 inSample = tagged Sample unpack(truncate(command.sample));
205 end
207 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 endrule
213 (* 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 endcase
224 endrule
226 endmodule