common: Add common align and section align macro.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2025-07-16 10:05:45 +02:00
parent fc9a6cd6c8
commit a9d6567a18
4 changed files with 23 additions and 13 deletions

View File

@ -39,14 +39,14 @@ static uint32_t alloc_bytes_peak;
#endif
#if defined(OMV_FB_OVERLAY_MEMORY)
#define FB_OVERLAY_MEMORY_FLAG 0x1
#define FB_OVERLAY_MEMORY_FLAG 0x1
extern char _fballoc_overlay_end, _fballoc_overlay_start;
static char *pointer_overlay = &_fballoc_overlay_end;
#endif
// fb_alloc_free_till_mark() will not free past this.
// Use fb_alloc_free_till_mark_permanent() instead.
#define FB_PERMANENT_FLAG 0x2
#define FB_PERMANENT_FLAG 0x2
char *fb_alloc_stack_pointer() {
return pointer;
@ -146,7 +146,7 @@ void *fb_alloc(uint32_t size, int hints) {
size = ((size + sizeof(uint32_t) - 1) / sizeof(uint32_t)) * sizeof(uint32_t); // Round Up
if (hints & FB_ALLOC_CACHE_ALIGN) {
size = ((size + OMV_ALLOC_ALIGNMENT - 1) / OMV_ALLOC_ALIGNMENT) * OMV_ALLOC_ALIGNMENT;
size = OMV_ALIGN_TO(size, OMV_ALLOC_ALIGNMENT);
size += OMV_ALLOC_ALIGNMENT - sizeof(uint32_t);
}

View File

@ -30,6 +30,11 @@
#define FB_ALLOC_PREFER_SPEED 1
#define FB_ALLOC_PREFER_SIZE 2
#define FB_ALLOC_CACHE_ALIGN 4
#ifndef OMV_ALLOC_ALIGNMENT
#define OMV_ALLOC_ALIGNMENT (OMV_CACHE_LINE_SIZE)
#endif
char *fb_alloc_stack_pointer();
void fb_alloc_fail();
void fb_alloc_init0();

View File

@ -26,20 +26,25 @@
#ifndef __OMV_COMMON_H__
#define __OMV_COMMON_H__
#define OMV_ATTR_ALIGNED(x, a) x __attribute__((aligned(a)))
#define OMV_ATTR_SECTION(x, s) x __attribute__((section(s)))
#define OMV_ATTR_ALWAYS_INLINE inline __attribute__((always_inline))
#define OMV_ATTR_OPTIMIZE(o) __attribute__((optimize(o)))
#define OMV_BREAK() __asm__ volatile ("BKPT")
#define OMV_ATTR_ALIGNED(x, a) x __attribute__((aligned(a)))
#define OMV_ATTR_SECTION(x, s) x __attribute__((section(s)))
#define OMV_ATTR_ALWAYS_INLINE inline __attribute__((always_inline))
#define OMV_ATTR_OPTIMIZE(o) __attribute__((optimize(o)))
#define OMV_ATTR_SEC_ALIGN(x, s, a) x __attribute__((section(s), aligned(a)))
#define OMV_DEBUG_BREAKPOINT() __asm__ volatile ("BKPT")
// Use 32-byte alignment on MCUs with no cache for DMA buffer alignment.
#ifndef __DCACHE_PRESENT
#define OMV_ALLOC_ALIGNMENT (32)
#define OMV_CACHE_LINE_SIZE (32)
#else
#define OMV_ALLOC_ALIGNMENT (__SCB_DCACHE_LINE_SIZE)
#define OMV_CACHE_LINE_SIZE (__SCB_DCACHE_LINE_SIZE)
#endif
#define OMV_ATTR_ALIGNED_DMA(x) OMV_ATTR_ALIGNED(x, OMV_ALLOC_ALIGNMENT)
#ifndef OMV_DMA_ALIGNMENT
#define OMV_DMA_ALIGNMENT (OMV_CACHE_LINE_SIZE)
#endif
#define OMV_ALIGN_TO(x, alignment) \
((((uintptr_t)(x)) + (alignment) - 1) & ~((uintptr_t)((alignment) - 1)))
#ifdef OMV_DEBUG_PRINTF
#define debug_printf(fmt, ...) \

View File

@ -68,7 +68,7 @@ typedef struct _vospi_state {
static vospi_state_t vospi;
static uint16_t OMV_ATTR_SECTION(OMV_ATTR_ALIGNED_DMA(vospi_buf[VOSPI_BUFFER_SIZE]), OMV_VOSPI_DMA_BUFFER);
static uint16_t OMV_ATTR_SEC_ALIGN(vospi_buf[VOSPI_BUFFER_SIZE], OMV_VOSPI_DMA_BUFFER, OMV_DMA_ALIGNMENT);
static void vospi_callback(omv_spi_t *spi, void *userdata, void *buf);
static void vospi_resync() {