-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateInterface.cpp
More file actions
268 lines (227 loc) · 8.16 KB
/
createInterface.cpp
File metadata and controls
268 lines (227 loc) · 8.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
////////////////////////////////////////////////////////////
// ESLCompiler
//==========================================================
//
// Author: TangSZ Time: 2012
// Department: MicroE of Shanghai Jiao Tong University
//----------------------------------------------------------
// This file generates a data interface file for ESL project,
// which needs a formal_map.h file as input and then generate
// an interface file used in ESL platform.
//
////////////////////////////////////////////////////////////
#include "rpucfg.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
int createInterface(const String & fileName, RPUConfig &config){
using std::cerr;
using std::endl;
using std::cout;
//const char * underline = "__";
//const char * functionNode = "_NODE";
//std::string::size_type fileNameBegin = fileName.find(underline)+2;
//std::string::size_type fileNameEnd = fileName.find(functionNode);
//std::string::size_type fileNameSubLength = fileNameEnd - fileNameBegin;
//String mapNameTemp = fileName.substr(fileNameBegin, fileNameSubLength) + "_formal_map.h";
String mapNameTemp = fileName.substr(0) + "_formal_map.h";
const char * mapFileName = mapNameTemp.c_str();
std::ifstream mapFile(mapFileName);
if(!mapFile)
{
cerr<<"Can't open file data.txt'\""<<mapFileName<<"\""<<endl;
return -1;
}
//int mapLoopTime = 0;
std::string line;
//std::string tempLoopData;
//getline(mapFile, line);
//std::istringstream stream(line);
//while (stream>>tempLoopData)
//{
// mapLoopTime++;
//}
//mapLoopTime = mapLoopTime - 2;
//config.setLoopTime(mapLoopTime);
const int loopTime = config.getLoopTime();
// Read map.h
int inNum = 0;
int outNum = 0;
char * equal = "_scalar";
DFGraph dfg_graph;
dfg_graph = config.graph();
String graphName=dfg_graph.name();
int inportSize = dfg_graph.inSize();
int outportSize = dfg_graph.outSize();
std::string tempScalar[32];
std::string **In = new std::string *[inportSize];
for(int j=0; j<inportSize; j++)
{
In[j] = new std::string[loopTime];
}
std::string **Out = new std::string *[outportSize];
for(int j=0; j<outportSize; j++)
{
Out[j] = new std::string[loopTime];
}
//do {
// if (line == "") continue;
// std::istringstream stream(line);
// for (int i=0; i<(loopTime+2); i++)
// {
// stream>>tempScalar[i];
// }
// if (strncmp(tempScalar[0].data(), equal,7) == 0)
// {
// for (int j=0; j<loopTime; j++)
// {
// In[inNum][j] = tempScalar[j+2];
// }
// inNum++;
// }
// else if (strncmp(tempScalar[loopTime+1].data(), equal,7) == 0)
// {
// for (int j=0; j<loopTime; j++)
// {
// Out[outNum][j] = tempScalar[j];
// }
// outNum++;
// }
// else std::cout<<"Incorrect!"<<std::endl;
//}
//while (getline(mapFile, line));
while (getline(mapFile, line)) {
if (line == "") continue;
std::istringstream stream(line);
for (int i=0; i<(loopTime+2); i++)
{
stream>>tempScalar[i];
}
if (strncmp(tempScalar[0].data(), equal,7) == 0)
{
for (int j=0; j<loopTime; j++)
{
In[inNum][j] = tempScalar[j+2];
}
inNum++;
}
else if (strncmp(tempScalar[loopTime+1].data(), equal,7) == 0)
{
for (int j=0; j<loopTime; j++)
{
Out[outNum][j] = tempScalar[j];
}
outNum++;
}
else std::cout<<"Incorrect!"<<std::endl;
}
//while (getline(mapFile, line));
const String SSRAM_interface =config.graph().name()+"_interface.h";
std::ofstream SSRAMinterfaceFile(SSRAM_interface.c_str());
assert(SSRAMinterfaceFile);
String portName;
int portSSRAM;
DFGPort * currInport;
DFGPort * currOutport;
//DFGVarPort * varPort;
int z;
int scalarInNum;
int ssramOutTopAddr, ssramOutBaseAddr;
RCA * ssramInPtr = config.rcas().begin()->get();
ssramOutTopAddr = config.rcas().back()->rcaSSRAMOutTopAddr();
ssramOutBaseAddr = config.rcas().back()->rcaSSRAMOutBaseAddr();
/* RCA ssramOutTopSize =config.rcas().back()->rcaSSRAMOutBaseAddr();*/
int ssramInSize = ssramInPtr->rcaSSRAMInTopAddr() - ssramInPtr->rcaSSRAMInBaseAddr();
int ssramOutSize = ssramOutTopAddr - ssramOutBaseAddr;
/* ssramInPtr = ssramInPtr + config.allRCAs().size()-1;*/
/* int ssramOutTopSize = ssramOutPtr->rcaSSRAMOutTopAddr();
int ssramOutBaseSize = ssramOutPtr->rcaSSRAMOutBaseAddr();*/
char tempUperString[256];
strcpy(tempUperString, graphName.c_str());
//int graphNamelength,i;
int graphNamelength;
graphNamelength=strlen(tempUperString);
for(int i=0;i<graphNamelength;i++)
{
tempUperString[i]=toupper(tempUperString[i]);
}
SSRAMinterfaceFile<<
"#define "<<tempUperString<<"_DIN \\\n";
for (int currLoopTime=0; currLoopTime < loopTime; currLoopTime++)
{
scalarInNum = 0;
for(z=0; z<inportSize; z++)
{
currInport = (&dfg_graph.inport(z));
if(!(currInport->isImmPort()))
{
portName = static_cast<DFGVarPort*>(currInport)->name();
if (portName.find("scalar") != -1)
{
portName = In[scalarInNum][currLoopTime];
portSSRAM = (*currInport).SSRAMAddress() + currLoopTime * ssramInSize;
if ((z == inportSize-1) && (currLoopTime == loopTime-1))
SSRAMinterfaceFile<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<") = (short)"<<portName<<";\n";
else SSRAMinterfaceFile<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<") = (short)"<<portName<<";\\\n";
//SSRAMinterfaceFile<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<") = (short)"<<portName<<";\\\n";
scalarInNum++;
}
else
{
portName = portName.substr(portName.find(".")+1);
portSSRAM = (*currInport).SSRAMAddress() + currLoopTime * ssramInSize;
if ((z == inportSize-1) && (currLoopTime == loopTime-1))
SSRAMinterfaceFile<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<") = (short)"<<portName<<";\n";
else SSRAMinterfaceFile<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<") = (short)"<<portName<<";\\\n";
//SSRAMinterfaceFile<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<") = (short)"<<portName<<";\\\n";
//scalarInNum++;
}
}
else
{
//2012.5.7 longlee Á¢¼´Êý²»½øÈëSSRAMÊäÈëÇø
//immPort = static_cast<DFGImmPort*>(currInport);
//immPortValue = immPort->value();
//portSSRAM = (*currInport).SSRAMAddress();
//SSRAMinterfaceFile<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<") = (short)"<<std::dec<<immPortValue<<";\\\n"; }
}
}
}
SSRAMinterfaceFile<<"\n\n\n";
SSRAMinterfaceFile<<"#define "<<tempUperString<<"_DOUT \\\n";
for (int currLoopTime=0; currLoopTime < loopTime; currLoopTime++)
{
int scalarOutNum = 0;
for(z=0; z<outportSize ; z++)
{
currOutport = (&dfg_graph.outport(z));
portName = static_cast<DFGVarPort*>(currOutport)->name();
//portName = Out[z][currLoopTime];
if (portName.find("scalar") != -1)
{
portName = Out[scalarOutNum][currLoopTime];
portSSRAM = (*currOutport).SSRAMAddress() + currLoopTime * ssramOutSize;
if ((z==outportSize-1) && (currLoopTime==loopTime-1))
SSRAMinterfaceFile<<portName<<" = "<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<");"<<"\n";
else SSRAMinterfaceFile<<portName<<" = "<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<");"<<"\\\n";
//SSRAMinterfaceFile<<portName<<" = "<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<");"<<"\\\n";
scalarOutNum++;
}
else
{
portName = portName.substr(portName.find(".")+1);
portSSRAM = (*currOutport).SSRAMAddress() + currLoopTime * ssramOutSize;
if ((z==outportSize-1) && (currLoopTime==loopTime-1))
SSRAMinterfaceFile<<portName<<" = "<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<");"<<"\n";
else SSRAMinterfaceFile<<portName<<" = "<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<");"<<"\\\n";
//SSRAMinterfaceFile<<portName<<" = "<<"*(RP16)( AHB0_S2_EMI_SSRAM + 0x"<<std::hex<<portSSRAM<<");"<<"\\\n";
}
}
}
SSRAMinterfaceFile<<std::endl;
SSRAMinterfaceFile.close();
return 0;
}