2012-12-12 18:04:27 -04:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_SITL_SCHEDULER_H__
|
|
|
|
#define __AP_HAL_SITL_SCHEDULER_H__
|
|
|
|
|
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: */
|
2015-05-04 03:15:12 -03:00
|
|
|
class HALSITL::SITLScheduler : public AP_HAL::Scheduler {
|
2012-12-12 18:04:27 -04:00
|
|
|
public:
|
2014-11-15 20:04:55 -04:00
|
|
|
SITLScheduler(SITL_State *sitlState);
|
2015-09-13 15:28:02 -03:00
|
|
|
static SITLScheduler *from(AP_HAL::Scheduler *scheduler) {
|
|
|
|
return static_cast<SITLScheduler*>(scheduler);
|
|
|
|
}
|
|
|
|
|
2012-12-12 18:04:27 -04:00
|
|
|
/* AP_HAL::Scheduler methods */
|
|
|
|
|
|
|
|
void init(void *unused);
|
2012-12-19 22:16:10 -04:00
|
|
|
void delay(uint16_t ms);
|
2012-12-12 18:04:27 -04:00
|
|
|
uint32_t millis();
|
|
|
|
uint32_t micros();
|
2014-08-19 18:57:45 -03:00
|
|
|
uint64_t millis64();
|
|
|
|
uint64_t micros64();
|
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
|
|
|
|
|
|
|
bool system_initializing();
|
|
|
|
void system_initialized();
|
|
|
|
|
2013-09-03 22:58:13 -03:00
|
|
|
void reboot(bool hold_in_bootloader);
|
2015-10-26 08:25:44 -03:00
|
|
|
void panic(const char *errormsg, ...) FORMAT(2, 3) NORETURN;
|
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
|
|
|
|
|
|
|
// callable from interrupt handler
|
2014-08-19 18:57:45 -03:00
|
|
|
static uint64_t _micros64();
|
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
|
|
|
|
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;
|
2012-12-13 18:57:01 -04:00
|
|
|
static struct timeval _sketch_start_time;
|
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-05-02 08:41:13 -03:00
|
|
|
uint64_t stopped_clock_usec;
|
2012-12-12 18:04:27 -04:00
|
|
|
};
|
2012-12-13 18:57:01 -04:00
|
|
|
#endif
|
2012-12-12 18:04:27 -04:00
|
|
|
#endif // __AP_HAL_SITL_SCHEDULER_H__
|
|
|
|
|
2012-12-13 18:57:01 -04:00
|
|
|
|