Skip to content

Commit 336aa91

Browse files
committed
update(port): add sof support
Signed-off-by: sakumisu <[email protected]>
1 parent 7a0e8ca commit 336aa91

File tree

10 files changed

+68
-6
lines changed

10 files changed

+68
-6
lines changed

cherryusb_config_template.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@
236236
#define CONFIG_USBDEV_EP_NUM 8
237237
#endif
238238

239+
// #define CONFIG_USBDEV_SOF_ENABLE
240+
239241
/* When your chip hardware supports high-speed and wants to initialize it in high-speed mode, the relevant IP will configure the internal or external high-speed PHY according to CONFIG_USB_HS. */
240242
// #define CONFIG_USB_HS
241243

common/usb_dc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t
138138

139139
/* usb dcd irq callback, called by user */
140140

141+
/**
142+
* @brief Usb sof irq callback.
143+
*/
144+
void usbd_event_sof_handler(uint8_t busid);
145+
141146
/**
142147
* @brief Usb connect irq callback.
143148
*/

core/usbd_core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,11 @@ static void usbd_class_event_notify_handler(uint8_t busid, uint8_t event, void *
10901090
}
10911091
}
10921092

1093+
void usbd_event_sof_handler(uint8_t busid)
1094+
{
1095+
g_usbd_core[busid].event_handler(busid, USBD_EVENT_SOF);
1096+
}
1097+
10931098
void usbd_event_connect_handler(uint8_t busid)
10941099
{
10951100
g_usbd_core[busid].event_handler(busid, USBD_EVENT_CONNECTED);

port/chipidea/usb_dc_chipidea.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,10 @@ int usb_dc_init(uint8_t busid)
462462
/* Clear status */
463463
USB_OTG_DEV->USBSTS = USB_OTG_DEV->USBSTS;
464464

465+
#ifdef CONFIG_USBDEV_SOF_ENABLE
466+
int_mask |= USB_USBINTR_SRE_MASK;
467+
#endif
468+
465469
/* Enable interrupt mask */
466470
USB_OTG_DEV->USBINTR |= int_mask;
467471

@@ -630,6 +634,12 @@ void USBD_IRQHandler(uint8_t busid)
630634
USB_LOG_ERR("usbd intr error!\r\n");
631635
}
632636

637+
#ifdef CONFIG_USBDEV_SOF_ENABLE
638+
if (int_status & intr_sof) {
639+
usbd_event_sof_handler(busid);
640+
}
641+
#endif
642+
633643
if (int_status & intr_reset) {
634644
g_chipidea_udc[busid].is_suspend = false;
635645
memset(g_chipidea_udc[busid].in_ep, 0, sizeof(struct chipidea_ep_state) * CONFIG_USBDEV_EP_NUM);

port/dwc2/usb_dc_dwc2.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ int usb_dc_init(uint8_t busid)
598598
#if CONFIG_DWC2_VBUS_SENSING
599599
USB_OTG_GLB->GINTMSK |= (USB_OTG_GINTMSK_OTGINT | USB_OTG_GINTMSK_SRQIM);
600600
#endif
601-
#if 0
601+
#ifdef CONFIG_USBDEV_SOF_ENABLE
602602
USB_OTG_GLB->GINTMSK |= USB_OTG_GINTMSK_SOFM;
603603
#endif
604604

@@ -1143,10 +1143,12 @@ void USBD_IRQHandler(uint8_t busid)
11431143
if (gint_status & USB_OTG_GINTSTS_IISOIXFR) {
11441144
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_IISOIXFR;
11451145
}
1146-
1146+
#ifdef CONFIG_USBDEV_SOF_ENABLE
11471147
if (gint_status & USB_OTG_GINTSTS_SOF) {
11481148
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_SOF;
1149+
usbd_event_sof_handler(busid);
11491150
}
1151+
#endif
11501152
if (gint_status & USB_OTG_GINTSTS_USBSUSP) {
11511153
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_USBSUSP;
11521154
usbd_event_suspend_handler(busid);

port/fsdev/usb_dc_fsdev.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ int usb_dc_init(uint8_t busid)
7979
/* Set winterruptmask variable */
8080
winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM |
8181
USB_CNTR_SUSPM | USB_CNTR_ERRM |
82-
USB_CNTR_SOFM | USB_CNTR_ESOFM |
83-
USB_CNTR_RESETM;
82+
USB_CNTR_ESOFM | USB_CNTR_RESETM;
83+
84+
#ifdef CONFIG_USBDEV_SOF_ENABLE
85+
winterruptmask |= USB_CNTR_SOFM;
86+
#endif
8487

8588
/* Set interrupt mask */
8689
USB->CNTR = (uint16_t)winterruptmask;
@@ -482,9 +485,12 @@ void USBD_IRQHandler(uint8_t busid)
482485

483486
USB->CNTR |= (uint16_t)USB_CNTR_LP_MODE;
484487
}
488+
#ifdef CONFIG_USBDEV_SOF_ENABLE
485489
if (wIstr & USB_ISTR_SOF) {
486490
USB->ISTR &= (uint16_t)(~USB_ISTR_SOF);
491+
usbd_event_sof_handler(0);
487492
}
493+
#endif
488494
if (wIstr & USB_ISTR_ESOF) {
489495
USB->ISTR &= (uint16_t)(~USB_ISTR_ESOF);
490496
}

port/hpm/usb_dc_hpm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ int usb_dc_init(uint8_t busid)
9595
int_mask = (USB_USBINTR_UE_MASK | USB_USBINTR_UEE_MASK | USB_USBINTR_SLE_MASK |
9696
USB_USBINTR_PCE_MASK | USB_USBINTR_URE_MASK);
9797

98+
#ifdef CONFIG_USBDEV_SOF_ENABLE
99+
int_mask |= USB_USBINTR_SRE_MASK;
100+
#endif
101+
98102
usb_device_init(g_hpm_udc[busid].handle, int_mask);
99103

100104
intc_m_enable_irq(_dcd_irqnum[busid]);
@@ -274,6 +278,11 @@ void USBD_IRQHandler(uint8_t busid)
274278
USB_LOG_ERR("usbd intr error!\r\n");
275279
}
276280

