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@13
|
49 module [CONNECTED_MODULE] mkConnectedApplication ();
|
punk@51
|
50 Core core <- mkCore(`VDEV_SCRATCH_MEMORYA);
|
punk@51
|
51 Core anotherCore <- mkCore(`VDEV_SCRATCH_MEMORYB);
|
punk@53
|
52 Vector#(2, Volume) channelVols = replicate(127);
|
punk@53
|
53 Mixer mixer <- mkMixer(2, channelVols); //should be max voices but 2 for now
|
punk@53
|
54
|
punk@13
|
55 Reg#(int) cycle <- mkReg(0);
|
punk@53
|
56 Reg#(int) sampleCount <-mkReg(0);
|
punk@52
|
57 Vector#(2, Reg#(Bool)) ac_fini <- replicateM(mkReg(False));
|
punk@33
|
58
|
punk@53
|
59 // FIFO#(AudioProcessorUnit) coreOut <- mkFIFO();
|
punk@53
|
60 // Services Samples
|
punk@53
|
61 ClientStub_AUDIOCORERRR client_stub <- mkClientStub_AUDIOCORERRR();
|
punk@48
|
62
|
punk@13
|
63
|
punk@36
|
64 //-----------------------------------------------------------
|
punk@36
|
65 // Debug port
|
punk@36
|
66
|
punk@36
|
67 ServerStub_AUDIOCORERRR server_stub <- mkServerStub_AUDIOCORERRR();
|
punk@36
|
68
|
punk@36
|
69
|
punk@13
|
70 // this is for the tracing
|
punk@13
|
71 rule printCycles;
|
punk@13
|
72 cycle <= cycle+1;
|
punk@13
|
73 $fdisplay(stderr, " => Cycle = %d", cycle);
|
punk@13
|
74 endrule
|
punk@13
|
75
|
punk@53
|
76 // Send to Mixer
|
punk@53
|
77 // Right now this is sorta retarded in that I pass from the output fifo into a new fifo
|
punk@53
|
78 // But I have to mod a bunch of things to fix this and I am not sure I understand
|
punk@53
|
79 // things well enough to do this quickly. So here it is as it is for now.
|
punk@53
|
80 rule mix;
|
punk@53
|
81 let coreOut <- core.sampleOutput.get();
|
punk@53
|
82 let anotherOut <- anotherCore.sampleOutput.get();
|
punk@53
|
83 mixer.toMixer(AudioStream {voice : 0, data : tagged Valid coreOut});
|
punk@53
|
84 mixer.toMixer(AudioStream {voice : 1, data : tagged Valid anotherOut});
|
punk@53
|
85 endrule
|
punk@53
|
86
|
punk@48
|
87 rule feedOutput;
|
punk@53
|
88 // let pipelineData <- core.sampleOutput.get();
|
punk@53
|
89 let pipeOut <- mixer.mainOut.get();
|
punk@53
|
90
|
punk@13
|
91 AudioProcessorControl endOfFileTag = EndOfFile;
|
punk@13
|
92 AudioProcessorControl sampleTag = Data;
|
punk@13
|
93
|
punk@53
|
94 sampleCount <= sampleCount+1;
|
punk@53
|
95
|
punk@53
|
96 $display("PIPE writes sample %x\n", sampleCount);
|
punk@53
|
97 case (pipeOut) matches
|
punk@52
|
98 tagged EndOfFile:
|
punk@52
|
99 begin
|
punk@52
|
100 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?);
|
punk@52
|
101 ac_fini[0] <= True;
|
punk@52
|
102 end
|
punk@52
|
103 tagged Sample .sample:
|
punk@52
|
104 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample)));
|
punk@25
|
105 endcase
|
punk@53
|
106 endrule
|
punk@13
|
107
|
punk@52
|
108 // Programming ghetto style!
|
punk@52
|
109 // right now I am repeating this rule for my second core.
|
punk@53
|
110 /* (* conservative_implicit_conditions *)
|
punk@52
|
111 rule feedAnotherOutput;
|
punk@52
|
112 let pipelineData <- anotherCore.sampleOutput.get();
|
punk@52
|
113 AudioProcessorControl endOfFileTag = EndOfFile;
|
punk@52
|
114 AudioProcessorControl sampleTag = Data;
|
punk@52
|
115
|
punk@52
|
116 $display("PIPE writes another sample\n");
|
punk@52
|
117 case (pipelineData) matches
|
punk@52
|
118 tagged EndOfFile:
|
punk@52
|
119 begin
|
punk@52
|
120 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(endOfFileTag)),?);
|
punk@52
|
121 ac_fini[1] <= True;
|
punk@52
|
122 end
|
punk@52
|
123 tagged Sample .sample:
|
punk@52
|
124 client_stub.makeRequest_SendProcessedStream(zeroExtend(pack(sampleTag)), zeroExtend(pack(sample)));
|
punk@52
|
125 endcase
|
punk@52
|
126 endrule
|
punk@53
|
127 */
|
punk@52
|
128
|
punk@52
|
129 // Can generally just stick with the EOF but since I have two Cores no mixer...
|
punk@52
|
130 /*(* conservative_implicit_conditions *)
|
punk@52
|
131 rule sendTerminate;
|
punk@52
|
132 Bool done = True;
|
punk@52
|
133 for (Integer i = 1; i < 2; i = i+1)
|
punk@52
|
134 done = ac_fini[i] && done;
|
punk@52
|
135
|
punk@52
|
136 if (done)
|
punk@52
|
137 client_stub.makeRequest_SendTerminate(zeroExtend(pack(1)));
|
punk@52
|
138
|
punk@52
|
139 endrule
|
punk@52
|
140 */
|
punk@52
|
141
|
punk@36
|
142 //***** SERVER Side *****
|
punk@36
|
143
|
punk@52
|
144 (* conservative_implicit_conditions *)
|
punk@36
|
145 rule feedInput;
|
punk@36
|
146 let command <- server_stub.acceptRequest_SendUnprocessedStream();
|
punk@36
|
147 AudioProcessorControl ctrl = unpack(truncate(command.ctrl));
|
rlm@41
|
148
|
punk@52
|
149 VoiceId channel = unpack(truncate(command.channel));
|
punk@48
|
150 // $display("rlm: %x", test);
|
rlm@41
|
151
|
punk@52
|
152 AudioProcessorUnit inSample;
|
punk@52
|
153
|
punk@52
|
154 if(ctrl == EndOfFile)
|
punk@52
|
155 begin
|
punk@43
|
156 $display("lsp: PIPE received EOF ");
|
punk@52
|
157 inSample = tagged EndOfFile;
|
punk@52
|
158 // core.sampleInput.put(tagged EndOfFile);
|
punk@36
|
159 end
|
punk@36
|
160 else
|
punk@36
|
161 begin
|
punk@43
|
162 // $display("lsp: PIPE received Data ");
|
punk@52
|
163 // core.sampleInput.put(tagged Sample unpack(truncate(command.sample)));
|
punk@52
|
164 inSample = tagged Sample unpack(truncate(command.sample));
|
punk@52
|
165 end
|
punk@52
|
166
|
punk@52
|
167 case (channel)
|
punk@52
|
168 0 : core.sampleInput.put(inSample);
|
punk@52
|
169 1 : anotherCore.sampleInput.put(inSample);
|
punk@52
|
170 endcase
|
punk@52
|
171
|
punk@36
|
172 endrule
|
punk@13
|
173 endmodule
|