cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
network_utils.cpp File Reference
#include <stdint.h>
#include "ap_int.h"
#include "ap_utils.h"
#include <hls_stream.h>
#include <queue>
#include <string>
#include "network_utils.hpp"
#include "NTS/AxisRaw.hpp"
Include dependency graph for network_utils.cpp:

Go to the source code of this file.

Macros

#define UINT8   ap_uint<8>
 
#define UINT32   ap_uint<32>
 

Functions

ap_uint< 32 > bigEndianToInteger (ap_uint< 8 > *buffer, int lsb)
 
void integerToBigEndian (ap_uint< 32 > n, ap_uint< 8 > *bytes)
 
ap_uint< 4 > keepToLen (ap_uint< 8 > keepValue)
 Swap the two bytes of a word (.i.e, 16 bits). More...
 
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. More...
 

Macro Definition Documentation

◆ UINT32

#define UINT32   ap_uint<32>

Definition at line 39 of file network_utils.cpp.

◆ UINT8

#define UINT8   ap_uint<8>

Copyright 2016 – 2021 IBM Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition at line 38 of file network_utils.cpp.

Function Documentation

◆ bigEndianToInteger()

ap_uint<32> bigEndianToInteger ( ap_uint< 8 > *  buffer,
int  lsb 
)

Definition at line 41 of file network_utils.cpp.

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 }
#define UINT32

◆ integerToBigEndian()

void integerToBigEndian ( ap_uint< 32 >  n,
ap_uint< 8 > *  bytes 
)

Definition at line 54 of file network_utils.cpp.

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 }

◆ keepToLen()

ap_uint<4> keepToLen ( ap_uint< 8 >  keepValue)

Swap the two bytes of a word (.i.e, 16 bits).

Parameters
[in]inpWord,the16-bit unsigned data to swap.
Returns
a 16-bit unsigned data.

Swap the four bytes of a double-word (.i.e, 32 bits).

Parameters
[in]inpDWord,a32-bit unsigned data.
Returns
a 32-bit unsigned data.

Returns the number of valid bytes in an AxiWord.

Parameters
[in]The'tkeep' field of the AxiWord.

Definition at line 94 of file network_utils.cpp.

94  {
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 }

◆ lenToKeep()

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.

Parameters
[in]Thenumber of valid bytes in an AxiWord.

Definition at line 114 of file network_utils.cpp.

114  {
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 }