Browse Source

AP_HAL: provide AP_HAL_MAIN()

Move the macros to a single place and reduce the variations not based on
board, but based on

- The name of the entry-point function, specified by AP_MAIN;
- Whether it contains argc/argv arguments or not.

The goal here is that programs (vehicles and examples) don't need to
include all possible boards to define a main function. Further patches
will change the programs.
master
Caio Marcelo de Oliveira Filho 9 years ago committed by Andrew Tridgell
parent
commit
19b4ca60c4
  1. 1
      libraries/AP_HAL/AP_HAL.h
  2. 40
      libraries/AP_HAL/AP_HAL_Main.h
  3. 1
      libraries/AP_HAL_AVR/AP_HAL_AVR.h
  4. 15
      libraries/AP_HAL_AVR/AP_HAL_AVR_Main.h
  5. 8
      libraries/AP_HAL_Empty/AP_HAL_Empty.h
  6. 16
      libraries/AP_HAL_Empty/AP_HAL_Empty_Main.h
  7. 1
      libraries/AP_HAL_FLYMAPLE/AP_HAL_FLYMAPLE.h
  8. 33
      libraries/AP_HAL_FLYMAPLE/AP_HAL_FLYMAPLE_Main.h
  9. 8
      libraries/AP_HAL_Linux/AP_HAL_Linux.h
  10. 16
      libraries/AP_HAL_Linux/AP_HAL_Linux_Main.h
  11. 1
      libraries/AP_HAL_PX4/AP_HAL_PX4.h
  12. 15
      libraries/AP_HAL_PX4/AP_HAL_PX4_Main.h
  13. 1
      libraries/AP_HAL_SITL/AP_HAL_SITL.h
  14. 15
      libraries/AP_HAL_SITL/AP_HAL_SITL_Main.h
  15. 1
      libraries/AP_HAL_VRBRAIN/AP_HAL_VRBRAIN.h
  16. 15
      libraries/AP_HAL_VRBRAIN/AP_HAL_VRBRAIN_Main.h

1
libraries/AP_HAL/AP_HAL.h

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
#include "AP_HAL_Namespace.h"
#include "AP_HAL_Boards.h"
#include "AP_HAL_Macros.h"
#include "AP_HAL_Main.h"
/* HAL Module Classes (all pure virtual) */
#include "UARTDriver.h"

40
libraries/AP_HAL/AP_HAL_Main.h

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
#ifndef __AP_HAL_MAIN_H__
#define __AP_HAL_MAIN_H__
#include "HAL.h"
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2 || CONFIG_HAL_BOARD == HAL_BOARD_FLYMAPLE
#define CONFIG_MAIN_WITHOUT_ARGC_ARGV 1
#endif
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
#define AP_MAIN __EXPORT ArduPilot_main
#endif
#ifndef AP_MAIN
#define AP_MAIN main
#endif
#if CONFIG_MAIN_WITHOUT_ARGC_ARGV
#define AP_HAL_MAIN() extern "C" { \
int AP_MAIN(void) { \
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(0, NULL, &callbacks); \
return 0; \
} \
}
#else
#define AP_HAL_MAIN() extern "C" { \
int AP_MAIN(int argc, char* const argv[]) { \
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(argc, argv, &callbacks); \
return 0; \
} \
}
#endif
#endif // __AP_HAL_MAIN_H__

1
libraries/AP_HAL_AVR/AP_HAL_AVR.h

@ -13,7 +13,6 @@ @@ -13,7 +13,6 @@
#include "HAL_AVR_APM1_Class.h"
#include "HAL_AVR_APM2_Class.h"
#include "AP_HAL_AVR_Main.h"
#endif // CONFIG_HAL_BOARD

15
libraries/AP_HAL_AVR/AP_HAL_AVR_Main.h

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
#ifndef __AP_HAL_AVR_MAIN_H__
#define __AP_HAL_AVR_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_APM1 || CONFIG_HAL_BOARD == HAL_BOARD_APM2
#define AP_HAL_MAIN() extern "C" {\
int main (void) {\
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(0, NULL, &callbacks); \
return 0; \
}\
}
#endif
#endif // __AP_HAL_AVR_MAIN_H__

8
libraries/AP_HAL_Empty/AP_HAL_Empty.h

@ -18,17 +18,9 @@ @@ -18,17 +18,9 @@
* All declaration and compilation should be guarded by CONFIG_HAL_BOARD macros.
* In this case, we're using CONFIG_HAL_BOARD == HAL_BOARD_EMPTY.
* When creating a new HAL, declare a new HAL_BOARD_ in AP_HAL/AP_HAL_Boards.h
*
* The module should also export an appropriate AP_HAL_MAIN() macro iff the
* appropriate CONFIG_HAL_BOARD value is set.
* The AP_HAL_MAIN macro expands to a main function (either an `int main (void)`
* or `int main (int argc, const char * argv[]), depending on platform) of an
* ArduPilot application, whose entry points are the c++ functions
* `void setup()` and `void loop()`, ala Arduino.
*/
#include "HAL_Empty_Class.h"
#include "AP_HAL_Empty_Main.h"
#endif //__AP_HAL_EMPTY_H__

16
libraries/AP_HAL_Empty/AP_HAL_Empty_Main.h

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
#ifndef __AP_HAL_EMPTY_MAIN_H__
#define __AP_HAL_EMPTY_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_EMPTY
#define AP_HAL_MAIN() extern "C" {\
int main (void) {\
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(0, NULL, &callbacks); \
return 0; \
}\
}
#endif // HAL_BOARD_EMPTY
#endif // __AP_HAL_EMPTY_MAIN_H__

1
libraries/AP_HAL_FLYMAPLE/AP_HAL_FLYMAPLE.h

@ -47,7 +47,6 @@ @@ -47,7 +47,6 @@
#if CONFIG_HAL_BOARD == HAL_BOARD_FLYMAPLE
#include "HAL_FLYMAPLE_Class.h"
#include "AP_HAL_FLYMAPLE_Main.h"
#endif // CONFIG_HAL_BOARD

33
libraries/AP_HAL_FLYMAPLE/AP_HAL_FLYMAPLE_Main.h

@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Flymaple port by Mike McCauley
*/
#ifndef __AP_HAL_FLYMAPLE_MAIN_H__
#define __AP_HAL_FLYMAPLE_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_FLYMAPLE
#define AP_HAL_MAIN() extern "C" {\
int main (void) {\
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(0, NULL, &callbacks); \
return 0; \
}\
}
#endif // HAL_BOARD_FLYMAPLE
#endif // __AP_HAL_FLYMAPLE_MAIN_H__

8
libraries/AP_HAL_Linux/AP_HAL_Linux.h

@ -18,19 +18,11 @@ @@ -18,19 +18,11 @@
* All declaration and compilation should be guarded by CONFIG_HAL_BOARD macros.
* In this case, we're using CONFIG_HAL_BOARD == HAL_BOARD_LINUX.
* When creating a new HAL, declare a new HAL_BOARD_ in AP_HAL/AP_HAL_Boards.h
*
* The module should also export an appropriate AP_HAL_MAIN() macro iff the
* appropriate CONFIG_HAL_BOARD value is set.
* The AP_HAL_MAIN macro expands to a main function (either an `int main (void)`
* or `int main (int argc, const char * argv[]), depending on platform) of an
* ArduPilot application, whose entry points are the c++ functions
* `void setup()` and `void loop()`, ala Arduino.
*/
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include "HAL_Linux_Class.h"
#include "AP_HAL_Linux_Main.h"
#endif // CONFIG_HAL_BOARD
#endif //__AP_HAL_LINUX_H__

16
libraries/AP_HAL_Linux/AP_HAL_Linux_Main.h

@ -1,16 +0,0 @@ @@ -1,16 +0,0 @@
#ifndef __AP_HAL_LINUX_MAIN_H__
#define __AP_HAL_LINUX_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#define AP_HAL_MAIN() extern "C" {\
int main (int argc, char * const argv[]) { \
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(argc, argv, &callbacks); \
return 0; \
}\
}
#endif // HAL_BOARD_LINUX
#endif // __AP_HAL_LINUX_MAIN_H__

1
libraries/AP_HAL_PX4/AP_HAL_PX4.h

@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
#include "HAL_PX4_Class.h"
#include "AP_HAL_PX4_Main.h"
#endif // CONFIG_HAL_BOARD
#endif // __AP_HAL_PX4_H__

15
libraries/AP_HAL_PX4/AP_HAL_PX4_Main.h

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
#ifndef __AP_HAL_PX4_MAIN_H__
#define __AP_HAL_PX4_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_PX4
#define AP_HAL_MAIN() \
extern "C" __EXPORT int SKETCH_MAIN(int argc, char * const argv[]); \
int SKETCH_MAIN(int argc, char * const argv[]) { \
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(argc, argv, &callbacks); \
return OK; \
}
#endif
#endif // __AP_HAL_PX4_MAIN_H__

1
libraries/AP_HAL_SITL/AP_HAL_SITL.h

@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
#include "HAL_SITL_Class.h"
#include "AP_HAL_SITL_Main.h"
#endif // CONFIG_HAL_BOARD

15
libraries/AP_HAL_SITL/AP_HAL_SITL_Main.h

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
#ifndef __AP_HAL_SITL_MAIN_H__
#define __AP_HAL_SITL_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
#define AP_HAL_MAIN() extern "C" {\
int main (int argc, char * const argv[]) { \
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(argc, argv, &callbacks); \
return 0; \
}\
}
#endif
#endif // __AP_HAL_SITL_MAIN_H__

1
libraries/AP_HAL_VRBRAIN/AP_HAL_VRBRAIN.h

@ -6,7 +6,6 @@ @@ -6,7 +6,6 @@
#if CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
#include "HAL_VRBRAIN_Class.h"
#include "AP_HAL_VRBRAIN_Main.h"
#endif // CONFIG_HAL_BOARD
#endif // __AP_HAL_VRBRAIN_H__

15
libraries/AP_HAL_VRBRAIN/AP_HAL_VRBRAIN_Main.h

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
#ifndef __AP_HAL_VRBRAIN_MAIN_H__
#define __AP_HAL_VRBRAIN_MAIN_H__
#if CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN
#define AP_HAL_MAIN() \
extern "C" __EXPORT int SKETCH_MAIN(int argc, char * const argv[]); \
int SKETCH_MAIN(int argc, char * const argv[]) { \
AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(argc, argv, &callbacks); \
return OK; \
}
#endif
#endif // __AP_HAL_VRBRAIN_MAIN_H__
Loading…
Cancel
Save