mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
OP-1721 C++ and ARM tools
Enable revo C++ support: 1. Set USE_CXX to enable compliation and linkage of C++ source code 2. Disables rtti and exceptions 3. operator new and delete call pios malloc/free 4. Static constructor invocation supported 5. Additional methods, compile options, and need to have main as a cpp to solve various link issues when using static constructors but to avoid adding unnecessary libs. 6. Upgrade arm tools
This commit is contained in:
parent
b0a0582e85
commit
53482be09c
89
flight/libraries/mini_cpp.cpp
Normal file
89
flight/libraries/mini_cpp.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
||||
* @{
|
||||
*
|
||||
* @file mini_cpp.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
|
||||
* @brief CPP support methods
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <pios.h>
|
||||
|
||||
// _init is called by __libc_init_array during invocation of static constructors
|
||||
// __libc_init_array calls _init, which is defined in crti.o. _init calls functions that are in .init section.
|
||||
// If you don't have meaningful stuff in .init section, just define an empty _init function.
|
||||
extern "C" int _init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// operator new
|
||||
void *operator new(size_t size) throw()
|
||||
{
|
||||
return pios_malloc(size);
|
||||
}
|
||||
|
||||
// operator delete
|
||||
void operator delete(void *p) throw()
|
||||
{
|
||||
pios_free(p);
|
||||
}
|
||||
|
||||
// The function __aeabi_atexit() handles the static destructors. This can be empty
|
||||
// because we have no operating system to return to, hence the static destructors
|
||||
// will never be called.
|
||||
extern "C" int __aeabi_atexit(__attribute__((unused)) void *object, __attribute__((unused)) void (*destructor)(void *), __attribute__((unused)) void *dso_handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// see https://answers.launchpad.net/gcc-arm-embedded/+question/221105
|
||||
// and https://answers.launchpad.net/gcc-arm-embedded/+question/224709
|
||||
__extension__ typedef int __guard __attribute__((mode(__DI__)));
|
||||
extern "C" int __cxa_atexit(void (*f)(void *), void *p, void *d);
|
||||
extern "C" int __cxa_guard_acquire(__guard *);
|
||||
extern "C" void __cxa_guard_release(__guard *);
|
||||
extern "C" void __cxa_guard_abort(__guard *);
|
||||
extern "C" void __cxa_pure_virtual(void);
|
||||
|
||||
int __cxa_guard_acquire(__attribute__((unused)) __guard *g)
|
||||
{
|
||||
return !*(char *)(g);
|
||||
};
|
||||
void __cxa_guard_release(__attribute__((unused)) __guard *g)
|
||||
{
|
||||
*(char *)g = 1;
|
||||
};
|
||||
void __cxa_guard_abort(__attribute__((unused)) __guard *) {};
|
||||
void __cxa_pure_virtual(void)
|
||||
{
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
int __cxa_atexit(__attribute__((unused)) void (*f)(void *), __attribute__((unused)) void *p, __attribute__((unused)) void *d)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
/**
|
||||
* @}
|
||||
*/
|
@ -219,6 +219,7 @@ static void SensorsTask(__attribute__((unused)) void *parameters)
|
||||
#endif
|
||||
break;
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
#if defined(PIOS_INCLUDE_MPU6000)
|
||||
gyro_test = PIOS_MPU6000_Test();
|
||||
accel_test = gyro_test;
|
||||
@ -277,7 +278,9 @@ static void SensorsTask(__attribute__((unused)) void *parameters)
|
||||
AccelSensorData accelSensorData;
|
||||
GyroSensorData gyroSensorData;
|
||||
|
||||
switch (bdinfo->board_rev) {
|
||||
uint8_t board_rev = bdinfo->board_rev;
|
||||
|
||||
switch (board_rev) {
|
||||
case 0x01: // L3GD20 + BMA180 board
|
||||
#if defined(PIOS_INCLUDE_BMA180)
|
||||
{
|
||||
|
@ -34,6 +34,10 @@
|
||||
#ifndef PIOS_H
|
||||
#define PIOS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <pios_helpers.h>
|
||||
#include <pios_math.h>
|
||||
#include <pios_constants.h>
|
||||
@ -360,4 +364,10 @@
|
||||
/* #define IDLE_COUNTS_PER_SEC_AT_NO_LOAD 995998 */
|
||||
|
||||
#endif /* USE_SIM_POSIX */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // closing brace for extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* PIOS_H */
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <string.h>
|
||||
#include <stm32f4xx.h>
|
||||
|
||||
extern int __libc_init_array(void);
|
||||
|
||||
/* prototype for main() that tells us not to worry about it possibly returning */
|
||||
extern int main(void) __attribute__((noreturn));
|
||||
|
||||
@ -91,6 +93,10 @@ void _main(void)
|
||||
/* leave a little space at the top in case memset() isn't a leaf with no locals */
|
||||
memset(&irq_stack, 0xa5, sizeof(irq_stack) - 64);
|
||||
|
||||
#ifdef PIOS_ENABLE_CXX
|
||||
__libc_init_array();
|
||||
#endif
|
||||
|
||||
/* call main */
|
||||
(void)main();
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ endif
|
||||
include ../board-info.mk
|
||||
include $(ROOT_DIR)/make/firmware-defs.mk
|
||||
|
||||
# REVO C++ support
|
||||
USE_CXX = YES
|
||||
|
||||
# ARM DSP library
|
||||
USE_DSP_LIB ?= NO
|
||||
|
||||
@ -70,7 +73,7 @@ ifndef TESTAPP
|
||||
## Application Core
|
||||
SRC += ../pios_usb_board_data.c
|
||||
SRC += $(OPMODULEDIR)/System/systemmod.c
|
||||
SRC += $(OPSYSTEM)/revolution.c
|
||||
CPPSRC += $(OPSYSTEM)/revolution.cpp
|
||||
SRC += $(OPSYSTEM)/pios_board.c
|
||||
SRC += $(FLIGHTLIB)/alarms.c
|
||||
SRC += $(FLIGHTLIB)/instrumentation.c
|
||||
@ -92,6 +95,7 @@ ifndef TESTAPP
|
||||
SRC += $(FLIGHTLIB)/auxmagsupport.c
|
||||
SRC += $(FLIGHTLIB)/lednotification.c
|
||||
SRC += $(FLIGHTLIB)/sha1.c
|
||||
CPPSRC += $(FLIGHTLIB)/mini_cpp.cpp
|
||||
|
||||
## UAVObjects
|
||||
include ./UAVObjects.inc
|
||||
|
@ -31,7 +31,7 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
extern "C" {
|
||||
#include "inc/openpilot.h"
|
||||
#include <uavobjectsinit.h>
|
||||
|
||||
@ -74,6 +74,7 @@ static void initTask(void *parameters);
|
||||
|
||||
/* Prototype of generated InitModules() function */
|
||||
extern void InitModules(void);
|
||||
}
|
||||
|
||||
/**
|
||||
* OpenPilot Main function:
|
@ -123,6 +123,7 @@ SRC += $(FLIGHTLIB)/optypes.c
|
||||
|
||||
## Modules
|
||||
SRC += $(foreach mod, $(MODULES), $(sort $(wildcard $(OPMODULEDIR)/$(mod)/*.c)))
|
||||
CPPSRC += $(foreach mod, $(MODULES), $(sort $(wildcard $(OPMODULEDIR)/$(mod)/*.cpp)))
|
||||
SRC += $(foreach mod, $(OPTMODULES), $(sort $(wildcard $(OPMODULEDIR)/$(mod)/*.c)))
|
||||
|
||||
# Declare all non-optional modules as built-in to force inclusion.
|
||||
|
@ -23,6 +23,9 @@ endif
|
||||
# Set to YES to compile for debugging
|
||||
DEBUG ?= NO
|
||||
|
||||
# Set to YES to compile C++ implemented features
|
||||
USE_CXX ?= NO
|
||||
|
||||
# Set to YES to use the Servo output pins for debugging via scope or logic analyser
|
||||
ENABLE_DEBUG_PINS ?= NO
|
||||
|
||||
@ -123,7 +126,7 @@ CFLAGS += -g$(DEBUGF)
|
||||
CFLAGS += -mapcs-frame
|
||||
CFLAGS += -fomit-frame-pointer
|
||||
CFLAGS += -Wall -Wextra
|
||||
CFLAGS += -Wfloat-equal -Wunsuffixed-float-constants -Wdouble-promotion
|
||||
CFLAGS += -Wfloat-equal -Wdouble-promotion
|
||||
CFLAGS += -Wshadow
|
||||
CFLAGS += -Werror
|
||||
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I.
|
||||
@ -157,12 +160,20 @@ else
|
||||
CFLAGS += -fdata-sections -ffunction-sections
|
||||
endif
|
||||
|
||||
ifeq ($(USE_CXX), YES)
|
||||
CFLAGS += -DPIOS_ENABLE_CXX
|
||||
endif
|
||||
|
||||
|
||||
# Compiler flags to generate dependency files
|
||||
CFLAGS += -MD -MP -MF $(OUTDIR)/dep/$(@F).d
|
||||
|
||||
# Flags only for C
|
||||
#CONLYFLAGS += -Wnested-externs
|
||||
CONLYFLAGS += $(CSTANDARD)
|
||||
CONLYFLAGS += $(CSTANDARD) -Wunsuffixed-float-constants
|
||||
|
||||
# CPP Flags
|
||||
CPPFLAGS += -fno-rtti -fno-exceptions -std=c++11 -fno-use-cxa-atexit
|
||||
|
||||
# Assembler flags.
|
||||
# -Wa,...: tell GCC to pass this to the assembler.
|
||||
@ -188,7 +199,12 @@ ifneq ($(DEBUG), YES)
|
||||
endif
|
||||
|
||||
# List of all source files.
|
||||
ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC)
|
||||
ifeq ($(USE_CXX), YES)
|
||||
ALLSRC = $(CPPSRCARM) $(CPPSRC) $(ASRCARM) $(ASRC) $(SRCARM) $(SRC)
|
||||
else
|
||||
ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC)
|
||||
endif
|
||||
|
||||
# List of all source files without directory and file-extension.
|
||||
ALLSRCBASE = $(notdir $(basename $(ALLSRC)))
|
||||
|
||||
@ -221,7 +237,11 @@ endif
|
||||
# @$(PYTHON) $(PYMITETOOLS)/pmImgCreator.py -f $(PYMITEPLAT)/pmfeatures.py -c -u -o $(OUTDIR)/pmlibusr_img.c --native-file=$(OUTDIR)/pmlibusr_nat.c $(FLIGHTPLANS)/test.py
|
||||
|
||||
# Link: create ELF output file from object files.
|
||||
ifeq ($(USE_CXX), YES)
|
||||
$(eval $(call LINK_CXX_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ), $(ALLLIB)))
|
||||
else
|
||||
$(eval $(call LINK_TEMPLATE, $(OUTDIR)/$(TARGET).elf, $(ALLOBJ), $(ALLLIB)))
|
||||
endif
|
||||
|
||||
# Assemble: create object files from assembler source files.
|
||||
$(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src))))
|
||||
@ -235,11 +255,13 @@ $(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src))))
|
||||
# Compile: create object files from C source files. ARM-only
|
||||
$(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src))))
|
||||
|
||||
ifeq ($(USE_CXX), YES)
|
||||
# Compile: create object files from C++ source files.
|
||||
$(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src))))
|
||||
$(foreach src, $(CPPSRC), $(eval $(call COMPILE_CXX_TEMPLATE, $(src))))
|
||||
|
||||
# Compile: create object files from C++ source files. ARM-only
|
||||
$(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src))))
|
||||
$(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CXX_ARM_TEMPLATE, $(src))))
|
||||
endif
|
||||
|
||||
# Compile: create assembler files from C source files. ARM/Thumb
|
||||
$(eval $(call PARTIAL_COMPILE_TEMPLATE, SRC))
|
||||
|
@ -233,10 +233,10 @@ endef
|
||||
# $2 = list of object files that make up the elf file
|
||||
define LINK_CXX_TEMPLATE
|
||||
.SECONDARY : $(1)
|
||||
.PRECIOUS : $(2)
|
||||
$(1): $(2)
|
||||
.PRECIOUS : $(2) $(3)
|
||||
$(1): $(2) $(3)
|
||||
@$(ECHO) $(MSG_LINKING) $$(call toprel, $$@)
|
||||
$(V1) $(CXX) $(THUMB) $$(CFLAGS) $(2) --output $$@ $$(LDFLAGS)
|
||||
$(V1) $(CXX) $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$(CXXFLAGS) $(2) $(3) --output $$@ $$(LDFLAGS)
|
||||
endef
|
||||
|
||||
# Compile: create assembler files from C source files. ARM/Thumb
|
||||
|
@ -57,14 +57,14 @@ endif
|
||||
|
||||
ifeq ($(UNAME), Linux)
|
||||
ifeq ($(ARCH), x86_64)
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2
|
||||
ARM_SDK_MD5_URL:= https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2/+md5
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2
|
||||
ARM_SDK_MD5_URL:= https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2/+md5
|
||||
QT_SDK_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-linux-x64-5.4.0.run
|
||||
QT_SDK_MD5_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-linux-x64-5.4.0.run.md5
|
||||
QT_SDK_ARCH := gcc_64
|
||||
else
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2
|
||||
ARM_SDK_MD5_URL := https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2/+md5
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2
|
||||
ARM_SDK_MD5_URL := https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-linux.tar.bz2/+md5
|
||||
QT_SDK_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-linux-x86-5.4.0.run
|
||||
QT_SDK_MD5_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-linux-x86-5.4.0.run.md5
|
||||
QT_SDK_ARCH := gcc
|
||||
@ -72,8 +72,8 @@ ifeq ($(UNAME), Linux)
|
||||
UNCRUSTIFY_URL := http://wiki.openpilot.org/download/attachments/18612236/uncrustify-0.60.tar.gz
|
||||
DOXYGEN_URL := http://wiki.openpilot.org/download/attachments/18612236/doxygen-1.8.3.1.src.tar.gz
|
||||
else ifeq ($(UNAME), Darwin)
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-mac.tar.bz2
|
||||
ARM_SDK_MD5_URL:= https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-mac.tar.bz2/+md5
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-mac.tar.bz2
|
||||
ARM_SDK_MD5_URL:= https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-mac.tar.bz2/+md5
|
||||
QT_SDK_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-mac-x64-clang-5.4.0.dmg
|
||||
QT_SDK_MD5_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-mac-x64-clang-5.4.0.dmg.md5
|
||||
QT_SDK_ARCH := clang_64
|
||||
@ -83,8 +83,8 @@ else ifeq ($(UNAME), Darwin)
|
||||
UNCRUSTIFY_URL := http://wiki.openpilot.org/download/attachments/18612236/uncrustify-0.60.tar.gz
|
||||
DOXYGEN_URL := http://wiki.openpilot.org/download/attachments/18612236/doxygen-1.8.3.1.src.tar.gz
|
||||
else ifeq ($(UNAME), Windows)
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-win32.zip
|
||||
ARM_SDK_MD5_URL:= https://launchpad.net/gcc-arm-embedded/4.8/4.8-2014-q1-update/+download/gcc-arm-none-eabi-4_8-2014q1-20140314-win32.zip/+md5
|
||||
ARM_SDK_URL := https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-win32.zip
|
||||
ARM_SDK_MD5_URL:= https://launchpad.net/gcc-arm-embedded/4.9/4.9-2014-q4-major/+download/gcc-arm-none-eabi-4_9-2014q4-20141203-win32.zip/+md5
|
||||
QT_SDK_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe
|
||||
QT_SDK_MD5_URL := http://download.qt-project.org/official_releases/qt/5.4/5.4.0/qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe.md5
|
||||
QT_SDK_ARCH := mingw491_32
|
||||
@ -100,7 +100,7 @@ GTEST_URL := http://wiki.openpilot.org/download/attachments/18612236/gtest-1.6.0
|
||||
|
||||
# When changing PYTHON_DIR, you must also update it in ground/openpilotgcs/src/python.pri
|
||||
# When changing SDL_DIR or OPENSSL_DIR, you must also update them in ground/openpilotgcs/openpilotgcs.pri
|
||||
ARM_SDK_DIR := $(TOOLS_DIR)/gcc-arm-none-eabi-4_8-2014q1
|
||||
ARM_SDK_DIR := $(TOOLS_DIR)/gcc-arm-none-eabi-4_9-2014q4
|
||||
QT_SDK_DIR := $(TOOLS_DIR)/qt-5.4.0
|
||||
MINGW_DIR := $(QT_SDK_DIR)/Tools/mingw491_32
|
||||
PYTHON_DIR := $(QT_SDK_DIR)/Tools/mingw491_32/opt/bin
|
||||
|
Loading…
x
Reference in New Issue
Block a user