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