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

📄 timer.c

📁 SHARP_ARM720T_LH79524/5软件开发包_支持TFT_LCD_NAND_FLASH_ETH_USB
💻 C
字号:
/**********************************************************************
 * Copyright (c) 2002 Sharp Microelectronics of the Americas
 *
 *        All rights reserved
 *      
 * $Workfile:   timer.c  $
 * $Revision:   1.0  $
 * $Author:   ZhangJ  $
 * $Date:   Oct 20 2004 09:31:54  $
 *
 * 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.
 *
 * Project: LH79524 SDK Example Code
 *
 * Description:
 *    This example shows how to use the timer driver
 *
 * Notes:
 *  
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh79524/bsps/sdk79524/examples/timers/timer.c-arc  $
 * 
 *    Rev 1.0   Oct 20 2004 09:31:54   ZhangJ
 * Initial revision.
 * 
 *    Rev 1.0   Aug 31 2003 09:15:08   ZhangJ
 * Initial revision.
 * 
 * 
 *********************************************************************/

#include "lh79524_chip.h"
#include "lh79524_int_driver.h"
#include "lh79524_timer_driver.h"
 
static INT_32   dev_irq;
static INT_32   dev_timer0 = 0;
static INT_32   timer0_occured = 0;

static void toggle_led(void);

/* Board specific definition */
#define SDK79524_XTAL_IN        11289600 
#define LPD79524_CPLD_LEDREG    (0x4C000000 + 0x00B00000)

/**********************************************************************
*
* Function: timer0_int_handler
*
* Purpose:
*   TIMER0 interruption handler 
*  
* Processing:
*
* Parameters:
*   None
*
* Outputs:
*   None
*
* Returns:
*   Nothing
*
* Notes:
*   None
*
**********************************************************************/
void timer0_int_handler(void)
{ 
    /* Set indication bit */
    timer0_occured = 1;
}

/**********************************************************************
*
* Function: c_entry
*
* Purpose:
*   Function entry point from the startup code.
*  
* Processing:
*   
*
* Parameters:
*   None
*
* Outputs:
*   None
*
* Returns:
*   Nothing
*
* Notes:
*   None
*
**********************************************************************/
INT_32 c_entry (void)
{
    void * intr_handler;

    /* Open IRQ */
    if ((dev_irq = irq_open(0, 0)) == 0x0)
    {
        /* Error opening the device */
        return 0;
    }
        
    /* Open TIMER */
    if ((dev_timer0 = timer0_open(TIMER0_BASE, SDK79524_XTAL_IN)) == 0x0)
    {
        /* Error opening the device */
        return 0;
    }

    /* Clear the counter */
    timer0_ioctl(dev_timer0, TIMER_CLEAR_CNT, 0);
    
    /* Set up the timer clock rate */
    timer0_ioctl (dev_timer0, TIMER_SET_CLK_RATE, TIMER_HCLK_DIV_128);
    
    /* Set up the device to act like a free running counter */
    timer0_ioctl (dev_timer0, TIMER_SET_CNT_MODE, 0);
    
    /* Set up the counter interval - 1 millisecond */
    timer0_ioctl (dev_timer0, TIMER_SET_CMP1, 50000);
    
    /* Set callback function */
    timer0_ioctl(dev_timer0, TIMER_SET_CALLBACK, (INT_32)timer0_int_handler);

    /* Enable IRQ source */
    irq_ioctl(dev_irq, IRQ_ENABLE_SOURCE, VIC_TIMER0);
    
    /* Get a binding to the interrupt service routine */
    timer0_ioctl(dev_timer0, TIMER_GET_ISR, (INT_32)&intr_handler);
  
    /* Set up interruption handler */
    irq_ioctl(dev_irq, IRQ_SET_HANDLER, (INT_32)intr_handler);
    
    /* Enable timer0 compare interrupt */
    timer0_ioctl(dev_timer0, TIMER_ENABLE_INT, TM0_INTCTRL_CMP1);

    /* Enable global IRQ bit */
    irq_ioctl(dev_irq, IRQ_GLOBAL_ENABLE, 1);

    /* Start the timer */
    timer_ioctl(dev_timer0, TIMER_START, 0);
    
    while (1)
    {
        /* wait until timer0 occured */
        if (timer0_occured != 0)    
        {
            /* timer0 occured, clear the bit and wait for new int */
            timer0_occured = 0;
            /* Flashing LED0 */
            toggle_led();
        }      
    }
    
    return 1;
}


/***********************************************************************
*
* Function: toggle_led
*
* Purpose: 
*  Provide a visual annunciator for timer interrupt indication.
*
* Processing: 
*  Rapidly toggle LEDs LED_GPIOA_D8 on the EVB79524 board.
*
* Parameters: None
*
* Outputs: None
*
* Returns: None
*
* Notes: None
*  
**********************************************************************/
static void toggle_led(void)
{
    long i;
    
    /* delay some time */
    for (i=0; i< 100000; i++);    

    /* 
     * Turn off LED0
     * Note: The hardware has a 16-bit address and mirrored at
     *       the following address.
     */
    *((unsigned int *)LPD79524_CPLD_LEDREG) |= 0x00020002;  

    /* delay some time */
    for (i=0; i< 100000; i++);    
    
    /* Turn on LED0 */
    *((unsigned int *)LPD79524_CPLD_LEDREG) &= 0xFFFDFFFD;  

}


#ifdef __iar

void main(void)
{
	c_entry();
	while(1);
}

#endif

⌨️ 快捷键说明

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