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

📄 vlx_test_io_static.c

📁 这是韩国EQUATOR公司提供的DEMO程序
💻 C
字号:
/**
*** Copyright (c) 2001 Equator Technologies, Inc.
**/

//*********************************************************************
//
// File: vlx_test_io_static.c :
//
//    Example program showing how to interact with the I/O side of the VLX.
//    This file contains main() and several support functions.
//
//*********************************************************************

#include <eti/ds.h>
#include <mm.h>
#include <eti/vlx.h>
#include <eti/mapca/vlxm_piomap.h>

#include "common.h"
#include "vlxasm.h" // Contains the VLX binary labels 

  #include <eti/mapca/vlxm_piomap.h> // WORKAROUND
  #include <eti/mapca/vlxc_piomap.h> // WORKAROUND

//----------------------------------
//
// Function Prototypes
//
//----------------------------------

// Function : InitBuffer()
//   ~ Initializes an array of unigned longs
void InitBuffer(unsigned long* pBuff);

// Function : InitDsReqPath()
//   ~ Initializes a data streamer path
void InitDsReqPath(
        DS_PATH_INFO*   dsPathRequest,
        BOOL            isSrcIO,
        BOOL            isDstIO,
        SINT32          bufferSize,
        SINT32          srcSize,
        SINT32          dstSize
);

//----------------------------------
//
// Global Variables
//
//----------------------------------
extern VLX_BIN vlxasm;           // vlx binary struct
PVLX_BIN       vlxBin = &vlxasm; // pointer to vlx binary struct

//----------------------------------
//
// main()
//
//----------------------------------
main() 
{

static UINT32 pVLxPIOReg = 0x0; // WORKAROUND


  //
  // Declarations
  //
 
  int i;
  int j;
  int succeeded=S_PASS;

  DS_DESCRIPTOR srcDs_W2D; // Src Descriptor from D$ to DS  buffer
  DS_DESCRIPTOR dstDs_D2W; // Dst Descriptor from DS buffer to D$ 
 
  DS_PATH_INFO reqMemIOPath;
  DS_PATH_INFO MemIOPath;

  DS_PATH_INFO reqIOMemPath;
  DS_PATH_INFO IOMemPath;

  SCODE status;
  unsigned short getBitsData;
  unsigned long  getBitsOffset;
  unsigned short gbCtrl;
  unsigned long  bufInIndex;
  unsigned long  bufOutIndex;

  volatile unsigned short*  pVlMemI;
  volatile unsigned short*  pVlMemSema;
  volatile unsigned short*  pVlMemStatus;

 #ifdef CONFIG_VERBOSE
  volatile unsigned short*  pVlMemD0;
  volatile unsigned short*  pVlMemD1;
  volatile unsigned short*  pVlMemGbData;
 #endif

  unsigned long inBuff[64*2];
  unsigned long outBuff[64*2];

  //
  // Code
  //

  printf("\nIn main()...\n");

  pVlMemI      = (volatile unsigned short *) VlxLookupCM1();
  pVlMemStatus = (volatile unsigned short *) (pVlMemI + VLXLAB_D0_STATUS); 
  pVlMemSema   = (volatile unsigned short *) (pVlMemI + VLXLAB_D1_SEMA); 

#ifdef CONFIG_VERBOSE
  pVlMemGbData = (volatile unsigned short *) (pVlMemI + VLXLAB_D0_GBDATA); 
  pVlMemD0     = (volatile unsigned short *) (VlxLookupCM1() + _VLMEM_DATA0_OFFSET_SHORT);
  pVlMemD1     = (volatile unsigned short *) (VlxLookupCM1() + _VLMEM_DATA1_OFFSET_SHORT);
  printf("\tpVlMemI          = 0x%lx\n", pVlMemI );
  printf("\tpVlMemD0         = 0x%lx\n", pVlMemD0 );
  printf("\tpVlMemD1         = 0x%lx\n", pVlMemD1 );
  printf("\tVLXLAB_D1_SEMA   = 0x%lx\n", VLXLAB_D1_SEMA );
  printf("\tpVlMemSema       = pVlMem + VLXLAB_D1_SEMA = 0x%lx\n", pVlMemSema );
  printf("\tVLXLAB_D0_STATUS = 0x%lx\n", VLXLAB_D0_STATUS );
  printf("\tpVlMemStatus     = pVlMem + VLXLAB_D0_STATUS = 0x%lx\n", pVlMemStatus );
#endif
 
  InitBuffer(inBuff); // Initialize source data

  //
  // Clear dst buffer to 0
  //
  for ( i=0; i < 64; i++ ) {
     outBuff[i] = 0;
  }

  //
  // Initialize DS Paths
  //
  InitDsReqPath(
        &reqMemIOPath, // Path Struct address
        FALSE,         // isSrcIO
        TRUE,          // isDstIO
        64,            // bufferSize
        64,            // srcSize
        0              // dstSize
  );
  
  InitDsReqPath(
        &reqIOMemPath, // Path Struct address
        TRUE,          // isSrcIO
        FALSE,         // isDstIO
        64,            // bufferSize
        0,             // srcSize
        64             // dstSize
  );

  //
  // Setup descriptor for VLx input stream
  //
  DsDescSetGenericFmt1(
	&srcDs_W2D, 				// DS_DESCRIPTOR *the_descriptor
	&srcDs_W2D, 				// DS_DESCRIPTOR *the_next_descriptor
        DS_DESC_HALT | DS_DESC_DATA_ACCESS_CA | DS_DESC_INHIBIT_FLUSH, // options
	(unsigned char *)inBuff,    		// void *addr
	128, 					// short width  
	1,                       		// short count  
	0 					// short stride
  );

  //
  // Setup descriptor for VLx output stream
  //
  DsDescSetGenericFmt1(
	&dstDs_D2W,                 // the_descriptor
	&dstDs_D2W,                 // the_next_descriptor
	DS_DESC_DATA_ACCESS_CA,     // options
	(unsigned char *)outBuff,   // addr
	128, 			    // width  
	1,                          // count  
	0 			    // stride
  );

  //
  // Open DS Paths
  //

  // Open IOMemPath (2)
  status = DsOpenPath(&reqIOMemPath, &IOMemPath);
  printf("\nOpened Path IOMemPath with status %d \n", status );

 #ifdef CONFIG_VERBOSE
  printf("Opened IOMemPath path on ds src channel: IO\n"); 
  printf("Opened IOMemPath path on ds dst channel: %d\n", 
	DsGetChannelIndexFromDS_CHANNEL(IOMemPath.dstCh.id));
  printf("DsGetBufferIndexFromDS_BUFFER(IOMemPath.buf.id) = %d\n", 
        DsGetBufferIndexFromDS_BUFFER(IOMemPath.buf.id) );
 #endif

  // Open MemIOPath (1)
  status = DsOpenPath(&reqMemIOPath, &MemIOPath);
  printf("\nOpened Path MemIOPath with status %d \n", status );

 #ifdef CONFIG_VERBOSE
  printf("Opened memory to io path on ds src channel: %d\n", 
	DsGetChannelIndexFromDS_CHANNEL(MemIOPath.srcCh.id));
  printf("Opened memory to io path on ds dst channel: IO\n"); 
  printf("DsGetBufferIndexFromDS_BUFFER(MemIOPath.buf.id) = %d\n", 
        DsGetBufferIndexFromDS_BUFFER(MemIOPath.buf.id) );
 #endif

  //
  // Setup GB
  //

  // 15   -- if set, jpeg consume mode (eats 0x00s)
  // 14   -- if set, jpeg dct mode
  // 13   -- if set, disable per-byte bit reversal to GB input
  // 12   -- if set, disable per-byte bit reversal from GB output
  // 11:6 -- DS buffer ID used by gb input buffer
  // 5:0  -- DS buffer ID used by gb output buffer
  gbCtrl      = 0;  // no consume, no jpeg dct, per-byte bit reversal enabled on I and O
  bufInIndex  = DsGetBufferIndexFromDS_BUFFER(MemIOPath.buf.id);
  bufOutIndex = DsGetBufferIndexFromDS_BUFFER(IOMemPath.buf.id);
  getBitsData =  (((gbCtrl & 0xf) << 12) | ((bufInIndex & 0x3f) << 6) | (bufOutIndex & 0x3f));

  //
  //  Write the values into the Vlx binary (pre-load).  
  //
  getBitsOffset = VLXLAB_D0_GBDATA;
  printf("\nGetBits configuration data at %d offset (short) in CM1\n", getBitsOffset);

  vlxBin->Binary[ getBitsOffset >> 2 ] = getBitsData; // convert long long to short
  printf("\nWrote GetBits configuration data = %x \n", getBitsData);

 #ifdef CONFIG_VERBOSE
  printf("\tbufInIndex  = %d [ DsGetBufferIndexFromDS_BUFFER(MemIOPath.buf.id) ]\n", bufInIndex );
  printf("\tbufOutIndex = %d [ DsGetBufferIndexFromDS_BUFFER(IOMemPath.buf.id) ] \n", bufOutIndex );
 #endif

  //
  // Load Vlx Binary from DRAM to VlMem
  //
  status = VlxLoadBinaryByValue(
               vlxBin,                                // Pointer to the binary struct
               ((vlxBin->BinaryByteLength + 1) >> 1), // Length to transfer is in 16-bit quantities
               VLXLAB_PCSTART,                        // transfer from the beginning of the vlx program code...
               0,                                     // ...which is the beginning of CM1 (offset 0)
               VLX_LOAD_PIO                           // Use PIO writes to do the transfer
  );

  //
  // Kick the input stream so that it is ready when the VLx starts
  // requesting input.
  //
  status = DsKick(MemIOPath.srcCh.id, &srcDs_W2D);
  printf("Kick the Vlx GB input, channel index = %d, status = %d\n", 
         DsGetChannelIndexFromDS_CHANNEL(MemIOPath.srcCh.id), status);

  status = DsKick(IOMemPath.dstCh.id, &dstDs_D2W);
  printf("Kick the Vlx GB output, channel index = %d, status = %d\n", 
         DsGetChannelIndexFromDS_CHANNEL(IOMemPath.dstCh.id), status);

 #ifdef CONFIG_VERBOSE
  printf("\nGB DATA Buffer :\n");
  printf("\tpVlMemGbData     = pVlMem + VLXLAB_D0_GBDATA = 0x%lx\n", pVlMemGbData );
  printf("\t*pVlMemGbData    = 0x%08x\n", *pVlMemGbData );
 #endif

  //
  //  Kick the Vlx so it starts processing
  //
  printf("Kick the Vlx\n");
  pVLxPIOReg = ( GetPIOBase() | VLXCOffset | VLXCRegModeNormalRegOffset ); // WORKAROUND
  *(volatile UINT32 *)pVLxPIOReg = 0x5; // WORKAROUND
  //VlxResetPC();  // Set the Vlx PC to 0
  VlxKick();     // Turn on the VLx clock

  printf("\nWaiting at DsWaitHalted(MemIOPath.srcCh.id, DS_TIMEOUT_INDEFINITE)...\n");
  DsWaitHalted(MemIOPath.srcCh.id, DS_TIMEOUT_INDEFINITE);
  printf("...halt detected...resume.\n");

  //
  //  Poll for Semaphore to be cleared by vlx
  //
  printf("\nWaiting for vlx to clear semaphore...\n");
  i=0;
  while(*(volatile unsigned short*)pVlMemSema != 0) {
	for(j=0;j<100;j++); // kill some time to avoid swamping bus
	if( i++ > SEMA_TIMEOUT_CYCLES ) break;
  }
  printf("pVlMemSema     = 0x%x\n", pVlMemSema );
  printf("*pVlMemSema    = 0x%x\n", *pVlMemSema );

  //
  //  Check if the semaphore timed-out
  //
  if (i>SEMA_TIMEOUT_CYCLES) {
    printf("ERROR...semaphore timed out, resume.\n");
    succeeded = S_FAIL_SEMA;
  } else {
    printf("...semaphore cleared, resume.\n");
  } 

  //
  //  Tell the VLx the show is over
  //
  printf("Halt the Vlx\n");
  VlxStop();  // turns off the VLx clock

  //
  //  Check if we get back what we sent to GB
  //
  printf("\n*** Performing check... ***\n");
  for (i= 0; i < 16; i++) {
     if (inBuff[i] != outBuff[i]) succeeded = S_FAIL_DATA;
     printf("\tinBuff[%d]  = 0x%08x\n", i, inBuff[i] );
     printf("\toutBuff[%d] = 0x%08x\n", i, outBuff[i] );
  }

  if (succeeded==S_PASS) {
     printf("\nPASSED!!\n");
  } else {
     printf("\nFAILED!! Try again...\n");
  }

  printf("\nStatus Buffer :\n");
  printf("\tpVlMemStatus     = pVlMem + VLXLAB_D0_STATUS = 0x%lx\n", pVlMemStatus );
  printf("\t*pVlMemStatus    = 0x%lx\n", *pVlMemStatus );

  printf("\nStatus : %d\n", succeeded);
  printf("end\n");

  return 0;

} // end main()

