1 #include <p24FJ64GA004.h>
4 // UART1 ublox GPS受信用リングバッファ
5 static unsigned char ubx_w, ubx_r;
6 static unsigned char ubx_buf[256];
9 #define UART2_BUFF_SIZE 16
10 static unsigned char uart2_w, uart2_r;
11 static unsigned char uart2_buf[UART2_BUFF_SIZE];
13 void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void)
16 uart1_rx_intf_clear();
17 while(uart1_rx_is_rdy()) {
18 ubx_buf[ubx_w++] = uart1_getc();
20 if (U1STAbits.OERR == 1) U1STAbits.OERR = 0;
22 void __attribute__((interrupt, no_auto_psv)) _U2RXInterrupt(void)
25 uart2_rx_intf_clear();
26 while(uart2_rx_is_rdy()) {
27 uart2_buf[uart2_w++] = uart2_getc();
28 if (uart2_w >= UART2_BUFF_SIZE) uart2_w = 0;
30 if (U2STAbits.OERR == 1) U2STAbits.OERR = 0;
33 void uart1_puts(char *s)
36 while(uart1_tx_is_full());
40 void uart2_puts(char *s)
43 while(uart2_tx_is_full());
47 void uart1_myputc(char c)
49 while(uart1_tx_is_full());
52 void uart2_myputc(char c)
54 while(uart2_tx_is_full());
61 int uart1_rcvbuf_is_data(void)
63 if (ubx_r == ubx_w) return 0;
66 int uart2_rcvbuf_is_data(void)
68 if (uart2_r == uart2_w) return 0;
75 int uart1_rcvbuf_getc(void)
77 if (ubx_r == ubx_w) return -1;
78 return ubx_buf[ubx_r++];
80 int uart2_rcvbuf_getc(void)
83 if (uart2_r == uart2_w) return -1;
84 out = uart2_buf[uart2_r++];
85 if (uart2_r >= UART2_BUFF_SIZE) uart2_r = 0;
89 void uart1_rcvbuf_clear(void)
94 void uart2_rcvbuf_clear(void)
98 void uart1_init(unsigned int mode, unsigned int sts, unsigned int baud)
106 void uart2_init(unsigned int mode, unsigned int sts, unsigned int baud)