?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /******************************************************************************
2  
3 USB Host Communication Device Class(CDC) Interface file
4  
5 This file provides all the interface functions to the CDC host client driver.
6 This file should be used in a project with usb_host_cdc.c to provide access
7 to CDC host.
8  
9 Acronyms/abbreviations used by this class:
10 * CDC - Communication Device Class
11 * ACM - Abstract Control Module
12  
13 This file provides interface functions for USB CDC host to the application.
14 These interface function can be used to set up transfers with the device attached
15 on the bus. Interface function USBHostCDC_Api_Get_IN_Data can be used to set up
16 transfer request to receive data from the device.Interface function
17 USBHostCDC_Api_Send_OUT_Data can be used to set up transfer request to send
18 data to the device. If USB_ENABLE_TRANSFER_EVENT is defined application will receive
19 an event on completion of transfer request otherwise application can poll the status
20 of transfer using function USBHostCDC_ApiTransferIsComplete. This file also provides
21 interface routine for ACM class specific requests in function USBHostCDC_Api_ACM_Request.
22  
23 FileName: usb_host_cdc_interface.c
24 Dependencies: None
25 Processor: PIC24/dsPIC30/dsPIC33/PIC32MX
26 Compiler: C30 v2.01/C32 v0.00.18
27 Company: Microchip Technology, Inc.
28  
29 Software License Agreement
30  
31 The software supplied herewith by Microchip Technology Incorporated
32 (the “Company”) for its PICmicro® Microcontroller is intended and
33 supplied to you, the Company’s customer, for use solely and
34 exclusively on Microchip PICmicro Microcontroller products. The
35 software is owned by the Company and/or its supplier, and is
36 protected under applicable copyright laws. All rights are reserved.
37 Any use in violation of the foregoing restrictions may subject the
38 user to criminal sanctions under applicable laws, as well as to
39 civil liability for the breach of the terms and conditions of this
40 license.
41  
42 THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
43 WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
44 TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
45 PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
46 IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
47 CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
48  
49 Change History:
50 Rev Description
51 ----- -----------
52 v2.6a No change
53  
54 2.7 Modified the code to allow connection of USB-RS232 dongles that do
55 not fully comply with CDC specifications
56  
57 Modified API USBHostCDC_Api_Send_OUT_Data to allow data transfers
58 more than 256 bytes
59  
60 2.7a No change
61 ********************************************************************************/
62 #include <stdlib.h>
63 #include <string.h>
64 #include "GenericTypeDefs.h"
65 #include "HardwareProfile.h"
66 #include "usb_config.h"
67 #include "USB\usb.h"
68 #include "USB\usb_host_cdc.h"
69 #include "USB\usb_host_cdc_interface.h"
70  
71  
72 // *****************************************************************************
73 // *****************************************************************************
74 // Constants
75 // *****************************************************************************
76 // *****************************************************************************
77  
78 // *****************************************************************************
79 // State Machine Constants
80 // *****************************************************************************
81 //******************************************************************************
82 //******************************************************************************
83 // Data Structures
84 //******************************************************************************
85 //******************************************************************************
86  
87 //******************************************************************************
88 //******************************************************************************
89 // Section: Local Prototypes
90 //******************************************************************************
91 //******************************************************************************
92 //******************************************************************************
93 //******************************************************************************
94 // Macros
95 //******************************************************************************
96 //******************************************************************************
97  
98  
99 //******************************************************************************
100 //******************************************************************************
101 // Section: CDC Host Global Variables
102 //******************************************************************************
103 //******************************************************************************
104  
105 //******************************************************************************
106 //******************************************************************************
107 // Section: CDC Host External Variables
108 //******************************************************************************
109 //******************************************************************************
110 extern USB_CDC_DEVICE_INFO deviceInfoCDC[] __attribute__ ((aligned));
111 extern BYTE CDCdeviceAddress ;
112  
113 //******************************************************************************
114 //******************************************************************************
115 // Section: CDC Host Global Variables
116 //******************************************************************************
117 //******************************************************************************
118  
119  
120 /****************************************************************************
121 Function:
122 BOOL USBHostCDC_Api_Get_IN_Data(BYTE no_of_bytes, BYTE* data)
123  
124 Description:
125 This function is called by application to receive Input data over DATA
126 interface. This function setsup the request to receive data from the device.
127  
128 Precondition:
129 None
130  
131 Parameters:
132 BYTE no_of_bytes - No. of Bytes expected from the device.
133 BYTE* data - Pointer to application receive data buffer.
134  
135 Return Values:
136 TRUE - Transfer request is placed successfully.
137 FALSE - Transfer request failed.
138  
139 Remarks:
140 None
141 ***************************************************************************/
142 BOOL USBHostCDC_Api_Get_IN_Data(BYTE no_of_bytes, BYTE* data)
143 {
144 BYTE i;
145  
146 for (i=0; (i<USB_MAX_CDC_DEVICES) && (deviceInfoCDC[i].deviceAddress != CDCdeviceAddress); i++);
147  
148 if(!USBHostCDCRead_DATA(CDCdeviceAddress, deviceInfoCDC[i].dataInterface.interfaceNum,
149 no_of_bytes,data,deviceInfoCDC[i].dataInterface.endpointIN))
150 {
151 return TRUE;
152 }
153 return FALSE;
154 }
155  
156  
157 /****************************************************************************
158 Function:
159 BOOL USBHostCDC_Api_Send_OUT_Data(BYTE no_of_bytes, BYTE* data)
160  
161 Description:
162 This function is called by application to transmit out data over DATA
163 interface. This function setsup the request to transmit data to the
164 device.
165  
166 Precondition:
167 None
168  
169 Parameters:
170 BYTE no_of_bytes - No. of Bytes expected from the device.
171 BYTE* data - Pointer to application transmit data buffer.
172  
173  
174 Return Values:
175 TRUE - Transfer request is placed successfully.
176 FALSE - Transfer request failed.
177  
178 Remarks:
179 None
180 ***************************************************************************/
181 BOOL USBHostCDC_Api_Send_OUT_Data(WORD no_of_bytes, BYTE* data)
182 {
183 BYTE i;
184  
185 for (i=0; (i<USB_MAX_CDC_DEVICES) && (deviceInfoCDC[i].deviceAddress != CDCdeviceAddress); i++);
186  
187 if(!USBHostCDCSend_DATA(CDCdeviceAddress, deviceInfoCDC[i].dataInterface.interfaceNum,
188 no_of_bytes,data,deviceInfoCDC[i].dataInterface.endpointOUT))
189 {
190 return TRUE;
191 }
192 return FALSE;
193 }
194  
195  
196 /****************************************************************************
197 Function:
198 BOOL USBHostCDC_ApiTransferIsComplete(BYTE* errorCodeDriver,BYTE* byteCount)
199  
200 Description:
201 This function is called by application to poll for transfer status. This
202 function returns true in the transfer is over. To check whether the transfer
203 was successfull or not , application must check the error code returned by
204 reference.
205  
206 Precondition:
207 None
208  
209 Parameters:
210 BYTE *errorCodeDriver - returns.
211 BYTE *byteCount - No. of bytes transferred.
212  
213  
214 Return Values:
215 TRUE - Transfer is has completed.
216 FALSE - Transfer is pending.
217  
218 Remarks:
219 None
220 ***************************************************************************/
221 BOOL USBHostCDC_ApiTransferIsComplete(BYTE* errorCodeDriver, BYTE* byteCount )
222 {
223 return(USBHostCDCTransferIsComplete(CDCdeviceAddress,errorCodeDriver,byteCount));
224 }
225  
226 /*******************************************************************************
227 Function:
228 BOOL USBHostCDC_ApiDeviceDetect( void )
229  
230 Description:
231 This function determines if a CDC device is attached
232 and ready to use.
233  
234 Precondition:
235 None
236  
237 Parameters:
238 None
239  
240 Return Values:
241 TRUE - CDC present and ready
242 FALSE - CDC not present or not ready
243  
244 Remarks:
245 Since this will often be called in a loop while waiting for
246 a device, we'll make sure the tasks are executed.
247 *******************************************************************************/
248 BOOL USBHostCDC_ApiDeviceDetect( void )
249 {
250 USBHostTasks();
251 USBHostCDCTasks();
252  
253 if ((USBHostCDCDeviceStatus(CDCdeviceAddress) == USB_CDC_NORMAL_RUNNING) &&
254 (CDCdeviceAddress != 0))
255 {
256 return TRUE;
257 }
258  
259 return FALSE;
260 }
261  
262  
263 /*******************************************************************************
264 Function:
265 BYTE USBHostCDC_Api_ACM_Request(BYTE requestType, BYTE size, BYTE* data)
266  
267 Description:
268 This function can be used by application code to dynamically access ACM specific
269 requests. This function should be used only if apllication intends to modify for
270 example the Baudrate from previouly configured rate. Data transmitted/received
271 to/from device is a array of bytes. Application must take extra care of understanding
272 the data format before using this function.
273  
274 Precondition:
275 Device must be enumerated and attached successfully.
276  
277 Parameters:
278 BYTE requestType - USB_CDC_SEND_ENCAPSULATED_COMMAND
279 - USB_CDC_GET_ENCAPSULATED_REQUEST
280 - USB_CDC_SET_LINE_CODING
281 - USB_CDC_SET_CONTROL_LINE_STATE
282 - USB_CDC_SET_CONTROL_LINE_STATE
283 These are the mandatory CDC request supported by the
284 CDC host stack.
285 BYTE size - No of bytes to be transferred.
286 BYTE *data - Pointer to data being transferred.
287  
288 Return Values:
289 USB_SUCCESS - Request started successfully
290 USB_CDC_DEVICE_NOT_FOUND - No device with specified address
291 USB_CDC_DEVICE_BUSY - Device not in proper state for
292 performing a transfer
293 USB_CDC_COMMAND_FAILED - Request is not supported.
294 USB_CDC_ILLEGAL_REQUEST - Requested ID is invalid.
295  
296 Remarks:
297 None
298 *******************************************************************************/
299 BYTE USBHostCDC_Api_ACM_Request(BYTE requestType, BYTE size, BYTE* data)
300 {
301 BYTE i;
302 BYTE return_val = USB_CDC_COMMAND_FAILED;
303  
304 // Find the correct device.
305 for (i=0; (i<USB_MAX_CDC_DEVICES) && (deviceInfoCDC[i].deviceAddress != CDCdeviceAddress); i++);
306 if (i == USB_MAX_CDC_DEVICES)
307 {
308 return USB_CDC_DEVICE_NOT_FOUND;
309 }
310  
311 switch(requestType)
312 {
313 case USB_CDC_SEND_ENCAPSULATED_COMMAND :
314 return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_SEND_ENCAPSULATED_COMMAND,0,
315 deviceInfoCDC[i].commInterface.interfaceNum,size,data,
316 0);
317 break;
318 case USB_CDC_GET_ENCAPSULATED_REQUEST :
319 return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_GET_ENCAPSULATED_REQUEST,1,
320 deviceInfoCDC[i].commInterface.interfaceNum,size,data,
321 0);
322 break;
323  
324 case USB_CDC_SET_COMM_FEATURE :
325 break;
326  
327 case USB_CDC_GET_COMM_FEATURE :
328 break;
329  
330 case USB_CDC_SET_LINE_CODING :
331 return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_SET_LINE_CODING,0,
332 deviceInfoCDC[i].commInterface.interfaceNum,size,data,
333 0);
334 break;
335  
336 case USB_CDC_GET_LINE_CODING :
337 return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_GET_LINE_CODING,1,
338 deviceInfoCDC[i].commInterface.interfaceNum,size,data,
339 0);
340 break;
341  
342 case USB_CDC_SET_CONTROL_LINE_STATE :
343 return_val = USBHostCDCTransfer(CDCdeviceAddress, USB_CDC_SET_CONTROL_LINE_STATE,0,
344 deviceInfoCDC[i].commInterface.interfaceNum,size,data,
345 0);
346 break;
347  
348 case USB_CDC_SEND_BREAK :
349 break;
350 default:
351 return USB_CDC_ILLEGAL_REQUEST;
352 break;
353 }
354 return return_val;
355 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3