annotate modules/bluespec/Pygar/core/revACS.cpp @ 71:86360c5ae9f2 pygar svn.72

[svn r72] added config for htg
author punk
date Wed, 12 May 2010 00:21:40 -0400
parents 5c963ab14143
children
rev   line source
punk@69 1 #include <stdio.h>
punk@69 2 #include <pthread.h>
punk@69 3 #include <semaphore.h>
punk@69 4
punk@69 5 #include "asim/provides/connected_application.h"
punk@69 6 #include "asim/provides/stats_device.h"
punk@69 7 //#include "asim/provides/SndfileWavUtil.h"
punk@69 8
punk@69 9 #include "asim/rrr/client_stub_AUDIOCORERRR.h"
punk@69 10
punk@69 11 using namespace std;
punk@69 12
punk@69 13 #define NUM_VOICES 2
punk@69 14
punk@69 15 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock;
punk@69 16 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond;
punk@69 17 sem_t CONNECTED_APPLICATION_CLASS::throttle;
punk@69 18
punk@69 19 // constructor
punk@69 20 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :
punk@69 21
punk@69 22 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this))
punk@69 23 {
punk@69 24 }
punk@69 25
punk@69 26 // destructor
punk@69 27 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()
punk@69 28 {
punk@69 29 }
punk@69 30
punk@69 31 // init
punk@69 32 void
punk@69 33 CONNECTED_APPLICATION_CLASS::Init()
punk@69 34 {
punk@69 35
punk@69 36 pthread_mutex_init(&lock, NULL);
punk@69 37 pthread_cond_init(&cond, NULL);
punk@69 38 sem_init(&throttle, 0, 64);
punk@69 39
punk@69 40 // enable stats
punk@69 41 STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats();
punk@69 42 }
punk@69 43
punk@69 44 void
punk@69 45 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()
punk@69 46 {
punk@69 47 sem_post(&throttle);
punk@69 48 }
punk@69 49
punk@69 50 void
punk@69 51 CONNECTED_APPLICATION_CLASS::EndSimulation()
punk@69 52 {
punk@69 53 printf("EndSimulation Called\n");
punk@69 54 fflush(stdout);
punk@69 55 pthread_mutex_lock(&lock);
punk@69 56 // Do something about the race occuring here
punk@69 57 pthread_cond_signal(&cond);
punk@69 58 pthread_mutex_unlock(&lock);
punk@69 59 printf("EndSimulation done\n");
punk@69 60 fflush(stdout);
punk@69 61 }
punk@69 62
punk@69 63 // main
punk@69 64 void
punk@69 65 CONNECTED_APPLICATION_CLASS::Main()
punk@69 66 {
punk@69 67 //rlm: two files
punk@69 68 FILE* inputFiles[NUM_VOICES];
punk@69 69 // FILE *inputFile;
punk@69 70 // FILE *inputFile1;
punk@69 71 UINT16 sample;
punk@69 72 UINT16 sample1;
punk@69 73
punk@69 74 //rlm: not sure if normal ints are ok here; using UINT16 because I know it works
punk@69 75 UINT16 channel0 = 0;
punk@69 76 UINT16 channel1 = 1;
punk@69 77
punk@69 78 //init processor
punk@69 79 int sleepCount = 0;
punk@69 80 int result = 0;
punk@69 81
punk@69 82 bool coreFin = false;
punk@69 83
punk@69 84 fflush(stdout);
punk@69 85
punk@69 86 // Convert input wav to pcm
punk@69 87
punk@69 88 printf("word\n");
punk@69 89
punk@69 90 for (int i = 0; i < NUM_VOICES; i++)
punk@69 91 {
punk@69 92 char* filename;
punk@69 93 sprintf(filename, "input%d", i);
punk@69 94
punk@69 95 printf("Opening audio file %s", strcat(filename, ".wav"));
punk@69 96 generate_pcm(strcat(filename, ".wav"),strcat(filename, ".pcm"));
punk@69 97 // generate_pcm("input1.wav", "input1.pcm");
punk@69 98
punk@69 99 inputFiles[i] = fopen(strcat(filename, ".pcm"), "r");
punk@69 100
punk@69 101 assert(inputFiles[i]);
punk@69 102 }
punk@69 103 /*
punk@69 104 //rlm: for now we are going to going to just have 2 files with "common names"
punk@69 105 generate_pcm("input.wav","input.pcm");
punk@69 106 generate_pcm("input1.wav", "input1.pcm");
punk@69 107 //Send data to the machine here.
punk@69 108 //rlm: two files
punk@69 109 inputFile = fopen("input.pcm","r");
punk@69 110 inputFile1 = fopen("input1.pcm", "r");
punk@69 111 assert(inputFile1);
punk@69 112 assert(inputFile);
punk@69 113 */
punk@69 114
punk@69 115 int count = 0;
punk@69 116
punk@69 117 printf("main:PROCESSOR about to enter loop %d\n", count);
punk@69 118
punk@69 119 //rlm: here we read both files. later refactor into a function.
punk@69 120 // also, this will terminate when the FIRST file reaches its end.
punk@69 121 while( (fread(&sample, 2, 1, inputFiles[0])) || (fread(&sample1, 2 , 1, inputFiles[1])))
punk@69 122 { /*
punk@69 123 printf("hi\n");
punk@69 124 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1)
punk@69 125 {
punk@69 126 sleepCount++;
punk@69 127 }
punk@69 128 else if (!coreFin && result == 1)
punk@69 129 {
punk@69 130 printf("\n***SOFT_CORE PASSED***\n");
punk@69 131 coreFin = true;
punk@69 132 }
punk@69 133 */
punk@69 134
punk@69 135 if(count%1000 == 0)
punk@69 136 printf("main: %d\n", count);
punk@69 137 count++;
punk@69 138 sem_wait(&throttle);
punk@69 139
punk@69 140 //rlm: two files.
punk@69 141 // clientStub->SendUnprocessedStream( Data,(UINT32)sample);
punk@69 142 clientStub->SendUnprocessedStream((UINT32)channel0 , Data,(UINT32)sample);
punk@69 143 clientStub->SendUnprocessedStream((UINT32)channel1 , Data,(UINT32)sample1);
punk@69 144 }
punk@69 145
punk@69 146 printf("main: out of loop\n");
punk@69 147
punk@69 148 // Need to put lock here to prevent potential race condition
punk@69 149 pthread_mutex_lock(&lock);
punk@69 150
punk@69 151 //rlm: have to send end-files to both voices.
punk@69 152 // all of these operations wil eventually be moved into functions.
punk@69 153 //clientStub->SendUnprocessedStream(EndOfFile,0);
punk@69 154 clientStub->SendUnprocessedStream((UINT32)channel0, EndOfFile,0);
punk@69 155 clientStub->SendUnprocessedStream((UINT32)channel1, EndOfFile,0);
punk@69 156
punk@69 157 printf("main: wait for end of file\n");
punk@69 158
punk@69 159 pthread_cond_wait(&cond, &lock);
punk@69 160 pthread_mutex_unlock(&lock);
punk@69 161
punk@69 162 printf("main: last data out\n");
punk@69 163
punk@69 164 // Convert input wav to pcm
punk@69 165 // this part is ok because there is always only one input file.
punk@69 166 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
punk@69 167
punk@69 168 printf("generate wav done\n");
punk@69 169
punk@69 170 // printf("If you missed it, core %s", coreFin ? "PASSED\n" : "FAILED\n");
punk@69 171 // Dump the stats file
punk@69 172
punk@69 173 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();
punk@69 174 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();
punk@69 175
punk@69 176 fflush(stdout);
punk@69 177 // exit(0);
punk@69 178 }