24 #ifndef VIVICORESERIAL_DEBUG_H
25 #define VIVICORESERIAL_DEBUG_H
31 #if defined(DBG_SERIAL_ENABLED)
32 # define SERIAL_DEBUG0_ENABLED
40 #if defined(DBG_GPIO_ENABLED)
41 # define DebugGPIODirectOut(DBG_GPIO_DDR, DBG_GPIO_BIT) DBG_GPIO_DDR = DBG_GPIO_DDR | (1 << DBG_GPIO_BIT)
42 # define DebugGPIOLow(DBG_GPIO_PORT, DBG_GPIO_BIT) DBG_GPIO_PORT = DBG_GPIO_PORT & ~(1 << DBG_GPIO_BIT)
43 # define DebugGPIOHigh(DBG_GPIO_PORT, DBG_GPIO_BIT) DBG_GPIO_PORT = DBG_GPIO_PORT | (1 << DBG_GPIO_BIT)
44 # define DebugGPIOWrite(DBG_GPIO_PORT, DBG_GPIO_BIT, BIT_VALUE) \
45 (BIT_VALUE ? DebugGPIOHigh(DBG_GPIO_PORT, DBG_GPIO_BIT) : DebugGPIOLow(DBG_GPIO_PORT, DBG_GPIO_BIT))
47 # define DebugGPIODirectOut(DBG_GPIO_DDR, DBG_GPIO_BIT)
48 # define DebugGPIOLow(DBG_GPIO_PORT, DBG_GPIO_BIT)
49 # define DebugGPIOHigh(DBG_GPIO_PORT, DBG_GPIO_BIT)
50 # define DebugGPIOWrite(DBG_GPIO_PORT, DBG_GPIO_BIT, BIT_VALUE)
56 #define HW_SERIAL_BAUD (250000)
57 #if (CORE_COMM_UART_PORT == 0)
58 # define DBG_SERIAL_INSTANCE Serial1
59 #elif (CORE_COMM_UART_PORT == 1)
60 # define DBG_SERIAL_INSTANCE Serial
62 # error Not supported!
66 #if defined(DBG_SERIAL_ENABLED)
67 # define DebugBegin() DBG_SERIAL_INSTANCE.begin(HW_SERIAL_BAUD)
73 #if defined(DBG_SERIAL_ENABLED)
74 # define DebugFlush(...) DBG_SERIAL_INSTANCE.flush()
75 # define DebugStackPointerPrint(...) \
76 DBG_SERIAL_INSTANCE.print("SP:"); \
77 DBG_SERIAL_INSTANCE.print((int)SP, HEX); \
78 DBG_SERIAL_INSTANCE.println()
80 # define DebugFlush(...)
81 # define DebugStackPointerPrint(...)
83 #define DebugPrint(...) \
84 DBG_SERIAL_INSTANCE.print('['); \
85 DBG_SERIAL_INSTANCE.print(millis()); \
86 DBG_SERIAL_INSTANCE.print("] "); \
87 DBG_SERIAL_INSTANCE.print(__PRETTY_FUNCTION__); \
88 DBG_SERIAL_INSTANCE.print(' '); \
89 DBG_SERIAL_INSTANCE.print(__LINE__); \
90 DBG_SERIAL_INSTANCE.print(": "); \
91 DBG_SERIAL_INSTANCE.print(__VA_ARGS__)
92 #define DebugPrintln(...) \
93 DBG_SERIAL_INSTANCE.print('['); \
94 DBG_SERIAL_INSTANCE.print(millis()); \
95 DBG_SERIAL_INSTANCE.print("] "); \
96 DBG_SERIAL_INSTANCE.print(__PRETTY_FUNCTION__); \
97 DBG_SERIAL_INSTANCE.print(' '); \
98 DBG_SERIAL_INSTANCE.print(__LINE__); \
99 DBG_SERIAL_INSTANCE.print(": "); \
100 DBG_SERIAL_INSTANCE.println(__VA_ARGS__)
101 #define DebugPlainPrint(...) DBG_SERIAL_INSTANCE.print(__VA_ARGS__)
102 #define DebugPlainPrintln(...) DBG_SERIAL_INSTANCE.println(__VA_ARGS__)
104 #define Debug1ByteHexPrint(v) \
105 if ((((v) >> 4) & 0x0F) > 9) { \
106 DBG_SERIAL_INSTANCE.print((char)('A' + ((uint8_t)(((v) >> 4) & 0x0F) - 10))); \
108 DBG_SERIAL_INSTANCE.print((uint8_t)(((v) >> 4) & 0x0F)); \
110 if (((v)&0x0F) > 9) { \
111 DBG_SERIAL_INSTANCE.print((char)('A' + ((uint8_t)((v)&0x0F) - 10))); \
113 DBG_SERIAL_INSTANCE.print((uint8_t)((v)&0x0F)); \
116 #define DebugHexPrint(v) Debug1ByteHexPrint(v)
118 #define DebugBinPrint(v) \
120 for (uint32_t _bit = 1UL << ((sizeof(v) * 8) - 1); _bit; _bit >>= 1) { \
121 DBG_SERIAL_INSTANCE.print(v &_bit ? '1' : '0'); \
125 #if defined(SERIAL_DEBUG0_ENABLED)
126 # define DebugPrint0(...) DebugPrint(__VA_ARGS__)
127 # define DebugPrintln0(...) DebugPrintln(__VA_ARGS__)
128 # define DebugPlainPrint0(...) DebugPlainPrint(__VA_ARGS__)
129 # define DebugPlainPrintln0(...) DebugPlainPrintln(__VA_ARGS__)
130 # define DebugHexPrint0(v) DebugHexPrint(v)
131 # define DebugBinPrint0(v) DebugBinPrint(v)
132 # define DebugStringPrint0(str) DebugPlainPrint(F(str))
133 # define DebugStringPrintln0(str) DebugPlainPrintln(F(str))
135 # define DebugPrint0(...)
136 # define DebugPrintln0(...)
137 # define DebugPlainPrint0(...)
138 # define DebugPlainPrintln0(...)
139 # define DebugHexPrint0(v)
140 # define DebugBinPrint0(v)
141 # define DebugStringPrint0(str)
142 # define DebugStringPrintln0(str)
145 #if defined(SERIAL_DEBUG1_ENABLED)
146 # define DebugPrint1(...) DebugPrint(__VA_ARGS__)
147 # define DebugPrintln1(...) DebugPrintln(__VA_ARGS__)
148 # define DebugPlainPrint1(...) DebugPlainPrint(__VA_ARGS__)
149 # define DebugPlainPrintln1(...) DebugPlainPrintln(__VA_ARGS__)
150 # define DebugHexPrint1(v) DebugHexPrint(v)
151 # define DebugBinPrint1(v) DebugBinPrint(v)
152 # define DebugStringPrint1(str) DebugPlainPrint(F(str))
153 # define DebugStringPrintln1(str) DebugPlainPrintln(F(str))
155 # define DebugPrint1(...)
156 # define DebugPrintln1(...)
157 # define DebugPlainPrint1(...)
158 # define DebugPlainPrintln1(...)
159 # define DebugHexPrint1(v)
160 # define DebugBinPrint1(v)
161 # define DebugStringPrint1(str)
162 # define DebugStringPrintln1(str)
165 #if defined(SERIAL_DEBUG2_ENABLED)
166 # define DebugPrint2(...) DebugPrint(__VA_ARGS__)
167 # define DebugPrintln2(...) DebugPrintln(__VA_ARGS__)
168 # define DebugPlainPrint2(...) DebugPlainPrint(__VA_ARGS__)
169 # define DebugPlainPrintln2(...) DebugPlainPrintln(__VA_ARGS__)
170 # define DebugHexPrint2(v) DebugHexPrint(v)
171 # define DebugBinPrint2(v) DebugBinPrint(v)
172 # define DebugStringPrint2(str) DebugPlainPrint(F(str))
173 # define DebugStringPrintln2(str) DebugPlainPrintln(F(str))
175 # define DebugPrint2(...)
176 # define DebugPrintln2(...)
177 # define DebugPlainPrint2(...)
178 # define DebugPlainPrintln2(...)
179 # define DebugHexPrint2(v)
180 # define DebugBinPrint2(v)
181 # define DebugStringPrint2(str)
182 # define DebugStringPrintln2(str)
185 #if defined(SERIAL_DEBUG_CIBO_ENABLED)
186 # define DebugPrintCIBO(str) DebugPlainPrint(F(str))
187 # define DebugPrintCIBOln(str) DebugPlainPrintln(F(str))
188 # define DebugHexPrintCIBO(v) DebugHexPrint(v)
190 # define DebugPrintCIBO(str)
191 # define DebugPrintCIBOln(str)
192 # define DebugHexPrintCIBO(v)
195 #if defined(SERIAL_DEBUG_COBI_ENABLED)
196 # define DebugPrintCOBI(str) DebugPlainPrint(F(str))
197 # define DebugPrintCOBIln(str) DebugPlainPrintln(F(str))
198 # define DebugHexPrintCOBI(v) DebugHexPrint(v)
200 # define DebugPrintCOBI(str)
201 # define DebugPrintCOBIln(str)
202 # define DebugHexPrintCOBI(v)