mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_HAL: create AP_HAL namespace and use for some HAL functionality
For certain basic functionality, there aren't much benefit to be able to vary the implementation easily at runtime. So instead of using virtual functions, use regular functions that are "resolved" at link time. The implementation of such functions is provided per board/platform. Examples of functions that fit this include: getting the current time (since boot), panic'ing, getting system information, rebooting. These functions are less likely to benefit from the indirection provided by virtual interfaces. For more complex hardware access APIs the indirection makes more sense and ease the testing (when we have it!). The idea is that instead of calling hal.scheduler->panic("on the streets of london"); now use AP_HAL::panic("on the streets of london"); A less important side-effect is that call-site code gets smaller. Currently the compiler needs to get the hal, get the scheduler pointer, get the right function pointer in the vtable for that scheduler. And the call must include an extra parameter ("this"). Now it will be just a function call, with the address resolved at link time. This patch introduces the first functions that will be in the namespace, further patches will implementations for each board and then switch the call-sites. The extra init() function allow any initial setup needed for the functions to work.
This commit is contained in:
parent
50e3c2ce3a
commit
efbc7648b1
@ -1,6 +1,4 @@
|
||||
|
||||
#ifndef __AP_HAL_H__
|
||||
#define __AP_HAL_H__
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@ -30,5 +28,4 @@
|
||||
/* HAL Class definition */
|
||||
#include "HAL.h"
|
||||
|
||||
#endif // __AP_HAL_H__
|
||||
|
||||
#include "system.h"
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "SPIDriver.h"
|
||||
#include "Storage.h"
|
||||
#include "UARTDriver.h"
|
||||
#include "system.h"
|
||||
|
||||
class AP_HAL::HAL {
|
||||
public:
|
||||
@ -49,7 +50,9 @@ public:
|
||||
rcout(_rcout),
|
||||
scheduler(_scheduler),
|
||||
util(_util)
|
||||
{}
|
||||
{
|
||||
AP_HAL::init();
|
||||
}
|
||||
|
||||
struct Callbacks {
|
||||
virtual void setup() = 0;
|
||||
|
20
libraries/AP_HAL/system.h
Normal file
20
libraries/AP_HAL/system.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <AP_Common/AP_Common.h>
|
||||
|
||||
#include "AP_HAL_Macros.h"
|
||||
|
||||
namespace AP_HAL {
|
||||
|
||||
void init();
|
||||
|
||||
void panic(const char *errormsg, ...) FORMAT(1, 2) NORETURN;
|
||||
|
||||
uint32_t micros();
|
||||
uint32_t millis();
|
||||
uint64_t micros64();
|
||||
uint64_t millis64();
|
||||
|
||||
} // namespace AP_HAL
|
9
libraries/AP_HAL_FLYMAPLE/system.cpp
Normal file
9
libraries/AP_HAL_FLYMAPLE/system.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <AP_HAL/system.h>
|
||||
|
||||
namespace AP_HAL {
|
||||
|
||||
void init()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace AP_HAL
|
9
libraries/AP_HAL_Linux/system.cpp
Normal file
9
libraries/AP_HAL_Linux/system.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <AP_HAL/system.h>
|
||||
|
||||
namespace AP_HAL {
|
||||
|
||||
void init()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace AP_HAL
|
9
libraries/AP_HAL_PX4/system.cpp
Normal file
9
libraries/AP_HAL_PX4/system.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <AP_HAL/system.h>
|
||||
|
||||
namespace AP_HAL {
|
||||
|
||||
void init()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace AP_HAL
|
9
libraries/AP_HAL_SITL/system.cpp
Normal file
9
libraries/AP_HAL_SITL/system.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <AP_HAL/system.h>
|
||||
|
||||
namespace AP_HAL {
|
||||
|
||||
void init()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace AP_HAL
|
9
libraries/AP_HAL_VRBRAIN/system.cpp
Normal file
9
libraries/AP_HAL_VRBRAIN/system.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <AP_HAL/system.h>
|
||||
|
||||
namespace AP_HAL {
|
||||
|
||||
void init()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace AP_HAL
|
Loading…
Reference in New Issue
Block a user