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

📄 interrupt_timer.c

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 C
字号:
//*----------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : interrupt_timer.c
//* Object              : Use the timer interrupt
//*
//* 1.0 19/02/01 JPP    : Creation
//* 1.0 27/03/01 JPP    : Additing Timer 1
//*----------------------------------------------------------------------------

//* Part description
#include    "parts/m63200/lib_m63200.h"
#include    "targets/eb63/eb63.h"

// Use the Library Handler defined in file periph/pio/pio_irq/irq_pio.s
extern void timer0_asm_irq_handler(void);
extern void timer1_asm_irq_handler(void);

//* Global variable
extern int count_timer0_interrupt;
extern int count_timer1_interrupt;

//*----------------------------------------------------------------------------
//* Function Name       : timer0_c_irq_handler
//* Object              : C handler interrup function called by the interrups
//*                       assembling routine
//* Input Parameters    : <RTC_pt> time rtc descriptor
//* Output Parameters   : increment count_timer0_interrupt
//*----------------------------------------------------------------------------
void timer0_c_irq_handler(TCDesc *TC_pt)
{
	u_int dummy;
    if ( (at91_pio_read ( &PIOB_DESC) & LED4 ) == LED4 )
    {
        at91_pio_write ( &PIOB_DESC, LED4, PIO_CLEAR_OUT );
    }
    else
    {
         at91_pio_write ( &PIOB_DESC, LED4, PIO_SET_OUT );
    }

	//* Acknowledge interrupt status
	dummy = TC_pt->tc_base->TC_SR;
	count_timer0_interrupt++;

}
//*----------------------------------------------------------------------------
//* Function Name       : timer0_c_irq_handler
//* Object              : C handler interrup function called by the interrups
//*                       assembling routine
//* Input Parameters    : <RTC_pt> time rtc descriptor
//* Output Parameters   : increment count_timer1_interrupt
//*----------------------------------------------------------------------------
void timer1_c_irq_handler(TCDesc *TC_pt)
{
	u_int dummy;
    if ( (at91_pio_read ( &PIOB_DESC) & LED5 ) == LED5 )
    {
        at91_pio_write ( &PIOB_DESC, LED5, PIO_CLEAR_OUT );
    }
    else
    {
         at91_pio_write ( &PIOB_DESC, LED5, PIO_SET_OUT );
    }

	//* Acknowledge interrupt status
	dummy = TC_pt->tc_base->TC_SR;
	count_timer1_interrupt++;

}

//*----------------------------------------------------------------------------
//* Function Name       : timer_init
//* Object              : Init timer counter
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
int timer_init ( void )
//* Begin
{
	//init the timer interrupt counter
    count_timer0_interrupt=0;
    count_timer1_interrupt=0;
	// open timer0
	at91_tc_open(&TC0_DESC, TC_CLKS_MCK1024 ,FALSE, FALSE);
	TC0_DESC.tc_base->TC_IER  = TC_CPCS;  //  IRQ enable CPC
	at91_irq_open(TC0_DESC.periph_id,3,AIC_SRCTYPE_INT_LEVEL_SENSITIVE,timer0_asm_irq_handler);
	// open timer1
	at91_tc_open(&TC1_DESC, TC_CLKS_MCK128 ,FALSE, FALSE);
	TC1_DESC.tc_base->TC_IER = TC_CPCS;  //  IRQ enable CPC
	at91_irq_open(TC1_DESC.periph_id,4,AIC_SRCTYPE_INT_LEVEL_SENSITIVE,timer1_asm_irq_handler);

	//* generate interrupt by software
    at91_irq_trig_cmd(TC0_DESC.periph_id,0);
    at91_irq_trig_cmd(TC1_DESC.periph_id,0);

     //* Start timer0
    at91_tc_trig_cmd(&TC0_DESC, TC_TRIG_CHANNEL);
     //* Start timer1
    at91_tc_trig_cmd(&TC1_DESC, TC_TRIG_CHANNEL);

    return(TRUE);
//* End
}
//*----------------------------------------------------------------------------
//* Function Name       : timer_close
//* Object              : Init timer counter
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
int timer_close ( void )
//* Begin
{
	// open timer0
	at91_tc_close(&TC0_DESC);
	TC0_DESC.tc_base->TC_IDR = -1;  //  IRQ disaable
	at91_irq_close(TC0_DESC.periph_id);
	// close timer1
	at91_tc_close(&TC1_DESC);
	TC1_DESC.tc_base->TC_IDR = -1;  //  IRQ disaable
	at91_irq_close(TC1_DESC.periph_id);

    return(TRUE);
//* End
}

⌨️ 快捷键说明

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