[rtems commit] Closes ticket #2390, and also updates the RPI implementation.

Ben Gras beng at rtems.org
Tue Aug 18 00:30:44 UTC 2015


Module:    rtems
Branch:    master
Commit:    b09a578e8ad4583a97349f866e981980f0ff6ade
Changeset: http://git.rtems.org/rtems/commit/?id=b09a578e8ad4583a97349f866e981980f0ff6ade

Author:    Andre Marques <andre.lousa.marques at gmail.com>
Date:      Mon Aug 17 11:42:27 2015 +0100

Closes ticket #2390, and also updates the RPI implementation.

makes rtems_gpio_bsp_get_value return uint32_t.  Motivation: simplify
beagle gpio implementation for common gpio apio.

---

 c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c |  2 +-
 c/src/lib/libbsp/shared/gpio.c                   | 18 ++++++++++++------
 c/src/lib/libbsp/shared/include/gpio.h           | 18 ++++++++++--------
 3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c b/c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c
index bd37e67..a782d11 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c
@@ -98,7 +98,7 @@ rtems_status_code rtems_gpio_bsp_clear(uint32_t bank, uint32_t pin)
   return RTEMS_SUCCESSFUL;
 }
 
-uint8_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin)
+uint32_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin)
 {
   return (BCM2835_REG(BCM2835_GPIO_GPLEV0) & (1 << pin));
 }
diff --git a/c/src/lib/libbsp/shared/gpio.c b/c/src/lib/libbsp/shared/gpio.c
index a87b39f..80e2727 100644
--- a/c/src/lib/libbsp/shared/gpio.c
+++ b/c/src/lib/libbsp/shared/gpio.c
@@ -911,7 +911,7 @@ uint32_t rtems_gpio_read_group(rtems_gpio_group *group)
   uint8_t i;
 
   if ( group->input_count == 0 ) {
-    return 0xDEADBEEF;
+    return GPIO_INPUT_ERROR;
   }
 
   bank = group->digital_input_bank;
@@ -1158,7 +1158,7 @@ uint32_t rtems_gpio_multi_read(
   sc = get_pin_bitmask(pin_numbers, pin_count, &bank, &bitmask, DIGITAL_INPUT);
 
   if ( sc != RTEMS_SUCCESSFUL ) {
-    return 0xDEADBEEF;
+    return GPIO_INPUT_ERROR;
   }
 
   ACQUIRE_LOCK(gpio_bank_state[bank].lock);
@@ -1250,11 +1250,11 @@ rtems_status_code rtems_gpio_clear(uint32_t pin_number)
   return sc;
 }
 
-uint8_t rtems_gpio_get_value(uint32_t pin_number)
+int rtems_gpio_get_value(uint32_t pin_number)
 {
   uint32_t bank;
   uint32_t pin;
-  int rv;
+  uint32_t rv;
 
   if ( pin_number < 0 || pin_number >= BSP_GPIO_PIN_COUNT ) {
     return -1;
@@ -1280,7 +1280,13 @@ uint8_t rtems_gpio_get_value(uint32_t pin_number)
 
   rv = rtems_gpio_bsp_get_value(bank, pin);
 
-  if ( gpio_pin_state[pin_number].logic_invert && rv > 0 ) {
+  if ( rv == GPIO_INPUT_ERROR ) {
+    RELEASE_LOCK(gpio_bank_state[bank].lock);
+
+    return -1;
+  }
+
+  if ( gpio_pin_state[pin_number].logic_invert ) {
     RELEASE_LOCK(gpio_bank_state[bank].lock);
 
     return !rv;
@@ -1288,7 +1294,7 @@ uint8_t rtems_gpio_get_value(uint32_t pin_number)
 
   RELEASE_LOCK(gpio_bank_state[bank].lock);
 
-  return ( rv > 0 ) ? 1 : rv;
+  return rv > 0;
 }
 
 rtems_status_code rtems_gpio_request_pin(
diff --git a/c/src/lib/libbsp/shared/include/gpio.h b/c/src/lib/libbsp/shared/include/gpio.h
index b2deb1e..54de5f1 100644
--- a/c/src/lib/libbsp/shared/include/gpio.h
+++ b/c/src/lib/libbsp/shared/include/gpio.h
@@ -57,6 +57,8 @@ extern "C" {
 #define INTERRUPT_SERVER_MODES RTEMS_TIMESLICE | RTEMS_PREEMPT
 #define INTERRUPT_SERVER_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
 
+#define GPIO_INPUT_ERROR ~0
+
 /**
  * @name GPIO data structures
  *
@@ -310,7 +312,7 @@ extern rtems_status_code rtems_gpio_write_group(
  *
  * @retval The function returns a 32-bit bitmask with the group's input pins
  *         current logical values.
- * @retval 0xDEADBEEF Group has no input pins.
+ * @retval GPIO_INPUT_ERROR Group has no input pins.
  */
 extern uint32_t rtems_gpio_read_group(rtems_gpio_group *group);
 
@@ -402,7 +404,7 @@ extern rtems_status_code rtems_gpio_multi_clear(
  *
  * @retval Bitmask with the values of the corresponding pins.
  *         0 for logical low and 1 for logical high.
- * @retval 0xDEADBEEF Could not read at least one pin level.
+ * @retval GPIO_INPUT_ERROR Could not read at least one pin level.
  */
 extern uint32_t rtems_gpio_multi_read(
   uint32_t *pin_numbers,
@@ -444,7 +446,7 @@ extern rtems_status_code rtems_gpio_clear(uint32_t pin_number);
  *         logical value.
  * @retval -1 Pin number is invalid, or not a digital input pin.
  */
-extern uint8_t rtems_gpio_get_value(uint32_t pin_number);
+extern int rtems_gpio_get_value(uint32_t pin_number);
 
 /**
  * @brief Requests multiple GPIO pin configurations. If the BSP provides
@@ -724,7 +726,7 @@ extern rtems_status_code rtems_gpio_bsp_multi_clear(
  *
  * @retval The function must return a bitmask with the values of the
  *         corresponding pins. 0 for logical low and 1 for logical high.
- * @retval 0xDEADBEEF Could not read at least one pin level.
+ * @retval GPIO_INPUT_ERROR Could not read at least one pin level.
  */
 extern uint32_t rtems_gpio_bsp_multi_read(uint32_t bank, uint32_t bitmask);
 
@@ -802,11 +804,11 @@ extern rtems_status_code rtems_gpio_bsp_clear(uint32_t bank, uint32_t pin);
  * @param[in] bank GPIO bank number.
  * @param[in] pin GPIO pin number within the given bank.
  *
- * @retval The function must return 0 or 1 depending on the pin current
- *         logical value.
- * @retval -1 Could not read the pin level.
+ * @retval The function must return 0 if the pin level is a logical low,
+ *         or non zero if it has a logical high.
+ * @retval GPIO_INPUT_ERROR Could not read the pin level.
  */
-extern uint8_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin);
+extern uint32_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin);
 
 /**
  * @brief Assigns the digital input function to the given pin.



More information about the vc mailing list