An I/O controller for virtual pinball machines: accelerometer nudge sensing, analog plunger input, button input encoding, LedWiz compatible output controls, and more.

Dependencies:   mbed FastIO FastPWM USBDevice

Fork of Pinscape_Controller by Mike R

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers KLXX_us_ticker_fix.c Source File

KLXX_us_ticker_fix.c

00001 #include <stddef.h>
00002 #include "us_ticker_api.h"
00003 
00004 // Bug fix: if scheduling an event in the past, schedule it for
00005 // the very near future rather than invoking the handler directly.
00006 // For Tickers and other recurring events, invoking the handler
00007 // can cause significant recursion, since the handler might try
00008 // to schedule the next event, which will end up back here, which
00009 // will call the handler again, and so on.  Forcing the event
00010 // into the future prevents this recursion and ensures bounded
00011 // stack use.  The effect will be the same either way: the handler
00012 // will be called late, since we can't actually travel back in time
00013 // and call it in the past.  But this way we don't blow the stack
00014 // if we have a high-frequency recurring event that has gotten
00015 // significantly behind (because of a long period with interrupts
00016 // disabled, say).
00017 extern void $Super$$us_ticker_set_interrupt(timestamp_t);
00018 void $Sub$$us_ticker_set_interrupt(timestamp_t timestamp) 
00019 {
00020     // If the event was in the past, schedule it for almost (but not
00021     // quite) immediately.  This prevents the base version from recursing
00022     // into the handler; instead, we'll schedule an interrupt as for any
00023     // other future event.
00024     int tcur = us_ticker_read();
00025     int delta = (int)((uint32_t)timestamp - tcur);
00026     if (delta <= 0)
00027         timestamp = tcur + 2;
00028         
00029     // call the base handler
00030     $Super$$us_ticker_set_interrupt(timestamp);
00031 }