From 964ca6029035706e5ba5be7a8304eba67920386d Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 9 Dec 2018 09:11:21 +0000 Subject: DAC reworked, fixed a problem in WSPI template. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12466 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/hal/include/hal_dac.h | 107 ++++++++++++++++++ os/hal/include/hal_wspi.h | 45 ++++++++ os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.h | 142 +++++------------------- os/hal/ports/STM32/LLD/OCTOSPIv1/hal_wspi_lld.h | 92 ++++----------- os/hal/ports/STM32/LLD/QUADSPIv1/hal_wspi_lld.h | 71 +++--------- os/hal/templates/hal_dac_lld.h | 98 ++-------------- os/hal/templates/hal_wspi_lld.h | 47 ++------ readme.txt | 2 +- 8 files changed, 238 insertions(+), 366 deletions(-) diff --git a/os/hal/include/hal_dac.h b/os/hal/include/hal_dac.h index 24eda81e1..6533f35d6 100644 --- a/os/hal/include/hal_dac.h +++ b/os/hal/include/hal_dac.h @@ -76,8 +76,115 @@ typedef enum { DAC_ERROR = 5 /**< Error. */ } dacstate_t; +/** + * @brief Type of a structure representing an DAC driver. + */ +typedef struct hal_dac_driver DACDriver; + +/** + * @brief Type of a structure representing an DAC driver configuration. + */ +typedef struct hal_dac_config DACConfig; + +/** + * @brief Type of a DAC conversion group. + */ +typedef struct hal_dac_conversion_group DACConversionGroup; + +/* Including the low level driver header, it exports information required + for completing types.*/ #include "hal_dac_lld.h" +/** + * @brief DAC notification callback type. + * + * @param[in] dacp pointer to the @p DACDriver object triggering the + * @param[in] buffer pointer to the next semi-buffer to be filled + * @param[in] n number of buffer rows available starting from @p buffer + * callback + */ +typedef void (*daccallback_t)(DACDriver *dacp, dacsample_t *buffer, size_t n); + +/** + * @brief DAC error callback type. + * + * @param[in] dacp pointer to the @p DACDriver object triggering the + * callback + * @param[in] err DAC error code + */ +typedef void (*dacerrorcallback_t)(DACDriver *dacp, dacerror_t err); + +/** + * @brief DAC Conversion group structure. + */ +struct hal_dac_conversion_group { + /** + * @brief Number of DAC channels. + */ + uint32_t num_channels; + /** + * @brief Operation complete callback or @p NULL. + */ + daccallback_t end_cb; + /** + * @brief Error handling callback or @p NULL. + */ + dacerrorcallback_t error_cb; + /* End of the mandatory fields.*/ + dac_lld_conversion_group_fields; +}; + +/** + * @brief Driver configuration structure. + */ +struct hal_dac_config { + /* End of the mandatory fields.*/ + dac_lld_config_fields; +}; + +/** + * @brief Structure representing a DAC driver. + */ +struct hal_dac_driver { + /** + * @brief Driver state. + */ + dacstate_t state; + /** + * @brief Conversion group. + */ + const DACConversionGroup *grpp; + /** + * @brief Samples buffer pointer. + */ + dacsample_t *samples; + /** + * @brief Samples buffer size. + */ + uint16_t depth; + /** + * @brief Current configuration data. + */ + const DACConfig *config; +#if DAC_USE_WAIT || defined(__DOXYGEN__) + /** + * @brief Waiting thread. + */ + thread_reference_t thread; +#endif /* DAC_USE_WAIT */ +#if DAC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) + /** + * @brief Mutex protecting the bus. + */ + mutex_t mutex; +#endif /* DAC_USE_MUTUAL_EXCLUSION */ +#if defined(DAC_DRIVER_EXT_FIELDS) + DAC_DRIVER_EXT_FIELDS +#endif + /* End of the mandatory fields.*/ + dac_lld_driver_fields; +}; + /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ diff --git a/os/hal/include/hal_wspi.h b/os/hal/include/hal_wspi.h index c3f2ac248..4f02eb3b5 100644 --- a/os/hal/include/hal_wspi.h +++ b/os/hal/include/hal_wspi.h @@ -120,6 +120,8 @@ typedef struct { uint32_t dummy; } wspi_command_t; +/* Including the low level driver header, it exports information required + for completing types.*/ #include "hal_wspi_lld.h" #if !defined(WSPI_SUPPORTS_MEMMAP) @@ -130,6 +132,49 @@ typedef struct { #error "low level does not define WSPI_DEFAULT_CFG_MASKS" #endif +/** + * @brief Driver configuration structure. + */ +struct hal_wspi_config { + /** + * @brief Operation complete callback or @p NULL. + */ + wspicallback_t end_cb; + /* End of the mandatory fields.*/ + wspi_lld_config_fields; +}; + +/** + * @brief Structure representing an WSPI driver. + */ +struct hal_wspi_driver { + /** + * @brief Driver state. + */ + wspistate_t state; + /** + * @brief Current configuration data. + */ + const WSPIConfig *config; +#if (WSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__) + /** + * @brief Waiting thread. + */ + thread_reference_t thread; +#endif /* WSPI_USE_WAIT */ +#if (WSPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) + /** + * @brief Mutex protecting the peripheral. + */ + mutex_t mutex; +#endif /* WSPI_USE_MUTUAL_EXCLUSION */ +#if defined(WSPI_DRIVER_EXT_FIELDS) + WSPI_DRIVER_EXT_FIELDS +#endif + /* End of the mandatory fields.*/ + wspi_lld_driver_fields; +}; + /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ diff --git a/os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.h b/os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.h index a3d29956a..d66a8b0e7 100644 --- a/os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.h +++ b/os/hal/ports/STM32/LLD/DACv1/hal_dac_lld.h @@ -286,6 +286,11 @@ */ typedef uint32_t dacchannel_t; +/** + * @brief Type representing a DAC sample. + */ +typedef uint16_t dacsample_t; + /** * @brief DAC channel parameters type. */ @@ -326,16 +331,6 @@ typedef struct { #endif } dacparams_t; -/** - * @brief Type of a structure representing an DAC driver. - */ -typedef struct DACDriver DACDriver; - -/** - * @brief Type representing a DAC sample. - */ -typedef uint16_t dacsample_t; - /** * @brief Possible DAC failure causes. * @note Error codes are architecture dependent and should not relied @@ -346,25 +341,6 @@ typedef enum { DAC_ERR_UNDERFLOW = 1 /**< DAC overflow condition. */ } dacerror_t; -/** - * @brief DAC notification callback type. - * - * @param[in] dacp pointer to the @p DACDriver object triggering the - * @param[in] buffer pointer to the next semi-buffer to be filled - * @param[in] n number of buffer rows available starting from @p buffer - * callback - */ -typedef void (*daccallback_t)(DACDriver *dacp, dacsample_t *buffer, size_t n); - -/** - * @brief DAC error callback type. - * - * @param[in] dacp pointer to the @p DACDriver object triggering the - * callback - * @param[in] err DAC error code - */ -typedef void (*dacerrorcallback_t)(DACDriver *dacp, dacerror_t err); - /** * @brief Samples alignment and size mode. */ @@ -379,100 +355,36 @@ typedef enum { #endif } dacdhrmode_t; +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /** - * @brief DAC Conversion group structure. + * @brief Low level fields of the DAC driver structure. */ -typedef struct { - /** - * @brief Number of DAC channels. - */ - uint32_t num_channels; - /** - * @brief Operation complete callback or @p NULL. - */ - daccallback_t end_cb; - /** - * @brief Error handling callback or @p NULL. - */ - dacerrorcallback_t error_cb; - /* End of the mandatory fields.*/ - /** - * @brief DAC initialization data. - * @note This field contains the (not shifted) value to be put into the - * TSEL field of the DAC CR register during initialization. All - * other fields are handled internally. - */ - uint32_t trigger; -} DACConversionGroup; +#define dac_lld_driver_fields \ + /* DAC channel parameters.*/ \ + const dacparams_t *params /** - * @brief Driver configuration structure. + * @brief Low level fields of the DAC configuration structure. */ -typedef struct { - /* End of the mandatory fields.*/ - /** - * @brief Initial output on DAC channels. - */ - dacsample_t init; - /** - * @brief DAC data holding register mode. - */ - dacdhrmode_t datamode; - /** - * @brief DAC control register. - */ - uint16_t cr; -} DACConfig; +#define dac_lld_config_fields \ + /* Initial output on DAC channels.*/ \ + dacsample_t init; \ + /* DAC data holding register mode.*/ \ + dacdhrmode_t datamode; \ + /* DAC control register.*/ \ + uint16_t cr /** - * @brief Structure representing a DAC driver. + * @brief Low level fields of the DAC group configuration structure. */ -struct DACDriver { - /** - * @brief Driver state. - */ - dacstate_t state; - /** - * @brief Conversion group. - */ - const DACConversionGroup *grpp; - /** - * @brief Samples buffer pointer. - */ - dacsample_t *samples; - /** - * @brief Samples buffer size. - */ - uint16_t depth; - /** - * @brief Current configuration data. - */ - const DACConfig *config; -#if DAC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif /* DAC_USE_WAIT */ -#if DAC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the bus. - */ - mutex_t mutex; -#endif /* DAC_USE_MUTUAL_EXCLUSION */ -#if defined(DAC_DRIVER_EXT_FIELDS) - DAC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ - /** - * @brief DAC channel parameters. - */ - const dacparams_t *params; -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define dac_lld_conversion_group_fields \ + /* DAC initialization data. This field contains the (not shifted) value \ + to be put into the TSEL field of the DAC CR register during \ + initialization. All other fields are handled internally.*/ \ + uint32_t trigger /*===========================================================================*/ /* External declarations. */ diff --git a/os/hal/ports/STM32/LLD/OCTOSPIv1/hal_wspi_lld.h b/os/hal/ports/STM32/LLD/OCTOSPIv1/hal_wspi_lld.h index fd0ac2cd1..eada95b2b 100644 --- a/os/hal/ports/STM32/LLD/OCTOSPIv1/hal_wspi_lld.h +++ b/os/hal/ports/STM32/LLD/OCTOSPIv1/hal_wspi_lld.h @@ -265,80 +265,34 @@ /* Driver data structures and types. */ /*===========================================================================*/ +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /** - * @brief Driver configuration structure. + * @brief Low level fields of the WSPI configuration structure. */ -struct hal_wspi_config { - /** - * @brief Operation complete callback or @p NULL. - */ - wspicallback_t end_cb; - /* End of the mandatory fields.*/ - /** - * @brief DCR1 register initialization data. - */ - uint32_t dcr1; - /** - * @brief DCR2 register initialization data. - * @note Prescaler field is internally ORed to this field, leave it - * to zero. - */ - uint32_t dcr2; - /** - * @brief DCR3 register initialization data. - */ - uint32_t dcr3; - /** - * @brief DCR4 register initialization data. - */ - uint32_t dcr4; -}; +#define wspi_lld_config_fields \ + /* DCR1 register initialization data.*/ \ + uint32_t dcr1; \ + /* DCR2 register initialization data. The prescaler field is internally \ + ORed to this field, leave it to zero.*/ \ + uint32_t dcr2; \ + /* DCR3 register initialization data.*/ \ + uint32_t dcr3; \ + /* DCR4 register initialization data.*/ \ + uint32_t dcr4 /** - * @brief Structure representing an WSPI driver. + * @brief Low level fields of the WSPI driver structure. */ -struct hal_wspi_driver { - /** - * @brief Driver state. - */ - wspistate_t state; - /** - * @brief Current configuration data. - */ - const WSPIConfig *config; -#if (WSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif /* WSPI_USE_WAIT */ -#if (WSPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* WSPI_USE_MUTUAL_EXCLUSION */ -#if defined(WSPI_DRIVER_EXT_FIELDS) - WSPI_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the OCTOSPIx registers block. - */ - OCTOSPI_TypeDef *ospi; - /** - * @brief OCTOSPI DMA stream. - */ - const stm32_dma_stream_t *dma; - /** - * @brief OCTOSPI DMA mode bit mask. - */ - uint32_t dmamode; -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define wspi_lld_driver_fields \ + /* Pointer to the OCTOSPIx registers block.*/ \ + OCTOSPI_TypeDef *ospi; \ + /* OCTOSPI DMA stream.*/ \ + const stm32_dma_stream_t *dma; \ + /* OCTOSPI DMA mode bit mask.*/ \ + uint32_t dmamode /*===========================================================================*/ /* External declarations. */ diff --git a/os/hal/ports/STM32/LLD/QUADSPIv1/hal_wspi_lld.h b/os/hal/ports/STM32/LLD/QUADSPIv1/hal_wspi_lld.h index 4f7f913ef..418ea613f 100644 --- a/os/hal/ports/STM32/LLD/QUADSPIv1/hal_wspi_lld.h +++ b/os/hal/ports/STM32/LLD/QUADSPIv1/hal_wspi_lld.h @@ -244,66 +244,27 @@ /* Driver data structures and types. */ /*===========================================================================*/ +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /** - * @brief Driver configuration structure. + * @brief Low level fields of the WSPI configuration structure. */ -struct hal_wspi_config { - /** - * @brief Operation complete callback or @p NULL. - */ - wspicallback_t end_cb; - /* End of the mandatory fields.*/ - /** - * @brief DCR register initialization data. - */ - uint32_t dcr; -}; +#define wspi_lld_config_fields \ + /* DCR register initialization data.*/ \ + uint32_t dcr /** - * @brief Structure representing an WSPI driver. + * @brief Low level fields of the WSPI driver structure. */ -struct hal_wspi_driver { - /** - * @brief Driver state. - */ - wspistate_t state; - /** - * @brief Current configuration data. - */ - const WSPIConfig *config; -#if (WSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif /* WSPI_USE_WAIT */ -#if (WSPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* WSPI_USE_MUTUAL_EXCLUSION */ -#if defined(WSPI_DRIVER_EXT_FIELDS) - WSPI_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the QUADSPIx registers block. - */ - QUADSPI_TypeDef *qspi; - /** - * @brief QUADSPI DMA stream. - */ - const stm32_dma_stream_t *dma; - /** - * @brief QUADSPI DMA mode bit mask. - */ - uint32_t dmamode; -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define wspi_lld_driver_fields \ + /* Pointer to the QUADSPIx registers block.*/ \ + QUADSPI_TypeDef *qspi; \ + /* QUADSPI DMA stream.*/ \ + const stm32_dma_stream_t *dma; \ + /* QUADSPI DMA mode bit mask.*/ \ + uint32_t dmamode /*===========================================================================*/ /* External declarations. */ diff --git a/os/hal/templates/hal_dac_lld.h b/os/hal/templates/hal_dac_lld.h index 541ddc535..12f2760c4 100644 --- a/os/hal/templates/hal_dac_lld.h +++ b/os/hal/templates/hal_dac_lld.h @@ -67,11 +67,6 @@ */ typedef uint32_t dacchannel_t; -/** - * @brief Type of a structure representing an DAC driver. - */ -typedef struct DACDriver DACDriver; - /** * @brief Type representing a DAC sample. */ @@ -87,97 +82,26 @@ typedef enum { DAC_ERR_UNDERFLOW = 1 /**< DAC overflow condition. */ } dacerror_t; -/** - * @brief DAC notification callback type. - * - * @param[in] dacp pointer to the @p DACDriver object triggering the - * @param[in] buffer pointer to the next semi-buffer to be filled - * @param[in] n number of buffer rows available starting from @p buffer - * callback - */ -typedef void (*daccallback_t)(DACDriver *dacp, dacsample_t *buffer, size_t n); - -/** - * @brief DAC error callback type. - * - * @param[in] dacp pointer to the @p DACDriver object triggering the - * callback - * @param[in] err DAC error code - */ -typedef void (*dacerrorcallback_t)(DACDriver *dacp, dacerror_t err); +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ /** - * @brief DAC Conversion group structure. + * @brief Low level fields of the DAC driver structure. */ -typedef struct { - /** - * @brief Number of DAC channels. - */ - uint32_t num_channels; - /** - * @brief Operation complete callback or @p NULL. - */ - daccallback_t end_cb; - /** - * @brief Error handling callback or @p NULL. - */ - dacerrorcallback_t error_cb; - /* End of the mandatory fields.*/ -} DACConversionGroup; +#define dac_lld_driver_fields /** - * @brief Driver configuration structure. + * @brief Low level fields of the DAC configuration structure. */ -typedef struct { - /* End of the mandatory fields.*/ - uint32_t dummy; -} DACConfig; +#define dac_lld_config_fields \ + /* Dummy configuration, it is not needed.*/ \ + uint32_t dummy /** - * @brief Structure representing a DAC driver. + * @brief Low level fields of the DAC group configuration structure. */ -struct DACDriver { - /** - * @brief Driver state. - */ - dacstate_t state; - /** - * @brief Conversion group. - */ - const DACConversionGroup *grpp; - /** - * @brief Samples buffer pointer. - */ - dacsample_t *samples; - /** - * @brief Samples buffer size. - */ - uint16_t depth; - /** - * @brief Current configuration data. - */ - const DACConfig *config; -#if DAC_USE_WAIT || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif /* DAC_USE_WAIT */ -#if DAC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the bus. - */ - mutex_t mutex; -#endif /* DAC_USE_MUTUAL_EXCLUSION */ -#if defined(DAC_DRIVER_EXT_FIELDS) - DAC_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define dac_lld_conversion_group_fields /*===========================================================================*/ /* External declarations. */ diff --git a/os/hal/templates/hal_wspi_lld.h b/os/hal/templates/hal_wspi_lld.h index 6c54d43b7..4c006f296 100644 --- a/os/hal/templates/hal_wspi_lld.h +++ b/os/hal/templates/hal_wspi_lld.h @@ -65,50 +65,19 @@ /* Driver data structures and types. */ /*===========================================================================*/ +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + /** - * @brief Driver configuration structure. + * @brief Low level fields of the WSPI configuration structure. */ -struct hal_wspi_config { - /** - * @brief Operation complete callback or @p NULL. - */ - wspicallback_t end_cb; - /* End of the mandatory fields.*/ -}; +#define wspi_lld_config_fields /** - * @brief Structure representing an WSPI driver. + * @brief Low level fields of the WSPI driver structure. */ -struct hal_wspi_driver { - /** - * @brief Driver state. - */ - wspistate_t state; - /** - * @brief Current configuration data. - */ - const WSPIConfig *config; -#if (WSPI_USE_WAIT == TRUE) || defined(__DOXYGEN__) - /** - * @brief Waiting thread. - */ - thread_reference_t thread; -#endif /* WSPI_USE_WAIT */ -#if (WSPI_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__) - /** - * @brief Mutex protecting the peripheral. - */ - mutex_t mutex; -#endif /* WSPI_USE_MUTUAL_EXCLUSION */ -#if defined(WSPI_DRIVER_EXT_FIELDS) - WSPI_DRIVER_EXT_FIELDS -#endif - /* End of the mandatory fields.*/ -}; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ +#define wspi_lld_driver_fields /*===========================================================================*/ /* External declarations. */ diff --git a/readme.txt b/readme.txt index fde900120..bc0707447 100644 --- a/readme.txt +++ b/readme.txt @@ -78,7 +78,7 @@ - NEW: Low level drivers simplification. There is a new template of LLD, now driver and configuration types are defined in the HLD, LLD just exports macros with the fields to be added to the structures. - So far the drivers updated are: RTC, SPI, TRNG. + So far the drivers updated are: DAC, RTC, SPI, TRNG, WSPI. - NEW: Added UART7/8 support to STM32 UART USARTv1 driver. - NEW: Added persistent storage interface to the STM32 RTCv2 driver. - NEW: STM32 RTCv2 driver now supports callbacks on events. -- cgit v1.2.3