|
| 1 | +/************************************************************************************************** |
| 2 | + Filename: hal_assert.c |
| 3 | + Revised: $Date: 2010-01-07 10:10:43 -0800 (Thu, 07 Jan 2010) $ |
| 4 | + Revision: $Revision: 21451 $ |
| 5 | +
|
| 6 | + Description: Describe the purpose and contents of the file. |
| 7 | +
|
| 8 | +
|
| 9 | + Copyright 2006-2010 Texas Instruments Incorporated. All rights reserved. |
| 10 | +
|
| 11 | + IMPORTANT: Your use of this Software is limited to those specific rights |
| 12 | + granted under the terms of a software license agreement between the user |
| 13 | + who downloaded the software, his/her employer (which must be your employer) |
| 14 | + and Texas Instruments Incorporated (the "License"). You may not use this |
| 15 | + Software unless you agree to abide by the terms of the License. The License |
| 16 | + limits your use, and you acknowledge, that the Software may not be modified, |
| 17 | + copied or distributed unless embedded on a Texas Instruments microcontroller |
| 18 | + or used solely and exclusively in conjunction with a Texas Instruments radio |
| 19 | + frequency transceiver, which is integrated into your product. Other than for |
| 20 | + the foregoing purpose, you may not use, reproduce, copy, prepare derivative |
| 21 | + works of, modify, distribute, perform, display or sell this Software and/or |
| 22 | + its documentation for any purpose. |
| 23 | +
|
| 24 | + YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE |
| 25 | + PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 26 | + INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, |
| 27 | + NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL |
| 28 | + TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, |
| 29 | + NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER |
| 30 | + LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES |
| 31 | + INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE |
| 32 | + OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT |
| 33 | + OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES |
| 34 | + (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. |
| 35 | +
|
| 36 | + Should you have any questions regarding your right to use this Software, |
| 37 | + contact Texas Instruments Incorporated at www.TI.com. |
| 38 | +**************************************************************************************************/ |
| 39 | + |
| 40 | + |
| 41 | +/* ------------------------------------------------------------------------------------------------ |
| 42 | + * Includes |
| 43 | + * ------------------------------------------------------------------------------------------------ |
| 44 | + */ |
| 45 | +#include "hal_assert.h" |
| 46 | +#include "hal_types.h" |
| 47 | +#include "hal_board.h" |
| 48 | +#include "hal_defs.h" |
| 49 | +#include "hal_mcu.h" |
| 50 | + |
| 51 | +#if (defined HAL_MCU_AVR) || (defined HAL_MCU_CC2430) || (defined HAL_MCU_CC2530) || \ |
| 52 | + (defined HAL_MCU_CC2533) || (defined HAL_MCU_MSP430) |
| 53 | + /* for access to debug data */ |
| 54 | + #include "mac_rx.h" |
| 55 | + #include "mac_tx.h" |
| 56 | +#endif |
| 57 | + |
| 58 | +/* ------------------------------------------------------------------------------------------------ |
| 59 | + * Local Prototypes |
| 60 | + * ------------------------------------------------------------------------------------------------ |
| 61 | + */ |
| 62 | +void halAssertHazardLights(void); |
| 63 | + |
| 64 | + |
| 65 | +/************************************************************************************************** |
| 66 | + * @fn halAssertHandler |
| 67 | + * |
| 68 | + * @brief Logic to handle an assert. |
| 69 | + * |
| 70 | + * @param none |
| 71 | + * |
| 72 | + * @return none |
| 73 | + ************************************************************************************************** |
| 74 | + */ |
| 75 | +void halAssertHandler(void) |
| 76 | +{ |
| 77 | + /* execute code that handles asserts */ |
| 78 | +#ifdef ASSERT_RESET |
| 79 | + HAL_SYSTEM_RESET(); |
| 80 | +#else |
| 81 | + halAssertHazardLights(); |
| 82 | +#endif |
| 83 | + |
| 84 | +} |
| 85 | + |
| 86 | + |
| 87 | +/************************************************************************************************** |
| 88 | + * @fn halAssertHazardLights |
| 89 | + * |
| 90 | + * @brief Blink LEDs to indicate an error. |
| 91 | + * |
| 92 | + * @param none |
| 93 | + * |
| 94 | + * @return none |
| 95 | + ************************************************************************************************** |
| 96 | + */ |
| 97 | +void halAssertHazardLights(void) |
| 98 | +{ |
| 99 | + enum |
| 100 | + { |
| 101 | + DEBUG_DATA_RSTACK_HIGH_OFS, |
| 102 | + DEBUG_DATA_RSTACK_LOW_OFS, |
| 103 | + DEBUG_DATA_TX_ACTIVE_OFS, |
| 104 | + DEBUG_DATA_RX_ACTIVE_OFS, |
| 105 | + |
| 106 | +#if (defined HAL_MCU_AVR) || (defined HAL_MCU_CC2430) |
| 107 | + DEBUG_DATA_INT_MASK_OFS, |
| 108 | +#elif (defined HAL_MCU_CC2530) || (defined HAL_MCU_CC2533) |
| 109 | + DEBUG_DATA_INT_MASK0_OFS, |
| 110 | + DEBUG_DATA_INT_MASK1_OFS, |
| 111 | +#endif |
| 112 | + |
| 113 | + DEBUG_DATA_SIZE |
| 114 | + }; |
| 115 | + |
| 116 | + uint8 buttonHeld; |
| 117 | + uint8 debugData[DEBUG_DATA_SIZE]; |
| 118 | + |
| 119 | + /* disable all interrupts before anything else */ |
| 120 | + HAL_DISABLE_INTERRUPTS(); |
| 121 | + |
| 122 | + /*------------------------------------------------------------------------------- |
| 123 | + * Initialize LEDs and turn them off. |
| 124 | + */ |
| 125 | + HAL_BOARD_INIT(); |
| 126 | + |
| 127 | + HAL_TURN_OFF_LED1(); |
| 128 | + HAL_TURN_OFF_LED2(); |
| 129 | + HAL_TURN_OFF_LED3(); |
| 130 | + HAL_TURN_OFF_LED4(); |
| 131 | + |
| 132 | + /*------------------------------------------------------------------------------- |
| 133 | + * Master infinite loop. |
| 134 | + */ |
| 135 | + for (;;) |
| 136 | + { |
| 137 | + buttonHeld = 0; |
| 138 | + |
| 139 | + /*------------------------------------------------------------------------------- |
| 140 | + * "Hazard lights" loop. A held keypress will exit this loop. |
| 141 | + */ |
| 142 | + do |
| 143 | + { |
| 144 | + HAL_LED_BLINK_DELAY(); |
| 145 | + |
| 146 | + /* toggle LEDS, the #ifdefs are in case HAL has logically remapped non-existent LEDs */ |
| 147 | +#if (HAL_NUM_LEDS >= 1) |
| 148 | + HAL_TOGGLE_LED1(); |
| 149 | +#if (HAL_NUM_LEDS >= 2) |
| 150 | + HAL_TOGGLE_LED2(); |
| 151 | +#if (HAL_NUM_LEDS >= 3) |
| 152 | + HAL_TOGGLE_LED3(); |
| 153 | +#if (HAL_NUM_LEDS >= 4) |
| 154 | + HAL_TOGGLE_LED4(); |
| 155 | +#endif |
| 156 | +#endif |
| 157 | +#endif |
| 158 | +#endif |
| 159 | + |
| 160 | + /* escape hatch to continue execution, set escape to '1' to continue execution */ |
| 161 | + { |
| 162 | + static uint8 escape = 0; |
| 163 | + if (escape) |
| 164 | + { |
| 165 | + escape = 0; |
| 166 | + return; |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + /* break out of loop if button is held long enough */ |
| 171 | + if (HAL_PUSH_BUTTON1()) |
| 172 | + { |
| 173 | + buttonHeld++; |
| 174 | + } |
| 175 | + else |
| 176 | + { |
| 177 | + buttonHeld = 0; |
| 178 | + } |
| 179 | + } |
| 180 | + while (buttonHeld != 10); /* loop until button is held specified number of loops */ |
| 181 | + |
| 182 | + /*------------------------------------------------------------------------------- |
| 183 | + * Just exited from "hazard lights" loop. |
| 184 | + */ |
| 185 | + |
| 186 | + /* turn off all LEDs */ |
| 187 | + HAL_TURN_OFF_LED1(); |
| 188 | + HAL_TURN_OFF_LED2(); |
| 189 | + HAL_TURN_OFF_LED3(); |
| 190 | + HAL_TURN_OFF_LED4(); |
| 191 | + |
| 192 | + /* wait for button release */ |
| 193 | + HAL_DEBOUNCE(!HAL_PUSH_BUTTON1()); |
| 194 | + |
| 195 | + /*------------------------------------------------------------------------------- |
| 196 | + * Load debug data into memory. |
| 197 | + */ |
| 198 | +#ifdef HAL_MCU_AVR |
| 199 | + { |
| 200 | + uint8 * pStack; |
| 201 | + pStack = (uint8 *) SP; |
| 202 | + pStack++; /* point to return address on stack */ |
| 203 | + debugData[DEBUG_DATA_RSTACK_HIGH_OFS] = *pStack; |
| 204 | + pStack++; |
| 205 | + debugData[DEBUG_DATA_RSTACK_LOW_OFS] = *pStack; |
| 206 | + } |
| 207 | + debugData[DEBUG_DATA_INT_MASK_OFS] = EIMSK; |
| 208 | +#endif |
| 209 | + |
| 210 | +#if (defined HAL_MCU_CC2430) |
| 211 | + debugData[DEBUG_DATA_INT_MASK_OFS] = RFIM; |
| 212 | +#elif (defined HAL_MCU_CC2530) || (defined HAL_MCU_CC2533) |
| 213 | + debugData[DEBUG_DATA_INT_MASK0_OFS] = RFIRQM0; |
| 214 | + debugData[DEBUG_DATA_INT_MASK1_OFS] = RFIRQM1; |
| 215 | +#endif |
| 216 | + |
| 217 | + |
| 218 | +#if (defined HAL_MCU_AVR) || (defined HAL_MCU_CC2430) || (defined HAL_MCU_CC2530) || \ |
| 219 | + (defined HAL_MCU_CC2533) || (defined HAL_MCU_MSP430) |
| 220 | + debugData[DEBUG_DATA_TX_ACTIVE_OFS] = macTxActive; |
| 221 | + debugData[DEBUG_DATA_RX_ACTIVE_OFS] = macRxActive; |
| 222 | +#endif |
| 223 | + |
| 224 | + /* initialize for data dump loop */ |
| 225 | + { |
| 226 | + uint8 iBit; |
| 227 | + uint8 iByte; |
| 228 | + |
| 229 | + iBit = 0; |
| 230 | + iByte = 0; |
| 231 | + |
| 232 | + /*------------------------------------------------------------------------------- |
| 233 | + * Data dump loop. A button press cycles data bits to an LED. |
| 234 | + */ |
| 235 | + while (iByte < DEBUG_DATA_SIZE) |
| 236 | + { |
| 237 | + /* wait for key press */ |
| 238 | + while(!HAL_PUSH_BUTTON1()); |
| 239 | + |
| 240 | + /* turn on all LEDs for first bit of byte, turn on three LEDs if not first bit */ |
| 241 | + HAL_TURN_ON_LED1(); |
| 242 | + HAL_TURN_ON_LED2(); |
| 243 | + HAL_TURN_ON_LED3(); |
| 244 | + if (iBit == 0) |
| 245 | + { |
| 246 | + HAL_TURN_ON_LED4(); |
| 247 | + } |
| 248 | + else |
| 249 | + { |
| 250 | + HAL_TURN_OFF_LED4(); |
| 251 | + } |
| 252 | + |
| 253 | + /* wait for debounced key release */ |
| 254 | + HAL_DEBOUNCE(!HAL_PUSH_BUTTON1()); |
| 255 | + |
| 256 | + /* turn off all LEDs */ |
| 257 | + HAL_TURN_OFF_LED1(); |
| 258 | + HAL_TURN_OFF_LED2(); |
| 259 | + HAL_TURN_OFF_LED3(); |
| 260 | + HAL_TURN_OFF_LED4(); |
| 261 | + |
| 262 | + /* output value of data bit to LED1 */ |
| 263 | + if (debugData[iByte] & (1 << (7 - iBit))) |
| 264 | + { |
| 265 | + HAL_TURN_ON_LED1(); |
| 266 | + } |
| 267 | + else |
| 268 | + { |
| 269 | + HAL_TURN_OFF_LED1(); |
| 270 | + } |
| 271 | + |
| 272 | + /* advance to next bit */ |
| 273 | + iBit++; |
| 274 | + if (iBit == 8) |
| 275 | + { |
| 276 | + iBit = 0; |
| 277 | + iByte++; |
| 278 | + } |
| 279 | + } |
| 280 | + } |
| 281 | + |
| 282 | + /* |
| 283 | + * About to enter "hazard lights" loop again. Turn off LED1 in case the last bit |
| 284 | + * displayed happened to be one. This guarantees all LEDs are off at the start of |
| 285 | + * the flashing loop which uses a toggle operation to change LED states. |
| 286 | + */ |
| 287 | + HAL_TURN_OFF_LED1(); |
| 288 | + } |
| 289 | +} |
| 290 | + |
| 291 | + |
| 292 | +/* ------------------------------------------------------------------------------------------------ |
| 293 | + * Compile Time Assertions |
| 294 | + * ------------------------------------------------------------------------------------------------ |
| 295 | + */ |
| 296 | + |
| 297 | +/* integrity check of type sizes */ |
| 298 | +HAL_ASSERT_SIZE( int8, 1); |
| 299 | +HAL_ASSERT_SIZE( uint8, 1); |
| 300 | +HAL_ASSERT_SIZE( int16, 2); |
| 301 | +HAL_ASSERT_SIZE(uint16, 2); |
| 302 | +HAL_ASSERT_SIZE( int32, 4); |
| 303 | +HAL_ASSERT_SIZE(uint32, 4); |
| 304 | + |
| 305 | + |
| 306 | +/************************************************************************************************** |
| 307 | +*/ |
0 commit comments