MOD54415 Watchdog timer implementation

Discussion to talk about software related topics only.
Post Reply
nicobari
Posts: 110
Joined: Mon Jan 30, 2012 12:15 pm

MOD54415 Watchdog timer implementation

Post by nicobari »

Hi,
I am trying to include software watchdog in my code to reset the Netburner in case I get stuck in a loop in my code. I looked up the example for the SBL2E and slightly modified it for MOD54415. My code is include below.

Code: Select all

///included
#include "predef.h"
#include <stdio.h>
#include <stdlib.h>
#include <basictypes.h>
#include <ucos.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <taskmon.h>
#include <smarttrap.h>
#include <effs_fat/fat.h>
#include <effs_fat/multi_drive_mmc_mcf.h>
#include <effs_fat/effs_utils.h>
#include <sim.h>
#include <pins.h>
#include <ucosmcfc.h>
#include <pinconstant.h>
#include <HiResTimer.h>
#include <utils.h>
#include <constants.h>
#include <cfinter.h>
#include <math.h>
#include <serial.h>
#include <dspi.h>
#include <bsp.h>


extern "C" {
void UserMain(void * pd);
    void SetIntc(long func, int vector, int level, int prio);
}

const char * AppName="wdExample";

/*
 * Interrupt occurs if watchdog is not periodically touched. In this case, a hardware reboot will occur
 */
INTERRUPT( wdReset, 0x2700 )
{
    ForceReboot();
}


/*
 * Task that periodically touches watchdog. If not called, an interrupt will be triggered and
 * wdReset will force reboot.
 */
void wdTouch( void *)
{
    while(1)
    {
        OSTimeDly(TICKS_PER_SECOND);
       // sim2.scm.cwsr = 0x55; /******I commented out this portion so that I actually see the netburner restart**********/
       // sim2.scm.cwsr = 0xAA;
    }
}

void UserMain(void * pd) {
    InitializeStack();
    OSChangePrio(MAIN_PRIO);
    EnableAutoUpdate();

    #ifndef _DEBUG
    EnableSmartTraps();
    #endif

    int fd0=0;
    SerialClose(0);

    fd0=OpenSerial( 0, 115200, 1, 8, eParityNone );//

    OSSimpleTaskCreate(wdTouch,MAIN_PRIO-1);

    SetIntc((long) &wdReset,25, 6, 3 ); /**********Level 6 interrupt for source 25 of INTC0 on MOD54415*********/

    iprintf("Starting Watchdog in 5 seconds\r\n");
    OSTimeDly(5*TICKS_PER_SECOND);
    
    sim2.scm.cwcr = 0x819F;/******Starting Watchdog timer**********/

    iprintf("Application started\n");
    int seconds = 0;
    while (1) {
        iprintf("%d\r\n",seconds++);
        OSTimeDly(20);
    }
}
I ran this code but it counts the seconds fine and never restarts even though I have commented out the write of 0x55 and 0xAA to CWSR register. What I might be doing incorrectly? I will appreciate any help in this matter.

Regards,
TM
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: MOD54415 Watchdog timer implementation

Post by rnixon »

My tools install has a 54415 watchdog example in the examples folder. Do you not have that one?
nicobari
Posts: 110
Joined: Mon Jan 30, 2012 12:15 pm

Re: MOD54415 Watchdog timer implementation

Post by nicobari »

I don't have a MOD54415 Watchdog example in my nburn folder. Is there a way you can upload it here so I can take a look at it?

Thanks,
TM
nicobari
Posts: 110
Joined: Mon Jan 30, 2012 12:15 pm

Re: MOD54415 Watchdog timer implementation

Post by nicobari »

I just noticed, I have NBEclipse 2.6.4 and MOD54415 Watchdog example is included in NBEclispse 2.6.5. I don't want to install NBEclipse 2.6.5 as it is still a Beta release.

Thanks,
TM
rlupish
Posts: 26
Joined: Thu Oct 10, 2013 6:15 am

Re: MOD54415 Watchdog timer implementation

Post by rlupish »

The following snippets should work, basically what we have running.

No intc necessary - if watchdog times out, system will reset/reboot.

// Usual #includes...

void WDG_Start(void) {

// Bit #7 is Core Watchdog Enabled: 1 = Enabled 0 = Disabled
// Bit #6-#5 is Core Watchdog reset/interrupt: 10 = reset on 1st timeout
// Bits #4-0 sets core watchdog timeout period: period = 2^^n clock cycles
// Assume system clock is running at 250 MHz
// 0x1C = 2^^30 * system cycle time = about 4.3 second

sim2.scm.cwcr = (vuword) (0xC0 | 0x1E);
}

/*
* ****************************************************************************
* Function:
* void WDG_Stop(void)
*
* This function disenables the watchdog timer.
* The "sim2" class is used to access the processor registers.
*
* Parameters: None
* Return: None
* ****************************************************************************
*/

void WDG_Stop(void) {

// Bit #7 is Core Watchdog Enabled: 1 = Enabled 0 = Disabled

sim2.scm.cwcr &= (vuword) 0xFF7F;
}
/*
* ****************************************************************************
* Function:
* int16u WDG_Is_Enabled (void)
*
* This function reports whether the hardware watchdog timer was
* enabled or not.
*
* Parameters: None
*
* Return:
* 1 = HW WDG is active
* 0 = HW WDG is diabled
* ****************************************************************************
*/

int WDG_Is_Enabled (void) {

if (sim2.scm.cwcr & 0x80)
{
return 1;
}
else
{
return 0;
}
}

/*
* ****************************************************************************
* Function:
* void ServiceWatchdog(void)
*
* The following function is a basic watchdog servicing routine
* to refresh the watchdog counter.
* This routine can be called inside longer wait loops to prevent the
* watchdog timer from resetting the processor.
*
* This routine is specific to the MOD5441X!
*
* Parameters: None
* Return: None
* ****************************************************************************
*/

void ServiceWatchdog(void) {

sim2.scm.cwsr = (vubyte) 0x55;
sim2.scm.cwsr = (vubyte) 0xAA;
return;
}

void UserMain(void * pd)
{
watchdog_service_function = ServiceWatchdog; // This is necessary

WDG_Stop(); // Disable

WDG_Start(); // Enable

while (1)
{
ServiceWatchdog();

OSTimeDly(<Some Number of Ticks);

}
}

nicobari
Posts: 110
Joined: Mon Jan 30, 2012 12:15 pm

Re: MOD54415 Watchdog timer implementation

Post by nicobari »

Thanks for the help.

Regard,
TM
Post Reply