Core Library
Loading...
Searching...
No Matches
Utilities

General Description

Basic utility types, macros and functions.

Macros

#define CY_UNUSED_PARAMETER(x)
 Simple macro to suppress the unused parameter warning by casting to void.
#define CY_HALT()
 Halt the processor in the debug state.
#define CY_ASSERT_HANDLER()
 Default assert handler.
#define CY_ASSERT(x)
 Utility macro when neither NDEBUG or CY_NO_ASSERT is not declared to check a condition and, if false, trigger a breakpoint.
#define CY_ASSERT_AND_RETURN(condition, value)
 Assert an argument is true, else call assert handler and return a value.
#define CY_ASSERT_AND_RETURN_VOID(condition)
 Assert an argument is true, else call assert handler and return.
#define CY_SVC_CALL()
 SuperVisorCall macro.
#define CY_LO8(x)
 Get the lower 8 bits of a 16-bit value.
#define CY_HI8(x)
 Get the upper 8 bits of a 16-bit value.
#define CY_LO16(x)
 Get the lower 16 bits of a 32-bit value.
#define CY_HI16(x)
 Get the upper 16 bits of a 32-bit value.
#define CY_SWAP_ENDIAN16(x)
 Swap the byte ordering of a 16-bit value.
#define CY_SWAP_ENDIAN32(x)
 Swap the byte ordering of a 32-bit value.
#define CY_SWAP_ENDIAN64(x)
 Swap the byte ordering of a 64-bit value.
#define CY_GET_REG8(addr)
 Reads the 8-bit value from the specified address.
#define CY_SET_REG8(addr, value)
 Writes an 8-bit value to the specified address.
#define CY_GET_REG16(addr)
 Reads the 16-bit value from the specified address.
#define CY_SET_REG16(addr, value)
 Writes the 16-bit value to the specified address.
#define CY_GET_REG24(addr)
 Reads the 24-bit value from the specified address.
#define CY_SET_REG24(addr, value)
 Writes the 24-bit value to the specified address.
#define CY_GET_REG32(addr)
 Reads the 32-bit value from the specified register.
#define CY_SET_REG32(addr, value)
 Writes the 32-bit value to the specified register.
#define _CLR_SET_FLD32U(reg, field, value)
 The macro for setting a register with a name field and value for providing get-clear-modify-write operations.
#define CY_REG32_CLR_SET(reg, field, value)
 Uses _CLR_SET_FLD32U macro for providing get-clear-modify-write operations with a name field and value and writes a resulting value to the 32-bit register.
#define _CLR_SET_FLD16U(reg, field, value)
 The macro for setting a 16-bit register with a name field and value for providing get-clear-modify-write operations.
#define CY_REG16_CLR_SET(reg, field, value)
 Uses _CLR_SET_FLD16U macro for providing get-clear-modify-write operations with a name field and value and writes a resulting value to the 16-bit register.
#define _CLR_SET_FLD8U(reg, field, value)
 The macro for setting a 8-bit register with a name field and value for providing get-clear-modify-write operations.
#define CY_REG8_CLR_SET(reg, field, value)
 Uses _CLR_SET_FLD8U macro for providing get-clear-modify-write operations with a name field and value and writes a resulting value to the 8-bit register.
#define _BOOL2FLD(field, value)
 Returns a field mask if the value is not false.
#define _BOOL2UINT(value)
 Returns 1, if the value is not false.
#define _FLD2BOOL(field, value)
 Returns true, if the value includes the field mask.
#define CY_SYSLIB_DIV_ROUND(a, b)
 Calculates a / b with rounding to the nearest integer, a and b must have the same sign.
#define CY_SYSLIB_DIV_ROUNDUP(a, b)
 Calculates a / b with rounding up if remainder != 0, both a and b must be positive.

Typedefs

typedef char cy_char8_t
 Specific-length typedef for the basic numerical types of char.
typedef float cy_float32_t
 Specific-length typedef for the basic numerical types of float.
typedef double cy_float64_t
 Specific-length typedef for the basic numerical types of double.

Macro Definition Documentation

◆ CY_UNUSED_PARAMETER

#define CY_UNUSED_PARAMETER ( x)
Value:
( (void)(x) )

Simple macro to suppress the unused parameter warning by casting to void.

◆ CY_HALT

#define CY_HALT ( )
Value:
do { \
__asm(" bkpt 1"); \
} while(false)

Halt the processor in the debug state.

◆ CY_ASSERT_HANDLER

#define CY_ASSERT_HANDLER ( )
Value:
#define CY_HALT()
Halt the processor in the debug state.
Definition cy_utils.h:81

Default assert handler.

