Changeset 11 for trunk/software/firmware/serial.c
- Timestamp:
- Jul 31, 2019, 5:43:21 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/firmware/serial.c
r1 r11 6 6 unsigned char uart_txbuf_prod; 7 7 volatile unsigned char uart_txbuf_cons; 8 9 char uart_rxbuf[UART_BUFSIZE]; 10 volatile unsigned char uart_rxbuf_prod; 11 unsigned char uart_rxbuf_cons; 12 13 #define LEDR LATAbits.LATA7 8 14 9 15 PUTCHAR(c) /* Macro */ … … 41 47 } 42 48 49 void 50 uart_putchar_raw(char c) 51 { 52 unsigned char new_uart_txbuf_prod; 53 new_uart_txbuf_prod = (uart_txbuf_prod + 1) & UART_BUFSIZE_MASK; 54 while (new_uart_txbuf_prod == uart_txbuf_cons) { 55 PIE1bits.TX1IE = 1; /* ensure we'll make progress */ 56 } 57 uart_txbuf[uart_txbuf_prod] = c; 58 uart_txbuf_prod = new_uart_txbuf_prod; 59 PIE1bits.TX1IE = 1; 60 } 61 62 void 63 uart_putchar_hard(char c) __wparam { 64 while (PIR1bits.TX1IF == 0) 65 ; 66 TXREG1 = c; 67 } 68 43 69 char 44 70 getchar(void) 45 71 { 46 72 char c; 73 char en; 74 en = PIE1bits.RC1IE; 75 PIE1bits.RC1IE = 0; 47 76 while (!PIR1bits.RC1IF); /* wait for a char */ 48 77 c = RCREG1; … … 51 80 RCSTA1bits.CREN = 1; 52 81 } 82 PIE1bits.RC1IE = en; 53 83 return c; 54 84 } 85 86 char 87 uart_getchar() 88 { 89 register char c; 90 LEDR = 1; 91 while (uart_rxbuf_cons == uart_rxbuf_prod) 92 ; 93 94 uart_rxbuf_cons = (uart_rxbuf_cons + 1) & UART_BUFSIZE_MASK; 95 c = uart_rxbuf[uart_rxbuf_cons]; 96 LEDR = 0; 97 return c; 98 }
Note: See TracChangeset
for help on using the changeset viewer.