libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
dmamux.c
Go to the documentation of this file.
1/** @addtogroup dmamux_file DMAMUX peripheral API
2@ingroup peripheral_apis
3
4@author @htmlonly &copy; @endhtmlonly 2019 Guillaume Revaillot <g.revaillot@gmail.com>
5
6LGPL License Terms @ref lgpl_license
7 */
8/*
9 * This file is part of the libopencm3 project.
10 *
11 * This library is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/**@{*/
26
28
29/*---------------------------------------------------------------------------*/
30/** @brief DMAMUX Reset DMA Channel
31
32Reset DMA Request configuration and interrupt flags for given DMA channel.
33
34@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
35@param[in] channel DMA channel number (@ref dma_ch)
36*/
37void dmamux_reset_dma_channel(uint32_t dmamux, uint8_t channel)
38{
39 DMAMUX_CxCR(dmamux, channel) = 0;
41}
42
43/*---------------------------------------------------------------------------*/
44/** @brief DMAMUX Set DMA Channel Request
45
46Set DMA Request Signal ID (@ref dmamux_cxcr_dmareq_id) for given DMA channel.
47Request must be set before enabling and after configuring said DMA channel.
48
49@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
50@param[in] channel DMA channel number (@ref dma_ch)
51@param[in] request_id DMA request (@ref dmamux_cxcr_dmareq_id)
52*/
53void dmamux_set_dma_channel_request(uint32_t dmamux, uint8_t channel, uint8_t request_id)
54{
55 uint32_t reg32 = DMAMUX_CxCR(dmamux, channel);
58 DMAMUX_CxCR(dmamux, channel) = reg32;
59}
60
61/*---------------------------------------------------------------------------*/
62/** @brief DMAMUX Get DMA Channel Request Selection
63
64@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
65@param[in] channel DMA channel number (@ref dma_ch)
66@returns DMA request (@ref dmamux_cxcr_dmareq_id)
67*/
68uint8_t dmamux_get_dma_channel_request(uint32_t dmamux, uint8_t channel)
69{
71}
72
73/*---------------------------------------------------------------------------*/
74/** @brief DMAMUX Enable DMA Request Event Generation
75
76@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
77@param[in] channel DMA channel number (@ref dma_ch)
78*/
79void dmamux_enable_dma_request_event_generation(uint32_t dmamux, uint8_t channel)
80{
81 DMAMUX_CxCR(dmamux, channel) |= DMAMUX_CxCR_EGE;
82}
83
84/*---------------------------------------------------------------------------*/
85/** @brief DMAMUX Disable DMA Request Event Generation
86
87@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
88@param[in] channel DMA channel number (@ref dma_ch)
89*/
90void dmamux_disable_dma_request_event_generation(uint32_t dmamux, uint8_t channel)
91{
92 DMAMUX_CxCR(dmamux, channel) &= ~DMAMUX_CxCR_EGE;
93}
94
95/*---------------------------------------------------------------------------*/
96/** @brief DMAMUX Set DMA Request Synchronization Input
97
98Set DMAMUX request synchronization input trigger signal id (@ref dmamux_cxcr_sync_id)
99for a given DMA channel.
100
101@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
102@param[in] channel DMA channel number (@ref dma_ch)
103@param[in] sync_input_id synchronization signal input id (@ref dmamux_cxcr_sync_id)
104*/
105void dmamux_set_dma_request_sync_input(uint32_t dmamux, uint8_t channel, uint8_t sync_input_id)
106{
107 uint32_t reg32 = DMAMUX_CxCR(dmamux, channel);
109 reg32 |= ((sync_input_id & DMAMUX_CxCR_SYNC_ID_MASK) << DMAMUX_CxCR_SYNC_ID_SHIFT);
110 DMAMUX_CxCR(dmamux, channel) = reg32;
111}
112
113/*---------------------------------------------------------------------------*/
114/** @brief DMAMUX Set DMA Request Synchronization Event Polarity
115
116Set DMAMUX request synchronization input signal polarity (@ref dmamux_cxcr_spol)
117for a given DMA channel.
118
119@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
120@param[in] channel DMA channel number (@ref dma_ch)
121@param[in] polarity synchronization signal input polarity (@ref dmamux_cxcr_spol)
122*/
123void dmamux_set_dma_request_sync_pol(uint32_t dmamux, uint8_t channel, uint8_t polarity)
124{
125 uint32_t reg32 = DMAMUX_CxCR(dmamux, channel);
127 reg32 |= ((polarity & DMAMUX_CxCR_SPOL_MASK) << DMAMUX_CxCR_SPOL_SHIFT);
128 DMAMUX_CxCR(dmamux, channel) = reg32;
129}
130
131/*---------------------------------------------------------------------------*/
132/** @brief DMAMUX Enable DMA Request Synchronization
133
134Enable DMAMUX request synchronization for a given DMA channel, propagating DMA
135request when configured event edge (DMAREQ_CxCR_SPOL) is detected on previously
136selected synchronization trigger input id.
137
138@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
139@param[in] channel DMA channel number (@ref dma_ch)
140*/
141void dmamux_enable_dma_request_sync(uint32_t dmamux, uint8_t channel)
142{
143 DMAMUX_CxCR(dmamux, channel) |= DMAMUX_CxCR_SE;
144}
145
146/*---------------------------------------------------------------------------*/
147/** @brief DMAMUX Disable DMA Request Synchronization
148
149@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
150@param[in] channel DMA channel number (@ref dma_ch)
151*/
152void dmamux_disable_dma_request_sync(uint32_t dmamux, uint8_t channel)
153{
154 DMAMUX_CxCR(dmamux, channel) &= ~DMAMUX_CxCR_SE;
155}
156
157/*---------------------------------------------------------------------------*/
158/** @brief DMAMUX Set DMA Request NBREQ To Forward
159
160Set number of request to forward (minus 1) to the dma controller after a synchronization
161event. This must be configured with synchronization and event generation disabled.
162
163@param[in] dmamux DMAMUX Controller base address (@ref dmamux_reg_base)
164@param[in] channel DMA Channel Number (@ref dma_ch)
165@param[in] nbreq Number of DMA Requests to Forward - minus 1 (0..31)
166*/
167void dmamux_set_dma_request_sync_nbreq(uint32_t dmamux, uint8_t channel, uint8_t nbreq)
168{
169 uint32_t reg32 = DMAMUX_CxCR(dmamux, channel);
171 reg32 |= ((nbreq & DMAMUX_CxCR_NBREQ_MASK) << DMAMUX_CxCR_NBREQ_SHIFT);
172 DMAMUX_CxCR(dmamux, channel) = reg32;
173}
174
175/*---------------------------------------------------------------------------*/
176/** @brief DMAMUX Enable DMA Request Overrun Interrupt
177
178@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
179@param[in] channel DMA channel number (@ref dma_ch)
180*/
181void dmamux_enable_dma_request_sync_overrun_interrupt(uint32_t dmamux, uint8_t channel)
182{
183 DMAMUX_CxCR(dmamux, channel) |= DMAMUX_CxCR_SOIE;
184}
185
186/*---------------------------------------------------------------------------*/
187/** @brief DMAMUX Disable DMA Request Overrun Interrupt
188
189@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
190@param[in] channel DMA channel number (@ref dma_ch)
191*/
192void dmamux_disable_dma_request_sync_overrun_interrupt(uint32_t dmamux, uint8_t channel)
193{
194 DMAMUX_CxCR(dmamux, channel) &= ~DMAMUX_CxCR_SOIE;
195}
196
197/*---------------------------------------------------------------------------*/
198/** @brief DMAMUX Get DMA Request Synchronization Overrun Interrupt Flag
199
200Get DMA Request Synchronization Overrun Interrupt for given DMA channel
201
202@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
203@param[in] channel DMA channel number (@ref dma_ch)
204@returns DMA Channel Synchronization Overrun Interrupt Flag
205*/
206uint32_t dmamux_get_dma_request_sync_overrun(uint32_t dmamux, uint8_t channel)
207{
208 return DMAMUX_CSR(dmamux) & DMAMUX_CSR_SOF(channel);
209}
210
211/*---------------------------------------------------------------------------*/
212/** @brief DMAMUX Clear DMA Request Synchronization Overrun Interrupt Flag
213
214Clear DMA Request Synchronization Overrun Interrupt for given DMA channel
215
216@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
217@param[in] channel DMA channel number (@ref dma_ch)
218*/
219void dmamux_clear_dma_request_sync_overrun(uint32_t dmamux, uint8_t channel)
220{
221 DMAMUX_CFR(dmamux) = DMAMUX_CFR_CSOF(channel);
222}
223
224/*---------------------------------------------------------------------------*/
225/** @brief DMAMUX Reset Request Generator Channel
226
227Reset Request Generator Channel Configuration and interrupt flags.
228
229@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
230@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
231*/
232void dmamux_reset_request_generator_channel(uint32_t dmamux, uint8_t rg_channel)
233{
234 DMAMUX_RGxCR(dmamux, rg_channel) = 0;
236}
237
238/*---------------------------------------------------------------------------*/
239/** @brief DMAMUX Enable Request Generator Channel
240
241Enable Request Generator Channel, Producting DMA Request on input signal trigger.
242These Requests are usable by the DMA Request Router.
243
244@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
245@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
246*/
247void dmamux_enable_request_generator(uint32_t dmamux, uint8_t rg_channel)
248{
249 DMAMUX_RGxCR(dmamux, rg_channel) |= DMAMUX_RGxCR_GE;
250}
251
252/*---------------------------------------------------------------------------*/
253/** @brief DMAMUX Disable Request Generator Channel
254
255@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
256@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
257*/
258void dmamux_disable_request_generator(uint32_t dmamux, uint8_t rg_channel)
259{
260 DMAMUX_RGxCR(dmamux, rg_channel) &= ~DMAMUX_RGxCR_GE;
261}
262
263/*---------------------------------------------------------------------------*/
264/** @brief DMAMUX Set Request Generator Input Trigger Signal
265
266Set DMAMUX Request Generator input signal id (@ref dmamux_rgxcr_sig_id) for given
267Request Generator Channel.
268
269@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
270@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
271@param[in] sig_id Request Generator Channel Input Signal Id (@ref dmamux_rgxcr_sig_id)
272*/
273void dmamux_set_request_generator_trigger(uint32_t dmamux, uint8_t rg_channel, uint8_t sig_id)
274{
275 uint32_t reg32 = DMAMUX_RGxCR(dmamux, rg_channel);
278 DMAMUX_RGxCR(dmamux, rg_channel) = reg32;
279}
280
281/*---------------------------------------------------------------------------*/
282/** @brief DMAMUX Set Request Generator Trigger Polarity
283
284Set DMAMUX Request Generator input signal polarity (@ref dmamux_rgxcr_gpol).
285
286@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
287@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
288@param[in] polarity Trigger signal input polarity (@ref dmamux_rgxcr_gpol)
289*/
290void dmamux_set_request_generator_trigger_pol(uint32_t dmamux, uint8_t rg_channel, uint8_t polarity)
291{
292 uint32_t reg32 = DMAMUX_RGxCR(dmamux, rg_channel);
294 reg32 |= ((polarity & DMAMUX_RGxCR_GPOL_MASK) << DMAMUX_RGxCR_GPOL_SHIFT);
295 DMAMUX_RGxCR(dmamux, rg_channel) = reg32;
296}
297
298/*---------------------------------------------------------------------------*/
299/** @brief DMAMUX Set Request Generator Trigger GNBREQ
300
301Set number of request to generate (minus 1). This must be configured while
302given Request Generator is disabled.
303
304@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
305@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
306@param[in] gnbreq Number of DMA Requests to Generate - minus 1 (0..31).
307*/
308void dmamux_set_request_generator_trigger_gnbreq(uint32_t dmamux, uint8_t rg_channel, uint8_t gnbreq)
309{
310 uint32_t reg32 = DMAMUX_RGxCR(dmamux, rg_channel);
313 DMAMUX_RGxCR(dmamux, rg_channel) = reg32;
314}
315
316/*---------------------------------------------------------------------------*/
317/** @brief DMAMUX Enable Request Generator Trigger Overrun Interrupt
318
319@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
320@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
321*/
322void dmamux_enable_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
323{
324 DMAMUX_RGxCR(dmamux, rg_channel) |= DMAMUX_RGxCR_OIE;
325}
326
327/*---------------------------------------------------------------------------*/
328/** @brief DMAMUX Disable Request Generator Trigger Overrun Interrupt
329
330@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
331@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
332*/
333void dmamux_disable_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
334{
335 DMAMUX_RGxCR(dmamux, rg_channel) &= ~DMAMUX_RGxCR_OIE;
336}
337
338/*---------------------------------------------------------------------------*/
339/** @brief DMAMUX Get Request Generator Trigger Overrun Interrupt Flag
340
341Get DMA Request Synchronization Overrun Interrupt Flag for given Request Generator Channel
342
343@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
344@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
345@returns Request Generator Channel Trigger Overrun Interrupt Flag
346*/
347uint32_t dmamux_get_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
348{
349 return DMAMUX_RGSR(dmamux) & DMAMUX_RGSR_OF(rg_channel);
350}
351
352/*---------------------------------------------------------------------------*/
353/** @brief DMAMUX Clear Request Generator Trigger Overrun Interrupt Flag
354
355Clear DMA Request Synchronization Overrun Interrupt Flag for given Request Generator
356Channel
357
358@param[in] dmamux DMAMUX controller base address (@ref dmamux_reg_base)
359@param[in] rg_channel Request Generator Channel Number (@ref dmamux_rg_channel)
360*/
361void dmamux_clear_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
362{
363 DMAMUX_RGCFR(dmamux) = DMAMUX_RGCFR_COF(rg_channel);
364}
365
366
367/**@}*/
#define DMAMUX_CFR_CSOF(dma_channel)
DMAMUX_CFR_CSOF Clear synchronization overrun event flag.
#define DMAMUX_CSR_SOF(dma_channel)
DMAMUX_CSR_SOF Synchronization overrun event flag.
#define DMAMUX_CxCR_SOIE
DMAMUX_CxCR_SOIE Interrupt enable at synchronization event overrun.
#define DMAMUX_CxCR_SYNC_ID_SHIFT
DMAMUX_CxCR_SYNC_ID Synchronization input selected.
#define DMAMUX_CxCR_NBREQ_MASK
#define DMAMUX_CxCR_NBREQ_SHIFT
DMAMUX_CxCR_NBREQ Number (minus 1) of DMA requests to forward.
#define DMAMUX_CxCR_SPOL_SHIFT
#define DMAMUX_CxCR_DMAREQ_ID_SHIFT
DMAMUX_CxCR_DMAREQ_ID Input DMA request line selected.
#define DMAMUX_CxCR_SYNC_ID_MASK
#define DMAMUX_CxCR_DMAREQ_ID_MASK
#define DMAMUX_CxCR_EGE
DMAMUX_CxCR_EGE Event generation enable/disable.
#define DMAMUX_CxCR_SE
DMAMUX_CxCR_SE Synchronous operating mode enable/disable.
#define DMAMUX_CxCR_SPOL_MASK
#define DMAMUX_RGCFR(dmamux_base)
#define DMAMUX_CxCR(dmamux_base, dma_channel)
#define DMAMUX_RGSR(dmamux_base)
#define DMAMUX_CFR(dmamux_base)
#define DMAMUX_RGxCR(dmamux_base, rg_channel)
#define DMAMUX_CSR(dmamux_base)
void dmamux_set_request_generator_trigger(uint32_t dmamux, uint8_t rg_channel, uint8_t sig_id)
DMAMUX Set Request Generator Input Trigger Signal.
Definition: dmamux.c:273
void dmamux_disable_dma_request_sync_overrun_interrupt(uint32_t dmamux, uint8_t channel)
DMAMUX Disable DMA Request Overrun Interrupt.
Definition: dmamux.c:192
void dmamux_enable_dma_request_sync(uint32_t dmamux, uint8_t channel)
DMAMUX Enable DMA Request Synchronization.
Definition: dmamux.c:141
void dmamux_disable_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
DMAMUX Disable Request Generator Trigger Overrun Interrupt.
Definition: dmamux.c:333
void dmamux_enable_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
DMAMUX Enable Request Generator Trigger Overrun Interrupt.
Definition: dmamux.c:322
void dmamux_enable_dma_request_sync_overrun_interrupt(uint32_t dmamux, uint8_t channel)
DMAMUX Enable DMA Request Overrun Interrupt.
Definition: dmamux.c:181
uint32_t dmamux_get_dma_request_sync_overrun(uint32_t dmamux, uint8_t channel)
DMAMUX Get DMA Request Synchronization Overrun Interrupt Flag.
Definition: dmamux.c:206
void dmamux_disable_request_generator(uint32_t dmamux, uint8_t rg_channel)
DMAMUX Disable Request Generator Channel.
Definition: dmamux.c:258
void dmamux_clear_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
DMAMUX Clear Request Generator Trigger Overrun Interrupt Flag.
Definition: dmamux.c:361
void dmamux_reset_dma_channel(uint32_t dmamux, uint8_t channel)
DMAMUX Reset DMA Channel.
Definition: dmamux.c:37
void dmamux_enable_dma_request_event_generation(uint32_t dmamux, uint8_t channel)
DMAMUX Enable DMA Request Event Generation.
Definition: dmamux.c:79
void dmamux_clear_dma_request_sync_overrun(uint32_t dmamux, uint8_t channel)
DMAMUX Clear DMA Request Synchronization Overrun Interrupt Flag.
Definition: dmamux.c:219
void dmamux_set_dma_channel_request(uint32_t dmamux, uint8_t channel, uint8_t request_id)
DMAMUX Set DMA Channel Request.
Definition: dmamux.c:53
uint8_t dmamux_get_dma_channel_request(uint32_t dmamux, uint8_t channel)
DMAMUX Get DMA Channel Request Selection.
Definition: dmamux.c:68
uint32_t dmamux_get_request_generator_trigger_overrun_interrupt(uint32_t dmamux, uint8_t rg_channel)
DMAMUX Get Request Generator Trigger Overrun Interrupt Flag.
Definition: dmamux.c:347
void dmamux_set_request_generator_trigger_gnbreq(uint32_t dmamux, uint8_t rg_channel, uint8_t gnbreq)
DMAMUX Set Request Generator Trigger GNBREQ.
Definition: dmamux.c:308
void dmamux_set_dma_request_sync_input(uint32_t dmamux, uint8_t channel, uint8_t sync_input_id)
DMAMUX Set DMA Request Synchronization Input.
Definition: dmamux.c:105
void dmamux_set_dma_request_sync_nbreq(uint32_t dmamux, uint8_t channel, uint8_t nbreq)
DMAMUX Set DMA Request NBREQ To Forward.
Definition: dmamux.c:167
void dmamux_disable_dma_request_sync(uint32_t dmamux, uint8_t channel)
DMAMUX Disable DMA Request Synchronization.
Definition: dmamux.c:152
void dmamux_enable_request_generator(uint32_t dmamux, uint8_t rg_channel)
DMAMUX Enable Request Generator Channel.
Definition: dmamux.c:247
void dmamux_set_dma_request_sync_pol(uint32_t dmamux, uint8_t channel, uint8_t polarity)
DMAMUX Set DMA Request Synchronization Event Polarity.
Definition: dmamux.c:123
void dmamux_reset_request_generator_channel(uint32_t dmamux, uint8_t rg_channel)
DMAMUX Reset Request Generator Channel.
Definition: dmamux.c:232
void dmamux_disable_dma_request_event_generation(uint32_t dmamux, uint8_t channel)
DMAMUX Disable DMA Request Event Generation.
Definition: dmamux.c:90
void dmamux_set_request_generator_trigger_pol(uint32_t dmamux, uint8_t rg_channel, uint8_t polarity)
DMAMUX Set Request Generator Trigger Polarity.
Definition: dmamux.c:290
#define DMAMUX_RGCFR_COF(rg_channel)
DMAMUX_RGCFR_COF COF Clear trigger event overrun flag.
#define DMAMUX_RGSR_OF(rg_channel)
DMAMUX_RGSR_OF Trigger OF event overrun flag.
#define DMAMUX_RGxCR_GNBREQ_MASK
#define DMAMUX_RGxCR_GNBREQ_SHIFT
DMAMUX_RGxCR_GNBREQ GNBREQ Number (minus 1) of DMA requests to generate.
#define DMAMUX_RGxCR_GE
DMAMUX_RGxCR_GE GE DMA request generator channel enable/disable.
#define DMAMUX_RGxCR_OIE
DMAMUX_RGxCR_OIE OIE Interrupt enable at trigger event overrun.
#define DMAMUX_RGxCR_SIG_ID_MASK
#define DMAMUX_RGxCR_SIG_ID_SHIFT
DMAMUX_RGxCR_SIG_ID SIG_ID DMA request trigger input selected.
#define DMAMUX_RGxCR_GPOL_SHIFT
#define DMAMUX_RGxCR_GPOL_MASK