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

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

Adding new version

File size: 6.2 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 EIC driver for AVR32 UC3.
7 *
8 * AVR32 External Interrupt Controller driver module.
9 *
10 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
11 * - Supported devices:  All AVR32 devices with an EIC module can be used.
12 * - AppNote:
13 *
14 * \author               Atmel Corporation: http://www.atmel.com \n
15 *                       Support and FAQ: http://support.atmel.no/
16 *
17 ******************************************************************************/
18
19/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions are met:
23 *
24 * 1. Redistributions of source code must retain the above copyright notice, this
25 * list of conditions and the following disclaimer.
26 *
27 * 2. Redistributions in binary form must reproduce the above copyright notice,
28 * this list of conditions and the following disclaimer in the documentation
29 * and/or other materials provided with the distribution.
30 *
31 * 3. The name of Atmel may not be used to endorse or promote products derived
32 * from this software without specific prior written permission.
33 *
34 * 4. This software may only be redistributed and used in connection with an Atmel
35 * AVR product.
36 *
37 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
39 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
40 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
41 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
47 *
48 */
49
50#include <avr32/io.h>
51#include "compiler.h"
52#include "preprocessor.h"
53#include "eic.h"
54
55
56
57void eic_init(volatile avr32_eic_t *eic, const eic_options_t *opt, unsigned int nb_lines)
58{
59  int i;
60  for (i = 0; i < nb_lines; i++)
61  {
62    // Set up mode level
63    eic->mode = (opt[i].eic_mode == 1) ? (eic->mode | (1 << opt[i].eic_line)) : (eic->mode & ~(1 << opt[i].eic_line));
64    // Set up edge type
65    eic->edge = (opt[i].eic_edge == 1) ? (eic->edge | (1 << opt[i].eic_line)) : (eic->edge & ~(1 << opt[i].eic_line));
66    // Set up level
67    eic->level = (opt[i].eic_level == 1) ? (eic->level | (1 << opt[i].eic_line)) : (eic->level & ~(1 << opt[i].eic_line));
68    // Set up if filter is used
69    eic->filter = (opt[i].eic_filter == 1) ? (eic->filter | (1 << opt[i].eic_line)) : (eic->filter & ~(1 << opt[i].eic_line));
70    // Set up which mode is used : asynchronous mode/ synchronous mode
71    eic->async = (opt[i].eic_async == 1) ? (eic->async | (1 << opt[i].eic_line)) : (eic->async & ~(1 << opt[i].eic_line));
72  }
73}
74
75void eic_enable_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
76{
77  eic->en = mask_lines;
78}
79
80void eic_enable_line(volatile avr32_eic_t *eic, unsigned int line_number)
81{
82  // Enable line line_number
83  eic->en = 1 << line_number;
84}
85
86void eic_disable_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
87{
88  eic->dis = mask_lines;
89}
90
91void eic_disable_line(volatile avr32_eic_t *eic, unsigned int line_number)
92{
93  // Disable line line_number
94  eic->dis = 1 << line_number;
95}
96
97Bool eic_is_line_enabled(volatile avr32_eic_t *eic, unsigned int line_number)
98{
99  return (eic->ctrl & (1 << line_number)) != 0;
100}
101
102void eic_enable_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
103{
104  eic->ier = mask_lines;
105}
106
107void eic_enable_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number)
108{
109  // Enable line line_number
110  eic->ier = 1 << line_number;
111}
112
113void eic_disable_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
114{
115  Bool global_interrupt_enabled = Is_global_interrupt_enabled();
116
117  if (global_interrupt_enabled) Disable_global_interrupt();
118  eic->idr = mask_lines;
119  eic->imr;
120  if (global_interrupt_enabled) Enable_global_interrupt();
121}
122
123void eic_disable_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number)
124{
125  Bool global_interrupt_enabled = Is_global_interrupt_enabled();
126
127  // Disable line line_number
128  if (global_interrupt_enabled) Disable_global_interrupt();
129  eic->idr = 1 << line_number;
130  eic->imr;
131  if (global_interrupt_enabled) Enable_global_interrupt();
132}
133
134Bool eic_is_interrupt_line_enabled(volatile avr32_eic_t *eic, unsigned int line_number)
135{
136  return (eic->imr & (1 << line_number)) != 0;
137}
138
139void eic_clear_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
140{
141  Bool global_interrupt_enabled = Is_global_interrupt_enabled();
142
143  if (global_interrupt_enabled) Disable_global_interrupt();
144  eic->icr = mask_lines;
145  eic->isr;
146  if (global_interrupt_enabled) Enable_global_interrupt();
147}
148
149void eic_clear_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number)
150{
151  Bool global_interrupt_enabled = Is_global_interrupt_enabled();
152
153  // Clear line line_number
154  if (global_interrupt_enabled) Disable_global_interrupt();
155  eic->icr = 1 << line_number;
156  eic->isr;
157  if (global_interrupt_enabled) Enable_global_interrupt();
158}
159
160Bool eic_is_interrupt_line_pending(volatile avr32_eic_t *eic, unsigned int line_number)
161{
162  return (eic->isr & (1 << line_number)) != 0;
163}
164
165#if !defined(AVR32_EIC_301_H_INCLUDED)
166void eic_enable_interrupt_scan(volatile avr32_eic_t *eic,unsigned int presc)
167{
168  // Enable SCAN function with PRESC value
169  eic->scan |= (presc << AVR32_EIC_SCAN_PRESC_OFFSET) | (1 << AVR32_EIC_SCAN_EN_OFFSET);
170}
171
172void eic_disable_interrupt_scan(volatile avr32_eic_t *eic)
173{
174  // Disable SCAN function
175  eic->scan = 0 << AVR32_EIC_SCAN_EN_OFFSET;
176}
177
178unsigned long eic_get_interrupt_pad_scan(volatile avr32_eic_t *eic)
179{
180  // Return pad number that causes interrupt
181  return(eic->scan>>AVR32_EIC_SCAN_PIN_OFFSET);
182}
183#endif
Note: See TracBrowser for help on using the repository browser.