HAL_ChibiOS: re-instate priority boost system
this adds back in the priority boost system for the main thread when waiting for a IMU sample. This significantly improves scheduling performance on very busy boards like a PH2.1
This commit is contained in:
parent
fff143d83e
commit
67993d6e5c
@ -51,6 +51,8 @@ Scheduler::Scheduler()
|
||||
|
||||
void Scheduler::init()
|
||||
{
|
||||
chVTObjectInit(&_boost_timer);
|
||||
|
||||
// setup the timer thread - this will call tasks at 1kHz
|
||||
_timer_thread_ctx = chThdCreateStatic(_timer_thread_wa,
|
||||
sizeof(_timer_thread_wa),
|
||||
@ -129,10 +131,12 @@ static void set_high_priority()
|
||||
/*
|
||||
return the main thread to normal priority
|
||||
*/
|
||||
static void set_normal_priority()
|
||||
static void set_normal_priority(void *ctx)
|
||||
{
|
||||
#if APM_MAIN_PRIORITY_BOOST != APM_MAIN_PRIORITY
|
||||
hal_chibios_set_priority(APM_MAIN_PRIORITY);
|
||||
thread_t *task = (thread_t *)ctx;
|
||||
// we don't need a reschedule as that happens automatically on ISR exit
|
||||
task->realprio = APM_MAIN_PRIORITY;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -140,13 +144,13 @@ static void set_normal_priority()
|
||||
a variant of delay_microseconds that boosts priority to
|
||||
APM_MAIN_PRIORITY_BOOST for APM_MAIN_PRIORITY_BOOST_USEC
|
||||
microseconds when the time completes. This significantly improves
|
||||
the regularity of timing of the main loop as it takes
|
||||
the regularity of timing of the main loop
|
||||
*/
|
||||
void Scheduler::delay_microseconds_boost(uint16_t usec)
|
||||
{
|
||||
set_high_priority();
|
||||
delay_microseconds(usec); //Suspends Thread for desired microseconds
|
||||
set_normal_priority();
|
||||
chVTSet(&_boost_timer, US2ST(200), set_normal_priority, chThdGetSelfX());
|
||||
_called_boost = true;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
#define CHIBIOS_SCHEDULER_MAX_TIMER_PROCS 8
|
||||
|
||||
#define APM_MAIN_PRIORITY_BOOST 180 // same as normal for now
|
||||
#define APM_MAIN_PRIORITY 180
|
||||
#define APM_TIMER_PRIORITY 178
|
||||
#define APM_RCIN_PRIORITY 177
|
||||
@ -33,6 +32,17 @@
|
||||
#define APM_SHELL_PRIORITY 57
|
||||
#define APM_STARTUP_PRIORITY 10
|
||||
|
||||
/*
|
||||
boost priority handling
|
||||
*/
|
||||
#ifndef APM_MAIN_PRIORITY_BOOST
|
||||
#define APM_MAIN_PRIORITY_BOOST 182
|
||||
#endif
|
||||
|
||||
#ifndef APM_MAIN_PRIORITY_BOOST_USEC
|
||||
#define APM_MAIN_PRIORITY_BOOST_USEC 200
|
||||
#endif
|
||||
|
||||
#ifndef APM_SPI_PRIORITY
|
||||
// SPI priority needs to be above main priority to ensure fast sampling of IMUs can keep up
|
||||
// with the data rate
|
||||
@ -110,6 +120,7 @@ private:
|
||||
|
||||
volatile bool _timer_event_missed;
|
||||
|
||||
virtual_timer_t _boost_timer;
|
||||
thread_t* _timer_thread_ctx;
|
||||
thread_t* _rcin_thread_ctx;
|
||||
thread_t* _io_thread_ctx;
|
||||
|
Loading…
Reference in New Issue
Block a user