diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index 9a39e4466..544d00724 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -37,12 +37,11 @@ #include "opentx.h" #include -#define CLI_STACK_SIZE 500 #define CLI_COMMAND_MAX_ARGS 8 #define CLI_COMMAND_MAX_LEN 256 OS_TID cliTaskId; -OS_STK cliStack[CLI_STACK_SIZE]; +TaskStack cliStack; Fifo<256> cliRxFifo; uint8_t cliTracesEnabled = false; @@ -151,6 +150,44 @@ int cliTrace(const char ** argv) return 0; } +int cliStackInfo(const char ** argv) +{ + int tid = 0; + if (toInt(argv, 1, &tid) > 0) { + int available = 0; + int total = 0; + switch(tid) { + case MENU_TASK_INDEX: + total = menusStack.getSize(); + available = menusStack.available(); + break; + case MIXER_TASK_INDEX: + total = mixerStack.getSize(); + available = mixerStack.available(); + break; + case AUDIO_TASK_INDEX: + total = audioStack.getSize(); + available = audioStack.available(); + break; + case CLI_TASK_INDEX: + total = cliStack.getSize(); + available = cliStack.available(); + break; + case MAIN_TASK_INDEX: + total = mainStackAvailable(); + available = mainStackSize(); + break; + default: + break; + } + serialPrint("%d available (%d total)", available, total); + } + else { + serialPrint("%s: Invalid argument \"%s\"", argv[0], argv[1]); + } + return 0; +} + int cliVolume(const char ** argv) { int level = 0; @@ -214,6 +251,7 @@ const CliCommand cliCommands[] = { { "ls", cliLs, "" }, { "play", cliPlay, "" }, { "print", cliDisplay, "
[] | " }, + { "stackinfo", cliStackInfo, "" }, { "trace", cliTrace, "on | off" }, { "volume", cliVolume, "" }, { "help", cliHelp, "[]" }, @@ -279,7 +317,7 @@ void cliTask(void * pdata) uint8_t c; while (!cliRxFifo.pop(c)) { - CoTickDelay(5); // 10ms + CoTickDelay(10); // 20ms } if (c == 12) { @@ -311,5 +349,5 @@ void cliTask(void * pdata) void cliStart() { - cliTaskId = CoCreateTaskEx(cliTask, NULL, 10, &cliStack[CLI_STACK_SIZE-1], CLI_STACK_SIZE, 1, false); + cliTaskId = CoCreateTaskEx(cliTask, NULL, 10, &cliStack.stack[CLI_STACK_SIZE-1], CLI_STACK_SIZE, 1, false); } diff --git a/radio/src/cli.h b/radio/src/cli.h index d57f205bf..83836eeef 100644 --- a/radio/src/cli.h +++ b/radio/src/cli.h @@ -44,6 +44,9 @@ extern uint8_t cliTracesEnabled; #ifdef __cplusplus #include "fifo.h" extern Fifo<256> cliRxFifo; +#include "tasks_arm.h" +#define CLI_STACK_SIZE 1000 +extern TaskStack cliStack; #endif void cliStart(); diff --git a/radio/src/debug.h b/radio/src/debug.h index 422d8b483..da513ad70 100644 --- a/radio/src/debug.h +++ b/radio/src/debug.h @@ -40,7 +40,9 @@ #include #include "rtc.h" #include "dump.h" +#if defined(CLI) #include "cli.h" +#endif #if defined(__cplusplus) extern "C" { diff --git a/radio/src/gui/9X/view_statistics.cpp b/radio/src/gui/9X/view_statistics.cpp index ff33cbb78..f70176609 100755 --- a/radio/src/gui/9X/view_statistics.cpp +++ b/radio/src/gui/9X/view_statistics.cpp @@ -196,11 +196,11 @@ void menuStatisticsDebug(uint8_t event) #if defined(CPUARM) lcd_putsLeft(MENU_DEBUG_Y_RTOS, STR_FREESTACKMINB); - lcd_outdezAtt(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_RTOS+2, stack_free(0), UNSIGN|LEFT|TINSIZE); + lcd_outdezAtt(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_RTOS+2, menusStack.available(), UNSIGN|LEFT|TINSIZE); lcd_puts(lcdLastPos, MENU_DEBUG_Y_RTOS, "/"); - lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS+2, stack_free(1), UNSIGN|LEFT|TINSIZE); + lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS+2, mixerStack.available(), UNSIGN|LEFT|TINSIZE); lcd_puts(lcdLastPos, MENU_DEBUG_Y_RTOS, "/"); - lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS+2, stack_free(2), UNSIGN|LEFT|TINSIZE); + lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS+2, audioStack.available(), UNSIGN|LEFT|TINSIZE); #endif #if !defined(CPUARM) @@ -213,7 +213,7 @@ void menuStatisticsDebug(uint8_t event) lcd_putsLeft(4*FH, STR_TMIXMAXMS); lcd_outdezAtt(MENU_DEBUG_COL1_OFS, 4*FH, DURATION_MS_PREC2(maxMixerDuration), PREC2); lcd_putsLeft(5*FH, STR_FREESTACKMINB); - lcd_outdezAtt(14*FW, 5*FH, stack_free(), UNSIGN) ; + lcd_outdezAtt(14*FW, 5*FH, stackAvailable(), UNSIGN) ; #endif lcd_puts(4*FW, 7*FH+1, STR_MENUTORESET); diff --git a/radio/src/gui/Taranis/view_statistics.cpp b/radio/src/gui/Taranis/view_statistics.cpp index 6368f9e58..0a6f83e33 100755 --- a/radio/src/gui/Taranis/view_statistics.cpp +++ b/radio/src/gui/Taranis/view_statistics.cpp @@ -163,7 +163,7 @@ void menuStatisticsDebug(uint8_t event) } lcd_putsLeft(MENU_DEBUG_Y_FREE_RAM, "Free Mem"); - lcd_outdezAtt(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_FREE_RAM, getAvailableMemory(), LEFT); + lcd_outdezAtt(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_FREE_RAM, availableMemory(), LEFT); lcd_puts(lcdLastPos, MENU_DEBUG_Y_FREE_RAM, "b"); #if defined(LUA) @@ -189,13 +189,13 @@ void menuStatisticsDebug(uint8_t event) lcd_putsLeft(MENU_DEBUG_Y_RTOS, STR_FREESTACKMINB); lcd_putsAtt(MENU_DEBUG_COL1_OFS, MENU_DEBUG_Y_RTOS+1, "[M]", SMLSIZE); - lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(0), UNSIGN|LEFT); + lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, menusStack.available(), UNSIGN|LEFT); lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[X]", SMLSIZE); - lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(1), UNSIGN|LEFT); + lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, mixerStack.available(), UNSIGN|LEFT); lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[A]", SMLSIZE); - lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(2), UNSIGN|LEFT); + lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, audioStack.available(), UNSIGN|LEFT); lcd_putsAtt(lcdLastPos+2, MENU_DEBUG_Y_RTOS+1, "[I]", SMLSIZE); - lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, stack_free(255), UNSIGN|LEFT); + lcd_outdezAtt(lcdLastPos, MENU_DEBUG_Y_RTOS, mainStackAvailable(), UNSIGN|LEFT); lcd_puts(3*FW, 7*FH+1, STR_MENUTORESET); lcd_status_line(); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index b9c971a22..d9733bc76 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2348,7 +2348,7 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim #if !defined(CPUARM) && !defined(SIMU) extern unsigned char __bss_end ; #define STACKPTR _SFR_IO16(0x3D) -void stack_paint() +void stackPaint() { // Init Stack while interrupts are disabled unsigned char *p ; @@ -2362,7 +2362,7 @@ void stack_paint() } } -uint16_t stack_free() +uint16_t stackAvailable() { unsigned char *p ; @@ -2492,7 +2492,7 @@ int main(void) lcdInit(); #endif - stack_paint(); + stackPaint(); #if defined(GUI) g_menuStack[0] = menuMainView; diff --git a/radio/src/opentx.h b/radio/src/opentx.h index 4a434962c..8dd967c4b 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -717,14 +717,14 @@ extern uint8_t flightModeTransitionLast; #endif #if defined(SIMU) - inline int getAvailableMemory() { return 1000; } + inline int availableMemory() { return 1000; } #elif defined(CPUARM) && !defined(SIMU) extern unsigned char *heap; extern int _end; extern int _estack; extern int _main_stack_start; extern int _heap_end; - #define getAvailableMemory() ((unsigned int)((unsigned char *)&_heap_end - heap)) + #define availableMemory() ((unsigned int)((unsigned char *)&_heap_end - heap)) #endif void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms); @@ -942,11 +942,8 @@ extern uint16_t lastMixerDuration; uint16_t getTmr16KHz(); #endif -#if defined(CPUARM) - uint32_t stack_free(uint32_t tid); - void stack_paint(); -#else - uint16_t stack_free(); +#if !defined(CPUARM) + uint16_t stackAvailable(); #endif #if defined(SPLASH) @@ -1050,12 +1047,7 @@ template void SWAP(t & a, t & b) { t tmp = b; b = a; a = tmp; } uint16_t isqrt32(uint32_t n); #if defined(CPUARM) && !defined(BOOT) -#if !defined(SIMU) -extern "C" { -#include -} -#endif - +#include "tasks_arm.h" extern OS_MutexID mixerMutex; inline void pauseMixerCalculations() { diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 965b0922b..4ed004709 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -330,7 +330,7 @@ void *main_thread(void *) #endif #if defined(CPUARM) - stack_paint(); + stackPaint(); #endif s_current_protocol[0] = 255; @@ -658,7 +658,7 @@ void eepromWriteBlock(uint8_t * pointer_ram, uint32_t pointer_eeprom, uint32_t s #endif #if !defined(CPUARM) -uint16_t stack_free() +uint16_t stackAvailable() { return 500; } diff --git a/radio/src/tasks_arm.cpp b/radio/src/tasks_arm.cpp index 5e0c1285d..803eb9aad 100644 --- a/radio/src/tasks_arm.cpp +++ b/radio/src/tasks_arm.cpp @@ -36,10 +36,10 @@ #include "opentx.h" -#define MENUS_STACK_SIZE 2000 -#define MIXER_STACK_SIZE 500 -#define AUDIO_STACK_SIZE 500 -#define BT_STACK_SIZE 500 +#define MENUS_STACK_SIZE 2000 +#define MIXER_STACK_SIZE 500 +#define AUDIO_STACK_SIZE 500 +#define BLUETOOTH_STACK_SIZE 500 #if defined(_MSC_VER) #define _ALIGNED(x) __declspec(align(x)) @@ -48,73 +48,85 @@ #endif OS_TID menusTaskId; -// stack must be aligned to 8 bytes otherwise printf for %f does not work! -OS_STK _ALIGNED(8) menusStack[MENUS_STACK_SIZE]; +// menus stack must be aligned to 8 bytes otherwise printf for %f does not work! +TaskStack _ALIGNED(8) menusStack; OS_TID mixerTaskId; -OS_STK mixerStack[MIXER_STACK_SIZE]; +TaskStack mixerStack; OS_TID audioTaskId; -OS_STK audioStack[AUDIO_STACK_SIZE]; +TaskStack audioStack; #if defined(BLUETOOTH) OS_TID btTaskId; -OS_STK btStack[BT_STACK_SIZE]; +TaskStack bluetoothStack; #endif OS_MutexID audioMutex; OS_MutexID mixerMutex; -void stack_paint() +enum TaskIndex { + MENU_TASK_INDEX, + MIXER_TASK_INDEX, + AUDIO_TASK_INDEX, + CLI_TASK_INDEX, + BLUETOOTH_TASK_INDEX, + TASK_INDEX_COUNT, + MAIN_TASK_INDEX = 255 +}; + +template +void TaskStack::paint() { - for (uint32_t i=0; i +uint32_t TaskStack::getSize() { - OS_STK *stack; - uint32_t size; + return size; +} - switch(tid) { - case 0: - stack = menusStack; - size = MENUS_STACK_SIZE; - break; - case 1: - stack = mixerStack; - size = MIXER_STACK_SIZE; - break; - case 2: - stack = audioStack; - size = AUDIO_STACK_SIZE; - break; -#if defined(PCBTARANIS) - case 255: - #if defined(SIMU) - return 1024; - #else - // main stack - stack = (OS_STK *)&_main_stack_start; - size = ((unsigned char *)&_estack - (unsigned char *)&_main_stack_start) / 4; - #endif - break; -#endif - default: - return 0; +uint32_t getStackAvailable(void * address, uint32_t size) +{ + uint32_t * array = (uint32_t *)address; + uint32_t i = 0; + while (i < size && array[i] == 0x55555555) { + i++; } - - uint32_t i=0; - for (; i +uint32_t TaskStack::available() +{ + return getStackAvailable(stack, size); +} + +void stackPaint() +{ + menusStack.paint(); + mixerStack.paint(); + audioStack.paint(); +#if defined(CLI) + cliStack.paint(); +#endif +} + +#if defined(CPUSTM32) +uint32_t mainStackSize() +{ + return ((unsigned char *)&_estack - (unsigned char *)&_main_stack_start) / 4; +} + +uint32_t mainStackAvailable() +{ + return getStackAvailable(&_main_stack_start, mainStackSize()); +} +#endif + #if !defined(SIMU) void mixerTask(void * pdata) @@ -176,7 +188,7 @@ void menusTask(void * pdata) } } -#if defined(REV9E) +#if defined(PCBTARANIS) && defined(REV9E) topLcdOff(); #endif @@ -204,12 +216,12 @@ void tasksStart() #endif #if defined(BLUETOOTH) - btTaskId = CoCreateTask(btTask, NULL, 15, &btStack[BT_STACK_SIZE-1], BT_STACK_SIZE); + btTaskId = CoCreateTask(btTask, NULL, 15, &bluetoothStack[BLUETOOTH_STACK_SIZE-1], BLUETOOTH_STACK_SIZE); #endif - mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE); - menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE); - audioTaskId = CoCreateTask(audioTask, NULL, 7, &audioStack[AUDIO_STACK_SIZE-1], AUDIO_STACK_SIZE); + mixerTaskId = CoCreateTask(mixerTask, NULL, 5, &mixerStack.stack[MIXER_STACK_SIZE-1], MIXER_STACK_SIZE); + menusTaskId = CoCreateTask(menusTask, NULL, 10, &menusStack.stack[MENUS_STACK_SIZE-1], MENUS_STACK_SIZE); + audioTaskId = CoCreateTask(audioTask, NULL, 7, &audioStack.stack[AUDIO_STACK_SIZE-1], AUDIO_STACK_SIZE); #if !defined(SIMU) audioMutex = CoCreateMutex(); diff --git a/radio/src/tasks_arm.h b/radio/src/tasks_arm.h new file mode 100644 index 000000000..9bb404b41 --- /dev/null +++ b/radio/src/tasks_arm.h @@ -0,0 +1,61 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * opentx is based on code named + * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, + * er9x by Erez Raviv: http://code.google.com/p/er9x/, + * and the original (and ongoing) project by + * Thomas Husterer, th9x: http://code.google.com/p/th9x/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + * + */ + +#ifndef _TASKS_ARM_H_ +#define _TASKS_ARM_H_ + +#if !defined(SIMU) +extern "C" { +#include +} +#endif + +template +class TaskStack +{ + public: + TaskStack() { } + void paint(); + uint32_t getSize(); + uint32_t available(); + OS_STK stack[size]; +}; + +void stackPaint(); +uint32_t mainStackSize(); +uint32_t mainStackAvailable(); + +#endif // _TASKS_ARM_H_