Browse Source

Optimized APM_RC.InputCh() to prevent global interrupt disable each time a value is read.

mission-4.1.18
John Arne Birkeland 12 years ago
parent
commit
97d85de361
  1. 11
      libraries/APM_RC/APM_RC_APM1.cpp
  2. 11
      libraries/APM_RC/APM_RC_APM2.cpp

11
libraries/APM_RC/APM_RC_APM1.cpp

@ -218,10 +218,15 @@ uint16_t APM_RC_APM1::InputCh(uint8_t ch)
return _HIL_override[ch]; return _HIL_override[ch];
} }
// we need to stop interrupts to be sure we get a correct 16 bit value // We need to block ICP4 interrupts during the read of 16 bit PWM values
cli(); uint8_t _timsk4 = TIMSK4;
TIMSK4 &= ~(1<<ICIE4);
// value
result = _PWM_RAW[ch]; result = _PWM_RAW[ch];
sei();
// Enable ICP4 interrupt if previously active
TIMSK4 = _timsk4;
// Because timer runs at 0.5us we need to do value/2 // Because timer runs at 0.5us we need to do value/2
result >>= 1; result >>= 1;

11
libraries/APM_RC/APM_RC_APM2.cpp

@ -240,11 +240,16 @@ uint16_t APM_RC_APM2::InputCh(unsigned char ch)
return _HIL_override[ch]; return _HIL_override[ch];
} }
// we need to block interrupts during the read of a 16 bit // We need to block ICP5 interrupts during the read of 16 bit PWM values
uint8_t _timsk5 = TIMSK5;
TIMSK5 &= ~(1<<ICIE5);
// value // value
cli();
result = _PWM_RAW[ch]; result = _PWM_RAW[ch];
sei();
// Enable ICP5 interrupt if previously active
TIMSK5 = _timsk5;
// Because timer runs at 0.5us we need to do value/2 // Because timer runs at 0.5us we need to do value/2
result >>= 1; result >>= 1;

Loading…
Cancel
Save