view modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 23:90197e3375e2 pygar svn.24

[svn r24] added testing, but something is wrong with our c++ file.
author rlm
date Wed, 28 Apr 2010 08:19:09 -0400
parents 6d461680c6d9
children 220c14f5963c
line wrap: on
line source
1 #include <stdio.h>
2 #include <pthread.h>
3 #include <semaphore.h>
5 #include "asim/provides/connected_application.h"
6 #include "asim/provides/stats_device.h"
7 //#include "asim/provides/SndfileWavUtil.h"
9 #include "asim/rrr/client_stub_AUDIOCORERRR.h"
11 using namespace std;
13 pthread_mutex_t CONNECTED_APPLICATION_CLASS::lock;
14 pthread_cond_t CONNECTED_APPLICATION_CLASS::cond;
15 sem_t CONNECTED_APPLICATION_CLASS::throttle;
17 // constructor
18 CONNECTED_APPLICATION_CLASS::CONNECTED_APPLICATION_CLASS(VIRTUAL_PLATFORM vp) :
20 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this))
21 {
22 }
24 // destructor
25 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()
26 {
27 }
29 // init
30 void
31 CONNECTED_APPLICATION_CLASS::Init()
32 {
34 pthread_mutex_init(&lock, NULL);
35 pthread_cond_init(&cond, NULL);
36 sem_init(&throttle, 0, 64);
38 // enable stats
39 STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats();
40 }
42 void
43 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()
44 {
45 sem_post(&throttle);
46 }
48 void
49 CONNECTED_APPLICATION_CLASS::EndSimulation()
50 {
51 printf("EndSimulation Called\n");
52 fflush(stdout);
53 pthread_mutex_lock(&lock);
54 // Do something about the race occuring here
55 pthread_cond_signal(&cond);
56 pthread_mutex_unlock(&lock);
57 printf("EndSimulation done\n");
58 fflush(stdout);
59 }
61 // main
62 void
63 CONNECTED_APPLICATION_CLASS::Main()
64 {
65 FILE *inputFile;
66 UINT16 sample;
68 // Convert input wav to pcm
69 generate_pcm("input.wav","input.pcm");
71 //Send data to the machine here.
72 inputFile = fopen("input.pcm","r");
73 assert(inputFile);
76 int count = 0;
78 printf("main:PROCESSOR about to enter loop %d\n", count);
80 while(fread(&sample, 2, 1, inputFile)) {
81 if(count%1000 == 0)
82 printf("main: %d\n", count);
83 count++;
84 sem_wait(&throttle);
85 printf("rlm:sending data to processor (%d)\n", count);
86 clientStub->SendUnprocessedStream(Data,(UINT32)sample);
87 }
89 printf("main: out of loop\n");
91 // Need to put lock here to prevent potential race condition
92 pthread_mutex_lock(&lock);
93 clientStub->SendUnprocessedStream(EndOfFile,0);
95 printf("main: wait for end of file\n");
97 pthread_cond_wait(&cond, &lock);
98 pthread_mutex_unlock(&lock);
100 printf("main: last data out\n");
102 // Convert input wav to pcm
103 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
105 printf("generate wav done\n");
107 fflush(stdout);
108 exit(0);
109 }
111 /* THIS IS THE CODE HANDLING FROM THE REGULAR SOFT-CORE
112 TO BE INCORPORATED
113 // main
114 void
115 CONNECTED_APPLICATION_CLASS::Main()
116 {
117 int sleepCount = 0;
118 int result = 0;
120 fflush(stdout);
122 while ((result = clientStub->ReadCPUToHost(0)) != 1) {
123 sleep(1);
124 //printf("System controller sleeps with result: %d\n", result);
125 sleepCount++;
126 if(sleepCount == 100) {
127 printf("Failed to get response from hardware, bailing\n\n");
128 printf("This means that either your hardware is hanging\n");
129 printf("or that the software hasn't given it enough time\n");
130 printf("to complete. If you think it needs more time, then\n");
131 printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n");
132 printf("(connected_application)\n");
133 exit(0);
134 }
135 }
137 if(result == 1) {
138 printf("\n***PASSED***\n");
139 }
141 // Dump the stats file
143 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();
144 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();
146 fflush(stdout);
147 exit(0);
148 }*/