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.c
1/* =============================================================================
2 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
3 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
4 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
5 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
6 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
7
8 Copyright (c) 2021 Pieter Conradie <https://piconomix.com>
9
10 License: MIT
11 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
12
13 Title: px_dbg_ft.h : Debug Flow Trace module
14 Author(s): Pieter Conradie
15 Creation Date: 2021-05-31
16
17============================================================================= */
18
19/* _____STANDARD INCLUDES____________________________________________________ */
20#include <stdio.h>
21
22/* _____PROJECT INCLUDES_____________________________________________________ */
23#include "px_dbg_ft.h"
24
25/* _____LOCAL DEFINITIONS____________________________________________________ */
26
27/* _____MACROS_______________________________________________________________ */
28
29/* _____GLOBAL VARIABLES_____________________________________________________ */
30/// 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
31PX_ATTR_SECTION(".noinit") uint8_t px_dbg_ft_buf_idx;
32
33/// 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
34PX_ATTR_SECTION(".noinit") uint32_t px_dbg_ft_buf[PX_DBG_FT_CFG_BUF_SIZE];
35
36/* _____LOCAL VARIABLES______________________________________________________ */
37// Name strings defined?
38#ifdef PX_LOG_CFG_NAMES
39// Define array of name strings for each name value
40PX_LOG_CFG_NAMES()
41#endif
42
43/* _____LOCAL FUNCTION DECLARATIONS__________________________________________ */
44
45/* _____LOCAL FUNCTIONS______________________________________________________ */
46#ifdef PX_LOG_CFG_NAMES
47const char * px_dbg_ft_name_val_to_str(px_dbg_ft_name_t name)
48{
49 if(name >= PX_SIZEOF_ARRAY(px_dbg_ft_name_str))
50 {
51 return "";
52 }
53 return px_dbg_ft_name_str[name];
54}
55#endif
56
57/* _____GLOBAL FUNCTIONS_____________________________________________________ */
58void _px_dbg_ft_init(void)
59{
60 px_dbg_ft_buf_idx = 0;
61
62 for(int i = 0; i < PX_DBG_FT_CFG_BUF_SIZE; i++)
63 {
64 px_dbg_ft_buf[i] = 0;
65 }
66}
67
68void _px_dbg_ft_log(const px_dbg_ft_name_t name, uint16_t line)
69{
70 uint32_t ft = (((uint32_t)name) << 16) | ((uint32_t)line);
71
72 px_dbg_ft_buf[px_dbg_ft_buf_idx] = ft;
73
74 if(++px_dbg_ft_buf_idx == PX_DBG_FT_CFG_BUF_SIZE)
75 {
76 px_dbg_ft_buf_idx = 0;
77 }
78}
79
80void _px_dbg_ft_log_param(const px_dbg_ft_name_t name, uint16_t line, uint8_t param)
81{
82 uint32_t ft = (((uint32_t)param) << 24) | (((uint32_t)name) << 16) | ((uint32_t)line);
83
84 px_dbg_ft_buf[px_dbg_ft_buf_idx] = ft;
85
86 if(++px_dbg_ft_buf_idx == PX_DBG_FT_CFG_BUF_SIZE)
87 {
88 px_dbg_ft_buf_idx = 0;
89 }
90}
91
93{
94 uint8_t idx = px_dbg_ft_buf_idx;
95 uint8_t name, param;
96 uint16_t line;
97
98 do
99 {
100 if(idx != 0)
101 {
102 idx--;
103 }
104 else
105 {
106 idx = PX_DBG_FT_CFG_BUF_SIZE - 1;
107 }
108 param = (px_dbg_ft_buf[idx] >> 24) & 0xff;
109 name = (px_dbg_ft_buf[idx] >> 16) & 0xff;
110 line = (px_dbg_ft_buf[idx] >> 0) & 0xffff;
111#ifdef PX_LOG_CFG_NAMES
112 printf("%u %s # %u (%u)\n", name, px_dbg_ft_name_val_to_str(name), line, param);
113#else
114 printf("%u # %u (%u)\n", name, line, param);
115#endif
116 }
117 while(idx != px_dbg_ft_buf_idx);
118}
119
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, ...)
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
#define PX_SIZEOF_ARRAY(array)
Calculate the number of items in an array.
Definition: px_defs.h:293