view modules/bluespec/Pygar/core/AudioCoreSystem.cpp @ 31:f41eef1bebfc pygar svn.32

[svn r32] Attempting to run soft core and audio
author punk
date Sat, 01 May 2010 11:50:20 -0400
parents 220c14f5963c
children 0c775e733b81
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 //init processor
69 int sleepCount = 0;
70 int result = 0;
72 bool coreFin = false;
74 fflush(stdout);
76 // Convert input wav to pcm
77 generate_pcm("input.wav","input.pcm");
79 //Send data to the machine here.
80 inputFile = fopen("input.pcm","r");
81 assert(inputFile);
83 int count = 0;
85 printf("main:PROCESSOR about to enter loop %d\n", count);
87 while(fread(&sample, 2, 1, inputFile)) {
88 if (!coreFin && (result = clientStub->ReadCPUToHost(0)) != 1)
89 {
90 sleepCount++;
91 if(sleepCount == 200) {
92 printf("Failed to get response from hardware, bailing\n\n");
93 printf("This means that either your hardware is hanging\n");
94 printf("or that the software hasn't given it enough time\n");
95 printf("to complete. If you think it needs more time, then\n");
96 printf("edit CONNECTED_APPLICATION_CLASS::Main() in ProcessorSystem.cpp\n");
97 printf("(connected_application)\n");
98 }
99 }
100 else if (!coreFin && result == 1)
101 {
102 printf("\n***SOFT_CORE PASSED***\n");
103 coreFin = true;
104 }
106 if(count%1000 == 0)
107 printf("main: %d\n", count);
108 count++;
109 sem_wait(&throttle);
110 // printf("rlm:sending data to processor (%d)\n", count);
111 clientStub->SendUnprocessedStream(Data,(UINT32)sample);
113 }
115 printf("main: out of loop\n");
117 // Need to put lock here to prevent potential race condition
118 pthread_mutex_lock(&lock);
119 clientStub->SendUnprocessedStream(EndOfFile,0);
121 printf("main: wait for end of file\n");
123 pthread_cond_wait(&cond, &lock);
124 pthread_mutex_unlock(&lock);
126 printf("main: last data out\n");
128 // Convert input wav to pcm
129 generate_wav("out_hw.pcm","input.wav","out_hw.wav");
131 printf("generate wav done\n");
133 printf("If you missed it, core ", coreFin ? "PASSED\n" : "FAILED\n");
134 // Dump the stats file
136 STATS_DEVICE_SERVER_CLASS::GetInstance()->DumpStats();
137 STATS_DEVICE_SERVER_CLASS::GetInstance()->EmitFile();
139 fflush(stdout);
140 exit(0);
141 }