/*---------------------------------------------------------------------------* Project: CtrBrom - library - pxi File: pxi_misc.c Copyright 2009 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$ *---------------------------------------------------------------------------*/ #include #include static u16 FifoCtrlInit = 0; /*********** function prototypes ******************/ static inline PXIFifoStatus i_pxiGetFromFifo(u32 *data_buf); static inline PXIFifoStatus i_pxiSetToFifo(u32 data); /*---------------------------------------------------------------------------* Name: pxiInitFifoBROM Description: initialize FIFO system for bootrom Arguments: None. Returns: None. *---------------------------------------------------------------------------*/ void pxiInitFifoBROM(void) { OSIntrMode enabled; enabled = osDisableInterrupts(); if (!FifoCtrlInit) { int i; FifoCtrlInit = TRUE; reg_PXI_FIFO_CNT = (REG_PXI_FIFO_CNT_SEND_CL_MASK | REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK); #ifdef SDK_ARM11 pxiSendIDByIntf( BROM_PXI_ID_INIT_ARM9 ); pxiWaitIDByIntf( BROM_PXI_ID_INIT_ARM7 ); #else // SDK_ARM9 pxiSendIDByIntf( BROM_PXI_ID_INIT_ARM7 ); pxiWaitIDByIntf( BROM_PXI_ID_INIT_ARM9 ); #endif // SDK_ARM9 } (void)osRestoreInterrupts(enabled); } /*---------------------------------------------------------------------------* Name: pxiNotifyID Description: Send 4bit id to other processor Arguments: id notifying id Returns: None *---------------------------------------------------------------------------*/ void pxiNotifyID( u32 id ) { pxiSendIDByFifo( PXI_FIFO_TAG_SYSTEM, id ); } /*---------------------------------------------------------------------------* Name: pxiWaitID Description: Wait 4bit id from the other processor Arguments: id waiting id Returns: None *---------------------------------------------------------------------------*/ void pxiWaitID( u32 id ) { pxiWaitIDByFifo( PXI_FIFO_TAG_SYSTEM, id ); } /*---------------------------------------------------------------------------* Name: pxiRecvID Description: Receive 4bit id from the other processor Arguments: None Returns: id *---------------------------------------------------------------------------*/ u8 pxiRecvID( void ) { u8 id; while (pxiRecvIDByFifo(PXI_FIFO_TAG_SYSTEM, &id) != PXI_FIFO_SUCCESS) { } return id; } /*---------------------------------------------------------------------------* Name: pxiSendIDByIntf Description: Send 4bit id to the other processor Arguments: id sending id Returns: None *---------------------------------------------------------------------------*/ void pxiSendIDByIntf( u32 id ) { reg_PXI_INTF = id << REG_PXI_INTF_SEND_SHIFT; } /*---------------------------------------------------------------------------* Name: pxiRecvIDByIntf Description: Receive 4bit id from the other processor Arguments: None Returns: received id *---------------------------------------------------------------------------*/ u32 pxiRecvIDByIntf( void ) { return ((reg_PXI_INTF & REG_PXI_INTF_RECV_MASK) >> REG_PXI_INTF_RECV_SHIFT); } /*---------------------------------------------------------------------------* Name: pxiWaitIDByIntf Description: Wait 4bit id from the other processor Arguments: id waiting id Returns: None *---------------------------------------------------------------------------*/ void pxiWaitIDByIntf( u32 id ) { while (pxiRecvIDByIntf() != id) { } } /*---------------------------------------------------------------------------* Name: pxiSendIDByFifo Description: Send 32bit-word to another CPU via FIFO Arguments: Returns: None *---------------------------------------------------------------------------*/ void pxiSendIDByFifo(PXIFifoTag tag, int id) { static PXIFifoMessage fifomsg; fifomsg.e.tag = tag; fifomsg.e.data = id; while ( i_pxiSetToFifo(fifomsg.raw) != PXI_FIFO_SUCCESS ) { } } /*---------------------------------------------------------------------------* Name: pxiRecvIDByFifo Description: Recv 32bit-word from another CPU via FIFO Arguments: Returns: if error occured, returns minus value *---------------------------------------------------------------------------*/ PXIFifoStatus pxiRecvIDByFifo(PXIFifoTag tag, void* buf) { static PXIFifoMessage fifomsg; u8* p = buf; while ( i_pxiGetFromFifo(&fifomsg.raw) != PXI_FIFO_SUCCESS ) { } if (fifomsg.e.tag != tag) { return PXI_FIFO_FAIL_RECV_ERR; } *p = (u8)fifomsg.e.data; return PXI_FIFO_SUCCESS; } /*---------------------------------------------------------------------------* Name: pxiWaitIDByFifo Description: Wait 32bit-word from another CPU via FIFO Arguments: id waiting id Returns: None *---------------------------------------------------------------------------*/ void pxiWaitIDByFifo(PXIFifoTag tag, u32 id) { u8 buf = (u8)id; do { while (pxiRecvIDByFifo(tag, &buf) != PXI_FIFO_SUCCESS) { } } while ( buf != id ); } /*---------------------------------------------------------------------------* Name: pxiSendDataByFifo Description: Send data to another CPU via FIFO Arguments: Returns: None *---------------------------------------------------------------------------*/ void pxiSendDataByFifo(PXIFifoTag tag, void* buf, int size) { static PXIFifoMessage fifomsg; u32* p = buf; int len = size/4; int i; fifomsg.e.tag = tag; fifomsg.e.data = len; while ( i_pxiSetToFifo(fifomsg.raw) != PXI_FIFO_SUCCESS ) { } for ( i=0; i max_size/4) { return PXI_FIFO_FAIL_SEND_ERR; } for ( i=0; i