?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file extint.c \brief External-Interrupt function library. */
2 //*****************************************************************************
3 //
4 // File Name : 'extint.c'
5 // Title : External-Interrupt function library
6 // Author : Pascal Stang - Copyright (C) 2002-2004
7 // Created : 5/10/2002
8 // Revised : 11/16/2004
9 // Version : 1.0
10 // Target MCU : Atmel AVR Series
11 // Editor Tabs : 4
12 //
13 // Notes: This library provides convenient standardized configuration and
14 // access to external interrupts. The library is designed to make
15 // it possible to write code that uses external interrupts without
16 // digging into the processor datasheets to find register names and
17 // bit-defines. The library also strives to allow code which uses
18 // external interrupts to more easily cross-compile between different
19 // microcontrollers.
20 //
21 // NOTE: Using this library has certain advantages, but also adds
22 // overhead and latency to interrupt servicing. If the smallest
23 // code size or fastest possible latency is needed, do NOT use this
24 // library; link your interrupts directly.
25 //
26 //*****************************************************************************
27  
28 #include <avr/io.h>
29 #include <avr/interrupt.h>
30  
31 #include "global.h"
32 #include "extint.h"
33  
34 // Global variables
35 typedef void (*voidFuncPtr)(void);
36 volatile static voidFuncPtr ExtIntFunc[EXTINT_NUM_INTERRUPTS];
37  
38 // functions
39  
40 //! initializes extint library
41 void extintInit(void)
42 {
43 u08 intNum;
44 // detach all user functions from interrupts
45 for(intNum=0; intNum<EXTINT_NUM_INTERRUPTS; intNum++)
46 extintDetach(intNum);
47  
48 }
49  
50 //! Configure external interrupt trigger
51 // NOTE: this function is not complete!!!
52 void extintConfigure(u08 interruptNum, u08 configuration)
53 {
54 if(interruptNum == EXTINT0)
55 {
56 MCUCR &= ~((1<<ISC01) | (1<<ISC00));
57 MCUCR |= configuration;
58 }
59 #ifdef SIG_INTERRUPT1
60 else if(interruptNum == EXTINT1)
61 {
62 MCUCR &= ~((1<<ISC11) | (1<<ISC10));
63 MCUCR |= configuration<<2;
64 }
65 #endif
66 #ifdef SIG_INTERRUPT2
67 else if(interruptNum == EXTINT2)
68 {
69 if(configuration == EXTINT_EDGE_RISING)
70 sbi(MCUCSR, ISC2);
71 else
72 cbi(MCUCSR, ISC2);
73 }
74 #endif
75 // need to handle a lot more cases
76 // and differences between processors.
77 // looking for clean way to do it...
78 }
79  
80 //! Attach a user function to an external interrupt
81 void extintAttach(u08 interruptNum, void (*userHandler)(void) )
82 {
83 // make sure the interrupt number is within bounds
84 if(interruptNum < EXTINT_NUM_INTERRUPTS)
85 {
86 // set the interrupt function to run
87 // the supplied user's function
88 ExtIntFunc[interruptNum] = userHandler;
89 }
90 }
91  
92 //! Detach a user function from an external interrupt
93 void extintDetach(u08 interruptNum)
94 {
95 // make sure the interrupt number is within bounds
96 if(interruptNum < EXTINT_NUM_INTERRUPTS)
97 {
98 // set the interrupt function to run
99 // the supplied user's function
100 ExtIntFunc[interruptNum] = 0;
101 }
102 }
103  
104 //! Interrupt handler for INT0
105 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT0)
106 {
107 // if a user function is defined, execute it
108 if(ExtIntFunc[EXTINT0])
109 ExtIntFunc[EXTINT0]();
110 }
111  
112 #ifdef SIG_INTERRUPT1
113 //! Interrupt handler for INT1
114 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT1)
115 {
116 // if a user function is defined, execute it
117 if(ExtIntFunc[EXTINT1])
118 ExtIntFunc[EXTINT1]();
119 }
120 #endif
121  
122 #ifdef SIG_INTERRUPT2
123 //! Interrupt handler for INT2
124 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT2)
125 {
126 // if a user function is defined, execute it
127 if(ExtIntFunc[EXTINT2])
128 ExtIntFunc[EXTINT2]();
129 }
130 #endif
131  
132 #ifdef SIG_INTERRUPT3
133 //! Interrupt handler for INT3
134 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT3)
135 {
136 // if a user function is defined, execute it
137 if(ExtIntFunc[EXTINT3])
138 ExtIntFunc[EXTINT3]();
139 }
140 #endif
141  
142 #ifdef SIG_INTERRUPT4
143 //! Interrupt handler for INT4
144 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT4)
145 {
146 // if a user function is defined, execute it
147 if(ExtIntFunc[EXTINT4])
148 ExtIntFunc[EXTINT4]();
149 }
150 #endif
151  
152 #ifdef SIG_INTERRUPT5
153 //! Interrupt handler for INT5
154 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT5)
155 {
156 // if a user function is defined, execute it
157 if(ExtIntFunc[EXTINT5])
158 ExtIntFunc[EXTINT5]();
159 }
160 #endif
161  
162 #ifdef SIG_INTERRUPT6
163 //! Interrupt handler for INT6
164 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT6)
165 {
166 // if a user function is defined, execute it
167 if(ExtIntFunc[EXTINT6])
168 ExtIntFunc[EXTINT6]();
169 }
170 #endif
171  
172 #ifdef SIG_INTERRUPT7
173 //! Interrupt handler for INT7
174 EXTINT_INTERRUPT_HANDLER(SIG_INTERRUPT7)
175 {
176 // if a user function is defined, execute it
177 if(ExtIntFunc[EXTINT7])
178 ExtIntFunc[EXTINT7]();
179 }
180 #endif
181  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3