view modules/bluespec/Pygar/core/AudioCoreRRR.cpp @ 23:90197e3375e2 pygar svn.24

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