To override default assert handler and use own assert handler

  1. Add CY_CUSTOM_ASSERT_HANDLER to Makefile DEFINES
    DEFINES += CY_CUSTOM_ASSERT_HANDLER
  2. Define own CY_ASSERT_HANDLER API
    {
    // Users code for custom assert handler
    }
    #define CY_ASSERT_HANDLER()
    Default assert handler.
    Definition cy_utils.h:102

◆ CY_ASSERT

#define CY_ASSERT ( x)
Value:
do { \
if(!(x)) \
{ \
CY_ASSERT_HANDLER();\
} \
} while (false)

Utility macro when neither NDEBUG or CY_NO_ASSERT is not declared to check a condition and, if false, trigger a breakpoint.

Assert an argument is true, else call assert handler

◆ CY_ASSERT_AND_RETURN

#define CY_ASSERT_AND_RETURN ( condition,
value )
Value:
do { \
if(!(condition)) \
{ \
CY_ASSERT_HANDLER();\
return (value); \
} \
} while (false)

Assert an argument is true, else call assert handler and return a value.

◆ CY_ASSERT_AND_RETURN_VOID

#define CY_ASSERT_AND_RETURN_VOID ( condition)
Value:
do { \
if(!(condition)) \
{ \
CY_ASSERT_HANDLER();\
return; \
} \
} while (false)

Assert an argument is true, else call assert handler and return.

◆ CY_SVC_CALL

#define CY_SVC_CALL ( )
Value:
do { \
__asm("svc #0"); \
} while(false)

SuperVisorCall macro.

◆ CY_LO8

#define CY_LO8 ( x)
Value:
((uint8_t) ((x) & 0xFFU))

Get the lower 8 bits of a 16-bit value.

◆ CY_HI8

#define CY_HI8 ( x)
Value:
((uint8_t) ((uint16_t)(x) >> 8U))

Get the upper 8 bits of a 16-bit value.

◆ CY_LO16

#define CY_LO16 ( x)
Value:
((uint16_t) ((x) & 0xFFFFU))

Get the lower 16 bits of a 32-bit value.

◆ CY_HI16

#define CY_HI16 ( x)
Value:
((uint16_t) ((uint32_t)(x) >> 16U))

Get the upper 16 bits of a 32-bit value.

◆ CY_SWAP_ENDIAN16

#define CY_SWAP_ENDIAN16 ( x)
Value:
((uint16_t)(((x) << 8U) | (((x) >> 8U) & 0x00FFU)))

Swap the byte ordering of a 16-bit value.

◆ CY_SWAP_ENDIAN32

#define CY_SWAP_ENDIAN32 ( x)
Value:
((uint32_t)((((x) >> 24U) & 0x000000FFU) | (((x) & 0x00FF0000U) >> 8U) | \
(((x) & 0x0000FF00U) << 8U) | ((x) << 24U)))

Swap the byte ordering of a 32-bit value.

◆ CY_SWAP_ENDIAN64

#define CY_SWAP_ENDIAN64 ( x)
Value:
((uint64_t) (((uint64_t) CY_SWAP_ENDIAN32((uint32_t)(x)) << 32U) | \
CY_SWAP_ENDIAN32((uint32_t)((x) >> 32U))))
#define CY_SWAP_ENDIAN32(x)
Swap the byte ordering of a 32-bit value.
Definition cy_utils.h:174

Swap the byte ordering of a 64-bit value.

◆ CY_GET_REG8

#define CY_GET_REG8 ( addr)
Value:
(*((const volatile uint8_t *)(addr)))

Reads the 8-bit value from the specified address.

This function can't be used to access the Core register, otherwise a fault occurs.

Parameters
addrThe register address.
Returns
The read value.

◆ CY_SET_REG8

#define CY_SET_REG8 ( addr,
value )
Value:
(*((volatile uint8_t *)(addr)) = (uint8_t)(value))

Writes an 8-bit value to the specified address.

This function can't be used to access the Core register, otherwise a fault occurs.

Parameters
addrThe register address.
valueThe value to write.

◆ CY_GET_REG16

#define CY_GET_REG16 ( addr)
Value:
(*((const volatile uint16_t *)(addr)))

Reads the 16-bit value from the specified address.

Parameters
addrThe register address.
Returns
The read value.

◆ CY_SET_REG16

#define CY_SET_REG16 ( addr,
value )
Value:
(*((volatile uint16_t *)(addr)) = (uint16_t)(value))

Writes the 16-bit value to the specified address.

Parameters
addrThe register address.
valueThe value to write.

◆ CY_GET_REG24

#define CY_GET_REG24 ( addr)
Value:
(((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))

Reads the 24-bit value from the specified address.

Parameters
addrThe register address.
Returns
The read value.

◆ CY_SET_REG24

#define CY_SET_REG24 ( addr,
value )
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(false)

