Open mdaiter opened 8 years ago
Have you tested the timing?
This code is fewer lines of source, and may compile to few bytes, but it does more work within the timing critical sections. The original was designed to push all the extra stuff outside of the interrupt disable regions.
Haven't tested the timing due to not having a board. However, it's just a boolean comparison. Would it really affect timing that much?
Yes, OneWire is timing critical. Especially on slow 8 bit processors like AVR, these small details matter.
yes, timing is critical, but the master is mostly dictating the timings. and a 1 MHz processor can waste a cycle and just spend 1µs on it. still ok. proposal to stay outside of atomic-code:
const uint8_t time_high = uint8_t(value ? 10 : 60);
const uint8_t time_low = uint8_t(value ? 55 : 5);
noInterrupts();
DIRECT_WRITE_LOW(_baseReg, _bitMask);
DIRECT_MODE_OUTPUT(_baseReg, _bitMask); // drive output low
delayMicroseconds(time_high);
DIRECT_WRITE_HIGH(_baseReg, _bitMask); // drive output high
interrupts();
delayMicroseconds(time_low);
There was redundant code within the if statement of the WriteBit function. Tried to reduce redundancy for compiler output's sake.