@@ -105,6 +105,16 @@ static bool _sof_en;
105105//--------------------------------------------------------------------
106106// DMA
107107//--------------------------------------------------------------------
108+ // When DMA requires cache synchronization for memory
109+ // Data synchronization: cache to memory
110+ #ifndef dsync_c2m
111+ #define dsync_c2m (_addr , _size )
112+ #endif // dsync_c2m
113+
114+ // Data synchronization: memory to cache
115+ #ifndef dsync_m2c
116+ #define dsync_m2c (_addr , _size )
117+ #endif // dsync_m2c
108118
109119TU_ATTR_ALWAYS_INLINE static inline bool dma_enabled (const dwc2_regs_t * dwc2 ) {
110120 #if !CFG_TUD_DWC2_DMA
@@ -467,9 +477,7 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
467477
468478 if (dma_enabled (dwc2 )) {
469479 dep -> diepdma = (uintptr_t )xfer -> buffer ;
470- if (total_bytes != 0 ) {
471- dwc2_dcd_sync_cache_to_memory (xfer -> buffer , total_bytes );
472- }
480+ dsync_c2m (xfer -> buffer , total_bytes );
473481 // For ISO endpoint set correct odd/even bit for next frame.
474482 if ((dep -> diepctl & DIEPCTL_EPTYP ) == DIEPCTL_EPTYP_0 && (XFER_CTL_BASE (epnum , dir ))-> interval == 1 ) {
475483 // Take odd/even bit from frame counter.
@@ -507,9 +515,7 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
507515
508516 if (dma_enabled (dwc2 )) {
509517 dep -> doepdma = (uintptr_t )xfer -> buffer ;
510- if (total_bytes != 0 ) {
511- dwc2_dcd_sync_cache_to_memory (xfer -> buffer , total_bytes );
512- }
518+ dsync_c2m (xfer -> buffer , total_bytes );
513519 }
514520
515521 dep -> doepctl |= DOEPCTL_EPENA | DOEPCTL_CNAK ;
@@ -1055,7 +1061,7 @@ static void handle_epout_irq(uint8_t rhport) {
10551061
10561062 if (dma_enabled (dwc2 )) {
10571063 dma_setup_prepare (rhport );
1058- dwc2_dcd_sync_memory_to_cache ((uint8_t * ) _setup_packet , sizeof (_setup_packet ));
1064+ dsync_m2c ((uint8_t * ) _setup_packet , sizeof (_setup_packet ));
10591065 }
10601066
10611067 dcd_event_setup_received (rhport , (uint8_t * ) _setup_packet , true);
@@ -1082,9 +1088,7 @@ static void handle_epout_irq(uint8_t rhport) {
10821088 if (epnum == 0 && xfer -> total_len == 0 ) {
10831089 dma_setup_prepare (rhport );
10841090 }
1085- if (xfer -> total_len ) {
1086- dwc2_dcd_sync_memory_to_cache (xfer -> buffer , xfer -> total_len );
1087- }
1091+ dsync_m2c (xfer -> buffer , xfer -> total_len );
10881092 dcd_event_xfer_complete (rhport , epnum , xfer -> total_len , XFER_RESULT_SUCCESS , true);
10891093 }
10901094 } else {
0 commit comments