aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUladzimir Pylinski <barthess@yandex.ru>2017-06-09 08:10:34 +0300
committerGitHub <noreply@github.com>2017-06-09 08:10:34 +0300
commitca686a5cbab4a2c6de321e7f1a9c06c28fd56f9a (patch)
tree0f90e9cc2f1cceee038eaabd3a21892e7d8b0ea8
parent830f09e2b7d9af3146b1ecd8821664d874355005 (diff)
parent4483baab02f3a80d262d42cb69961f1f349b5d1e (diff)
downloadChibiOS-Contrib-ca686a5cbab4a2c6de321e7f1a9c06c28fd56f9a.tar.gz
ChibiOS-Contrib-ca686a5cbab4a2c6de321e7f1a9c06c28fd56f9a.tar.bz2
ChibiOS-Contrib-ca686a5cbab4a2c6de321e7f1a9c06c28fd56f9a.zip
Merge pull request #118 from dismirlian/usbh_devel
USBH: fix compile with IAR
-rw-r--r--os/hal/include/usbh/dev/uvc.h20
-rw-r--r--os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c2
-rw-r--r--os/hal/src/usbh/hal_usbh_msd.c4
-rw-r--r--os/hal/src/usbh/hal_usbh_uvc.c26
4 files changed, 29 insertions, 23 deletions
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/ports/STM32/LLD/USBHv1/hal_usbh_lld.c b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c
index 7981695..5954cb2 100644
--- a/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c
+++ b/os/hal/ports/STM32/LLD/USBHv1/hal_usbh_lld.c
@@ -387,7 +387,7 @@ static bool _update_urb(usbh_ep_t *ep, uint32_t hctsiz, usbh_urb_t *urb, bool co
osalDbgCheck(len == ep->xfer.partial); //TODO: if len == ep->xfer.partial, use this instead of the above code
}
-#if 1
+#if 0
osalDbgAssert(urb->actualLength + len <= urb->requestedLength, "what happened?");
#else
if (urb->actualLength + len > urb->requestedLength) {
diff --git a/os/hal/src/usbh/hal_usbh_msd.c b/os/hal/src/usbh/hal_usbh_msd.c
index 121e730..b564e8e 100644
--- a/os/hal/src/usbh/hal_usbh_msd.c
+++ b/os/hal/src/usbh/hal_usbh_msd.c
@@ -347,7 +347,7 @@ static msd_bot_result_t _msd_bot_transaction(msd_transaction_t *tran, USBHMassSt
if (status == USBH_URBSTATUS_STALL) {
uerrf("\tMSD: Data phase: USBH_URBSTATUS_STALL, clear halt");
- status = usbhEPReset(ep);
+ status = (usbhEPReset(ep) == HAL_SUCCESS) ? USBH_URBSTATUS_OK : USBH_URBSTATUS_ERROR;
}
if (status != USBH_URBSTATUS_OK) {
@@ -365,7 +365,7 @@ static msd_bot_result_t _msd_bot_transaction(msd_transaction_t *tran, USBHMassSt
if (status == USBH_URBSTATUS_STALL) {
uwarn("\tMSD: Status phase: USBH_URBSTATUS_STALL, clear halt and retry");
- status = usbhEPReset(&lunp->msdp->epin);
+ status = (usbhEPReset(&lunp->msdp->epin) == HAL_SUCCESS) ? USBH_URBSTATUS_OK : USBH_URBSTATUS_ERROR;
if (status == USBH_URBSTATUS_OK) {
status = usbhBulkTransfer(&lunp->msdp->epin, &csw,
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();