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

📄 pspan_diag.c

📁 adlink master board 6760 pci driver for control powerspan slave pci driver
💻 C
📖 第 1 页 / 共 3 页
字号:
          
       }
      
    }
    
    // DMA interrupt isr end
    ////////////////////////////
    
    
    
    /*  
    ///////////////
    //PSPAN_IntClear (hPlx);
    PSPAN_IntDisable(hPlx,PSPAN_IntHandlerRoutine);
    
    logMsg("Now Got interrupt--I am in Pspan II IntHandlerRoutine.\n",0,0,0,0,0,0);
    taskDelay(100);
    
    //PSPAN_IntSet (hPlx);
    PSPAN_IntEnable(hPlx, PSPAN_IntHandlerRoutine);
    
    return;
    ///////////////
    */
    
}


void PSPAN_EnableDisableInterrupts(PSPAN_HANDLE hPlx)
{
    int cmd;

    printf ("WARNING!!!\n");
    printf ("----------\n");
    printf ("Your hardware has level sensitive interrupts.\n");
    /*
    printf ("You must modify the source code of PSPAN_IntEnable(), in the file PSPAN_lib.c,\n");
    printf ("to acknowledge the interrupt before enabling interrupts.\n");
    printf ("Without this modification, your PC will HANG upon interrupt!\n");
    */

    do
    {
        printf ("Enable / Disable interrupts\n");
        printf ("---------------------------\n");
        printf ("1. %s interrupts\n", PSPAN_IntIsEnabled(hPlx) ? "Disable" : "Enable");
        printf ("2. run interrupts routines.\n");
        printf ("99. Back to main menu\n");
        printf ("\n");
        printf ("Enter option: ");
        cmd = 0;
        fgets(line, sizeof(line), stdin);
        sscanf (line, "%d",&cmd);
        switch (cmd)
        {
        case 1:
            if (PSPAN_IntIsEnabled(hPlx))
            {
                printf ("Disabling interrupt Int\n");
                PSPAN_IntDisable(hPlx,PSPAN_IntHandlerRoutine);
            }
            else
            {
                printf ("Enabling interrupts\n");
                PSPAN_configureDMAInterrupts( hPlx,0);
                if (!PSPAN_IntEnable(hPlx, PSPAN_IntHandlerRoutine))
                    printf ("failed enabling interrupts\n");
            }
            break;
        /*   
        case 2:
            PSPAN_IntHandlerRoutine(hPlx,0);
            break;
        */
        
        default:
            break;
            
        }// switch clause end
        
    } 
    while (cmd!=99);
}

void PSPAN_EEPROMAccess(PSPAN_HANDLE hPlx)
{
    int cmd;
    UCHAR addr;
    UCHAR dwData;

    do
    {
        printf ("Access the board's serial EEPROM\n");
        printf ("--------------------------------\n");

        printf ("1. Display EEPROM content\n");
        printf ("2. Read word from serial EEPROM on the board\n");
        printf ("3. Write word to the serial EEPROM on the board\n");
        printf ("99. Back to main menu\n");
        printf ("\n");
        printf ("Enter option: ");
        cmd = 0;
        fgets(line, sizeof(line), stdin);
        sscanf (line, "%d",&cmd);
        switch (cmd)
        {
        case 1:
            for (addr=0; addr<0xff; addr++)
            {
                if (!(addr % 0x10))
                printf("\n %02x: ", addr);
                printf("%02x  ", PSPAN_EepromByteRead(hPlx, addr) );
            }
            printf ("\n");
            break;
            
        case 2:
            printf ("Enter address to read from (0-7f): ");
            fgets(line, sizeof(line), stdin);
            sscanf (line, "%x", &addr);
            printf ("Value read: %02x\n", PSPAN_EepromByteRead(hPlx, addr));
            break;

        case 3:
            printf ("Enter address to write to (0-7f): ");
            fgets(line, sizeof(line), stdin);
            sscanf (line, "%x", &addr);
            printf ("Enter data to write: ");
            fgets(line, sizeof(line), stdin);
            sscanf (line, "%x",&dwData);
            //PSPAN_EepromByteWrite(hPlx, addr, dwData); // protect the original content by pgn
            break;

        default:
            break;
        }
    } while (cmd!=99);
}

PSPAN_HANDLE PSPAN_LocateAndOpenBoard(DWORD dwVendorID, DWORD dwDeviceID)
{
    DWORD cards, my_card;
    PSPAN_HANDLE hPlx = NULL;

    if (dwVendorID==0)
    {
        printf ("Enter VendorID: ");
        fgets(line, sizeof(line), stdin);
        sscanf (line, "%x",&dwVendorID);
        if (dwVendorID==0) return NULL;

        printf ("Enter DeviceID: ");
        fgets(line, sizeof(line), stdin);
        sscanf (line, "%x",&dwDeviceID);
    }
    
    cards = PSPAN_CountCards (dwVendorID, dwDeviceID);
    
    if (cards==0) 
    {
        printf("%s", PSPAN_ErrorString);
        return NULL;
    }
    else if (cards==1) my_card = 1;
    else
    {
        DWORD i;

        printf("Found %d matching PCI cards\n", cards);
        printf("Select card (1-%d): ", cards);
        i = 0;
        fgets(line, sizeof(line), stdin);
        sscanf (line, "%d",&i);
        if (i>=1 && i <=cards) my_card = i;
        else 
        {
            printf ("Choice out of range\n");
            return NULL;
        }
    }
    // to correct an errata with BIT7 of BAR0 in some PSPAN chips, use PSPAN_OPEN_FIX_BIT7
    if (PSPAN_Open (&hPlx, dwVendorID, dwDeviceID, my_card - 1, 0 /* PSPAN_OPEN_FIX_BIT7 */ ))
        printf ("Pspan II PCI card found!\n");
    else printf ("%s", PSPAN_ErrorString);
    return hPlx;
}


