annotate modules/bluespec/Pygar/core/audioCorePipeline.bsv @ 62:90fa9b289aab pygar svn.63

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