From 9e0cc8347cc993d6fd4424adb4f41b1e9d09cc1d Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Sat, 24 Feb 2024 16:37:20 +0800 Subject: [PATCH] align for some buffers --- class/hub/usbh_hub.c | 4 ++-- common/usb_util.h | 14 ++++++++------ core/usbh_core.c | 2 +- port/ehci/usb_ehci_priv.h | 2 +- port/ehci/usb_hc_ehci.c | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index 73b9e61b..f638a342 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -19,8 +19,8 @@ #define EXTHUB_FIRST_INDEX 2 -USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_buf[CONFIG_USBHOST_MAX_BUS][32]; -USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_intbuf[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USB_ALIGN_SIZE]; +USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_buf[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(32, CONFIG_USB_ALIGN_SIZE)]; +USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t g_hub_intbuf[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_MAX_EXTHUBS + 1][USB_ALIGN_UP(1, CONFIG_USB_ALIGN_SIZE)]; extern int usbh_free_devaddr(struct usbh_hubport *hport); extern int usbh_enumerate(struct usbh_hubport *hport); diff --git a/common/usb_util.h b/common/usb_util.h index 797e7b26..624cd9fc 100644 --- a/common/usb_util.h +++ b/common/usb_util.h @@ -46,7 +46,7 @@ #endif #elif defined(__ICCARM__) || defined(__ICCRX__) || defined(__ICCRISCV__) #ifndef __USED -#if defined(__ICCARM_V8) || defined (__ICCRISCV__) +#if defined(__ICCARM_V8) || defined(__ICCRISCV__) #define __USED __attribute__((used)) #else #define __USED __root @@ -54,7 +54,7 @@ #endif #ifndef __WEAK -#if defined(__ICCARM_V8) || defined (__ICCRISCV__) +#if defined(__ICCARM_V8) || defined(__ICCRISCV__) #define __WEAK __attribute__((weak)) #else #define __WEAK _Pragma("__weak") @@ -62,7 +62,7 @@ #endif #ifndef __PACKED -#if defined(__ICCARM_V8) || defined (__ICCRISCV__) +#if defined(__ICCARM_V8) || defined(__ICCRISCV__) #define __PACKED __attribute__((packed, aligned(1))) #else /* Needs IAR language extensions */ @@ -71,7 +71,7 @@ #endif #ifndef __PACKED_STRUCT -#if defined(__ICCARM_V8) || defined (__ICCRISCV__) +#if defined(__ICCARM_V8) || defined(__ICCRISCV__) #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) #else /* Needs IAR language extensions */ @@ -80,7 +80,7 @@ #endif #ifndef __PACKED_UNION -#if defined(__ICCARM_V8) || defined (__ICCRISCV__) +#if defined(__ICCARM_V8) || defined(__ICCRISCV__) #define __PACKED_UNION union __attribute__((packed, aligned(1))) #else /* Needs IAR language extensions */ @@ -89,7 +89,7 @@ #endif #ifndef __ALIGNED -#if defined(__ICCARM_V8) || defined (__ICCRISCV__) +#if defined(__ICCARM_V8) || defined(__ICCRISCV__) #define __ALIGNED(x) __attribute__((aligned(x))) #elif (__VER__ >= 7080000) /* Needs IAR language extensions */ @@ -205,4 +205,6 @@ #define USB_MEM_ALIGNX __attribute__((aligned(CONFIG_USB_ALIGN_SIZE))) +#define USB_ALIGN_UP(size, align) (((size) + (align)-1) & ~((align)-1)) + #endif /* USB_UTIL_H */ diff --git a/core/usbh_core.c b/core/usbh_core.c index 6ca6ddc1..2e43ee50 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -14,7 +14,7 @@ struct usbh_class_info *usbh_class_info_table_end = NULL; usb_slist_t g_bus_head = USB_SLIST_OBJECT_INIT(g_bus_head); -USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t ep0_request_buffer[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_REQUEST_BUFFER_LEN]; +USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t ep0_request_buffer[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USBHOST_REQUEST_BUFFER_LEN, CONFIG_USB_ALIGN_SIZE)]; USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct usb_setup_packet g_setup_buffer[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USBHOST_MAX_EHPORTS]; struct usbh_bus g_usbhost_bus[CONFIG_USBHOST_MAX_BUS]; diff --git a/port/ehci/usb_ehci_priv.h b/port/ehci/usb_ehci_priv.h index 2a67b686..3123346e 100644 --- a/port/ehci/usb_ehci_priv.h +++ b/port/ehci/usb_ehci_priv.h @@ -60,7 +60,7 @@ struct ehci_hcd { }; extern struct ehci_hcd g_ehci_hcd[CONFIG_USBHOST_MAX_BUS]; -extern uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][CONFIG_USB_EHCI_FRAME_LIST_SIZE]; +extern uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USB_EHCI_FRAME_LIST_SIZE, 1024)]; int ehci_iso_urb_init(struct usbh_bus *bus, struct usbh_urb *urb); void ehci_remove_itd_urb(struct usbh_bus *bus, struct usbh_urb *urb); diff --git a/port/ehci/usb_hc_ehci.c b/port/ehci/usb_hc_ehci.c index f15b1a61..f3be5801 100644 --- a/port/ehci/usb_hc_ehci.c +++ b/port/ehci/usb_hc_ehci.c @@ -22,7 +22,7 @@ USB_NOCACHE_RAM_SECTION struct ehci_qh_hw g_async_qh_head[CONFIG_USBHOST_MAX_BUS USB_NOCACHE_RAM_SECTION struct ehci_qh_hw g_periodic_qh_head[CONFIG_USBHOST_MAX_BUS][EHCI_PERIOIDIC_QH_NUM]; /* The frame list */ -USB_NOCACHE_RAM_SECTION uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][CONFIG_USB_EHCI_FRAME_LIST_SIZE] __attribute__((aligned(4096))); +USB_NOCACHE_RAM_SECTION uint32_t g_framelist[CONFIG_USBHOST_MAX_BUS][USB_ALIGN_UP(CONFIG_USB_EHCI_FRAME_LIST_SIZE, 1024)] __attribute__((aligned(4096))); static struct ehci_qh_hw *ehci_qh_alloc(struct usbh_bus *bus) {