hsk_libs-dev  163:b63ae088cc97
High Speed Karlsruhe XC878 library collection
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
hsk_ex.h
Go to the documentation of this file.
1 /** \file
2  * HSK External Interrupt Routing headers
3  *
4  * This file offers functions to activate external interrupts and connect
5  * them to the available input pins.
6  *
7  * @author kami
8  */
9 
10 #ifndef _HSK_EX_H_
11 #define _HSK_EX_H_
12 
13 /*
14  * C51 does not include the used register bank in pointer types.
15  */
16 #ifdef __C51__
17  #define using(bank)
18 #endif
19 
20 /*
21  * SDCC does not like the \c code keyword for function pointers, C51 needs it
22  * or it will use generic pointers.
23  */
24 #ifdef SDCC
25  #undef code
26  #define code
27 #endif /* SDCC */
28 
29 /**
30  * Typedef for externel interrupt channels.
31  */
32 typedef ubyte hsk_ex_channel;
33 
34 /**
35  * \defgroup EX_EXINT External Interrupt Channels
36  *
37  * This group consists of defines representing external interrupt channels.
38  *
39  * @{
40  */
41 
42 /**
43  * External interrupt channel EXINT0.
44  *
45  * Mask with EA, disable with EX0.
46  */
47 #define EX_EXINT0 0
48 
49 /**
50  * External interrupt channel EXINT1.
51  *
52  * Mask with EA, disable with EX1.
53  */
54 #define EX_EXINT1 1
55 
56 /**
57  * External interrupt channel EXINT2.
58  *
59  * Mask with EX2.
60  */
61 #define EX_EXINT2 2
62 
63 /**
64  * External interrupt channel EXINT3.
65  *
66  * Mask with EXM.
67  */
68 #define EX_EXINT3 3
69 
70 /**
71  * External interrupt channel EXINT4.
72  *
73  * Mask with EXM.
74  */
75 #define EX_EXINT4 4
76 
77 /**
78  * External interrupt channel EXINT5.
79  *
80  * Mask with EXM.
81  */
82 #define EX_EXINT5 5
83 
84 /**
85  * External interrupt channel EXINT6.
86  *
87  * Mask with EXM.
88  */
89 #define EX_EXINT6 6
90 
91 /**
92  * @}
93  */
94 
95 /**
96  * \defgroup EX_EDGE External Interrupt Triggers
97  *
98  * This group contains defines representing the different edge triggers
99  *
100  * @{
101  */
102 
103 /**
104  * Trigger interrupt on rising edge.
105  */
106 #define EX_EDGE_RISING 0
107 
108 /**
109  * Trigger interrupt on falling edge.
110  */
111 #define EX_EDGE_FALLING 1
112 
113 /**
114  * Trigger interrupt on both edges.
115  */
116 #define EX_EDGE_BOTH 2
117 
118 /**
119  * @}
120  */
121 
122 /**
123  * Enable an external interrupt channel.
124  *
125  * It is good practice to enable a port for the channel first, because
126  * port changes on an active interrupt may cause an undesired interrupt.
127  *
128  * The callback function can be set to 0 if a change of the function is
129  * not desired. For channels EXINT0 and EXINT1 the callback is ignored,
130  * implement interrupts 0 and 2 instead.
131  *
132  * @param channel
133  * The channel to activate, one of \ref EX_EXINT
134  * @param edge
135  * The triggering edge, one of \ref EX_EDGE
136  * @param callback
137  * The callback function for an interrupt event
138  */
139 void hsk_ex_channel_enable(const hsk_ex_channel channel,
140  const ubyte edge,
141  const void (code * const callback)(void) using(1));
142 
143 /**
144  * Disables an external interrupt channel.
145  *
146  * @param channel
147  * The channel to disable, one of \ref EX_EXINT
148  */
149 void hsk_ex_channel_disable(const hsk_ex_channel channel);
150 
151 /**
152  * Typedef for externel interrupt ports.
153  */
154 typedef ubyte hsk_ex_port;
155 
156 /**
157  * \defgroup EX_EXINT_P External Interrupt Input Ports
158  *
159  * Each define of this group represents an external interrupt port
160  * configuration
161  *
162  * @{
163  */
164 
165 /**
166  * External interrupt EXINT0 input port P0.5.
167  */
168 #define EX_EXINT0_P05 0
169 
170 /**
171  * External interrupt EXINT3 input port P1.1.
172  */
173 #define EX_EXINT3_P11 1
174 
175 /**
176  * External interrupt EXINT0 input port P1.4.
177  */
178 #define EX_EXINT0_P14 2
179 
180 /**
181  * External interrupt EXINT5 input port P1.5.
182  */
183 #define EX_EXINT5_P15 3
184 
185 /**
186  * External interrupt EXINT6 input port P1.6.
187  */
188 #define EX_EXINT6_P16 4
189 
190 /**
191  * External interrupt EXINT3 input port P3.0.
192  */
193 #define EX_EXINT3_P30 5
194 
195 /**
196  * External interrupt EXINT4 input port P3.2.
197  */
198 #define EX_EXINT4_P32 6
199 
200 /**
201  * External interrupt EXINT5 input port P3.3.
202  */
203 #define EX_EXINT5_P33 7
204 
205 /**
206  * External interrupt EXINT6 input port P3.4.
207  */
208 #define EX_EXINT6_P34 8
209 
210 /**
211  * External interrupt EXINT4 input port P3.7.
212  */
213 #define EX_EXINT4_P37 9
214 
215 /**
216  * External interrupt EXINT3 input port P4.0.
217  */
218 #define EX_EXINT3_P40 10
219 
220 /**
221  * External interrupt EXINT4 input port P4.1.
222  */
223 #define EX_EXINT4_P41 11
224 
225 /**
226  * External interrupt EXINT6 input port P4.2.
227  */
228 #define EX_EXINT6_P42 12
229 
230 /**
231  * External interrupt EXINT5 input port P4.4.
232  */
233 #define EX_EXINT5_P44 13
234 
235 /**
236  * External interrupt EXINT6 input port P4.5.
237  */
238 #define EX_EXINT6_P45 14
239 
240 /**
241  * External interrupt EXINT1 input port P5.0.
242  */
243 #define EX_EXINT1_P50 15
244 
245 /**
246  * External interrupt EXINT2 input port P5.1.
247  */
248 #define EX_EXINT2_P51 16
249 
250 /**
251  * External interrupt EXINT5 input port P5.2.
252  */
253 #define EX_EXINT5_P52 17
254 
255 /**
256  * External interrupt EXINT1 input port P5.3.
257  */
258 #define EX_EXINT1_P53 18
259 
260 /**
261  * External interrupt EXINT2 input port P5.4.
262  */
263 #define EX_EXINT2_P54 19
264 
265 /**
266  * External interrupt EXINT3 input port P5.5.
267  */
268 #define EX_EXINT3_P55 20
269 
270 /**
271  * External interrupt EXINT4 input port P5.6.
272  */
273 #define EX_EXINT4_P56 21
274 
275 /**
276  * External interrupt EXINT6 input port P5.7.
277  */
278 #define EX_EXINT6_P57 22
279 
280 /**
281  * @}
282  */
283 
284 /**
285  * Opens an input port for an external interrupt.
286  *
287  * @param port
288  * The port to open, one of \ref EX_EXINT_P
289  */
290 void hsk_ex_port_open(const hsk_ex_port port);
291 
292 /**
293  * Disconnects an input port from an external interrupt.
294  *
295  * @param port
296  * The port to close, one of \ref EX_EXINT_P
297  */
298 void hsk_ex_port_close(const hsk_ex_port port);
299 
300 /*
301  * Restore the usual meaning of \c code.
302  */
303 #ifdef SDCC
304  #undef code
305  #define code __code
306 #endif
307 
308 /*
309  * Restore the usual meaning of \c using(bank).
310  */
311 #ifdef __C51__
312  #undef using
313 #endif /* __C51__ */
314 
315 #endif /* _HSK_EX_H_ */
316