nordic_common.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* Copyright (c) 2008 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. */
  11. /** @file
  12. * @brief Common defines and macros for firmware developed by Nordic Semiconductor.
  13. */
  14. #ifndef NORDIC_COMMON_H__
  15. #define NORDIC_COMMON_H__
  16. /** The upper 8 bits of a 32 bit value */
  17. //lint -emacro(572,MSB) // Suppress warning 572 "Excessive shift value"
  18. #define MSB_32(a) (((a) & 0xFF000000) >> 24)
  19. /** The lower 8 bits (of a 32 bit value) */
  20. #define LSB_32(a) ((a) & 0x000000FF)
  21. /** The upper 8 bits of a 16 bit value */
  22. //lint -emacro(572,MSB_16) // Suppress warning 572 "Excessive shift value"
  23. #define MSB_16(a) (((a) & 0xFF00) >> 8)
  24. /** The lower 8 bits (of a 16 bit value) */
  25. #define LSB_16(a) ((a) & 0x00FF)
  26. /** Leaves the minimum of the two 32-bit arguments */
  27. /*lint -emacro(506, MIN) */ /* Suppress "Constant value Boolean */
  28. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  29. /** Leaves the maximum of the two 32-bit arguments */
  30. /*lint -emacro(506, MAX) */ /* Suppress "Constant value Boolean */
  31. #define MAX(a, b) ((a) < (b) ? (b) : (a))
  32. /** Concatenates two parameters. Useful as a second level of indirection,
  33. * when a parameter can be macro itself. */
  34. #define CONCAT_2(p1, p2) p1##p2
  35. /** Concatenates three parameters. Useful as a second level of indirection,
  36. * when a parameter can be macro itself. */
  37. #define CONCAT_3(p1, p2, p3) p1##p2##p3
  38. /**@brief Set a bit in the uint32 word.
  39. *
  40. * @param[in] W Word whose bit is being set.
  41. * @param[in] B Bit number in the word to be set.
  42. */
  43. #define SET_BIT(W,B) ((W) |= (uint32_t)(1U << (B)))
  44. /**@brief Clears a bit in the uint32 word.
  45. *
  46. * @param[in] W Word whose bit is to be cleared.
  47. * @param[in] B Bit number in the word to be cleared.
  48. */
  49. #define CLR_BIT(W, B) ((W) &= (~((uint32_t)1 << (B))))
  50. /**@brief Checks if a bit is set.
  51. *
  52. * @param[in] W Word whose bit is to be checked.
  53. * @param[in] B Bit number in the word to be checked.
  54. *
  55. * @retval 1 if bit is set.
  56. * @retval 0 if bit is not set.
  57. */
  58. #define IS_SET(W,B) (((W) >> (B)) & 1)
  59. #define BIT_0 0x01 /**< The value of bit 0 */
  60. #define BIT_1 0x02 /**< The value of bit 1 */
  61. #define BIT_2 0x04 /**< The value of bit 2 */
  62. #define BIT_3 0x08 /**< The value of bit 3 */
  63. #define BIT_4 0x10 /**< The value of bit 4 */
  64. #define BIT_5 0x20 /**< The value of bit 5 */
  65. #define BIT_6 0x40 /**< The value of bit 6 */
  66. #define BIT_7 0x80 /**< The value of bit 7 */
  67. #define BIT_8 0x0100 /**< The value of bit 8 */
  68. #define BIT_9 0x0200 /**< The value of bit 9 */
  69. #define BIT_10 0x0400 /**< The value of bit 10 */
  70. #define BIT_11 0x0800 /**< The value of bit 11 */
  71. #define BIT_12 0x1000 /**< The value of bit 12 */
  72. #define BIT_13 0x2000 /**< The value of bit 13 */
  73. #define BIT_14 0x4000 /**< The value of bit 14 */
  74. #define BIT_15 0x8000 /**< The value of bit 15 */
  75. #define BIT_16 0x00010000 /**< The value of bit 16 */
  76. #define BIT_17 0x00020000 /**< The value of bit 17 */
  77. #define BIT_18 0x00040000 /**< The value of bit 18 */
  78. #define BIT_19 0x00080000 /**< The value of bit 19 */
  79. #define BIT_20 0x00100000 /**< The value of bit 20 */
  80. #define BIT_21 0x00200000 /**< The value of bit 21 */
  81. #define BIT_22 0x00400000 /**< The value of bit 22 */
  82. #define BIT_23 0x00800000 /**< The value of bit 23 */
  83. #define BIT_24 0x01000000 /**< The value of bit 24 */
  84. #define BIT_25 0x02000000 /**< The value of bit 25 */
  85. #define BIT_26 0x04000000 /**< The value of bit 26 */
  86. #define BIT_27 0x08000000 /**< The value of bit 27 */
  87. #define BIT_28 0x10000000 /**< The value of bit 28 */
  88. #define BIT_29 0x20000000 /**< The value of bit 29 */
  89. #define BIT_30 0x40000000 /**< The value of bit 30 */
  90. #define BIT_31 0x80000000 /**< The value of bit 31 */
  91. #define UNUSED_VARIABLE(X) ((void)(X))
  92. #define UNUSED_PARAMETER(X) UNUSED_VARIABLE(X)
  93. #define UNUSED_RETURN_VALUE(X) UNUSED_VARIABLE(X)
  94. #endif // NORDIC_COMMON_H__