📄 dm642_cli.c
字号:
// Setup the DSP's EMIF
DM642SetupEMIF(hDM642);
}
if (0 == strcmp(sChoice, "30"))
{
// Scan PCI bus
PCI_Print_all_cards_info();
}
/*if (0 == strcmp(sChoice, "29"))
{
// Locate DM642 board
ChangeBoard(&hDM642, 0, 0);
if (!hDM642)
{
printf("DM642 card open failed!\n");
}
}*/
//--------------------------------------------------------------
// Board-changing related routines/choices (if > 1 board) ...
//--------------------------------------------------------------
if (0 == strcmp(sChoice, "c"))
{
if (gnBoardsFound > 1)
{
if (ChangeBoard(&hDM642,
DM642_DEFAULT_VENDOR_ID,
DM642_DEFAULT_DEVICE_ID) < 0)
{
printf("Error changing boards!!!\n");
*phDM642 = NULL;
break;
}
} // end if Boards Found > 1
}
//---------------------------------------
// The Quit Choice ...
// This kicks us out of the loop.
//---------------------------------------
if (0 == strcmp (sChoice, "q"))
{
// exit
break;
}
} // (infinite) while-loop
} // END DM642RunMainCLIMenu()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuReadFpgaVersionReg
////
//// Purpose: This routine reads the FPGA version register and displays
//// its value to the screen.
//// The DM642 library does the dirty work.
////
//// Input Parameters:
//// hDM642 -- Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void menuReadFpgaVersionReg( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned nVal = 0;
//------------------------------------------------------------------------
if (kNoError == nStatus)
{
// Read the version register
nStatus = DM642ReadFpgaReg(hDM642, kFamrOffs_FVR, &nVal);
}
if (kNoError == nStatus)
{
// Display the register on the screen
printf("FPGA Version Reg: 0x%02x\n", nVal);
}
} // End menuReadFpgaVersionReg()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: showFlashPageReg
////
//// Purpose: This routine reads and displays the Flash Page Register.
//// The DM642 library does the dirty work.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) :
//// kNoError (0) - successful read of register
//// an error code - register-read failed
////
//////////////////////////////////////////////////////////////////////////////
int showFlashPageReg( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned nVal = 0;
if (kNoError == nStatus)
{
// Read the register value
nStatus = DM642ReadFpgaReg(hDM642, kFamrOffs_FPR, &nVal);
}
if (kNoError == nStatus)
{
// Display the current register value
printf("Current Flash Page Register value: 0x%02x\n", nVal);
}
return (nStatus);
} // END showFlashPageReg()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuWriteFlashPageReg
////
//// Purpose: This routine displays the Flash Page Register. It then
//// prompts the user for a new value, writes that value to the
//// FPR, and finally reads the FPR back and displays its new
/// current value.
//// The DM642 library does the dirty work.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void menuWriteFlashPageReg( DM642_HANDLE hDM642 )
{
int nStatus = kNoError;
unsigned nVal = 0;
unsigned nNewVal = 0;
while (kNoError == nStatus)
{
if (kNoError == nStatus)
{
//-----------------------------------------------------
// Read the register value and display it to the user
// before they change it.
//-----------------------------------------------------
nStatus = showFlashPageReg(hDM642);
}
if (kNoError == nStatus)
{
// get the new register value from the user
nStatus = getInt("Enter the value to write to the Flash Page Reg (or q) >> ", "%x",
&nNewVal);
}
if (kNoError == nStatus)
{
// Write the value
DM642WriteFpgaReg(hDM642, kFamrOffs_FPR, nNewVal);
}
if (kNoError == nStatus)
{
// Read the register value
DM642ReadFpgaReg(hDM642, kFamrOffs_FPR, &nVal);
}
if (kNoError == nStatus)
{
printf("Flash Page Register value: 0x%02x\n", nVal);
}
} // while (kNoError == nStatus)
} // end menuWriteFlashPageReg()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuReadDSPConfigSpace
////
//// Purpose: This routine reads the DM642's Config Space and displays
//// its results on the screen. The user provides the Config
//// Address and the number of Config words to read-n-display.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void menuReadDSPConfigSpace( DM642_HANDLE hDM642 )
{
unsigned int nLoc = 0;
unsigned int nStartAddr = 0;
unsigned int nVal = 0;
int nNumWords = 0;
int nIndex = 0;
int nStatus = kNoError;
while (kNoError == nStatus)
{
if (kNoError == nStatus)
{
// Get the starting address from the user
nStatus = getInt("Read: Enter DSP Config Space Address (or q) >> ", "%x",
&nStartAddr);
}
if (kNoError == nStatus)
{
// Get the number of words to read
nStatus = getInt("Read: Enter number of words to read (or q) >> ", "%x",
&nNumWords);
}
if (kNoError == nStatus)
{
for (nIndex = 0; nIndex < nNumWords; nIndex++)
{
// Calculate the current address
nLoc = (nStartAddr + (nIndex * kBytesPerWord));
if (kNoError == nStatus)
{
// read the value from memory
nVal = DM642ReadPCIReg(hDM642, nLoc);
}
if (kNoError == nStatus)
{
printf("Address: 0x%08x Value: 0x%08x\n", nLoc, nVal);
}
} // internal for-loop
}
if (CHOICE_Q != nStatus)
{
printf ("DSP config space read %s\n\n",
(kNoError == nStatus) ? "passed" : "FAILED!");
}
} // external while-loop
} // End menuReadDSPConfigSpace()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuWriteDSPConfigSpace
////
//// Purpose: This routine writes to a register (location/offset) in the
//// DM642's Configuration Space. The user provides the register
//// (offset) and the value to write.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void menuWriteDSPConfigSpace( DM642_HANDLE hDM642 )
{
unsigned int nCfgAddr = 0;
unsigned int nVal = 0;
int nStatus = kNoError;
while (kNoError == nStatus)
{
if (kNoError == nStatus)
{
// Get the address from the user
nStatus = getInt("Write: Enter DSP Config Space Address (or q) >> ", "%x",
&nCfgAddr);
}
if (kNoError == nStatus)
{
// Get the value to write from the user
nStatus = getInt("Write: Value to write (or q) >> ", "%x", &nVal);
}
if (kNoError == nStatus)
{
// Write the register
DM642WritePCIReg(hDM642, nCfgAddr, nVal);
}
if (kNoError == nStatus)
{
// Read the register
nVal = DM642ReadPCIReg(hDM642, nCfgAddr);
}
if (kNoError == nStatus)
{
printf("CfgAddr: 0x%08x: Value: 0x%08x\n", nCfgAddr, nVal);
}
if (CHOICE_Q != nStatus)
{
printf("DSP config space write %s\n\n",
(kNoError == nStatus) ? "passed" : "FAILED!");
}
} // while-loop
} // End menuWriteDSPConfigSpace()
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// Name: menuReadDSPMem
////
//// Purpose: This routine reads a specified number of words/bytes
//// from a spcified address and displays the values to the
//// screen. The user provides the starting address, the
//// word count, and the bytes per word.
////
//// Input Parameters:
//// hDM642 - Handle of the currently-open DM642 board/card
////
//// Output Parameters: none
////
//// Return Value(s) : none
////
//////////////////////////////////////////////////////////////////////////////
void menuReadDSPMem( DM642_HANDLE hDM642 )
{
unsigned int nLoc = 0;
unsigned int nVal = 0;
unsigned int nStartAddr = 0;
int nNum = 0;
int nCount = 0;
int nStatus = kNoError;
int nBytesPerWord = 0;
while (kNoError == nStatus)
{
if (kNoError == nStatus)
{
// Get the Full memory address from the user
nStatus = getInt("Read: Memory start Address (or q) >> ", "%x",
&nStartAddr);
}
if (kNoError == nStatus)
{
// Get the number of words to read from the user
nStatus = getInt("Read: Enter # of words (or q) >> ", "%x",
&nNum);
}
if (kNoError == nStatus)
{
// Get the number of bytes per word to read. (1,2,or 4)
nStatus = getInt("Read: Enter # bytes per word (or q) >> ", "%x",
&nBytesPerWord);
}
if (kNoError == nStatus)
{
// Read the words from memory and display them on the screen
for (nCount = 0; nCount < nNum; nCount++)
{
// Calculate the current address
nLoc = nStartAddr + nCount*nBytesPerWord;
if (kNoError == nStatus)
{
// Read the value from memory
nStatus = DM642ReadDSPMem(hDM642, nLoc, &nVal, nBytesPerWord);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -