1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
/*This file is prepared for Doxygen automatic documentation generation.*/
/*! \file *********************************************************************
*
* \brief PDCA driver for AVR32 UC3.
*
* This file defines a useful set of functions for the PDCA interface on AVR32
* devices.
*
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
* - Supported devices: All AVR32 devices with a PDCA module.
* - AppNote:
*
* \author Atmel Corporation: http://www.atmel.com \n
* Support and FAQ: http://support.atmel.no/
*
******************************************************************************/
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of Atmel may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 4. This software may only be redistributed and used in connection with an Atmel
* AVR product.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
*/
#include "compiler.h"
#include "pdca.h"
volatile avr32_pdca_channel_t *pdca_get_handler(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = &AVR32_PDCA.channel[pdca_ch_number];
if (pdca_ch_number >= AVR32_PDCA_CHANNEL_LENGTH)
return (volatile avr32_pdca_channel_t *)PDCA_INVALID_ARGUMENT;
return pdca_channel;
}
int pdca_init_channel(unsigned int pdca_ch_number, const pdca_channel_options_t *opt)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_disable_interrupt_transfer_complete(pdca_ch_number); // disable channel interrupt
pdca_disable_interrupt_reload_counter_zero(pdca_ch_number); // disable channel interrupt
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
if (global_interrupt_enabled) Disable_global_interrupt();
pdca_channel->mar = (unsigned long)opt->addr;
pdca_channel->tcr = opt->size;
pdca_channel->psr = opt->pid;
pdca_channel->marr = (unsigned long)opt->r_addr;
pdca_channel->tcrr = opt->r_size;
pdca_channel->mr =
#if (defined AVR32_PDCA_120_H_INCLUDED ) || (defined AVR32_PDCA_121_H_INCLUDED ) || (defined AVR32_PDCA_122_H_INCLUDED )
opt->etrig << AVR32_PDCA_ETRIG_OFFSET |
#endif // #ifdef AVR32_PDCA_120_H_INCLUDED
opt->transfer_size << AVR32_PDCA_SIZE_OFFSET;
pdca_channel->cr = AVR32_PDCA_ECLR_MASK;
pdca_channel->isr;
if (global_interrupt_enabled) Enable_global_interrupt();
return PDCA_SUCCESS;
}
unsigned int pdca_get_channel_status(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
return (pdca_channel->sr & AVR32_PDCA_TEN_MASK) != 0;
}
void pdca_disable(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
// Disable transfer
pdca_channel->cr = AVR32_PDCA_TDIS_MASK;
}
void pdca_enable(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
// Enable transfer
pdca_channel->cr = AVR32_PDCA_TEN_MASK;
}
unsigned int pdca_get_load_size(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
return pdca_channel->tcr;
}
void pdca_load_channel(unsigned int pdca_ch_number, volatile void *addr, unsigned int size)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
if (global_interrupt_enabled) Disable_global_interrupt();
pdca_channel->mar = (unsigned long)addr;
pdca_channel->tcr = size;
pdca_channel->cr = AVR32_PDCA_ECLR_MASK;
pdca_channel->isr;
if (global_interrupt_enabled) Enable_global_interrupt();
}
unsigned int pdca_get_reload_size(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
return pdca_channel->tcrr;
}
void pdca_reload_channel(unsigned int pdca_ch_number, volatile void *addr, unsigned int size)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
if (global_interrupt_enabled) Disable_global_interrupt();
// set up next memory address
pdca_channel->marr = (unsigned long)addr;
// set up next memory size
pdca_channel->tcrr = size;
pdca_channel->cr = AVR32_PDCA_ECLR_MASK;
pdca_channel->isr;
if (global_interrupt_enabled) Enable_global_interrupt();
}
void pdca_set_peripheral_select(unsigned int pdca_ch_number, unsigned int pid)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_channel->psr = pid;
}
void pdca_set_transfer_size(unsigned int pdca_ch_number, unsigned int transfer_size)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_channel->mr = (pdca_channel->mr & ~AVR32_PDCA_SIZE_MASK) |
transfer_size << AVR32_PDCA_SIZE_OFFSET;
}
#if (defined AVR32_PDCA_120_H_INCLUDED ) || (defined AVR32_PDCA_121_H_INCLUDED ) || (defined AVR32_PDCA_122_H_INCLUDED )
void pdca_disable_event_trigger(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_channel->mr &= ~AVR32_PDCA_ETRIG_MASK;
}
void pdca_enable_event_trigger(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_channel->mr |= AVR32_PDCA_ETRIG_MASK;
}
#endif // #ifdef AVR32_PDCA_120_H_INCLUDED
void pdca_disable_interrupt_transfer_error(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
if (global_interrupt_enabled) Disable_global_interrupt();
pdca_channel->idr = AVR32_PDCA_TERR_MASK;
pdca_channel->isr;
if (global_interrupt_enabled) Enable_global_interrupt();
}
void pdca_enable_interrupt_transfer_error(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_channel->ier = AVR32_PDCA_TERR_MASK;
}
void pdca_disable_interrupt_transfer_complete(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
if (global_interrupt_enabled) Disable_global_interrupt();
pdca_channel->idr = AVR32_PDCA_TRC_MASK;
pdca_channel->isr;
if (global_interrupt_enabled) Enable_global_interrupt();
}
void pdca_enable_interrupt_transfer_complete(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_channel->ier = AVR32_PDCA_TRC_MASK;
}
void pdca_disable_interrupt_reload_counter_zero(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
if (global_interrupt_enabled) Disable_global_interrupt();
pdca_channel->idr = AVR32_PDCA_RCZ_MASK;
pdca_channel->isr;
if (global_interrupt_enabled) Enable_global_interrupt();
}
void pdca_enable_interrupt_reload_counter_zero(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
pdca_channel->ier = AVR32_PDCA_RCZ_MASK;
}
unsigned long pdca_get_transfer_status(unsigned int pdca_ch_number)
{
// get the correct channel pointer
volatile avr32_pdca_channel_t *pdca_channel = pdca_get_handler(pdca_ch_number);
return pdca_channel->isr;
}
|