Logo
MSP430USBDevelopersPackage_5_20_06_02
UsbCdc.h
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 /*
33  * ======== UsbCdc.h ========
34  */
35 
36 #ifndef _UsbCdc_H_
37 #define _UsbCdc_H_
38 
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43 
44 
45 /*----------------------------------------------------------------------------
46  * The following function names and macro names are deprecated. These were
47  * updated to new names to follow OneMCU naming convention.
48  +---------------------------------------------------------------------------*/
49 #ifndef DEPRECATED
50 #define kUSBCDC_sendStarted USBCDC_SEND_STARTED
51 #define kUSBCDC_sendComplete USBCDC_SEND_COMPLETE
52 #define kUSBCDC_intfBusyError USBCDC_INTERFACE_BUSY_ERROR
53 #define kUSBCDC_receiveStarted USBCDC_RECEIVE_STARTED
54 #define kUSBCDC_receiveCompleted USBCDC_RECEIVE_COMPLETED
55 #define kUSBCDC_receiveInProgress USBCDC_RECEIVE_IN_PROGRESS
56 #define kUSBCDC_generalError USBCDC_GENERAL_ERROR
57 #define kUSBCDC_busNotAvailable USBCDC_BUS_NOT_AVAILABLE
58 #define kUSBCDC_waitingForSend USBCDC_WAITING_FOR_SEND
59 #define kUSBCDC_waitingForReceive USBCDC_WAITING_FOR_RECEIVE
60 #define kUSBCDC_dataWaiting USBCDC_DATA_WAITING
61 #define kUSB_allCdcEvents USBCDC_ALL_CDC_EVENTS
62 #define kUSBCDC_noDataWaiting USBCDC_NO_DATA_WAITING
63 
64 #define USBCDC_intfStatus USBCDC_getInterfaceStatus
65 #define USBCDC_bytesInUSBBuffer USBCDC_getBytesInUSBBuffer
66 #endif
67 
68 
69 #define USBCDC_SEND_STARTED 0x01
70 #define USBCDC_SEND_COMPLETE 0x02
71 #define USBCDC_INTERFACE_BUSY_ERROR 0x03
72 #define USBCDC_RECEIVE_STARTED 0x04
73 #define USBCDC_RECEIVE_COMPLETED 0x05
74 #define USBCDC_RECEIVE_IN_PROGRESS 0x06
75 #define USBCDC_GENERAL_ERROR 0x07
76 #define USBCDC_BUS_NOT_AVAILABLE 0x08
77 //returned by USBCDC_rejectData() if no data pending
78 #define USBCDC_NO_DATA_WAITING 0X01
79 #define USBCDC_WAITING_FOR_SEND 0x01
80 #define USBCDC_WAITING_FOR_RECEIVE 0x02
81 #define USBCDC_DATA_WAITING 0x04
82 #define USBCDC_BUS_NOT_AVAILABLE 0x08
83 #define USBCDC_ALL_CDC_EVENTS 0xFF
84 
85 
86 #ifdef _CDC_
87 struct _CdcWrite {
88  uint16_t nCdcBytesToSend; //holds counter of bytes to be sent
89  uint16_t nCdcBytesToSendLeft; //holds counter how many bytes is still to be sent
90  const uint8_t* pUsbBufferToSend; //holds the buffer with data to be sent
91  uint8_t bCurrentBufferXY; //is 0 if current buffer to write data is X, or 1 if current buffer is Y
92  uint8_t bZeroPacketSent; //= FALSE;
93  uint8_t last_ByteSend;
94 } CdcWriteCtrl[CDC_NUM_INTERFACES];
95 
96 struct _CdcRead {
97  uint8_t *pUserBuffer; //holds the current position of user's receiving buffer. If NULL- no receiving
98  //operation started
99  uint8_t *pCurrentEpPos; //current positon to read of received data from curent EP
100  uint16_t nBytesToReceive; //holds how many bytes was requested by receiveData() to receive
101  uint16_t nBytesToReceiveLeft; //holds how many bytes is still requested by receiveData() to receive
102  uint8_t * pCT1; //holds current EPBCTxx register
103  uint8_t * pCT2; //holds next EPBCTxx register
104  uint8_t * pEP2; //holds addr of the next EP buffer
105  uint8_t nBytesInEp; //how many received bytes still available in current EP
106  uint8_t bCurrentBufferXY; //indicates which buffer is used by host to transmit data via OUT endpoint3
107 } CdcReadCtrl[CDC_NUM_INTERFACES];
108 
109 #endif
110 
111 /*----------------------------------------------------------------------------
112  * These functions can be used in application
113  +----------------------------------------------------------------------------*/
114 //*****************************************************************************
115 //
118 //
119 //******************************************************************************
120 //*****************************************************************************
121 //
159 //
160 //*****************************************************************************
161 
162 uint8_t USBCDC_sendData (const uint8_t* data, uint16_t size, uint8_t intfNum);
163 
164 //*****************************************************************************
165 //
205 //
206 //*****************************************************************************
207 
208 uint8_t USBCDC_receiveData (uint8_t* data, uint16_t size, uint8_t intfNum);
209 
210 //*****************************************************************************
211 //
234 //
235 //*****************************************************************************
236 
237 uint8_t USBCDC_abortReceive (uint16_t* size, uint8_t intfNum);
238 
239 //*****************************************************************************
240 //
254 //
255 //*****************************************************************************
256 uint8_t USBCDC_rejectData (uint8_t intfNum);
257 
258 
259 //*****************************************************************************
260 //
277 //
278 //*****************************************************************************
279 uint8_t USBCDC_abortSend (uint16_t* size, uint8_t intfNum);
280 
281 //*****************************************************************************
282 //
314 //
315 //*****************************************************************************
316 uint8_t USBCDC_getInterfaceStatus (uint8_t intfNum, uint16_t* bytesSent, uint16_t* bytesReceived);
317 
318 
319 //*****************************************************************************
320 //
333 //
334 //*****************************************************************************
335 
336 uint8_t USBCDC_getBytesInUSBBuffer (uint8_t intfNum);
337 //******************************************************************************
338 //
339 // Close the Doxygen group.
341 //
342 //******************************************************************************
343 
344 
345 /*----------------------------------------------------------------------------
346  * Event-Handling routines
347  +----------------------------------------------------------------------------*/
348 //*****************************************************************************
349 //
352 //
353 //******************************************************************************
354 
355 //*****************************************************************************
356 //
384 //
385 //*****************************************************************************
386 uint8_t USBCDC_handleDataReceived (uint8_t intfNum);
387 
388 //*****************************************************************************
389 //
406 //
407 //*****************************************************************************
408 uint8_t USBCDC_handleSendCompleted (uint8_t intfNum);
409 
410 //*****************************************************************************
411 //
429 //
430 //*****************************************************************************
431 uint8_t USBCDC_handleReceiveCompleted (uint8_t intfNum);
432 
433 /*
434  * Toggle state variable for CTS in USB Stack
435  */
436 void USBCDC_setCTS(uint8_t state);
437 
438 //*****************************************************************************
439 //
453 //
454 //*****************************************************************************
455 uint8_t USBCDC_handleSetLineCoding (uint8_t intfNum, uint32_t lBaudrate);
456 
457 //*****************************************************************************
458 //
472 //
473 //*****************************************************************************
474 uint8_t USBCDC_handleSetControlLineState (uint8_t intfNum, uint8_t lineState);
475 
476 //******************************************************************************
477 //
478 // Close the Doxygen group.
480 //
481 //******************************************************************************
482 
483 
484 /*----------------------------------------------------------------------------
485  * These functions is to be used ONLY by USB stack, and not by application
486  +----------------------------------------------------------------------------*/
487 
491 uint8_t usbGetLineCoding(void);
492 
496 uint8_t usbSetLineCoding(void);
497 
501 uint8_t usbSetControlLineState(void);
502 
506 uint8_t Handler_SetLineCoding(void);
507 
508 #ifdef __cplusplus
509 }
510 #endif
511 #endif //_UsbCdc_H_
uint8_t USBCDC_handleSetControlLineState(uint8_t intfNum, uint8_t lineState)
uint8_t USBCDC_abortSend(uint16_t *size, uint8_t intfNum)
uint8_t USBCDC_rejectData(uint8_t intfNum)
uint8_t USBCDC_sendData(const uint8_t *data, uint16_t size, uint8_t intfNum)
uint8_t USBCDC_getBytesInUSBBuffer(uint8_t intfNum)
uint8_t USBCDC_receiveData(uint8_t *data, uint16_t size, uint8_t intfNum)
uint8_t USBCDC_handleReceiveCompleted(uint8_t intfNum)
uint8_t USBCDC_handleDataReceived(uint8_t intfNum)
uint8_t USBCDC_handleSetLineCoding(uint8_t intfNum, uint32_t lBaudrate)
uint8_t USBCDC_handleSendCompleted(uint8_t intfNum)
uint8_t USBCDC_getInterfaceStatus(uint8_t intfNum, uint16_t *bytesSent, uint16_t *bytesReceived)
uint8_t USBCDC_abortReceive(uint16_t *size, uint8_t intfNum)