Embedded System Design 2 - Project
dbprint.c
Go to the documentation of this file.
1 /***************************************************************************//**
2  * @file dbprint.c
3  * @brief Homebrew println/printf replacement "DeBugPrint".
4  * @details Originally designed for use on the Silicion Labs Happy Gecko EFM32 board (EFM32HG322 -- TQFP48).
5  * @version 6.2
6  * @author Brecht Van Eeckhoudt
7  *
8  * ******************************************************************************
9  *
10  * @section Versions
11  *
12  * Please check https://github.com/Fescron/dbprint to find the latest version of dbprint!
13  *
14  * @li v1.0: "define" used to jump between VCOM or other mode, itoa (<stdlib.h>) used aswell as stdio.h
15  * @li v1.1: Separated printInt method in a separate function for printing "int32_t" and "uint32_t" values.
16  * @li v1.2: Added more options to the initialize method (location selection & boolean if VCOM is used).
17  * @li v2.0: Restructured files to be used in other projects, added a lot more documentation, added "dbAlert" and "dbClear" methods.
18  * @li v2.1: Added interrupt functionality.
19  * @li v2.2: Added parse functions, separated method for printing uint values in a separate one for DEC and HEX notation.
20  * @li v2.3: Updated documentation.
21  * @li v2.4: Fixed notes.
22  * @li v2.5: Separated method for printing int values in a separate one for DEC and HEX notation.
23  * @li v2.6: Stopped using itoa (<stdlib.h>) in all methods.
24  * @li v3.0: Simplified number printing, stopped using separate methods for uint and int values.
25  * @li v3.1: Removed useless if... check.
26  * @li v3.2: Added the ability to print text in a color.
27  * @li v3.3: Added info, warning and critical error printing methods.
28  * @li v3.4: Added printInt(_hex) methods that directly go to a new line.
29  * @li v3.5: Added USART0 IRQ handlers.
30  * @li v3.6: Added the ability to print (u)int values as INFO, WARN or CRIT lines.
31  * @li v3.7: Added separate "_hex" methods for dbinfo/warn/critInt instead of a boolean to select (hexa)decimal notation.
32  * @li v3.8: Added ReadChar-Int-Line methods.
33  * @li v3.9: Added "void" between argument brackets were before nothing was.
34  * @li v4.0: Added more documentation.
35  * @li v4.1: Added color reset before welcome message.
36  * @li v5.0: Made uint-char conversion methods static, moved color functionality to enum,
37  * started moving interrupt functionality to use getters and setters.
38  * @li v5.1: Fixed interrupt functionality with getters and setters.
39  * @li v6.0: Cleaned up interrupt functionality and added some documentation.
40  * (put some code in comments to maybe fix later if ever necessary)
41  * @li v6.1: Made `dbpointer` a local variable (removed `extern`).
42  * Removed `extern` from the documentation.
43  * @li v6.2: Removed `static` before the local variables (not necessary).
44  *
45  * ******************************************************************************
46  *
47  * @todo
48  * **Future improvements:**@n
49  * - Fix `dbSet_TXbuffer` and also add more functionality to print numbers, ...
50  * - Separate back-end <-> MCU specific code
51  *
52  * ******************************************************************************
53  *
54  * @section License
55  *
56  * **Copyright (C) 2019 - Brecht Van Eeckhoudt**
57  *
58  * This program is free software: you can redistribute it and/or modify
59  * it under the terms of the **GNU General Public License** as published by
60  * the Free Software Foundation, either **version 3** of the License, or
61  * (at your option) any later version.
62  *
63  * This program is distributed in the hope that it will be useful,
64  * but WITHOUT ANY WARRANTY; without even the implied warranty of
65  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66  * GNU General Public License for more details.
67  *
68  * *A copy of the GNU General Public License can be found in the `LICENSE`
69  * file along with this source code.*
70  *
71  * @n
72  *
73  * Some methods also use code obtained from examples from [Silicon Labs' GitHub](https://github.com/SiliconLabs/peripheral_examples).
74  * These sections are licensed under the Silabs License Agreement. See the file
75  * "Silabs_License_Agreement.txt" for details. Before using this software for
76  * any purpose, you must agree to the terms of that agreement.
77  *
78  * ******************************************************************************
79  *
80  * @attention
81  * See the file `dbprint_documentation.h` for a lot of useful documentation!
82  *
83  ******************************************************************************/
84 
85 
86 #include "debug_dbprint.h" /* Enable or disable printing to UART for debugging */
87 
88 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
89 
90 
91 #include <stdint.h> /* (u)intXX_t */
92 #include <stdbool.h> /* "bool", "true", "false" */
93 #include "em_cmu.h" /* Clock Management Unit */
94 #include "em_gpio.h" /* General Purpose IO (GPIO) peripheral API */
95 #include "em_usart.h" /* Universal synchr./asynchr. receiver/transmitter (USART/UART) Peripheral API */
96 
97 
98 /* Local definitions */
99 /* Macro definitions that return a character when given a value */
100 #define TO_HEX(i) (i <= 9 ? '0' + i : 'A' - 10 + i) /* "?:" = ternary operator (return ['0' + i] if [i <= 9] = true, ['A' - 10 + i] if false) */
101 #define TO_DEC(i) (i <= 9 ? '0' + i : '?') /* return "?" if out of range */
102 
103 /* ANSI colors */
104 #define COLOR_RED "\x1b[31m"
105 #define COLOR_GREEN "\x1b[32m"
106 #define COLOR_BLUE "\x1b[34m"
107 #define COLOR_CYAN "\x1b[36m"
108 #define COLOR_MAGENTA "\x1b[35m"
109 #define COLOR_YELLOW "\x1b[33m"
110 #define COLOR_RESET "\x1b[0m"
111 
112 
113 /** Local variable to store the settings (pointer). */
114 USART_TypeDef* dbpointer;
115 
116 /* Local variables to store data */
117 /* -> Volatile because it's modified by an interrupt service routine (@RAM) */
118 volatile bool dataReceived = false; /* true if there is a line of data received */
121 
122 
123 /* Local prototypes */
124 static void uint32_to_charHex (char *buf, uint32_t value, bool spacing);
125 static void uint32_to_charDec (char *buf, uint32_t value);
126 static uint32_t charDec_to_uint32 (char *buf);
127 //static uint32_t charHex_to_uint32 (char *buf); // Unused but kept here just in case
128 
129 
130 /**************************************************************************//**
131  * @brief
132  * Initialize USARTx.
133  *
134  * @param[in] pointer
135  * Pointer to USARTx.
136  *
137  * @param[in] location
138  * Location for pin routing.
139  *
140  * @param[in] vcom
141  * @li `true` - Isolation switch enabled by setting `PA9` high so the **Virtual COM port (CDC)** can be used.
142  * @li `false` - Isolation switch disabled on the Happy Gecko board.
143  *
144  * @param[in] interrupts
145  * @li `true` - Enable interrupt functionality.
146  * @li `false` - No interrupt functionality is initialized.
147  *****************************************************************************/
148 void dbprint_INIT (USART_TypeDef* pointer, uint8_t location, bool vcom, bool interrupts)
149 {
150  /* Store the pointer in the global variable */
151  dbpointer = pointer;
152 
153  /*
154  * USART_INITASYNC_DEFAULT:
155  * config.enable = usartEnable // Specifies whether TX and/or RX is enabled when initialization is completed
156  * // (Enable RX/TX when initialization is complete).
157  * config.refFreq = 0 // USART/UART reference clock assumed when configuring baud rate setup
158  * // (0 = Use current configured reference clock for configuring baud rate).
159  * config.baudrate = 115200 // Desired baudrate (115200 bits/s).
160  * config.oversampling = usartOVS16 // Oversampling used (16x oversampling).
161  * config.databits = usartDatabits8 // Number of data bits in frame (8 data bits).
162  * config.parity = usartNoParity // Parity mode to use (no parity).
163  * config.stopbits = usartStopbits1 // Number of stop bits to use (1 stop bit).
164  * config.mvdis = false // Majority Vote Disable for 16x, 8x and 6x oversampling modes (Do not disable majority vote).
165  * config.prsRxEnable = false // Enable USART Rx via PRS (Not USART PRS input mode).
166  * config.prsRxCh = 0 // Select PRS channel for USART Rx. (Only valid if prsRxEnable is true - PRS channel 0).
167  * config.autoCsEnable = false // Auto CS enabling (Auto CS functionality enable/disable switch - disabled).
168  */
169 
170  USART_InitAsync_TypeDef config = USART_INITASYNC_DEFAULT;
171 
172  /* Enable oscillator to GPIO*/
173  CMU_ClockEnable(cmuClock_GPIO, true);
174 
175 
176  /* Enable oscillator to USARTx modules */
177  if (dbpointer == USART0)
178  {
179  CMU_ClockEnable(cmuClock_USART0, true);
180  }
181  else if (dbpointer == USART1)
182  {
183  CMU_ClockEnable(cmuClock_USART1, true);
184  }
185 
186 
187  /* Set PA9 (EFM_BC_EN) high if necessary to enable the isolation switch */
188  if (vcom)
189  {
190  GPIO_PinModeSet(gpioPortA, 9, gpioModePushPull, 1);
191  GPIO_PinOutSet(gpioPortA, 9);
192  }
193 
194 
195  /* Set pin modes for UART TX and RX pins */
196  if (dbpointer == USART0)
197  {
198  switch (location)
199  {
200  case 0:
201  GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 0); /* RX */
202  GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 1); /* TX */
203  break;
204  case 2:
205  GPIO_PinModeSet(gpioPortC, 10, gpioModeInput, 0); /* RX */
206  /* No TX pin in this mode */
207  break;
208  case 3:
209  GPIO_PinModeSet(gpioPortE, 12, gpioModeInput, 0); /* RX */
210  GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 1); /* TX */
211  break;
212  case 4:
213  GPIO_PinModeSet(gpioPortB, 8, gpioModeInput, 0); /* RX */
214  GPIO_PinModeSet(gpioPortB, 7, gpioModePushPull, 1); /* TX */
215  break;
216  case 5:
217  case 6:
218  GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0); /* RX */
219  GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1); /* TX */
220  break;
221  /* default: */
222  /* No default */
223  }
224  }
225  else if (dbpointer == USART1)
226  {
227  switch (location)
228  {
229  case 0:
230  GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0); /* RX */
231  GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1); /* TX */
232  break;
233  case 2:
234  case 3:
235  GPIO_PinModeSet(gpioPortD, 6, gpioModeInput, 0); /* RX */
236  GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull, 1); /* TX */
237  break;
238  case 4:
239  GPIO_PinModeSet(gpioPortA, 0, gpioModeInput, 0); /* RX */
240  GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 1); /* TX */
241  break;
242  case 5:
243  GPIO_PinModeSet(gpioPortC, 2, gpioModeInput, 0); /* RX */
244  GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 1); /* TX */
245  break;
246  /* default: */
247  /* No default */
248  }
249  }
250 
251 
252  /* Initialize USART asynchronous mode */
253  USART_InitAsync(dbpointer, &config);
254 
255  /* Route pins */
256  switch (location)
257  {
258  case 0:
259  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
260  break;
261  case 1:
262  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC1;
263  break;
264  case 2:
265  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC2;
266  break;
267  case 3:
268  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC3;
269  break;
270  case 4:
271  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC4;
272  break;
273  case 5:
274  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC5;
275  break;
276  case 6:
277  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC6;
278  break;
279  default:
280  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_DEFAULT;
281  }
282 
283  /* Enable interrupts if necessary and print welcome string (and make an alert sound in the console) */
284  if (interrupts)
285  {
286  /* Initialize USART interrupts */
287 
288  /* RX Data Valid Interrupt Enable
289  * Set when data is available in the receive buffer. Cleared when the receive buffer is empty. */
290  USART_IntEnable(dbpointer, USART_IEN_RXDATAV);
291 
292  /* TX Complete Interrupt Enable
293  * Set when a transmission has completed and no more data is available in the transmit buffer.
294  * Cleared when a new transmission starts. */
295  USART_IntEnable(dbpointer, USART_IEN_TXC);
296 
297  if (dbpointer == USART0)
298  {
299  /* Enable USART interrupts */
300  NVIC_EnableIRQ(USART0_RX_IRQn);
301  NVIC_EnableIRQ(USART0_TX_IRQn);
302  }
303  else if (dbpointer == USART1)
304  {
305  /* Enable USART interrupts */
306  NVIC_EnableIRQ(USART1_RX_IRQn);
307  NVIC_EnableIRQ(USART1_TX_IRQn);
308  }
309 
310  /* Print welcome string */
312  dbprintln("\a\r\f### UART initialized (interrupt mode) ###");
313  dbinfo("This is an info message.");
314  dbwarn("This is a warning message.");
315  dbcrit("This is a critical error message.");
316  dbprintln("### Start executing programmed code ###\n");
317 
318  /* Set TX Complete Interrupt Flag (transmission has completed and no more data
319  * is available in the transmit buffer) */
320  USART_IntSet(dbpointer, USART_IFS_TXC);
321  }
322  /* Print welcome string (and make an alert sound in the console) if not in interrupt mode */
323  else
324  {
326  dbprintln("\a\r\f### UART initialized (no interrupts) ###");
327  dbinfo("This is an info message.");
328  dbwarn("This is a warning message.");
329  dbcrit("This is a critical error message.");
330  dbprintln("### Start executing programmed code ###\n");
331  }
332 }
333 
334 
335 /**************************************************************************//**
336  * @brief
337  * Sound an alert in the terminal.
338  *
339  * @details
340  * Print the *bell* (alert) character to USARTx.
341  *****************************************************************************/
342 void dbAlert (void)
343 {
344  USART_Tx(dbpointer, '\a');
345 }
346 
347 
348 /**************************************************************************//**
349  * @brief
350  * Clear the terminal.
351  *
352  * @details
353  * Print the *form feed* character to USARTx. Accessing old data is still
354  * possible by scrolling up in the serial port program.
355  *****************************************************************************/
356 void dbClear (void)
357 {
358  USART_Tx(dbpointer, '\f');
359 }
360 
361 
362 /**************************************************************************//**
363  * @brief
364  * Print a string (char array) to USARTx.
365  *
366  * @note
367  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
368  * the input message (array) needs to end with NULL (`"\0"`)!
369  *
370  * @param[in] message
371  * The string to print to USARTx.
372  *****************************************************************************/
373 void dbprint (char *message)
374 {
375  /* "message[i] != 0" makes "uint32_t length = strlen(message)"
376  * not necessary (given string MUST be terminated by NULL for this to work) */
377  for (uint32_t i = 0; message[i] != 0; i++)
378  {
379  USART_Tx(dbpointer, message[i]);
380  }
381 }
382 
383 
384 /**************************************************************************//**
385  * @brief
386  * Print a string (char array) to USARTx and go to the next line.
387  *
388  * @note
389  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
390  * the input message (array) needs to end with NULL (`"\0"`)!
391  *
392  * @param[in] message
393  * The string to print to USARTx.
394  *****************************************************************************/
395 void dbprintln (char *message)
396 {
397  dbprint(message);
398 
399  /* Carriage return */
400  USART_Tx(dbpointer, '\r');
401 
402  /* Line feed (new line) */
403  USART_Tx(dbpointer, '\n');
404 }
405 
406 
407 /**************************************************************************//**
408  * @brief
409  * Print a string (char array) to USARTx in a given color.
410  *
411  * @note
412  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
413  * the input message (array) needs to end with NULL (`"\0"`)!
414  *
415  * @param[in] message
416  * The string to print to USARTx.
417  *
418  * @param[in] color
419  * The color to print the text in.
420  *****************************************************************************/
421 void dbprint_color (char *message, dbprint_color_t color)
422 {
423  switch (color)
424  {
425  case DEFAULT_COLOR:
427  dbprint(message);
428  break;
429  case RED:
431  dbprint(message);
433  break;
434  case GREEN:
436  dbprint(message);
438  break;
439  case BLUE:
441  dbprint(message);
443  break;
444  case CYAN:
446  dbprint(message);
448  break;
449  case MAGENTA:
451  dbprint(message);
453  break;
454  case YELLOW:
456  dbprint(message);
458  break;
459  default:
461  dbprint(message);
462  }
463 }
464 
465 
466 /**************************************************************************//**
467  * @brief
468  * Print a string (char array) to USARTx in a given color and go to the next line.
469  *
470  * @note
471  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
472  * the input message (array) needs to end with NULL (`"\0"`)!
473  *
474  * @param[in] message
475  * The string to print to USARTx.
476  *
477  * @param[in] color
478  * The color to print the text in.
479  *****************************************************************************/
480 void dbprintln_color (char *message, dbprint_color_t color)
481 {
482  dbprint_color(message, color);
483 
484  /* Carriage return */
485  USART_Tx(dbpointer, '\r');
486 
487  /* Line feed (new line) */
488  USART_Tx(dbpointer, '\n');
489 }
490 
491 
492 /**************************************************************************//**
493  * @brief
494  * Print an *info* string (char array) to USARTx and go to the next line.
495  *
496  * @note
497  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
498  * the input message (array) needs to end with NULL (`"\0"`)!
499  *
500  * @param[in] message
501  * The string to print to USARTx.
502  *****************************************************************************/
503 void dbinfo (char *message)
504 {
505  dbprint("INFO: ");
506  dbprintln(message);
507 }
508 
509 
510 /**************************************************************************//**
511  * @brief
512  * Print a *warning* string (char array) in yellow to USARTx and go to the next line.
513  *
514  * @note
515  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
516  * the input message (array) needs to end with NULL (`"\0"`)!
517  *
518  * @param[in] message
519  * The string to print to USARTx.
520  *****************************************************************************/
521 void dbwarn (char *message)
522 {
523  dbprint_color("WARN: ", YELLOW);
524  dbprintln_color(message, YELLOW);
525 }
526 
527 
528 /**************************************************************************//**
529  * @brief
530  * Print a *critical error* string (char array) in red to USARTx and go to the next line.
531  *
532  * @note
533  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
534  * the input message (array) needs to end with NULL (`"\0"`)!
535  *
536  * @param[in] message
537  * The string to print to USARTx.
538  *****************************************************************************/
539 void dbcrit (char *message)
540 {
541  dbprint_color("CRIT: ", RED);
542  dbprintln_color(message, RED);
543 }
544 
545 
546 /**************************************************************************//**
547  * @brief
548  * Print an *info* value surrounded by two strings (char array) to USARTx.
549  *
550  * @details
551  * "INFO: " gets added in front, the decimal notation is used and
552  * the function advances to the next line.
553  *
554  * @note
555  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
556  * the input message (array) needs to end with NULL (`"\0"`)!
557  *
558  * @param[in] message1
559  * The first part of the string to print to USARTx.
560  *
561  * @param[in] value
562  * The value to print between the two string parts.
563  *
564  * @param[in] message2
565  * The second part of the string to print to USARTx.
566  *****************************************************************************/
567 void dbinfoInt (char *message1, int32_t value, char *message2)
568 {
569  dbprint("INFO: ");
570  dbprint(message1);
571  dbprintInt(value);
572  dbprintln(message2);
573 }
574 
575 
576 /**************************************************************************//**
577  * @brief
578  * Print a *warning* value surrounded by two strings (char array) to USARTx.
579  *
580  * @details
581  * "WARN: " gets added in front, the decimal notation is used and
582  * the function advances to the next line. The value is in the color white,
583  * the rest is yellow.
584  *
585  * @note
586  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
587  * the input message (array) needs to end with NULL (`"\0"`)!
588  *
589  * @param[in] message1
590  * The first part of the string to print to USARTx.
591  *
592  * @param[in] value
593  * The value to print between the two string parts.
594  *
595  * @param[in] message2
596  * The second part of the string to print to USARTx.
597  *****************************************************************************/
598 void dbwarnInt (char *message1, int32_t value, char *message2)
599 {
600  dbprint_color("WARN: ", YELLOW);
601  dbprint_color(message1, YELLOW);
602  dbprintInt(value);
603  dbprintln_color(message2, YELLOW);
604 }
605 
606 
607 /**************************************************************************//**
608  * @brief
609  * Print a *critical* value surrounded by two strings (char array) to USARTx.
610  *
611  * @details
612  * "CRIT: " gets added in front, the decimal notation is used and
613  * the function advances to the next line. The value is in the color white,
614  * the rest is red.
615  *
616  * @note
617  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
618  * the input message (array) needs to end with NULL (`"\0"`)!
619  *
620  * @param[in] message1
621  * The first part of the string to print to USARTx.
622  *
623  * @param[in] value
624  * The value to print between the two string parts.
625  *
626  * @param[in] message2
627  * The second part of the string to print to USARTx.
628  *****************************************************************************/
629 void dbcritInt (char *message1, int32_t value, char *message2)
630 {
631  dbprint_color("CRIT: ", RED);
632  dbprint_color(message1, RED);
633  dbprintInt(value);
634  dbprintln_color(message2, RED);
635 }
636 
637 
638 /**************************************************************************//**
639  * @brief
640  * Print an *info* value surrounded by two strings (char array) to USARTx.
641  *
642  * @details
643  * "INFO: " gets added in front, the hexadecimal notation is used and
644  * the function advances to the next line.
645  *
646  * @note
647  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
648  * the input message (array) needs to end with NULL (`"\0"`)!
649  *
650  * @param[in] message1
651  * The first part of the string to print to USARTx.
652  *
653  * @param[in] value
654  * The value to print between the two string parts.
655  *
656  * @param[in] message2
657  * The second part of the string to print to USARTx.
658  *****************************************************************************/
659 void dbinfoInt_hex (char *message1, int32_t value, char *message2)
660 {
661  dbprint("INFO: ");
662  dbprint(message1);
663  dbprintInt_hex(value);
664  dbprintln(message2);
665 }
666 
667 
668 /**************************************************************************//**
669  * @brief
670  * Print a *warning* value surrounded by two strings (char array) to USARTx.
671  *
672  * @details
673  * "WARN: " gets added in front, the hexadecimal notation is used and
674  * the function advances to the next line. The value is in the color white,
675  * the rest is yellow.
676  *
677  * @note
678  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
679  * the input message (array) needs to end with NULL (`"\0"`)!
680  *
681  * @param[in] message1
682  * The first part of the string to print to USARTx.
683  *
684  * @param[in] value
685  * The value to print between the two string parts.
686  *
687  * @param[in] message2
688  * The second part of the string to print to USARTx.
689  *****************************************************************************/
690 void dbwarnInt_hex (char *message1, int32_t value, char *message2)
691 {
692  dbprint_color("WARN: ", YELLOW);
693  dbprint_color(message1, YELLOW);
694  dbprintInt_hex(value);
695  dbprintln_color(message2, YELLOW);
696 }
697 
698 
699 /**************************************************************************//**
700  * @brief
701  * Print a *critical* value surrounded by two strings (char array) to USARTx.
702  *
703  * @details
704  * "CRIT: " gets added in front, the hexadecimal notation is used and
705  * the function advances to the next line. The value is in the color white,
706  * the rest is red.
707  *
708  * @note
709  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
710  * the input message (array) needs to end with NULL (`"\0"`)!
711  *
712  * @param[in] message1
713  * The first part of the string to print to USARTx.
714  *
715  * @param[in] value
716  * The value to print between the two string parts.
717  *
718  * @param[in] message2
719  * The second part of the string to print to USARTx.
720  *****************************************************************************/
721 void dbcritInt_hex (char *message1, int32_t value, char *message2)
722 {
723  dbprint_color("CRIT: ", RED);
724  dbprint_color(message1, RED);
725  dbprintInt_hex(value);
726  dbprintln_color(message2, RED);
727 }
728 
729 
730 /**************************************************************************//**
731  * @brief
732  * Print a number in decimal notation to USARTx.
733  *
734  * @param[in] value
735  * The number to print to USARTx.@n
736  * This can be of type `uint32_t` or `int32_t`.
737  *****************************************************************************/
738 void dbprintInt (int32_t value)
739 {
740  /* Buffer to put the char array in (Needs to be 10) */
741  char decchar[10];
742 
743  /* Convert a negative number to a positive one and print the "-" */
744  if (value < 0)
745  {
746  /* Negative of value = flip all bits, +1
747  * bitwise logic: "~" = "NOT" */
748  uint32_t negativeValue = (~value) + 1;
749 
750  dbprint("-");
751 
752  /* Convert the value */
753  uint32_to_charDec(decchar, negativeValue);
754  }
755  else
756  {
757  /* Convert the value */
758  uint32_to_charDec(decchar, value);
759  }
760 
761  /* Print the buffer */
762  dbprint(decchar);
763 }
764 
765 
766 /**************************************************************************//**
767  * @brief
768  * Print a number in decimal notation to USARTx and go to the next line.
769  *
770  * @param[in] value
771  * The number to print to USARTx.@n
772  * This can be of type `uint32_t` or `int32_t`.
773  *****************************************************************************/
774 void dbprintlnInt (int32_t value)
775 {
776  dbprintInt(value);
777 
778  /* Carriage return */
779  USART_Tx(dbpointer, '\r');
780 
781  /* Line feed (new line) */
782  USART_Tx(dbpointer, '\n');
783 }
784 
785 
786 /**************************************************************************//**
787  * @brief
788  * Print a number in hexadecimal notation to USARTx.
789  *
790  * @param[in] value
791  * The number to print to USARTx.@n
792  * This can be of type `uint32_t` or `int32_t`.
793  *****************************************************************************/
794 void dbprintInt_hex (int32_t value)
795 {
796  char hexchar[9]; /* Needs to be 9 */
797  uint32_to_charHex(hexchar, value, true); /* true: add spacing between eight HEX chars */
798  dbprint("0x");
799  dbprint(hexchar);
800 }
801 
802 
803 /**************************************************************************//**
804  * @brief
805  * Print a number in hexadecimal notation to USARTx and go to the next line.
806  *
807  * @param[in] value
808  * The number to print to USARTx.@n
809  * This can be of type `uint32_t` or `int32_t`.
810  *****************************************************************************/
811 void dbprintlnInt_hex (int32_t value)
812 {
813  dbprintInt_hex(value);
814 
815  /* Carriage return */
816  USART_Tx(dbpointer, '\r');
817 
818  /* Line feed (new line) */
819  USART_Tx(dbpointer, '\n');
820 }
821 
822 
823 /**************************************************************************//**
824  * @brief
825  * Read a character from USARTx.
826  *
827  * @return
828  * The character read from USARTx.
829  *****************************************************************************/
830 char dbReadChar (void)
831 {
832  return (USART_Rx(dbpointer));
833 }
834 
835 
836 /**************************************************************************//**
837  * @brief
838  * Read a decimal character from USARTx and convert it to a `uint8_t` value.
839  *
840  * @note
841  * Specific methods exist to read `uint16_t` and `uint32_t` values:
842  * - `uint16_t USART_RxDouble(USART_TypeDef *usart);`
843  * - `uint32_t USART_RxDoubleExt(USART_TypeDef *usart);`
844  *
845  * @return
846  * The converted `uint8_t` value.
847  *****************************************************************************/
848 uint8_t dbReadInt (void)
849 {
850  /* Method expects a char array ending with a null termination character */
851  char value[2];
852  value[0]= dbReadChar();
853  value[1] = '\0';
854 
855  return (charDec_to_uint32(value));
856 }
857 
858 
859 /**************************************************************************//**
860  * @brief
861  * Read a string (char array) from USARTx.
862  *
863  * @note
864  * The reading stops when a `"CR"` (Carriage Return, ENTER) character
865  * is received or the maximum length (`DBPRINT_BUFFER_SIZE`) is reached.
866  *
867  * @param[in] buf
868  * The buffer to put the resulting string in.@n
869  * **This needs to have a length of `DBPRINT_BUFFER_SIZE` for the function
870  * to work properly: `char buf[DBPRINT_BUFFER_SIZE];`!**
871  *****************************************************************************/
872 void dbReadLine (char *buf)
873 {
874  for (uint32_t i = 0; i < DBPRINT_BUFFER_SIZE - 1 ; i++ )
875  {
876  char localBuffer = USART_Rx(dbpointer);
877 
878  /* Check if a CR character is received */
879  if (localBuffer == '\r')
880  {
881  /* End with a null termination character, expected by the dbprintln method */
882  buf[i] = '\0';
883  break;
884  }
885  else
886  {
887  buf[i] = localBuffer;
888  }
889  }
890 }
891 
892 
893 /**************************************************************************//**
894  * @brief
895  * Check if data was received using interrupts in the RX buffer.
896  *
897  * @note
898  * The index of the RX buffer gets reset in the RX handler when a CR character
899  * is received or the buffer is filled.
900  *
901  * @attention
902  * Interrupt functionality has to be enabled on initialization for this
903  * function to work correctly.
904  *
905  * @return
906  * @li `true` - Data is received in the RX buffer.
907  * @li `false` - No data is received.
908  *****************************************************************************/
909 bool dbGet_RXstatus (void)
910 {
911  return (dataReceived);
912 }
913 
914 
915 // TODO: Needs fixing (but probably won't ever be used):
916 //**************************************************************************//**
917 // * @brief
918 // * Set the value of the TX buffer and start transmitting it using interrupts.
919 // *
920 // * @details
921 // * The `"TX Complete Interrupt Flag"` also gets set at the end of the
922 // * function (transmission has completed and no more data is available
923 // * in the transmit buffer).
924 // *
925 // * @note
926 // * If the input is not a string (ex.: `"Hello world!"`) but a char array,
927 // * the input message (array) needs to end with NULL (`"\0"`)!
928 // *
929 // * @note
930 // * The index of the RX buffer gets reset in the TX handler when all the
931 // * characters in the buffer are send.
932 // *
933 // * @attention
934 // * Interrupt functionality has to be enabled on initialization for this
935 // * function to work correctly.
936 // *
937 // * @param[in] message
938 // * The string to put in the TX buffer.
939 // *****************************************************************************/
940 //void dbSet_TXbuffer (char *message)
941 //{
942 // uint32_t i;
943 //
944 // /* Copy data to the TX buffer */
945 // for (i = 0; message[i] != 0 && i < DBPRINT_BUFFER_SIZE-1; i++)
946 // {
947 // tx_buffer[i] = message[i];
948 // }
949 //
950 // /* Set TX Complete Interrupt Flag (transmission has completed and no more data
951 // * is available in the transmit buffer) */
952 // USART_IntSet(dbpointer, USART_IFS_TXC);
953 //
954 // TODO: Perhaps some functionality needs to be added to send numbers and
955 // that might need functionality to disable interrupts. For reference
956 // some old code that could be put in a main.c file is put below.
957 // /* Data is ready to retransmit (notified by the RX handler) */
958 // if (dbprint_rxdata)
959 // {
960 // uint32_t i;
961 //
962 // /* RX Data Valid Interrupt Enable
963 // * Set when data is available in the receive buffer. Cleared when the receive buffer is empty.
964 // *
965 // * TX Complete Interrupt Enable
966 // * Set when a transmission has completed and no more data is available in the transmit buffer.
967 // * Cleared when a new transmission starts.
968 // */
969 //
970 // /* Disable "RX Data Valid Interrupt Enable" and "TX Complete Interrupt Enable" interrupts */
971 // USART_IntDisable(dbpointer, USART_IEN_RXDATAV);
972 // USART_IntDisable(dbpointer, USART_IEN_TXC);
973 //
974 // /* Copy data from the RX buffer to the TX buffer */
975 // for (i = 0; dbprint_rx_buffer[i] != 0 && i < DBPRINT_BUFFER_SIZE-3; i++)
976 // {
977 // dbprint_tx_buffer[i] = dbprint_rx_buffer[i];
978 // }
979 //
980 // /* Add "new line" characters */
981 // dbprint_tx_buffer[i++] = '\r';
982 // dbprint_tx_buffer[i++] = '\n';
983 // dbprint_tx_buffer[i] = '\0';
984 //
985 // /* Reset "notification" variable */
986 // dbprint_rxdata = false;
987 //
988 // /* Enable "RX Data Valid Interrupt" and "TX Complete Interrupt" interrupts */
989 // USART_IntEnable(dbpointer, USART_IEN_RXDATAV);
990 // USART_IntEnable(dbpointer, USART_IEN_TXC);
991 //
992 // /* Set TX Complete Interrupt Flag (transmission has completed and no more data
993 // * is available in the transmit buffer) */
994 // USART_IntSet(dbpointer, USART_IFS_TXC);
995 // }
996 //
997 //}
998 
999 
1000 /**************************************************************************//**
1001  * @brief
1002  * Get the value of the RX buffer and clear the `dataReceived` flag.
1003  *
1004  * @note
1005  * The index of the RX buffer gets reset in the RX handler when a CR character
1006  * is received or the buffer is filled.
1007  *
1008  * @attention
1009  * Interrupt functionality has to be enabled on initialization for this
1010  * function to work correctly.
1011  *
1012  * @param[in] buf
1013  * The buffer to put the resulting string in.@n
1014  * **This needs to have a length of `DBPRINT_BUFFER_SIZE` for the function
1015  * to work properly: `char buf[DBPRINT_BUFFER_SIZE];`!**
1016  *****************************************************************************/
1017 void dbGet_RXbuffer (char *buf)
1018 {
1019  if (dataReceived)
1020  {
1021  uint32_t i;
1022 
1023  /* Copy data from the RX buffer to the given buffer */
1024  for (i = 0; rx_buffer[i] != 0 && i < DBPRINT_BUFFER_SIZE-1; i++)
1025  {
1026  buf[i] = rx_buffer[i];
1027  }
1028 
1029  /* Add NULL termination character */
1030  buf[i++] = '\0';
1031 
1032  /* Reset "notification" variable */
1033  dataReceived = false;
1034  }
1035  else
1036  {
1037  dbcrit("No received data available!");
1038  }
1039 }
1040 
1041 
1042 /**************************************************************************//**
1043  * @brief
1044  * Convert a `uint32_t` value to a hexadecimal char array (string).
1045  *
1046  * @note
1047  * This is a static method because it's only internally used in this file
1048  * and called by other methods if necessary.
1049  *
1050  * @param[out] buf
1051  * The buffer to put the resulting string in.@n
1052  * **This needs to have a length of 9: `char buf[9];`!**
1053  *
1054  * @param[in] value
1055  * The `uint32_t` value to convert to a string.
1056  *
1057  * @param[in] spacing
1058  * @li `true` - Add spacing between the eight HEX chars to make two groups of four.
1059  * @li `false` - Don't add spacing between the eight HEX chars.
1060  *****************************************************************************/
1061 static void uint32_to_charHex (char *buf, uint32_t value, bool spacing)
1062 {
1063  /* 4 nibble HEX representation */
1064  if (value <= 0xFFFF)
1065  {
1066  /* Only get necessary nibble by ANDing with a mask and
1067  * shifting one nibble (4 bits) per position */
1068  buf[0] = TO_HEX(((value & 0xF000) >> 12));
1069  buf[1] = TO_HEX(((value & 0x0F00) >> 8 ));
1070  buf[2] = TO_HEX(((value & 0x00F0) >> 4 ));
1071  buf[3] = TO_HEX( (value & 0x000F) );
1072  buf[4] = '\0'; /* NULL termination character */
1073  }
1074 
1075  /* 8 nibble HEX representation */
1076  else
1077  {
1078  /* Only get necessary nibble by ANDing with a mask and
1079  * shifting one nibble (4 bits) per position */
1080  buf[0] = TO_HEX(((value & 0xF0000000) >> 28));
1081  buf[1] = TO_HEX(((value & 0x0F000000) >> 24));
1082  buf[2] = TO_HEX(((value & 0x00F00000) >> 20));
1083  buf[3] = TO_HEX(((value & 0x000F0000) >> 16));
1084 
1085  /* Add spacing if necessary */
1086  if (spacing)
1087  {
1088  buf[4] = ' '; /* Spacing */
1089  buf[5] = TO_HEX(((value & 0x0000F000) >> 12));
1090  buf[6] = TO_HEX(((value & 0x00000F00) >> 8 ));
1091  buf[7] = TO_HEX(((value & 0x000000F0) >> 4 ));
1092  buf[8] = TO_HEX( (value & 0x0000000F) );
1093  buf[9] = '\0'; /* NULL termination character */
1094  }
1095  else
1096  {
1097  buf[4] = TO_HEX(((value & 0x0000F000) >> 12));
1098  buf[5] = TO_HEX(((value & 0x00000F00) >> 8 ));
1099  buf[6] = TO_HEX(((value & 0x000000F0) >> 4 ));
1100  buf[7] = TO_HEX( (value & 0x0000000F) );
1101  buf[8] = '\0'; /* NULL termination character */
1102  }
1103  }
1104 }
1105 
1106 
1107 /**************************************************************************//**
1108  * @brief
1109  * Convert a `uint32_t` value to a decimal char array (string).
1110  *
1111  * @note
1112  * This is a static method because it's only internally used in this file
1113  * and called by other methods if necessary.
1114  *
1115  * @param[out] buf
1116  * The buffer to put the resulting string in.@n
1117  * **This needs to have a length of 10: `char buf[10];`!**
1118  *
1119  * @param[in] value
1120  * The `uint32_t` value to convert to a string.
1121  *****************************************************************************/
1122 static void uint32_to_charDec (char *buf, uint32_t value)
1123 {
1124  if (value == 0)
1125  {
1126  buf[0] = '0';
1127  buf[1] = '\0'; /* NULL termination character */
1128  }
1129  else
1130  {
1131  /* MAX uint32_t value = FFFFFFFFh = 4294967295d (10 decimal chars) */
1132  char backwardsBuf[10];
1133 
1134  uint32_t calcval = value;
1135  uint8_t length = 0;
1136  uint8_t lengthCounter = 0;
1137 
1138 
1139  /* Loop until the value is zero (separate characters 0-9) and calculate length */
1140  while (calcval)
1141  {
1142  uint32_t rem = calcval % 10;
1143  backwardsBuf[length] = TO_DEC(rem); /* Convert to ASCII character */
1144  length++;
1145 
1146  calcval = calcval - rem;
1147  calcval = calcval / 10;
1148  }
1149 
1150  /* Backwards counter */
1151  lengthCounter = length;
1152 
1153  /* Reverse the characters in the buffer for the final string */
1154  for (uint8_t i = 0; i < length; i++)
1155  {
1156  buf[i] = backwardsBuf[lengthCounter-1];
1157  lengthCounter--;
1158  }
1159 
1160  /* Add NULL termination character */
1161  buf[length] = '\0';
1162  }
1163 }
1164 
1165 
1166 /**************************************************************************//**
1167  * @brief
1168  * Convert a string (char array) in decimal notation to a `uint32_t` value.
1169  *
1170  * @note
1171  * If the input is not a string (ex.: `"00BA0FA1"`) but a char array,
1172  * the input buffer (array) needs to end with NULL (`"\0"`)!
1173  *
1174  * @note
1175  * This is a static method because it's only internally used in this file
1176  * and called by other methods if necessary.
1177  *
1178  * @param[in] buf
1179  * The decimal string to convert to a `uint32_t` value.
1180  *
1181  * @return
1182  * The resulting `uint32_t` value.
1183  *****************************************************************************/
1184 static uint32_t charDec_to_uint32 (char *buf)
1185 {
1186  /* Value to eventually return */
1187  uint32_t value = 0;
1188 
1189  /* Loop until buffer is empty */
1190  while (*buf)
1191  {
1192  /* Get current character, increment afterwards */
1193  uint8_t byte = *buf++;
1194 
1195  /* Check if the next value we need to add can fit in a uint32_t */
1196  if ( (value <= 0xFFFFFFF) && ((byte - '0') <= 0xF) )
1197  {
1198  /* Convert the ASCII (decimal) character to the representing decimal value
1199  * and add it to the value (which is multiplied by 10 for each position) */
1200  value = (value * 10) + (byte - '0');
1201  }
1202  else
1203  {
1204  /* Given buffer can't fit in uint32_t */
1205  return (0);
1206  }
1207  }
1208 
1209  return (value);
1210 }
1211 
1212 
1213 // Unused but kept here just in case:
1214 //**************************************************************************//**
1215 // * @brief
1216 // * Convert a string (char array) in hexadecimal notation to a `uint32_t` value.
1217 // *
1218 // * @note
1219 // * If the input is not a string (ex.: `"00120561"`) but a char array,
1220 // * the input buffer (array) needs to end with NULL (`"\0"`)!@n
1221 // * The input string can't have the prefix `0x`.
1222 // *
1223 // * @note
1224 // * This is a static method because it's only internally used in this file
1225 // * and called by other methods if necessary.
1226 // *
1227 // * @param[in] buf
1228 // * The hexadecimal string to convert to a `uint32_t` value.
1229 // *
1230 // * @return
1231 // * The resulting `uint32_t` value.
1232 // *****************************************************************************/
1233 //static uint32_t charHex_to_uint32 (char *buf)
1234 //{
1235 // /* Value to eventually return */
1236 // uint32_t value = 0;
1237 //
1238 // /* Loop until buffer is empty */
1239 // while (*buf)
1240 // {
1241 // /* Get current character, increment afterwards */
1242 // uint8_t byte = *buf++;
1243 //
1244 // /* Convert the hex character to the 4-bit equivalent
1245 // * number using the ASCII table indexes */
1246 // if (byte >= '0' && byte <= '9') byte = byte - '0';
1247 // else if (byte >= 'a' && byte <='f') byte = byte - 'a' + 10;
1248 // else if (byte >= 'A' && byte <='F') byte = byte - 'A' + 10;
1249 //
1250 // /* Check if the next byte we need to add can fit in a uint32_t */
1251 // if ( (value <= 0xFFFFFFF) && (byte <= 0xF) )
1252 // {
1253 // /* Shift one nibble (4 bits) to make space for a new digit
1254 // * and add the 4 bits (ANDing with a mask, 0xF = 0b1111) */
1255 // value = (value << 4) | (byte & 0xF);
1256 // }
1257 // else
1258 // {
1259 // /* Given buffer can't fit in uint32_t */
1260 // return (0);
1261 // }
1262 // }
1263 //
1264 // return (value);
1265 //}
1266 
1267 
1268 /**************************************************************************//**
1269  * @brief
1270  * USART0 RX interrupt service routine.
1271  *
1272  * @details
1273  * The index gets reset to zero when a special character (CR) is received or
1274  * the buffer is filled.
1275  *
1276  * @note
1277  * The *weak* definition for this method is located in `system_efm32hg.h`.
1278  *****************************************************************************/
1280 {
1281  /* "static" so it keeps its value between invocations */
1282  static uint32_t i = 0;
1283 
1284  /* Get and clear the pending USART interrupt flags */
1285  uint32_t flags = USART_IntGet(dbpointer);
1286  USART_IntClear(dbpointer, flags);
1287 
1288  /* Store incoming data into dbprint_rx_buffer */
1289  rx_buffer[i++] = USART_Rx(dbpointer);
1290 
1291  /* Set dbprint_rxdata when a special character is received (~ full line received) */
1292  if ( (rx_buffer[i - 1] == '\r') || (rx_buffer[i - 1] == '\f') )
1293  {
1294  dataReceived = true;
1295  rx_buffer[i - 1] = '\0'; /* Overwrite CR or LF character */
1296  i = 0;
1297  }
1298 
1299  /* Set dbprint_rxdata when the buffer is full */
1300  if (i >= (DBPRINT_BUFFER_SIZE - 2))
1301  {
1302  dataReceived = true;
1303  rx_buffer[i] = '\0'; /* Do not overwrite last character */
1304  i = 0;
1305  }
1306 }
1307 
1308 
1309 /**************************************************************************//**
1310  * @brief
1311  * USART0 TX interrupt service routine.
1312  *
1313  * @details
1314  * The index gets reset to zero when all the characters in the buffer are send.
1315  *
1316  * @note
1317  * The *weak* definition for this method is located in `system_efm32hg.h`.
1318  *****************************************************************************/
1320 {
1321  /* "static" so it keeps its value between invocations */
1322  static uint32_t i = 0;
1323 
1324  /* Get and clear the pending USART interrupt flags */
1325  uint32_t flags = USART_IntGet(dbpointer);
1326  USART_IntClear(dbpointer, flags);
1327 
1328  /* Mask flags AND "TX Complete Interrupt Flag" */
1329  if (flags & USART_IF_TXC)
1330  {
1331  /* Index is smaller than the maximum buffer size and
1332  * the current item to print is not "NULL" (\0) */
1333  if ( (i < DBPRINT_BUFFER_SIZE) && (tx_buffer[i] != '\0') )
1334  {
1335  /* Transmit byte at current index and increment index */
1336  USART_Tx(dbpointer, tx_buffer[i++]);
1337  }
1338  else
1339  {
1340  i = 0; /* No more data to send */
1341  }
1342  }
1343 }
1344 
1345 
1346 /**************************************************************************//**
1347  * @brief
1348  * USART1 RX interrupt service routine.
1349  *
1350  * @note
1351  * The *weak* definition for this method is located in `system_efm32hg.h`.
1352  *****************************************************************************/
1354 {
1355  /* Call other handler */
1357 }
1358 
1359 
1360 /**************************************************************************//**
1361  * @brief
1362  * USART1 TX interrupt service routine.
1363  *
1364  * @note
1365  * The *weak* definition for this method is located in `system_efm32hg.h`.
1366  *****************************************************************************/
1368 {
1369  /* Call other handler */
1371 }
1372 
1373 #endif /* DEBUG_DBPRINT */
Definition: dbprint.h:57
#define COLOR_GREEN
Definition: dbprint.c:105
void dbprint(char *message)
Print a string (char array) to USARTx.
Definition: dbprint.c:373
#define COLOR_YELLOW
Definition: dbprint.c:109
void dbprintlnInt(int32_t value)
Print a number in decimal notation to USARTx and go to the next line.
Definition: dbprint.c:774
Definition: dbprint.h:54
void dbinfoInt_hex(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:659
void dbprintln(char *message)
Print a string (char array) to USARTx and go to the next line.
Definition: dbprint.c:395
void dbinfoInt(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:567
void dbwarnInt_hex(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:690
void dbcritInt(char *message1, int32_t value, char *message2)
Print a critical value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:629
void dbAlert(void)
Sound an alert in the terminal.
Definition: dbprint.c:342
volatile char tx_buffer[80]
Definition: dbprint.c:120
#define COLOR_MAGENTA
Definition: dbprint.c:108
void dbwarn(char *message)
Print a warning string (char array) in yellow to USARTx and go to the next line.
Definition: dbprint.c:521
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:598
#define TO_DEC(i)
Definition: dbprint.c:101
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
uint8_t dbReadInt(void)
Read a decimal character from USARTx and convert it to a uint8_t value.
Definition: dbprint.c:848
#define COLOR_RED
Definition: dbprint.c:104
volatile bool dataReceived
Definition: dbprint.c:118
static uint32_t charDec_to_uint32(char *buf)
Convert a string (char array) in decimal notation to a uint32_t value.
Definition: dbprint.c:1184
Definition: dbprint.h:55
void dbprintlnInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx and go to the next line.
Definition: dbprint.c:811
volatile char rx_buffer[80]
Definition: dbprint.c:119
static void uint32_to_charDec(char *buf, uint32_t value)
Convert a uint32_t value to a decimal char array (string).
Definition: dbprint.c:1122
void dbcritInt_hex(char *message1, int32_t value, char *message2)
Print a critical value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:721
Definition: dbprint.h:59
Definition: dbprint.h:56
void USART1_TX_IRQHandler(void)
USART1 TX interrupt service routine.
Definition: dbprint.c:1367
#define COLOR_BLUE
Definition: dbprint.c:106
USART_TypeDef * dbpointer
Definition: dbprint.c:114
#define COLOR_CYAN
Definition: dbprint.c:107
char dbReadChar(void)
Read a character from USARTx.
Definition: dbprint.c:830
#define TO_HEX(i)
Definition: dbprint.c:100
void dbClear(void)
Clear the terminal.
Definition: dbprint.c:356
void dbprint_INIT(USART_TypeDef *pointer, uint8_t location, bool vcom, bool interrupts)
Initialize USARTx.
Definition: dbprint.c:148
void USART1_RX_IRQHandler(void)
USART1 RX interrupt service routine.
Definition: dbprint.c:1353
#define DBPRINT_BUFFER_SIZE
Definition: dbprint.h:48
Enable or disable printing to UART with dbprint.
void USART0_TX_IRQHandler(void)
USART0 TX interrupt service routine.
Definition: dbprint.c:1319
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
Definition: dbprint.c:738
bool dbGet_RXstatus(void)
Check if data was received using interrupts in the RX buffer.
Definition: dbprint.c:909
void dbprintInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx.
Definition: dbprint.c:794
enum dbprint_colors dbprint_color_t
void dbprintln_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color and go to the next line.
Definition: dbprint.c:480
#define COLOR_RESET
Definition: dbprint.c:110
void dbReadLine(char *buf)
Read a string (char array) from USARTx.
Definition: dbprint.c:872
void dbGet_RXbuffer(char *buf)
Get the value of the RX buffer and clear the dataReceived flag.
Definition: dbprint.c:1017
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539
static void uint32_to_charHex(char *buf, uint32_t value, bool spacing)
Convert a uint32_t value to a hexadecimal char array (string).
Definition: dbprint.c:1061
void USART0_RX_IRQHandler(void)
USART0 RX interrupt service routine.
Definition: dbprint.c:1279
void dbprint_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color.
Definition: dbprint.c:421