原文章地址:http://blog.csdn.net/jbb0523/article/details/7822437
题目:DSP中断的使用——个人第一例:定时器中断的使用
软件开发环境环境:CCS3.1,在CCS Setup中设置成Simulator模式
CPU:TMS320C6416
工程共包含三个文件:main.c,Vectors.asm,BootLoader.cmd
另外还添加了一个库文件:rts6400.lib,根据我的CCS安装目录,该文件位于C:CCStudio_v3.1C6000cgtoolslib目录下
【源文件main.c】
//由于使用了printf函数
#include
/*定义控制寄存器*/
extern cregister volatile unsigned int AMR; /* Address Mode Register */
extern cregister volatile unsigned int CSR; /* Control Status Register */
extern cregister volatile unsigned int IFR; /* Interrupt Flag Register */
extern cregister volatile unsigned int ISR; /* Interrupt Set Register */
extern cregister volatile unsigned int ICR; /* Interrupt Clear Register */
extern cregister volatile unsigned int IER; /* Interrupt Enable Register */
extern cregister volatile unsigned int ISTP; /* Interrupt Service Tbl Ptr */
extern cregister volatile unsigned int IRP; /* Interrupt Return Pointer */
extern cregister volatile unsigned int NRP; /* Non-maskable Int Return Ptr*/
extern cregister volatile unsigned int IN; /* General Purpose Input Reg */
extern cregister volatile unsigned int OUT; /* General Purpose Output Reg */
/* 定义中断选择寄存器 */
#define MUXH 0x019C0000
#define MUXL 0x019C0004
#define EXTPOL 0x019C0008
/*定义定时器1寄存器*/
#define CTL1 0x01980000 //Timer1 control register
#define PRD1 0x01980004 //Timer1 period register
#define CNT1 0x01980008 //Timer1 counter register
int counter = 0;//记录中断次数
interrupt void xint0_isr(void)
{
counter ++;
printf("xint0_isr:%d
",counter);
}
void Interrupt_Init(void)
{
ICR = 0x00000400;
*( volatile unsigned int* )MUXH=0x7fff7fe2;//DSP中断10分配给Timer中断
*( volatile unsigned int* )CTL1= 0x00000201; //计数器功能设置
*( volatile unsigned int* )PRD1= 0x1000; //计数器周期值
}
void Interrupt_Start(void)
{
IER |= 0x00000402; // IE10=1
CSR |= 0x00000001; // 全局中断使能
*( volatile unsigned int* )CTL1|= 0x000000C0; //计数器清零,启动
}
void main()
{
Interrupt_Init();
printf("interrupt init done!
");
Interrupt_Start();
while(1)
{
;
}
}
【源文件Vectors.asm】
.ref _c_int00
.ref _xint0_isr ; timer 1 interrupt handler
.sect ".vectors"
RESET_RST:
mvkl .S2 _c_int00, B0
mvkh .S2 _c_int00, B0
B .S2 B0
NOP
NOP
NOP
NOP
NOP
NMI_RST:
b nrp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RESV1:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
RESV2:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT4:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT5:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT6:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT7:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT8:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT9:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT10:
b _xint0_isr
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT11:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT12:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT13:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT14:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
INT15:
b irp
NOP
NOP
NOP
NOP
NOP
NOP
NOP
【源文件BootLoader.cmd】
-c
-o jbb0523.out
-m jbb0523.map
-heap 0x2000
-stack 0x4000
-l rts6400.lib
MEMORY
{
BOOT_RAM: origin = 00000000h, length = 00000400h
IRAM: origin =00000400h length =200000h
SRAM: origin =80000000h length =400000h
}
SECTIONS
{
.vectors : > BOOT_RAM
.vec : > IRAM
.text : > IRAM
.cinit : > IRAM
.stack : > IRAM
.bss : > IRAM
.far : > IRAM
.sysmem : > IRAM
.cio : > IRAM
.switch : > IRAM
.const : > IRAM
.heap : > IRAM
}
=================================================
源代码到此结束,编译链接后,load program,加载生成的jbb0523.out,然后run,可以看到如下现象:
调试过程中,可以通过View---Registers菜单项,添加Core Registers,TimerRegisters和Interrupt Registers,如下图所示
从以上窗口中,可以看到相关的寄存器的值。