From 3cd6638e01b1cc2caa93d97fa92c1cb9820feef4 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 2 Apr 2016 19:31:54 +0200 Subject: [PATCH 01/28] [Horus] Fontcache added. Should improve a lot the menus speed. --- radio/src/fonts.h | 3 + radio/src/gui/horus/bitmapbuffer.cpp | 47 ++++++++++++--- radio/src/gui/horus/bitmapbuffer.h | 4 +- radio/src/gui/horus/fonts.cpp | 20 +++++++ radio/src/gui/horus/lcd.h | 71 +++++++++++++---------- radio/src/gui/horus/menu_model_inputs.cpp | 2 +- radio/src/gui/horus/menu_model_mixes.cpp | 2 +- radio/src/gui/horus/menu_model_setup.cpp | 6 +- radio/src/opentx.cpp | 1 + 9 files changed, 110 insertions(+), 46 deletions(-) diff --git a/radio/src/fonts.h b/radio/src/fonts.h index 44f8bbc42..c1ca10f6e 100644 --- a/radio/src/fonts.h +++ b/radio/src/fonts.h @@ -26,6 +26,9 @@ extern const uint16_t * const fontspecsTable[16]; extern const uint8_t * const fontsTable[16]; +extern BitmapBuffer * fontCache[2]; +void loadFontCache(); + #else extern const pm_uchar font_5x7[]; diff --git a/radio/src/gui/horus/bitmapbuffer.cpp b/radio/src/gui/horus/bitmapbuffer.cpp index a35c0504f..93c9764d5 100644 --- a/radio/src/gui/horus/bitmapbuffer.cpp +++ b/radio/src/gui/horus/bitmapbuffer.cpp @@ -247,8 +247,7 @@ void BitmapBuffer::drawBitmapPattern(coord_t x, coord_t y, const uint8_t * bmp, } } -#define FONT_MAX_HEIGHT 42 -void BitmapBuffer::drawFontPattern(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags) +void BitmapBuffer::drawCharWithoutCache(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags) { coord_t offset = spec[index]; coord_t width = spec[index+1] - offset; @@ -256,6 +255,14 @@ void BitmapBuffer::drawFontPattern(coord_t x, coord_t y, const uint8_t * font, c lcdNextPos = x + width; } +void BitmapBuffer::drawCharWithCache(coord_t x, coord_t y, const BitmapBuffer * font, const uint16_t * spec, int index, LcdFlags flags) +{ + coord_t offset = spec[index]; + coord_t width = spec[index+1] - offset; + drawBitmap(x, y, font, offset, 0, width); + lcdNextPos = x + width; +} + void BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlags flags) { int width = getTextWidth(s, len, flags); @@ -263,6 +270,7 @@ void BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_t l int fontindex = FONTSIZE(flags) >> 8; const pm_uchar * font = fontsTable[fontindex]; const uint16_t * fontspecs = fontspecsTable[fontindex]; + BitmapBuffer * fontcache = NULL; if (flags & RIGHT) x -= width; @@ -271,12 +279,32 @@ void BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_t l if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) { flags = TEXT_INVERTED_COLOR | (flags & 0x0ffff); - if (FONTSIZE(flags) == TINSIZE) + if (fontindex == TINSIZE_INDEX) { drawSolidFilledRect(x-INVERT_HORZ_MARGIN+2, y-INVERT_VERT_MARGIN+2, width+2*INVERT_HORZ_MARGIN-5, INVERT_LINE_HEIGHT-7, TEXT_INVERTED_BGCOLOR); - else if (FONTSIZE(flags) == SMLSIZE) + } + else if (fontindex == SMLSIZE_INDEX) { drawSolidFilledRect(x-INVERT_HORZ_MARGIN, y+1, width+2*INVERT_HORZ_MARGIN-2, INVERT_LINE_HEIGHT-5, TEXT_INVERTED_BGCOLOR); - else - drawSolidFilledRect(x-INVERT_HORZ_MARGIN, y, width+2*INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); + } + else if (fontindex == STDSIZE_INDEX) { + drawSolidFilledRect(x-INVERT_HORZ_MARGIN, y, INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); + drawSolidFilledRect(x+width, y, INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); + fontcache = fontCache[1]; + } + } + else if (!(flags & NO_FONTCACHE)) { + if (fontindex == STDSIZE_INDEX) { + uint16_t fgColor = lcdColorTable[COLOR_IDX(flags)]; + uint16_t bgColor = *getPixelPtr(x, y); + if (fgColor == lcdColorTable[TEXT_COLOR_INDEX] && bgColor == lcdColorTable[TEXT_BGCOLOR_INDEX]) { + fontcache = fontCache[0]; + } + else if (fgColor == lcdColorTable[TEXT_INVERTED_COLOR_INDEX] && bgColor == lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX]) { + fontcache = fontCache[1]; + } + else { + // TRACE("No cache for \"%s\"", s); + } + } } const coord_t orig_x = x; @@ -295,7 +323,12 @@ void BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_t l break; } else if (c >= 0x20) { - drawFontPattern(x, y, font, fontspecs, getMappedChar(c), flags); + if (fontcache) { + drawCharWithCache(x, y, fontcache, fontspecs, getMappedChar(c), flags); + } + else { + drawCharWithoutCache(x, y, font, fontspecs, getMappedChar(c), flags); + } x = lcdNextPos; } else if (c == 0x1F) { // X-coord prefix diff --git a/radio/src/gui/horus/bitmapbuffer.h b/radio/src/gui/horus/bitmapbuffer.h index 913d39e28..2dc6a350e 100644 --- a/radio/src/gui/horus/bitmapbuffer.h +++ b/radio/src/gui/horus/bitmapbuffer.h @@ -176,7 +176,9 @@ class BitmapBuffer: public BitmapBufferBase void drawBitmapPattern(coord_t x, coord_t y, const uint8_t * bmp, LcdFlags flags, coord_t offset=0, coord_t width=0); - void drawFontPattern(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags); + void drawCharWithoutCache(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags); + + void drawCharWithCache(coord_t x, coord_t y, const BitmapBuffer * font, const uint16_t * spec, int index, LcdFlags flags); void drawText(coord_t x, coord_t y, const char * s, LcdFlags flags) { diff --git a/radio/src/gui/horus/fonts.cpp b/radio/src/gui/horus/fonts.cpp index 14f1801bd..7e68afd22 100644 --- a/radio/src/gui/horus/fonts.cpp +++ b/radio/src/gui/horus/fonts.cpp @@ -78,3 +78,23 @@ pm_uchar font_stdsizebold[] = { const uint16_t * const fontspecsTable[16] = { font_stdsize_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsizebold_specs }; const uint8_t * const fontsTable[16] = { font_stdsize, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsizebold }; + +BitmapBuffer * fontCache[2]; + +BitmapBuffer * createFontCache(const uint8_t * font, LcdFlags fg, LcdFlags bg) +{ + coord_t width = *((uint16_t *)font); + coord_t height = *(((uint16_t *)font)+1); + + BitmapBuffer * buffer = new BitmapBuffer(BMP_RGB565, width, height); + buffer->clear(bg); + buffer->drawBitmapPattern(0, 0, font, fg); + + return buffer; +} + +void loadFontCache() +{ + fontCache[0] = createFontCache(fontsTable[0], TEXT_COLOR, TEXT_BGCOLOR); + fontCache[1] = createFontCache(fontsTable[0], TEXT_INVERTED_COLOR, TEXT_INVERTED_BGCOLOR); +} diff --git a/radio/src/gui/horus/lcd.h b/radio/src/gui/horus/lcd.h index d90382835..b97775e93 100644 --- a/radio/src/gui/horus/lcd.h +++ b/radio/src/gui/horus/lcd.h @@ -24,58 +24,67 @@ #include "bitmapbuffer.h" #if defined(PCBHORUS) - #define LCD_W 480 - #define LCD_H 272 - #define LCD_COLS 30 + #define LCD_W 480 + #define LCD_H 272 + #define LCD_COLS 30 #else - #define LCD_W 800 - #define LCD_H 480 - #define LCD_COLS 40 + #define LCD_W 800 + #define LCD_H 480 + #define LCD_COLS 40 #endif #define CENTER -#define lcdint_t int32_t +#define lcdint_t int32_t -#define BSS 0x00 +#define BSS 0x00 /* lcd common flags */ -#define BLINK 0x01 +#define BLINK 0x01 /* drawText flags */ -#define INVERS 0x02 -#define LEFT 0x00 -#define CENTERED 0x04 /* align left */ -#define RIGHT 0x08 /* align left */ +#define INVERS 0x02 +#define LEFT 0x00 +#define CENTERED 0x04 /* align left */ +#define RIGHT 0x08 /* align left */ /* drawNumber flags */ -#define LEADING0 0x10 -#define PREC1 0x20 -#define PREC2 0x30 -#define MODE(flags) ((((int8_t)(flags) & 0x30) - 0x10) >> 4) +#define LEADING0 0x10 +#define PREC1 0x20 +#define PREC2 0x30 +#define MODE(flags) ((((int8_t)(flags) & 0x30) - 0x10) >> 4) -#define ZCHAR 0x10 +#define ZCHAR 0x10 /* rect, square flags */ -#define ROUND 0x04 +#define ROUND 0x04 /* telemetry flags */ -#define NO_UNIT 0x40 +#define NO_UNIT 0x40 -#define FONTSIZE(x) ((x) & 0x0700) -#define TINSIZE 0x0100 -#define SMLSIZE 0x0200 -#define MIDSIZE 0x0300 -#define DBLSIZE 0x0400 -#define XXLSIZE 0x0500 -#define BOLD 0x0600 -#define VERTICAL 0x0800 +enum FontSizeIndex { + STDSIZE_INDEX, + TINSIZE_INDEX, + SMLSIZE_INDEX, + MIDSIZE_INDEX, + DBLSIZE_INDEX, + XXLSIZE_INDEX +}; -#define TIMEBLINK 0x1000 -#define TIMEHOUR 0x2000 -#define STREXPANDED 0x4000 +#define FONTSIZE(x) ((x) & 0x0700) +#define TINSIZE (TINSIZE_INDEX << 8) +#define SMLSIZE (SMLSIZE_INDEX << 8) +#define MIDSIZE (MIDSIZE_INDEX << 8) +#define DBLSIZE (DBLSIZE_INDEX << 8) +#define XXLSIZE (XXLSIZE_INDEX << 8) +#define BOLD 0x0600 +#define VERTICAL 0x0800 +#define TIMEBLINK 0x1000 +#define TIMEHOUR 0x2000 +#define NO_FONTCACHE 0x8000 #include "colors.h" + #define DISPLAY_PIXELS_COUNT (LCD_W*LCD_H) #define DISPLAY_BUFFER_SIZE (sizeof(display_t)*DISPLAY_PIXELS_COUNT) diff --git a/radio/src/gui/horus/menu_model_inputs.cpp b/radio/src/gui/horus/menu_model_inputs.cpp index 58458fb93..45dcb4f56 100644 --- a/radio/src/gui/horus/menu_model_inputs.cpp +++ b/radio/src/gui/horus/menu_model_inputs.cpp @@ -233,7 +233,7 @@ bool menuModelExpoOne(evt_t event) case EXPO_FIELD_SOURCE: lcdDrawText(MENUS_MARGIN_LEFT, y, NO_INDENT(STR_SOURCE)); - putsMixerSource(EXPO_ONE_2ND_COLUMN, y, ed->srcRaw, STREXPANDED|(menuHorizontalPosition==0?attr:0)); + putsMixerSource(EXPO_ONE_2ND_COLUMN, y, ed->srcRaw, menuHorizontalPosition==0 ? attr : 0); if (attr && menuHorizontalPosition==0) ed->srcRaw = checkIncDec(event, ed->srcRaw, INPUTSRC_FIRST, INPUTSRC_LAST, EE_MODEL|INCDEC_SOURCE|NO_INCDEC_MARKS, isInputSourceAvailable); if (ed->srcRaw >= MIXSRC_FIRST_TELEM) { putsTelemetryChannelValue(EXPO_ONE_2ND_COLUMN+60, y, (ed->srcRaw - MIXSRC_FIRST_TELEM)/3, convertTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1, ed->scale), LEFT|(menuHorizontalPosition==1?attr:0)); diff --git a/radio/src/gui/horus/menu_model_mixes.cpp b/radio/src/gui/horus/menu_model_mixes.cpp index fb2cfe776..d3801282f 100644 --- a/radio/src/gui/horus/menu_model_mixes.cpp +++ b/radio/src/gui/horus/menu_model_mixes.cpp @@ -201,7 +201,7 @@ bool menuModelMixOne(evt_t event) break; case MIX_FIELD_SOURCE: lcdDrawText(MENUS_MARGIN_LEFT, y, NO_INDENT(STR_SOURCE)); - putsMixerSource(MIXES_2ND_COLUMN, y, md2->srcRaw, STREXPANDED|attr); + putsMixerSource(MIXES_2ND_COLUMN, y, md2->srcRaw, attr); if (attr) CHECK_INCDEC_MODELSOURCE(event, md2->srcRaw, 1, MIXSRC_LAST); break; case MIX_FIELD_WEIGHT: diff --git a/radio/src/gui/horus/menu_model_setup.cpp b/radio/src/gui/horus/menu_model_setup.cpp index f5b5b64f0..1948b6962 100644 --- a/radio/src/gui/horus/menu_model_setup.cpp +++ b/radio/src/gui/horus/menu_model_setup.cpp @@ -105,7 +105,7 @@ void editTimerMode(int timerIdx, coord_t y, LcdFlags attr, evt_t event) } drawStringWithIndex(MENUS_MARGIN_LEFT, y, STR_TIMER, timerIdx+1); putsTimerMode(MODEL_SETUP_2ND_COLUMN, y, timer->mode, (menuHorizontalPosition<=0 ? attr : 0)); - putsTimer(MODEL_SETUP_2ND_COLUMN+50, y, timer->start, (menuHorizontalPosition==1 ? attr|TIMEHOUR : TIMEHOUR)); + putsTimer(MODEL_SETUP_2ND_COLUMN+50, y, timer->start, (menuHorizontalPosition!=0 ? attr|TIMEHOUR : TIMEHOUR)); if (attr && s_editMode>0) { switch (menuHorizontalPosition) { case 0: @@ -203,14 +203,10 @@ bool menuModelSetup(evt_t event) IF_EXTERNAL_MODULE_XJT(FAILSAFE_ROWS(EXTERNAL_MODULE)), LABEL(Trainer), 0, TRAINER_CHANNELS_ROWS(), IF_TRAINER_ON(2) }); -#if (defined(DSM2) || defined(PXX)) if (menuEvent) { moduleFlag[0] = 0; -#if NUM_MODULES > 1 moduleFlag[1] = 0; -#endif } -#endif int sub = menuVerticalPosition; diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index daf92bd33..10830210d 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2609,6 +2609,7 @@ void opentxInit(OPENTX_INIT_ARGS) #if defined(COLORLCD) loadTheme(); + loadFontCache(); #endif if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on From 664a966bbc97c2bc9e51b62038be2c3a8a7a951e Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 2 Apr 2016 19:32:28 +0200 Subject: [PATCH 02/28] Cosmetics --- radio/src/targets/horus/delays.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/targets/horus/delays.c b/radio/src/targets/horus/delays.c index 3431f9d3e..cc74bc6cc 100644 --- a/radio/src/targets/horus/delays.c +++ b/radio/src/targets/horus/delays.c @@ -18,7 +18,7 @@ * GNU General Public License for more details. */ -#include "../horus/board_horus.h" +#include "board_horus.h" void delaysInit(void) { From b0bda14f23c5beeb09f039890431c845a372fd42 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 2 Apr 2016 20:45:22 +0200 Subject: [PATCH 03/28] [Horus] My last commit did break BOLD --- radio/src/gui/horus/bitmapbuffer.cpp | 13 ++++++++----- radio/src/gui/horus/lcd.h | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/radio/src/gui/horus/bitmapbuffer.cpp b/radio/src/gui/horus/bitmapbuffer.cpp index 93c9764d5..f9084e59d 100644 --- a/radio/src/gui/horus/bitmapbuffer.cpp +++ b/radio/src/gui/horus/bitmapbuffer.cpp @@ -279,16 +279,19 @@ void BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_t l if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) { flags = TEXT_INVERTED_COLOR | (flags & 0x0ffff); - if (fontindex == TINSIZE_INDEX) { + if (fontindex == STDSIZE_INDEX) { + drawSolidFilledRect(x-INVERT_HORZ_MARGIN, y, INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); + drawSolidFilledRect(x+width, y, INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); + fontcache = fontCache[1]; + } + else if (fontindex == TINSIZE_INDEX) { drawSolidFilledRect(x-INVERT_HORZ_MARGIN+2, y-INVERT_VERT_MARGIN+2, width+2*INVERT_HORZ_MARGIN-5, INVERT_LINE_HEIGHT-7, TEXT_INVERTED_BGCOLOR); } else if (fontindex == SMLSIZE_INDEX) { drawSolidFilledRect(x-INVERT_HORZ_MARGIN, y+1, width+2*INVERT_HORZ_MARGIN-2, INVERT_LINE_HEIGHT-5, TEXT_INVERTED_BGCOLOR); } - else if (fontindex == STDSIZE_INDEX) { - drawSolidFilledRect(x-INVERT_HORZ_MARGIN, y, INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); - drawSolidFilledRect(x+width, y, INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); - fontcache = fontCache[1]; + else { + drawSolidFilledRect(x-INVERT_HORZ_MARGIN, y, width+2*INVERT_HORZ_MARGIN, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR); } } else if (!(flags & NO_FONTCACHE)) { diff --git a/radio/src/gui/horus/lcd.h b/radio/src/gui/horus/lcd.h index b97775e93..d98a495e7 100644 --- a/radio/src/gui/horus/lcd.h +++ b/radio/src/gui/horus/lcd.h @@ -68,7 +68,8 @@ enum FontSizeIndex { SMLSIZE_INDEX, MIDSIZE_INDEX, DBLSIZE_INDEX, - XXLSIZE_INDEX + XXLSIZE_INDEX, + BOLDSTDSIZE_INDEX, }; #define FONTSIZE(x) ((x) & 0x0700) @@ -77,7 +78,8 @@ enum FontSizeIndex { #define MIDSIZE (MIDSIZE_INDEX << 8) #define DBLSIZE (DBLSIZE_INDEX << 8) #define XXLSIZE (XXLSIZE_INDEX << 8) -#define BOLD 0x0600 +#define BOLD (BOLDSTDSIZE_INDEX << 8) + #define VERTICAL 0x0800 #define TIMEBLINK 0x1000 #define TIMEHOUR 0x2000 From a0b4053e82b9e716c2f57e24547b8e151ab73a11 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 2 Apr 2016 21:05:22 +0200 Subject: [PATCH 04/28] [Crossfire] Now the pulses frame is encoded the same way than other Crossfire frames --- radio/src/pulses/crossfire.cpp | 10 +++++----- radio/src/pulses/pulses_arm.h | 2 +- radio/src/telemetry/crossfire.h | 5 ++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/radio/src/pulses/crossfire.cpp b/radio/src/pulses/crossfire.cpp index 3acce4a3c..a10763cf9 100644 --- a/radio/src/pulses/crossfire.cpp +++ b/radio/src/pulses/crossfire.cpp @@ -18,9 +18,8 @@ * GNU General Public License for more details. */ -#include "../opentx.h" +#include "opentx.h" -#define CROSSFIRE_START_BYTE 0x0F #define CROSSFIRE_CH_CENTER 0x3E0 #define CROSSFIRE_CH_BITS 11 @@ -28,7 +27,9 @@ void createCrossfireFrame(uint8_t * frame, int16_t * pulses) { uint8_t * buf = frame; - *buf++ = CROSSFIRE_START_BYTE; + *buf++ = BROADCAST_ADDRESS; + *buf++ = 24; // 1(ID) + 22 + 1(CRC) + *buf++ = CHANNELS_ID; uint32_t bits = 0; uint8_t bitsavailable = 0; @@ -41,6 +42,5 @@ void createCrossfireFrame(uint8_t * frame, int16_t * pulses) bitsavailable -= 8; } } - *buf++ = 0; - *buf++ = crc16(frame, 24); + *buf = crc8(&frame[2], 24); } diff --git a/radio/src/pulses/pulses_arm.h b/radio/src/pulses/pulses_arm.h index eb4f35289..969816142 100644 --- a/radio/src/pulses/pulses_arm.h +++ b/radio/src/pulses/pulses_arm.h @@ -69,7 +69,7 @@ PACK(struct Dsm2PulsesData { #endif #define CROSSFIRE_BAUDRATE 400000 -#define CROSSFIRE_FRAME_LEN 25 +#define CROSSFIRE_FRAME_LEN (3+22+1) #define CROSSFIRE_CHANNELS_COUNT 16 PACK(struct CrossfirePulsesData { uint8_t pulses[CROSSFIRE_FRAME_LEN]; diff --git a/radio/src/telemetry/crossfire.h b/radio/src/telemetry/crossfire.h index 5fa88a513..37afb7e0b 100644 --- a/radio/src/telemetry/crossfire.h +++ b/radio/src/telemetry/crossfire.h @@ -21,7 +21,10 @@ #ifndef _CROSSFIRE_H_ #define _CROSSFIRE_H_ -#define LINK_STATS_ID 0x14 +#define BROADCAST_ADDRESS 0x00 + +#define LINK_STATS_ID 0x14 +#define CHANNELS_ID 0x16 void processCrossfireTelemetryData(uint8_t data); void crossfireSetDefault(int index, uint8_t id, uint8_t subId); From 9673df83a7f9e3cd6c2faf0f5c85e8fb21227a30 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Sun, 27 Mar 2016 22:40:40 +0200 Subject: [PATCH 05/28] Interrupt counters added (use -DDEBUG_INTERRUPTS=YES to enable and CLI command "print int" to see them) --- radio/src/CMakeLists.txt | 6 +++ radio/src/cli.cpp | 21 ++++++++ radio/src/debug.cpp | 37 +++++++++++++ radio/src/debug.h | 52 +++++++++++++++++++ radio/src/targets/horus/board_horus.cpp | 18 +++---- radio/src/targets/horus/pulses_driver.cpp | 3 ++ radio/src/targets/horus/sdio_sd.c | 42 ++++++++------- radio/src/targets/horus/serial2_driver.cpp | 1 + radio/src/targets/horus/telemetry_driver.cpp | 1 + radio/src/targets/horus/trainer_driver.cpp | 1 + radio/src/targets/horus/usb_driver.c | 2 + radio/src/targets/taranis/audio_driver.cpp | 1 + .../src/targets/taranis/bluetooth_driver.cpp | 1 + radio/src/targets/taranis/board_taranis.cpp | 1 + radio/src/targets/taranis/lcd_driver.cpp | 41 ++++++++------- radio/src/targets/taranis/pulses_driver.cpp | 3 ++ radio/src/targets/taranis/serial2_driver.cpp | 1 + .../src/targets/taranis/telemetry_driver.cpp | 2 + radio/src/targets/taranis/trainer_driver.cpp | 1 + radio/src/targets/taranis/usb_driver.c | 2 + radio/src/thirdparty/CoOS/portable/arch.c | 3 ++ 21 files changed, 188 insertions(+), 52 deletions(-) diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index 7e53ab2c0..dafa3d1f4 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -485,6 +485,8 @@ if(ARCH STREQUAL ARM) option(DEBUG_TRACE_BUFFER "Debug Trace Screen" OFF) option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger/DIY-Multiprotocol-TX-Module)" OFF) option(SUPPORT_D16_EU_ONLY "XJT module only supports D16-EU and LR12-EU" OFF) # TODO rename to XJT_EU_ONLY + option(DEBUG_INTERRUPTS "Count interrupts" OFF) + if(TIMERS EQUAL 3) add_definitions(-DTIMERS=3) else() @@ -511,6 +513,10 @@ if(ARCH STREQUAL ARM) if(DEBUG_TRACE_BUFFER) add_definitions(-DDEBUG_TRACE_BUFFER) endif() + if(DEBUG_INTERRUPTS) + add_definitions(-DDEBUG_INTERRUPTS) + set(DEBUG ON) + endif() if(CLI) add_definitions(-DCLI) set(FIRMWARE_SRC ${FIRMWARE_SRC} cli.cpp) diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index 669ac9634..41fef09ed 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -357,6 +357,22 @@ int cliSet(const char ** argv) return 0; } + +#if defined(DEBUG_INTERRUPTS) +void printInterrupts() +{ + __disable_irq(); + struct InterruptCounters ic = interruptCounters; + memset(&interruptCounters, 0, sizeof(interruptCounters)); + interruptCounters.resetTime = get_tmr10ms(); + __enable_irq(); + serialPrint("Interrupts count in the last %u ms:", (get_tmr10ms() - ic.resetTime) * 10); + for(int n = 0; n < INT_LAST; n++) { + serialPrint("%s: %u", interruptNames[n], ic.cnt[n]); + } +} +#endif //#if defined(DEBUG_INTERRUPTS) + int cliDisplay(const char ** argv) { long long int address = 0; @@ -484,6 +500,11 @@ int cliDisplay(const char ** argv) serialPrint(" CCR4 0x%x", tim->CCR4); } } +#if defined(DEBUG_INTERRUPTS) + else if (!strcmp(argv[1], "int")) { + printInterrupts(); + } +#endif //#if defined(DEBUG_INTERRUPTS) else if (toLongLongInt(argv, 1, &address) > 0) { int size = 256; if (toInt(argv, 2, &size) >= 0) { diff --git a/radio/src/debug.cpp b/radio/src/debug.cpp index e375015bf..ee90a686d 100644 --- a/radio/src/debug.cpp +++ b/radio/src/debug.cpp @@ -102,3 +102,40 @@ void dumpTraceBuffer() TRACE("End of Trace Buffer dump"); } #endif + +#if defined(DEBUG_INTERRUPTS) + +#if defined(PCBHORUS) + const char * interruptNames[INT_LAST] = { + "Tick ", // INT_TICK, + "1ms ", // INT_1MS, + "Ser2 ", // INT_SER2, + "TelDm", // INT_TELEM_DMA, + "Sdio ", // INT_SDIO, + "SdDma", // INT_SDIO_DMA, + "D2S7 ", // INT_DMA2S7, + "Tim1 ", // INT_TIM1CC, + "Tim2 ", // INT_TIM2, + "Tim3 ", // INT_TIM3, + "Usb " // INT_OTG_FS, + }; +#elif defined(PCBTARANIS) + const char * interruptNames[INT_LAST] = { + "Tick ", // INT_TICK, + "5ms ", // INT_5MS, + "Audio", // INT_AUDIO, + "BlueT", // INT_BLUETOOTH, + "Lcd ", // INT_LCD, + "T1CC ", // INT_TIM1CC, + "Tim1 ", // INT_TIM1, + "Tim8 ", // INT_TIM8, + "Ser2 ", // INT_SER2, + "TelDm", // INT_TELEM_DMA, + "TelUs", // INT_TELEM_USART, + "Train", // INT_TRAINER, + "Usb ", // INT_OTG_FS, + }; +#endif + +struct InterruptCounters interruptCounters; +#endif //#if defined(DEBUG_INTERRUPTS) diff --git a/radio/src/debug.h b/radio/src/debug.h index 135e795c3..878960aec 100644 --- a/radio/src/debug.h +++ b/radio/src/debug.h @@ -185,5 +185,57 @@ public: #endif // defined(JITTER_MEASURE) + +#if defined(DEBUG_INTERRUPTS) && !defined(BOOT) + +#if defined(PCBHORUS) +enum InterruptNames { + INT_TICK, + INT_1MS, + INT_SER2, + INT_TELEM_DMA, + INT_SDIO, + INT_SDIO_DMA, + INT_DMA2S7, + INT_TIM1CC, + INT_TIM2, + INT_TIM3, + INT_OTG_FS, + INT_LAST +}; +#elif defined(PCBTARANIS) +enum InterruptNames { + INT_TICK, + INT_5MS, + INT_AUDIO, + INT_BLUETOOTH, + INT_LCD, + INT_TIM1CC, + INT_TIM1, + INT_TIM8, + INT_SER2, + INT_TELEM_DMA, + INT_TELEM_USART, + INT_TRAINER, + INT_OTG_FS, + INT_LAST +}; +#endif + +struct InterruptCounters +{ + uint32_t cnt[INT_LAST]; + uint32_t resetTime; +}; + +extern const char * interruptNames[INT_LAST]; +extern struct InterruptCounters interruptCounters; + +#define DEBUG_INTERRUPT(int) (++interruptCounters.cnt[int]) +#else +#define DEBUG_INTERRUPT(int) +#endif //#if defined(DEBUG_INTERRUPTS) + + #endif // _DEBUG_H_ diff --git a/radio/src/targets/horus/board_horus.cpp b/radio/src/targets/horus/board_horus.cpp index 5cbaf2d12..66ca387a3 100644 --- a/radio/src/targets/horus/board_horus.cpp +++ b/radio/src/targets/horus/board_horus.cpp @@ -58,8 +58,8 @@ void init2MhzTimer() TIMER_2MHz_TIMER->CR1 = TIM_CR1_CEN; } -// Starts TIMER at 200Hz, 5mS period -void init5msTimer() +// Starts TIMER at 1000Hz +void init1msTimer() { INTERRUPT_5MS_TIMER->ARR = 999 ; // 1mS INTERRUPT_5MS_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1 ; // 1uS from 30MHz @@ -72,15 +72,8 @@ void init5msTimer() NVIC_SetPriority(TIM8_TRG_COM_TIM14_IRQn, 7); } -void stop5msTimer( void ) -{ - TIM14->CR1 = 0 ; // stop timer - NVIC_DisableIRQ(TIM8_TRG_COM_TIM14_IRQn) ; - RCC->APB1ENR &= ~RCC_APB1ENR_TIM14EN ; // Disable clock -} - // TODO use the same than board_sky9x.cpp -void interrupt5ms() +void interrupt1ms() { static uint32_t pre_scale ; // Used to get 10 Hz counter @@ -106,7 +99,8 @@ void interrupt5ms() extern "C" void TIM8_TRG_COM_TIM14_IRQHandler() { TIM14->SR &= ~TIM_SR_UIF ; - interrupt5ms() ; + interrupt1ms() ; + DEBUG_INTERRUPT(INT_1MS); } void boardInit() @@ -155,7 +149,7 @@ void boardInit() lcdInit(); audioInit(); init2MhzTimer(); - init5msTimer(); + init1msTimer(); usbInit(); hapticInit(); diff --git a/radio/src/targets/horus/pulses_driver.cpp b/radio/src/targets/horus/pulses_driver.cpp index 3db61e347..129610ed4 100644 --- a/radio/src/targets/horus/pulses_driver.cpp +++ b/radio/src/targets/horus/pulses_driver.cpp @@ -165,6 +165,7 @@ static void intmoduleNoneStop() #if !defined(SIMU) extern "C" void DMA2_Stream7_IRQHandler(void) { + DEBUG_INTERRUPT(INT_DMA2S7); if(DMA_GetITStatus(INTMODULE_DMA_STREAM, DMA_IT_TCIF7)) { // TODO we could send the 8 next channels here (when needed) DMA_ClearITPendingBit(INTMODULE_DMA_STREAM, DMA_IT_TCIF7); @@ -173,6 +174,7 @@ extern "C" void DMA2_Stream7_IRQHandler(void) extern "C" void TIM1_CC_IRQHandler() { + DEBUG_INTERRUPT(INT_TIM1CC); INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // stop this interrupt INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // clear flag @@ -551,6 +553,7 @@ static void extmodulePpmStop() extern "C" void TIM2_IRQHandler() { + DEBUG_INTERRUPT(INT_TIM2); //determine if its CC or UP interrupt uint16_t sr = EXTMODULE_TIMER->SR; uint16_t dier = EXTMODULE_TIMER->DIER; diff --git a/radio/src/targets/horus/sdio_sd.c b/radio/src/targets/horus/sdio_sd.c index ea3fbaedd..7b494848b 100644 --- a/radio/src/targets/horus/sdio_sd.c +++ b/radio/src/targets/horus/sdio_sd.c @@ -1,23 +1,23 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * 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. - */ - +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * 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. + */ + /* Includes ------------------------------------------------------------------*/ #include "../horus/sdio_sd.h" @@ -2776,11 +2776,13 @@ OPTIMIZE("O0") uint8_t convert_from_bytes_to_power_of_two(uint16_t NumberOfBytes void SDIO_IRQHandler(void) { + DEBUG_INTERRUPT(INT_SDIO); SD_ProcessIRQ(); } void SD_SDIO_DMA_IRQHANDLER(void) { + DEBUG_INTERRUPT(INT_SDIO_DMA); SD_ProcessDMAIRQ(); } diff --git a/radio/src/targets/horus/serial2_driver.cpp b/radio/src/targets/horus/serial2_driver.cpp index d849d62c0..fae6e56e0 100644 --- a/radio/src/targets/horus/serial2_driver.cpp +++ b/radio/src/targets/horus/serial2_driver.cpp @@ -134,6 +134,7 @@ uint8_t serial2TracesEnabled() #if !defined(SIMU) extern "C" void SERIAL_USART_IRQHandler(void) { + DEBUG_INTERRUPT(INT_SER2); // Send if (USART_GetITStatus(SERIAL_USART, USART_IT_TXE) != RESET) { uint8_t txchar; diff --git a/radio/src/targets/horus/telemetry_driver.cpp b/radio/src/targets/horus/telemetry_driver.cpp index 20d33883c..2a749c519 100644 --- a/radio/src/targets/horus/telemetry_driver.cpp +++ b/radio/src/targets/horus/telemetry_driver.cpp @@ -136,6 +136,7 @@ void sportSendBuffer(uint8_t * buffer, uint32_t count) extern "C" void TELEMETRY_DMA_TX_IRQHandler(void) { + DEBUG_INTERRUPT(INT_TELEM_DMA); if (DMA_GetITStatus(TELEMETRY_DMA_Stream_TX, TELEMETRY_DMA_TX_FLAG_TC)) { DMA_ClearITPendingBit(TELEMETRY_DMA_Stream_TX, TELEMETRY_DMA_TX_FLAG_TC); telemetryPortSetDirectionInput(); diff --git a/radio/src/targets/horus/trainer_driver.cpp b/radio/src/targets/horus/trainer_driver.cpp index f78c50d54..9c2225eab 100644 --- a/radio/src/targets/horus/trainer_driver.cpp +++ b/radio/src/targets/horus/trainer_driver.cpp @@ -103,6 +103,7 @@ void stop_trainer_capture() #if !defined(SIMU) extern "C" void TIM3_IRQHandler() { + DEBUG_INTERRUPT(INT_TIM3); uint16_t capture = 0; bool doCapture = false; diff --git a/radio/src/targets/horus/usb_driver.c b/radio/src/targets/horus/usb_driver.c index 92905ecf9..3232ae6bb 100644 --- a/radio/src/targets/horus/usb_driver.c +++ b/radio/src/targets/horus/usb_driver.c @@ -20,6 +20,7 @@ #include "board_horus.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" +#include "debug.h" int usbPlugged(void) { @@ -46,6 +47,7 @@ USB_OTG_CORE_HANDLE USB_OTG_dev; void OTG_FS_IRQHandler(void) { + DEBUG_INTERRUPT(INT_OTG_FS); USBD_OTG_ISR_Handler(&USB_OTG_dev); } diff --git a/radio/src/targets/taranis/audio_driver.cpp b/radio/src/targets/taranis/audio_driver.cpp index 834450941..c1bd4a3ec 100644 --- a/radio/src/targets/taranis/audio_driver.cpp +++ b/radio/src/targets/taranis/audio_driver.cpp @@ -120,6 +120,7 @@ void audioEnd() extern "C" void AUDIO_TIM_IRQHandler() { + DEBUG_INTERRUPT(INT_AUDIO); DAC->CR &= ~DAC_CR_DMAEN1 ; // Stop DMA requests #if !defined(REV9E) DAC->CR &= ~DAC_CR_DMAUDRIE1 ; // Stop underrun interrupt diff --git a/radio/src/targets/taranis/bluetooth_driver.cpp b/radio/src/targets/taranis/bluetooth_driver.cpp index 573225e29..49f9a4993 100644 --- a/radio/src/targets/taranis/bluetooth_driver.cpp +++ b/radio/src/targets/taranis/bluetooth_driver.cpp @@ -104,6 +104,7 @@ void bluetoothDone() extern "C" void USART6_IRQHandler(void) { + DEBUG_INTERRUPT(INT_BLUETOOTH); if (USART_GetITStatus(BT_USART, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(BT_USART, USART_IT_RXNE); uint8_t byte = USART_ReceiveData(BT_USART); diff --git a/radio/src/targets/taranis/board_taranis.cpp b/radio/src/targets/taranis/board_taranis.cpp index 9894d1379..088e63eee 100644 --- a/radio/src/targets/taranis/board_taranis.cpp +++ b/radio/src/targets/taranis/board_taranis.cpp @@ -108,6 +108,7 @@ extern "C" void INTERRUPT_5MS_IRQHandler() { INTERRUPT_5MS_TIMER->SR &= ~TIM_SR_UIF ; interrupt5ms() ; + DEBUG_INTERRUPT(INT_5MS); } #if defined(REV9E) diff --git a/radio/src/targets/taranis/lcd_driver.cpp b/radio/src/targets/taranis/lcd_driver.cpp index 5c31a5178..8e3fdf4d3 100644 --- a/radio/src/targets/taranis/lcd_driver.cpp +++ b/radio/src/targets/taranis/lcd_driver.cpp @@ -1,23 +1,23 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * 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. - */ - +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * 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. + */ + #include "../../opentx.h" #define WriteData(x) AspiData(x) @@ -199,6 +199,7 @@ void lcdRefresh(bool wait) extern "C" void DMA1_Stream7_IRQHandler() { + DEBUG_INTERRUPT(INT_LCD); //clear interrupt flag DMA1_Stream7->CR &= ~DMA_SxCR_TCIE ; // Stop interrupt DMA1->HIFCR |= DMA_HIFCR_CTCIF7; // Clear interrupt flag diff --git a/radio/src/targets/taranis/pulses_driver.cpp b/radio/src/targets/taranis/pulses_driver.cpp index c646a61d5..9aae3e98d 100644 --- a/radio/src/targets/taranis/pulses_driver.cpp +++ b/radio/src/targets/taranis/pulses_driver.cpp @@ -375,6 +375,7 @@ static void intmodulePpmStop() #if !defined(SIMU) extern "C" void TIM1_CC_IRQHandler() { + DEBUG_INTERRUPT(INT_TIM1CC); INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // stop this interrupt INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // clear flag DMA2_Stream6->CR &= ~DMA_SxCR_EN; // disable DMA, it will have the whole of the execution time of setupPulses() to actually stop @@ -402,6 +403,7 @@ extern "C" void TIM1_CC_IRQHandler() extern "C" void TIM1_UP_TIM10_IRQHandler() { + DEBUG_INTERRUPT(INT_TIM1); INTMODULE_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag INTMODULE_TIMER->ARR = *modulePulsesData[INTERNAL_MODULE].ppm.ptr++ ; @@ -612,6 +614,7 @@ extern "C" void TIM8_CC_IRQHandler() extern "C" void TIM8_UP_TIM13_IRQHandler() { + DEBUG_INTERRUPT(INT_TIM8); EXTMODULE_TIMER->SR &= ~TIM_SR_UIF ; // Clear flag EXTMODULE_TIMER->ARR = *modulePulsesData[EXTERNAL_MODULE].ppm.ptr++ ; diff --git a/radio/src/targets/taranis/serial2_driver.cpp b/radio/src/targets/taranis/serial2_driver.cpp index 83d4afafc..44514979a 100644 --- a/radio/src/targets/taranis/serial2_driver.cpp +++ b/radio/src/targets/taranis/serial2_driver.cpp @@ -138,6 +138,7 @@ uint8_t serial2TracesEnabled() #if !defined(SIMU) extern "C" void SERIAL_USART_IRQHandler(void) { + DEBUG_INTERRUPT(INT_SER2); // Send if (USART_GetITStatus(SERIAL_USART, USART_IT_TXE) != RESET) { uint8_t txchar; diff --git a/radio/src/targets/taranis/telemetry_driver.cpp b/radio/src/targets/taranis/telemetry_driver.cpp index d1a4dca3d..7ee4fb5bd 100644 --- a/radio/src/targets/taranis/telemetry_driver.cpp +++ b/radio/src/targets/taranis/telemetry_driver.cpp @@ -114,6 +114,7 @@ void sportSendBuffer(uint8_t * buffer, uint32_t count) extern "C" void TELEMETRY_DMA_TX_IRQHandler(void) { + DEBUG_INTERRUPT(INT_TELEM_DMA); if (DMA_GetITStatus(TELEMETRY_DMA_Stream_TX, TELEMETRY_DMA_TX_FLAG_TC)) { DMA_ClearITPendingBit(TELEMETRY_DMA_Stream_TX, TELEMETRY_DMA_TX_FLAG_TC); telemetryPortSetDirectionInput(); @@ -123,6 +124,7 @@ extern "C" void TELEMETRY_DMA_TX_IRQHandler(void) #define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE) extern "C" void TELEMETRY_USART_IRQHandler(void) { + DEBUG_INTERRUPT(INT_TELEM_USART); uint32_t status = TELEMETRY_USART->SR; while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) { uint8_t data = TELEMETRY_USART->DR; diff --git a/radio/src/targets/taranis/trainer_driver.cpp b/radio/src/targets/taranis/trainer_driver.cpp index 8fe4d7e8b..125c7156d 100644 --- a/radio/src/targets/taranis/trainer_driver.cpp +++ b/radio/src/targets/taranis/trainer_driver.cpp @@ -103,6 +103,7 @@ void stop_trainer_capture() #if !defined(SIMU) extern "C" void TIM3_IRQHandler() { + DEBUG_INTERRUPT(INT_TRAINER); uint16_t capture = 0; bool doCapture = false; diff --git a/radio/src/targets/taranis/usb_driver.c b/radio/src/targets/taranis/usb_driver.c index be936686a..e6dcc4ad2 100644 --- a/radio/src/targets/taranis/usb_driver.c +++ b/radio/src/targets/taranis/usb_driver.c @@ -20,6 +20,7 @@ #include "board_taranis.h" #include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" +#include "debug.h" int usbPlugged(void) { @@ -46,6 +47,7 @@ USB_OTG_CORE_HANDLE USB_OTG_dev; void OTG_FS_IRQHandler(void) { + DEBUG_INTERRUPT(INT_OTG_FS); USBD_OTG_ISR_Handler(&USB_OTG_dev); } diff --git a/radio/src/thirdparty/CoOS/portable/arch.c b/radio/src/thirdparty/CoOS/portable/arch.c index 9ea864356..30a970230 100644 --- a/radio/src/thirdparty/CoOS/portable/arch.c +++ b/radio/src/thirdparty/CoOS/portable/arch.c @@ -37,6 +37,8 @@ /*---------------------------- Include ---------------------------------------*/ #include +#include "debug.h" + U64 OSTickCnt = 0; /*!< Current system tick counter */ /** @@ -90,6 +92,7 @@ OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk) */ void SysTick_Handler(void) { + DEBUG_INTERRUPT(INT_TICK); OSSchedLock++; /* Lock scheduler. */ OSTickCnt++; /* Increment systerm time. */ #if CFG_TASK_WAITTING_EN >0 From a8aa6148e53dc9f7b0214b35723c7433e21a0881 Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Mon, 28 Mar 2016 12:48:25 +0200 Subject: [PATCH 06/28] Tasks switching log added (use -DDEBUG_TASKS=YES to enable and CLI command "print tsl" to see it, only works on Horus) --- radio/src/CMakeLists.txt | 5 +++ radio/src/cli.cpp | 59 +++++++++++++++++++++++++ radio/src/cli.h | 1 + radio/src/debug.cpp | 26 +++++++++++ radio/src/debug.h | 19 ++++++++ radio/src/tasks_arm.h | 5 +++ radio/src/thirdparty/CoOS/kernel/task.c | 8 +++- 7 files changed, 122 insertions(+), 1 deletion(-) diff --git a/radio/src/CMakeLists.txt b/radio/src/CMakeLists.txt index dafa3d1f4..d715286bd 100644 --- a/radio/src/CMakeLists.txt +++ b/radio/src/CMakeLists.txt @@ -486,6 +486,7 @@ if(ARCH STREQUAL ARM) option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger/DIY-Multiprotocol-TX-Module)" OFF) option(SUPPORT_D16_EU_ONLY "XJT module only supports D16-EU and LR12-EU" OFF) # TODO rename to XJT_EU_ONLY option(DEBUG_INTERRUPTS "Count interrupts" OFF) + option(DEBUG_TASKS "Task switching statistics" OFF) if(TIMERS EQUAL 3) add_definitions(-DTIMERS=3) @@ -517,6 +518,10 @@ if(ARCH STREQUAL ARM) add_definitions(-DDEBUG_INTERRUPTS) set(DEBUG ON) endif() + if(DEBUG_TASKS) + add_definitions(-DDEBUG_TASKS) + set(DEBUG ON) + endif() if(CLI) add_definitions(-DCLI) set(FIRMWARE_SRC ${FIRMWARE_SRC} cli.cpp) diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index 41fef09ed..3bcd12439 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -373,6 +373,60 @@ void printInterrupts() } #endif //#if defined(DEBUG_INTERRUPTS) +#if defined(DEBUG_TASKS) + +void printTaskSwitchLog() +{ + serialPrint("Tasks legend [, ]:"); + for(int n = 0; n <= CFG_MAX_USER_TASKS+1; n++) { + if (0 == n) { + serialPrint("%d: Idle", n); + } + if (cliTaskId == n) { + serialPrint("%d: CLI", n); + } + else if (menusTaskId == n) { + serialPrint("%d: menus", n); + } + else if (mixerTaskId == n) { + serialPrint("%d: mixer", n); + } + else if (audioTaskId == n) { + serialPrint("%d: audio", n); + } +#if defined(BLUETOOTH) + else if (btTaskId == n) { + serialPrint("%d: BT", n); + } +#endif + } + serialCrlf(); + + serialPrint("Tasks switch log at %u [