ardupilot/libraries/AP_HAL_SITL/HAL_SITL_Class.cpp

101 lines
2.6 KiB
C++
Raw Normal View History

/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
#include <AP_HAL/AP_HAL.h>
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
2015-10-19 11:26:18 -03:00
#include <assert.h>
#include "AP_HAL_SITL.h"
#include "AP_HAL_SITL_Namespace.h"
#include "HAL_SITL_Class.h"
#include "Scheduler.h"
#include "AnalogIn.h"
#include "UARTDriver.h"
#include "Storage.h"
#include "RCInput.h"
2012-12-17 23:56:21 -04:00
#include "RCOutput.h"
#include "SITL_State.h"
#include "Util.h"
#include <AP_HAL_Empty/AP_HAL_Empty.h>
#include <AP_HAL_Empty/AP_HAL_Empty_Private.h>
using namespace HALSITL;
static SITLEEPROMStorage sitlEEPROMStorage;
static SITL_State sitlState;
static SITLScheduler sitlScheduler(&sitlState);
2012-12-17 23:56:21 -04:00
static SITLRCInput sitlRCInput(&sitlState);
static SITLRCOutput sitlRCOutput(&sitlState);
static SITLAnalogIn sitlAnalogIn(&sitlState);
// use the Empty HAL for hardware we don't emulate
static Empty::GPIO emptyGPIO;
static Empty::Semaphore emptyI2Csemaphore;
static Empty::I2CDriver emptyI2C(&emptyI2Csemaphore);
static Empty::SPIDeviceManager emptySPI;
static Empty::OpticalFlow emptyOpticalFlow;
static SITLUARTDriver sitlUart0Driver(0, &sitlState);
static SITLUARTDriver sitlUart1Driver(1, &sitlState);
static SITLUARTDriver sitlUart2Driver(2, &sitlState);
2013-11-22 04:16:05 -04:00
static SITLUARTDriver sitlUart3Driver(3, &sitlState);
2013-12-21 07:26:30 -04:00
static SITLUARTDriver sitlUart4Driver(4, &sitlState);
static SITLUtil utilInstance;
HAL_SITL::HAL_SITL() :
AP_HAL::HAL(
&sitlUart0Driver, /* uartA */
2013-11-22 04:16:05 -04:00
&sitlUart1Driver, /* uartB */
&sitlUart2Driver, /* uartC */
2013-11-22 04:16:05 -04:00
&sitlUart3Driver, /* uartD */
2013-12-21 07:26:30 -04:00
&sitlUart4Driver, /* uartE */
&emptyI2C, /* i2c */
&emptyI2C, /* i2c */
&emptyI2C, /* i2c */
&emptySPI, /* spi */
&sitlAnalogIn, /* analogin */
&sitlEEPROMStorage, /* storage */
2013-10-05 05:32:23 -03:00
&sitlUart0Driver, /* console */
&emptyGPIO, /* gpio */
2012-12-17 23:56:21 -04:00
&sitlRCInput, /* rcinput */
&sitlRCOutput, /* rcoutput */
&sitlScheduler, /* scheduler */
&utilInstance, /* util */
&emptyOpticalFlow), /* onboard optical flow */
_sitl_state(&sitlState)
{}
2015-10-19 12:59:47 -03:00
void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const
{
2015-10-19 12:59:47 -03:00
assert(callbacks);
_sitl_state->init(argc, argv);
scheduler->init();
uartA->begin(115200);
rcin->init();
rcout->init();
//spi->init();
//i2c->begin();
//i2c->setTimeout(100);
analogin->init();
2015-10-19 11:26:18 -03:00
callbacks->setup();
scheduler->system_initialized();
for (;;) {
callbacks->loop();
}
}
const AP_HAL::HAL& AP_HAL::get_HAL() {
static const HAL_SITL hal;
return hal;
}
#endif // CONFIG_HAL_BOARD == HAL_BOARD_SITL