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

📄 irq_ser.c

📁 AT91所有开发板的资料 AT91所有开发板的资料
💻 C
字号:
/*******************************************************************************
 * 
 * ARM Strategic Support Group
 *
 *******************************************************************************/

/*******************************************************************************
 *
 * Module       : irq_ser.c
 * Description  : Setups Samsung KS32C50100 IRQ registers and services the IRQ's 
 *				  (button interrupt requests)
 * Tool Chain	: ARM Developer Suite v1.0
 * Platform     : Evaluator7T
 * History      : 
 *
 *		980416 ASloss
 *      - added button interrupt service
 *      - added header information
 *		  
 *		980625 ASloss
 *		- irq_installhandler alter to be Load PC compatible
 *
 *		980730 ASloss
 *		- added swi_chandler
 *
 *		2000-04-04 Andrew N. Sloss
 *		- port to Evaluator7T
 *	
 * Notes        : Refer to the Samsung KS32C50100 documentation 
 *
 *******************************************************************************/

/*******************************************************************************
 * IMPORT
 *******************************************************************************/

#include <stdio.h>
#include "swi.h"

/*******************************************************************************
 * MACRO'S
 *******************************************************************************/

// -- Samsung KS32C50100 specifics...........

#define SYSCFG				0x03FF0000
#define IOPMOD      		((volatile unsigned *)(SYSCFG + 0x5000))
#define IOPCON      		((volatile unsigned *)(SYSCFG + 0x5004))
#define IOPDATA     		((volatile unsigned *)(SYSCFG + 0x5008))

#define INTPND				((volatile unsigned *)(SYSCFG + 0x4004))
#define INTMSK				((volatile unsigned *)(SYSCFG + 0x4008))
#define INT_GLOBAL			(21)

#define INT_SW3_MASK		(1)

#define IO_ENABLE_INT0		(1<<4)
#define IO_ACTIVE_HIGH_INT0	(1<<3)
#define IO_RISING_EDGE_INT0	(1)


// -- Standard ARM vector locations.......... 

#define IRQVector (unsigned *) 0x18
#define SWIVector (unsigned *) 0x08

/*****************************************************************************
 * EXTERN's
 *****************************************************************************/

extern void handler_irq(void);
extern void handler_swi(void);
extern void switch_swi (void);
extern void SetupSVC(void);
extern int  Angel_IRQ_Address;
extern int  Angel_SWI_Address;

/*****************************************************************************
 * STATICS
 *****************************************************************************/

// none...

/*****************************************************************************
 * ROUTINES
 *****************************************************************************/

/* -- irq_installIRQhandler ------------------------------------------------------
 *                                                            
 * Description  : Places a branch instruction for the routine into the defined 
 *                'vector' location - this function returns the original 
 *                contents of the 'vector      
 *
 * Parameters   : unsigned routine - IRQ handler
 *		: unsigned *vector - IRQ vector   
 * Return       : 
 * Notes        : 'routine' MUST BE WITHIN A  RANGE OF 32Mbytes FROM 'vector'
 *                                                                             
 */

static void irq_installIRQhandler (unsigned routine, unsigned *vector) 
{
unsigned old_vector_value = 0;
unsigned *absolute;   
  
   old_vector_value = 0;

	/*******************************************************************************	
	 * Now the inverse must be done on the original vector to retrieve the Angel   *
	 * IRQ Handler routine .                                                       *
	 *******************************************************************************/
   
   old_vector_value  = *vector;  	 // Get old vector contents ....................
   old_vector_value ^= 0xe59ff000;	 // Mask off the instruction to get the offset
 
	// ** calculate absolute address

   absolute	     	= (unsigned *) (0x18 +old_vector_value+0x8); 
					// IRQ Address
   Angel_IRQ_Address 	= *absolute; 	// chain Angel Interrupt Handler	  
   *absolute		= routine; 	// IRQ handler

}

