diff options
Diffstat (limited to 'os/common/oslib/include')
-rw-r--r-- | os/common/oslib/include/chfactory.h | 3 | ||||
-rw-r--r-- | os/common/oslib/include/chfifo.h | 12 | ||||
-rw-r--r-- | os/common/oslib/include/chmempools.h | 68 |
3 files changed, 64 insertions, 19 deletions
diff --git a/os/common/oslib/include/chfactory.h b/os/common/oslib/include/chfactory.h index 43b389cc4..e89d0814b 100644 --- a/os/common/oslib/include/chfactory.h +++ b/os/common/oslib/include/chfactory.h @@ -333,7 +333,8 @@ extern "C" { #if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__)
dyn_objects_fifo_t *chFactoryCreateObjectsFIFO(const char *name,
size_t objsize,
- size_t objn);
+ size_t objn,
+ unsigned objalign);
dyn_objects_fifo_t *chFactoryFindObjectsFIFO(const char *name);
void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp);
#endif
diff --git a/os/common/oslib/include/chfifo.h b/os/common/oslib/include/chfifo.h index 9f3c0924b..1df57ef41 100644 --- a/os/common/oslib/include/chfifo.h +++ b/os/common/oslib/include/chfifo.h @@ -110,22 +110,26 @@ extern "C" { /**
* @brief Initializes a FIFO object.
+ * @pre The messages size must be a multiple of the alignment
+ * requirement.
*
* @param[out] ofp pointer to a @p objects_fifo_t structure
* @param[in] objsize size of objects
* @param[in] objn number of objects available
+ * @param[in] objalign required objects alignment
* @param[in] objbuf pointer to the buffer of objects, it must be able
- * to hold @p objn objects of @p objsize size
+ * to hold @p objn objects of @p objsize size with
+ * @p objealign alignment
* @param[in] msgbuf pointer to the buffer of messages, it must be able
* to hold @p objn messages
*
* @init
*/
static inline void chFifoObjectInit(objects_fifo_t *ofp, size_t objsize,
- size_t objn, void *objbuf,
- msg_t *msgbuf) {
+ size_t objn, unsigned objalign,
+ void *objbuf, msg_t *msgbuf) {
- chGuardedPoolObjectInit(&ofp->free, objsize);
+ chGuardedPoolObjectInitAligned(&ofp->free, objsize, objalign);
chGuardedPoolLoadArray(&ofp->free, objbuf, objn);
chMBObjectInit(&ofp->mbx, msgbuf, objn);
}
diff --git a/os/common/oslib/include/chmempools.h b/os/common/oslib/include/chmempools.h index 25de236ce..0e9773374 100644 --- a/os/common/oslib/include/chmempools.h +++ b/os/common/oslib/include/chmempools.h @@ -69,6 +69,7 @@ typedef struct { struct pool_header *next; /**< @brief Pointer to the header. */
size_t object_size; /**< @brief Memory pool objects
size. */
+ unsigned align; /**< @brief Required alignment. */
memgetfunc_t provider; /**< @brief Memory blocks provider
for this pool. */
} memory_pool_t;
@@ -95,10 +96,11 @@ typedef struct { *
* @param[in] name the name of the memory pool variable
* @param[in] size size of the memory pool contained objects
+ * @param[in] align required memory alignment
* @param[in] provider memory provider function for the memory pool
*/
-#define _MEMORYPOOL_DATA(name, size, provider) \
- {NULL, size, provider}
+#define _MEMORYPOOL_DATA(name, size, align, provider) \
+ {NULL, size, align, provider}
/**
* @brief Static memory pool initializer.
@@ -107,11 +109,12 @@ typedef struct { *
* @param[in] name the name of the memory pool variable
* @param[in] size size of the memory pool contained objects
+ * @param[in] align required memory alignment
* @param[in] provider memory provider function for the memory pool or @p NULL
* if the pool is not allowed to grow automatically
*/
-#define MEMORYPOOL_DECL(name, size, provider) \
- memory_pool_t name = _MEMORYPOOL_DATA(name, size, provider)
+#define MEMORYPOOL_DECL(name, size, align, provider) \
+ memory_pool_t name = _MEMORYPOOL_DATA(name, size, align, provider)
#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
/**
@@ -121,10 +124,11 @@ typedef struct { *
* @param[in] name the name of the memory pool variable
* @param[in] size size of the memory pool contained objects
+ * @param[in] align required memory alignment
*/
-#define _GUARDEDMEMORYPOOL_DATA(name, size) { \
+#define _GUARDEDMEMORYPOOL_DATA(name, size, align) { \
_SEMAPHORE_DATA(name.sem, (cnt_t)0), \
- _MEMORYPOOL_DATA(NULL, size, NULL) \
+ _MEMORYPOOL_DATA(NULL, size, align, NULL) \
}
/**
@@ -134,9 +138,10 @@ typedef struct { *
* @param[in] name the name of the guarded memory pool variable
* @param[in] size size of the memory pool contained objects
+ * @param[in] align required memory alignment
*/
-#define GUARDEDMEMORYPOOL_DECL(name, size) \
- guarded_memory_pool_t name = _GUARDEDMEMORYPOOL_DATA(name, size)
+#define GUARDEDMEMORYPOOL_DECL(name, size, align) \
+ guarded_memory_pool_t name = _GUARDEDMEMORYPOOL_DATA(name, size, align)
#endif /* CH_CFG_USE_SEMAPHORES == TRUE */
/*===========================================================================*/
@@ -146,14 +151,17 @@ typedef struct { #ifdef __cplusplus
extern "C" {
#endif
- void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider);
+ void chPoolObjectInitAligned(memory_pool_t *mp, size_t size,
+ unsigned align, memgetfunc_t provider);
void chPoolLoadArray(memory_pool_t *mp, void *p, size_t n);
void *chPoolAllocI(memory_pool_t *mp);
void *chPoolAlloc(memory_pool_t *mp);
void chPoolFreeI(memory_pool_t *mp, void *objp);
void chPoolFree(memory_pool_t *mp, void *objp);
#if CH_CFG_USE_SEMAPHORES == TRUE
- void chGuardedPoolObjectInit(guarded_memory_pool_t *gmp, size_t size);
+ void chGuardedPoolObjectInitAligned(guarded_memory_pool_t *gmp,
+ size_t size,
+ unsigned align);
void chGuardedPoolLoadArray(guarded_memory_pool_t *gmp, void *p, size_t n);
void *chGuardedPoolAllocTimeoutS(guarded_memory_pool_t *gmp,
systime_t timeout);
@@ -171,6 +179,26 @@ extern "C" { /*===========================================================================*/
/**
+ * @brief Initializes an empty memory pool.
+ *
+ * @param[out] mp pointer to a @p memory_pool_t structure
+ * @param[in] size the size of the objects contained in this memory pool,
+ * the minimum accepted size is the size of a pointer to
+ * void.
+ * @param[in] provider memory provider function for the memory pool or
+ * @p NULL if the pool is not allowed to grow
+ * automatically
+ *
+ * @init
+ */
+static inline void chPoolObjectInit(memory_pool_t *mp,
+ size_t size,
+ memgetfunc_t provider) {
+
+ chPoolObjectInitAligned(mp, size, PORT_NATURAL_ALIGN, provider);
+}
+
+/**
* @brief Adds an object to a memory pool.
* @pre The memory pool must be already been initialized.
* @pre The added object must be of the right size for the specified
@@ -207,13 +235,27 @@ static inline void chPoolAdd(memory_pool_t *mp, void *objp) { */
static inline void chPoolAddI(memory_pool_t *mp, void *objp) {
- chDbgCheckClassI();
-
chPoolFreeI(mp, objp);
}
#if (CH_CFG_USE_SEMAPHORES == TRUE) || defined(__DOXYGEN__)
/**
+ * @brief Initializes an empty guarded memory pool.
+ *
+ * @param[out] gmp pointer to a @p guarded_memory_pool_t structure
+ * @param[in] size the size of the objects contained in this guarded
+ * memory pool, the minimum accepted size is the size
+ * of a pointer to void.
+ *
+ * @init
+ */
+static inline void chGuardedPoolObjectInit(guarded_memory_pool_t *gmp,
+ size_t size) {
+
+ chGuardedPoolObjectInitAligned(gmp, size, PORT_NATURAL_ALIGN);
+}
+
+/**
* @brief Adds an object to a guarded memory pool.
* @pre The guarded memory pool must be already been initialized.
* @pre The added object must be of the right size for the specified
@@ -248,8 +290,6 @@ static inline void chGuardedPoolAdd(guarded_memory_pool_t *gmp, void *objp) { */
static inline void chGuardedPoolAddI(guarded_memory_pool_t *gmp, void *objp) {
- chDbgCheckClassI();
-
chGuardedPoolFreeI(gmp, objp);
}
|