usb_phdc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /******************************************************************************
  2. *
  3. * Freescale Semiconductor Inc.
  4. * (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
  5. * ALL RIGHTS RESERVED.
  6. *
  7. ******************************************************************************
  8. *
  9. * THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
  10. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  11. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  12. * IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  13. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  15. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  16. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  17. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  18. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  19. * THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. **************************************************************************//*!
  22. *
  23. * @file usb_phdc.h
  24. *
  25. * @author
  26. *
  27. * @version
  28. *
  29. * @date
  30. *
  31. * @brief The file contains USB stack PHDC class layer API header function.
  32. *
  33. *****************************************************************************/
  34. #ifndef _USB_PHDC_H
  35. #define _USB_PHDC_H
  36. /******************************************************************************
  37. * Includes
  38. *****************************************************************************/
  39. #include "types.h"
  40. #include "usb_class.h"
  41. #include "usb_descriptor.h"
  42. #ifdef COMPOSITE_DEV
  43. #include "usb_composite.h"
  44. #endif
  45. /******************************************************************************
  46. * Constants - None
  47. *****************************************************************************/
  48. /******************************************************************************
  49. * Macro's
  50. *****************************************************************************/
  51. #define MAX_QOS_BIN_ELEMS (4)
  52. #define PHDC_RX_ENDPOINTS (1)/* the num of receive endpoints */
  53. #ifndef _MC9S08JS16_H
  54. #define PHDC_TX_ENDPOINTS (2)/* the num of transmit endpoints*/
  55. #else
  56. #define PHDC_TX_ENDPOINTS (1)/* the num of transmit endpoints*/
  57. #endif
  58. #define SET_FEATURE_REQUEST (3)
  59. #define CLEAR_FEATURE_REQUEST (1)
  60. #define GET_STATUS_REQUEST (0)
  61. #define INVALID_VAL (0xFF)
  62. #define USB_SET_REQUEST_MASK (0x02)
  63. #define USB_APP_META_DATA_PARAMS_CHANGED (0xF2)
  64. #define USB_APP_FEATURE_CHANGED (0xF3)
  65. #ifndef COMPOSITE_DEV
  66. #if !(defined LITTLE_ENDIAN)
  67. #define BYTE_SWAP16(a) (a)
  68. #else
  69. #define BYTE_SWAP16(a) (uint_16)((((uint_16)(a)&0xFF00)>>8) | \
  70. (((uint_16)(a)&0x00FF)<<8))
  71. #endif
  72. #endif
  73. /******************************************************************************
  74. * Types
  75. *****************************************************************************/
  76. #ifndef __HIWARE__
  77. #pragma pack(1)
  78. #endif
  79. /* structure to hold a request in the endpoint QOS bin */
  80. typedef struct _usb_class_phdc_qos_bin
  81. {
  82. uint_8 controller_ID; /* Controller ID*/
  83. uint_8 channel; /* Endpoint number */
  84. boolean meta_data; /* Packet is a meta data or not */
  85. uint_8 num_tfr; /* Num of transfers that follow the meta
  86. data packet.
  87. used only when meta_data is TRUE */
  88. uint_8 qos; /* Qos of the transfers that follow the meta
  89. data packet */
  90. uint_8_ptr app_buff; /* Buffer to send */
  91. USB_PACKET_SIZE size; /* Size of the transfer */
  92. }USB_CLASS_PHDC_QOS_BIN, *PTR_USB_CLASS_PHDC_QOS_BIN;
  93. /* USB class phdc Transmit endpoint data */
  94. typedef struct _usb_class_phdc_tx_endpoint
  95. {
  96. uint_8 endpoint; /* from the application */
  97. uint_8 type; /* from the application */
  98. USB_PACKET_SIZE size; /* from the application */
  99. uint_8 qos; /* from the application */
  100. uint_8 current_qos; /* from received meta data */
  101. uint_8 transfers_queued; /* from application meta data */
  102. uint_8 bin_consumer; /* num of dequeued transfers */
  103. uint_8 bin_producer; /* num of queued transfers */
  104. uint_16 transfer_size; /* Transfer Size */
  105. uint_16 current_offset; /* Offset into Tranfer Size */
  106. USB_CLASS_PHDC_QOS_BIN qos_bin[MAX_QOS_BIN_ELEMS];
  107. }USB_CLASS_PHDC_TX_ENDPOINT;
  108. /* USB class phdc Receive endpoint data */
  109. typedef struct _usb_class_phdc_rx_endpoint
  110. {
  111. uint_8 endpoint; /* from the application */
  112. uint_8 type; /* from the application */
  113. USB_PACKET_SIZE size; /* from the application */
  114. uint_8 qos; /* from the application */
  115. uint_8 current_qos; /* from received meta data */
  116. uint_8 transfers_left; /* from received meta data */
  117. uint_16 buffer_size; /* Application Buffer Size */
  118. uint_8_ptr buff_ptr; /* Application Buffer Ptr */
  119. uint_16 transfer_size; /* Transfer Size */
  120. uint_16 cur_offset; /* Offset into Transfer Size */
  121. }USB_CLASS_PHDC_RX_ENDPOINT;
  122. /* USB class phdc endpoint data */
  123. typedef struct _usb_class_phdc_endpoint_data
  124. {
  125. /* Number of recv non control endpoints */
  126. uint_8 count_rx;
  127. /* Number of send non control endpoints */
  128. uint_8 count_tx;
  129. /* Receive endpoint info structure */
  130. USB_CLASS_PHDC_RX_ENDPOINT ep_rx[PHDC_RX_ENDPOINTS];
  131. /* Send endpoint info structure */
  132. USB_CLASS_PHDC_TX_ENDPOINT ep_tx[PHDC_TX_ENDPOINTS];
  133. }USB_CLASS_PHDC_ENDPOINT_DATA, *PTR_USB_CLASS_PHDC_ENDPOINT_DATA;
  134. /* USB class phdc Transfer Size */
  135. typedef struct _usb_class_phdc_xfer_size
  136. {
  137. uint_8 direction; /* Direction of Xfer */
  138. uint_8_ptr in_buff; /* Pointer to Buffer */
  139. USB_PACKET_SIZE in_size; /* Length of Buffer */
  140. uint_16 transfer_size; /* Transfer Size */
  141. #if USB_METADATA_SUPPORTED
  142. boolean meta_data_packet; /* meta data packet flag */
  143. #endif
  144. }USB_CLASS_PHDC_XFER_SIZE, *PTR_USB_CLASS_PHDC_XFER_SIZE;
  145. /* USB class PHDC Receive Buffer */
  146. typedef struct _usb_class_phdc_rx_buff
  147. {
  148. uint_8_ptr in_buff; /* Pointer to input Buffer */
  149. USB_PACKET_SIZE in_size; /* Length of Input Buffer*/
  150. uint_16 out_size; /* Size of Output Buffer */
  151. uint_8_ptr out_buff; /* Pointer to Output Buffer */
  152. uint_16 transfer_size;
  153. uint_8 qos; /* Tranfer QOS */
  154. #if USB_METADATA_SUPPORTED
  155. boolean meta_data_packet;/* meta data packet flag */
  156. #endif
  157. }USB_CLASS_PHDC_RX_BUFF, *PTR_USB_CLASS_PHDC_RX_BUFF;
  158. /* event structures */
  159. typedef struct _usb_app_event_send_complete
  160. {
  161. uint_8 qos; /* Qos of the data sent */
  162. uint_8_ptr buffer_ptr; /* Pointer to the buffer sent */
  163. USB_PACKET_SIZE size; /* Size of the data sent */
  164. }USB_APP_EVENT_SEND_COMPLETE, *PTR_USB_APP_EVENT_SEND_COMPLETE;
  165. /* USB class PHDC Data Received */
  166. typedef struct _usb_app_event_data_received
  167. {
  168. uint_8 qos; /* Qos of the data received */
  169. uint_8_ptr buffer_ptr; /* Pointer to the data received */
  170. USB_PACKET_SIZE size; /* Size of the data received */
  171. uint_16 transfer_size; /* Total transfer Size */
  172. }USB_APP_EVENT_DATA_RECEIVED, *PTR_USB_APP_EVENT_DATA_RECEIVED;
  173. /* PHDC error codes */
  174. typedef enum _usb_phdc_error
  175. {
  176. USB_PHDC_SUCCESS = 0,
  177. #if USB_METADATA_SUPPORTED
  178. USB_PHDC_METADATA_EXPECTED_NOT_RECEIVED = 256,
  179. USB_PHDC_METADATA_RECEIVED_NOT_EXPECTED = 257,
  180. USB_PHDC_CORRUPT_METADATA_PACKET_RECEIVED = 258,
  181. #endif
  182. }USB_PHDC_ERROR;
  183. /* PHDC error structure */
  184. typedef struct _usb_phdc_error_struct
  185. {
  186. USB_PHDC_ERROR error_code; /* PHDC Error Code */
  187. uint_8 qos; /* Tranfer QOS */
  188. }USB_PHDC_ERROR_STRUCT, *PTR_USB_PHDC_ERROR_STRUCT;
  189. #if USB_METADATA_SUPPORTED
  190. #define METADATA_PREAMBLE_SIGNATURE (16)
  191. #define METADATA_QOSENCODING_VERSION (1)
  192. #define METADATA_HEADER_SIZE (20)
  193. /* structure for meta_data msg preamble */
  194. typedef struct _usb_meta_data_msg_preamble
  195. {
  196. /*Meta data string for verifiability*/
  197. char signature[METADATA_PREAMBLE_SIGNATURE];
  198. /* Number of transfers to follow the meta data packet */
  199. uint_8 num_tfr;
  200. /* QOS encoding version */
  201. uint_8 version;
  202. /* QOS of the transfers to follow */
  203. uint_8 qos;
  204. /* Size of the opaque meta data */
  205. uint_8 opaque_data_size;
  206. /* Opaque meta data */
  207. uint_8 opaque_data[1];
  208. }USB_META_DATA_MSG_PREAMBLE, *PTR_USB_META_DATA_MSG_PREAMBLE;
  209. /* USB class PHDC Metadata Params */
  210. typedef struct _usb_app_event_metadata_params
  211. {
  212. uint_8 channel; /* Endpoint number */
  213. uint_8 num_tfr; /* Number of transfers */
  214. uint_8 qos; /* QOS of the data */
  215. uint_8_ptr metadata_ptr; /* pointer to the meta data */
  216. USB_PACKET_SIZE size; /* Size of the transfer */
  217. }USB_APP_EVENT_METADATA_PARAMS, *PTR_USB_APP_EVENT_METADATA_PARAMS;
  218. #endif
  219. #if defined(__CWCC__)
  220. #pragma options align=reset
  221. #elif defined(__IAR_SYSTEMS_ICC__)
  222. #pragma pack()
  223. #endif
  224. /******************************************************************************
  225. * Global Functions
  226. *****************************************************************************/
  227. extern uint_8 USB_Class_PHDC_Init (
  228. uint_8 controller_ID,
  229. USB_CLASS_CALLBACK phdc_class_callback,
  230. USB_REQ_FUNC vendor_req_callback
  231. );
  232. extern uint_8 USB_Phdc_Other_Requests(uint_8 controller_ID,
  233. USB_SETUP_STRUCT*setup_packet,
  234. uint_8_ptr *data,
  235. USB_PACKET_SIZE *size);
  236. #ifdef COMPOSITE_DEV
  237. extern void USB_Class_PHDC_Event (
  238. uint_8 controller_ID, /* [IN] Controller ID */
  239. uint_8 event, /* [IN] Event Type */
  240. void* val /* [IN] Pointer to configuration Value */
  241. );
  242. #endif
  243. void USB_Class_PHDC_Endpoint_Service (
  244. PTR_USB_DEV_EVENT_STRUCT event /* [IN] Pointer to USB Event Structure */
  245. );
  246. extern uint_8 USB_Class_PHDC_DeInit
  247. (
  248. uint_8 controller_ID
  249. );
  250. extern uint_8 USB_Class_PHDC_Send_Data (
  251. uint_8 controller_ID,
  252. boolean meta_data,
  253. uint_8 num_tfr,
  254. uint_8 current_qos,
  255. uint_8_ptr app_buff,
  256. USB_PACKET_SIZE size
  257. );
  258. #define USB_Class_PHDC_Periodic_Task USB_Class_Periodic_Task
  259. extern uint_8 USB_Class_PHDC_Recv_Data (
  260. uint_8 controller_ID,
  261. uint_8 current_qos,
  262. uint_8_ptr app_buff,
  263. USB_PACKET_SIZE size
  264. );
  265. #endif