mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-12 19:10:32 +03:00
PICO: Update pico_trace.[ch] and PICO_trace.mk
This commit is contained in:
parent
ce5c93f6e9
commit
25aaebb168
4 changed files with 106 additions and 17 deletions
|
@ -4,10 +4,9 @@
|
|||
# The top level Makefile adds $(MCU_COMMON_SRC) and $(DEVICE_STDPERIPH_SRC) to SRC collection.
|
||||
#
|
||||
|
||||
# PICO_TRACE = 1
|
||||
DEFAULT_OUTPUT := uf2
|
||||
|
||||
PICO_TRACE = 1
|
||||
|
||||
PICO_LIB_OPTIMISATION := -O2 -fuse-linker-plugin -ffast-math -fmerge-all-constants
|
||||
|
||||
# This file PICO.mk is $(TARGET_PLATFORM_DIR)/mk/$(TARGET_MCU_FAMILY).mk
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
# PICO_trace
|
||||
#
|
||||
# Allow tracing into and out of functions without modifying the source code
|
||||
#
|
||||
# Enable by setting PICO_TRACE variable in make, e.g. by export PICO_TRACE=1; make ...
|
||||
#
|
||||
PICO_WRAPPED_FUNCTIONS = main
|
||||
PICO_WRAPPED_FUNCTIONS += init initEEPROM isEEPROMVersionValid
|
||||
PICO_WRAPPED_FUNCTIONS += init initEEPROM isEEPROMVersionValid resetEEPROM writeUnmodifiedConfigToEEPROM resetConfig pgResetAll
|
||||
PICO_TRACE_LD_FLAGS += $(foreach fn, $(PICO_WRAPPED_FUNCTIONS), -Wl,--wrap=$(fn))
|
||||
PICO_TRACE_SRC += PICO/pico_trace.c
|
||||
|
||||
DEVICE_FLAGS += -DPICO_TRACE
|
||||
|
|
|
@ -1,25 +1,102 @@
|
|||
/*
|
||||
* This file is part of Betaflight.
|
||||
*
|
||||
* Betaflight is free software. You can redistribute this software
|
||||
* and/or modify this software under the terms of the GNU General
|
||||
* Public License as published by the Free Software Foundation,
|
||||
* either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* Betaflight 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this software.
|
||||
*
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pico_trace.h"
|
||||
#include "pico/stdio.h"
|
||||
#include "pico/stdio_uart.h"
|
||||
#include "pico/platform/compiler.h"
|
||||
|
||||
static int depth;
|
||||
|
||||
static const char* prefix[]= {
|
||||
"-- ",
|
||||
"--- ",
|
||||
"---- ",
|
||||
"----- ",
|
||||
"------ ",
|
||||
"------- "
|
||||
};
|
||||
|
||||
static const int plen = sizeof(prefix)/sizeof(prefix[0]);
|
||||
|
||||
void picotrace_prefix(void)
|
||||
{
|
||||
stdio_printf(prefix[depth%plen]);
|
||||
}
|
||||
|
||||
// Wrap main to insert the initialisation code.
|
||||
extern int main(int argc, char * argv[]);
|
||||
extern int REAL_FUNC(main)(int argc, char * argv[]);
|
||||
int WRAPPER_FUNC(main)(int argc, char * argv[])
|
||||
{
|
||||
stdio_init_all();
|
||||
return REAL_FUNC(main)(argc, argv);
|
||||
//stdio_init_all();
|
||||
stdio_uart_init();
|
||||
tprintf("\n=== Betaflight main ===");
|
||||
depth++;
|
||||
int mr = REAL_FUNC(main)(argc, argv);
|
||||
depth--;
|
||||
tprintf("\n=== Betaflight main end ===");
|
||||
return mr;
|
||||
}
|
||||
|
||||
#define TRACEvoidvoid(x) \
|
||||
extern void x(void);\
|
||||
extern void REAL_FUNC(x)(void); \
|
||||
void WRAPPER_FUNC(x)(void)\
|
||||
{\
|
||||
tprintf("*** enter " #x " ***");\
|
||||
REAL_FUNC(x)();\
|
||||
tprintf("*** exit " #x " ***");\
|
||||
extern void x(void); \
|
||||
extern void REAL_FUNC(x)(void); \
|
||||
void WRAPPER_FUNC(x)(void) \
|
||||
{ \
|
||||
tprintf("Enter " #x ""); \
|
||||
depth++;REAL_FUNC(x)();depth--; \
|
||||
tprintf("Exit " #x ""); \
|
||||
}
|
||||
|
||||
#define TRACEboolvoid(x) \
|
||||
extern bool x(void); \
|
||||
extern bool REAL_FUNC(x)(void); \
|
||||
bool WRAPPER_FUNC(x)(void) \
|
||||
{ \
|
||||
tprintf("Enter " #x ""); \
|
||||
depth++; \
|
||||
bool ret__ = REAL_FUNC(x)(); \
|
||||
depth--; \
|
||||
tprintf("Exit " #x ""); \
|
||||
return ret__; \
|
||||
}
|
||||
|
||||
#define TRACEvoidbool(x) \
|
||||
extern void x(bool _); \
|
||||
extern void REAL_FUNC(x)(bool _); \
|
||||
void WRAPPER_FUNC(x)(bool xyz__) \
|
||||
{ \
|
||||
tprintf("Enter " #x " [%d]", xyz__); \
|
||||
depth++; REAL_FUNC(x)(xyz__); depth--; \
|
||||
tprintf("Exit " #x ""); \
|
||||
}
|
||||
|
||||
|
||||
// remember to add to PICO_WRAPPED_FUNCTIONS in PICO_trace.mk
|
||||
TRACEvoidvoid(init)
|
||||
TRACEvoidvoid(initEEPROM)
|
||||
TRACEvoidvoid(isEEPROMVersionValid)
|
||||
TRACEvoidvoid(initEEPROM)
|
||||
TRACEvoidvoid(isEEPROMVersionValid)
|
||||
TRACEvoidvoid(writeUnmodifiedConfigToEEPROM)
|
||||
TRACEboolvoid(resetEEPROM)
|
||||
TRACEvoidvoid(resetConfig)
|
||||
TRACEvoidvoid(pgResetAll)
|
||||
TRACEvoidbool(serialInit)
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#include "pico/stdio.h"
|
||||
#include "pico/platform/compiler.h"
|
||||
#pragma once
|
||||
|
||||
#define tprintf(fmt,...) do {stdio_printf(fmt, ## __VA_ARGS__); stdio_printf("\n"); } while (0)
|
||||
extern void picotrace_prefix(void);
|
||||
|
||||
#define tprintf(fmt,...) do { \
|
||||
picotrace_prefix(); \
|
||||
stdio_printf(fmt, ## __VA_ARGS__); \
|
||||
stdio_printf("\n"); \
|
||||
} while (0)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue