DuneNvme  1.0.0
This is a simple NVMe test environment that allows experimentation with the low level PCIe NVMe interfaces as available on a Xilinx FPGA environment.
BeamLibBasic.h
1 /*******************************************************************************
2  * BeamLibBasic.h Basic implementation of BeamLib functionality
3  * T.Barnaby, Beam Ltd, 2020-04-10
4  *******************************************************************************
5  */
31 #pragma once
32 
33 #include <stdint.h>
34 #include <stdarg.h>
35 #include <semaphore.h>
36 
37 // Snippets from Beam-lib
38 #if LDEBUG1
39 #define dl1printf(fmt, a...) tprintf(fmt, ##a)
40 #define dl1hd32(data, nWords) bhd32(data, nWords)
41 #else
42 #define dl1printf(fmt, a...)
43 #define dl1hd32(data, nWords)
44 #endif
45 
46 #if LDEBUG2
47 #define dl2printf(fmt, a...) tprintf(fmt, ##a)
48 #define dl2hd32(data, nWords) bhd32(data, nWords)
49 #else
50 #define dl2printf(fmt, a...)
51 #define dl2hd32(data, nWords)
52 #endif
53 
54 #if LDEBUG3
55 #define dl3printf(fmt, a...) tprintf(fmt, ##a)
56 #define dl3hd32(data, nWords) bhd32(data, nWords)
57 #else
58 #define dl3printf(fmt, a...)
59 #define dl3hd32(data, nWords)
60 #endif
61 
62 #if LDEBUG4
63 #define dl4printf(fmt, a...) tprintf(fmt, ##a)
64 #define dl4hd32(data, nWords) bhd32(data, nWords)
65 #else
66 #define dl4printf(fmt, a...)
67 #define dl4hd32(data, nWords)
68 #endif
69 
70 #if LDEBUG5
71 #define dl5printf(fmt, a...) tprintf(fmt, ##a)
72 #define dl5hd32(data, nWords) bhd32(data, nWords)
73 #else
74 #define dl5printf(fmt, a...)
75 #define dl5hd32(data, nWords)
76 #endif
77 
78 typedef bool Bool;
79 typedef uint8_t BUInt8;
80 typedef uint32_t BUInt32;
81 typedef uint64_t BUInt64;
82 typedef unsigned int BUInt;
83 
84 // Timeouts
85 typedef BUInt32 BTimeout;
86 const BTimeout BTimeoutForever = 0xFFFFFFFF; // Forever timeout
87 
89 class BSemaphore {
90 public:
91  BSemaphore();
92  BSemaphore(const BSemaphore& semaphore);
93  ~BSemaphore();
94 
95  Bool wait(BTimeout timeoutUs = BTimeoutForever);
96  void set();
97 
98  int getValue() const;
99  BSemaphore& operator=(const BSemaphore& semaphore);
100 
101 private:
102  sem_t osema;
103 };
104 
105 // Simple Byte Fifo
106 class BFifoBytes {
107 public:
108  BFifoBytes(BUInt size);
109  ~BFifoBytes();
110 
111  void clear();
112 
113  BUInt size();
114  int resize(BUInt size);
115 
116  BUInt writeAvailable();
117  int write(const void* data, BUInt num);
118 
119  BUInt readAvailable();
120  int read(void* data, BUInt num);
121 
122 protected:
123  BUInt osize;
124  char* odata;
125  volatile BUInt owritePos;
126  volatile BUInt oreadPos;
127 };
128 
129 
130 void tprintf(const char* fmt, ...);
131 void bhd8(void* data, BUInt32 n);
132 void bhd32(void* data,BUInt32 n);
133 void bhd32a(void* data,BUInt32 n);
134 double getTime();
int resize(BUInt size)
Resize FIFO, clears it as well.
Definition: BeamLibBasic.cpp:116
BUInt writeAvailable()
How many items that can be written.
Definition: BeamLibBasic.cpp:128
Semaphore class.
Definition: BeamLibBasic.h:89
int write(const void *data, BUInt num)
Write a set of items. Can only write a maximum of writeAvailableChunk() to save going beyond end of F...
Definition: BeamLibBasic.cpp:137
volatile BUInt oreadPos
The read pointer.
Definition: BeamLibBasic.h:126
char * odata
FIFO memory buffer.
Definition: BeamLibBasic.h:124
Bool wait(BTimeout timeoutUs=BTimeoutForever)
Wait for the semaphore.
Definition: BeamLibBasic.cpp:62
Definition: BeamLibBasic.h:106
BUInt readAvailable()
How many items are available to read.
Definition: BeamLibBasic.cpp:161
int read(void *data, BUInt num)
Read a set of items.
Definition: BeamLibBasic.cpp:170
void set()
Set the semaphore.
Definition: BeamLibBasic.cpp:58
BUInt osize
The size of the FIFO.
Definition: BeamLibBasic.h:123
BUInt size()
Returns fifo size.
Definition: BeamLibBasic.cpp:112
volatile BUInt owritePos
The write pointer.
Definition: BeamLibBasic.h:125