usb_canbus: Minor code reformatting of drain_hw_queue()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2023-04-14 14:48:40 -04:00
parent f10c60eea7
commit 3377f29bc5
1 changed files with 10 additions and 10 deletions

View File

@ -169,18 +169,18 @@ send_frame(struct canbus_msg *msg)
static int static int
drain_hw_queue(void) drain_hw_queue(void)
{ {
uint32_t pull_pos = UsbCan.pull_pos;
for (;;) { for (;;) {
uint32_t push_pos = readl(&UsbCan.push_pos); uint32_t push_pos = readl(&UsbCan.push_pos);
uint32_t pull_pos = UsbCan.pull_pos; if (push_pos == pull_pos)
if (push_pos != pull_pos) { // No more data to send
uint32_t pos = pull_pos % ARRAY_SIZE(UsbCan.queue); return 0;
int ret = send_frame(&UsbCan.queue[pos]); uint32_t pos = pull_pos % ARRAY_SIZE(UsbCan.queue);
if (ret < 0) int ret = send_frame(&UsbCan.queue[pos]);
return -1; if (ret < 0)
UsbCan.pull_pos = pull_pos + 1; // USB is busy - retry later
continue; return -1;
} UsbCan.pull_pos = pull_pos = pull_pos + 1;
return 0;
} }
} }