Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
3 | <title>Procyon AVRlib: extint.c Source File</title> |
||
4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
5 | </head><body> |
||
6 | <!-- Generated by Doxygen 1.4.2 --> |
||
7 | <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
||
8 | <h1>extint.c</h1><a href="extint_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file extint.c \brief External-Interrupt function library. */</span> |
||
9 | 00002 <span class="comment">//*****************************************************************************</span> |
||
10 | 00003 <span class="comment">//</span> |
||
11 | 00004 <span class="comment">// File Name : 'extint.c'</span> |
||
12 | 00005 <span class="comment">// Title : External-Interrupt function library</span> |
||
13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002-2004</span> |
||
14 | 00007 <span class="comment">// Created : 5/10/2002</span> |
||
15 | 00008 <span class="comment">// Revised : 11/16/2004</span> |
||
16 | 00009 <span class="comment">// Version : 1.0</span> |
||
17 | 00010 <span class="comment">// Target MCU : Atmel AVR Series</span> |
||
18 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
19 | 00012 <span class="comment">//</span> |
||
20 | 00013 <span class="comment">// Notes: This library provides convenient standardized configuration and</span> |
||
21 | 00014 <span class="comment">// access to external interrupts. The library is designed to make</span> |
||
22 | 00015 <span class="comment">// it possible to write code that uses external interrupts without</span> |
||
23 | 00016 <span class="comment">// digging into the processor datasheets to find register names and</span> |
||
24 | 00017 <span class="comment">// bit-defines. The library also strives to allow code which uses</span> |
||
25 | 00018 <span class="comment">// external interrupts to more easily cross-compile between different</span> |
||
26 | 00019 <span class="comment">// microcontrollers.</span> |
||
27 | 00020 <span class="comment">//</span> |
||
28 | 00021 <span class="comment">// NOTE: Using this library has certain advantages, but also adds</span> |
||
29 | 00022 <span class="comment">// overhead and latency to interrupt servicing. If the smallest</span> |
||
30 | 00023 <span class="comment">// code size or fastest possible latency is needed, do NOT use this</span> |
||
31 | 00024 <span class="comment">// library; link your interrupts directly.</span> |
||
32 | 00025 <span class="comment">//</span> |
||
33 | 00026 <span class="comment">//*****************************************************************************</span> |
||
34 | 00027 |
||
35 | 00028 <span class="preprocessor">#include <avr/io.h></span> |
||
36 | 00029 <span class="preprocessor">#include <avr/interrupt.h></span> |
||
37 | 00030 |
||
38 | 00031 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
39 | 00032 <span class="preprocessor">#include "<a class="code" href="extint_8h.html">extint.h</a>"</span> |
||
40 | 00033 |
||
41 | 00034 <span class="comment">// Global variables</span> |
||
42 | 00035 <span class="keyword">typedef</span> void (*voidFuncPtr)(void); |
||
43 | 00036 <span class="keyword">volatile</span> <span class="keyword">static</span> voidFuncPtr ExtIntFunc[EXTINT_NUM_INTERRUPTS]; |
||
44 | 00037 |
||
45 | 00038 <span class="comment">// functions</span> |
||
46 | 00039 <span class="comment"></span> |
||
47 | 00040 <span class="comment">//! initializes extint library</span> |
||
48 | <a name="l00041"></a><a class="code" href="extint_8h.html#a14">00041</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a2">extintInit</a>(<span class="keywordtype">void</span>) |
||
49 | 00042 { |
||
50 | 00043 u08 intNum; |
||
51 | 00044 <span class="comment">// detach all user functions from interrupts</span> |
||
52 | 00045 <span class="keywordflow">for</span>(intNum=0; intNum<EXTINT_NUM_INTERRUPTS; intNum++) |
||
53 | 00046 <a class="code" href="extint_8c.html#a5">extintDetach</a>(intNum); |
||
54 | 00047 |
||
55 | 00048 } |
||
56 | 00049 <span class="comment"></span> |
||
57 | 00050 <span class="comment">//! Configure external interrupt trigger</span> |
||
58 | 00051 <span class="comment"></span><span class="comment">// NOTE: this function is not complete!!!</span> |
||
59 | <a name="l00052"></a><a class="code" href="extint_8h.html#a15">00052</a> <span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a3">extintConfigure</a>(u08 interruptNum, u08 configuration) |
||
60 | 00053 { |
||
61 | 00054 <span class="keywordflow">if</span>(interruptNum == <a class="code" href="extint_8h.html#a0">EXTINT0</a>) |
||
62 | 00055 { |
||
63 | 00056 MCUCR &= ~((1<<ISC01) | (1<<ISC00)); |
||
64 | 00057 MCUCR |= configuration; |
||
65 | 00058 } |
||
66 | 00059 <span class="preprocessor"> #ifdef SIG_INTERRUPT1</span> |
||
67 | 00060 <span class="preprocessor"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(interruptNum == <a class="code" href="extint_8h.html#a1">EXTINT1</a>) |
||
68 | 00061 { |
||
69 | 00062 MCUCR &= ~((1<<ISC11) | (1<<ISC10)); |
||
70 | 00063 MCUCR |= configuration<<2; |
||
71 | 00064 } |
||
72 | 00065 <span class="preprocessor"> #endif</span> |
||
73 | 00066 <span class="preprocessor"></span><span class="preprocessor"> #ifdef SIG_INTERRUPT2</span> |
||
74 | 00067 <span class="preprocessor"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(interruptNum == <a class="code" href="extint_8h.html#a2">EXTINT2</a>) |
||
75 | 00068 { |
||
76 | 00069 <span class="keywordflow">if</span>(configuration == <a class="code" href="extint_8h.html#a11">EXTINT_EDGE_RISING</a>) |
||
77 | 00070 sbi(MCUCSR, ISC2); |
||
78 | 00071 <span class="keywordflow">else</span> |
||
79 | 00072 cbi(MCUCSR, ISC2); |
||
80 | 00073 } |
||
81 | 00074 <span class="preprocessor"> #endif</span> |
||
82 | 00075 <span class="preprocessor"></span> <span class="comment">// need to handle a lot more cases</span> |
||
83 | 00076 <span class="comment">// and differences between processors.</span> |
||
84 | 00077 <span class="comment">// looking for clean way to do it...</span> |
||
85 | 00078 } |
||
86 | 00079 <span class="comment"></span> |
||
87 | 00080 <span class="comment">//! Attach a user function to an external interrupt</span> |
||
88 | <a name="l00081"></a><a class="code" href="extint_8h.html#a16">00081</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a4">extintAttach</a>(u08 interruptNum, <span class="keywordtype">void</span> (*userHandler)(<span class="keywordtype">void</span>) ) |
||
89 | 00082 { |
||
90 | 00083 <span class="comment">// make sure the interrupt number is within bounds</span> |
||
91 | 00084 <span class="keywordflow">if</span>(interruptNum < EXTINT_NUM_INTERRUPTS) |
||
92 | 00085 { |
||
93 | 00086 <span class="comment">// set the interrupt function to run</span> |
||
94 | 00087 <span class="comment">// the supplied user's function</span> |
||
95 | 00088 ExtIntFunc[interruptNum] = userHandler; |
||
96 | 00089 } |
||
97 | 00090 } |
||
98 | 00091 <span class="comment"></span> |
||
99 | 00092 <span class="comment">//! Detach a user function from an external interrupt</span> |
||
100 | <a name="l00093"></a><a class="code" href="extint_8h.html#a17">00093</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="extint_8c.html#a5">extintDetach</a>(u08 interruptNum) |
||
101 | 00094 { |
||
102 | 00095 <span class="comment">// make sure the interrupt number is within bounds</span> |
||
103 | 00096 <span class="keywordflow">if</span>(interruptNum < EXTINT_NUM_INTERRUPTS) |
||
104 | 00097 { |
||
105 | 00098 <span class="comment">// set the interrupt function to run</span> |
||
106 | 00099 <span class="comment">// the supplied user's function</span> |
||
107 | 00100 ExtIntFunc[interruptNum] = 0; |
||
108 | 00101 } |
||
109 | 00102 } |
||
110 | 00103 <span class="comment"></span> |
||
111 | 00104 <span class="comment">//! Interrupt handler for INT0</span> |
||
112 | <a name="l00105"></a><a class="code" href="extint_8c.html#a6">00105</a> <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT0) |
||
113 | 00106 { |
||
114 | 00107 <span class="comment">// if a user function is defined, execute it</span> |
||
115 | 00108 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a0">EXTINT0</a>]) |
||
116 | 00109 ExtIntFunc[<a class="code" href="extint_8h.html#a0">EXTINT0</a>](); |
||
117 | 00110 } |
||
118 | 00111 |
||
119 | 00112 <span class="preprocessor">#ifdef SIG_INTERRUPT1</span> |
||
120 | 00113 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT1</span> |
||
121 | 00114 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT1) |
||
122 | 00115 { |
||
123 | 00116 <span class="comment">// if a user function is defined, execute it</span> |
||
124 | 00117 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a1">EXTINT1</a>]) |
||
125 | 00118 ExtIntFunc[<a class="code" href="extint_8h.html#a1">EXTINT1</a>](); |
||
126 | 00119 } |
||
127 | 00120 <span class="preprocessor">#endif</span> |
||
128 | 00121 <span class="preprocessor"></span> |
||
129 | 00122 <span class="preprocessor">#ifdef SIG_INTERRUPT2</span> |
||
130 | 00123 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT2</span> |
||
131 | 00124 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT2) |
||
132 | 00125 { |
||
133 | 00126 <span class="comment">// if a user function is defined, execute it</span> |
||
134 | 00127 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a2">EXTINT2</a>]) |
||
135 | 00128 ExtIntFunc[<a class="code" href="extint_8h.html#a2">EXTINT2</a>](); |
||
136 | 00129 } |
||
137 | 00130 <span class="preprocessor">#endif</span> |
||
138 | 00131 <span class="preprocessor"></span> |
||
139 | 00132 <span class="preprocessor">#ifdef SIG_INTERRUPT3</span> |
||
140 | 00133 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT3</span> |
||
141 | 00134 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT3) |
||
142 | 00135 { |
||
143 | 00136 <span class="comment">// if a user function is defined, execute it</span> |
||
144 | 00137 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a3">EXTINT3</a>]) |
||
145 | 00138 ExtIntFunc[<a class="code" href="extint_8h.html#a3">EXTINT3</a>](); |
||
146 | 00139 } |
||
147 | 00140 <span class="preprocessor">#endif</span> |
||
148 | 00141 <span class="preprocessor"></span> |
||
149 | 00142 <span class="preprocessor">#ifdef SIG_INTERRUPT4</span> |
||
150 | 00143 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT4</span> |
||
151 | 00144 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT4) |
||
152 | 00145 { |
||
153 | 00146 <span class="comment">// if a user function is defined, execute it</span> |
||
154 | 00147 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a4">EXTINT4</a>]) |
||
155 | 00148 ExtIntFunc[<a class="code" href="extint_8h.html#a4">EXTINT4</a>](); |
||
156 | 00149 } |
||
157 | 00150 <span class="preprocessor">#endif</span> |
||
158 | 00151 <span class="preprocessor"></span> |
||
159 | 00152 <span class="preprocessor">#ifdef SIG_INTERRUPT5</span> |
||
160 | 00153 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT5</span> |
||
161 | 00154 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT5) |
||
162 | 00155 { |
||
163 | 00156 <span class="comment">// if a user function is defined, execute it</span> |
||
164 | 00157 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a5">EXTINT5</a>]) |
||
165 | 00158 ExtIntFunc[<a class="code" href="extint_8h.html#a5">EXTINT5</a>](); |
||
166 | 00159 } |
||
167 | 00160 <span class="preprocessor">#endif</span> |
||
168 | 00161 <span class="preprocessor"></span> |
||
169 | 00162 <span class="preprocessor">#ifdef SIG_INTERRUPT6</span> |
||
170 | 00163 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT6</span> |
||
171 | 00164 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT6) |
||
172 | 00165 { |
||
173 | 00166 <span class="comment">// if a user function is defined, execute it</span> |
||
174 | 00167 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a6">EXTINT6</a>]) |
||
175 | 00168 ExtIntFunc[<a class="code" href="extint_8h.html#a6">EXTINT6</a>](); |
||
176 | 00169 } |
||
177 | 00170 <span class="preprocessor">#endif</span> |
||
178 | 00171 <span class="preprocessor"></span> |
||
179 | 00172 <span class="preprocessor">#ifdef SIG_INTERRUPT7</span> |
||
180 | 00173 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT7</span> |
||
181 | 00174 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT7) |
||
182 | 00175 { |
||
183 | 00176 <span class="comment">// if a user function is defined, execute it</span> |
||
184 | 00177 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a7">EXTINT7</a>]) |
||
185 | 00178 ExtIntFunc[<a class="code" href="extint_8h.html#a7">EXTINT7</a>](); |
||
186 | 00179 } |
||
187 | 00180 <span class="preprocessor">#endif</span> |
||
188 | 00181 <span class="preprocessor"></span> |
||
189 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by |
||
190 | <a href="http://www.doxygen.org/index.html"> |
||
191 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
192 | </body> |
||
193 | </html> |
Powered by WebSVN v2.8.3