ChibiOS/HAL  6.1.0
hal_dac_lld.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_dac_lld.h
19  * @brief PLATFORM DAC subsystem low level driver header.
20  *
21  * @addtogroup DAC
22  * @{
23  */
24 
25 #ifndef HAL_DAC_LLD_H
26 #define HAL_DAC_LLD_H
27 
28 #if HAL_USE_DAC || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Driver constants. */
32 /*===========================================================================*/
33 
34 /**
35  * @brief Maximum number of DAC channels per unit.
36  */
37 #define DAC_MAX_CHANNELS 2
38 
39 /*===========================================================================*/
40 /* Driver pre-compile time settings. */
41 /*===========================================================================*/
42 
43 /**
44  * @name Configuration options
45  * @{
46  */
47 /**
48  * @brief DAC1 CH1 driver enable switch.
49  * @details If set to @p TRUE the support for DAC1 channel 1 is included.
50  * @note The default is @p FALSE.
51  */
52 #if !defined(PLATFORM_DAC_USE_DAC1) || defined(__DOXYGEN__)
53 #define PLATFORM_DAC_USE_DAC1 FALSE
54 #endif
55 /** @} */
56 
57 /*===========================================================================*/
58 /* Derived constants and error checks. */
59 /*===========================================================================*/
60 
61 /*===========================================================================*/
62 /* Driver data structures and types. */
63 /*===========================================================================*/
64 
65 /**
66  * @brief Type of a DAC channel index.
67  */
68 typedef uint32_t dacchannel_t;
69 
70 /**
71  * @brief Type of a structure representing an DAC driver.
72  */
73 typedef struct DACDriver DACDriver;
74 
75 /**
76  * @brief Type representing a DAC sample.
77  */
78 typedef uint16_t dacsample_t;
79 
80 /**
81  * @brief Possible DAC failure causes.
82  * @note Error codes are architecture dependent and should not relied
83  * upon.
84  */
85 typedef enum {
86  DAC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */
87  DAC_ERR_UNDERFLOW = 1 /**< DAC overflow condition. */
88 } dacerror_t;
89 
90 /**
91  * @brief DAC notification callback type.
92  *
93  * @param[in] dacp pointer to the @p DACDriver object triggering the
94  * @param[in] buffer pointer to the next semi-buffer to be filled
95  * @param[in] n number of buffer rows available starting from @p buffer
96  * callback
97  */
98 typedef void (*daccallback_t)(DACDriver *dacp, dacsample_t *buffer, size_t n);
99 
100 /**
101  * @brief DAC error callback type.
102  *
103  * @param[in] dacp pointer to the @p DACDriver object triggering the
104  * callback
105  * @param[in] err DAC error code
106  */
107 typedef void (*dacerrorcallback_t)(DACDriver *dacp, dacerror_t err);
108 
109 /**
110  * @brief DAC Conversion group structure.
111  */
112 typedef struct {
113  /**
114  * @brief Number of DAC channels.
115  */
116  uint32_t num_channels;
117  /**
118  * @brief Operation complete callback or @p NULL.
119  */
121  /**
122  * @brief Error handling callback or @p NULL.
123  */
125  /* End of the mandatory fields.*/
127 
128 /**
129  * @brief Driver configuration structure.
130  */
131 typedef struct {
132  /* End of the mandatory fields.*/
133  uint32_t dummy;
134 } DACConfig;
135 
136 /**
137  * @brief Structure representing a DAC driver.
138  */
139 struct DACDriver {
140  /**
141  * @brief Driver state.
142  */
144  /**
145  * @brief Conversion group.
146  */
148  /**
149  * @brief Samples buffer pointer.
150  */
152  /**
153  * @brief Samples buffer size.
154  */
155  uint16_t depth;
156  /**
157  * @brief Current configuration data.
158  */
160 #if DAC_USE_WAIT || defined(__DOXYGEN__)
161  /**
162  * @brief Waiting thread.
163  */
165 #endif /* DAC_USE_WAIT */
166 #if DAC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
167  /**
168  * @brief Mutex protecting the bus.
169  */
171 #endif /* DAC_USE_MUTUAL_EXCLUSION */
172 #if defined(DAC_DRIVER_EXT_FIELDS)
173  DAC_DRIVER_EXT_FIELDS
174 #endif
175  /* End of the mandatory fields.*/
176 };
177 
178 /*===========================================================================*/
179 /* Driver macros. */
180 /*===========================================================================*/
181 
182 /*===========================================================================*/
183 /* External declarations. */
184 /*===========================================================================*/
185 
186 #if PLATFORM_DAC_USE_DAC1 && !defined(__DOXYGEN__)
187 extern DACDriver DACD1;
188 #endif
189 
190 #ifdef __cplusplus
191 extern "C" {
192 #endif
193  void dac_lld_init(void);
194  void dac_lld_start(DACDriver *dacp);
195  void dac_lld_stop(DACDriver *dacp);
196  void dac_lld_put_channel(DACDriver *dacp,
197  dacchannel_t channel,
198  dacsample_t sample);
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif /* HAL_USE_DAC */
206 
207 #endif /* HAL_DAC_LLD_H */
208 
209 /** @} */
Driver configuration structure.
Definition: hal_dac_lld.h:131
daccallback_t end_cb
Operation complete callback or NULL.
Definition: hal_dac_lld.h:120
uint32_t dacchannel_t
Type of a DAC channel index.
Definition: hal_dac_lld.h:68
DACDriver DACD1
DAC1 driver identifier.
Definition: hal_dac_lld.c:39
dacsample_t * samples
Samples buffer pointer.
Definition: hal_dac_lld.h:151
dacstate_t
Driver state machine possible states.
Definition: hal_dac.h:70
thread_reference_t thread
Waiting thread.
Definition: hal_dac_lld.h:164
void dac_lld_start(DACDriver *dacp)
Configures and activates the DAC peripheral.
Definition: hal_dac_lld.c:77
void dac_lld_stop(DACDriver *dacp)
Deactivates the DAC peripheral.
Definition: hal_dac_lld.c:98
Structure representing a DAC driver.
Definition: hal_dac_lld.h:139
void dac_lld_init(void)
Low level DAC driver initialization.
Definition: hal_dac_lld.c:63
dacstate_t state
Driver state.
Definition: hal_dac_lld.h:143
dacerrorcallback_t error_cb
Error handling callback or NULL.
Definition: hal_dac_lld.h:124
void(* dacerrorcallback_t)(DACDriver *dacp, dacerror_t err)
DAC error callback type.
Definition: hal_dac_lld.h:107
mutex_t mutex
Mutex protecting the bus.
Definition: hal_dac_lld.h:170
void(* daccallback_t)(DACDriver *dacp, dacsample_t *buffer, size_t n)
DAC notification callback type.
Definition: hal_dac_lld.h:98
DAC Conversion group structure.
Definition: hal_dac_lld.h:112
void * thread_reference_t
Type of a thread reference.
Definition: osal.h:180
void dac_lld_put_channel(DACDriver *dacp, dacchannel_t channel, dacsample_t sample)
Outputs a value directly on a DAC channel.
Definition: hal_dac_lld.c:120
uint16_t depth
Samples buffer size.
Definition: hal_dac_lld.h:155
void dac_lld_start_conversion(DACDriver *dacp)
Starts a DAC conversion.
Definition: hal_dac_lld.c:145
dacerror_t
Possible DAC failure causes.
Definition: hal_dac_lld.h:85
uint32_t num_channels
Number of DAC channels.
Definition: hal_dac_lld.h:116
uint32_t mutex_t
Type of a mutex.
Definition: osal.h:223
uint16_t dacsample_t
Type representing a DAC sample.
Definition: hal_dac_lld.h:78
void dac_lld_stop_conversion(DACDriver *dacp)
Stops an ongoing conversion.
Definition: hal_dac_lld.c:160
const DACConversionGroup * grpp
Conversion group.
Definition: hal_dac_lld.h:147
const DACConfig * config
Current configuration data.
Definition: hal_dac_lld.h:159