From 6b39a17ac99e88355162d972206b1e2bbcf45ced Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 27 Sep 2018 12:48:06 +0000 Subject: 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 --- os/lib/include/chfactory.h | 73 ++++++++++++++++++++++++++++++++++++++++- os/lib/src/chfactory.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) (limited to 'os/lib') 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 */ /** @} */ -- cgit v1.2.3