39 volatile char u1_tx_buf[UART1_TX_BUFFERSIZE];
40 volatile uint32_t u1_tx_head, u1_tx_tail;
42 #if UART1_RX_BUFFERSIZE > 32
43 volatile char u1_rx_buf[UART1_RX_BUFFERSIZE-32];
44 volatile uint32_t u1_rx_head, u1_rx_tail;
47 void uart1_isr(
void) {
49 #if UART1_RX_BUFFERSIZE > 32
50 if (*UART1_USTAT & ( 1 << 6)) {
51 while( *UART1_URXCON != 0 ) {
52 uint32_t u1_rx_tail_next;
53 u1_rx_tail_next = u1_rx_tail+1;
54 if (u1_rx_tail_next >=
sizeof(u1_rx_buf))
56 if (u1_rx_head != u1_rx_tail_next) {
57 u1_rx_buf[u1_rx_tail]= *UART1_UDATA;
58 u1_rx_tail = u1_rx_tail_next;
60 while (*UART1_URXCON !=0)
if (*UART1_UDATA);
67 while( *UART1_UTXCON != 0 ) {
68 if (u1_tx_head == u1_tx_tail) {
69 #if UART1_RX_BUFFERSIZE > 32
70 *UART1_UCON |= (1 << 13);
77 *UART1_UDATA = u1_tx_buf[u1_tx_tail];
79 if (u1_tx_tail >=
sizeof(u1_tx_buf))
84 void uart1_putc(
char c) {
87 #if UART1_RX_BUFFERSIZE > 32
88 *UART1_UCON |= (1 << 13);
93 if( (u1_tx_head == u1_tx_tail) &&
94 (*UART1_UTXCON != 0)) {
97 u1_tx_buf[u1_tx_head] = c;
99 if (u1_tx_head >=
sizeof(u1_tx_buf))
101 if (u1_tx_head == u1_tx_tail) {
103 if (u1_tx_head) { u1_tx_head -=1; }
else { u1_tx_head =
sizeof(u1_tx_buf); }
106 uint32_t u1_tx_tail_save=u1_tx_tail;
109 #if UART1_RX_BUFFERSIZE > 32
110 *UART1_UCON &= ~(1 << 13);
115 while (u1_tx_tail_save == u1_tx_tail) ;
123 #if UART1_RX_BUFFERSIZE > 32
124 *UART1_UCON &= ~(1 << 13);
132 uint8_t uart1_getc(
void) {
133 #if UART1_RX_BUFFERSIZE > 32
136 if (u1_rx_head != u1_rx_tail) {
137 c = u1_rx_buf[u1_rx_head++];
138 if (u1_rx_head >=
sizeof(u1_rx_buf))
144 while(uart1_can_get() == 0) {
continue; }