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 {
|
punk@13
|
65 FILE *inputFile;
|
punk@13
|
66 UINT16 sample;
|
punk@13
|
67
|
punk@13
|
68 // Convert input wav to pcm
|
punk@13
|
69 generate_pcm("input.wav","input.pcm");
|
punk@13
|
70
|
punk@13
|
71 //Send data to the machine here.
|
punk@13
|
72 inputFile = fopen("input.pcm","r");
|
punk@13
|
73 assert(inputFile);
|
punk@13
|
74
|
punk@13
|
75
|
punk@13
|
76 int count = 0;
|
punk@13
|
77
|
rlm@23
|
78 printf("main:PROCESSOR about to enter loop %d\n", count);
|
punk@13
|
79
|
punk@13
|
80 while(fread(&sample, 2, 1, inputFile)) {
|
punk@13
|
81 if(count%1000 == 0)
|
punk@13
|
82 printf("main: %d\n", count);
|
punk@13
|
83 count++;
|
punk@13
|
84 sem_wait(&throttle);
|
punk@25
|
85 // printf("rlm:sending data to processor (%d)\n", count);
|
punk@13
|
86 clientStub->SendUnprocessedStream(Data,(UINT32)sample);
|
punk@13
|
87 }
|
punk@13
|
88
|
punk@13
|
89 printf("main: out of loop\n");
|
punk@13
|
90
|
punk@13
|
91 // Need to put lock here to prevent potential race condition
|
punk@13
|
92 pthread_mutex_lock(&lock);
|
punk@13
|
93 clientStub->SendUnprocessedStream(EndOfFile,0);
|
punk@13
|
94
|
punk@13
|
95 printf("main: wait for end of file\n");
|
punk@13
|
96
|
punk@13
|
97 pthread_cond_wait(&cond, &lock);
|
punk@13
|
98 pthread_mutex_unlock(&lock);
|
punk@13
|
99
|
rlm@23
|
100 printf("main: last data out\n");
|
punk@13
|
101
|
punk@13
|
102 // Convert input wav to pcm
|
punk@13
|
103 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
|
punk@13
|
104
|
punk@13
|
105 printf("generate wav done\n");
|
punk@13
|
106
|
punk@13
|
107 fflush(stdout);
|
punk@13
|
108 exit(0);
|
punk@13
|
109 }
|
punk@13
|
110
|
punk@13
|
111 /* THIS IS THE CODE HANDLING FROM THE REGULAR SOFT-CORE
|
punk@13
|
112 TO BE INCORPORATED
|
punk@13
|
113 // main
|
punk@13
|
114 void
|
punk@13
|
115 CONNECTED_APPLICATION_CLASS::Main()
|
punk@13
|
116 {
|
punk@13
|
117 int sleepCount = 0;
|
punk@13
|
118 int result = 0;
|
punk@13
|
119
|
punk@13
|
120 fflush(stdout);
|
punk@13
|
121
|
punk@13
|
122 while ((result = clientStub->ReadCPUToHost(0)) != 1) {
|
punk@13
|
123 sleep(1);
|
punk@13
|
124 //printf("System controller sleeps with result: %d\n", result);
|
punk@13
|
125 sleepCount++;
|
punk@13
|
126 if(sleepCount == 100) {
|
punk@13
|
127 printf("Failed to get response from hardware, bailing\n\n");
|
punk@13
|
128 printf("This means that either your hardware is hanging\n");
|
punk@13
|
129 printf("or that the software hasn't given it enough time\n");
|
punk@13
|
130 printf("to complete. If you think it needs more time, then\n");
|
punk@13
|
131 printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n");
|
punk@13
|
132 printf("(connected_application)\n");
|
punk@13
|
133 exit(0);
|
punk@13
|
134 }
|
punk@13
|
135 }
|
punk@13
|
136
|
punk@13
|
137 if(result == 1) {
|
punk@13
|
138 printf("\n***PASSED***\n");
|
punk@13
|
139 }
|
punk@13
|
140
|
punk@13
|
141 // Dump the stats file
|
punk@13
|
142
|
punk@13
|
143 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();
|
punk@13
|
144 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();
|
punk@13
|
145
|
punk@13
|
146 fflush(stdout);
|
punk@13
|
147 exit(0);
|
punk@13
|
148 }*/
|