From 4483baab02f3a80d262d42cb69961f1f349b5d1e Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Thu, 8 Jun 2017 12:38:14 -0300 Subject: USBH: UVC, fix compile with IAR --- os/hal/include/usbh/dev/uvc.h | 20 ++++++++++---------- os/hal/src/usbh/hal_usbh_uvc.c | 26 ++++++++++++++++---------- 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'os') diff --git a/os/hal/include/usbh/dev/uvc.h b/os/hal/include/usbh/dev/uvc.h index ab12199..c68a082 100644 --- a/os/hal/include/usbh/dev/uvc.h +++ b/os/hal/include/usbh/dev/uvc.h @@ -182,7 +182,7 @@ typedef enum { } usbh_uvc_ctrl_vs_interface_controls_t; -typedef struct { +typedef PACKED_STRUCT { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubType; @@ -194,9 +194,9 @@ typedef struct { uint8_t bAspectRatioY; uint8_t bmInterfaceFlags; uint8_t bCopyProtect; -} __attribute__((__packed__)) usbh_uvc_format_mjpeg_t; +} usbh_uvc_format_mjpeg_t; -typedef struct { +typedef PACKED_STRUCT { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubType; @@ -210,10 +210,10 @@ typedef struct { uint32_t dwDefaultFrameInterval; uint8_t bFrameIntervalType; uint32_t dwFrameInterval[0]; -} __attribute__((__packed__)) usbh_uvc_frame_mjpeg_t; +} usbh_uvc_frame_mjpeg_t; -typedef struct { +typedef PACKED_STRUCT { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubType; @@ -227,9 +227,9 @@ typedef struct { uint32_t dwDefaultFrameInterval; uint8_t bFrameIntervalType; uint32_t dwFrameInterval[0]; -} __attribute__((__packed__)) usbh_uvc_frame_uncompressed_t; +} usbh_uvc_frame_uncompressed_t; -typedef struct { +typedef PACKED_STRUCT { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubType; @@ -242,9 +242,9 @@ typedef struct { uint8_t bAspectRatioY; uint8_t bmInterfaceFlags; uint8_t bCopyProtect; -} __attribute__((__packed__)) usbh_uvc_format_uncompressed; +} usbh_uvc_format_uncompressed; -typedef struct { +typedef PACKED_STRUCT { uint16_t bmHint; uint8_t bFormatIndex; uint8_t bFrameIndex; @@ -261,7 +261,7 @@ typedef struct { // uint8_t bPreferedVersion; // uint8_t bMinVersion; // uint8_t bMaxVersion; -} __attribute__((__packed__)) usbh_uvc_ctrl_vs_probecommit_data_t; +} usbh_uvc_ctrl_vs_probecommit_data_t; diff --git a/os/hal/src/usbh/hal_usbh_uvc.c b/os/hal/src/usbh/hal_usbh_uvc.c index 9cbbb03..b0507a0 100644 --- a/os/hal/src/usbh/hal_usbh_uvc.c +++ b/os/hal/src/usbh/hal_usbh_uvc.c @@ -198,7 +198,7 @@ void usbhuvcPrintProbeCommit(const usbh_uvc_ctrl_vs_probecommit_data_t *pc) { #endif static void _post(USBHUVCDriver *uvcdp, usbh_urb_t *urb, memory_pool_t *mp, uint16_t type) { - usbhuvc_message_base_t *const msg = (usbhuvc_message_base_t *)urb->buff - 1; + usbhuvc_message_base_t *const msg = (usbhuvc_message_base_t *)((uint8_t *)urb->buff - offsetof(usbhuvc_message_data_t, data)); msg->timestamp = osalOsGetSystemTimeX(); usbhuvc_message_base_t *const new_msg = (usbhuvc_message_base_t *)chPoolAllocI(mp); @@ -210,7 +210,7 @@ static void _post(USBHUVCDriver *uvcdp, usbh_urb_t *urb, memory_pool_t *mp, uint msg->length = urb->actualLength; /* change the URB's buffer to the newly allocated one */ - urb->buff = (uint8_t *)(new_msg + 1); + urb->buff = ((usbhuvc_message_data_t *)new_msg)->data; } else { /* couldn't post the message, free the newly allocated buffer */ uerr("UVC: error, mailbox overrun"); @@ -298,6 +298,7 @@ static void _cb_iso(usbh_urb_t *urb) { bool usbhuvcStreamStart(USBHUVCDriver *uvcdp, uint16_t min_ep_sz) { bool ret = HAL_FAILED; + osalSysLock(); osalDbgCheck(uvcdp && (uvcdp->state != USBHUVC_STATE_UNINITIALIZED) && (uvcdp->state != USBHUVC_STATE_BUSY)); @@ -312,21 +313,24 @@ bool usbhuvcStreamStart(USBHUVCDriver *uvcdp, uint16_t min_ep_sz) { uvcdp->state = USBHUVC_STATE_BUSY; osalSysUnlock(); + uint32_t workramsz; + const uint8_t *elem; + uint32_t datapackets; + uint32_t data_sz; + //set the alternate setting if (_set_vs_alternate(uvcdp, min_ep_sz) != HAL_SUCCESS) goto exit; //reserve working RAM - uint32_t datapackets; - uint32_t data_sz = (uvcdp->ep_iso.wMaxPacketSize + sizeof(usbhuvc_message_data_t) + 3) & ~3; - + data_sz = (uvcdp->ep_iso.wMaxPacketSize + sizeof(usbhuvc_message_data_t) + 3) & ~3; datapackets = HAL_USBHUVC_WORK_RAM_SIZE / data_sz; if (datapackets == 0) { uerr("Not enough work RAM"); goto failed; } - uint32_t workramsz = datapackets * data_sz; + workramsz = datapackets * data_sz; uinfof("Reserving %u bytes of RAM (%d data packets of %d bytes)", workramsz, datapackets, data_sz); if (datapackets > (HAL_USBHUVC_MAX_MAILBOX_SZ - HAL_USBHUVC_STATUS_PACKETS_COUNT)) { uwarn("Mailbox may overflow, use a larger HAL_USBHUVC_MAX_MAILBOX_SZ. UVC will under-utilize the assigned work RAM."); @@ -340,8 +344,8 @@ bool usbhuvcStreamStart(USBHUVCDriver *uvcdp, uint16_t min_ep_sz) { } //initialize the mempool - const uint8_t *elem = (const uint8_t *)uvcdp->mp_data_buffer; chPoolObjectInit(&uvcdp->mp_data, data_sz, NULL); + elem = (const uint8_t *)uvcdp->mp_data_buffer; while (datapackets--) { chPoolFree(&uvcdp->mp_data, (void *)elem); elem += data_sz; @@ -351,9 +355,11 @@ bool usbhuvcStreamStart(USBHUVCDriver *uvcdp, uint16_t min_ep_sz) { usbhEPOpen(&uvcdp->ep_iso); //allocate 1 buffer and submit the first transfer - usbhuvc_message_data_t *const msg = (usbhuvc_message_data_t *)chPoolAlloc(&uvcdp->mp_data); - osalDbgCheck(msg); - usbhURBObjectInit(&uvcdp->urb_iso, &uvcdp->ep_iso, _cb_iso, uvcdp, msg->data, uvcdp->ep_iso.wMaxPacketSize); + { + usbhuvc_message_data_t *const msg = (usbhuvc_message_data_t *)chPoolAlloc(&uvcdp->mp_data); + osalDbgCheck(msg); + usbhURBObjectInit(&uvcdp->urb_iso, &uvcdp->ep_iso, _cb_iso, uvcdp, msg->data, uvcdp->ep_iso.wMaxPacketSize); + } osalSysLock(); usbhURBSubmitI(&uvcdp->urb_iso); osalOsRescheduleS(); -- cgit v1.2.3