diff options
| author | Keith Packard <keithp@keithp.com> | 2016-12-17 20:58:36 -0800 |
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2017-01-25 12:21:43 -0700 |
| commit | fe25510fc23031f1a3c1b42edd37067d1989a9f6 (patch) | |
| tree | 3cdc98d2c3d1c8d9bd95045771be7d15226d246b /src/drivers/ao_gps_ublox.c | |
| parent | 4163d88ed36ce8863218366f1fb504f7061a4ca5 (diff) | |
altos/arm: Align data so that gcc 5.4 doesn't do byte-accesses. Add -Wcast-align
Gcc 5.4.1 tracks alignment of data through assignments, so that a
uint32_t pointer which comes from byte-aligned uint8_t data:
extern uint8_t foo[];
uint32_t *q = (void *) foo;
Fetches and stores through this pointer are done bytewise. This is
slow (meh), but if q references a device register, things to bad very
quickly.
This patch works around this bug in the compiler by adding
__attribute__((aligned(4))) tags to some variables, or changing them
from uint8_t to uint32_t. Places doing this will now be caught as I've
added -Wcast-align to the compiler flags. That required adding (void
*) casts, after the relevant code was checked to make sure the
compiler could tell that the addresses were aligned.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/drivers/ao_gps_ublox.c')
| -rw-r--r-- | src/drivers/ao_gps_ublox.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/drivers/ao_gps_ublox.c b/src/drivers/ao_gps_ublox.c index 22af413a..c720f802 100644 --- a/src/drivers/ao_gps_ublox.c +++ b/src/drivers/ao_gps_ublox.c @@ -156,7 +156,7 @@ static char __xdata *ublox_target; static void ublox_u16(uint8_t offset) { - uint16_t __xdata *ptr = (uint16_t __xdata *) (ublox_target + offset); + uint16_t __xdata *ptr = (uint16_t __xdata *) (void __xdata *) (ublox_target + offset); uint16_t val; val = data_byte(); @@ -175,7 +175,7 @@ static void ublox_u8(uint8_t offset) static void ublox_u32(uint8_t offset) __reentrant { - uint32_t __xdata *ptr = (uint32_t __xdata *) (ublox_target + offset); + uint32_t __xdata *ptr = (uint32_t __xdata *) (void __xdata *) (ublox_target + offset); uint32_t val; val = ((uint32_t) data_byte ()); |
