1 /*
2  * @brief Programming API used with Virtual Communication port
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2013
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products.  This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __CDC_VCOM_H_
33 #define __CDC_VCOM_H_
34 
35 #include "app_usbd_cfg.h"
36 
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41 
42 /** @ingroup EXAMPLES_USBDROM_15XX_COMPOSITE
43  * @{
44  */
45 
46 #define VCOM_RX_BUF_SZ      512
47 #define VCOM_TX_CONNECTED   _BIT(8)		/* connection state is for both RX/Tx */
48 #define VCOM_TX_BUSY        _BIT(0)
49 #define VCOM_RX_DONE        _BIT(0)
50 #define VCOM_RX_BUF_FULL    _BIT(1)
51 #define VCOM_RX_BUF_QUEUED  _BIT(2)
52 #define VCOM_RX_DB_QUEUED   _BIT(3)
53 
54 /**
55  * Structure containing Virtual Comm port control data
56  */
57 typedef struct VCOM_DATA {
58 	USBD_HANDLE_T hUsb;
59 	USBD_HANDLE_T hCdc;
60 	uint8_t *rx_buff;
61 	uint16_t rx_rd_count;
62 	uint16_t rx_count;
63 	volatile uint16_t tx_flags;
64 	volatile uint16_t rx_flags;
65 } VCOM_DATA_T;
66 
67 /**
68  * Virtual Comm port control data instance.
69  */
70 extern VCOM_DATA_T g_vCOM;
71 
72 /**
73  * @brief	Virtual com port init routine
74  * @param	hUsb		: Handle to USBD stack instance
75  * @param	pDesc		: Pointer to configuration descriptor
76  * @param	pUsbParam	: Pointer USB param structure returned by previous init call
77  * @return	Always returns LPC_OK.
78  */
79 ErrorCode_t vcom_init (USBD_HANDLE_T hUsb, USB_CORE_DESCS_T *pDesc, USBD_API_INIT_PARAM_T *pUsbParam);
80 
81 /**
82  * @brief	Virtual com port buffered read routine
83  * @param	pBuf	: Pointer to buffer where read data should be copied
84  * @param	buf_len	: Length of the buffer passed
85  * @return	Return number of bytes read.
86  */
87 uint32_t vcom_bread (uint8_t *pBuf, uint32_t buf_len);
88 
89 /**
90  * @brief	Virtual com port read routine
91  * @param	pBuf	: Pointer to buffer where read data should be copied
92  * @param	buf_len	: Length of the buffer passed
93  * @return	Always returns LPC_OK.
94  */
95 ErrorCode_t vcom_read_req (uint8_t *pBuf, uint32_t buf_len);
96 
97 /**
98  * @brief	Gets current read count.
99  * @return	Returns current read count.
100  */
101 uint32_t vcom_read_cnt(void);
102 
103 /**
104  * @brief	Check if Vcom is connected
105  * @return	Returns non-zero value if connected.
106  */
vcom_connected(void)107 static INLINE uint32_t vcom_connected(void) {
108 	return g_vCOM.tx_flags & VCOM_TX_CONNECTED;
109 }
110 
111 /**
112  * @brief	Virtual com port write routine
113  * @param	pBuf	: Pointer to buffer to be written
114  * @param	buf_len	: Length of the buffer passed
115  * @return	Number of bytes written
116  */
117 uint32_t vcom_write (uint8_t *pBuf, uint32_t buf_len);
118 
119 /**
120  * @}
121  */
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif /* __CDC_VCOM_H_ */
128