aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2017-10-03 13:47:17 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2017-10-03 13:47:17 +0000
commit5e48932850f78d3c3fc90ae73982f1ce5ba21e38 (patch)
treedadfd0381ae0974cc6ed632ea7001410fcecdc10 /os
parent4d364b8aba9b23c25126d24ee9ae9c791b83f970 (diff)
downloadChibiOS-5e48932850f78d3c3fc90ae73982f1ce5ba21e38.tar.gz
ChibiOS-5e48932850f78d3c3fc90ae73982f1ce5ba21e38.tar.bz2
ChibiOS-5e48932850f78d3c3fc90ae73982f1ce5ba21e38.zip
Objects FIFOs added to the factory.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10754 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/common/oslib/include/chfactory.h54
-rw-r--r--os/common/oslib/include/chfifo.h8
-rw-r--r--os/common/oslib/src/chfactory.c94
3 files changed, 147 insertions, 9 deletions
diff --git a/os/common/oslib/include/chfactory.h b/os/common/oslib/include/chfactory.h
index acb8c79a4..43b389cc4 100644
--- a/os/common/oslib/include/chfactory.h
+++ b/os/common/oslib/include/chfactory.h
@@ -79,6 +79,13 @@
#define CH_CFG_FACTORY_MAILBOXES TRUE
#endif
+/**
+ * @brief Enables factory for objects FIFOs.
+ */
+#if !defined(CH_CFG_FACTORY_OBJ_FIFOS) || defined(__DOXYGEN__)
+#define CH_CFG_FACTORY_OBJ_FIFOS TRUE
+#endif
+
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
@@ -88,7 +95,8 @@
#define CH_FACTORY_REQUIRES_HEAP \
((CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || \
- (CH_CFG_FACTORY_MAILBOXES == TRUE))
+ (CH_CFG_FACTORY_MAILBOXES == TRUE) || \
+ (CH_CFG_FACTORY_OBJ_FIFOS == TRUE))
#if (CH_CFG_FACTORY_MAX_NAMES_LENGHT < 0) || \
(CH_CFG_FACTORY_MAX_NAMES_LENGHT > 32)
@@ -115,6 +123,10 @@
#error "CH_CFG_FACTORY_MAILBOXES requires CH_CFG_USE_MAILBOXES"
#endif
+#if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) && (CH_CFG_USE_OBJ_FIFOS == FALSE)
+#error "CH_CFG_FACTORY_OBJ_FIFOS requires CH_CFG_USE_OBJ_FIFOS"
+#endif
+
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
@@ -209,13 +221,36 @@ typedef struct ch_dyn_mailbox {
*/
mailbox_t mbx;
/**
- * @brief Mailbox buffer.
+ * @brief Messages buffer.
* @note This requires C99.
*/
- msg_t buffer[];
+ msg_t msgbuf[];
} dyn_mailbox_t;
#endif
+#if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__)
+/**
+ * @brief Type of a dynamic buffer object.
+ */
+typedef struct ch_dyn_objects_fifo {
+ /**
+ * @brief List element of the dynamic buffer object.
+ */
+ dyn_element_t element;
+ /**
+ * @brief The objects FIFO.
+ */
+ objects_fifo_t fifo;
+ /**
+ * @brief Messages buffer.
+ * @note This open array is followed by another area containing the
+ * objects, this area is not represented in this structure.
+ * @note This requires C99.
+ */
+ msg_t msgbuf[];
+} dyn_objects_fifo_t;
+#endif
+
/**
* @brief Type of the factory main object.
*/
@@ -250,6 +285,12 @@ typedef struct ch_objects_factory {
*/
dyn_list_t mbx_list;
#endif /* CH_CFG_FACTORY_MAILBOXES = TRUE */
+#if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__)
+ /**
+ * @brief List of the allocated "objects FIFO" objects.
+ */
+ dyn_list_t fifo_list;
+#endif /* CH_CFG_FACTORY_OBJ_FIFOS = TRUE */
} objects_factory_t;
/*===========================================================================*/
@@ -289,6 +330,13 @@ extern "C" {
dyn_mailbox_t *chFactoryFindMailbox(const char *name);
void chFactoryReleaseMailbox(dyn_mailbox_t *dmp);
#endif
+#if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__)
+ dyn_objects_fifo_t *chFactoryCreateObjectsFIFO(const char *name,
+ size_t objsize,
+ size_t objn);
+ dyn_objects_fifo_t *chFactoryFindObjectsFIFO(const char *name);
+ void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp);
+#endif
#ifdef __cplusplus
}
#endif
diff --git a/os/common/oslib/include/chfifo.h b/os/common/oslib/include/chfifo.h
index 537314192..9f3c0924b 100644
--- a/os/common/oslib/include/chfifo.h
+++ b/os/common/oslib/include/chfifo.h
@@ -44,11 +44,11 @@
#ifndef CHFIFO_H
#define CHFIFO_H
-#if !defined(CH_CFG_USE_FIFO)
-#define CH_CFG_USE_FIFO TRUE
+#if !defined(CH_CFG_USE_OBJ_FIFOS)
+#define CH_CFG_USE_OBJ_FIFOS TRUE
#endif
-#if (CH_CFG_USE_FIFO == TRUE) || defined(__DOXYGEN__)
+#if (CH_CFG_USE_OBJ_FIFOS == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/
/* Module constants. */
@@ -327,7 +327,7 @@ static inline msg_t chFifoReceiveObjectTimeout(objects_fifo_t *ofp,
return chMBFetchTimeout(&ofp->mbx, (msg_t *)objpp, timeout);
}
-#endif /* CH_CFG_USE_FIFO == TRUE */
+#endif /* CH_CFG_USE_OBJ_FIFOS == TRUE */
#endif /* CHFIFO_H */
diff --git a/os/common/oslib/src/chfactory.c b/os/common/oslib/src/chfactory.c
index b7e355143..5e7604917 100644
--- a/os/common/oslib/src/chfactory.c
+++ b/os/common/oslib/src/chfactory.c
@@ -248,6 +248,9 @@ void _factory_init(void) {
#if CH_CFG_FACTORY_MAILBOXES == TRUE
dyn_list_init(&ch_factory.mbx_list);
#endif
+#if CH_CFG_FACTORY_OBJ_FIFOS == TRUE
+ dyn_list_init(&ch_factory.fifo_list);
+#endif
}
#if (CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || defined(__DOXIGEN__)
@@ -494,7 +497,7 @@ void chFactoryReleaseSemaphore(dyn_semaphore_t *dsp) {
* @brief Creates a dynamic mailbox object.
* @post A reference to the dynamic mailbox object is returned and the
* reference counter is initialized to one.
- * @post The dynamic buffer object is filled with zeros.
+ * @post The dynamic mailbox object is initialized and ready to use.
*
* @param[in] name name to be assigned to the new dynamic mailbox object
* @param[in] n mailbox buffer size as number of messages
@@ -516,7 +519,7 @@ dyn_mailbox_t *chFactoryCreateMailbox(const char *name, size_t n) {
(n * sizeof (msg_t)));
if (dmp != NULL) {
/* Initializing mailbox object data.*/
- chMBObjectInit(&dmp->mbx, dmp->buffer, n);
+ chMBObjectInit(&dmp->mbx, dmp->msgbuf, n);
}
chSysUnlock();
@@ -569,6 +572,93 @@ void chFactoryReleaseMailbox(dyn_mailbox_t *dmp) {
}
#endif /* CH_CFG_FACTORY_MAILBOXES = TRUE */
+#if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__)
+/**
+ * @brief Creates a dynamic "objects FIFO" object.
+ * @post A reference to the dynamic "objects FIFO" object is returned and
+ * the reference counter is initialized to one.
+ * @post The dynamic "objects FIFO" object is initialized and ready to use.
+ *
+ * @param[in] name name to be assigned to the new dynamic "objects FIFO"
+ * object
+ *
+ * @return The reference to the created dynamic "objects FIFO"
+ * object.
+ * @retval NULL if the dynamic "objects FIFO" object cannot be
+ * allocated or a dynamic "objects FIFO" object with
+ * the same name exists.
+ *
+ * @api
+ */
+dyn_objects_fifo_t *chFactoryCreateObjectsFIFO(const char *name,
+ size_t objsize,
+ size_t objn) {
+ dyn_objects_fifo_t *dofp;
+
+ chSysLock();
+
+ dofp = (dyn_objects_fifo_t *)dyn_create_object_heap(name,
+ &ch_factory.fifo_list,
+ sizeof (dyn_objects_fifo_t) +
+ (objn * sizeof (msg_t)) +
+ (objn * objsize));
+ if (dofp != NULL) {
+ /* Initializing mailbox object data.*/
+ chFifoObjectInit(&dofp->fifo, objsize, objn,
+ dofp->msgbuf, (void *)&dofp->msgbuf[objn]);
+ }
+
+ chSysUnlock();
+
+ return dofp;
+}
+
+/**
+ * @brief Retrieves a dynamic "objects FIFO" object.
+ * @post A reference to the dynamic "objects FIFO" object is returned with
+ * the reference counter increased by one.
+ *
+ * @param[in] name name of the dynamic "objects FIFO" object
+ *
+ * @return The reference to the found dynamic "objects FIFO"
+ * object.
+ * @retval NULL if a dynamic "objects FIFO" object with the specified
+ * name does not exist.
+ *
+ * @api
+ */
+dyn_objects_fifo_t *chFactoryFindObjectsFIFO(const char *name) {
+ dyn_objects_fifo_t *dofp;
+
+ chSysLock();
+
+ dofp = (dyn_objects_fifo_t *)dyn_find_object(name, &ch_factory.fifo_list);
+
+ chSysUnlock();
+
+ return dofp;
+}
+
+/**
+ * @brief Releases a dynamic "objects FIFO" object.
+ * @details The reference counter of the dynamic "objects FIFO" object is
+ * decreased by one, if reaches zero then the dynamic "objects FIFO"
+ * object memory is freed.
+ *
+ * @param[in] dofp dynamic "objects FIFO" object reference
+ *
+ * @api
+ */
+void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp) {
+
+ chSysLock();
+
+ dyn_release_object_heap(&dofp->element, &ch_factory.fifo_list);
+
+ chSysUnlock();
+}
+#endif /* CH_CFG_FACTORY_MAILBOXES = TRUE */
+
#endif /* CH_CFG_USE_FACTORY == TRUE */
/** @} */