46 #if (CH_CFG_USE_FACTORY == TRUE) || defined(__DOXYGEN__) 55 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) 56 #define F_LOCK() chMtxLock(&ch_factory.mtx) 57 #define F_UNLOCK() chMtxUnlock(&ch_factory.mtx) 59 #define F_LOCK() (void) chSemWait(&ch_factory.sem) 60 #define F_UNLOCK() chSemSignal(&ch_factory.sem) 86 static inline void dyn_list_init(
dyn_list_t *dlp) {
110 if (prev->
next == element) {
123 #if CH_FACTORY_REQUIRES_HEAP || defined(__DOXYGEN__) 124 static dyn_element_t *dyn_create_object_heap(
const char *name,
132 dep = dyn_list_find(name, dlp);
148 dep->
refs = (ucnt_t)1;
149 dep->
next = dlp->next;
165 if (dep->
refs == (ucnt_t)0) {
166 dep = dyn_list_unlink(dep, dlp);
172 #if CH_FACTORY_REQUIRES_POOLS || defined(__DOXYGEN__) 173 static dyn_element_t *dyn_create_object_pool(
const char *name,
181 dep = dyn_list_find(name, dlp);
197 dep->
refs = (ucnt_t)1;
198 dep->
next = dlp->next;
214 if (dep->
refs == (ucnt_t)0) {
215 dep = dyn_list_unlink(dep, dlp);
227 dep = dyn_list_find(name, dlp);
247 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) 253 #if CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE 254 dyn_list_init(&ch_factory.
obj_list);
259 #if CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE 260 dyn_list_init(&ch_factory.
buf_list);
262 #if CH_CFG_FACTORY_SEMAPHORES == TRUE 263 dyn_list_init(&ch_factory.
sem_list);
268 #if CH_CFG_FACTORY_MAILBOXES == TRUE 269 dyn_list_init(&ch_factory.
mbx_list);
271 #if CH_CFG_FACTORY_OBJ_FIFOS == TRUE 276 #if (CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || defined(__DOXIGEN__) 353 while ((
void *)rop != (
void *)&ch_factory.
obj_list) {
354 if (rop->
objp == objp) {
385 dyn_release_object_pool(&rop->
element,
393 #if (CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || defined(__DOXIGEN__) 419 memset((
void *)dbp->
buffer, 0, size);
472 #if (CH_CFG_FACTORY_SEMAPHORES == TRUE) || defined(__DOXIGEN__) 545 dyn_release_object_pool(&dsp->
element,
553 #if (CH_CFG_FACTORY_MAILBOXES == TRUE) || defined(__DOXIGEN__) 577 (n *
sizeof (msg_t)));
633 #if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__) 664 (objn *
sizeof (msg_t)) +
Type of a dynamic buffer object.
static void chFifoObjectInit(objects_fifo_t *ofp, size_t objsize, size_t objn, unsigned objalign, void *objbuf, msg_t *msgbuf)
Initializes a FIFO object.
mailbox_t mbx
The mailbox.
static void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider)
Initializes an empty memory pool.
dyn_element_t element
List element of the dynamic buffer object.
void chPoolFree(memory_pool_t *mp, void *objp)
Releases an object into a memory pool.
uint8_t buffer[]
The buffer.
void _factory_init(void)
Initializes the objects factory.
struct ch_dyn_element * next
Next dynamic object in the list.
Type of a dynamic object list element.
void chFactoryReleaseSemaphore(dyn_semaphore_t *dsp)
Releases a dynamic semaphore object.
registered_object_t * chFactoryFindObject(const char *name)
Retrieves a registered object.
void chHeapFree(void *p)
Frees a previously allocated memory block.
semaphore_t sem
The semaphore.
Type of a dynamic buffer object.
dyn_element_t element
List element of the dynamic semaphore.
dyn_mailbox_t * chFactoryCreateMailbox(const char *name, size_t n)
Creates a dynamic mailbox object.
void * chPoolAlloc(memory_pool_t *mp)
Allocates an object from a memory pool.
msg_t msgbuf[]
Messages buffer.
dyn_element_t element
List element of the dynamic buffer object.
void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp)
Releases a dynamic "objects FIFO" object.
Type of a dynamic semaphore.
msg_t msgbuf[]
Messages buffer.
#define chDbgCheck(c)
Function parameters check.
dyn_mailbox_t * chFactoryFindMailbox(const char *name)
Retrieves a dynamic mailbox object.
memory_pool_t sem_pool
Pool of the available semaphores.
Type of a registered object.
dyn_buffer_t * chFactoryCreateBuffer(const char *name, size_t size)
Creates a generic dynamic buffer object.
registered_object_t * chFactoryRegisterObject(const char *name, void *objp)
Registers a generic object.
ucnt_t refs
Number of references to this object.
#define chDbgAssert(c, r)
Condition assertion.
mutex_t mtx
Factory access mutex or semaphore.
dyn_list_t buf_list
List of the allocated buffer objects.
registered_object_t * chFactoryFindObjectByPointer(void *objp)
Retrieves a registered object by pointer.
void chSemObjectInit(semaphore_t *sp, cnt_t n)
Initializes a semaphore with the specified counter value.
dyn_list_t sem_list
List of the allocated semaphores.
dyn_semaphore_t * chFactoryCreateSemaphore(const char *name, cnt_t n)
Creates a dynamic semaphore object.
static void * chHeapAlloc(memory_heap_t *heapp, size_t size)
Allocates a block of memory from the heap by using the first-fit algorithm.
dyn_objects_fifo_t * chFactoryCreateObjectsFIFO(const char *name, size_t objsize, size_t objn, unsigned objalign)
Creates a dynamic "objects FIFO" object.
void chFactoryReleaseBuffer(dyn_buffer_t *dbp)
Releases a dynamic buffer object.
dyn_list_t obj_list
List of the registered objects.
void * objp
Pointer to the object.
dyn_semaphore_t * chFactoryFindSemaphore(const char *name)
Retrieves a dynamic semaphore object.
memory_pool_t obj_pool
Pool of the available registered objects.
dyn_element_t element
List element of the dynamic buffer object.
void chFactoryReleaseMailbox(dyn_mailbox_t *dmp)
Releases a dynamic mailbox object.
dyn_buffer_t * chFactoryFindBuffer(const char *name)
Retrieves a dynamic buffer object.
void chMtxObjectInit(mutex_t *mp)
Initializes s mutex_t structure.
Type of a dynamic buffer object.
ChibiOS/RT main include file.
dyn_element_t element
List element of the registered object.
objects_fifo_t fifo
The objects FIFO.
static void * chCoreAllocAlignedI(size_t size, unsigned align)
Allocates a memory block.
dyn_objects_fifo_t * chFactoryFindObjectsFIFO(const char *name)
Retrieves a dynamic "objects FIFO" object.
void chFactoryReleaseObject(registered_object_t *rop)
Releases a registered object.
objects_factory_t ch_factory
Factory object static instance.
dyn_list_t fifo_list
List of the allocated "objects FIFO" objects.
Type of the factory main object.
void chMBObjectInit(mailbox_t *mbp, msg_t *buf, size_t n)
Initializes a mailbox_t object.
dyn_list_t mbx_list
List of the allocated buffer objects.
#define CH_CFG_FACTORY_MAX_NAMES_LENGTH
Maximum length for object names.
Type of a dynamic object list.