📄 usrusbcbiufidevinit.c
字号:
/* usrUsbCbiUfiDevInit.c - USB Mass Storage CBI driver initialization *//* Copyright 1999-2000 Wind River Systems, Inc. *//*Modification history--------------------01a,10dec00,wef Created*/ /*DESCRIPTION This configlette initializes the USB Mass Storage Control / Bulk / Interruptdriver and places it in the driver table. On boot, it can be refered to by the name given specified by CBI_DRIVE_NAME. This assumes the USB host stack has already been initialized and has a host controller driver attached. *//* includes */#include "dosFsLib.h"#include "usb/usbdLib.h"#include "usb/usbQueueLib.h"#include "drv/usb/usbCbiUfiDevLib.h"/* defines */#define VX_UNBREAKABLE 0x0002 /* No debuging into this task *//* locals */LOCAL QUEUE_HANDLE cbiCallbackQueue;LOCAL USB_MESSAGE cbiDeviceStatus;LOCAL USBD_NODE_ID ufiNodeId; /* Store for nodeId of the UFI device */LOCAL BLK_DEV * pUfiBlkDev = NULL; /* Store for drive structure */LOCAL DOS_VOL_DESC * pUfiDosVol = NULL; /* Store for file system structure */LOCAL BOOL ufiConnected = FALSE; /* True if a UFI device exists */LOCAL BOOL ufiDevInUse = FALSE; /* True while IO operations are */ /* operations are being performed */ /*************************************************************************** ufiMountDrive - mounts a drive to the DOSFS.** RETURNS: OK or ERROR*/LOCAL STATUS ufiMountDrive ( USBD_NODE_ID attachCode /* attach code */ ) { /* Create the block device with in the driver */ pUfiBlkDev = (BLK_DEV *) usbCbiUfiBlkDevCreate (ufiNodeId); if (pUfiBlkDev == NULL) { printf ("usbCbiUfiBlkDevCreate() returned ERROR\n"); return ERROR; } /* Mount the drive to DOSFS */ pUfiDosVol = dosFsDevInit (CBI_DRIVE_NAME, pUfiBlkDev, NULL); if (pUfiDosVol == NULL) { printf ("dosFsDevInit() returned ERROR\n"); return ERROR; } return OK; } /*************************************************************************** ufiAttachCallback - user attach callback for USB UFI class driver.** RETURNS: Nothing*/LOCAL VOID ufiAttachCallback ( pVOID arg, /* caller-defined argument */ USBD_NODE_ID nodeId, /* pointer to UFI Device */ UINT16 attachCode /* attach code */ ) { usbQueuePut (cbiCallbackQueue, (UINT16) nodeId, /* msg */ attachCode, /* wParam */ (UINT32) NULL, /* lParam */ 5000); }/***************************************************************************** ufiClientThread- Handle control of drives being plugged / unplugged** This function controls what happens when a new drive gets plugged in* or when an existing drive gets removed.** RETURNS: Nothing*/ LOCAL VOID ufiClientThread(void) { static int index; DEV_HDR *hdr; while (1) { usbQueueGet (cbiCallbackQueue, &cbiDeviceStatus, OSS_BLOCK); /* If attached. Only one device is supported at a time */ if ((cbiDeviceStatus.wParam == USB_UFI_ATTACH) && (ufiConnected != TRUE)) { ufiConnected = TRUE; /* UFI device detected */ ufiNodeId = (USBD_NODE_ID) cbiDeviceStatus.msg; /* Store nodeId of UFI device */ /* Lock the device for protection */ if (usbCbiUfiDevLock (ufiNodeId) != OK) printf ("usbCbiUfiDevLock() returned ERROR\n"); /* Mount the drive to the DOS file system */ if (ufiMountDrive(ufiNodeId) != OK) printf ("ufiMountDrive () returned ERROR\n"); printf ("UFI Device Installed as %s\n", CBI_DRIVE_NAME); } else { if (cbiDeviceStatus.msg == (UINT16) ufiNodeId) /* UFI device removed. Check nodeId */ { ufiConnected = FALSE; /* Declare that device doesn't exist */ if ((ufiDevInUse == FALSE) && (pUfiBlkDev != NULL)) { /* Remove the dosFs handles if the device is not being used */ if ( (hdr = iosDevFind (CBI_DRIVE_NAME, NULL)) != NULL ) iosDevDelete (hdr); /* Unlock the UFI device structure, so that it gets destroyed */ if (usbCbiUfiDevUnlock ((USBD_NODE_ID) cbiDeviceStatus.msg) != OK) printf ("usbCbiUfiDevUnlock() returned ERROR\n"); printf ("%s removed and uninstalled from FS\n", CBI_DRIVE_NAME); pUfiBlkDev = NULL; pUfiDosVol = NULL; } } } } }/***************************************************************************** ufiClntRegister- Mass Storage Drive Registration** This function registers a CBI - UFI drive with the USBD. In addition, it* also spawns a task to handle plugging / unplugging activity.** RETURNS: Nothing*/ LOCAL VOID ufiClntRegister (void) { int taskId; /* This queue is used to pass status parameters to the task spawned below */ if (usbQueueCreate (128, &cbiCallbackQueue)!=OK) printf("callback queue creation error\n "); /* Spawn a task to manage drive removal and insertion */ if((taskId = taskSpawn ("tUfiClnt", 5, VX_UNBREAKABLE, 20000, (FUNCPTR) ufiClientThread, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )) ==ERROR) printf(" TaskSpawn Error...!\n"); /* Register for dynamic attach callback */ if (usbCbiUfiDynamicAttachRegister (ufiAttachCallback, (pVOID)NULL) != OK) printf ("usbCbiUfiDynamicAttachRegister() returned ERROR\n"); }/*************************************************************************** usrUsbCbiUfiDevInit - initializes USB UFI Mass storage driver.** RETURNS: Nothing*/ void usrUsbCbiUfiDevInit (void) { /* Initialize the UFI class driver */ if (usbCbiUfiDevInit () == OK) printf ("usbCbiUfiDevInit() returned OK\n"); else printf ("usbCbiUfiDevInit() returned ERROR\n"); /* Registration routine */ ufiClntRegister (); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -