📄 usbh_usbds_api.c
字号:
}
}
/*=============================================================================================
// Function_Name: USBH_USBDS_AddListDev
//
// description : Append newly to the end of URB device information structure list.
//
// argument : void
//
// return : USBH_USBD_DEVLIST_HEAD * NULL = fail to secure, others = area address secured ( out )
===============================================================================================*/
STATIC_T USBH_USBD_DEVLIST_HEAD * USBH_USBDS_AddListDev( void )
{
USBH_USBD_DEVLIST_HEAD *Devtmp, *wUsbDevL=NULL;
UCHAR i;
/*
Only the list may remain, in the case that it was mutilated during joint.
The list like that deletes it here.
*/
for(i=0; i<USBH_USBD_DEVICE_MAX; i++) {
if(DeviceListTbl[i].Enable == USBD_ENABLE) {
if(DeviceListTbl[i].DeviceList.sUsbDev.devNum == 0) {
DeviceListTbl[i].Enable = USBD_DISABLE;
DeviceListTbl[i].DeviceList.psPrev->psNext = DeviceListTbl[i].DeviceList.psNext;
if(DeviceListTbl[i].DeviceList.psNext != NULL) {
DeviceListTbl[i].DeviceList.psNext->psPrev = DeviceListTbl[i].DeviceList.psPrev;
}
memset(wUsbDevL, 0, sizeof(USBH_USBD_DEVLIST_HEAD));
DeviceCtlTbl.DevCount--;
}
}
}
/* Area securing */
for(i=0; i<USBH_USBD_DEVICE_MAX; i++) {
if(DeviceListTbl[i].Enable == USBD_DISABLE) {
wUsbDevL = &DeviceListTbl[i].DeviceList;
DeviceListTbl[i].Enable = USBD_ENABLE;
break;
}
}
memset(wUsbDevL, 0, sizeof(USBH_USBD_DEVLIST_HEAD));
if(DeviceCtlTbl.DevInfo == NULL) {
DeviceCtlTbl.DevInfo = wUsbDevL;
} else {
Devtmp = (USBH_USBD_DEVLIST_HEAD *)&DeviceCtlTbl.DevInfo;
while(Devtmp->psNext != NULL) {
Devtmp = Devtmp->psNext;
}
wUsbDevL->psNext = Devtmp->psNext;
Devtmp->psNext = (USBH_USBD_DEVLIST_HEAD *) wUsbDevL ;
wUsbDevL->psPrev = Devtmp;
}
DeviceCtlTbl.DevCount++;
wUsbDevL->sUsbDev.eState = USBH_USBD_USB_STATE_NOTATTACHED;
wUsbDevL->sUsbDev.eSpeed = USBH_USBD_USB_SPEED_UNKNOWN;
return wUsbDevL;
}
/*=============================================================================================
// Function_Name: USBH_USBDS_DelListDev
//
// description : Free URB device information structure list.
//
// argument USBH_USBD_USBDEV * Area to be free ( in )
//
// return : USBH_USBD_STATUS_SUCCESS Freeing finish normally
// : USBH_USBD_STATUS_UNSUCCESSFUL Table to be freed is already freed
===============================================================================================*/
STATIC_T long USBH_USBDS_DelListDev( USBH_USBD_USBDEV *wUsbDevL )
{
USBH_USBD_DEVLIST_HEAD *Devtmp;
UCHAR i;
/* Delete all URB of device to be deleted */
for(i=0; i<USBH_USBD_URB_MAX; i++) {
if(UrbListTbl[i].Urb_List.psDev == wUsbDevL) {
UrbListTbl[i].Enable = USBD_DISABLE;
}
}
Devtmp = (USBH_USBD_DEVLIST_HEAD *)DeviceCtlTbl.DevInfo;
if( DeviceCtlTbl.DevInfo->psNext != NULL ){
while( Devtmp != NULL ){
if(wUsbDevL == &Devtmp->sUsbDev) {
if(Devtmp->psNext == NULL ){
/* There is no list behind */
Devtmp->psPrev->psNext = NULL;
} else {
/* There is a list behind */
Devtmp->psPrev->psNext = Devtmp->psNext;
Devtmp->psNext->psPrev = Devtmp->psPrev;
}
Devtmp->psPrev = NULL;
Devtmp->psNext = NULL;
DeviceCtlTbl.DevCount--;
break;
}
Devtmp = Devtmp->psNext;
}
} else {
DeviceCtlTbl.DevInfo = NULL;
DeviceCtlTbl.DevCount = 0;
}
/* Disable device */
for(i=0; i<USBH_USBD_DEVICE_MAX; i++) {
if(wUsbDevL == &DeviceListTbl[i].DeviceList.sUsbDev) {
DeviceListTbl[i].Enable = USBD_DISABLE;
DeviceListTbl[i].DeviceList.sUsbDev.devNum = 0;
break;
}
}
if(i == USBH_USBD_DEVICE_MAX) {
return USBH_USBD_STATUS_UNSUCCESSFUL;
}
return USBH_USBD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_USBDS_SearchDev
//
// description : Search URB device information structure agreed with device address from URB device information structure list.
//
// argument : devaddr Device address ( in )
// : *retValue (out)USBH_USBD_STATUS_SUCCESS Searching successed
// STATUS_NO_EXISTENCE_PORT no correspondence
//
// return : USBH_USBD_USBDEV * Searching successed = device information address, No correspondence = NULL
===============================================================================================*/
USBH_USBD_USBDEV * USBH_USBDS_SearchDev( UCHAR devaddr, long *retValue )
{
USBH_USBD_DEVLIST_HEAD *UsbDevListWK;
if(devaddr == ROOTHUB_ADDR) {
return &RootHubDev.sUsbDev ;
} else {
UsbDevListWK = (USBH_USBD_DEVLIST_HEAD *)DeviceCtlTbl.DevInfo;
if(UsbDevListWK == NULL) {
return NULL;
}
*retValue = USBH_USBD_STATUS_SUCCESS ;
while( UsbDevListWK->sUsbDev.devNum != devaddr ) {
if( UsbDevListWK->psNext == NULL ) {
*retValue = STATUS_NO_EXISTENCE_PORT ;
return NULL;
}
UsbDevListWK = UsbDevListWK->psNext ;
}
return &UsbDevListWK->sUsbDev ;
}
}
/*=============================================================================================
// Function_Name: USBH_USBDS_SearchDevList
//
// description : Search device information list agreed from URB device information.
//
// argument : *wUsbDev URB Device information ( in )
//
// return : USBH_USBD_STATUS_SUCCESS Device list being successed for searching
// : NULL No device information for searching object
===============================================================================================*/
STATIC_T USBH_USBD_DEVLIST_HEAD * USBH_USBDS_SearchDevList( USBH_USBD_USBDEV *wUsbDev )
{
USBH_USBD_DEVLIST_HEAD *UsbDevListWK;
if(wUsbDev == &RootHubDev.sUsbDev) {
UsbDevListWK = (USBH_USBD_DEVLIST_HEAD *)&RootHubDev;
} else {
UsbDevListWK = (USBH_USBD_DEVLIST_HEAD *)DeviceCtlTbl.DevInfo;
if(UsbDevListWK == NULL) {
return NULL;
}
while( &UsbDevListWK->sUsbDev != wUsbDev ) {
if( UsbDevListWK->psNext == NULL ) {
return NULL ;
}
UsbDevListWK = UsbDevListWK->psNext ;
}
}
return UsbDevListWK ;
}
/*=============================================================================================
// Function_Name: USBH_USBDS_AddURBList
//
// description : Get URB and add to list.
//
// argument : void
//
// return : USBH_USBD_URB * URB structure got
// : USBH_USBD_STATUS_UNSUCCESSFUL Fail to get
===============================================================================================*/
STATIC_T USBH_USBD_URB * USBH_USBDS_AddURBList( void )
{
USBH_USBD_URB *psURB=0;
UCHAR i;
if( OS_SnsCtx() != TRUE ){
OS_LocCpu();
}
/* Area securing */
for(i=0; i<USBH_USBD_URB_MAX; i++) {
if(UrbListTbl[i].Enable == USBD_DISABLE) {
psURB = (USBH_USBD_URB *)&UrbListTbl[i].Urb_List;
UrbListTbl[i].Enable = USBD_ENABLE;
break;
}
}
if(i < USBH_USBD_URB_MAX) {
memset(psURB, 0, sizeof(USBH_USBD_URB));
psURB->pSetupPacket = (UCHAR *)&setupDataTbl[i];
} else {
psURB = (USBH_USBD_URB *)USBH_USBD_STATUS_UNSUCCESSFUL;
}
if( OS_SnsCtx() != TRUE ){
OS_UnlCpu();
}
return psURB;
}
/*=============================================================================================
// Function_Name: USBH_USBDS_DelListURB
//
// description : Free specified URB and delete from list.
//
// argument : *psURB URB structure to delete ( in )
//
// return : USBH_USBD_STATUS_SUCCESS Deleting success
// : USBH_USBD_STATUS_UNSUCCESSFUL Deleting failure
===============================================================================================*/
STATIC_T long USBH_USBDS_DelListURB( USBH_USBD_URB *psURB )
{
UCHAR i;
long ret;
if( OS_SnsCtx() != TRUE ){
OS_LocCpu();
}
/* Free URB management area */
for(i=0; i<USBH_USBD_URB_MAX; i++) {
if(&UrbListTbl[i].Urb_List == psURB) {
if(UrbListTbl[i].Enable == USBD_ENABLE) {
UrbListTbl[i].Enable = USBD_DISABLE;
break;
}
}
}
if( i < USBH_USBD_URB_MAX ) {
ret = USBH_USBD_STATUS_SUCCESS;
} else {
ret = USBH_USBD_STATUS_UNSUCCESSFUL;
}
if( OS_SnsCtx() != TRUE ){
OS_UnlCpu();
}
return ret;
}
/*=============================================================================================
// Function_Name: USBH_USBDS_Init
//
// description : Initialize this module.
//
// Carry out securing of necessary memory area and initialization of HCD and reset,
// Initialization of each function block.
//
// argument : pfnCallback Pointer to call back function to notify completion ( in )
//
// return : USBH_USBD_STATUS_SUCCESS Process finish normally
// USBH_USBD_STATUS_NO_DEVICE Host Controller is not found
// USBH_USBD_STATUS_MEM_ERROR Can't secure memory area
===============================================================================================*/
long USBH_USBDS_Init( USBH_USBD_CALLBACK pfnCallback, UCHAR sw )
{
pfnInit.Callback = pfnCallback;
usbdInitialize = 1;
portPowerDo = 0;
hubStart = 0;
portPowerNum = 0;
connectWaitCount = 0;
SavhubStat = DelhubStat = 0;
// Hub management initialization
// Device management initialization
USBH_USBD_Mode = USBH_USBD_MODE_INIT;
/* Device management table */
memset(&RootHubDev, 0, sizeof(USBH_USBD_DEVLIST_HEAD));
DeviceCtlTbl.DevCount = 0;
DeviceCtlTbl.DevInfo = NULL;
memset(DeviceListTbl, 0, sizeof(USBH_USBD_DEVLIST_TBL)*USBH_USBD_DEVICE_MAX);
/* Interface information table initialization */
memset(IfListTbl, 0, sizeof(USBH_USBD_IF_CTBL)*USBH_USBD_IF_CTBL_MAX);
/* Endpoint information table initialization */
memset(EpListTbl, 0, sizeof(USBH_USBD_EP_CTBL)*USBH_USBD_EP_CTBL_MAX);
/* When RootHub Reset, the initializationof class driver is not performed */
if(sw == 0) {
// Class driver information
memset(&ClassINFO, 0, sizeof(USBH_USBD_ClssDriverINFO)*USBH_USBD_CLASSDRIVERNUM);
ClassINFONum = 0;
}
// URB management initalization
memset(UrbListTbl, 0, sizeof(USBH_USBD_URB_TBL)*USBH_USBD_URB_MAX);
// Connected device information
// URBHeader = NULL ; /* URB structure initialization */
// Power management initalization
/* HCD initialization USBH_USBDS_HCDCallbackProc *pfnCallback */
pfnInit.retValue = USBH_HCD_Init(USBH_USBDS_HCDCallbackProc);
return pfnInit.retValue;
}
/*=============================================================================================
// Function_Name: USBH_USBDS_Cleanup
//
// description : The HostStack operation is stopped.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -