📄 hw_routines.c
字号:
(
A_UINT16 Mode // 0 for off, 1 for on
)
{
quietMode = Mode;
return;
}
#endif
/**************************************************************************
* uiOpenYieldLog - open the yield log file.
*
* A user interface command which turns on logging to the yield log file
*
* RETURNS: 1 if file opened, 0 if not
*/
A_UINT16 uiOpenYieldLog
(
char *filename, /* name of file to log to */
A_BOOL append
)
{
/* open file for writing */
if (append) {
yieldLogFile = fopen(filename, "a+");
}
else {
yieldLogFile = fopen(filename, "w");
}
if (yieldLogFile == NULL) {
uiPrintf("Unable to open yield log file %s\n", filename);
return(0);
} else {
uiPrintf("Opened file %s for yieldLog\n", filename);
}
/* set flag to say yield logging enabled */
yieldLogging = 1;
return(1);
}
/**************************************************************************
* uiYieldLog - write a string to the yield log file
*
* A user interface command which writes a string to the log file
*
* RETURNS: 1 if sucessful, 0 if not
*/
A_UINT16 uiYieldLog
(
char *string
)
{
if (yieldLogging > 0) {
if(yieldLogFile == NULL) {
uiPrintf("Error, yield logfile not valid, unable to write to file\n");
return 0;
}
/* write string to file */
fprintf(yieldLogFile, string);
fflush(yieldLogFile);
}
return 1;
}
/**************************************************************************
* uiCloseYieldLog - close the yield logging file
*
* A user interface command which closes an already open log file
*
* RETURNS: void
*/
void uiCloseYieldLog(void)
{
if ( yieldLogging) {
if (yieldLogFile != NULL)
fclose(yieldLogFile);
yieldLogging = 0;
}
return;
}
A_UINT16 hwGetBarSelect(A_UINT16 devIndex) {
return (A_UINT16) globDrvInfo.pDevInfoArray[devIndex]->pdkInfo->bar_select;
}
A_UINT16 hwSetBarSelect(A_UINT16 devIndex, A_UINT16 bs) {
if (driverVer.minorVersion >= 2) {
if (bs < globDrvInfo.pDevInfoArray[devIndex]->pdkInfo->numBars) {
globDrvInfo.pDevInfoArray[devIndex]->pdkInfo->bar_select = bs;
return bs;
}
}
globDrvInfo.pDevInfoArray[devIndex]->pdkInfo->bar_select = 0;
return 0;
}
/**************************************************************************
* hwMemWriteBlock - Write a block of memory within the simulation environment
*
* Write a block of memory within the simulation environment
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwMemWriteBlock
(
A_UINT16 devIndex,
A_UCHAR *pBuffer,
A_UINT32 length,
A_UINT32 *pPhysAddr
)
{
A_UCHAR *pMem; /* virtual pointer to area to be written */
A_UINT16 i;
A_UINT32 startPhysAddr; /* physical address of start of device memory block,
for easier readability */
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
if(*pPhysAddr == 0)
{
return(-1);
}
/* first need to check that the phys address is within the allocated memory block.
Need to make sure that the begin size and endsize match. Will check all the
devices. Only checking the memory block, will not allow registers to be accessed
this way
*/
/* want to scan all of the F2's to see if this is an allowable address for any of them
if it is then allow the access. This stays compatable with existing lab scripts */
for (i = 0; i < WLAN_MAX_DEV; i++) {
if(pdevInfo = globDrvInfo.pDevInfoArray[i]) {
//check start and end addresswithin memory allocation
startPhysAddr = pdevInfo->pdkInfo->memPhyAddr;
if((*pPhysAddr >= startPhysAddr) &&
(*pPhysAddr <= (startPhysAddr + pdevInfo->pdkInfo->memSize)) &&
((*pPhysAddr + length) >= startPhysAddr) &&
((*pPhysAddr + length) <= (startPhysAddr + pdevInfo->pdkInfo->memSize))
) {
/* address is within range, so can do the write */
/* get the virtual pointer to start and read */
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->memVirAddr + (*pPhysAddr - pdevInfo->pdkInfo->memPhyAddr));
memcpy(pMem, pBuffer, length);
return(0);
}
// check within the register regions
startPhysAddr = pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select];
if ((*pPhysAddr >= startPhysAddr) &&
(*pPhysAddr < startPhysAddr + pdevInfo->pdkInfo->aregRange[pdevInfo->pdkInfo->bar_select]) &&
((*pPhysAddr + length) >= startPhysAddr) &&
((*pPhysAddr + length) <= (startPhysAddr + pdevInfo->pdkInfo->aregRange[pdevInfo->pdkInfo->bar_select]))) {
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (*pPhysAddr - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
memcpy(pMem, pBuffer, length);
return(0);
}
}
}
/* if got to here, then address is bad */
uiPrintf("Warning: Address is not within legal memory range, nothing written\n");
return(-1);
}
/**************************************************************************
* hwMemReadBlock - Read a block of memory within the simulation environment
*
* Read a block of memory within the simulation environment
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwMemReadBlock
(
A_UINT16 devIndex,
A_UCHAR *pBuffer,
A_UINT32 physAddr,
A_UINT32 length
)
{
A_UCHAR *pMem; /* virtual pointer to area to be written */
A_UINT16 i;
A_UINT32 startPhysAddr; /* physical address of start of device memory block,
for easier readability */
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
/* first need to check that the phys address is within the allocated memory block.
Need to make sure that the begin size and endsize match. Will check all the
devices. Only checking the memory block, will not allow registers to be accessed
this way
*/
for (i = 0; i < WLAN_MAX_DEV; i++) {
if(pdevInfo = globDrvInfo.pDevInfoArray[i]) {
//check start and end addresswithin memory allocation
startPhysAddr = pdevInfo->pdkInfo->memPhyAddr;
if((physAddr >= startPhysAddr) &&
(physAddr <= (startPhysAddr + pdevInfo->pdkInfo->memSize)) &&
((physAddr + length) >= startPhysAddr) &&
((physAddr + length) <= (startPhysAddr + pdevInfo->pdkInfo->memSize))
) {
/* address is within range, so can do the read */
/* get the virtual pointer to start and read */
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->memVirAddr + (physAddr - pdevInfo->pdkInfo->memPhyAddr));
memcpy(pBuffer, pMem, length);
return(0);
}
startPhysAddr = pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select];
if ((physAddr >= startPhysAddr) &&
(physAddr < startPhysAddr + pdevInfo->pdkInfo->aregRange[pdevInfo->pdkInfo->bar_select]) &&
((physAddr + length) >= startPhysAddr) &&
((physAddr + length) <= (startPhysAddr + pdevInfo->pdkInfo->aregRange[pdevInfo->pdkInfo->bar_select]))) {
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (physAddr - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
// check within the register regions
memcpy(pBuffer, pMem, length);
return(0);
}
}
}
/* if got to here, then address is bad */
uiPrintf("Warning: Address (%x) is not within legal memory range, nothing read\n", physAddr);
return(-1);
}
//#ifdef ART_BUILD
#if 1
//#else
/**************************************************************************
* hwGetPhysMem - get a block of physically contiguous memory
*
* This routine gets physically contiguous driver-level memory
*
* RETURNS: The physical address of the memory allocated
*/
/* #####Note may replace this with the function later that returns */
/* both physical and virtual memory of buffer. */
void *hwGetPhysMem
(
A_UINT16 devIndex,
A_UINT32 memSize, /* number of bytes to allocate */
A_UINT32 *physAddress
)
{
A_UCHAR *virtAddress;
A_UINT32 offset; /* offset from start of where descriptor is */
A_UINT16 numBlocks; /* num blocks need to allocate */
A_UINT16 index; /* index of first block to allocate */
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
if((memSize/BUFF_BLOCK_SIZE + 1) >= (1 << 8 * sizeof(A_UINT16))) {
uiPrintf("WARNING: Physical memory of size %ld out of range - returning NULL address\n", memSize);
return(NULL);
}
/* calculate how many blocks of memory are needed and round up result */
numBlocks = (A_UINT16) (memSize/BUFF_BLOCK_SIZE + ((memSize % BUFF_BLOCK_SIZE) || 0));
if(memGetIndexForBlock2(pdevInfo, pdevInfo->pbuffMapBytes, numBlocks, &index) != A_OK) {
uiPrintf("WARNING: Failed to allocate physical memory of size %ld - returning NULL address\n", memSize);
return(NULL);
}
/* got an index, now calculate addresses */
offset = index * BUFF_BLOCK_SIZE;
virtAddress = (A_UCHAR *)(pdevInfo->pdkInfo->memVirAddr + offset);
*physAddress = (A_UINT32)(pdevInfo->pdkInfo->memPhyAddr + offset);
// /* zero out memory */ -- Need to handle for predator also, so comment for now
// memset(virtAddress, 0, memSize);
return(virtAddress);
}
/**************************************************************************
* hwFreeAll - Environment specific code for Command to free all the
* currently allocated memory
*
* This routine calls to the hardware abstraction layer, to free all of the
* currently allocated memory. This will include all descriptors and packet
* data as well as any memory allocated with the alloc command.
*
*
* RETURNS: N/A
*/
void hwFreeAll
(
A_UINT16 devIndex
)
{
A_UINT32 NumBuffBlocks;
A_UINT32 NumBuffMapBytes;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
if(pdevInfo) {
NumBuffBlocks = pdevInfo->pdkInfo->memSize / BUFF_BLOCK_SIZE;
NumBuffMapBytes = NumBuffBlocks / 8;
/* clear the memory allocated by clearing all the map bytes */
memset( pdevInfo->pbuffMapBytes, 0, NumBuffMapBytes * sizeof(A_UCHAR) );
memset( pdevInfo->pnumBuffs, 0, NumBuffBlocks * sizeof(A_UINT16) );
}
return;
}
/**************************************************************************
* hwEnableFeature - Handle feature enable within windows environment
*
* Enable ISR features within windows environment
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwEnableFeature
(
A_UINT16 devIndex,
PIPE_CMD *pCmd
)
{
printf("hwEnableFeature not implemented\n");
return(0);
}
/**************************************************************************
* hwDisableFeature - Handle feature disable within windows environment
*
* Disble ISR features within windows environment
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwDisableFeature
(
A_UINT16 devIndex,
PIPE_CMD *pCmd
)
{
printf("hwDiableFeature not implemented\n");
return(0);
}
/**************************************************************************
* hwGetStats - Get stats
*
* call into kernel plugin to get the stats copied into user supplied
* buffer
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwGetStats
(
A_UINT16 devIndex,
A_UINT32 clearOnRead,
A_UCHAR *pBuffer,
A_BOOL rxStats
)
{
printf("hwGetStats not implemented\n");
return(0);
}
/**************************************************************************
* hwGetSingleStat - Get single stat
*
* call into kernel plugin to get the stats copied into user supplied
* buffer
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwGetSingleStat
(
A_UINT16 devIndex,
A_UINT32 statID,
A_UINT32 clearOnRead,
A_UCHAR *pBuffer,
A_BOOL rxStats
)
{
printf("hwGetSingleStat not implemented\n");
return(0);
}
/**************************************************************************
* hwRemapHardware - Remap the hardware to a new address
*
* Remap the hardware to a new address
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwRemapHardware
(
A_UINT16 devIndex,
A_UINT32 mapAddress
)
{
printf("hwReMapHardware not implemented\n");
return(0);
}
/**************************************************************************
* hwTramWriteBlock - Write trace ram
*
* Write a block of trace ram
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwTramWriteBlock
(
A_UINT16 devIndex,
A_UCHAR *pBuffer,
A_UINT32 length,
A_UINT32 physAddr
)
{
A_UINT32 numDWords = length / 4;
A_UINT32 *pData = (A_UINT32 *)pBuffer;
A_UINT32 i;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
for(i = 0; i < numDWords; i++) {
//write the address
hwMemWrite32(devIndex,pdevInfo->pdkInfo->aregPhyAddr[0] + 0x18, physAddr);
//write the value
hwMemWrite32(devIndex,pdevInfo->pdkInfo->aregPhyAddr[0] + 0x1c, *pData);
pData++;
physAddr++;
}
return 0;
}
/**************************************************************************
* hwTramReadBlock - Read a block of trace ram
*
* Read a block of traceram
*
*
* RETURNS: 0 on success, -1 on error
*/
A_INT16 hwTramReadBlock
(
A_UINT16 devIndex,
A_UCHAR *pBuffer,
A_UINT32 physAddr,
A_UINT32 length
)
{
A_UINT32 numDWords = length / 4;
A_UINT32 *pData = (A_UINT32 *)pBuffer;
A_UINT32 i;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
for(i = 0; i < numDWords; i++) {
//write the address
hwMemWrite32(devIndex, pdevInfo->pdkInfo->aregPhyAddr[0] + 0x18, physAddr);
//read the value
*pData = hwMemRead32(devIndex, pdevInfo->pdkInfo->aregPhyAddr[0] + 0x1c);
pData++;
physAddr++;
}
return 0;
}
#endif // ART_BUILD
/**************************************************************************
* freeDevInfo - frees memory held by devInfo
*
* RETURNS: N/A
*/
void freeDevInfo
(
MDK_WLAN_DEV_INFO *pdevInfo
)
{
A_FREE(pdevInfo->pdkInfo);
A_FREE(pdevInfo);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -