Jelajahi Sumber

feat(dcache): update dcache api

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 7 bulan lalu
induk
melakukan
1d95077161

+ 3 - 12
cherryusb_config_template.h

@@ -333,18 +333,9 @@
 // #define CONFIG_USB_MUSB_SUNXI
 
 /* ================ USB Dcache Configuration ==================*/
-
-#ifdef CONFIG_USB_DCACHE_ENABLE
-/* style 1*/
-// void usb_dcache_clean(uintptr_t addr, uint32_t size);
-// void usb_dcache_invalidate(uintptr_t addr, uint32_t size);
-// void usb_dcache_flush(uintptr_t addr, uint32_t size);
-
-/* style 2*/
-// #define usb_dcache_clean(addr, size)
-// #define usb_dcache_invalidate(addr, size)
-// #define usb_dcache_flush(addr, size)
-#endif
+// #define CONFIG_USB_DCACHE_ENABLE
+// #undef CONFIG_USB_ALIGN_SIZE
+// #define CONFIG_USB_ALIGN_SIZE 32
 
 #ifndef usb_phyaddr2ramaddr
 #define usb_phyaddr2ramaddr(addr) (addr)

+ 3 - 0
common/usb_dcache.h

@@ -10,6 +10,9 @@
 #if CONFIG_USB_ALIGN_SIZE % 32
 #error "CONFIG_USB_ALIGN_SIZE must be multiple of 32"
 #endif
+void usb_dcache_clean(uintptr_t addr, size_t size);
+void usb_dcache_invalidate(uintptr_t addr, size_t size);
+void usb_dcache_flush(uintptr_t addr, size_t size);
 #else
 #define usb_dcache_clean(addr, size)
 #define usb_dcache_invalidate(addr, size)

+ 1 - 0
docs/source/version.rst

@@ -119,6 +119,7 @@ v1.5.0
 - **重构device video 传输,直接在图像数据中填充 uvc header,达到zero memcpy**
 - **增加 usb_osal_thread_schedule_other api,用于在释放 class 资源之前,先释放所有 class 线程,避免释放 class 资源以后线程还在使用该 class 资源**
 - **dwc2 device 增加 dcache 功能,可用于 STM32H7/H7R/ESP32P4**
+- **bouffalo/hpm/esp/st/nxp dcache api 支持**
 - ch32 device iso 更新
 - cmake,scons,kconfig 更新
 - 使用 USB_ASSERT_MSG 对部分代码检查

+ 18 - 0
port/ehci/usb_glue_bouffalo.c

@@ -4,6 +4,7 @@
  * SPDX-License-Identifier: Apache-2.0
  */
 #include "bflb_core.h"
+#include "bflb_l1c.h"
 #include "usbh_core.h"
 #include "hardware/usb_v2_reg.h"
 
@@ -141,3 +142,20 @@ uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
     }
     return USB_SPEED_HIGH;
 }
+
+#ifdef CONFIG_USB_DCACHE_ENABLE
+void usb_dcache_clean(uintptr_t addr, size_t size)
+{
+    bflb_l1c_dcache_clean_range((void *)addr, size);
+}
+
+void usb_dcache_invalidate(uintptr_t addr, size_t size)
+{
+    bflb_l1c_dcache_invalidate_range((void *)addr, size);
+}
+
+void usb_dcache_flush(uintptr_t addr, size_t size)
+{
+    bflb_l1c_dcache_clean_invalidate_range((void *)addr, size);
+}
+#endif

+ 21 - 2
port/hpmicro/usb_glue_hpm.c

@@ -6,6 +6,8 @@
  */
 #include "hpm_common.h"
 #include "hpm_soc.h"
+#include "hpm_l1c_drv.h"
+#include "usb_config.h"
 
 void (*g_usb_hpm_irq[2])(uint8_t busid);
 uint8_t g_usb_hpm_busid[2];
@@ -13,7 +15,7 @@ uint8_t g_usb_hpm_busid[2];
 ATTR_WEAK void hpm_usb_isr_enable(uint32_t base)
 {
     if (base == HPM_USB0_BASE) {
-        intc_m_enable_irq(IRQn_USB0); 
+        intc_m_enable_irq(IRQn_USB0);
     } else {
 #ifdef HPM_USB1_BASE
         intc_m_enable_irq(IRQn_USB1);
@@ -24,7 +26,7 @@ ATTR_WEAK void hpm_usb_isr_enable(uint32_t base)
 ATTR_WEAK void hpm_usb_isr_disable(uint32_t base)
 {
     if (base == HPM_USB0_BASE) {
-        intc_m_disable_irq(IRQn_USB0); 
+        intc_m_disable_irq(IRQn_USB0);
     } else {
 #ifdef HPM_USB1_BASE
         intc_m_disable_irq(IRQn_USB1);
@@ -48,4 +50,21 @@ void hpm_isr_usb1(void)
 {
     g_usb_hpm_irq[1](g_usb_hpm_busid[1]);
 }
+#endif
+
+#ifdef CONFIG_USB_DCACHE_ENABLE
+void usb_dcache_clean(uintptr_t addr, size_t size)
+{
+    l1c_dc_writeback(addr, size);
+}
+
+void usb_dcache_invalidate(uintptr_t addr, size_t size)
+{
+    l1c_dc_invalidate(addr, size);
+}
+
+void usb_dcache_flush(uintptr_t addr, size_t size)
+{
+    l1c_dc_flush(addr, size);
+}
 #endif

+ 19 - 1
port/nxp/usb_glue_mcx.c

@@ -6,6 +6,7 @@
 #include "usbd_core.h"
 #include "usbh_core.h"
 #include "fsl_common.h"
+#include "fsl_cache.h"
 #include "usb_chipidea_reg.h"
 
 __WEAK void USBD_IRQHandler(uint8_t busid)
@@ -428,4 +429,21 @@ uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
 void USB1_HS_IRQHandler(void)
 {
     g_usb_nxp_irq(0);
-}
+}
+
+#ifdef CONFIG_USB_DCACHE_ENABLE
+void usb_dcache_clean(uintptr_t addr, size_t size)
+{
+    DCACHE_CleanByRange(addr, size);
+}
+
+void usb_dcache_invalidate(uintptr_t addr, size_t size)
+{
+    DCACHE_InvalidateByRange(addr, size);
+}
+
+void usb_dcache_flush(uintptr_t addr, size_t size)
+{
+    DCACHE_CleanInvalidateByRange(addr, size);
+}
+#endif