Lines Matching refs:acm
385 struct UsbAcmDevice *acm = NULL;
390 acm = (struct UsbAcmDevice *)event->context;
400 AcmEnable(acm);
404 AcmDisable(acm);
405 acm->enableEvtCnt = 0;
410 AcmSetup(acm, event->setup);
415 AcmSuspend(acm);
419 AcmResume(acm);
440 acm->notifyReq = req;
468 static int32_t SerialCtrlMsg(struct AcmDevice *acm, uint8_t request, uint16_t value, void *buf, uin…
471 if (acm == NULL || buf == NULL || acm->intPipe == NULL) {
475 uint16_t index = acm->intPipe->interfaceId;
478 if (acm->ctrlReq == NULL) {
480 acm->ctrlReq = UsbAllocRequest(acm->ctrDevHandle, 0, len);
481 if (acm->ctrlReq == NULL) {
497 if (acm->ctrPipe != NULL) {
498 parmas.pipeAddress = acm->ctrPipe->pipeAddress;
499 parmas.pipeId = acm->ctrPipe->pipeId;
506 ret = UsbFillRequest(acm->ctrlReq, acm->ctrDevHandle, &parmas);
512 ret = UsbSubmitRequestSync(acm->ctrlReq);
517 if (!acm->ctrlReq->compInfo.status) {
518 HDF_LOGE("%s status=%d ", __func__, acm->ctrlReq->compInfo.status);
523 static struct UsbInterface *GetUsbInterfaceById(const struct AcmDevice *acm, uint8_t interfaceIndex)
526 return UsbClaimInterface(acm->session, acm->busNum, acm->devAddr, interfaceIndex);
530 …const struct AcmDevice *acm, uint8_t interfaceIndex, UsbPipeType pipeType, UsbPipeDirection pipeDi…
535 info = &acm->ctrIface->info;
536 interfaceHandle = acm->ctrDevHandle;
539 info = &acm->iface[interfaceIndex]->info;
540 interfaceHandle = InterfaceIdToHandle(acm, info->interfaceIndex);
564 static struct UsbPipeInfo *GetPipe(const struct AcmDevice *acm, UsbPipeType pipeType, UsbPipeDirect…
567 if (acm == NULL) {
571 for (i = 0; i < acm->interfaceCnt; i++) {
573 if (!acm->iface[i]) {
577 p = EnumePipe(acm, i, pipeType, pipeDirection);
591 struct AcmDevice *acm = NULL;
597 acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm));
598 if (acm == NULL) {
602 // 初始化互斥锁,&acm->lock表示指向互斥量的指针
603 if (OsalMutexInit(&acm->lock) != HDF_SUCCESS) {
611 acm->busNum = (uint8_t)info->busNum;
612 acm->devAddr = (uint8_t)info->devNum;
613 acm->interfaceCnt = info->interfaceLength;
614 …err = memcpy_s((void *)(acm->interfaceIndex), USB_MAX_INTERFACES, (const void *)info->interfaceNum…
624 acm->device = device;
625 device->service = &(acm->service);
626 acm->device->service->Dispatch = UsbSerialDeviceDispatch;
631 if (OsalMutexDestroy(&acm->lock)) {
635 OsalMemFree(acm);
636 acm = NULL;
640 static int32_t AcmAllocReadRequests(struct AcmDevice *acm)
646 …acm->readReq[i] = UsbAllocRequest(InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), 0, acm->…
647 if (!acm->readReq[i]) {
651 readParmas.userData = (void *)acm;
652 readParmas.pipeAddress = acm->dataInPipe->pipeAddress;
653 readParmas.pipeId = acm->dataInPipe->pipeId;
654 readParmas.interfaceId = acm->dataInPipe->interfaceId;
659 …readParmas.dataReq.directon = (((uint8_t)acm->dataInPipe->pipeDirection) >> USB_PIPE_DIR_OFFSET) &…
660 readParmas.dataReq.length = (int)acm->readSize;
662 …ret = UsbFillRequest(acm->readReq[i], InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), &rea…
671 AcmFreeReadRequests(acm);
675 static int32_t AcmAllocNotifyRequest(struct AcmDevice *acm)
680 …acm->notifyReq = UsbAllocRequest(InterfaceIdToHandle(acm, acm->intPipe->interfaceId), 0, acm->intS…
681 if (!acm->notifyReq) {
685 intParmas.userData = (void *)acm;
686 intParmas.pipeAddress = acm->intPipe->pipeAddress;
687 intParmas.pipeId = acm->intPipe->pipeId;
688 intParmas.interfaceId = acm->intPipe->interfaceId;
693 …intParmas.dataReq.directon = (((uint8_t)acm->intPipe->pipeDirection) >> USB_PIPE_DIR_OFFSET) & DIR…
694 intParmas.dataReq.length = (int)acm->intSize;
696 …ret = UsbFillRequest(acm->notifyReq, InterfaceIdToHandle(acm, acm->intPipe->interfaceId), &intParm…
704 AcmFreeNotifyReqeust(acm);
708 static void AcmReleaseInterfaces(struct AcmDevice *acm)
710 for (uint8_t i = 0; i < acm->interfaceCnt; i++) {
711 if (acm->iface[i]) {
713 UsbReleaseInterface(acm->iface[i]);
714 acm->iface[i] = NULL;
717 if (acm->ctrIface) {
718 UsbReleaseInterface(acm->ctrIface);
719 acm->ctrIface = NULL;
723 static int32_t AcmClaimInterfaces(struct AcmDevice *acm)
725 for (uint8_t i = 0; i < acm->interfaceCnt; i++) {
727 acm->iface[i] = GetUsbInterfaceById((const struct AcmDevice *)acm, acm->interfaceIndex[i]);
728 if (acm->iface[i] == NULL) {
729 HDF_LOGE("%s: interface%d is null", __func__, acm->interfaceIndex[i]);
734 acm->ctrIface = GetUsbInterfaceById((const struct AcmDevice *)acm, USB_CTRL_INTERFACE_ID);
735 if (acm->ctrIface == NULL) {
743 // 根据acm->interfaceCnt循环释放接口对象
744 AcmReleaseInterfaces(acm);
748 static void AcmCloseInterfaces(struct AcmDevice *acm)
750 for (uint8_t i = 0; i < acm->interfaceCnt; i++) {
751 if (acm->devHandle[i]) {
753 UsbCloseInterface(acm->devHandle[i]);
754 acm->devHandle[i] = NULL;
757 if (acm->ctrDevHandle) {
758 UsbCloseInterface(acm->ctrDevHandle);
759 acm->ctrDevHandle = NULL;
763 static int32_t AcmOpenInterfaces(struct AcmDevice *acm)
765 for (uint8_t i = 0; i < acm->interfaceCnt; i++) {
766 if (acm->iface[i]) {
768 acm->devHandle[i] = UsbOpenInterface(acm->iface[i]);
769 if (acm->devHandle[i] == NULL) {
775 acm->ctrDevHandle = UsbOpenInterface(acm->ctrIface);
776 if (acm->ctrDevHandle == NULL) {
785 AcmCloseInterfaces(acm);
789 static int32_t AcmGetPipes(struct AcmDevice *acm)
792 acm->dataInPipe = GetPipe(acm, USB_PIPE_TYPE_BULK, USB_PIPE_DIRECTION_IN);
793 if (acm->dataInPipe == NULL) {
798 acm->dataOutPipe = GetPipe(acm, USB_PIPE_TYPE_BULK, USB_PIPE_DIRECTION_OUT);
799 if (acm->dataOutPipe == NULL) {
804 …acm->ctrPipe = EnumePipe(acm, acm->ctrIface->info.interfaceIndex, USB_PIPE_TYPE_CONTROL, USB_PIPE_…
805 if (acm->ctrPipe == NULL) {
810 acm->intPipe = GetPipe(acm, USB_PIPE_TYPE_INTERRUPT, USB_PIPE_DIRECTION_IN);
811 if (acm->intPipe == NULL) {
816 acm->readSize = acm->dataInPipe->maxPacketSize;
817 acm->writeSize = acm->dataOutPipe->maxPacketSize;
818 acm->ctrlSize = acm->ctrPipe->maxPacketSize;
819 acm->intSize = acm->intPipe->maxPacketSize;
825 AcmFreePipes(acm);
829 static void AcmFreeRequests(struct AcmDevice *acm)
835 AcmFreeReadRequests(acm);
836 AcmFreeNotifyReqeust(acm);
837 AcmFreeWriteRequests(acm);
838 AcmWriteBufFree(acm);
841 static int32_t AcmAllocRequests(const struct AcmDevice *acm)
845 if (AcmWriteBufAlloc(acm) < 0) {
851 struct AcmWb *snd = (struct AcmWb *)&(acm->wb[i]);
854 … InterfaceIdToHandle((struct AcmDevice *)acm, acm->dataOutPipe->interfaceId), 0, acm->writeSize);
855 snd->instance = (struct AcmDevice *)acm;
862 ret = AcmAllocNotifyRequest((struct AcmDevice *)acm); // 分配并填充中断IO Request对象
868 ret = AcmAllocReadRequests((struct AcmDevice *)acm); // 分配并填充readReq IO Request对象
877 AcmFreeNotifyReqeust((struct AcmDevice *)acm);
879 AcmFreeWriteRequests((struct AcmDevice *)acm);
881 AcmWriteBufFree((struct AcmDevice *)acm);
885 static int32_t AcmInit(struct AcmDevice *acm)
889 if (acm->initFlag) {
899 acm->session = NULL;
900 // 根据acm->interfaceIndex[i]分别获取UsbInterface接口对象
901 ret = AcmClaimInterfaces(acm);
906 // 根据acm->iface[i]分别打开UsbInterface接口对象
907 ret = AcmOpenInterfaces(acm);
913 ret = AcmGetPipes(acm);
919 ret = AcmAllocRequests(acm);
925 acm->lineCoding.dwDTERate = CPU_TO_LE32(DATARATE);
926 acm->lineCoding.bCharFormat = USB_CDC_1_STOP_BITS;
927 acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
928 acm->lineCoding.bDataBits = DATA_BITS_LENGTH;
929 acm->initFlag = true;
934 AcmFreePipes(acm);
937 AcmCloseInterfaces(acm);
940 AcmReleaseInterfaces(acm);
942 // 在主机端退出USB DDK,acm->session代表指向会话上下文的指针
943 UsbExitHostSdk(acm->session);
944 acm->session = NULL;
948 static void AcmRelease(struct AcmDevice *acm)
950 if (!(acm->initFlag)) {
955 AcmCloseInterfaces(acm);
956 AcmReleaseInterfaces(acm);
957 AcmFreeRequests(acm);
958 AcmFreePipes(acm);
960 UsbExitHostSdk(acm->session);
961 acm->session = NULL;
963 acm->initFlag = false;
969 struct AcmDevice *acm = NULL;
975 acm = (struct AcmDevice *)device->service;
976 // 初始化互斥锁,&acm->readLock表示指向互斥量的指针
977 if (acm == NULL) {
980 OsalMutexInit(&acm->readLock);
981 OsalMutexInit(&acm->writeLock);
982 HDF_LOGD("%s:%d busNum = %d,devAddr = %d", __func__, __LINE__, acm->busNum, acm->devAddr);
984 ret = UsbSerialDeviceAlloc(acm);
989 acm->initFlag = false;
999 struct AcmDevice *acm = NULL;
1005 acm = (struct AcmDevice *)device->service;
1006 if (acm == NULL) {
1007 HDF_LOGE("%s: acm is null", __func__);
1013 if (acm->initFlag) {
1015 AcmRelease(acm);
1018 UsbSeriaDevicelFree(acm);
1020 OsalMutexDestroy(&acm->writeLock);
1021 OsalMutexDestroy(&acm->readLock);
1022 OsalMutexDestroy(&acm->lock);
1023 OsalMemFree(acm);
1024 acm = NULL;
1144 static int32_t UsbAllocWriteRequests(struct AcmDevice *acm)
1149 struct AcmWb *snd = &acm->wb[i];
1151 snd->request = UsbRawAllocRequest(acm->devHandle, 0, acm->dataOutEp->maxPacketSize);
1152 snd->instance = acm;
1165 struct AcmDevice *acm = NULL;
1174 acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm));
1175 if (acm == NULL) {
1179 if (OsalMutexInit(&acm->lock) != HDF_SUCCESS) {
1186 acm->busNum = (uint8_t)info->busNum;
1187 acm->devAddr = (uint8_t)info->devNum;
1188 acm->interfaceCnt = info->interfaceLength;
1189 …err = memcpy_s((void *)(acm->interfaceIndex), USB_MAX_INTERFACES, (const void *)info->interfaceNum…
1200 device->service = &(acm->service);
1202 acm->device = device;
1207 if (OsalMutexDestroy(&acm->lock)) {
1211 OsalMemFree(acm);
1212 acm = NULL;
1216 static int32_t UsbAllocReadRequests(struct AcmDevice *acm)
1219 uint32_t size = acm->dataInEp->maxPacketSize;
1223 acm->readReq[i] = UsbRawAllocRequest(acm->devHandle, 0, size);
1224 if (!acm->readReq[i]) {
1229 reqData.endPoint = acm->dataInEp->addr;
1232 reqData.userData = (void *)acm;
1236 int32_t ret = UsbRawFillBulkRequest(acm->readReq[i], acm->devHandle, &reqData);
1246 static int32_t UsbAllocNotifyRequest(struct AcmDevice *acm)
1249 uint32_t size = acm->notifyEp->maxPacketSize;
1252 acm->notifyReq = UsbRawAllocRequest(acm->devHandle, 0, size);
1253 if (!acm->notifyReq) {
1258 fillRequestData.endPoint = acm->notifyEp->addr;
1262 fillRequestData.userData = (void *)acm;
1265 ret = UsbRawFillInterruptRequest(acm->notifyReq, acm->devHandle, &fillRequestData);
1274 static int32_t UsbSerialInit(struct AcmDevice *acm)
1280 if (acm->initFlag) {
1290 acm->session = session;
1292 devHandle = UsbRawOpenDevice(session, acm->busNum, acm->devAddr);
1298 acm->devHandle = devHandle;
1300 ret = UsbGetConfigDescriptor(devHandle, &acm->config);
1306 ret = UsbParseConfigDescriptor(acm, acm->config);
1313 ret = AcmWriteBufAlloc(acm);
1319 ret = UsbAllocWriteRequests(acm);
1325 ret = UsbAllocNotifyRequest(acm);
1330 ret = UsbAllocReadRequests(acm);
1335 ret = UsbStartIo(acm);
1341 acm->lineCoding.dwDTERate = CPU_TO_LE32(DATARATE);
1342 acm->lineCoding.bCharFormat = USB_CDC_1_STOP_BITS;
1343 acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
1344 acm->lineCoding.bDataBits = DATA_BITS_LENGTH;
1346 ret = UsbRawSubmitRequest(acm->notifyReq);
1352 acm->initFlag = true;
1359 UsbStopIo(acm); // 停止IO线程并释放所有资源
1361 UsbFreeReadRequests(acm);
1363 UsbFreeNotifyReqeust(acm);
1365 UsbFreeWriteRequests(acm);
1367 AcmWriteBufFree(acm);
1369 UsbReleaseInterfaces(acm);
1371 UsbRawFreeConfigDescriptor(acm->config);
1372 acm->config = NULL;
1376 UsbRawExit(acm->session); // 退出USB DDK的专家模式
1381 static void UsbSerialRelease(struct AcmDevice *acm)
1383 if (!(acm->initFlag)) {
1389 UsbStopIo(acm);
1394 UsbFreeReadRequests(acm);
1395 UsbFreeNotifyReqeust(acm);
1396 UsbFreeWriteRequests(acm);
1397 AcmWriteBufFree(acm);
1398 UsbReleaseInterfaces(acm);
1399 (void)UsbRawCloseDevice(acm->devHandle);
1400 UsbRawFreeConfigDescriptor(acm->config);
1401 acm->config = NULL;
1403 UsbRawExit(acm->session);
1405 acm->initFlag = false;
1410 struct AcmDevice *acm = NULL;
1417 acm = (struct AcmDevice *)device->service;
1418 if (acm == NULL) {
1421 OsalMutexInit(&acm->readLock);
1422 OsalMutexInit(&acm->writeLock);
1424 ret = UsbSerialDeviceAlloc(acm);
1429 acm->initFlag = false;
1437 struct AcmDevice *acm = NULL;
1443 acm = (struct AcmDevice *)device->service;
1444 if (acm == NULL) {
1445 HDF_LOGE("%s: acm is null", __func__);
1451 if (acm->initFlag) {
1453 UsbSerialRelease(acm);
1455 UsbSeriaDevicelFree(acm);
1456 OsalMutexDestroy(&acm->writeLock);
1457 OsalMutexDestroy(&acm->readLock);
1458 OsalMutexDestroy(&acm->lock);
1459 OsalMemFree(acm);
1460 acm = NULL;
1476 USB ACM设备核心代码路径为drivers\peripheral\usb\gadget\function\acm\cdcacm.c。其使用示例如下所示,首先根据描述符创建设备,然后获取接口,打开…
1481 static int32_t AcmCreateFuncDevice(struct UsbAcmDevice *acm, struct DeviceResourceIface *iface)
1486 …if (iface->GetString(acm->device->property, "udc_name", (const char **)&acm->udcName, UDC_NAME) !=…
1491 fnDev = (struct UsbFnDevice *)UsbFnGetDevice(acm->udcName);
1496 // 解析acm每一个Iface
1497 ret = AcmParseEachIface(acm, fnDev);
1503 acm->fnDev = fnDev;
1512 static int32_t AcmParseEachPipe(struct UsbAcmDevice *acm, struct UsbAcmInterface *iface)
1528 acm->notifyPipe.id = pipeInfo.id;
1529 acm->notifyPipe.maxPacketSize = pipeInfo.maxPacketSize;
1530 acm->ctrlIface = *iface;
1534 acm->dataInPipe.id = pipeInfo.id;
1535 acm->dataInPipe.maxPacketSize = pipeInfo.maxPacketSize;
1536 acm->dataIface = *iface;
1538 acm->dataOutPipe.id = pipeInfo.id;
1539 acm->dataOutPipe.maxPacketSize = pipeInfo.maxPacketSize;
1551 static int32_t AcmParseEachIface(struct UsbAcmDevice *acm, struct UsbFnDevice *fnDev)
1566 (void)AcmParseAcmIface(acm, fnIface);
1572 (void)AcmParseAcmIface(acm, fnIface);
1583 static int32_t AcmAllocCtrlRequests(struct UsbAcmDevice *acm, int32_t num)
1585 struct DListHead *head = &acm->ctrlPool;
1590 DListHeadInit(&acm->ctrlPool);
1591 acm->ctrlReqNum = 0;
1600 ctrlInfo->acm = acm;
1602 … acm->ctrlIface.handle, sizeof(struct UsbCdcLineCoding) + sizeof(struct UsbCdcLineCoding));
1609 acm->ctrlReqNum++;
1622 struct UsbAcmDevice *acm, uint8_t type, uint16_t value, const void *data, uint32_t length)
1624 struct UsbFnRequest *req = acm->notifyReq;
1633 acm->notifyReq = NULL;
1634 acm->pending = false;
1641 notify->wIndex = CPU_TO_LE16(acm->ctrlIface.fn->info.index);
1652 acm->notifyReq = req;
1662 static int32_t AcmReleaseFuncDevice(struct UsbAcmDevice *acm)
1666 (void)UsbFnInterfaceClose(acm->ctrlIface.handle);
1667 (void)UsbFnInterfaceClose(acm->dataIface.handle);
1669 (void)UsbFnInterfaceStopRecvEvent(acm->ctrlIface.fn);
1671 ret = UsbFnDeviceRemove(acm->fnDev);
1677 static int32_t AcmReleaseFuncDevice(struct UsbAcmDevice *acm)
1680 if (acm->fnDev == NULL) {
1685 AcmFreeCtrlRequests(acm);
1686 AcmFreeNotifyRequest(acm);
1688 (void)UsbFnCloseInterface(acm->ctrlIface.handle);
1689 (void)UsbFnCloseInterface(acm->dataIface.handle);
1690 (void)UsbFnStopRecvInterfaceEvent(acm->ctrlIface.fn);