px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_dbg_ft.h
1#ifndef __PX_DBG_FT_H__
2#define __PX_DBG_FT_H__
3/* =============================================================================
4 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
5 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
6 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
7 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
8 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
9
10 Copyright (c) 2021 Pieter Conradie <https://piconomix.com>
11
12 License: MIT
13 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
14
15 Title: px_dbg_ft.h : Debug Flow Trace module
16 Author(s): Pieter Conradie
17 Creation Date: 2021-05-31
18
19============================================================================= */
20/**
21 * @ingroup UTILS
22 * @defgroup PX_DBG_FT px_dbg_ft.h : Debug Flow Trace module
23 *
24 * Log flow of a program to a RAM buffer for post mortem inspection.
25 *
26 * File(s):
27 * - utils/inc/px_dbg_ft.h
28 * - utils/inc/px_dbg_ft_cfg_template.h
29 * - utils/src/px_dbg_ft.c
30 *
31 * @{
32 */
33
34/* _____STANDARD INCLUDES____________________________________________________ */
35
36/* _____PROJECT INCLUDES_____________________________________________________ */
37#include "px_defs.h"
38
39// Define PX_DBG_FT for the benefit of Doxygen references
40#ifdef __DOX__
41 /// Set flag to disable (PX_DBG_FT=0) or enable (PX_DBG_FT=1) log output.
42 #define PX_DBG_FT 1
43#endif
44
45// PX_DBG_FT symbol defined in Makefile?
46#if defined(PX_DBG_FT)
47 // Yes. Include project specific configuration. See "px_dbg_ft_cfg_template.h"
48 #include "px_dbg_ft_cfg.h"
49#else
50 // No: Remove all log code.
51 #define PX_DBG_FT 0
52 #define PX_DBG_FT_CFG_BUF_SIZE 16
53 typedef enum
54 {
55 PX_DBG_FT_NAME_NONE = 0,
57#endif
58
59// Check that all project specific options have been specified in "px_dbg_ft_cfg.h"
60#if ( !defined(PX_DBG_FT ) \
61 || !defined(PX_DBG_FT_CFG_BUF_SIZE) )
62#error "One or more options not defined in 'px_dbg_ft_cfg.h'"
63#endif
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68/* _____DEFINITIONS _________________________________________________________ */
69
70/* _____TYPE DEFINITIONS_____________________________________________________ */
71
72/* _____GLOBAL VARIABLES_____________________________________________________ */
73/// Index of next empty position; Placed in .noinit section so that it is not set to zero by C initialization code before it can be inspected
74extern uint8_t px_dbg_ft_buf_index;
75
76/// Buffer for log output; Placed in .noinit section so that it is not set to zero by C initialization code before it can be inspected
78
79/* _____GLOBAL FUNCTION DECLARATIONS_________________________________________ */
80/**
81 * Initialise debug flow trace module.
82 */
83void _px_dbg_ft_init(void);
84
85/**
86 * Internal function to log a name and file line number.
87 *
88 * @param name Custom name value as defined in 'px_dbg_ft_cfg.h'
89 * @param line File line number
90 */
91void _px_dbg_ft_log(const px_dbg_ft_name_t name, uint16_t line);
92
93/**
94 * Internal function to log a name, file line number and parameter.
95 *
96 * @param name Custom name value as defined in 'px_dbg_ft_cfg.h'
97 * @param line File line number
98 * @param param Parameter
99 */
100void _px_dbg_ft_log_param(const px_dbg_ft_name_t name, uint16_t line, uint8_t param);
101
102/**
103 * Report flow trace logged in buffer.
104 */
105void px_dbg_ft_report(void);
106
107/* _____MACROS_______________________________________________________________ */
108// PX_DBG_FT enabled?
109#if PX_DBG_FT
110
111/// Macro to declare a name value once at the top of each C file.
112#define PX_DBG_FT_NAME(name) PX_ATTR_UNUSED static const px_dbg_ft_name_t px_dbg_ft_name = name;
113
114/// Macro to initialise debug flow trace module
115#define PX_DBG_FT_INIT() \
116 do \
117 { \
118 _px_dbg_ft_init(); \
119 } \
120 while(0)
121
122/// Macro to log a name and file line number
123#define PX_DBG_FT_LOG() \
124 do \
125 { \
126 _px_dbg_ft_log(px_dbg_ft_name, (uint16_t)__LINE__); \
127 } \
128 while(0)
129
130/// Macro to log a name and a specified file line number
131#define PX_DBG_FT_LOG_LINE(line) \
132 do \
133 { \
134 _px_dbg_ft_log(px_dbg_ft_name, line); \
135 } \
136 while(0)
137
138/// Macro to log a name, file line number and parameter
139#define PX_DBG_FT_LOG_PARAM(param) \
140 do \
141 { \
142 _px_dbg_ft_log_param(px_dbg_ft_name, (uint16_t)__LINE__, param); \
143 } \
144 while(0)
145
146/// Macro to log a name, specified file line number and parameter
147#define PX_DBG_FT_LOG_LINE_PARAM(line, param) \
148 do \
149 { \
150 _px_dbg_ft_log_param(px_dbg_ft_name, line, param); \
151 } \
152 while(0)
153
154#else
155 // PX_DBG_FT = 0; Remove debug flow trace code
156 #define PX_DBG_FT_NAME(name)
157 #define PX_DBG_FT_INIT()
158 #define PX_DBG_FT_LOG()
159 #define PX_DBG_FT_LOG_LINE(line)
160 #define PX_DBG_FT_LOG_PARAM(param)
161 #define PX_DBG_FT_LOG_LINE_PARAM(line, param)
162#endif
163
164#ifdef __cplusplus
165}
166#endif
167
168/// @}
169#endif
void px_dbg_ft_report(void)
Report flow trace logged in buffer.
Definition: px_dbg_ft.c:92
void _px_dbg_ft_init(void)
Initialise debug flow trace module.
px_dbg_ft_name_t
Customized name values (must be sequential starting at 0, e.g. 0, 1, 2, 3, ...)
uint8_t px_dbg_ft_buf_index
Index of next empty position; Placed in .noinit section so that it is not set to zero by C initializa...
void _px_dbg_ft_log(const px_dbg_ft_name_t name, uint16_t line)
Internal function to log a name and file line number.
Definition: px_dbg_ft.c:68
uint32_t px_dbg_ft_buf[PX_DBG_FT_CFG_BUF_SIZE]
Buffer for log output; Placed in .noinit section so that it is not set to zero by C initialization co...
#define PX_DBG_FT_CFG_BUF_SIZE
Debug output string buffer size.
void _px_dbg_ft_log_param(const px_dbg_ft_name_t name, uint16_t line, uint8_t param)
Internal function to log a name, file line number and parameter.
Definition: px_dbg_ft.c:80