/* -- irq_installSWIhandler ------------------------------------------------------
 *                                                            
 * Description  : Places a branch instruction for the routine into the defined 
 *                'vector' location - this function returns the original 
 *                contents of the 'vector      
 *
 * Parameters   : unsigned routine - IRQ handler
 *		: unsigned *vector - IRQ vector   
 * Return       : 
 * Notes        : 'routine' MUST BE WITHIN A  RANGE OF 32Mbytes FROM 'vector'
 *                                                                             
 */

static void irq_installSWIhandler (unsigned routine, unsigned *vector) 
{
unsigned old_vector_value;
unsigned *absolute;   
  
   old_vector_value = 0;

	/*******************************************************************************	
	 * Now the inverse must be done on the original vector to retrieve the Angel   *
	 * IRQ Handler routine .                                                       *
	 *******************************************************************************/
   
   old_vector_value  = *vector;  	 // Get old vector contents ....................
   old_vector_value ^= 0xe59ff000;	 // Mask off the instruction to get the offset
 
	// ** calculate absolute address

   absolute	     	= (unsigned *)  (0x8+old_vector_value+0x8); 
					// SWI Address
   Angel_SWI_Address 	= *absolute; 	// chain Angel Interrupt Handler	  
   *absolute		= routine; 	// SWI handler

}

/* -- irq_initbutton ---------------------------------------------------------
 *                                                            
 * Description  :  Initialises the button interrupt    
 *
 * Parameters   : none...   
 * Return       : none...
 * Notes        : none...
 *                                                                             
 */

static void irq_initbutton (void)
{
  // -- unmask interrupts for the button ................
	
  *(volatile int*)INTMSK &= ~((1 << INT_GLOBAL) | (1 <<0));   
		
  *IOPCON 	|= IO_ENABLE_INT0; 			// enable int0
  *IOPCON	|= IO_ACTIVE_HIGH_INT0; 	// set as active high
  *IOPCON	|= IO_RISING_EDGE_INT0;		// allow for RISING EDGE
}


/* -- irq_buttonpress -----------------------------------------------------------
 *
 * Description  : handles the button press interrupt...
 *
 * Parameters   : none...
 * Return       : none...
 * Notes        : none...
 *
 */ 

void  irq_buttonpress (void) 
{
   /* Read in the Interrupt source .................................. */

	swi_interrupt ();
	
	*(unsigned *) INTPND |= INT_SW3_MASK;
}

/* -- irq_init ----------------------------------------------------------------
 * 
 * Description  : This module is where all system setup would be placed - in 
 *                this case it is only Counter/Timer that we are initialising 
 *                so we only have a routine to initialise this. Also called 
 *                from here is the Interrupt Handler install routine and 
 *                initialize button interrupt
 *
 * Parameters   : none...
 * Return       : none...
 * Notes        : none...
 *
 */

void irq_init (void)
{
	SetupSVC();		/* This is necessary if Angel is not running
				 *  on the target (as when running semi-hosted
				 *  from E-Ice) otherwise, let Angel handle it */

	irq_initbutton ();

	irq_installIRQhandler ((unsigned)handler_irq, IRQVector);
	irq_installSWIhandler ((unsigned)handler_swi, SWIVector);
}

/* -- swi_chandler --------------------------------------------------------------
 * 
 * Description	: SWI C handler - check the SWI number and call the correct
 *                routine...
 *
 *
 * Parameters	: unsigned swi_number 
 * Return	: none... 
 * Other info	: none... 
 *
 */
 
void swi_chandler (unsigned swi_number)
{

	//
	// ** SWI List ....................................
 	//

	switch (swi_number) {

	case	0x55075:	

		break;

	case	0x78:

		swi_78_routine ();
		break;

	default		:
		break;	
	}	

}	


/*******************************************************************************
 * END OF irq_ser.c
 *******************************************************************************/

⌨️ 快捷键说明

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