diff --git a/tracker/software/cfg/pp10a/chconf.h b/tracker/software/cfg/pp10a/chconf.h index aafad186..795cb730 100644 --- a/tracker/software/cfg/pp10a/chconf.h +++ b/tracker/software/cfg/pp10a/chconf.h @@ -557,8 +557,11 @@ * @brief Idle Loop hook. * @details This hook is continuously invoked by the idle thread loop. */ +#define PORT_IDLE_THREAD_STACK_SIZE 256 #define CH_CFG_IDLE_LOOP_HOOK() { \ /* Idle loop code here.*/ \ + extern void pktIdleThread(void); \ + pktIdleThread(); \ } /** diff --git a/tracker/software/cfg/pp10a/portab.h b/tracker/software/cfg/pp10a/portab.h index bc823405..53cbfcde 100644 --- a/tracker/software/cfg/pp10a/portab.h +++ b/tracker/software/cfg/pp10a/portab.h @@ -149,7 +149,7 @@ * Number of general AX25/APRS processing & frame send buffers. * Can configured as being in CCM to save system core memory use. */ -#define NUMBER_COMMON_PKT_BUFFERS 10U +#define NUMBER_COMMON_PKT_BUFFERS 15U #define RESERVE_BUFFERS_FOR_INTERNAL 2U #define MAX_BUFFERS_FOR_BURST_SEND 5U #if (MAX_BUFFERS_FOR_BURST_SEND > \ diff --git a/tracker/software/cfg/pp10b/chconf.h b/tracker/software/cfg/pp10b/chconf.h index aafad186..795cb730 100644 --- a/tracker/software/cfg/pp10b/chconf.h +++ b/tracker/software/cfg/pp10b/chconf.h @@ -557,8 +557,11 @@ * @brief Idle Loop hook. * @details This hook is continuously invoked by the idle thread loop. */ +#define PORT_IDLE_THREAD_STACK_SIZE 256 #define CH_CFG_IDLE_LOOP_HOOK() { \ /* Idle loop code here.*/ \ + extern void pktIdleThread(void); \ + pktIdleThread(); \ } /** diff --git a/tracker/software/cfg/pp10b/portab.h b/tracker/software/cfg/pp10b/portab.h index 1db67a22..d6a98352 100644 --- a/tracker/software/cfg/pp10b/portab.h +++ b/tracker/software/cfg/pp10b/portab.h @@ -139,9 +139,9 @@ #define NUMBER_RX_PKT_BUFFERS 3U /* Number of general AX25/APRS processing & frame send buffers. */ -#define NUMBER_COMMON_PKT_BUFFERS 10U +#define NUMBER_COMMON_PKT_BUFFERS 15U #define RESERVE_BUFFERS_FOR_INTERNAL 2U -#define MAX_BUFFERS_FOR_BURST_SEND 3U +#define MAX_BUFFERS_FOR_BURST_SEND 5U #if (MAX_BUFFERS_FOR_BURST_SEND > \ (NUMBER_COMMON_PKT_BUFFERS - RESERVE_BUFFERS_FOR_INTERNAL)) #warning "Can not allocate requested buffers for burst send - set to 50%" diff --git a/tracker/software/source/protocols/packet/aprs.c b/tracker/software/source/protocols/packet/aprs.c index e026cc15..28e0e7f3 100644 --- a/tracker/software/source/protocols/packet/aprs.c +++ b/tracker/software/source/protocols/packet/aprs.c @@ -1,4 +1,4 @@ -/* trackuino copyright (C) 2010 EA5HAV Javi +/* Certain parts from trackuino copyright (C) 2010 EA5HAV Javi * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,6 +27,7 @@ #include "flash.h" #include "image.h" #include "beacon.h" +#include "threads.h" #define METER_TO_FEET(m) (((m)*26876) / 8192) diff --git a/tracker/software/source/threads/rxtx/beacon.c b/tracker/software/source/threads/rxtx/beacon.c index af213aae..df20b808 100644 --- a/tracker/software/source/threads/rxtx/beacon.c +++ b/tracker/software/source/threads/rxtx/beacon.c @@ -31,9 +31,8 @@ THD_FUNCTION(bcnThread, arg) { sysinterval_t time = chVTGetSystemTime(); /* Now wait for our delay before starting. */ - sysinterval_t delay = conf->beacon.init_delay; - chThdSleep(delay); + chThdSleepUntil(chVTGetSystemTime() + conf->beacon.init_delay); while(true) { @@ -96,7 +95,7 @@ THD_FUNCTION(bcnThread, arg) { conf->symbol, dataPoint, true); if(packet == NULL) { - TRACE_WARN("BCN > No free packet objects" + TRACE_ERROR("BCN > No free packet objects" " for position transmission"); } else { if(!transmitOnRadio(packet, @@ -129,7 +128,7 @@ THD_FUNCTION(bcnThread, arg) { */ packet = aprs_compose_aprsd_message(conf->call, path, call); if(packet == NULL) { - TRACE_WARN("BCN > No free packet objects " + TRACE_ERROR("BCN > No free packet objects " "or badly formed APRSD message"); } else { if(!transmitOnRadio(packet, @@ -159,7 +158,7 @@ thread_t * start_beacon_thread(bcn_app_conf_t *conf, const char *name) { name, LOWPRIO, bcnThread, conf); if(!th) { // Print startup error, do not start watchdog for this thread - TRACE_ERROR("BCN > Could not start thread (not enough memory available)"); + TRACE_ERROR("BCN > Could not start thread (insufficient memory)"); } return th; } diff --git a/tracker/software/source/threads/threads.c b/tracker/software/source/threads/threads.c index 5b28ed0a..1d03fcb5 100644 --- a/tracker/software/source/threads/threads.c +++ b/tracker/software/source/threads/threads.c @@ -23,8 +23,7 @@ void start_essential_threads(void) chThdSleep(TIME_MS2I(300)); // Wait for tracking manager to initialize } -void start_user_threads(void) -{ +void start_user_threads(void) { conf_t *conf_flash = (conf_t*)0x08060000; /* Check if a user update has been made to configuration in flash. */ if(conf_flash->magic != CONFIG_MAGIC_UPDATED) { @@ -69,21 +68,35 @@ void start_user_threads(void) 0, conf_sram.aprs.rx.radio_conf.rssi); } - - /** - * General thread termination and cleanup. - * Called by the thread that is terminating. - */ -/* void pktTerminateThread(thread_t *th) { - (void)th; - }*/ - - /** - * General thread termination and cleanup. - * Handled from the idle thread hook. - */ -/* void release_terminated_thread(thread_t *th) { - (void)th; - }*/ +} + +/** + * General thread termination and cleanup. + * Called by the thread that is terminating. + * A message is posted to the idle thread. + * Idle then releases the calling thread. + */ +void pktTerminateSelf(void) { + /* Post self thread to idle for termination cleanup. */ + msg_t msg = chMsgSend(chSysGetIdleThreadX(), MSG_OK); + chThdExit(msg); +} + +/** + * General thread termination and cleanup. + * Called from the idle thread hook. + */ +void pktIdleThread(void) { + chSysLock(); + if(!chMsgIsPendingI(chThdGetSelfX())) { + chSysUnlock(); + return; + } + /* Get the message from the terminating thread. */ + chSysUnlock(); + thread_t *tp = chMsgWait(); + (void)chMsgGet(tp); + chMsgRelease(tp, MSG_OK); + (void)chThdWait(tp); } diff --git a/tracker/software/source/threads/threads.h b/tracker/software/source/threads/threads.h index 1e931d9e..deec6566 100644 --- a/tracker/software/source/threads/threads.h +++ b/tracker/software/source/threads/threads.h @@ -5,8 +5,12 @@ void start_essential_threads(void); void start_user_threads(void); -void pktTerminateThread(thread_t *th); -void release_terminated_thread(thread_t *th); +void pktTerminateSelf(void); +void pktIdleThread(void); + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ extern sysinterval_t watchdog_tracking; // Last update time for module TRACKING