Added pools to CMSIS RTOS.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7381 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
66ff6722d2
commit
dad8b482d9
|
@ -30,6 +30,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module local definitions. */
|
/* Module local definitions. */
|
||||||
|
@ -421,4 +422,53 @@ osStatus osMutexDelete (osMutexId mutex_id) {
|
||||||
return osOK;
|
return osOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a memory pool.
|
||||||
|
* @note The pool is not really created because it is allocated statically,
|
||||||
|
* this function just re-initializes it.
|
||||||
|
*/
|
||||||
|
osPoolId osPoolCreate (const osPoolDef_t *pool_def) {
|
||||||
|
|
||||||
|
chPoolObjectInit(pool_def->pool, (size_t)pool_def->item_sz, NULL);
|
||||||
|
chPoolLoadArray(pool_def->pool, pool_def->items, (size_t)pool_def->pool_sz);
|
||||||
|
|
||||||
|
return (osPoolId)pool_def->pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocate an object.
|
||||||
|
*/
|
||||||
|
void *osPoolAlloc (osPoolId pool_id) {
|
||||||
|
void *object;
|
||||||
|
|
||||||
|
syssts_t sts = chSysGetStatusAndLockX();
|
||||||
|
object = chPoolAllocI((memory_pool_t *)pool_id);
|
||||||
|
chSysRestoreStatusX(sts);
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocate an object clearing it.
|
||||||
|
*/
|
||||||
|
void *osPoolCAlloc (osPoolId pool_id) {
|
||||||
|
void *object;
|
||||||
|
|
||||||
|
object = chPoolAllocI((memory_pool_t *)pool_id);
|
||||||
|
memset(object, 0, pool_id->mp_object_size);
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Free an object.
|
||||||
|
*/
|
||||||
|
osStatus osPoolFree (osPoolId pool_id, void *block) {
|
||||||
|
|
||||||
|
syssts_t sts = chSysGetStatusAndLockX();
|
||||||
|
chPoolFreeI((memory_pool_t *)pool_id, block);
|
||||||
|
chSysRestoreStatusX(sts);
|
||||||
|
|
||||||
|
return osOK;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define osFeature_MainThread 1
|
#define osFeature_MainThread 1
|
||||||
#define osFeature_Pool 0
|
#define osFeature_Pool 1
|
||||||
#define osFeature_MailQ 0
|
#define osFeature_MailQ 0
|
||||||
#define osFeature_MessageQ 0
|
#define osFeature_MessageQ 0
|
||||||
#define osFeature_Signals 31
|
#define osFeature_Signals 31
|
||||||
|
@ -211,6 +211,11 @@ typedef binary_semaphore_t *osMutexId;
|
||||||
*/
|
*/
|
||||||
typedef semaphore_t *osSemaphoreId;
|
typedef semaphore_t *osSemaphoreId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of pointer to memory pool control block.
|
||||||
|
*/
|
||||||
|
typedef memory_pool_t *osPoolId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of an event.
|
* @brief Type of an event.
|
||||||
*/
|
*/
|
||||||
|
@ -221,10 +226,10 @@ typedef struct {
|
||||||
void *p;
|
void *p;
|
||||||
int32_t signals;
|
int32_t signals;
|
||||||
} value;
|
} value;
|
||||||
/* union {
|
union {
|
||||||
osMailQId mail_id;
|
/* osMailQId mail_id;*/
|
||||||
osMessageQId message_id;
|
osMessageQId message_id;
|
||||||
} def;*/
|
} def;
|
||||||
} osEvent;
|
} osEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -257,6 +262,16 @@ typedef struct os_semaphore_def {
|
||||||
uint32_t dummy;
|
uint32_t dummy;
|
||||||
} osSemaphoreDef_t;
|
} osSemaphoreDef_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of a memory pool definition block.
|
||||||
|
*/
|
||||||
|
typedef struct os_pool_def {
|
||||||
|
uint32_t pool_sz;
|
||||||
|
uint32_t item_sz;
|
||||||
|
memory_pool_t *pool;
|
||||||
|
void *items;
|
||||||
|
} osPoolDef_t;
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Module macros. */
|
/* Module macros. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -336,6 +351,29 @@ const osTimerDef_t os_timer_def_##name = { \
|
||||||
*/
|
*/
|
||||||
#define osSemaphore(name) &os_semaphore_def_##name
|
#define osSemaphore(name) &os_semaphore_def_##name
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Define a Memory Pool.
|
||||||
|
*/
|
||||||
|
#if defined(osObjectsExternal)
|
||||||
|
#define osPoolDef(name, no, type) \
|
||||||
|
extern const osPoolDef_t os_pool_def_##name
|
||||||
|
#else
|
||||||
|
#define osPoolDef(name, no, type) \
|
||||||
|
static const type os_pool_buf_##name[no]; \
|
||||||
|
static memory_pool_t os_pool_obj_##name; \
|
||||||
|
const osPoolDef_t os_pool_def_##name = { \
|
||||||
|
(no), \
|
||||||
|
sizeof (type), \
|
||||||
|
(void *)&os_pool_obj_##name, \
|
||||||
|
(void *)&os_pool_buf_##name[0] \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Access a Memory Pool definition.
|
||||||
|
*/
|
||||||
|
#define osPool(name) &os_pool_def_##name
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* External declarations. */
|
/* External declarations. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -369,6 +407,10 @@ extern "C" {
|
||||||
osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
|
osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
|
||||||
osStatus osMutexRelease (osMutexId mutex_id);
|
osStatus osMutexRelease (osMutexId mutex_id);
|
||||||
osStatus osMutexDelete (osMutexId mutex_id);
|
osStatus osMutexDelete (osMutexId mutex_id);
|
||||||
|
osPoolId osPoolCreate (const osPoolDef_t *pool_def);
|
||||||
|
void *osPoolAlloc (osPoolId pool_id);
|
||||||
|
void *osPoolCAlloc (osPoolId pool_id);
|
||||||
|
osStatus osPoolFree (osPoolId pool_id, void *block);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue