1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 22:35:12 +03:00

[ARM] Tasks stack class created

New taskinfo command added to the CLI. CLI stack size increased as it
was too short for the ls command (the CLI did hang!)
This commit is contained in:
Bertrand Songis 2015-09-05 11:10:18 +02:00
parent 2a2650376c
commit d14931f77f
10 changed files with 194 additions and 86 deletions

View file

@ -37,12 +37,11 @@
#include "opentx.h"
#include <ctype.h>
#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<CLI_STACK_SIZE> 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, "<directory>" },
{ "play", cliPlay, "<filename>" },
{ "print", cliDisplay, "<address> [<size>] | <what>" },
{ "stackinfo", cliStackInfo, "<tid>" },
{ "trace", cliTrace, "on | off" },
{ "volume", cliVolume, "<level>" },
{ "help", cliHelp, "[<command>]" },
@ -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);
}

View file

@ -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<CLI_STACK_SIZE> cliStack;
#endif
void cliStart();

View file

@ -40,7 +40,9 @@
#include <inttypes.h>
#include "rtc.h"
#include "dump.h"
#if defined(CLI)
#include "cli.h"
#endif
#if defined(__cplusplus)
extern "C" {

View file

@ -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);

View file

@ -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();

View file

@ -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;

View file

@ -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<class t> 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 <CoOS.h>
}
#endif
#include "tasks_arm.h"
extern OS_MutexID mixerMutex;
inline void pauseMixerCalculations()
{

View file

@ -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;
}

View file

@ -39,7 +39,7 @@
#define MENUS_STACK_SIZE 2000
#define MIXER_STACK_SIZE 500
#define AUDIO_STACK_SIZE 500
#define BT_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<MENUS_STACK_SIZE> _ALIGNED(8) menusStack;
OS_TID mixerTaskId;
OS_STK mixerStack[MIXER_STACK_SIZE];
TaskStack<MENUS_STACK_SIZE> mixerStack;
OS_TID audioTaskId;
OS_STK audioStack[AUDIO_STACK_SIZE];
TaskStack<AUDIO_STACK_SIZE> audioStack;
#if defined(BLUETOOTH)
OS_TID btTaskId;
OS_STK btStack[BT_STACK_SIZE];
TaskStack<BLUETOOTH_STACK_SIZE> 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<int size>
void TaskStack<size>::paint()
{
for (uint32_t i=0; i<MENUS_STACK_SIZE; i++)
menusStack[i] = 0x55555555;
for (uint32_t i=0; i<MIXER_STACK_SIZE; i++)
mixerStack[i] = 0x55555555;
for (uint32_t i=0; i<AUDIO_STACK_SIZE; i++)
audioStack[i] = 0x55555555;
for (uint32_t i=0; i<size; i++) {
stack[i] = 0x55555555;
}
}
uint32_t stack_free(uint32_t tid)
template<int size>
uint32_t TaskStack<size>::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<size; i++)
if (stack[i] != 0x55555555)
break;
return i*4;
}
template<int size>
uint32_t TaskStack<size>::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();

61
radio/src/tasks_arm.h Normal file
View file

@ -0,0 +1,61 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - 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 <CoOS.h>
}
#endif
template<int size>
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_