SysFlashOpMessage.h
Go to the documentation of this file.
1 
40 #ifndef LibMultiSense_SysFlashOpMessage
41 #define LibMultiSense_SysFlashOpMessage
42 
43 #include <typeinfo>
44 
46 
47 namespace crl {
48 namespace multisense {
49 namespace details {
50 namespace wire {
51 
52 class SysFlashOp {
53 public:
56 
57  //
58  // Maximum payload length per operation
59 
60  static CRL_CONSTEXPR uint32_t MAX_LENGTH = 1024;
61 
62  //
63  // Parameters representing the desired flash operation
64 
65  static CRL_CONSTEXPR uint32_t OP_STATUS = 0; // just check status
66  static CRL_CONSTEXPR uint32_t OP_ERASE = 1; // erase entire region
67  static CRL_CONSTEXPR uint32_t OP_PROGRAM = 2; // program/verify chunk within region
68  static CRL_CONSTEXPR uint32_t OP_VERIFY = 3; // just verify chunk within region
69 
70  uint32_t operation;
71 
72  //
73  // Parameters representing the desired flash region
74 
75  static CRL_CONSTEXPR uint32_t RGN_BITSTREAM = 0; // FPGA configuration bitstream
76  static CRL_CONSTEXPR uint32_t RGN_FIRMWARE = 1; // Microblaze firmware
77 
78  uint32_t region;
79 
80  //
81  // Remaining fields are only used for OP_PROGRAM and OP_VERIFY:
82 
83  uint32_t start_address; // start address of chunk to program or verify
84  uint32_t length; // size of chunk to program or verify (power-of-2)
85 
86  uint8_t data[MAX_LENGTH];
87 
88  //
89  // Constructors
90 
92  SysFlashOp(uint32_t op=OP_STATUS,
93  uint32_t r=RGN_BITSTREAM,
94  uint32_t s=0,
95  uint32_t l=0) : operation(op),
96  region(r),
97  start_address(s),
98  length(l) {};
99  //
100  // Serialization routine
101 
102  template<class Archive>
103  void serialize(Archive& message,
104  const VersionType version)
105  {
106  (void) version;
107  message & operation;
108  message & region;
109 
110  switch(operation) {
111  case OP_PROGRAM:
112  case OP_VERIFY:
113 
114  message & start_address;
115  message & length;
116 
117  if(length > MAX_LENGTH)
118  CRL_EXCEPTION("length (%u) exceeds MAX_LENGTH (%u)",
119  length, MAX_LENGTH);
120 
121  if (typeid(Archive) == typeid(utility::BufferStreamWriter))
122  message.write(data, length);
123  else
124  message.read(data, length);
125 
126  break;
127  case OP_STATUS:
128  case OP_ERASE:
129  // start/length/data not required
130  break;
131  default:
132  CRL_EXCEPTION("unknown operation (%d)", (int)operation);
133  }
134 
135  switch(region) {
136  case RGN_BITSTREAM:
137  case RGN_FIRMWARE:
138  break;
139  default:
140  CRL_EXCEPTION("unknown region (%d)", (int)region);
141  }
142  }
143 };
144 
145 }}}} // namespaces
146 
147 #endif
static CRL_CONSTEXPR uint32_t OP_PROGRAM
#define CRL_EXCEPTION(fmt,...)
Definition: Exception.hh:71
static CRL_CONSTEXPR uint32_t OP_ERASE
void serialize(Archive &message, const VersionType version)
static CRL_CONSTEXPR uint32_t OP_STATUS
static CRL_CONSTEXPR VersionType VERSION
static CRL_CONSTEXPR uint32_t MAX_LENGTH
static CRL_CONSTEXPR uint32_t RGN_FIRMWARE
SysFlashOp(uint32_t op=OP_STATUS, uint32_t r=RGN_BITSTREAM, uint32_t s=0, uint32_t l=0)
static CRL_CONSTEXPR uint32_t OP_VERIFY
Definition: channel.cc:56
static CRL_CONSTEXPR IdType ID_CMD_SYS_FLASH_OP
Definition: Protocol.h:168
SysFlashOp(utility::BufferStreamReader &r, VersionType v)
static CRL_CONSTEXPR uint32_t RGN_BITSTREAM
#define CRL_CONSTEXPR
Definition: Portability.hh:51


multisense_lib
Author(s):
autogenerated on Sun Mar 14 2021 02:34:50