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