2021-08-15 01:47:48 +01:00
|
|
|
#include "CmsisDapInterface.hpp"
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.hpp"
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
|
|
|
|
{
|
|
|
|
|
using namespace Bloom::Exceptions;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-10-01 16:50:57 +01:00
|
|
|
CmsisDapInterface::CmsisDapInterface(Usb::HidInterface&& usbHidInterface)
|
|
|
|
|
: usbHidInterface(std::move(usbHidInterface))
|
|
|
|
|
{}
|
|
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
void CmsisDapInterface::sendCommand(const Command& cmsisDapCommand) {
|
|
|
|
|
if (this->msSendCommandDelay.count() > 0) {
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
std::int64_t now = duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
|
|
|
|
|
std::int64_t difference = (now - this->lastCommandSentTimeStamp);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (difference < this->msSendCommandDelay.count()) {
|
|
|
|
|
std::this_thread::sleep_for(milliseconds(this->msSendCommandDelay.count() - difference));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->lastCommandSentTimeStamp = now;
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 22:53:04 +00:00
|
|
|
this->getUsbHidInterface().write(cmsisDapCommand.rawCommand());
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
}
|