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) : punk@13: 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@13: 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: punk@13: int count = 0; punk@13: punk@13: printf("main: about to enter loop %d\n", count); punk@13: punk@13: while(fread(&sample, 2, 1, inputFile)) { punk@13: if(count%1000 == 0) punk@13: printf("main: %d\n", count); punk@13: count++; punk@13: sem_wait(&throttle); punk@13: clientStub->SendUnprocessedStream(Data,(UINT32)sample); 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: punk@13: printf("main: lastt 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@13: fflush(stdout); punk@13: exit(0); punk@13: } punk@13: punk@13: /* THIS IS THE CODE HANDLING FROM THE REGULAR SOFT-CORE punk@13: TO BE INCORPORATED punk@13: // main punk@13: void punk@13: CONNECTED_APPLICATION_CLASS::Main() punk@13: { punk@13: int sleepCount = 0; punk@13: int result = 0; punk@13: punk@13: fflush(stdout); punk@13: punk@13: while ((result = clientStub->ReadCPUToHost(0)) != 1) { punk@13: sleep(1); punk@13: //printf("System controller sleeps with result: %d\n", result); punk@13: sleepCount++; punk@13: if(sleepCount == 100) { punk@13: printf("Failed to get response from hardware, bailing\n\n"); punk@13: printf("This means that either your hardware is hanging\n"); punk@13: printf("or that the software hasn't given it enough time\n"); punk@13: printf("to complete. If you think it needs more time, then\n"); punk@13: printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n"); punk@13: printf("(connected_application)\n"); punk@13: exit(0); punk@13: } punk@13: } punk@13: punk@13: if(result == 1) { punk@13: printf("\n***PASSED***\n"); punk@13: } punk@13: 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@13: fflush(stdout); punk@13: exit(0); punk@13: }*/