Skip to content

Commit 9be5fde

Browse files
authored
finished misra 17.8 (#241)
1 parent 3c3aba3 commit 9be5fde

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

board/drivers/usb.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,16 @@ int current_int0_alt_setting = 0;
394394
// packet read and write
395395

396396
void *USB_ReadPacket(void *dest, uint16_t len) {
397-
uint32_t i = 0;
397+
398+
void *dest_copy = dest;
398399
uint32_t count32b = (len + 3U) / 4U;
399400

400-
for ( i = 0; i < count32b; i++) {
401+
for (uint32_t i = 0; i < count32b; i++) {
401402
// packed?
402-
*(__attribute__((__packed__)) uint32_t *)dest = USBx_DFIFO(0);
403-
dest += 4;
403+
*(__attribute__((__packed__)) uint32_t *)dest_copy = USBx_DFIFO(0);
404+
dest_copy += 4;
404405
}
405-
return ((void *)dest);
406+
return ((void *)dest_copy);
406407
}
407408

408409
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) {
412413
#endif
413414

414415
uint8_t numpacket = (len + (MAX_RESP_LEN - 1U)) / MAX_RESP_LEN;
415-
uint32_t count32b = 0, i = 0;
416+
uint32_t count32b = 0;
416417
count32b = (len + 3U) / 4U;
417418

418419
// bullshit
@@ -421,9 +422,10 @@ void USB_WritePacket(const uint8_t *src, uint16_t len, uint32_t ep) {
421422
USBx_INEP(ep)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
422423

423424
// load the FIFO
424-
for (i = 0; i < count32b; i++) {
425-
USBx_DFIFO(ep) = *((__attribute__((__packed__)) uint32_t *)src);
426-
src += 4;
425+
const uint8_t *src_copy = src;
426+
for (uint32_t i = 0; i < count32b; i++) {
427+
USBx_DFIFO(ep) = *((__attribute__((__packed__)) uint32_t *)src_copy);
428+
src_copy += 4;
427429
}
428430
}
429431

0 commit comments

Comments
 (0)