#1489: TRACE() output intercepted and shown in Companion (shortcut F6) #1270: simple Trainer Simulator (shortcut F5) #1466: telemetry simulator (shorcut F5)
308 lines
6.8 KiB
C++
308 lines
6.8 KiB
C++
/*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#include "opentx.h"
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
|
|
#if (defined(DEBUG) && defined(CPUARM)) || defined(SIMU)
|
|
|
|
#if defined(SIMU)
|
|
traceCallbackFunc traceCallback = 0;
|
|
#endif
|
|
|
|
#if defined(SIMU)
|
|
#define PRINTF_BUFFER_SIZE 1024
|
|
#else
|
|
#define PRINTF_BUFFER_SIZE 256
|
|
#endif
|
|
|
|
// Outputs a string to the UART
|
|
void debugPuts(const char *format, ...)
|
|
{
|
|
va_list arglist;
|
|
char tmp[PRINTF_BUFFER_SIZE];
|
|
|
|
va_start(arglist, format);
|
|
vsnprintf(tmp, PRINTF_BUFFER_SIZE, format, arglist);
|
|
va_end(arglist);
|
|
|
|
#if defined(SIMU)
|
|
fputs(tmp, stdout);
|
|
fflush(stdout);
|
|
if (traceCallback) {
|
|
traceCallback(tmp);
|
|
}
|
|
#else
|
|
const char *t = tmp;
|
|
while (*t) {
|
|
debugPutc(*t++);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void dump(unsigned char *data, unsigned int size)
|
|
{
|
|
debugPuts("DUMP %d bytes ...\n\r", size);
|
|
unsigned int i = 0, j=0;
|
|
while (i*32+j < size) {
|
|
debugPuts("%.2X ", data[i*32+j]);
|
|
j++;
|
|
if (j==32) {
|
|
i++; j=0;
|
|
debugPuts("\n\r");
|
|
}
|
|
}
|
|
debugPuts("\n\r");
|
|
}
|
|
|
|
|
|
#if !defined(SIMU)
|
|
|
|
uint32_t Mem_address ;
|
|
uint32_t Next_mem_address ;
|
|
uint32_t Memaddmode ;
|
|
Fifo<512> debugRxFifo;
|
|
|
|
void crlf()
|
|
{
|
|
debugPutc( 13 ) ;
|
|
debugPutc( 10 ) ;
|
|
}
|
|
|
|
// Send a single 4 bit value to the RS232 port as a hex digit
|
|
void hex_digit_send( unsigned char c )
|
|
{
|
|
c &= 0x0F ;
|
|
if ( c > 9 )
|
|
{
|
|
c += 7 ;
|
|
}
|
|
c += '0' ;
|
|
debugPutc( c ) ;
|
|
}
|
|
|
|
// Send the 8 bit value to the RS232 port as 2 hex digits
|
|
void p2hex( unsigned char c )
|
|
{
|
|
// asm("swap %c") ;
|
|
hex_digit_send( c >> 4 ) ;
|
|
// asm("swap %c") ;
|
|
hex_digit_send( c ) ;
|
|
}
|
|
|
|
// Send the 16 bit value to the RS232 port as 4 hex digits
|
|
void p4hex( uint16_t value )
|
|
{
|
|
p2hex( value >> 8 ) ;
|
|
p2hex( value ) ;
|
|
}
|
|
|
|
// Send the 32 bit value to the RS232 port as 8 hex digits
|
|
void p8hex( uint32_t value )
|
|
{
|
|
p4hex( value >> 16 ) ;
|
|
p4hex( value ) ;
|
|
}
|
|
|
|
|
|
static void dispw_256( register uint32_t address, register uint32_t lines )
|
|
{
|
|
register uint32_t i ;
|
|
register uint32_t j ;
|
|
address &= 0xFFFFFFFC ;
|
|
for ( i = 0 ; i < lines ; i += 1 )
|
|
{
|
|
p8hex( address ) ;
|
|
for ( j = 0 ; j < 4 ; j += 1 )
|
|
{
|
|
debugPutc(' ') ;
|
|
p8hex( *( (uint32_t *)address ) ) ;
|
|
address += 4 ;
|
|
}
|
|
crlf() ;
|
|
}
|
|
}
|
|
|
|
extern Fifo<512> uart3TxFifo;
|
|
|
|
void debugFlush()
|
|
{
|
|
uart3TxFifo.flush();
|
|
}
|
|
|
|
void debugTask(void* pdata)
|
|
{
|
|
uint8_t rxchar ;
|
|
|
|
TRACE("DEBUG Task started");
|
|
|
|
crlf() ;
|
|
dispw_256( (uint32_t)USART3, 4 ) ;
|
|
|
|
for (;;) {
|
|
|
|
while ( (USART3->SR & USART_SR_RXNE) == 0 )
|
|
CoTickDelay(5); // 10ms
|
|
|
|
rxchar = USART3->DR;
|
|
|
|
if ( Memaddmode )
|
|
{
|
|
if ( ( rxchar >= 'a' ) && ( rxchar <= 'f' ) )
|
|
{
|
|
rxchar -= 0x20; // toupper!
|
|
}
|
|
if ( ( ( rxchar >= '0' ) && ( rxchar <= '9' ) ) || ( ( rxchar >= 'A' ) && ( rxchar <= 'F' ) ) )
|
|
{
|
|
debugPutc( rxchar );
|
|
rxchar -= '0';
|
|
if ( rxchar > 9 )
|
|
{
|
|
rxchar -= 7;
|
|
}
|
|
Mem_address <<= 4;
|
|
Mem_address |= rxchar;
|
|
}
|
|
else if ( rxchar == 13 )
|
|
{
|
|
crlf();
|
|
if ( Mem_address == 0 )
|
|
{
|
|
Mem_address = Next_mem_address;
|
|
}
|
|
dispw_256( Mem_address, 4 );
|
|
Next_mem_address = Mem_address + 64;
|
|
Memaddmode = 0;
|
|
}
|
|
else if ( rxchar == 8 )
|
|
{
|
|
debugPutc( rxchar );
|
|
debugPutc( rxchar );
|
|
debugPutc( rxchar );
|
|
Mem_address >>= 4;
|
|
}
|
|
else if ( rxchar == 27 )
|
|
{
|
|
crlf();
|
|
Memaddmode = 0;
|
|
}
|
|
|
|
}
|
|
|
|
if ( rxchar == '?' )
|
|
{
|
|
Memaddmode = 1;
|
|
Mem_address = 0;
|
|
debugPutc( '>' );
|
|
}
|
|
|
|
if ( rxchar == 'm' )
|
|
{
|
|
crlf();
|
|
p8hex( (uint32_t) &g_model.moduleData[0] );
|
|
debugPutc( ' ' );
|
|
p8hex( (uint32_t) &g_model.moduleData[1] );
|
|
crlf();
|
|
}
|
|
|
|
}
|
|
}
|
|
#endif // #if !defined(SIMU)
|
|
#endif // #if (defined(DEBUG) && defined(CPUARM)) || defined(SIMU)
|
|
|
|
|
|
#if defined(DEBUG_TRACE_BUFFER)
|
|
|
|
static struct TraceElement traceBuffer[TRACE_BUFFER_LEN];
|
|
static uint8_t traceBufferPos;
|
|
extern Fifo<512> uart3TxFifo;
|
|
gtime_t filltm(gtime_t *t, struct gtm *tp);
|
|
|
|
void trace_event(enum TraceEvent event, uint32_t data)
|
|
{
|
|
if (traceBufferPos >= TRACE_BUFFER_LEN) return;
|
|
__disable_irq();
|
|
struct TraceElement * p = &traceBuffer[traceBufferPos++];
|
|
__enable_irq();
|
|
p->time = g_rtcTime;
|
|
p->time_ms = g_ms100;
|
|
p->event = event;
|
|
p->data = data;
|
|
}
|
|
|
|
void trace_event_i(enum TraceEvent event, uint32_t data)
|
|
{
|
|
if (traceBufferPos >= TRACE_BUFFER_LEN) return;
|
|
struct TraceElement * p = &traceBuffer[traceBufferPos++];
|
|
p->time = g_rtcTime;
|
|
p->time_ms = g_ms100;
|
|
p->event = event;
|
|
p->data = data;
|
|
}
|
|
|
|
|
|
const struct TraceElement * getTraceElement(uint16_t idx)
|
|
{
|
|
if (idx < TRACE_BUFFER_LEN) return &traceBuffer[idx];
|
|
return 0;
|
|
}
|
|
|
|
#include "stamp-opentx.h"
|
|
|
|
void dumpTraceBuffer()
|
|
{
|
|
TRACE("Dump of Trace Buffer ("VERS_STR " " DATE_STR " " TIME_STR "):");
|
|
TRACE("# Time Event Data");
|
|
for(int n = 0; n < TRACE_BUFFER_LEN; ++n) {
|
|
struct gtm tp;
|
|
filltm(&traceBuffer[n].time, &tp);
|
|
TRACE_INFO_WP("%02d ", n);
|
|
TRACE_INFO_WP("%4d-%02d-%02d,%02d:%02d:%02d.%02d0", tp.tm_year+1900, tp.tm_mon+1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec, traceBuffer[n].time_ms);
|
|
TRACE(" %03d 0x%08x", traceBuffer[n].event, traceBuffer[n].data);
|
|
if (traceBuffer[n].time == 0 && traceBuffer[n].time_ms == 0) break;
|
|
if ((n % 5) == 0) {
|
|
while (!uart3TxFifo.empty()) {
|
|
CoTickDelay(1);
|
|
}
|
|
}
|
|
}
|
|
TRACE("End of Trace Buffer dump");
|
|
}
|
|
|
|
#endif
|
|
|