/*---------------------------------------------------------------------------* 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 #ifdef __cplusplus extern "C" { #endif //================================================================================ // INTERRUPT MASK //================================================================================ /*---------------------------------------------------------------------------* Name: osSetInterruptMask Description: set irq factor Arguments: mask irq factor Returns: previous factors *---------------------------------------------------------------------------*/ OSIntrMask osSetInterruptMask( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osGetInterruptMask Description: get irq factor Arguments: None Returns: irq factor which is set now *---------------------------------------------------------------------------*/ static inline OSIntrMask osGetInterruptMask(void) { return reg_OS_IE; } /*---------------------------------------------------------------------------* Name: osEnableInterruptMask Description: set specified irq factor Arguments: mask irq factor Returns: previous factors *---------------------------------------------------------------------------*/ OSIntrMask osEnableInterruptMask( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osDisableInterruptMask Description: unset specified irq factor Arguments: mask irq factor Returns: previous factors *---------------------------------------------------------------------------*/ OSIntrMask osDisableInterruptMask( 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: osEnableInterruptID Description: set Interrupt Set Enable Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osEnableInterruptID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osDisableInterruptID Description: set Interrupt Clear Enable Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osDisableInterruptID( OSIntrID id ); /*---------------------------------------------------------------------------* 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 ); //================================================================================ // INTERRUPT PENDING //================================================================================ /*---------------------------------------------------------------------------* 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 ); /*---------------------------------------------------------------------------* Name: osGetInterruptPendingMask Description: get IF bit Arguments: None Returns: value of IF *---------------------------------------------------------------------------*/ static inline OSIntrMask osGetInterruptPendingMask( void ) { #ifdef SDK_ARM9 return reg_OS_IF; #else // MPCORE return reg_OS_IDR_SET_PENDING_ST; #endif // MPCORE } /*---------------------------------------------------------------------------* Name: osClearInterruptPendingID Description: set Interrupt Clear Pending Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ BOOL osClearInterruptPendingID( OSIntrID id ); /*---------------------------------------------------------------------------* Name: osIsInterruptIDPending Description: set Interrupt Clear Pending Register Arguments: Interrupt Distributor ID Returns: TRUE if last state is pending *---------------------------------------------------------------------------*/ static inline BOOL osIsInterruptPending( OSIntrID id ) { #ifdef SDK_ARM11 u32 ofs = id/32; u32 sft = id%32; BOOL retval; retval = TRUE & (reg_OS_IDR_SET_PND[ofs] >> sft); #else // SDK_ARM9 OSIntrMask prep = reg_OS_IF; BOOL retval; retval = TRUE & (BOOL)(prep >> id); #endif // SDK_ARM9 return retval; } //================================================================================ // 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 CHECK //================================================================================ /*---------------------------------------------------------------------------* Name: osSetInterruptCheckFlag Description: set irq flag to check being called Arguments: irq factors to be set Returns: None *---------------------------------------------------------------------------*/ void osSetInterruptCheckFlag( OSIntrMask intr ); /*---------------------------------------------------------------------------* Name: osClearInterruptCheckFlag Description: clear irq flag stored in HW_INTR_CHECK_BUF Arguments: irq factors to be cleared Returns: None *---------------------------------------------------------------------------*/ void osClearInterruptCheckFlag( OSIntrMask mask ); /*---------------------------------------------------------------------------* Name: osGetInterruptCheckFlag Description: get irq factors stored in HW_INTR_CHECK_BUF Arguments: None Returns: irq flags factors in HW_INTR_CHECK_BUG *---------------------------------------------------------------------------*/ static inline OSIntrMask osGetInterruptCheckFlag( void ) { return *(OSIntrMask *)HW_INTR_CHECK_BUF; } //================================================================================ // WAIT FOR INTERRUPT //================================================================================ /*---------------------------------------------------------------------------* Name: osWaitInterrupt 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 osWaitInterrupt( BOOL clear, OSIntrMask irqFlags ); //================================================================================ // INTERRUPT FLAG (INCLUDING TO WAIT FOR INTERRUPT) //================================================================================ /*---------------------------------------------------------------------------* Name: osInitIntrFlag Description: Initialize eventflag and task for interrupts Arguments: None Returns: TRUE if success. *---------------------------------------------------------------------------*/ BOOL osInitIntrFlag( void ); /*---------------------------------------------------------------------------* Name: osWaitInterruptID Description: wait specifiled interrupt. Arguments: id interrupt ID to wait Returns: None *---------------------------------------------------------------------------*/ BOOL osWaitInterruptID( int id ); /*---------------------------------------------------------------------------* Name: osWaitInterruptMask Description: wait specifiled mask for interrupts. supported only 0-31 Arguments: mask interrupt mask to wait Returns: received interrupt mask, 0 if failed. NOTE: non-waiting interrupt bits may set *---------------------------------------------------------------------------*/ OSIntrMask osWaitInterruptMask( OSIntrMask mask ); #ifdef __cplusplus } /* extern "C" */ #endif /* BROM_OS_INTERRUPT_H_ */ #endif