Merge pull request #2647 from andrewleech/additional_dcd_sof_enable

Add support for dcd_sof_enable() to some additional ports.
This commit is contained in:
HiFiPhile 2024-05-27 20:42:28 +02:00 committed by GitHub
commit 1fe86f654f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 58 additions and 39 deletions

View File

@ -396,9 +396,8 @@ bool tud_connect(void) {
return true;
}
bool tud_sof_cb_enable(bool en) {
void tud_sof_cb_enable(bool en) {
usbd_sof_enable(_usbd_rhport, SOF_CONSUMER_USER, en);
return true;
}
//--------------------------------------------------------------------+
@ -1194,7 +1193,7 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const* event, bool in_isr)
}
if (tu_bit_test(_usbd_dev.sof_consumer, SOF_CONSUMER_USER)) {
dcd_event_t const event_sof = {.rhport = event->rhport, .event_id = DCD_EVENT_SOF};
dcd_event_t const event_sof = {.rhport = event->rhport, .event_id = DCD_EVENT_SOF, .sof.frame_count = event->sof.frame_count};
queue_event(&event_sof, in_isr);
}
break;

View File

@ -98,7 +98,7 @@ bool tud_disconnect(void);
bool tud_connect(void);
// Enable or disable the Start Of Frame callback support
bool tud_sof_cb_enable(bool en);
void tud_sof_cb_enable(bool en);
// Carry out Data and Status stage of control transfer
// - If len = 0, it is equivalent to sending status only

View File

@ -309,10 +309,12 @@ void dcd_disconnect(uint8_t rhport)
void dcd_sof_enable(uint8_t rhport, bool en)
{
(void) rhport;
(void) en;
// TODO implement later
ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);
if (en) {
dcd_reg->USBINTR |= INTR_SOF;
} else {
dcd_reg->USBINTR &= ~INTR_SOF;
}
}
//--------------------------------------------------------------------+
@ -679,7 +681,8 @@ void dcd_int_handler(uint8_t rhport)
if (int_status & INTR_SOF)
{
dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
const uint32_t frame = dcd_reg->FRINDEX;
dcd_event_sof(rhport, frame, true);
}
}

View File

@ -183,9 +183,12 @@ void dcd_connect(uint8_t rhport)
void dcd_sof_enable(uint8_t rhport, bool en)
{
(void) rhport;
(void) en;
// TODO implement later
if (en) {
USB->DEVICE.INTENSET.bit.SOF = 1;
} else {
USB->DEVICE.INTENCLR.bit.SOF = 1;
}
}
/*------------------------------------------------------------------*/
@ -374,7 +377,9 @@ void dcd_int_handler (uint8_t rhport)
if ( int_status & USB_DEVICE_INTFLAG_SOF )
{
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
const uint32_t frame = USB->DEVICE.FNUM.bit.FNUM;
dcd_event_sof(0, frame, true);
//dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
}
// SAMD doesn't distinguish between Suspend and Disconnect state.

View File

@ -120,6 +120,9 @@ static struct {
// nRF can only carry one DMA at a time, this is used to guard the access to EasyDMA
atomic_flag dma_running;
// Track whether sof has been manually enabled
bool sof_enabled;
} _dcd;
/*------------------------------------------------------------------*/
@ -283,9 +286,13 @@ void dcd_connect(uint8_t rhport) {
void dcd_sof_enable(uint8_t rhport, bool en) {
(void) rhport;
(void) en;
// TODO implement later
if (en) {
_dcd.sof_enabled = true;
NRF_USBD->INTENSET = USBD_INTENSET_SOF_Msk;
} else {
_dcd.sof_enabled = false;
NRF_USBD->INTENCLR = USBD_INTENCLR_SOF_Msk;
}
}
//--------------------------------------------------------------------+
@ -607,13 +614,16 @@ void dcd_int_handler(uint8_t rhport) {
}
}
if (!iso_enabled) {
// ISO endpoint is not used, SOF is only enabled one-time for remote wakeup
// so we disable it now
NRF_USBD->INTENCLR = USBD_INTENSET_SOF_Msk;
if (!iso_enabled && !_dcd.sof_enabled) {
// SOF interrupt not manually enabled and ISO endpoint is not used,
// SOF is only enabled one-time for remote wakeup so we disable it now
NRF_USBD->INTENCLR = USBD_INTENCLR_SOF_Msk;
}
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
const uint32_t frame = NRF_USBD->FRAMECNTR;
dcd_event_sof(0, frame, true);
//dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
}
if (int_status & USBD_INTEN_USBEVENT_Msk) {

View File

@ -29,10 +29,6 @@
#if CFG_TUD_ENABLED && defined(TUP_USBIP_RUSB2)
// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
// We disable SOF for now until needed later on
#define USE_SOF 0
#include "device/dcd.h"
#include "rusb2_type.h"
@ -74,6 +70,8 @@ typedef struct
{
pipe_state_t pipe[PIPE_COUNT];
uint8_t ep[2][16]; /* a lookup table for a pipe index from an endpoint address */
// Track whether sof has been manually enabled
bool sof_enabled;
} dcd_data_t;
static dcd_data_t _dcd;
@ -664,6 +662,10 @@ void dcd_init(uint8_t rhport)
rusb2_reg_t* rusb = RUSB2_REG(rhport);
rusb2_module_start(rhport, true);
// We disable SOF for now until needed later on.
// Since TinyUSB doesn't use SOF for now, and this interrupt often (1ms interval)
_dcd.sof_enabled = false;
#ifdef RUSB2_SUPPORT_HIGHSPEED
if ( rusb2_is_highspeed_rhport(rhport) ) {
rusb->SYSCFG_b.HSE = 1;
@ -708,7 +710,7 @@ void dcd_init(uint8_t rhport)
rusb->INTSTS0 = 0;
rusb->INTENB0 = RUSB2_INTSTS0_VBINT_Msk | RUSB2_INTSTS0_BRDY_Msk | RUSB2_INTSTS0_BEMP_Msk |
RUSB2_INTSTS0_DVST_Msk | RUSB2_INTSTS0_CTRT_Msk | (USE_SOF ? RUSB2_INTSTS0_SOFR_Msk : 0) |
RUSB2_INTSTS0_DVST_Msk | RUSB2_INTSTS0_CTRT_Msk | (_dcd.sof_enabled ? RUSB2_INTSTS0_SOFR_Msk : 0) |
RUSB2_INTSTS0_RESM_Msk;
rusb->BEMPENB = 1;
rusb->BRDYENB = 1;
@ -756,10 +758,9 @@ void dcd_disconnect(uint8_t rhport)
void dcd_sof_enable(uint8_t rhport, bool en)
{
(void) rhport;
(void) en;
// TODO implement later
rusb2_reg_t* rusb = RUSB2_REG(rhport);
_dcd.sof_enabled = en;
rusb->INTENB0_b.SOFE = en ? 1: 0;
}
//--------------------------------------------------------------------+
@ -949,18 +950,19 @@ void dcd_int_handler(uint8_t rhport)
// Resumed
if ( is0 & RUSB2_INTSTS0_RESM_Msk ) {
dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
#if (0 == USE_SOF)
rusb->INTENB0_b.SOFE = 0;
#endif
if (!_dcd.sof_enabled) {
rusb->INTENB0_b.SOFE = 0;
}
}
// SOF received
if ( (is0 & RUSB2_INTSTS0_SOFR_Msk) && rusb->INTENB0_b.SOFE ) {
// USBD will exit suspended mode when SOF event is received
dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
#if (0 == USE_SOF)
rusb->INTENB0_b.SOFE = 0;
#endif
const uint32_t frame = rusb->FRMNUM_b.FRNM;
dcd_event_sof(rhport, frame, true);
if (!_dcd.sof_enabled) {
rusb->INTENB0_b.SOFE = 0;
}
}
// Device state changes
@ -979,9 +981,9 @@ void dcd_int_handler(uint8_t rhport)
case RUSB2_INTSTS0_DVSQ_STATE_SUSP2:
case RUSB2_INTSTS0_DVSQ_STATE_SUSP3:
dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
#if (0 == USE_SOF)
rusb->INTENB0_b.SOFE = 1;
#endif
if (!_dcd.sof_enabled) {
rusb->INTENB0_b.SOFE = 1;
}
default: break;
}