1: uhs_status_t Usbh_Cdc_Close(
void* pContext)
2: {
3:
PCDC_DEVICE pCdcDevice;
4: uhs_status_t nRetvalResorce;
5: CDC_FUNC_STATUS nRetval;
6: uhs_boolean_t isErr = FALSE;
7: uhs_ubit8_t u8CntDeviceId;
8: uhs_status_t nRetStatus;
9:
10:
11:
12:
13: DIAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_CLOSE );
14:
15:
16:
17:
18:
if( pContext == NULL ) {
19: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
20:
return(
USBCDC_API_PARAM_ERROR );
21: }
22:
23:
24:
25:
26:
if( g_pCdcDriver == NULL ) {
27: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
28:
return(
USBCDC_API_SYS_SYSTEM_ERROR );
29: }
30:
31:
32:
33:
34:
35: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_API_DET);
36:
if(nRetStatus !=
USBCDC_API_SUCCESS){
37: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR );
38:
return(nRetStatus);
39: }
40:
41:
42:
43:
44: nRetvalResorce = CdcUtils_AcquisitionSemaphore(pCdcDevice->pDataInExecuteLock, WAITFOREVER);
45:
if( nRetvalResorce != TRUE ){
46:
47:
48: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
49:
50:
51: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
52:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
53: }
54:
55:
56:
57:
58:
if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) ||
59: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) {
60:
61:
62:
63: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
64: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
65: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE );
66:
return(
USBCDC_API_NOT_READY );
67: }
68:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) {
69:
70:
71:
72: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
73: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
74: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT );
75:
return(
USBCDC_API_NO_SUPPORT );
76: }
77:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CLOSE ) {
78:
79:
80:
81: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
82: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
83: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_ALREADY_CLOSE );
84:
return(
USBCDC_API_ALREADY_CLOSE );
85: }
86:
else {
87: ;
88: }
89:
90:
91:
92:
93: nRetvalResorce = CdcUtils_AcquisitionSemaphore(pCdcDevice->pBulkINBuffAccessLock, WAITFOREVER);
94:
if( nRetvalResorce != TRUE ){
95:
96:
97:
98: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
99: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
100:
101: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
102:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
103: }
104:
105:
106:
107:
108: nRetval = Usbh_Cdc_StopBulkINMsg(pCdcDevice);
109:
if(nRetval != CDC_FUNC_STATUS_SUCCESS ) {
110:
111:
112: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pBulkINBuffAccessLock );
113:
114:
115:
116: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
117:
118:
119:
120: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
121:
122:
123: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_BULK );
124:
return(
USBCDC_API_TRANS_DATA_FAILED );
125: }
126:
127:
128:
129:
130: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CLOSE;
131:
132:
133:
134: pCdcDevice->pBulkInBuff->isBulkINFlag = FALSE;
135:
136:
137:
138: pCdcDevice->pBulkInBuff->isBulkINUserFlag = FALSE;
139:
140:
141:
142:
143:
144:
if( pCdcDevice->pBulkInBuff->pu8TempBuff != NULL ) {
145:
146:
147:
148:
if( CdcUtils_BuffFree( pCdcDevice->pBulkInBuff->pu8TempBuff ) == FALSE ){
149: isErr = TRUE;
150: }
151: pCdcDevice->pBulkInBuff->pu8TempBuff = NULL;
152: }
153:
154:
155:
156:
157:
158:
if( pCdcDevice->pBulkInBuff->pu8StartBuff != NULL ) {
159:
160:
161:
162:
if( CdcUtils_BuffFree( pCdcDevice->pBulkInBuff->pu8StartBuff ) == FALSE ){
163: isErr = TRUE;
164: }
165: pCdcDevice->pBulkInBuff->pu8StartBuff = NULL;
166: }
167:
168:
169:
170:
171:
if( isErr == TRUE ) {
172:
173:
174: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pBulkINBuffAccessLock );
175:
176:
177:
178: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
179:
180:
181:
182: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
183:
184:
185: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
186:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
187: }
188:
189:
190:
191:
192: nRetvalResorce = CdcUtils_ReleaseSemaphore( pCdcDevice->pBulkINBuffAccessLock );
193:
if(nRetvalResorce != TRUE){
194:
195:
196: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
197:
198:
199:
200: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
201:
202:
203: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
204:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
205: }
206:
207:
208:
209:
210: nRetvalResorce = CdcUtils_ReleaseSemaphore( pCdcDevice->pDataInExecuteLock );
211:
if(nRetvalResorce != TRUE){
212:
213:
214: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
215:
216:
217: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
218:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
219: }
220:
221:
222:
223:
224: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
225:
if(nRetvalResorce != TRUE){
226:
227: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
228:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
229: }
230:
231:
232:
233:
234: DIAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_CLOSE_FINISH );
235:
236:
return(
USBCDC_API_SUCCESS );
237: }