⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mconfig.c

📁 atheros ar5001 5002 driver
💻 C
📖 第 1 页 / 共 5 页
字号:

	// Re-enable AGC to A2 traffic
	REGW(devNum, 0x9808, REGR(devNum, 0x9808) & (~0x08000000));
	mSleep(1);
}


/**************************************************************************
* setSingleTransmitPower - Set one pcdac value to be copied to all rates
*   with zero gain_delta.
*   Ignores power scaling but will be reset by resetDevice or changeChannel.
*
*/
MANLIB_API void setSingleTransmitPower
(
 A_UINT32 devNum, 
 A_UCHAR pcdac
)
{
    LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];

	if (checkDevNum(devNum) == FALSE) {
		mError(devNum, EINVAL, "Device Number %d:setSingleTransmitPower\n", devNum);
		return;
	}
	if (gLibInfo.pLibDevArray[devNum]->devState < RESET_STATE) {
		mError(devNum, EILSEQ, "Device Number %d:setSingleTransmitPower: Device should be out of Reset before changing transmit power\n", devNum);
		return;
	}

    ar5kInitData[pLibDev->ar5kInitIndex].pRfAPI->setSinglePower(devNum, pcdac);

}


/**************************************************************************
* devSleep - Put the device to sleep for sleep power measurements
*
*/
MANLIB_API void devSleep
(
 A_UINT32 devNum
)
{

	if (checkDevNum(devNum) == FALSE) {
		mError(devNum, EINVAL, "Device Number %d:devSleep\n", devNum);
		return;
	}
	if (gLibInfo.pLibDevArray[devNum]->devState < RESET_STATE) {
		mError(devNum, EILSEQ, "Device Number %d:devSleep: Device should be out of Reset before entering sleep\n", devNum);
		return;
	}

#ifdef MDK_AP
	mError(devNum, EINVAL, "Device Number %d:devSleep: AP cannot go to sleep \n", devNum);
#else
	REGW(devNum, F2_SFR, F2_SFR_SLEEP);
#endif
}

MANLIB_API A_UINT32 checkProm
(
 A_UINT32 devNum,
 A_UINT32 enablePrint
)
{
    LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];

	if (checkDevNum(devNum) == FALSE) {
		mError(devNum, EINVAL, "Device Number %d:printProm\n", devNum);
		return 1;
	}
	if (gLibInfo.pLibDevArray[devNum]->devState < RESET_STATE) {
		mError(devNum, EILSEQ, "Device Number %d:printProm: Device should be out of Reset before checking the EEPROM\n", devNum);
		return 1;
	}

	//check that the info fromt the eeprom is valid
	if(!pLibDev->eepData.infoValid) {
		//mError(EILSEQ, "Device Number %d:checkProm: eeprom info is not valid\n", devNum);
		return 1;
	}
    if(((pLibDev->eepData.version >> 12) & 0xF) == 1) {
#ifndef __ATH_DJGPPDOS__
		check5210Prom(devNum, enablePrint);
#endif
	}
    else if(((pLibDev->eepData.version >> 12) & 0xF) >= 3) {
		
	}
	else{	
		mError(devNum, EIO, "Device Number %d:checkProm: Wrong PROM Version to print\n", devNum);
        return 1;
    }

	return 0;
}


