diff --git a/os/kernel/include/chmemcore.h b/os/kernel/include/chmemcore.h index f42478125..58cb318b2 100644 --- a/os/kernel/include/chmemcore.h +++ b/os/kernel/include/chmemcore.h @@ -35,15 +35,25 @@ */ typedef void *(*memgetfunc_t)(size_t size); +/** + * @brief Alignment size constant. + */ +#define MEM_ALIGN_SIZE sizeof(stkalign_t) + /** * @brief Alignment mask constant. */ -#define MEM_ALIGN_MASK (sizeof(stkalign_t) - 1) +#define MEM_ALIGN_MASK (MEM_ALIGN_SIZE - 1) /** * @brief Alignment helper macro. */ -#define MEM_ALIGN_SIZE(p) (((size_t)(p) + MEM_ALIGN_MASK) & ~MEM_ALIGN_MASK) +#define MEM_ALIGN_PREV(p) ((size_t)(p) & ~MEM_ALIGN_MASK) + +/** + * @brief Alignment helper macro. + */ +#define MEM_ALIGN_NEXT(p) MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK) /** * @brief Returns whatever a pointer or memory size is aligned to diff --git a/os/kernel/include/chmempools.h b/os/kernel/include/chmempools.h index 1c2e2aa70..9dbe332c8 100644 --- a/os/kernel/include/chmempools.h +++ b/os/kernel/include/chmempools.h @@ -59,7 +59,7 @@ typedef struct { * @param[in] provider memory provider function for the memory pool */ #define _MEMORYPOOL_DATA(name, size, provider) \ - {NULL, MEM_ALIGN_SIZE(size), provider} + {NULL, MEM_ALIGN_NEXT(size), provider} /** * @brief Static memory pool initializer in hungry mode. diff --git a/os/kernel/src/chheap.c b/os/kernel/src/chheap.c index 13db7cf6b..c655e3852 100644 --- a/os/kernel/src/chheap.c +++ b/os/kernel/src/chheap.c @@ -125,7 +125,7 @@ void *chHeapAlloc(MemoryHeap *heapp, size_t size) { if (heapp == NULL) heapp = &default_heap; - size = MEM_ALIGN_SIZE(size); + size = MEM_ALIGN_NEXT(size); qp = &heapp->h_free; H_LOCK(heapp); diff --git a/os/kernel/src/chmemcore.c b/os/kernel/src/chmemcore.c index 69d3014a5..1fed481c5 100644 --- a/os/kernel/src/chmemcore.c +++ b/os/kernel/src/chmemcore.c @@ -24,18 +24,20 @@ * @addtogroup memcore * @details Core Memory Manager related APIs and services. *
sizeof(stkalign_t)
.
+ * type so it is not possible to allocate less
+ * than MEM_ALIGN_SIZE
.
*
* @param[in] size the size of the block to be allocated
* @return A pointer to the allocated memory block.
@@ -92,8 +92,8 @@ void *chCoreAlloc(size_t size) {
/**
* @brief Allocates a memory block.
* @details The size of the returned block is aligned to the alignment
- * type @p align_t so it is not possible to allocate less than
- * sizeof(align_t)
.
+ * type so it is not possible to allocate less than
+ * MEM_ALIGN_SIZE
.
*
* @param[in] size the size of the block to be allocated.
* @return A pointer to the allocated memory block.
@@ -104,7 +104,7 @@ void *chCoreAlloc(size_t size) {
void *chCoreAllocI(size_t size) {
void *p;
- size = MEM_ALIGN_SIZE(size);
+ size = MEM_ALIGN_NEXT(size);
if ((size_t)(endmem - nextmem) < size)
return NULL;
p = nextmem;
diff --git a/os/kernel/src/chmempools.c b/os/kernel/src/chmempools.c
index 054823af0..83e6366f4 100644
--- a/os/kernel/src/chmempools.c
+++ b/os/kernel/src/chmempools.c
@@ -55,7 +55,7 @@ void chPoolInit(MemoryPool *mp, size_t size, memgetfunc_t provider) {
chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit");
mp->mp_next = NULL;
- mp->mp_object_size = MEM_ALIGN_SIZE(size);
+ mp->mp_object_size = MEM_ALIGN_NEXT(size);
mp->mp_provider = provider;
}
diff --git a/readme.txt b/readme.txt
index 3d91239d1..8516b1c41 100644
--- a/readme.txt
+++ b/readme.txt
@@ -69,8 +69,13 @@
*****************************************************************************
*** 2.3.0 ***
+- FIX: Fixed Cortex-Mx linker scripts alignment of __heap_base__, the
+ correct alignment is now enforced at runtime into core_init() in order
+ to make the OS integration easier (bug 3191112)(backported to 2.2.2).
+- FIX: Fixed error in function chCoreAllocI() function documentation (bug
+ 3191107)(backported to 2.2.2).
- FIX: Fixed minor problem with memory pools (bug 3190512)(backported to
- 2.2.1).
+ 2.2.2).
- FIX: Stack overflow in CM0 ports when nearing interrupts saturation (bug
3187105)(backported to 2.2.1).
- FIX: Fixed error in _BSEMAPHORE_DATA macro (bug 3184139)(backported to
diff --git a/todo.txt b/todo.txt
index 44c0c464f..90d631345 100644
--- a/todo.txt
+++ b/todo.txt
@@ -37,7 +37,7 @@ X Transactional flash file system implementation.
X I2C device driver class support and at least one implementation.
X Shared DMA channels support in the STM32/STM8L HALs.
X RAM ISR vectors support in the STM32 HAL.
-X New device driver models: Clock, Systick, RTC, WDG, DAC, Power Monitor.
+X New device driver models: Clock, Systick, PT, RTC, WDG, DAC, Power Monitor.
Later but within 2.x.x
- Batch testing of the ARM7/ARMCMx port using OpenOCD, with reports.