📄 timer_example.c
字号:
/***********************************************************************
* $Workfile: timer_example.c $
* $Revision: 1.3 $
* $Author: WellsK $
* $Date: Apr 27 2004 15:00:50 $
*
* Project: Timer driver example
*
* Description:
* A timer driver (interrupt mode) example.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a400/bsps/sdk7a400/examples/timers/timer_example.c-arc $
*
* Rev 1.3 Apr 27 2004 15:00:50 WellsK
* Corrected LED enumeration name for SDK builds.
*
* Rev 1.2 Mar 11 2004 11:22:40 WellsK
* Added IDK support.
*
* Rev 1.1 Oct 01 2003 14:56:46 WellsK
* Added missing file header. Added support for relocatable
* MMU table and interrupt vector areas.
*
*
***********************************************************************
* 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_arm922t_cp15_driver.h"
#include "abl_irq_fiq.h"
#include "lh7a400_int_driver.h"
#include "lh7a400_timer_driver.h"
#include "sdk7a400_cpld_driver.h"
#include "idk7a400_cpld_driver.h"
/* Timer device handles */
INT_32 timer1dev, timer2dev;
/* LED states */
BOOL_32 status_led, gpio_led;
/* Timer count value */
volatile UNS_32 t1count;
/***********************************************************************
*
* Function: timer1_user_interrupt
*
* Purpose: Timer 1 interrupt handler
*
* Processing:
* Clear the timer interrupt and increment the 1Hz interrupt count.
* Toggle the state of the LED and update it.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void timer1_user_interrupt(void)
{
if (status_led == TRUE)
{
/* Toggle state */
status_led = FALSE;
}
else
{
status_led = TRUE;
}
#ifdef IDK
/* Set new state of LED */
idk_enable_led(IDK_RUN_LED, status_led);
#else
/* Set new state of LED */
cpld_enable_led(LED_STATUS1, status_led);
#endif
/* Clear the interrupt and increment count */
timer_ioctl(timer1dev, TIMER_INT_CLEAR, 0);
t1count++;
}
/***********************************************************************
*
* Function: timer2_user_interrupt
*
* Purpose: Timer 2 interrupt handler
*
* Processing:
* Clear the timer interrupt. Toggle the state of the LED and
* update it.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void timer2_user_interrupt(void)
{
if (gpio_led == TRUE)
{
/* Toggle state */
gpio_led = FALSE;
}
else
{
gpio_led = TRUE;
}
#ifdef IDK
/* Set new state of LED */
idk_enable_led(IDK_SLEEP_LED, gpio_led);
#else
/* Set new state of LED */
cpld_enable_led(LED_GPIO, gpio_led);
#endif
/* Clear the interrupt and increment count */
timer_ioctl(timer2dev, TIMER_INT_CLEAR, 0);
}
/***********************************************************************
*
* Function: c_entry
*
* Purpose: Timer driver example
*
* Processing:
* See function. This example sets up the timers with interrupts
* and performs some basic counting.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Always returns 1
*
* Notes: None
*
**********************************************************************/
int c_entry(void)
{
/* Start with both LEDs on */
status_led = gpio_led = TRUE;
/* 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 CPLDs */
cpld_init();
#ifdef IDK
idk_cpld_init();
#endif
/* Initialize interrupt system */
int_initialize(0xC0000000);
/* Install standard IRQ dispatcher at ARM IRQ vector */
int_install_handler(IRQ_VEC, (PFV) irq_dispatcher);
/* Install timers handler in the IRQ dispatcher */
int_install_irq_handler(INT_TC1UINTR, (PFV) timer1_user_interrupt);
int_install_irq_handler(INT_TC2UINTR, (PFV) timer2_user_interrupt);
/* Open timer 1 */
if ((timer1dev = timer_open(TIMER1, 0)) == 0x00000000)
{
return 0;
}
/* Open timer 2 */
if ((timer2dev = timer_open(TIMER2, 0)) == 0x00000000)
{
return 0;
}
/* Setup timer 1 for a 1Hz tick (1000000 microseconds) */
timer_ioctl(timer1dev, TIMER_SET_USECS, (1000 * 1000));
/* Setup timer 2 for a 10Hz tick ((1000000 / 10) microseconds) */
timer_ioctl(timer2dev, TIMER_SET_USECS, (100 * 1000));
/* Enable each timer (starts counting) */
timer_ioctl(timer1dev, TIMER_ENABLE, 1);
timer_ioctl(timer2dev, TIMER_ENABLE, 1);
/* Enable timer interrupts in the interrupt controller */
int_enable(INT_TC1UINTR);
int_enable(INT_TC2UINTR);
/* Clear any latched timer interrupts */
timer_ioctl(timer1dev, TIMER_INT_CLEAR, 0);
timer_ioctl(timer2dev, TIMER_INT_CLEAR, 0);
/* Enable IRQ interrupts in the ARM core */
enable_irq();
/* Wait for 10 seconds and toggle LEDs */
t1count = 0;
while (t1count < 10);
/* Close timers */
timer_close(timer1dev);
timer_close(timer2dev);
/* Disable timer interrupts in the interrupt controller */
int_disable(INT_TC1UINTR);
int_disable(INT_TC2UINTR);
/* Disable ARM core IRQ interrupts */
disable_irq();
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 + -