📄 usbh_hcd_api.c
字号:
/*
* description : USBH HCD APIs(global)
* Maker : Hiromichi Kondo
* Copyright : (C)2005,SEIKO EPSON Corp. All Rights Reserved.
*/
#include <string.h> /* memset */
#include <SPRSTS.h>
#include <SPRDEF.h>
#include <usbh_hcd.h>
#include <usbh_hcds_vhub.h>
#include <usbh_hcds_channel.h>
#include <usbh_hcds_fifo.h>
#include <usbh_hcds_72V05.h>
#include <usbh_hcds_urb.h>
#include <usbh_hcds_port.h>
#include <Reg72V05.h>
/*****************************************
* Define
*****************************************/
/*****************************************
* Struct definition
*****************************************/
/*****************************************
* Function prototype declaration
*****************************************/
static long HCDS_InitCallback( unsigned long event, unsigned long param1, void *pParam );
static long HCDS_PortStatusChangedCallback(unsigned long portState, unsigned long portSpeed, void *pParam);
static long HCDS_HCResumeCmpCallback(unsigned long param0, unsigned long param1, void *pParam);
static long HCDS_DetDevConnectCallback(unsigned long param0, unsigned long param1, void *pParam);
void HCDS_ExecCallback(USBH_HCD_CALLBACK pfnFunc, unsigned long param0, unsigned long param1, void *pParam);
/*****************************************
* Macro definition
*****************************************/
/*****************************************
* Variable definition
*****************************************/
#ifdef DEBUG_C
HCD_MANAGER HCDStatus;
#else /* #ifdef DEBUG_C */
static HCD_MANAGER HCDStatus;
#endif /* #ifdef DEBUG_C */
/*=============================================================================================
// Function_Name: USBH_HCD_Init
//
// description : Initialize this module.
//
// Allocate the necessary memory used for this module, and confirm Host Controller, do reset,
// and initialize each functional block.
//
// argument : *pfnCallback (in)Pointer of callback function that is called when completed
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully.
// USBH_HCD_STATUS_NO_DEVICE Host Controller is not found
// USBH_HCD_STATUS_MEM_ERROR Failed to allocate memory area
===============================================================================================*/
long USBH_HCD_Init( USBH_HCD_CALLBACK pfnCallback )
{
memset(&HCDStatus, 0, sizeof(HCDStatus));
USBH_HCDS_HCReset(); /* Reset the Host Controller */
if( USBH_HCDS_HCDetect() == STATUS_NO_DEVICE ){
/* Host Controller doesn't exist */
return USBH_HCD_STATUS_NO_DEVICE;
}
USBH_HCDS_URBInit(); /* Initialize the URB control */
USBH_HCDS_VHUBInit(); /* Initialize the virtual route hub */
USBH_HCDS_CHInit(); /* Initialize the channel control */
USBH_HCDS_FIFOInit(); /* Initialize the FIFO control */
USBH_HCDS_PortInit(); /* Initialize the Port control */
HCDStatus.pfnInitCallback = pfnCallback;
// Can not do GoActHost when it is in 1 port operation
if( (RegRead(REG08_ClkSelect) & MASK_Port1x2 ) == BIT_Port1x2_1Port ) {
USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_ACTDEVICE, HCDS_InitCallback);
} else {
USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_ACTHOST, HCDS_InitCallback);
}
return USBH_HCD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_HCD_Cleanup
//
// description : Restore this module back to the state before initialization.
//
// The power supplied to VBUS of the route hub port is stopped,
// and the memory area allocated by this module is released.
//
// argument : None
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully
// USBH_HCD_STATUS_UNSUCCESSFUL Host Controller is suspending
===============================================================================================*/
long USBH_HCD_Cleanup( void )
{
if( HCDStatus.bmFlags.hcSuspend == 1 ){
/* Host Controller is suspending */
return USBH_HCD_STATUS_UNSUCCESSFUL;
}
USBH_HCDS_HCHostInactive();
USBH_HCDS_HCPMControl(USBH_HCDS_HC_PM_STATE_SLEEP, NULL);
return USBH_HCD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_HCD_AllocDev
//
// description : Allocate memory area for the USB device control.
//
// Allocate the necessary memory used for the USB device control, and set the head pointer of allocated memory area
// into the private area for Host Controller of the structure which is passed.
//
// argument : *psUsbDev (in)Pointer of USB device information structure
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully
// USBH_HCD_STATUS_MEM_ERROR The memory area was not able to be allocated.
// USBH_HCD_STATUS_INVALID_PARAMETER Passed parameter errror
===============================================================================================*/
long USBH_HCD_AllocDev( USBH_HCD_USBDEV *psUsbDev )
{
if( psUsbDev == NULL ){
/* The pointer of the USB device information structure is NULL */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
if( psUsbDev->pHCPriv != NULL ){
/* A private area for Host Controller of the USB device information structure is used */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
if( psUsbDev->psParent == NULL ){
/* USB device information structure of route hub */
HCDStatus.psRootDev = psUsbDev;
} else {
/* The USB device information structure of connected device */
if( HCDStatus.psRootDev == NULL ){
/* The USB device information structure of the route hub has not been passed */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
}
psUsbDev->pHCPriv = &HCDStatus;
return USBH_HCD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_HCD_FreeDev
//
// description : Release the allocated memory for the USB device control
//
// Release the allocated memory for the USB device control,
// and set the NULL pointer in a private field for Host Controller of structure which is passed.
//
// argument : *psUsbDev (in)Pointer of USB device information structure
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully
// USBH_HCD_STATUS_INVALID_PARAMETER Error in passed parameters
===============================================================================================*/
long USBH_HCD_FreeDev( USBH_HCD_USBDEV *psUsbDev )
{
if( psUsbDev == NULL ){
/* The pointer of the USB device information structure is NULL */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
psUsbDev->pHCPriv = NULL;
return USBH_HCD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_HCD_GetFrameNum
//
// description : Get the current Frame Number
//
// Get the current Frame Number and set it in the passed storage field
//
// argument : pFrameNum (in)Field to storage Frame Number
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully
// USBH_HCD_STATUS_INVALID_PARAMETER Error in passed parameters
===============================================================================================*/
long USBH_HCD_GetFrameNum( unsigned short *pFrameNum )
{
if( pFrameNum == NULL ){
/* The storage field is NULL */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
/*=======================/
/ Get the current Frame Number /
/=======================*/
*pFrameNum = USBH_HCDS_HCGetFrameNumber();
return USBH_HCD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_HCD_SubmitURB
//
// description : Register and execute the passed URB
//
// Register and execute the passed URB
//
// argument : *psUrb (in)Pointer of URB structure
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully
// USBH_HCD_STATUS_MEM_ERROR Failed to allocate memory area
// USBH_HCD_STATUS_PIPE_ERROR The pipe to Endpoint of the USB device was not created
// USBH_HCD_STATUS_INVALID_PARAMETER Error in passed parameters
// USBH_HCD_STATUS_UNSUCCESSFUL Host Controller is suspending
===============================================================================================*/
long USBH_HCD_SubmitURB( USBH_HCD_URB *psUrb )
{
long retValue;
if( psUrb == NULL ){
/* The pointer of the URB structure is NULL */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
if( HCDStatus.bmFlags.hcSuspend == 1 ){
/* Host Controller is suspending */
return USBH_HCD_STATUS_UNSUCCESSFUL;
}
if( (psUrb->transFlag & USBH_HCD_URB_ASYNC_UNLINK) == 0 ){
/* This is not asynchronous cancel of the URB */
retValue = USBH_HCDS_URBSubmit(psUrb, HCDStatus.psRootDev);
if( retValue != STATUS_SUCCESS ){
/* The empty channel doesn't exist */
if( retValue == STATUS_MEM_ERROR ){
/* Memory allocation error */
return USBH_HCD_STATUS_MEM_ERROR;
} else if( retValue == STATUS_UNSUCCESSFUL ){
/* Channel allocation error */
return USBH_HCD_STATUS_PIPE_ERROR;
}
/* Parameter error */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
} else {
/* URB asynchronous cancel */
/*===========================================================/
/ For cancellation processing can be completed quickly, implement it by synchronous cancellation/
/============================================================*/
retValue = USBH_HCDS_URBUnlink(psUrb, HCDStatus.psRootDev);
if( retValue != STATUS_SUCCESS ){
/* Parameter error */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
}
return USBH_HCD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_HCD_UnlinkURB
//
// description : Cancel and delete the passed URB
//
// Cancele and delete the passed URB
//
// argument : *psUrb (in)Pointer of URB structure
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully
// USBH_HCD_STATUS_INVALID_PARAMETER Error in passed parameters
// USBH_HCD_STATUS_UNSUCCESSFUL Host Controller is suspending
===============================================================================================*/
long USBH_HCD_UnlinkURB( USBH_HCD_URB *psUrb )
{
long retValue;
if( psUrb == NULL ){
/* The pointer of the URB structure is NULL */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
if( HCDStatus.bmFlags.hcSuspend == 1 ){
/* Host Controller is suspending */
return USBH_HCD_STATUS_UNSUCCESSFUL;
}
/*===============/
/ Cancellation process /
/===============*/
retValue = USBH_HCDS_URBUnlink(psUrb, HCDStatus.psRootDev);
if( retValue != STATUS_SUCCESS ){
/* Parameter error */
return USBH_HCD_STATUS_INVALID_PARAMETER;
}
return USBH_HCD_STATUS_SUCCESS;
}
/*=============================================================================================
// Function_Name: USBH_HCD_EndpointDisable
//
// description : Endpoint of the specified USB device is stopped
//
// Cancel all the URB of corresponding Endpoint from passed USB device information structure and Endpoint address,
// and stop the Endpoint
//
// argument : *psDev (in)Pointer of USB device information structure
// epAddress (in)Endpoint address
// bit7:Direction(1:IN,0:OUT)
// bit6-4:Reserved(always 0)
// bit3-0:Endpoint number
//
// return : USBH_HCD_STATUS_SUCCESS Processing is completed successfully
// USBH_HCD_STATUS_INVALID_PARAMETER Error in passed parameters
// USBH_HCD_STATUS_UNSUCCESSFUL Host Controller is suspending
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -