virtual_com.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _USB_CDC_VCOM_H_
  35. #define _USB_CDC_VCOM_H_ 1
  36. #include "usb_device_descriptor.h"
  37. #include "fsl_common.h"
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
  42. #define CONTROLLER_ID kUSB_ControllerEhci0
  43. #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
  44. #endif /* USB_DEVICE_CONFIG_EHCI */
  45. #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
  46. #define CONTROLLER_ID kUSB_ControllerKhci0
  47. #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
  48. #endif /* USB_DEVICE_CONFIG_KHCI */
  49. #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
  50. #define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0
  51. #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
  52. #endif /* USB_DEVICE_CONFIG_LPCIP3511FS */
  53. #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
  54. #define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0
  55. #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
  56. #endif /* USB_DEVICE_CONFIG_LPCIP3511HS */
  57. #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)
  58. #define CONTROLLER_ID kUSB_ControllerLpcIp3511Fs0
  59. #define DATA_BUFF_SIZE FS_CDC_VCOM_BULK_OUT_PACKET_SIZE
  60. #endif
  61. #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)
  62. #define CONTROLLER_ID kUSB_ControllerLpcIp3511Hs0
  63. #define DATA_BUFF_SIZE HS_CDC_VCOM_BULK_OUT_PACKET_SIZE
  64. #endif
  65. #define USB_DEVICE_INTERRUPT_PRIORITY (3U)
  66. /* Currently configured line coding */
  67. #define LINE_CODING_SIZE (0x07)
  68. #define LINE_CODING_DTERATE (115200)
  69. #define LINE_CODING_CHARFORMAT (0x00)
  70. #define LINE_CODING_PARITYTYPE (0x00)
  71. #define LINE_CODING_DATABITS (0x08)
  72. /* Communications feature */
  73. #define COMM_FEATURE_DATA_SIZE (0x02)
  74. #define STATUS_ABSTRACT_STATE (0x0000)
  75. #define COUNTRY_SETTING (0x0000)
  76. /* Notification of serial state */
  77. #define NOTIF_PACKET_SIZE (0x08)
  78. #define UART_BITMAP_SIZE (0x02)
  79. #define NOTIF_REQUEST_TYPE (0xA1)
  80. /* Define the types for application */
  81. typedef struct _usb_cdc_vcom_struct
  82. {
  83. usb_device_handle deviceHandle; /* USB device handle. */
  84. volatile uint8_t attach; /* A flag to indicate whether a usb device is attached. 1: attached, 0: not attached */
  85. uint8_t speed; /* Speed of USB device. USB_SPEED_FULL/USB_SPEED_LOW/USB_SPEED_HIGH. */
  86. volatile uint8_t
  87. startTransactions; /* A flag to indicate whether a CDC device is ready to transmit and receive data. */
  88. uint8_t currentConfiguration; /* Current configuration value. */
  89. uint8_t currentInterfaceAlternateSetting
  90. [USB_CDC_VCOM_INTERFACE_COUNT]; /* Current alternate setting value for each interface. */
  91. } usb_cdc_vcom_struct_t;
  92. /* Define the infomation relates to abstract control model */
  93. typedef struct _usb_cdc_acm_info
  94. {
  95. uint8_t serialStateBuf[NOTIF_PACKET_SIZE + UART_BITMAP_SIZE]; /* Serial state buffer of the CDC device to notify the
  96. serial state to host. */
  97. bool dtePresent; /* A flag to indicate whether DTE is present. */
  98. uint16_t breakDuration; /* Length of time in milliseconds of the break signal */
  99. uint8_t dteStatus; /* Status of data terminal equipment */
  100. uint8_t currentInterface; /* Current interface index. */
  101. uint16_t uartState; /* UART state of the CDC device. */
  102. } usb_cdc_acm_info_t;
  103. /*******************************************************************************
  104. * Prototypes
  105. ******************************************************************************/
  106. /*!
  107. * @brief Application initialization function.
  108. *
  109. * This function initializes the application.
  110. *
  111. * @return pointer to USB device handle.
  112. */
  113. usb_device_handle USB_VcomInit(void);
  114. /*!
  115. * @brief Application initialization function.
  116. *
  117. * This function initializes the application.
  118. *
  119. * @return pointer to USB device handle.
  120. */
  121. void USB_VcomDeinit(usb_device_handle deviceHandle);
  122. /*!
  123. * @brief USB recive data from host using a blocking method.
  124. *
  125. * This function recives data from host by usb cdc protocol
  126. * @param baseAddr pointer to USB device handle.
  127. * @param buf pointer to the data.
  128. * @param count size of the transfer.
  129. *
  130. * @return A USB error code or kStatus_USB_Success.
  131. */
  132. status_t USB_VcomReadBlocking(usb_device_handle baseAddr, uint8_t *buf, size_t count);
  133. /*!
  134. * @brief USB recive 'count' number of data from host using a blocking method.
  135. *
  136. * This function recives data from host by usb cdc protocol
  137. * @param baseAddr pointer to USB device handle.
  138. * @param buf pointer to the data.
  139. * @param count size of the transfer.
  140. *
  141. * @return A USB error code or kStatus_USB_Success.
  142. */
  143. status_t USB_VcomReadPolling(usb_device_handle baseAddr, uint8_t *buf, size_t count);
  144. /*!
  145. * @brief USB send data to host using a blocking method.
  146. *
  147. * This function sends data to host by usb cdc protocol
  148. * @param baseAddr pointer to USB device handle.
  149. * @param buf pointer to the data.
  150. * @param count size of the transfer.
  151. *
  152. * @return None.
  153. */
  154. void USB_VcomWriteBlocking(usb_device_handle baseAddr, const uint8_t *buf, size_t count);
  155. #endif /* _USB_CDC_VCOM_H_ */