Ticket #2390: 0001-Closes-ticket-2390-and-also-updates-the-RPI-implemen.patch

File 0001-Closes-ticket-2390-and-also-updates-the-RPI-implemen.patch, 5.4 KB (added by André Marques, on Aug 17, 2015 at 10:50:44 AM)

Added ben and gedare suggestions.

  • c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c

    From 421115643014a36f7cd6a2b77e015355c49d3efb Mon Sep 17 00:00:00 2001
    From: Andre Marques <andre.lousa.marques@gmail.com>
    Date: Mon, 17 Aug 2015 11:42:27 +0100
    Subject: [PATCH] Closes ticket #2390, and also updates the RPI implementation.
    
    ---
     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 b rtems_status_code rtems_gpio_bsp_clear(uint32_t bank, uint32_t pin) 
    9898  return RTEMS_SUCCESSFUL;
    9999}
    100100
    101 uint8_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin)
     101uint32_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin)
    102102{
    103103  return (BCM2835_REG(BCM2835_GPIO_GPLEV0) & (1 << pin));
    104104}
  • c/src/lib/libbsp/shared/gpio.c

    diff --git a/c/src/lib/libbsp/shared/gpio.c b/c/src/lib/libbsp/shared/gpio.c
    index a87b39f..80e2727 100644
    a b uint32_t rtems_gpio_read_group(rtems_gpio_group *group) 
    911911  uint8_t i;
    912912
    913913  if ( group->input_count == 0 ) {
    914     return 0xDEADBEEF;
     914    return GPIO_INPUT_ERROR;
    915915  }
    916916
    917917  bank = group->digital_input_bank;
    uint32_t rtems_gpio_multi_read( 
    11581158  sc = get_pin_bitmask(pin_numbers, pin_count, &bank, &bitmask, DIGITAL_INPUT);
    11591159
    11601160  if ( sc != RTEMS_SUCCESSFUL ) {
    1161     return 0xDEADBEEF;
     1161    return GPIO_INPUT_ERROR;
    11621162  }
    11631163
    11641164  ACQUIRE_LOCK(gpio_bank_state[bank].lock);
    rtems_status_code rtems_gpio_clear(uint32_t pin_number) 
    12501250  return sc;
    12511251}
    12521252
    1253 uint8_t rtems_gpio_get_value(uint32_t pin_number)
     1253int rtems_gpio_get_value(uint32_t pin_number)
    12541254{
    12551255  uint32_t bank;
    12561256  uint32_t pin;
    1257   int rv;
     1257  uint32_t rv;
    12581258
    12591259  if ( pin_number < 0 || pin_number >= BSP_GPIO_PIN_COUNT ) {
    12601260    return -1;
    uint8_t rtems_gpio_get_value(uint32_t pin_number) 
    12801280
    12811281  rv = rtems_gpio_bsp_get_value(bank, pin);
    12821282
    1283   if ( gpio_pin_state[pin_number].logic_invert && rv > 0 ) {
     1283  if ( rv == GPIO_INPUT_ERROR ) {
     1284    RELEASE_LOCK(gpio_bank_state[bank].lock);
     1285
     1286    return -1;
     1287  }
     1288
     1289  if ( gpio_pin_state[pin_number].logic_invert ) {
    12841290    RELEASE_LOCK(gpio_bank_state[bank].lock);
    12851291
    12861292    return !rv;
    uint8_t rtems_gpio_get_value(uint32_t pin_number) 
    12881294
    12891295  RELEASE_LOCK(gpio_bank_state[bank].lock);
    12901296
    1291   return ( rv > 0 ) ? 1 : rv;
     1297  return rv > 0;
    12921298}
    12931299
    12941300rtems_status_code rtems_gpio_request_pin(
  • c/src/lib/libbsp/shared/include/gpio.h

    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 b extern "C" { 
    5757#define INTERRUPT_SERVER_MODES RTEMS_TIMESLICE | RTEMS_PREEMPT
    5858#define INTERRUPT_SERVER_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
    5959
     60#define GPIO_INPUT_ERROR ~0
     61
    6062/**
    6163 * @name GPIO data structures
    6264 *
    extern rtems_status_code rtems_gpio_write_group( 
    310312 *
    311313 * @retval The function returns a 32-bit bitmask with the group's input pins
    312314 *         current logical values.
    313  * @retval 0xDEADBEEF Group has no input pins.
     315 * @retval GPIO_INPUT_ERROR Group has no input pins.
    314316 */
    315317extern uint32_t rtems_gpio_read_group(rtems_gpio_group *group);
    316318
    extern rtems_status_code rtems_gpio_multi_clear( 
    402404 *
    403405 * @retval Bitmask with the values of the corresponding pins.
    404406 *         0 for logical low and 1 for logical high.
    405  * @retval 0xDEADBEEF Could not read at least one pin level.
     407 * @retval GPIO_INPUT_ERROR Could not read at least one pin level.
    406408 */
    407409extern uint32_t rtems_gpio_multi_read(
    408410  uint32_t *pin_numbers,
    extern rtems_status_code rtems_gpio_clear(uint32_t pin_number); 
    444446 *         logical value.
    445447 * @retval -1 Pin number is invalid, or not a digital input pin.
    446448 */
    447 extern uint8_t rtems_gpio_get_value(uint32_t pin_number);
     449extern int rtems_gpio_get_value(uint32_t pin_number);
    448450
    449451/**
    450452 * @brief Requests multiple GPIO pin configurations. If the BSP provides
    extern rtems_status_code rtems_gpio_bsp_multi_clear( 
    724726 *
    725727 * @retval The function must return a bitmask with the values of the
    726728 *         corresponding pins. 0 for logical low and 1 for logical high.
    727  * @retval 0xDEADBEEF Could not read at least one pin level.
     729 * @retval GPIO_INPUT_ERROR Could not read at least one pin level.
    728730 */
    729731extern uint32_t rtems_gpio_bsp_multi_read(uint32_t bank, uint32_t bitmask);
    730732
    extern rtems_status_code rtems_gpio_bsp_clear(uint32_t bank, uint32_t pin); 
    802804 * @param[in] bank GPIO bank number.
    803805 * @param[in] pin GPIO pin number within the given bank.
    804806 *
    805  * @retval The function must return 0 or 1 depending on the pin current
    806  *         logical value.
    807  * @retval -1 Could not read the pin level.
     807 * @retval The function must return 0 if the pin level is a logical low,
     808 *         or non zero if it has a logical high.
     809 * @retval GPIO_INPUT_ERROR Could not read the pin level.
    808810 */
    809 extern uint8_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin);
     811extern uint32_t rtems_gpio_bsp_get_value(uint32_t bank, uint32_t pin);
    810812
    811813/**
    812814 * @brief Assigns the digital input function to the given pin.