/**************************************************************************
* setupEEPromMap - Read the EEPROM and setup the structure
*
* Returns: TRUE if the EEPROM is calibrated, else FALSE
*/
A_BOOL setupEEPromMap
(
 A_UINT32 devNum
)
{
    LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
    A_UINT32     pciReg;

    // Only check the EEPROM once
    if(pLibDev->eepData.eepromChecked == TRUE) {
        return pLibDev->eepData.infoValid;
    }
    else  // This code will only be run the first time this function is called
    {
		// Setup the PCI Config space for correct card access on the first reset
		// Setup memory window, bus mastering, & SERR
		pciReg = pLibDev->devMap.OScfgRead(devNum, F2_PCI_CMD);
		pciReg |= (MEM_ACCESS_ENABLE | MASTER_ENABLE | SYSTEMERROR_ENABLE); 
		pciReg &= ~MEM_WRITE_INVALIDATE; // Disable write & invalidate for our device
		pLibDev->devMap.OScfgWrite(devNum, F2_PCI_CMD, pciReg);

		pciReg = pLibDev->devMap.OScfgRead(devNum, F2_PCI_CACHELINESIZE);
		//changed this to not write the cacheline size, only want to write the latency timer
		pciReg = (pciReg & 0xffff00ff) | (0x40 << 8);
		pLibDev->devMap.OScfgWrite(devNum, F2_PCI_CACHELINESIZE, pciReg);

        pLibDev->eepData.version = (A_UINT16) eepromRead(devNum, (ATHEROS_EEPROM_OFFSET + 1));
        pLibDev->eepData.protect = (A_UINT16) eepromRead(devNum, (EEPROM_PROTECT_OFFSET));

        if(((pLibDev->eepData.version >> 12) & 0xF) < 2) {
#ifndef __ATH_DJGPPDOS__
			read5210eepData(devNum);			
#endif
		}

        else if(((pLibDev->eepData.version >> 12) & 0xF) == 2) {
			mError(devNum, EIO, "Device Number %d:Version 2 EEPROM not supported \n", devNum);
		} else if ((((pLibDev->eepData.version >> 12) & 0xF) == 3) || (((pLibDev->eepData.version >> 12) & 0xF) == 4)) {
			if(!readEEPData_16K(devNum)) {
				mError(devNum, EIO, "Device Number %d:Unable to read 16K eeprom info\n", devNum);
				pLibDev->eepData.eepromChecked = TRUE;
				pLibDev->eepData.infoValid = FALSE;
				return FALSE;
			}
			if(((pLibDev->eepData.version >> 12) & 0xF) == 4) {
				//read the EAR
				if(!readEar(devNum, pLibDev->p16kEepHeader->earStartLocation)) {
					mError(devNum, EIO, "Unable to read EAR information from EEPROM\n");
					pLibDev->eepData.eepromChecked = TRUE;
					pLibDev->eepData.infoValid = FALSE;
					return FALSE;
				}
			}
			pLibDev->eepromHeaderChecked = TRUE;
		}


		else {
			mError(devNum, EIO, "Device Number %d:setupEEPromMap: Invalid version found: 0x%04X\n", devNum, pLibDev->eepData.version);
			pLibDev->eepData.eepromChecked = TRUE;
			pLibDev->eepData.infoValid = FALSE;
			return FALSE;
		}		
        pLibDev->eepData.infoValid = TRUE;
        pLibDev->eepData.eepromChecked = TRUE;
        return TRUE;
    }
}

#ifdef HEADER_LOAD_SCHEME
A_BOOL setupEEPromHeaderMap
(
 A_UINT32 devNum
)
{
    LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];

    // Only check the EEPROM once
    if(pLibDev->eepromHeaderChecked == TRUE) {
        return TRUE;
    }

    allocateEepStructs(devNum);
	pLibDev->eepData.version = (A_UINT16) eepromRead(devNum, (ATHEROS_EEPROM_OFFSET + 1));
	if (((pLibDev->eepData.version >> 12) & 0xF) == 3) {
		readHeaderInfo(devNum, pLibDev->p16kEepHeader);
		pLibDev->eepromHeaderChecked = TRUE;
		return TRUE;
	}
	return FALSE;
}
#endif //HEADER_LOAD_SCHEME

void initializeTransmitPower
(
	A_UINT32 devNum,
	A_UINT32 freq,
	A_INT32  override,
	A_UCHAR  *pwrSettings
)
{
    LIB_DEV_INFO *pLibDev = gLibInfo.pLibDevArray[devNum];
	A_UINT32 i = pLibDev->ar5kInitIndex;


	if (ar5kInitData[i].pRfAPI->setPower == NULL)
	{
		return;
	}

	ar5kInitData[i].pRfAPI->setPower(devNum, freq, override, pwrSettings);
	return;
}




/**************************************************************************
* checkDevNum - Makes sure the device is initialized before using
*
* RETURNS: FALSE if device not yet initialized - else TRUE
*/
A_BOOL checkDevNum
(
 A_UINT32 devNum
) 
{
	if(gLibInfo.pLibDevArray[devNum] == NULL) {
#ifndef NO_LIB_PRINT
		printf("Device Number %d:DevNum not initialized for function: ", devNum);
#endif
		return FALSE;
	}
	return TRUE;
}

