Skip to content

Commit

Permalink
revert sof_isr driver rename since it cause issue with existing code
Browse files Browse the repository at this point in the history
also removed commented tud_sof_isr_set() API
  • Loading branch information
hathach committed Jun 9, 2022
1 parent 806806d commit 8451d05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
40 changes: 14 additions & 26 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = cdcd_open,
.control_xfer_cb = cdcd_control_xfer_cb,
.xfer_cb = cdcd_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -110,7 +110,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = mscd_open,
.control_xfer_cb = mscd_control_xfer_cb,
.xfer_cb = mscd_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -122,7 +122,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = hidd_open,
.control_xfer_cb = hidd_control_xfer_cb,
.xfer_cb = hidd_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -134,7 +134,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = audiod_open,
.control_xfer_cb = audiod_control_xfer_cb,
.xfer_cb = audiod_xfer_cb,
.sof_isr = audiod_sof_isr
.sof = audiod_sof_isr
},
#endif

Expand All @@ -146,7 +146,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = videod_open,
.control_xfer_cb = videod_control_xfer_cb,
.xfer_cb = videod_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -158,7 +158,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.reset = midid_reset,
.control_xfer_cb = midid_control_xfer_cb,
.xfer_cb = midid_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -170,7 +170,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = vendord_open,
.control_xfer_cb = tud_vendor_control_xfer_cb,
.xfer_cb = vendord_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -182,7 +182,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = usbtmcd_open_cb,
.control_xfer_cb = usbtmcd_control_xfer_cb,
.xfer_cb = usbtmcd_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -194,7 +194,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = dfu_rtd_open,
.control_xfer_cb = dfu_rtd_control_xfer_cb,
.xfer_cb = NULL,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -206,7 +206,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = dfu_moded_open,
.control_xfer_cb = dfu_moded_control_xfer_cb,
.xfer_cb = NULL,
.sof_isr = NULL
.sof = NULL
},
#endif

Expand All @@ -218,7 +218,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = netd_open,
.control_xfer_cb = netd_control_xfer_cb,
.xfer_cb = netd_xfer_cb,
.sof_isr = NULL,
.sof = NULL,
},
#endif

Expand All @@ -230,7 +230,7 @@ static usbd_class_driver_t const _usbd_driver[] =
.open = btd_open,
.control_xfer_cb = btd_control_xfer_cb,
.xfer_cb = btd_xfer_cb,
.sof_isr = NULL
.sof = NULL
},
#endif
};
Expand Down Expand Up @@ -264,8 +264,6 @@ static inline usbd_class_driver_t const * get_driver(uint8_t drvid)
// DCD Event
//--------------------------------------------------------------------+

//static tud_sof_isr_t _sof_isr = NULL;

enum { RHPORT_INVALID = 0xFFu };
static uint8_t _usbd_rhport = RHPORT_INVALID;

Expand Down Expand Up @@ -373,12 +371,6 @@ bool tud_connect(void)
return true;
}

//void tud_sof_isr_set(tud_sof_isr_t sof_isr)
//{
// _sof_isr = sof_isr;
// dcd_sof_enable(_usbd_rhport, _sof_isr != NULL);
//}

//--------------------------------------------------------------------+
// USBD Task
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -422,7 +414,6 @@ bool tud_init (uint8_t rhport)
}

_usbd_rhport = rhport;
//_sof_isr = NULL;

// Init device controller driver
dcd_init(rhport);
Expand Down Expand Up @@ -1110,15 +1101,12 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const * event, bool in_isr)
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
{
usbd_class_driver_t const * driver = get_driver(i);
if (driver->sof_isr)
if (driver->sof)
{
driver->sof_isr(event->rhport, event->sof.frame_count);
driver->sof(event->rhport, event->sof.frame_count);
}
}

// SOF user handler in ISR context
// if (_sof_isr) _sof_isr(event->sof.frame_count);

// Some MCUs after running dcd_remote_wakeup() does not have way to detect the end of remote wakeup
// which last 1-15 ms. DCD can use SOF as a clear indicator that bus is back to operational
if ( _usbd_dev.suspended )
Expand Down
6 changes: 0 additions & 6 deletions src/device/usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
extern "C" {
#endif

// typedef void (*tud_sof_isr_t) (uint32_t frame_count);

//--------------------------------------------------------------------+
// Application API
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -95,10 +93,6 @@ bool tud_disconnect(void);
// Return false on unsupported MCUs
bool tud_connect(void);

// Set Start-of-frame (1ms interval) IRQ handler
// NULL means disabled, frame_count may not be supported on mcus
// void tud_sof_isr_set(tud_sof_isr_t sof_isr);

// Carry out Data and Status stage of control transfer
// - If len = 0, it is equivalent to sending status only
// - If len > wLength : it will be truncated
Expand Down
2 changes: 1 addition & 1 deletion src/device/usbd_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct
uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len);
bool (* control_xfer_cb ) (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
void (* sof_isr ) (uint8_t rhport, uint32_t frame_count); // optional
void (* sof ) (uint8_t rhport, uint32_t frame_count); // optional
} usbd_class_driver_t;

// Invoked when initializing device stack to get additional class drivers.
Expand Down

1 comment on commit 8451d05

@Rocky04
Copy link
Contributor

@Rocky04 Rocky04 commented on 8451d05 Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hathach
Why was it renamed, what was the issue with the existing code?
Because that function pointer is executed within the ISR and not like the functions with the callback suffix in the main loop I would think it helps to understand the code better if the ISR suffix is used. Especially when a SOF callback and ISR function is used.

Please sign in to comment.