1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 01:05:10 +03:00

Interrupt counters added (use -DDEBUG_INTERRUPTS=YES to enable and CLI command "print int" to see them)

This commit is contained in:
Damjan Adamic 2016-03-27 22:40:40 +02:00
parent a0b4053e82
commit 9673df83a7
21 changed files with 188 additions and 52 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -37,6 +37,8 @@
/*---------------------------- Include ---------------------------------------*/
#include <coocox.h>
#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