aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2017-10-02 14:51:07 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2017-10-02 14:51:07 +0000
commit52f6af16df6b4b6f2a45be44c306053cc543109b (patch)
tree6089116b02283f0ee163ca792d5161928d59f075
parent011329ed906cfbf1d019e1a06cd000f2494451ee (diff)
downloadChibiOS-52f6af16df6b4b6f2a45be44c306053cc543109b.tar.gz
ChibiOS-52f6af16df6b4b6f2a45be44c306053cc543109b.tar.bz2
ChibiOS-52f6af16df6b4b6f2a45be44c306053cc543109b.zip
Adjustments to the new code.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10745 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/common/oslib/include/chfactory.h2
-rw-r--r--os/common/oslib/include/chfifo.h213
-rw-r--r--os/common/oslib/include/chmempools.h15
-rw-r--r--os/common/oslib/src/chfactory.c1
-rw-r--r--os/rt/include/ch.h2
5 files changed, 209 insertions, 24 deletions
diff --git a/os/common/oslib/include/chfactory.h b/os/common/oslib/include/chfactory.h
index f4fbf8161..a18dfbefa 100644
--- a/os/common/oslib/include/chfactory.h
+++ b/os/common/oslib/include/chfactory.h
@@ -261,7 +261,7 @@ typedef struct ch_objects_factory {
/*===========================================================================*/
#if !defined(__DOXYGEN__)
-objects_factory_t ch_factory;
+extern objects_factory_t ch_factory;
#endif
#ifdef __cplusplus
diff --git a/os/common/oslib/include/chfifo.h b/os/common/oslib/include/chfifo.h
index f1ca6637c..46349c019 100644
--- a/os/common/oslib/include/chfifo.h
+++ b/os/common/oslib/include/chfifo.h
@@ -29,7 +29,7 @@
#define CHFIFO_H
#if !defined(CH_CFG_USE_FIFO)
-#define CH_CFG_USE_FIFO FALSE
+#define CH_CFG_USE_FIFO TRUE
#endif
#if (CH_CFG_USE_FIFO == TRUE) || defined(__DOXYGEN__)
@@ -83,25 +83,7 @@ typedef struct {
#ifdef __cplusplus
extern "C" {
#endif
- void *chFifoAllocObjectI(objects_fifo_t *ofp);
- void *chFifoAllocObjectTimeout(objects_fifo_t *ofp,
- systime_t timeout);
- msg_t chFifoReleaseObjectI(objects_fifo_t *ofp,
- void *objp);
- msg_t chFifoReleaseObject(objects_fifo_t *ofp,
- void *objp);
- msg_t chFifoPostObjectI(objects_fifo_t *ofp,
- void *objp);
- msg_t chFifoPostObjectS(objects_fifo_t *ofp,
- void *objp);
- msg_t chFifoPostObject(objects_fifo_t *ofp, void *obj);
- msg_t chFifoFetchObjectI(objects_fifo_t *ofp,
- void **objpp);
- msg_t chFifoFetchObjectS(objects_fifo_t *ofp,
- void **objpp);
- msg_t chFifoFetchObjectTimeout(objects_fifo_t *ofp,
- void **objpp,
- systime_t timeout);
+
#ifdef __cplusplus
}
#endif
@@ -113,14 +95,201 @@ extern "C" {
/**
* @brief Initializes a mail object.
*
- * @param[out] mop pointer to a @p mail_t structure
+ * @param[out] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objsize size of objects
+ * @param[in] objn number of objects available
+ * @param[in] objbuf pointer to the buffer of objects, it must be able
+ * to hold @p objn objects of @p objsize size
+ * @param[in] msgbuf pointer to the buffer of messages, it must be able
+ * to hold @p objn messages
*
* @init
*/
-static inline void chMailObjectInit(mail_t *mop) {
+static inline void chMailObjectInit(objects_fifo_t *ofp, size_t objsize,
+ size_t objn, void *objbuf,
+ msg_t *msgbuf) {
+
+ chGuardedPoolObjectInit(&ofp->free, objsize);
+ chGuardedPoolLoadArray(&ofp->free, objbuf, objn);
+ chMBObjectInit(&ofp->mbx, msgbuf, (cnt_t)objn); /* TODO: make this a size_t, no more sems there.*/
+}
+
+/**
+ * @brief Allocates a free object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @return The pointer to the allocated object.
+ * @retval NULL if an object is not immediately available.
+ *
+ * @iclass
+ */
+static inline void *chFifoAllocObjectI(objects_fifo_t *ofp) {
+
+ return chGuardedPoolAllocI(&ofp->free);
+}
+
+/**
+ * @brief Allocates a free object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] timeout the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The pointer to the allocated object.
+ * @retval NULL if an object is not available within the specified
+ * timeout.
+ *
+ * @iclass
+ */
+static inline void *chFifoAllocObjectTimeout(objects_fifo_t *ofp,
+ systime_t timeout) {
+
+ return chGuardedPoolAllocTimeout(&ofp->free, timeout);
+}
+
+/**
+ * @brief Releases a fetched object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be released
+ *
+ * @iclass
+ */
+static inline void chFifoReleaseObjectI(objects_fifo_t *ofp,
+ void *objp) {
+
+ chGuardedPoolFreeI(&ofp->free, objp);
+}
+
+/**
+ * @brief Releases a fetched object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be released
+ *
+ * @api
+ */
+static inline void chFifoReleaseObject(objects_fifo_t *ofp,
+ void *objp) {
+
+ chGuardedPoolFree(&ofp->free, objp);
+}
+
+/**
+ * @brief Posts an object.
+ * @note By design the object can be always immediately posted.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be released
+ *
+ * @iclass
+ */
+static inline void chFifoPostObjectI(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+ msg = chMBPostI(&ofp->mbx, (msg_t)objp);
+ chDbgAssert(msg == MSG_OK, "post failed");
}
+/**
+ * @brief Posts an object.
+ * @note By design the object can be always immediately posted.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be released
+ *
+ * @sclass
+ */
+static inline void chFifoPostObjectS(objects_fifo_t *ofp,
+ void *objp) {
+ msg_t msg;
+
+ msg = chMBPostS(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+
+/**
+ * @brief Posts an object.
+ * @note By design the object can be always immediately posted.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objp pointer to the object to be released
+ *
+ * @api
+ */
+static inline void chFifoPostObject(objects_fifo_t *ofp, void *objp) {
+
+ msg_t msg;
+
+ msg = chMBPost(&ofp->mbx, (msg_t)objp, TIME_IMMEDIATE);
+ chDbgAssert(msg == MSG_OK, "post failed");
+}
+
+/**
+ * @brief Fetches an object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objpp pointer to the fetched object reference
+ * @return The operation status.
+ * @retval MSG_OK if an object has been correctly fetched.
+ * @retval MSG_TIMEOUT if the FIFO is empty and a message cannot be fetched.
+ *
+ * @api
+ */
+static inline msg_t chFifoFetchObjectI(objects_fifo_t *ofp,
+ void **objpp) {
+
+ return chMBFetchI(&ofp->mbx, (msg_t *)objpp);
+}
+
+/**
+ * @brief Fetches an object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objpp pointer to the fetched object reference
+ * @param[in] timeout the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval MSG_OK if an object has been correctly fetched.
+ * @retval MSG_TIMEOUT if the operation has timed out.
+ *
+ * @sclass
+ */
+static inline msg_t chFifoFetchObjectTimeoutS(objects_fifo_t *ofp,
+ void **objpp,
+ systime_t timeout) {
+
+ return chMBFetchS(&ofp->mbx, (msg_t *)objpp, timeout);
+}
+
+/**
+ * @brief Fetches an object.
+ *
+ * @param[in] ofp pointer to a @p objects_fifo_t structure
+ * @param[in] objpp pointer to the fetched object reference
+ * @param[in] timeout the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval MSG_OK if an object has been correctly fetched.
+ * @retval MSG_TIMEOUT if the operation has timed out.
+ *
+ * @api
+ */
+static inline msg_t chFifoFetchObjectTimeout(objects_fifo_t *ofp,
+ void **objpp,
+ systime_t timeout) {
+
+ return chMBFetch(&ofp->mbx, (msg_t *)objpp, timeout);
+}
#endif /* CH_CFG_USE_FIFO == TRUE */
#endif /* CHFIFO_H */
diff --git a/os/common/oslib/include/chmempools.h b/os/common/oslib/include/chmempools.h
index ab763b401..25de236ce 100644
--- a/os/common/oslib/include/chmempools.h
+++ b/os/common/oslib/include/chmempools.h
@@ -252,6 +252,21 @@ static inline void chGuardedPoolAddI(guarded_memory_pool_t *gmp, void *objp) {
chGuardedPoolFreeI(gmp, objp);
}
+
+/**
+ * @brief Allocates an object from a guarded memory pool.
+ * @pre The guarded memory pool must be already been initialized.
+ *
+ * @param[in] gmp pointer to a @p guarded_memory_pool_t structure
+ * @return The pointer to the allocated object.
+ * @retval NULL if the operation timed out.
+ *
+ * @iclass
+ */
+static inline void *chGuardedPoolAllocI(guarded_memory_pool_t *gmp) {
+
+ return chPoolAllocI(&gmp->pool);
+}
#endif /* CH_CFG_USE_SEMAPHORES == TRUE */
#endif /* CH_CFG_USE_MEMPOOLS == TRUE */
diff --git a/os/common/oslib/src/chfactory.c b/os/common/oslib/src/chfactory.c
index e556489b1..48b88441b 100644
--- a/os/common/oslib/src/chfactory.c
+++ b/os/common/oslib/src/chfactory.c
@@ -42,7 +42,6 @@
#include <string.h>
#include "ch.h"
-#include "chfactory.h"
#if (CH_CFG_USE_FACTORY == TRUE) || defined(__DOXYGEN__)
diff --git a/os/rt/include/ch.h b/os/rt/include/ch.h
index a11f1ec22..da509adad 100644
--- a/os/rt/include/ch.h
+++ b/os/rt/include/ch.h
@@ -100,6 +100,8 @@
#include "chmemcore.h"
#include "chheap.h"
#include "chmempools.h"
+#include "chfifo.h"
+#include "chfactory.h"
#include "chdynamic.h"
#if !defined(_CHIBIOS_RT_CONF_)