📄 inth.c
字号:
//**************************************************************************************/
// COMMIT.INC */
// NEPTUNE TESTING CODE INTERRUPT MODULE. */
// REV 0.1 */
// 19/10/05 */
// ZHANGXUGUANG */
//***************************************************************************************
#include "inth.h"
#include "inth_w.h"
#include "UART_IrDA.h"
#include "gpio.h"
#include "interrupt_mapping.h"
extern void Setgroup32bit( unsigned int RegisterAddr, unsigned int bitPosition,
unsigned int bitWidth, unsigned int confValue );
isrpointer armirq[96]; //define 96 interuption pointer. all interruption mustbe
// void function ( );
extern isrpointer gpioirq[64]; //define 96 interuption pointer. all interruption mustbe
//***************************************************************************************/
//Functioin Name:void InitializeParameter( )
//Parameter :No
//Description :initialize all parameter.
//Rev :0.1
//Author :zhangxuguang
//Ecr :1.19/10/05
//****************************************************************************************/
void InitializeParameter( )
{
struct isrParameter initParameter;
initParameter.trigerLowLevel = 1;
initParameter.trigerFallingEdge = 0;
initParameter.inthFiqMode = 1;
initParameter.inthIrqMode = 0;
initParameter.inthPriority = 0xff;
}
//***************************************************************************************/
//Functioin Name: OpenInterrupt( unsigned int )
//Parameter : indexInt indicate which interruption will be open.
//Description : open and interruption from 0 to 95.
//Rev : 0.1
//Author : zhangxuguang
//ECN : 1.25/10/05 changed && to || in No.1 line. this is a logic error.
//***************************************************************************************/
void OpenInterrupt( unsigned int indexInt )
{
if( (indexInt<0 )||(indexInt>= 96 )){
while( 1 );
}
if( indexInt < 32 ){
Setgroup32bit( INTH_L1_MIR,indexInt,1,0x0 ); // open L1 interruption.
}
else if( indexInt<64 ){
Setgroup32bit( INTH_L1_MIR,LEV2_IRQ_INT,1,0x0 ); // open L1 interruption.
Setgroup32bit( INTH_L2_MIR_1,(indexInt-32) ,1 , 0x0 );// open L2 0-31 interruption
}
else{
Setgroup32bit( INTH_L1_MIR,LEV2_IRQ_INT,1,0x0 ); // open L1 interruption.
Setgroup32bit( INTH_L2_MIR_2,(indexInt-64) ,1 , 0x0 );// opent L2 32-63 interrupt.
}
}
//***************************************************************************************/
//Function Name : void InterruptInit( )
//Parameter : No
//Description : Disable all interrupt.
//Rev : 0.1
//Author : zhangxuguang
//Ecr : 1.19/10/05 created.
//***************************************************************************************/
void InterruptInit( )
{
unsigned int inthNumber =0;
for(inthNumber =0;inthNumber < 96;inthNumber++ )
{
armirq[inthNumber] = 0x0;
} //initialization all interruption handler
for(inthNumber =0;inthNumber < 64;inthNumber++ ) //function pointer. it maybe dangeous to
{
gpioirq[inthNumber] = 0x0;
} //corrupt whole software.
Setgroup32bit( INTH_L1_MIR,0,32,0xffffffff); // set l1 mir register to 0xffffffff.
Setgroup32bit( INTH_L2_MIR_1,0,32,0xffffffff); //set L2 gloabl mask register 1.
Setgroup32bit( INTH_L2_MIR_2,0,32,0xffffffff); //set L2 gloabl mask register 2.
}
//***************************************************************************************/
//Function Name : void InterruptProcess( unsigned int );
//Parameter : No
//Description : Disable all interrupt.
//Rev : 0.1
//Author : zhangxuguang
//EcN : 1.19/10/05 created.
// 2.25/10/05 changed && to || in second line. this is a logic error.
//***************************************************************************************/
void InterruptProcess( unsigned int inthIndex )
{
isrpointer isrProcess;
if( (inthIndex >= 96 )||(inthIndex<0) ){
while( 1 );
}
else {
isrProcess = armirq[inthIndex];
(*isrProcess)();
}
return; //return to call function.
}
//***************************************************************************************/
//Function Name : void ConfInterrupt
//Parameter : No
//Description : Configure the interrutp triger, mode..
//Rev : 0.1
//Author : zhangxuguang
//EcN : 1.19/10/05 created.
//***************************************************************************************/
void ConfInterrupt( unsigned int inthNumber, unsigned int irqOrFiq,
unsigned int trigerMode,unsigned int inthPriority )
{
if( (inthNumber <= 31)&&(inthNumber>=0) ){
Setgroup32bit( INTH_L1_ILR_REG(inthNumber),0,1,irqOrFiq ); // ILR REG 0 bit, 0:IRQ, 1:FIQ.
Setgroup32bit( INTH_L1_ILR_REG(inthNumber),1,1,trigerMode); // ILR REG 1 bit, 0:fall edge, 1:low level.
Setgroup32bit( INTH_L1_ILR_REG(inthNumber),2,5,inthPriority); // ILR REG 5 bit,
OpenInterrupt( inthNumber );
}
else if( inthNumber < 64 ){
Setgroup32bit( INTH_L2_ILR_0_31(inthNumber),0,1,irqOrFiq ); // ILR L2 0 bit, 0:IRQ, 1: FIQ
Setgroup32bit( INTH_L2_ILR_0_31(inthNumber),1,1,trigerMode); // ILR L2 1 BIT 0: EDGE, 1: LOW LEVEL.
Setgroup32bit( INTH_L2_ILR_0_31(inthNumber),2,7,(inthPriority-32)); // ILR L2 priority.
OpenInterrupt( inthNumber );
}
else if( inthNumber < 96 ){
Setgroup32bit( INTH_L2_ILR_32_63(inthNumber),0,1,irqOrFiq ); // ILR L2 0 bit, 0:IRQ, 1: FIQ
Setgroup32bit( INTH_L2_ILR_32_63(inthNumber),1,1,trigerMode); // ILR L2 1 BIT 0: EDGE, 1: LOW LEVEL.
Setgroup32bit( INTH_L2_ILR_32_63(inthNumber),2,7,(inthPriority-32)); // ILR L2 priority.
OpenInterrupt( inthNumber );
}
else{
while(1);
}
}
/*-----------------------------------------------------------------------------
* NAME : InterruptClearPending
*
* DESCRIPTION : Clear selected interrupt pending bit
*
* PARAMETERS : irq - Logical Number interrupt
*
* RETURN VALUE : UWORD16 Error Code
* TRUE - ITR/IFR bit write
* FALSE - Wrong Logical Interrupt number
*
*------------------------------------------------------------------------------*/
void InterruptClearPending(UWORD8 ItIndex)
{
UWORD16 ActivItIndex;
UWORD8 section, It_index_in_section;
//Test if the interrupt comes from the second handler
if (ItIndex>31)
{
section = ItIndex/32 - 1;
It_index_in_section = ItIndex % 32;
//Clear the ITR register
ClearBitIndex(REG32(INTH_L1_ITR+section*0x100),It_index_in_section);
}
else
{
//Clear the level1 ITR register
ClearBitIndex(REG32(INTH_L1_ITR),ItIndex);
}
}
//***************************************************************************************/
//Function Name : void DisableInerrupt
//Parameter : 1. interrupt number. 2. disable mode.0: disable all, 1.disable indicated by parameter 1.
//Description : Disable all interrupt.
//Rev : 0.1
//Author : zhangxuguang
//EcN : 1.19/10/05 created.
// 2.25/10/05 change the && to || in No.6 line. this is a logic error.
//***************************************************************************************/
void DisableInerrupt( unsigned inthIndex, unsigned int disableFlag )
{
if ( disableFlag == 0 ){
Setgroup32bit( INTH_L1_MIR,0,32,0xffffffff); //disalbe all INTERRUPT L1.
Setgroup32bit( INTH_L2_MIR_1,0,32,0xffffffff); //disable all interrupt L2.
Setgroup32bit( INTH_L2_MIR_2,0,32,0xffffffff);
}
else if( (inthIndex<0 )||(inthIndex>= 96 )){
while(1);
}
else if( inthIndex < 32 ){
Setgroup32bit( INTH_L1_MIR, inthIndex, 1, 0x1 ); // open L1 interruption.
}
else if( inthIndex < 64 ){
Setgroup32bit( INTH_L2_MIR_1,(inthIndex-32) ,1 , 0x1 );// open L2 0-31 interruption
}
else{
Setgroup32bit( INTH_L2_MIR_2,(inthIndex-64) ,1 , 0x1 );// opent L2 32-63 interrupt.
}
}
//***************************************************************************************/
//Function Name : unsigned int GetInthVector( )
//Parameter : NO
//Description : Get the interruption number .from 0 to 96
//Rev : 0.1
//Author : zhangxuguang
//Ecr :1. 1.19/10/05 created.
//****************************************************************************************/
unsigned int GetInthVectorForIRQ( )
{
unsigned int isrNumber = 0xffff;
isrNumber = 0x0000001f&(*( unsigned int*)( INTH_L1_SIR_IRQ ) ); //Read the sir_l1
if( isrNumber == 0 ) {
isrNumber = 0x0000007f&(*(unsigned int*)( INTH_L2_SIR_IRQ )); //L2 number from 32 to 95
isrNumber = isrNumber + 32;
return isrNumber;
}
else
return isrNumber;
}
//*****************************************************************************************/
//Function Name :void EnableNewInterrupt( )
//Parameter : isrMode :0,IRQ, 1,FIQ
//Description : configure the control register to enable new inth entry.
//Rev : 0.1
//Author : zhangxuguang
//Ecr : 1.19/10/05 created.
//*****************************************************************************************/
void EnableNewInterrupt( unsigned int isrMode )
{
if( isrMode == INTH_IRQ_MODE ){
Setgroup32bit( INTH_L2_CONTROL, 0, 1, 1 ); //control register 0 bit is setted as 1.
Setgroup32bit( INTH_L1_CONTROL, 0, 1, 1 ); //l1 control register 0 bit is setted as 1.
}
else if( isrMode == INTH_FIQ_MODE ){
Setgroup32bit( INTH_L2_CONTROL, 1, 1, 1 ); // enable L2 new fiq generation .
Setgroup32bit( INTH_L1_CONTROL, 1, 1, 1 ); // enable L1 new fiq generation .
}
}
//******************************************************************************************/
//Function Name: unsigned int IsrRegister( unsigned int )
//Parameter : unsigned int inthIndex : to index the interruption's no. 2. functioin's pointer.
//Description : write a function's pointer to a array dependond on the parameter.
//Rev : 0.1
//Author : zhangxuguang
//ECR : 1.24/10/05 created.
//error code : 0: success, 1, common error tbd, 0xff , the parameter is not between the arrange.
//******************************************************************************************/
unsigned int IsrRegister( unsigned int inthIndex , isrpointer isrHandlerName )
{
if ( (inthIndex < 0) ||( inthIndex > 95) ){
return INTH_REQ_FAILED ; // errocde is the parameter is error.
}
else{
armirq[inthIndex] = isrHandlerName; // fill the arry with the handler function
// function's pointer.
}
return INTH_REQ_OK;
}
//=====================================================================//
//EX_AbortD : Abort (data) exception //
//=====================================================================//
#pragma INTERRUPT(EX_AbortD, dabt)
void EX_AbortD (void)
{
UART_Printf(UART2, "An ABORT D was generated\n");
while (1) ;
}
//=====================================================================//
//EX_AbortP : Abort (data) exception //
//=====================================================================//
#pragma INTERRUPT(EX_AbortP, dabt)
void EX_AbortP (void)
{
UART_Printf(UART2, "An ABORT P was generated\n");
while (1) ;
}
//=====================================================================//
//EX_Fiq : FIQ interrupt routine //
//=====================================================================//
#pragma INTERRUPT(EX_FIQ, fiq)
void EX_FIQ (void)
{
UART_Printf(UART2, "An ABORT FIQ was generated\n");
while (1) ;
}
//=====================================================================//
//EX_Irq : IRQ interrupt routine //
//=====================================================================//
#pragma INTERRUPT(EX_IRQ, irq)
void EX_IRQ (void)
{
int inthIndex;
isrpointer isrProcess;
inthIndex = GetInthVectorForIRQ();
// InterruptProcess(dex);
if( (inthIndex >= 96 )||(inthIndex<0) ){
while( 1 );
}
else {
isrProcess = armirq[inthIndex];
(*isrProcess)();
InterruptClearPending(inthIndex);
}
/*
switch(GetInthVectorForIRQ())
{
case 10:
MAILBOX_InthProcess();
UART_Printf(UART2, "A MailBox ABORT IRQ was generated\n");
break;
case 33:
kbcinthprocess();
break;
case 72:
UART_Printf(UART2, "GPIO%d has an interrupt! \r\n", gpio_readirq(2));
UART_Printf(UART2, "Press any key to continue... \r\n");
UART_GetNum(UART2);
break;
default:
break;
}*/
if(inthIndex>=32)
{
Setgroupbit(0xfffe0018, 0, 1, 1 ); // enable new l2 interrupt
}
*(unsigned int *)0xfffecb18 = 0x00000001;
}
//=====================================================================//
//EX_Undef : Undefined interrupt routine //
//=====================================================================//
#pragma INTERRUPT(EX_Undef, udef)
void EX_Undef (void)
{
UART_Printf(UART2, "An undefined instruction abort was generated\n");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -