source: trunk/software/firmware/serial2.c @ 12

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

Firmware for V2 boards

File size: 846 bytes
RevLine 
[11]1#include <pic18fregs.h>
2#include <stdio.h>
3#include <my_serial2.h>
4
5char uart2_txbuf[UART2_BUFSIZE];
6unsigned char uart2_txbuf_prod;
7volatile unsigned char uart2_txbuf_cons;
8
9char uart2_rxbuf[UART2_BUFSIZE];
10volatile unsigned char uart2_rxbuf_prod;
11unsigned char uart2_rxbuf_cons;
12
13void
14uart2_putchar_raw(char c)
15{
16        unsigned char new_uart2_txbuf_prod;
17        new_uart2_txbuf_prod = (uart2_txbuf_prod + 1) & UART2_BUFSIZE_MASK;
18        while (new_uart2_txbuf_prod == uart2_txbuf_cons) {
19                PIE3bits.TX2IE = 1; /* ensure we'll make progress */
20        }
21        uart2_txbuf[uart2_txbuf_prod] = c;
22        uart2_txbuf_prod = new_uart2_txbuf_prod;
23        PIE3bits.TX2IE = 1;
24}
25
26char
27uart2_getchar()
28{
29        register char c;
30        while (uart2_rxbuf_cons == uart2_rxbuf_prod)
31                ;
32
33        uart2_rxbuf_cons = (uart2_rxbuf_cons + 1) & UART2_BUFSIZE_MASK;
34        c = uart2_rxbuf[uart2_rxbuf_cons];
35        return c;
36}
Note: See TracBrowser for help on using the repository browser.