aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-09-27 12:48:06 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-09-27 12:48:06 +0000
commit6b39a17ac99e88355162d972206b1e2bbcf45ced (patch)
treee5097c88e4700d89d64922d219b4e10f821a16f7
parentabea526c12673b5da562003c647f224916c37dd2 (diff)
downloadChibiOS-6b39a17ac99e88355162d972206b1e2bbcf45ced.tar.gz
ChibiOS-6b39a17ac99e88355162d972206b1e2bbcf45ced.tar.bz2
ChibiOS-6b39a17ac99e88355162d972206b1e2bbcf45ced.zip
Pipes API added to factory. Updated templates (to be run).
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12298 110e8d01-0319-4d1e-a829-52ad28d1bb01
-rw-r--r--os/lib/include/chfactory.h73
-rw-r--r--os/lib/src/chfactory.c82
-rw-r--r--tools/ftl/processors/conf/chconf_nil/chconf.h.ftl14
-rw-r--r--tools/ftl/processors/conf/chconf_rt/chconf.h.ftl20
4 files changed, 187 insertions, 2 deletions
diff --git a/os/lib/include/chfactory.h b/os/lib/include/chfactory.h
index 0f66bf906..aaaa5d2c2 100644
--- a/os/lib/include/chfactory.h
+++ b/os/lib/include/chfactory.h
@@ -82,6 +82,20 @@
#define CH_CFG_FACTORY_OBJ_FIFOS 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
+
+/**
+ * @brief Enables factory for Pipes.
+ */
+#if !defined(CH_CFG_FACTORY_PIPES) || defined(__DOXYGEN__)
+#define CH_CFG_FACTORY_PIPES TRUE
+#endif
+
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
@@ -107,6 +121,13 @@
/*lint restore*/
#endif
+#if (CH_CFG_FACTORY_PIPES == TRUE) && (CH_CFG_USE_PIPES == FALSE)
+/*lint -save -e767 [20.5] Valid because the #undef.*/
+#undef CH_CFG_FACTORY_PIPES
+#define CH_CFG_FACTORY_PIPES FALSE
+/*lint restore*/
+#endif
+
#define CH_FACTORY_REQUIRES_POOLS \
((CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || \
(CH_CFG_FACTORY_SEMAPHORES == TRUE))
@@ -114,7 +135,8 @@
#define CH_FACTORY_REQUIRES_HEAP \
((CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || \
(CH_CFG_FACTORY_MAILBOXES == TRUE) || \
- (CH_CFG_FACTORY_OBJ_FIFOS == TRUE))
+ (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || \
+ (CH_CFG_FACTORY_PIPES == TRUE))
#if (CH_CFG_FACTORY_MAX_NAMES_LENGTH < 0) || \
(CH_CFG_FACTORY_MAX_NAMES_LENGTH > 32)
@@ -267,6 +289,29 @@ typedef struct ch_dyn_objects_fifo {
} dyn_objects_fifo_t;
#endif
+#if (CH_CFG_FACTORY_PIPES == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Type of a dynamic pipe object.
+ */
+typedef struct ch_dyn_pipe {
+ /**
+ * @brief List element of the dynamic pipe object.
+ */
+ dyn_element_t element;
+ /**
+ * @brief The pipe.
+ */
+ pipe_t pipe;
+ /*lint -save -e9038 [18.7] Required by design.*/
+ /**
+ * @brief Messages buffer.
+ * @note This requires C99.
+ */
+ uint8_t buffer[];
+ /*lint restore*/
+} dyn_pipe_t;
+#endif
+
/**
* @brief Type of the factory main object.
*/
@@ -315,6 +360,12 @@ typedef struct ch_objects_factory {
*/
dyn_list_t fifo_list;
#endif /* CH_CFG_FACTORY_OBJ_FIFOS = TRUE */
+#if (CH_CFG_FACTORY_PIPES == TRUE) || defined(__DOXYGEN__)
+ /**
+ * @brief List of the allocated pipe objects.
+ */
+ dyn_list_t pipe_list;
+#endif /* CH_CFG_FACTORY_PIPES = TRUE */
} objects_factory_t;
/*===========================================================================*/
@@ -363,6 +414,11 @@ extern "C" {
dyn_objects_fifo_t *chFactoryFindObjectsFIFO(const char *name);
void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp);
#endif
+#if (CH_CFG_FACTORY_PIPES == TRUE) || defined(__DOXYGEN__)
+ dyn_pipe_t *chFactoryCreatePipe(const char *name, size_t size);
+ dyn_pipe_t *chFactoryFindPipe(const char *name);
+ void chFactoryReleasePipe(dyn_pipe_t *dpp);
+#endif
#ifdef __cplusplus
}
#endif
@@ -475,6 +531,21 @@ static inline objects_fifo_t *chFactoryGetObjectsFIFO(dyn_objects_fifo_t *dofp)
}
#endif /* CH_CFG_FACTORY_OBJ_FIFOS == TRUE */
+#if (CH_CFG_FACTORY_PIPES == TRUE) || defined(__DOXYGEN__)
+/**
+ * @brief Returns the pointer to the inner pipe.
+ *
+ * @param[in] dpp dynamic pipe object reference
+ * @return The pointer to the pipe.
+ *
+ * @api
+ */
+static inline pipe_t *chFactoryGetPipe(dyn_pipe_t *dpp) {
+
+ return &dpp->pipe;
+}
+#endif /* CH_CFG_FACTORY_PIPES == TRUE */
+
#endif /* CH_CFG_USE_FACTORY == TRUE */
#endif /* CHFACTORY_H */
diff --git a/os/lib/src/chfactory.c b/os/lib/src/chfactory.c
index b65aad86e..149f673d8 100644
--- a/os/lib/src/chfactory.c
+++ b/os/lib/src/chfactory.c
@@ -720,6 +720,88 @@ void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp) {
}
#endif /* CH_CFG_FACTORY_OBJ_FIFOS = TRUE */
+#if (CH_CFG_FACTORY_PIPES == TRUE) || defined(__DOXIGEN__)
+/**
+ * @brief Creates a dynamic pipe object.
+ * @post A reference to the dynamic pipe object is returned and
+ * the reference counter is initialized to one.
+ * @post The dynamic pipe object is initialized and ready to use.
+ *
+ * @param[in] name name to be assigned to the new dynamic pipe
+ * object
+ * @param[in] size pipe buffer size
+ * @return The reference to the created dynamic pipe
+ * object.
+ * @retval NULL if the dynamic pipe object cannot be
+ * allocated or a dynamic pipe object with
+ * the same name exists.
+ *
+ * @api
+ */
+dyn_pipe_t *chFactoryCreatePipe(const char *name, size_t size) {
+ dyn_pipe_t *dpp;
+
+ F_LOCK();
+
+ dpp = (dyn_pipe_t *)dyn_create_object_heap(name,
+ &ch_factory.pipe_list,
+ sizeof (dyn_pipe_t) + size);
+ if (dpp != NULL) {
+ /* Initializing mailbox object data.*/
+ chPipeObjectInit(&dpp->pipe, dpp->buffer, size);
+ }
+
+ F_UNLOCK();
+
+ return dpp;
+}
+
+/**
+ * @brief Retrieves a dynamic pipe object.
+ * @post A reference to the dynamic pipe object is returned with
+ * the reference counter increased by one.
+ *
+ * @param[in] dpp dynamic pipe object reference
+ *
+ * @return The reference to the found dynamic pipe
+ * object.
+ * @retval NULL if a dynamic pipe object with the specified
+ * name does not exist.
+ *
+ * @api
+ */
+dyn_pipe_t *chFactoryFindPipe(const char *name) {
+ dyn_pipe_t *dpp;
+
+ F_LOCK();
+
+ dpp = (dyn_pipe_t *)dyn_find_object(name, &ch_factory.fifo_list);
+
+ F_UNLOCK();
+
+ return dpp;
+}
+
+/**
+ * @brief Releases a dynamic pipe object.
+ * @details The reference counter of the dynamic pipe object is
+ * decreased by one, if reaches zero then the dynamic pipe
+ * object memory is freed.
+ *
+ * @param[in] dpp dynamic pipe object reference
+ *
+ * @api
+ */
+void chFactoryReleasePipe(dyn_pipe_t *dpp) {
+
+ F_LOCK();
+
+ dyn_release_object_heap(&dpp->element, &ch_factory.pipe_list);
+
+ F_UNLOCK();
+}
+#endif /* CH_CFG_FACTORY_PIPES = TRUE */
+
#endif /* CH_CFG_USE_FACTORY == TRUE */
/** @} */
diff --git a/tools/ftl/processors/conf/chconf_nil/chconf.h.ftl b/tools/ftl/processors/conf/chconf_nil/chconf.h.ftl
index ade7873fa..e6d9596af 100644
--- a/tools/ftl/processors/conf/chconf_nil/chconf.h.ftl
+++ b/tools/ftl/processors/conf/chconf_nil/chconf.h.ftl
@@ -170,6 +170,15 @@
#define CH_CFG_USE_OBJ_FIFOS ${doc.CH_CFG_USE_OBJ_FIFOS!"TRUE"}
/**
+ * @brief Pipes APIs.
+ * @details If enabled then the pipes APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#define CH_CFG_USE_PIPES ${doc.CH_CFG_USE_PIPES!"TRUE"}
+
+/**
* @brief Managed RAM size.
* @details Size of the RAM area to be managed by the OS. If set to zero
* then the whole available RAM is used. The core memory is made
@@ -232,6 +241,11 @@
*/
#define CH_CFG_FACTORY_OBJ_FIFOS ${doc.CH_CFG_FACTORY_OBJ_FIFOS!"TRUE"}
+/**
+ * @brief Enables factory for Pipes.
+ */
+#define CH_CFG_FACTORY_PIPES ${doc.CH_CFG_FACTORY_PIPES!"TRUE"}
+
/** @} */
/*===========================================================================*/
diff --git a/tools/ftl/processors/conf/chconf_rt/chconf.h.ftl b/tools/ftl/processors/conf/chconf_rt/chconf.h.ftl
index 129186f2e..598f55cf5 100644
--- a/tools/ftl/processors/conf/chconf_rt/chconf.h.ftl
+++ b/tools/ftl/processors/conf/chconf_rt/chconf.h.ftl
@@ -371,7 +371,7 @@
#endif
/**
- * @brief Objects FIFOs APIs.
+ * @brief Objects FIFOs APIs.
* @details If enabled then the objects FIFOs APIs are included
* in the kernel.
*
@@ -382,6 +382,17 @@
#endif
/**
+ * @brief Pipes APIs.
+ * @details If enabled then the pipes APIs are included
+ * in the kernel.
+ *
+ * @note The default is @p TRUE.
+ */
+#if !defined(CH_CFG_USE_PIPES)
+#define CH_CFG_USE_PIPES ${doc.CH_CFG_USE_PIPES!"TRUE"}
+#endif
+
+/**
* @brief Dynamic Threads APIs.
* @details If enabled then the dynamic threads creation APIs are included
* in the kernel.
@@ -458,6 +469,13 @@
#define CH_CFG_FACTORY_OBJ_FIFOS ${doc.CH_CFG_FACTORY_OBJ_FIFOS!"TRUE"}
#endif
+/**
+ * @brief Enables factory for Pipes.
+ */
+#if !defined(CH_CFG_FACTORY_PIPES) || defined(__DOXYGEN__)
+#define CH_CFG_FACTORY_PIPES ${doc.CH_CFG_FACTORY_PIPES!"TRUE"}
+#endif
+
/** @} */
/*===========================================================================*/