1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Optimize SoftwareSerial::setRxIntMsk()

This precalculates the mask register and value, making setRxIntMask
considerably less complicated. Right now, this is not a big deal, but
simplifying it allows using it inside the ISR next.
This commit is contained in:
Matthijs Kooijman 2014-04-23 19:13:58 +02:00
parent ddbe3174f0
commit ce6b0f89e3
2 changed files with 9 additions and 2 deletions

View File

@ -403,6 +403,11 @@ void SoftwareSerial::begin(long speed)
// (others might also need it, so we disable the interrupt by using // (others might also need it, so we disable the interrupt by using
// the per-pin PCMSK register). // the per-pin PCMSK register).
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin)); *digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
// Precalculate the pcint mask register and value, so setRxIntMask
// can be used inside the ISR without costing too much time.
_pcint_maskreg = digitalPinToPCMSK(_receivePin);
_pcint_maskvalue = _BV(digitalPinToPCMSKbit(_receivePin));
tunedDelay(_tx_delay); // if we were low this establishes the end tunedDelay(_tx_delay); // if we were low this establishes the end
} }
@ -417,9 +422,9 @@ void SoftwareSerial::begin(long speed)
void SoftwareSerial::setRxIntMsk(bool enable) void SoftwareSerial::setRxIntMsk(bool enable)
{ {
if (enable) if (enable)
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin)); *_pcint_maskreg |= _pcint_maskvalue;
else else
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin)); *_pcint_maskreg &= ~_pcint_maskvalue;
} }
void SoftwareSerial::end() void SoftwareSerial::end()

View File

@ -53,6 +53,8 @@ private:
volatile uint8_t *_receivePortRegister; volatile uint8_t *_receivePortRegister;
uint8_t _transmitBitMask; uint8_t _transmitBitMask;
volatile uint8_t *_transmitPortRegister; volatile uint8_t *_transmitPortRegister;
volatile uint8_t *_pcint_maskreg;
uint8_t _pcint_maskvalue;
uint16_t _rx_delay_centering; uint16_t _rx_delay_centering;
uint16_t _rx_delay_intrabit; uint16_t _rx_delay_intrabit;