Add cache line size alignment to buffer macro

Signed-off-by: HiFiPhile <admin@hifiphile.com>
This commit is contained in:
HiFiPhile
2025-06-13 13:17:41 +02:00
parent e84efd2771
commit e19ff3ecae
2 changed files with 20 additions and 6 deletions

View File

@@ -36,39 +36,39 @@
#endif #endif
//------------- Device DCache declaration -------------// //------------- Device DCache declaration -------------//
#define TUD_EPBUF_DCACHE_SIZE(_size) (CFG_TUD_MEM_DCACHE_ENABLE ? \ #define TUD_EPBUF_DCACHE_SIZE(_size) (TUD_EPBUF_DCACHE_ALIGNED ? \
(TU_DIV_CEIL(_size, CFG_TUD_MEM_DCACHE_LINE_SIZE) * CFG_TUD_MEM_DCACHE_LINE_SIZE) : (_size)) (TU_DIV_CEIL(_size, CFG_TUD_MEM_DCACHE_LINE_SIZE) * CFG_TUD_MEM_DCACHE_LINE_SIZE) : (_size))
// Declare an endpoint buffer with uint8_t[size] // Declare an endpoint buffer with uint8_t[size]
#define TUD_EPBUF_DEF(_name, _size) \ #define TUD_EPBUF_DEF(_name, _size) \
union { \ union { \
CFG_TUD_MEM_ALIGN uint8_t _name[_size]; \ CFG_TUD_MEM_ALIGN uint8_t _name[_size]; \
uint8_t _name##_dcache_padding[TUD_EPBUF_DCACHE_SIZE(_size)]; \ TU_ATTR_ALIGNED(TUD_EPBUF_DCACHE_ALIGNED ? CFG_TUD_MEM_DCACHE_LINE_SIZE : 1) uint8_t _name##_dcache_padding[TUD_EPBUF_DCACHE_SIZE(_size)]; \
} }
// Declare an endpoint buffer with a type // Declare an endpoint buffer with a type
#define TUD_EPBUF_TYPE_DEF(_type, _name) \ #define TUD_EPBUF_TYPE_DEF(_type, _name) \
union { \ union { \
CFG_TUD_MEM_ALIGN _type _name; \ CFG_TUD_MEM_ALIGN _type _name; \
uint8_t _name##_dcache_padding[TUD_EPBUF_DCACHE_SIZE(sizeof(_type))]; \ TU_ATTR_ALIGNED(TUD_EPBUF_DCACHE_ALIGNED ? CFG_TUD_MEM_DCACHE_LINE_SIZE : 1) uint8_t _name##_dcache_padding[TUD_EPBUF_DCACHE_SIZE(sizeof(_type))]; \
} }
//------------- Host DCache declaration -------------// //------------- Host DCache declaration -------------//
#define TUH_EPBUF_DCACHE_SIZE(_size) (CFG_TUH_MEM_DCACHE_ENABLE ? \ #define TUH_EPBUF_DCACHE_SIZE(_size) (TUH_EPBUF_DCACHE_ALIGNED ? \
(TU_DIV_CEIL(_size, CFG_TUH_MEM_DCACHE_LINE_SIZE) * CFG_TUH_MEM_DCACHE_LINE_SIZE) : (_size)) (TU_DIV_CEIL(_size, CFG_TUH_MEM_DCACHE_LINE_SIZE) * CFG_TUH_MEM_DCACHE_LINE_SIZE) : (_size))
// Declare an endpoint buffer with uint8_t[size] // Declare an endpoint buffer with uint8_t[size]
#define TUH_EPBUF_DEF(_name, _size) \ #define TUH_EPBUF_DEF(_name, _size) \
union { \ union { \
CFG_TUH_MEM_ALIGN uint8_t _name[_size]; \ CFG_TUH_MEM_ALIGN uint8_t _name[_size]; \
uint8_t _name##_dcache_padding[TUH_EPBUF_DCACHE_SIZE(_size)]; \ TU_ATTR_ALIGNED(TUH_EPBUF_DCACHE_ALIGNED ? CFG_TUH_MEM_DCACHE_LINE_SIZE : 1) uint8_t _name##_dcache_padding[TUH_EPBUF_DCACHE_SIZE(_size)]; \
} }
// Declare an endpoint buffer with a type // Declare an endpoint buffer with a type
#define TUH_EPBUF_TYPE_DEF(_type, _name) \ #define TUH_EPBUF_TYPE_DEF(_type, _name) \
union { \ union { \
CFG_TUH_MEM_ALIGN _type _name; \ CFG_TUH_MEM_ALIGN _type _name; \
uint8_t _name##_dcache_padding[TUH_EPBUF_DCACHE_SIZE(sizeof(_type))]; \ TU_ATTR_ALIGNED(TUH_EPBUF_DCACHE_ALIGNED ? CFG_TUH_MEM_DCACHE_LINE_SIZE : 1) uint8_t _name##_dcache_padding[TUH_EPBUF_DCACHE_SIZE(sizeof(_type))]; \
} }

View File

@@ -465,6 +465,13 @@
#define CFG_TUD_MEM_DCACHE_LINE_SIZE CFG_TUSB_MEM_DCACHE_LINE_SIZE #define CFG_TUD_MEM_DCACHE_LINE_SIZE CFG_TUSB_MEM_DCACHE_LINE_SIZE
#endif #endif
#if CFG_TUD_MEM_DCACHE_ENABLE && \
(CFG_TUD_DWC2_DMA_ENABLE || defined(TUP_USBIP_CHIPIDEA_HS))
#define TUD_EPBUF_DCACHE_ALIGNED 1
#else
#define TUD_EPBUF_DCACHE_ALIGNED 0
#endif
#ifndef CFG_TUD_ENDPOINT0_SIZE #ifndef CFG_TUD_ENDPOINT0_SIZE
#define CFG_TUD_ENDPOINT0_SIZE 64 #define CFG_TUD_ENDPOINT0_SIZE 64
#endif #endif
@@ -584,6 +591,13 @@
#define CFG_TUH_MEM_DCACHE_LINE_SIZE CFG_TUSB_MEM_DCACHE_LINE_SIZE #define CFG_TUH_MEM_DCACHE_LINE_SIZE CFG_TUSB_MEM_DCACHE_LINE_SIZE
#endif #endif
#if CFG_TUH_MEM_DCACHE_ENABLE && \
(CFG_TUH_DWC2_DMA_ENABLE || defined(TUP_USBIP_CHIPIDEA_HS))
#define TUH_EPBUF_DCACHE_ALIGNED 1
#else
#define TUH_EPBUF_DCACHE_ALIGNED 0
#endif
//------------- CLASS -------------// //------------- CLASS -------------//
#ifndef CFG_TUH_HUB #ifndef CFG_TUH_HUB