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

📄 isr.c

📁 Freescale 56800系列DSP的参考C语言源代码
💻 C
字号:
/*-----------------------------------------------------------------------*

	Sample Code for DSP56800 - Jan 2002
	(c) Metrowerks, A Motorola Company.
	
	Source code to illustrate writing ISR in C and the usage
	for #pragma directives necessary to ISR in C
		
 *-----------------------------------------------------------------------*/

#include <stdio.h>
#include "56805.h"
#include "led.h"
#include "isr.h"

static void delay ();

int led_position = 0;
int led_group = 0;

void initIsr ()
{
	asm (bfset #$0100,sr);
	asm (bfclr #$0200,sr);			/* allow lowest priority */
	asm (bfset #$fe12,X:IPR);		/* enable both IRQ A & B, and all other interrupts */

	asm (bfset #$0100,X:GPR10);		/* Timer A Ch 0 lowest priority */	

	/* stop timer 0*/
	asm	(move #$0000,X:TMRA0_CTRL);
	
	/* timer 0 compare 1/2, load, counter */
	asm (move #$ffff,X:TMRA0_CMP1);
	asm (move #$0000,X:TMRA0_CMP2);
	asm (move #$ffff,X:TMRA0_LOAD);
	asm (move #$ffff,X:TMRA0_CNTR);
	
	/* enable timer0 compare interrupt */
	asm (move #$4000,X:TMRA0_SCR);
	
	/* timer0 primary source on bus / 128 */
	asm (move #$3e30,X:TMRA0_CTRL);
}



/* Interrupt-safe function: 
A function call that conserves all register content
(excluding PC,SP) across a call. Please note that 
Standard C libary is not interrupt-safe */


/* ISR that call non interrupt-safe functions need
#pragma interrupt saveall to:

1. call a runtime routine that save all register (except SP,PC)
2. return with RTI */
#pragma interrupt saveall
void isrIRQA ()
{
	/* debounce key with delay for simplicity, disadvantage:
	1. high latency
	2. no repoll of switch state after deounce delay */
	delay ();
	puts ("IRQA detected");	/* Standard C library call */
	offLED (led_group == 0 ? 1 : 3);	/* switch off LED from last group */
	led_group = 0;
}


/* ISR that call non interrupt-safe functions need
#pragma interrupt saveall to:

1. call a runtime routine that save all register (except SP,PC)
2. return with RTI */
#pragma interrupt saveall
void isrIRQB ()
{
	/* debounce key with delay for simplicity, disadvantage:
	1. high latency
	2. no repoll of switch state after deounce delay */
	delay ();
	puts ("IRQB detected");	/* Standard C library call */
	offLED (led_group == 0 ? 1 : 3);	/* switch off LED from last group */
	led_group = 1;
}


/* ISR that does not call interrupt-unsafe functions can use #pragma interrupt to:
1. save all used register
2. return with RTI
*/
#pragma interrupt
void isrTimerA0Compare ()
{
	/* next LED */
	toggleLED (led_group == 0 ? 1 : 3);

	/* clear compare status flags */
	asm (bfclr #$8000,X:TMRA0_SCR);

}


#pragma interrupt called
static void delay ()
{
	long i;
	
	for (i = 0; i < 0x2ffff; i++)
	{
		/* more nop's for consistence across optimization */
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
		asm (nop);
	}
}

⌨️ 快捷键说明

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