source: trunk/software/firmware/serial.c @ 8

Last change on this file since 8 was 1, checked in by bouyer, 7 years ago

Initial commit of soc-conso files

File size: 980 bytes
Line 
1#include <pic18fregs.h>
2#include <stdio.h>
3#include <my_serial.h>
4
5char uart_txbuf[UART_BUFSIZE];
6unsigned char uart_txbuf_prod;
7volatile unsigned char uart_txbuf_cons;
8
9PUTCHAR(c) /* Macro */
10{
11        unsigned char new_uart_txbuf_prod;
12#if 0
13        if  (!PORTBbits.RB7)
14                return;
15#endif
16        new_uart_txbuf_prod = (uart_txbuf_prod + 1) & UART_BUFSIZE_MASK;
17#if 1
18
19again:
20        while (new_uart_txbuf_prod == uart_txbuf_cons) {
21                PIE1bits.TX1IE = 1; /* ensure we'll make progress */
22        }
23        uart_txbuf[uart_txbuf_prod] = c;
24        uart_txbuf_prod = new_uart_txbuf_prod;
25        PIE1bits.TX1IE = 1;
26        if (c == '\n') {
27                c = '\r';
28                new_uart_txbuf_prod = (uart_txbuf_prod + 1) & UART_BUFSIZE_MASK;
29                goto again;
30        }
31#else
32again:
33        while (!PIR1bits.TX1IF)
34                ; /* wait */
35        TXREG1 = c;
36        if (c == '\n') {
37                c = '\r';
38                goto again;
39        }
40#endif
41}
42
43char
44getchar(void)
45{
46        char c;
47        while (!PIR1bits.RC1IF); /* wait for a char */
48        c = RCREG1;
49        if (RCSTA1bits.OERR) {
50                RCSTA1bits.CREN = 0;
51                RCSTA1bits.CREN = 1;
52        }
53        return c;
54}
Note: See TracBrowser for help on using the repository browser.