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  message & operation;
107  message & region;
108 
109  switch(operation) {
110  case OP_PROGRAM:
111  case OP_VERIFY:
112 
113  message & start_address;
114  message & length;
115 
116  if(length > MAX_LENGTH)
117  CRL_EXCEPTION("length (%u) exceeds MAX_LENGTH (%u)",
118  length, MAX_LENGTH);
119 
120  if (typeid(Archive) == typeid(utility::BufferStreamWriter))
121  message.write(data, length);
122  else
123  message.read(data, length);
124 
125  break;
126  case OP_STATUS:
127  case OP_ERASE:
128  // start/length/data not required
129  break;
130  default:
131  CRL_EXCEPTION("unknown operation (%d)", (int)operation);
132  }
133 
134  switch(region) {
135  case RGN_BITSTREAM:
136  case RGN_FIRMWARE:
137  break;
138  default:
139  CRL_EXCEPTION("unknown region (%d)", (int)region);
140  }
141  }
142 };
143 
144 }}}}; // namespaces
145 
146 #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:159
SysFlashOp(utility::BufferStreamReader &r, VersionType v)
static CRL_CONSTEXPR uint32_t RGN_BITSTREAM
#define CRL_CONSTEXPR
Definition: Portability.hh:38


multisense_lib
Author(s):
autogenerated on Sat Apr 6 2019 02:16:46