PixelKey
NeoPixel USB Key
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1#ifndef LOG_H
2#define LOG_H
3
4#include <stdint.h>
5#include <stdbool.h>
6
7#include "hal_data.h"
8#include "helper_macros.h"
9
17typedef enum e_diag_signal
18{
19 DIAG_SIGNAL_NONE,
25
26typedef enum e_diag_counter
27{
28 DIAG_COUNTER_USB_READ_ERROR,
29 DIAG_COUNTER_USB_WRITE_ERROR,
30 DIAG_COUNTER_USB_OPERATION_ERROR,
31 DIAG_COUNTER_COUNT
32} diag_counter_t;
33
34typedef enum e_diag_timing
35{
36 DIAG_TIMING_FRAME_TX,
37 DIAG_TIMING_FRAME_BLOCK_TX,
38 DIAG_TIMING_FRAME_BLOCK_BUFFER,
39 DIAG_TIMING_FRAME_RENDER,
40 DIAG_TIMING_COUNT
41} diag_timing_t;
42
43typedef struct st_diag_timing_data
44{
45 uint32_t last;
46 uint32_t min;
47 uint32_t max;
48 uint32_t sum;
49 uint32_t cnt;
50 uint32_t _start;
52
53typedef struct st_diag
54{
55 diag_signal_t signals;
56 uint32_t counters[DIAG_COUNTER_COUNT];
57 diag_timing_data_t timing_data[DIAG_TIMING_COUNT];
58} diag_t;
59
60#if DIAGNOSTICS_ENABLE
61extern diag_t g_diag;
62
63 #define LOG_SIGNAL(signal) do { g_diag.signals |= (signal); } while (0)
64 #define LOG_SIGNAL_CLEAR(signal) do { g_diag.signals &= ~(signal); } while (0)
65 #define LOG_SIGNAL_RESET() do { g_diag.signals = 0; } while (0)
66
67 #define LOG_COUNTER(counter) do { g_diag.counters[(counter)] += 1; } while (0)
68 #define LOG_COUNTER_CLEAR(counter) do { g_diag.counters[(counter)] = 0; } while (0)
69 #define LOG_COUNTER_RESET() do { for (int _i = 0; _i < DIAG_COUNTER_COUNT; _i++) g_diag.counters[_i] = 0; } while (0)
70
71 #define LOG_TIME_START(timer) do { g_diag.timing_data[(timer)]._start = SysTick->VAL; } while (0)
72 #define LOG_TIME(timer) do { \
73 uint32_t _t = SysTick->VAL; \
74 uint32_t _d = (g_diag.timing_data[(timer)]._start - _t) & SysTick_VAL_CURRENT_Msk; \
75 g_diag.timing_data[(timer)]._start = _t; \
76 g_diag.timing_data[(timer)].last = _d; \
77 g_diag.timing_data[(timer)].max = max(g_diag.timing_data[(timer)].max, _d); \
78 g_diag.timing_data[(timer)].min = min(g_diag.timing_data[(timer)].min, _d); \
79 g_diag.timing_data[(timer)].sum += _d; \
80 g_diag.timing_data[(timer)].cnt++; \
81 } while (0)
82 #define LOG_TIME_RESET(timer) do { g_diag.timing_data[(timer)] = (diag_timing_data_t) { ._start = 0, .last = 0, .min = UINT32_MAX, .max = 0, .sum = 0, .cnt = 0 }; } while (0)
83 #define LOG_TIME_RESET_ALL() do { for (int _i = 0; _i < DIAG_TIMING_COUNT; _i++) LOG_TIME_RESET(_i); } while (0)
84#else
85 #define LOG_SIGNAL(signal)
86 #define LOG_SIGNAL_CLEAR(signal)
87 #define LOG_SIGNAL_RESET()
88
89 #define LOG_COUNTER(counter)
90 #define LOG_COUNTER_CLEAR(counter)
91 #define LOG_COUNTER_RESET()
92
93 #define LOG_TIME_START(timer)
94 #define LOG_TIME(timer)
95 #define LOG_TIME_RESET(timer)
96 #define LOG_TIME_RESET_ALL()
97#endif
98
101#endif
#define FLAG32(i)
Create an uint32 flag.
Definition: helper_macros.h:72
diag_signal_t
Diagnostic signals.
Definition: log.h:18
@ DIAG_SIGNAL_USB_ERROR
A USB error occurred.
Definition: log.h:22
@ DIAG_SIGNAL_NPDATA_OVERFLOW
The data transfer function was called before the previous transmission completed.
Definition: log.h:21
@ DIAG_SIGNAL_RENDER_ERROR
A render error occurred.
Definition: log.h:23
@ DIAG_SIGNAL_RENDER_UNDERFLOW
The frame is stale and has not been updated since the last transmission.
Definition: log.h:20
Definition: log.h:54
Definition: log.h:44
uint32_t max
Max timing data.
Definition: log.h:47
uint32_t cnt
Number of entries in the timing data sum.
Definition: log.h:49
uint32_t min
Min timing data.
Definition: log.h:46
uint32_t sum
Total sum of timing data.
Definition: log.h:48
uint32_t _start
Start time for delta.
Definition: log.h:50
uint32_t last
Last timing data.
Definition: log.h:45