use warnings; use strict; use RPi::Const qw(:all); use Inline ('C' => 'DATA' => libs => '-lwiringPi -lrt -lwiringPiDev -lpthread'); my $continue = 1; $SIG{INT} = sub { $continue = 0; }; sub cref_handler { print "cref handler\n"; } my $cref = \&cref_handler; init(); pin_mode(3, INPUT); setInterruptCref(3, EDGE_FALLING, $cref); my $running; while ($continue){ print "running\n" if ! $running; $running = 1; } __DATA__ __C__ #include #include void init (){ wiringPiSetupGpio(); } PerlInterpreter* mine; SV* perl_callback_cref; void interruptHandlerCref(){ PERL_SET_CONTEXT(mine); dSP; ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; call_sv(perl_callback_cref, G_DISCARD|G_NOARGS); FREETMPS; LEAVE; } int setInterruptCref(int pin, int edge, SV* callback){ mine = Perl_get_context(); perl_callback_cref = callback; int interrupt = wiringPiISR(pin, edge, &interruptHandlerCref); return interrupt; } void pin_mode (int pin, int mode){ pinMode(pin, mode); }