Skip to content

Commit 1fe86f6

Browse files
authored
Merge pull request #2647 from andrewleech/additional_dcd_sof_enable
Add support for dcd_sof_enable() to some additional ports.
2 parents fd11bf1 + 003a5d4 commit 1fe86f6

File tree

6 files changed

+58
-39
lines changed

6 files changed

+58
-39
lines changed

src/device/usbd.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,8 @@ bool tud_connect(void) {
396396
return true;
397397
}
398398

399-
bool tud_sof_cb_enable(bool en) {
399+
void tud_sof_cb_enable(bool en) {
400400
usbd_sof_enable(_usbd_rhport, SOF_CONSUMER_USER, en);
401-
return true;
402401
}
403402

404403
//--------------------------------------------------------------------+
@@ -1194,7 +1193,7 @@ TU_ATTR_FAST_FUNC void dcd_event_handler(dcd_event_t const* event, bool in_isr)
11941193
}
11951194

11961195
if (tu_bit_test(_usbd_dev.sof_consumer, SOF_CONSUMER_USER)) {
1197-
dcd_event_t const event_sof = {.rhport = event->rhport, .event_id = DCD_EVENT_SOF};
1196+
dcd_event_t const event_sof = {.rhport = event->rhport, .event_id = DCD_EVENT_SOF, .sof.frame_count = event->sof.frame_count};
11981197
queue_event(&event_sof, in_isr);
11991198
}
12001199
break;

src/device/usbd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool tud_disconnect(void);
9898
bool tud_connect(void);
9999

100100
// Enable or disable the Start Of Frame callback support
101-
bool tud_sof_cb_enable(bool en);
101+
void tud_sof_cb_enable(bool en);
102102

103103
// Carry out Data and Status stage of control transfer
104104
// - If len = 0, it is equivalent to sending status only

src/portable/chipidea/ci_hs/dcd_ci_hs.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,12 @@ void dcd_disconnect(uint8_t rhport)
309309

310310
void dcd_sof_enable(uint8_t rhport, bool en)
311311
{
312-
(void) rhport;
313-
(void) en;
314-
315-
// TODO implement later
312+
ci_hs_regs_t* dcd_reg = CI_HS_REG(rhport);
313+
if (en) {
314+
dcd_reg->USBINTR |= INTR_SOF;
315+
} else {
316+
dcd_reg->USBINTR &= ~INTR_SOF;
317+
}
316318
}
317319

318320
//--------------------------------------------------------------------+
@@ -679,7 +681,8 @@ void dcd_int_handler(uint8_t rhport)
679681

680682
if (int_status & INTR_SOF)
681683
{
682-
dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
684+
const uint32_t frame = dcd_reg->FRINDEX;
685+
dcd_event_sof(rhport, frame, true);
683686
}
684687
}
685688

src/portable/microchip/samd/dcd_samd.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,12 @@ void dcd_connect(uint8_t rhport)
183183
void dcd_sof_enable(uint8_t rhport, bool en)
184184
{
185185
(void) rhport;
186-
(void) en;
187186

188-
// TODO implement later
187+
if (en) {
188+
USB->DEVICE.INTENSET.bit.SOF = 1;
189+
} else {
190+
USB->DEVICE.INTENCLR.bit.SOF = 1;
191+
}
189192
}
190193

191194
/*------------------------------------------------------------------*/
@@ -374,7 +377,9 @@ void dcd_int_handler (uint8_t rhport)
374377
if ( int_status & USB_DEVICE_INTFLAG_SOF )
375378
{
376379
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
377-
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
380+
const uint32_t frame = USB->DEVICE.FNUM.bit.FNUM;
381+
dcd_event_sof(0, frame, true);
382+
//dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
378383
}
379384

380385
// SAMD doesn't distinguish between Suspend and Disconnect state.

src/portable/nordic/nrf5x/dcd_nrf5x.c

+18-8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ static struct {
120120

121121
// nRF can only carry one DMA at a time, this is used to guard the access to EasyDMA
122122
atomic_flag dma_running;
123+
124+
// Track whether sof has been manually enabled
125+
bool sof_enabled;
123126
} _dcd;
124127

125128
/*------------------------------------------------------------------*/
@@ -283,9 +286,13 @@ void dcd_connect(uint8_t rhport) {
283286

284287
void dcd_sof_enable(uint8_t rhport, bool en) {
285288
(void) rhport;
286-
(void) en;
287-
288-
// TODO implement later
289+
if (en) {
290+
_dcd.sof_enabled = true;
291+
NRF_USBD->INTENSET = USBD_INTENSET_SOF_Msk;
292+
} else {
293+
_dcd.sof_enabled = false;
294+
NRF_USBD->INTENCLR = USBD_INTENCLR_SOF_Msk;
295+
}
289296
}
290297

291298
//--------------------------------------------------------------------+
@@ -607,13 +614,16 @@ void dcd_int_handler(uint8_t rhport) {
607614
}
608615
}
609616

610-
if (!iso_enabled) {
611-
// ISO endpoint is not used, SOF is only enabled one-time for remote wakeup
612-
// so we disable it now
613-
NRF_USBD->INTENCLR = USBD_INTENSET_SOF_Msk;
617+
if (!iso_enabled && !_dcd.sof_enabled) {
618+
// SOF interrupt not manually enabled and ISO endpoint is not used,
619+
// SOF is only enabled one-time for remote wakeup so we disable it now
620+
621+
NRF_USBD->INTENCLR = USBD_INTENCLR_SOF_Msk;
614622
}
615623

616-
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
624+
const uint32_t frame = NRF_USBD->FRAMECNTR;
625+
dcd_event_sof(0, frame, true);
626+
//dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
617627
}
618628

619629
if (int_status & USBD_INTEN_USBEVENT_Msk) {

src/portable/renesas/rusb2/dcd_rusb2.c

+21-19
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929

3030
#if CFG_TUD_ENABLED && defined(TUP_USBIP_RUSB2)
3131

32-
// Since TinyUSB doesn't use SOF for now, and this interrupt too often (1ms interval)
33-
// We disable SOF for now until needed later on
34-
#define USE_SOF 0
35-
3632
#include "device/dcd.h"
3733
#include "rusb2_type.h"
3834

@@ -74,6 +70,8 @@ typedef struct
7470
{
7571
pipe_state_t pipe[PIPE_COUNT];
7672
uint8_t ep[2][16]; /* a lookup table for a pipe index from an endpoint address */
73+
// Track whether sof has been manually enabled
74+
bool sof_enabled;
7775
} dcd_data_t;
7876

7977
static dcd_data_t _dcd;
@@ -664,6 +662,10 @@ void dcd_init(uint8_t rhport)
664662
rusb2_reg_t* rusb = RUSB2_REG(rhport);
665663
rusb2_module_start(rhport, true);
666664

665+
// We disable SOF for now until needed later on.
666+
// Since TinyUSB doesn't use SOF for now, and this interrupt often (1ms interval)
667+
_dcd.sof_enabled = false;
668+
667669
#ifdef RUSB2_SUPPORT_HIGHSPEED
668670
if ( rusb2_is_highspeed_rhport(rhport) ) {
669671
rusb->SYSCFG_b.HSE = 1;
@@ -708,7 +710,7 @@ void dcd_init(uint8_t rhport)
708710

709711
rusb->INTSTS0 = 0;
710712
rusb->INTENB0 = RUSB2_INTSTS0_VBINT_Msk | RUSB2_INTSTS0_BRDY_Msk | RUSB2_INTSTS0_BEMP_Msk |
711-
RUSB2_INTSTS0_DVST_Msk | RUSB2_INTSTS0_CTRT_Msk | (USE_SOF ? RUSB2_INTSTS0_SOFR_Msk : 0) |
713+
RUSB2_INTSTS0_DVST_Msk | RUSB2_INTSTS0_CTRT_Msk | (_dcd.sof_enabled ? RUSB2_INTSTS0_SOFR_Msk : 0) |
712714
RUSB2_INTSTS0_RESM_Msk;
713715
rusb->BEMPENB = 1;
714716
rusb->BRDYENB = 1;
@@ -756,10 +758,9 @@ void dcd_disconnect(uint8_t rhport)
756758

757759
void dcd_sof_enable(uint8_t rhport, bool en)
758760
{
759-
(void) rhport;
760-
(void) en;
761-
762-
// TODO implement later
761+
rusb2_reg_t* rusb = RUSB2_REG(rhport);
762+
_dcd.sof_enabled = en;
763+
rusb->INTENB0_b.SOFE = en ? 1: 0;
763764
}
764765

765766
//--------------------------------------------------------------------+
@@ -949,18 +950,19 @@ void dcd_int_handler(uint8_t rhport)
949950
// Resumed
950951
if ( is0 & RUSB2_INTSTS0_RESM_Msk ) {
951952
dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
952-
#if (0 == USE_SOF)
953-
rusb->INTENB0_b.SOFE = 0;
954-
#endif
953+
if (!_dcd.sof_enabled) {
954+
rusb->INTENB0_b.SOFE = 0;
955+
}
955956
}
956957

957958
// SOF received
958959
if ( (is0 & RUSB2_INTSTS0_SOFR_Msk) && rusb->INTENB0_b.SOFE ) {
959960
// USBD will exit suspended mode when SOF event is received
960-
dcd_event_bus_signal(rhport, DCD_EVENT_SOF, true);
961-
#if (0 == USE_SOF)
962-
rusb->INTENB0_b.SOFE = 0;
963-
#endif
961+
const uint32_t frame = rusb->FRMNUM_b.FRNM;
962+
dcd_event_sof(rhport, frame, true);
963+
if (!_dcd.sof_enabled) {
964+
rusb->INTENB0_b.SOFE = 0;
965+
}
964966
}
965967

966968
// Device state changes
@@ -979,9 +981,9 @@ void dcd_int_handler(uint8_t rhport)
979981
case RUSB2_INTSTS0_DVSQ_STATE_SUSP2:
980982
case RUSB2_INTSTS0_DVSQ_STATE_SUSP3:
981983
dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
982-
#if (0 == USE_SOF)
983-
rusb->INTENB0_b.SOFE = 1;
984-
#endif
984+
if (!_dcd.sof_enabled) {
985+
rusb->INTENB0_b.SOFE = 1;
986+
}
985987

986988
default: break;
987989
}

0 commit comments

Comments
 (0)