Skip to content

Commit 6849fe3

Browse files
authored
Merge pull request #6 from espreng/api-avr4809-master
Bug fix: Backwards compatibility broken on clockCycles.. functions
2 parents 602fb66 + 8004fa5 commit 6849fe3

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

cores/arduino/Arduino.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ extern "C"{
7878
PERFORM_SIGROW_CORRECTION_F_CPU = 1 */
7979
extern uint32_t F_CPU_CORRECTED;
8080

81-
uint16_t clockCyclesPerMicrosecond(uint32_t clk);
82-
uint16_t clockCyclesToMicroseconds(uint16_t cycles, uint32_t clk);
83-
uint32_t microsecondsToClockCycles(uint16_t cycles, uint32_t clk);
81+
uint16_t clockCyclesPerMicrosecondComp(uint32_t clk);
82+
uint16_t clockCyclesPerMicrosecond();
83+
uint16_t clockCyclesToMicroseconds(uint16_t cycles);
84+
uint32_t microsecondsToClockCycles(uint16_t microseconds);
8485

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

cores/arduino/wiring.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ volatile uint32_t timerb3_overflow_count = 0;
5050
volatile uint32_t timerb3_millis = 0;
5151
static uint16_t timerb3_fract = 0;
5252

53-
inline uint16_t clockCyclesPerMicrosecond(uint32_t clk ){
53+
inline uint16_t clockCyclesPerMicrosecondComp(uint32_t clk){
5454
return ( (clk) / 1000000L );
5555
}
5656

57-
inline uint16_t clockCyclesToMicroseconds(uint16_t cycles, uint32_t clk){
58-
return ( cycles / clockCyclesPerMicrosecond(clk) );
57+
inline uint16_t clockCyclesPerMicrosecond(){
58+
return clockCyclesPerMicrosecondComp(F_CPU_CORRECTED);
5959
}
6060

61-
inline uint32_t microsecondsToClockCycles(uint16_t cycles, uint32_t clk){
62-
return ( cycles * clockCyclesPerMicrosecond(clk) );
61+
inline uint16_t clockCyclesToMicroseconds(uint16_t cycles){
62+
return ( cycles / clockCyclesPerMicrosecond() );
63+
}
64+
65+
inline uint32_t microsecondsToClockCycles(uint16_t microseconds){
66+
return ( microseconds * clockCyclesPerMicrosecond() );
6367
}
6468

6569
ISR(TCB3_INT_vect)
@@ -545,7 +549,7 @@ void init()
545549
/********************* TCB3 for system time tracking **************************/
546550

547551
/* Calculate relevant time tracking values */
548-
microseconds_per_timerb3_overflow = clockCyclesToMicroseconds(TIME_TRACKING_CYCLES_PER_OVF, F_CPU_CORRECTED);
552+
microseconds_per_timerb3_overflow = clockCyclesToMicroseconds(TIME_TRACKING_CYCLES_PER_OVF);
549553
microseconds_per_timerb3_tick = microseconds_per_timerb3_overflow/TIME_TRACKING_TIMER_PERIOD;
550554

551555
millis_inc = microseconds_per_timerb3_overflow / 1000;

0 commit comments

Comments
 (0)