📄 hc_otg.h
字号:
/****************************************************************
* MT View Silicon Tech. Inc.
*
* Copyright 2007, MT View Silicon Tech. Inc., ShangHai, China
* All rights reserved.
*
*
* Filename: hc_otg.h
*
* Programmer: Grey
*
* Created: 01/xx/2008
*
* Description: usb host controller for otg core head file
*
*
*****************************************************************/
#ifndef __HC_OTG_H__
#define __HC_OTG_H__
#include "otg_hal.h"
#include "usb_ch9.h"
#include "usb_error.h"
/* otg host controller hardware config */
#define HIGH_SPEED_EN 0 /* enable host high-speed function */
#define PHY_SUSPEND_MODE_PIN_EN 0 /* enable SuspendM signal of the PHY */
#define MAX_HC_NUM 1 /* host hardware number 1 */
#define MAX_HC_ENDPOINT_NUM 5 /* host hardware endpoint number 0 ~ 4 */
#define MAX_RH_PORT_NUM 1 /* root hub port number 1 */
#define CTRL_EP_FIFO_SIZE 64 /* control endpoint fifo size 64 bytes */
#define BULK_EP_FIFO_SIZE 512 /* Tx and Rx endpoint fifo size 512 bytes */
#define TRANSACTION_TIME_OUT 5000 /* wait TxPktRdy bit clear and RxPktRdy bit set time out */
//
// Port Status Field, PortStatus
// USB 2.0 Table 11-21
//
#define HUB_PORT_CONNECTION 0x0001
#define HUB_PORT_ENABLE 0x0002
#define HUB_PORT_SUSPEND 0x0004
#define HUB_PORT_OVER_CURRENT 0x0008
#define HUB_PORT_RESET 0x0010
#define HUB_PORT_POWER 0x0100
#define HUB_PORT_LOW_SPEED 0x0200 // (1 = LOW, 0 = FULL/HIGH)
#define HUB_PORT_HIGH_SPEED 0x0400 // (1 = HIGH, 0 = FULL)
//
// Port Change Field, PortChange
// USB 2.0 Table 11-22
//
#define HUB_C_PORT_CONNECTION 0x0001
#define HUB_C_PORT_ENABLE 0x0002
#define HUB_C_PORT_SUSPEND 0x0004
#define HUB_C_PORT_OVER_CURRENT 0x0008
#define HUB_C_PORT_RESET 0x0010
/*
* host controller physical endpoint
*/
typedef struct _HC_EP
{
BYTE Index; /* hardware endpoint index number */
}HC_EP;
/*
* root hub port.
* The port status and port change is defined in USB2.0 spec table-11.21 and table-11.22
*/
typedef struct _HC_RH_PORT
{
WORD PortStatus;
WORD PortChange;
}HC_RH_PORT;
/*
* host controller structure
*/
typedef struct _HC
{
CHAR *HcType; /* host controller name: "otg_host" */
CHAR *HcIDStr; /* host controller product/vendor string: "mvsilicon" */
// OTG_REG *Reg; /* otg host controller register pointer */
HC_EP Ep[MAX_HC_ENDPOINT_NUM]; /* host hardware endpoint information */
WORD HcEpMap; /* host hardware endpoint allocate map */
BOOL IsRHPortConn; /* root hub port connection status, 1 indicate connected */
HC_RH_PORT Port; /* host root hub port */
BYTE Set;
}HC;
/*
* endpoint descriptor
*/
typedef struct _HC_ED
{
BYTE FuncAddr; /* function address */
BYTE EndPointNum; /* endpoint number */
BYTE TransferType; /* endpoint type: ctrl, bulk, interrupt, isochronous */
BYTE Direction; /* endpoint transfer direction: in, out */
WORD MaxPacketSize; /* max packet size */
BYTE Interval; /* for interrupt and isochronous endpoint, control and bulk set 0 */
HC_EP *Ep; /* host controller endpoint information */
HC *Hc; /* host controller */
BYTE Set;
}HC_ED;
/*---------------------------------HCD transfer control--------------------------------*/
/*
* setup transaction
* send setup packet and check response
*/
extern BYTE
HcSetupTransaction(
HC_ED *ed,
BYTE *dat,
WORD length
);
/*
* control in transaction
* receive control transfer data packets and zero data status packet
*/
extern BYTE
HcCtrlInTransaction(
HC_ED *ed,
BYTE *dat,
WORD *length
);
/*
* control out transaction
* send control transfer data packets and zero data status packet
*/
extern BYTE
HcCtrlOutTransaction(
HC_ED *ed,
BYTE *dat,
WORD length
);
/*
* bulk in transaction
* receive bulk transfer data packets, DMA option
*/
extern BYTE
HcBulkInTransaction(
HC_ED *ed,
BYTE *dat,
WORD *length,
BOOL isUseDMA
);
/*
* bulk out transaction
* send bulk transfer data packets, DMA option
*/
extern BYTE
HcBulkOutTransaction(
HC_ED *ed,
BYTE *dat,
WORD length,
BOOL isUseDMA
);
/*------------------------------------------------------------------------------------*/
/*-------------------------------HC endpoint source allocate -------------------------*/
/*
* allocate host controller source
*/
extern HC*
AllocHc(VOID);
/*
* free host controller source
*/
extern VOID
FreeHc(
HC *hc
);
/*
* open host controller
*/
extern VOID
OpenHc(
HC *hc
);
/*
* create one HC endpoint for logic ED
*/
extern HC_EP*
HcAllocHcEndpoint(
HC *hc,
BYTE epNum
);
/*
* free one HC endpoint
*/
extern VOID
HcFreeHcEndpoint(
HC *hc,
HC_EP *ep
);
/*
* open one HC endpoint
*/
extern VOID
OpenHcEndpoint(
HC *hc,
HC_ED *ed
);
/*------------------------------------------------------------------------------------*/
/*----------------------------------HC status control---------------------------------*/
/*
* host reset USB
*/
extern VOID
HcResetUsb(
HC *hc
);
/*
* host suspend USB
*/
extern VOID
HcSuspendUsb(
HC *hc
);
/*
* host resume USB from suspend
*/
extern VOID
HcResumeUsb(
HC *hc
);
/*------------------------------------------------------------------------------------*/
/*----------------------------------HC frame---------------------------------*/
/*
* get current frame number
*/
extern DWORD
HcGetFrameNum(
HC *hc
);
/*--------------------------------------------------------------------------*/
/*--------------------------------HC init----------------------------*/
/*--------------------------------------------------------------------*/
/*------------------------------HC root hub------------------------------*/
/*
* open root hub polling interrupt
* the interval of polling is 250ms
*/
extern VOID
HcOpenRootHubPollInt(
HC *hc
);
/*
* Get root hub port status.
* Return port status and port change. port status field is the low word of return value,
* port change field is the high word of return value.
* The port status and port change is defined in USB2.0 spec table-11.21 and table-11.22
*/
extern DWORD
HcGetRootHubPortStatus(
HC *hc,
BYTE portNum
);
/*
* enable root hub one port
*/
extern BOOL
HcEnableRootHubPort(
HC *hc,
BYTE portNum
);
/*----------------------------------------------------------------------*/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -