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