1: uhs_status_t Usbh_Cdc_GetLineCoding(
void* pContext,
2:
PCDC_LINE_CODING pstData)
3: {
4:
PCDC_DEVICE pCdcDevice;
5: usb_device_request_t* pRequest;
6: CDC_FUNC_STATUS nRetval;
7: uhs_ubit8_t *pu8GetBuff;
8: uhs_ubit8_t u8CntDeviceId;
9: uhs_status_t nRetStatus;
10: uhs_status_t nRetvalResorce;
11:
12:
13:
14:
15:
if( pContext == NULL ){
16: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
17:
return(
USBCDC_API_PARAM_ERROR );
18: }
19:
20:
21:
22:
23:
if( g_pCdcDriver == NULL ) {
24: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT );
25:
return(
USBCDC_API_SYS_SYSTEM_ERROR );
26: }
27:
28:
29:
30:
31:
32: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET);
33:
if(nRetStatus !=
USBCDC_API_SUCCESS){
34: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR );
35:
return(nRetStatus);
36: }
37:
38:
39:
40:
41:
if(pstData == NULL) {
42:
43:
44: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
45: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR );
46:
return(
USBCDC_API_PARAM_ERROR );
47: }
48:
49:
50:
51:
52:
if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) ||
53: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) {
54:
55:
56: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
57: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE );
58:
return(
USBCDC_API_NOT_READY );
59: }
60:
else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) {
61:
62:
63: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
64: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT );
65:
return(
USBCDC_API_NO_SUPPORT );
66: }
67:
else {
68: ;
69: }
70:
71:
72:
73:
74: pRequest = CdcUtils_Malloc(
sizeof(usb_device_request_t));
75:
if(pRequest == NULL) {
76: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
77: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
78:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
79: }
80:
81:
82:
83:
84: pu8GetBuff = CdcUtils_Malloc(7);
85:
if(pu8GetBuff == NULL) {
86: CdcUtils_Free(pRequest);
87: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
88: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
89:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
90: }
91:
92:
93:
94:
95: pRequest->bmRequestType = 0xA1;
96: pRequest->bRequest = 0x21;
97: pRequest->wValue0 = 0x00;
98: pRequest->wValue1 = 0x00;
99: pRequest->wIndex0 = 0x00;
100: pRequest->wIndex1 = 0x00;
101: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0007 );
102: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0007 );
103:
104:
105:
106:
107: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pu8GetBuff, NULL);
108:
if(nRetval != CDC_FUNC_STATUS_SUCCESS){
109: CdcUtils_Free(pRequest);
110: CdcUtils_Free(pu8GetBuff);
111:
112:
113: (
void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
114: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ );
115:
return(
USBCDC_API_TRANS_CLSREQ_FAILED );
116: }
117:
118:
119:
120:
121: pstData->u32BaudRate = PACK32_LITTLE_ENDIAN( pu8GetBuff[3], pu8GetBuff[2], pu8GetBuff[1], pu8GetBuff[0] );
122: pstData->StopBit = (
LINE_CODING_STOPBIT)(pu8GetBuff[4]);
123: pstData->Parity = (
LINE_CODING_PARITY)(pu8GetBuff[5]);
124: pstData->DataBit = (
LINE_CODING_DATABIT)(pu8GetBuff[6]);
125:
126:
127:
128:
129: CdcUtils_Free(pu8GetBuff);
130:
131:
132:
133:
134: CdcUtils_Free(pRequest);
135:
136:
137:
138:
139: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] );
140:
if(nRetvalResorce != TRUE){
141:
142: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE );
143:
return(
USBCDC_API_SYS_OUT_OF_RESOURCE );
144: }
145:
146:
return(
USBCDC_API_SUCCESS );
147: }