APMrover2: Start using new Functor implementation

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
This commit is contained in:
Lucas De Marchi 2015-05-24 20:48:51 -03:00 committed by Andrew Tridgell
parent 20ef7efaf6
commit 84f399ec3c
3 changed files with 54 additions and 35 deletions

View File

@ -2,6 +2,7 @@
#ifndef __AP_HAL_NAMESPACE_H__
#define __AP_HAL_NAMESPACE_H__
#include <AP_Vehicle_Type.h>
#include "string.h"
#include "utility/FastDelegate.h"
@ -29,10 +30,6 @@
#define DELEGATE_FUNCTION(rettype, ...) fastdelegate::FastDelegate0<rettype, ## __VA_ARGS__>
#ifndef APM_BUILD_FUNCTOR
#define APM_BUILD_FUNCTOR 0
#endif
#if APM_BUILD_FUNCTOR
#include "utility/functor.h"

View File

@ -51,37 +51,7 @@ public:
};
};
/*
define common vehicle build types. Note that the APM_BUILD_DIRECTORY
define is only available with makefile based build, not with
arduino.
Also note that code needs to support other APM_BUILD_DIRECTORY
values for example sketches
*/
#define APM_BUILD_APMrover2 1
#define APM_BUILD_ArduCopter 2
#define APM_BUILD_ArduPlane 3
#define APM_BUILD_AntennaTracker 4
#define APM_BUILD_UNKNOWN 5
/*
using this macro catches cases where we try to check vehicle type on
build systems that don't support it
*/
#ifdef APM_BUILD_DIRECTORY
#define APM_BUILD_TYPE(type) ((type) == APM_BUILD_DIRECTORY)
#else
#define APM_BUILD_TYPE(type) ((type) == APM_BUILD_UNKNOWN)
#endif
#ifndef APM_BUILD_FUNCTOR
#define APM_BUILD_FUNCTOR 0
#endif
#if APM_BUILD_TYPE(APM_BUILD_APMrover2) || APM_BUILD_TYPE(APM_BUILD_ArduPlane)
# define APM_BUILD_DELEGATES 1
#else
# define APM_BUILD_DELEGATES 0
#endif
#include "AP_Vehicle_Type.h"
#endif // AP_VEHICLE_H

View File

@ -0,0 +1,52 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AP_VEHICLE_TYPE_H
#define AP_VEHICLE_TYPE_H
/*
define common vehicle build types. Note that the APM_BUILD_DIRECTORY
define is only available with makefile based build, not with
arduino.
Also note that code needs to support other APM_BUILD_DIRECTORY
values for example sketches
*/
#define APM_BUILD_APMrover2 1
#define APM_BUILD_ArduCopter 2
#define APM_BUILD_ArduPlane 3
#define APM_BUILD_AntennaTracker 4
#define APM_BUILD_UNKNOWN 5
/*
using this macro catches cases where we try to check vehicle type on
build systems that don't support it
*/
#ifdef APM_BUILD_DIRECTORY
#define APM_BUILD_TYPE(type) ((type) == APM_BUILD_DIRECTORY)
#else
#define APM_BUILD_TYPE(type) ((type) == APM_BUILD_UNKNOWN)
#endif
#if APM_BUILD_TYPE(APM_BUILD_APMrover2)
# define APM_BUILD_FUNCTOR 1
# define APM_BUILD_DELEGATES 0
#elif APM_BUILD_TYPE(APM_BUILD_ArduPlane)
# define APM_BUILD_FUNCTOR 0
# define APM_BUILD_DELEGATES 1
#else
# define APM_BUILD_FUNCTOR 0
# define APM_BUILD_DELEGATES 0
#endif
#endif // AP_VEHICLE_TYPE_H