SysFlashOpMessage.h
Go to the documentation of this file.
00001 
00040 #ifndef LibMultiSense_SysFlashOpMessage
00041 #define LibMultiSense_SysFlashOpMessage
00042 
00043 #include <typeinfo>
00044 
00045 #include "details/utility/Portability.hh"
00046 
00047 namespace crl {
00048 namespace multisense {
00049 namespace details {
00050 namespace wire {
00051 
00052 class SysFlashOp {
00053 public:
00054     static CRL_CONSTEXPR IdType      ID      = ID_CMD_SYS_FLASH_OP;
00055     static CRL_CONSTEXPR VersionType VERSION = 1; 
00056 
00057     //
00058     // Maximum payload length per operation
00059 
00060     static CRL_CONSTEXPR uint32_t MAX_LENGTH = 1024;
00061 
00062     //
00063     // Parameters representing the desired flash operation
00064 
00065     static CRL_CONSTEXPR uint32_t OP_STATUS  = 0; // just check status
00066     static CRL_CONSTEXPR uint32_t OP_ERASE   = 1; // erase entire region
00067     static CRL_CONSTEXPR uint32_t OP_PROGRAM = 2; // program/verify chunk within region
00068     static CRL_CONSTEXPR uint32_t OP_VERIFY  = 3; // just verify chunk within region
00069 
00070     uint32_t operation;
00071 
00072     //
00073     // Parameters representing the desired flash region
00074 
00075     static CRL_CONSTEXPR uint32_t RGN_BITSTREAM   = 0; // FPGA configuration bitstream
00076     static CRL_CONSTEXPR uint32_t RGN_FIRMWARE    = 1; // Microblaze firmware
00077 
00078     uint32_t region;
00079 
00080     //
00081     // Remaining fields are only used for OP_PROGRAM and OP_VERIFY:
00082 
00083     uint32_t start_address;  // start address of chunk to program or verify
00084     uint32_t length;         // size of chunk to program or verify (power-of-2)
00085 
00086     uint8_t data[MAX_LENGTH];
00087 
00088     //
00089     // Constructors
00090 
00091     SysFlashOp(utility::BufferStreamReader&r, VersionType v) {serialize(r,v);};
00092     SysFlashOp(uint32_t op=OP_STATUS, 
00093                uint32_t r=RGN_BITSTREAM,
00094                uint32_t s=0,
00095                uint32_t l=0) : operation(op), 
00096                                region(r),
00097                                start_address(s),
00098                                length(l) {};
00099     //
00100     // Serialization routine
00101 
00102     template<class Archive>
00103         void serialize(Archive&          message,
00104                        const VersionType version)
00105     {
00106         message & operation;
00107         message & region;
00108 
00109         switch(operation) {
00110             case OP_PROGRAM:
00111             case OP_VERIFY:
00112 
00113                 message & start_address;
00114                 message & length;
00115 
00116                 if(length > MAX_LENGTH)
00117                     CRL_EXCEPTION("length (%u) exceeds MAX_LENGTH (%u)", 
00118                                   length, MAX_LENGTH);
00119 
00120                 if (typeid(Archive) == typeid(utility::BufferStreamWriter))
00121                     message.write(data, length);
00122                 else
00123                     message.read(data, length);
00124 
00125                 break;
00126             case OP_STATUS:
00127             case OP_ERASE:
00128                 // start/length/data not required
00129                 break;
00130             default:
00131                 CRL_EXCEPTION("unknown operation (%d)", (int)operation);
00132         }
00133 
00134         switch(region) {
00135             case RGN_BITSTREAM:
00136             case RGN_FIRMWARE:
00137                 break;
00138             default:
00139                 CRL_EXCEPTION("unknown region (%d)", (int)region);
00140         }
00141     }
00142 };
00143 
00144 }}}}; // namespaces
00145 
00146 #endif


multisense_lib
Author(s):
autogenerated on Fri Apr 5 2019 02:28:24