From 4ced1453cee7a3131459040efd57f73bfc77aece Mon Sep 17 00:00:00 2001 From: fishsoupisgood Date: Mon, 15 Jun 2020 14:02:42 +0100 Subject: guage code --- app/usart.c | 55 ++++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'app/usart.c') diff --git a/app/usart.c b/app/usart.c index 163fe4f..8d98287 100644 --- a/app/usart.c +++ b/app/usart.c @@ -22,31 +22,25 @@ usart1_isr (void) /* Check if we were called because of RXNE. */ if (((USART_CR1 (USART1) & USART_CR1_RXNEIE) != 0) && - ((USART_SR (USART1) & USART_SR_RXNE) != 0)) - { + ((USART_SR (USART1) & USART_SR_RXNE) != 0)) { - /* Retrieve the data from the peripheral. */ - data = usart_recv (USART1); + /* Retrieve the data from the peripheral. */ + data = usart_recv (USART1); - ring_write_byte (&rx1_ring, data); - } + ring_write_byte (&rx1_ring, data); + } /* Check if we were called because of TXE. */ if (((USART_CR1 (USART1) & USART_CR1_TXEIE) != 0) && - ((USART_SR (USART1) & USART_SR_TXE) != 0)) - { - - if (ring_read_byte (&tx1_ring, &data)) - { - /*No more data, Disable the TXE interrupt, it's no longer needed. */ - USART_CR1 (USART1) &= ~USART_CR1_TXEIE; - } - else - { - usart_send (USART1, data); - } - } + ((USART_SR (USART1) & USART_SR_TXE) != 0)) { + + if (ring_read_byte (&tx1_ring, &data)) { + /*No more data, Disable the TXE interrupt, it's no longer needed. */ + USART_CR1 (USART1) &= ~USART_CR1_TXEIE; + } else + usart_send (USART1, data); + } } @@ -56,23 +50,22 @@ _write (int file, char *ptr, int len) { int ret; - if (file == 1) - { - ret = len; + if (file == 1) { + ret = len; - usart1_drain (); + usart1_drain(); - while (len--) - { - if (*ptr == '\n') - ring_write_byte (&tx1_ring, '\r'); - ring_write_byte (&tx1_ring, *(ptr++)); - } + while (len--) { + if (*ptr == '\n') + ring_write_byte (&tx1_ring, '\r'); - USART_CR1 (USART1) |= USART_CR1_TXEIE; - return ret; + ring_write_byte (&tx1_ring, * (ptr++)); } + USART_CR1 (USART1) |= USART_CR1_TXEIE; + return ret; + } + errno = EIO; return -1; } -- cgit v1.2.3