⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xiotest.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
字号:
/*
 * Copyright (c) 1995,1996,1997 by TriMedia Technologies. 
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : xiotest.c   1.2
 *
 *  Last update              : 15:31:09 - 97/10/28
 *
 *  Description              :
 *      Do three back to back transactions in the order write, read.
 *      Cover the entire 16MB xio address space by triggering all the
 *      24 address bits one bit at a time.
 * 
 *      Assumes LE mode for CPU for data comparision.
 *
 *	Returns status= 0 (TM_LIBDEV_OK)  on success.
 *
 *	Any positive number indicates some number of Mismatch error.
 *
 *	Also returns status= 0x0505001 (XIO_ERR_INVALID_PROCESSOR) 
 *	  if not running on a TriMedia with a XIO unit (TM1100).
 *
 *  Notes                    :
 *
 * 	xioWrite() and xioRead() are two macros defined	in tmXIO.h.  
 *	They will work only if your board has an XIO device, and 
 *      several modifications that are necessary in order to execute 
 *      XIO tests correctly (including programming of the XIO address 
 *      decoder FPGA).  You may turn this on by switching the sense 
 *      of the '#if 0' to '#if 1' in the routine wr_rd().
 *
 * 	For a board with a TM1100-XIO and without any XIO devices 
 *      attached, we will just read/write the xioCTL_ADDRESS register 
 *      to verify that the MMIO registers are functioning.  
 *      This is the default.
 *
 *  Revision                 : 2
 */

/* -------------------------------------------------------------- */


#include <stdio.h>
#include <tmlib/dprintf.h>
#include <tm1/mmio.h>
#include <tm1/tmProcessor.h>

#include <tm1/tmXIO.h>
#include <tm1/tmXIOmmio.h>

#include <tm1/tmHelp.h>


#define PROGRAM_VERSION     "1.2"


#define XIO_FILTER_ACTIVE_BITS          0xfc0007bf


void        wr_rd(int);

static Int  instance;

unsigned long mismatches;	/* number of errors in XIO transfer */
int         wr_byte;

/*--------------------------------------------------*/
ReportError(status)
    int         status;
{
    printf("ERROR: code %x\n", status);
    DP(("ERROR: code %x\n", status));
 
    exit(status);
}

/*--------------------------------------------------*/
/* Macro to do compact error checking on device library calls:
 */
#define E(x)                                    \
{                                               \
    tmLibdevErr_t status;                       \
                                                \
    status = x;                                 \
    if (status != TMLIBDEV_OK)                  \
    {                                           \
       ReportError(status);                     \
    }                                           \
}
 

/*--------------------------------------------------*/
main()
{
    xioInstanceSetup_t xioCtrl;
    pxioCapabilities_t pcap;
    pprocCapabilities_t proc_info;
    unsigned long mmio_data;
    int         i;

    /* =========================================================== 
     * Start of initialization
     */
    DPsize(4 * 1024 * 1024);

    E(xioGetCapabilities(&pcap));
 
    DP(("\nTrimedia XIO Test Program, V%s\n\n", PROGRAM_VERSION));
    DP(("Running on ")); tmHelpReportSystem(Null);
    DP(("This program uses XIO library version %d.%d.%d\n",
        pcap->version.majorVersion,
        pcap->version.minorVersion,
        pcap->version.buildVersion));
    DP(("to demostrate XIO transfers.\n"));

    E(procGetCapabilities(&proc_info));
 
    if (proc_info->deviceID < PROC_DEVICE_TM1100) {

	/* will abort with 'XIO_ERR_INVALID_PROCESSOR' after xioOpen */ 
        DP((" ----- No XIO unit on this processor ----- \n"));
        printf(" ----- No XIO unit on this processor ----- \n");
    }

    /*
     * Get XIO ready by: Open, Setup.
     */
    E(xioOpen(&instance));
 
    DP(("Open done \n"));

    mismatches = 0;
    wr_byte = 1;

    xioCtrl.ctlAddress = 0x16;
    xioCtrl.waitStates = 0;
    xioCtrl.busEnable = True;
    xioCtrl.internalClockEnable = False;
    xioCtrl.clockFreqDivider = 0; 

    E(xioInstanceSetup( instance, &xioCtrl ) );

    /* Read the XIO_CTL MMIO register, verify we've set 
     * correctly set it to (xio_base | XIO_CTL_XIO_BUS)  
     */
    mmio_data = MMIO(XIO_CTL);

    if ((mmio_data & XIO_FILTER_ACTIVE_BITS) != 
	( (xioCtrl.ctlAddress << XIO_CTL_ADDRESS_SHIFT) 
	  | XIO_CTL_XIO_BUS) ) {
	mismatches++;
	printf(" ERROR: failed to write and read XIO_CTL correctly\n");
	return (mismatches);
    }

    /* Perform write followed by read to 
     * the different shifted addresses 
     *
     * Slaves are only 17bit wide for( i=0; i<23; i++ )
     */
    for (i = 0; i < 17; i++) {
	wr_rd(i);
	wr_byte++;
    }

    E(xioClose(instance));

    if (mismatches == 0)
	printf(" ----- XIO Success! ----- \n");

    return (mismatches);
}
/*--------------------------------------------------*/

void 
  wr_rd( int addr_shift )
{
    unsigned long xio_addr, data;

    xio_addr = (0x1 << addr_shift);

    /* Write the data and read it back to test 
     *   that it is valid.  
     */

#if 0

    /* xioWrite() and xioRead() are two macros defined 
     *  in tmXIO.h.  They will work only if your board
     *  has an XIO device, and several modifications that
     *  are necessary in order to execute XIO tests 
     *  correctly (including programming of the XIO 
     *  address decoder FPGA). 
     */

    xioWrite( xio_addr, wr_byte ); 
    data = xioRead( xio_addr ); 
#else

    /* For a board without any XIO devices attached,
     * we will just read/write the xioCTL_ADDRESS
     * register to verify that the MMIO registers 
     * are functioning.
     */   

    xioSetCTL_ADDRESS(wr_byte);
    data = xioGetCTL_ADDRESS;
#endif

    if (data != wr_byte ) {
        printf(" ERROR: %02x != %02x at %08x \n", 
			data, wr_byte, xio_addr );
        mismatches++;
    } else {
 
        printf("   %02x == %02x at %08x \n", 
			data, wr_byte, xio_addr );
    }
}
/*--------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -