hal_defs.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**************************************************************************************************
  2. Filename: hal_defs.h
  3. Revised: $Date: 2008-10-07 14:47:15 -0700 (Tue, 07 Oct 2008) $
  4. Revision: $Revision: 18212 $
  5. Description: This file contains useful macros and data types
  6. Copyright 2005-2007 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef HAL_DEFS_H
  34. #define HAL_DEFS_H
  35. /* ------------------------------------------------------------------------------------------------
  36. * Macros
  37. * ------------------------------------------------------------------------------------------------
  38. */
  39. #ifndef BV
  40. #define BV(n) (1 << (n))
  41. #endif
  42. #ifndef BF
  43. #define BF(x,b,s) (((x) & (b)) >> (s))
  44. #endif
  45. #ifndef MIN
  46. #define MIN(n,m) (((n) < (m)) ? (n) : (m))
  47. #endif
  48. #ifndef MAX
  49. #define MAX(n,m) (((n) < (m)) ? (m) : (n))
  50. #endif
  51. #ifndef ABS
  52. #define ABS(n) (((n) < 0) ? -(n) : (n))
  53. #endif
  54. /* takes a byte out of a uint32 : var - uint32, ByteNum - byte to take out (0 - 3) */
  55. #define BREAK_UINT32( var, ByteNum ) \
  56. (uint8)((uint32)(((var) >>((ByteNum) * 8)) & 0x00FF))
  57. #define BUILD_UINT32(Byte0, Byte1, Byte2, Byte3) \
  58. ((uint32)((uint32)((Byte0) & 0x00FF) \
  59. + ((uint32)((Byte1) & 0x00FF) << 8) \
  60. + ((uint32)((Byte2) & 0x00FF) << 16) \
  61. + ((uint32)((Byte3) & 0x00FF) << 24)))
  62. #define BUILD_UINT16(loByte, hiByte) \
  63. ((uint16)(((loByte) & 0x00FF) + (((hiByte) & 0x00FF) << 8)))
  64. #define HI_UINT16(a) (((a) >> 8) & 0xFF)
  65. #define LO_UINT16(a) ((a) & 0xFF)
  66. #define BUILD_UINT8(hiByte, loByte) \
  67. ((uint8)(((loByte) & 0x0F) + (((hiByte) & 0x0F) << 4)))
  68. #define HI_UINT8(a) (((a) >> 4) & 0x0F)
  69. #define LO_UINT8(a) ((a) & 0x0F)
  70. /*
  71. * This macro is for use by other macros to form a fully valid C statement.
  72. * Without this, the if/else conditionals could show unexpected behavior.
  73. *
  74. * For example, use...
  75. * #define SET_REGS() st( ioreg1 = 0; ioreg2 = 0; )
  76. * instead of ...
  77. * #define SET_REGS() { ioreg1 = 0; ioreg2 = 0; }
  78. * or
  79. * #define SET_REGS() ioreg1 = 0; ioreg2 = 0;
  80. * The last macro would not behave as expected in the if/else construct.
  81. * The second to last macro will cause a compiler error in certain uses
  82. * of if/else construct
  83. *
  84. * It is not necessary, or recommended, to use this macro where there is
  85. * already a valid C statement. For example, the following is redundant...
  86. * #define CALL_FUNC() st( func(); )
  87. * This should simply be...
  88. * #define CALL_FUNC() func()
  89. *
  90. * (The while condition below evaluates false without generating a
  91. * constant-controlling-loop type of warning on most compilers.)
  92. */
  93. #define st(x) do { x } while (__LINE__ == -1)
  94. /**************************************************************************************************
  95. */
  96. #endif