diff --git a/src/shared/radio/MavlinkDriver/MavlinkDriver.h b/src/shared/radio/MavlinkDriver/MavlinkDriver.h index 81607862cfe14f10b7de94b1faf00bd2fcce23bb..a1186fc2505ea36d780c40b89889ee4adb7572f5 100644 --- a/src/shared/radio/MavlinkDriver/MavlinkDriver.h +++ b/src/shared/radio/MavlinkDriver/MavlinkDriver.h @@ -42,6 +42,8 @@ implementation before including MavlinkDriver.h" #include <radio/Transceiver.h> #include <utils/collections/SyncPacketQueue.h> +#include <functional> + #include "MavlinkStatus.h" namespace Boardcore diff --git a/src/shared/radio/SX1278/SX1278Common.cpp b/src/shared/radio/SX1278/SX1278Common.cpp index a4cc12d11b023225a5504b94801a93956e9772fb..83a24b9cd9a9851729c481096370a85e03e5d9fa 100644 --- a/src/shared/radio/SX1278/SX1278Common.cpp +++ b/src/shared/radio/SX1278/SX1278Common.cpp @@ -23,6 +23,7 @@ #include "SX1278Common.h" #include <kernel/scheduler/scheduler.h> +#include <utils/Constants.h> namespace Boardcore { @@ -107,10 +108,10 @@ ISX1278::IrqFlags SX1278Common::waitForIrqBusy(LockMode &_guard, // otherwise don't do anything with it (void)_guard; - long long start = miosix::getTick(); + long long start = miosix::getTime(); IrqFlags ret_irq = 0; - while ((miosix::getTick() - start) < timeout) + while ((miosix::getTime() - start) < timeout * Constants::NS_IN_MS) { // Delay between polls const unsigned int DELAY = 100; @@ -143,7 +144,7 @@ bool SX1278Common::waitForIrqInner(LockMode &_guard, bool unlock) mutex.unlock(); } - int start = miosix::getTick(); + long long start = miosix::getTime(); miosix::TimedWaitResult result = miosix::TimedWaitResult::NoTimeout; { @@ -151,8 +152,8 @@ bool SX1278Common::waitForIrqInner(LockMode &_guard, bool unlock) while (state.irq_wait_thread && result == miosix::TimedWaitResult::NoTimeout) { - result = miosix::Thread::IRQenableIrqAndTimedWaitMs( - lock, start + IRQ_TIMEOUT); + result = miosix::Thread::IRQenableIrqAndTimedWait( + lock, start + IRQ_TIMEOUT * Constants::NS_IN_MS); } } diff --git a/src/shared/radio/SX1278/SX1278Fsk.cpp b/src/shared/radio/SX1278/SX1278Fsk.cpp index 1cf29fceea9de8e894c51ab6a1b1ba746164595c..20b68bf5f41c60559eeb2c941526fcb898795463 100644 --- a/src/shared/radio/SX1278/SX1278Fsk.cpp +++ b/src/shared/radio/SX1278/SX1278Fsk.cpp @@ -34,7 +34,7 @@ namespace Boardcore using namespace SX1278; using namespace SX1278::Fsk; -long long now() { return miosix::getTick() * 1000 / miosix::TICK_FREQ; } +long long now() { return miosix::getTime() / Constants::NS_IN_MS; } // Enable: // - PayloadReady, PacketSent on DIO0 (mode 00) diff --git a/src/shared/radio/Xbee/Xbee.cpp b/src/shared/radio/Xbee/Xbee.cpp index 35553d134b2a3598838e5c728cc9f327c08f7e55..8ae96029d6b9c19555d7d99acae722091cb0cf5f 100644 --- a/src/shared/radio/Xbee/Xbee.cpp +++ b/src/shared/radio/Xbee/Xbee.cpp @@ -64,7 +64,7 @@ bool Xbee::send(uint8_t* pkt, size_t packetLength) MAX_PACKET_PAYLOAD_LENGTH); return false; } - long long startTick = miosix::getTick(); + long long startTime = miosix::getTime(); TXRequestFrame txReq; uint8_t txFrameId = buildTXRequestFrame(txReq, pkt, packetLength); @@ -75,9 +75,9 @@ bool Xbee::send(uint8_t* pkt, size_t packetLength) writeFrame(txReq); // Wait for a TX Status frame - long long timeoutTick = miosix::getTick() + txTimeout; + long long timeoutTime = miosix::getTime() + txTimeout; - while (waitForFrame(FTYPE_TX_STATUS, FRAME_POLL_INTERVAL, timeoutTick)) + while (waitForFrame(FTYPE_TX_STATUS, FRAME_POLL_INTERVAL, timeoutTime)) { TXStatusFrame* f = parsingApiFrame.toFrameType<TXStatusFrame>(); @@ -106,7 +106,7 @@ bool Xbee::send(uint8_t* pkt, size_t packetLength) ++status.txTimeoutCount; LOG_ERR(logger, "TX_STATUS timeout"); } - timeToSendStats.add(miosix::getTick() - startTick); + timeToSendStats.add(miosix::getTime() - startTime); StackLogger::getInstance().updateStack(THID_XBEE); @@ -160,7 +160,7 @@ ssize_t Xbee::receive(uint8_t* buf, size_t bufMaxSize) XbeeStatus Xbee::getStatus() { - status.timestamp = miosix::getTick(); + status.timestamp = miosix::getTime(); status.timeToSendStats = timeToSendStats.getStats(); return status; } @@ -178,7 +178,7 @@ void Xbee::reset() // When the xbee is ready, we should assert SSEL to tell it to use // SPI, and it should provide us with a modem status frame - long long timeout = miosix::getTick() + 1000; + long long timeout = miosix::getTime() + 1 * Constants::NS_IN_S; do { // Assert SSEL on every iteration as we don't exactly know when the @@ -200,7 +200,7 @@ void Xbee::reset() break; } miosix::Thread::sleep(5); - } while (miosix::getTick() < timeout); + } while (miosix::getTime() < timeout); } void Xbee::wakeReceiver(bool forceReturn) @@ -293,7 +293,7 @@ bool Xbee::readRXFrame() void Xbee::writeFrame(APIFrame& frame) { - frame.timestamp = miosix::getTick(); // Only for logging purposes + frame.timestamp = miosix::getTime(); // Only for logging purposes // Serialize the frame uint8_t txBuf[MAX_API_FRAME_SIZE]; @@ -319,7 +319,7 @@ void Xbee::writeFrame(APIFrame& frame) } bool Xbee::waitForFrame(uint8_t frameType, unsigned int pollInterval, - long long timeoutTick) + long long timeoutTime) { do { @@ -337,7 +337,7 @@ bool Xbee::waitForFrame(uint8_t frameType, unsigned int pollInterval, { miosix::Thread::sleep(pollInterval); } - } while (miosix::getTick() < timeoutTick); + } while (miosix::getTime() < timeoutTime); return false; } @@ -380,10 +380,10 @@ bool Xbee::sendATCommand(const char* cmd, ATCommandResponseFrame* response, bool success = false; - long long timeoutTick = miosix::getTick() + timeout; + long long timeoutTime = miosix::getTime() + (timeout * Constants::NS_IN_MS); while (waitForFrame(FTYPE_AT_COMMAND_RESPONSE, FRAME_POLL_INTERVAL, - timeoutTick)) + timeoutTime)) { ATCommandResponseFrame* f = parsingApiFrame.toFrameType<ATCommandResponseFrame>(); @@ -435,7 +435,7 @@ uint8_t Xbee::sendATCommandInternal(uint8_t txFrameId, const char* cmd, void Xbee::handleFrame(APIFrame& frame) { // Set the timestamp to the frame - frame.timestamp = miosix::getTick(); + frame.timestamp = miosix::getTime(); switch (frame.frameType) {