|
1 /********************************************************************* |
|
2 * |
|
3 * Microchip USB C18 Firmware - CDC Version 1.0 |
|
4 * |
|
5 ********************************************************************* |
|
6 * FileName: cdc.h |
|
7 * Dependencies: See INCLUDES section below |
|
8 * Processor: PIC18 |
|
9 * Compiler: C18 2.30.01+ |
|
10 * Company: Microchip Technology, Inc. |
|
11 * |
|
12 * Software License Agreement |
|
13 * |
|
14 * The software supplied herewith by Microchip Technology Incorporated |
|
15 * (the “Company”) for its PICmicro® Microcontroller is intended and |
|
16 * supplied to you, the Company’s customer, for use solely and |
|
17 * exclusively on Microchip PICmicro Microcontroller products. The |
|
18 * software is owned by the Company and/or its supplier, and is |
|
19 * protected under applicable copyright laws. All rights are reserved. |
|
20 * Any use in violation of the foregoing restrictions may subject the |
|
21 * user to criminal sanctions under applicable laws, as well as to |
|
22 * civil liability for the breach of the terms and conditions of this |
|
23 * license. |
|
24 * |
|
25 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, |
|
26 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED |
|
27 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
|
28 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, |
|
29 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR |
|
30 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
|
31 * |
|
32 * Author Date Comment |
|
33 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
34 * Rawin Rojvanit 7/21/04 Original. |
|
35 ********************************************************************/ |
|
36 #ifndef CDC_H |
|
37 #define CDC_H |
|
38 |
|
39 /** I N C L U D E S **********************************************************/ |
|
40 #include "typedefs.h" |
|
41 |
|
42 /** D E F I N I T I O N S ****************************************************/ |
|
43 |
|
44 /* Class-Specific Requests */ |
|
45 #define SEND_ENCAPSULATED_COMMAND 0x00 |
|
46 #define GET_ENCAPSULATED_RESPONSE 0x01 |
|
47 #define SET_COMM_FEATURE 0x02 |
|
48 #define GET_COMM_FEATURE 0x03 |
|
49 #define CLEAR_COMM_FEATURE 0x04 |
|
50 #define SET_LINE_CODING 0x20 |
|
51 #define GET_LINE_CODING 0x21 |
|
52 #define SET_CONTROL_LINE_STATE 0x22 |
|
53 #define SEND_BREAK 0x23 |
|
54 |
|
55 /* Notifications * |
|
56 * Note: Notifications are polled over |
|
57 * Communication Interface (Interrupt Endpoint) |
|
58 */ |
|
59 #define NETWORK_CONNECTION 0x00 |
|
60 #define RESPONSE_AVAILABLE 0x01 |
|
61 #define SERIAL_STATE 0x20 |
|
62 |
|
63 |
|
64 /* Device Class Code */ |
|
65 #define CDC_DEVICE 0x02 |
|
66 |
|
67 /* Communication Interface Class Code */ |
|
68 #define COMM_INTF 0x02 |
|
69 |
|
70 /* Communication Interface Class SubClass Codes */ |
|
71 #define ABSTRACT_CONTROL_MODEL 0x02 |
|
72 |
|
73 /* Communication Interface Class Control Protocol Codes */ |
|
74 #define V25TER 0x01 // Common AT commands ("Hayes(TM)") |
|
75 |
|
76 |
|
77 /* Data Interface Class Codes */ |
|
78 #define DATA_INTF 0x0A |
|
79 |
|
80 /* Data Interface Class Protocol Codes */ |
|
81 #define NO_PROTOCOL 0x00 // No class specific protocol required |
|
82 |
|
83 |
|
84 /* Communication Feature Selector Codes */ |
|
85 #define ABSTRACT_STATE 0x01 |
|
86 #define COUNTRY_SETTING 0x02 |
|
87 |
|
88 /* Functional Descriptors */ |
|
89 /* Type Values for the bDscType Field */ |
|
90 #define CS_INTERFACE 0x24 |
|
91 #define CS_ENDPOINT 0x25 |
|
92 |
|
93 /* bDscSubType in Functional Descriptors */ |
|
94 #define DSC_FN_HEADER 0x00 |
|
95 #define DSC_FN_CALL_MGT 0x01 |
|
96 #define DSC_FN_ACM 0x02 // ACM - Abstract Control Management |
|
97 #define DSC_FN_DLM 0x03 // DLM - Direct Line Managment |
|
98 #define DSC_FN_TELEPHONE_RINGER 0x04 |
|
99 #define DSC_FN_RPT_CAPABILITIES 0x05 |
|
100 #define DSC_FN_UNION 0x06 |
|
101 #define DSC_FN_COUNTRY_SELECTION 0x07 |
|
102 #define DSC_FN_TEL_OP_MODES 0x08 |
|
103 #define DSC_FN_USB_TERMINAL 0x09 |
|
104 /* more.... see Table 25 in USB CDC Specification 1.1 */ |
|
105 |
|
106 /* CDC Bulk IN transfer states */ |
|
107 #define CDC_TX_READY 0 |
|
108 #define CDC_TX_BUSY 1 |
|
109 #define CDC_TX_BUSY_ZLP 2 // ZLP: Zero Length Packet |
|
110 #define CDC_TX_COMPLETING 3 |
|
111 |
|
112 /****************************************************************************** |
|
113 * Macro: BOOL mUSBUSARTIsTxTrfReady(void) |
|
114 * |
|
115 * PreCondition: None |
|
116 * |
|
117 * Input: None |
|
118 * |
|
119 * Output: None |
|
120 * |
|
121 * Side Effects: None |
|
122 * |
|
123 * Overview: This macro is used to check if the CDC class is ready |
|
124 * to send more data. |
|
125 * Typical Usage: if(mUSBUSARTIsTxTrfReady()) |
|
126 * |
|
127 * Note: None |
|
128 *****************************************************************************/ |
|
129 #define mUSBUSARTIsTxTrfReady() (cdc_trf_state == CDC_TX_READY) |
|
130 |
|
131 /****************************************************************************** |
|
132 * Macro: (bit) mCDCUsartRxIsBusy(void) |
|
133 * |
|
134 * PreCondition: None |
|
135 * |
|
136 * Input: None |
|
137 * |
|
138 * Output: None |
|
139 * |
|
140 * Side Effects: None |
|
141 * |
|
142 * Overview: This macro is used to check if CDC bulk OUT endpoint is |
|
143 * busy (owned by SIE) or not. |
|
144 * Typical Usage: if(mCDCUsartRxIsBusy()) |
|
145 * |
|
146 * Note: None |
|
147 *****************************************************************************/ |
|
148 #define mCDCUsartRxIsBusy() CDC_BULK_BD_OUT.Stat.UOWN |
|
149 |
|
150 /****************************************************************************** |
|
151 * Macro: (bit) mCDCUsartTxIsBusy(void) |
|
152 * |
|
153 * PreCondition: None |
|
154 * |
|
155 * Input: None |
|
156 * |
|
157 * Output: None |
|
158 * |
|
159 * Side Effects: None |
|
160 * |
|
161 * Overview: This macro is used to check if CDC bulk IN endpoint is |
|
162 * busy (owned by SIE) or not. |
|
163 * Typical Usage: if(mCDCUsartTxIsBusy()) |
|
164 * |
|
165 * Note: None |
|
166 *****************************************************************************/ |
|
167 #define mCDCUsartTxIsBusy() CDC_BULK_BD_IN.Stat.UOWN |
|
168 |
|
169 /****************************************************************************** |
|
170 * Macro: byte mCDCGetRxLength(void) |
|
171 * |
|
172 * PreCondition: None |
|
173 * |
|
174 * Input: None |
|
175 * |
|
176 * Output: mCDCGetRxLength returns cdc_rx_len |
|
177 * |
|
178 * Side Effects: None |
|
179 * |
|
180 * Overview: mCDCGetRxLength is used to retrieve the number of bytes |
|
181 * copied to user's buffer by the most recent call to |
|
182 * getsUSBUSART function. |
|
183 * |
|
184 * Note: None |
|
185 *****************************************************************************/ |
|
186 #define mCDCGetRxLength() cdc_rx_len |
|
187 |
|
188 /****************************************************************************** |
|
189 * Macro: void mUSBUSARTTxRam(byte *pData, byte len) |
|
190 * |
|
191 * PreCondition: cdc_trf_state must be in the CDC_TX_READY state. |
|
192 * |
|
193 * Value of 'len' must be equal to or smaller than 255 bytes. |
|
194 * |
|
195 * Input: pDdata : Pointer to the starting location of data bytes |
|
196 * len : Number of bytes to be transferred |
|
197 * |
|
198 * Output: None |
|
199 * |
|
200 * Side Effects: None |
|
201 * |
|
202 * Overview: Use this macro to transfer data located in data memory. |
|
203 * Use this macro when: |
|
204 * 1. Data stream is not null-terminated |
|
205 * 2. Transfer length is known |
|
206 * |
|
207 * Remember: cdc_trf_state must == CDC_TX_READY |
|
208 * Unlike putsUSBUSART, there is not code double checking |
|
209 * the transfer state. Unexpected behavior will occur if |
|
210 * this function is called when cdc_trf_state != CDC_TX_READY |
|
211 * |
|
212 * Note: This macro only handles the setup of the transfer. The |
|
213 * actual transfer is handled by CDCTxService(). |
|
214 *****************************************************************************/ |
|
215 #define mUSBUSARTTxRam(pData,len) \ |
|
216 { \ |
|
217 pCDCSrc.bRam = pData; \ |
|
218 cdc_tx_len = len; \ |
|
219 cdc_mem_type = _RAM; \ |
|
220 cdc_trf_state = CDC_TX_BUSY; \ |
|
221 } |
|
222 |
|
223 /****************************************************************************** |
|
224 * Macro: void mUSBUSARTTxRom(rom byte *pData, byte len) |
|
225 * |
|
226 * PreCondition: cdc_trf_state must be in the CDC_TX_READY state. |
|
227 * |
|
228 * Value of 'len' must be equal to or smaller than 255 bytes. |
|
229 * |
|
230 * Input: pDdata : Pointer to the starting location of data bytes |
|
231 * len : Number of bytes to be transferred |
|
232 * |
|
233 * Output: None |
|
234 * |
|
235 * Side Effects: None |
|
236 * |
|
237 * Overview: Use this macro to transfer data located in program memory. |
|
238 * Use this macro when: |
|
239 * 1. Data stream is not null-terminated |
|
240 * 2. Transfer length is known |
|
241 * |
|
242 * Remember: cdc_trf_state must == CDC_TX_READY |
|
243 * Unlike putrsUSBUSART, there is not code double checking |
|
244 * the transfer state. Unexpected behavior will occur if |
|
245 * this function is called when cdc_trf_state != CDC_TX_READY |
|
246 * |
|
247 * Note: This macro only handles the setup of the transfer. The |
|
248 * actual transfer is handled by CDCTxService(). |
|
249 *****************************************************************************/ |
|
250 #define mUSBUSARTTxRom(pData,len) \ |
|
251 { \ |
|
252 pCDCSrc.bRom = pData; \ |
|
253 cdc_tx_len = len; \ |
|
254 cdc_mem_type = _ROM; \ |
|
255 cdc_trf_state = CDC_TX_BUSY; \ |
|
256 } |
|
257 |
|
258 /** S T R U C T U R E S ******************************************************/ |
|
259 |
|
260 /* Line Coding Structure */ |
|
261 #define LINE_CODING_LENGTH 0x07 |
|
262 |
|
263 typedef union _LINE_CODING |
|
264 { |
|
265 struct |
|
266 { |
|
267 byte _byte[LINE_CODING_LENGTH]; |
|
268 }; |
|
269 struct |
|
270 { |
|
271 DWORD dwDTERate; // Complex data structure |
|
272 byte bCharFormat; |
|
273 byte bParityType; |
|
274 byte bDataBits; |
|
275 }; |
|
276 } LINE_CODING; |
|
277 |
|
278 typedef union _CONTROL_SIGNAL_BITMAP |
|
279 { |
|
280 byte _byte; |
|
281 struct |
|
282 { |
|
283 unsigned DTE_PRESENT; // [0] Not Present [1] Present |
|
284 unsigned CARRIER_CONTROL; // [0] Deactivate [1] Activate |
|
285 }; |
|
286 } CONTROL_SIGNAL_BITMAP; |
|
287 |
|
288 |
|
289 /* Functional Descriptor Structure - See CDC Specification 1.1 for details */ |
|
290 |
|
291 /* Header Functional Descriptor */ |
|
292 typedef struct _USB_CDC_HEADER_FN_DSC |
|
293 { |
|
294 byte bFNLength; |
|
295 byte bDscType; |
|
296 byte bDscSubType; |
|
297 word bcdCDC; |
|
298 } USB_CDC_HEADER_FN_DSC; |
|
299 |
|
300 /* Abstract Control Management Functional Descriptor */ |
|
301 typedef struct _USB_CDC_ACM_FN_DSC |
|
302 { |
|
303 byte bFNLength; |
|
304 byte bDscType; |
|
305 byte bDscSubType; |
|
306 byte bmCapabilities; |
|
307 } USB_CDC_ACM_FN_DSC; |
|
308 |
|
309 /* Union Functional Descriptor */ |
|
310 typedef struct _USB_CDC_UNION_FN_DSC |
|
311 { |
|
312 byte bFNLength; |
|
313 byte bDscType; |
|
314 byte bDscSubType; |
|
315 byte bMasterIntf; |
|
316 byte bSaveIntf0; |
|
317 } USB_CDC_UNION_FN_DSC; |
|
318 |
|
319 /* Call Management Functional Descriptor */ |
|
320 typedef struct _USB_CDC_CALL_MGT_FN_DSC |
|
321 { |
|
322 byte bFNLength; |
|
323 byte bDscType; |
|
324 byte bDscSubType; |
|
325 byte bmCapabilities; |
|
326 byte bDataInterface; |
|
327 } USB_CDC_CALL_MGT_FN_DSC; |
|
328 |
|
329 /** E X T E R N S ************************************************************/ |
|
330 extern byte cdc_rx_len; |
|
331 |
|
332 extern byte cdc_trf_state; |
|
333 extern POINTER pCDCSrc; |
|
334 extern byte cdc_tx_len; |
|
335 extern byte cdc_mem_type; |
|
336 |
|
337 /** P U B L I C P R O T O T Y P E S *****************************************/ |
|
338 void USBCheckCDCRequest(void); |
|
339 void CDCInitEP(void); |
|
340 byte getsUSBUSART(char *buffer, byte len); |
|
341 void putrsUSBUSART(const rom char *data); |
|
342 void putsUSBUSART(char *data); |
|
343 void CDCTxService(void); |
|
344 |
|
345 #endif //CDC_H |