cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
nts_utils.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2016 -- 2021 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
31 #ifndef _NTS_UTILS_H_
32 #define _NTS_UTILS_H_
33 
34 #include "../MEM/mem.hpp"
35 #include "../NTS/nts.hpp"
36 
37 using namespace std;
38 
39 
44 #ifndef __SYNTHESIS__
45  extern bool gTraceEvent;
46  extern bool gFatalError;
47  extern unsigned int gSimCycCnt;
48 #endif
49 
50 
51 
54 #ifndef __SYNTH_LOG2CEIL__
55 #define __SYNTH_LOG2CEIL__
56 
65  template<uint64_t n> struct log2Ceil {
66  //-- Code extracted from the book:
67  //-- "High-level Synthesis: Blue Book" by By Michael Fingeroff.
68  //-- Since the parameter 'n' is usually based on a template parameter,
69  //-- it requires the use of enumerated types to perform the computation
70  //-- so that the result is statically determinable at compile time.
71  //-- One important point to note about using "brute force" approach is
72  //-- that there must be sufficient enumerations to cover all of the
73  //-- possible values.
74  enum {
75  val = \
76  n <= 0x1 ? 1 : \
77  n <= 0x2 ? 1 : \
78  n <= 0x4 ? 2 : \
79  n <= 0x8 ? 3 : \
80  n <= 0x10 ? 4 : \
81  n <= 0x20 ? 5 : \
82  n <= 0x40 ? 6 : \
83  n <= 0x80 ? 7 : \
84  n <= 0x100 ? 8 : \
85  n <= 0x200 ? 9 : \
86  n <= 0x400 ? 10 : \
87  n <= 0x800 ? 11 : \
88  n <= 0x1000 ? 12 : \
89  n <= 0x2000 ? 13 : \
90  n <= 0x4000 ? 14 : \
91  n <= 0x8000 ? 15 : \
92  n <= 0x10000 ? 16 : \
93  n <= 0x20000 ? 17 : \
94  n <= 0x40000 ? 18 : \
95  n <= 0x80000 ? 19 : \
96  n <= 0x100000 ? 20 : \
97  n <= 0x200000 ? 21 : \
98  n <= 0x400000 ? 22 : \
99  n <= 0x800000 ? 23 : \
100  n <= 0x1000000 ? 24 : \
101  n <= 0x2000000 ? 25 : \
102  n <= 0x4000000 ? 26 : \
103  n <= 0x8000000 ? 27 : \
104  n <= 0x10000000 ? 28 : \
105  n <= 0x20000000 ? 29 : \
106  n <= 0x40000000 ? 30 : \
107  n <= 0x80000000 ? 31 : \
108  n <= 0x100000000 ? 32 : \
109  33
110  };
111  };
112 #endif
113 
114 
117 tKeep lenTotKeep(ap_uint<4> noValidBytes);
118 LE_tKeep lenToLE_tKeep (ap_uint<4> noValidBytes);
119 
120 ap_uint<16> byteSwap16(ap_uint<16> inputValue);
121 ap_uint<32> byteSwap32(ap_uint<32> inputValue);
122 ap_uint<48> byteSwap48(ap_uint<48> inputValue);
123 ap_uint<64> byteSwap64(ap_uint<64> inputValue);
124 
125 
128 const char *getTcpStateName(TcpState tcpState);
129 
130 
133 void printAxisRaw (const char *callerName, AxisRaw chunk);
134 void printAxisRaw (const char *callerName, \
135  const char *message, AxisRaw chunk);
136 void printDmCmd (const char *callerName, DmCmd dmCmd);
137 void printArpBindPair (const char *callerName, ArpBindPair arpBind);
138 void printSockAddr (const char *callerName, SockAddr sockAddr);
139 void printSockAddr (const char *callerName, LE_SockAddr leSockAddr);
140 void printSockAddr ( SockAddr sockAddr);
141 void printSockPair (const char *callerName, SocketPair sockPair);
142 void printSockPair (const char *callerName, LE_SocketPair leSockPair);
143 void printLE_SockAddr (const char *callerName, LE_SockAddr leSockAddr);
144 void printLE_SockPair (const char *callerName, LE_SocketPair leSockPair);
145 void printIp4Addr (const char *callerName, \
146  const char *message, Ip4Addr ip4Addr);
147 void printIp4Addr (const char *callerName, Ip4Addr ip4Addr);
148 void printEthAddr (const char *callerName, \
149  const char *message, EthAddr ethAddr);
150 void printEthAddr (const char *callerName, EthAddr ethAddr);
151 void printEthAddr ( EthAddr ethAddr);
152 void printTcpPort (const char *callerName, TcpPort tcpPort);
153 void printTcpPort ( TcpPort tcpPort);
154 
155 
158 // Concatenate two char constants
159 #define concat2(firstCharConst, secondCharConst) firstCharConst secondCharConst
160 // Concatenate three char constants
161 #define concat3(firstCharConst, secondCharConst, thirdCharConst) firstCharConst secondCharConst thirdCharConst
162 
163 
168 #ifndef __SYNTHESIS__
169  #define printInfo(callerName , format, ...) \
170  do { gTraceEvent = true; printf("(@%5.5d) [%-20s] INFO - " format, gSimCycCnt, callerName, ##__VA_ARGS__); } while (0)
171 #else
172  #define printInfo(callerName , format, ...) \
173  do {} while (0);
174 #endif
175 
176 
181 #ifndef __SYNTHESIS__
182  #define printWarn(callerName , format, ...) \
183  do { gTraceEvent = true; printf("(@%5.5d) [%-20s] WARNING - " format, gSimCycCnt, callerName, ##__VA_ARGS__); } while (0)
184 #else
185  #define printWarn(callerName , format, ...) \
186  do {} while (0);
187 #endif
188 
189 
194 #ifndef __SYNTHESIS__
195  #define printError(callerName , format, ...) \
196  do { gTraceEvent = true; printf("(@%5.5d) [%-20s] ERROR - " format, gSimCycCnt, callerName, ##__VA_ARGS__); } while (0)
197 #else
198  #define printError(callerName , format, ...) \
199  do {} while (0);
200 #endif
201 
202 
207 #ifndef __SYNTHESIS__
208  #define printFatal(callerName , format, ...) \
209  do { gTraceEvent = true; gFatalError = true; printf("\n(@%5.5d) [%-20s] FATAL - " format, gSimCycCnt, callerName, ##__VA_ARGS__); printf("\n\n"); exit(99); } while (0)
210 #else
211  #define printFatal(callerName , format, ...) \
212  do {} while (0);
213 #endif
214 
215 
222 #ifndef __SYNTHESIS__
223  #define assessSize(callerName , stream , streamName, depth) \
224  do { if (stream.size() >= depth) printFatal(callerName, "Stream \'%s\' is full: Cannot write.", streamName); } while (0)
225 #else
226  #define assessSize(callerName , stream, streamName, depth) \
227  do {} while (0);
228 #endif
229 
230 #endif
231 
ap_uint< 48 > byteSwap48(ap_uint< 48 > inputValue)
Swap the six bytes of a triple-word (.i.e, 48 bits).
Definition: nts_utils.cpp:370
void printEthAddr(EthAddr ethAddr)
void printLE_SockPair(const char *callerName, LE_SocketPair sockPair)
Print a socket pair association in LITTLE-ENDIAN order.
Definition: nts_utils.cpp:102
ap_uint< 64/8 > tKeep
Definition: AxisRaw.hpp:128
ap_uint< 48 > EthAddr
Definition: AxisEth.hpp:120
LE_tKeep lenToLE_tKeep(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...
Definition: nts_utils.cpp:307
void printArpBindPair(const char *callerName, ArpBindPair arpBind)
Print an ARP binding pair association.
Definition: nts_utils.cpp:80
TcpState
Definition: nts_types.hpp:296
ap_uint< 64 > byteSwap64(ap_uint< 64 > inputValue)
Swap the eight bytes of a quad-word (.i.e, 64 bits).
Definition: nts_utils.cpp:382
void printAxisRaw(const char *callerName, AxisRaw chunk)
Prints an Axis raw data chunk (used for debugging).
Definition: nts_utils.cpp:46
ap_uint< 64/8 > LE_tKeep
Definition: AxisRaw.hpp:124
void printTcpPort(TcpPort tcpPort)
ap_uint< 32 > Ip4Addr
Definition: AxisIp4.hpp:169
void printDmCmd(const char *callerName, DmCmd dmCmd)
Prints the details of a Data Mover Command (used for debugging).
Definition: nts_utils.cpp:69
unsigned int gSimCycCnt
Definition: tb_nal.cpp:150
void printLE_SockAddr(const char *callerName, LE_SockAddr leSockAddr)
Print a socket address encoded in LITTLE_ENDIAN order.
Definition: nts_utils.cpp:162
bool gTraceEvent
Definition: tb_nal.cpp:151
ap_uint< 16 > TcpPort
Definition: AxisTcp.hpp:105
const char * getTcpStateName(TcpState tcpState)
Returns the name of an enum-based TCP-State as a user friendly string.
Definition: nts_utils.cpp:272
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...
Definition: nts_utils.cpp:328
bool gFatalError
Definition: tb_nal.cpp:152
void printIp4Addr(const char *callerName, const char *message, Ip4Addr ip4Addr)
Print an IPv4 address prepended with a message (used for debugging).
Definition: nts_utils.cpp:205
void printSockPair(const char *callerName, SocketPair sockPair)
Print a socket pair association.
Definition: nts_utils.cpp:114
void printSockAddr(SockAddr sockAddr)
ap_uint< 32 > byteSwap32(ap_uint< 32 > inputVector)
Definition: udp.cpp:78
ap_uint< 16 > byteSwap16(ap_uint< 16 > inputVector)
Definition: udp.cpp:82