Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file extint.h \brief External-Interrupt function library. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'extint.h' |
||
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 | #ifndef EXTINT_H |
||
29 | #define EXTINT_H |
||
30 | |||
31 | #include "global.h" |
||
32 | |||
33 | // constants/macros/typdefs |
||
34 | |||
35 | // interrupt macros for attaching user functions to external interrupts |
||
36 | // use these with extintAttach( intNum, function ) |
||
37 | #define EXTINT0 0x00 ///< External Interrupt 0 |
||
38 | #define EXTINT1 0x01 ///< External Interrupt 1 |
||
39 | #define EXTINT2 0x02 ///< External Interrupt 2 |
||
40 | #define EXTINT3 0x03 ///< External Interrupt 3 |
||
41 | #define EXTINT4 0x04 ///< External Interrupt 4 |
||
42 | #define EXTINT5 0x05 ///< External Interrupt 5 |
||
43 | #define EXTINT6 0x06 ///< External Interrupt 6 |
||
44 | #define EXTINT7 0x07 ///< External Interrupt 7 |
||
45 | |||
46 | #define EXTINT_LEVEL_LOW 0x00 ///< Trigger on low level |
||
47 | #define EXTINT_EDGE_ANY 0x01 ///< Trigger on any edge |
||
48 | #define EXTINT_EDGE_FALLING 0x02 ///< Trigger on falling edge |
||
49 | #define EXTINT_EDGE_RISING 0x03 ///< Trigger on rising edge |
||
50 | |||
51 | // type of interrupt handler to use |
||
52 | // *do not change unless you know what you're doing |
||
53 | // Value may be SIGNAL or INTERRUPT |
||
54 | #ifndef EXTINT_INTERRUPT_HANDLER |
||
55 | #define EXTINT_INTERRUPT_HANDLER SIGNAL |
||
56 | #endif |
||
57 | |||
58 | // processor-adaptive defines |
||
59 | // mainstream AVR processors generally have 1,2,3, or 8 external interrupts |
||
60 | // (if someone has a better idea of how to manage this, let me know) |
||
61 | #ifdef SIG_INTERRUPT7 |
||
62 | #define EXTINT_NUM_INTERRUPTS 8 |
||
63 | #else |
||
64 | #ifdef SIG_INTERRUPT2 |
||
65 | #define EXTINT_NUM_INTERRUPTS 3 |
||
66 | #else |
||
67 | #ifdef SIG_INTERRUPT1 |
||
68 | #define EXTINT_NUM_INTERRUPTS 2 |
||
69 | #else |
||
70 | #define EXTINT_NUM_INTERRUPTS 1 |
||
71 | #endif |
||
72 | #endif |
||
73 | #endif |
||
74 | |||
75 | // functions |
||
76 | |||
77 | //! initializes extint library |
||
78 | void extintInit(void); |
||
79 | |||
80 | //! Configure external interrupt trigger |
||
81 | void extintConfigure(u08 interruptNum, u08 configuration); |
||
82 | |||
83 | // extintAttach and extintDetach commands |
||
84 | // These functions allow the attachment (or detachment) of any user |
||
85 | // function to an external interrupt. "Attaching" one of your own |
||
86 | // functions to an interrupt means that it will be called whenever |
||
87 | // that interrupt is triggered. Example usage: |
||
88 | // |
||
89 | // extintAttach(EXTINT0, myInterruptHandler); |
||
90 | // extintDetach(EXTINT0); |
||
91 | // |
||
92 | // extintAttach causes the myInterruptHandler() to be attached, and therefore |
||
93 | // execute, whenever the corresponding interrupt occurs. extintDetach removes |
||
94 | // the association and executes no user function when the interrupt occurs. |
||
95 | // myInterruptFunction must be defined with no return value and no arguments: |
||
96 | // |
||
97 | // void myInterruptHandler(void) { ... } |
||
98 | |||
99 | //! Attach a user function to an external interrupt |
||
100 | void extintAttach(u08 interruptNum, void (*userHandler)(void) ); |
||
101 | //! Detach a user function from an external interrupt |
||
102 | void extintDetach(u08 interruptNum); |
||
103 | |||
104 | #endif |
Powered by WebSVN v2.8.3