update dwc2 iso transfer

This commit is contained in:
sakumisu
2022-08-21 13:03:26 +08:00
parent 1e80e240e2
commit 7391b7a5b9
4 changed files with 52 additions and 6 deletions

View File

@@ -149,6 +149,7 @@ void usbd_configure_done_callback(void)
}
volatile bool tx_flag = 0;
volatile bool ep_tx_busy_flag = false;
void usbd_audio_open(uint8_t intf)
{
@@ -163,6 +164,8 @@ void usbd_audio_close(uint8_t intf)
void usbd_audio_iso_callback(uint8_t ep, uint32_t nbytes)
{
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
ep_tx_busy_flag = false;
}
static struct usbd_endpoint audio_in_ep = {
@@ -182,10 +185,17 @@ void audio_init()
usbd_initialize();
}
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
void audio_test()
{
while (1) {
if (tx_flag) {
memset(write_buffer, 'a', 2048);
ep_tx_busy_flag = true;
usbd_ep_start_write(AUDIO_IN_EP, write_buffer, 2048);
while (ep_tx_busy_flag) {
}
}
}
}

View File

@@ -160,21 +160,27 @@ void usbd_audio_close(uint8_t intf)
#define AUDIO_OUT_EP_MPS 64
#endif
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t out_buffer[AUDIO_OUT_EP_MPS];
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t out_buffer[AUDIO_OUT_PACKET];
volatile bool ep_tx_busy_flag = false;
void usbd_configure_done_callback(void)
{
/* setup first out ep read transfer */
usbd_ep_start_read(AUDIO_OUT_EP, out_buffer, AUDIO_OUT_EP_MPS);
usbd_ep_start_read(AUDIO_OUT_EP, out_buffer, AUDIO_OUT_PACKET);
}
void usbd_audio_out_callback(uint8_t ep, uint32_t bytes)
void usbd_audio_out_callback(uint8_t ep, uint32_t nbytes)
{
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
usbd_ep_start_read(AUDIO_OUT_EP, out_buffer, AUDIO_OUT_PACKET);
}
void usbd_audio_in_callback(uint8_t ep, uint32_t bytes)
void usbd_audio_in_callback(uint8_t ep, uint32_t nbytes)
{
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
ep_tx_busy_flag = false;
}
static struct usbd_endpoint audio_in_ep = {
@@ -206,6 +212,11 @@ void audio_test()
{
while (1) {
if (tx_flag) {
// memset(write_buffer, 'a', 2048);
// ep_tx_busy_flag = true;
// usbd_ep_start_write(AUDIO_IN_EP, write_buffer, 2048);
// while (ep_tx_busy_flag) {
// }
}
}
}

View File

@@ -141,6 +141,11 @@ const uint8_t video_descriptor[] = {
0x00
};
void usbd_configure_done_callback(void)
{
/* no out ep, so do nothing */
}
volatile bool tx_flag = 0;
void usbd_video_open(uint8_t intf)
@@ -158,6 +163,7 @@ volatile bool iso_tx_busy = false;
void usbd_video_iso_callback(uint8_t ep, uint32_t nbytes)
{
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
iso_tx_busy = false;
}
@@ -170,6 +176,7 @@ void video_init()
{
usbd_desc_register(video_descriptor);
usbd_add_interface(usbd_video_alloc_intf(CAM_FPS, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
usbd_add_interface(usbd_video_alloc_intf(CAM_FPS, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
usbd_add_endpoint(&video_in_ep);
usbd_initialize();
@@ -198,7 +205,7 @@ void video_test()
}
} else {
iso_tx_busy = true;
usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE, NULL);
usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE);
while (iso_tx_busy) {
}
}

View File

@@ -841,6 +841,16 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
#ifdef CONFIG_USB_DWC2_DMA_ENABLE
usb_dwc2_dcache_clean((uintptr_t)data, data_len);
USB_OTG_INEP(ep_idx)->DIEPDMA = (uint32_t)data;
if (g_dwc2_udc.in_ep[ep_idx].ep_type == 0x01) {
if ((USB_OTG_DEV->DSTS & (1U << 8)) == 0U) {
USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
} else {
USB_OTG_INEP(ep_idx)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
}
USB_OTG_INEP(ep_idx)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_MULCNT);
USB_OTG_INEP(ep_idx)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_MULCNT & (1U << 29));
}
USB_OTG_INEP(ep_idx)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
#else
USB_OTG_INEP(ep_idx)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
@@ -911,6 +921,14 @@ int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
#ifdef CONFIG_USB_DWC2_DMA_ENABLE
USB_OTG_OUTEP(ep_idx)->DOEPDMA = (uint32_t)data;
if (g_dwc2_udc.out_ep[ep_idx].ep_type == 0x01) {
if ((USB_OTG_DEV->DSTS & (1U << 8)) == 0U) {
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
} else {
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
}
}
#endif
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= (USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);