123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- #if !defined(CY_UTILS_H)
- #define CY_UTILS_H
- #if defined(__cplusplus)
- extern "C" {
- #endif
- #define CY_UNUSED_PARAMETER(x) ( (void)(x) )
- static inline void CY_HALT(void)
- {
- __asm(" bkpt 1");
- }
- #ifdef CY_ASSERT
- #undef CY_ASSERT
- #endif
- #if defined(NDEBUG) || defined(CY_NO_ASSERT)
- #define CY_ASSERT(x) do { \
- } while(0)
- #else
- #define CY_ASSERT(x) do { \
- if(!(x)) \
- { \
- CY_HALT(); \
- } \
- } while(0)
- #endif
- #define CY_LO8(x) ((uint8_t) ((x) & 0xFFU))
- #define CY_HI8(x) ((uint8_t) ((uint16_t)(x) >> 8U))
- #define CY_LO16(x) ((uint16_t) ((x) & 0xFFFFU))
- #define CY_HI16(x) ((uint16_t) ((uint32_t)(x) >> 16U))
- #define CY_SWAP_ENDIAN16(x) ((uint16_t)(((x) << 8U) | (((x) >> 8U) & 0x00FFU)))
- #define CY_SWAP_ENDIAN32(x) ((uint32_t)((((x) >> 24U) & 0x000000FFU) | (((x) & 0x00FF0000U) >> 8U) | \
- (((x) & 0x0000FF00U) << 8U) | ((x) << 24U)))
- #define CY_SWAP_ENDIAN64(x) ((uint64_t) (((uint64_t) CY_SWAP_ENDIAN32((uint32_t)(x)) << 32U) | \
- CY_SWAP_ENDIAN32((uint32_t)((x) >> 32U))))
- #if defined(__ARMCC_VERSION)
-
- #if (__ARMCC_VERSION >= 6010050)
- #define CY_NOINIT __attribute__ ((section(".noinit")))
- #else
- #define CY_NOINIT __attribute__ ((section(".noinit"), zero_init))
- #endif
- #define CY_SECTION(name) __attribute__ ((section(name)))
- #define CY_UNUSED __attribute__ ((unused))
- #define CY_NOINLINE __attribute__ ((noinline))
-
- #define CY_ALIGN(align) __ALIGNED(align)
- #define CY_RAMFUNC_BEGIN __attribute__ ((section(".cy_ramfunc")))
- #define CY_RAMFUNC_END
- #elif defined (__GNUC__)
- #if defined (__clang__)
- #define CY_NOINIT __attribute__ ((section("__DATA, __noinit")))
- #define CY_SECTION(name) __attribute__ ((section("__DATA, "name)))
- #define CY_RAMFUNC_BEGIN __attribute__ ((section("__DATA, .cy_ramfunc")))
- #define CY_RAMFUNC_END
- #else
- #define CY_NOINIT __attribute__ ((section(".noinit")))
- #define CY_SECTION(name) __attribute__ ((section(name)))
- #define CY_RAMFUNC_BEGIN __attribute__ ((section(".cy_ramfunc")))
- #define CY_RAMFUNC_END
- #endif
-
- #define CY_UNUSED __attribute__ ((unused))
- #define CY_NOINLINE __attribute__ ((noinline))
- #define CY_ALIGN(align) __ALIGNED(align)
- #elif defined (__ICCARM__)
- #define CY_PRAGMA(x) _Pragma(#x)
- #define CY_NOINIT __no_init
- #define CY_SECTION(name) CY_PRAGMA(location = name)
- #define CY_UNUSED
- #define CY_NOINLINE CY_PRAGMA(optimize = no_inline)
- #define CY_RAMFUNC_BEGIN CY_PRAGMA(diag_suppress = Ta023) __ramfunc
- #define CY_RAMFUNC_END CY_PRAGMA(diag_default = Ta023)
- #if (__VER__ < 8010001)
- #define CY_ALIGN(align) CY_PRAGMA(data_alignment = align)
- #else
- #define CY_ALIGN(align) __ALIGNED(align)
- #endif
- #else
- #error "An unsupported toolchain"
- #endif
- #define CY_GET_REG8(addr) (*((const volatile uint8_t *)(addr)))
- #define CY_SET_REG8(addr, value) (*((volatile uint8_t *)(addr)) = (uint8_t)(value))
- #define CY_GET_REG16(addr) (*((const volatile uint16_t *)(addr)))
- #define CY_SET_REG16(addr, value) (*((volatile uint16_t *)(addr)) = (uint16_t)(value))
- #define CY_GET_REG24(addr) (((uint32_t) (*((const volatile uint8_t *)(addr)))) | \
- (((uint32_t) (*((const volatile uint8_t *)(addr) + 1))) << 8U) | \
- (((uint32_t) (*((const volatile uint8_t *)(addr) + 2))) << 16U))
- #define CY_SET_REG24(addr, value) do \
- { \
- (*((volatile uint8_t *) (addr))) = (uint8_t)(value); \
- (*((volatile uint8_t *) (addr) + 1)) = (uint8_t)((value) >> 8U); \
- (*((volatile uint8_t *) (addr) + 2)) = (uint8_t)((value) >> 16U); \
- } \
- while(0)
- #define CY_GET_REG32(addr) (*((const volatile uint32_t *)(addr)))
- #define CY_SET_REG32(addr, value) (*((volatile uint32_t *)(addr)) = (uint32_t)(value))
- #define _CLR_SET_FLD32U(reg, field, value) (((reg) & ((uint32_t)(~(field ## _Msk)))) | (_VAL2FLD(field, value)))
- #define CY_REG32_CLR_SET(reg, field, value) ((reg) = _CLR_SET_FLD32U((reg), field, (value)))
- #define _CLR_SET_FLD16U(reg, field, value) ((uint16_t)(((reg) & ((uint16_t)(~(field ## _Msk)))) | \
- ((uint16_t)_VAL2FLD(field, value))))
-
-
- #define CY_REG16_CLR_SET(reg, field, value) ((reg) = _CLR_SET_FLD16U((reg), field, (value)))
- #define _CLR_SET_FLD8U(reg, field, value) ((uint8_t)(((reg) & ((uint8_t)(~(field ## _Msk)))) | \
- ((uint8_t)_VAL2FLD(field, value))))
-
-
- #define CY_REG8_CLR_SET(reg, field, value) ((reg) = _CLR_SET_FLD8U((reg), field, (value)))
- #define _BOOL2FLD(field, value) (((value) != false) ? (field ## _Msk) : 0UL)
- #define _FLD2BOOL(field, value) (((value) & (field ## _Msk)) != 0UL)
- #define CY_SYSLIB_DIV_ROUND(a, b) (((a) + ((b) / 2U)) / (b))
- #define CY_SYSLIB_DIV_ROUNDUP(a, b) ((((a) - 1U) / (b)) + 1U)
- #ifdef __cplusplus
- }
- #endif
- #endif
|