Skip to content

Commit c57a780

Browse files
author
Josuah Demangeon
committed
move most channel event handlers out of ISR
Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 881451e commit c57a780

File tree

1 file changed

+24
-35
lines changed

1 file changed

+24
-35
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,8 @@ static enum uhc_dwc2_chan_event uhc_dwc2_hal_chan_decode_intr(const struct devic
822822
enum uhc_dwc2_chan_event chan_event;
823823
uint32_t hcint;
824824

825-
hcint = sys_read32((mem_addr_t)&chan_regs->hcint);
826825
/* Clear the interrupt bits by writing them back */
826+
hcint = sys_read32((mem_addr_t)&chan_regs->hcint);
827827
sys_write32(hcint, (mem_addr_t)&chan_regs->hcint);
828828

829829
/* Note:
@@ -938,37 +938,11 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
938938

939939
LOG_DBG("Channel event: 0x%08x", chan_event);
940940

941-
switch (chan_event) {
942-
case DWC2_CHAN_EVENT_NONE:
943-
/* No event, nothing to do */
944-
break;
945-
case DWC2_CHAN_EVENT_CPLT:
946-
if (!uhc_dwc2_buffer_is_done(chan)) {
947-
uhc_dwc2_buffer_exec_proceed(dev, chan);
948-
break;
949-
}
941+
if (chan_event == DWC2_CHAN_EVENT_CPLT && !uhc_dwc2_buffer_is_done(chan)) {
942+
uhc_dwc2_buffer_exec_proceed(dev, chan);
943+
} else {
950944
chan->event = chan_event;
951-
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CHAN0 + chan->chan_idx));
952-
break;
953-
case DWC2_CHAN_EVENT_ERROR:
954-
LOG_ERR("Channel error handling not implemented yet");
955-
/* TODO: get channel error, halt the chan */
956-
break;
957-
case DWC2_CHAN_EVENT_HALT_REQ:
958-
LOG_ERR("Channel halt request handling not implemented yet");
959-
960-
/* TODO: Implement halting the ongoing transfer */
961-
962-
/* Hint:
963-
* We've halted a transfer, so we need to trigger the chan callback
964-
* Halt request event is triggered when packet is successful completed.
965-
* But just treat all halted transfers as errors
966-
* Notify the task waiting for the chan halt or halt it right away
967-
* _internal_chan_event_notify(chan, true);
968-
*/
969-
break;
970-
default:
971-
break;
945+
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CHAN0 + i - 1));
972946
}
973947
}
974948
}
@@ -1324,7 +1298,7 @@ static inline void uhc_dwc2_handle_chan_events(const struct device *dev, struct
13241298
struct usb_dwc2_reg *const dwc2 = config->base;
13251299
const struct usb_dwc2_host_chan *chan_regs = UHC_DWC2_CHAN_REG(dwc2, chan->chan_idx);
13261300

1327-
LOG_DBG("Pipe event: %d", chan->event);
1301+
LOG_DBG("Channel event: 0x%08x", chan->event);
13281302

13291303
if (chan->event == DWC2_CHAN_EVENT_CPLT) {
13301304
/* XFER transfer is done, process the transfer and release the chan buffer */
@@ -1346,10 +1320,25 @@ static inline void uhc_dwc2_handle_chan_events(const struct device *dev, struct
13461320
}
13471321

13481322
uhc_xfer_return(dev, xfer, 0);
1323+
}
13491324

1350-
} else {
1351-
/* TODO: Handle the rest chan events */
1352-
LOG_ERR("Unhandled chan event %d", chan->event);
1325+
if (chan->event == DWC2_CHAN_EVENT_ERROR) {
1326+
LOG_ERR("Channel error handling not implemented yet");
1327+
/* TODO: get channel error, halt the chan */
1328+
}
1329+
1330+
if (chan->event == DWC2_CHAN_EVENT_HALT_REQ) {
1331+
LOG_ERR("Channel halt request handling not implemented yet");
1332+
1333+
/* TODO: Implement halting the ongoing transfer */
1334+
1335+
/* Hint:
1336+
* We've halted a transfer, so we need to trigger the chan callback
1337+
* Halt request event is triggered when packet is successful completed.
1338+
* But just treat all halted transfers as errors
1339+
* Notify the task waiting for the chan halt or halt it right away
1340+
* _internal_chan_event_notify(chan, true);
1341+
*/
13531342
}
13541343
}
13551344

0 commit comments

Comments
 (0)