Lines Matching refs:acm
358 descData.property = acm->device->property;
361 fnDev = (struct UsbFnDevice *) UsbFnCreateDevice(acm->udcName, &descData);
374 req = UsbFnAllocCtrlRequest(acm->ctrlIface.handle,
377 req = UsbFnAllocCtrlRequest(acm->ctrlIface.handle,
385 ret = UsbFnStartRecvInterfaceEvent(acm->ctrlIface.fn, 0xff, UsbAcmEventCallback, acm);
389 struct UsbAcmDevice *acm = NULL;
395 acm = (struct UsbAcmDevice *)event->context;
405 AcmEnable(acm);
409 AcmDisable(acm);
410 acm->enableEvtCnt = 0;
415 AcmSetup(acm, event->setup);
420 AcmSuspend(acm);
424 AcmResume(acm);
467 static int32_t SerialCtrlMsg(struct AcmDevice *acm, uint8_t request,
471 uint16_t index = acm->intPipe->interfaceId;
474 if (acm == NULL || buf == NULL) {
477 if (acm->ctrlReq == NULL) {
479 acm->ctrlReq = UsbAllocRequest(acm->ctrDevHandle, 0, len);
480 if (acm->ctrlReq == NULL) {
495 params.pipeAddress = acm->ctrPipe->pipeAddress;
496 params.pipeId = acm->ctrPipe->pipeId;
501 ret = UsbFillRequest(acm->ctrlReq, acm->ctrDevHandle, ¶ms);
506 ret = UsbSubmitRequestSync(acm->ctrlReq);
510 if (!acm->ctrlReq->compInfo.status) {
511 HDF_LOGE("%s status=%d ", __func__, acm->ctrlReq->compInfo.status);
516 static struct UsbInterface *GetUsbInterfaceById(const struct AcmDevice *acm,
521 …tmpIf = (struct UsbInterface *)UsbClaimInterface(acm->session, acm->busNum, acm->devAddr, interfac…
525 static struct UsbPipeInfo *EnumePipe(const struct AcmDevice *acm,
534 info = &acm->ctrIface->info;
535 interfaceHandle = acm->ctrDevHandle;
539 info = &acm->iface[interfaceIndex]->info;
541 interfaceHandle = InterfaceIdToHandle(acm, info->interfaceIndex);
564 static struct UsbPipeInfo *GetPipe(const struct AcmDevice *acm,
568 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;
595 acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm));
596 if (acm == NULL) {
599 // Initialize the mutex. &acm->lock indicates the pointer pointing to the mutex.
600 if (OsalMutexInit(&acm->lock) != HDF_SUCCESS) {
605 acm->busNum = info->busNum;
606 acm->devAddr = info->devNum;
607 acm->interfaceCnt = info->interfaceLength;
608 err = memcpy_s((void *)(acm->interfaceIndex), USB_MAX_INTERFACES,
616 acm->device = device;
617 device->service = &(acm->service);
618 acm->device->service->Dispatch = UsbSerialDeviceDispatch;
622 if (OsalMutexDestroy(&acm->lock)) {
626 OsalMemFree(acm);
627 acm = NULL;
631 static int32_t AcmAllocReadRequests(struct AcmDevice *acm)
637 …acm->readReq[i] = UsbAllocRequest(InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), 0, acm->…
638 if (!acm->readReq[i]) {
641 readParams.userData = (void *)acm;
642 readParams.pipeAddress = acm->dataInPipe->pipeAddress;
643 readParams.pipeId = acm->dataInPipe->pipeId;
644 readParams.interfaceId = acm->dataInPipe->interfaceId;
649 … readParams.dataReq.direction = (acm->dataInPipe->pipeDirection >> USB_PIPE_DIR_OFFSET) & 0x1;
650 readParams.dataReq.length = acm->readSize;
652 …ret = UsbFillRequest(acm->readReq[i], InterfaceIdToHandle(acm, acm->dataInPipe->interfaceId), &rea…
660 AcmFreeReadRequests(acm);
664 static int32_t AcmAllocNotifyRequest(struct AcmDevice *acm)
669 …acm->notifyReq = UsbAllocRequest(InterfaceIdToHandle(acm, acm->intPipe->interfaceId), 0, acm->intS…
670 if (!acm->notifyReq) {
673 intParams.userData = (void *)acm;
674 intParams.pipeAddress = acm->intPipe->pipeAddress;
675 intParams.pipeId = acm->intPipe->pipeId;
676 intParams.interfaceId = acm->intPipe->interfaceId;
681 …intParams.dataReq.direction = (acm->intPipe->pipeDirection >> USB_PIPE_DIR_OFFSET) & DIRECTION_MAS…
682 intParams.dataReq.length = acm->intSize;
684 …ret = UsbFillRequest(acm->notifyReq, InterfaceIdToHandle(acm, acm->intPipe->interfaceId), &intPara…
691 AcmFreeNotifyRequest(acm);
695 static void AcmReleaseInterfaces(struct AcmDevice *acm)
697 for (int32_t i = 0; i < acm->interfaceCnt; i++) {
698 if (acm->iface[i]) {
700 UsbReleaseInterface(acm->iface[i]);
701 acm->iface[i] = NULL;
704 if (acm->ctrIface) {
705 UsbReleaseInterface(acm->ctrIface);
706 acm->ctrIface = NULL;
710 static int32_t AcmClaimInterfaces(struct AcmDevice *acm)
712 for (int32_t i = 0; i < acm->interfaceCnt; i++) {
714 acm->iface[i] = GetUsbInterfaceById((const struct AcmDevice *)acm, acm->interfaceIndex[i]);
715 if (acm->iface[i] == NULL) {
721 acm->ctrIface = GetUsbInterfaceById((const struct AcmDevice *)acm, USB_CTRL_INTERFACE_ID);
722 if (acm->ctrIface == NULL) {
729 // Release the UsbInterface object cyclically based on acm->interfaceCnt.
730 AcmReleaseInterfaces(acm);
734 static void AcmCloseInterfaces(struct AcmDevice *acm)
736 for (int32_t i = 0; i < acm->interfaceCnt; i++) {
737 if (acm->devHandle[i]) {
739 UsbCloseInterface(acm->devHandle[i]);
740 acm->devHandle[i] = NULL;
743 if (acm->ctrDevHandle) {
744 UsbCloseInterface(acm->ctrDevHandle);
745 acm->ctrDevHandle = NULL;
749 static int32_t AcmOpenInterfaces(struct AcmDevice *acm)
751 for (int32_t i = 0; i < acm->interfaceCnt; i++) {
752 if (acm->iface[i]) {
754 acm->devHandle[i] = UsbOpenInterface(acm->iface[i]);
755 if (acm->devHandle[i] == NULL) {
760 acm->ctrDevHandle = UsbOpenInterface(acm->ctrIface);
761 if (acm->ctrDevHandle == NULL) {
769 AcmCloseInterfaces(acm);
773 static int32_t AcmGetPipes(struct AcmDevice *acm)
776 acm->dataInPipe = GetPipe(acm, USB_PIPE_TYPE_BULK, USB_PIPE_DIRECTION_IN);
777 if (acm->dataInPipe == NULL) {
782 acm->dataOutPipe = GetPipe(acm, USB_PIPE_TYPE_BULK, USB_PIPE_DIRECTION_OUT);
783 if (acm->dataOutPipe == NULL) {
788 …acm->ctrPipe = EnumePipe(acm, acm->ctrIface->info.interfaceIndex, USB_PIPE_TYPE_CONTROL, USB_PIPE_…
789 if (acm->ctrPipe == NULL) {
794 acm->intPipe = GetPipe(acm, USB_PIPE_TYPE_INTERRUPT, USB_PIPE_DIRECTION_IN);
795 if (acm->intPipe == NULL) {
799 acm->readSize = acm->dataInPipe->maxPacketSize;
800 acm->writeSize = acm->dataOutPipe->maxPacketSize;
801 acm->ctrlSize = acm->ctrPipe->maxPacketSize;
802 acm->intSize = acm->intPipe->maxPacketSize;
807 AcmFreePipes(acm);
811 static void AcmFreeRequests(struct AcmDevice *acm)
817 AcmFreeReadRequests(acm);
818 AcmFreeNotifyRequest(acm);
819 AcmFreeWriteRequests(acm);
820 AcmWriteBufFree(acm);
823 static int32_t AcmAllocRequests(struct AcmDevice *acm)
827 if (AcmWriteBufAlloc(acm) < 0) {
832 struct AcmWb *snd = &(acm->wb[i]);
834 …snd->request = UsbAllocRequest(InterfaceIdToHandle(acm, acm->dataOutPipe->interfaceId), 0, acm->wr…
835 snd->instance = acm;
841 ret = AcmAllocNotifyRequest(acm); // Allocate and fill in the interrupt I/O request.
846 ret = AcmAllocReadRequests(acm); // Allocate and fill in the readReq I/O request.
854 AcmFreeNotifyRequest(acm);
856 AcmFreeWriteRequests(acm);
858 AcmWriteBufFree(acm);
862 static int32_t AcmInit(struct AcmDevice *acm)
867 if (acm->initFlag == true) {
876 acm->session = session;
878 // Obtain UsbInterface objects based on acm->interfaceIndex[i].
879 ret = AcmClaimInterfaces(acm);
884 // Open UsbInterface objects based on acm->iface[i].
885 ret = AcmOpenInterfaces(acm);
891 ret = AcmGetPipes(acm);
896 ret = AcmAllocRequests(acm);
901 acm->lineCoding.dwDTERate = CpuToLe32(DATARATE); // Convert to little-endian data.
902 acm->lineCoding.bCharFormat = CHARFORMAT; // 8
903 acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
904 acm->lineCoding.bDataBits = USB_CDC_1_STOP_BITS;
905 acm->initFlag = true;
909 AcmFreePipes(acm);
912 AcmCloseInterfaces(acm);
915 AcmReleaseInterfaces(acm);
917 …// Exit the USB DDK on the host. acm->session indicates the pointer pointing to the session contex…
918 UsbExitHostSdk(acm->session);
919 acm->session = NULL;
923 static void AcmRelease(struct AcmDevice *acm)
925 if (acm->initFlag == false) {
929 AcmFreeRequests(acm);
930 AcmFreePipes(acm);
931 AcmCloseInterfaces(acm);
932 AcmReleaseInterfaces(acm);
934 UsbExitHostSdk(acm->session);
935 acm->session = NULL;
936 acm->initFlag = false;
942 struct AcmDevice *acm = NULL;
947 acm = (struct AcmDevice *)device->service;
948 // Initialize the mutex. &acm->readLock indicates the pointer pointing to the mutex.
949 OsalMutexInit(&acm->readLock);
950 OsalMutexInit(&acm->writeLock);
951 HDF_LOGD("%s:%d busNum=%d,devAddr=%d", __func__, __LINE__, acm->busNum, acm->devAddr);
954 ret = UsbSerialDeviceAlloc(acm);
959 acm->initFlag = false;
966 struct AcmDevice *acm = NULL;
971 acm = (struct AcmDevice *)device->service;
972 if (acm == NULL) {
978 if (acm->initFlag == true) {
979 AcmRelease(acm);
982 UsbSeriaDevicelFree(acm);
984 OsalMutexDestroy(&acm->writeLock);
985 OsalMutexDestroy(&acm->readLock);
986 OsalMutexDestroy(&acm->lock);
987 OsalMemFree(acm);
988 acm = NULL;
1105 static int32_t UsbAllocWriteRequests(struct AcmDevice *acm)
1110 struct AcmWb *snd = &acm->wb[i];
1112 snd->request = UsbRawAllocRequest(acm->devHandle, 0, acm->dataOutEp->maxPacketSize);
1113 snd->instance = acm;
1125 struct AcmDevice *acm = NULL;
1133 acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm));
1134 if (acm == NULL) {
1137 if (OsalMutexInit(&acm->lock) != HDF_SUCCESS) {
1143 acm->busNum = info->busNum;
1144 acm->devAddr = info->devNum;
1145 acm->interfaceCnt = info->interfaceLength;
1146 err = memcpy_s((void *)(acm->interfaceIndex), USB_MAX_INTERFACES,
1155 device->service = &(acm->service);
1157 acm->device = device;
1161 if (OsalMutexDestroy(&acm->lock)) {
1165 OsalMemFree(acm);
1166 acm = NULL;
1170 static int32_t UsbAllocReadRequests(struct AcmDevice *acm)
1173 int32_t size = acm->dataInEp->maxPacketSize;
1178 acm->readReq[i] = UsbRawAllocRequest(acm->devHandle, 0, size);
1179 if (!acm->readReq[i]) {
1183 reqData.endPoint = acm->dataInEp->addr;
1186 reqData.userData = (void *)acm;
1191 ret = UsbRawFillBulkRequest(acm->readReq[i], acm->devHandle, &reqData);
1200 static int32_t UsbAllocNotifyRequest(struct AcmDevice *acm)
1203 int32_t size = acm->notifyEp->maxPacketSize;
1207 acm->notifyReq = UsbRawAllocRequest(acm->devHandle, 0, size);
1208 if (!acm->notifyReq) {
1212 fillRequestData.endPoint = acm->notifyEp->addr;
1216 fillRequestData.userData = (void *)acm;
1220 ret = UsbRawFillInterruptRequest(acm->notifyReq, acm->devHandle, &fillRequestData);
1228 static int32_t UsbSerialInit(struct AcmDevice *acm)
1234 if (acm->initFlag == true) {
1243 acm->session = session;
1246 devHandle = UsbRawOpenDevice(session, acm->busNum, acm->devAddr);
1251 acm->devHandle = devHandle;
1253 ret = UsbGetConfigDescriptor(devHandle, &acm->config);
1258 ret = UsbParseConfigDescriptor(acm, acm->config);
1264 ret = AcmWriteBufAlloc(acm);
1269 ret = UsbAllocWriteRequests(acm);
1274 ret = UsbAllocNotifyRequest(acm);
1278 ret = UsbAllocReadRequests(acm);
1282 ret = UsbStartIo(acm);
1287 acm->lineCoding.dwDTERate = CpuToLe32(DATARATE);
1288 acm->lineCoding.bCharFormat = CHARFORMAT;
1289 acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
1290 acm->lineCoding.bDataBits = USB_CDC_1_STOP_BITS;
1292 ret = UsbRawSubmitRequest(acm->notifyReq);
1297 acm->initFlag = true;
1301 UsbStopIo(acm); // Stop the I/O thread and release all resources.
1303 UsbFreeReadRequests(acm);
1305 UsbFreeNotifyRequest(acm);
1307 UsbFreeWriteRequests(acm);
1309 AcmWriteBufFree(acm);
1311 UsbReleaseInterfaces(acm);
1313 UsbRawFreeConfigDescriptor(acm->config);
1314 acm->config = NULL;
1318 UsbRawExit(acm->session); // Exit the expert mode of the USB DDK.
1323 static void UsbSerialRelease(struct AcmDevice *acm)
1325 if (acm->initFlag == false) {
1330 UsbStopIo(acm);
1335 UsbFreeReadRequests(acm);
1336 UsbFreeNotifyRequest(acm);
1337 UsbFreeWriteRequests(acm);
1338 AcmWriteBufFree(acm);
1339 (void)UsbRawCloseDevice(acm->devHandle);
1340 UsbReleaseInterfaces(acm);
1341 UsbRawFreeConfigDescriptor(acm->config);
1342 acm->config = NULL;
1344 UsbRawExit(acm->session);
1346 acm->initFlag = false;
1351 struct AcmDevice *acm = NULL;
1357 acm = (struct AcmDevice *)device->service;
1358 OsalMutexInit(&acm->readLock);
1359 OsalMutexInit(&acm->writeLock);
1361 ret = UsbSerialDeviceAlloc(acm);
1366 acm->initFlag = false;
1373 struct AcmDevice *acm = NULL;
1378 acm = (struct AcmDevice *)device->service;
1379 if (acm == NULL) {
1385 if (acm->initFlag == true) {
1386 UsbSerialRelease(acm);
1388 UsbSeriaDevicelFree(acm);
1389 OsalMutexDestroy(&acm->writeLock);
1390 OsalMutexDestroy(&acm->readLock);
1391 OsalMutexDestroy(&acm->lock);
1392 OsalMemFree(acm);
1393 acm = NULL;
1408 The core code of the USB ACM device is stored in **drivers\peripheral\usb\gadget\function\acm\cdcac…
1413 static int32_t AcmCreateFuncDevice(struct UsbAcmDevice *acm, struct DeviceResourceIface *iface)
1427 fnDev = (struct UsbFnDevice *)UsbFnDeviceCreate(acm->udcName, &descData);
1438 static int32_t AcmParseEachPipe(struct UsbAcmDevice *acm, struct UsbAcmInterface *iface)
1450 static int32_t AcmParseEachIface(struct UsbAcmDevice *acm, struct UsbFnDevice *fnDev)
1468 static int32_t AcmAllocCtrlRequests(struct UsbAcmDevice *acm, int32_t num)
1471 req = UsbFnCtrlRequestAlloc(acm->ctrlIface.handle,
1479 ret = UsbFnInterfaceStartRecvEvent(acm->ctrlIface.fn, 0xff, UsbAcmEventCallback, acm);
1487 static int32_t AcmSendNotifyRequest(struct UsbAcmDevice *acm, uint8_t type,
1500 static int32_t AcmReleaseFuncDevice(struct UsbAcmDevice *acm)
1504 (void)UsbFnInterfaceClose(acm->ctrlIface.handle);
1505 (void)UsbFnInterfaceClose(acm->dataIface.handle);
1507 (void)UsbFnInterfaceStopRecvEvent(acm->ctrlIface.fn);
1509 ret = UsbFnDeviceRemove(acm->fnDev);