📄 p9030_diag.c
字号:
printf ("WARNING!!!\n");
printf ("----------\n");
printf ("Your hardware has level sensitive interrupts.\n");
printf ("You must modify the source code of P9030_IntEnable(), in the file p9030_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", P9030_IntIsEnabled(hPlx) ? "Disable" : "Enable");
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 (P9030_IntIsEnabled(hPlx))
{
printf ("Disabling interrupt Int\n");
P9030_IntDisable(hPlx);
}
else
{
printf ("Enabling interrupts\n");
if (!P9030_IntEnable(hPlx, PLX_IntHandlerRoutine))
printf ("failed enabling interrupts\n");
}
break;
}
} while (cmd!=99);
}
void PLX_EEPROMAccess(P9030_HANDLE hPlx)
{
int cmd;
DWORD addr;
DWORD dwData;
do
{
printf ("Access the board's serial EEPROM\n");
printf ("--------------------------------\n");
if (!P9030_EEPROMValid(hPlx))
printf ("Note: PLX EEPROM valid BIT is 0\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 (!P9030_EEPROMReadDWord(hPlx, addr, &dwData))
{
printf("\nError occurred reading serial EEPROM - %s\n", P9030_ErrorString);
break;
}
printf("%08x ", dwData);
}
printf ("\n");
break;
case 2:
printf ("Enter address to read from (0-7f): ");
fgets(line, sizeof(line), stdin);
sscanf (line, "%x", &addr);
if (P9030_EEPROMReadDWord(hPlx, addr, &dwData))
printf ("Value read: %08x\n", dwData);
else
printf("Error occurred reading serial EEPROM - %s\n", P9030_ErrorString);
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);
if (!P9030_EEPROMWriteDWord(hPlx, addr, dwData))
printf("Error occurred reading serial EEPROM - %s\n", P9030_ErrorString);
break;
default:
break;
}
} while (cmd!=99);
}
P9030_HANDLE PLX_LocateAndOpenBoard(DWORD dwVendorID, DWORD dwDeviceID)
{
DWORD cards, my_card;
P9030_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 = P9030_CountCards (dwVendorID, dwDeviceID);
if (cards==0)
{
printf("%s", P9030_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 (P9030_Open (&hPlx, dwVendorID, dwDeviceID, my_card - 1))
printf ("PLX 9030 PCI card found!\n");
else printf ("%s", P9030_ErrorString);
return hPlx;
}
int main(int argc, char *argv[])
{
int cmd;
P9030_HANDLE hPlx = NULL;
HANDLE hWD;
printf ("PLX 9030 diagnostic utility.\n");
printf ("Application accesses hardware using " WD_PROD_NAME ".\n");
// make sure DriverBuilder is loaded
if (!PCI_Get_WD_handle(&hWD)) return 0;
WD_Close (hWD);
hPlx = PLX_LocateAndOpenBoard(0x10b5, 0x9030);
do
{
printf ("\n");
printf ("PLX 9030 main menu\n");
printf ("-------------------\n");
printf ("1. Scan PCI bus\n");
printf ("2. Locate/Choose PLX 9030 board\n");
if (hPlx)
{
DWORD dwCNTRL = P9030_ReadReg(hPlx, P9030_CNTRL);
dwCNTRL |= BIT29;
P9030_WriteReg( hPlx, P9030_CNTRL, dwCNTRL);
printf ("3. PCI configuration registers\n");
printf ("4. PLX 9030 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 ("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 9030 board
if (hPlx) P9030_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;
P9030_GetPciSlot(hPlx, &pciSlot);
PCI_EditConfigReg(pciSlot);
}
break;
case 4: // PLX 9030 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;
}
} while (cmd!=99);
if (hPlx) P9030_Close(hPlx);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -