2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2012-12-11 21:30:12 -04:00
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2012-12-11 21:30:12 -04:00
|
|
|
|
2015-10-19 11:26:18 -03:00
|
|
|
#include <assert.h>
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_HAL_SITL.h"
|
2015-05-04 03:15:12 -03:00
|
|
|
#include "AP_HAL_SITL_Namespace.h"
|
|
|
|
#include "HAL_SITL_Class.h"
|
2012-12-12 18:04:27 -04:00
|
|
|
#include "Scheduler.h"
|
2012-12-13 18:57:01 -04:00
|
|
|
#include "AnalogIn.h"
|
2012-12-12 18:04:27 -04:00
|
|
|
#include "UARTDriver.h"
|
|
|
|
#include "Storage.h"
|
2012-12-17 22:33:46 -04:00
|
|
|
#include "RCInput.h"
|
2012-12-17 23:56:21 -04:00
|
|
|
#include "RCOutput.h"
|
2016-07-21 21:58:02 -03:00
|
|
|
#include "GPIO.h"
|
2012-12-13 18:57:01 -04:00
|
|
|
#include "SITL_State.h"
|
2012-12-18 21:13:01 -04:00
|
|
|
#include "Util.h"
|
2012-12-13 18:57:01 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL_Empty/AP_HAL_Empty.h>
|
|
|
|
#include <AP_HAL_Empty/AP_HAL_Empty_Private.h>
|
2012-12-17 22:33:46 -04:00
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
using namespace HALSITL;
|
2012-12-11 21:30:12 -04:00
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
static EEPROMStorage sitlEEPROMStorage;
|
2012-12-13 18:57:01 -04:00
|
|
|
static SITL_State sitlState;
|
2016-01-10 02:23:32 -04:00
|
|
|
static Scheduler sitlScheduler(&sitlState);
|
|
|
|
static RCInput sitlRCInput(&sitlState);
|
|
|
|
static RCOutput sitlRCOutput(&sitlState);
|
|
|
|
static AnalogIn sitlAnalogIn(&sitlState);
|
2016-07-21 21:58:02 -03:00
|
|
|
static GPIO sitlGPIO(&sitlState);
|
2012-12-11 21:30:12 -04:00
|
|
|
|
2012-12-18 06:14:32 -04:00
|
|
|
// use the Empty HAL for hardware we don't emulate
|
2015-12-01 15:57:35 -04:00
|
|
|
static Empty::I2CDeviceManager i2c_mgr_instance;
|
2015-12-07 15:01:34 -04:00
|
|
|
static Empty::SPIDeviceManager emptySPI;
|
2015-11-23 15:15:41 -04:00
|
|
|
static Empty::OpticalFlow emptyOpticalFlow;
|
2012-12-17 22:33:46 -04:00
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
static UARTDriver sitlUart0Driver(0, &sitlState);
|
|
|
|
static UARTDriver sitlUart1Driver(1, &sitlState);
|
|
|
|
static UARTDriver sitlUart2Driver(2, &sitlState);
|
|
|
|
static UARTDriver sitlUart3Driver(3, &sitlState);
|
|
|
|
static UARTDriver sitlUart4Driver(4, &sitlState);
|
2016-04-19 00:48:18 -03:00
|
|
|
static UARTDriver sitlUart5Driver(5, &sitlState);
|
2012-12-11 21:30:12 -04:00
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
static Util utilInstance(&sitlState);
|
2012-12-18 21:13:01 -04:00
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
HAL_SITL::HAL_SITL() :
|
2012-12-11 21:30:12 -04:00
|
|
|
AP_HAL::HAL(
|
2017-01-09 08:23:23 -04:00
|
|
|
&sitlUart0Driver, /* uartA */
|
|
|
|
&sitlUart1Driver, /* uartB */
|
|
|
|
&sitlUart2Driver, /* uartC */
|
|
|
|
&sitlUart3Driver, /* uartD */
|
|
|
|
&sitlUart4Driver, /* uartE */
|
|
|
|
&sitlUart5Driver, /* uartF */
|
2015-12-01 15:57:35 -04:00
|
|
|
&i2c_mgr_instance,
|
2017-01-09 08:23:23 -04:00
|
|
|
&emptySPI, /* spi */
|
|
|
|
&sitlAnalogIn, /* analogin */
|
2012-12-12 18:04:27 -04:00
|
|
|
&sitlEEPROMStorage, /* storage */
|
2017-01-09 08:23:23 -04:00
|
|
|
&sitlUart0Driver, /* console */
|
|
|
|
&sitlGPIO, /* gpio */
|
|
|
|
&sitlRCInput, /* rcinput */
|
|
|
|
&sitlRCOutput, /* rcoutput */
|
|
|
|
&sitlScheduler, /* scheduler */
|
|
|
|
&utilInstance, /* util */
|
2017-04-02 11:55:19 -03:00
|
|
|
&emptyOpticalFlow, /* onboard optical flow */
|
|
|
|
nullptr), /* CAN */
|
2012-12-13 18:57:01 -04:00
|
|
|
_sitl_state(&sitlState)
|
2012-12-11 21:30:12 -04:00
|
|
|
{}
|
|
|
|
|
2015-10-19 12:59:47 -03:00
|
|
|
void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const
|
2012-12-13 18:57:01 -04:00
|
|
|
{
|
2015-10-19 12:59:47 -03:00
|
|
|
assert(callbacks);
|
|
|
|
|
2012-12-13 18:57:01 -04:00
|
|
|
_sitl_state->init(argc, argv);
|
2015-12-02 11:14:20 -04:00
|
|
|
scheduler->init();
|
2012-12-11 21:30:12 -04:00
|
|
|
uartA->begin(115200);
|
|
|
|
|
2015-12-02 11:14:20 -04:00
|
|
|
rcin->init();
|
|
|
|
rcout->init();
|
2012-12-17 22:33:46 -04:00
|
|
|
|
2017-01-09 08:23:23 -04:00
|
|
|
// spi->init();
|
2015-12-02 11:14:20 -04:00
|
|
|
analogin->init();
|
2015-10-19 11:26:18 -03:00
|
|
|
|
|
|
|
callbacks->setup();
|
|
|
|
scheduler->system_initialized();
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
callbacks->loop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& AP_HAL::get_HAL() {
|
|
|
|
static const HAL_SITL hal;
|
|
|
|
return hal;
|
|
|
|
}
|
2012-12-11 21:30:12 -04:00
|
|
|
|
2017-01-09 08:23:23 -04:00
|
|
|
#endif // CONFIG_HAL_BOARD == HAL_BOARD_SITL
|