📄 utopia2_example.c
字号:
/* ============================================================================
* Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2006
*
* Use of this software is controlled by the terms and conditions found
* in the license agreement under which this software has been supplied.
* ============================================================================
*/
/** ============================================================================
* @file Utopia2_example.c
*
* @path $(CSLPATH)\example\c6486\utopia2\src
*
* @desc This is an example program for UTOPIA2 of CSL 3x.
* This performs UTOPIA2 user defined cell transfer using PDMA in
* multi-PHY and standard cell mode.
*
* ============================================================================
* @n Target Platform: TCI6486 VDB
* ============================================================================
* @n <b> Example Description </b>
* @verbatim
This Example,
1. Sets up the test bench (UTOPIA2 Master) for multi-PHY mode
2. Enables the utopia2 power/sleep controller
3. Initializes PDMA and sets up Tx and Rx PDMA channels
4. Configures the UTOPIA2 in multi-PHY mode and standard cell mode.
5. Enables the transmit and receive PDMA channel.
6. Sets up the Interrupt.
7. Enables the UTOPIA transmit and receive port.
8. Waits till cell transmit and receive.
9. Verifies the transmited and received data.
@endverbatim
*
* =============================================================================
*
* <b> Procedure to run the example </b>
* @verbatim
* 1. Configure the CCS setup to work with the emulator being used
* 2. Please refer CCS manual for setup configuration and loading
* proper GEL file
* 3. Launch CCS window
* 4. Open project Utopia_example.pjt
* 5. Build the project and load the .out file of the project.
*
* @endverbatim
*
*/
/* =============================================================================
* Revision History
* ===============
* 06-Jul-2006 NG File created
* =============================================================================
*/
#include <stdio.h>
#include <csl_utopia2.h>
#include <csl_pdma.h>
#include <example_init.h>
#include <cslr_pim.h>
#define GEM_ID 0
#define FAIL 0
#define PASS 1
Uint32 profile_results[NUM_CELL*4];
Uint32 profileStartLowXmt[NUM_CELL], profileStartHighXmt[NUM_CELL];
Uint32 profileStopLowXmt[NUM_CELL], profileStopHighXmt[NUM_CELL];
Uint32 result_buffer[12];
Uint32 result;
void utopia_setup(Uint32 SlaveId,Uint32 Udc,Uint32 PhyMode,
Uint32 UtopiaBitMode);
void setup_rru(Uint32 gem_num,Uint32 pad_num);
extern volatile Uint32 Test_Done;
void PdmaHwSetup(Uint32 num_words);
void PdmaChSetup(Uint32 XmtAddr,Uint32 RcvAddr,
Uint32 num_bytes,Uint32 num_cell,Uint32 sint);
CSL_PdmaObj PdmaObj;
CSL_PdmaHandle hPdma;
CSL_PdmaHwSetup PdmaSetup_Tx;
CSL_PdmaHwSetup PdmaSetup_Rx;
CSL_PdmaGblSetup PdmaGblSetup;
CSL_PdmaPeriCtrlSetup PdmaPeriCtlSetup_Tx;
CSL_PdmaPeriCtrlSetup PdmaPeriCtlSetup_Rx;
CSL_PdmaChHwSetup ChannelSetup_Tx;
CSL_PdmaChHwSetup ChannelSetup_Rx;
CSL_ChannelContext ChanContext_Tx;
CSL_ChannelContext ChanContext_Rx;
CSL_ChanTferCtl ChTferCtl_Tx;
CSL_ChanTferCtl ChTferCtl_Rx;
CSL_BufSize cntBuf_Tx;
CSL_BufSize cntBuf_Rx;
CSL_Utopia2HwSetup SphyU_Setup;
CSL_Utopia2UcrSetup ucrSetup;
CSL_Utopia2ClkSetup clocksp;
CSL_Utopia2ErrorSetup errorSetup;
CSL_Utopia2RruSetup rruSetup;
CSL_Utopia2Rrsr UtopiaRrsr;
CSL_Utopia2Obj myUtopiaObj;
CSL_Utopia2Handle hUtopia;
CSL_Utopia2RegsOvly utopiaRegs;
Uint32 TX_CHANNEL_NUM;
Uint32 RX_CHANNEL_NUM;
/*
* =============================================================================
* @func utopia_txRx
*
* @desc
* @n This function is to transmit and receive the utopia cells.
*
* @arg
* None
*
* @return
* result
* 0 - Successful
* 1 - Fail
* =============================================================================
*/
Uint32 utopia_txRx (
void
)
{
Uint32 Cell_Num;
CSL_Status pStatus = (CSL_Status)NULL;
Uint32 result=0;
Uint32 Bit_Mode,Phy_Mode;
CSL_BitMask16 UtopiaErrClear = 0xFFFF;
Uint32 cell_num_bytes=0,cell_num_words =0;
Uint32 cell_num_bytes_pad=0;
Uint32 Udc_Size = 0,Slave_Id = 0;
Uint32 j;
Uint32 *Xmt_Addr;
Uint32 *Rcv_Addr;
Uint32 Sint;
if (GEM_ID == 0) {
/* Initialization */
UTOPIA_Domain_Enable();
UTOPIA_Setup_Interrupt();
Sint = GEM_ID;
TX_CHANNEL_NUM = GEM_ID;
RX_CHANNEL_NUM = GEM_ID + 8;
/* Load cellsize,number of cells */
Cell_Num = Test_List[0].Num_Cell;
Bit_Mode = Test_List[0].Utopia_bit_mode;
Udc_Size = Test_List[0].Udc;
Slave_Id = Test_List[0].SlaveId;
Phy_Mode = Test_List[0].Utopia_Mode;
if (Bit_Mode) {
cell_num_bytes = Udc_Size + 54 ;
}
else {
cell_num_bytes = Udc_Size + 53 ;
}
Xmt_Addr = Xmt_srcAddr + GEM_ID * 0x1000000/4 + 0x10000000/4;
Rcv_Addr = Rcv_dstAddr + GEM_ID * 0x1000000/4 + 0x10000000/4;
cell_num_bytes_pad = (cell_num_bytes % 4)?(cell_num_bytes +
(4 - (cell_num_bytes %4))):cell_num_bytes;
cell_num_words = cell_num_bytes_pad/4 ;
/* MaskMatch Value setup for GEM_ID */
for (j = 0;j < Cell_Num;j++) {
Xmt_Addr[cell_num_words*j+1+GEM_ID] = 0x11+0x11*GEM_ID;
}
/* Initialize Pdma Module */
CSL_pdmaInit(NULL);
hPdma = CSL_pdmaOpen(&PdmaObj, CSL_PDMA, NULL, &pStatus);
/* Pdma setup for Tx */
PdmaHwSetup(cell_num_words);
PdmaChSetup((Uint32)Xmt_Addr, (Uint32)Rcv_Addr, cell_num_bytes_pad,
Cell_Num,Sint);
CSL_pdmaHwSetup(hPdma, &PdmaSetup_Tx, TX_EVENT);
CSL_pdmaChHwSetup(hPdma, &ChannelSetup_Tx, TX_CHANNEL_NUM);
/* Pdma setup for Rx */
CSL_pdmaHwSetup(hPdma, &PdmaSetup_Rx, RX_EVENT);
CSL_pdmaChHwSetup(hPdma, &ChannelSetup_Rx, RX_CHANNEL_NUM);
/* Configure UCR - Utopia Module Setup and Hnadle Open */
utopia_setup(Slave_Id,Udc_Size,Phy_Mode,Bit_Mode);
hUtopia = CSL_utopia2Open(&myUtopiaObj, CSL_UTOPIA2, NULL, &pStatus);
setup_rru(GEM_ID,(cell_num_bytes_pad - cell_num_bytes));
CSL_utopia2HwSetup(hUtopia, &SphyU_Setup);
utopiaRegs = hUtopia->regs;
CSL_pdmaHwControl(hPdma,CSL_PDMA_CMD_GLOBAL_ENABLE,(Uint32)NULL);
/* Enable Utopia Tx and Rx */
CSL_utopia2HwControl(hUtopia, CSL_UTOPIA2_CMD_XMT_ENABLE, NULL);
CSL_utopia2HwControl(hUtopia, CSL_UTOPIA2_CMD_REC_ENABLE, NULL);
/* Clearing the Error Pending Register for Clock Detect Failure */
CSL_utopia2HwControl(hUtopia, CSL_UTOPIA2_CMD_ERROR_CLEAR,
&UtopiaErrClear);
/* Wait for PDMA tranfer completion */
do {
;
} while(Test_Done != 2);
/* Close All Handles */
CSL_utopia2Close(hUtopia);
CSL_pdmaClose(hPdma);
Close_Interrupt_Handle();
/* Src Buffer and Destination buffer data compare */
result = Verify_Result((Uint32)Xmt_Addr, (Uint32)Rcv_Addr,
Cell_Num, cell_num_bytes_pad,
cell_num_bytes, Udc_Size,Bit_Mode);
}
return (result);
}
/*
* =============================================================================
* @func PdmaHwSetup
*
* @desc
* @n This function is to setup the pdma hardware parameters
*
* @arg
* None
*
* @return
* None
* =============================================================================
*/
void PdmaHwSetup (
Uint32 num_words
)
{
PdmaSetup_Tx.gbl = &PdmaGblSetup;
PdmaSetup_Rx.gbl = &PdmaGblSetup;
PdmaSetup_Tx.pctl =&PdmaPeriCtlSetup_Tx;
PdmaSetup_Rx.pctl =&PdmaPeriCtlSetup_Rx;
PdmaGblSetup.strt = 0x0;
PdmaGblSetup.soft = 0x0;
PdmaGblSetup.free = 0x0;
PdmaPeriCtlSetup_Tx.bend = 0x0;
PdmaPeriCtlSetup_Tx.clrs = 0x0;
PdmaPeriCtlSetup_Tx.sfrm = 0x0;
PdmaPeriCtlSetup_Tx.pe = 0x1;
PdmaPeriCtlSetup_Tx.sync = 0x1;
PdmaPeriCtlSetup_Tx.pri = 0x3;
PdmaPeriCtlSetup_Tx.abu = 0x0;
PdmaPeriCtlSetup_Tx.dir = 0x0;
PdmaPeriCtlSetup_Tx.pblen = (num_words-1);
PdmaPeriCtlSetup_Tx.pmod = 0x1;
PdmaPeriCtlSetup_Tx.sblen = (num_words-1);
PdmaPeriCtlSetup_Tx.smod = 0x0;
PdmaPeriCtlSetup_Rx.bend = 0x0;
PdmaPeriCtlSetup_Rx.clrs = 0x0;
PdmaPeriCtlSetup_Rx.sfrm = 0x0;
PdmaPeriCtlSetup_Rx.pe = 0x2;
PdmaPeriCtlSetup_Rx.sync = 0x1;
PdmaPeriCtlSetup_Rx.pri = 0x3;
PdmaPeriCtlSetup_Rx.abu = 0x1;
PdmaPeriCtlSetup_Rx.dir = 0x1;
PdmaPeriCtlSetup_Rx.pblen = (num_words-1);
PdmaPeriCtlSetup_Rx.pmod = 0x1;
PdmaPeriCtlSetup_Rx.sblen = (num_words-1);
PdmaPeriCtlSetup_Rx.smod = 0x0;
}
/*
* =============================================================================
* @func PdmaChSetup
*
* @desc
* @n This function is to setup the pdma channel parameters
*
* @arg
* XmtAddr - Transmit address
* RcvAddr - Receive address
* num_bytes - number of bytes
* num_cell - number of cells
* sint - source interrupt
*
* @return
* None
* =============================================================================
*/
void PdmaChSetup (
Uint32 XmtAddr,
Uint32 RcvAddr,
Uint32 num_bytes,
Uint32 num_cell,
Uint32 sint
)
{
Uint32 Buff_Size_Circular;
ChannelSetup_Tx.chContext = &ChanContext_Tx;
ChannelSetup_Rx.chContext = &ChanContext_Rx;
Buff_Size_Circular = num_bytes;
ChTferCtl_Tx.strt = 0x1;
ChTferCtl_Tx.imod = 0x0;
ChTferCtl_Tx.ie = 0x1;
ChTferCtl_Tx.sint = sint;
ChTferCtl_Tx.psiz = 0x2;
ChTferCtl_Tx.ssiz = 0x2;
ChTferCtl_Tx.ff = 0x0;
ChTferCtl_Tx.bcz = 0x0;
ChTferCtl_Tx.wrptr = 0x0;
ChTferCtl_Tx.rdptr = 0x0;
cntBuf_Tx.sbuf = (num_cell*num_bytes);
cntBuf_Tx.pbuf = 0;
ChanContext_Tx.SAR = XmtAddr;
ChanContext_Tx.PAR = TxQue_Addr;
ChanContext_Tx.cnt_buff = &cntBuf_Tx;
ChanContext_Tx.chTctl = &ChTferCtl_Tx;
ChTferCtl_Rx.strt = 0x1;
ChTferCtl_Rx.imod = 0x0;
ChTferCtl_Rx.ie = 0x1;
ChTferCtl_Rx.sint = sint;
ChTferCtl_Rx.psiz = 0x2;
ChTferCtl_Rx.ssiz = 0x2;
ChTferCtl_Rx.ff = 0x0;
ChTferCtl_Rx.bcz = 0x0;
ChTferCtl_Rx.wrptr = 0x0;
ChTferCtl_Rx.rdptr = 0x0;
cntBuf_Rx.sbuf = (num_cell*num_bytes);
cntBuf_Rx.pbuf = Buff_Size_Circular;
ChanContext_Rx.SAR = RcvAddr;
ChanContext_Rx.PAR = RxQue_Addr;
ChanContext_Rx.cnt_buff = &cntBuf_Tx;
ChanContext_Rx.chTctl = &ChTferCtl_Rx;
}
/*
* =============================================================================
* @func utopia_setup
*
* @desc
* @n This function is to setup utopia
*
* @arg
* None
* SlaveId - Utopia Slave id
* Udc - Utopia user defined cell
* PhyMode - Utopia physical mode
* UtopiaBitMode - Utopia bit mode
*
* @return
* None
* =============================================================================
*/
void utopia_setup (
Uint32 SlaveId,
Uint32 Udc,
Uint32 PhyMode,
Uint32 UtopiaBitMode
)
{
/* Utopia Setup for Multiphy */
SphyU_Setup.ucrSetup = &ucrSetup;
/* Big Endian */
ucrSetup.Endianness = 0;
/* User Defined Cell 53B */
ucrSetup.txUdc = Udc;
/* User Defined Cell 53B */
ucrSetup.rxUdc = Udc;
/* Utopia Tx Enable */
ucrSetup.txUtopia2Enable = 0;
/* Utopia Rx Enable */
ucrSetup.rxUtopia2Enable = 0;
/* Utopia Single PHY */
ucrSetup.phyModeEnable = PhyMode;
/* Utopia 16/8 bit Mode */
ucrSetup.utopia2BitMode = UtopiaBitMode;
/* Slave ID */
ucrSetup.slendSlid = SlaveId;
SphyU_Setup.clkSetup = &clocksp;
/* Set utopia Rx clock count */
clocksp.rxClkCount = 0x0;
/*Set utopia Tx clock count */
clocksp.txClkCount = 0x0;
SphyU_Setup.errorSetup = &errorSetup;
errorSetup.txClkFailIntEnb = 0;
errorSetup.rxClkFailIntEnb = 0;
errorSetup.txClkPresentIntEnb = 0;
errorSetup.rxClkPresentIntEnb = 0;
errorSetup.txQueueStallIntEnb = 0;
errorSetup.rxQueueStallIntEnb = 0;
errorSetup.txClkFail = 0;
errorSetup.rxClkFail = 0;
errorSetup.txClkPresent = 0;
errorSetup.rxClkPresent = 0;
}
/*
* =============================================================================
* @func setup_rru
*
* @desc
* @n This function is to setup PSC
*
* @arg
* gem_num - gem id
* pad_num - number of padding
*
* @return
* None
* =============================================================================
*/
void setup_rru (
Uint32 gem_num,
Uint32 pad_num
)
{
rruSetup.rmmrMask0 = 0x0011;
rruSetup.rmmrMatch0 = 0x00ff;
rruSetup.rmmrMask1 = 0x0022;
rruSetup.rmmrMatch1 = 0x00ff;
rruSetup.rmmrMask2 = 0x0033;
rruSetup.rmmrMatch2 = 0x00ff;
rruSetup.rmmrMask3 = 0x0044;
rruSetup.rmmrMatch3 = 0x00ff;
rruSetup.rmmrMask4 = 0x0055;
rruSetup.rmmrMatch4 = 0x00ff;
rruSetup.rmmrMask5 = 0x0066;
rruSetup.rmmrMatch5 = 0x00ff;
UtopiaRrsr.rbyt = ((5+(4*gem_num)- pad_num)<<16);
UtopiaRrsr.rbit = 0;
rruSetup.rrsr = &UtopiaRrsr;
SphyU_Setup.rruSetup = &rruSetup;
}
/*
* =============================================================================
* @func main
*
* @desc
* This is the main routine, which invokes TSIP external loopback example.
* =============================================================================
*/
void main (
void
)
{
Uint32 result = FAIL;
/* Function call to perform the tx and rx */
result = utopia_txRx();
if (!result) {
printf("Utopia Tx Rx Example Pass \n");
}
else {
printf("Utopia Tx Rx Example Fail \n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -