2012-08-23 15:36:13 -03:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_AVR_SCHEDULER_H__
|
|
|
|
#define __AP_HAL_AVR_SCHEDULER_H__
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2012-08-23 15:36:13 -03:00
|
|
|
#include "AP_HAL_AVR_Namespace.h"
|
|
|
|
|
2012-09-07 20:07:38 -03:00
|
|
|
#define AVR_SCHEDULER_MAX_TIMER_PROCS 4
|
|
|
|
|
2012-12-06 19:24:55 -04:00
|
|
|
/* Class for managing the AVR Timers: */
|
|
|
|
class AP_HAL_AVR::AVRTimer {
|
|
|
|
public:
|
|
|
|
static void init();
|
|
|
|
static uint32_t millis();
|
|
|
|
static uint32_t micros();
|
|
|
|
static void delay_microseconds(uint16_t us);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Scheduler implementation: */
|
2012-11-28 21:53:35 -04:00
|
|
|
class AP_HAL_AVR::AVRScheduler : public AP_HAL::Scheduler {
|
2012-08-23 15:36:13 -03:00
|
|
|
public:
|
2012-11-28 21:53:35 -04:00
|
|
|
AVRScheduler();
|
2012-08-23 15:36:13 -03:00
|
|
|
/* AP_HAL::Scheduler methods */
|
2012-09-07 20:07:38 -03:00
|
|
|
|
|
|
|
/* init: implementation-specific void* argument expected to be an
|
|
|
|
* AP_HAL_AVR::ISRRegistry*. */
|
|
|
|
void init(void *isrregistry);
|
2012-12-19 22:16:10 -04:00
|
|
|
void delay(uint16_t ms);
|
2012-09-06 15:20:12 -03:00
|
|
|
uint32_t millis();
|
|
|
|
uint32_t micros();
|
2015-04-29 23:17:34 -03:00
|
|
|
uint64_t millis64();
|
|
|
|
uint64_t micros64();
|
2012-09-06 15:20:12 -03:00
|
|
|
void delay_microseconds(uint16_t us);
|
2012-10-26 22:02:52 -03:00
|
|
|
void register_delay_callback(AP_HAL::Proc, uint16_t min_time_ms);
|
2013-01-03 21:32:36 -04:00
|
|
|
|
2013-09-30 04:00:38 -03:00
|
|
|
void register_timer_process(AP_HAL::MemberProc);
|
|
|
|
void register_io_process(AP_HAL::MemberProc);
|
2012-09-07 20:07:38 -03:00
|
|
|
void suspend_timer_procs();
|
|
|
|
void resume_timer_procs();
|
2013-01-03 21:32:36 -04:00
|
|
|
|
2013-01-10 17:50:23 -04:00
|
|
|
bool in_timerprocess();
|
|
|
|
|
2013-09-30 04:00:38 -03:00
|
|
|
void register_timer_failsafe(AP_HAL::Proc, uint32_t period_us);
|
2013-01-10 17:50:23 -04:00
|
|
|
|
|
|
|
bool system_initializing();
|
|
|
|
void system_initialized();
|
|
|
|
|
2015-06-05 20:08:28 -03:00
|
|
|
void panic(const prog_char_t *errormsg) NORETURN;
|
2013-09-03 22:58:13 -03:00
|
|
|
void reboot(bool hold_in_bootloader);
|
2012-09-07 20:07:38 -03:00
|
|
|
|
2013-10-12 04:23:27 -03:00
|
|
|
void set_timer_speed(uint16_t timer_hz);
|
|
|
|
|
2012-09-07 20:07:38 -03:00
|
|
|
private:
|
2012-12-06 19:24:55 -04:00
|
|
|
static AVRTimer _timer;
|
|
|
|
|
2013-01-10 17:50:23 -04:00
|
|
|
static volatile bool _in_timer_proc;
|
|
|
|
|
2012-09-07 20:07:38 -03:00
|
|
|
AP_HAL::Proc _delay_cb;
|
2012-10-26 22:02:52 -03:00
|
|
|
uint16_t _min_delay_cb_ms;
|
2013-01-10 17:50:23 -04:00
|
|
|
bool _initialized;
|
2013-01-03 21:32:36 -04:00
|
|
|
|
|
|
|
/* _timer_isr_event() and _run_timer_procs are static so they can be
|
|
|
|
* called from an interrupt. */
|
|
|
|
static void _timer_isr_event();
|
|
|
|
static void _run_timer_procs(bool called_from_isr);
|
|
|
|
|
2013-09-30 04:00:38 -03:00
|
|
|
static AP_HAL::Proc _failsafe;
|
2012-09-07 20:07:38 -03:00
|
|
|
|
|
|
|
static volatile bool _timer_suspended;
|
2013-01-03 21:32:36 -04:00
|
|
|
static volatile bool _timer_event_missed;
|
2013-09-30 04:00:38 -03:00
|
|
|
static AP_HAL::MemberProc _timer_proc[AVR_SCHEDULER_MAX_TIMER_PROCS];
|
2012-09-07 20:07:38 -03:00
|
|
|
static uint8_t _num_timer_procs;
|
2013-10-12 04:23:27 -03:00
|
|
|
static volatile uint8_t _timer2_reset_value;
|
2012-09-07 20:07:38 -03:00
|
|
|
|
|
|
|
};
|
2012-08-23 15:36:13 -03:00
|
|
|
#endif // __AP_HAL_AVR_SCHEDULER_H__
|
|
|
|
|