90 #if DEBUG_DBPRINT == 1 102 #define TO_HEX(i) (i <= 9 ? '0' + i : 'A' - 10 + i) 103 #define TO_DEC(i) (i <= 9 ? '0' + i : '?') 106 #define COLOR_RED "\x1b[31m" 107 #define COLOR_GREEN "\x1b[32m" 108 #define COLOR_BLUE "\x1b[34m" 109 #define COLOR_CYAN "\x1b[36m" 110 #define COLOR_MAGENTA "\x1b[35m" 111 #define COLOR_YELLOW "\x1b[33m" 112 #define COLOR_RESET "\x1b[0m" 150 void dbprint_INIT (USART_TypeDef* pointer, uint8_t location,
bool vcom,
bool interrupts)
172 USART_InitAsync_TypeDef config = USART_INITASYNC_DEFAULT;
175 CMU_ClockEnable(cmuClock_GPIO,
true);
181 CMU_ClockEnable(cmuClock_USART0,
true);
185 CMU_ClockEnable(cmuClock_USART1,
true);
192 GPIO_PinModeSet(gpioPortA, 9, gpioModePushPull, 1);
193 GPIO_PinOutSet(gpioPortA, 9);
203 GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 0);
204 GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 1);
207 GPIO_PinModeSet(gpioPortC, 10, gpioModeInput, 0);
211 GPIO_PinModeSet(gpioPortE, 12, gpioModeInput, 0);
212 GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 1);
215 GPIO_PinModeSet(gpioPortB, 8, gpioModeInput, 0);
216 GPIO_PinModeSet(gpioPortB, 7, gpioModePushPull, 1);
220 GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
221 GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
232 GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
233 GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
237 GPIO_PinModeSet(gpioPortD, 6, gpioModeInput, 0);
238 GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull, 1);
241 GPIO_PinModeSet(gpioPortA, 0, gpioModeInput, 0);
242 GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 1);
245 GPIO_PinModeSet(gpioPortC, 2, gpioModeInput, 0);
246 GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 1);
261 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
264 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC1;
267 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC2;
270 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC3;
273 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC4;
276 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC5;
279 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC6;
282 dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_DEFAULT;
292 USART_IntEnable(
dbpointer, USART_IEN_RXDATAV);
297 USART_IntEnable(
dbpointer, USART_IEN_TXC);
302 NVIC_EnableIRQ(USART0_RX_IRQn);
303 NVIC_EnableIRQ(USART0_TX_IRQn);
308 NVIC_EnableIRQ(USART1_RX_IRQn);
309 NVIC_EnableIRQ(USART1_TX_IRQn);
314 dbprintln(
"\a\r\f### UART initialized (interrupt mode) ###");
315 dbinfo(
"This is an info message.");
316 dbwarn(
"This is a warning message.");
317 dbcrit(
"This is a critical error message.");
318 dbprintln(
"### Start executing programmed code ###\n");
328 dbprintln(
"\a\r\f### UART initialized (no interrupts) ###");
329 dbinfo(
"This is an info message.");
330 dbwarn(
"This is a warning message.");
331 dbcrit(
"This is a critical error message.");
332 dbprintln(
"### Start executing programmed code ###\n");
379 for (uint32_t i = 0; message[i] != 0; i++)
569 void dbinfoInt (
char *message1, int32_t value,
char *message2)
600 void dbwarnInt (
char *message1, int32_t value,
char *message2)
631 void dbcritInt (
char *message1, int32_t value,
char *message2)
750 uint32_t negativeValue = (~value) + 1;
881 if (localBuffer ==
'\r')
889 buf[i] = localBuffer;
1039 dbcrit(
"No received data available!");
1066 if (value <= 0xFFFF)
1070 buf[0] =
TO_HEX(((value & 0xF000) >> 12));
1071 buf[1] =
TO_HEX(((value & 0x0F00) >> 8 ));
1072 buf[2] =
TO_HEX(((value & 0x00F0) >> 4 ));
1073 buf[3] =
TO_HEX( (value & 0x000F) );
1082 buf[0] =
TO_HEX(((value & 0xF0000000) >> 28));
1083 buf[1] =
TO_HEX(((value & 0x0F000000) >> 24));
1084 buf[2] =
TO_HEX(((value & 0x00F00000) >> 20));
1085 buf[3] =
TO_HEX(((value & 0x000F0000) >> 16));
1091 buf[5] =
TO_HEX(((value & 0x0000F000) >> 12));
1092 buf[6] =
TO_HEX(((value & 0x00000F00) >> 8 ));
1093 buf[7] =
TO_HEX(((value & 0x000000F0) >> 4 ));
1094 buf[8] =
TO_HEX( (value & 0x0000000F) );
1099 buf[4] =
TO_HEX(((value & 0x0000F000) >> 12));
1100 buf[5] =
TO_HEX(((value & 0x00000F00) >> 8 ));
1101 buf[6] =
TO_HEX(((value & 0x000000F0) >> 4 ));
1102 buf[7] =
TO_HEX( (value & 0x0000000F) );
1134 char backwardsBuf[10];
1136 uint32_t calcval = value;
1138 uint8_t lengthCounter = 0;
1144 uint32_t rem = calcval % 10;
1145 backwardsBuf[length] =
TO_DEC(rem);
1148 calcval = calcval - rem;
1149 calcval = calcval / 10;
1153 lengthCounter = length;
1156 for (uint8_t i = 0; i < length; i++)
1158 buf[i] = backwardsBuf[lengthCounter-1];
1195 uint8_t byte = *buf++;
1198 if ( (value <= 0xFFFFFFF) && ((byte -
'0') <= 0xF) )
1202 value = (value * 10) + (byte -
'0');
1284 static uint32_t i = 0;
1287 uint32_t flags = USART_IntGet(
dbpointer);
1324 static uint32_t i = 0;
1327 uint32_t flags = USART_IntGet(
dbpointer);
1331 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.