Line | |
---|
1 | |
---|
2 | char getchar(void); |
---|
3 | |
---|
4 | #define UART2_BUFSIZE 16 |
---|
5 | #define UART2_BUFSIZE_MASK 0x0f |
---|
6 | |
---|
7 | extern char uart2_txbuf[UART2_BUFSIZE]; |
---|
8 | extern unsigned char uart2_txbuf_prod; |
---|
9 | extern volatile unsigned char uart2_txbuf_cons; |
---|
10 | |
---|
11 | extern char uart2_rxbuf[UART2_BUFSIZE]; |
---|
12 | extern volatile unsigned char uart2_rxbuf_prod; |
---|
13 | extern unsigned char uart2_rxbuf_cons; |
---|
14 | |
---|
15 | char uart2_getchar(void); |
---|
16 | void 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.