From e65a5b08cda0ef8358b4a851feb74860cdc74625 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Mon, 2 Oct 2017 12:19:24 +0000 Subject: Added mailboxes to the factory. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10743 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/common/oslib/include/chfactory.h | 50 ++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'os/common/oslib/include') diff --git a/os/common/oslib/include/chfactory.h b/os/common/oslib/include/chfactory.h index 9dbcb7b57..ae975d3bd 100644 --- a/os/common/oslib/include/chfactory.h +++ b/os/common/oslib/include/chfactory.h @@ -68,6 +68,13 @@ #define CH_CFG_FACTORY_SEMAPHORES TRUE #endif +/** + * @brief Enables factory for mailboxes. + */ +#if !defined(CH_CFG_FACTORY_MAILBOXES) || defined(__DOXYGEN__) +#define CH_CFG_FACTORY_MAILBOXES TRUE +#endif + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ @@ -76,7 +83,8 @@ ((CH_CFG_FACTORY_SEMAPHORES == TRUE)) #define CH_FACTORY_REQUIRES_HEAP \ - ((CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE)) + ((CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || \ + (CH_CFG_FACTORY_MAILBOXES == TRUE)) #if (CH_CFG_FACTORY_MAX_NAMES_LENGHT < 0) || \ (CH_CFG_FACTORY_MAX_NAMES_LENGHT > 32) @@ -99,6 +107,10 @@ #error "CH_CFG_FACTORY_SEMAPHORES requires CH_CFG_USE_SEMAPHORES" #endif +#if (CH_CFG_FACTORY_MAILBOXES == TRUE) && (CH_CFG_USE_MAILBOXES == FALSE) +#error "CH_CFG_FACTORY_MAILBOXES requires CH_CFG_USE_MAILBOXES" +#endif + /*===========================================================================*/ /* Module data structures and types. */ /*===========================================================================*/ @@ -156,7 +168,7 @@ typedef struct ch_dyn_object { */ dyn_element_t element; /** - * @brief Physical buffer objects. + * @brief The buffer. * @note This requires C99. */ uint8_t buffer[]; @@ -173,12 +185,33 @@ typedef struct ch_dyn_semaphore { */ dyn_element_t element; /** - * @brief Physical semaphore. + * @brief The semaphore. */ semaphore_t sem; } dyn_semaphore_t; #endif +#if (CH_CFG_FACTORY_MAILBOXES == TRUE) || defined(__DOXIGEN__) +/** + * @brief Type of a dynamic buffer object. + */ +typedef struct ch_dyn_mailbox { + /** + * @brief List element of the dynamic buffer object. + */ + dyn_element_t element; + /** + * @brief The mailbox. + */ + mailbox_t mbx; + /** + * @brief Mailbox buffer. + * @note This requires C99. + */ + msg_t buffer[]; +} dyn_mailbox_t; +#endif + /** * @brief Type of the factory main object. */ @@ -207,6 +240,12 @@ typedef struct ch_objects_factory { */ memory_pool_t sem_pool; #endif /* CH_CFG_FACTORY_SEMAPHORES = TRUE */ +#if (CH_CFG_FACTORY_MAILBOXES == TRUE) || defined(__DOXIGEN__) + /** + * @brief List of the allocated buffer objects. + */ + dyn_list_t mbx_list; +#endif /* CH_CFG_FACTORY_MAILBOXES = TRUE */ } objects_factory_t; /*===========================================================================*/ @@ -241,6 +280,11 @@ extern "C" { dyn_semaphore_t *chFactoryFindSemaphore(const char *name); void chFactoryReleaseSemaphore(dyn_semaphore_t *dsp); #endif +#if (CH_CFG_FACTORY_MAILBOXES == TRUE) || defined(__DOXIGEN__) + dyn_mailbox_t *chFactoryCreateMailbox(const char *name, cnt_t n); + dyn_mailbox_t *chFactoryFindMailbox(const char *name); + void chFactoryReleaseMailbox(dyn_mailbox_t *dmp); +#endif #ifdef __cplusplus } #endif -- cgit v1.2.3