punk@13: #include punk@13: #include punk@13: #include punk@13: punk@13: #include "asim/provides/connected_application.h" punk@13: #include "asim/provides/stats_device.h" punk@13: //#include "asim/provides/SndfileWavUtil.h" punk@13: punk@13: #include "asim/rrr/client_stub_AUDIOCORERRR.h" punk@13: punk@13: using namespace std; punk@13: punk@13: pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; punk@13: pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; punk@13: sem_t CONNECTED_APPLICATION_CLASS::throttle; punk@13: punk@13: // constructor punk@13: CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : rlm@23: rlm@23: clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) punk@13: { punk@13: } punk@13: punk@13: // destructor punk@13: CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() punk@13: { punk@13: } punk@13: punk@13: // init punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::Init() punk@13: { punk@13: punk@13: pthread_mutex_init(&lock, NULL); punk@13: pthread_cond_init(&cond, NULL); punk@13: sem_init(&throttle, 0, 64); punk@13: punk@13: // enable stats punk@13: STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats(); punk@13: } punk@13: punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::UpdateSemaphore() punk@13: { punk@13: sem_post(&throttle); punk@13: } punk@13: punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::EndSimulation() punk@13: { punk@13: printf("EndSimulation Called\n"); punk@13: fflush(stdout); punk@13: pthread_mutex_lock(&lock); punk@13: // Do something about the race occuring here punk@13: pthread_cond_signal(&cond); punk@13: pthread_mutex_unlock(&lock); punk@13: printf("EndSimulation done\n"); punk@13: fflush(stdout); punk@13: } punk@13: punk@13: // main punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::Main() punk@13: { punk@13: FILE *inputFile; punk@13: UINT16 sample; punk@31: punk@31: //init processor punk@31: int sleepCount = 0; punk@31: int result = 0; punk@31: punk@31: bool coreFin = false; punk@31: punk@31: fflush(stdout); punk@31: punk@13: // Convert input wav to pcm punk@13: generate_pcm("input.wav","input.pcm"); punk@13: punk@13: //Send data to the machine here. punk@13: inputFile = fopen("input.pcm","r"); punk@13: assert(inputFile); punk@13: punk@13: int count = 0; punk@13: rlm@23: printf("main:PROCESSOR about to enter loop %d\n", count); punk@13: punk@13: while(fread(&sample, 2, 1, inputFile)) { punk@31: if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1) punk@31: { punk@31: sleepCount++; punk@31: if(sleepCount == 200) { punk@31: printf("Failed to get response from hardware, bailing\n\n"); punk@31: printf("This means that either your hardware is hanging\n"); punk@31: printf("or that the software hasn't given it enough time\n"); punk@31: printf("to complete. If you think it needs more time, then\n"); punk@31: printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n"); punk@31: printf("(connected_application)\n"); punk@31: } punk@31: } punk@31: else if (!coreFin && result == 1) punk@31: { punk@31: printf("\n***SOFT_CORE PASSED***\n"); punk@31: coreFin = true; punk@31: } punk@31: punk@13: if(count%1000 == 0) punk@13: printf("main: %d\n", count); punk@13: count++; punk@13: sem_wait(&throttle); punk@25: // printf("rlm:sending data to processor (%d)\n", count); punk@13: clientStub->SendUnprocessedStream(Data,(UINT32)sample); punk@31: punk@13: } punk@13: punk@13: printf("main: out of loop\n"); punk@13: punk@13: // Need to put lock here to prevent potential race condition punk@13: pthread_mutex_lock(&lock); punk@13: clientStub->SendUnprocessedStream(EndOfFile,0); punk@13: punk@13: printf("main: wait for end of file\n"); punk@13: punk@13: pthread_cond_wait(&cond, &lock); punk@13: pthread_mutex_unlock(&lock); punk@13: rlm@23: printf("main: last data out\n"); punk@13: punk@13: // Convert input wav to pcm punk@13: generate_wav("out_hw.pcm","input.wav","out_hw.wav"); punk@13: punk@13: printf("generate wav done\n"); punk@13: punk@31: printf("If you missed it, core ", coreFin ? "PASSED\n" : "FAILED\n"); punk@13: // Dump the stats file punk@13: punk@13: STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats(); punk@13: STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile(); punk@13: punk@31: fflush(stdout); punk@13: exit(0); punk@31: }