Skip to content

Commit 5ad7870

Browse files
committed
Port pulseIn to new architecture
The asm part doesn't change, so the only needed functions were a corrected microsecondsToClockCycles and portInputRegister
1 parent 45a61af commit 5ad7870

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

cores/arduino/Arduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ extern uint32_t F_CPU_CORRECTED;
8080

8181
uint16_t clockCyclesPerMicrosecondComp(uint32_t clk);
8282
uint16_t clockCyclesPerMicrosecond();
83-
uint16_t clockCyclesToMicroseconds(uint16_t cycles);
84-
uint32_t microsecondsToClockCycles(uint16_t microseconds);
83+
unsigned long clockCyclesToMicroseconds(unsigned long cycles);
84+
unsigned long microsecondsToClockCycles(unsigned long microseconds);
8585

8686
// Get the bit location within the hardware port of the given virtual pin.
8787
// This comes from the pins_*.c file for the active board configuration.

cores/arduino/wiring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ inline uint16_t clockCyclesPerMicrosecond(){
5858
return clockCyclesPerMicrosecondComp(F_CPU_CORRECTED);
5959
}
6060

61-
inline uint16_t clockCyclesToMicroseconds(uint16_t cycles){
61+
inline unsigned long clockCyclesToMicroseconds(unsigned long cycles){
6262
return ( cycles / clockCyclesPerMicrosecond() );
6363
}
6464

65-
inline uint32_t microsecondsToClockCycles(uint16_t microseconds){
65+
inline unsigned long microsecondsToClockCycles(unsigned long microseconds){
6666
return ( microseconds * clockCyclesPerMicrosecond() );
6767
}
6868

cores/arduino/wiring_pulse.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
#include "wiring_private.h"
2424
#include "pins_arduino.h"
2525

26-
// TODO: port to 4809
27-
28-
#if 0
29-
3026
/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
3127
* or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds
3228
* to 3 minutes in length, but must be called at least a few dozen microseconds
@@ -45,7 +41,7 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
4541

4642
// convert the timeout from microseconds to a number of times through
4743
// the initial loop; it takes approximately 16 clock cycles per iteration
48-
unsigned long maxloops = microsecondsToClockCycles(timeout, F_CPU)/16;
44+
unsigned long maxloops = microsecondsToClockCycles(timeout)/12;
4945

5046
unsigned long width = countPulseASM(portInputRegister(port), bit, stateMask, maxloops);
5147

@@ -94,6 +90,4 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
9490
return 0;
9591
}
9692
return micros() - start;
97-
}
98-
99-
#endif
93+
}

0 commit comments

Comments
 (0)