88 #if DEBUG_DBPRINT == 1 100 #define TO_HEX(i) (i <= 9 ? '0' + i : 'A' - 10 + i) 101 #define TO_DEC(i) (i <= 9 ? '0' + i : '?') 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" 148 void dbprint_INIT (USART_TypeDef* pointer, uint8_t location,
bool vcom,
bool interrupts)
170 USART_InitAsync_TypeDef config = USART_INITASYNC_DEFAULT;
173 CMU_ClockEnable(cmuClock_GPIO,
true);
179 CMU_ClockEnable(cmuClock_USART0,
true);
183 CMU_ClockEnable(cmuClock_USART1,
true);
190 GPIO_PinModeSet(gpioPortA, 9, gpioModePushPull, 1);
191 GPIO_PinOutSet(gpioPortA, 9);
201 GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 0);
202 GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 1);
205 GPIO_PinModeSet(gpioPortC, 10, gpioModeInput, 0);
209 GPIO_PinModeSet(gpioPortE, 12, gpioModeInput, 0);
210 GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 1);
213 GPIO_PinModeSet(gpioPortB, 8, gpioModeInput, 0);
214 GPIO_PinModeSet(gpioPortB, 7, gpioModePushPull, 1);
218 GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
219 GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
230 GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
231 GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
235 GPIO_PinModeSet(gpioPortD, 6, gpioModeInput, 0);
236 GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull, 1);
239 GPIO_PinModeSet(gpioPortA, 0, gpioModeInput, 0);
240 GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 1);
243 GPIO_PinModeSet(gpioPortC, 2, gpioModeInput, 0);
244 GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 1);
259 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
262 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC1;
265 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC2;
268 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC3;
271 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC4;
274 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC5;
277 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC6;
280 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_DEFAULT;
290 USART_IntEnable(
dbpointer, USART_IEN_RXDATAV);
295 USART_IntEnable(
dbpointer, USART_IEN_TXC);
300 NVIC_EnableIRQ(USART0_RX_IRQn);
301 NVIC_EnableIRQ(USART0_TX_IRQn);
306 NVIC_EnableIRQ(USART1_RX_IRQn);
307 NVIC_EnableIRQ(USART1_TX_IRQn);
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");
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");
377 for (uint32_t i = 0; message[i] != 0; i++)
567 void dbinfoInt (
char *message1, int32_t value,
char *message2)
598 void dbwarnInt (
char *message1, int32_t value,
char *message2)
629 void dbcritInt (
char *message1, int32_t value,
char *message2)
748 uint32_t negativeValue = (~value) + 1;
879 if (localBuffer ==
'\r')
887 buf[i] = localBuffer;
1037 dbcrit(
"No received data available!");
1064 if (value <= 0xFFFF)
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) );
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));
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) );
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) );
1132 char backwardsBuf[10];
1134 uint32_t calcval = value;
1136 uint8_t lengthCounter = 0;
1142 uint32_t rem = calcval % 10;
1143 backwardsBuf[length] =
TO_DEC(rem);
1146 calcval = calcval - rem;
1147 calcval = calcval / 10;
1151 lengthCounter = length;
1154 for (uint8_t i = 0; i < length; i++)
1156 buf[i] = backwardsBuf[lengthCounter-1];
1193 uint8_t byte = *buf++;
1196 if ( (value <= 0xFFFFFFF) && ((byte -
'0') <= 0xF) )
1200 value = (value * 10) + (byte -
'0');
1282 static uint32_t i = 0;
1285 uint32_t flags = USART_IntGet(
dbpointer);
1322 static uint32_t i = 0;
1325 uint32_t flags = USART_IntGet(
dbpointer);
1329 if (flags & USART_IF_TXC)
void dbprint(char *message)
Print a string (char array) to USARTx.
void dbprintlnInt(int32_t value)
Print a number in decimal notation to USARTx and go to the next line.
void dbinfoInt_hex(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
void dbprintln(char *message)
Print a string (char array) to USARTx and go to the next line.
void dbinfoInt(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
void dbwarnInt_hex(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
void dbcritInt(char *message1, int32_t value, char *message2)
Print a critical value surrounded by two strings (char array) to USARTx.
void dbAlert(void)
Sound an alert in the terminal.
volatile char tx_buffer[80]
void dbwarn(char *message)
Print a warning string (char array) in yellow to USARTx and go to the next line.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
uint8_t dbReadInt(void)
Read a decimal character from USARTx and convert it to a uint8_t value.
volatile bool dataReceived
static uint32_t charDec_to_uint32(char *buf)
Convert a string (char array) in decimal notation to a uint32_t value.
void dbprintlnInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx and go to the next line.
volatile char rx_buffer[80]
static void uint32_to_charDec(char *buf, uint32_t value)
Convert a uint32_t value to a decimal char array (string).
void dbcritInt_hex(char *message1, int32_t value, char *message2)
Print a critical value surrounded by two strings (char array) to USARTx.
void USART1_TX_IRQHandler(void)
USART1 TX interrupt service routine.
USART_TypeDef * dbpointer
char dbReadChar(void)
Read a character from USARTx.
void dbClear(void)
Clear the terminal.
void dbprint_INIT(USART_TypeDef *pointer, uint8_t location, bool vcom, bool interrupts)
Initialize USARTx.
void USART1_RX_IRQHandler(void)
USART1 RX interrupt service routine.
#define DBPRINT_BUFFER_SIZE
Enable or disable printing to UART with dbprint.
void USART0_TX_IRQHandler(void)
USART0 TX interrupt service routine.
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
bool dbGet_RXstatus(void)
Check if data was received using interrupts in the RX buffer.
void dbprintInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx.
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.
void dbReadLine(char *buf)
Read a string (char array) from USARTx.
void dbGet_RXbuffer(char *buf)
Get the value of the RX buffer and clear the dataReceived flag.
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
static void uint32_to_charHex(char *buf, uint32_t value, bool spacing)
Convert a uint32_t value to a hexadecimal char array (string).
void USART0_RX_IRQHandler(void)
USART0 RX interrupt service routine.
void dbprint_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color.