AG903ライブラリリファレンス
内容インデックスホーム
前へ上へ次へ
usb_cdc_commif_api.c

USBH CDC CommonI/F API

USBH CDC CommonI/F API

none

AXELL CORPORATION

2017_02_22 初版 

2017_10_26 Ver2.0

1: 9: 10: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: #include "usb_cdc_acm.h" 24: #include "usb_cdc_common.h" 25: #include "usb_cdc_macro.h" 26: #include "usb_cdc_osutils.h" 27: #include "usb_cdc_commif_api.h" 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: 59: 60: #ifdef USBH_STACK_DEBUG_BUILD 61: static const char g_filename[] = __FILE__; 62: #endif 63: 64: 65: 66: 67: 68: 80: 81: uhs_status_t Usbh_Cdc_GetVersion(uhs_ubit8_t* pu8MajorVersion, 82: uhs_ubit8_t* pu8MinorVersion) 83: { 84: 85: 86: 87: if( (pu8MajorVersion == NULL) || 88: (pu8MinorVersion == NULL) ) { 89: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 90: return( USBCDC_API_PARAM_ERROR ); 91: } 92: 93: 94: 95: 96: if( g_pCdcDriver == NULL ) { 97: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 98: return( USBCDC_API_SYS_SYSTEM_ERROR ); 99: } 100: 101: 102: *pu8MajorVersion = CDC_MAJOR_VERSION; 103: 104: *pu8MinorVersion = CDC_MINOR_VERSION; 105: 106: return( USBCDC_API_SUCCESS ); 107: } 108: 109: 141: uhs_status_t Usbh_Cdc_RegistCallBack(void* pContext, 142: cdc_callback_t pUserNotifyCallback, 143: uhs_ubit8_t u8TotalBuffSize) 144: { 145: PCDC_DEVICE pCdcDevice; 146: uhs_status_t nRetvalResorce; 147: uhs_ubit8_t u8CntDeviceId; 148: uhs_status_t nRetStatus; 149: 150: 151: 152: 153: 154: CIAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_REGIST ); 155: 156: 157: 158: 159: if( pContext == NULL ){ 160: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 161: return( USBCDC_API_PARAM_ERROR ); 162: } 163: 164: 165: 166: 167: if( g_pCdcDriver == NULL ) { 168: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 169: return( USBCDC_API_SYS_SYSTEM_ERROR ); 170: } 171: 172: 173: 174: 175: 176: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 177: if(nRetStatus != USBCDC_API_SUCCESS){ 178: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 179: return(nRetStatus); 180: } 181: 182: 183: 184: 185: if( ( pUserNotifyCallback == NULL ) || 186: ( u8TotalBuffSize < (CDC_BULKIN_BUFF_MIN_SIZE / 1024)) || 187: ( u8TotalBuffSize > (CDC_BULKIN_BUFF_MAX_SIZE / 1024)) ) { 188: 189: 190: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 191: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 192: return( USBCDC_API_PARAM_ERROR ); 193: } 194: 195: 196: 197: 198: nRetvalResorce = CdcUtils_AcquisitionSemaphore(pCdcDevice->pRegistExecuteLock, WAITFOREVER); 199: if( nRetvalResorce != TRUE ){ 200: 201: 202: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 203: 204: 205: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 206: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 207: } 208: 209: 210: 211: 212: if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING ) { 213: ; 214: } 215: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 216: 217: 218: 219: (void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock ); 220: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 221: 222: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 223: return( USBCDC_API_NO_SUPPORT ); 224: } 225: else { 226: 227: 228: 229: (void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock ); 230: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 231: 232: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_ALREADY_REGIST ); 233: return( USBCDC_API_ALREADY_REGIST ); 234: } 235: 236: 237: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_REGIST; 238: 239: 240: 241: 242: pCdcDevice->pUserNotifyCallback = pUserNotifyCallback; 243: 244: 245: 246: 247: if( (pCdcDevice->pIntInBuff = (PCDC_INTIN_BUFF)CdcUtils_Malloc((uhs_size_t) sizeof(CDC_INTIN_BUFF))) == NULL ) { 248: 249: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING; 250: 251: pCdcDevice->pUserNotifyCallback = NULL; 252: 253: 254: 255: 256: (void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock ); 257: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 258: 259: 260: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 261: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 262: } 263: 264: 265: 266: 267: pCdcDevice->pIntInBuff->u8WritePos = 0; 268: pCdcDevice->pIntInBuff->u8ReceiveSize = 0; 269: pCdcDevice->pIntInBuff->isIntINUserFlag = TRUE; 270: 271: 272: 273: 274: if( (pCdcDevice->pIntInBuff->pu8StartBuff = (uhs_ubit8_t*)CdcUtils_Malloc((uhs_size_t)(USB_MAXPKT_CTRLEP))) == NULL ) { 275: 276: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING; 277: 278: pCdcDevice->pUserNotifyCallback = NULL; 279: 280: 281: (void)CdcUtils_Free( pCdcDevice->pIntInBuff ); 282: 283: 284: (void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock ); 285: 286: 287: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 288: 289: 290: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 291: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 292: } 293: 294: 295: 296: 297: if( (pCdcDevice->pIntInBuff->pu8TempBuff = (uhs_ubit8_t*)CdcUtils_Malloc((uhs_size_t)(pCdcDevice->pIntInPipe->u32MaxPacketSize))) == NULL ) { 298: 299: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING; 300: 301: pCdcDevice->pUserNotifyCallback = NULL; 302: 303: 304: (void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8StartBuff ); 305: 306: (void)CdcUtils_Free( pCdcDevice->pIntInBuff ); 307: 308: 309: (void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock ); 310: 311: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 312: 313: 314: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 315: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 316: } 317: 318: 319: 320: 321: if( (pCdcDevice->pBulkInBuff = (PCDC_BULKIN_BUFF)CdcUtils_Malloc((uhs_size_t) sizeof(CDC_BULKIN_BUFF))) == NULL ) { 322: 323: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING; 324: 325: pCdcDevice->pUserNotifyCallback = NULL; 326: 327: 328: (void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8TempBuff ); 329: 330: (void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8StartBuff ); 331: 332: (void)CdcUtils_Free( pCdcDevice->pIntInBuff ); 333: 334: 335: (void)CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock ); 336: 337: 338: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 339: 340: 341: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 342: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 343: } 344: 345: 346: 347: 348: pCdcDevice->pBulkInBuff->pu8StartBuff = NULL; 349: pCdcDevice->pBulkInBuff->pu8EndBuff = NULL; 350: pCdcDevice->pBulkInBuff->pu8ReadPos = NULL; 351: pCdcDevice->pBulkInBuff->pu8WritePos = NULL; 352: pCdcDevice->pBulkInBuff->pu8TempBuff = NULL; 353: pCdcDevice->pBulkInBuff->u32RemainBuffSize = 0; 354: pCdcDevice->pBulkInBuff->u8TotalBuffSize = u8TotalBuffSize; 355: pCdcDevice->pBulkInBuff->isBulkINFlag = FALSE; 356: pCdcDevice->pBulkInBuff->isBulkINUserFlag = FALSE; 357: 358: 359: 360: 361: nRetvalResorce = CdcUtils_ReleaseSemaphore( pCdcDevice->pRegistExecuteLock ); 362: if(nRetvalResorce != TRUE){ 363: 364: pCdcDevice->nDeviceStat = CDC_DEVICE_STAT_CONNECTING; 365: 366: pCdcDevice->pUserNotifyCallback = NULL; 367: 368: 369: (void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8TempBuff ); 370: 371: (void)CdcUtils_Free( pCdcDevice->pIntInBuff->pu8StartBuff ); 372: 373: (void)CdcUtils_Free( pCdcDevice->pIntInBuff ); 374: 375: (void)CdcUtils_Free( pCdcDevice->pBulkInBuff ); 376: 377: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 378: 379: 380: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 381: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 382: } 383: 384: 385: 386: 387: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 388: if(nRetvalResorce != TRUE){ 389: 390: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 391: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 392: } 393: 394: 395: 396: 397: CIAPI_CDC_REPORT_MILESTONE( USBCDC_CHKPOINTS_API_REGIST_FINISH ); 398: 399: return( USBCDC_API_SUCCESS ); 400: } 401: 402: 422: uhs_status_t Usbh_Cdc_SendEncapsulatedCommand(void* pContext, 423: PCDC_BUFF_INFO pstData) 424: { 425: PCDC_DEVICE pCdcDevice; 426: usb_device_request_t* pRequest; 427: CDC_FUNC_STATUS nRetval; 428: uhs_ubit8_t u8CntDeviceId; 429: uhs_status_t nRetStatus; 430: uhs_status_t nRetvalResorce; 431: 432: 433: 434: 435: if( pContext == NULL ){ 436: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 437: return( USBCDC_API_PARAM_ERROR ); 438: } 439: 440: 441: 442: 443: if( g_pCdcDriver == NULL ) { 444: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 445: return( USBCDC_API_SYS_SYSTEM_ERROR ); 446: } 447: 448: 449: 450: 451: 452: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 453: if(nRetStatus != USBCDC_API_SUCCESS){ 454: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 455: return(nRetStatus); 456: } 457: 458: 459: 460: 461: if( (pstData == NULL) || 462: (pstData->pu8Buff == NULL) || 463: (pstData->u32RequestLength == 0) ) { 464: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 465: 466: 467: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 468: return( USBCDC_API_PARAM_ERROR ); 469: } 470: 471: 472: 473: 474: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 475: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 476: 477: 478: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 479: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 480: return( USBCDC_API_NOT_READY ); 481: } 482: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 483: 484: 485: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 486: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 487: return( USBCDC_API_NO_SUPPORT ); 488: } 489: else { 490: ; 491: } 492: 493: 494: 495: 496: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 497: if(pRequest == NULL) { 498: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 499: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 500: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 501: } 502: 503: 504: 505: 506: pRequest->bmRequestType = 0x21; 507: pRequest->bRequest = 0x00; 508: pRequest->wValue0 = 0x00; 509: pRequest->wValue1 = 0x00; 510: pRequest->wIndex0 = 0x00; 511: pRequest->wIndex1 = 0x00; 512: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->u32RequestLength ); 513: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->u32RequestLength ); 514: 515: 516: 517: 518: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pstData->pu8Buff, &pstData->u32ActualLength); 519: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 520: CdcUtils_Free(pRequest); 521: 522: 523: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 524: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 525: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 526: } 527: 528: 529: 530: 531: CdcUtils_Free(pRequest); 532: 533: 534: 535: 536: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 537: if(nRetvalResorce != TRUE){ 538: 539: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 540: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 541: } 542: 543: return( USBCDC_API_SUCCESS ); 544: } 545: 546: 566: uhs_status_t Usbh_Cdc_GetEncapsulatedResponse(void* pContext, 567: PCDC_BUFF_INFO pstData) 568: { 569: PCDC_DEVICE pCdcDevice; 570: usb_device_request_t* pRequest; 571: CDC_FUNC_STATUS nRetval; 572: uhs_ubit8_t u8CntDeviceId; 573: uhs_status_t nRetStatus; 574: uhs_status_t nRetvalResorce; 575: 576: 577: 578: 579: if( pContext == NULL ){ 580: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 581: return( USBCDC_API_PARAM_ERROR ); 582: } 583: 584: 585: 586: 587: if( g_pCdcDriver == NULL ) { 588: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 589: return( USBCDC_API_SYS_SYSTEM_ERROR ); 590: } 591: 592: 593: 594: 595: 596: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 597: if(nRetStatus != USBCDC_API_SUCCESS){ 598: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 599: return(nRetStatus); 600: } 601: 602: 603: 604: 605: if( (pstData == NULL) || 606: (pstData->pu8Buff == NULL) || 607: (pstData->u32RequestLength == 0) ) { 608: 609: 610: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 611: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 612: return( USBCDC_API_PARAM_ERROR ); 613: } 614: 615: 616: 617: 618: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 619: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 620: 621: 622: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 623: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 624: return( USBCDC_API_NOT_READY ); 625: } 626: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 627: 628: 629: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 630: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 631: return( USBCDC_API_NO_SUPPORT ); 632: } 633: else { 634: ; 635: } 636: 637: 638: 639: 640: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 641: if(pRequest == NULL) { 642: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 643: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 644: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 645: } 646: 647: 648: 649: 650: pRequest->bmRequestType = 0xA1; 651: pRequest->bRequest = 0x01; 652: pRequest->wValue0 = 0x00; 653: pRequest->wValue1 = 0x00; 654: pRequest->wIndex0 = 0x00; 655: pRequest->wIndex1 = 0x00; 656: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->u32RequestLength ); 657: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->u32RequestLength ); 658: 659: 660: 661: 662: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pstData->pu8Buff, &pstData->u32ActualLength); 663: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 664: CdcUtils_Free(pRequest); 665: 666: 667: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 668: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 669: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 670: } 671: 672: 673: 674: 675: CdcUtils_Free(pRequest); 676: 677: 678: 679: 680: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 681: if(nRetvalResorce != TRUE){ 682: 683: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 684: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 685: } 686: 687: return( USBCDC_API_SUCCESS ); 688: } 689: 690: 712: uhs_status_t Usbh_Cdc_SetCommFeature(void* pContext, 713: PCDC_COMM_FEATURE pstData) 714: { 715: PCDC_DEVICE pCdcDevice; 716: usb_device_request_t* pRequest; 717: CDC_FUNC_STATUS nRetval; 718: uhs_ubit8_t u8CntDeviceId; 719: uhs_ubit8_t *pu8SetBuff; 720: uhs_status_t nRetStatus; 721: uhs_status_t nRetvalResorce; 722: 723: 724: 725: 726: if( pContext == NULL ){ 727: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 728: return( USBCDC_API_PARAM_ERROR ); 729: } 730: 731: 732: 733: 734: if( g_pCdcDriver == NULL ) { 735: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 736: return( USBCDC_API_SYS_SYSTEM_ERROR ); 737: } 738: 739: 740: 741: 742: 743: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 744: if(nRetStatus != USBCDC_API_SUCCESS){ 745: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 746: return(nRetStatus); 747: } 748: 749: 750: 751: 752: if( pstData == NULL ) { 753: 754: 755: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 756: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 757: return( USBCDC_API_PARAM_ERROR ); 758: } 759: if( (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_ABSTRACT_STATE) && 760: (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_COUNTRY_SETTING) ) { 761: 762: 763: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 764: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 765: return( USBCDC_API_PARAM_ERROR ); 766: } 767: if( (pstData->FeatureSelector == COMM_FEATURE_SELECTOR_ABSTRACT_STATE) && 768: (pstData->u16Data > 3) ) { 769: 770: 771: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 772: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 773: return( USBCDC_API_PARAM_ERROR ); 774: } 775: 776: 777: 778: 779: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 780: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 781: 782: 783: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 784: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 785: return( USBCDC_API_NOT_READY ); 786: } 787: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 788: 789: 790: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 791: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 792: return( USBCDC_API_NO_SUPPORT ); 793: } 794: else { 795: ; 796: } 797: 798: 799: 800: 801: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 802: if(pRequest == NULL) { 803: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 804: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 805: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 806: } 807: 808: 809: 810: 811: pu8SetBuff = CdcUtils_Malloc(2); 812: if(pu8SetBuff == NULL) { 813: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 814: CdcUtils_Free(pRequest); 815: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 816: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 817: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 818: } 819: 820: 821: 822: 823: pRequest->bmRequestType = 0x21; 824: pRequest->bRequest = 0x02; 825: pRequest->wValue0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->FeatureSelector ); 826: pRequest->wValue1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->FeatureSelector ); 827: pRequest->wIndex0 = 0x00; 828: pRequest->wIndex1 = 0x00; 829: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0002 ); 830: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0002 ); 831: 832: 833: 834: 835: pu8SetBuff[0] = UNPACK16_LITTLE_ENDIAN_LSB( pstData->u16Data ); 836: pu8SetBuff[1] = UNPACK16_LITTLE_ENDIAN_MSB( pstData->u16Data ); 837: 838: 839: 840: 841: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pu8SetBuff, NULL); 842: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 843: CdcUtils_Free(pu8SetBuff); 844: CdcUtils_Free(pRequest); 845: 846: 847: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 848: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 849: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 850: } 851: 852: 853: 854: 855: CdcUtils_Free(pu8SetBuff); 856: 857: 858: 859: 860: CdcUtils_Free(pRequest); 861: 862: 863: 864: 865: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 866: if(nRetvalResorce != TRUE){ 867: 868: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 869: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 870: } 871: 872: return( USBCDC_API_SUCCESS ); 873: } 874: 875: 897: uhs_status_t Usbh_Cdc_GetCommFeature(void* pContext, 898: PCDC_COMM_FEATURE pstData) 899: { 900: PCDC_DEVICE pCdcDevice; 901: usb_device_request_t* pRequest; 902: CDC_FUNC_STATUS nRetval; 903: uhs_ubit8_t u8CntDeviceId; 904: uhs_status_t nRetStatus; 905: uhs_status_t nRetvalResorce; 906: 907: 908: 909: 910: if( pContext == NULL ){ 911: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 912: return( USBCDC_API_PARAM_ERROR ); 913: } 914: 915: 916: 917: 918: if( g_pCdcDriver == NULL ) { 919: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 920: return( USBCDC_API_SYS_SYSTEM_ERROR ); 921: } 922: 923: 924: 925: 926: 927: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 928: if(nRetStatus != USBCDC_API_SUCCESS){ 929: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 930: return(nRetStatus); 931: } 932: 933: 934: 935: 936: if(pstData == NULL) { 937: 938: 939: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 940: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 941: return( USBCDC_API_PARAM_ERROR ); 942: } 943: if( (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_ABSTRACT_STATE) && 944: (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_COUNTRY_SETTING) ) { 945: 946: 947: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 948: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 949: return( USBCDC_API_PARAM_ERROR ); 950: } 951: 952: 953: 954: 955: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 956: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 957: 958: 959: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 960: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 961: return( USBCDC_API_NOT_READY ); 962: } 963: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 964: 965: 966: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 967: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 968: return( USBCDC_API_NO_SUPPORT ); 969: } 970: else { 971: ; 972: } 973: 974: 975: 976: 977: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 978: if(pRequest == NULL) { 979: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 980: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 981: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 982: } 983: 984: 985: 986: 987: pRequest->bmRequestType = 0xA1; 988: pRequest->bRequest = 0x03; 989: pRequest->wValue0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->FeatureSelector ); 990: pRequest->wValue1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->FeatureSelector ); 991: pRequest->wIndex0 = 0x00; 992: pRequest->wIndex1 = 0x00; 993: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0002 ); 994: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0002 ); 995: 996: 997: 998: 999: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, (uhs_ubit8_t*)(&pstData->u16Data), NULL); 1000: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 1001: CdcUtils_Free(pRequest); 1002: 1003: 1004: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1005: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 1006: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 1007: } 1008: 1009: 1010: 1011: 1012: CdcUtils_Free(pRequest); 1013: 1014: 1015: 1016: 1017: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1018: if(nRetvalResorce != TRUE){ 1019: 1020: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1021: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1022: } 1023: 1024: return( USBCDC_API_SUCCESS ); 1025: } 1026: 1027: 1049: uhs_status_t Usbh_Cdc_ClearCommFeature(void* pContext, 1050: PCDC_COMM_FEATURE pstData) 1051: { 1052: PCDC_DEVICE pCdcDevice; 1053: usb_device_request_t* pRequest; 1054: CDC_FUNC_STATUS nRetval; 1055: uhs_ubit8_t u8CntDeviceId; 1056: uhs_status_t nRetStatus; 1057: uhs_status_t nRetvalResorce; 1058: 1059: 1060: 1061: 1062: if( pContext == NULL ){ 1063: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1064: return( USBCDC_API_PARAM_ERROR ); 1065: } 1066: 1067: 1068: 1069: 1070: if( g_pCdcDriver == NULL ) { 1071: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 1072: return( USBCDC_API_SYS_SYSTEM_ERROR ); 1073: } 1074: 1075: 1076: 1077: 1078: 1079: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 1080: if(nRetStatus != USBCDC_API_SUCCESS){ 1081: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 1082: return(nRetStatus); 1083: } 1084: 1085: 1086: 1087: 1088: if(pstData == NULL){ 1089: 1090: 1091: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1092: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1093: return( USBCDC_API_PARAM_ERROR ); 1094: } 1095: if( (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_ABSTRACT_STATE) && 1096: (pstData->FeatureSelector != COMM_FEATURE_SELECTOR_COUNTRY_SETTING) ) { 1097: 1098: 1099: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1100: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1101: return( USBCDC_API_PARAM_ERROR ); 1102: } 1103: 1104: 1105: 1106: 1107: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 1108: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 1109: 1110: 1111: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1112: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 1113: return( USBCDC_API_NOT_READY ); 1114: } 1115: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 1116: 1117: 1118: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1119: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 1120: return( USBCDC_API_NO_SUPPORT ); 1121: } 1122: else { 1123: ; 1124: } 1125: 1126: 1127: 1128: 1129: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 1130: if(pRequest == NULL) { 1131: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1132: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1133: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1134: } 1135: 1136: 1137: 1138: 1139: pRequest->bmRequestType = 0x21; 1140: pRequest->bRequest = 0x04; 1141: pRequest->wValue0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->FeatureSelector ); 1142: pRequest->wValue1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->FeatureSelector ); 1143: pRequest->wIndex0 = 0x00; 1144: pRequest->wIndex1 = 0x00; 1145: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0000 ); 1146: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0000 ); 1147: 1148: 1149: 1150: 1151: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, NULL, NULL); 1152: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 1153: CdcUtils_Free(pRequest); 1154: 1155: 1156: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1157: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 1158: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 1159: } 1160: 1161: 1162: 1163: 1164: CdcUtils_Free(pRequest); 1165: 1166: 1167: 1168: 1169: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1170: if(nRetvalResorce != TRUE){ 1171: 1172: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1173: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1174: } 1175: 1176: return( USBCDC_API_SUCCESS ); 1177: } 1178: 1179: 1201: uhs_status_t Usbh_Cdc_SetLineCoding(void* pContext, 1202: PCDC_LINE_CODING pstData) 1203: { 1204: PCDC_DEVICE pCdcDevice; 1205: usb_device_request_t* pRequest; 1206: CDC_FUNC_STATUS nRetval; 1207: uhs_ubit8_t *pu8SetBuff; 1208: uhs_ubit8_t u8CntDeviceId; 1209: uhs_status_t nRetStatus; 1210: uhs_status_t nRetvalResorce; 1211: 1212: 1213: 1214: 1215: if( pContext == NULL ){ 1216: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1217: return( USBCDC_API_PARAM_ERROR ); 1218: } 1219: 1220: 1221: 1222: 1223: if( g_pCdcDriver == NULL ) { 1224: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 1225: return( USBCDC_API_SYS_SYSTEM_ERROR ); 1226: } 1227: 1228: 1229: 1230: 1231: 1232: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 1233: if(nRetStatus != USBCDC_API_SUCCESS){ 1234: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 1235: return(nRetStatus); 1236: } 1237: 1238: 1239: 1240: 1241: 1242: if( pstData == NULL ) { 1243: 1244: 1245: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1246: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1247: return( USBCDC_API_PARAM_ERROR ); 1248: } 1249: if( pstData->u32BaudRate == 0 ) { 1250: 1251: 1252: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1253: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1254: return( USBCDC_API_PARAM_ERROR ); 1255: } 1256: if( (pstData->StopBit != LINE_CODING_STOPBIT_1) && 1257: (pstData->StopBit != LINE_CODING_STOPBIT_15) && 1258: (pstData->StopBit != LINE_CODING_STOPBIT_2) ) { 1259: 1260: 1261: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1262: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1263: return( USBCDC_API_PARAM_ERROR ); 1264: } 1265: if( (pstData->Parity != LINE_CODING_PARITY_NONE) && 1266: (pstData->Parity != LINE_CODING_PARITY_ODD) && 1267: (pstData->Parity != LINE_CODING_PARITY_EVEN) && 1268: (pstData->Parity != LINE_CODING_PARITY_MARK) && 1269: (pstData->Parity != LINE_CODING_PARITY_SPACE) ) { 1270: 1271: 1272: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1273: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1274: return( USBCDC_API_PARAM_ERROR ); 1275: } 1276: if( (pstData->DataBit != LINE_CODING_DATABIT_5) && 1277: (pstData->DataBit != LINE_CODING_DATABIT_6) && 1278: (pstData->DataBit != LINE_CODING_DATABIT_7) && 1279: (pstData->DataBit != LINE_CODING_DATABIT_8) && 1280: (pstData->DataBit != LINE_CODING_DATABIT_16) ) { 1281: 1282: 1283: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1284: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1285: return( USBCDC_API_PARAM_ERROR ); 1286: } 1287: 1288: 1289: 1290: 1291: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 1292: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 1293: 1294: 1295: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1296: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 1297: return( USBCDC_API_NOT_READY ); 1298: } 1299: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 1300: 1301: 1302: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1303: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 1304: return( USBCDC_API_NO_SUPPORT ); 1305: } 1306: else { 1307: ; 1308: } 1309: 1310: 1311: 1312: 1313: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 1314: if(pRequest == NULL) { 1315: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1316: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1317: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1318: } 1319: 1320: 1321: 1322: 1323: pu8SetBuff = CdcUtils_Malloc(7); 1324: if(pu8SetBuff == NULL) { 1325: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1326: CdcUtils_Free(pRequest); 1327: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1328: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1329: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1330: } 1331: 1332: 1333: 1334: 1335: pRequest->bmRequestType = 0x21; 1336: pRequest->bRequest = 0x20; 1337: pRequest->wValue0 = 0x00; 1338: pRequest->wValue1 = 0x00; 1339: pRequest->wIndex0 = 0x00; 1340: pRequest->wIndex1 = 0x00; 1341: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0007 ); 1342: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0007 ); 1343: 1344: 1345: 1346: 1347: pu8SetBuff[0] = UNPACK32_LITTLE_ENDIAN_LSB( pstData->u32BaudRate ); 1348: pu8SetBuff[1] = UNPACK32_LITTLE_ENDIAN_LSBM( pstData->u32BaudRate ); 1349: pu8SetBuff[2] = UNPACK32_LITTLE_ENDIAN_MSBM( pstData->u32BaudRate ); 1350: pu8SetBuff[3] = UNPACK32_LITTLE_ENDIAN_MSB( pstData->u32BaudRate ); 1351: pu8SetBuff[4] = (uhs_ubit8_t)(pstData->StopBit); 1352: pu8SetBuff[5] = (uhs_ubit8_t)(pstData->Parity); 1353: pu8SetBuff[6] = (uhs_ubit8_t)(pstData->DataBit); 1354: 1355: 1356: 1357: 1358: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pu8SetBuff, NULL); 1359: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 1360: CdcUtils_Free(pu8SetBuff); 1361: CdcUtils_Free(pRequest); 1362: 1363: 1364: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1365: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 1366: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 1367: } 1368: 1369: 1370: 1371: 1372: CdcUtils_Free(pu8SetBuff); 1373: 1374: 1375: 1376: 1377: CdcUtils_Free(pRequest); 1378: 1379: 1380: 1381: 1382: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1383: if(nRetvalResorce != TRUE){ 1384: 1385: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1386: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1387: } 1388: 1389: return( USBCDC_API_SUCCESS ); 1390: } 1391: 1392: 1414: uhs_status_t Usbh_Cdc_GetLineCoding(void* pContext, 1415: PCDC_LINE_CODING pstData) 1416: { 1417: PCDC_DEVICE pCdcDevice; 1418: usb_device_request_t* pRequest; 1419: CDC_FUNC_STATUS nRetval; 1420: uhs_ubit8_t *pu8GetBuff; 1421: uhs_ubit8_t u8CntDeviceId; 1422: uhs_status_t nRetStatus; 1423: uhs_status_t nRetvalResorce; 1424: 1425: 1426: 1427: 1428: if( pContext == NULL ){ 1429: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1430: return( USBCDC_API_PARAM_ERROR ); 1431: } 1432: 1433: 1434: 1435: 1436: if( g_pCdcDriver == NULL ) { 1437: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 1438: return( USBCDC_API_SYS_SYSTEM_ERROR ); 1439: } 1440: 1441: 1442: 1443: 1444: 1445: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 1446: if(nRetStatus != USBCDC_API_SUCCESS){ 1447: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 1448: return(nRetStatus); 1449: } 1450: 1451: 1452: 1453: 1454: if(pstData == NULL) { 1455: 1456: 1457: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1458: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1459: return( USBCDC_API_PARAM_ERROR ); 1460: } 1461: 1462: 1463: 1464: 1465: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 1466: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 1467: 1468: 1469: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1470: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 1471: return( USBCDC_API_NOT_READY ); 1472: } 1473: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 1474: 1475: 1476: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1477: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 1478: return( USBCDC_API_NO_SUPPORT ); 1479: } 1480: else { 1481: ; 1482: } 1483: 1484: 1485: 1486: 1487: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 1488: if(pRequest == NULL) { 1489: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1490: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1491: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1492: } 1493: 1494: 1495: 1496: 1497: pu8GetBuff = CdcUtils_Malloc(7); 1498: if(pu8GetBuff == NULL) { 1499: CdcUtils_Free(pRequest); 1500: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1501: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1502: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1503: } 1504: 1505: 1506: 1507: 1508: pRequest->bmRequestType = 0xA1; 1509: pRequest->bRequest = 0x21; 1510: pRequest->wValue0 = 0x00; 1511: pRequest->wValue1 = 0x00; 1512: pRequest->wIndex0 = 0x00; 1513: pRequest->wIndex1 = 0x00; 1514: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0007 ); 1515: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0007 ); 1516: 1517: 1518: 1519: 1520: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, pu8GetBuff, NULL); 1521: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 1522: CdcUtils_Free(pRequest); 1523: CdcUtils_Free(pu8GetBuff); 1524: 1525: 1526: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1527: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 1528: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 1529: } 1530: 1531: 1532: 1533: 1534: pstData->u32BaudRate = PACK32_LITTLE_ENDIAN( pu8GetBuff[3], pu8GetBuff[2], pu8GetBuff[1], pu8GetBuff[0] ); 1535: pstData->StopBit = (LINE_CODING_STOPBIT)(pu8GetBuff[4]); 1536: pstData->Parity = (LINE_CODING_PARITY)(pu8GetBuff[5]); 1537: pstData->DataBit = (LINE_CODING_DATABIT)(pu8GetBuff[6]); 1538: 1539: 1540: 1541: 1542: CdcUtils_Free(pu8GetBuff); 1543: 1544: 1545: 1546: 1547: CdcUtils_Free(pRequest); 1548: 1549: 1550: 1551: 1552: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1553: if(nRetvalResorce != TRUE){ 1554: 1555: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1556: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1557: } 1558: 1559: return( USBCDC_API_SUCCESS ); 1560: } 1561: 1562: 1584: uhs_status_t Usbh_Cdc_SetControlLineState(void* pContext, 1585: PCDC_CONTROL_LINE_STATE pstData) 1586: { 1587: PCDC_DEVICE pCdcDevice; 1588: usb_device_request_t* pRequest; 1589: CDC_FUNC_STATUS nRetval; 1590: uhs_ubit8_t u8CntDeviceId; 1591: uhs_status_t nRetStatus; 1592: uhs_status_t nRetvalResorce; 1593: 1594: 1595: 1596: 1597: if( pContext == NULL ){ 1598: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1599: return( USBCDC_API_PARAM_ERROR ); 1600: } 1601: 1602: 1603: 1604: 1605: if( g_pCdcDriver == NULL ) { 1606: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 1607: return( USBCDC_API_SYS_SYSTEM_ERROR ); 1608: } 1609: 1610: 1611: 1612: 1613: 1614: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 1615: if(nRetStatus != USBCDC_API_SUCCESS){ 1616: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 1617: return(nRetStatus); 1618: } 1619: 1620: 1621: 1622: 1623: if(pstData == NULL) { 1624: 1625: 1626: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1627: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1628: return( USBCDC_API_PARAM_ERROR ); 1629: } 1630: if( pstData->u16Data > 3 ) { 1631: 1632: 1633: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1634: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1635: return( USBCDC_API_PARAM_ERROR ); 1636: } 1637: 1638: 1639: 1640: 1641: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 1642: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 1643: 1644: 1645: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1646: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 1647: return( USBCDC_API_NOT_READY ); 1648: } 1649: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 1650: 1651: 1652: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1653: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 1654: return( USBCDC_API_NO_SUPPORT ); 1655: } 1656: else { 1657: ; 1658: } 1659: 1660: 1661: 1662: 1663: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 1664: if(pRequest == NULL) { 1665: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1666: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1667: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1668: } 1669: 1670: 1671: 1672: 1673: pRequest->bmRequestType = 0x21; 1674: pRequest->bRequest = 0x22; 1675: pRequest->wValue0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->u16Data ); 1676: pRequest->wValue1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->u16Data ); 1677: pRequest->wIndex0 = 0x00; 1678: pRequest->wIndex1 = 0x00; 1679: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0000 ); 1680: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0000 ); 1681: 1682: 1683: 1684: 1685: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, NULL, NULL); 1686: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 1687: CdcUtils_Free(pRequest); 1688: 1689: 1690: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1691: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 1692: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 1693: } 1694: 1695: 1696: 1697: 1698: CdcUtils_Free(pRequest); 1699: 1700: 1701: 1702: 1703: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1704: if(nRetvalResorce != TRUE){ 1705: 1706: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1707: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1708: } 1709: 1710: return( USBCDC_API_SUCCESS ); 1711: } 1712: 1713: 1735: uhs_status_t Usbh_Cdc_SendBreak(void* pContext, 1736: PCDC_SEND_BREAK pstData) 1737: { 1738: PCDC_DEVICE pCdcDevice; 1739: usb_device_request_t* pRequest; 1740: CDC_FUNC_STATUS nRetval; 1741: uhs_ubit8_t u8CntDeviceId; 1742: uhs_status_t nRetStatus; 1743: uhs_status_t nRetvalResorce; 1744: 1745: 1746: 1747: 1748: if( pContext == NULL ){ 1749: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1750: return( USBCDC_API_PARAM_ERROR ); 1751: } 1752: 1753: 1754: 1755: 1756: if( g_pCdcDriver == NULL ) { 1757: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_INIT ); 1758: return( USBCDC_API_SYS_SYSTEM_ERROR ); 1759: } 1760: 1761: 1762: 1763: 1764: 1765: nRetStatus = Usbh_Cdc_CheckDeviceStatus(pContext, &pCdcDevice, &u8CntDeviceId, ID_CLSREQ_DET); 1766: if(nRetStatus != USBCDC_API_SUCCESS){ 1767: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_SYSTEM_ERROR ); 1768: return(nRetStatus); 1769: } 1770: 1771: 1772: 1773: 1774: if(pstData == NULL) { 1775: 1776: 1777: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1778: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_PARAM_ERROR ); 1779: return( USBCDC_API_PARAM_ERROR ); 1780: } 1781: 1782: 1783: 1784: 1785: if( (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_CONNECTING) || 1786: (pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_REGIST) ) { 1787: 1788: 1789: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1790: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NOT_USE ); 1791: return( USBCDC_API_NOT_READY ); 1792: } 1793: else if( pCdcDevice->nDeviceStat == CDC_DEVICE_STAT_NO_SUPPORT ) { 1794: 1795: 1796: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1797: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_NO_SUPPORT ); 1798: return( USBCDC_API_NO_SUPPORT ); 1799: } 1800: else { 1801: ; 1802: } 1803: 1804: 1805: 1806: 1807: pRequest = CdcUtils_Malloc(sizeof(usb_device_request_t)); 1808: if(pRequest == NULL) { 1809: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1810: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1811: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1812: } 1813: 1814: 1815: 1816: 1817: pRequest->bmRequestType = 0x21; 1818: pRequest->bRequest = 0x23; 1819: pRequest->wValue0 = UNPACK16_LITTLE_ENDIAN_LSB( pstData->u16Data ); 1820: pRequest->wValue1 = UNPACK16_LITTLE_ENDIAN_MSB( pstData->u16Data ); 1821: pRequest->wIndex0 = 0x00; 1822: pRequest->wIndex1 = 0x00; 1823: pRequest->wLength0 = UNPACK16_LITTLE_ENDIAN_LSB( 0x0000 ); 1824: pRequest->wLength1 = UNPACK16_LITTLE_ENDIAN_MSB( 0x0000 ); 1825: 1826: 1827: 1828: 1829: nRetval = Usbh_Cdc_ForCommand(pCdcDevice, pRequest, NULL, NULL); 1830: if(nRetval != CDC_FUNC_STATUS_SUCCESS){ 1831: CdcUtils_Free(pRequest); 1832: 1833: 1834: (void)CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1835: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_FAILED_CLSREQ ); 1836: return( USBCDC_API_TRANS_CLSREQ_FAILED ); 1837: } 1838: 1839: 1840: 1841: 1842: CdcUtils_Free(pRequest); 1843: 1844: 1845: 1846: 1847: nRetvalResorce = CdcUtils_ReleaseSemaphore( g_pCdcDriver->pClsReqDetAccessLock[u8CntDeviceId] ); 1848: if(nRetvalResorce != TRUE){ 1849: 1850: CIAPI_CDC_REPORT_SUMMARY( USBCDC_LOG_SYS_OUT_OF_RESOURCE ); 1851: return( USBCDC_API_SYS_OUT_OF_RESOURCE ); 1852: } 1853: 1854: return( USBCDC_API_SUCCESS ); 1855: } 1856:
Copyright (c) 2017-2025 Axell Corporation. All rights reserved.