39 volatile char u2_tx_buf[UART2_TX_BUFFERSIZE];
40 volatile uint32_t u2_tx_head, u2_tx_tail;
42 #if UART2_RX_BUFFERSIZE > 32
43 volatile char u2_rx_buf[UART2_RX_BUFFERSIZE-32];
44 volatile uint32_t u2_rx_head, u2_rx_tail;
47 void uart2_isr(
void) {
49 #if UART2_RX_BUFFERSIZE > 32
50 if (*UART2_USTAT & ( 1 << 6)) {
51 while( *UART2_URXCON != 0 ) {
52 uint32_t u2_rx_tail_next;
53 u2_rx_tail_next = u2_rx_tail+1;
54 if (u2_rx_tail_next >=
sizeof(u2_rx_buf))
56 if (u2_rx_head != u2_rx_tail_next) {
57 u2_rx_buf[u2_rx_tail]= *UART2_UDATA;
58 u2_rx_tail = u2_rx_tail_next;
60 while (*UART2_URXCON !=0)
if (*UART2_UDATA);
67 while( *UART2_UTXCON != 0 ) {
68 if (u2_tx_head == u2_tx_tail) {
69 #if UART2_RX_BUFFERSIZE > 32
70 *UART2_UCON |= (1 << 13);
77 *UART2_UDATA = u2_tx_buf[u2_tx_tail];
79 if (u2_tx_tail >=
sizeof(u2_tx_buf))
84 void uart2_putc(
char c) {
87 #if UART2_RX_BUFFERSIZE > 32
88 *UART2_UCON |= (1 << 13);
93 if( (u2_tx_head == u2_tx_tail) &&
94 (*UART2_UTXCON != 0)) {
97 u2_tx_buf[u2_tx_head] = c;
99 if (u2_tx_head >=
sizeof(u2_tx_buf))
101 if (u2_tx_head == u2_tx_tail) {
103 if (u2_tx_head) { u2_tx_head -=1; }
else { u2_tx_head =
sizeof(u2_tx_buf); }
106 uint32_t u2_tx_tail_save=u2_tx_tail;
109 #if UART2_RX_BUFFERSIZE > 32
110 *UART2_UCON &= ~(1 << 13);
115 while (u2_tx_tail_save == u2_tx_tail) ;
123 #if UART2_RX_BUFFERSIZE > 32
124 *UART2_UCON &= ~(1 << 13);
132 uint8_t uart2_getc(
void) {
133 #if UART2_RX_BUFFERSIZE > 32
136 if (u2_rx_head != u2_rx_tail) {
137 c = u2_rx_buf[u2_rx_head++];
138 if (u2_rx_head >=
sizeof(u2_rx_buf))
144 while(uart2_can_get() == 0) {
continue; }