mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-26 01:33:56 -04:00
HAL_ChibiOS: gain back 250usec in loop time
if we have already called delay_microseconds_boost() then we know we've given up time to drivers, so we can avoid the extra delay in the HAL
This commit is contained in:
parent
e0c9d9b592
commit
b7c4dea9d3
@ -145,10 +145,16 @@ static THD_FUNCTION(main_loop,arg)
|
||||
g_callbacks->loop();
|
||||
|
||||
/*
|
||||
give up 250 microseconds of time, to ensure drivers get a
|
||||
chance to run.
|
||||
give up 250 microseconds of time if the INS loop hasn't
|
||||
called delay_microseconds_boost(), to ensure low priority
|
||||
drivers get a chance to run. Calling
|
||||
delay_microseconds_boost() means we have already given up
|
||||
time from the main loop, so we don't need to do it again
|
||||
here
|
||||
*/
|
||||
hal.scheduler->delay_microseconds(250);
|
||||
if (!schedulerInstance.check_called_boost()) {
|
||||
hal.scheduler->delay_microseconds(250);
|
||||
}
|
||||
}
|
||||
thread_running = false;
|
||||
}
|
||||
|
@ -132,10 +132,22 @@ static void set_normal_priority()
|
||||
*/
|
||||
void Scheduler::delay_microseconds_boost(uint16_t usec)
|
||||
{
|
||||
delay_microseconds(usec); //Suspends Thread for desired microseconds
|
||||
set_high_priority();
|
||||
delay_microseconds(APM_MAIN_PRIORITY_BOOST_USEC);
|
||||
delay_microseconds(usec); //Suspends Thread for desired microseconds
|
||||
set_normal_priority();
|
||||
_called_boost = true;
|
||||
}
|
||||
|
||||
/*
|
||||
return true if delay_microseconds_boost() has been called since last check
|
||||
*/
|
||||
bool Scheduler::check_called_boost(void)
|
||||
{
|
||||
if (!_called_boost) {
|
||||
return false;
|
||||
}
|
||||
_called_boost = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Scheduler::delay(uint16_t ms)
|
||||
|
@ -49,21 +49,6 @@
|
||||
#define APM_I2C_PRIORITY 176
|
||||
#endif
|
||||
|
||||
/* how long to boost priority of the main thread for each main
|
||||
loop. This needs to be long enough for all interrupt-level drivers
|
||||
(mostly SPI drivers) to run, and for the main loop of the vehicle
|
||||
code to start the AHRS update.
|
||||
|
||||
Priority boosting of the main thread in delay_microseconds_boost()
|
||||
avoids the problem that drivers in hpwork all happen to run right
|
||||
at the start of the period where the main vehicle loop is calling
|
||||
wait_for_sample(). That causes main loop timing jitter, which
|
||||
reduces performance. Using the priority boost the main loop
|
||||
temporarily runs at a priority higher than hpwork and the timer
|
||||
thread, which results in much more consistent loop timing.
|
||||
*/
|
||||
#define APM_MAIN_PRIORITY_BOOST_USEC 150
|
||||
|
||||
#define APM_MAIN_THREAD_STACK_SIZE 8192
|
||||
|
||||
/* Scheduler implementation: */
|
||||
@ -89,13 +74,16 @@ public:
|
||||
void system_initialized();
|
||||
void hal_initialized() { _hal_initialized = true; }
|
||||
|
||||
bool check_called_boost(void);
|
||||
|
||||
private:
|
||||
bool _initialized;
|
||||
volatile bool _hal_initialized;
|
||||
AP_HAL::Proc _delay_cb;
|
||||
uint16_t _min_delay_cb_ms;
|
||||
AP_HAL::Proc _failsafe;
|
||||
|
||||
bool _called_boost;
|
||||
|
||||
volatile bool _timer_suspended;
|
||||
|
||||
AP_HAL::MemberProc _timer_proc[CHIBIOS_SCHEDULER_MAX_TIMER_PROCS];
|
||||
|
Loading…
Reference in New Issue
Block a user