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 274 #if CH_CFG_FACTORY_PIPES == TRUE 279 #if (CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || defined(__DOXIGEN__) 356 while ((
void *)rop != (
void *)&ch_factory.
obj_list) {
357 if (rop->
objp == objp) {
388 dyn_release_object_pool(&rop->
element,
396 #if (CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || defined(__DOXIGEN__) 422 memset((
void *)dbp->
buffer, 0, size);
475 #if (CH_CFG_FACTORY_SEMAPHORES == TRUE) || defined(__DOXIGEN__) 548 dyn_release_object_pool(&dsp->
element,
556 #if (CH_CFG_FACTORY_MAILBOXES == TRUE) || defined(__DOXIGEN__) 580 (n *
sizeof (msg_t)));
636 #if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__) 667 (objn *
sizeof (msg_t)) +
726 #if (CH_CFG_FACTORY_PIPES == TRUE) || defined(__DOXIGEN__) 749 dpp = (
dyn_pipe_t *)dyn_create_object_heap(name,
Type of a dynamic buffer object.
void chHeapFree(void *p)
Frees a previously allocated memory block.
dyn_pipe_t * chFactoryFindPipe(const char *name)
Retrieves a dynamic pipe object.
void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp)
Releases a dynamic "objects FIFO" object.
void chFactoryReleaseObject(registered_object_t *rop)
Releases a registered object.
dyn_element_t element
List element of the dynamic pipe object.
mailbox_t mbx
The mailbox.
dyn_element_t element
List element of the dynamic buffer object.
uint8_t buffer[]
The buffer.
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_mailbox_t * chFactoryFindMailbox(const char *name)
Retrieves a dynamic mailbox object.
static void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider)
Initializes an empty memory pool.
dyn_objects_fifo_t * chFactoryCreateObjectsFIFO(const char *name, size_t objsize, size_t objn, unsigned objalign)
Creates a dynamic "objects FIFO" object.
struct ch_dyn_element * next
Next dynamic object in the list.
registered_object_t * chFactoryRegisterObject(const char *name, void *objp)
Registers a generic object.
void chMBObjectInit(mailbox_t *mbp, msg_t *buf, size_t n)
Initializes a mailbox_t object.
void chPoolFree(memory_pool_t *mp, void *objp)
Releases an object into a memory pool.
Type of a dynamic object list element.
uint8_t buffer[]
Messages buffer.
semaphore_t sem
The semaphore.
dyn_objects_fifo_t * chFactoryFindObjectsFIFO(const char *name)
Retrieves a dynamic "objects FIFO" object.
void chFactoryReleaseMailbox(dyn_mailbox_t *dmp)
Releases a dynamic mailbox object.
void chFactoryReleasePipe(dyn_pipe_t *dpp)
Releases a dynamic pipe object.
Type of a dynamic buffer object.
void chFactoryReleaseSemaphore(dyn_semaphore_t *dsp)
Releases a dynamic semaphore object.
dyn_element_t element
List element of the dynamic semaphore.
#define chDbgCheck(c)
Function parameters check.
msg_t msgbuf[]
Messages buffer.
dyn_element_t element
List element of the dynamic buffer object.
Type of a dynamic semaphore.
msg_t msgbuf[]
Messages buffer.
memory_pool_t sem_pool
Pool of the available semaphores.
static void chFifoObjectInitAligned(objects_fifo_t *ofp, size_t objsize, size_t objn, unsigned objalign, void *objbuf, msg_t *msgbuf)
Initializes a FIFO object.
Type of a registered object.
void * chPoolAlloc(memory_pool_t *mp)
Allocates an object from a memory pool.
dyn_buffer_t * chFactoryFindBuffer(const char *name)
Retrieves a dynamic buffer object.
void chFactoryReleaseBuffer(dyn_buffer_t *dbp)
Releases a dynamic buffer object.
ucnt_t refs
Number of references to this object.
mutex_t mtx
Factory access mutex or semaphore.
dyn_list_t buf_list
List of the allocated buffer objects.
void chSemObjectInit(semaphore_t *sp, cnt_t n)
Initializes a semaphore with the specified counter value.
registered_object_t * chFactoryFindObjectByPointer(void *objp)
Retrieves a registered object by pointer.
Type of a dynamic pipe object.
dyn_list_t sem_list
List of the allocated semaphores.
dyn_buffer_t * chFactoryCreateBuffer(const char *name, size_t size)
Creates a generic dynamic buffer object.
dyn_mailbox_t * chFactoryCreateMailbox(const char *name, size_t n)
Creates a dynamic mailbox object.
objects_factory_t ch_factory
Factory object static instance.
dyn_list_t obj_list
List of the registered objects.
void * objp
Pointer to the object.
registered_object_t * chFactoryFindObject(const char *name)
Retrieves a registered object.
dyn_list_t pipe_list
List of the allocated pipe objects.
memory_pool_t obj_pool
Pool of the available registered objects.
#define chDbgAssert(c, r)
Condition assertion.
dyn_element_t element
List element of the dynamic buffer object.
void chMtxObjectInit(mutex_t *mp)
Initializes s mutex_t structure.
dyn_semaphore_t * chFactoryCreateSemaphore(const char *name, cnt_t n)
Creates a dynamic semaphore object.
Type of a dynamic buffer object.
void chPipeObjectInit(pipe_t *pp, uint8_t *buf, size_t n)
Initializes a mailbox_t object.
void _factory_init(void)
Initializes the objects factory.
ChibiOS/RT main include file.
dyn_element_t element
List element of the registered object.
objects_fifo_t fifo
The objects FIFO.
dyn_semaphore_t * chFactoryFindSemaphore(const char *name)
Retrieves a dynamic semaphore object.
dyn_list_t fifo_list
List of the allocated "objects FIFO" objects.
Type of the factory main object.
dyn_list_t mbx_list
List of the allocated buffer objects.
dyn_pipe_t * chFactoryCreatePipe(const char *name, size_t size)
Creates a dynamic pipe object.
#define CH_CFG_FACTORY_MAX_NAMES_LENGTH
Maximum length for object names.
Type of a dynamic object list.
static void * chCoreAllocAlignedI(size_t size, unsigned align)
Allocates a memory block.