Skip to content

Commit

Permalink
Add __UNALIGNED_UINT64_READ/WRITE
Browse files Browse the repository at this point in the history
Extend unaligned access support macros to cover 64-bit accesses.
  • Loading branch information
kjbracey committed Dec 16, 2019
1 parent c9d4a4a commit 4d48ba1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CMSIS/Core/Include/cmsis_armcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
#ifndef __UNALIGNED_UINT32_READ
#define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
#endif
#ifndef __UNALIGNED_UINT64_WRITE
#define __UNALIGNED_UINT64_WRITE(addr, val) ((*((__packed uint64_t *)(addr))) = (val))
#endif
#ifndef __UNALIGNED_UINT64_READ
#define __UNALIGNED_UINT64_READ(addr) (*((const __packed uint64_t *)(addr)))
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
Expand Down
16 changes: 16 additions & 0 deletions CMSIS/Core/Include/cmsis_armclang.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@
#pragma clang diagnostic pop
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT64_WRITE
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpacked"
/*lint -esym(9058, T_UINT64_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT64_WRITE */
__PACKED_STRUCT T_UINT64_WRITE { uint64_t v; };
#pragma clang diagnostic pop
#define __UNALIGNED_UINT64_WRITE(addr, val) (void)((((struct T_UINT64_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT64_READ
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpacked"
/*lint -esym(9058, T_UINT64_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT64_READ */
__PACKED_STRUCT T_UINT64_READ { uint64_t v; };
#pragma clang diagnostic pop
#define __UNALIGNED_UINT64_READ(addr) (((const struct T_UINT64_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
Expand Down
16 changes: 16 additions & 0 deletions CMSIS/Core/Include/cmsis_armclang_ltm.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@
#pragma clang diagnostic pop
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT64_WRITE
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpacked"
/*lint -esym(9058, T_UINT64_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT64_WRITE */
__PACKED_STRUCT T_UINT64_WRITE { uint64_t v; };
#pragma clang diagnostic pop
#define __UNALIGNED_UINT64_WRITE(addr, val) (void)((((struct T_UINT64_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT64_READ
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpacked"
/*lint -esym(9058, T_UINT64_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT64_READ */
__PACKED_STRUCT T_UINT64_READ { uint64_t v; };
#pragma clang diagnostic pop
#define __UNALIGNED_UINT64_READ(addr) (((const struct T_UINT64_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
Expand Down
24 changes: 24 additions & 0 deletions CMSIS/Core/Include/cmsis_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT64_WRITE
__PACKED_STRUCT T_UINT64_WRITE { uint64_t v; };
#define __UNALIGNED_UINT64_WRITE(addr, val) (void)((((struct T_UINT64_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT64_READ
__PACKED_STRUCT T_UINT64_READ { uint64_t v; };
#define __UNALIGNED_UINT64_READ(addr) (((const struct T_UINT64_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
Expand Down Expand Up @@ -189,6 +197,14 @@
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT64_WRITE
__PACKED_STRUCT T_UINT64_WRITE { uint64_t v; };
#define __UNALIGNED_UINT64_WRITE(addr, val) (void)((((struct T_UINT64_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT64_READ
__PACKED_STRUCT T_UINT64_READ { uint64_t v; };
#define __UNALIGNED_UINT64_READ(addr) (((const struct T_UINT64_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __align(x)
#endif
Expand Down Expand Up @@ -260,6 +276,14 @@
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT64_WRITE
__PACKED_STRUCT T_UINT64_WRITE { uint64_t v; };
#define __UNALIGNED_UINT64_WRITE(addr, val) (void)((((struct T_UINT64_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT64_READ
__PACKED_STRUCT T_UINT64_READ { uint64_t v; };
#define __UNALIGNED_UINT64_READ(addr) (((const struct T_UINT64_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
#define __ALIGNED(x)
Expand Down
16 changes: 16 additions & 0 deletions CMSIS/Core/Include/cmsis_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@
#pragma GCC diagnostic pop
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT64_WRITE
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpacked"
#pragma GCC diagnostic ignored "-Wattributes"
__PACKED_STRUCT T_UINT64_WRITE { uint64_t v; };
#pragma GCC diagnostic pop
#define __UNALIGNED_UINT64_WRITE(addr, val) (void)((((struct T_UINT64_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT64_READ
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpacked"
#pragma GCC diagnostic ignored "-Wattributes"
__PACKED_STRUCT T_UINT64_READ { uint64_t v; };
#pragma GCC diagnostic pop
#define __UNALIGNED_UINT64_READ(addr) (((const struct T_UINT64_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
Expand Down
26 changes: 24 additions & 2 deletions CMSIS/Core/Include/cmsis_iccarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ __IAR_FT uint16_t __iar_uint16_read(void const *ptr)
#pragma language=extended
__IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
{
*(__packed uint16_t*)(ptr) = val;;
*(__packed uint16_t*)(ptr) = val;
}
#pragma language=restore
#define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
Expand All @@ -214,7 +214,7 @@ __IAR_FT uint32_t __iar_uint32_read(void const *ptr)
#pragma language=extended
__IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
{
*(__packed uint32_t*)(ptr) = val;;
*(__packed uint32_t*)(ptr) = val;
}
#pragma language=restore
#define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
Expand All @@ -228,6 +228,28 @@ __packed struct __iar_u32 { uint32_t v; };
#define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
#endif

#ifndef __UNALIGNED_UINT64_READ
#pragma language=save
#pragma language=extended
__IAR_FT uint64_t __iar_uint64_read(void const *ptr)
{
return *(__packed uint64_t*)(ptr);
}
#pragma language=restore
#define __UNALIGNED_UINT64_READ(PTR) __iar_uint64_read(PTR)
#endif

#ifndef __UNALIGNED_UINT64_WRITE
#pragma language=save
#pragma language=extended
__IAR_FT void __iar_uint64_write(void const *ptr, uint64_t val)
{
*(__packed uint64_t*)(ptr) = val;
}
#pragma language=restore
#define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
#endif

#ifndef __USED
#if __ICCARM_V8
#define __USED __attribute__((used))
Expand Down

0 comments on commit 4d48ba1

Please sign in to comment.