270 lines
6.9 KiB
C
270 lines
6.9 KiB
C
/*!
|
|
* \file hal_assert.c
|
|
*
|
|
* \brief Target xc6xxx hal spi implementation
|
|
*
|
|
* \copyright Revised BSD License, see section \ref LICENSE.
|
|
*
|
|
* \code
|
|
*
|
|
* _ __ _ ________ _
|
|
* | |/ /(_)___ / ____/ /_ (_)___
|
|
* | // / __ \/ / / __ \/ / __ \
|
|
* / |/ / / / / /___/ / / / / /_/ /
|
|
* /_/|_/_/_/ /_/\____/_/ /_/_/ .___/
|
|
* /_/
|
|
* (C) 2022-2025 XinChip
|
|
*
|
|
* \endcode
|
|
*
|
|
* \author ( XinChip ) Alex-J
|
|
*
|
|
* \author ( XinChip )
|
|
*/
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* Includes
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
#include "hal_assert.h"
|
|
#include "hal_types.h"
|
|
#include "hal_board.h"
|
|
#include "hal_defs.h"
|
|
#include "hal_mcu.h"
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* Local Prototypes
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
void halAssertHazardLights(void);
|
|
|
|
|
|
/**************************************************************************************************
|
|
* @fn halAssertHandler
|
|
*
|
|
* @brief Logic to handle an assert.
|
|
*
|
|
* @param none
|
|
*
|
|
* @return none
|
|
**************************************************************************************************
|
|
*/
|
|
void halAssertHandler( void )
|
|
{
|
|
#if defined( HAL_ASSERT_RESET )
|
|
HAL_SYSTEM_RESET();
|
|
#elif defined ( HAL_ASSERT_LIGHTS )
|
|
halAssertHazardLights();
|
|
#elif defined( HAL_ASSERT_SPIN )
|
|
volatile uint8 i = 1;
|
|
HAL_DISABLE_INTERRUPTS();
|
|
while(i);
|
|
#endif
|
|
|
|
return;
|
|
}
|
|
|
|
#if !defined ASSERT_WHILE
|
|
/**************************************************************************************************
|
|
* @fn halAssertHazardLights
|
|
*
|
|
* @brief Blink LEDs to indicate an error.
|
|
*
|
|
* @param none
|
|
*
|
|
* @return none
|
|
**************************************************************************************************
|
|
*/
|
|
void halAssertHazardLights(void)
|
|
{
|
|
enum
|
|
{
|
|
DEBUG_DATA_RSTACK_HIGH_OFS,
|
|
DEBUG_DATA_RSTACK_LOW_OFS,
|
|
DEBUG_DATA_TX_ACTIVE_OFS,
|
|
DEBUG_DATA_RX_ACTIVE_OFS,
|
|
DEBUG_DATA_SIZE
|
|
};
|
|
|
|
uint8 buttonHeld;
|
|
uint8 debugData[DEBUG_DATA_SIZE] = {0};
|
|
|
|
/* disable all interrupts before anything else */
|
|
HAL_DISABLE_INTERRUPTS();
|
|
|
|
/*-------------------------------------------------------------------------------
|
|
* Initialize LEDs and turn them off.
|
|
*/
|
|
HAL_BOARD_INIT();
|
|
|
|
HAL_TURN_OFF_LED1();
|
|
HAL_TURN_OFF_LED2();
|
|
HAL_TURN_OFF_LED3();
|
|
HAL_TURN_OFF_LED4();
|
|
|
|
/*-------------------------------------------------------------------------------
|
|
* Master infinite loop.
|
|
*/
|
|
for (;;)
|
|
{
|
|
buttonHeld = 0;
|
|
|
|
/*-------------------------------------------------------------------------------
|
|
* "Hazard lights" loop. A held keypress will exit this loop.
|
|
*/
|
|
do
|
|
{
|
|
HAL_LED_BLINK_DELAY();
|
|
|
|
/* toggle LEDS, the #ifdefs are in case HAL has logically remapped non-existent LEDs */
|
|
#if (HAL_NUM_LEDS >= 1)
|
|
HAL_TOGGLE_LED1();
|
|
#if (HAL_NUM_LEDS >= 2)
|
|
HAL_TOGGLE_LED2();
|
|
#if (HAL_NUM_LEDS >= 3)
|
|
HAL_TOGGLE_LED3();
|
|
#if (HAL_NUM_LEDS >= 4)
|
|
HAL_TOGGLE_LED4();
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
/* escape hatch to continue execution, set escape to '1' to continue execution */
|
|
{
|
|
static uint8 escape = 0;
|
|
if (escape)
|
|
{
|
|
escape = 0;
|
|
return;
|
|
}
|
|
}
|
|
|
|
/* break out of loop if button is held long enough */
|
|
// if (HAL_PUSH_BUTTON1()) // TODO
|
|
// {
|
|
// buttonHeld++;
|
|
// }
|
|
// else
|
|
// {
|
|
// buttonHeld = 0;
|
|
// }
|
|
}
|
|
while (buttonHeld != 10); /* loop until button is held specified number of loops */
|
|
|
|
/*-------------------------------------------------------------------------------
|
|
* Just exited from "hazard lights" loop.
|
|
*/
|
|
|
|
/* turn off all LEDs */
|
|
HAL_TURN_OFF_LED1();
|
|
HAL_TURN_OFF_LED2();
|
|
HAL_TURN_OFF_LED3();
|
|
HAL_TURN_OFF_LED4();
|
|
|
|
/* wait for button release */
|
|
// HAL_DEBOUNCE(!HAL_PUSH_BUTTON1()); // TODO
|
|
|
|
/*-------------------------------------------------------------------------------
|
|
* Load debug data into memory.
|
|
*/
|
|
#ifdef HAL_MCU_AVR
|
|
{
|
|
uint8 * pStack;
|
|
pStack = (uint8 *) SP;
|
|
pStack++; /* point to return address on stack */
|
|
debugData[DEBUG_DATA_RSTACK_HIGH_OFS] = *pStack;
|
|
pStack++;
|
|
debugData[DEBUG_DATA_RSTACK_LOW_OFS] = *pStack;
|
|
}
|
|
debugData[DEBUG_DATA_INT_MASK_OFS] = EIMSK;
|
|
#endif
|
|
|
|
/* initialize for data dump loop */
|
|
{
|
|
uint8 iBit;
|
|
uint8 iByte;
|
|
|
|
iBit = 0;
|
|
iByte = 0;
|
|
|
|
/*-------------------------------------------------------------------------------
|
|
* Data dump loop. A button press cycles data bits to an LED.
|
|
*/
|
|
while (iByte < DEBUG_DATA_SIZE)
|
|
{
|
|
/* wait for key press */
|
|
// while(!HAL_PUSH_BUTTON1()); // TODO
|
|
|
|
/* turn on all LEDs for first bit of byte, turn on three LEDs if not first bit */
|
|
HAL_TURN_ON_LED1();
|
|
HAL_TURN_ON_LED2();
|
|
HAL_TURN_ON_LED3();
|
|
if (iBit == 0)
|
|
{
|
|
HAL_TURN_ON_LED4();
|
|
}
|
|
else
|
|
{
|
|
HAL_TURN_OFF_LED4();
|
|
}
|
|
|
|
/* wait for debounced key release */
|
|
// HAL_DEBOUNCE(!HAL_PUSH_BUTTON1()); // TODO
|
|
|
|
/* turn off all LEDs */
|
|
HAL_TURN_OFF_LED1();
|
|
HAL_TURN_OFF_LED2();
|
|
HAL_TURN_OFF_LED3();
|
|
HAL_TURN_OFF_LED4();
|
|
|
|
/* output value of data bit to LED1 */
|
|
if (debugData[iByte] & (1 << (7 - iBit)))
|
|
{
|
|
HAL_TURN_ON_LED1();
|
|
}
|
|
else
|
|
{
|
|
HAL_TURN_OFF_LED1();
|
|
}
|
|
|
|
/* advance to next bit */
|
|
iBit++;
|
|
if (iBit == 8)
|
|
{
|
|
iBit = 0;
|
|
iByte++;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* About to enter "hazard lights" loop again. Turn off LED1 in case the last bit
|
|
* displayed happened to be one. This guarantees all LEDs are off at the start of
|
|
* the flashing loop which uses a toggle operation to change LED states.
|
|
*/
|
|
HAL_TURN_OFF_LED1();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* Compile Time Assertions
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
/* integrity check of type sizes */
|
|
HAL_ASSERT_SIZE( int8, 1);
|
|
HAL_ASSERT_SIZE( uint8, 1);
|
|
HAL_ASSERT_SIZE( int16, 2);
|
|
HAL_ASSERT_SIZE(uint16, 2);
|
|
HAL_ASSERT_SIZE( int32, 4);
|
|
HAL_ASSERT_SIZE(uint32, 4);
|
|
#pragma message("note: compile depend")
|
|
//HAL_ASSERT_SIZE( int32, 8); // TODO
|
|
//HAL_ASSERT_SIZE(uint32, 8); // TODO
|
|
|
|
|
|
/**************************************************************************************************
|
|
*/
|