Skip to content

Commit c3ea39c

Browse files
committed
Interrupts: use optional argument for interrupts
1 parent 485a4b4 commit c3ea39c

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

hardware/zpuino/zpu20/cores/zpuino/interrupt.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
static __attribute__((always_inline)) inline void sei()
77
{
8-
INTRCTL=1;
8+
INTRCTL=1;
99
}
1010

1111
static __attribute__((always_inline)) inline void cli()
1212
{
13-
INTRCTL=0;
14-
13+
INTRCTL=0;
1514
}
15+
16+
extern void attachInterrupt(unsigned int, void (*)(void), int mode=0);
17+
extern void detachInterrupt(unsigned int);
18+
extern int attachInterrupt(unsigned int line, void (*function)(void*), void *arg);
19+
20+
1621
#endif

hardware/zpuino/zpu20/cores/zpuino/zpuino.cpp

+24-15
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,40 @@
55

66
#define ZPUINO_MAX_INTERRUPTS 16
77

8-
typedef void(*interrupt_type_t)(void);
8+
struct interrupt_type_t {
9+
void(*func)(void*);
10+
void*arg;
11+
};
912

1013
static interrupt_type_t itable[ZPUINO_MAX_INTERRUPTS]={0};
1114

15+
int attachInterrupt(unsigned int line, void (*function)(void*), void *arg)
16+
{
17+
if (line>=ZPUINO_MAX_INTERRUPTS)
18+
return -1;
19+
// cli();
20+
itable[line].func = function;
21+
itable[line].arg = arg;
22+
// sei();
23+
return 0;
24+
}
25+
1226
void attachInterrupt(unsigned int line, void (*function)(void), int mode)
1327
{
14-
if (line>=ZPUINO_MAX_INTERRUPTS)
15-
return;
16-
// cli();
17-
itable[line] = function;
18-
// sei();
28+
attachInterrupt(line, (void(*)(void*))function, NULL);
1929
}
30+
2031
void detachInterrupt(unsigned int line)
2132
{
22-
// cli();
23-
if (line>=ZPUINO_MAX_INTERRUPTS)
24-
return;
25-
itable[line] = 0;
26-
// sei();
33+
if (line>=ZPUINO_MAX_INTERRUPTS)
34+
return;
35+
itable[line].func = 0;
2736
}
2837

2938
void _zpu_interrupt(unsigned int line)
3039
{
31-
if (line>=ZPUINO_MAX_INTERRUPTS)
32-
return;
33-
if (itable[line])
34-
itable[line]();
40+
if (line>=ZPUINO_MAX_INTERRUPTS)
41+
return;
42+
if (itable[line].func)
43+
itable[line].func(itable[line].arg);
3544
}

hardware/zpuino/zpu20/cores/zpuino/zpuino.h

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#define _BV(x) (1<<(x))
1111
#endif
1212

13-
extern void attachInterrupt(unsigned int, void (*)(void), int mode=0);
14-
extern void detachInterrupt(unsigned int);
15-
1613
typedef volatile unsigned int* register_t;
1714

1815
extern void itoa(int value, char *dest, int base);

0 commit comments

Comments
 (0)