DM642外部中断的实现总结

-)在含有操作系统DSP/BIOS的程序中实现外部中断比较简单,只需要进行如下操作:

(1)    在源程序文件中,假设为main.c,在其中添加一个中断处理函数,若要使用外部中断4,可添加函数,这里不需要在前面加入interrupt关键字

void int_isp4()

{

//添加中断处理代码

}

(2)打开DSP/BIOS配置文件xxx.cdb,选择“Scheduling”下的“HWI - Hardware Interrupt Service Routine Manager”项,即HWI模块,它管理着DSP/BIOS中的硬件中断向量表,提供基本的中断控制函数(如图1所示),列出了DM642的所有中断向量表,其中HWI_INT4, HWI_INT5,HWI_INT6, HWI_INT7是外部中断,这里选择HWI_INT4,在其选项上点击右键,选择”Propertyes”,弹出如图2所示:

图1


图2

在function中输入在程序文件中定义的中断处理函数,如第一步所定义的int_isp4,注意在这里记得在其函数名前面加上下划线。由此即可完成对外部中断的配置。

 

(二)在非DSP/BIOS中使用CSL API进行设置相对来说比较复杂一些,主要进行如下操作:

(1)定义描述DM642中断的向量表文件,这里使用TI公司提供的一个中断向量表文件模板:ves_dm642.asm,内容如下:

* Copyright (C) 2003 Texas Instruments Incorporated

* All Rights Reserved

*---------vecs_edma1.asm---------

* Assembly file to set up interrupt servicetable (IST)

*------------------------------------------------------------------------------

* Global symbols defined here and exportedout of this file

*------------------------------------------------------------------------------

  .global _vectors

  .global _c_int00

   .global_vector1

  .global _vector2

  .global _vector3

  .global _ int_isp4

  .global _vector5

  .global _vector6

  .global _vector7

  .global _ vector8

  .global _vector9        

  .global _vector10

  .global _vector11 

  .global _vector12

  .global _vector13  

  .global _vector14  

  .global _vector15  

*------------------------------------------------------------------------------

* Global symbols referenced in this filebut defined somewhere else.

* Remember that your interrupt service routinesneed to be referenced here.

*------------------------------------------------------------------------------

  .ref _c_int00

*------------------------------------------------------------------------------

* This is a macro that instantiates one entryin the interrupt service table.

*------------------------------------------------------------------------------

VEC_ENTRY .macro addr

   STW   B0,*--B15

   MVKL  addr,B0

   MVKH  addr,B0

   B     B0

   LDW   *B15++,B0

   NOP   2

   NOP  

   NOP  

  .endm

*------------------------------------------------------------------------------

* This is a dummy interrupt service routineused to initialize the IST.

*------------------------------------------------------------------------------

_vec_dummy:

 B    B3

 NOP  5

*------------------------------------------------------------------------------

* This is the actual interrupt servicetable (IST). It is properly aligned and

* is located in the subsection .text:vecs.This means if you don't explicitly

* specify this section in your linkercommand file, it will default and link

* into the .text section. Remember to setthe ISTP register to point to this

* table.

*------------------------------------------------------------------------------

 .sect ".text:vecs"

 .align 1024

_vectors:

_vector0:  VEC_ENTRY _c_int00    ;RESET

_vector1:  VEC_ENTRY _vec_dummy  ;NMI

_vector2:  VEC_ENTRY _vec_dummy  ;RSVD

_vector3:  VEC_ENTRY _vec_dummy

_vector4:  VEC_ENTRY _ int_isp4

_vector5:  VEC_ENTRY _ vec_dummy

_vector6:  VEC_ENTRY _vec_dummy

_vector7:  VEC_ENTRY _vec_dummy

_vector8:  VEC_ENTRY _HWIEdma  

_vector9:  VEC_ENTRY _vec_dummy

_vector10: VEC_ENTRY _vec_dummy

_vector11: VEC_ENTRY _vec_dummy

_vector12: VEC_ENTRY _vec_dummy   

_vector13: VEC_ENTRY _vec_dummy

_vector14: VEC_ENTRY _vec_dummy

_vector15: VEC_ENTRY _vec_dummy

*------------------------------------------------------------------------------

(2)在源程序文件main.c中添加外部中断处理函数定义,假设还是使用外部中断4,则在程序中如下定义:

interrupt void int_isp4()

{

//中断处理代码

}

注意这里要在函数定义前面添加interrupt关键字,同时将函数名添加进中断向量表文件的对应位置,如上面程序所示,这里需要在其前面添加下划线(汇编程序调用C语言函数需要在函数加上下划线)。

(3)在源程序的初始化代码中需要对中断进行使能,同时由于外部中断和GPIO口是复用的,因此将GPIO口作为中断输入需要对GPIO口进行配置。具体如下:

 1.GPIO口配置成中断输入:当GPIO口配置成一般输入/输出口时,GPIO引脚上的CPU中断或者EDMA事件产生分为两中:Pass Through模式和Logical模式,我们这里使用Pass Through模式,那么必须进行如下设置(非外部中断不用进行这步操作):

    I.设置GPEN寄存器,把GPxEN位置”1”.

    II设置GPDIR寄存器,把GPxDIR位置”0”,将GPx引脚配置为输入引角,

    III设置GPPOL寄存器,设置GPINTx中断或者事件的触发极性或者触发方式。

用CSL  API函数实现如下:

hGpio=GPIO_open(GPIO_DEV0,GPIO_OPEN_RESET);//打开GPIO句柄

GPIO_pinEnable(hGpio,GPIO_PIN4);//使能GPIO pin4

GPIO_pinDirection(hGpio,GPIO_PIN4,GPIO_INPUT);// 把GP4DIR位置”0”,将GPx引脚配置为输入引角,

GPIO_intPolarity(hGpio,GPIO_GPINT4,GPIO_RISING);//设置GPINT4中断由上升沿触发。

2.中断初始化:

 在声明部分加入:

 extern far void vectors();

 在初始函数中加入:

IRQ_setVecs(vectors);//装载中断向量表;

IRQ_nmiEnable();

IRQ_map(IRQ_EVT_EXTINT4,4);//中断映射外部中断引脚4,EXT_INT4.

IRQ_reset(IRQ_EVT_EXTINT4);

IRQ_enable(IRQ_EVT_EXTINT4);//中断使能。默认IRQ_EVT_EXTINT4是关闭的。

IRQ_globalEnable();//使能全局中断控制位

 至此,在程序运行中便可以响应外部中断了。

注意:在使能外设中断之前,切忌打开全局中断,不然会没反应;


你可能感兴趣的:(DM642外部中断的实现总结)