Lines Matching defs:acm

37 static int32_t SerialSendCtrlMsg(struct AcmDevice *acm, uint8_t request, uint16_t value, void *buf, uint16_t len);
39 static int32_t UsbSerialInit(struct AcmDevice *acm);
40 static void UsbSerialRelease(struct AcmDevice *acm);
45 struct AcmDevice *acm = (struct AcmDevice *)data;
48 if (acm == NULL) {
49 HDF_LOGE("%{public}s:%{public}d acm is null", __func__, __LINE__);
54 if (acm->devHandle == NULL) {
55 HDF_LOGE("%{public}s:%{public}d acm->devHandle is null", __func__, __LINE__);
60 ret = UsbRawHandleRequests(acm->devHandle);
77 static int32_t UsbStartIo(struct AcmDevice *acm)
96 ret = OsalThreadCreate(&acm->ioThread, (OsalThreadEntry)UsbIoThread, (void *)acm);
102 ret = OsalThreadStart(&acm->ioThread, &threadCfg);
111 static void UsbStopIo(struct AcmDevice *acm)
134 ret = OsalThreadDestroy(&acm->ioThread);
176 static int32_t UsbGetBulkEndpoint(struct AcmDevice *acm, const struct UsbRawEndpointDescriptor *endPoint)
180 acm->dataInEp = OsalMemAlloc(sizeof(struct UsbEndpoint));
181 if (acm->dataInEp == NULL) {
185 acm->dataInEp->addr = endPoint->endpointDescriptor.bEndpointAddress;
186 acm->dataInEp->interval = endPoint->endpointDescriptor.bInterval;
187 acm->dataInEp->maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize;
190 acm->dataOutEp = OsalMemAlloc(sizeof(struct UsbEndpoint));
191 if (acm->dataOutEp == NULL) {
195 acm->dataOutEp->addr = endPoint->endpointDescriptor.bEndpointAddress;
196 acm->dataOutEp->interval = endPoint->endpointDescriptor.bInterval;
197 acm->dataOutEp->maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize;
204 struct AcmDevice *acm, const struct UsbRawInterface *interface, uint8_t interfaceIndex)
211 acm->ctrlIface = interfaceIndex;
212 acm->notifyEp = OsalMemAlloc(sizeof(struct UsbEndpoint));
213 if (acm->notifyEp == NULL) {
218 acm->notifyEp->addr = interface->altsetting->endPoint[0].endpointDescriptor.bEndpointAddress;
219 acm->notifyEp->interval = interface->altsetting->endPoint[0].endpointDescriptor.bInterval;
220 acm->notifyEp->maxPacketSize = interface->altsetting->endPoint[0].endpointDescriptor.wMaxPacketSize;
223 acm->dataIface = interfaceIndex;
226 if (UsbGetBulkEndpoint(acm, endPoint) != HDF_SUCCESS) {
237 static int32_t UsbParseConfigDescriptor(struct AcmDevice *acm, struct UsbRawConfigDescriptor *config)
239 if ((acm == NULL) || (config == NULL)) {
240 HDF_LOGE("%{public}s:%{public}d acm or config is null", __func__, __LINE__);
244 for (uint8_t i = 0; i < acm->interfaceCnt; i++) {
245 uint8_t interfaceIndex = acm->interfaceIndex[i];
248 int32_t ret = UsbRawClaimInterface(acm->devHandle, interfaceIndex);
254 UsbParseConfigDescriptorProcess(acm, interface, interfaceIndex);
260 static void UsbReleaseInterfaces(struct AcmDevice *acm)
262 if ((acm == NULL) || (acm->devHandle == NULL)) {
263 HDF_LOGE("%{public}s:%{public}d acm is null", __func__, __LINE__);
267 (void)UsbRawReleaseInterface(acm->devHandle, acm->ctrlIface);
268 (void)UsbRawReleaseInterface(acm->devHandle, acm->dataIface);
270 if (acm->notifyEp) {
271 OsalMemFree(acm->notifyEp);
272 acm->notifyEp = NULL;
274 if (acm->dataInEp) {
275 OsalMemFree(acm->dataInEp);
276 acm->dataInEp = NULL;
278 if (acm->dataOutEp) {
279 OsalMemFree(acm->dataOutEp);
280 acm->dataOutEp = NULL;
284 static int32_t UsbAllocWriteRequests(struct AcmDevice *acm)
289 struct AcmWb *snd = &acm->wb[i];
290 snd->request = UsbRawAllocRequest(acm->devHandle, 0, acm->dataOutEp->maxPacketSize);
291 snd->instance = acm;
301 static void UsbFreeWriteRequests(struct AcmDevice *acm)
307 snd = &acm->wb[i];
315 static int32_t AcmWbAlloc(const struct AcmDevice *acm)
321 wb = (struct AcmWb *)&acm->wb[i];
358 static int32_t AcmWbIsAvail(const struct AcmDevice *acm)
363 OsalMutexLock((struct OsalMutex *)&acm->writeLock);
365 n -= acm->wb[i].use;
367 OsalMutexUnlock((struct OsalMutex *)&acm->writeLock);
371 static int32_t AcmStartWb(struct AcmDevice *acm, struct AcmWb *wb)
375 if ((acm == NULL) || (wb == NULL) || (acm->dataOutEp == NULL) || (acm->devHandle == NULL) ||
380 acm->transmitting++;
382 reqData.endPoint = acm->dataOutEp->addr;
390 ret = UsbRawFillBulkRequest(wb->request, acm->devHandle, &reqData);
396 acm->writeReq = wb->request;
401 acm->transmitting--;
407 static int32_t AcmWriteBufAlloc(const struct AcmDevice *acm)
409 struct AcmWb *wb = (struct AcmWb *)&acm->wb[0];
413 wb->buf = OsalMemCalloc(acm->dataOutEp->maxPacketSize);
427 static void AcmWriteBufFree(struct AcmDevice *acm)
429 struct AcmWb *wb = &acm->wb[0];
461 static int32_t SerialSendCtrlMsg(struct AcmDevice *acm, uint8_t request, uint16_t value, void *buf, uint16_t len)
466 if (acm == NULL || buf == NULL) {
470 if (acm->ctrlReq == NULL) {
471 acm->ctrlReq = UsbRawAllocRequest(acm->devHandle, 0, USB_CTRL_REQ_SIZE);
472 if (acm->ctrlReq == NULL) {
486 ret = UsbRawSendControlRequest(acm->ctrlReq, acm->devHandle, &ctrlReq);
491 if (acm->ctrlReq->status) {
492 HDF_LOGE("%{public}s status=%{public}d ", __func__, acm->ctrlReq->status);
497 static int32_t UsbSerialDeviceAlloc(struct AcmDevice *acm)
501 if (acm == NULL) {
502 HDF_LOGE("%{public}s: acm null pointer", __func__);
520 acm->lineCoding = port->lineCoding;
521 acm->port = port;
522 port->acm = acm;
527 static void UsbSeriaDevicelFree(struct AcmDevice *acm)
529 struct SerialDevice *port = acm->port;
541 struct AcmDevice *acm = port->acm;
547 if (acm->readReq[i]->status != USB_REQUEST_COMPLETED) {
549 __func__, __LINE__, i, acm->readReq[i]->status);
568 OsalMutexLock(&acm->readLock);
573 OsalMutexUnlock(&acm->readLock);
576 OsalMutexUnlock(&acm->readLock);
590 struct AcmDevice *acm = port->acm;
598 if (memcmp(&acm->lineCoding, &port->lineCoding, sizeof(struct UsbCdcLineCoding))) {
600 memcpy_s(&acm->lineCoding, sizeof(struct UsbCdcLineCoding), &port->lineCoding, sizeof(port->lineCoding));
611 acm, USB_DDK_CDC_REQ_SET_LINE_CODING, 0, &acm->lineCoding, sizeof(struct UsbCdcLineCoding));
636 struct AcmDevice *acm = NULL;
645 acm = port->acm;
646 if (acm == NULL) {
656 ret = UsbSerialInit(acm);
673 ret = UsbRawSubmitRequest(acm->readReq[i]);
695 if (port->acm == NULL) {
696 HDF_LOGE("%{public}s:%{public}d acm is NULL invalid parma", __func__, __LINE__);
710 OsalMutexLock(&port->acm->readLock);
712 OsalMutexUnlock(&port->acm->readLock);
714 UsbSerialRelease(port->acm);
721 struct AcmDevice *acm = NULL;
731 acm = port->acm;
732 if (acm == NULL) {
733 HDF_LOGE("%{public}s: acm is null", __func__);
736 if (AcmWbIsAvail(acm)) {
737 wbn = AcmWbAlloc(acm);
746 wb = &acm->wb[wbn];
756 if (acm->dataOutEp != NULL) {
757 size = (size > acm->dataOutEp->maxPacketSize) ? acm->dataOutEp->maxPacketSize : size;
758 if (memcpy_s(wb->buf, acm->dataOutEp->maxPacketSize, tmp, size) != EOK) {
764 if (AcmStartWb(acm, wb) != HDF_SUCCESS) {
771 static int32_t AcmStartWbSync(struct AcmDevice *acm, struct AcmWb *wb)
777 requestData.endPoint = acm->dataOutEp->addr;
783 acm->writeReq = wb->request;
784 ret = UsbRawSendBulkRequest(wb->request, acm->devHandle, &requestData);
796 struct AcmDevice *acm = NULL;
806 acm = port->acm;
807 if (acm == NULL) {
812 if (AcmWbIsAvail(acm)) {
813 wbn = AcmWbAlloc(acm);
822 wb = &acm->wb[wbn];
832 if (acm->dataOutEp == NULL) {
835 size = (size > acm->dataOutEp->maxPacketSize) ? acm->dataOutEp->maxPacketSize : size;
836 if (memcpy_s(wb->buf, acm->dataOutEp->maxPacketSize, tmp, size) != EOK) {
841 if (AcmStartWbSync(acm, wb) != HDF_SUCCESS) {
853 struct AcmDevice *acm = port->acm;
858 g_syncRequest = UsbRawAllocRequest(acm->devHandle, 0, acm->dataInEp->maxPacketSize);
866 requestData.endPoint = acm->dataInEp->addr;
868 requestData.length = acm->dataInEp->maxPacketSize;
872 ret = UsbRawSendBulkRequest(g_syncRequest, acm->devHandle, &requestData);
917 struct AcmDevice *acm = NULL;
935 acm = (struct AcmDevice *)client->device->service;
936 port = acm->port;
968 struct AcmDevice *acm = NULL;
977 acm = (struct AcmDevice *)OsalMemCalloc(sizeof(*acm));
978 if (acm == NULL) {
982 if (OsalMutexInit(&acm->lock) != HDF_SUCCESS) {
989 acm->busNum = (uint8_t)info->busNum;
990 acm->devAddr = (uint8_t)info->devNum;
991 acm->interfaceCnt = info->interfaceLength;
992 err = memcpy_s((void *)(acm->interfaceIndex), USB_MAX_INTERFACES, (const void *)info->interfaceNumber,
1003 device->service = &(acm->service);
1005 acm->device = device;
1010 if (OsalMutexDestroy(&acm->lock)) {
1014 OsalMemFree(acm);
1015 acm = NULL;
1019 static void AcmProcessNotification(const struct AcmDevice *acm, const unsigned char *buf)
1021 (void)acm;
1038 const struct UsbRawRequest *req, struct AcmDevice *acm, unsigned int currentSize, unsigned int expectedSize)
1040 if (acm->nbSize < expectedSize) {
1041 if (acm->nbSize) {
1042 OsalMemFree(acm->notificationBuffer);
1043 acm->nbSize = 0;
1046 acm->notificationBuffer = (uint8_t *)OsalMemCalloc(allocSize);
1047 if (!acm->notificationBuffer) {
1050 acm->nbSize = allocSize;
1052 unsigned int copySize = MIN(currentSize, expectedSize - acm->nbIndex);
1053 int32_t ret = memcpy_s(&acm->notificationBuffer[acm->nbIndex], acm->nbSize - acm->nbIndex, req->buffer, copySize);
1057 acm->nbIndex += copySize;
1069 struct AcmDevice *acm = (struct AcmDevice *)req->userData;
1070 if (acm == NULL) {
1071 HDF_LOGE("%{public}s:%{public}d userData(acm) is NULL!", __func__, __LINE__);
1088 if (acm->nbIndex) {
1089 dr = (struct UsbCdcNotification *)acm->notificationBuffer;
1098 if (AcmNotificationBufferProcess(req, acm, currentSize, expectedSize) != HDF_SUCCESS) {
1101 currentSize = acm->nbIndex;
1104 AcmProcessNotification(acm, (unsigned char *)dr);
1105 acm->nbIndex = 0;
1123 struct AcmDevice *acm = (struct AcmDevice *)req->userData;
1124 if (acm == NULL || acm->port == NULL) {
1137 OsalMutexLock(&acm->readLock);
1138 if (DataFifoIsFull(&acm->port->readFifo)) {
1139 DataFifoSkip(&acm->port->readFifo, size);
1141 uint32_t count = DataFifoWrite(&acm->port->readFifo, data, size);
1145 OsalMutexUnlock(&acm->readLock);
1153 static int32_t UsbAllocReadRequests(struct AcmDevice *acm)
1156 uint32_t size = acm->dataInEp->maxPacketSize;
1159 acm->readReq[i] = UsbRawAllocRequest(acm->devHandle, 0, size);
1160 if (!acm->readReq[i]) {
1165 reqData.endPoint = acm->dataInEp->addr;
1168 reqData.userData = (void *)acm;
1172 int32_t ret = UsbRawFillBulkRequest(acm->readReq[i], acm->devHandle, &reqData);
1182 static void UsbFreeReadRequests(struct AcmDevice *acm)
1186 if (acm == NULL) {
1187 HDF_LOGE("%{public}s: acm is NULL", __func__);
1192 if (acm->readReq[i]) {
1193 UsbRawFreeRequest(acm->readReq[i]);
1194 acm->readReq[i] = NULL;
1199 static int32_t UsbAllocNotifyRequest(struct AcmDevice *acm)
1202 if ((acm == NULL) || (acm->notifyEp == NULL)) {
1203 HDF_LOGE("%{public}s: acm or notifyEp is NULL", __func__);
1206 uint32_t size = acm->notifyEp->maxPacketSize;
1209 acm->notifyReq = UsbRawAllocRequest(acm->devHandle, 0, size);
1210 if (!acm->notifyReq) {
1215 fillRequestData.endPoint = acm->notifyEp->addr;
1219 fillRequestData.userData = (void *)acm;
1222 ret = UsbRawFillInterruptRequest(acm->notifyReq, acm->devHandle, &fillRequestData);
1231 static void UsbFreeNotifyReqeust(struct AcmDevice *acm)
1235 if ((acm == NULL) || (acm->notifyReq == NULL)) {
1236 HDF_LOGE("%{public}s: acm or notifyReq is NULL", __func__);
1240 ret = UsbRawFreeRequest(acm->notifyReq);
1242 acm->notifyReq = NULL;
1248 static void UsbAllocRequests(struct AcmDevice *acm, int32_t ret)
1250 ret = UsbAllocWriteRequests(acm);
1256 ret = UsbAllocNotifyRequest(acm);
1261 ret = UsbAllocReadRequests(acm);
1266 ret = UsbStartIo(acm);
1272 acm->lineCoding.dwDTERate = CPU_TO_LE32(DATARATE);
1273 acm->lineCoding.bCharFormat = USB_CDC_1_STOP_BITS;
1274 acm->lineCoding.bParityType = USB_CDC_NO_PARITY;
1275 acm->lineCoding.bDataBits = DATA_BITS_LENGTH;
1277 ret = UsbRawSubmitRequest(acm->notifyReq);
1282 ret = AcmWriteBufAlloc(acm);
1289 UsbStopIo(acm);
1291 UsbFreeReadRequests(acm);
1293 UsbFreeNotifyReqeust(acm);
1295 UsbFreeWriteRequests(acm);
1297 AcmWriteBufFree(acm);
1299 UsbReleaseInterfaces(acm);
1302 static int32_t UsbSerialInit(struct AcmDevice *acm)
1307 if (acm->initFlag) {
1316 acm->session = session;
1317 devHandle = UsbRawOpenDevice(session, acm->busNum, acm->devAddr);
1323 acm->devHandle = devHandle;
1324 ret = UsbGetConfigDescriptor(devHandle, &acm->config);
1330 ret = UsbParseConfigDescriptor(acm, acm->config);
1336 UsbAllocRequests(acm, ret);
1337 acm->initFlag = true;
1341 UsbRawFreeConfigDescriptor(acm->config);
1342 acm->config = NULL;
1346 UsbRawExit(acm->session);
1350 static void UsbSerialRelease(struct AcmDevice *acm)
1352 if (!(acm->initFlag)) {
1358 UsbStopIo(acm);
1363 UsbFreeReadRequests(acm);
1364 UsbFreeNotifyReqeust(acm);
1365 UsbFreeWriteRequests(acm);
1366 AcmWriteBufFree(acm);
1367 UsbReleaseInterfaces(acm);
1368 (void)UsbRawCloseDevice(acm->devHandle);
1369 UsbRawFreeConfigDescriptor(acm->config);
1370 acm->config = NULL;
1371 UsbRawExit(acm->session);
1373 acm->initFlag = false;
1378 struct AcmDevice *acm = NULL;
1385 acm = (struct AcmDevice *)device->service;
1386 if (acm == NULL) {
1389 OsalMutexInit(&acm->readLock);
1390 OsalMutexInit(&acm->writeLock);
1392 ret = UsbSerialDeviceAlloc(acm);
1397 acm->initFlag = false;
1407 struct AcmDevice *acm = NULL;
1413 acm = (struct AcmDevice *)device->service;
1414 if (acm == NULL) {
1415 HDF_LOGE("%{public}s: acm is null", __func__);
1421 if (acm->initFlag) {
1423 UsbSerialRelease(acm);
1425 UsbSeriaDevicelFree(acm);
1426 OsalMutexDestroy(&acm->writeLock);
1427 OsalMutexDestroy(&acm->readLock);
1428 OsalMutexDestroy(&acm->lock);
1429 OsalMemFree(acm);
1430 acm = NULL;