mirror of
https://github.com/rvtr/ctr_firmware.git
synced 2025-10-31 07:51:08 -04:00
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_firmware@152 b871894f-2f95-9b40-918c-086798483c85
356 lines
9.1 KiB
C
356 lines
9.1 KiB
C
/*---------------------------------------------------------------------------*
|
|
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 <brom/os.h>
|
|
#include <brom/pxi.h>
|
|
|
|
|
|
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<len; i++ )
|
|
{
|
|
while ( i_pxiSetToFifo(p[i]) != PXI_FIFO_SUCCESS )
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*
|
|
Name: pxiRecvDataByFifo
|
|
|
|
Description: Recv data to another CPU via FIFO
|
|
|
|
Arguments:
|
|
|
|
Returns: if error occured, returns minus value
|
|
*---------------------------------------------------------------------------*/
|
|
PXIFifoStatus pxiRecvDataByFifo(PXIFifoTag tag, void* buf, int max_size )
|
|
{
|
|
static PXIFifoMessage fifomsg;
|
|
u32* p = buf;
|
|
int len;
|
|
int i;
|
|
|
|
while ( i_pxiGetFromFifo(&fifomsg.raw) != PXI_FIFO_SUCCESS )
|
|
{
|
|
}
|
|
|
|
if (fifomsg.e.tag != tag)
|
|
{
|
|
return PXI_FIFO_FAIL_SEND_ERR;
|
|
}
|
|
|
|
len = fifomsg.e.data;
|
|
|
|
if (len > max_size/4)
|
|
{
|
|
return PXI_FIFO_FAIL_SEND_ERR;
|
|
}
|
|
|
|
for ( i=0; i<len; i++ )
|
|
{
|
|
while ( i_pxiGetFromFifo(&p[i]) != PXI_FIFO_SUCCESS )
|
|
{
|
|
}
|
|
}
|
|
|
|
return PXI_FIFO_SUCCESS;
|
|
}
|
|
|
|
|
|
//======================================================================
|
|
// Write Send-FIFO reg.
|
|
//======================================================================
|
|
static inline PXIFifoStatus i_pxiSetToFifo(u32 data)
|
|
{
|
|
OSIntrMode enabled;
|
|
|
|
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_ERR_MASK)
|
|
{
|
|
reg_PXI_FIFO_CNT |= (REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK);
|
|
return PXI_FIFO_FAIL_SEND_ERR;
|
|
}
|
|
|
|
enabled = osDisableInterrupts();
|
|
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_SEND_FULL_MASK)
|
|
{
|
|
(void)osRestoreInterrupts(enabled);
|
|
return PXI_FIFO_FAIL_SEND_FULL;
|
|
}
|
|
|
|
reg_PXI_SEND_FIFO = data;
|
|
(void)osRestoreInterrupts(enabled);
|
|
return PXI_FIFO_SUCCESS;
|
|
}
|
|
|
|
|
|
//======================================================================
|
|
// Read Send-FIFO reg.
|
|
//======================================================================
|
|
static inline PXIFifoStatus i_pxiGetFromFifo(u32 *data_buf)
|
|
{
|
|
|
|
OSIntrMode enabled;
|
|
|
|
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_ERR_MASK)
|
|
{
|
|
reg_PXI_FIFO_CNT |= (REG_PXI_FIFO_CNT_E_MASK | REG_PXI_FIFO_CNT_ERR_MASK);
|
|
return PXI_FIFO_FAIL_RECV_ERR;
|
|
}
|
|
|
|
enabled = osDisableInterrupts();
|
|
if (reg_PXI_FIFO_CNT & REG_PXI_FIFO_CNT_RECV_EMP_MASK)
|
|
{
|
|
(void)osRestoreInterrupts(enabled);
|
|
return PXI_FIFO_FAIL_RECV_EMPTY;
|
|
}
|
|
|
|
*data_buf = reg_PXI_RECV_FIFO;
|
|
(void)osRestoreInterrupts(enabled);
|
|
|
|
return PXI_FIFO_SUCCESS;
|
|
}
|
|
|
|
|