//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------

void InitBuffer(unsigned long* pBuff) {
  //
  // Setup source of input stream to VLx --
  // This is just a dummy feed into the VLx GetBits input;
  // The corresponding VLx program will just send us back the
  // same information we feed to it as input.
  //

  int i = 0;

  for (i=0;i<4;i+=16) {
      pBuff[i+0] = 0x76543210;
      pBuff[i+1] = 0xfedcba98;
      pBuff[i+2] = 0x89abcdef;
      pBuff[i+3] = 0x01234567;
      pBuff[i+4] = 0x76543210;
      pBuff[i+5] = 0xfedcba98;
      pBuff[i+6] = 0x89abcdef;
      pBuff[i+7] = 0x01234567;
      pBuff[i+8] = 0xaaaaaaaa;
      pBuff[i+9] = 0xbbbbbbbb;
      pBuff[i+10] = 0xcccccccc;
      pBuff[i+11] = 0xdddddddd;
      pBuff[i+12] = 0xeeeeeeee;
      pBuff[i+13] = 0xffffffff;
      pBuff[i+14] = 0x00000000;
      pBuff[i+15] = 0x11111111;
  } // for

} // InitBuff()

//---------------------------------------------------------------------------------------------

void
InitDsReqPath(
        DS_PATH_INFO    *dsPathRequest,
        BOOL            isSrcIO,
        BOOL            isDstIO,
        SINT32          bufferSize,
        SINT32          srcSize,
        SINT32          dstSize
)
{
    dsPathRequest->srcCh.transferBurstSize      = DS_DEFAULT;
    dsPathRequest->srcCh.dtsPriority            = 0;
    dsPathRequest->srcCh.channelPriority        = DS_DEFAULT;
    dsPathRequest->srcCh.descriptorFetchMode    = DS_ACCESS_MODE_COHERENT_ALLOCATE;
    dsPathRequest->srcCh.wayMask                = DS_DEFAULT;
    dsPathRequest->srcCh.base                   = 0;

    dsPathRequest->dstCh.transferBurstSize      = DS_DEFAULT;
    dsPathRequest->dstCh.dtsPriority            = 0;
    dsPathRequest->dstCh.channelPriority        = DS_DEFAULT;
    dsPathRequest->dstCh.descriptorFetchMode    = DS_ACCESS_MODE_COHERENT_ALLOCATE;
    dsPathRequest->dstCh.wayMask                = DS_DEFAULT;
    dsPathRequest->dstCh.base                   = 0;

    dsPathRequest->buf.bufferSize               = bufferSize; // in bytes
    dsPathRequest->buf.srcChunkSize             = srcSize;
    dsPathRequest->buf.dstChunkSize             = dstSize;

    dsPathRequest->isSrcIO                      = isSrcIO;
    dsPathRequest->isDstIO                      = isDstIO;
    dsPathRequest->flags                        = 0;

    dsPathRequest->srcCh.minInterburstDelay     = DS_DEFAULT;
    dsPathRequest->dstCh.minInterburstDelay     = DS_DEFAULT;

} // end InitDsReqPath()

⌨️ 快捷键说明

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