Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
InterruptMask.h
00001 //***************************************************************************// 00002 /* InterruptMask Library */ 00003 /* Napoleon Leoni, February 18,2014*/ 00004 /* This class enables masking a GPIO interrupt from a specific MBED pin*/ 00005 // Note to get the actual pin number in the LPC of an mbed pin in P0 00006 // simply do pN-P0_0, for example p12-P0_0=17, that is pin 12 in the mbed 00007 // corresponds to Port[0].17 or bit 17 of port 0. 00008 //***************************************************************************// 00009 //* Example usage */ 00010 //* >#include "InterruptMask.h" 00011 //* >InterruptIn upPressed(p15); 00012 //* >InterruptMask maskUpButtonInt(p15); //Interrupt mask object allows easy access to 00013 //* > //mask/unmask interrupts from a GPIO source 00014 //* >void ISRup(void){ 00015 //*> myled1=!myled1; 00016 //*>} 00017 //*>int main() { 00018 //*> upPressed.rise(&ISRup); 00019 //*> //downPressed.rise(&ISRdown); 00020 //*> bool disableInterrupt=false; 00021 //*> int counter=0,tdelay=10; 00022 //*> 00023 //*> while (1) { 00024 //*> //This section of code periodically (every 10 seconds) masks the specified GPIO interrupt 00025 //*> //showing how to both mask it and unmask it as well as how to clear pending interrupts 00026 //*> counter++; 00027 //*> if(counter>=tdelay){ 00028 //*> disableInterrupt=!disableInterrupt; 00029 //*> if(disableInterrupt) maskUpButtonInt.maskIntR() ; //mask interrupt 00030 //*> if(!disableInterrupt){ 00031 //*> maskUpButtonInt.ClrInt(); //clear any pending interrupt before unmasking 00032 //*> maskUpButtonInt.unMaskIntR(); //unmask interrupt 00033 //*> } 00034 //*> counter=0; 00035 //*> } 00036 //*> } 00037 //*>} 00038 00039 // 00040 // TESTS RUN // 00041 // I print to the LCD three important LPC1768 registers: 00042 // ISER0..Interrupt set Enable register(address 0xE000E100), 00043 // contents of ISER0 are accesible via: *(NVIC->ISER) 00044 // 00045 // IntEnR..GPIO interrupt enable on rising, shows which pins are attached to EINT3 00046 // on their rising edge (these are only for mbed pins mapped to LPC pins on Port 0) 00047 // its contents are available using th macro LPC_GPIOINT->IO0IntEnR 00048 // IntEnF..GPIO interrupt enable on falling, shows which pins are attached to EINT3 00049 // on their falling edge (these are only for mbed pins mapped to LPC pins on Port 0) 00050 // its contents are available using th macro LPC_GPIOINT->IO0IntEnF 00051 // 00052 // The test program periodically masks/unmasks (every 10 seconds) a specified interrupt 00053 // from a GPIO pin, 00054 // 00055 //*********************************************************************************** 00056 // TEST DESCRIPTION Resulting Register Values ANALYSYS 00057 // 1 ISR attached to rise ISER0 0x0020 0010 Works as expected when p15 interrupt on rise edge 00058 // edge of p15(toggle LED1) IO0IntEnR 0x0082 0000 (when p15 unmasked) is masked the proper bit appears masked in IO0IntEnR 00059 // and p12(toggle LED2) IO0IntEnR 0x0002 0000 (when p15 masked) and the up action of the joystick does not toggle the LED 00060 // while the down motion continues to work. Once the interrupt 00061 // from p15 is unmasked the up joysstick action works again. 00062 // TEST DESCRIPTION STATUS 00063 // 2 check mask functionality for all PASS 00064 // GPIO pins attached to joystick , both 00065 // for rise and fall attached interrupts 00066 // 00067 // 3 When interrupt is cleared (ClrInt() ) PASS 00068 // before unmasking there should be no pending 00069 // interrupts 00070 // 00071 //*********************************************************************************** 00072 00073 #include "mbed.h" 00074 00075 #ifndef INTERRUPTMASK 00076 #define INTERRUPTMASK 00077 00078 class InterruptMask{ 00079 00080 public: 00081 00082 private: 00083 int mPin; 00084 int mask; 00085 int unmask; 00086 volatile unsigned int* IOIntEnF; // pointer to register with fall enable interrupt for 00087 // appropriate LPC port depending on the GPIO pin 00088 volatile unsigned int* IOIntEnR;// pointer to register with rise enable interrupt for 00089 // appropriate LPC port depending on the GPIO pin 00090 volatile unsigned int* IOIntClr; //pointer to register to clear interrupt for 00091 // appropriate LPC port depending on the GPIO pin 00092 public: 00093 //default constructor required, should not be use will yield error 00094 InterruptMask(); 00095 //Constructor to be used, initialize with any valid mbed pin (p5 thru p30 except pins 19-20) 00096 //you will need one InterruptMask for every pin you want ot have control over. 00097 InterruptMask(PinName GPIOpin); 00098 00099 //This method will mask (disable) any rising edge interrupts of the specified pin 00100 void maskIntR(void); 00101 00102 //This method will mask (disable) any faling edge interrupts of the specified pin 00103 void maskIntF(void); 00104 00105 //This method will unmask (enable) any rising edge interrupts of the specified pin 00106 void unMaskIntR(void); 00107 00108 //This method will unmask (enable) any falling edge interrupts of the specified pin 00109 void unMaskIntF(void); 00110 00111 //This method will clear any pending interrupts of the specified pin 00112 void ClrInt(void); 00113 00114 }; 00115 00116 #endif
Generated on Sat Jul 16 2022 06:30:35 by
1.7.2