📄 extint_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: extint.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><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><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>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name : 'extint.c'</span>00005 <span class="comment">// Title : External-Interrupt function library</span>00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2002-2004</span>00007 <span class="comment">// Created : 5/10/2002</span>00008 <span class="comment">// Revised : 11/16/2004</span>00009 <span class="comment">// Version : 1.0</span>00010 <span class="comment">// Target MCU : Atmel AVR Series</span>00011 <span class="comment">// Editor Tabs : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// Notes: This library provides convenient standardized configuration and</span>00014 <span class="comment">// access to external interrupts. The library is designed to make</span>00015 <span class="comment">// it possible to write code that uses external interrupts without</span>00016 <span class="comment">// digging into the processor datasheets to find register names and</span>00017 <span class="comment">// bit-defines. The library also strives to allow code which uses</span>00018 <span class="comment">// external interrupts to more easily cross-compile between different</span>00019 <span class="comment">// microcontrollers.</span>00020 <span class="comment">//</span>00021 <span class="comment">// NOTE: Using this library has certain advantages, but also adds</span>00022 <span class="comment">// overhead and latency to interrupt servicing. If the smallest</span>00023 <span class="comment">// code size or fastest possible latency is needed, do NOT use this</span>00024 <span class="comment">// library; link your interrupts directly.</span>00025 <span class="comment">//</span>00026 <span class="comment">//*****************************************************************************</span>00027 00028 <span class="preprocessor">#include <avr/io.h></span>00029 <span class="preprocessor">#include <avr/interrupt.h></span>00030 00031 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>00032 <span class="preprocessor">#include "<a class="code" href="extint_8h.html">extint.h</a>"</span>00033 00034 <span class="comment">// Global variables</span>00035 <span class="keyword">typedef</span> void (*voidFuncPtr)(void);00036 <span class="keyword">volatile</span> <span class="keyword">static</span> voidFuncPtr ExtIntFunc[EXTINT_NUM_INTERRUPTS];00037 00038 <span class="comment">// functions</span>00039 <span class="comment"></span>00040 <span class="comment">//! initializes extint library</span><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>)00042 {00043 u08 intNum;00044 <span class="comment">// detach all user functions from interrupts</span>00045 <span class="keywordflow">for</span>(intNum=0; intNum<EXTINT_NUM_INTERRUPTS; intNum++)00046 <a class="code" href="extint_8c.html#a5">extintDetach</a>(intNum);00047 00048 }00049 <span class="comment"></span>00050 <span class="comment">//! Configure external interrupt trigger</span>00051 <span class="comment"></span><span class="comment">// NOTE: this function is not complete!!!</span><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)00053 {00054 <span class="keywordflow">if</span>(interruptNum == <a class="code" href="extint_8h.html#a0">EXTINT0</a>)00055 {00056 MCUCR &= ~((1<<ISC01) | (1<<ISC00));00057 MCUCR |= configuration;00058 }00059 <span class="preprocessor"> #ifdef SIG_INTERRUPT1</span>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>)00061 {00062 MCUCR &= ~((1<<ISC11) | (1<<ISC10));00063 MCUCR |= configuration<<2;00064 }00065 <span class="preprocessor"> #endif</span>00066 <span class="preprocessor"></span><span class="preprocessor"> #ifdef SIG_INTERRUPT2</span>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>)00068 {00069 <span class="keywordflow">if</span>(configuration == <a class="code" href="extint_8h.html#a11">EXTINT_EDGE_RISING</a>)00070 sbi(MCUCSR, ISC2);00071 <span class="keywordflow">else</span>00072 cbi(MCUCSR, ISC2);00073 }00074 <span class="preprocessor"> #endif</span>00075 <span class="preprocessor"></span> <span class="comment">// need to handle a lot more cases</span>00076 <span class="comment">// and differences between processors.</span>00077 <span class="comment">// looking for clean way to do it...</span>00078 }00079 <span class="comment"></span>00080 <span class="comment">//! Attach a user function to an external interrupt</span><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>) )00082 {00083 <span class="comment">// make sure the interrupt number is within bounds</span>00084 <span class="keywordflow">if</span>(interruptNum < EXTINT_NUM_INTERRUPTS)00085 {00086 <span class="comment">// set the interrupt function to run</span>00087 <span class="comment">// the supplied user's function</span>00088 ExtIntFunc[interruptNum] = userHandler;00089 }00090 }00091 <span class="comment"></span>00092 <span class="comment">//! Detach a user function from an external interrupt</span><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)00094 {00095 <span class="comment">// make sure the interrupt number is within bounds</span>00096 <span class="keywordflow">if</span>(interruptNum < EXTINT_NUM_INTERRUPTS)00097 {00098 <span class="comment">// set the interrupt function to run</span>00099 <span class="comment">// the supplied user's function</span>00100 ExtIntFunc[interruptNum] = 0;00101 }00102 }00103 <span class="comment"></span>00104 <span class="comment">//! Interrupt handler for INT0</span><a name="l00105"></a><a class="code" href="extint_8c.html#a6">00105</a> <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT0)00106 {00107 <span class="comment">// if a user function is defined, execute it</span>00108 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a0">EXTINT0</a>])00109 ExtIntFunc[<a class="code" href="extint_8h.html#a0">EXTINT0</a>]();00110 }00111 00112 <span class="preprocessor">#ifdef SIG_INTERRUPT1</span>00113 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT1</span>00114 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT1)00115 {00116 <span class="comment">// if a user function is defined, execute it</span>00117 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a1">EXTINT1</a>])00118 ExtIntFunc[<a class="code" href="extint_8h.html#a1">EXTINT1</a>]();00119 }00120 <span class="preprocessor">#endif</span>00121 <span class="preprocessor"></span>00122 <span class="preprocessor">#ifdef SIG_INTERRUPT2</span>00123 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT2</span>00124 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT2)00125 {00126 <span class="comment">// if a user function is defined, execute it</span>00127 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a2">EXTINT2</a>])00128 ExtIntFunc[<a class="code" href="extint_8h.html#a2">EXTINT2</a>]();00129 }00130 <span class="preprocessor">#endif</span>00131 <span class="preprocessor"></span>00132 <span class="preprocessor">#ifdef SIG_INTERRUPT3</span>00133 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT3</span>00134 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT3)00135 {00136 <span class="comment">// if a user function is defined, execute it</span>00137 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a3">EXTINT3</a>])00138 ExtIntFunc[<a class="code" href="extint_8h.html#a3">EXTINT3</a>]();00139 }00140 <span class="preprocessor">#endif</span>00141 <span class="preprocessor"></span>00142 <span class="preprocessor">#ifdef SIG_INTERRUPT4</span>00143 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT4</span>00144 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT4)00145 {00146 <span class="comment">// if a user function is defined, execute it</span>00147 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a4">EXTINT4</a>])00148 ExtIntFunc[<a class="code" href="extint_8h.html#a4">EXTINT4</a>]();00149 }00150 <span class="preprocessor">#endif</span>00151 <span class="preprocessor"></span>00152 <span class="preprocessor">#ifdef SIG_INTERRUPT5</span>00153 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT5</span>00154 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT5)00155 {00156 <span class="comment">// if a user function is defined, execute it</span>00157 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a5">EXTINT5</a>])00158 ExtIntFunc[<a class="code" href="extint_8h.html#a5">EXTINT5</a>]();00159 }00160 <span class="preprocessor">#endif</span>00161 <span class="preprocessor"></span>00162 <span class="preprocessor">#ifdef SIG_INTERRUPT6</span>00163 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT6</span>00164 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT6)00165 {00166 <span class="comment">// if a user function is defined, execute it</span>00167 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a6">EXTINT6</a>])00168 ExtIntFunc[<a class="code" href="extint_8h.html#a6">EXTINT6</a>]();00169 }00170 <span class="preprocessor">#endif</span>00171 <span class="preprocessor"></span>00172 <span class="preprocessor">#ifdef SIG_INTERRUPT7</span>00173 <span class="preprocessor"></span><span class="comment">//! Interrupt handler for INT7</span>00174 <span class="comment"></span>EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT7)00175 {00176 <span class="comment">// if a user function is defined, execute it</span>00177 <span class="keywordflow">if</span>(ExtIntFunc[<a class="code" href="extint_8h.html#a7">EXTINT7</a>])00178 ExtIntFunc[<a class="code" href="extint_8h.html#a7">EXTINT7</a>]();00179 }00180 <span class="preprocessor">#endif</span>00181 <span class="preprocessor"></span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by <a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -