From 5beceaae5c57dcf1b92d1def5954ac331a19a63a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 23 Jan 2017 11:13:19 -0500 Subject: [PATCH] io.h: read/write[bwl] should use barrier Add barrier() calls to low-level read/write io calls so that their callers don't need to. Signed-off-by: Kevin O'Connor --- src/avr/serial.c | 3 --- src/generic/io.h | 16 +++++++++++++--- src/sam3x8e/serial.c | 3 --- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/avr/serial.c b/src/avr/serial.c index 0b5fea1f..32619ecc 100644 --- a/src/avr/serial.c +++ b/src/avr/serial.c @@ -126,12 +126,10 @@ console_get_output(uint8_t len) return NULL; // Disable TX irq and move buffer writeb(&transmit_max, 0); - barrier(); tpos = readb(&transmit_pos); tmax -= tpos; memmove(&transmit_buf[0], &transmit_buf[tpos], tmax); writeb(&transmit_pos, 0); - barrier(); writeb(&transmit_max, tmax); enable_tx_irq(); return &transmit_buf[tmax]; @@ -141,7 +139,6 @@ console_get_output(uint8_t len) void console_push_output(uint8_t len) { - barrier(); writeb(&transmit_max, readb(&transmit_max) + len); enable_tx_irq(); } diff --git a/src/generic/io.h b/src/generic/io.h index 2a16cf20..12bbd489 100644 --- a/src/generic/io.h +++ b/src/generic/io.h @@ -2,24 +2,34 @@ #define __GENERIC_IO_H #include // uint32_t +#include "compiler.h" // barrier static inline void writel(void *addr, uint32_t val) { + barrier(); *(volatile uint32_t *)addr = val; } static inline void writew(void *addr, uint16_t val) { + barrier(); *(volatile uint16_t *)addr = val; } static inline void writeb(void *addr, uint8_t val) { + barrier(); *(volatile uint8_t *)addr = val; } static inline uint32_t readl(const void *addr) { - return *(volatile const uint32_t *)addr; + uint32_t val = *(volatile const uint32_t *)addr; + barrier(); + return val; } static inline uint16_t readw(const void *addr) { - return *(volatile const uint16_t *)addr; + uint16_t val = *(volatile const uint16_t *)addr; + barrier(); + return val; } static inline uint8_t readb(const void *addr) { - return *(volatile const uint8_t *)addr; + uint8_t val = *(volatile const uint8_t *)addr; + barrier(); + return val; } #endif // io.h diff --git a/src/sam3x8e/serial.c b/src/sam3x8e/serial.c index a14f97fb..3532d5f3 100644 --- a/src/sam3x8e/serial.c +++ b/src/sam3x8e/serial.c @@ -131,12 +131,10 @@ console_get_output(uint8_t len) return NULL; // Disable TX irq and move buffer writeb(&transmit_max, 0); - barrier(); tpos = readb(&transmit_pos); tmax -= tpos; memmove(&transmit_buf[0], &transmit_buf[tpos], tmax); writeb(&transmit_pos, 0); - barrier(); writeb(&transmit_max, tmax); enable_tx_irq(); return &transmit_buf[tmax]; @@ -146,7 +144,6 @@ console_get_output(uint8_t len) void console_push_output(uint8_t len) { - barrier(); writeb(&transmit_max, readb(&transmit_max) + len); enable_tx_irq(); }