[PATCH 11 minor addeum] arm/raspberrypi: GPIO - using RTEMS interrupt lock during BSP

Pavel Pisa pisa at cmp.felk.cvut.cz
Tue Sep 6 17:18:33 UTC 2016


Locking can be used only when RTEMS reaches multitasking state
  _System_state_Is_up( _System_state_Get() )
---
 c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 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 6c01d62..f7c8c36 100644
--- a/c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c
+++ b/c/src/lib/libbsp/arm/raspberrypi/gpio/rpi-gpio.c
@@ -19,6 +19,7 @@
 #include <bsp/irq-generic.h>
 #include <bsp/gpio.h>
 #include <bsp/rpi-gpio.h>
+#include <rtems/score/sysstate.h>
 
 #include <stdlib.h>
 
@@ -57,16 +58,21 @@ static rtems_status_code rpi_select_pin_function(
   /* Calculate the pin function select register address. */
   volatile uint32_t *pin_addr = (uint32_t *) BCM2835_GPIO_REGS_BASE +
                                              (pin / 10);
-  uint32_t reg_old;
   uint32_t reg_new;
+  int use_locks;
   rtems_interrupt_lock_context lock_context;
 
-  rtems_interrupt_lock_acquire(&rtems_gpio_bsp_lock, &lock_context);
-  reg_new = reg_old = *pin_addr;
+  use_locks = _System_state_Is_up( _System_state_Get() );
+  if ( use_locks )
+    rtems_interrupt_lock_acquire(&rtems_gpio_bsp_lock, &lock_context);
+
+  reg_new = *pin_addr;
   reg_new &= ~SELECT_PIN_FUNCTION(RPI_ALT_FUNC_MASK, pin);
   reg_new |= SELECT_PIN_FUNCTION(type, pin);
   *pin_addr = reg_new;
-  rtems_interrupt_lock_release(&rtems_gpio_bsp_lock, &lock_context);
+
+  if ( use_locks )
+    rtems_interrupt_lock_release(&rtems_gpio_bsp_lock, &lock_context);
 
   return RTEMS_SUCCESSFUL;
 }
-- 
1.9.1




More information about the devel mailing list