1: uhs_status_t Usbh_Cdc_RegistCallBack(
void* pContext,
2:
cdc_callback_t pUserNotifyCallback,
3: uhs_ubit8_t u8TotalBuffSize)
4: {
5:
PCDC_DEVICE pCdcDevice;
6: uhs_status_t nRetvalResorce;
7: uhs_ubit8_t u8CntDeviceId;
8: uhs_status_t nRetStatus;
9:
10:
11:
12:
13:
14: CIAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_REGIST );
15:
16:
17:
18:
19:
if( pContext == NULL ){
20: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
21:
return(
USBCDC_API_PARAM_ERROR );
22: }
23:
24:
25:
26:
27:
if( g_pCdcDriver == NULL ) {
28: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
29:
return(
USBCDC_API_SYS_SYSTEM_ERROR );
30: }
31:
32:
33:
34:
35:
36: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET);
37:
if(nRetStatus !=
USBCDC_API_SUCCESS){
38: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR );
39:
return(nRetStatus);
40: }
41:
42:
43:
44:
45:
if( ( pUserNotifyCallback == NULL ) ||
46: ( u8TotalBuffSize < (CDC_BULKIN_BUFF_MIN_SIZE / 1024)) ||
47: ( u8TotalBuffSize > (CDC_BULKIN_BUFF_MAX_SIZE / 1024)) ) {
48:
49:
50: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
51: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
52:
return(
USBCDC_API_PARAM_ERROR );
53: }
54:
55:
56:
57:
58: nRetvalResorce = CdcUtils_AcquisitionSemaphore(pCdcDevice->pRegistExecuteLock, WAITFOREVER);
59:
if( nRetvalResorce != TRUE ){
60:
61:
62: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
63:
64:
65: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
66:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
67: }
68:
69:
70:
71:
72:
if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING ) {
73: ;
74: }
75:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) {
76:
77:
78:
79: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock );
80: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
81:
82: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT );
83:
return(
USBCDC_API_NO_SUPPORT );
84: }
85:
else {
86:
87:
88:
89: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock );
90: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
91:
92: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_ALREADY_REGIST );
93:
return(
USBCDC_API_ALREADY_REGIST );
94: }
95:
96:
97: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_REGIST;
98:
99:
100:
101:
102: pCdcDevice->pUserNotifyCallback = pUserNotifyCallback;
103:
104:
105:
106:
107:
if( (pCdcDevice->pIntInBuff = (
PCDC_INTIN_BUFF)CdcUtils_Malloc((uhs_size_t)
sizeof(CDC_INTIN_BUFF))) == NULL ) {
108:
109: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING;
110:
111: pCdcDevice->pUserNotifyCallback = NULL;
112:
113:
114:
115:
116: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock );
117: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
118:
119:
120: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
121:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
122: }
123:
124:
125:
126:
127: pCdcDevice->pIntInBuff->u8WritePos = 0;
128: pCdcDevice->pIntInBuff->u8ReceiveSize = 0;
129: pCdcDevice->pIntInBuff->isIntINUserFlag = TRUE;
130:
131:
132:
133:
134:
if( (pCdcDevice->pIntInBuff->pu8StartBuff = (uhs_ubit8_t*)CdcUtils_Malloc((uhs_size_t)(USB_MAXPKT_CTRLEP))) == NULL ) {
135:
136: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING;
137:
138: pCdcDevice->pUserNotifyCallback = NULL;
139:
140:
141: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff );
142:
143:
144: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock );
145:
146:
147: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
148:
149:
150: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
151:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
152: }
153:
154:
155:
156:
157:
if( (pCdcDevice->pIntInBuff->pu8TempBuff = (uhs_ubit8_t*)CdcUtils_Malloc((uhs_size_t)(pCdcDevice->pIntInPipe->u32MaxPacketSize))) == NULL ) {
158:
159: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING;
160:
161: pCdcDevice->pUserNotifyCallback = NULL;
162:
163:
164: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8StartBuff );
165:
166: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff );
167:
168:
169: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock );
170:
171: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
172:
173:
174: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
175:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
176: }
177:
178:
179:
180:
181:
if( (pCdcDevice->pBulkInBuff = (
PCDC_BULKIN_BUFF)CdcUtils_Malloc((uhs_size_t)
sizeof(CDC_BULKIN_BUFF))) == NULL ) {
182:
183: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING;
184:
185: pCdcDevice->pUserNotifyCallback = NULL;
186:
187:
188: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8TempBuff );
189:
190: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8StartBuff );
191:
192: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff );
193:
194:
195: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock );
196:
197:
198: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
199:
200:
201: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
202:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
203: }
204:
205:
206:
207:
208: pCdcDevice->pBulkInBuff->pu8StartBuff = NULL;
209: pCdcDevice->pBulkInBuff->pu8EndBuff = NULL;
210: pCdcDevice->pBulkInBuff->pu8ReadPos = NULL;
211: pCdcDevice->pBulkInBuff->pu8WritePos = NULL;
212: pCdcDevice->pBulkInBuff->pu8TempBuff = NULL;
213: pCdcDevice->pBulkInBuff->u32RemainBuffSize = 0;
214: pCdcDevice->pBulkInBuff->u8TotalBuffSize = u8TotalBuffSize;
215: pCdcDevice->pBulkInBuff->isBulkINFlag = FALSE;
216: pCdcDevice->pBulkInBuff->isBulkINUserFlag = FALSE;
217:
218:
219:
220:
221: nRetvalResorce = CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock );
222:
if(nRetvalResorce != TRUE){
223:
224: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING;
225:
226: pCdcDevice->pUserNotifyCallback = NULL;
227:
228:
229: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8TempBuff );
230:
231: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8StartBuff );
232:
233: (
void)CdcUtils_Free( pCdcDevice->pIntInBuff );
234:
235: (
void)CdcUtils_Free( pCdcDevice->pBulkInBuff );
236:
237: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
238:
239:
240: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
241:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
242: }
243:
244:
245:
246:
247: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
248:
if(nRetvalResorce != TRUE){
249:
250: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
251:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
252: }
253:
254:
255:
256:
257: CIAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_REGIST_FINISH );
258:
259:
return(
USBCDC_API_SUCCESS );
260: }