/**************************************************************************
* reverseBits - Reverses bit_count bits in val
*
* RETURNS: Bit reversed value
*/
A_UINT32 reverseBits
(
 A_UINT32 val, 
 int bit_count
)
{
	A_UINT32	retval = 0;
	A_UINT32	bit;
	int			i;

	for (i = 0; i < bit_count; i++)
	{
		bit = (val >> i) & 1;
		retval = (retval << 1) | bit;
	}
	return retval;
}

/**************************************************************************
* mError - output error messages
*
* 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
*/
int mError
(
	A_UINT32 devNum,
	A_UINT32 error,
    const char * format,
    ...
)
{

    LIB_DEV_INFO *pLibDev;
    va_list argList;
    int retval = 0;
#ifndef NO_LIB_PRINT
    char    buffer[256];
#endif

    /*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
     */
#ifndef NO_LIB_PRINT
    printf("%s : ", strerror(error));
    retval = vprintf(format, argList);
    fflush(stdout);

#ifndef MDK_AP
#ifndef __ATH_DJGPPDOS__
    if (logging) {
		vsprintf(buffer, format, argList);
        fputs(buffer, logFileHandle);
		fflush(logFileHandle);
    }
#endif //__ATH_DJGPPDOS__
#endif //MDK_AP
#endif //NO_LIB_PRINT


	if(devNum != 0xdead) {
	    //take a copy of the error buffer
		pLibDev = gLibInfo.pLibDevArray[devNum];
		vsprintf(pLibDev->mdkErrStr, format, argList);
		pLibDev->mdkErrno = error;
	}
	else {
		//this is a special case where initializeDevice failed,
		//before a devNum could be assigned, store these in static variables
		vsprintf(tempMDKErrStr, format, argList);
		tempMDKErrno = error;

	}
    va_end(argList);    /* cleanup arg list */

    return(retval);
}

/**************************************************************************
* getMdkErrStr - Get last error string
*
* This routine should only be called if mdkErrno is set.  It will copy
* the last error string into the callers buffer.  Callers buffer should
* be at least SIZE_ERROR_BUFFER bytes
*
* RETURNS: same as printf.  Number of characters printed
*/
MANLIB_API void getMdkErrStr
(	
  	A_UINT32 devNum,
    A_CHAR *pBuffer		//pointer to called allocated memory 
)
{
    LIB_DEV_INFO *pLibDev;
	char *pErrString;

	if(devNum == 0xdead) {
		pErrString = tempMDKErrStr;
	}
	else {
		pLibDev = gLibInfo.pLibDevArray[devNum];
		pErrString = pLibDev->mdkErrStr;
	}
	strncpy(pBuffer, pErrString, SIZE_ERROR_BUFFER-1);
	return;
}

/**************************************************************************
* getLastErrorNo - get the last error number
*
* Returns : mdkErrno
*/
MANLIB_API A_INT32 getMdkErrNo
(
	A_UINT32 devNum
)
{
    LIB_DEV_INFO *pLibDev;
	A_INT32 returnValue;

	if(devNum == 0xdead) {
		returnValue = tempMDKErrno;
		tempMDKErrno = 0;
	}
	else {
		pLibDev = gLibInfo.pLibDevArray[devNum];
		returnValue = pLibDev->mdkErrno;
		pLibDev->mdkErrno = 0;
	}
	return returnValue;
}

#ifndef MDK_AP
/**************************************************************************
* enableLogging - enable logging of any lib messages to file 
*
*  
*
*/
MANLIB_API void enableLogging
(
 A_CHAR *pFilename
)
{
	logging = 1;

	logFileHandle = fopen(pFilename, "a+");

    if (logFileHandle == NULL) {
        printf( "Unable to open file for logging within library%s\n", pFilename);
		logging = 0;
    }
}

/**************************************************************************
* disableLogging - turn off logging flag
*
*
*/
MANLIB_API void disableLogging(void)
{
	logging = 0;
	fclose(logFileHandle);
	logFileHandle = NULL;
}
#endif

MANLIB_API void devlibCleanup()
{
	A_UINT32 i;

	// cleanup all the devInfo structures
    	for ( i = 0; i < LIB_MAX_DEV; i++ ) {
        	if ( gLibInfo.pLibDevArray[i] ) {
				closeDevice(i);
	    		gLibInfo.pLibDevArray[i] = NULL;        
        	}
	}
   
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -