📄 usrusbbulkdevinit.c
字号:
/* usrUsbBulkDevInit.c - USB Mass Storage CBI driver initialization *//* Copyright 1999-2000 Wind River Systems, Inc. *//*Modification history--------------------01b,12apr01,wef added support for multiple devices, added new param to usbBulkBlkDevCreate () for read/ write type.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 the BULK_DRIVE_NAME configuration parameter. This configlette 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/usbBulkDevLib.h"/* defines */#define VX_UNBREAKABLE 0x0002 /* No debuging into this task *//* locals */LOCAL QUEUE_HANDLE bulkCallbackQueue;LOCAL USB_MESSAGE bulkDeviceStatus;LOCAL BLK_DEV * pBulkBlkDev = NULL; /* Store for drive structure */LOCAL DOS_VOL_DESC * pBulkDosVol = NULL; /* Store for file system structure */USBD_NODE_ID bulkNodeId;/*************************************************************************** bulkMountDrive - mounts a drive to the DOSFS.** RETURNS: OK or ERROR*/LOCAL STATUS bulkMountDrive ( USBD_NODE_ID attachCode /* attach code */ ) { /* Create the block device with in the driver */ pBulkBlkDev = (BLK_DEV *) usbBulkBlkDevCreate (bulkNodeId, NULL, NULL, USB_SCSI_FLAG_READ_WRITE10); if (pBulkBlkDev == NULL) { logMsg ("usbBulkBlkDevCreate() returned ERROR\n", 0, 0, 0, 0, 0, 0); return ERROR; } /* Mount the drive to DOSFS */ pBulkDosVol = dosFsDevInit (BULK_DRIVE_NAME, pBulkBlkDev, NULL); if (pBulkDosVol == NULL) { logMsg ("dosFsDevInit() returned ERROR\n", 0, 0, 0, 0, 0, 0); return ERROR; } return OK; } /*************************************************************************** bulkAttachCallback - user attach callback for USB BULK class driver.** RETURNS: Nothing*/LOCAL VOID bulkAttachCallback ( pVOID arg, /* caller-defined argument */ USBD_NODE_ID nodeId, /* pointer to BULK Device */ UINT16 attachCode /* attach code */ ) { usbQueuePut (bulkCallbackQueue, (UINT16) nodeId, /* msg */ attachCode, /* wParam */ (UINT32) NULL, /* lParam */ 5000); }/***************************************************************************** bulkClientThread- 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 bulkClientThread(void) { static int index; DEV_HDR *hdr; while (1) { /* * the queue parameters will be: * msg = nodeId * wParam = attach code */ usbQueueGet (bulkCallbackQueue, &bulkDeviceStatus, OSS_BLOCK); /* If attached. Only one device is supported at a time */ if (bulkDeviceStatus.wParam == USB_BULK_ATTACH) { bulkNodeId = (USBD_NODE_ID) bulkDeviceStatus.msg; /* Lock the device for protection */ if (usbBulkDevLock (bulkNodeId) != OK) printf ("usbBulkDevLock() returned ERROR\n"); /* Mount the drive to the DOS file system */ if (bulkMountDrive(bulkNodeId) != OK) printf ("bulkMountDrive () returned ERROR\n"); printf ("Bulk Device Installed as %s\n", BULK_DRIVE_NAME); } /* Device was removed */ else if (bulkDeviceStatus.wParam == USB_BULK_REMOVE) { bulkNodeId = (USBD_NODE_ID) bulkDeviceStatus.msg; /* Remove the dosFs handles if the device is not being used */ if ( (hdr = iosDevFind (BULK_DRIVE_NAME, NULL)) != NULL ) iosDevDelete (hdr); /* Unlock the BULK device structure, so that it gets destroyed */ if (usbBulkDevUnlock (bulkNodeId) != OK) { printf ("usbBulkDevUnlock() returned ERROR\n"); return; } printf ("%s removed and uninstalled from FS\n", BULK_DRIVE_NAME); /* free memory for the device */ bulkNodeId = NULL; pBulkDosVol = NULL; } } }/*************************************************************************** usrUsbBulkDevInit - initializes USB BULK Mass storage driver.** This function initializes the BULK driver and registers a CBI - BULK * drive with the USBD. In addition, it also spawns a task to handle * plugging / unplugging activity.** RETURNS: Nothing*/ void usrUsbBulkDevInit (void) { int taskId; /* Initialize the BULK class driver */ if (usbBulkDevInit () == OK) logMsg ("usbBulkDevInit() returned OK\n", 0, 0, 0, 0, 0, 0); else logMsg ("usbBulkDevInit() returned ERROR\n", 0, 0, 0, 0, 0, 0); /* This queue is used to pass status parameters to the task spawned below */ if (usbQueueCreate (128, &bulkCallbackQueue)!=OK) { logMsg ("callback queue creation error\n ", 0, 0, 0, 0, 0, 0); return; } /* Spawn a task to manage drive removal and insertion */ if((taskId = taskSpawn ("tBulkClnt", 5, 0, 20000, (FUNCPTR) bulkClientThread, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )) ==ERROR) { logMsg (" TaskSpawn Error...!\n", 0, 0, 0, 0, 0, 0); return; } /* Register for dynamic attach callback */ if (usbBulkDynamicAttachRegister (bulkAttachCallback, (pVOID)NULL) != OK) logMsg ("usbBulkDynamicAttachRegister() returned ERROR\n", 0, 0, 0, 0, 0, 0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -