2018-05-08 02:47:08 -03:00
|
|
|
#include "Scheduler.h"
|
2019-05-11 05:16:51 -03:00
|
|
|
#include "AP_HAL.h"
|
2022-12-03 18:48:07 -04:00
|
|
|
#include <stdio.h>
|
2018-05-08 02:47:08 -03:00
|
|
|
|
|
|
|
using namespace AP_HAL;
|
|
|
|
|
2019-05-15 01:09:13 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2018-05-08 02:47:08 -03:00
|
|
|
void Scheduler::register_delay_callback(AP_HAL::Proc proc,
|
|
|
|
uint16_t min_time_ms)
|
|
|
|
{
|
|
|
|
_delay_cb = proc;
|
|
|
|
_min_delay_cb_ms = min_time_ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scheduler::call_delay_cb()
|
|
|
|
{
|
|
|
|
if (_delay_cb == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_in_delay_callback) {
|
|
|
|
// don't recurse!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_in_delay_callback = true;
|
|
|
|
_delay_cb();
|
|
|
|
_in_delay_callback = false;
|
|
|
|
}
|
2019-05-11 05:16:51 -03:00
|
|
|
|
2019-05-15 01:09:13 -03:00
|
|
|
ExpectDelay::ExpectDelay(uint32_t ms)
|
2019-05-11 05:16:51 -03:00
|
|
|
{
|
2019-05-15 01:09:13 -03:00
|
|
|
hal.scheduler->expect_delay_ms(ms);
|
2019-05-11 05:16:51 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
ExpectDelay::~ExpectDelay()
|
|
|
|
{
|
2019-05-15 01:09:13 -03:00
|
|
|
hal.scheduler->expect_delay_ms(0);
|
2019-05-11 05:16:51 -03:00
|
|
|
}
|
2022-12-03 18:48:07 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
implement TimeCheck class for TIME_CHECK() support
|
|
|
|
*/
|
|
|
|
TimeCheck::TimeCheck(uint32_t _limit_ms, const char *_file, uint32_t _line) :
|
|
|
|
limit_ms(_limit_ms),
|
2024-09-20 09:20:43 -03:00
|
|
|
line(_line),
|
|
|
|
file(_file)
|
2022-12-03 18:48:07 -04:00
|
|
|
{
|
|
|
|
start_ms = AP_HAL::millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeCheck::~TimeCheck()
|
|
|
|
{
|
|
|
|
const uint32_t end_ms = AP_HAL::millis();
|
|
|
|
const uint32_t delta_ms = end_ms - start_ms;
|
|
|
|
if (delta_ms > limit_ms) {
|
|
|
|
::printf("Delta %u at %s:%u\n", unsigned(delta_ms), file, unsigned(line));
|
|
|
|
}
|
|
|
|
}
|