⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wdt_example.c

📁 含t h r e a d x,u c o s 的b s p
💻 C
字号:
/***********************************************************************
 * $Workfile:   wdt_example.c  $
 * $Revision:   1.3  $
 * $Author:   WellsK  $
 * $Date:   Apr 15 2004 14:29:44  $
 *
 * Project: WDT driver example
 *
 * Description:
 *     A simple WDT driver example.
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a404/bsps/sdk7a404/examples/wdt/wdt_example.c-arc  $
 * 
 *    Rev 1.3   Apr 15 2004 14:29:44   WellsK
 * Added interrupt wrapper for IAR toolchain.
 * 
 *    Rev 1.2   Oct 01 2003 12:03:58   WellsK
 * Added logic to get TTB address from register CP15 TTB.
 * 
 *    Rev 1.1   Sep 18 2003 09:25:06   WellsK
 * Updated example for MMU and VIC driver changes.
 * 
 *    Rev 1.0   Jul 01 2003 16:13:38   WellsK
 * Initial revision.
 * 
 *
 ***********************************************************************
 * SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
 * OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
 * AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES, 
 * SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
 *
 * SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY 
 * FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A 
 * SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
 * FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
 *
 * COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *     CAMAS, WA
 **********************************************************************/

#include "abl_types.h"
#include "abl_irq_fiq.h"
#include "abl_arm922t_cp15_driver.h"
#include "lh7a404_vic_driver.h"
#include "lh7a404_wdt_driver.h"
#include "sdk7a404_cpld_driver.h"

/* WDT timer interrupt counter */
volatile INT_32 wdtcount;

/* WDT device handle */
INT_32 wdtdev;

/***********************************************************************
 *
 * Function: wdt_fiq_user_handler
 *
 * Purpose: Watchdog timer FIQ interrupt handler
 *
 * Processing:
 *     Reset the watchdog timer and increment the interrupt count.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes:
 *     Be careful using the ((interrupt ("IRQ"))) attribute when using
 *     GNU toolsets. The generated code to save and restore the stacks
 *     doesn't always seem to be correct.
 *
 **********************************************************************/
#ifdef __GNUC__
/* Watchdog timer interrupt handler */
void wdt_fiq_user_handler(void) __attribute__ ((interrupt ("FIQ")));
void wdt_fiq_user_handler(void)
#endif

#ifdef __ghs__
/* Watchdog timer interrupt handler */
__interrupt void wdt_fiq_user_handler(void)
#endif

#ifdef __arm
/* Watchdog timer interrupt handler */
__irq void wdt_fiq_user_handler(void)
#endif

#ifdef __ICCARM__
/* Watchdog timer interrupt handler */
__fiq void wdt_fiq_user_handler(void)
#endif
{
    /* Reset the watchdog timer and increment interrupt count */
    wdt_ioctl(wdtdev, WDT_RESET, 0);
    wdtcount++;
}

/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Watchdog timer example with FIQ interrupts
 *
 * Processing:
 *     See function. This example sets up the FIQ interrupt to call the
 *     WDT handler when an FIQ occurs.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Always returns 1
 *
 * Notes:
 *     Don't try to single step through this program. The watchdog
 *     timer needs to be handled in realtime. Failure to handle the
 *     watchdog timer when it needs it will eventually result in a
 *     chip reset.
 *
 **********************************************************************/
int c_entry(void)
{
    INT_32 oldwdtcount;
    BOOL_32 ledstate = TRUE;

    oldwdtcount = wdtcount = 0;
    
    /* Disable interrupts in ARM core */
    disable_irq_fiq();

    /* Set virtual address of MMU table (needed for VIC driver
       functions) */
    cp15_set_vmmu_addr((UNS_32 *) cp15_get_ttb());

    /* Initialize interrupt system */
    vic_initialize(0xC0000000);

    /* Install WDT interrupt at ARM FIQ vector */
    vic_install_arm_handler(FIQ_VEC, (PFV) wdt_fiq_user_handler);

    /* Enable WDT interrupt as an FIQ interrupt */
    vic_install_handler(VIC_WDTINTR, VIC_FIQ,
        (PFV) wdt_fiq_user_handler);

    /* Open watchdog timer */
    if ((wdtdev = wdt_open(WDTIMER, 0)) == 0x00000000)
    {
        return 0;
    }

    /* Setup WDT for FIQ interrupt first mode */
    wdt_ioctl(wdtdev, WDT_INT_FIRST, 1);
    /* Setup WDT for a PCLK count of 2**(16 + 6) clocks per tick */
    wdt_ioctl(wdtdev, WDT_COUNT, 6);

    /* Enable watchdog timer interrupt in the interrupt controller */
    vic_int_enable(VIC_WDTINTR, TRUE);

    /* Enable FIQ interrupts */
    enable_fiq();

    /* Enable watchdog timer */
    wdt_ioctl(wdtdev, WDT_ENABLE, 1);

    /* Reset the watchdog timer */
    wdt_ioctl(wdtdev, WDT_RESET, 0);

    /* Wait for 25 ticks */
    while (wdtcount < 25)
    {
        if (oldwdtcount != wdtcount)
        {
            oldwdtcount = wdtcount;
            if (ledstate == TRUE)
            {
                /* Toggle state */
                ledstate = FALSE;
            }
            else
            {
                ledstate = TRUE;
            }

            /* Set new state of LED */
            cpld_enable_led(ledstate);
        }
    }

    /* Close watchdog */
    wdt_close(wdtdev);

    /* Disable watchdog timer interrupt in the interrupt controller */
    vic_int_enable(VIC_WDTINTR, FALSE);

    /* Disable ARM core FIQ interrupts */
    disable_fiq();

    return 1;
}

#ifndef __GNUC__
/* With ARM and GHS toolsets, the entry point is main() - this will
   allow the linker to generate wrapper code to setup stacks, allocate
   heap area, and initialize and copy code and data segments. For GNU
   toolsets, the entry point is through __start() in the crt0_gnu.asm
   file, and that startup code will setup stacks and data */
int main(void)
{
    return c_entry();
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -