hsk-libs-dev  270
High Speed Karlsruhe XC878 library collection
hsk_isr.h
Go to the documentation of this file.
1 /** \file
2  * HSK Shared Interrupt Service Routine headers
3  *
4  * This header is used by other libraries to use interrupts with multiple
5  * sources. A callback function can be provided for each available interrupt
6  * source.
7  *
8  * @author kami
9  *
10  * \section isr_pages SFR Pages
11  *
12  * An ISR callback function cannot make assumptions about current SFR pages
13  * like the regular functions that can expect all pages to be set to 0.
14  *
15  * Instead a callback function needs to set all pages and restore whatever
16  * page was in use previously.
17  *
18  * The following table lists the store and restore selectors by context and
19  * must be obeyed to avoid memory corruption:
20  * | Save | Restore | Context
21  * |------------|---------------|------------------------
22  * | SST0 | RST0 | ISRs
23  * | SST1 | RST1 | ISR callback functions
24  * | SST2 | RST2 | NMI ISR
25  * | SST3 | RST3 | NMI callback functions
26  *
27  * Every callback function is called with RMAP = 0. If the callback function
28  * changes RMAP it does not have to take care of restoring it. RMAP is always
29  * restored to its original state by the shared ISRs.
30  *
31  * \section isr_banks Register Banks
32  *
33  * Interrupts are each a root node of their own call tree. This is why they
34  * must preserve all the working registers.
35  *
36  * the pushing and popping of the 8 \c Rn registers for each interrupt call
37  * costs 64 CCLK cycles.
38  *
39  * To avoid this overhead different register banks are used. Call trees, i.e.
40  * interrupts, can use the same register bank if they cannot interrupt each
41  * other. Each used register bank costs 8 bytes of regular \c data memory.
42  * To minimize this cost all interrupts must have the same priority.
43  *
44  * The following table is used:
45  * | Priority | Context | Bank
46  * |-----------:|-----------------------|------
47  * | - | Regular code | 0
48  * | 0 | ISR, callback | 1
49  * | 1 | ISR, callback | -
50  * | 2 | ISR, callback | -
51  * | 3 | ISR, callback | -
52  * | NMI | NMI ISR, callback | 2
53  *
54  * Assigning higher priority to an ISR will affect (as in break) the operation
55  * of all lower priority ISRs.
56  */
57 
58 #ifndef _HSK_ISR_H_
59 #define _HSK_ISR_H_
60 
61 /*
62  * ISR prototypes for SDCC.
63  */
64 #ifdef SDCC
65 #include "hsk_isr.isr"
66 #endif /* SDCC */
67 
68 /*
69  * SDCC does not like the \c code keyword for function pointers, C51 needs it
70  * or it will use generic pointers.
71  */
72 #ifdef SDCC
73  #undef code
74  #define code
75 #endif /* SDCC */
76 
77 /*
78  * C51 does not include the used register bank in pointer types.
79  */
80 #ifdef __C51__
81  #define using(bank)
82 #endif
83 
84 /**
85  * Shared interrupt 5 routine. Activate the interrupt by setting ET2 = 1.
86  *
87  * This interrupt has the following sources:
88  * - Timer 2 Overflow (TF2)
89  * - Timer 2 External Event (EXF2)
90  * - T2CCU CCT Overflow (CCTOVF)
91  * - Normal Divider Overflow (NDOV)
92  * - End of Syn Byte (EOFSYN)
93  * - Syn Byte Error (ERRSYN)
94  * - CAN Interrupt 0 (CANSRC0)
95  */
97  /**
98  * Function to be called back when the TF2 interrupt event is
99  * triggered.
100  */
101  void (code *TF2)(void) using(1);
102 
103  /**
104  * Function to be called back when the EXF2 interrupt event is
105  * triggered.
106  */
107  void (code *EXF2)(void) using(1);
108 
109  /**
110  * Function to be called back when the CCTOVF interrupt event is
111  * triggered.
112  */
113  void (code *CCTOVF)(void) using(1);
114 
115  /**
116  * Function to be called back when the NDOV interrupt event is
117  * triggered.
118  */
119  void (code *NDOV)(void) using(1);
120 
121  /**
122  * Function to be called back when the EOFSYN interrupt event is
123  * triggered.
124  */
125  void (code *EOFSYN)(void) using(1);
126 
127  /**
128  * Function to be called back when the ERRSYN interrupt event is
129  * triggered.
130  */
131  void (code *ERRSYN)(void) using(1);
132 
133  /**
134  * Function to be called back when the CANSRC0 interrupt event is
135  * triggered.
136  */
137  void (code *CANSRC0)(void) using(1);
138 };
139 
140 /**
141  * Introduce callback function pointers for ISR 5.
142  */
143 extern volatile struct hsk_isr5_callback pdata hsk_isr5;
144 
145 /**
146  * Shared interrupt 6 routine. Activate the interrupt by setting EADC = 1.
147  *
148  * This interrupt has the following sources:
149  * - CANSRC1
150  * - CANSRC2
151  * - ADCSR0
152  * - ADCSR1
153  */
155  /**
156  * Function to be called back when the CANSRC1 interrupt event is
157  * triggered.
158  */
159  void (code *CANSRC1)(void) using(1);
160 
161  /**
162  * Function to be called back when the CANSRC2 interrupt event is
163  * triggered.
164  */
165  void (code *CANSRC2)(void) using(1);
166 
167  /**
168  * Function to be called back when the ADCSR0 interrupt event is
169  * triggered.
170  */
171  void (code *ADCSR0)(void) using(1);
172 
173  /**
174  * Function to be called back when the ADCSR1 interrupt event is
175  * triggered.
176  */
177  void (code *ADCSR1)(void) using(1);
178 };
179 
180 /**
181  * Introduce callback function pointers for ISR 6.
182  */
183 extern volatile struct hsk_isr6_callback pdata hsk_isr6;
184 
185 /**
186  * Shared interrupt 8 routine. Activate the interrupt by setting EX2 = 1.
187  *
188  * This interrupt has the following sources:
189  * - External Interrupt 2 (EXINT2)
190  * - UART1 (RI)
191  * - UART1 (TI)
192  * - Timer 21 Overflow (TF2)
193  * - T21EX (EXF2)
194  * - UART1 Fractional Divider (Normal Divider Overflow) (NDOV)
195  * - CORDIC (EOC)
196  * - MDU Result Ready (IRDY)
197  * - MDU Error (IERR)
198  */
200  /**
201  * Function to be called back when the EXINT2 interrupt event is
202  * triggered.
203  */
204  void (code *EXINT2)(void) using(1);
205 
206  /**
207  * Function to be called back when the RI interrupt event is
208  * triggered.
209  */
210  void (code *RI)(void) using(1);
211 
212  /**
213  * Function to be called back when the TI interrupt event is
214  * triggered.
215  */
216  void (code *TI)(void) using(1);
217 
218  /**
219  * Function to be called back when the TF2 interrupt event is
220  * triggered.
221  */
222  void (code *TF2)(void) using(1);
223 
224  /**
225  * Function to be called back when the EXF2 interrupt event is
226  * triggered.
227  */
228  void (code *EXF2)(void) using(1);
229 
230  /**
231  * Function to be called back when the NDOV interrupt event is
232  * triggered.
233  */
234  void (code *NDOV)(void) using(1);
235 
236  /**
237  * Function to be called back when the EOC interrupt event is
238  * triggered.
239  */
240  void (code *EOC)(void) using(1);
241 
242  /**
243  * Function to be called back when the IRDY interrupt event is
244  * triggered.
245  */
246  void (code *IRDY)(void) using(1);
247 
248  /**
249  * Function to be called back when the IERR interrupt event is
250  * triggered.
251  */
252  void (code *IERR)(void) using(1);
253 };
254 
255 /**
256  * Introduce callback function pointers for ISR 8.
257  */
258 extern volatile struct hsk_isr8_callback pdata hsk_isr8;
259 
260 /**
261  * Shared interrupt 9 routine. Activate the interrupt by setting EXM = 1.
262  *
263  * This interrupt has the following sources:
264  * - EXINT3/T2CC0
265  * - EXINT4/T2CC1
266  * - EXINT5/T2CC2
267  * - EXINT6/T2CC3
268  * - CANSRC2
269  */
271  /**
272  * Function to be called back when the EXINT3/T2CC0 interrupt event is
273  * triggered.
274  */
275  void (code *EXINT3)(void) using(1);
276 
277  /**
278  * Function to be called back when the EXINT4/T2CC1 interrupt event is
279  * triggered.
280  */
281  void (code *EXINT4)(void) using(1);
282 
283  /**
284  * Function to be called back when the EXINT5/T2CC2 interrupt event is
285  * triggered.
286  */
287  void (code *EXINT5)(void) using(1);
288 
289  /**
290  * Function to be called back when the EXINT6/T2CC3 interrupt event is
291  * triggered.
292  */
293  void (code *EXINT6)(void) using(1);
294 
295  /**
296  * Function to be called back when the CANSRC3 interrupt event is
297  * triggered.
298  */
299  void (code *CANSRC3)(void) using(1);
300 };
301 
302 /**
303  * Introduce callback function pointers for ISR 9.
304  */
305 extern volatile struct hsk_isr9_callback pdata hsk_isr9;
306 
307 /**
308  * Shared non-maskable interrupt routine.
309  *
310  * This interrupt has the following sources:
311  * - Watchdog Timer NMI (NMIWDT)
312  * - PLL NMI (NMIPLL)
313  * - Flash Timer NMI (NMIFLASH)
314  * - VDDP Prewarning NMI (NMIVDDP)
315  * - Flash ECC NMI (NMIECC)
316  */
318  /**
319  * Function to be called back when the NMIWDT interrupt event is
320  * triggered.
321  */
322  void (code *NMIWDT)(void) using(2);
323 
324  /**
325  * Function to be called back when the NMIPLL interrupt event is
326  * triggered.
327  */
328  void (code *NMIPLL)(void) using(2);
329 
330  /**
331  * Function to be called back when the NMIFLASH interrupt event is
332  * triggered.
333  */
334  void (code *NMIFLASH)(void) using(2);
335 
336  /**
337  * Function to be called back when the NMIVDDP interrupt event is
338  * triggered.
339  */
340  void (code *NMIVDDP)(void) using(2);
341 
342  /**
343  * Function to be called back when the NMIECC interrupt event is
344  * triggered.
345  */
346  void (code *NMIECC)(void) using(2);
347 };
348 
349 /**
350  * Introduce callback function pointers for NMI ISR.
351  *
352  * Functions called back from the NMI ISR should use SST3/RST3 instead of
353  * SST1/RST1, because they might interrupt other ISRs.
354  */
355 extern volatile struct hsk_isr14_callback pdata hsk_isr14;
356 
357 /*
358  * Restore the usual meaning of \c code.
359  */
360 #ifdef SDCC
361  #undef code
362  #define code __code
363 #endif /* SDCC */
364 
365 /*
366  * Restore the usual meaning of \c using(bank).
367  */
368 #ifdef __C51__
369  #undef using
370 #endif /* __C51__ */
371 
372 #endif /* _HSK_ISR_H_ */
volatile struct hsk_isr6_callback hsk_isr6
Introduce callback function pointers for ISR 6.
Definition: hsk_isr.c:161
void(* NDOV)(void)
Function to be called back when the NDOV interrupt event is triggered.
Definition: hsk_isr.h:119
void(* CANSRC0)(void)
Function to be called back when the CANSRC0 interrupt event is triggered.
Definition: hsk_isr.h:137
void(* CCTOVF)(void)
Function to be called back when the CCTOVF interrupt event is triggered.
Definition: hsk_isr.h:113
Shared interrupt 9 routine.
Definition: hsk_isr.h:270
Shared non-maskable interrupt routine.
Definition: hsk_isr.h:317
volatile struct hsk_isr5_callback hsk_isr5
Introduce callback function pointers for ISR 5.
Definition: hsk_isr.c:56
void(* TF2)(void)
Function to be called back when the TF2 interrupt event is triggered.
Definition: hsk_isr.h:101
void(* EXF2)(void)
Function to be called back when the EXF2 interrupt event is triggered.
Definition: hsk_isr.h:107
void(* EOFSYN)(void)
Function to be called back when the EOFSYN interrupt event is triggered.
Definition: hsk_isr.h:125
void(* ERRSYN)(void)
Function to be called back when the ERRSYN interrupt event is triggered.
Definition: hsk_isr.h:131
Shared interrupt 6 routine.
Definition: hsk_isr.h:154
volatile struct hsk_isr8_callback hsk_isr8
Introduce callback function pointers for ISR 8.
Definition: hsk_isr.c:225
volatile struct hsk_isr14_callback hsk_isr14
Introduce callback function pointers for NMI ISR.
Definition: hsk_isr.c:420
volatile struct hsk_isr9_callback hsk_isr9
Introduce callback function pointers for ISR 9.
Definition: hsk_isr.c:342
Shared interrupt 8 routine.
Definition: hsk_isr.h:199
Shared interrupt 5 routine.
Definition: hsk_isr.h:96