📄 srio_ext_loopback_example.c
字号:
/* ============================================================================
* Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
*
* Use of this software is controlled by the terms and conditions found in the
* license agreement under which this software has been supplied.
* ============================================================================
*/
/** ===========================================================================
* @file Srio_ext_loopback_example.c
*
* @path $(CSLPATH)\example\srio\src
*
* @desc This is a simple external lookback example of usage of CSL APIs
* of the SRIO module.
*
* ============================================================================
* @n Target Platform: EVM and Adapter board
* ============================================================================
*
* ============================================================================
* @n <b> Example Description </b>
* @n This is an example of the CSL SRIO usage for a LSU port.
* @verbatim
1. Setup SRIO module for external loop back transfer on LSU1.
2. Setup the destination and source data areas.
3. Configure LSU1 registers.
4. Start transfer.
5. Wait for completion of the transfer.
6. Verify the destination contains the expected data.
@endverbatim
*
*=============================================================================
*
* @n <b> Procedure </b>
* @verbatim
1. Configure the CCS setup
2. Please refer CCS manual for setup configuration and loading
proper GEL file
3. Launch CCS window
4. Open project Srio_ext_loopback_example.pjt
5. Build the project and load the .out file of the project.
@endverbatim
*
*
* ============================================================================
*/
/* ============================================================================
* Revision History
* ===============
* 31-Aug-2006 NG File created
* ============================================================================
*/
#include <csl_srio.h>
#include <cslr_dev.h>
#include <soc.h>
#include <stdio.h>
/* Macros */
#define SRIO_SET_DEVICE_ID(base_dev_id, large_base_dev_id) \
CSL_FMK(SRIO_BASE_ID_BASE_DEVICEID, base_dev_id) | \
CSL_FMK(SRIO_BASE_ID_LARGE_BASE_DEVICEID, large_base_dev_id)
#define LARGE_DEV_ID 0xBEEF
#define SMALL_DEV_ID 0xAB
#define SRIO_PKT_TYPE_NWRITE 0x54
#define SELECTED_LSU 0
#define TRANSFER_SIZE 256
/* globals */
static Uint8 src[TRANSFER_SIZE];
static Uint8 dst[TRANSFER_SIZE];
static CSL_SrioHwSetup setup = CSL_SRIO_HWSETUP_DEFAULTS;
/* Function prototypes */
void srio_Create_Setup (
CSL_SrioHwSetup *pSetup,
int bootcomplete
);
/*
* ============================================================================
* @func main
*
* @desc
* This is the main routine of this program which invokes the different
* components to complete a simple LSU transfer.
* ============================================================================
*/
void main (
void
)
{
volatile Uint32 index, dummy_cnt;
Uint8 lsu_no;
CSL_SrioContext context;
CSL_Status status;
CSL_SrioHandle hSrio;
CSL_SrioObj srioObj;
CSL_InstNum srioNum = 0; /* Instance number of the SRIO */
CSL_SrioParam srioParam;
CSL_SrioDirectIO_ConfigXfr lsu_conf = {0};
CSL_SrioPortData response;
/* Unlock the powersaver control register */
CSL_FINST (((CSL_DevRegs*)CSL_DEV_REGS)->PERLOCK, DEV_PERLOCK_LOCKVAL,
UNLOCK);
/* Enable the SRIO */
CSL_FINST (((CSL_DevRegs*)CSL_DEV_REGS)->PERCFG0, DEV_PERCFG0_SRIOCTL,
ENABLE);
/* Initialization and Open of the SRIO */
status = CSL_srioInit (&context);
hSrio = CSL_srioOpen (&srioObj, srioNum, &srioParam, &status);
if (status != CSL_SOK) {
printf("SRIO: ... Cannot open SRIO, failed\n");
return;
}
/* Create the setup structure */
srio_Create_Setup (&setup, 1);
response.index = 0;
do {
/* Setup the SRIO with the selected setup in the last step */
status = CSL_srioHwSetup (hSrio, &setup);
if (status != CSL_SOK) {
printf("SRIO: ... Hardwrae setup, failed\n");
return;
}
//Delay for PLL? need to re-clear errors?
for(index=0; index<0x10000; index++) {
dummy_cnt = index + 1;
dummy_cnt++;
}
CSL_srioGetHwStatus (hSrio, CSL_SRIO_QUERY_SP_ERR_STAT, &response);
}while(response.data & 0x1);
/* Setup the source and destination */
for(index=0; index<TRANSFER_SIZE; index++) {
src[index] = index + 1;
dst[index] = 0;
}
/* Create an LSU configuration */
lsu_conf.srcNodeAddr = (Uint32)&src[0]; /* Source address */
lsu_conf.dstNodeAddr.addressHi = 0;
lsu_conf.dstNodeAddr.addressLo = (Uint32)&dst[0]; /* Destination address */
lsu_conf.byteCnt = TRANSFER_SIZE;
lsu_conf.idSize = 1; /* 16 bit device id */
lsu_conf.priority = 2; /* PKT priority is 2 */
lsu_conf.xambs = 0; /* Not an extended
address */
lsu_conf.dstId = LARGE_DEV_ID;
lsu_conf.intrReq = 0; /* No interrupts */
lsu_conf.pktType = SRIO_PKT_TYPE_NWRITE;
/* write with no
response */
lsu_conf.hopCount = 0; /* Valid for
maintainance pkt */
lsu_conf.doorbellInfo = 0; /* Not a doorbell pkt */
lsu_conf.outPortId = 0; /* Tx on Port 0 */
for(index=0; index<0x10000; index++) {
/* Configure the LSU1 and start transmission */
lsu_no = SELECTED_LSU;
CSL_srioLsuSetup (hSrio, &lsu_conf, lsu_no);
/* Wait for the completion of transfer */
response.index = lsu_no;
do {
CSL_srioGetHwStatus (hSrio, CSL_SRIO_QUERY_LSU_BSY_STAT, &response);
}while(response.data == 1);
}
/* A delay, above checks seems to be not working
may be because, it is a write operation with
no response */
for(index=0; index<0x10000; index++) {
dummy_cnt = index + 1;
dummy_cnt++;
}
/* Verify whether data is transfered */
for(index=0; index<TRANSFER_SIZE; index++) {
if (src[index] != dst[index]) {
break;
}
}
if (index == TRANSFER_SIZE) {
printf("SRIO: ... LSU transfered %d bytes of data correctly\n",
TRANSFER_SIZE);
} else {
printf("SRIO: ... LSU failed to transfer data\n");
}
}
/*
* ============================================================================
* @func srio_Create_Setup
*
* @desc
* This routine setsup a structure with the required setup of the SRIO.
* ============================================================================
*/
void srio_Create_Setup (
CSL_SrioHwSetup *pSetup,
int bootcomplete
)
{
Uint32 index;
/* Peripheral enable */
pSetup->perEn = 1;
/* While in shutdown, put memories in sleep mode */
pSetup->periCntlSetup.swMemSleepOverride = 1;
/* Disable loopback operation
* NOTE: External lookback operation is enabled
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -