annotate modules/bluespec/Pygar/core/AudioCoreRRR.cpp @ 33:2c8166d205d5 pygar svn.34

[svn r34] uses scratchpad, set up for audio through c
author punk
date Tue, 04 May 2010 10:13:53 -0400
parents 220c14f5963c
children 49049f97312c
rev   line source
punk@13 1 #include <cstdio>
punk@13 2 #include <cstdlib>
punk@13 3 #include <iostream>
punk@13 4 #include <iomanip>
punk@13 5 #include <stdio.h>
punk@13 6 #include <sys/stat.h>
punk@13 7
punk@13 8 #include "asim/rrr/service_ids.h"
punk@13 9
punk@13 10 #include "asim/provides/connected_application.h"
punk@13 11
punk@13 12 using namespace std;
punk@13 13
punk@13 14 // ===== service instantiation =====
punk@13 15 AUDIOCORERRR_SERVER_CLASS AUDIOCORERRR_SERVER_CLASS::instance;
punk@13 16
punk@13 17 // constructor
punk@13 18 AUDIOCORERRR_SERVER_CLASS::AUDIOCORERRR_SERVER_CLASS() :
punk@15 19 serverStub(new AUDIOCORERRR_SERVER_STUB_CLASS(this))
punk@13 20 {
punk@13 21 // instantiate stub
rlm@23 22
rlm@23 23 printf("rlm: init called\n\n");
punk@13 24 outputFile = NULL;
punk@13 25 memory = NULL;
punk@13 26 fflush(stdout);
punk@13 27 }
punk@13 28
punk@13 29 // destructor
punk@13 30 AUDIOCORERRR_SERVER_CLASS::~AUDIOCORERRR_SERVER_CLASS()
punk@13 31 {
rlm@23 32 printf("rlm: AUDIOCORERRR_SERVER_CLASS::~AUDIOCORERRR_SERVER_CLASS()\n");
punk@13 33 Cleanup();
punk@13 34 }
punk@13 35
punk@13 36 // init
punk@13 37 void
punk@13 38 AUDIOCORERRR_SERVER_CLASS::Init(PLATFORMS_MODULE p)
punk@13 39 {
rlm@23 40 printf("rlm: AUDIOCORERRR_SERVER_CLASS::Init(PLATFORMS_MODULE p)\n");
rlm@23 41 parent = p;
punk@13 42 }
punk@13 43
punk@13 44 // uninit
punk@13 45 void
punk@13 46 AUDIOCORERRR_SERVER_CLASS::Uninit()
punk@13 47 {
rlm@23 48 printf("rlm: AUDIOCORERRR_SERVER_CLASS::Uninit()\n");
rlm@23 49 Cleanup();
punk@13 50 }
punk@13 51
punk@13 52 // cleanup
punk@13 53 void
punk@13 54 AUDIOCORERRR_SERVER_CLASS::Cleanup()
punk@13 55 {
rlm@23 56 printf("rlm: AUDIOCORERRR_SERVER_CLASS::Cleanup() \n\n");
rlm@23 57 delete serverStub;
punk@13 58 }
punk@13 59
punk@13 60
punk@13 61 //
punk@13 62 // RRR service methods
punk@13 63 //
punk@13 64
punk@33 65 /* Not used by scratchpad
punk@13 66 UINT32
punk@13 67 AUDIOCORERRR_SERVER_CLASS::MemoryRequestLoad (UINT32 address)
punk@13 68 {
punk@13 69 UINT32 returnVal;
rlm@23 70 printf("rlm: AUDIOCORERRR_SERVER_CLASS::MemoryRequestLoad (UINT32 address)\n");
punk@13 71 if(memory == NULL) {
punk@13 72 memory = new FUNCP_SIMULATED_MEMORY_CLASS();
punk@13 73 }
punk@13 74
punk@13 75
punk@13 76 memory->Read(0,(UINT64) address, sizeof(UINT32), &returnVal);
punk@13 77 return returnVal;
punk@13 78 }
punk@13 79
punk@13 80 void
punk@13 81 AUDIOCORERRR_SERVER_CLASS::MemoryRequestStore (UINT32 address, UINT32 data)
punk@13 82 {
rlm@23 83 printf("rlm: AUDIOCORERRR_SERVER_CLASS::MemoryRequestStore (UINT32 address, UINT32 data)\n");
punk@13 84 if(memory == NULL) {
punk@13 85 memory = new FUNCP_SIMULATED_MEMORY_CLASS();
punk@13 86 }
punk@13 87
punk@13 88 memory->Write(0,(UINT64) address, sizeof(UINT32), &data);
punk@22 89 }
punk@33 90 */
punk@13 91
punk@13 92 void
punk@13 93
punk@13 94 AUDIOCORERRR_SERVER_CLASS::SendProcessedStream(UINT16 control, UINT16 data)
punk@13 95 {
punk@13 96
punk@25 97 // printf("rlm: SendProcessedStream called,\n");
punk@13 98 AudioProcessorControl audioProcessorControl = (AudioProcessorControl) control;
punk@13 99 switch(control) {
punk@13 100 case EndOfFile:
punk@13 101 if(outputFile != NULL) {
rlm@23 102 printf("rlm: FILE is NULL\n");
punk@13 103 fflush(outputFile);
punk@13 104 fclose(outputFile);
punk@13 105 outputFile = NULL;
punk@13 106 } else {
rlm@23 107 printf("rlm: Opening file for output.\n");
punk@13 108 outputFile = fopen("out_hw.pcm","w");
punk@13 109 assert(outputFile);
punk@13 110 fflush(outputFile);
punk@13 111 fclose(outputFile);
punk@13 112 }
punk@13 113
punk@13 114 // Long term this should be in the data portion. But until I have code running, keep it here.
punk@13 115 CONNECTED_APPLICATION_CLASS::EndSimulation();
punk@13 116 break;
punk@13 117
punk@13 118 case Data:
punk@13 119 if(outputFile == NULL) {
punk@13 120 outputFile = fopen("out_hw.pcm","w");
punk@13 121 assert(outputFile);
punk@13 122 }
punk@13 123
rlm@23 124 CONNECTED_APPLICATION_CLASS::UpdateSemaphore();
punk@25 125 // printf("rlm: writing data to out_hw.pcm\n");
punk@13 126 fwrite(&data, 2,1 , outputFile);
punk@13 127 break;
punk@13 128 }
punk@13 129 }