Skip to content

Commit

Permalink
Merge pull request #62 from lsst-ts/tickets/DM-42107
Browse files Browse the repository at this point in the history
DM-42107: MPU C++ redesign
  • Loading branch information
pkubanek authored Apr 25, 2024
2 parents e8d6e2d + cc479d3 commit 1641101
Show file tree
Hide file tree
Showing 16 changed files with 495 additions and 748 deletions.
1 change: 1 addition & 0 deletions doc/version-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ v1.11.0
to FPGA class.
* Improved documentation.
* Public constants to explain meaning of the numbers
* mpuCommands redesign

v1.10.1
-------
Expand Down
16 changes: 13 additions & 3 deletions include/Modbus/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class Buffer : public std::vector<uint8_t> {
template <typename dt>
void write(dt data);

template <typename vt>
inline void writeVector(std::vector<vt> data) {
for (auto d : data) {
write<vt>(d);
}
}

/**
* Writes 24bit signed integer.
*
Expand Down Expand Up @@ -254,9 +261,12 @@ inline void Buffer::write(float data) {

template <>
inline void Buffer::write(std::vector<uint8_t> data) {
for (auto d : data) {
write<uint8_t>(d);
}
writeVector<uint8_t>(data);
}

template <>
inline void Buffer::write(std::vector<uint16_t> data) {
writeVector<uint16_t>(data);
}

} // namespace Modbus
Expand Down
6 changes: 3 additions & 3 deletions include/Modbus/BusList.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ class BusList : public std::vector<CommandRecord> {
* the @glos{FPGA}, which is responsible to pass it to the hardware
* controller.
*
* @param address ModBus/@glos{ILC} address @param func ModBus/@glos{ILC}
* function code @param timing function call timing in microseconds
* (1/10^-6 second)
* @param address ModBus/@glos{ILC} address
* @param func ModBus/@glos{ILC} function code
* @param timing function call timing in microseconds (1/10^-6 second)
*/
void callFunction(uint8_t address, uint8_t func, uint32_t timming) {
emplace(end(), CommandRecord(Buffer(address, func), timming));
Expand Down
7 changes: 6 additions & 1 deletion include/Modbus/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Modbus {
* @param len length of the buffer
*/
template <typename dt>
static const std::string hexDump(dt *buf, size_t len) {
static const std::string hexDump(const dt *buf, size_t len) {
std::ostringstream os;
os << std::setfill('0') << std::hex;
for (size_t i = 0; i < len; i++) {
Expand All @@ -55,6 +55,11 @@ static const std::string hexDump(dt *buf, size_t len) {
return os.str();
}

template <typename dt>
static const std::string hexDump(const std::vector<dt> &data) {
return hexDump<dt>(data.data(), data.size());
}

/**
* Exception thrown when calculated CRC doesn't match received CRC.
*/
Expand Down
14 changes: 12 additions & 2 deletions include/cRIO/CliApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ class CliApp : public Application {
/**
* Construct CliApp.
*
* @param _description a short description of the application
* @param name command line application name
* @param description a short description of the application
*/
CliApp(const char* name, const char* description) : Application(name, description), _history_fn(NULL) {}
CliApp(const char* name, const char* description);

/**
* Class destructor. Subclasses are encouraged to include all destruction
Expand Down Expand Up @@ -242,6 +243,8 @@ get_the_answer command.

/**
* Process unmatched commands.
*
* @param cmds commands to be processed
*/
virtual int processUnmached(command_vec cmds);

Expand All @@ -250,6 +253,13 @@ get_the_answer command.
*/
void printCommands();

/**
* Exits the application.
*
* @param cmds commands to be processed
*/
virtual int _exit(command_vec cmds);

int verbose;

private:
Expand Down
23 changes: 18 additions & 5 deletions include/cRIO/FPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ namespace cRIO {

class MPU;

/**
* Commands for FPGA MPU unit.
*/
enum MPUCommands {
WRITE = 1,
READ_US = 2,
READ_MS = 3,
WAIT_US = 100,
WAIT_MS = 101,
IRQ = 240,
TELEMETRY = 254,
RESET = 255,
};

/**
* Interface class for cRIO FPGA. Subclasses can talk either to the real HW, or
* be a software simulator.
Expand Down Expand Up @@ -109,13 +123,12 @@ class FPGA : public SimpleFPGA {
void mpuCommands(MPU& mpu, const std::chrono::duration<double>& timeout = 500ms);

/**
* Commands FPGA to write to MPU commands buffer. Data to write are passed
* along in mpu parameter - you need to fill the MPU commands prior to
* calling this method.
* Commands FPGA to write to MPU commands buffer.
*
* @param mpu Modbus Processing Unit to write
* @param data data to write to the MPU command buffer
* @param timeout timeout in milliseconds
*/
virtual void writeMPUFIFO(MPU& mpu) = 0;
virtual void writeMPUFIFO(const std::vector<uint8_t>& data, uint32_t timeout) = 0;

/**
* Commands FPGA to copy MPU output FIFO to FPGA-C/C++ output FIFO. This
Expand Down
Loading

0 comments on commit 1641101

Please sign in to comment.