cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
network_utils.cpp
Go to the documentation of this file.
1 
17 // *
18 // * cloudFPGA
19 // * =============================================
20 // * Created: Apr 2019
21 // * Authors: FAB, WEI, NGL
22 // *
23 // * Description:
24 // * This file contains network types and functions that are shared
25 // * across HLS cores.
26 // *
27 
28 #include <stdint.h>
29 #include "ap_int.h"
30 #include "ap_utils.h"
31 #include <hls_stream.h>
32 #include <queue>
33 #include <string>
34 #include "network_utils.hpp"
35 #include "NTS/AxisRaw.hpp"
36 
37 
38 #define UINT8 ap_uint<8>
39 #define UINT32 ap_uint<32>
40 
41 UINT32 bigEndianToInteger(UINT8 *buffer, int lsb)
42 {
43  UINT32 tmp = 0;
44  tmp = ((UINT32) buffer[lsb + 0]);
45  tmp |= ((UINT32) buffer[lsb + 1]) << 8;
46  tmp |= ((UINT32) buffer[lsb + 2]) << 16;
47  tmp |= ((UINT32) buffer[lsb + 3]) << 24;
48 
49  //printf("LSB: %#1x, return: %#04x\n",(UINT8) buffer[lsb + 3], (UINT32) tmp);
50 
51  return tmp;
52 }
53 
55 {
56  bytes[3] = (n >> 24) & 0xFF;
57  bytes[2] = (n >> 16) & 0xFF;
58  bytes[1] = (n >> 8) & 0xFF;
59  bytes[0] = n & 0xFF;
60 }
61 
62 
63 
70 /* MOVED to nts_utils.hpp
71  ap_uint<16> byteSwap16(ap_uint<16> inputVector) {
72  return (inputVector.range(7,0), inputVector(15, 8));
73  }
74  */
75 
76 
83 /* MOVED to nts_utils.hpp
84  ap_uint<32> byteSwap32(ap_uint<32> inputVector) {
85  return (inputVector.range( 7, 0), inputVector(15, 8),
86  inputVector.range(23,16), inputVector(31, 24));
87  }
88  */
89 
90 
94 ap_uint<4> keepToLen(ap_uint<8> keepValue) {
95  ap_uint<4> count = 0;
96  switch(keepValue){
97  case 0x01: count = 1; break;
98  case 0x03: count = 2; break;
99  case 0x07: count = 3; break;
100  case 0x0F: count = 4; break;
101  case 0x1F: count = 5; break;
102  case 0x3F: count = 6; break;
103  case 0x7F: count = 7; break;
104  case 0xFF: count = 8; break;
105  }
106  return count;
107 }
108 
109 
114 ap_uint<8> lenToKeep(ap_uint<4> noValidBytes) {
115  ap_uint<8> keep = 0;
116 
117  switch(noValidBytes) {
118  case 1: keep = 0x01; break;
119  case 2: keep = 0x03; break;
120  case 3: keep = 0x07; break;
121  case 4: keep = 0x0F; break;
122  case 5: keep = 0x1F; break;
123  case 6: keep = 0x3F; break;
124  case 7: keep = 0x7F; break;
125  case 8: keep = 0xFF; break;
126  }
127  return keep;
128 }
129 
: A generic class used by the Network-Transport-Stack (NTS) to to transfer a chunk of data over an AX...
ap_uint< 8 > lenToKeep(ap_uint< 4 > noValidBytes)
Returns the 'tkeep' field of an AxiWord as a function of the number of valid bytes in that word.
ap_uint< 4 > keepToLen(ap_uint< 8 > keepValue)
Swap the two bytes of a word (.i.e, 16 bits).
#define UINT32
#define UINT8
ap_uint< 32 > bigEndianToInteger(ap_uint< 8 > *buffer, int lsb)
void integerToBigEndian(ap_uint< 32 > n, ap_uint< 8 > *bytes)