Skip to content

Commit 69c6dfa

Browse files
committed
Add simpler checkUblox locking
1 parent 4ffee19 commit 69c6dfa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/u-blox_GNSS.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,16 @@ const char *DevUBLOXGNSS::statusString(sfe_ublox_status_e stat)
10481048
}
10491049

10501050
// Check for the arrival of new I2C/Serial/SPI data
1051-
10521051
// Called regularly to check for available bytes on the user' specified port
1052+
1053+
void DevUBLOXGNSS::lockCheckUblox(void) { if (_enableCheckUbloxLock) _checkUbloxLock = true; }
1054+
void DevUBLOXGNSS::unlockCheckUblox(void) { _checkUbloxLock = false; }
1055+
10531056
bool DevUBLOXGNSS::checkUblox(uint8_t requestedClass, uint8_t requestedID)
10541057
{
1058+
if (_checkUbloxLock)
1059+
return false;
1060+
10551061
return checkUbloxInternal(&packetCfg, requestedClass, requestedID);
10561062
}
10571063

@@ -4621,6 +4627,8 @@ void DevUBLOXGNSS::addToChecksum(uint8_t incoming)
46214627
// Given a packet and payload, send everything including CRC bytes via I2C port
46224628
sfe_ublox_status_e DevUBLOXGNSS::sendCommand(ubxPacket *outgoingUBX, uint16_t maxWait, bool expectACKonly)
46234629
{
4630+
lockCheckUblox();
4631+
46244632
if (!lock()) return SFE_UBLOX_STATUS_FAIL;
46254633

46264634
sfe_ublox_status_e retVal = SFE_UBLOX_STATUS_SUCCESS;
@@ -4646,6 +4654,8 @@ sfe_ublox_status_e DevUBLOXGNSS::sendCommand(ubxPacket *outgoingUBX, uint16_t ma
46464654
_debugSerial.println(F("Send I2C Command failed"));
46474655
}
46484656
#endif
4657+
unlock();
4658+
unlockCheckUblox();
46494659
return retVal;
46504660
}
46514661
}
@@ -4688,6 +4698,9 @@ sfe_ublox_status_e DevUBLOXGNSS::sendCommand(ubxPacket *outgoingUBX, uint16_t ma
46884698
{
46894699
processSpiBuffer(&packetCfg, 0, 0); // Process any SPI data received during the sendSpiCommand - but only if not checking for a response
46904700
}
4701+
4702+
unlockCheckUblox();
4703+
46914704
return retVal;
46924705
}
46934706

src/u-blox_GNSS.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,19 @@ class DevUBLOXGNSS
136136
// Flag to indicate if we are connected to UART1 or UART2
137137
// Needed to select the correct config items when enabling a periodic message
138138
bool _UART2 = false; // Default to UART1
139+
139140
// the lock / unlock functions can be used if you have multiple tasks writing to the bus.
140141
// the idea is that in a RTOS you override this class and the two functions in which you take and give a mutex.
141142
virtual bool lock(void) { return true; }
142143
virtual void unlock(void) { }
143144

145+
// A simpler lock to prevent checkUblox from being called while a sendCommand and waitForResponse is in progress
146+
void lockCheckUblox(void) __attribute__((weak));
147+
void unlockCheckUblox(void) __attribute__((weak));
148+
volatile bool _checkUbloxLock = false;
149+
public:
150+
volatile bool _enableCheckUbloxLock = false; // Change this to true to enable simple checkUblox locking
151+
144152
public:
145153
void connectedToUART2(bool connected = true) { _UART2 = connected; }
146154

0 commit comments

Comments
 (0)