arm/raspberrypi: add locking around GPIO pin function selection.

This is required if function or direction is changed by some driver
after start of thread multitasking or in interrupts drivers.

There can be problem with calling GPIO function selection before
data section is initialized. But actual ticket lock implementation
seems to be compatible even with memory initialized to zero oven
on SMP.
This commit is contained in:
Pavel Pisa
2016-05-19 10:34:18 +02:00
parent 4b62192f05
commit 12582291e0

View File

@@ -21,6 +21,8 @@
#include <stdlib.h>
RTEMS_INTERRUPT_LOCK_DEFINE( static, rtems_gpio_bsp_lock, "rtems_gpio_bsp_lock" );
/* Calculates a bitmask to assign an alternate function to a given pin. */
#define SELECT_PIN_FUNCTION(fn, pn) (fn << ((pn % 10) * 3))
@@ -56,11 +58,14 @@ static rtems_status_code rpi_select_pin_function(
(pin / 10);
uint32_t reg_old;
uint32_t reg_new;
rtems_interrupt_lock_context lock_context;
rtems_interrupt_lock_acquire(&rtems_gpio_bsp_lock, &lock_context);
reg_new = reg_old = *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);
return RTEMS_SUCCESSFUL;
}