AnsweredAssumed Answered

SWT interrupt with MQX

Question asked by Hugo Bouchard on Nov 3, 2016
Latest reply on Nov 15, 2016 by Hugo Bouchard


I want to setup a watchdog but I don't want to use MQX watchdog. I rather use SWT watchdog from the microcontroller (MPC5668G). By the way, I'm using MQX 4.1.1.


Here is the init function to setup the watchdog. As you can see, I've setup the watchdog to interrupt first and then reset on second consecutive timeout. However, even if a watchdog timer timeout occurs, the ISR is never called.


 * Function name: SWT_Init
 * Description:   This function initializes the Software Watchdog Timer.
 * Inputs:
 *     eMode -> Watchdog refresh mode (normal, window)
 *     eAction -> Action to be taken when watchdog timeout occurs
 *     u32Timeout -> Watchdog timeout in ms
 *     u32WindowStartValue -> Value after which watchdog should be refreshed if
 *                            window mode is used (ignored in normal mode) in ms
 *     pfIsr -> Function that will be call upon watchdog timeout
 * Outputs:
 *     None
void SWT_Init(SWT_eWatchdogMode eMode, SWT_eWatchdogAction eAction, uint32_t u32Timeout, uint32_t u32WindowStartValue, INT_EXCEPTION_FPTR pfIsr)
    uint32_t u32NbClkTicks;
    vuint32_t u32TmpTCR;
    vuint32_t u32TmpCR;


    /* Clear any pending interrupt */
    SWT.IR.B.TIF = (vuint32_t)1;


    /* Install interrupt function to be called */
//    _int_install_isr(PSP_EXCPT_WATCHDOG_TIMER, pfIsr, NULL);
    _int_set_exception_handler(PSP_EXCPT_WATCHDOG_TIMER, pfIsr);


    /* Enable watchdog interrupt */
    _PSP_SPR_GET(u32TmpTCR, E200CORE_TCR);
    u32TmpTCR |= E200CORE_TCR_WIE;
    _PSP_SPR_SET(E200CORE_TCR, u32TmpTCR);


    /* Set watchdog mode */
    if(SWT_KE_MODE_WINDOW == eMode)
        u32TmpCR |= SWT_KU32_CR_WND;


        u32NbClkTicks = (SWT_KU32_WATCHDOG_CLOCK_FREQ / (uint32_t)1000) * u32WindowStartValue;
        SWT.WN.R = u32NbClkTicks;
        u32TmpCR &= ~SWT_KU32_CR_WND;


    /* Set action to be taken when watchdog timeout occurs */
        u32TmpCR |= SWT_KU32_CR_ITR;
        u32TmpCR &= ~SWT_KU32_CR_ITR;


    /* Watchdog counter stop in debug mode, enable access by z6 core, enable watchdog and  hardware lock bit */
    u32TmpCR |= (   SWT_KU32_CR_FRZ
                  | SWT_KU32_CR_MAP0
                  | SWT_KU32_CR_HLK
                  | SWT_KU32_CR_WEN);


    /* Set timeout value */
    u32NbClkTicks = (SWT_KU32_WATCHDOG_CLOCK_FREQ / (uint32_t)1000) * u32Timeout;
    SWT.TO.R = u32NbClkTicks;


    /* Update control register */
    SWT.CR.R = u32TmpCR;


Here is what I do in my init task:




/* Initialize and start watchdog */
SWT_Init(SWT_KE_MODE_REGULAR, SWT_KE_ACTION_INTERRUPT_THEN_RESET, (uint32_t)200, (uint32_t)0, HandleWatchdogTimeout);


Here is my ISR function:


void HandleWatchdogTimeout(uint32_t u32IsrVector, uint32_t u32ExceptionVector, void * pvIsrData, void * pvExceptionFrame)

    printf("u32IsrVector: %d\nu32ExceptionVector: %d\n", u32IsrVector, u32ExceptionVector);



I've also tried to setup a simple ISR function with _int_install_isr() but it doesn't work better. Does anyone has an idea of what the problem could be?