diff --git a/src/drivers/device/vdev_posix.cpp b/src/drivers/device/vdev_posix.cpp index ca75c91923..d3b54c3db5 100644 --- a/src/drivers/device/vdev_posix.cpp +++ b/src/drivers/device/vdev_posix.cpp @@ -48,8 +48,6 @@ #include #include -#define PX4_DEBUG(...) - using namespace device; extern "C" { diff --git a/src/modules/simulator/simulator.cpp b/src/modules/simulator/simulator.cpp index 9f7b0c9597..139a25ac65 100644 --- a/src/modules/simulator/simulator.cpp +++ b/src/modules/simulator/simulator.cpp @@ -36,7 +36,7 @@ * A device simulator */ -#include +#include #include #include #include diff --git a/src/platforms/posix/px4_layer/px4_posix_tasks.cpp b/src/platforms/posix/px4_layer/px4_posix_tasks.cpp index c831ae04dd..c09845b79a 100644 --- a/src/platforms/posix/px4_layer/px4_posix_tasks.cpp +++ b/src/platforms/posix/px4_layer/px4_posix_tasks.cpp @@ -37,7 +37,7 @@ * Implementation of existing task API for Linux */ -#include +#include #include #include #include diff --git a/src/platforms/posix/tests/hello/hello_start_posix.cpp b/src/platforms/posix/tests/hello/hello_start_posix.cpp index 962645fabe..8dde729a6e 100644 --- a/src/platforms/posix/tests/hello/hello_start_posix.cpp +++ b/src/platforms/posix/tests/hello/hello_start_posix.cpp @@ -57,14 +57,14 @@ int hello_main(int argc, char *argv[]) { if (argc < 2) { - printf("usage: hello {start|stop|status}\n"); + PX4_WARN("usage: hello {start|stop|status}\n"); return 1; } if (!strcmp(argv[1], "start")) { if (HelloExample::appState.isRunning()) { - printf("already running\n"); + PX4_INFO("already running\n"); /* this is not an error */ return 0; } @@ -86,15 +86,15 @@ int hello_main(int argc, char *argv[]) if (!strcmp(argv[1], "status")) { if (HelloExample::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: hello_main {start|stop|status}\n"); + PX4_WARN("usage: hello_main {start|stop|status}\n"); return 1; } diff --git a/src/platforms/posix/tests/vcdev_test/vcdevtest_example.cpp b/src/platforms/posix/tests/vcdev_test/vcdevtest_example.cpp index 7f1c452d33..0721ae035a 100644 --- a/src/platforms/posix/tests/vcdev_test/vcdevtest_example.cpp +++ b/src/platforms/posix/tests/vcdev_test/vcdevtest_example.cpp @@ -59,7 +59,7 @@ static int writer_main(int argc, char *argv[]) int fd = px4_open(TESTDEV, PX4_F_RDONLY); if (fd < 0) { - printf("--- Open failed %d %d", fd, px4_errno); + PX4_INFO("--- Open failed %d %d", fd, px4_errno); return -px4_errno; } @@ -67,14 +67,14 @@ static int writer_main(int argc, char *argv[]) int i=0; while (i<3) { // Wait for 3 seconds - printf("--- Sleeping for 4 sec\n"); + PX4_INFO("--- Sleeping for 4 sec\n"); ret = sleep(4); if (ret < 0) { - printf("--- sleep failed %d %d\n", ret, errno); + PX4_INFO("--- sleep failed %d %d\n", ret, errno); return ret; } - printf("--- writing to fd\n"); + PX4_INFO("--- writing to fd\n"); ret = px4_write(fd, buf, 1); ++i; } @@ -110,16 +110,16 @@ static int test_pub_block(int fd, unsigned long blocked) { int ret = px4_ioctl(fd, DEVIOCSPUBBLOCK, blocked); if (ret < 0) { - printf("ioctl PX4_DEVIOCSPUBBLOCK failed %d %d", ret, px4_errno); + PX4_INFO("ioctl PX4_DEVIOCSPUBBLOCK failed %d %d", ret, px4_errno); return -px4_errno; } ret = px4_ioctl(fd, DEVIOCGPUBBLOCK, 0); if (ret < 0) { - printf("ioctl PX4_DEVIOCGPUBBLOCK failed %d %d", ret, px4_errno); + PX4_INFO("ioctl PX4_DEVIOCGPUBBLOCK failed %d %d", ret, px4_errno); return -px4_errno; } - printf("pub_blocked = %d %s\n", ret, (unsigned long)ret == blocked ? "PASS" : "FAIL"); + PX4_INFO("pub_blocked = %d %s\n", ret, (unsigned long)ret == blocked ? "PASS" : "FAIL"); return 0; } @@ -131,29 +131,29 @@ int VCDevExample::main() _node = new VCDevNode(); if (_node == 0) { - printf("Failed to allocate VCDevNode\n"); + PX4_INFO("Failed to allocate VCDevNode\n"); return -ENOMEM; } if (_node->init() != PX4_OK) { - printf("Failed to init VCDevNode\n"); + PX4_INFO("Failed to init VCDevNode\n"); return 1; } int fd = px4_open(TESTDEV, PX4_F_RDONLY); if (fd < 0) { - printf("Open failed %d %d", fd, px4_errno); + PX4_INFO("Open failed %d %d", fd, px4_errno); return -px4_errno; } void *p = 0; int ret = px4_ioctl(fd, DIOC_GETPRIV, (unsigned long)&p); if (ret < 0) { - printf("ioctl DIOC_GETPRIV failed %d %d", ret, px4_errno); + PX4_INFO("ioctl DIOC_GETPRIV failed %d %d", ret, px4_errno); return -px4_errno; } - printf("priv data = %p %s\n", p, p == (void *)_node ? "PASS" : "FAIL"); + PX4_INFO("priv data = %p %s\n", p, p == (void *)_node ? "PASS" : "FAIL"); ret = test_pub_block(fd, 1); if (ret < 0) @@ -174,32 +174,32 @@ int VCDevExample::main() (char* const*)NULL); while (!appState.exitRequested() && i<13) { - printf("=====================\n"); - printf("==== sleeping 2 sec ====\n"); + PX4_INFO("=====================\n"); + PX4_INFO("==== sleeping 2 sec ====\n"); sleep(2); fds[0].fd = fd; fds[0].events = POLLIN; fds[0].revents = 0; - printf("==== Calling Poll\n"); + PX4_INFO("==== Calling Poll\n"); ret = px4_poll(fds, 1, 1000); - printf("==== Done poll\n"); + PX4_INFO("==== Done poll\n"); if (ret < 0) { - printf("==== poll failed %d %d\n", ret, px4_errno); + PX4_INFO("==== poll failed %d %d\n", ret, px4_errno); px4_close(fd); } else if (i > 0) { if (ret == 0) - printf("==== Nothing to read - PASS\n"); + PX4_INFO("==== Nothing to read - PASS\n"); else - printf("==== poll returned %d\n", ret); + PX4_INFO("==== poll returned %d\n", ret); } else if (i == 0) { if (ret == 1) - printf("==== %d to read - %s\n", ret, fds[0].revents & POLLIN ? "PASS" : "FAIL"); + PX4_INFO("==== %d to read - %s\n", ret, fds[0].revents & POLLIN ? "PASS" : "FAIL"); else - printf("==== %d to read - FAIL\n", ret); + PX4_INFO("==== %d to read - FAIL\n", ret); } ++i; diff --git a/src/platforms/posix/tests/wqueue/wqueue_main.cpp b/src/platforms/posix/tests/wqueue/wqueue_main.cpp index a7117cca09..8dd5cc9707 100644 --- a/src/platforms/posix/tests/wqueue/wqueue_main.cpp +++ b/src/platforms/posix/tests/wqueue/wqueue_main.cpp @@ -37,6 +37,7 @@ * * @author Mark Charlebois */ +#include #include #include #include "wqueue_test.h" @@ -46,10 +47,10 @@ int PX4_MAIN(int argc, char **argv) { px4::init(argc, argv, "wqueue_test"); - printf("wqueue hello\n"); + PX4_INFO("wqueue hello\n"); WQueueTest wq; wq.main(); - printf("goodbye\n"); + PX4_INFO("goodbye\n"); return 0; } diff --git a/src/platforms/posix/tests/wqueue/wqueue_start_posix.cpp b/src/platforms/posix/tests/wqueue/wqueue_start_posix.cpp index 20c9975578..2479020097 100644 --- a/src/platforms/posix/tests/wqueue/wqueue_start_posix.cpp +++ b/src/platforms/posix/tests/wqueue/wqueue_start_posix.cpp @@ -39,6 +39,7 @@ */ #include "wqueue_test.h" #include +#include #include #include #include @@ -53,14 +54,14 @@ int wqueue_test_main(int argc, char *argv[]) { if (argc < 2) { - printf("usage: wqueue_test {start|stop|status}\n"); + PX4_INFO("usage: wqueue_test {start|stop|status}\n"); return 1; } if (!strcmp(argv[1], "start")) { if (WQueueTest::appState.isRunning()) { - printf("already running\n"); + PX4_INFO("already running\n"); /* this is not an error */ return 0; } @@ -82,15 +83,15 @@ int wqueue_test_main(int argc, char *argv[]) if (!strcmp(argv[1], "status")) { if (WQueueTest::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: wqueue_test {start|stop|status}\n"); + PX4_INFO("usage: wqueue_test {start|stop|status}\n"); return 1; } diff --git a/src/platforms/px4_defines.h b/src/platforms/px4_defines.h index 1b2cf1dea5..c17b39e4c5 100644 --- a/src/platforms/px4_defines.h +++ b/src/platforms/px4_defines.h @@ -39,7 +39,7 @@ #pragma once -#include +#include /* Get the name of the default value fiven the param name */ #define PX4_PARAM_DEFAULT_VALUE_NAME(_name) PARAM_##_name##_DEFAULT diff --git a/src/platforms/px4_debug.h b/src/platforms/px4_log.h similarity index 84% rename from src/platforms/px4_debug.h rename to src/platforms/px4_log.h index 6cac039b28..e0d3cff8d4 100644 --- a/src/platforms/px4_debug.h +++ b/src/platforms/px4_log.h @@ -32,13 +32,25 @@ ****************************************************************************/ /** - * @file px4_debug.h - * Platform dependant debug + * @file px4_log.h + * Platform dependant logging/debug */ #pragma once -#if defined(__PX4_LINUX) || defined(__PX4_QURT) +#if defined(__PX4_QURT) + +__BEGIN_DECLS +extern void qurt_log(const char *fmt, ...); +__END_DECLS + +#define PX4_DBG(...) qurt_log(__VA_ARGS__) +#define PX4_DEBUG(...) qurt_log(__VA_ARGS__) +#define PX4_INFO(...) qurt_log(__VA_ARGS__) +#define PX4_WARN(...) qurt_log(__VA_ARGS__) +#define PX4_ERR(...) { qurt_log("ERROR file %s line %d:", __FILE__, __LINE__); qurt_log(__VA_ARGS__); } + +#elif defined(__PX4_LINUX) #if defined(__PX4_LINUX) #include diff --git a/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp b/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp index c077e21c8a..e5d2297e9a 100644 --- a/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp +++ b/src/platforms/qurt/px4_layer/px4_qurt_tasks.cpp @@ -53,11 +53,13 @@ #include #include +#include #include #define MAX_CMD_LEN 100 -#define PX4_MAX_TASKS 100 +#define PX4_MAX_TASKS 5 + struct task_entry { int pid; @@ -73,28 +75,28 @@ typedef struct { px4_main_t entry; int argc; - char *argv[]; - // strings are allocated after the + char * argv[]; + // strings are allocated after } pthdata_t; static void entry_adapter ( void *ptr ) { - printf("entry_adapter\n"); pthdata_t *data = (pthdata_t *) ptr; + PX4_DEBUG("entry_adapter %p %p entry %p %d %p\n", ptr, data, data->entry, data->argc, data->argv[0]); - printf("data->entry = %p\n", data->entry); + PX4_DEBUG("data->entry = %p\n", data->entry); data->entry(data->argc, data->argv); free(ptr); - printf("after entry\n"); - printf("Before px4_task_exit\n"); + PX4_DEBUG("after entry\n"); + PX4_DEBUG("Before px4_task_exit\n"); px4_task_exit(0); - printf("After px4_task_exit\n"); + PX4_DEBUG("After px4_task_exit\n"); } void px4_systemreset(bool to_bootloader) { - printf("Called px4_system_reset\n"); + PX4_DEBUG("Called px4_system_reset\n"); } px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int stack_size, px4_main_t entry, char * const *argv) @@ -107,7 +109,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int unsigned long structsize; char * p = (char *)argv; - printf("px4_task_spawn_cmd entry = %p\n", entry); + PX4_DEBUG("px4_task_spawn_cmd entry = %p %p %s\n", entry, argv, argv[0]); // Calculate argc while (p != (char *)0) { p = argv[argc]; @@ -116,20 +118,24 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int ++argc; len += strlen(p)+1; } - printf("arg %d %p\n", argc, argv); + PX4_DEBUG("arg %d %p\n", argc, argv); structsize = sizeof(pthdata_t)+(argc+1)*sizeof(char *); pthdata_t *taskdata; + PX4_DEBUG("arg %d %p\n", argc, argv); // not safe to pass stack data to the thread creation taskdata = (pthdata_t *)malloc(structsize+len); + PX4_DEBUG("arg %d %p\n", argc, argv); offset = ((unsigned long)taskdata)+structsize; + PX4_DEBUG("arg %d %p\n", argc, argv); taskdata->entry = entry; taskdata->argc = argc; + PX4_DEBUG("arg %d %p\n", argc, argv); for (i=0; iargv[i] = (char *)offset; strcpy((char *)offset, argv[i]); offset+=strlen(argv[i])+1; @@ -142,11 +148,11 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int taskmap[i].pid = i+1; taskmap[i].name = name; taskmap[i].isused = true; - taskmap[i].sp = malloc(stack_size); + taskmap[i].sp = malloc(2048); break; } } - printf("TEST2\n"); + PX4_DEBUG("taskdata %p entry %p %d %p\n", taskdata, taskdata->entry, taskdata->argc, taskdata->argv[0]); thread_create(entry_adapter, taskmap[i].sp, i+1, (void *) taskdata); return i+1; @@ -154,7 +160,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int int px4_task_delete(px4_task_t id) { - printf("Called px4_task_delete\n"); + PX4_DEBUG("Called px4_task_delete\n"); return -EINVAL; } @@ -167,7 +173,7 @@ void px4_task_exit(int ret) int px4_task_kill(px4_task_t id, int sig) { - printf("Called px4_task_kill\n"); + PX4_DEBUG("Called px4_task_kill\n"); return -EINVAL; } @@ -176,16 +182,16 @@ void px4_show_tasks() int idx; int count = 0; - printf("Active Tasks:\n"); + PX4_DEBUG("Active Tasks:\n"); for (idx=0; idx < PX4_MAX_TASKS; idx++) { if (taskmap[idx].isused) { - printf(" %-10s %d\n", taskmap[idx].name.c_str(), taskmap[idx].pid); + PX4_DEBUG(" %-10s %d\n", taskmap[idx].name.c_str(), taskmap[idx].pid); count++; } } if (count == 0) - printf(" No running tasks\n"); + PX4_DEBUG(" No running tasks\n"); } diff --git a/src/platforms/qurt/px4_layer/work_thread.c b/src/platforms/qurt/px4_layer/work_thread.c index a57cf4b10a..3873034189 100644 --- a/src/platforms/qurt/px4_layer/work_thread.c +++ b/src/platforms/qurt/px4_layer/work_thread.c @@ -139,7 +139,7 @@ static void work_process(FAR struct wqueue_s *wqueue, int lock_id) work_unlock(lock_id); if (!worker) { - printf("MESSED UP: worker = 0\n"); + PX4_WARN("MESSED UP: worker = 0\n"); } else worker(arg); diff --git a/src/platforms/qurt/tests/hello/hello_example.cpp b/src/platforms/qurt/tests/hello/hello_example.cpp index 6827220888..d0a4de0dc6 100644 --- a/src/platforms/qurt/tests/hello/hello_example.cpp +++ b/src/platforms/qurt/tests/hello/hello_example.cpp @@ -1,4 +1,3 @@ - /**************************************************************************** * * Copyright (C) 2015 Mark Charlebois. All rights reserved. @@ -40,6 +39,7 @@ */ #include "hello_example.h" +#include #include #include @@ -52,7 +52,7 @@ int HelloExample::main() int i=0; while (!appState.exitRequested() && i<5) { - printf(" Doing work...\n"); + PX4_DEBUG(" Doing work...\n"); ++i; } diff --git a/src/platforms/qurt/tests/hello/hello_main.cpp b/src/platforms/qurt/tests/hello/hello_main.cpp index 69e8c21ec0..d18c016753 100644 --- a/src/platforms/qurt/tests/hello/hello_main.cpp +++ b/src/platforms/qurt/tests/hello/hello_main.cpp @@ -38,6 +38,7 @@ * @author Mark Charlebois */ #include +#include #include #include "hello_example.h" #include @@ -46,10 +47,10 @@ int PX4_MAIN(int argc, char **argv) { px4::init(argc, argv, "hello"); - printf("hello\n"); + PX4_DEBUG("hello\n"); HelloExample hello; hello.main(); - printf("goodbye\n"); + PX4_DEBUG("goodbye\n"); return 0; } diff --git a/src/platforms/qurt/tests/hello/hello_start_qurt.cpp b/src/platforms/qurt/tests/hello/hello_start_qurt.cpp index 71f30cd8dd..7c935e1ab4 100644 --- a/src/platforms/qurt/tests/hello/hello_start_qurt.cpp +++ b/src/platforms/qurt/tests/hello/hello_start_qurt.cpp @@ -38,6 +38,7 @@ * @author Mark Charlebois */ #include "hello_example.h" +#include #include #include #include @@ -52,11 +53,11 @@ extern "C" __EXPORT int hello_main(int argc, char *argv[]); static void usage() { - printf("usage: hello {start|stop|status}\n"); + PX4_DEBUG("usage: hello {start|stop|status}\n"); } int hello_main(int argc, char *argv[]) { - printf("argc = %d %s %s %p\n", argc, argv[0], argv[1], argv[2]); + PX4_DEBUG("argc = %d %s %s %p\n", argc, argv[0], argv[1], argv[2]); if (argc < 2) { usage(); return 1; @@ -64,8 +65,9 @@ int hello_main(int argc, char *argv[]) if (!strcmp(argv[1], "start")) { + PX4_DEBUG("Starting\n"); if (HelloExample::appState.isRunning()) { - printf("already running\n"); + PX4_DEBUG("already running\n"); /* this is not an error */ return 0; } @@ -73,7 +75,7 @@ int hello_main(int argc, char *argv[]) daemon_task = px4_task_spawn_cmd("hello", SCHED_DEFAULT, SCHED_PRIORITY_MAX - 5, - 2000, + 16000, PX4_MAIN, (char* const*)argv); @@ -87,10 +89,10 @@ int hello_main(int argc, char *argv[]) if (!strcmp(argv[1], "status")) { if (HelloExample::appState.isRunning()) { - printf("is running\n"); + PX4_DEBUG("is running\n"); } else { - printf("not started\n"); + PX4_DEBUG("not started\n"); } return 0;