source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifiHD/src/SOFTWARE_FRAMEWORK/DRIVERS/PDCA/pdca.c @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

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