Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Creates a bit mask based on a single bit-number position.

Files

lib_def.h

Prototypes

Code Block
languagecpp
          DEF_BIT(bit);
           
          DEF_BIT08(bit);
          DEF_BIT16(bit);
          DEF_BIT32(bit);
          DEF_BIT64(bit);


Arguments

bit

Bit number of the bit mask to set.

...

To avoid overflowing any target CPU and/or compiler’s integer data type, unsigned bit constant 1 is either cast to specified integer data type size or suffixed with long integer modifier, ‘L’. This may still be insufficient for CPUs and/or compilers that support long long integer data types, in which case ‘LL’ integer modifier should be suffixed. However, since almost all 16- and 32-bit CPUs and compilers support long integer data types but many may not support long long integer data types, only long integer data types and modifiers are supported.

Example Usage

Code Block
languagecpp
          CPU_INT16U  mask_16;
          CPU_INT32U  mask_32;
           
          mask_16 = DEF_BIT(12u);
          mask_16 = DEF_BIT16(15u);
          mask_32 = DEF_BIT(19u);
          mask_32 = DEF_BIT16(23u);   /* 16-bit shift macro overflows; sets mask_32 = 0          */
          mask_32 = DEF_BIT32(28u);   /* 32-bit shift macro correctly  sets mask_32 = 0x10000000 */