view modules/bluespec/Pygar/core/#AudioCoreSystem.cpp# @ 15:a1833d9f6e3d pygar svn.16

[svn r16] Recent
author punk
date Tue, 27 Apr 2010 13:11:45 -0400
parents 6d461680c6d9
children
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) :
19 clientStub(new AUDIOCORERRR_CLIENT_STUB_CLASS(this))
20 {
21 }
23 // destructor
24 CONNECTED_APPLICATION_CLASS::~CONNECTED_APPLICATION_CLASS()
25 {
26 }
28 // init
29 void
30 CONNECTED_APPLICATION_CLASS::Init()
31 {
33 pthread_mutex_init(&lock, NULL);
34 pthread_cond_init(&cond, NULL);
35 sem_init(&throttle, 0, 64);
37 // enable stats
38 STATS_DEVICE_SERVER_CLASS::GetInstance()->SetupStats();
39 }
41 void
42 CONNECTED_APPLICATION_CLASS::UpdateSemaphore()
43 {
44 sem_post(&throttle);
45 }
47 void
48 CONNECTED_APPLICATION_CLASS::EndSimulation()
49 {
50 printf("EndSimulation Called\n");
51 fflush(stdout);
52 pthread_mutex_lock(&lock);
53 // Do something about the race occuring here
54 pthread_cond_signal(&cond);
55 pthread_mutex_unlock(&lock);
56 printf("EndSimulation done\n");
57 fflush(stdout);
58 }
60 // main
61 void
62 CONNECTED_APPLICATION_CLASS::Main()
63 {
64 FILE *inputFile;
65 UINT16 sample;
67 // Convert input wav to pcm
68 generate_pcm("input.wav","input.pcm");
70 //Send data to the machine here.
71 inputFile = fopen("input.pcm","r");
72 assert(inputFile);
75 int count = 0;
77 printf("main: about to enter loop %d\n", count);
79 while(fread(&sample, 2, 1, inputFile)) {
80 if(count%1000 == 0)
81 printf("main: %d\n", count);
82 count++;
83 sem_wait(&throttle);
84 clientStub->SendUnprocessedStream(Data,(UINT32)sample);
85 }
87 printf("main: out of loop\n");
89 // Need to put lock here to prevent potential race condition
90 pthread_mutex_lock(&lock);
91 clientStub->SendUnprocessedStream(EndOfFile,0);
93 printf("main: wait for end of file\n");
95 pthread_cond_wait(&cond, &lock);
96 pthread_mutex_unlock(&lock);
98 printf("main: lastt data out\n");
100 // Convert input wav to pcm
101 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
103 printf("generate wav done\n");
105 fflush(stdout);
106 exit(0);
107 }
109 /* THIS IS THE CODE HANDLING FROM THE REGULAR SOFT-CORE
110 TO BE INCORPORATED
111 // main
112 void
113 CONNECTED_APPLICATION_CLASS::Main()
114 {
115 int sleepCount = 0;
116 int result = 0;
118 fflush(stdout);
120 while ((result = clientStub->ReadCPUToHost(0)) != 1) {
121 sleep(1);
122 //printf("System controller sleeps with result: %d\n", result);
123 sleepCount++;
124 if(sleepCount == 100) {
125 printf("Failed to get response from hardware, bailing\n\n");
126 printf("This means that either your hardware is hanging\n");
127 printf("or that the software hasn't given it enough time\n");
128 printf("to complete. If you think it needs more time, then\n");
129 printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n");
130 printf("(connected_application)\n");
131 exit(0);
132 }
133 }
135 if(result == 1) {
136 printf("\n***PASSED***\n");
137 }
139 // Dump the stats file
141 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();
142 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();
144 fflush(stdout);
145 exit(0);
146 }*/