📄 usbuhcdsupport.c
字号:
/* usbUhcdSupport.c - USB UHCD HCD register access routines *//* Copyright 2004-2005 Wind River Systems, Inc. This software includes software licensed to Wind River Systems, Inc. by Wipro, Ltd. Wind River licensees may use this software according to the terms of their Wind River license agreement(s) applicable to this software.*//*Modification history--------------------01h,28mar05,pdg non-PCI changes01g,15oct04,ami Refgen Changes01f,11oct04,ami Apigen Changes01e,07oct04,mta Review comment changes01d,05oct04,mta SPR100704- Removal of floating point math01c,28jul03,mat Endian related changes01b,26jun03,mat changing the code to WRS standards.01a,25apr03,ram written.*//*DESCRIPTIONThis file contains the fucntions which would be used to access various register/sub-fields of the UHCD.INCLUDE FILES: usb2/usbOsal.h, usb2/usbHst.h, usb2/usbUhci.h,usb2/usbUhcdScheduleQueue.h, usb2/usbUhcdSupport.h,usb2/usbUhcdCommon.h, usb2/usbUhcdScheduleQueue.h*//*INTERNAL ******************************************************************************* * Filename : usbUhcdSupport.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * * Description : This file contains the fucntions which would * be used to access various register/sub-fields of the UHCD. * * ******************************************************************************//* includes */#include "usb2/usbOsal.h"#include "usb2/usbHst.h"#include "usb2/usbUhci.h"#include "usb2/usbUhcdScheduleQueue.h"#include "usb2/usbUhcdSupport.h"#include "usb2/usbUhcdCommon.h"#include "usb2/usbUhcdScheduleQueue.h"/* forward declarations *//***************************************************************************** usbUhcdWriteReg - write a value to the UHCD's register.** This routine writes a value to the UHCD's register.** RETURNS: void** ERRNO:* None.** \NOMANUAL*/void usbUhcdWriteReg ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset, UINT16 valueToWrite ) { /* To hold the value of the register */ UINT16 sReg= 0; OS_LOG_MESSAGE_LOW(UHCD,"Entering usbUhcdWriteReg\n",0,0,0,0); /* Read the word from the register at the offset mentioned */ sReg = USB_UHCD_READ_WORD( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Update the value which is to be written */ sReg = sReg | valueToWrite; /* Write the value to the register */ USB_UHCD_WRITE_WORD(pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset, sReg); OS_LOG_MESSAGE_LOW(UHCD,"Exiting usbUhcdWriteReg\n",0,0,0,0); return; }/* End of usbUhcdWriteReg *//***************************************************************************** usbUhcdReadReg - read a value from the UHCD's register.** This routine reads a value from the UHCD's register.** RETURNS: sReadValue** ERRNO:* None.** \NOMANUAL*/INT16 usbUhcdReadReg ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset ) { /* To hold the value of the register */ UINT16 sReadValue= 0; OS_LOG_MESSAGE_LOW(UHCD,"Entering usbUhcdReadReg\n",0,0,0,0); /* Read the word from the register at the offset mentioned */ sReadValue = USB_UHCD_READ_WORD( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); OS_LOG_MESSAGE_LOW(UHCD,"Exiting usbUhcdReadReg\n",0,0,0,0); return sReadValue; }/* End of usbUhcdReadReg *//***************************************************************************** usbUhcdRegxSetBit - sets a bit of the UHCD's register** This routine sets a bit of the UHCD's register.** RETURNS: N/A** ERRNO:* None.** \NOMANUAL*/void usbUhcdRegxSetBit ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset, UINT8 setBit ) { /* To hold the value of the register */ UINT16 regx = 0; OS_LOG_MESSAGE_LOW(UHCD,"Entering usbUhcdRegxSetBit()\n",0,0,0,0); /* Read the word from the register at the offset mentioned */ regx = USB_UHCD_READ_WORD ( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Update the value which is to be written */ regx = regx | ( 1 << setBit ); /* Write the value to the register */ USB_UHCD_WRITE_WORD (pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset, regx); OS_LOG_MESSAGE_LOW(UHCD,"Exiting usbUhcdRegxSetBit()\n",0,0,0,0); }/* End of usbUhcdRegxSetBit() *//***************************************************************************** usbUhcdRegxClearBit - clears a bit of the UHCD's register** This routine clears a bit of the UHCD's register.** RETURNS: N/A** ERRNO:* None.** \NOMANUAL*/void usbUhcdRegxClearBit ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset, UINT8 clearBit ) { /* To hold the value of the register */ UINT16 regx = 0; OS_LOG_MESSAGE_LOW(UHCD,"Entering usbUhcdRegxClearBit()\n",0,0,0,0); /* Read the word from the register at the offset mentioned */ regx = USB_UHCD_READ_WORD ( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Update the value which is to be written */ regx = regx & ~( 1 << clearBit ); /* Write the value to the register */ USB_UHCD_WRITE_WORD (pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset, regx); OS_LOG_MESSAGE_LOW(UHCD,"Exiting usbUhcdRegxClearBit()\n",0,0,0,0); }/* End of usbUhcdRegxClearBit() *//***************************************************************************** usbUhcdPortSetBit - sets a bit of the UHCD's port register** This function is used to set a bit of the UHCD's port regsiter** RETURNS: N/A** ERRNO:* None.** \NOMANUAL*/void usbUhcdPortSetBit(PUHCD_DATA pHCDData,UINT8 usbUhcdRegBaseOffset,UINT8 setBit) { /* To hold the value of the register */ UINT16 regx = 0; OS_LOG_MESSAGE_LOW(UHCD,"Entering usbUhcdPortSetBit()\n",0,0,0,0); /* Read the word from the register at the offset mentioned */ regx = USB_UHCD_READ_WORD ( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Update the value which is to be written */ regx = (regx & 0xFFF5) | ( 1 << setBit ); /* Write the value to the register */ USB_UHCD_WRITE_WORD (pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset, regx); OS_LOG_MESSAGE_LOW(UHCD,"Exiting usbUhcdPortSetBit()\n",0,0,0,0); }/* End of usbUhcdPortSetBit() *//***************************************************************************** usbUhcdPortClearBit - clears a bit of the UHCD's port register** This routine sets a bit of the UHCD's port register.** RETURNS: N/A** ERRNO:* None.** \NOMANUAL*/void usbUhcdPortClearBit ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset, UINT8 clearBit ) { /* To hold the value of the register */ UINT16 regx = 0; /* Read the word from the register at the offset mentioned */ regx = USB_UHCD_READ_WORD ( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Mask the specific fields so that clearing is not a problem */ regx &= 0xFFF5; OS_LOG_MESSAGE_LOW(UHCD,"Entering usbUhcdPortClearBit()\n",0,0,0,0); /* Bits 1 and 3 can be cleared by writing a 1 */ if ( clearBit == 1 || clearBit == 3) { regx |= (1 << clearBit); } /* The remaining bits will be cleared by writing 0 */ else { regx = regx & ~( 1 << clearBit ); } /* Write the value to the register */ USB_UHCD_WRITE_WORD( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset, regx); OS_LOG_MESSAGE_LOW(UHCD,"Exiting usbUhcdPortClearBit()\n",0,0,0,0); }/* End of usbUhcdPortClearBit() *//***************************************************************************** usbUhcdIsBitSet - check whether a bit is set of the UHCD's register** This routine checks whether a bit is set of the UHCD's register.** RETURNS: TRUE, FALSE if bit is not set** ERRNO:* None.** \NOMANUAL*/BOOLEAN usbUhcdIsBitSet ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset, UINT8 whichBit ) { /* To hold the value of the register */ UINT16 regx = 0; /* Read the word from the register at the offset mentioned */ regx = USB_UHCD_READ_WORD( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Return the value of the bit in the specified bit position */ return( ((regx >> whichBit) & 0x01) == 1 ); }/* End of usbUhcdIsBitSet() *//***************************************************************************** usbUhcdIsBitReset - check whether a bit is reset of the UHCD's register** This routine checks whether a bit is reset of the UHCD's register.** RETURNS: TRUE, FALSE if bit is not reset** ERRNO:* None.** \NOMANUAL*/BOOLEAN usbUhcdIsBitReset ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset, UINT8 whichBit ) { /* To hold the value of the register */ UINT16 regx = 0; OS_LOG_MESSAGE_LOW(UHCD,"usbUhcdIsBitReset() is entered\n",0,0,0,0); /* Read the word from the register at the offset mentioned */ regx = USB_UHCD_READ_WORD( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Return the value of the bit in the specified bit position */ return( ((regx >> whichBit) & 0x01) == 0 ); }/* End of usbUhcdIsBitReset) *//***************************************************************************** usbUhcdGetBit - get the bit value of the of the UHCD's register** This routine gets the bit value of the of the UHCD's register.** RETURNS: UINT8, the value of the register** ERRNO:* None.** \NOMANUAL*/UINT8 usbUhcdGetBit ( PUHCD_DATA pHCDData, UINT8 usbUhcdRegBaseOffset, UINT8 whichBit ) { /* To hold the value of the register */ UINT16 regx = 0; OS_LOG_MESSAGE_LOW(UHCD,"usbUhcdGetBit() entered\n",0,0,0,0); /* Read the word from the register at the offset mentioned */ regx = USB_UHCD_READ_WORD( pHCDData->usbUhcdUsbBase + usbUhcdRegBaseOffset); /* Return the value of the bit in the specified bit position */ return( ((regx >> whichBit) & 0x01) ); }/* End of usbUhcdGetBit() *//***************************************************************************** usbUhcdHcReset - resets the HC** This routine resets the HC.** RETURNS: N/A** ERRNO:* None.** \NOMANUAL*/void usbUhcdHcReset ( PUHCD_DATA pHCDData ) { /* To hold the wait count */ UINT32 wait_count = 0; OS_LOG_MESSAGE_LOW(UHCD,"Entering usbUhcdHcReset()\n",0,0,0,0); /* Set bit 1 in USBCMD register to reset the HC */ usbUhcdRegxSetBit (pHCDData, USB_UHCD_USBCMD, 1); /* Wait for reset to complete */ for (wait_count = 0; wait_count < USB_UHCD_NUM_OF_RETRIES && usbUhcdIsBitSet (pHCDData, USB_UHCD_USBCMD, 1); wait_count++); /* Check if reset was not successful */ if (wait_count == USB_UHCD_NUM_OF_RETRIES ) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to reset UHC\n",0,0,0,0); return; } OS_LOG_MESSAGE_LOW(UHCD,"Exiting UHCD_hcreset()\n",0,0,0,0); }/* End of usbUhcdHcReset() *//***************************************************************************** usbUhciDelay - resets the HC** Sends a reset signal to the Host Controller ** RETURNS: N/A** ERRNO:* None.** \NOMANUAL*/void usbUhciDelay ( PUHCD_DATA pHCDData, UINT16 uDelay ) { /* To hold the frame number */ UINT16 uFrameNumber, uCurrentFrameNumber; /* Compute the current delay */ UINT16 uCurrentDelay = 0; /* Read the SOF before giving a reset */ uFrameNumber = USB_UHCD_READ_WORD( pHCDData->usbUhcdUsbBase + USB_UHCD_FRNUM) & 0x3FF ; /* Initialise Current frmae number to frame number */ uCurrentFrameNumber = uFrameNumber; /* Wait till the delay is reached */ while (uCurrentDelay < uDelay) { /* Read the current frame number */ uCurrentFrameNumber = USB_UHCD_READ_WORD( pHCDData->usbUhcdUsbBase + USB_UHCD_FRNUM) & 0x3FF; /* Compute the current delay */ if (uCurrentFrameNumber >= uFrameNumber) { uCurrentDelay = uCurrentFrameNumber - uFrameNumber; } else { uCurrentDelay = 1023 - uFrameNumber + uCurrentFrameNumber; } } return;}/***************************************************************************** usbUhciLog2 - Function to return log to the base 2** Returns the log value to the base 2** RETURNS: UINT32 , log value to the base 2** ERRNO:* None.** \NOMANUAL*/UINT32 usbUhciLog2 ( UINT32 value ) { int i=0; UINT32 tempElement = value; for (i=0; i<32; i++) { if (tempElement==0) break; tempElement = (tempElement>>1); } if(i) return (i -1) ; else return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -