APM:Libraries
HAL_SITL_Class.cpp
Go to the documentation of this file.
1 #include <AP_HAL/AP_HAL.h>
2 
3 #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
4 
5 #include <assert.h>
6 
7 #include "AP_HAL_SITL.h"
9 #include "HAL_SITL_Class.h"
10 #include "Scheduler.h"
11 #include "AnalogIn.h"
12 #include "UARTDriver.h"
13 #include "Storage.h"
14 #include "RCInput.h"
15 #include "RCOutput.h"
16 #include "GPIO.h"
17 #include "SITL_State.h"
18 #include "Util.h"
19 
22 
23 using namespace HALSITL;
24 
27 static Scheduler sitlScheduler(&sitlState);
28 static RCInput sitlRCInput(&sitlState);
29 static RCOutput sitlRCOutput(&sitlState);
30 static AnalogIn sitlAnalogIn(&sitlState);
31 static GPIO sitlGPIO(&sitlState);
32 
33 // use the Empty HAL for hardware we don't emulate
37 
38 static UARTDriver sitlUart0Driver(0, &sitlState);
39 static UARTDriver sitlUart1Driver(1, &sitlState);
40 static UARTDriver sitlUart2Driver(2, &sitlState);
41 static UARTDriver sitlUart3Driver(3, &sitlState);
42 static UARTDriver sitlUart4Driver(4, &sitlState);
43 static UARTDriver sitlUart5Driver(5, &sitlState);
44 
45 static Util utilInstance(&sitlState);
46 
48  AP_HAL::HAL(
49  &sitlUart0Driver, /* uartA */
50  &sitlUart1Driver, /* uartB */
51  &sitlUart2Driver, /* uartC */
52  &sitlUart3Driver, /* uartD */
53  &sitlUart4Driver, /* uartE */
54  &sitlUart5Driver, /* uartF */
55  &i2c_mgr_instance,
56  &emptySPI, /* spi */
57  &sitlAnalogIn, /* analogin */
58  &sitlEEPROMStorage, /* storage */
59  &sitlUart0Driver, /* console */
60  &sitlGPIO, /* gpio */
61  &sitlRCInput, /* rcinput */
62  &sitlRCOutput, /* rcoutput */
63  &sitlScheduler, /* scheduler */
64  &utilInstance, /* util */
65  &emptyOpticalFlow, /* onboard optical flow */
66  nullptr), /* CAN */
67  _sitl_state(&sitlState)
68 {}
69 
70 void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const
71 {
72  assert(callbacks);
73 
74  _sitl_state->init(argc, argv);
75  scheduler->init();
76  uartA->begin(115200);
77 
78  rcin->init();
79  rcout->init();
80 
81  // spi->init();
82  analogin->init();
83 
84  callbacks->setup();
86 
88  callbacks->loop();
90  }
91  execv(argv[0], argv);
92  AP_HAL::panic("PANIC: REBOOT FAILED");
93 }
94 
96  static const HAL_SITL hal;
97  return hal;
98 }
99 
100 #endif // CONFIG_HAL_BOARD == HAL_BOARD_SITL
virtual void setup()=0
static UARTDriver sitlUart2Driver(2, &sitlState)
virtual void loop()=0
HALSITL::SITL_State * _sitl_state
virtual void begin(uint32_t baud)=0
static UARTDriver sitlUart0Driver(0, &sitlState)
static UARTDriver sitlUart1Driver(1, &sitlState)
static bool _should_reboot
Definition: Scheduler.h:53
static UARTDriver sitlUart3Driver(3, &sitlState)
const AP_HAL::HAL & hal
Definition: UARTDriver.cpp:37
static EEPROMStorage sitlEEPROMStorage
static ChibiOS::Util utilInstance
virtual void init()=0
virtual void init()=0
virtual void init()=0
static Empty::OpticalFlow emptyOpticalFlow
void run(int argc, char *const argv[], Callbacks *callbacks) const override
static UARTDriver sitlUart4Driver(4, &sitlState)
const HAL & get_HAL()
static void _run_io_procs(bool called_from_isr)
Definition: Scheduler.cpp:176
void init(int argc, char *const argv[])
Definition: SITL_State.cpp:492
virtual void init()=0
AP_HAL::UARTDriver * uartA
Definition: HAL.h:100
static Empty::SPIDeviceManager emptySPI
static SITL_State sitlState
AP_HAL::RCOutput * rcout
Definition: HAL.h:113
void panic(const char *errormsg,...) FMT_PRINTF(1
Definition: system.cpp:140
static Empty::I2CDeviceManager i2c_mgr_instance
AP_HAL::RCInput * rcin
Definition: HAL.h:112
static UARTDriver sitlUart5Driver(5, &sitlState)
AP_HAL::Scheduler * scheduler
Definition: HAL.h:114
AP_HAL::AnalogIn * analogin
Definition: HAL.h:108
virtual void system_initialized()=0