Writes the 24-bit value to the specified address.

Parameters
addrThe register address.
valueThe value to write.

◆ CY_GET_REG32

#define CY_GET_REG32 ( addr)
Value:
(*((const volatile uint32_t *)(addr)))

Reads the 32-bit value from the specified register.

The address is the little endian order (LSB in lowest address).

Parameters
addrThe register address.
Returns
The read value.

◆ CY_SET_REG32

#define CY_SET_REG32 ( addr,
value )
Value:
(*((volatile uint32_t *)(addr)) = (uint32_t)(value))

Writes the 32-bit value to the specified register.

The address is the little endian order (LSB in lowest address).

Parameters
addrThe register address.
valueThe value to write.

◆ _CLR_SET_FLD32U

#define _CLR_SET_FLD32U ( reg,
field,
value )
Value:
(((reg) & ((uint32_t)(~(field ## _Msk)))) | (_VAL2FLD(field, value)))

The macro for setting a register with a name field and value for providing get-clear-modify-write operations.

Returns a resulting value to be assigned to the register.

◆ CY_REG32_CLR_SET

#define CY_REG32_CLR_SET ( reg,
field,
value )
Value:
((reg) = _CLR_SET_FLD32U((reg), field, (value)))
#define _CLR_SET_FLD32U(reg, field, value)
The macro for setting a register with a name field and value for providing get-clear-modify-write ope...
Definition cy_utils.h:382

Uses _CLR_SET_FLD32U macro for providing get-clear-modify-write operations with a name field and value and writes a resulting value to the 32-bit register.

◆ _CLR_SET_FLD16U

#define _CLR_SET_FLD16U ( reg,
field,
value )
Value:
((uint16_t)(((reg) & ((uint16_t)(~(field ## _Msk)))) | ((uint16_t)_VAL2FLD(field, value))))

The macro for setting a 16-bit register with a name field and value for providing get-clear-modify-write operations.

Returns a resulting value to be assigned to the 16-bit register.

◆ CY_REG16_CLR_SET

#define CY_REG16_CLR_SET ( reg,
field,
value )
Value:
((reg) = _CLR_SET_FLD16U((reg), field, (value)))
#define _CLR_SET_FLD16U(reg, field, value)
The macro for setting a 16-bit register with a name field and value for providing get-clear-modify-wr...
Definition cy_utils.h:407

Uses _CLR_SET_FLD16U macro for providing get-clear-modify-write operations with a name field and value and writes a resulting value to the 16-bit register.

◆ _CLR_SET_FLD8U

#define _CLR_SET_FLD8U ( reg,
field,
value )
Value:
((uint8_t)(((reg) & ((uint8_t)(~(field ## _Msk)))) | ((uint8_t)_VAL2FLD(field, value))))

The macro for setting a 8-bit register with a name field and value for providing get-clear-modify-write operations.

Returns a resulting value to be assigned to the 8-bit register.

◆ CY_REG8_CLR_SET

#define CY_REG8_CLR_SET ( reg,
field,
value )
Value:
((reg) = _CLR_SET_FLD8U((reg), field, (value)))
#define _CLR_SET_FLD8U(reg, field, value)
The macro for setting a 8-bit register with a name field and value for providing get-clear-modify-wri...
Definition cy_utils.h:432

Uses _CLR_SET_FLD8U macro for providing get-clear-modify-write operations with a name field and value and writes a resulting value to the 8-bit register.

◆ _BOOL2FLD

#define _BOOL2FLD ( field,
value )
Value:
(((value) != false) ? (field ## _Msk) : 0UL)

Returns a field mask if the value is not false.

Returns 0, if the value is false.

◆ _BOOL2UINT

#define _BOOL2UINT ( value)
Value:
((value) ? 1UL : 0UL)

Returns 1, if the value is not false.

Returns 0, if the value is false.

◆ _FLD2BOOL

#define _FLD2BOOL ( field,
value )
Value:
(((value) & (field ## _Msk)) != 0UL)

Returns true, if the value includes the field mask.

Returns false, if the value doesn't include the field mask.

◆ CY_SYSLIB_DIV_ROUND

#define CY_SYSLIB_DIV_ROUND ( a,
b )
Value:
(((a) + ((b) / 2U)) / (b))

Calculates a / b with rounding to the nearest integer, a and b must have the same sign.

◆ CY_SYSLIB_DIV_ROUNDUP

#define CY_SYSLIB_DIV_ROUNDUP ( a,
b )
Value:
((((a) - 1U) / (b)) + 1U)

Calculates a / b with rounding up if remainder != 0, both a and b must be positive.