1: uhs_status_t Usbh_Cdc_WriteData(
void* pContext,
2:
PCDC_BUFF_INFO pstData)
3: {
4:
PCDC_DEVICE pCdcDevice;
5: uhs_status_t nRetvalResorce;
6: CDC_FUNC_STATUS nRetval;
7: uhs_ubit8_t u8CntDeviceId;
8: uhs_status_t nRetStatus;
9:
10:
11:
12:
13:
if( pContext == NULL) {
14: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
15:
return(
USBCDC_API_PARAM_ERROR );
16: }
17:
18:
19:
20:
21:
if( g_pCdcDriver == NULL ) {
22: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
23:
return(
USBCDC_API_SYS_SYSTEM_ERROR );
24: }
25:
26:
27:
28:
29:
30: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_API_DET);
31:
if(nRetStatus !=
USBCDC_API_SUCCESS){
32: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR );
33:
return(nRetStatus);
34: }
35:
36:
37:
38:
39:
if( (pstData == NULL) ||
40: (pstData->pu8Buff == NULL) ||
41: (pstData->u32RequestLength == 0) ) {
42: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
43: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
44:
return(
USBCDC_API_PARAM_ERROR );
45: }
46:
47:
48:
49:
50: nRetvalResorce = CdcUtils_AcquisitionSemaphore(pCdcDevice->pDataOutExecuteLock, WAITFOREVER);
51:
if( nRetvalResorce != TRUE ){
52:
53: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
54: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
55:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
56: }
57:
58:
59:
60:
61:
if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) ||
62: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) {
63:
64:
65:
66: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataOutExecuteLock );
67: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
68: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE );
69:
return(
USBCDC_API_NOT_READY );
70: }
71:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) {
72:
73:
74:
75: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataOutExecuteLock );
76: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
77: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT );
78:
return(
USBCDC_API_NO_SUPPORT );
79: }
80:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CLOSE ) {
81:
82:
83:
84: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataOutExecuteLock );
85: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
86: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_OPEN );
87:
return(
USBCDC_API_NOT_OPEN );
88: }
89:
else {
90: ;
91: }
92:
93:
94: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
95:
96:
97:
98:
99: nRetval = Usbh_Cdc_IssueSyncBulkOutMsg(pCdcDevice, pstData,
100: g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId],
CDC_BULK_TIMEOUT);
101:
if(nRetval != CDC_FUNC_STATUS_SUCCESS ) {
102:
103:
104:
105: (
void)CdcUtils_ReleaseSemaphore( pCdcDevice->pDataOutExecuteLock );
106:
107:
108: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_BULK );
109:
if( nRetval == CDC_FUNC_STATUS_HALT_PIPE ) {
110:
return(
USBCDC_API_TRANS_HALT_PIPE );
111: }
else{
112:
return(
USBCDC_API_TRANS_DATA_FAILED );
113: }
114: }
115:
116:
117:
118:
119: nRetvalResorce = CdcUtils_ReleaseSemaphore( pCdcDevice->pDataOutExecuteLock );
120:
if(nRetvalResorce != TRUE){
121:
122:
123: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pApiDetAccessLock[u8CntDeviceId] );
124:
125: DIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
126:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
127: }
128:
129:
return(
USBCDC_API_SUCCESS );
130: }