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

📄 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
//*                     : Use LED7 & LED8 for status interrupt
//*
//* 1.0 10/01/02 JPP    : Creation
//*----------------------------------------------------------------------------

//* Part description
#include    "parts/m42800/lib_m42800.h"
#include	"parts/m42800/reg_m42800.h"
#include    "targets/eb42/eb42.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;
    //* Acknowledge interrupt status
    dummy = TC_pt->tc_base->TC_SR;
    count_timer0_interrupt++;
    //* read the ouput state
    if ( (at91_pio_read ( &PIOB_DESC) & LED8 ) == LED8 )
    {
        at91_pio_write ( &PIOB_DESC, LED8, PIO_CLEAR_OUT );
    }
    else
    {
         at91_pio_write ( &PIOB_DESC, LED8, PIO_SET_OUT );
    }
    // enable the next PIO IRQ

}
//*----------------------------------------------------------------------------
//* 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;
    //* Acknowledge interrupt status
    dummy = TC_pt->tc_base->TC_SR;
    count_timer1_interrupt++;

    //* read the ouput state
    if ( (at91_pio_read ( &PIOB_DESC) & LED7 ) == LED7 )
    {
        at91_pio_write ( &PIOB_DESC, LED7, PIO_CLEAR_OUT );
    }
    else
    {
         at91_pio_write ( &PIOB_DESC, LED7, PIO_SET_OUT );
    }
}

//*----------------------------------------------------------------------------
//* 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_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_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_BASE.TC_IDR = -1;                  //  IRQ disable
    at91_irq_close(TC0_DESC.periph_id);

    // close timer1
    at91_tc_close(&TC1_DESC);
    TC1_BASE.TC_IDR = -1;                  //  IRQ disable
    at91_irq_close(TC1_DESC.periph_id);
    at91_pio_write ( &PIOB_DESC, LED7|LED8, PIO_CLEAR_OUT );

    return(TRUE);
//* End
}

⌨️ 快捷键说明

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