From 3db5f3bb3b9eba407e6db198d533cd775cd6ee36 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Tue, 12 May 2015 11:37:28 -0700 Subject: [PATCH] QuRT: toolchain changes Reworking toolchain and main.cpp for QuRT to a final link can be done and the apps.h file is autogenerated. Signed-off-by: Mark Charlebois --- Tools/qurt_apps.py | 9 ++-- makefiles/firmware_qurt.mk | 2 +- makefiles/qurt/config_qurt_default.mk | 50 +++++++++---------- makefiles/qurt_elf.mk | 5 +- makefiles/toolchain_hexagon.mk | 42 ++++++++++++---- .../posix/tests/hrt_test/hrt_test.cpp | 16 +++--- .../tests/hrt_test/hrt_test_start_posix.cpp | 10 ++-- src/platforms/qurt/main.cpp | 16 +++--- src/platforms/qurt/px4_layer/module.mk | 12 ++++- .../qurt/px4_layer/px4_qurt_impl.cpp | 31 ++++++------ 10 files changed, 109 insertions(+), 84 deletions(-) diff --git a/Tools/qurt_apps.py b/Tools/qurt_apps.py index ef2972de3d..540a564aa5 100755 --- a/Tools/qurt_apps.py +++ b/Tools/qurt_apps.py @@ -44,8 +44,7 @@ print print """ #include #include - -#define __EXPORT +#include #include #include @@ -84,14 +83,14 @@ map apps = app_map(); static void list_builtins(void) { - cout << "Builtin Commands:" << endl; + printf("Builtin Commands:\\n"); for (map::iterator it=apps.begin(); it!=apps.end(); ++it) - cout << '\t' << it->first << endl; + printf("\\t%s\\n", (it->first).c_str()); } static int shutdown_main(int argc, char *argv[]) { - cout << "Shutting down" << endl; + printf("Shutting down\\n"); exit(0); } diff --git a/makefiles/firmware_qurt.mk b/makefiles/firmware_qurt.mk index 6385517214..41128fa60f 100644 --- a/makefiles/firmware_qurt.mk +++ b/makefiles/firmware_qurt.mk @@ -58,6 +58,6 @@ HEXAGON_TOOLS_ROOT = /opt/6.4.05 V_ARCH = v5 HEXAGON_CLANG_BIN = $(addsuffix /qc/bin,$(HEXAGON_TOOLS_ROOT)) SIM = $(HEXAGON_CLANG_BIN)/hexagon-sim -SIMFLAGS+= -m$(V_ARCH) --timing +SIMFLAGS+= -m$(V_ARCH) sim: $(SIM) $(SIMFLAGS) Build/qurt_default.build/mainapp diff --git a/makefiles/qurt/config_qurt_default.mk b/makefiles/qurt/config_qurt_default.mk index 2e2323f4f0..7fab719582 100644 --- a/makefiles/qurt/config_qurt_default.mk +++ b/makefiles/qurt/config_qurt_default.mk @@ -10,18 +10,18 @@ # # Board support modules # -MODULES += drivers/device -MODULES += drivers/blinkm -MODULES += drivers/hil -MODULES += drivers/led -MODULES += drivers/rgbled -MODULES += modules/sensors +#MODULES += drivers/device +#MODULES += drivers/blinkm +#MODULES += drivers/hil +#MODULES += drivers/led +#MODULES += drivers/rgbled +#MODULES += modules/sensors #MODULES += drivers/ms5611 # # System commands # -MODULES += systemcmds/param +#MODULES += systemcmds/param # # General system control @@ -31,8 +31,8 @@ MODULES += systemcmds/param # # Estimation modules (EKF/ SO3 / other filters) # -MODULES += modules/attitude_estimator_ekf -MODULES += modules/ekf_att_pos_estimator +#MODULES += modules/attitude_estimator_ekf +#MODULES += modules/ekf_att_pos_estimator # # Vehicle Control @@ -42,37 +42,37 @@ MODULES += modules/ekf_att_pos_estimator # # Library modules # -MODULES += modules/systemlib -MODULES += modules/systemlib/mixer -MODULES += modules/uORB +#MODULES += modules/systemlib +#MODULES += modules/systemlib/mixer +#MODULES += modules/uORB #MODULES += modules/dataman #MODULES += modules/sdlog2 -MODULES += modules/simulator -MODULES += modules/commander +#MODULES += modules/simulator +#MODULES += modules/commander # # Libraries # -MODULES += lib/mathlib -MODULES += lib/mathlib/math/filter -MODULES += lib/geo -MODULES += lib/geo_lookup -MODULES += lib/conversion +#MODULES += lib/mathlib +#MODULES += lib/mathlib/math/filter +#MODULES += lib/geo +#MODULES += lib/geo_lookup +#MODULES += lib/conversion # # QuRT port # MODULES += platforms/qurt/px4_layer -MODULES += platforms/posix/drivers/accelsim -MODULES += platforms/posix/drivers/gyrosim -MODULES += platforms/posix/drivers/adcsim -MODULES += platforms/posix/drivers/barosim +#MODULES += platforms/posix/drivers/accelsim +#MODULES += platforms/posix/drivers/gyrosim +#MODULES += platforms/posix/drivers/adcsim +#MODULES += platforms/posix/drivers/barosim # # Unit tests # MODULES += platforms/qurt/tests/hello -MODULES += platforms/posix/tests/vcdev_test +#MODULES += platforms/posix/tests/vcdev_test #MODULES += platforms/posix/tests/hrt_test -MODULES += platforms/posix/tests/wqueue +#MODULES += platforms/posix/tests/wqueue diff --git a/makefiles/qurt_elf.mk b/makefiles/qurt_elf.mk index 57c6434e1d..0634013451 100644 --- a/makefiles/qurt_elf.mk +++ b/makefiles/qurt_elf.mk @@ -56,10 +56,8 @@ $(PRODUCT_SHARED_PRELINK): $(OBJS) $(MODULE_OBJS) $(LIBRARY_LIBS) $(GLOBAL_DEPS) $(PRODUCT_SHARED_LIB): $(PRODUCT_SHARED_PRELINK) $(call LINK_A,$@,$(PRODUCT_SHARED_PRELINK)) -MAIN = $(PX4_BASE)/src/platforms/qurt/main.cpp $(WORK_DIR)mainapp: $(PRODUCT_SHARED_LIB) - $(PX4_BASE)/Tools/qurt_apps.py > apps.h - $(call LINK,$@, -I. $(MAIN) $(PRODUCT_SHARED_LIB)) + $(call LINK,$@, $(PRODUCT_SHARED_LIB)) # # Utility rules @@ -70,4 +68,3 @@ clean: $(MODULE_CLEANS) @$(ECHO) %% cleaning $(Q) $(REMOVE) $(PRODUCT_ELF) $(Q) $(REMOVE) $(OBJS) $(DEP_INCLUDES) $(EXTRA_CLEANS) - diff --git a/makefiles/toolchain_hexagon.mk b/makefiles/toolchain_hexagon.mk index 62863a908f..11564918c8 100644 --- a/makefiles/toolchain_hexagon.mk +++ b/makefiles/toolchain_hexagon.mk @@ -38,6 +38,7 @@ # Toolchain commands. Normally only used inside this file. # HEXAGON_TOOLS_ROOT = /opt/6.4.05 +HEXAGON_SDK_ROOT = /opt/Hexagon_SDK/2.0 #V_ARCH = v4 V_ARCH = v5 CROSSDEV = hexagon- @@ -45,6 +46,9 @@ HEXAGON_BIN = $(addsuffix /gnu/bin,$(HEXAGON_TOOLS_ROOT)) HEXAGON_CLANG_BIN = $(addsuffix /qc/bin,$(HEXAGON_TOOLS_ROOT)) HEXAGON_LIB_DIR = $(HEXAGON_TOOLS_ROOT)/gnu/hexagon/lib HEXAGON_ISS_DIR = $(HEXAGON_TOOLS_ROOT)/qc/lib/iss +TOOLSLIB = $(HEXAGON_TOOLS_ROOT)/dinkumware/lib/$(V_ARCH)/G0 +QCTOOLSLIB = $(HEXAGON_TOOLS_ROOT)/qc/lib/$(V_ARCH)/G0 +QURTLIB = $(HEXAGON_SDK_ROOT)/lib/common/qurt/ADSP$(V_ARCH)MP/lib CC = $(HEXAGON_CLANG_BIN)/$(CROSSDEV)clang @@ -56,6 +60,24 @@ NM = $(HEXAGON_BIN)/$(CROSSDEV)nm OBJCOPY = $(HEXAGON_BIN)/$(CROSSDEV)objcopy OBJDUMP = $(HEXAGON_BIN)/$(CROSSDEV)objdump +QURTLIBS = \ + $(TOOLSLIB)/init.o \ + $(QURTLIB)/crt0.o \ + $(TOOLSLIB)/libc.a \ + $(TOOLSLIB)/libqcc.a \ + $(QCTOOLSLIB)/libhexagon.a \ + $(QURTLIB)/libqurt.a \ + $(QURTLIB)/libqurtkernel.a \ + $(QURTLIB)/libqurtcfs.a \ + $(QURTLIB)/libqube_compat.a \ + $(QURTLIB)/libtimer.a \ + $(QURTLIB)/libposix.a \ + $(TOOLSLIB)/libstdc++.a \ + $(QURTLIB)/../examples/cust_config.o \ + $(TOOLSLIB)/fini.o + + + # Check if the right version of the toolchain is available # CROSSDEV_VER_SUPPORTED = 6.4.05 @@ -68,7 +90,7 @@ endif # XXX this is pulled pretty directly from the fmu Make.defs - needs cleanup -MAXOPTIMIZATION ?= -Os +MAXOPTIMIZATION ?= -O0 # Base CPU flags for each of the supported architectures. # @@ -91,6 +113,7 @@ ARCHDEFINES += -DCONFIG_ARCH_BOARD_$(CONFIG_BOARD) \ -I$(PX4_BASE)/../dspal/include \ -I$(PX4_BASE)/../dspal/sys \ -I$(PX4_BASE)/mavlink/include/mavlink \ + -I$(QURTLIB)/..//include \ -Wno-error=shadow # optimisation flags @@ -179,7 +202,7 @@ endif HEXAGON_LIB_PATH = $(HEXAGON_TOOLS_ROOT)/gnu/hexagon/lib/$(V_ARCH)/G0 LIB_HEXAGON = $(HEXAGON_TOOLS_ROOT)/qc/lib/$(V_ARCH)/G0/libhexagon.a -EXTRA_LIBS += $(PX4_BASE)../dspal_libs/libdspal.a +#EXTRA_LIBS += $(PX4_BASE)../dspal_libs/libdspal.a # Flags we pass to the assembler # @@ -190,7 +213,7 @@ AFLAGS = $(CFLAGS) -D__ASSEMBLY__ \ LDSCRIPT = $(PX4_BASE)/posix-configs/posixtest/scripts/ld.script # Flags we pass to the linker # -LDFLAGS += \ +LDFLAGS += -g -nostdlib --section-start .start=0x1d000000\ $(EXTRALDFLAGS) \ $(addprefix -L,$(LIB_DIRS)) @@ -240,7 +263,7 @@ endef define PRELINK @$(ECHO) "PRELINK: $1" @$(MKDIR) -p $(dir $1) - echo $(Q) $(LD) -Ur -o $1 $2 + @echo $(Q) $(LD) -Ur -o $1 $2 $(Q) $(LD) -Ur -o $1 $2 endef @@ -250,8 +273,8 @@ endef define PRELINKF @$(ECHO) "PRELINKF: $1" @$(MKDIR) -p $(dir $1) - echo $(Q) $(LD) -Ur -T$(LDSCRIPT) -o $1 $2 - $(Q) $(LD) -Ur -T$(LDSCRIPT) -o $1 $2 + @echo $(Q) $(LD) -Ur -T$(LDSCRIPT) -o $1 $2 + $(Q) $(LD) -Ur -T$(LDSCRIPT) -o $1 $2 endef # $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1 @@ -287,10 +310,7 @@ endef define LINK @$(ECHO) "LINK: $1" @$(MKDIR) -p $(dir $1) - echo $(Q) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $1 $2 $(LIBS) - $(Q) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $1 $2 $(EXTRA_LIBS) - -# $(Q) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $1 $2 $(LIBS) $(EXTRA_LIBS) $(LIBGCC) - + @echo $(Q) $(LD) $(LDFLAGS) -o $1 --start-group $2 $(EXTRA_LIBS) $(QURTLIBS) --end-group + $(Q) $(LD) $(LDFLAGS) -o $1 --start-group $2 $(EXTRA_LIBS) $(QURTLIBS) --end-group endef diff --git a/src/platforms/posix/tests/hrt_test/hrt_test.cpp b/src/platforms/posix/tests/hrt_test/hrt_test.cpp index f5291b7dd7..8dd1f4bde3 100644 --- a/src/platforms/posix/tests/hrt_test/hrt_test.cpp +++ b/src/platforms/posix/tests/hrt_test/hrt_test.cpp @@ -53,7 +53,7 @@ static int update_interval = 1; static void timer_expired(void *arg) { static int i = 0; - printf("Test\n"); + PX4_INFO("Test\n"); if (i < 5) { i++; hrt_call_after(&t1, update_interval, timer_expired, (void *)0); @@ -67,24 +67,24 @@ int HRTTest::main() hrt_abstime t = hrt_absolute_time(); usleep(1000000); hrt_abstime elt = hrt_elapsed_time(&t); - printf("Elapsed time %llu in 1 sec (usleep)\n", (unsigned long long)elt); - printf("Start time %llu\n", (unsigned long long)t); + PX4_INFO("Elapsed time %llu in 1 sec (usleep)\n", (unsigned long long)elt); + PX4_INFO("Start time %llu\n", (unsigned long long)t); t = hrt_absolute_time(); sleep(1); elt = hrt_elapsed_time(&t); - printf("Elapsed time %llu in 1 sec (sleep)\n", (unsigned long long)elt); - printf("Start time %llu\n", (unsigned long long)t); + PX4_INFO("Elapsed time %llu in 1 sec (sleep)\n", (unsigned long long)elt); + PX4_INFO("Start time %llu\n", (unsigned long long)t); memset(&t1, 0, sizeof(t1)); - printf("HRT_CALL %d\n", hrt_called(&t1)); + PX4_INFO("HRT_CALL %d\n", hrt_called(&t1)); hrt_call_after(&t1, update_interval, timer_expired, (void *)0); sleep(2); - printf("HRT_CALL - %d\n", hrt_called(&t1)); + PX4_INFO("HRT_CALL - %d\n", hrt_called(&t1)); hrt_cancel(&t1); - printf("HRT_CALL + %d\n", hrt_called(&t1)); + PX4_INFO("HRT_CALL + %d\n", hrt_called(&t1)); return 0; } diff --git a/src/platforms/posix/tests/hrt_test/hrt_test_start_posix.cpp b/src/platforms/posix/tests/hrt_test/hrt_test_start_posix.cpp index 9d521364a8..241df590ee 100644 --- a/src/platforms/posix/tests/hrt_test/hrt_test_start_posix.cpp +++ b/src/platforms/posix/tests/hrt_test/hrt_test_start_posix.cpp @@ -49,14 +49,14 @@ extern "C" __EXPORT int hrttest_main(int argc, char *argv[]); int hrttest_main(int argc, char *argv[]) { if (argc < 2) { - printf("usage: hrttest_main {start|stop|status}\n"); + PX4_WARN("usage: hrttest_main {start|stop|status}\n"); return 1; } if (!strcmp(argv[1], "start")) { if (HRTTest::appState.isRunning()) { - printf("already running\n"); + PX4_INFO("already running\n"); /* this is not an error */ return 0; } @@ -78,15 +78,15 @@ int hrttest_main(int argc, char *argv[]) if (!strcmp(argv[1], "status")) { if (HRTTest::appState.isRunning()) { - printf("is running\n"); + PX4_INFO("is running\n"); } else { - printf("not started\n"); + PX4_INFO("not started\n"); } return 0; } - printf("usage: hrttest_main {start|stop|status}\n"); + PX4_WARN("usage: hrttest_main {start|stop|status}\n"); return 1; } diff --git a/src/platforms/qurt/main.cpp b/src/platforms/qurt/main.cpp index 58d37da24b..ae90d13e51 100644 --- a/src/platforms/qurt/main.cpp +++ b/src/platforms/qurt/main.cpp @@ -37,12 +37,9 @@ * @author Mark Charlebois */ -#include -#include #include -#include #include -#include +//#include //using namespace std; @@ -52,7 +49,6 @@ #include "px4_middleware.h" static const char *commands = -"x\n" "hello start" #if 0 "uorb start\n" @@ -79,15 +75,15 @@ static const char *commands = static void run_cmd(const vector &appargs) { // command is appargs[0] string command = appargs[0]; - printf("Looking for %s\n", command.c_str()); + //printf("Looking for %s\n", command.c_str()); if (apps.find(command) != apps.end()) { const char *arg[2+1]; unsigned int i = 0; - printf("size = %d\n", appargs.size()); + //printf("size = %d\n", appargs.size()); while (i < appargs.size() && appargs[i].c_str()[0] != '\0') { arg[i] = (char *)appargs[i].c_str(); - printf(" arg = '%s'\n", arg[i]); + //printf(" arg = '%s'\n", arg[i]); ++i; } arg[i] = (char *)0; @@ -97,7 +93,7 @@ static void run_cmd(const vector &appargs) { } else { - cout << "Invalid command" << endl; + //cout << "Invalid command" << endl; list_builtins(); } } @@ -159,8 +155,10 @@ extern void init_once(void); int main(int argc, char **argv) { + printf("In main\n"); px4::init_once(); px4::init(argc, argv, "mainapp"); process_commands(commands); for (;;) {} } + diff --git a/src/platforms/qurt/px4_layer/module.mk b/src/platforms/qurt/px4_layer/module.mk index 7d377e8bdd..5ee11aa2ad 100644 --- a/src/platforms/qurt/px4_layer/module.mk +++ b/src/platforms/qurt/px4_layer/module.mk @@ -35,6 +35,15 @@ # NuttX / uORB adapter library # +SRCDIR=$(dir $(MODULE_MK)) + +apps.h: $(PX4_BASE)/Tools/qurt_apps.py + $(PX4_BASE)/Tools/qurt_apps.py > $@ + +# Force creation of apps.h +main_.cpp: $(SRCDIR)/../main.cpp apps.h + cp $(SRCDIR)/../main.cpp $@ + SRCS = \ px4_qurt_impl.cpp \ px4_qurt_tasks.cpp \ @@ -49,6 +58,7 @@ SRCS = \ sq_addlast.c \ sq_remfirst.c \ sq_addafter.c \ - dq_rem.c + dq_rem.c \ + main_.cpp MAXOPTIMIZATION = -Os diff --git a/src/platforms/qurt/px4_layer/px4_qurt_impl.cpp b/src/platforms/qurt/px4_layer/px4_qurt_impl.cpp index 48303ec651..ad971c08be 100644 --- a/src/platforms/qurt/px4_layer/px4_qurt_impl.cpp +++ b/src/platforms/qurt/px4_layer/px4_qurt_impl.cpp @@ -46,7 +46,9 @@ #include #include #include +#include #include "systemlib/param/param.h" +#include __BEGIN_DECLS @@ -58,6 +60,14 @@ unsigned int sleep(unsigned int sec) { return 0; } extern void hrt_init(void); +void qurt_log(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + printf(fmt, args); + printf("n"); +} + __END_DECLS extern struct wqueue_s gwork[NWORKERS]; @@ -71,12 +81,7 @@ void init_once(void) { work_queues_init(); hrt_init(); -} - -void init(int argc, char *argv[], const char *app_name) -{ - printf("App name: %s\n", app_name); - + // Create high priority worker thread g_work[HPWORK].pid = px4_task_spawn_cmd("wkr_high", SCHED_DEFAULT, @@ -95,6 +100,11 @@ void init(int argc, char *argv[], const char *app_name) } +void init(int argc, char *argv[], const char *app_name) +{ + PX4_DEBUG("App name: %s\n", app_name); +} + } /** Retrieve from the data manager store */ @@ -131,12 +141,3 @@ size_t strnlen(const char *s, size_t maxlen) return i; } -void qurt_log(const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - vprintf(fmt, args); - printf("\n"); -} -