OSDN Git Service

11/11/30 12H serial csv out.
[scilog/cpu2010.git] / myuart.c
1 #include <p24FJ64GA004.h>
2 #include "myuart.h"
3
4 // ublox GPS受信用リングバッファ
5 static unsigned char   ubx_w, ubx_r;
6 static unsigned char    ubx_buf[256];
7
8 void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void)
9 {
10     // 割り込みフラグクリア
11     uart1_rx_intf_clear();
12     while(uart1_rx_is_rdy()) {
13         ubx_buf[ubx_w++] = uart1_getc();
14     }
15     if (U1STAbits.OERR == 1) U1STAbits.OERR = 0;
16 }
17 void uart1_puts(char *s)
18 {
19     while(*s != 0) {
20         while(uart1_tx_is_full());
21         U1TXREG = *s++;
22     }
23 }
24 void uart2_puts(char *s)
25 {
26     while(*s != 0) {
27         while(uart2_tx_is_full());
28         U2TXREG = *s++;
29     }
30 }
31 /*
32 return 0=なし 1=あり
33  */
34 int uart1_rcvbuf_is_data(void)
35 {
36     if (ubx_r == ubx_w) return 0;
37     return 1;
38 }
39 /*
40  return データ -1=データ無し
41  */
42 int uart1_rcvbuf_getc(void)
43 {
44     if (ubx_r == ubx_w) return -1;
45     return ubx_buf[ubx_r++];
46 }
47
48 void uart1_rcvbuf_clear(void)
49 {
50     ubx_r = ubx_w;
51 }
52
53 void uart1_init(unsigned int mode, unsigned int sts, unsigned int baud)
54 {
55     U1MODE = mode;
56     U1STA = sts;
57     U1BRG = baud;
58     ubx_w = 0;
59     ubx_r = 0;
60 }
61 void uart2_init(unsigned int mode, unsigned int sts, unsigned int baud)
62 {
63     U2MODE = mode;
64     U2STA = sts;
65     U2BRG = baud;
66 }