Mercurial > pygar
diff modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 13:6d461680c6d9 pygar svn.14
[svn r14] more stuff
author | punk |
---|---|
date | Tue, 27 Apr 2010 09:03:28 -0400 |
parents | |
children | 90197e3375e2 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/bluespec/Pygar/core/AudioCoreSystem.cpp Tue Apr 27 09:03:28 2010 -0400 1.3 @@ -0,0 +1,146 @@ 1.4 +#include <stdio.h> 1.5 +#include <pthread.h> 1.6 +#include <semaphore.h> 1.7 + 1.8 +#include "asim/provides/connected_application.h" 1.9 +#include "asim/provides/stats_device.h" 1.10 +//#include "asim/provides/SndfileWavUtil.h" 1.11 + 1.12 +#include "asim/rrr/client_stub_AUDIOCORERRR.h" 1.13 + 1.14 +using namespace std; 1.15 + 1.16 +pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock; 1.17 +pthread_cond_t CONNECTED_APPLICATION_CLASS::cond; 1.18 +sem_t CONNECTED_APPLICATION_CLASS::throttle; 1.19 + 1.20 +// constructor 1.21 +CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) : 1.22 + clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this)) 1.23 +{ 1.24 +} 1.25 + 1.26 +// destructor 1.27 +CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS() 1.28 +{ 1.29 +} 1.30 + 1.31 +// init 1.32 +void 1.33 +CONNECTED_APPLICATION_CLASS::Init() 1.34 +{ 1.35 + 1.36 + pthread_mutex_init(&lock, NULL); 1.37 + pthread_cond_init(&cond, NULL); 1.38 + sem_init(&throttle, 0, 64); 1.39 + 1.40 + // enable stats 1.41 + STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats(); 1.42 +} 1.43 + 1.44 +void 1.45 +CONNECTED_APPLICATION_CLASS::UpdateSemaphore() 1.46 +{ 1.47 + sem_post(&throttle); 1.48 +} 1.49 + 1.50 +void 1.51 +CONNECTED_APPLICATION_CLASS::EndSimulation() 1.52 +{ 1.53 + printf("EndSimulation Called\n"); 1.54 + fflush(stdout); 1.55 + pthread_mutex_lock(&lock); 1.56 + // Do something about the race occuring here 1.57 + pthread_cond_signal(&cond); 1.58 + pthread_mutex_unlock(&lock); 1.59 + printf("EndSimulation done\n"); 1.60 + fflush(stdout); 1.61 +} 1.62 + 1.63 +// main 1.64 +void 1.65 +CONNECTED_APPLICATION_CLASS::Main() 1.66 +{ 1.67 + FILE *inputFile; 1.68 + UINT16 sample; 1.69 + 1.70 + // Convert input wav to pcm 1.71 + generate_pcm("input.wav","input.pcm"); 1.72 + 1.73 + //Send data to the machine here. 1.74 + inputFile = fopen("input.pcm","r"); 1.75 + assert(inputFile); 1.76 + 1.77 + 1.78 + int count = 0; 1.79 + 1.80 + printf("main: about to enter loop %d\n", count); 1.81 + 1.82 + while(fread(&sample, 2, 1, inputFile)) { 1.83 + if(count%1000 == 0) 1.84 + printf("main: %d\n", count); 1.85 + count++; 1.86 + sem_wait(&throttle); 1.87 + clientStub->SendUnprocessedStream(Data,(UINT32)sample); 1.88 + } 1.89 + 1.90 + printf("main: out of loop\n"); 1.91 + 1.92 + // Need to put lock here to prevent potential race condition 1.93 + pthread_mutex_lock(&lock); 1.94 + clientStub->SendUnprocessedStream(EndOfFile,0); 1.95 + 1.96 + printf("main: wait for end of file\n"); 1.97 + 1.98 + pthread_cond_wait(&cond, &lock); 1.99 + pthread_mutex_unlock(&lock); 1.100 + 1.101 + printf("main: lastt data out\n"); 1.102 + 1.103 + // Convert input wav to pcm 1.104 + generate_wav("out_hw.pcm","input.wav","out_hw.wav"); 1.105 + 1.106 + printf("generate wav done\n"); 1.107 + 1.108 + fflush(stdout); 1.109 + exit(0); 1.110 +} 1.111 + 1.112 +/* THIS IS THE CODE HANDLING FROM THE REGULAR SOFT-CORE 1.113 +TO BE INCORPORATED 1.114 +// main 1.115 +void 1.116 +CONNECTED_APPLICATION_CLASS::Main() 1.117 +{ 1.118 + int sleepCount = 0; 1.119 + int result = 0; 1.120 + 1.121 + fflush(stdout); 1.122 + 1.123 + while ((result = clientStub->ReadCPUToHost(0)) != 1) { 1.124 + sleep(1); 1.125 + //printf("System controller sleeps with result: %d\n", result); 1.126 + sleepCount++; 1.127 + if(sleepCount == 100) { 1.128 + printf("Failed to get response from hardware, bailing\n\n"); 1.129 + printf("This means that either your hardware is hanging\n"); 1.130 + printf("or that the software hasn't given it enough time\n"); 1.131 + printf("to complete. If you think it needs more time, then\n"); 1.132 + printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n"); 1.133 + printf("(connected_application)\n"); 1.134 + exit(0); 1.135 + } 1.136 + } 1.137 + 1.138 + if(result == 1) { 1.139 + printf("\n***PASSED***\n"); 1.140 + } 1.141 + 1.142 + // Dump the stats file 1.143 + 1.144 + STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats(); 1.145 + STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile(); 1.146 + 1.147 + fflush(stdout); 1.148 + exit(0); 1.149 +}*/