1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/debug.c Thu Oct 18 18:36:19 2018 +0200
1.3 @@ -0,0 +1,50 @@
1.4 +#include "pic32_c.h"
1.5 +#include "debug.h"
1.6 +
1.7 +/* Value output functions. */
1.8 +
1.9 +void bits(uint32_t reg)
1.10 +{
1.11 + vbits(REG(reg));
1.12 +}
1.13 +
1.14 +void vbits(uint32_t val)
1.15 +{
1.16 + uint32_t mask;
1.17 +
1.18 + for (mask = (1 << 31); mask; mask >>= 1)
1.19 + if (val & mask)
1.20 + uart_write('1');
1.21 + else
1.22 + uart_write('0');
1.23 +
1.24 + uart_write('\r');
1.25 + uart_write('\n');
1.26 +}
1.27 +
1.28 +void vhex(uint32_t val)
1.29 +{
1.30 + uint32_t mask;
1.31 + uint8_t digit, shift;
1.32 +
1.33 + for (mask = (0b1111 << 28), shift = 28; mask; mask >>= 4, shift -= 4)
1.34 + {
1.35 + digit = (val & mask) >> shift;
1.36 + if (digit > 9)
1.37 + uart_write('A' + digit - 10);
1.38 + else
1.39 + uart_write('0' + digit);
1.40 + }
1.41 +
1.42 + uart_write('\r');
1.43 + uart_write('\n');
1.44 +}
1.45 +
1.46 +/* General output functions. */
1.47 +
1.48 +void uart_write(char c)
1.49 +{
1.50 + while (REG(UART_REG(1, UxSTA)) & (1 << 9)); /* UTXBF (buffer full) */
1.51 +
1.52 + REG(UART_REG(1, UxTXREG)) = c;
1.53 +}