📄 dchandle.c
字号:
/*
//*************************************************************************
//
// P H I L I P S P R O P R I E T A R Y
//
// COPYRIGHT (c) 2000-2002 BY PHILIPS SINGAPORE.
// -- ALL RIGHTS RESERVED --
//
// File Name: MainLoop.C
// Created: Feb. 1, 2000
// Modified: May 31, 2002
// Revision: 1.0
//
//*************************************************************************
// Abstract:
//
//*************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <bios.h>
#include <dos.h>
#include <malloc.h>
#include "SysCnfg.h"
#include "BasicTyp.h"
#include "DcCommon.h"
#include "Hal4sys.h"
#include "Hal4ISA.h"
#include "Hal4IKit.h"
#include "Hal4D13.h"
#include "D13_REG.h"
#include "D13_DcS.h"
#include "usb100.h"
#include "chap_9.h"
#include "Hal4OTG.h"
#include "OTGSvc.h"
#include "DcHandle.h"
//**************************************************************************
/*
//*************************************************************************
// USB protocol function pointer arrays
//*************************************************************************
*/
#define MAX_STANDARD_REQUEST 0x0D
void (*StandardDeviceRequest[])(void) =
{
Chap9_GetStatus,
Chap9_ClearFeature,
Chap9sup_StallEP0,
Chap9_SetFeature,
Chap9sup_StallEP0,
Chap9_SetAddress,
Chap9_GetDescriptor,
Chap9sup_StallEP0,
Chap9_GetConfiguration,
Chap9_SetConfiguration,
Chap9_GetInterface,
Chap9_SetInterface,
Chap9sup_StallEP0
};
CHAR * _NAME_USB_REQUEST_DIRECTION[] =
{
"Host_to_device",
"Device_to_host"
};
CHAR * _NAME_USB_REQUEST_RECIPIENT[] =
{
"Device",
"Interface",
"Endpoint(0)",
"Other"
};
CHAR * _NAME_USB_REQUEST_TYPE[] =
{
"Standard",
"Class",
"Vendor",
"Reserved"
};
CHAR * _NAME_USB_STANDARD_REQUEST[] =
{
"GET_STATUS",
"CLEAR_FEATURE",
"RESERVED",
"SET_FEATURE",
"RESERVED",
"SET_ADDRESS",
"GET_DESCRIPTOR",
"SET_DESCRIPTOR",
"GET_CONFIGURATION",
"SET_CONFIGURATION",
"GET_INTERFACE",
"SET_INTERFACE",
"SYNC_FRAME"
};
/*
//*************************************************************************
// Class device requests
//*************************************************************************
*/
/*
//*************************************************************************
// Vendor Device Request
//*************************************************************************
*/
/*
//*************************************************************************
// Public/Global static data
//*************************************************************************
*/
extern UCHAR bIRQL;
extern UCHAR bVerbose;
extern OTG_TCB OtgTcb;
// Task Control Block
DC_TCB D13TaskControlBlock;
// USB Device Info
USB_DEV_INFO D13_DevInfo;
// USB Default Control Pipe
CONTROL_XFER DCPCtrlXfer;
/*
//*************************************************************************
// Main Function
//*************************************************************************
*/
void Dc_Handler(void)
{
DcSup_Handler4OTG();
}
/*
//*************************************************************************
// Subroutines - 1
//**********4***************************************************************
*/
void DcSup_Handler4OTG(void)
{
if (D13_DevInfo.bits.Event_BusReset)
{
printf("DC: Bus reset!\n");
DcHSup_BusReset();
RaiseIRQL();
OtgTcb.a_bus_reset = 1;
OtgTcb.a_bus_suspend = 0;
OtgTcb.b_bus_suspend = 0;
// These OTG internal variables should be cleared upon a bus reset
OtgTcb.b_hnp_en = 0;
OtgTcb.a_hnp_support = 0;
OtgTcb.a_alt_hnp_support = 0;
D13_DevInfo.bits.Event_BusReset = 0;
LowerIRQL();
} /* if bus reset */
if (D13_DevInfo.bits.Event_Suspend)
{
DcHSup_SuspendChange();
RaiseIRQL();
OtgTcb.a_bus_suspend = 1;
OtgTcb.b_bus_suspend = 1;
D13_DevInfo.bits.Event_Suspend = 0;
LowerIRQL();
printf("DC: Bus suspend!\n");
}
if (D13_DevInfo.bits.Event_BusResume)
{
RaiseIRQL();
OtgTcb.a_bus_suspend = 0;
OtgTcb.b_bus_suspend = 0;
D13_DevInfo.bits.Event_BusResume = 0;
LowerIRQL();
printf("DC: Bus resume!\n");
}
if (DCPCtrlXfer.FSMState == USBFSM4DCP_SETUPPROC)
{
DcHSup_SetupTokenHandler();
}
if ((DCPCtrlXfer.FSMState == USBFSM4DCP_REQUESTPROC) && !DCPCtrlXfer.bAbort)
{
DcHSup_USBDeviceRequestHandler();
} /* if setup_packet for DeviceRequest*/
// }
}
/*
//*************************************************************************
// Subroutines - 2
//*************************************************************************
*/
void DcHSup_SetupTokenHandler(void)
{
/*
// Normal path
// Setup Transaction starts after a completed Control Transfer.
*/
DcHSup_RaiseIRQL();
DCPCtrlXfer.bAbort = FALSE;
DCPCtrlXfer.wLength = 0;
DCPCtrlXfer.wCount = 0;
if( D13_ReadEndpointWOClearBuffer(EPINDEX4EP0_CONTROL_OUT, \
(PUSHORT)(& DCPCtrlXfer.DeviceRequest), \
sizeof(DEVICE_REQUEST)) \
== sizeof(DEVICE_REQUEST) \
)
{
DcHSup_LowerIRQL();
/*
// After Checking OverWritten Bit, It's sure that Setup Pkt Data is valid.
*/
DCPCtrlXfer.wLength = DCPCtrlXfer.DeviceRequest.wLength;
DCPCtrlXfer.wCount = 0;
printf("DC: Setup_handler: bRequest=x%xh, bmRequest=x%xh, wLength=x%xh \n", \
DCPCtrlXfer.DeviceRequest.bRequest, \
DCPCtrlXfer.DeviceRequest.bmRequestType, \
DCPCtrlXfer.DeviceRequest.wLength);
if (DIR_D2H == DCPCtrlXfer.DeviceRequest.bmRequestType.XferDir)
{
/* get command */
DcHSup_RaiseIRQL();
DcHSup_AcknowledgeSETUP();
DCPCtrlXfer.FSMState = USBFSM4DCP_REQUESTPROC;
DcHSup_LowerIRQL();
}
else
{
/* set command */
if (0 == DCPCtrlXfer.DeviceRequest.wLength)
{
/* Set command without Data stage*/
DcHSup_RaiseIRQL();
DcHSup_AcknowledgeSETUP();
DCPCtrlXfer.FSMState = USBFSM4DCP_REQUESTPROC; // no such command is supported so far .
DcHSup_LowerIRQL();
}
else
{
/*
// Set command with Data stage
// get Data Buffer
*/
if(DCPCtrlXfer.DeviceRequest.wLength <= MAX_CONTROLDATA_SIZE)
{
/* set command with OUT token */
DcHSup_RaiseIRQL();
DCPCtrlXfer.FSMState = USBFSM4DCP_DATAOUT;
DcHSup_AcknowledgeSETUP();
DcHSup_LowerIRQL();
}
else
{
DcHSup_RaiseIRQL();
DcHSup_AcknowledgeSETUP();
Chap9sup_StallEP0InControlWrite();
DCPCtrlXfer.FSMState = USBFSM4DCP_STALL;
DcHSup_LowerIRQL();
printf("DCPCtrlXfer.FSMState = x%hx\n Unknow set up command\n", DCPCtrlXfer.FSMState);
printf("wLength = x%hx\n", DCPCtrlXfer.DeviceRequest.wLength);
}
}
}
}
else
{
printf("wrong setup command\n");
DcHSup_LowerIRQL();
Chap9sup_StallEP0();
}
}
void DcHSup_USBDeviceRequestHandler(void)
{
UCHAR byType;
UCHAR byReqIndex;
byType = DCPCtrlXfer.DeviceRequest.bmRequestType.Type;
byReqIndex = DCPCtrlXfer.DeviceRequest.bRequest & USB_REQUEST_MASK;
if ((byType == USB_STANDARD_REQUEST) && (byReqIndex < MAX_STANDARD_REQUEST))
(*StandardDeviceRequest[byReqIndex])();
// else if ((byType == USB_CLASS_REQUEST) && (byReqIndex < MAX_CLASS_REQUEST))
// (*ClassDeviceRequest[byReqIndex])();
// else if ((byType == USB_VENDOR_REQUEST) && (byReqIndex < MAX_VENDOR_REQUEST))
// (*VendorDeviceRequest[byReqIndex])();
else
Chap9sup_StallEP0();
}
void DcHSup_Connect2USB(void)
{
/*
// reset event flags
*/
RaiseIRQL();
D13_DevInfo.dwValue = 0;
DCPCtrlXfer.FSMState = USBFSM4DCP_IDLE;
LowerIRQL();
DcS_ConfigEndpoint();
DcS_Connect2USB();
}
void DcHSup_BusReset(void)
{
// D13 need to reconfig endpoint configuration registers upon a bus reset
DcS_ConfigEndpoint();
}
void DcHSup_SuspendChange(void)
{
}
void DcHSup_AcknowledgeSETUP(void)
{
if( DcS_IsSetupPktInvalid() || DCPCtrlXfer.bAbort)
{
return;
}
/*
// Acknowledge setup here to unlock in/out endp
// !!! I have 10Bytes Time @12Mbps to complete ACKSETUP !!!
*/
D13_AcknowledgeSETUP();
D13_ClearBuffer(EPINDEX4EP0_CONTROL_OUT);
}
void DcHSup_Help4USBDevRequest(UCHAR type, UCHAR req)
{
UCHAR typ = type;
typ >>= 5;
if(type == USB_STANDARD_REQUEST) {
printf("Request Type = %s, Request = %s.\n", _NAME_USB_REQUEST_TYPE[typ],
_NAME_USB_STANDARD_REQUEST[req]);
}
else {
if(bVerbose)
printf("Request Type = %s, bRequest = 0x%x.\n", _NAME_USB_REQUEST_TYPE[typ],
req);
}
}
void DcHSup_PrintDevStateInfo(void)
{
}
void DcHSup_PrintDefaultControlPipeInfo(void)
{
USHORT i;
switch (DCPCtrlXfer.FSMState)
{
case USBFSM4DCP_IDLE:
printf("Control state = USBFSM4DCP_IDLE.\n");
break;
case USBFSM4DCP_STALL:
printf("Control state = USBFSM4DCP_STALL.\n");
break;
case USBFSM4DCP_DATAOUT:
printf("Control state = USBFSM4DCP_DATAOUT.\n");
break;
case USBFSM4DCP_DATAIN:
printf("Control state = USBFSM4DCP_DATAIN.\n");
break;
case USBFSM4DCP_REQUESTPROC:
printf("Control state = USBFSM4DCP_REQUESTPROC.\n");
break;
case USBFSM4DCP_HANDSHAKE:
printf("Control state = USBFSM4DCP_HANDSHAKE.\n");
break;
case USBFSM4DCP_SETUPPROC:
printf("Control state = USBFSM4DCP_SETUPPROC.\n");
break;
default:
printf("Control state = x%x, Unknown State.\n", DCPCtrlXfer.FSMState);
break;
}
printf(" DCPCtrlXfer.wCount = %x.\n", DCPCtrlXfer.wCount);
printf("Last Device Request: bmRequestType = 0x%x, bRequest= 0x%x, wValue = 0x%x, wLength = 0x%x, wIndex = 0x%x.\n",
DCPCtrlXfer.DeviceRequest.bmRequestType,
DCPCtrlXfer.DeviceRequest.bRequest,
DCPCtrlXfer.DeviceRequest.wValue,
DCPCtrlXfer.DeviceRequest.wLength,
DCPCtrlXfer.DeviceRequest.wIndex);
printf("Data: ");
for(i = 0; i < DCPCtrlXfer.DeviceRequest.wLength; i ++)
printf("0x%x, ", *((DCPCtrlXfer.ptrBuf)+i));
printf("\n");
}
void DcHSup_Init( void)
{
// Acquire System Related Resource
DcS_DumpReg();
DcS_AcquireD13();
// DcS_DumpReg();
// Reconnect Soft-Connect
printf("Re-connect D13 in ISP1161.\n");
DcS_Reconnect2USB();
}
void DcHSup_Exit(void)
{
DcS_DisconnectUSB();
DcS_ReleaseD13();
}
void DcHSup_RaiseIRQL(void)
{
RaiseIRQL();
bIRQL = 1;
}
void DcHSup_LowerIRQL(void)
{
bIRQL = 0;
LowerIRQL();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -