2012-12-12 18:04:27 -04:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_SITL_SCHEDULER_H__
|
|
|
|
#define __AP_HAL_SITL_SCHEDULER_H__
|
|
|
|
|
|
|
|
#include <AP_HAL.h>
|
2012-12-13 18:57:01 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL
|
2012-12-12 18:04:27 -04:00
|
|
|
#include "AP_HAL_AVR_SITL_Namespace.h"
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#define SITL_SCHEDULER_MAX_TIMER_PROCS 4
|
|
|
|
|
|
|
|
/* Scheduler implementation: */
|
2012-12-13 18:57:01 -04:00
|
|
|
class AVR_SITL::SITLScheduler : public AP_HAL::Scheduler {
|
2012-12-12 18:04:27 -04:00
|
|
|
public:
|
|
|
|
SITLScheduler();
|
|
|
|
/* 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();
|
|
|
|
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
|
|
|
|
2012-12-12 18:04:27 -04:00
|
|
|
void register_timer_process(AP_HAL::TimedProc);
|
2013-04-17 08:33:50 -03:00
|
|
|
void register_io_process(AP_HAL::TimedProc);
|
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-01-03 21:32:52 -04:00
|
|
|
void register_timer_failsafe(AP_HAL::TimedProc, uint32_t period_us);
|
2013-01-10 17:50:32 -04:00
|
|
|
|
|
|
|
bool system_initializing();
|
|
|
|
void system_initialized();
|
|
|
|
|
2012-12-12 18:04:27 -04:00
|
|
|
void reboot();
|
2012-12-17 22:42:38 -04:00
|
|
|
void panic(const prog_char_t *errormsg);
|
2012-12-12 18:04:27 -04:00
|
|
|
|
2012-12-13 18:57:01 -04:00
|
|
|
bool interrupts_are_blocked(void) { return _nested_atomic_ctr != 0; }
|
|
|
|
|
2013-01-03 21:32:52 -04:00
|
|
|
void sitl_begin_atomic() { _nested_atomic_ctr++; }
|
|
|
|
void sitl_end_atomic();
|
2012-12-13 18:57:01 -04:00
|
|
|
|
|
|
|
// callable from interrupt handler
|
|
|
|
static uint32_t _micros();
|
2013-04-17 08:33:50 -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:
|
|
|
|
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;
|
2012-12-12 18:04:27 -04:00
|
|
|
static AP_HAL::TimedProc _failsafe;
|
|
|
|
|
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;
|
2012-12-12 18:04:27 -04:00
|
|
|
static AP_HAL::TimedProc _timer_proc[SITL_SCHEDULER_MAX_TIMER_PROCS];
|
2013-04-17 08:33:50 -03:00
|
|
|
static AP_HAL::TimedProc _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
|
|
|
|
2013-01-10 17:50:32 -04:00
|
|
|
bool _initialized;
|
|
|
|
|
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
|
|
|
|