⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb.c

📁 本程序为ST公司开发的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/************************************************** * * usb.c * * CVS ID:   $Id: usb.c,v 1.84 2007/10/22 12:00:31 trubac Exp $ * Author:   Leos Longauer [LL], Michal Chlapik [MC] - STM * Date:     $Date: 2007/10/22 12:00:31 $ * Revision: $Revision: 1.84 $ *  * Description: *  *   usb task: header * *************************************************** *  * COPYRIGHT (C) ST Microelectronics  2005 *            All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: usb.c,v $ * Revision 1.84  2007/10/22 12:00:31  trubac * command is saved locally if previous one is still in progress to * avoid losing of stop commands * * Revision 1.83  2007/09/21 05:40:11  mishima * Correct file type from MS to Unix. This file is completely same with revision 1.82. * * Revision 1.81  2007/09/21 01:53:39  mishima * Added MTP class driver control for WMDRM. * * Revision 1.80  2007/08/23 14:17:45  longauer * dv_msd.a - small correction of the driver READ10 processing * usb.c - error handling hidden bug found; reinitialization is refused if HIGH_Z is *  ON; stop enum.timer after device disconection * * Revision 1.79  2007/08/20 16:30:32  longauer * more robust HIGH_Z setting (proper timers handling) * * Revision 1.78  2007/08/10 12:33:30  longauer * IPOD_AP compilation switch enables future iAP * * Revision 1.77  2007/08/07 09:50:56  longauer * USB_VbusEnable() positive logic; pass-through acknowledge robustness enhancement; *  iAP preparation * * Revision 1.76  2007/08/06 08:52:27  belardi * Added GPIO control * * Revision 1.75  2007/07/26 09:15:35  trubac * Fixed support for fixed media devices * * Revision 1.74  2007/07/16 14:43:59  longauer * function Usb_VbusEnable() added; forced reinitialization bug solved (gUsbOn) * * Revision 1.73  2007/07/12 16:44:46  longauer * init/close usb controller cmd/status path partly implemented * * Revision 1.72  2007/07/10 13:57:22  longauer * one U3 device playable, check medium process improved, usb events renaming * * Revision 1.71  2007/07/09 11:10:35  longauer * preparation for forced closing *  of the usb controller, preparation for iAP, total medium size info, *  usb device serial number string length corrected, cleaning * * Revision 1.70  2007/07/03 14:08:25  belardi * Fix minor bug in USB_GetVolume() parameters * * Revision 1.69  2007/06/28 20:53:56  longauer * 1.Usb restructuralization in order to supports more LUNs and interface preparation *  for iAP; 2.PHY emulation moved; 3.compilation works with IPOD_PASSTHROUGH==0; 4. *  usb patching init moved from main.c * * Revision 1.68  2007/06/04 16:58:47  longauer * USBtask rearrangement in order to support more logical units; new file usb_pri.h added with USBtask private declarations; USB compilation switches added; constants renaming; * * Revision 1.67  2007/05/02 12:33:07  belardi * Removed unused variable * * Revision 1.66  2007/03/27 14:29:00  longauer * patch of the 'combined reports' iPod nano problem * * Revision 1.65  2007/03/19 18:04:31  longauer * APP_HUB_ON added in order to enable/disable HUB feature * * Revision 1.64  2007/03/16 10:30:39  longauer * USB_StartEnumTimer() added -> to save 1300 *  patch bytes in the case of enumeration timeout change * * Revision 1.63  2007/03/02 14:00:12  sedmik * fix for binary upstream; USB reinitialization added * * Revision 1.62  2007/02/22 18:37:25  belardi * Removed unused variable * * Revision 1.61  2007/02/22 14:27:34  marcucci * Add function to patch MGC structures * * Revision 1.60  2007/02/21 20:18:17  longauer * usb states and error reorganization;  usb state is propagated to player task = usb *  state messaging * * Revision 1.59  2007/02/16 13:45:59  belardi * Removed unused variable to remove compiler warning * * Revision 1.58  2007/02/13 16:32:45  longauer * long input to the driver possible without errors; preparation for error and message *  handling * * Revision 1.57  2007/02/09 12:14:38  belardi * First integration of iPod pass-through * * Revision 1.56  2007/01/30 12:35:21  chlapik * max device block size as #define set to 2048B * * Revision 1.55  2007/01/29 14:32:01  chlapik * support for USB devices with any block size (not only 512B) * * Revision 1.54  2006/12/12 16:33:22  longauer * medium removal handling * * Revision 1.53  2006/12/07 13:19:39  longauer * MUSB_DestroySystem() repaired - HUB everytime recognized *  after usb reinitialization; SFF redirected to SCSI; * * Revision 1.52  2006/12/05 16:55:36  longauer * medium check can not be off for devices with removable medium * * Revision 1.51  2006/12/05 14:33:09  chlapik * fixed bug - check medium performed only once after medium is pugged in, not anymore * * Revision 1.50  2006/12/04 16:30:38  longauer * CheckEnumeration can not be executed during BSR is pending. * * Revision 1.49  2006/11/30 18:26:59  longauer * V2.400ER; LG is working; known problem with HUB * * Revision 1.48  2006/11/20 07:25:44  chlapik * fixed bug - if stop cmd coming very fast after xfer cmd, faster than first interrupt occurs, then stop ready sent immediately also if last xfer not finished * * Revision 1.47  2006/11/13 19:04:02  longauer * RC15 * * Revision 1.46  2006/11/07 18:09:31  longauer * RC12 - SFF implemented; Sony doesn't work yet because of READ10/12 issue * * Revision 1.45  2006/11/01 09:36:26  longauer * 1.more robust=less aborts; 2.more devices supported 3.hub added * * Revision 1.44  2006/10/10 17:21:19  longauer * to prevent some  devices which could hook the driver during enumeration * * Revision 1.43  2006/09/18 09:55:26  belardi * Corrected CVS keyword usage *\ * Revision 1.42  2006/09/18 09:25:57  belardi * Added Log CVS keyword into file header * * ***************************************************/#include "configuration.h"#include "debug.h"#include "gendef.h"#if (0 != HAVE_USB)#include "hwreg.h"#include "osal.h"#include "utility.h" /* GPIO */#include "mconfig.h"#include "controller.h"#include "xfile.h"#include "FATsupport.h"#include "dynmem.h"#include "usb_pri.h"/*************************** DEBUGGING ****************************//* to compile usb.c from the command line to produce assembler:M:\WORK\PROJECTS\ACCORDO+\SOLUTION\OS20\ACCORDO\sources\usb>tcc --debug -O3 -Ono_fp_formats -Ono_inline --apcs=/inter --diag_suppress=1 -DOS20_MALLOC=0 -DOS20_OUTPUT=0 -DOS_WIN -DMUSB_DIAG=0 -DOS20_PROFILING=0 -I..\main -I..\debug -I..\controller -I..\hwreg -I..\osal -I..\osal\OS20\include -I..\osal\OS20\include\common -I..\osal\OS20\drivers\eft -I..\osal\OS20\drivers\eic -I..\capture -I..\fsystem -I..\servo -I..\decoder -I..\player\STM -Iinclude -Iinclude\system -Iinclude\system\afs -Iafs\uHAL -I. -Iinclude\drivers\hid -Iinclude\drivers\hub -Iinclude\drivers\msd -S usb.c*/#ifdef _USB_DEBUGtypedef struct{	uint8 bMountDebug;	uint8 bUnmountDebug;	uint16 UsbISRCounter_max_debug;} _DRIVER_status_debug;typedef struct{	uint8 b1_InitUSBTask_semaphore_wait;	uint8 b1_InitUSBTask_usb_process_preevents;	uint8 b1_InitUSBTask_usb_transition_handler;	uint8 b1_InitUSBTask_usb_process_postevents;	uint8 b1_InitUSBTask_Error;} _TASK_status_debug;typedef struct{	uint16 usb_read_error_1;	uint16 usb_read_error_2;	uint16 usb_read_error_3;	uint16 usb_read_error_4;	uint16 usb_read_error_5;	uint16 usb_read_error_6;	uint16 usb_read_error_7;	uint8 b3;	uint8 b5;} _xfer_transition_sebug;typedef struct{	uint8 b2_1;	uint8 b2_2;	uint8 b2_3;	uint8 b2_4;	uint8 b2_5;	uint8 b2_6;   	uint8 b2_7;	uint8 b21_1;	uint8 b21_2;	uint8 b211_1;	uint8 b211_2;	uint8 b22_1;	uint8 b22_2;	uint8 b22_3;	uint8 b22_4;} _process_preevents_debug;typedef struct{	uint8 b3_1;	uint8 b3_2;	uint16 d3_3;	uint16 d3_4;} _background_transition_debug;typedef struct{_DRIVER_status_debug DRIVER_status_debug;_TASK_status_debug TASK_status_debug;_xfer_transition_sebug xfer_transition_sebug;_process_preevents_debug process_preevents_debug;_background_transition_debug background_transition_debug;uint8 b4_1;} USB_DEBUG;USB_DEBUG USB_debug;unsigned char bIsUsbInterrupt = 0;#endif /*_USB_DEBUG*//**************************** GLOBALS *****************************/static uint32 UsbISRcounter = 0;#if (1 == HAVE_WMDRM)	uint8 USB_temp_buf[MTP_TEMP_BUF_SIZE];        // MTP_TEMP_BUF_SIZE = 2400 bytes#else	uint8 USB_temp_buf[C_USB_MAX_DEV_BLOCK_SIZE];#endifstatic uint8* pUSB_temp_buf = USB_temp_buf;uint8 gUsbOn = FALSE;tUsbDevice gUsbDevice;/**************************** usb task ****************************/t_fsm usb_fsm_xfer;t_fsm usb_fsm_stop;t_fsm usb_fsm_background;#if (1 == HAVE_WMDRM) t_fsm usb_fsm_mtp;#endift_child_cmd_event local_usb_cmd_event;t_bool local_cmd_present = b_FALSE;t_child_cmd_event local_cmd;#if ((0!=IPOD_PASSTHROUGH) || (0!=IPOD_AP))	//[LL]newt_usb_downstream_cmd_event local_usb_downstream_cmd;t_usb_upstream_cmd_event local_usb_upstream_cmd;#endif /*IPOD_PASSTHROUGH || IPOD_AP*//******************************************************************/#ifndef _USB_HOST /* current OTG state *///static MUSB_OtgState MGC_eMsdOtgState = MUSB_AB_IDLE;/* UCDI variables */static uint8 MGC_bDesireHostRole = TRUE;	/* FALSE - used in the case of Otg */#endif /* _USB_HOST */static MUSB_Port* MGC_pCdiPort = NULL;static MUSB_BusHandle MGC_hCdiBus = NULL;// [MM] was const, but in the code it is casted to uint8*// and written to, so it will not work when executed from ROMstatic uint8 MGC_aMsdPeripheralList[128] ={/*    MUSB_TARGET_CLASS, MUSB_CLASS_PER_INTERFACE,     MUSB_TARGET_INTERFACE, 0,     MUSB_TARGET_CLASS, MUSB_CLASS_MASS_STORAGE,     MUSB_TARGET_SUBCLASS, MGC_MSD_SCSI_SUBCLASS,    MUSB_TARGET_PROTOCOL, MGC_MSD_BOT_PROTOCOL,    MUSB_TARGET_ACCEPT#ifdef _USB_HUB    MUSB_TARGET_CLASS, MUSB_CLASS_HUB,     MUSB_TARGET_ACCEPT#endif#ifdef _USB_HID    MUSB_TARGET_CLASS, MUSB_CLASS_HID,     MUSB_TARGET_ACCEPT#endif*/0};#if 0//to play with TPLuint8_t MGC_aMsdPeripheralListx[] ={	/* reject MP3-H06 - driver doesn't start IN transfer for REQUEST_SENSE */    MUSB_TARGET_VID, 0x6F, 0x06,    MUSB_TARGET_PID, 0x00, 0x80,    MUSB_TARGET_REJECT,	/* reject 'Add-on technology'? - LUNs */    MUSB_TARGET_VID, 0x7D, 0x0D,    MUSB_TARGET_PID, 0x24, 0x19,    MUSB_TARGET_REJECT,	/* reject Sandisk Cruzer micro 512MB - LUNs *///    MUSB_TARGET_VID, 0x81, 0x07,//    MUSB_TARGET_PID, 0x06, 0x54,//    MUSB_TARGET_REJECT,	/* reject MemoRive slim 1GB - 2LUNs */    MUSB_TARGET_VID, 0x7D, 0x0D,    MUSB_TARGET_PID, 0x24, 0x1A,    MUSB_TARGET_REJECT,	/* reject Leidisk MTU-7A 256MB - sends 124B istead of 64B! */    MUSB_TARGET_VID, 0x8F, 0x05,    MUSB_TARGET_PID, 0x81, 0x93,    MUSB_TARGET_REJECT,	/* BOT/SCSI */    MUSB_TARGET_CLASS, MUSB_CLASS_PER_INTERFACE,     MUSB_TARGET_INTERFACE, 0,     MUSB_TARGET_CLASS, MUSB_CLASS_MASS_STORAGE,     MUSB_TARGET_SUBCLASS, MGC_MSD_SCSI_SUBCLASS,    MUSB_TARGET_PROTOCOL, MGC_MSD_BOT_PROTOCOL,    MUSB_TARGET_ACCEPT,	0 /* placeholder for driver index */};#endif#if (1 == HAVE_WMDRM)  /* Added two device drivers for MTP */  static MUSB_DeviceDriver MGC_aDeviceDriver[C_USB_MTP + C_USB_HID + 1 + C_USB_HUB + C_USB_MTP];#else/* by default 1 mass-storage driver */static MUSB_DeviceDriver MGC_aDeviceDriver[C_USB_HID + 1 + C_USB_HUB];#endif#if ((0!=IPOD_PASSTHROUGH) || (0!=IPOD_AP))	//[LL]newstatic MUSB_CisClient MGC_IpodCisClient = {	MUSB_IpodDeviceAddHandler,	MUSB_IpodDeviceRemoveHandler,	MUSB_IpodDeviceInputHandler,	MUSB_IpodDeviceOutputHandler};#endif /*IPOD_PASSTHROUGH || IPOD_AP*/static MUSB_HostClient MGC_MsdHostClient = {    MGC_aMsdPeripheralList,				/* peripheral list */    0,    /*sizeof(MGC_aMsdPeripheralList),*/	/* peripheral list length - filled in main */    MGC_aDeviceDriver,					/* device driver list */    0									/* device list length - filled in main */};#ifndef _USB_HOSTstatic MUSB_OtgClient MGC_MsdOtgClient = {	NULL,								/* no instance data; we are singleton */	&MGC_bDesireHostRole,	MUSB_MsdNewOtgState,	(MUSB_pfOtgError)MUSB_MsdOtgError};#endif /* _USB_HOST */#define LimitOfUSBCounter 1/****************************** FORWARDS **********************************/void usb_handler(void);teUsbFsmCompl usb_process_preevents(void);teUsbFsmCompl usb_stop_transition(void);#if (1 == HAVE_WMDRM) teUsbFsmCompl usb_mtp_transition(void);#endifteUsbFsmCompl usb_xfer_transition(void);teUsbFsmCompl usb_xfer_transision_check_error(t_fsm* usb_fsm, t_usb_state err);teUsbFsmCompl usb_background_transition(void);teUsbFsmCompl usb_state_handling(void);/****************************** PATCHING **********************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -