2016-01-10 02:23:32 -04:00
|
|
|
#pragma once
|
2012-12-12 18:04:27 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-05-04 03:15:12 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
#include "AP_HAL_SITL_Namespace.h"
|
2012-12-12 18:04:27 -04:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#define SITL_SCHEDULER_MAX_TIMER_PROCS 4
|
|
|
|
|
|
|
|
/* Scheduler implementation: */
|
2016-01-10 02:23:32 -04:00
|
|
|
class HALSITL::Scheduler : public AP_HAL::Scheduler {
|
2012-12-12 18:04:27 -04:00
|
|
|
public:
|
2016-01-10 02:23:32 -04:00
|
|
|
Scheduler(SITL_State *sitlState);
|
|
|
|
static Scheduler *from(AP_HAL::Scheduler *scheduler) {
|
|
|
|
return static_cast<HALSITL::Scheduler*>(scheduler);
|
2015-09-13 15:28:02 -03:00
|
|
|
}
|
|
|
|
|
2012-12-12 18:04:27 -04:00
|
|
|
/* AP_HAL::Scheduler methods */
|
|
|
|
|
2015-12-02 11:14:20 -04:00
|
|
|
void init();
|
2012-12-19 22:16:10 -04:00
|
|
|
void delay(uint16_t ms);
|
2012-12-12 18:04:27 -04:00
|
|
|
void delay_microseconds(uint16_t us);
|
|
|
|
void register_delay_callback(AP_HAL::Proc, uint16_t min_time_ms);
|
2013-01-03 21:32:52 -04:00
|
|
|
|
2013-09-30 07:35:42 -03:00
|
|
|
void register_timer_process(AP_HAL::MemberProc);
|
|
|
|
void register_io_process(AP_HAL::MemberProc);
|
2012-12-12 18:04:27 -04:00
|
|
|
void suspend_timer_procs();
|
|
|
|
void resume_timer_procs();
|
2013-01-03 21:32:52 -04:00
|
|
|
|
2013-01-10 17:50:32 -04:00
|
|
|
bool in_timerprocess();
|
|
|
|
|
2013-09-30 07:35:42 -03:00
|
|
|
void register_timer_failsafe(AP_HAL::Proc, uint32_t period_us);
|
2013-01-10 17:50:32 -04:00
|
|
|
|
|
|
|
void system_initialized();
|
|
|
|
|
2013-09-03 22:58:13 -03:00
|
|
|
void reboot(bool hold_in_bootloader);
|
2012-12-12 18:04:27 -04:00
|
|
|
|
2015-05-04 21:59:07 -03:00
|
|
|
bool interrupts_are_blocked(void) {
|
|
|
|
return _nested_atomic_ctr != 0;
|
|
|
|
}
|
2012-12-13 18:57:01 -04:00
|
|
|
|
2015-05-04 21:59:07 -03:00
|
|
|
void sitl_begin_atomic() {
|
|
|
|
_nested_atomic_ctr++;
|
|
|
|
}
|
2013-01-03 21:32:52 -04:00
|
|
|
void sitl_end_atomic();
|
2012-12-13 18:57:01 -04:00
|
|
|
|
2015-05-04 21:59:07 -03:00
|
|
|
static void timer_event() {
|
|
|
|
_run_timer_procs(true);
|
|
|
|
_run_io_procs(true);
|
|
|
|
}
|
2012-12-13 18:57:01 -04:00
|
|
|
|
2015-11-11 09:43:18 -04:00
|
|
|
uint64_t stopped_clock_usec() const { return _stopped_clock_usec; }
|
|
|
|
|
2012-12-12 18:04:27 -04:00
|
|
|
private:
|
2014-11-15 20:04:55 -04:00
|
|
|
SITL_State *_sitlState;
|
2012-12-12 18:04:27 -04:00
|
|
|
uint8_t _nested_atomic_ctr;
|
|
|
|
AP_HAL::Proc _delay_cb;
|
|
|
|
uint16_t _min_delay_cb_ms;
|
2013-09-30 07:35:42 -03:00
|
|
|
static AP_HAL::Proc _failsafe;
|
2012-12-12 18:04:27 -04:00
|
|
|
|
2013-01-03 21:32:52 -04:00
|
|
|
static void _run_timer_procs(bool called_from_isr);
|
2013-04-17 08:33:50 -03:00
|
|
|
static void _run_io_procs(bool called_from_isr);
|
2013-01-03 21:32:52 -04:00
|
|
|
|
2012-12-12 18:04:27 -04:00
|
|
|
static volatile bool _timer_suspended;
|
2013-01-03 21:32:52 -04:00
|
|
|
static volatile bool _timer_event_missed;
|
2013-09-30 07:35:42 -03:00
|
|
|
static AP_HAL::MemberProc _timer_proc[SITL_SCHEDULER_MAX_TIMER_PROCS];
|
|
|
|
static AP_HAL::MemberProc _io_proc[SITL_SCHEDULER_MAX_TIMER_PROCS];
|
2012-12-12 18:04:27 -04:00
|
|
|
static uint8_t _num_timer_procs;
|
2013-04-17 08:33:50 -03:00
|
|
|
static uint8_t _num_io_procs;
|
2012-12-12 18:04:27 -04:00
|
|
|
static bool _in_timer_proc;
|
2013-04-17 08:33:50 -03:00
|
|
|
static bool _in_io_proc;
|
2012-12-12 18:04:27 -04:00
|
|
|
|
2015-03-21 11:27:25 -03:00
|
|
|
void stop_clock(uint64_t time_usec);
|
2013-01-10 17:50:32 -04:00
|
|
|
|
2015-03-21 11:27:25 -03:00
|
|
|
bool _initialized;
|
2015-11-11 09:43:18 -04:00
|
|
|
uint64_t _stopped_clock_usec;
|
2012-12-12 18:04:27 -04:00
|
|
|
};
|
2016-01-10 02:23:32 -04:00
|
|
|
#endif // CONFIG_HAL_BOARD
|
|
|
|
|
|
|
|
|
2012-12-12 18:04:27 -04:00
|
|
|
|
2012-12-13 18:57:01 -04:00
|
|
|
|