2013-01-02 06:39:26 -04:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_PX4_SCHEDULER_H__
|
|
|
|
#define __AP_HAL_PX4_SCHEDULER_H__
|
|
|
|
|
|
|
|
#include <AP_HAL.h>
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
|
|
|
|
#include "AP_HAL_PX4_Namespace.h"
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <signal.h>
|
2013-01-20 22:54:09 -04:00
|
|
|
#include <pthread.h>
|
2013-01-24 00:02:50 -04:00
|
|
|
#include <systemlib/perf_counter.h>
|
2013-01-02 06:39:26 -04:00
|
|
|
|
2013-01-20 22:54:09 -04:00
|
|
|
#define PX4_SCHEDULER_MAX_TIMER_PROCS 8
|
2013-01-02 06:39:26 -04:00
|
|
|
|
2013-01-24 00:02:50 -04:00
|
|
|
#define APM_MAIN_PRIORITY 200
|
|
|
|
#define APM_TIMER_PRIORITY 201
|
|
|
|
#define APM_IO_PRIORITY 60
|
|
|
|
#define APM_OVERTIME_PRIORITY 10
|
|
|
|
|
2013-01-02 06:39:26 -04:00
|
|
|
/* Scheduler implementation: */
|
|
|
|
class PX4::PX4Scheduler : public AP_HAL::Scheduler {
|
|
|
|
public:
|
|
|
|
PX4Scheduler();
|
|
|
|
/* AP_HAL::Scheduler methods */
|
|
|
|
|
|
|
|
void init(void *unused);
|
|
|
|
void delay(uint16_t ms);
|
|
|
|
uint32_t millis();
|
|
|
|
uint32_t micros();
|
|
|
|
void delay_microseconds(uint16_t us);
|
|
|
|
void register_delay_callback(AP_HAL::Proc, uint16_t min_time_ms);
|
|
|
|
void register_timer_process(AP_HAL::TimedProc);
|
|
|
|
void register_timer_failsafe(AP_HAL::TimedProc, uint32_t period_us);
|
|
|
|
void suspend_timer_procs();
|
|
|
|
void resume_timer_procs();
|
|
|
|
void reboot();
|
|
|
|
void panic(const prog_char_t *errormsg);
|
|
|
|
|
2013-01-10 21:20:43 -04:00
|
|
|
bool in_timerprocess();
|
|
|
|
bool system_initializing();
|
|
|
|
void system_initialized();
|
|
|
|
|
2013-01-02 06:39:26 -04:00
|
|
|
private:
|
2013-01-10 21:20:43 -04:00
|
|
|
bool _initialized;
|
2013-01-02 06:39:26 -04:00
|
|
|
AP_HAL::Proc _delay_cb;
|
|
|
|
uint16_t _min_delay_cb_ms;
|
2013-01-20 22:54:09 -04:00
|
|
|
AP_HAL::TimedProc _failsafe;
|
|
|
|
volatile bool _timer_pending;
|
|
|
|
uint64_t _sketch_start_time;
|
|
|
|
|
|
|
|
volatile bool _timer_suspended;
|
|
|
|
AP_HAL::TimedProc _timer_proc[PX4_SCHEDULER_MAX_TIMER_PROCS];
|
|
|
|
uint8_t _num_timer_procs;
|
|
|
|
volatile bool _in_timer_proc;
|
|
|
|
volatile bool _timer_event_missed;
|
2013-01-24 00:02:50 -04:00
|
|
|
|
|
|
|
pthread_t _timer_thread_ctx;
|
|
|
|
pthread_t _io_thread_ctx;
|
|
|
|
|
2013-01-20 22:54:09 -04:00
|
|
|
void *_timer_thread(void);
|
2013-01-24 00:02:50 -04:00
|
|
|
void *_io_thread(void);
|
|
|
|
|
2013-01-20 22:54:09 -04:00
|
|
|
void _run_timers(bool called_from_timer_thread);
|
2013-01-02 06:39:26 -04:00
|
|
|
|
2013-01-24 00:02:50 -04:00
|
|
|
perf_counter_t _perf_timers;
|
|
|
|
perf_counter_t _perf_delay;
|
2013-01-02 06:39:26 -04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif // __AP_HAL_PX4_SCHEDULER_H__
|
|
|
|
|
|
|
|
|