64 #define THIS_NAME "SIM"
66 #define TRACE_OFF 0x0000
67 #define TRACE_UOE 1 << 1
68 #define TRACE_UAF 1 << 2
69 #define TRACE_MMIO 1 << 3
70 #define TRACE_ALL 0xFFFF
72 #define DEBUG_LEVEL (TRACE_UOE)
113 stream<UdpAppData> &siUSIF_Data,
114 stream<UdpAppMeta> &siUSIF_Meta,
116 stream<UdpAppData> &soUSIF_Data,
117 stream<UdpAppMeta> &soUSIF_Meta,
118 stream<UdpAppDLen> &soUSIF_DLen)
129 switch (uaf_rxFsmState ) {
131 if (!siUSIF_Meta.empty() and !soUSIF_Meta.full()) {
132 siUSIF_Meta.read(appMeta);
136 soUSIF_Meta.write(swappedMeta);
137 soUSIF_DLen.write(0);
142 if (!siUSIF_Data.empty() and !soUSIF_Data.full()) {
143 siUSIF_Data.read(appData);
147 soUSIF_Data.write(appData);
149 uaf_rxFsmState = RX_IDLE;
171 static bool mmio_printOnce =
true;
175 if (mmio_printOnce) {
176 printInfo(myName,
"[SHELL/NTS/UOE] is ready -> Enabling operation of the UDP Shell Interface (USIF).\n");
177 mmio_printOnce =
false;
208 ofstream &dataGoldFile,
210 ofstream &metaGoldFile,
218 stream<UdpAppData> &soUSIF_Data,
219 stream<UdpAppMeta> &soUSIF_Meta,
220 stream<UdpAppDLen> &soUSIF_DLen,
222 stream<UdpAppData> &siUSIF_Data,
223 stream<UdpAppMeta> &siUSIF_Meta,
224 stream<UdpAppDLen> &siUSIF_DLen,
226 stream<UdpPort> &siUSIF_LsnReq,
227 stream<StsBool> &soUSIF_LsnRep,
229 stream<UdpPort> &siUSIF_ClsReq)
238 static int uoe_rxpStartupDelay = 50;
239 static int uoe_txpStartupDelay = 0;
240 static bool uoe_isReady =
false;
241 static bool uoe_rxpIsReady =
false;
242 static bool uoe_txpIsReady =
false;
251 if (uoe_startupDelay) {
257 if (uoe_rxpStartupDelay)
258 uoe_rxpStartupDelay--;
260 uoe_rxpIsReady =
true;
261 if (uoe_txpStartupDelay)
262 uoe_txpStartupDelay--;
264 uoe_txpIsReady =
true;
271 switch (uoe_lsnState) {
273 if (!siUSIF_LsnReq.empty()) {
274 siUSIF_LsnReq.read(uoe_lsnPortReq);
276 uoe_lsnPortReq.to_int());
277 uoe_lsnState = LSN_SEND_REP;
281 if (!soUSIF_LsnRep.full()) {
282 soUSIF_LsnRep.write(
OK);
286 printWarn(
myLsnName,
"Cannot send listen reply back to [USIF] because stream is full.\n");
296 static int uoe_rxByteCnt;
297 static Ly4Len uoe_txByteCnt;
298 static int uoe_dgmCnt=0;
299 static int uoe_waitEndOfTxTest=0;
300 const int nrDgmToSend=7;
301 if (uoe_rxpIsReady) {
302 switch (uoe_rxpState) {
304 if (!soUSIF_Meta.full() and !soUSIF_DLen.full()) {
305 if (uoe_waitEndOfTxTest) {
307 uoe_waitEndOfTxTest--;
309 else if (uoe_dgmCnt == nrDgmToSend) {
316 switch (uoe_dgmCnt) {
320 uoe_rxByteCnt = echoDgrmLen;
322 uoe_waitEndOfTxTest = 0;
328 uoe_txByteCnt = testDgrmLen;
330 uoe_waitEndOfTxTest = (testDgrmLen / 8) + 1;
331 uoe_rxpState = RXP_SEND_8801;
335 uoe_rxByteCnt = echoDgrmLen;
337 uoe_waitEndOfTxTest = 0;
346 soUSIF_Meta.write(uoe_rxMeta);
347 soUSIF_DLen.write(uoe_rxByteCnt);
359 if (!soUSIF_Data.full()) {
360 appData.
setTData((random() << 32) | random()) ;
361 if (uoe_rxByteCnt > 8) {
371 soUSIF_Data.write(appData);
381 if (!soUSIF_Data.full()) {
382 printInfo(
myRxpName,
"Requesting Tx test mode to generate a datagram of length=%d and to send it to socket: \n",
383 uoe_txByteCnt.to_uint());
390 soUSIF_Data.write(appData);
400 bool firstChunk=
true;
401 int txByteReq = uoe_txByteCnt;
405 for (
int i=0; i<8; i++) {
407 unsigned char byte = (
GEN_CHK0 >> ((7-i)*8)) & 0xFF;
413 firstChunk = !firstChunk;
416 for (
int i=0; i<8; i++) {
418 unsigned char byte = (
GEN_CHK1 >> ((7-i)*8)) & 0xFF;
424 firstChunk = !firstChunk;
426 if (txByteReq == 0) {
446 if (uoe_txpIsReady) {
447 switch (uoe_txpState) {
449 if (!siUSIF_Meta.empty() and !siUSIF_DLen.empty()) {
452 siUSIF_Meta.read(appMeta);
453 siUSIF_DLen.read(uoe_appDLen);
455 if (uoe_appDLen == 0) {
456 printInfo(
myTxpName,
"This UDP Tx datagram is forwarded in streaming mode (DLen=0).\n");
459 printInfo(
myTxpName,
"Receiving %d bytes of data from [USIF].\n", uoe_appDLen.to_int());
471 if (!siUSIF_Data.empty()) {
473 siUSIF_Data.read(appData);
475 if (uoe_appDLen != 0) {
476 uoe_appDLen -= appData.
getLen();
482 uoe_txpState = TXP_WAIT_META;
483 if (uoe_appDLen != 0) {
void setTLast(tLast last)
void setLE_TLast(LE_tLast last)
void setLE_TData(LE_tData data, int leHi=64 -1, int leLo=0)
void setTKeep(tKeep keep)
void setTData(tData data)
void setLE_TKeep(LE_tKeep keep, int leHi=64/8-1, int leLo=0)
#define DEFAULT_HOST_LSN_PORT
#define DEFAULT_HOST_IP4_ADDR
#define DEFAULT_FPGA_IP4_ADDR
bool writeAxisRawToFile(AxisRaw &axisRaw, ofstream &outFileStream)
Dump an Axis raw data chunk to a file.
bool writeSocketPairToFile(SocketPair &socketPair, ofstream &outFileStream)
Dump a SocketPair to a file.
#define DEFAULT_FPGA_SND_PORT
#define DEFAULT_HOST_SND_PORT
void printAxisRaw(const char *callerName, AxisRaw chunk)
Prints an Axis raw data chunk (used for debugging).
void printSockAddr(const char *callerName, SockAddr sockAddr)
Print a socket address.
tKeep lenTotKeep(ap_uint< 4 > noValidBytes)
A function to set a number of '1' in an 8-bit field. It is used here to set the number of valid bytes...
#define printInfo(callerName, format,...)
A macro to print an information message.
#define printWarn(callerName, format,...)
A macro to print a warning message.
#define concat3(firstCharConst, secondCharConst, thirdCharConst)
void printSockPair(const char *callerName, SocketPair sockPair)
Print a socket pair association.
#define RECV_MODE_LSN_PORT
#define XMIT_MODE_LSN_PORT
#define ECHO_MODE_LSN_PORT
void stepSim()
Increment the simulation counter.
void pUAF(stream< UdpAppData > &siUSIF_Data, stream< UdpAppMeta > &siUSIF_Meta, stream< UdpAppData > &soUSIF_Data, stream< UdpAppMeta > &soUSIF_Meta, stream< UdpAppDLen > &soUSIF_DLen)
Emulate the behavior of the ROLE/UdpAppFlash (UAF).
unsigned int gMaxSimCycles
void increaseSimTime(unsigned int cycles)
Increase the simulation time of the testbench.
void pMMIO(StsBit *piSHL_Ready, CmdBit *poUSIF_Enable)
Emulate the behavior of the SHELL & MMIO.
void pUOE(int &nrErr, ofstream &dataGoldFile, ofstream &dataFile, ofstream &metaGoldFile, ofstream &metaFile, int echoDgrmLen, SockAddr testSock, int testDgrmLen, StsBit *poMMIO_Ready, stream< UdpAppData > &soUSIF_Data, stream< UdpAppMeta > &soUSIF_Meta, stream< UdpAppDLen > &soUSIF_DLen, stream< UdpAppData > &siUSIF_Data, stream< UdpAppMeta > &siUSIF_Meta, stream< UdpAppDLen > &siUSIF_DLen, stream< UdpPort > &siUSIF_LsnReq, stream< StsBool > &soUSIF_LsnRep, stream< UdpPort > &siUSIF_ClsReq)
Emulate behavior of the SHELL/NTS/UDP Offload Engine (UOE).
: Simulation environment for the UDP Shell Interface (USIF).
ap_uint< 32 > byteSwap32(ap_uint< 32 > inputVector)
ap_uint< 16 > byteSwap16(ap_uint< 16 > inputVector)