📄 usrusbmseinit.c
字号:
/* usrUsbMseInit.c - Initialization of the USB Mouse driver *//* Copyright 1999-2001 Wind River Systems, Inc. *//*Modification history--------------------01b,02feb01,wef Added ios functionality - allows for open, close, read, ioctl, etc access to the printer.01a,23aug00,wef Created*//*DESCRIPTIONThis configlette initializes the USB mouse driver. This assumes theUSB host stack has already been initialized and has a host controllerdriver attached. This configlette demonstrates how a user might integrate a USB class driver into the vxWorks file system. usbMseDevCreate () intalls a USBmouse and its associated driver functions into the driver table allowingthe mouse to be accesed with standard fopen, close, read, write, etc. typecalls. *//* includes */#include "drv/usb/usbMouseLib.h"/* defines */#define TX_BUF_NUM 0x10000#define USB_MSE_MUTEX_TAKE(tmout) \ semTake (usbMseMutex, (int) (tmout))#define USB_MSE_MUTEX_GIVE \ semGive (usbMseMutex)#define USB_MSE_LIST_SEM_TAKE(tmout) \ semTake (usbMseListMutex, (int) (tmout))#define USB_MSE_LIST_SEM_GIVE \ semGive (usbMseListMutex)#define MSE_NAME_LEN_MAX 100#define USB_MSE_NAME "/usbMo/"/* data types *//* typedefs */ typedef struct usb_mse_node { NODE node; struct usb_mse_dev * pUsbMseDev; } USB_MSE_NODE;typedef struct usb_mse_dev /* USB_MSE_DEV */ { DEV_HDR ioDev; SIO_CHAN * pSioChan; UINT16 numOpen; UINT32 bufSize; UCHAR * buff; SEL_WAKEUP_LIST selList; USB_MSE_NODE * pUsbMseNode; } USB_MSE_DEV; /* local variables */LOCAL SEM_ID usbMseMutex; /* mutex semaphore */LOCAL SEM_ID usbMseListMutex; /* mutex semaphore to protect list */LOCAL UINT32 mseCount = 0;LOCAL LIST usbMseList; /* all USB mouses in the system */LOCAL SIO_CHAN *pMseSioChan;LOCAL HID_MSE_BOOT_REPORT *pReportlocal;LOCAL int usbMseDrvNum = 0; /* driver number *//* forward declarations */LOCAL void mseAttachCallback (void * arg, SIO_CHAN *pChan, UINT16 attachCode);LOCAL void usbMseDrvAttachCallback (void * arg, SIO_CHAN *pChan, UINT16 attachCode);LOCAL STATUS usbMseRptCallback (void *putReportArg, pHID_MSE_BOOT_REPORT pReport);LOCAL int usbMseRead (USB_MSE_DEV * pUsbMseDev,UCHAR *buffer, UINT32 nBytes);LOCAL int usbMseClose (USB_MSE_DEV * pUsbMseDev);LOCAL int usbMseWrite (USB_MSE_DEV * pUsbMseDev, UCHAR * buffer, UINT32 nBytes);LOCAL int usbMseOpen (USB_MSE_DEV * pUsbMseDev, char * name, int flags, int mode);LOCAL STATUS usbMseTxCallback (void *, char *);LOCAL int usbMseIoctl (USB_MSE_DEV * pUsbMseDev, int request, void * arg);LOCAL STATUS usbMseDevFind (SIO_CHAN *pChan, USB_MSE_DEV * pUsbMseDev);LOCAL STATUS usbMseDevDelete (USB_MSE_DEV * pUsbMseDev);/********************************************************************************* usbMseDevCreate - create a VxWorks device for an USB mouse** This routine creates a device on a specified serial channel. Each channel* to be used should have exactly one device associated with it by calling* this routine.** For instance, to create the device "/ /0", the proper call would be:* .CS* usbMseDevCreate ("/usbMo/0", pSioChan);* .CE* Where pSioChan is the address of the underlying SIO_CHAN serial channel* descriptor (defined in sioLib.h).* This routine is typically called by the USB mouse driver, when it detects * an insertion of a USB mouse.** RETURNS: OK, or ERROR if the driver is not installed, or the* device already exists, or failed to allocate memory.*/STATUS usbMseDevCreate ( char * name, /* name to use for this device */ SIO_CHAN * pSioChan /* pointer to core driver structure */ ) { USB_MSE_NODE * pUsbMseNode = NULL; /* pointer to device node */ USB_MSE_DEV * pUsbMseDev = NULL; /* pointer to USB device */ /* Create the mutex semaphores */ usbMseMutex = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); usbMseListMutex = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE); /* initialize the linked list */ lstInit (&usbMseList); usbMseDrvNum = iosDrvInstall ((FUNCPTR) NULL, (FUNCPTR) usbMseDevDelete, (FUNCPTR) usbMseOpen, (FUNCPTR) usbMseClose, (FUNCPTR) usbMseRead, (FUNCPTR) usbMseWrite, (FUNCPTR) usbMseIoctl); if (usbMseDrvNum <= 0) { errnoSet (S_ioLib_NO_DRIVER); return (ERROR); } if (pSioChan == (SIO_CHAN *) ERROR) { return (ERROR); } /* allocate memory for the device */ if ((pUsbMseDev = (USB_MSE_DEV *) calloc (1, sizeof (USB_MSE_DEV))) == NULL) return (ERROR); pUsbMseDev->pSioChan = pSioChan; /* allocate memory for this node, and populate it */ pUsbMseNode = (USB_MSE_NODE *) calloc (1, sizeof (USB_MSE_NODE)); /* record useful information */ pUsbMseNode->pUsbMseDev = pUsbMseDev; pUsbMseDev->pUsbMseNode = pUsbMseNode; /* add the node to the list */ USB_MSE_LIST_SEM_TAKE (WAIT_FOREVER); lstAdd (&usbMseList, (NODE *) pUsbMseNode); USB_MSE_LIST_SEM_GIVE; /* allow for select support */ selWakeupListInit (&pUsbMseDev->selList); /* start the device in the only supported mode */ sioIoctl (pUsbMseDev->pSioChan, SIO_MODE_SET, (void *) SIO_MODE_INT); /* add the device to the I/O system */ return (iosDevAdd (&pUsbMseDev->ioDev, name, usbMseDrvNum)); }/********************************************************************************* usbMseDevDelete - delete a VxWorks device for an USB mouse** This routine deletes a device on a specified serial channel. ** This routine is typically called by the USB mouse driver, when it detects * a removal of a USB mouse.** RETURNS: OK, or ERROR if the driver is not installed.*/LOCAL STATUS usbMseDevDelete ( USB_MSE_DEV * pUsbMseDev /* mouse device to read from */ ) { int status = OK; /* holder for the return value */ if (usbMseDrvNum <= 0) { errnoSet (S_ioLib_NO_DRIVER); return (ERROR); } /* remove the device from the I/O system */ iosDevDelete (&pUsbMseDev->ioDev); /* remove from list */ USB_MSE_LIST_SEM_TAKE (WAIT_FOREVER); lstDelete (&usbMseList, (NODE *) pUsbMseDev->pUsbMseNode); USB_MSE_LIST_SEM_GIVE; /* free memory for the device */ free (pUsbMseDev->pUsbMseNode); free (pUsbMseDev); return (status); }/*************************************************************************** usbMseDevFind - find the USB_MSE_DEV device for an SIO channel** RETURNS: OK, or ERROR*/ LOCAL STATUS usbMseDevFind ( SIO_CHAN * pChan, /* pointer to affected SIO_CHAN */ USB_MSE_DEV * pUsbMseDev /* pointer to an USB_MSE_DEV */ ) { USB_MSE_NODE * pUsbMseNode = NULL; /* pointer to USB device node */ USB_MSE_DEV * pTempDev; /* pointer to an USB_MSE_DEV */ if (pChan == NULL) return (ERROR); /* protect it from other module's routines */ USB_MSE_LIST_SEM_TAKE (WAIT_FOREVER); /* loop through all the devices */ for (pUsbMseNode = (USB_MSE_NODE *) lstFirst (&usbMseList); pUsbMseNode != NULL; pUsbMseNode = (USB_MSE_NODE *) lstNext ((NODE *) pUsbMseNode)) { pTempDev = pUsbMseNode->pUsbMseDev; /* return as soon as you find it */ if (pTempDev->pSioChan == pChan) { * (UINT32 *) pUsbMseDev = (UINT32) pTempDev; USB_MSE_LIST_SEM_GIVE; return (OK); } } USB_MSE_LIST_SEM_GIVE; return (ERROR); }/*************************************************************************** mseAttachCallback - receives attach callbacks from mouse SIO driver** RETURNS: N/A*/LOCAL void mseAttachCallback ( void * arg, /* caller-defined argument */ SIO_CHAN *pChan, /* pointer to affected SIO_CHAN */ UINT16 attachCode /* defined as USB_KBD_xxxx */ ) { UINT32 usbMseDev; /* mouse device */ char mseName [MSE_NAME_LEN_MAX]; /* mouse name */ if (attachCode == USB_MSE_ATTACH)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -