This commit is contained in:
Nav
2022-01-11 21:12:25 +00:00
parent 023b655145
commit d462358b1e
21 changed files with 128 additions and 23 deletions

View File

@@ -12,8 +12,8 @@ using namespace Bloom::Exceptions;
void CmsisDapInterface::sendCommand(const Command& cmsisDapCommand) {
if (this->msSendCommandDelay.count() > 0) {
using namespace std::chrono;
long now = duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
long difference = (now - this->lastCommandSentTimeStamp);
std::int64_t now = duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
std::int64_t difference = (now - this->lastCommandSentTimeStamp);
if (difference < this->msSendCommandDelay.count()) {
std::this_thread::sleep_for(milliseconds(this->msSendCommandDelay.count() - difference));
@@ -28,7 +28,7 @@ void CmsisDapInterface::sendCommand(const Command& cmsisDapCommand) {
std::unique_ptr<Response> CmsisDapInterface::getResponse() {
auto rawResponse = this->getUsbHidInterface().read(10000);
if (rawResponse.size() == 0) {
if (rawResponse.empty()) {
throw DeviceCommunicationFailure("Empty CMSIS-DAP response received");
}

View File

@@ -19,6 +19,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
{
public:
explicit CmsisDapInterface() = default;
virtual ~CmsisDapInterface() = default;
CmsisDapInterface(const CmsisDapInterface& other) = default;
CmsisDapInterface(CmsisDapInterface&& other) = default;
CmsisDapInterface& operator = (const CmsisDapInterface& other) = default;
CmsisDapInterface& operator = (CmsisDapInterface&& other) = default;
Usb::HidInterface& getUsbHidInterface() {
return this->usbHidInterface;
@@ -80,6 +87,6 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
* being sent, where x is the value of msSendCommandDelay.
*/
std::chrono::milliseconds msSendCommandDelay = std::chrono::milliseconds(0);
long lastCommandSentTimeStamp = 0;
std::int64_t lastCommandSentTimeStamp = 0;
};
}

View File

@@ -8,8 +8,15 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
class Command
{
public:
Command() = default;
virtual ~Command() = default;
Command(const Command& other) = default;
Command(Command&& other) = default;
Command& operator = (const Command& other) = default;
Command& operator = (Command&& other) = default;
[[nodiscard]] unsigned char getCommandId() const {
return this->commandId;
}
@@ -28,11 +35,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
[[nodiscard]] int getCommandSize() const {
// +1 for the command ID
return (int) (1 + this->getData().size());
return static_cast<int>(1 + this->getData().size());
}
[[nodiscard]] std::uint16_t getDataSize() const {
return (std::uint16_t) this->getData().size();
return static_cast<std::uint16_t>(this->getData().size());
}
/**

View File

@@ -10,6 +10,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
Response() = default;
virtual ~Response() = default;
Response(const Response& other) = default;
Response(Response&& other) = default;
Response& operator = (const Response& other) = default;
Response& operator = (Response&& other) = default;
virtual void init(const std::vector<unsigned char>& rawResponse);
[[nodiscard]] unsigned char getResponseId() const {

View File

@@ -12,11 +12,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
AVR8_BREAK_EVENT = 0x40,
};
inline bool operator==(unsigned char rawId, AvrEventId id) {
inline bool operator == (unsigned char rawId, AvrEventId id) {
return static_cast<unsigned char>(id) == rawId;
}
inline bool operator==(AvrEventId id, unsigned char rawId) {
inline bool operator == (AvrEventId id, unsigned char rawId) {
return rawId == id;
}

View File

@@ -26,6 +26,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
AvrCommandFrame::lastSequenceId = 0;
}
};
virtual ~AvrCommandFrame() = default;
AvrCommandFrame(const AvrCommandFrame& other) = default;
AvrCommandFrame(AvrCommandFrame&& other) = default;
AvrCommandFrame& operator = (const AvrCommandFrame& other) = default;
AvrCommandFrame& operator = (AvrCommandFrame&& other) = default;
[[nodiscard]] unsigned char getProtocolVersion() const {
return this->protocolVersion;

View File

@@ -18,19 +18,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
FAILED = 0xA0,
};
inline bool operator==(unsigned char rawId, ResponseId id) {
inline bool operator == (unsigned char rawId, ResponseId id) {
return static_cast<unsigned char>(id) == rawId;
}
inline bool operator==(ResponseId id, unsigned char rawId) {
inline bool operator == (ResponseId id, unsigned char rawId) {
return static_cast<unsigned char>(id) == rawId;
}
inline bool operator!=(unsigned char rawId, ResponseId id) {
inline bool operator != (unsigned char rawId, ResponseId id) {
return static_cast<unsigned char>(id) != rawId;
}
inline bool operator!=(ResponseId id, unsigned char rawId) {
inline bool operator != (ResponseId id, unsigned char rawId) {
return static_cast<unsigned char>(id) != rawId;
}

View File

@@ -13,11 +13,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
FAILED_WITH_DATA = 0xA1
};
inline bool operator==(unsigned char rawId, ResponseId id) {
inline bool operator == (unsigned char rawId, ResponseId id) {
return static_cast<unsigned char>(id) == rawId;
}
inline bool operator==(ResponseId id, unsigned char rawId) {
inline bool operator == (ResponseId id, unsigned char rawId) {
return rawId == id;
}

View File

@@ -20,6 +20,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
this->initFromAvrResponses(AVRResponses);
}
virtual ~AvrResponseFrame() = default;
AvrResponseFrame(const AvrResponseFrame& other) = default;
AvrResponseFrame(AvrResponseFrame&& other) = default;
AvrResponseFrame& operator = (const AvrResponseFrame& other) = default;
AvrResponseFrame& operator = (AvrResponseFrame&& other) = default;
/**
* An AVRResponse contains a single fragment of an AvrResponseFrame.
*