Browse Source

HAL_FLYMAPLE: updates for AP_HAL::MemberProc

master
Andrew Tridgell 12 years ago
parent
commit
c27a61f210
  1. 10
      libraries/AP_HAL_FLYMAPLE/AnalogIn.cpp
  2. 14
      libraries/AP_HAL_FLYMAPLE/AnalogIn.h
  3. 16
      libraries/AP_HAL_FLYMAPLE/Scheduler.cpp
  4. 12
      libraries/AP_HAL_FLYMAPLE/Scheduler.h

10
libraries/AP_HAL_FLYMAPLE/AnalogIn.cpp

@ -32,19 +32,13 @@ extern const AP_HAL::HAL& hal; @@ -32,19 +32,13 @@ extern const AP_HAL::HAL& hal;
* This seems to be determined empirically */
#define CHANNEL_READ_REPEAT 2
/* Static variable instances */
FLYMAPLEAnalogSource* FLYMAPLEAnalogIn::_channels[FLYMAPLE_INPUT_MAX_CHANNELS] = {NULL};
int16_t FLYMAPLEAnalogIn::_num_channels = 0;
int16_t FLYMAPLEAnalogIn::_active_channel = 0;
uint16_t FLYMAPLEAnalogIn::_channel_repeat_count = 0;
FLYMAPLEAnalogIn::FLYMAPLEAnalogIn() :
_vcc(FLYMAPLEAnalogSource(ANALOG_INPUT_BOARD_VCC))
{}
void FLYMAPLEAnalogIn::init(void* machtnichts) {
/* Register FLYMAPLEAnalogIn::_timer_event with the scheduler. */
hal.scheduler->register_timer_process(reinterpret_cast<AP_HAL::TimedProc>(&FLYMAPLEAnalogIn::_timer_event), this);
hal.scheduler->register_timer_process(AP_HAL_MEMBERPROC(&FLYMAPLEAnalogIn::_timer_event));
/* Register each private channel with FLYMAPLEAnalogIn. */
_register_channel(&_vcc);
}
@ -74,7 +68,7 @@ void FLYMAPLEAnalogIn::_register_channel(FLYMAPLEAnalogSource* ch) { @@ -74,7 +68,7 @@ void FLYMAPLEAnalogIn::_register_channel(FLYMAPLEAnalogSource* ch) {
regs->CR2 |= ADC_CR2_SWSTART;
}
void FLYMAPLEAnalogIn::_timer_event(uint32_t t)
void FLYMAPLEAnalogIn::_timer_event(void)
{
adc_reg_map *regs = ADC1->regs;
if (_channels[_active_channel]->_pin == ANALOG_INPUT_NONE) {

14
libraries/AP_HAL_FLYMAPLE/AnalogIn.h

@ -86,13 +86,13 @@ public: @@ -86,13 +86,13 @@ public:
AP_HAL::AnalogSource* channel(int16_t n);
protected:
static FLYMAPLEAnalogSource* _create_channel(int16_t num);
static void _register_channel(FLYMAPLEAnalogSource*);
static void _timer_event(uint32_t);
static FLYMAPLEAnalogSource* _channels[FLYMAPLE_INPUT_MAX_CHANNELS];
static int16_t _num_channels;
static int16_t _active_channel;
static uint16_t _channel_repeat_count;
FLYMAPLEAnalogSource* _create_channel(int16_t num);
void _register_channel(FLYMAPLEAnalogSource*);
void _timer_event(void);
FLYMAPLEAnalogSource* _channels[FLYMAPLE_INPUT_MAX_CHANNELS];
int16_t _num_channels;
int16_t _active_channel;
uint16_t _channel_repeat_count;
private:
// On Flymaple, VCC measurement is at pin 20. VCC (=VIN) of 5V is only present

16
libraries/AP_HAL_FLYMAPLE/Scheduler.cpp

@ -36,12 +36,11 @@ using namespace AP_HAL_FLYMAPLE_NS; @@ -36,12 +36,11 @@ using namespace AP_HAL_FLYMAPLE_NS;
extern const AP_HAL::HAL& hal;
AP_HAL::TimedProc FLYMAPLEScheduler::_failsafe = NULL;
AP_HAL::Proc FLYMAPLEScheduler::_failsafe = NULL;
volatile bool FLYMAPLEScheduler::_timer_suspended = false;
volatile bool FLYMAPLEScheduler::_timer_event_missed = false;
volatile bool FLYMAPLEScheduler::_in_timer_proc = false;
AP_HAL::TimedProc FLYMAPLEScheduler::_timer_proc[FLYMAPLE_SCHEDULER_MAX_TIMER_PROCS] = {NULL};
void * FLYMAPLEScheduler::_timer_arg[FLYMAPLE_SCHEDULER_MAX_TIMER_PROCS] = {NULL};
AP_HAL::MemberProc FLYMAPLEScheduler::_timer_proc[FLYMAPLE_SCHEDULER_MAX_TIMER_PROCS] = {NULL};
uint8_t FLYMAPLEScheduler::_num_timer_procs = 0;
FLYMAPLEScheduler::FLYMAPLEScheduler() :
@ -109,7 +108,7 @@ void FLYMAPLEScheduler::register_delay_callback(AP_HAL::Proc proc, uint16_t min_ @@ -109,7 +108,7 @@ void FLYMAPLEScheduler::register_delay_callback(AP_HAL::Proc proc, uint16_t min_
_min_delay_cb_ms = min_time_ms;
}
void FLYMAPLEScheduler::register_timer_process(AP_HAL::TimedProc proc, void *arg)
void FLYMAPLEScheduler::register_timer_process(AP_HAL::MemberProc proc)
{
for (int i = 0; i < _num_timer_procs; i++) {
if (_timer_proc[i] == proc) {
@ -122,7 +121,6 @@ void FLYMAPLEScheduler::register_timer_process(AP_HAL::TimedProc proc, void *arg @@ -122,7 +121,6 @@ void FLYMAPLEScheduler::register_timer_process(AP_HAL::TimedProc proc, void *arg
* because that memory won't be used until _num_timer_procs is
* incremented. */
_timer_proc[_num_timer_procs] = proc;
_timer_arg[_num_timer_procs] = arg;
/* _num_timer_procs is used from interrupt, and multiple bytes long. */
noInterrupts();
_num_timer_procs++;
@ -130,12 +128,12 @@ void FLYMAPLEScheduler::register_timer_process(AP_HAL::TimedProc proc, void *arg @@ -130,12 +128,12 @@ void FLYMAPLEScheduler::register_timer_process(AP_HAL::TimedProc proc, void *arg
}
}
void FLYMAPLEScheduler::register_io_process(AP_HAL::TimedProc k, void *arg)
void FLYMAPLEScheduler::register_io_process(AP_HAL::MemberProc k)
{
// IO processes not supported on FLYMAPLE
}
void FLYMAPLEScheduler::register_timer_failsafe(AP_HAL::TimedProc failsafe, uint32_t period_us)
void FLYMAPLEScheduler::register_timer_failsafe(AP_HAL::Proc failsafe, uint32_t period_us)
{
/* XXX Assert period_us == 1000 */
_failsafe = failsafe;
@ -168,7 +166,7 @@ void FLYMAPLEScheduler::_failsafe_timer_event() @@ -168,7 +166,7 @@ void FLYMAPLEScheduler::_failsafe_timer_event()
{
// run the failsafe, if one is setup
if (_failsafe != NULL)
_failsafe(NULL);
_failsafe();
}
void FLYMAPLEScheduler::begin_atomic()
@ -189,7 +187,7 @@ void FLYMAPLEScheduler::_run_timer_procs(bool called_from_isr) @@ -189,7 +187,7 @@ void FLYMAPLEScheduler::_run_timer_procs(bool called_from_isr)
// now call the timer based drivers
for (int i = 0; i < _num_timer_procs; i++) {
if (_timer_proc[i] != NULL) {
_timer_proc[i](_timer_arg[i]);
_timer_proc[i]();
}
}
} else if (called_from_isr) {

12
libraries/AP_HAL_FLYMAPLE/Scheduler.h

@ -34,17 +34,16 @@ public: @@ -34,17 +34,16 @@ public:
void register_delay_callback(AP_HAL::Proc,
uint16_t min_time_ms);
void register_timer_process(AP_HAL::TimedProc, void *);
void register_timer_process(AP_HAL::MemberProc);
void register_io_process(AP_HAL::TimedProc, void *);
void register_io_process(AP_HAL::MemberProc);
void suspend_timer_procs();
void resume_timer_procs();
bool in_timerprocess();
void register_timer_failsafe(AP_HAL::TimedProc,
uint32_t period_us);
void register_timer_failsafe(AP_HAL::Proc, uint32_t period_us);
void begin_atomic();
void end_atomic();
@ -68,12 +67,11 @@ private: @@ -68,12 +67,11 @@ private:
static void _run_timer_procs(bool called_from_isr);
static void _failsafe_timer_event();
static AP_HAL::TimedProc _failsafe;
static AP_HAL::Proc _failsafe;
static volatile bool _timer_suspended;
static volatile bool _timer_event_missed;
static AP_HAL::TimedProc _timer_proc[FLYMAPLE_SCHEDULER_MAX_TIMER_PROCS];
static void * _timer_arg[FLYMAPLE_SCHEDULER_MAX_TIMER_PROCS];
static AP_HAL::MemberProc _timer_proc[FLYMAPLE_SCHEDULER_MAX_TIMER_PROCS];
static uint8_t _num_timer_procs;
};

Loading…
Cancel
Save