Skip to content

Commit 881451e

Browse files
author
Josuah Demangeon
committed
move channel ISR handler in the main ISR
An intermediate step before simplifying/combining it with the main ISR. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent b2e5c72 commit 881451e

File tree

1 file changed

+38
-47
lines changed

1 file changed

+38
-47
lines changed

drivers/usb/uhc/uhc_dwc2.c

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ struct uhc_dwc2_data {
157157
struct k_event event;
158158
struct uhc_dwc2_chan chan[UHC_DWC2_MAX_CHAN];
159159
/* Data, that is used in multiple threads */
160-
enum uhc_dwc2_event event;
161160
enum uhc_port_state port_state;
162161
/* FIFO */
163162
uint16_t fifo_top;
@@ -877,51 +876,6 @@ static inline enum uhc_dwc2_ctrl_stage cal_next_pid(enum uhc_dwc2_ctrl_stage pid
877876
}
878877
}
879878

880-
/*
881-
* Decode a channel interrupt and take appropriate action.
882-
* Interrupt context.
883-
*/
884-
static void uhc_dwc2_handle_chan_intr(const struct device *dev, struct uhc_dwc2_chan *chan)
885-
{
886-
struct uhc_dwc2_data *priv = uhc_get_private(dev);
887-
enum uhc_dwc2_chan_event chan_event = uhc_dwc2_hal_chan_decode_intr(dev, chan);
888-
889-
LOG_DBG("Channel event: %d", chan_event);
890-
891-
switch (chan_event) {
892-
case DWC2_CHAN_EVENT_NONE:
893-
/* No event, nothing to do */
894-
break;
895-
case DWC2_CHAN_EVENT_CPLT:
896-
if (!uhc_dwc2_buffer_is_done(chan)) {
897-
uhc_dwc2_buffer_exec_proceed(dev, chan);
898-
break;
899-
}
900-
chan->event = chan_event;
901-
k_event_set(&priv->event, BIT(UHC_DWC2_EVENT_CHAN0 + chan->chan_idx));
902-
break;
903-
case DWC2_CHAN_EVENT_ERROR:
904-
LOG_ERR("Channel error handling not implemented yet");
905-
/* TODO: get channel error, halt the chan */
906-
break;
907-
case DWC2_CHAN_EVENT_HALT_REQ:
908-
LOG_ERR("Channel halt request handling not implemented yet");
909-
910-
/* TODO: Implement halting the ongoing transfer */
911-
912-
/* Hint:
913-
* We've halted a transfer, so we need to trigger the chan callback
914-
* Halt request event is triggered when packet is successful completed.
915-
* But just treat all halted transfers as errors
916-
* Notify the task waiting for the chan halt or halt it right away
917-
* _internal_chan_event_notify(chan, true);
918-
*/
919-
break;
920-
default:
921-
CODE_UNREACHABLE;
922-
}
923-
}
924-
925879
static void uhc_dwc2_isr_handler(const struct device *dev)
926880
{
927881
struct uhc_dwc2_data *priv = uhc_get_private(dev);
@@ -978,7 +932,44 @@ static void uhc_dwc2_isr_handler(const struct device *dev)
978932
/* One or more channels have pending interrupts. Store the mask of those channels */
979933
channels = sys_read32((mem_addr_t)&dwc2->haint);
980934
for (uint8_t i; (i = __builtin_ffs(channels)) != 0; channels &= !BIT(i - 1)) {
981-
uhc_dwc2_handle_chan_intr(dev, &priv->chan[i - 1]);
935+
struct uhc_dwc2_chan *chan = &priv->chan[i - 1];
936+
enum uhc_dwc2_chan_event chan_event =
937+
uhc_dwc2_hal_chan_decode_intr(dev, chan);
938+
939+
LOG_DBG("Channel event: 0x%08x", chan_event);
940+
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+
}
950+
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;
972+
}
982973
}
983974
}
984975

0 commit comments

Comments
 (0)