rogue
Loading...
Searching...
No Matches
Block.h
Go to the documentation of this file.
1
17#ifndef __ROGUE_INTERFACES_MEMORY_BLOCK_H__
18#define __ROGUE_INTERFACES_MEMORY_BLOCK_H__
19#include "rogue/Directives.h"
20
21#include <stdint.h>
22
23#include <memory>
24#include <string>
25#include <thread>
26#include <vector>
27
29
30#ifndef NO_PYTHON
31 #include <boost/python.hpp>
32#endif
33
34namespace rogue {
35namespace interfaces {
36namespace memory {
37
38#ifndef NO_PYTHON
39
40// Template function to convert a python list to a C++ std::vector
41template <typename T>
42inline std::vector<T> py_list_to_std_vector(const boost::python::object& iterable) {
43 return std::vector<T>(boost::python::stl_input_iterator<T>(iterable), boost::python::stl_input_iterator<T>());
44}
45
46// Template function to convert a c++ std::vector to a python list
47template <class T>
48inline boost::python::list std_vector_to_py_list(std::vector<T> vector) {
49 typename std::vector<T>::iterator iter;
50 boost::python::list list;
51 for (iter = vector.begin(); iter != vector.end(); ++iter) {
52 list.append(*iter);
53 }
54 return list;
55}
56
57// Template function to convert a python object to a c++ type with checking
58template <typename T>
59inline T py_object_convert(const boost::python::object& obj) {
60 boost::python::extract<T> ret(obj);
61
62 if (!ret.check())
63 return (T)0;
64 else
65 return ret;
66}
67
68#endif
69
70// Forward declaration
71class Variable;
72
96class Block : public Master {
97 protected:
98 // Mutex
99 std::mutex mtx_;
100
101 // Path
102 std::string path_;
103
104 // Mode
105 std::string mode_;
106
107 // Bulk Enable
109
110 // Block level update enable
112
113 // Persistant Block Verify Enable
115
116 // Verify Requred After Write, transiant
118
119 // Verify transaction in progress
121
122 // verifyBase byte, transiant
123 uint32_t verifyBase_;
124
125 // verify Size, transiant
126 uint32_t verifySize_;
127
128 // Block data
129 uint8_t* blockData_;
130
131 // Verify data
132 uint8_t* verifyData_;
133
134 // Verify Mask
135 uint8_t* verifyMask_;
136
137 // Verify Block
138 uint8_t* verifyBlock_;
139
140 // Block size
141 uint32_t size_;
142
143 // Block offset
144 uint64_t offset_;
145
146 // Update Flag, transiant
148
149 // Block python transactions flag
151
152 // Block logging
153 std::shared_ptr<rogue::Logging> bLog_;
154
155 // Variable list
156 std::vector<std::shared_ptr<rogue::interfaces::memory::Variable>> variables_;
157
158 // Enable flag
160
161 // Stale flag
162 bool stale_;
163
164 // Retry count
165 uint32_t retryCount_;
166
167#ifndef NO_PYTHON
168
169 // Call variable update for all variables
170 void varUpdate();
171
172#endif
173
174 // byte reverse
175 static inline void reverseBytes(uint8_t* data, uint32_t byteSize);
176
178 // Byte array set/get helpers
180
181 // Set data from pointer to internal staged memory
182 void setBytes(const uint8_t* data, rogue::interfaces::memory::Variable* var, uint32_t index);
183
184 // Get data to pointer from internal block or staged memory
185 void getBytes(uint8_t* data, rogue::interfaces::memory::Variable* var, uint32_t index);
186
187 // Custom init function called after addVariables
188 virtual void customInit();
189
190 // Custom cleanup function called before delete
191 virtual void customClean();
192
193 public:
207 static std::shared_ptr<rogue::interfaces::memory::Block> create(uint64_t offset, uint32_t size);
208
209 // Setup class for use in python
210 static void setup_python();
211
222 Block(uint64_t offset, uint32_t size);
223
224 // Destroy the Block
225 virtual ~Block();
226
234 std::string path();
235
244 std::string mode();
245
253 bool bulkOpEn();
254
262 void setEnable(bool enable);
263
269 void setLogLevel(uint32_t level) {
270 bLog_->setLevel(level);
271 }
272
280 uint64_t offset();
281
291 uint64_t address();
292
300 uint32_t size();
301
303 bool blockPyTrans();
304
305 private:
315 void intStartTransaction(uint32_t type,
316 bool forceWr,
317 bool check,
319 int32_t index);
320
321 public:
331 void startTransaction(uint32_t type,
332 bool forceWr,
333 bool check,
335 int32_t index = -1);
336
337#ifndef NO_PYTHON
338
350 void startTransactionPy(uint32_t type,
351 bool forceWr,
352 bool check,
353 std::shared_ptr<rogue::interfaces::memory::Variable> var,
354 int32_t index);
355
356#endif
357
363 bool checkTransaction();
364
365#ifndef NO_PYTHON
366
375 void checkTransactionPy();
376
377#endif
378
385 void write(rogue::interfaces::memory::Variable* var, int32_t index = -1);
386
393 void read(rogue::interfaces::memory::Variable* var, int32_t index = -1);
394
402 void addVariables(std::vector<std::shared_ptr<rogue::interfaces::memory::Variable>> variables);
403
404#ifndef NO_PYTHON
405
411 void addVariablesPy(boost::python::object variables);
412
413#endif
414
416 std::vector<std::shared_ptr<rogue::interfaces::memory::Variable>> variables();
417
418#ifndef NO_PYTHON
419
425 boost::python::object variablesPy();
426
427#endif
428
434 void rateTest();
435
437 // Python functions
439
440#ifndef NO_PYTHON
441
454 void setPyFunc(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
455
468 boost::python::object getPyFunc(rogue::interfaces::memory::Variable* var, int32_t index);
469
470#endif
471
473 // Raw Bytes
475
476#ifndef NO_PYTHON
477
489 void setByteArrayPy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
490
502 boost::python::object getByteArrayPy(rogue::interfaces::memory::Variable* var, int32_t index);
503
504#endif
505
517 void setByteArray(const uint8_t* value, rogue::interfaces::memory::Variable* var, int32_t index);
518
530 void getByteArray(uint8_t* value, rogue::interfaces::memory::Variable* var, int32_t index);
531
533 // Unsigned int
535
536#ifndef NO_PYTHON
537
549 void setUIntPy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
550
562 boost::python::object getUIntPy(rogue::interfaces::memory::Variable* var, int32_t index);
563
564#endif
565
577 void setUInt(const uint64_t& value, rogue::interfaces::memory::Variable* var, int32_t index);
578
590 uint64_t getUInt(rogue::interfaces::memory::Variable* var, int32_t index);
591
593 // Int
595
596#ifndef NO_PYTHON
597
609 void setIntPy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
610
622 boost::python::object getIntPy(rogue::interfaces::memory::Variable* var, int32_t index);
623
624#endif
625
637 void setInt(const int64_t& value, rogue::interfaces::memory::Variable* var, int32_t index);
638
650 int64_t getInt(rogue::interfaces::memory::Variable* var, int32_t index);
651
653 // Bool
655
656#ifndef NO_PYTHON
657
667 void setBoolPy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
668
678 boost::python::object getBoolPy(rogue::interfaces::memory::Variable* var, int32_t index);
679
680#endif
681
691 void setBool(const bool& value, rogue::interfaces::memory::Variable* var, int32_t index);
692
702 bool getBool(rogue::interfaces::memory::Variable* var, int32_t index);
703
705 // String
707
708#ifndef NO_PYTHON
709
717 void setStringPy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
718
726 boost::python::object getStringPy(rogue::interfaces::memory::Variable* var, int32_t index);
727
728#endif
729
737 void setString(const std::string& value, rogue::interfaces::memory::Variable* var, int32_t index);
738
746 std::string getString(rogue::interfaces::memory::Variable* var, int32_t index);
747
755 void getString(rogue::interfaces::memory::Variable* var, std::string& valueRet, int32_t index);
756
764 void getValue(rogue::interfaces::memory::Variable* var, std::string& valueRet, int32_t index) {
765 getString(var, valueRet, index);
766 }
767
769 // Float
771
772#ifndef NO_PYTHON
773
781 void setFloatPy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
782
790 boost::python::object getFloatPy(rogue::interfaces::memory::Variable* var, int32_t index);
791
792#endif
793
801 void setFloat(const float& value, rogue::interfaces::memory::Variable* var, int32_t index);
802
810 float getFloat(rogue::interfaces::memory::Variable* var, int32_t index);
811
813 // Double
815
816#ifndef NO_PYTHON
817
825 void setDoublePy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
826
834 boost::python::object getDoublePy(rogue::interfaces::memory::Variable* var, int32_t index);
835
836#endif
837
845 void setDouble(const double& value, rogue::interfaces::memory::Variable* var, int32_t index);
846
854 double getDouble(rogue::interfaces::memory::Variable* var, int32_t index);
855
857 // Fixed Point
859
860#ifndef NO_PYTHON
861
869 void setFixedPy(boost::python::object& value, rogue::interfaces::memory::Variable* var, int32_t index);
870
878 boost::python::object getFixedPy(rogue::interfaces::memory::Variable* var, int32_t index);
879
880#endif
881
889 void setFixed(const double& value, rogue::interfaces::memory::Variable* var, int32_t index);
890
898 double getFixed(rogue::interfaces::memory::Variable* var, int32_t index);
899};
900
902typedef std::shared_ptr<rogue::interfaces::memory::Block> BlockPtr;
903
904} // namespace memory
905} // namespace interfaces
906} // namespace rogue
907
908#endif
Memory interface block device.
Definition Block.h:96
void setString(const std::string &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets string variable data from C++ input.
Definition Block.cpp:1549
boost::python::object getPyFunc(rogue::interfaces::memory::Variable *var, int32_t index)
Gets variable data using a Python callback/value conversion.
Definition Block.cpp:828
void setDoublePy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets double variable data from Python input.
Definition Block.cpp:1733
uint32_t size()
Returns block size in bytes.
Definition Block.cpp:161
boost::python::object getStringPy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets string variable data as Python output.
Definition Block.cpp:1527
void addVariablesPy(boost::python::object variables)
Adds variables to this block (Python API).
Definition Block.cpp:610
void setBoolPy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets boolean variable data from Python input.
Definition Block.cpp:1372
double getDouble(rogue::interfaces::memory::Variable *var, int32_t index)
Gets double variable data as C++ output.
Definition Block.cpp:1867
float getFloat(rogue::interfaces::memory::Variable *var, int32_t index)
Gets float variable data as C++ output.
Definition Block.cpp:1718
void setUInt(const uint64_t &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets unsigned-integer variable data from C++ input.
Definition Block.cpp:1114
boost::python::object variablesPy()
Returns the variable list associated with this block (Python API).
Definition Block.cpp:625
void setFixed(const double &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets fixed-point variable data from C++ input.
Definition Block.cpp:2002
void setDouble(const double &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets double variable data from C++ input.
Definition Block.cpp:1853
void setPyFunc(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets variable data using a Python callback/value.
Definition Block.cpp:772
std::vector< std::shared_ptr< rogue::interfaces::memory::Variable > > variables()
Returns the variable list associated with this block (C++ API).
Definition Block.cpp:618
bool checkTransaction()
Checks transaction result in C++ mode.
Definition Block.cpp:357
void startTransaction(uint32_t type, bool forceWr, bool check, rogue::interfaces::memory::Variable *var, int32_t index=-1)
Starts a C++ transaction for this block.
Definition Block.cpp:279
void write(rogue::interfaces::memory::Variable *var, int32_t index=-1)
Issues write/verify/check sequence from C++.
Definition Block.cpp:422
std::vector< std::shared_ptr< rogue::interfaces::memory::Variable > > variables_
Definition Block.h:156
void setFloatPy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets float variable data from Python input.
Definition Block.cpp:1584
void getBytes(uint8_t *data, rogue::interfaces::memory::Variable *var, uint32_t index)
Definition Block.cpp:719
boost::python::object getUIntPy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets unsigned-integer variable data as Python output.
Definition Block.cpp:1047
boost::python::object getIntPy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets signed-integer variable data as Python output.
Definition Block.cpp:1272
bool bulkOpEn()
Returns whether this block participates in bulk operations.
Definition Block.cpp:139
boost::python::object getDoublePy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets double variable data as Python output.
Definition Block.cpp:1822
void setFloat(const float &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets float variable data from C++ input.
Definition Block.cpp:1704
std::string path()
Returns the path of the block in the device tree.
Definition Block.cpp:129
void setUIntPy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets unsigned-integer variable data from Python input.
Definition Block.cpp:920
void getValue(rogue::interfaces::memory::Variable *var, std::string &valueRet, int32_t index)
Alias to getString(var, valueRet, index).
Definition Block.h:764
void read(rogue::interfaces::memory::Variable *var, int32_t index=-1)
Issues read/check sequence from C++.
Definition Block.cpp:429
void setStringPy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets string variable data from Python input.
Definition Block.cpp:1507
void setInt(const int64_t &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets signed-integer variable data from C++ input.
Definition Block.cpp:1337
bool blockPyTrans()
Returns whether Python transaction callbacks are blocked.
Definition Block.cpp:166
boost::python::object getBoolPy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets boolean variable data as Python output.
Definition Block.cpp:1459
void setIntPy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets signed-integer variable data from Python input.
Definition Block.cpp:1143
bool getBool(rogue::interfaces::memory::Variable *var, int32_t index)
Gets boolean variable data as C++ output.
Definition Block.cpp:1492
std::string mode()
Returns the block access mode.
Definition Block.cpp:134
uint64_t getUInt(rogue::interfaces::memory::Variable *var, int32_t index)
Gets unsigned-integer variable data as C++ output.
Definition Block.cpp:1128
double getFixed(rogue::interfaces::memory::Variable *var, int32_t index)
Gets fixed-point variable data as C++ output.
Definition Block.cpp:2023
void setBytes(const uint8_t *data, rogue::interfaces::memory::Variable *var, uint32_t index)
Definition Block.cpp:644
void setEnable(bool enable)
Sets the block enable state.
Definition Block.cpp:144
int64_t getInt(rogue::interfaces::memory::Variable *var, int32_t index)
Gets signed-integer variable data as C++ output.
Definition Block.cpp:1352
void setByteArray(const uint8_t *value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets variable data from C++ byte array input.
Definition Block.cpp:904
static void reverseBytes(uint8_t *data, uint32_t byteSize)
Definition Block.cpp:632
uint64_t offset()
Returns the local offset of this block.
Definition Block.cpp:151
void startTransactionPy(uint32_t type, bool forceWr, bool check, std::shared_ptr< rogue::interfaces::memory::Variable > var, int32_t index)
Starts a block transaction from Python.
Definition Block.cpp:315
boost::python::object getFloatPy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets float variable data as Python output.
Definition Block.cpp:1673
void checkTransactionPy()
Checks transaction result.
Definition Block.cpp:413
void setByteArrayPy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets variable data from Python byte-array-like input.
Definition Block.cpp:862
void setBool(const bool &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets boolean variable data from C++ input.
Definition Block.cpp:1486
std::shared_ptr< rogue::Logging > bLog_
Definition Block.h:153
uint64_t address()
Returns the full address of this block.
Definition Block.cpp:156
boost::python::object getFixedPy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets fixed-point variable data as Python output.
Definition Block.cpp:1971
void getByteArray(uint8_t *value, rogue::interfaces::memory::Variable *var, int32_t index)
Gets variable data into a C++ byte array buffer.
Definition Block.cpp:909
void addVariables(std::vector< std::shared_ptr< rogue::interfaces::memory::Variable > > variables)
Adds variables to this block (C++ API).
Definition Block.cpp:450
boost::python::object getByteArrayPy(rogue::interfaces::memory::Variable *var, int32_t index)
Gets variable data as a Python byte-array-like object.
Definition Block.cpp:881
void setLogLevel(uint32_t level)
Sets logging verbosity level for this block.
Definition Block.h:269
std::string getString(rogue::interfaces::memory::Variable *var, int32_t index)
Gets string variable data as C++ output.
Definition Block.cpp:1560
void rateTest()
Runs block rate-test helper for performance testing.
Definition Block.cpp:2049
void setFixedPy(boost::python::object &value, rogue::interfaces::memory::Variable *var, int32_t index)
Sets fixed-point variable data from Python input.
Definition Block.cpp:1882
Master endpoint for memory transactions.
Definition Master.h:50
static std::shared_ptr< rogue::interfaces::memory::Master > create()
Creates a memory master instance.
Definition Master.cpp:44
Memory variable descriptor and typed accessor facade.
Definition Variable.h:62
boost::python::list std_vector_to_py_list(std::vector< T > vector)
Definition Block.h:48
T py_object_convert(const boost::python::object &obj)
Definition Block.h:59
std::shared_ptr< rogue::interfaces::memory::Block > BlockPtr
Shared pointer alias for Block.
Definition Block.h:902
std::vector< T > py_list_to_std_vector(const boost::python::object &iterable)
Definition Block.h:42