📄 interrupt.c
字号:
/****************************************************************************/
/* */
/* FILE NAME VERSION */
/* */
/* INTERRUPT.C 1.0 */
/* */
/* DESCRIPTION */
/* */
/* JX44B0(S3C44B0X)中断实验 */
/* */
/* */
/* DATA STRUCTURES */
/* */
/* FUNCTIONS : */
/* 在JX44B0教学实验箱进行中断处理的实验 */
/* */
/* DEPENDENCIES */
/* JX44B0-1 */
/* JX44B0-2 */
/* JX44B0-3 */
/* */
/* */
/* NAME: */
/* REMARKS: */
/* */
/* Copyright (C) 2003 Wuhan CVTECH CO.,LTD */
/****************************************************************************/
/****************************************************************************/
/* 学习ARM处理器中非矢量方式处理中断的方法: */
/* 测试中断源:外部中断1 */
/* 中断触发方式:低电平触发 */
/* 中断触发源:按下JX44B0实验箱中的EXINT0按钮将触发该中断 */
/* 注意: 请不要按下EXINT0按钮旁边的按键,该键为复位键,将引发系统复位,如果 */
/* 按下,请断连调试器,并重新连接、重新下载程序,然后运行 */
/****************************************************************************/
/* 包含文件 */
#include "44b.h"
typedef (*ISR_ROUTINE_ENTRY)(void);
void delay();
void ext0_int_isr(void);
void IsrIRQ() __attribute__ ((interrupt("IRQ"))); /* 声明为中断服务里例程 */
int ext0_count = 0;
int dither_count = 0;
/*****************************************************************************
// Function name : IsrIRQ
// Description : 非矢量方式下中断的查表处理
// 中断地址表位于0x0c7fff00开始的256字节
// Return type : void
// Argument : void
*****************************************************************************/
void IsrIRQ()
{
int count = 0;
unsigned int isr_pending;
unsigned int isr_mask = 0x00000001;
unsigned int isr_mask_set = rINTMSK;
ISR_ROUTINE_ENTRY isr_routine_entry = (ISR_ROUTINE_ENTRY)0x0;
__asm__ (
"STMFD SP!, {r1,r4-r8} @ SAVE r1,r4-r10 \n"
"nop \n");
isr_pending = (rINTPND & ~isr_mask_set);
while(isr_mask)
{
if(isr_pending&isr_mask)
{
isr_routine_entry = (ISR_ROUTINE_ENTRY)(*(int*)(HandleADC+count));
break;
}
count+=4;
isr_mask <<= 1;
}
if(isr_routine_entry) (*isr_routine_entry)();
__asm__ (
"LDMFD SP!, {r1,r4-r8} @ RESTORE r1,r4-r10 \n"
"nop \n");
}
/*****************************************************************************
// Function name : init_interrupt_handler
// Description : 非矢量方式下中断向量表初始化处理
// Return type : void
// Argument : irq_handler
// 中断处理函数入口
*****************************************************************************/
void init_interrupt_handler(unsigned int irq_handler)
{
int i;
rINTPND = 0x00000000; /* 清除所有未决的中断*/
rI_ISPC = 0x03FFFFFF;
for( i = 0; i < 256; i+=4) /* 清除中断表*/
{
*(unsigned int*)(_ISR_STARTADDRESS+i) = 0;
}
*(unsigned int*)(HandleIRQ) = irq_handler; /* 设置IRQ模式处理函数 */
}
/*****************************************************************************
// Function name : install_isr_handler
// Description : 非矢量方式下中断向量的安装
// Return type : void
// Argument : irq_no, 中断号
// irq_routine, 中断处理函数地址
*****************************************************************************/
void install_isr_handler(int irq_no, void* irq_routine)
{
*(unsigned int*)(irq_no) = (unsigned int)irq_routine;
}
/*****************************************************************************
// Function name : Main
// Description : 中断测试程序主函数
// 实现外部中断0的测试,引发中断后在中断处理函数中显示跑马灯
// Return type : int
// Argument : void
*****************************************************************************/
int Main()
{
int old_index ;
rINTCON=0x7; /* Non-vect,IRQ disable,FIQ disable */
init_interrupt_handler((unsigned int)IsrIRQ);
install_isr_handler(HandleEINT0, (void*)ext0_int_isr);
rINTMOD=0x0; /*设置所有中断为IRQ模式 */
rINTMSK=(0x07ffffff&~(BIT_GLOBAL|BIT_EINT0)); /*使能外部中断0 */
rINTCON=0x5; /*Non-vect,IRQ enable,FIQ disable */
ext0_count = 0;
dither_count = 0;
while(1)
{
delay();
dither_count++;
}
}
/*****************************************************************************
// Function name : ext0_int_isr
// Description : 外部中断0处理函数
// Return type : int
// Argument : void
*****************************************************************************/
void ext0_int_isr(void)
{
rI_ISPC=BIT_EINT0; /*清除外部中断0 */
if(dither_count > 5)
{
dither_count = 0;
if(ext0_count&1) /*交替显示发光二极管 */
*(unsigned char*)0x2000000 = 0xff;
else
*(unsigned char*)0x2000000 = 0x0f;
ext0_count++;
}
}
void delay()
{
int index = 0;
for ( index = 0 ; index < 100000; index++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -