HAL_Linux: update for new scheduler API

This commit is contained in:
Andrew Tridgell 2013-09-28 16:28:36 +10:00
parent 1d820761be
commit cca59ce3c9
4 changed files with 29 additions and 7 deletions

View File

@ -1,5 +1,7 @@
#include <AP_HAL.h> #include <AP_HAL.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include "I2CDriver.h" #include "I2CDriver.h"
#include <sys/types.h> #include <sys/types.h>
@ -145,3 +147,4 @@ uint8_t LinuxI2CDriver::lockup_count()
{ {
return 0; return 0;
} }
#endif // CONFIG_HAL_BOARD

View File

@ -1,3 +1,6 @@
#include <AP_HAL.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include "Scheduler.h" #include "Scheduler.h"
#include "Storage.h" #include "Storage.h"
@ -81,7 +84,7 @@ void LinuxScheduler::register_delay_callback(AP_HAL::Proc proc,
_min_delay_cb_ms = min_time_ms; _min_delay_cb_ms = min_time_ms;
} }
void LinuxScheduler::register_timer_process(AP_HAL::TimedProc proc) void LinuxScheduler::register_timer_process(AP_HAL::TimedProc proc, void *arg)
{ {
for (uint8_t i = 0; i < _num_timer_procs; i++) { for (uint8_t i = 0; i < _num_timer_procs; i++) {
if (_timer_proc[i] == proc) { if (_timer_proc[i] == proc) {
@ -91,13 +94,14 @@ void LinuxScheduler::register_timer_process(AP_HAL::TimedProc proc)
if (_num_timer_procs < LINUX_SCHEDULER_MAX_TIMER_PROCS) { if (_num_timer_procs < LINUX_SCHEDULER_MAX_TIMER_PROCS) {
_timer_proc[_num_timer_procs] = proc; _timer_proc[_num_timer_procs] = proc;
_timer_arg[_num_timer_procs] = arg;
_num_timer_procs++; _num_timer_procs++;
} else { } else {
hal.console->printf("Out of timer processes\n"); hal.console->printf("Out of timer processes\n");
} }
} }
void LinuxScheduler::register_io_process(AP_HAL::TimedProc proc) void LinuxScheduler::register_io_process(AP_HAL::TimedProc proc, void *arg)
{ {
for (uint8_t i = 0; i < _num_io_procs; i++) { for (uint8_t i = 0; i < _num_io_procs; i++) {
if (_io_proc[i] == proc) { if (_io_proc[i] == proc) {
@ -107,6 +111,7 @@ void LinuxScheduler::register_io_process(AP_HAL::TimedProc proc)
if (_num_io_procs < LINUX_SCHEDULER_MAX_TIMER_PROCS) { if (_num_io_procs < LINUX_SCHEDULER_MAX_TIMER_PROCS) {
_io_proc[_num_io_procs] = proc; _io_proc[_num_io_procs] = proc;
_io_arg[_num_io_procs] = arg;
_num_io_procs++; _num_io_procs++;
} else { } else {
hal.console->printf("Out of IO processes\n"); hal.console->printf("Out of IO processes\n");
@ -145,7 +150,7 @@ void LinuxScheduler::_run_timers(bool called_from_timer_thread)
// now call the timer based drivers // now call the timer based drivers
for (int i = 0; i < _num_timer_procs; i++) { for (int i = 0; i < _num_timer_procs; i++) {
if (_timer_proc[i] != NULL) { if (_timer_proc[i] != NULL) {
_timer_proc[i](tnow); _timer_proc[i](_timer_arg[i]);
} }
} }
} else if (called_from_timer_thread) { } else if (called_from_timer_thread) {
@ -154,7 +159,7 @@ void LinuxScheduler::_run_timers(bool called_from_timer_thread)
// and the failsafe, if one is setup // and the failsafe, if one is setup
if (_failsafe != NULL) { if (_failsafe != NULL) {
_failsafe(tnow); _failsafe(NULL);
} }
_in_timer_proc = false; _in_timer_proc = false;
@ -184,7 +189,7 @@ void LinuxScheduler::_run_io(void)
// now call the IO based drivers // now call the IO based drivers
for (int i = 0; i < _num_io_procs; i++) { for (int i = 0; i < _num_io_procs; i++) {
if (_io_proc[i] != NULL) { if (_io_proc[i] != NULL) {
_io_proc[i](tnow); _io_proc[i](_io_arg[i]);
} }
} }
} }
@ -251,3 +256,5 @@ void LinuxScheduler::reboot(bool hold_in_bootloader)
{ {
for(;;); for(;;);
} }
#endif // CONFIG_HAL_BOARD

View File

@ -3,6 +3,8 @@
#define __AP_HAL_LINUX_SCHEDULER_H__ #define __AP_HAL_LINUX_SCHEDULER_H__
#include <AP_HAL_Linux.h> #include <AP_HAL_Linux.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include <sys/time.h> #include <sys/time.h>
#include <pthread.h> #include <pthread.h>
@ -24,8 +26,8 @@ public:
void register_delay_callback(AP_HAL::Proc, void register_delay_callback(AP_HAL::Proc,
uint16_t min_time_ms); uint16_t min_time_ms);
void register_timer_process(AP_HAL::TimedProc); void register_timer_process(AP_HAL::TimedProc, void *arg);
void register_io_process(AP_HAL::TimedProc); void register_io_process(AP_HAL::TimedProc, void *arg);
void suspend_timer_procs(); void suspend_timer_procs();
void resume_timer_procs(); void resume_timer_procs();
@ -58,10 +60,12 @@ private:
volatile bool _timer_suspended; volatile bool _timer_suspended;
AP_HAL::TimedProc _timer_proc[LINUX_SCHEDULER_MAX_TIMER_PROCS]; AP_HAL::TimedProc _timer_proc[LINUX_SCHEDULER_MAX_TIMER_PROCS];
void * _timer_arg[LINUX_SCHEDULER_MAX_TIMER_PROCS];
uint8_t _num_timer_procs; uint8_t _num_timer_procs;
volatile bool _in_timer_proc; volatile bool _in_timer_proc;
AP_HAL::TimedProc _io_proc[LINUX_SCHEDULER_MAX_TIMER_PROCS]; AP_HAL::TimedProc _io_proc[LINUX_SCHEDULER_MAX_TIMER_PROCS];
void * _io_arg[LINUX_SCHEDULER_MAX_TIMER_PROCS];
uint8_t _num_io_procs; uint8_t _num_io_procs;
volatile bool _in_io_proc; volatile bool _in_io_proc;
@ -79,4 +83,6 @@ private:
void _run_io(void); void _run_io(void);
}; };
#endif // CONFIG_HAL_BOARD
#endif // __AP_HAL_LINUX_SCHEDULER_H__ #endif // __AP_HAL_LINUX_SCHEDULER_H__

View File

@ -1,3 +1,7 @@
#include <AP_HAL.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include "UARTDriver.h" #include "UARTDriver.h"
#include <stdio.h> #include <stdio.h>
@ -172,3 +176,5 @@ size_t LinuxUARTDriver::write(uint8_t c)
} }
return 0; return 0;
} }
#endif // CONFIG_HAL_BOARD