diff options
author | fishsoupisgood <github@madingley.org> | 2020-06-15 14:02:42 +0100 |
---|---|---|
committer | fishsoupisgood <github@madingley.org> | 2020-06-15 14:02:42 +0100 |
commit | 4ced1453cee7a3131459040efd57f73bfc77aece (patch) | |
tree | 78cbcbdcef4847b5b194cf65470ffb45a3e7a8e3 /app/usart.c | |
parent | d23934fedc0b76863fcb2ba653560e108309bce6 (diff) | |
download | robs_speedo-4ced1453cee7a3131459040efd57f73bfc77aece.tar.gz robs_speedo-4ced1453cee7a3131459040efd57f73bfc77aece.tar.bz2 robs_speedo-4ced1453cee7a3131459040efd57f73bfc77aece.zip |
guage code
Diffstat (limited to 'app/usart.c')
-rw-r--r-- | app/usart.c | 55 |
1 files changed, 24 insertions, 31 deletions
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; } |