@@ -164,6 +164,25 @@ static void qtd_init (ehci_qtd_t* qtd, void const* buffer, uint16_t total_bytes)
164
164
static inline void list_insert (ehci_link_t * current , ehci_link_t * new , uint8_t new_type );
165
165
static inline ehci_link_t * list_next (ehci_link_t * p_link_pointer );
166
166
167
+ TU_ATTR_WEAK void hcd_dcache_clean (void * addr , uint32_t data_size ) {
168
+ (void ) addr ;
169
+ (void ) data_size ;
170
+ }
171
+
172
+ // invalidate data cache: mark cache as invalid, next read will read from memory
173
+ // Required BOTH before and after an DMA RX transfer
174
+ TU_ATTR_WEAK void hcd_dcache_invalidate (void * addr , uint32_t data_size ) {
175
+ (void ) addr ;
176
+ (void ) data_size ;
177
+ }
178
+
179
+ // clean and invalidate data cache
180
+ // Required before an DMA transfer where memory is both read/write by DMA
181
+ TU_ATTR_WEAK void hcd_dcache_clean_invalidate (void * addr , uint32_t data_size ) {
182
+ (void ) addr ;
183
+ (void ) data_size ;
184
+ }
185
+
167
186
//--------------------------------------------------------------------+
168
187
// HCD API
169
188
//--------------------------------------------------------------------+
@@ -342,9 +361,7 @@ bool ehci_init(uint8_t rhport, uint32_t capability_reg, uint32_t operatial_reg)
342
361
343
362
regs -> periodic_list_base = (uint32_t ) framelist ;
344
363
345
- if (hcd_dcache_clean ) {
346
- hcd_dcache_clean (& ehci_data , sizeof (ehci_data_t ));
347
- }
364
+ hcd_dcache_clean (& ehci_data , sizeof (ehci_data_t ));
348
365
349
366
//------------- TT Control (NXP only) -------------//
350
367
regs -> nxp_tt_control = 0 ;
@@ -429,10 +446,8 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
429
446
// TODO might need to disable async/period list
430
447
list_insert (list_head , (ehci_link_t * ) p_qhd , EHCI_QTYPE_QHD );
431
448
432
- if (hcd_dcache_clean ) {
433
- hcd_dcache_clean (p_qhd , sizeof (ehci_qhd_t ));
434
- hcd_dcache_clean (list_head , sizeof (ehci_link_t ));
435
- }
449
+ hcd_dcache_clean (p_qhd , sizeof (ehci_qhd_t ));
450
+ hcd_dcache_clean (list_head , sizeof (ehci_link_t ));
436
451
437
452
return true;
438
453
}
@@ -447,10 +462,8 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
447
462
qtd_init (td , setup_packet , 8 );
448
463
td -> pid = EHCI_PID_SETUP ;
449
464
450
- if (hcd_dcache_clean && hcd_dcache_clean_invalidate ) {
451
- hcd_dcache_clean ((void * ) setup_packet , 8 );
452
- hcd_dcache_clean_invalidate (td , sizeof (ehci_qtd_t ));
453
- }
465
+ hcd_dcache_clean ((void * ) setup_packet , 8 );
466
+ hcd_dcache_clean_invalidate (td , sizeof (ehci_qtd_t ));
454
467
455
468
// sw region
456
469
qhd -> p_qtd_list_head = td ;
@@ -459,9 +472,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
459
472
// attach TD
460
473
qhd -> qtd_overlay .next .address = (uint32_t ) td ;
461
474
462
- if (hcd_dcache_clean_invalidate ) {
463
- hcd_dcache_clean_invalidate (qhd , sizeof (ehci_qhd_t ));
464
- }
475
+ hcd_dcache_clean_invalidate (qhd , sizeof (ehci_qhd_t ));
465
476
466
477
return true;
467
478
}
@@ -496,15 +507,13 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
496
507
qtd -> pid = qhd -> pid ;
497
508
}
498
509
499
- if (hcd_dcache_clean && hcd_dcache_clean_invalidate ) {
500
- // IN transfer: invalidate buffer, OUT transfer: clean buffer
501
- if (dir ) {
502
- hcd_dcache_invalidate (buffer , buflen );
503
- }else {
504
- hcd_dcache_clean (buffer , buflen );
505
- }
506
- hcd_dcache_clean_invalidate (qtd , sizeof (ehci_qtd_t ));
510
+ // IN transfer: invalidate buffer, OUT transfer: clean buffer
511
+ if (dir ) {
512
+ hcd_dcache_invalidate (buffer , buflen );
513
+ }else {
514
+ hcd_dcache_clean (buffer , buflen );
507
515
}
516
+ hcd_dcache_clean_invalidate (qtd , sizeof (ehci_qtd_t ));
508
517
509
518
// Software: assign TD to QHD
510
519
qhd -> p_qtd_list_head = qtd ;
@@ -513,9 +522,7 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
513
522
// attach TD to QHD start transferring
514
523
qhd -> qtd_overlay .next .address = (uint32_t ) qtd ;
515
524
516
- if (hcd_dcache_clean_invalidate ) {
517
- hcd_dcache_clean_invalidate (qhd , sizeof (ehci_qhd_t ));
518
- }
525
+ hcd_dcache_clean_invalidate (qhd , sizeof (ehci_qhd_t ));
519
526
520
527
return true;
521
528
}
@@ -570,9 +577,7 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd)
570
577
{
571
578
ehci_qtd_t * volatile qtd = (ehci_qtd_t * volatile ) p_qhd -> p_qtd_list_head ;
572
579
573
- if (hcd_dcache_invalidate ) {
574
- hcd_dcache_invalidate (qtd , sizeof (ehci_qtd_t ));
575
- }
580
+ hcd_dcache_invalidate (qtd , sizeof (ehci_qtd_t ));
576
581
577
582
bool const is_ioc = (qtd -> int_on_complete != 0 );
578
583
uint8_t const ep_addr = tu_edpt_addr (p_qhd -> ep_number , qtd -> pid == EHCI_PID_IN ? 1 : 0 );
@@ -596,9 +601,7 @@ static void async_list_xfer_complete_isr(ehci_qhd_t * const async_head)
596
601
ehci_qhd_t * p_qhd = async_head ;
597
602
do
598
603
{
599
- if (hcd_dcache_invalidate ) {
600
- hcd_dcache_invalidate (p_qhd , sizeof (ehci_qhd_t ));
601
- }
604
+ hcd_dcache_invalidate (p_qhd , sizeof (ehci_qhd_t ));
602
605
603
606
// halted or error is processed in error isr
604
607
if ( !p_qhd -> qtd_overlay .halted ) {
0 commit comments