Update documentation about timing in the wait loops

This commit is contained in:
Jared Hancock
2021-08-20 12:31:10 -05:00
committed by Rotzbua
parent c553f4df61
commit 3b760c359a

View File

@@ -163,10 +163,10 @@ MFRC522::StatusCode MFRC522::PCD_CalculateCRC( byte *data, ///< In: Pointer to
PCD_WriteRegister(FIFODataReg, length, data); // Write data to the FIFO PCD_WriteRegister(FIFODataReg, length, data); // Write data to the FIFO
PCD_WriteRegister(CommandReg, PCD_CalcCRC); // Start the calculation PCD_WriteRegister(CommandReg, PCD_CalcCRC); // Start the calculation
// Wait for the CRC calculation to complete. Each iteration of the while-loop takes 17.73μs. // Wait for the CRC calculation to complete. Check for the register to
// TODO check/modify for other architectures than Arduino Uno 16bit // indicate that the CRC calculation is complete in a loop. If the
// calculation is not indicated as complete in ~90ms, then time out
// Wait for the CRC calculation to complete. Each iteration of the while-loop takes 17.73us. // the operation.
uint32_t deadline = millis() + 89; uint32_t deadline = millis() + 89;
do { do {
@@ -181,7 +181,7 @@ MFRC522::StatusCode MFRC522::PCD_CalculateCRC( byte *data, ///< In: Pointer to
} }
yield(); yield();
} }
while (millis() < deadline); while (static_cast<uint32_t> (millis()) < deadline);
// 89ms passed and nothing happend. Communication with the MFRC522 might be down. // 89ms passed and nothing happend. Communication with the MFRC522 might be down.
return STATUS_TIMEOUT; return STATUS_TIMEOUT;
@@ -483,15 +483,21 @@ MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The co
PCD_SetRegisterBitMask(BitFramingReg, 0x80); // StartSend=1, transmission of data starts PCD_SetRegisterBitMask(BitFramingReg, 0x80); // StartSend=1, transmission of data starts
} }
// Wait for the command to complete. // In PCD_Init() we set the TAuto flag in TModeReg. This means the timer
// In PCD_Init() we set the TAuto flag in TModeReg. This means the timer automatically starts when the PCD stops transmitting. // automatically starts when the PCD stops transmitting.
// Each iteration of the do-while-loop takes 17.86μs. //
// TODO check/modify for other architectures than Arduino Uno 16bit // Wait here for the command to complete. The bits specified in the
// `waitIRq` parameter define what bits constitute a completed command.
// When they are set in the ComIrqReg register, then the command is
// considered complete. If the command is not indicated as complete in
// ~36ms, then consider the command as timed out.
uint32_t deadline = millis() + 36; uint32_t deadline = millis() + 36;
bool completed = false;
do { do {
byte n = PCD_ReadRegister(ComIrqReg); // ComIrqReg[7..0] bits are: Set1 TxIRq RxIRq IdleIRq HiAlertIRq LoAlertIRq ErrIRq TimerIRq byte n = PCD_ReadRegister(ComIrqReg); // ComIrqReg[7..0] bits are: Set1 TxIRq RxIRq IdleIRq HiAlertIRq LoAlertIRq ErrIRq TimerIRq
if (n & waitIRq) { // One of the interrupts that signal success has been set. if (n & waitIRq) { // One of the interrupts that signal success has been set.
completed = true;
break; break;
} }
if (n & 0x01) { // Timer interrupt - nothing received in 25ms if (n & 0x01) { // Timer interrupt - nothing received in 25ms
@@ -499,10 +505,10 @@ MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The co
} }
yield(); yield();
} }
while (millis() < deadline); while (static_cast<uint32_t> (millis()) < deadline);
// 35.7ms and nothing happend. Communication with the MFRC522 might be down. // 36ms and nothing happend. Communication with the MFRC522 might be down.
if (millis() >= deadline) { if (!completed) {
return STATUS_TIMEOUT; return STATUS_TIMEOUT;
} }