summaryrefslogtreecommitdiffstats
path: root/app/usart.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/usart.c')
-rw-r--r--app/usart.c55
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;
}