1.1 --- a/debug.c Fri Oct 19 17:50:59 2018 +0200
1.2 +++ b/debug.c Fri Oct 19 18:05:07 2018 +0200
1.3 @@ -20,7 +20,7 @@
1.4 #include "pic32_c.h"
1.5 #include "debug.h"
1.6
1.7 -/* Value output functions. */
1.8 +/* Value output functions using UART1. */
1.9
1.10 void bits(uint32_t reg)
1.11 {
1.12 @@ -59,13 +59,39 @@
1.13 uart_write('\n');
1.14 }
1.15
1.16 -/* General output functions. */
1.17 +
1.18 +
1.19 +/* General input/output functions. */
1.20 +
1.21 +int uart_can_read(int uart)
1.22 +{
1.23 + return REG(UART_REG(uart, UxSTA)) & 1;
1.24 +}
1.25 +
1.26 +char uart_read_char(int uart)
1.27 +{
1.28 + return (char) REG(UART_REG(uart, UxRXREG));
1.29 +}
1.30 +
1.31 +int uart_can_write(int uart)
1.32 +{
1.33 + return !(REG(UART_REG(uart, UxSTA)) & (1 << 9)); /* UTXBF (buffer full) */
1.34 +}
1.35 +
1.36 +void uart_write_char(int uart, char c)
1.37 +{
1.38 + while (!uart_can_write(uart)); /* busy loop */
1.39 +
1.40 + REG(UART_REG(uart, UxTXREG)) = c;
1.41 +}
1.42 +
1.43 +
1.44 +
1.45 +/* Functions using UART1. */
1.46
1.47 void uart_write(char c)
1.48 {
1.49 - while (REG(UART_REG(1, UxSTA)) & (1 << 9)); /* UTXBF (buffer full) */
1.50 -
1.51 - REG(UART_REG(1, UxTXREG)) = c;
1.52 + uart_write_char(1, c);
1.53 }
1.54
1.55 void uart_write_string(const char *s)