AP_HAL_PX4: implement HAL::run()

This commit is contained in:
Caio Marcelo de Oliveira Filho 2015-10-19 13:41:36 -02:00 committed by Andrew Tridgell
parent 3fe1d86c80
commit 0dab23c4df
3 changed files with 14 additions and 7 deletions

View File

@ -6,7 +6,8 @@
#define AP_HAL_MAIN() \ #define AP_HAL_MAIN() \
extern "C" __EXPORT int SKETCH_MAIN(int argc, char * const argv[]); \ extern "C" __EXPORT int SKETCH_MAIN(int argc, char * const argv[]); \
int SKETCH_MAIN(int argc, char * const argv[]) { \ int SKETCH_MAIN(int argc, char * const argv[]) { \
hal.init(argc, argv); \ AP_HAL::HAL::FunCallbacks callbacks(setup, loop); \
hal.run(argc, argv, &callbacks); \
return OK; \ return OK; \
} }

View File

@ -114,12 +114,10 @@ static void loop_overtime(void *)
px4_ran_overtime = true; px4_ran_overtime = true;
} }
static AP_HAL::HAL::Callbacks* g_callbacks;
static int main_loop(int argc, char **argv) static int main_loop(int argc, char **argv)
{ {
extern void setup(void);
extern void loop(void);
hal.uartA->begin(115200); hal.uartA->begin(115200);
hal.uartB->begin(38400); hal.uartB->begin(38400);
hal.uartC->begin(57600); hal.uartC->begin(57600);
@ -140,7 +138,7 @@ static int main_loop(int argc, char **argv)
schedulerInstance.hal_initialized(); schedulerInstance.hal_initialized();
setup(); g_callbacks->setup();
hal.scheduler->system_initialized(); hal.scheduler->system_initialized();
perf_counter_t perf_loop = perf_alloc(PC_ELAPSED, "APM_loop"); perf_counter_t perf_loop = perf_alloc(PC_ELAPSED, "APM_loop");
@ -165,7 +163,7 @@ static int main_loop(int argc, char **argv)
*/ */
hrt_call_after(&loop_overtime_call, 100000, (hrt_callout)loop_overtime, NULL); hrt_call_after(&loop_overtime_call, 100000, (hrt_callout)loop_overtime, NULL);
loop(); g_callbacks->loop();
if (px4_ran_overtime) { if (px4_ran_overtime) {
/* /*
@ -307,6 +305,13 @@ void HAL_PX4::init(int argc, char * const argv[]) const
exit(1); exit(1);
} }
void HAL_PX4::run(int argc, char * const argv[], Callbacks* callbacks) const
{
assert(callbacks);
g_callbacks = callbacks;
init(argc, argv);
}
const AP_HAL::HAL& AP_HAL::get_HAL() { const AP_HAL::HAL& AP_HAL::get_HAL() {
static const HAL_PX4 hal_px4; static const HAL_PX4 hal_px4;
return hal_px4; return hal_px4;

View File

@ -15,6 +15,7 @@ class HAL_PX4 : public AP_HAL::HAL {
public: public:
HAL_PX4(); HAL_PX4();
void init(int argc, char * const argv[]) const; void init(int argc, char * const argv[]) const;
void run(int argc, char* const argv[], Callbacks* callbacks) const override;
}; };
void hal_px4_set_priority(uint8_t priority); void hal_px4_set_priority(uint8_t priority);