mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Merge pull request #3864 from facchinm/pulseInLongOVF
fix pulseInLong considering overflow
This commit is contained in:
commit
53049046cb
@ -69,22 +69,24 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
|
|||||||
uint8_t port = digitalPinToPort(pin);
|
uint8_t port = digitalPinToPort(pin);
|
||||||
uint8_t stateMask = (state ? bit : 0);
|
uint8_t stateMask = (state ? bit : 0);
|
||||||
|
|
||||||
unsigned long maxMicros = micros() + timeout;
|
unsigned long startMicros = micros();
|
||||||
|
|
||||||
// wait for any previous pulse to end
|
// wait for any previous pulse to end
|
||||||
while ((*portInputRegister(port) & bit) == stateMask)
|
while ((*portInputRegister(port) & bit) == stateMask) {
|
||||||
if (micros() > maxMicros)
|
if (micros() - startMicros > timeout)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// wait for the pulse to start
|
// wait for the pulse to start
|
||||||
while ((*portInputRegister(port) & bit) != stateMask)
|
while ((*portInputRegister(port) & bit) != stateMask) {
|
||||||
if (micros() > maxMicros)
|
if (micros() - startMicros > timeout)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long start = micros();
|
unsigned long start = micros();
|
||||||
// wait for the pulse to stop
|
// wait for the pulse to stop
|
||||||
while ((*portInputRegister(port) & bit) == stateMask) {
|
while ((*portInputRegister(port) & bit) == stateMask) {
|
||||||
if (micros() > maxMicros)
|
if (micros() - startMicros > timeout)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return micros() - start;
|
return micros() - start;
|
||||||
|
@ -69,22 +69,24 @@ uint32_t pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
|
|||||||
uint32_t bit = p.ulPin;
|
uint32_t bit = p.ulPin;
|
||||||
uint32_t stateMask = state ? bit : 0;
|
uint32_t stateMask = state ? bit : 0;
|
||||||
|
|
||||||
unsigned long maxMicros = micros() + timeout;
|
unsigned long startMicros = micros();
|
||||||
|
|
||||||
// wait for any previous pulse to end
|
// wait for any previous pulse to end
|
||||||
while ((p.pPort->PIO_PDSR & bit) == stateMask)
|
while ((p.pPort->PIO_PDSR & bit) == stateMask) {
|
||||||
if (micros() > maxMicros)
|
if (micros() - startMicros > timeout)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// wait for the pulse to start
|
// wait for the pulse to start
|
||||||
while ((p.pPort->PIO_PDSR & bit) != stateMask)
|
while ((p.pPort->PIO_PDSR & bit) != stateMask) {
|
||||||
if (micros() > maxMicros)
|
if (micros() - startMicros > timeout)
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long start = micros();
|
unsigned long start = micros();
|
||||||
// wait for the pulse to stop
|
// wait for the pulse to stop
|
||||||
while ((p.pPort->PIO_PDSR & bit) == stateMask) {
|
while ((p.pPort->PIO_PDSR & bit) == stateMask) {
|
||||||
if (micros() > maxMicros)
|
if (micros() - startMicros > timeout)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return micros() - start;
|
return micros() - start;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user