void PSPAN_test (void )
{

    long  li;
    long ll;
    
    int number;
    short pVendorId;
    short pDeviceId;
    int   pBusNo;
    int   pDeviceNo;
    int   pFuncNo;
     

	
	// added begin by pgn
	for(number=0;number<32;number++)
	{
   	     if( pciGetDeviceNum(number,&pVendorId,&pDeviceId,&pBusNo,&pDeviceNo,&pFuncNo) == 0 )
 	     {
 	       	    printf("\n%d\n",number);
 		        printf("pVendorId is 0x%x.\n",pVendorId);
 		        printf("pDeviceId is 0x%x.\n",pDeviceId);
	  	        printf("pBusNo is 0x%x.\n",pBusNo);
		        printf("pDeviceNo is 0x%x.\n",pDeviceNo);
    		    printf("pFuncNo is 0x%x.\n",pFuncNo);
         }
         else
         {
            	 printf("\nerror%d\n",number);
         }
        
        
	    if( pciFindDevice(0x107e, 0x9060,number,&pBusNo,&pDeviceNo,&pFuncNo)==0)
	    {
   	    	printf("\n_pBusNo is 0x%x.\n",pBusNo);
  	        printf("_pDeviceNo is 0x%x.\n",pDeviceNo);
  	        printf("_pFuncNo is 0x%x.\n",pFuncNo);

	        pciConfigInLong(pBusNo,pDeviceNo,pFuncNo,0x10,&ll);
        	printf("_hPlx->addrDesc[0].dwAddr is 0x%x\n",ll);
        	pciConfigInAddressSpace(pBusNo,pDeviceNo,pFuncNo,0x10,&li);
        	printf("_hPlx->addrDesc[0].dwbytes is 0x%x\n",li);
                    
        	pciConfigInLong(pBusNo,pDeviceNo,pFuncNo,0x14,&ll);
        	printf("_hPlx->addrDesc[1].dwAddr is 0x%x\n",ll);
        	pciConfigInAddressSpace(pBusNo,pDeviceNo,pFuncNo,0x14,&li);
        	printf("_hPlx->addrDesc[1].dwbytes is 0x%x\n",li);
        
        	pciConfigInLong(pBusNo,pDeviceNo,pFuncNo,0x18,&ll);
        	printf("_hPlx->addrDesc[2].dwAddr is 0x%x\n",ll);
        	pciConfigInAddressSpace(pBusNo,pDeviceNo,pFuncNo,0x18,&li);
        	printf("_hPlx->addrDesc[2].dwbytes is 0x%x\n",li); 
        	
        	pciConfigInLong(pBusNo,pDeviceNo,pFuncNo,0x1c,&ll);
        	printf("_hPlx->addrDesc[2].dwAddr is 0x%x\n",ll);
        	pciConfigInAddressSpace(pBusNo,pDeviceNo,pFuncNo,0x1c,&li);
        	printf("_hPlx->addrDesc[2].dwbytes is 0x%x\n",li);         	
        	
        	printf("\nfind device %d ok\n",number); 
        }
        else
        {
              	printf("find device %d error\n",number);
              	
        }
             
    } // end of for loop clause       
    
    
}

/******************************************************************************
* NAME:  PSPAN_testSimpleDMA
*
* DESCRIPTION: simple DMA test on specified channel
*
* INPUT PARAMETERS:
*     channel             
*
* RETURN VALUES: none
*
*******************************************************************************/
void PSPAN_SimpleDMA( PSPAN_HANDLE hPlx, unsigned long  channel ,int direction )
{
    int cmd;
    
   unsigned short size;
   unsigned long i, ulPcAddr, ulLocAddr, ulBaseAddr;

   printf("Local to PCI DMA %d : \n", channel);     /* DMA */
   size = 0x2000 / 2;                               /* transfer bytes count */
   
   // define the pointer to the PCI address 
   printf("Enter PCI Address:\n");
   fgets(line, sizeof(line), stdin);
   sscanf (line, "%x",&ulPcAddr);
   
   // get 4k aligned address 
   ulPcAddr =  (ulPcAddr + 0xFFF) & ~0x00000FFF;   
   
   // define the pointer to the local address 
   printf("Enter PB Address:\n");
   fgets(line, sizeof(line), stdin);
   sscanf (line, "%x",&ulLocAddr); 
   
   // the 3 last bits of SRC and DEST addr must be the same for powerspan DMA transfer 
   ulLocAddr = (ulLocAddr & 0xFFFFFFF8) | (ulPcAddr & 0x7);       
   
    
   /* disable all interrupts in IER0 and IER1 registers */
   //PSPAN_WriteReg ( hPlx, T_IER0, 0);
   //PSPAN_WriteReg ( hPlx, T_IER1, 0);
  
   

⌨️ 快捷键说明

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