📄 p9054_diag.c
字号:
printf ("Enter option: ");
cmd = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd);
switch (cmd)
{
case 1:
if (P9054_IntIsEnabled(hPlx))
{
printf ("Disabling interrupt Int\n");
P9054_IntDisable(hPlx);
}
else
{
printf ("Enabling interrupts\n");
if (!P9054_IntEnable(hPlx, PLX_IntHandlerRoutine))
printf("%s", P9054_ErrorString);
}
break;
}
} while (cmd!=99);
}
void PLX_EEPROMAccess(P9054_HANDLE hPlx)
{
int cmd;
DWORD addr;
DWORD dwData;
do
{
printf ("Access the board's serial EEPROM\n");
printf ("--------------------------------\n");
if (!P9054_EEPROMValid(hPlx))
printf ("Note: PLX EEPROM valid BIT is 0\n");
printf (" Note: reading/writing to odd addresses is meaningless,\n");
printf (" as data is stored in words.\n");
printf ("1. Display EEPROM content\n");
printf ("2. Read dword from serial EEPROM on the board\n");
printf ("3. Write dword 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 += 4)
{
if (!(addr % 0x10))
printf("\n %02x: ", addr);
if (!P9054_EEPROMReadDWord(hPlx, addr, &dwData))
{
printf("\nError occurred reading serial EEPROM - %s\n", P9054_ErrorString);
break;
}
printf("%08x ", dwData);
}
printf ("\n");
break;
case 2:
printf ("Enter address to read from (0-ff): ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x", &addr);
if (P9054_EEPROMReadDWord(hPlx, addr, &dwData))
printf ("Value read: %x\n", dwData);
else
printf("Error occurred reading serial EEPROM - %s\n", P9054_ErrorString);
break;
case 3:
printf ("Enter address to write to (0-ff): ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x", &addr);
printf ("Enter data to write: ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x",&dwData);
if (!P9054_EEPROMWriteDWord(hPlx, addr, dwData))
printf("Error occurred reading serial EEPROM - %s\n", P9054_ErrorString);
break;
default:
break;
}
} while (cmd!=99);
}
P9054_HANDLE PLX_LocateAndOpenBoard(DWORD dwVendorID, DWORD dwDeviceID)
{
DWORD cards, my_card;
P9054_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 = P9054_CountCards (dwVendorID, dwDeviceID);
if (cards==0)
{
printf("%s", P9054_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;
}
}
if (P9054_Open (&hPlx, dwVendorID, dwDeviceID, my_card - 1))
printf ("PLX 9054 PCI card found!\n");
else printf ("%s", P9054_ErrorString);
return hPlx;
}
int main(int argc, char *argv[])
{
int cmd;
P9054_HANDLE hPlx = NULL;
HANDLE hWD;
printf ("PLX 9054 diagnostic utility.\n");
printf ("Application accesses hardware using " WD_PROD_NAME ".\n");
P9054_RegisterWinDriver();
// make sure WinDriver is loaded
if (!PCI_Get_WD_handle(&hWD)) return 0;
WD_Close (hWD);
hPlx = PLX_LocateAndOpenBoard(0x10b5, 0x5406);
do
{
printf ("\n");
printf ("PLX 9054 main menu\n");
printf ("-------------------\n");
printf ("1. Scan PCI bus\n");
printf ("2. Locate/Choose PLX 9054 board\n");
if (hPlx)
{
printf ("3. PCI configuration registers\n");
printf ("4. PLX 9054 local registers\n");
printf ("5. Access address spaces on the board\n");
printf ("6. Access local address ranges on the board\n");
printf ("7. Enable / Disable interrupts\n");
printf ("8. Access serial EEPROM on the board\n");
printf ("9. Write continus data to SRAM.\n");
printf ("10. Read SRAM and Write to file sram.dat\n");
printf ("11. Write specified data to SRAM.\n");
printf ("12. Write SRAM Byte by Byte.\n");
printf ("13. Write DPRAM.\n");
printf ("14. Read DPRAM and save as file dpram.dat.\n");
printf ("15. Read PCI Base Address 0.\n");
printf ("16. DMA .\n");
}
printf ("99. Exit\n");
printf ("Enter option: ");
cmd = 0;
fgets(line, sizeof(line), stdin);
sscanf (line, "%d",&cmd);
switch (cmd)
{
case 1: // Scan PCI bus
PCI_Print_all_cards_info();
break;
case 2: // Locate PLX 9054 board
if (hPlx) P9054_Close(hPlx);
hPlx = PLX_LocateAndOpenBoard(0, 0);
if (!hPlx) printf ("PLX card open failed!\n");
break;
case 3: // PCI configuration registers
if (hPlx)
{
WD_PCI_SLOT pciSlot;
P9054_GetPciSlot(hPlx, &pciSlot);
PCI_EditConfigReg(pciSlot);
}
break;
case 4: // PLX 9054 local registers
if (hPlx) PLX_EditReg(hPlx);
break;
case 5: // Access address spaces on the board
if (hPlx) PLX_BoardAccess(hPlx, FALSE);
break;
case 6: // Access local address ranges on the board
if (hPlx) PLX_BoardAccess(hPlx, TRUE);
break;
case 7: // Enable / Disable interrupts
if (hPlx) PLX_EnableDisableInterrupts(hPlx);
break;
case 8: // Access serial EEPROM on the board
if (hPlx) PLX_EEPROMAccess(hPlx);
break;
case 9:
if (hPlx)
WriteSram(hPlx);
break;
case 10:
if (hPlx)
ReadSram(hPlx);
break;
case 11:
if (hPlx)
WriteSramSameDate(hPlx);
break;
case 12:
if (hPlx)
WriteSramByByte(hPlx);
break;
case 13:
if (hPlx)
WriteDpram(hPlx);
break;
case 14:
if (hPlx)
ReadDpram(hPlx);
break;
case 15:
if (hPlx)
ReadPciBa0(hPlx);
break;
case 16:
if (hPlx)
DMA_SG_L2P(hPlx);
break;
}
} while (cmd!=99);
if (hPlx) P9054_Close(hPlx);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -