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-02-19 20:30:54 -04:00
|
|
|
#define APM_MAIN_PRIORITY 180
|
|
|
|
#define APM_TIMER_PRIORITY 181
|
2013-09-04 00:15:27 -03:00
|
|
|
#define APM_UART_PRIORITY 60
|
|
|
|
#define APM_IO_PRIORITY 59
|
2013-01-24 00:02:50 -04:00
|
|
|
#define APM_OVERTIME_PRIORITY 10
|
2013-01-25 05:43:06 -04:00
|
|
|
#define APM_STARTUP_PRIORITY 10
|
2013-01-24 00:02:50 -04:00
|
|
|
|
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);
|
2013-09-30 07:36:19 -03:00
|
|
|
void register_timer_process(AP_HAL::MemberProc);
|
|
|
|
void register_io_process(AP_HAL::MemberProc);
|
|
|
|
void register_timer_failsafe(AP_HAL::Proc, uint32_t period_us);
|
2013-01-02 06:39:26 -04:00
|
|
|
void suspend_timer_procs();
|
|
|
|
void resume_timer_procs();
|
2013-09-03 22:58:13 -03:00
|
|
|
void reboot(bool hold_in_bootloader);
|
2013-01-02 06:39:26 -04:00
|
|
|
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-10-28 02:10:51 -03:00
|
|
|
void hal_initialized() { _hal_initialized = true; }
|
|
|
|
|
2013-01-02 06:39:26 -04:00
|
|
|
private:
|
2013-01-10 21:20:43 -04:00
|
|
|
bool _initialized;
|
2013-10-28 02:10:51 -03:00
|
|
|
volatile bool _hal_initialized;
|
2013-01-02 06:39:26 -04:00
|
|
|
AP_HAL::Proc _delay_cb;
|
|
|
|
uint16_t _min_delay_cb_ms;
|
2013-09-30 07:36:19 -03:00
|
|
|
AP_HAL::Proc _failsafe;
|
2013-01-20 22:54:09 -04:00
|
|
|
volatile bool _timer_pending;
|
|
|
|
uint64_t _sketch_start_time;
|
|
|
|
|
|
|
|
volatile bool _timer_suspended;
|
2013-04-17 08:33:50 -03:00
|
|
|
|
2013-09-30 07:36:19 -03:00
|
|
|
AP_HAL::MemberProc _timer_proc[PX4_SCHEDULER_MAX_TIMER_PROCS];
|
2013-01-20 22:54:09 -04:00
|
|
|
uint8_t _num_timer_procs;
|
|
|
|
volatile bool _in_timer_proc;
|
2013-04-17 08:33:50 -03:00
|
|
|
|
2013-09-30 07:36:19 -03:00
|
|
|
AP_HAL::MemberProc _io_proc[PX4_SCHEDULER_MAX_TIMER_PROCS];
|
2013-04-17 08:33:50 -03:00
|
|
|
uint8_t _num_io_procs;
|
|
|
|
volatile bool _in_io_proc;
|
|
|
|
|
2013-01-20 22:54:09 -04:00
|
|
|
volatile bool _timer_event_missed;
|
2013-01-24 00:02:50 -04:00
|
|
|
|
2013-10-19 02:47:35 -03:00
|
|
|
pid_t _main_task_pid;
|
2013-01-24 00:02:50 -04:00
|
|
|
pthread_t _timer_thread_ctx;
|
|
|
|
pthread_t _io_thread_ctx;
|
2013-09-04 00:15:27 -03:00
|
|
|
pthread_t _uart_thread_ctx;
|
2013-01-24 00:02:50 -04:00
|
|
|
|
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-09-04 00:15:27 -03:00
|
|
|
void *_uart_thread(void);
|
2013-01-24 00:02:50 -04:00
|
|
|
|
2013-01-20 22:54:09 -04:00
|
|
|
void _run_timers(bool called_from_timer_thread);
|
2013-04-17 08:33:50 -03:00
|
|
|
void _run_io(void);
|
2013-01-02 06:39:26 -04:00
|
|
|
|
2013-10-13 18:29:30 -03:00
|
|
|
void delay_microseconds_semaphore(uint16_t us);
|
|
|
|
|
2013-01-24 00:02:50 -04:00
|
|
|
perf_counter_t _perf_timers;
|
2013-04-17 08:33:50 -03:00
|
|
|
perf_counter_t _perf_io_timers;
|
2013-01-24 00:02:50 -04:00
|
|
|
perf_counter_t _perf_delay;
|
2013-01-02 06:39:26 -04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif // __AP_HAL_PX4_SCHEDULER_H__
|
|
|
|
|
|
|
|
|