From c9031f1d3630a634b0d03a1daf0f7414636ed420 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 28 Feb 2012 18:05:05 +1100 Subject: [PATCH] SITL: implement cli()/sei() properly for desktop build this disables simulated hardware interrupts during critical sections --- libraries/Desktop/include/avr/interrupt.h | 6 ++++-- libraries/Desktop/support/Arduino.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/libraries/Desktop/include/avr/interrupt.h b/libraries/Desktop/include/avr/interrupt.h index 09ac4f1494..db18edeba0 100644 --- a/libraries/Desktop/include/avr/interrupt.h +++ b/libraries/Desktop/include/avr/interrupt.h @@ -6,7 +6,9 @@ #define ISR(vector,...) void vector(void); \ void vector(void) -#define cli() -#define sei() +extern "C" { +void cli(void); +void sei(void); +} #endif diff --git a/libraries/Desktop/support/Arduino.cpp b/libraries/Desktop/support/Arduino.cpp index 134bdc635d..ab4caa7d83 100644 --- a/libraries/Desktop/support/Arduino.cpp +++ b/libraries/Desktop/support/Arduino.cpp @@ -5,6 +5,7 @@ #include "avr/pgmspace.h" #include #include +#include #include "desktop.h" extern "C" { @@ -14,6 +15,24 @@ volatile uint8_t __iomem[1024]; unsigned __brkval = 0x2000; unsigned __bss_end = 0x1000; +// disable interrupts +void cli(void) +{ + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGALRM); + sigprocmask(SIG_BLOCK,&set,NULL); +} + +// enable interrupts +void sei(void) +{ + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGALRM); + sigprocmask(SIG_UNBLOCK,&set,NULL); +} + void pinMode(uint8_t pin, uint8_t mode) {