📄 hw_routines.c
字号:
if (pdevInfo->pdkInfo->res_type[i] == RES_IO) { //check if its IO space
if ((address >= pdevInfo->pdkInfo->aregPhyAddr[i]) && (address <
(pdevInfo->pdkInfo->aregPhyAddr[i] + pdevInfo->pdkInfo->aregRange[i]))) {
return A_OK;
}
}
}
return A_ENOENT;
}
/**************************************************************************
* hwMemRead8 - read an 8 bit value
*
* This routine will call into the simulation environment to activate an
* 8 bit PCI memory read cycle, value read is returned to caller
*
* RETURNS: the value read
*/
A_UINT8 hwMemRead8
(
A_UINT16 devIndex,
A_UINT32 address /* the address to read from */
)
{
#ifdef SIM
A_UINT8 value;
#endif
A_UINT8 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
#ifdef SIM
PCIsimMemReadB(address, &value);
return value;
#else
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (address - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
return (*pMem);
#endif
}
//check within memory allocation
if(A_OK == checkMemSpace(pdevInfo, address))
{
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
return(*pMem);
}
uiPrintf("ERROR: hwMemRead8 could not access hardware address: %08lx\n", address);
return (0xdb);
}
/**************************************************************************
* hwMemRead16 - read a 16 bit value
*
* This routine will call into the simulation environment to activate a
* 16 bit PCI memory read cycle, value read is returned to caller
*
* RETURNS: the value read
*/
A_UINT16 hwMemRead16
(
A_UINT16 devIndex,
A_UINT32 address /* the address to read from */
)
{
#ifdef SIM
A_UINT8 value;
#endif
A_UINT16 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
#ifdef SIM
PCIsimMemReadW(address, &value);
return value;
#else
pMem = (A_UINT16 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (address - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
return (*pMem);
#endif
}
//check within memory allocation
if(A_OK == checkMemSpace(pdevInfo, address))
{
pMem = (A_UINT16 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
return(*pMem);
}
uiPrintf("ERROR: hwMemRead16 could not access hardware address: %08lx\n", address);
return (0xdead);
}
/**************************************************************************
* hwMemRead32 - read an 32 bit value
*
* This routine will call into the simulation environment to activate a
* 32 bit PCI memory read cycle, value read is returned to caller
*
* RETURNS: the value read
*/
A_UINT32 hwMemRead32
(
A_UINT16 devIndex,
A_UINT32 address /* the address to read from */
)
{
#ifdef SIM
A_UINT8 value;
#endif
A_UINT32 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
if (A_OK == checkIOSpace(pdevInfo, address))
{
return(hwIORead(devIndex, address));
}
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
#ifdef SIM
PCIsimMemReadDW(address, &value);
return value;
#else
q_uiPrintf("hwMRd:bs=%d:rva=%x:rpa=%x:addr=%x:\n", pdevInfo->pdkInfo->bar_select, pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select], pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select], address );
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (address - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
q_uiPrintf("Reg addr %x \n", pMem);
q_uiPrintf("Reg Val %x read\n", *(volatile int *)pMem);
return(*(volatile int *)pMem);
//return(0xbabe);
#endif
}
//check within memory allocation
if(A_OK == checkMemSpace(pdevInfo, address))
{
q_uiPrintf("mva=%x:mpa=%x:addr=%x:\n", pdevInfo->pdkInfo->memVirAddr, pdevInfo->pdkInfo->memPhyAddr, address);
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
q_uiPrintf("Mem Val %x read\n", *pMem);
return(*pMem);
}
uiPrintf("ERROR: hwMemRead32 could not access hardware address: %08lx\n", address);
return (0xdeadbeef);
}
/**************************************************************************
* hwMemWrite8 - write an 8 bit value
*
* This routine will call into the simulation environment to activate an
* 8 bit PCI memory write cycle
*
* RETURNS: N/A
*/
void hwMemWrite8
(
A_UINT16 devIndex,
A_UINT32 address, /* the address to write */
A_UINT8 value /* value to write */
)
{
A_UINT8 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
#ifdef SIM
PCIsimMemWriteB(address, value);
#else
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (address - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
*pMem = value;
#endif
return;
}
// check within our malloc area
if(A_OK == checkMemSpace(pdevInfo, address))
{
pMem = (A_UINT8 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
*pMem = value;
return;
}
uiPrintf("ERROR: hwMemWrite8 could not access hardware address: %08lx\n", address);
}
/**************************************************************************
* hwMemWrite16 - write a 16 bit value
*
* This routine will call into the simulation environment to activate a
* 16 bit PCI memory write cycle
*
* RETURNS: N/A
*/
void hwMemWrite16
(
A_UINT16 devIndex,
A_UINT32 address, /* the address to write */
A_UINT16 value /* value to write */
)
{
A_UINT16 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
#ifdef SIM
PCIsimMemWriteW(address, value);
#else
pMem = (A_UINT16 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (address - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
*pMem = value;
#endif
return;
}
// check within our malloc area
if(A_OK == checkMemSpace(pdevInfo, address))
{
pMem = (A_UINT16 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
*pMem = value;
return;
}
uiPrintf("ERROR: hwMemWrite16 could not access hardware address: %08lx\n", address);
}
/**************************************************************************
* hwMemWrite32 - write a 32 bit value
*
* This routine will call into the simulation environment to activate a
* 32 bit PCI memory write cycle
*
* RETURNS: N/A
*/
void hwMemWrite32
(
A_UINT16 devIndex,
A_UINT32 address, /* the address to write */
A_UINT32 value /* value to write */
)
{
A_UINT32 *pMem;
MDK_WLAN_DEV_INFO *pdevInfo;
pdevInfo = globDrvInfo.pDevInfoArray[devIndex];
if (A_OK == checkIOSpace(pdevInfo, address))
{
hwIOWrite(devIndex, address, value);
return;
}
// check within the register regions
if (A_OK == checkRegSpace(pdevInfo, address))
{
#ifdef SIM
PCIsimMemWriteDW(address, value);
#else
q_uiPrintf("hwMWr:bs=%d:rva=%x:rpa=%x:addr=%x:value=%x\n", pdevInfo->pdkInfo->bar_select, pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select], pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select], address , value );
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->aregVirAddr[pdevInfo->pdkInfo->bar_select] + (address - pdevInfo->pdkInfo->aregPhyAddr[pdevInfo->pdkInfo->bar_select]));
*pMem = value;
q_uiPrintf("Reg Val %x written at %x\n", value, pMem);
#endif
return;
}
// check within our malloc area
if(A_OK == checkMemSpace(pdevInfo, address))
{
pMem = (A_UINT32 *) (pdevInfo->pdkInfo->memVirAddr +
(address - pdevInfo->pdkInfo->memPhyAddr));
q_uiPrintf("mva=%x:mpa=%x:addr=%x:value=%x\n", pdevInfo->pdkInfo->memVirAddr, pdevInfo->pdkInfo->memPhyAddr, address , value );
*pMem = value;
q_uiPrintf("Mem Val %x written\n", value);
return;
}
uiPrintf("ERROR: hwMemWrite32 could not access hardware address: %08lx\n", address);
}
#ifndef __ATH_DJGPPDOS__
/**************************************************************************
* uiPrintf - print to the perl console
*
* This routine is the equivalent of printf. It is used such that logging
* capabilities can be added.
*
* RETURNS: same as printf. Number of characters printed
*/
A_INT32 uiPrintf
(
const char * format,
...
)
{
va_list argList;
A_INT32 retval = 0;
A_CHAR buffer[1024];
/*if have logging turned on then can also write to a file if needed */
/* get the arguement list */
va_start(argList, format);
/* using vprintf to perform the printing it is the same is printf, only
* it takes a va_list or arguments
*/
retval = vprintf(format, argList);
fflush(stdout);
if (logging) {
vsprintf(buffer, format, argList);
fputs(buffer, logFile);
fflush(logFile);
}
va_end(argList); /* cleanup arg list */
return(retval);
}
A_INT32 q_uiPrintf
(
const char * format,
...
)
{
va_list argList;
A_INT32 retval = 0;
A_CHAR buffer[256];
if ( !quietMode ) {
va_start(argList, format);
retval = vprintf(format, argList);
fflush(stdout);
if ( logging ) {
vsprintf(buffer, format, argList);
fputs(buffer, logFile);
}
va_end(argList); // clean up arg list
}
return(retval);
}
#endif
/**************************************************************************
* statsPrintf - print to the perl console and to stats file
*
* This routine is the equivalent of printf. In addition it will write
* to the file in stats format (ie with , delimits). If the pointer to
* the file is null, just print to console
*
* RETURNS: same as printf. Number of characters printed
*/
A_INT16 statsPrintf
(
FILE *pFile,
const char * format,
...
)
{
va_list argList;
int retval = 0;
char buffer[256];
/*if have logging turned on then can also write to a file if needed */
/* get the arguement list */
va_start(argList, format);
/* using vprintf to perform the printing it is the same is printf, only
* it takes a va_list or arguments
*/
retval = vprintf(format, argList);
fflush(stdout);
if (logging) {
vsprintf(buffer, format, argList);
fputs(buffer, logFile);
}
if (pFile)
{
vsprintf(buffer, format, argList);
fputs(buffer, pFile);
fputc(',', pFile);
fflush(pFile);
}
va_end(argList); /* cleanup arg list */
return(retval);
}
#ifndef __ATH_DJGPPDOS__
/**************************************************************************
* uilog - turn on logging
*
* A user interface command which turns on logging to a fill, all of the
* information printed on screen
*
* RETURNS: 1 if file opened, 0 if not
*/
A_UINT16 uilog
(
char *filename, /* name of file to log to */
A_BOOL append
)
{
//** the following added by ccshiang
uilogClose();
//** the above added by ccshiang
/* open file for writing */
if (append) {
logFile = fopen(filename, "a+");
}
else {
logFile = fopen(filename, "w");
}
if (logFile == NULL) {
uiPrintf("Unable to open file %s\n", filename);
return(0);
}
/* set flag to say logging enabled */
logging = 1;
#ifndef MDK_AP
//turn on logging in the library
enableLogging(filename);
#endif
return(1);
}
#endif
/**************************************************************************
* uiWriteToLog - write a string to the log file
*
* A user interface command which writes a string to the log file
*
* RETURNS: 1 if sucessful, 0 if not
*/
A_UINT16 uiWriteToLog
(
char *string
)
{
if(logFile == NULL) {
uiPrintf("Error, logfile not valid, unable to write to file\n");
return 0;
}
/* write string to file */
fprintf(logFile, string);
return 1;
}
void configPrint
(
A_BOOL flag
)
{
enablePrint = flag;
}
#ifndef __ATH_DJGPPDOS__
/**************************************************************************
* uilogClose - close the logging file
*
* A user interface command which closes an already open log file
*
* RETURNS: 1 if file opened, 0 if not
*/
void uilogClose(void)
{
if ( logging ) {
fclose(logFile);
logging = 0;
//** the following added by ccshiang
logFile = NULL;
//** the above added by ccshiang
}
return;
}
/**************************************************************************
* quiet - set quiet mode on or off
*
* A user interface command which turns quiet mode on or off
*
* RETURNS: N/A
*/
DLL_EXPORT void dk_quiet
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -