t

Fork of mbed-dev by mbed official

Revision:
150:02e0a0aed4ec
Parent:
149:156823d33999
--- a/targets/TARGET_ONSEMI/TARGET_NCS36510/gpio_irq_api.c	Fri Oct 28 11:17:30 2016 +0100
+++ b/targets/TARGET_ONSEMI/TARGET_NCS36510/gpio_irq_api.c	Tue Nov 08 17:45:16 2016 +0000
@@ -79,17 +79,17 @@
 
 /** Main GPIO IRQ handler called from vector table handler
  *
- * @param gpioBase    The GPIO register base address
- * @return            void
+ * @param gpioBase  The GPIO register base address
+ * @return          void
  */
 void fGpioHandler(void)
 {
     uint8_t index;
     uint32_t active_interrupts = 0;
-    gpio_irq_event event;
+    gpio_irq_event event = IRQ_NONE;
     GpioReg_pt gpioBase;
 
-    /* Enable the GPIO clock */
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
     gpioBase = GPIOREG;
@@ -106,15 +106,12 @@
                 if ((gpioBase->IRQ_POLARITY_SET >> index) &0x01)  {
                     /* Edge triggered high */
                     event = IRQ_RISE;
-                } else if ((gpioBase->IRQ_POLARITY_CLEAR >> index) &0x01) {
+                } else {
                     /* Edge triggered low */
                     event = IRQ_FALL;
-                } else {
-                    /* Edge none */
-                    event = IRQ_NONE;
                 }
             }
-            gpioBase->IRQ_CLEAR |= (0x1 << index);
+            gpioBase->IRQ_CLEAR = (0x1 << index);
 
             /* Call the handler registered to the pin */
             irq_handler(gpioIds[index], event);
@@ -145,22 +142,16 @@
     /* Store the ID, this is required by registered handler function */
     gpioIds[pin] = id;
 
-    /* Enable the GPIO clock */
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
     /* Initialize the GPIO membase */
     obj->GPIOMEMBASE = GPIOREG;
 
     /* Set default values for the pin interrupt */
-    /* TODO: Only one DIO line is configured using this function; overrides other DIO line setting
-     * If mbed layer wants to call this function repeatedly for setting multiple DIO lines as input
-     * then change this setting to  obj->GPIOMEMBASE->W_IN |= obj->pinMask. All parameter setting needs to change from = to |=
-     */
     obj->GPIOMEMBASE->W_IN = obj->pinMask;
-    obj->GPIOMEMBASE->IRQ_ENABLE_SET = obj->pinMask;
     obj->GPIOMEMBASE->IRQ_EDGE = obj->pinMask;
-    obj->GPIOMEMBASE->IRQ_POLARITY_SET = (obj->pinMask);
-    obj->GPIOMEMBASE->ANYEDGE_SET = IO_NONE;
+    obj->GPIOMEMBASE->IRQ_POLARITY_SET = obj->pinMask;
 
     /* Register the handler for this pin */
     irq_handler = handler;
@@ -178,10 +169,11 @@
  */
 void gpio_irq_free(gpio_irq_t *obj)
 {
-    /* Enable the GPIO clock */
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
-    obj->GPIOMEMBASE->W_IN = (IO_ALL ^ (obj->pinMask));
+    /* Disable IRQs to indicate that it is now free */
+    obj->GPIOMEMBASE->IRQ_ENABLE_CLEAR = obj->pinMask;
     gpioIds[obj->pin] = 0;
 }
 
@@ -193,42 +185,35 @@
  */
 void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
 {
-
-    /* Enable the GPIO clock */
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
-
+    obj->GPIOMEMBASE->IRQ_EDGE = obj->pinMask;
+    
     switch(event) {
-        case IRQ_RISE:
-            obj->GPIOMEMBASE->IRQ_EDGE = (obj->pinMask);
-            obj->GPIOMEMBASE->IRQ_LEVEL = (IO_ALL ^ (obj->pinMask));
-            /* Enable is an integer; hence checking for 1 or 0*/
-            if (enable == 1) {
-                /* Enable rising edge */
-                obj->GPIOMEMBASE->IRQ_POLARITY_SET = (obj->pinMask);
-            } else if (enable == 0) {
-                /* Disable rising edge */
-                obj->GPIOMEMBASE->IRQ_POLARITY_SET = (IO_ALL ^ (obj->pinMask));
-            }
-            break;
+        case IRQ_RISE: 
+          
+            /* Enable rising edge */
+            obj->GPIOMEMBASE->IRQ_POLARITY_SET = obj->pinMask;
+           break;
 
         case IRQ_FALL:
-            obj->GPIOMEMBASE->IRQ_EDGE = (obj->pinMask);
-            obj->GPIOMEMBASE->IRQ_LEVEL = (IO_ALL ^ (obj->pinMask));
-            /* Enable is an integer; hence checking for 1 or 0*/
-            if (enable == 1) {
-                /* Enable falling edge */
-                obj->GPIOMEMBASE->IRQ_POLARITY_CLEAR = (obj->pinMask);
-            } else if (enable == 0) {
-                /* Disable falling edge */
-                obj->GPIOMEMBASE->IRQ_POLARITY_CLEAR = (IO_ALL ^ (obj->pinMask));
-            }
+
+            /* Enable falling edge */
+            obj->GPIOMEMBASE->IRQ_POLARITY_CLEAR = obj->pinMask;
             break;
 
         default:
             /* No event is set */
             break;
     }
+    /* Enable the IRQ based on enable parameter */
+    if (enable) {
 
+        obj->GPIOMEMBASE->IRQ_ENABLE_SET = obj->pinMask;
+    } else {
+
+        obj->GPIOMEMBASE->IRQ_ENABLE_CLEAR = obj->pinMask;
+    }
 }
 
 /** Enable GPIO IRQ
@@ -238,10 +223,10 @@
  */
 void gpio_irq_enable(gpio_irq_t *obj)
 {
-    /* Enable the GPIO clock */
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
-    obj->GPIOMEMBASE->IRQ_ENABLE_SET = (obj->pinMask);
+    obj->GPIOMEMBASE->IRQ_ENABLE_SET = obj->pinMask;
 }
 
 /** Disable GPIO IRQ
@@ -251,10 +236,11 @@
  */
 void gpio_irq_disable(gpio_irq_t *obj)
 {
-    /* Enable the GPIO clock */
+
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
-    obj->GPIOMEMBASE->IRQ_ENABLE_CLEAR = (obj->pinMask);
+    obj->GPIOMEMBASE->IRQ_ENABLE_CLEAR = obj->pinMask;
 }
 
 #endif //DEVICE_INTERRUPTIN