1:
9:
10:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
#include "usb_cdc_acm.h"
24:
#include "usb_cdc_osutils.h"
25:
#include "usb_cdc_internal_api.h"
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
#ifdef USBH_STACK_DEBUG_BUILD
59:
static const char g_filename[] = __FILE__;
60:
#endif
61:
PCDC_DRIVER g_pCdcDriver = NULL;
62:
63:
64:
65:
66:
67:
68:
84: uhs_status_t
Usbh_Cdc_Init(
app_callback_info* stCallback)
85: {
86: CDC_FUNC_STATUS nRetval;
87:
88:
89:
90:
91: IAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_INITIALIZE );
92:
93:
94:
95:
96:
if(stCallback->clsdrv_type != USB_CLASS_CDC){
97: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
98:
return(
UDI_STAT_DATA_ERROR );
99: }
100:
101:
102:
103:
104:
if(g_pCdcDriver != NULL){
105: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_ALREADY_INIT );
106:
return(
UDI_STAT_DATA_ERROR );
107: }
108:
109:
110:
111:
112:
113: g_pCdcDriver = (
PCDC_DRIVER)CdcUtils_Malloc(
sizeof(CDC_DRIVER));
114:
if( g_pCdcDriver == NULL ) {
115: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
116:
return(
UDI_STAT_RESOURCE_UNAVAIL );
117: }
118:
119: nRetval = Usbh_Cdc_CreateCdcDriver( stCallback->attach_callback, stCallback->detach_callback );
120:
if(nRetval != CDC_FUNC_STATUS_SUCCESS ) {
121: (
void)CdcUtils_Free(g_pCdcDriver);
122: g_pCdcDriver = NULL;
123: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CRE_CDCD );
124:
return(
UDI_STAT_DATA_ERROR );
125: }
126:
127:
128:
129:
130: nRetval = Usbh_Cdc_Acm_Initialize();
131:
if(nRetval != CDC_FUNC_STATUS_SUCCESS ) {
132: (
void)Usbh_Cdc_DeleteCdcDriver();
133: (
void)CdcUtils_Free(g_pCdcDriver);
134: g_pCdcDriver = NULL;
135: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CBI_INIT );
136:
return(
UDI_STAT_DATA_ERROR );
137: }
138:
139:
140:
141:
142: IAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_INITIALIZE_FINISH );
143:
144:
return(
UDI_OK );
145: }
146:
147:
157: uhs_status_t
Usbh_Cdc_Exit(
void* stCallback)
158: {
159: ((
void)stCallback);
160:
161: CDC_FUNC_STATUS nRetval;
162: uhs_boolean_t bRetval;
163:
164:
165:
166:
167: IAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_FINALIZE );
168:
169:
170:
171:
172:
if( g_pCdcDriver == NULL ) {
173: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
174:
return(
UDI_STAT_DATA_ERROR );
175: }
176:
177:
178:
179:
180: nRetval = Usbh_Cdc_Acm_Finalize();
181:
if( nRetval != CDC_FUNC_STATUS_SUCCESS ) {
182: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CBI_EXIT );
183: (
void)Usbh_Cdc_DeleteCdcDriver( );
184: (
void)CdcUtils_Free(g_pCdcDriver);
185: g_pCdcDriver = NULL;
186:
return(
UDI_STAT_DATA_ERROR );
187: }
188:
189:
190:
191:
192:
193: nRetval = Usbh_Cdc_DeleteCdcDriver();
194:
if( nRetval != CDC_FUNC_STATUS_SUCCESS ) {
195: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_DEL_CDCD );
196: (
void)CdcUtils_Free(g_pCdcDriver);
197: g_pCdcDriver = NULL;
198:
return(
UDI_STAT_DATA_ERROR );
199: }
200:
201: bRetval = CdcUtils_Free(g_pCdcDriver);
202: g_pCdcDriver = NULL;
203:
if( bRetval != TRUE ) {
204: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
205:
return(
UDI_STAT_RESOURCE_UNAVAIL );
206: }
207:
208:
209:
210:
211: IAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_FINALIZE_FINISH );
212:
213:
return(
UDI_OK );
214: }
215:
216:
225: uhs_status_t
Usbh_Cdc_ReregisterCallback(
app_callback_info* stCallback)
226: {
227:
228:
229:
230:
if( g_pCdcDriver == NULL ) {
231: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
232:
return(
UDI_STAT_DATA_ERROR );
233: }
234:
235:
236:
237:
238:
if(stCallback->clsdrv_type != USB_CLASS_CDC){
239: IAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
240:
return(
UDI_STAT_DATA_ERROR );
241: }
242:
243:
244:
245:
246: g_pCdcDriver->pUserAttachCallback = stCallback->attach_callback;
247: g_pCdcDriver->pUserDetachCallback = stCallback->detach_callback;
248:
249:
return(
UDI_OK );
250: }
251: