Browse Source

AP_HAL_AVR: implement HAL::run() for APM1 and APM2

mission-4.1.18
Caio Marcelo de Oliveira Filho 9 years ago committed by Andrew Tridgell
parent
commit
3fe1d86c80
  1. 6
      libraries/AP_HAL_AVR/AP_HAL_AVR_Main.h
  2. 16
      libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.cpp
  3. 1
      libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.h
  4. 16
      libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.cpp
  5. 1
      libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.h

6
libraries/AP_HAL_AVR/AP_HAL_AVR_Main.h

@ -5,10 +5,8 @@ @@ -5,10 +5,8 @@
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2
#define AP_HAL_MAIN() extern "C" {\
int main (void) {\
hal.init(0, NULL); \
setup();\
hal.scheduler->system_initialized(); \
for(;;) loop();\
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(0, NULL, &callbacks); \
return 0; \
}\
}

16
libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.cpp

@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
* wrap the whole HAL_AVR_APM1 class declaration and definition. */
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1
#include <assert.h>
#include "AP_HAL_AVR.h"
#include "AP_HAL_AVR_private.h"
#include "HAL_AVR_APM1_Class.h"
@ -86,6 +88,20 @@ void HAL_AVR_APM1::init(int argc, char * const argv[]) const { @@ -86,6 +88,20 @@ void HAL_AVR_APM1::init(int argc, char * const argv[]) const {
PORTJ |= _BV(0);
};
void HAL_AVR_APM1::run(int argc, char* const argv[], Callbacks* callbacks) const
{
assert(callbacks);
init(argc, argv);
callbacks->setup();
scheduler->system_initialized();
for (;;) {
callbacks->loop();
}
}
const AP_HAL::HAL& AP_HAL::get_HAL() {
static const HAL_AVR_APM1 hal;
return hal;

1
libraries/AP_HAL_AVR/HAL_AVR_APM1_Class.h

@ -21,6 +21,7 @@ class HAL_AVR_APM1 : public AP_HAL::HAL { @@ -21,6 +21,7 @@ class HAL_AVR_APM1 : public AP_HAL::HAL {
public:
HAL_AVR_APM1();
void init(int argc, char * const argv[]) const;
void run(int argc, char* const argv[], Callbacks* callbacks) const override;
};
/**

16
libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.cpp

@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
* wrap the whole HAL_AVR_APM2 class declaration and definition. */
#if CONFIG_HAL_BOARD == HAL_BOARD_APM2
#include <assert.h>
#include "AP_HAL_AVR.h"
#include "AP_HAL_AVR_private.h"
#include "HAL_AVR_APM2_Class.h"
@ -85,6 +87,20 @@ void HAL_AVR_APM2::init(int argc, char * const argv[]) const { @@ -85,6 +87,20 @@ void HAL_AVR_APM2::init(int argc, char * const argv[]) const {
PORTH |= _BV(0);
};
void HAL_AVR_APM2::run(int argc, char* const argv[], Callbacks* callbacks) const
{
assert(callbacks);
init(argc, argv);
callbacks->setup();
scheduler->system_initialized();
for (;;) {
callbacks->loop();
}
}
const AP_HAL::HAL& AP_HAL::get_HAL() {
static const HAL_AVR_APM2 hal;
return hal;

1
libraries/AP_HAL_AVR/HAL_AVR_APM2_Class.h

@ -21,6 +21,7 @@ class HAL_AVR_APM2 : public AP_HAL::HAL { @@ -21,6 +21,7 @@ class HAL_AVR_APM2 : public AP_HAL::HAL {
public:
HAL_AVR_APM2();
void init(int argc, char * const argv[]) const;
void run(int argc, char* const argv[], Callbacks* callbacks) const override;
};
/**

Loading…
Cancel
Save