mbed library sources. With a patch for the can_api

Fork of mbed-dev by mbed official

Revision:
150:02e0a0aed4ec
Parent:
149:156823d33999
--- a/targets/TARGET_ONSEMI/TARGET_NCS36510/gpio_api.c	Fri Oct 28 11:17:30 2016 +0100
+++ b/targets/TARGET_ONSEMI/TARGET_NCS36510/gpio_api.c	Tue Nov 08 17:45:16 2016 +0000
@@ -109,9 +109,6 @@
     /** - Get PAD IO register address for the PAD number */
     PadReg_t *PadRegOffset = (PadReg_t*)(PADREG_BASE + (pin * PAD_REG_ADRS_BYTE_SIZE));
 
-    /* - Disable the GPIO clock */
-    CLOCK_DISABLE(CLOCK_GPIO);
-
     /** - Enable the clock for PAD peripheral device */
     CLOCK_ENABLE(CLOCK_PAD);
 
@@ -142,7 +139,7 @@
  */
 void gpio_dir(gpio_t *obj, PinDirection direction)
 {
-    /* Enable the GPIO clock */
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
     if (direction == PIN_INPUT) {
@@ -151,8 +148,6 @@
         obj->GPIOMEMBASE->W_OUT = obj->gpioMask;
     }
 
-    /* - Disable the GPIO clock */
-    CLOCK_DISABLE(CLOCK_GPIO);
 }
 
 /** Set the output value
@@ -162,7 +157,8 @@
  */
 void gpio_write(gpio_t *obj, int value)
 {
-    /* Enable the GPIO clock */
+
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
     /* Set the GPIO based on value */
@@ -172,8 +168,6 @@
         obj->GPIOMEMBASE->R_IRQ_W_CLEAR = obj->gpioMask;
     }
 
-    /* - Disable the GPIO clock */
-    CLOCK_DISABLE(CLOCK_GPIO);
 }
 
 /** Read the input value
@@ -185,13 +179,23 @@
 {
     int ret;
 
-    /* Enable the GPIO clock */
+    /* Enable the GPIO clock which may have been switched off by other drivers */
     CLOCK_ENABLE(CLOCK_GPIO);
 
     ret = (obj->GPIOMEMBASE->R_STATE_W_SET & obj->gpioMask) ? 1: 0;
 
-    /* - Disable the GPIO clock */
-    CLOCK_DISABLE(CLOCK_GPIO);
-
     return ret;
 }
+
+/* Checks if gpio object is connected (pin was not initialized with NC)
+ * @param pin The pin to be set as GPIO
+ * @return 0 if port is initialized with NC
+ **/
+int gpio_is_connected(const gpio_t *obj)
+{
+    if(obj->gpioPin != (PinName)NC) {
+        return 1;
+    } else {
+        return 0;
+    }
+}