281+
#ifdef CONFIG_USBDEV_SOF_ENABLE
282+
if (int_status & intr_sof) {
283+
usbd_event_sof_handler(busid);
284+
}
285+
#endif
277286
if (int_status & intr_reset) {
278287
g_hpm_udc[busid].is_suspend = false;
279288
memset(g_hpm_udc[busid].in_ep, 0, sizeof(struct hpm_ep_state) * USB_NUM_BIDIR_ENDPOINTS);

port/kinetis/usb_dc_kinetis.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ int usb_dc_init(uint8_t busid)
102102
USB_INTEN_SLEEPEN_MASK | USB_INTEN_RESUMEEN_MASK |
103103
USB_INTEN_ERROREN_MASK;
104104

105+
#ifdef CONFIG_USBDEV_SOF_ENABLE
106+
USB_OTG_DEV->INTEN |= USB_INTEN_SOFTOKEN_MASK;
107+
#endif
108+
105109
USB_OTG_DEV->CTL |= USB_CTL_USBENSOFEN_MASK;
106110
return 0;
107111
}
@@ -380,11 +384,12 @@ void USBD_IRQHandler(uint8_t busid)
380384
if (is & USB_ISTAT_RESUME_MASK) {
381385
USB_OTG_DEV->ISTAT = USB_ISTAT_RESUME_MASK;
382386
}
383-
387+
#ifdef CONFIG_USBDEV_SOF_ENABLE
384388
if (is & USB_ISTAT_SOFTOK_MASK) {
385389
USB_OTG_DEV->ISTAT = USB_ISTAT_SOFTOK_MASK;
390+
usbd_event_sof_handler(busid);
386391
}
387-
392+
#endif
388393
if (is & USB_ISTAT_STALL_MASK) {
389394
USB_OTG_DEV->ISTAT = USB_ISTAT_STALL_MASK;
390395
}

port/musb/usb_dc_musb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ int usb_dc_init(uint8_t busid)
273273
HWREGH(USB_BASE + MUSB_TXIE_OFFSET) = USB_TXIE_EP0;
274274
HWREGH(USB_BASE + MUSB_RXIE_OFFSET) = 0;
275275

276+
#ifdef CONFIG_USBDEV_SOF_ENABLE
277+
HWREGB(USB_BASE + MUSB_IE_OFFSET) |= USB_IE_SOF;
278+
#endif
279+
276280
HWREGB(USB_BASE + MUSB_POWER_OFFSET) |= USB_POWER_SOFTCONN;
277281
return 0;
278282
}
@@ -721,8 +725,11 @@ void USBD_IRQHandler(uint8_t busid)
721725
usb_ep0_state = USB_EP0_STATE_SETUP;
722726
}
723727

728+
#ifdef CONFIG_USBDEV_SOF_ENABLE
724729
if (is & USB_IS_SOF) {
730+
usbd_event_sof_handler(0);
725731
}
732+
#endif
726733

727734
if (is & USB_IS_RESUME) {
728735
usbd_event_resume_handler(0);

port/rp2040/usb_dc_rp2040.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ int usb_dc_init(uint8_t busid)
181181
USB_INTS_DEV_SUSPEND_BITS | USB_INTS_DEV_RESUME_FROM_HOST_BITS |
182182
(FORCE_VBUS_DETECT ? 0 : USB_INTS_DEV_CONN_DIS_BITS);
183183

184+
#ifdef CONFIG_USBDEV_SOF_ENABLE
185+
usb_hw->inte |= USB_INTS_DEV_SOF_BITS;
186+
#endif
187+
184188
// Enable USB interrupt at processor
185189
irq_set_enabled(USBCTRL_IRQ, true);
186190

@@ -577,6 +581,13 @@ void USBD_IRQHandler(uint8_t busid)
577581
usbd_event_resume_handler(0);
578582
}
579583

584+
#ifdef CONFIG_USBDEV_SOF_ENABLE
585+
if (status & USB_INTS_DEV_SOF_BITS) {
586+
handled |= USB_INTS_DEV_SOF_BITS;
587+
usbd_event_sof_handler(0);
588+
}
589+
#endif
590+
580591
if (status ^ handled) {
581592
USB_LOG_INFO("Unhandled IRQ 0x%x\n", (uint32_t)(status ^ handled));
582593
}

0 commit comments

Comments
 (0)