source: trunk/software/firmware/my_serial2.h @ 11

Last change on this file since 11 was 11, checked in by bouyer, 5 years ago

Firmware for V2 boards

File size: 1.2 KB
Line 
1
2char getchar(void);
3
4#define UART2_BUFSIZE 16
5#define UART2_BUFSIZE_MASK 0x0f
6
7extern char uart2_txbuf[UART2_BUFSIZE];
8extern unsigned char uart2_txbuf_prod;
9extern volatile unsigned char uart2_txbuf_cons;
10
11extern char uart2_rxbuf[UART2_BUFSIZE];
12extern volatile unsigned char uart2_rxbuf_prod;
13extern unsigned char uart2_rxbuf_cons;
14
15char uart2_getchar(void);
16void uart2_putchar_raw(char);
17
18#define USART2_INIT { \
19                uart2_txbuf_prod = uart2_txbuf_cons = 0; \
20                uart2_rxbuf_prod = uart2_rxbuf_cons = 0; \
21                (void)RCREG2; \
22                PIE3bits.RC2IE = 1; \
23        }
24
25#define USART2_INTR {\
26        if (PIE3bits.TX2IE && PIR3bits.TX2IF) { \
27                if (uart2_txbuf_prod == uart2_txbuf_cons) { \
28                        PIE3bits.TX2IE = 0; /* buffer empty */ \
29                } else { \
30                        /* Place char in TXREG - this starts transmition */ \
31                        TXREG2 = uart2_txbuf[uart2_txbuf_cons]; \
32                        uart2_txbuf_cons = (uart2_txbuf_cons + 1) & UART2_BUFSIZE_MASK;\
33                } \
34        } \
35        if (PIE3bits.RC2IE && PIR3bits.RC2IF) { \
36                register char c = RCREG2; \
37                if (RCSTA2bits.OERR) { \
38                        RCSTA2bits.CREN = 0; \
39                        RCSTA2bits.CREN = 1; \
40                } \
41                uart2_rxbuf_prod = (uart2_rxbuf_prod + 1) & UART2_BUFSIZE_MASK;\
42                uart2_rxbuf[uart2_rxbuf_prod] = c; \
43        }\
44    }
Note: See TracBrowser for help on using the repository browser.