//*----------------------------------------------------------------------------
//* 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 : main.c
//* Object : main application written in C
//* Creation : ODi 11/18/2002
//*
//*----------------------------------------------------------------------------
#include "lib_arm920t.h"
#include "AT91RM9200.h"
#include "lib_AT91RM9200.h"
#include "def.h"
#include "console.h"
//* Interrupt Handlers
extern void AT91F_ST_ASM_HANDLER(void);
//* system timer counter
unsigned int StTick = 0;
//*----------------------------------------------------------------------------
//* \fn AT91F_GetTickCount
//* \brief This function returns the value of the system timer
//* This function is for demonstration purpose only
//*----------------------------------------------------------------------------
unsigned int AT91F_GetTickCount(void)
{
return(StTick);
}
//*----------------------------------------------------------------------------
//* \fn AT91F_ST_HANDLER
//* \brief This function is invoked by main
//* This function is for demonstration purpose only
//*----------------------------------------------------------------------------
void AT91F_ST_HANDLER(void)
{
volatile int StStatus;
puts("test st interrupt\n ");
printf("%x\n",StTick );
// Read the system timer status register
StStatus = *(AT91C_ST_SR);
StTick++;
// if(!(StTick&0xff))
// putch('I');
}
void __irq irq_handler(void)
{
void (*svr)(void);
AT91PS_AIC ptr = AT91C_BASE_AIC;
U32 i;
U8 irq_idx;
//取得中断入口地址可用AIC_IVR或用AIC_ISR作索引得到AIC_SVR数组中的地址
i = ptr->AIC_IVR; //read AIC_IVR
irq_idx = ptr->AIC_ISR&0x1f;
//边沿触发中断必须以此清中断
AT91F_AIC_ClearIt(AT91C_BASE_AIC, irq_idx);
// Write in the IVR to support Protect Mode
// No effect in Normal Mode
// De-assert the NIRQ and clear the source in Protect Mode
ptr->AIC_IVR = (AT91_REG)ptr;
puts("I kim\n ");
printf("%x,%x,%x\n", irq_idx, ptr->AIC_IPR, ptr->AIC_CISR);
svr = (void (*)(void))i;//ptr->AIC_SVR[irq_idx];
(*svr)();
AT91F_AIC_AcknowledgeIt(ptr); //退出中断前必须应答
}
static void InitPio(void)
{
//led
AT91F_PIO_CfgOutput(AT91C_BASE_PIOB, AT91C_PIO_PB25|AT91C_PIO_PB26);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB, AT91C_PIO_PB25|AT91C_PIO_PB26);
//key
// AT91F_PIO_CfgInput(AT91C_BASE_PIOB, AT91C_PIO_PB6|AT91C_PIO_PB7|AT91C_PIO_PB8|AT91C_PIO_PB9);
//buzzer
AT91F_PIO_CfgOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);
AT91F_PIO_SetOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);
delay(20);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOB, AT91C_PIO_PB22);
}
//*----------------------------------------------------------------------------
//* \fn main
//* \brief
//*
//*----------------------------------------------------------------------------
int main()
{
puts("\n\n-I- ======================================\n");
puts("-I- AT91RM9200 Timer-counter example\n");
puts("-I- --------------------------------------\n");
InitPio();
//* System Timer initialization
//AT91F_ST_SetPeriodInterval(AT91C_BASE_ST, AT91C_ST_PITS);
AT91F_ST_SetPeriodInterval(AT91C_BASE_ST, 1500);
AT91F_ST_EnableIt(AT91C_BASE_ST, AT91C_ST_PITS);
AT91F_AIC_ConfigureIt (
AT91C_BASE_AIC, // AIC base address
AT91C_ID_SYS, // System peripheral ID
AT91C_AIC_PRIOR_HIGHEST, // Max priority
AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, // Level sensitive
AT91F_ST_ASM_HANDLER );
//* Enable ST interrupt
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);
delay(100);
AT91F_RTC_InterruptDisable(AT91C_BASE_RTC, 0x1f);
// AT91F_ST_DisableIt(AT91C_BASE_ST, 0xf);
*AT91C_PMC_IDR = 0xf0f;
while(1);
}
评论0