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
This commit is contained in:
Giovanni Di Sirio 2018-09-27 12:48:06 +00:00
parent abea526c12
commit 6b39a17ac9
4 changed files with 187 additions and 2 deletions

View File

@ -82,6 +82,20 @@
#define CH_CFG_FACTORY_OBJ_FIFOS TRUE #define CH_CFG_FACTORY_OBJ_FIFOS TRUE
#endif #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. */ /* Derived constants and error checks. */
/*===========================================================================*/ /*===========================================================================*/
@ -107,6 +121,13 @@
/*lint restore*/ /*lint restore*/
#endif #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 \ #define CH_FACTORY_REQUIRES_POOLS \
((CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || \ ((CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || \
(CH_CFG_FACTORY_SEMAPHORES == TRUE)) (CH_CFG_FACTORY_SEMAPHORES == TRUE))
@ -114,7 +135,8 @@
#define CH_FACTORY_REQUIRES_HEAP \ #define CH_FACTORY_REQUIRES_HEAP \
((CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || \ ((CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || \
(CH_CFG_FACTORY_MAILBOXES == 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) || \ #if (CH_CFG_FACTORY_MAX_NAMES_LENGTH < 0) || \
(CH_CFG_FACTORY_MAX_NAMES_LENGTH > 32) (CH_CFG_FACTORY_MAX_NAMES_LENGTH > 32)
@ -267,6 +289,29 @@ typedef struct ch_dyn_objects_fifo {
} dyn_objects_fifo_t; } dyn_objects_fifo_t;
#endif #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. * @brief Type of the factory main object.
*/ */
@ -315,6 +360,12 @@ typedef struct ch_objects_factory {
*/ */
dyn_list_t fifo_list; dyn_list_t fifo_list;
#endif /* CH_CFG_FACTORY_OBJ_FIFOS = TRUE */ #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; } objects_factory_t;
/*===========================================================================*/ /*===========================================================================*/
@ -363,6 +414,11 @@ extern "C" {
dyn_objects_fifo_t *chFactoryFindObjectsFIFO(const char *name); dyn_objects_fifo_t *chFactoryFindObjectsFIFO(const char *name);
void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp); void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp);
#endif #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 #ifdef __cplusplus
} }
#endif #endif
@ -475,6 +531,21 @@ static inline objects_fifo_t *chFactoryGetObjectsFIFO(dyn_objects_fifo_t *dofp)
} }
#endif /* CH_CFG_FACTORY_OBJ_FIFOS == TRUE */ #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 /* CH_CFG_USE_FACTORY == TRUE */
#endif /* CHFACTORY_H */ #endif /* CHFACTORY_H */

View File

@ -720,6 +720,88 @@ void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp) {
} }
#endif /* CH_CFG_FACTORY_OBJ_FIFOS = TRUE */ #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 */ #endif /* CH_CFG_USE_FACTORY == TRUE */
/** @} */ /** @} */

View File

@ -169,6 +169,15 @@
*/ */
#define CH_CFG_USE_OBJ_FIFOS ${doc.CH_CFG_USE_OBJ_FIFOS!"TRUE"} #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. * @brief Managed RAM size.
* @details Size of the RAM area to be managed by the OS. If set to zero * @details Size of the RAM area to be managed by the OS. If set to zero
@ -232,6 +241,11 @@
*/ */
#define CH_CFG_FACTORY_OBJ_FIFOS ${doc.CH_CFG_FACTORY_OBJ_FIFOS!"TRUE"} #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"}
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/

View File

@ -381,6 +381,17 @@
#define CH_CFG_USE_OBJ_FIFOS ${doc.CH_CFG_USE_OBJ_FIFOS!"TRUE"} #define CH_CFG_USE_OBJ_FIFOS ${doc.CH_CFG_USE_OBJ_FIFOS!"TRUE"}
#endif #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. * @brief Dynamic Threads APIs.
* @details If enabled then the dynamic threads creation APIs are included * @details If enabled then the dynamic threads creation APIs are included
@ -458,6 +469,13 @@
#define CH_CFG_FACTORY_OBJ_FIFOS ${doc.CH_CFG_FACTORY_OBJ_FIFOS!"TRUE"} #define CH_CFG_FACTORY_OBJ_FIFOS ${doc.CH_CFG_FACTORY_OBJ_FIFOS!"TRUE"}
#endif #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
/** @} */ /** @} */
/*===========================================================================*/ /*===========================================================================*/