📄 papp_eve.c
字号:
/*------------------------------------------------------------------------------
$File: //tdi_sw/tdi/examples/usb/pcd/common/papp_eve.c $
$DateTime: 2004/12/20 19:06:16 $
$Revision: #10 $
Purpose: Functions to service all callback events
------------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
CONFIDENTIAL AND PROPRIETARY INFORMATION OF SOFTCONNEX TECHNOLOGIES, INC.
THIS NOTICE IS NOT TO BE DELETED, MODIFIED, MOVED OR CHANGED IN ANY WAY.
Copyright (c) 1999 - 2004 by SoftConnex Technologies, Inc.
This software is protected by copyright laws and international copyright
treaties, as well as other intellectual property laws and treaties. This
software is a CONFIDENTIAL, unpublished work of authorship, and with portions
constituting TRADE SECRETS of SoftConnex Technologies, Inc., a Delaware USA
corporation. Any unauthorized use, disclosure, and/or reproduction of this
software, or any part of this software; or distribution of this software in any
form or by any means; or storage of this software in any database or retrieval
system, without the express written consent of, and license from, SoftConnex
Technologies, Inc. is strictly prohibited. This software is protected under the
copyright and/or trade secret laws in other countries in addition to USA. All
Rights Reserved. Failure to abide by the use, disclosure and/or reproduction
restrictions may result in civil and /or criminal penalties, and will be
prosecuted to the maximum extent of the law.
------------------------------------------------------------------------------*/
#include "project.h"
volatile U8 vendorCommandStatus = 0;
/* The following is a mutex for vendorCommandStatus. Since vendorCommandStatus
is shared between the event handler and the main loop, and the main loop and
the event handler can potentially get out of sync, we need the protection.
Event handler should clear vendorCommandStatus only if the value of
vendorCommandStatus = 1 from the point it receives the SETUP packet to the
point it finishes the control transfer */
volatile SctBool vendorCmdStatClear = SCC_FALSE;
volatile U8 CurrentConfigNum = 0;
volatile SctBool resetStarted = SCC_FALSE;
volatile SctBool enumerationDone = SCC_FALSE;
volatile SctBool configurationDone = SCC_FALSE;
volatile SctBool addressPending = SCC_FALSE;
volatile U32 appState = APP_STATE_DEVICE_DETACHED;
volatile U32 usbAssignedAddress = 0;
TdiPeriphEp* ep0;
TdiPeriphEp* ep1;
TdiPeriphEp* ep2;
TdiPeriphEp* ep3;
TdiPeriphEp* ep4;
TdiPeriphEp* ep5;
TdiPeriphEp* ep6;
TdiPurb isoInUrb;
TdiPurb isoOutUrb;
TdiPurb intrInUrb;
TdiPurb intrOutUrb;
TdiPurb controlInUrb;
TdiPurb controlOutUrb;
TdiPurb bulkInUrb;
TdiPurb bulkOutUrb;
extern SctStatus PCDAPP_ProcessClassCommand(TdiPeriphController* pc,
PeriphSetupRequest* request);
extern SctStatus PCDAPP_ProcessVendorCommand(TdiPeriphController* pc,
PeriphSetupRequest* request);
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_FindEp
Purpose : Find the ep struct
Arguments : pc - controller handle
epAddr - USB device address
Returns : TdiPeriphEp*
Notes :
-----------------------------------------------------------------------------*/
TdiPeriphEp* PCDAPP_EVE_FindEp(TdiPeriphController* pc, U16 epAddr)
{
return *(pc->ep + (epAddr & USB_MASK_ENDPOINT_ADDRESS));
}
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_SetEpStall
Purpose : Set stall to an ep
Arguments : pc - controller handle
epAddr - USB device address
Returns : none
Notes :
-----------------------------------------------------------------------------*/
void PCDAPP_EVE_SetEpStall(TdiPeriphController* pc, U16 epAddress)
{
TdiPeriphEp* ep;
ep = PCDAPP_EVE_FindEp(pc, epAddress);
if (NULL == ep)
{
PRINT1("(PCDAPP_EVE_SetEpStall) ERROR: Endpoint not found.\n");
return;
}
PCD_ConfigEp(pc, epAddress, EP_HALT_SET, ep);
}
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_ClearEpStall
Purpose : Clear stall on the ep
Arguments : pc - controller handle
epAddr - USB device address
Returns : none
Notes :
-----------------------------------------------------------------------------*/
void PCDAPP_EVE_ClearEpStall(TdiPeriphController* pc, U16 epAddress)
{
TdiPeriphEp* ep;
ep = PCDAPP_EVE_FindEp(pc, epAddress);
if (NULL == ep)
{
PRINT1("(PCDAPP_EVE_ClearEpStall) ERROR: Endpoint not found.\n");
return;
}
PCD_ConfigEp(pc, epAddress, EP_HALT_CLEAR, ep);
}
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_SetAddress
Purpose : Process Set Address command
Arguments : pc - controller handle
epAddr - USB device address
Returns : none
Notes :
-----------------------------------------------------------------------------*/
void PCDAPP_EVE_SetAddress(TdiPeriphController* pc, U32 addr)
{
PCD_SetAddress(pc, addr);
}
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_InitializeEp
Purpose : Initialize ep structure
Arguments : pc - periphController handle
ep - Endpoint struct address
descriptor - Endpoint descriptor management struct address
Returns : SctStatus
Notes :
-----------------------------------------------------------------------------*/
SctStatus PCDAPP_EVE_InitializeEp(TdiPeriphController* pc, TdiPeriphEp* ep,
U8* descriptor)
{
ep->urb = NULL;
ep->halted = SCC_FALSE;
ep->address = descriptor[USBDESC_EP_BENDPOINTADDRESS];
ep->epNumber = (ep->address & USBDESC_EP_NUM_MASK);
ep->maxPktSize = descriptor[USBDESC_EP_WMAXPACKETSIZE];
ep->maxPktSize |= (descriptor[USBDESC_EP_WMAXPACKETSIZE + 1]) << 8;
ep->type = (descriptor[USBDESC_EP_BMATTRIBUTES] & USBDESC_EP_TYPE_MASK);
ep->direction = (ep->address & USBDESC_EP_DIRECTION);
return SCS_SUCCESS;
}
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_SetConfiguration
Purpose : Process Set Configuration command
Arguments : pc - controller handle
config - config descriptor management struct pointer
configNum - configuration number
Returns : Configuration Descriptor pointer
Notes :
-----------------------------------------------------------------------------*/
SctStatus PCDAPP_EVE_SetConfiguration(TdiPeriphController* pc, U8* configDescr,
U16 configNum)
{
U32 totalLength = 0;
U32 offset = 0;
U32 descrType;
U32 epMps = 0;
U8 epCount = 0;
TdiPeriphEp* ep;
U8* epDescriptor;
U8 addr;
U8 direction;
U8 epType;
SctStatus result;
/* Disable interrupts on the controller */
/* Parse the config descriptor for interface and within the interface
** parse for endpoint descriptor and initialize those endpoints
*/
descrType = configDescr[USBDESC_BDESCRIPTORTYPE];
if (USB_CONFIG_DESCRIPTOR != descrType)
{
PRINT1("(PCDAPP_EVE_SetConfiguration) ERROR: This is not a config descriptor.\n");
}
totalLength = configDescr[USBDESC_CONFIG_WTOTALLENGTH];
/* Parse this config descriptor for all endpoint descriptors and
** initialize them
*/
while (offset < totalLength)
{
offset += configDescr[offset];
descrType = configDescr[offset + 1];
if (USB_ENDPOINT_DESCRIPTOR == descrType)
{
epCount++;
epDescriptor = &configDescr[offset];
addr = epDescriptor[USBDESC_EP_BENDPOINTADDRESS];
direction = (addr & USB_MASK_REQUEST_DIRECTION);
epType = (epDescriptor[USBDESC_EP_BMATTRIBUTES] & USBDESC_EP_TYPE_MASK);
epMps = epDescriptor[USBDESC_EP_WMAXPACKETSIZE];
epMps |= (epDescriptor[USBDESC_EP_WMAXPACKETSIZE + 1] << 8);
result = PCD_CreateEp(pc, addr, direction, epType, epMps, &ep);
if (NULL == ep)
{
/* Enable interrupts on the controller */
PRINT1("(PCDAPP_EVE_SetConfiguration) ERROR: "
" Failed to create endpoint.\n");
return SCS_ERROR;
}
switch (epCount)
{
case 1:
ep1 = ep;
break;
case 2:
ep2 = ep;
break;
case 3:
ep3 = ep;
break;
case 4:
ep4 = ep;
break;
case 5:
ep5 = ep;
break;
case 6:
ep6 = ep;
break;
default:
break;
}
PCDAPP_EVE_InitializeEp(pc, ep, epDescriptor);
}
}
PCD_SetDeviceConfig(pc, configNum);
configurationDone = SCC_TRUE;
/* Enable interrupts on the controller */
return SCS_SUCCESS;
}
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_ClearConfiguration
Purpose : Process Clear Configuration command
Arguments : pc - Peripheral Controller handle
Returns : SctStatus
Notes :
-----------------------------------------------------------------------------*/
SctStatus PCDAPP_EVE_ClearConfiguration(TdiPeriphController* pc)
{
U32 i;
TdiPeriphEp** ep;
ep = pc->ep;
for (i = 0; i < USB_MAX_ENDPOINT; i++, ep++)
{
if (NULL != *ep)
{
PCD_DestroyEp(pc, *ep);
*ep = NULL;
}
}
PCD_ClearDeviceConfig(pc);
return SCS_SUCCESS;
}
/*------------------------------------------------------------------------------
Name : PCDAPP_EVE_ProcessGetStatus
Purpose : Process get status command
Arguments : pc - peripheral controller handle
request - SETUP packet
Returns : SctStatus
Notes :
-----------------------------------------------------------------------------*/
SctStatus PCDAPP_EVE_ProcessGetStatus(TdiPeriphController* pc,
PeriphSetupRequest* request)
{
U8 b;
b = 0;
if ((request->bmRequestType & USB_MASK_RECIPIENT) == USB_RECIPIENT_DEVICE)
{
if (SCC_TRUE == pc->remoteWakeupEnable)
{
b = 2;
}
if (SCC_TRUE == pc->selfPowered)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -