hal_assert.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**************************************************************************************************
  2. Filename: hal_assert.h
  3. Revised: $Date: 2009-02-16 18:03:22 -0800 (Mon, 16 Feb 2009) $
  4. Revision: $Revision: 19172 $
  5. Description: Describe the purpose and contents of the file.
  6. Copyright 2006-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_ASSERT_H
  34. #define HAL_ASSERT_H
  35. /* ------------------------------------------------------------------------------------------------
  36. * Macros
  37. * ------------------------------------------------------------------------------------------------
  38. */
  39. /*
  40. * HAL_ASSERT( expression ) - The given expression must evaluate as "true" or else the assert
  41. * handler is called. From here, the call stack feature of the debugger can pinpoint where
  42. * the problem occurred.
  43. *
  44. * HAL_ASSERT_FORCED( ) - If asserts are in use, immediately calls the assert handler.
  45. *
  46. * HAL_ASSERT_STATEMENT( statement ) - Inserts the given C statement but only when asserts
  47. * are in use. This macros allows debug code that is not part of an expression.
  48. *
  49. * HAL_ASSERT_DECLARATION( declaration ) - Inserts the given C declaration but only when asserts
  50. * are in use. This macros allows debug code that is not part of an expression.
  51. *
  52. * Asserts can be disabled for optimum performance and minimum code size (ideal for
  53. * finalized, debugged production code). To disable, define the preprocessor
  54. * symbol HALNODEBUG at the project level.
  55. */
  56. #ifdef HALNODEBUG
  57. #define HAL_ASSERT(expr)
  58. #define HAL_ASSERT_FORCED()
  59. #define HAL_ASSERT_STATEMENT(statement)
  60. #define HAL_ASSERT_DECLARATION(declaration)
  61. #else
  62. #define HAL_ASSERT(expr) st( if (!( expr )) halAssertHandler(); )
  63. #define HAL_ASSERT_FORCED() halAssertHandler()
  64. #define HAL_ASSERT_STATEMENT(statement) st( statement )
  65. #define HAL_ASSERT_DECLARATION(declaration) declaration
  66. #endif
  67. /*
  68. * This macro compares the size of the first parameter to the integer value
  69. * of the second parameter. If they do not match, a compile time error for
  70. * negative array size occurs (even gnu chokes on negative array size).
  71. *
  72. * This compare is done by creating a typedef for an array. No variables are
  73. * created and no memory is consumed with this check. The created type is
  74. * used for checking only and is not for use by any other code. The value
  75. * of 10 in this macro is arbitrary, it just needs to be a value larger
  76. * than one to result in a positive number for the array size.
  77. */
  78. #define HAL_ASSERT_SIZE(x,y) typedef char x ## _assert_size_t[-1+10*(sizeof(x) == (y))]
  79. /* ------------------------------------------------------------------------------------------------
  80. * Prototypes
  81. * ------------------------------------------------------------------------------------------------
  82. */
  83. void halAssertHandler(void);
  84. /**************************************************************************************************
  85. */
  86. /**************************************************************************************************
  87. * FUNCTIONS - API
  88. **************************************************************************************************/
  89. extern void halAssertHazardLights(void);
  90. #endif