hal_assert.c 9.4 KB

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