hal_assert.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /**************************************************************************************************
  2. Filename: hal_assert.c
  3. Revised: $Date: 2008-06-13 19:14:56 -0700 (Fri, 13 Jun 2008) $
  4. Revision: $Revision: 17243 $
  5. Description: Describe the purpose and contents of the file.
  6. Copyright 2006-2008 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. /* ------------------------------------------------------------------------------------------------
  34. * Includes
  35. * ------------------------------------------------------------------------------------------------
  36. */
  37. #include "hal_assert.h"
  38. #include "hal_types.h"
  39. #include "hal_board.h"
  40. #include "hal_defs.h"
  41. #include "hal_mcu.h"
  42. #ifndef HAL_ONLY_BUILD
  43. /* for access to debug data */
  44. #include "mac_rx.h"
  45. #include "mac_tx.h"
  46. #endif
  47. /* ------------------------------------------------------------------------------------------------
  48. * Local Prototypes
  49. * ------------------------------------------------------------------------------------------------
  50. */
  51. void halAssertHazardLights(void);
  52. /**************************************************************************************************
  53. * @fn halAssertHandler
  54. *
  55. * @brief Logic to handle an assert.
  56. *
  57. * @param none
  58. *
  59. * @return none
  60. **************************************************************************************************
  61. */
  62. void halAssertHandler(void)
  63. {
  64. /* execute code that handles asserts */
  65. #ifdef ASSERT_RESET
  66. HAL_SYSTEM_RESET();
  67. #else
  68. halAssertHazardLights();
  69. #endif
  70. }
  71. /**************************************************************************************************
  72. * @fn halAssertHazardLights
  73. *
  74. * @brief Blink LEDs to indicate an error.
  75. *
  76. * @param none
  77. *
  78. * @return none
  79. **************************************************************************************************
  80. */
  81. void halAssertHazardLights(void)
  82. {
  83. enum
  84. {
  85. DEBUG_DATA_RSTACK_HIGH_OFS,
  86. DEBUG_DATA_RSTACK_LOW_OFS,
  87. DEBUG_DATA_TX_ACTIVE_OFS,
  88. DEBUG_DATA_RX_ACTIVE_OFS,
  89. #if (defined HAL_MCU_AVR) || (defined HAL_MCU_CC2430)
  90. DEBUG_DATA_INT_MASK_OFS,
  91. #elif (defined HAL_MCU_CC2530)
  92. DEBUG_DATA_INT_MASK0_OFS,
  93. DEBUG_DATA_INT_MASK1_OFS,
  94. #endif
  95. DEBUG_DATA_SIZE
  96. };
  97. uint8 buttonHeld;
  98. uint8 debugData[DEBUG_DATA_SIZE];
  99. /* disable all interrupts before anything else */
  100. HAL_DISABLE_INTERRUPTS();
  101. /*-------------------------------------------------------------------------------
  102. * Initialize LEDs and turn them off.
  103. */
  104. HAL_BOARD_INIT();
  105. HAL_TURN_OFF_LED1();
  106. HAL_TURN_OFF_LED2();
  107. HAL_TURN_OFF_LED3();
  108. HAL_TURN_OFF_LED4();
  109. /*-------------------------------------------------------------------------------
  110. * Master infinite loop.
  111. */
  112. for (;;)
  113. {
  114. buttonHeld = 0;
  115. /*-------------------------------------------------------------------------------
  116. * "Hazard lights" loop. A held keypress will exit this loop.
  117. */
  118. do
  119. {
  120. HAL_LED_BLINK_DELAY();
  121. /* toggle LEDS, the #ifdefs are in case HAL has logically remapped non-existent LEDs */
  122. #if (HAL_NUM_LEDS >= 1)
  123. HAL_TOGGLE_LED1();
  124. #if (HAL_NUM_LEDS >= 2)
  125. HAL_TOGGLE_LED2();
  126. #if (HAL_NUM_LEDS >= 3)
  127. HAL_TOGGLE_LED3();
  128. #if (HAL_NUM_LEDS >= 4)
  129. HAL_TOGGLE_LED4();
  130. #endif
  131. #endif
  132. #endif
  133. #endif
  134. /* escape hatch to continue execution, set escape to '1' to continue execution */
  135. {
  136. static uint8 escape = 0;
  137. if (escape)
  138. {
  139. escape = 0;
  140. return;
  141. }
  142. }
  143. /* break out of loop if button is held long enough */
  144. if (HAL_PUSH_BUTTON1())
  145. {
  146. buttonHeld++;
  147. }
  148. else
  149. {
  150. buttonHeld = 0;
  151. }
  152. }
  153. while (buttonHeld != 10); /* loop until button is held specified number of loops */
  154. /*-------------------------------------------------------------------------------
  155. * Just exited from "hazard lights" loop.
  156. */
  157. /* turn off all LEDs */
  158. HAL_TURN_OFF_LED1();
  159. HAL_TURN_OFF_LED2();
  160. HAL_TURN_OFF_LED3();
  161. HAL_TURN_OFF_LED4();
  162. /* wait for button release */
  163. HAL_DEBOUNCE(!HAL_PUSH_BUTTON1());
  164. /*-------------------------------------------------------------------------------
  165. * Load debug data into memory.
  166. */
  167. #ifdef HAL_MCU_AVR
  168. {
  169. uint8 * pStack;
  170. pStack = (uint8 *) SP;
  171. pStack++; /* point to return address on stack */
  172. debugData[DEBUG_DATA_RSTACK_HIGH_OFS] = *pStack;
  173. pStack++;
  174. debugData[DEBUG_DATA_RSTACK_LOW_OFS] = *pStack;
  175. }
  176. debugData[DEBUG_DATA_INT_MASK_OFS] = EIMSK;
  177. #endif
  178. #if (defined HAL_MCU_CC2430)
  179. debugData[DEBUG_DATA_INT_MASK_OFS] = RFIM;
  180. #elif (defined HAL_MCU_CC2530)
  181. debugData[DEBUG_DATA_INT_MASK0_OFS] = RFIRQM0;
  182. debugData[DEBUG_DATA_INT_MASK1_OFS] = RFIRQM1;
  183. #endif
  184. #ifndef HAL_ONLY_BUILD
  185. debugData[DEBUG_DATA_TX_ACTIVE_OFS] = macTxActive;
  186. debugData[DEBUG_DATA_RX_ACTIVE_OFS] = macRxActive;
  187. #endif
  188. /* initialize for data dump loop */
  189. {
  190. uint8 iBit;
  191. uint8 iByte;
  192. iBit = 0;
  193. iByte = 0;
  194. /*-------------------------------------------------------------------------------
  195. * Data dump loop. A button press cycles data bits to an LED.
  196. */
  197. while (iByte < DEBUG_DATA_SIZE)
  198. {
  199. /* wait for key press */
  200. while(!HAL_PUSH_BUTTON1());
  201. /* turn on all LEDs for first bit of byte, turn on three LEDs if not first bit */
  202. HAL_TURN_ON_LED1();
  203. HAL_TURN_ON_LED2();
  204. HAL_TURN_ON_LED3();
  205. if (iBit == 0)
  206. {
  207. HAL_TURN_ON_LED4();
  208. }
  209. else
  210. {
  211. HAL_TURN_OFF_LED4();
  212. }
  213. /* wait for debounced key release */
  214. HAL_DEBOUNCE(!HAL_PUSH_BUTTON1());
  215. /* turn off all LEDs */
  216. HAL_TURN_OFF_LED1();
  217. HAL_TURN_OFF_LED2();
  218. HAL_TURN_OFF_LED3();
  219. HAL_TURN_OFF_LED4();
  220. /* output value of data bit to LED1 */
  221. if (debugData[iByte] & (1 << (7 - iBit)))
  222. {
  223. HAL_TURN_ON_LED1();
  224. }
  225. else
  226. {
  227. HAL_TURN_OFF_LED1();
  228. }
  229. /* advance to next bit */
  230. iBit++;
  231. if (iBit == 8)
  232. {
  233. iBit = 0;
  234. iByte++;
  235. }
  236. }
  237. }
  238. /*
  239. * About to enter "hazard lights" loop again. Turn off LED1 in case the last bit
  240. * displayed happened to be one. This guarantees all LEDs are off at the start of
  241. * the flashing loop which uses a toggle operation to change LED states.
  242. */
  243. HAL_TURN_OFF_LED1();
  244. }
  245. }
  246. /* ------------------------------------------------------------------------------------------------
  247. * Compile Time Assertions
  248. * ------------------------------------------------------------------------------------------------
  249. */
  250. /* integrity check of type sizes */
  251. HAL_ASSERT_SIZE( int8, 1);
  252. HAL_ASSERT_SIZE( uint8, 1);
  253. HAL_ASSERT_SIZE( int16, 2);
  254. HAL_ASSERT_SIZE(uint16, 2);
  255. HAL_ASSERT_SIZE( int32, 4);
  256. HAL_ASSERT_SIZE(uint32, 4);
  257. /**************************************************************************************************
  258. */