The switching between different AP_HAL was happening by giving different
definitions of AP_HAL_BOARD_DRIVER, and the programs would use it to
instantiate.
A program or library code would have to explicitly include (and depend)
on the concrete implementation of the HAL, even when using it only via
interface.
The proposed change move this dependency to be link time. There is a
AP_HAL::get_HAL() function that is used by the client code. Each
implementation of HAL provides its own definition of this function,
returning the appropriate concrete instance.
Since this replaces the job of AP_HAL_BOARD_DRIVER, the definition was
removed.
The static variables for PX4 and VRBRAIN were named differently to avoid
shadowing the extern symbol 'hal'.
It both reduces flash size and move symbols to read-only sections.
The scheduler_tasks table is one known not to be in read-only section before due
to the FastDelegate implementation. Before and after this patch:
APMrover2 $ size APMrover2.elf{.old,}
text data bss dec hex filename
611406 4832 40920 657158 a0706 APMrover2.elf.old
609686 4824 38936 653446 9f886 APMrover2.elf
APMrover2 $ nm -C APMrover2.elf{.old,} |grep tasks
0000000000696f80 B Rover::scheduler_tasks
000000000047c440 R Rover::scheduler_tasks
As can be seen above, now the scheduler_tasks symbol is in a read-only data
section and in all of them we decreased the total size.
For APM2 we have a similar situation, but the table was already in text section
because it was using plain C pointers:
APMrover2 $ size APMrover2.elf{.old,}
text data bss dec hex filename
189518 1038 3494 194050 2f602 APMrover2.elf.old
189216 1038 3480 193734 2f4c6 APMrover2.elf
APMrover2 $ nm -C APMrover2.elf{.old,} |grep tasks
00001f92 T Rover::scheduler_tasks
00001f8a T Rover::scheduler_tasks
Now that we are using C++11 we can use variadic templates to simplify
the FastDelegate classes. It also simplifies moving away from the
FastDelegate implementation.
Start to add code behind APM_BUILD_FUNCTOR to support changing the
functor implementation (without breaking the build while the change is
not complete).
the idea of a separate console class was never really used, and just
added confusion in a HAL port. It also consumes some much needed ram
and flash space on APM2
this allows the class to be passed in, meaning that drivers that use
register_timer_process() and register_io_process() don't need to use
static members. That results in simpler, easier to read code
* I'd love to build a proper abstraction for logging, but I don't have the
time to do so right now.
* The dataflash libs need to be pushed into the AP_HAL_AVR anyway, so I'll
do that now and replace the interface with a better logging driver later.