/*---------------------------------------------------------------------------* Project: CtrBrom - OS - include File: interrupt.h Copyright 2008 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Date:: $ $Rev$ $Author$ *---------------------------------------------------------------------------*/ #ifndef BROM_OS_INTERRUPT_H_ #define BROM_OS_INTERRUPT_H_ #include #include #include #ifdef SDK_ARM11 #include #else // SDK_ARM9 #include #endif // SDK_ARM9 #ifdef __cplusplus extern "C" { #endif #ifdef SDK_ARM11 #define OS_IDR_INTR_PRIO_DEFAULT 8 // Interrupt priority default (0-15) #endif // SDK_ARM11 typedef u32 OSIntrMode; typedef enum { OS_IRQ_DISABLE = HW_PSR_IRQ_DISABLE, OS_IRQ_ENABLE = 0 } OSIrqMode; typedef enum { OS_FIQ_DISABLE = HW_PSR_FIQ_DISABLE, OS_FIQ_ENABLE = 0 } OSFiqMode; //---- interrupt handler type //typedef IRQ void (*OSIntrHandler) (void); typedef void (*OSIntrHandler) (void); typedef void (*OSIntrFunction) (void); //IRQ void osInterruptHandler( void ); void osInterruptHandler( void ); void i_osInitInterruptTable( void ); void i_osEnableIrqThreadSwitch( void ); OSIntrMode osEnableIrq( void ); OSIntrMode osDisableIrq( void ); OSIntrMode osRestoreIrq( OSIntrMode state ); OSIntrMode osEnableFiq( void ); OSIntrMode osDisableFiq( void ); OSIntrMode osRestoreFiq( OSIntrMode state ); OSIntrMode osEnableIrqAndFiq( void ); OSIntrMode osDisableIrqAndFiq( void ); OSIntrMode osRestoreIrqAndFiq( OSIntrMode state ); /*---------------------------------------------------------------------------* Name: osInitInterrupts Description: Initialize Interrupts Arguments: None Returns: None *---------------------------------------------------------------------------*/ void osInitInterrupt( void ); /*---------------------------------------------------------------------------* Name: osSetInterruptHandler Description: Set interrupt handler Arguments: interrupt ID interrupt handler Returns: None *---------------------------------------------------------------------------*/ void osSetInterruptHandler( OSIntrID id, OSIntrFunction handler ); //================================================================================ // INTERRUPT MASK //================================================================================ /*---------------------------------------------------------------------------* Name: osEnableInterrupts Description: Set CPSR to enable irq and fiq interrupts Arguments: None. Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE *---------------------------------------------------------------------------*/ OSIntrMode osEnableInterrupts( void ); /*---------------------------------------------------------------------------* Name: osDisableInterrupts Description: Set CPSR to disable irq and fiq interrupts Arguments: None. Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE *---------------------------------------------------------------------------*/ OSIntrMode osDisableInterrupts( void ); /*---------------------------------------------------------------------------* Name: osRestoreInterrupts Description: Restore CPSR irq and fiq interrupts Arguments: state of irq interrupt bit Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE *---------------------------------------------------------------------------*/ OSIntrMode osRestoreInterrupts( OSIntrMode state ); /*---------------------------------------------------------------------------* Name: osEnableInterrupts_IrqAndFiq Description: Set CPSR to enable irq and fiq interrupts Arguments: None. Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE *---------------------------------------------------------------------------*/ OSIntrMode osEnableInterrupts_IrqAndFiq( void ); /*---------------------------------------------------------------------------* Name: osDisableInterrupts_IrqAndFiq Description: Set CPSR to disable irq and fiq interrupts Arguments: None. Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE *---------------------------------------------------------------------------*/ OSIntrMode osDisableInterrupts_IrqAndFiq( void ); /*---------------------------------------------------------------------------* Name: osRestoreInterrupts_IrqAndFiq Description: Restore CPSR irq and fiq interrupts Arguments: state of irq interrupt bit Returns: last state of HW_PSR_IRQ_DISABLE & HW_PSR_FIQ_DISABLE *---------------------------------------------------------------------------*/ OSIntrMode osRestoreInterrupts_IrqAndFiq( OSIntrMode state ); /*---------------------------------------------------------------------------* Name: osEnableInterruptID Description: set Interrupt Set Enable Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osEnableInterruptID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osEnableInterruptMask Description: set specified irq factor Arguments: mask irq factor Returns: previous factors *---------------------------------------------------------------------------*/ OSIntrMask osEnableInterruptMask( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osDisableInterruptID Description: set Interrupt Clear Enable Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osDisableInterruptID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osDisableInterruptMask Description: unset specified irq factor Arguments: mask irq factor Returns: previous factors *---------------------------------------------------------------------------*/ OSIntrMask osDisableInterruptMask( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osRestoreInterruptID Description: set Interrupt Clear Enable Register Arguments: id : Interrupt Distributor ID state : state whether interrupt is enabled Returns: TRUE if last state is enabled *---------------------------------------------------------------------------*/ BOOL osRestoreInterruptID( OSIntrID id, BOOL state ); /*---------------------------------------------------------------------------* Name: osSetInterruptMask Description: set irq factor Arguments: mask irq factor Returns: previous factors *---------------------------------------------------------------------------*/ OSIntrMask osSetInterruptMask( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osRestoreInterruptMask Description: set irq factor Arguments: mask irq factor Returns: previous factors *---------------------------------------------------------------------------*/ static inline OSIntrMask osRestoreInterruptMask( OSIntrMask mask ) { return osSetInterruptMask( mask ); } /*---------------------------------------------------------------------------* Name: osGetInterruptMask Description: get irq factor Arguments: None Returns: irq factor which is set now *---------------------------------------------------------------------------*/ static inline OSIntrMask osGetInterruptMask(void) { #ifdef SDK_ARM11 return reg_OS_IDR_SET_IE_ALL; #else // SDK_ARM9 return reg_OS_IE; #endif // SDK_ARM9 } //================================================================================ // INTERRUPT PENDING //================================================================================ /*---------------------------------------------------------------------------* Name: osClearInterruptPendingID Description: set Interrupt Clear Pending Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osClearInterruptPendingID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osClearInterruptPendingMask Description: reset IF bit (setting bit causes to clear bit for interrupt) Arguments: intr irq factor Returns: previous factors *---------------------------------------------------------------------------*/ OSIntrMask osClearInterruptPendingMask( OSIntrMask mask ); #ifdef SDK_ARM11 /*---------------------------------------------------------------------------* Name: osSetInterruptPendingID Description: set Interrupt Set Pending Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osSetInterruptPendingID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osRestoreInterruptPendingID Description: restore Interrupt Pending Arguments: id : Interrupt Distributor ID state : state whether interrupt is enabled Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osRestoreInterruptPendingID( OSIntrID id, BOOL state ); /*---------------------------------------------------------------------------* Name: osSetEndOfInterruptRegister Description: set ID to End of Interrupt Register change state to Inactive. Arguments: Interrupt Distributor ID Returns: None *---------------------------------------------------------------------------*/ void osSetEndOfInterruptRegister( OSIntrID id ); /*---------------------------------------------------------------------------* Name: i_osReadHighestPendingInterruptRegister Description: read ID from Highest Pending Interrupt Register Arguments: None Returns: Interrupt Distributor ID *---------------------------------------------------------------------------*/ OSIntrID i_osReadHighestPendingInterruptRegister( void ); /*---------------------------------------------------------------------------* Name: i_osReadInterruptAcknowledgeRegister Description: read ID from Interrupt Acknowledge Register get interrupt ID and change state to NotPending and Active. Arguments: None Returns: Interrupt Distributor ID *---------------------------------------------------------------------------*/ OSIntrID i_osReadInterruptAcknowledgeRegister( void ); #endif // SDK_ARM11 /*---------------------------------------------------------------------------* Name: osIsInterruptPendingID Description: set Interrupt Clear Pending Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osIsInterruptPendingID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osGetInterruptPendingMask Description: get IF bit Arguments: None Returns: value of IF *---------------------------------------------------------------------------*/ static inline OSIntrMask osGetInterruptPendingMask( void ) { #ifdef SDK_ARM11 return reg_OS_IDR_SET_PND_ALL; #else // SDK_ARM9 return reg_OS_IF; #endif // SDK_ARM9 } //================================================================================ // INTERRUPT HANDLER //================================================================================ /*---------------------------------------------------------------------------* Name: i_osInitInterruptTable Description: initialize irq table Arguments: None Returns: None *---------------------------------------------------------------------------*/ void i_osInitInterruptTable(void); /*---------------------------------------------------------------------------* Name: osSetInterruptHandler Description: set irq handler for specified interrupt Arguments: intrBit irq factor function irq handler for specified interrupt Returns: None *---------------------------------------------------------------------------*/ void osSetInterruptHandler( OSIntrID id, OSIntrFunction function ); /*---------------------------------------------------------------------------* Name: osGetInterruptHandler Description: Get interrupt handler Arguments: interrupt ID interrupt handler Returns: None *---------------------------------------------------------------------------*/ OSIntrFunction osGetInterruptHandler( OSIntrID id ); //================================================================================ // INTERRUPT FLAG (INCLUDING TO WAIT FOR INTERRUPT) //================================================================================ /*---------------------------------------------------------------------------* Name: osSetInterruptCheckID Description: set irq flag to check being called Arguments: irq factors to be set Returns: None *---------------------------------------------------------------------------*/ BOOL osSetInterruptCheckID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osSetInterruptCheckMask Description: set irq flag to check being called Arguments: irq factors to be set Returns: None *---------------------------------------------------------------------------*/ void osSetInterruptCheckMask( OSIntrMask intr ); /*---------------------------------------------------------------------------* Name: osClearInterruptCheckID Description: clear irq flag stored in HW_INTR_CHECK_BUF Arguments: irq factors to be set Returns: None *---------------------------------------------------------------------------*/ BOOL osClearInterruptCheckID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osClearInterruptCheckMask Description: clear irq flag stored in HW_INTR_CHECK_BUF Arguments: irq factors to be cleared Returns: None *---------------------------------------------------------------------------*/ void osClearInterruptCheckMask( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osIsInterruptCheckID Description: check irq flag stored in HW_INTR_CHECK_BUF Arguments: irq factors to be set Returns: None *---------------------------------------------------------------------------*/ BOOL osIsInterruptCheckID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osIsInterruptCheckMask Description: check irq flag stored in HW_INTR_CHECK_BUF Arguments: irq factors to be cleared Returns: TRUE if irq flag exists *---------------------------------------------------------------------------*/ BOOL osIsInterruptCheckMask( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osGetInterruptCheckMask Description: get irq factors stored in HW_INTR_CHECK_BUF Arguments: None Returns: irq flags factors in HW_INTR_CHECK_BUG *---------------------------------------------------------------------------*/ static inline OSIntrMask osGetInterruptCheckMask( void ) { #ifdef SDK_ARM11 return *(OSIntrMask *)HW_INTR_CHECK0_BUF; #else // SDK_ARM9 return *(OSIntrMask *)HW_INTR_CHECK_BUF; #endif // SDK_ARM9 } //================================================================================ // WAIT FOR INTERRUPT //================================================================================ /*---------------------------------------------------------------------------* Name: osWaitInterruptID Description: wait specifiled interrupt. OS_WaitInterrupt doesn't switch thread. OS_WaitInterrupt wait by using OS_Halt(). Arguments: clear TRUE if want to clear interrupt flag before wait. FALSE if not. irqFlags bit of interrupts to wait for Returns: None *---------------------------------------------------------------------------*/ void osWaitInterruptID( BOOL clear, OSIntrID id ); /*---------------------------------------------------------------------------* Name: osWaitInterruptMask Description: wait specifiled interrupt. OS_WaitInterrupt doesn't switch thread. OS_WaitInterrupt wait by using OS_Halt(). Arguments: clear TRUE if want to clear interrupt flag before wait. FALSE if not. irqFlags bit of interrupts to wait for Returns: None *---------------------------------------------------------------------------*/ void osWaitInterruptMask( BOOL clear, OSIntrMask irqFlags ); #ifdef __cplusplus } /* extern "C" */ #endif /* BROM_OS_INTERRUPT_H_ */ #endif