modules: Use common alignment macros.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2025-07-16 10:13:39 +02:00
parent 8df82bdc00
commit 678be91f39
3 changed files with 7 additions and 21 deletions

View File

@ -81,7 +81,7 @@ static soft_timer_entry_t flir_lepton_spi_rx_timer = {};
static int fir_lepton_spi_rx_cb_tail = 0;
static int fir_lepton_spi_rx_cb_expected_pid = 0;
static int fir_lepton_spi_rx_cb_expected_sid = 0;
static uint16_t OMV_ATTR_SECTION(OMV_ATTR_ALIGNED_DMA(fir_lepton_buf[VOSPI_BUFFER_SIZE]), OMV_VOSPI_DMA_BUFFER);
static uint16_t OMV_ATTR_SEC_ALIGN(fir_lepton_buf[VOSPI_BUFFER_SIZE], OMV_VOSPI_DMA_BUFFER, OMV_DMA_ALIGNMENT);
static void fir_lepton_spi_callback(omv_spi_t *spi, void *userdata, void *buf);
static mp_obj_t fir_lepton_spi_resync_callback(mp_obj_t unused) {

View File

@ -56,20 +56,12 @@
#define RGB565_FIXED_VER 11
#define NEW_PIXFORMAT_VER 20
#ifndef __DCACHE_PRESENT
#define IMAGE_ALIGNMENT 32 // Use 32-byte alignment on MCUs with no cache for DMA buffer alignment.
#else
#define IMAGE_ALIGNMENT __SCB_DCACHE_LINE_SIZE
#endif
#define IMAGE_ALIGNMENT OMV_CACHE_LINE_SIZE
#define IMAGE_T_SIZE_ALIGNED (((sizeof(uint32_t) + sizeof(image_t) + (IMAGE_ALIGNMENT) -1) \
/ (IMAGE_ALIGNMENT)) \
* (IMAGE_ALIGNMENT))
static size_t image_size_aligned(image_t *image) {
return ((image_size(image) + (IMAGE_ALIGNMENT) -1) / (IMAGE_ALIGNMENT)) * (IMAGE_ALIGNMENT);
}
typedef enum image_io_stream_type {
IMAGE_IO_FILE_STREAM,
IMAGE_IO_MEMORY_STREAM,
@ -579,7 +571,7 @@ static mp_obj_t py_imageio_make_new(const mp_obj_type_t *type, size_t n_args, si
}
stream->count = mp_obj_get_int(args[1]);
stream->size = IMAGE_T_SIZE_ALIGNED + image_size_aligned(&image);
stream->size = IMAGE_T_SIZE_ALIGNED + OMV_ALIGN_TO(image_size(&image), IMAGE_ALIGNMENT);
fb_alloc_mark();
stream->buffer = fb_alloc(stream->count * stream->size, FB_ALLOC_PREFER_SIZE | FB_ALLOC_CACHE_ALIGN);

View File

@ -51,13 +51,7 @@
#include "py_ml.h"
#include "ulab/code/ndarray.h"
#ifndef IMLIB_ML_MODEL_ALIGN
#ifndef __DCACHE_PRESENT
#define IMLIB_ML_MODEL_ALIGN (32 - 1)
#else
#define IMLIB_ML_MODEL_ALIGN (__SCB_DCACHE_LINE_SIZE - 1)
#endif
#endif
#define IMLIB_ML_MODEL_ALIGN (OMV_CACHE_LINE_SIZE)
static size_t py_ml_tuple_sum(mp_obj_tuple_t *o) {
if (o->len < 1) {
@ -372,9 +366,9 @@ mp_obj_t py_ml_model_make_new(const mp_obj_type_t *type, size_t n_args, size_t n
fb_alloc_mark_permanent();
} else {
// Align size and memory and keep a reference to the GC block.
size_t size = (model->size + IMLIB_ML_MODEL_ALIGN) & ~IMLIB_ML_MODEL_ALIGN;
model->_raw = m_malloc(size + IMLIB_ML_MODEL_ALIGN);
model->data = (void *) (((uintptr_t) model->_raw + IMLIB_ML_MODEL_ALIGN) & ~IMLIB_ML_MODEL_ALIGN);
size_t size = OMV_ALIGN_TO(model->size, IMLIB_ML_MODEL_ALIGN);
model->_raw = m_malloc(size + IMLIB_ML_MODEL_ALIGN - 1);
model->data = (void *) OMV_ALIGN_TO(model->_raw, IMLIB_ML_MODEL_ALIGN);
}
// Read file data.