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

This commit is contained in:
John Arne Birkeland 2012-11-08 01:03:24 +01:00
parent 50a4838879
commit 97d85de361
2 changed files with 16 additions and 6 deletions

View File

@ -218,10 +218,15 @@ uint16_t APM_RC_APM1::InputCh(uint8_t ch)
return _HIL_override[ch];
}
// we need to stop interrupts to be sure we get a correct 16 bit value
cli();
// We need to block ICP4 interrupts during the read of 16 bit PWM values
uint8_t _timsk4 = TIMSK4;
TIMSK4 &= ~(1<<ICIE4);
// value
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
result >>= 1;

View File

@ -240,11 +240,16 @@ uint16_t APM_RC_APM2::InputCh(unsigned char 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
cli();
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
result >>= 1;