From 9be5fdead90dd731df2c7a6b1f3cd268c9e232d8 Mon Sep 17 00:00:00 2001 From: rbiasini Date: Thu, 4 Jul 2019 01:37:26 -0700 Subject: [PATCH] finished misra 17.8 (#241) --- board/drivers/usb.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/board/drivers/usb.h b/board/drivers/usb.h index 5102ca46728fe7..84cc81ffb4eaa0 100644 --- a/board/drivers/usb.h +++ b/board/drivers/usb.h @@ -394,15 +394,16 @@ int current_int0_alt_setting = 0; // packet read and write void *USB_ReadPacket(void *dest, uint16_t len) { - uint32_t i = 0; + + void *dest_copy = dest; uint32_t count32b = (len + 3U) / 4U; - for ( i = 0; i < count32b; i++) { + for (uint32_t i = 0; i < count32b; i++) { // packed? - *(__attribute__((__packed__)) uint32_t *)dest = USBx_DFIFO(0); - dest += 4; + *(__attribute__((__packed__)) uint32_t *)dest_copy = USBx_DFIFO(0); + dest_copy += 4; } - return ((void *)dest); + return ((void *)dest_copy); } void USB_WritePacket(const uint8_t *src, uint16_t len, uint32_t ep) { @@ -412,7 +413,7 @@ void USB_WritePacket(const uint8_t *src, uint16_t len, uint32_t ep) { #endif uint8_t numpacket = (len + (MAX_RESP_LEN - 1U)) / MAX_RESP_LEN; - uint32_t count32b = 0, i = 0; + uint32_t count32b = 0; count32b = (len + 3U) / 4U; // bullshit @@ -421,9 +422,10 @@ void USB_WritePacket(const uint8_t *src, uint16_t len, uint32_t ep) { USBx_INEP(ep)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA); // load the FIFO - for (i = 0; i < count32b; i++) { - USBx_DFIFO(ep) = *((__attribute__((__packed__)) uint32_t *)src); - src += 4; + const uint8_t *src_copy = src; + for (uint32_t i = 0; i < count32b; i++) { + USBx_DFIFO(ep) = *((__attribute__((__packed__)) uint32_t *)src_copy); + src_copy += 4; } }