usrUsbAcmInit.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:4k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrUsbAcmInit.c - USB ACM class driver initialization */
  2. /* Copyright 2000-2001 Wind River Systems, Inc. */
  3. /*
  4. Modification history
  5. --------------------
  6. 01a,09jan00,wef  Created
  7. */
  8.  
  9. /*
  10. DESCRIPTION
  11.  
  12. This configlette initializes the USB ACM Communication class driver.  This
  13. driver is intended for USB modems.  This configlette assumes the USB host 
  14. stack has already been initialized and has a host controller driver attached.
  15. This file also contains routines that are used to issue AT commands to the
  16. modem.  These are given here for testing purposes and are intended to show
  17. how communication to the modem should be in a typical application.
  18. Parameters 
  19. ACM_TYCO_CHAN_NUMBER - channel that the ACM device will be installed on.
  20. */
  21. /* includes */
  22. #include "vxWorks.h"
  23. #include "string.h"
  24. #include "sioLib.h"
  25. #include "errno.h"
  26. #include "ctype.h"
  27. #include "logLib.h"
  28. #include "usb/usbPlatform.h"
  29. #include "usb/ossLib.h"     /* operations system srvcs */
  30. #include "usb/usb.h"     /* general USB definitions */
  31. #include "usb/usbListLib.h"     /* linked list functions */
  32. #include "usb/usbdLib.h"     /* USBD interface */
  33. #include "usb/usbLib.h"     /* USB utility functions */
  34. #include "usb/usbCommdevices.h"
  35. #include "drv/usb/usbAcmLib.h"      /* our API */
  36. /* locals */
  37. int noOfAcmChans = 0; /* Count of acm channel structs */
  38. /***************************************************************************
  39. *
  40. * usbAcmAttachCallback- ACM class driver Registration
  41. *
  42. * This function the what happens when a new modem is plugged in or an 
  43. * existing modem is disconnected.  It is responsible for creating the tty
  44. * device and installing it into the I/O system.
  45. *
  46. *
  47. * RETURNS: OK or Error
  48. */
  49. STATUS usbAcmAttachCallback 
  50.     (
  51.     pVOID arg, 
  52.     SIO_CHAN *pChan,
  53.     UINT16 callbackType, 
  54.     UINT8* ptr1, 
  55.     UINT16 ct
  56.     )
  57.     {
  58.     char tyName [20]; /* string for device name */
  59.     char tyPtr [20];
  60.     DEV_HDR * pDevice;
  61.     USB_ACM_SIO_CHAN * pSioChan = (USB_ACM_SIO_CHAN *)pChan;
  62.     tyName[0] = ''; /* initialize to null string */
  63.     strcat (tyName, "/tyCo/");
  64.     if(callbackType == USB_ACM_CALLBACK_ATTACH)
  65. {
  66. logMsg (" New modem attached n",0 ,0 ,0, 0, 0, 0);
  67. pSioChan->unitNo = noOfAcmChans;
  68. /* after 2 default serial ports */
  69. strcat (tyName, itos (pSioChan->unitNo + ACM_TYCO_CHAN_NUMBER));     
  70. if(ttyDevCreate (tyName, (SIO_CHAN *)pSioChan, 512, 512) == ERROR)
  71.     {
  72.     logMsg (" %s could not be added to the dev list n", tyName,
  73.         0 ,0 ,0, 0, 0);
  74.     return ERROR;
  75.     }
  76. else
  77.     logMsg (" %s successfully added to dev list n", tyName,
  78.     0 ,0 ,0, 0, 0);
  79.     
  80. noOfAcmChans++;
  81. }
  82.     else if(callbackType == USB_ACM_CALLBACK_DETACH)
  83. {
  84. logMsg ("Modem removed n",0 ,0 ,0, 0, 0, 0);
  85. strcat (tyName, itos (pSioChan->unitNo + ACM_TYCO_CHAN_NUMBER));     /* after 2 default serial ports */
  86. pDevice = iosDevFind(tyName, (char *) &tyPtr);
  87. if (pDevice == NULL)
  88.     {
  89.     logMsg ("%s not found", tyName,0 ,0 ,0, 0, 0);
  90.     return ERROR;
  91.     }
  92. iosDevDelete(pDevice);
  93. logMsg (" %s removed from dev list n", tyName,0 ,0 ,0, 0, 0);
  94. noOfAcmChans--;
  95. }
  96.     return OK;
  97.     }
  98. /*************************************************************************
  99. *
  100. * usrUsbAcmInit - initializes USB ACM class driver.
  101. *
  102. * RETURNS: Nothing
  103. */
  104. void usrUsbAcmInit (void)
  105.     {
  106.     /* Initialize the BULK class driver */
  107.  
  108.     if (usbAcmLibInit () != OK)
  109. logMsg ("usbAcmLibInit() returned ERRORn",0 ,0 ,0, 0, 0, 0);
  110.  
  111.     /* Register for acm device attachment/removal */
  112.     if( usbAcmCallbackRegister (NULL,
  113.         USB_ACM_CALLBACK_ATTACH, 
  114.         (FUNCPTR) usbAcmAttachCallback,
  115.         0) 
  116.      == ERROR)
  117. logMsg ("usbAcmCallbackRegister() returned ERRORn",0 ,0 ,0, 0, 0, 0);
  118.     }