arm: Add nRF51 GPIO peripheral
RFC v2 1/2 arm: Add nRF51 GPIO peripheral
---
Changes in v2:
- Only call QEMU GPIO update handlers if value changes
- Code style changes
- Removed unused includes
hw/gpio/Makefile.objs | 1 + hw/gpio/nrf51_gpio.c | 320 +++++++++++++++++++++++++++++++++++ include/hw/gpio/nrf51_gpio.h | 57 +++++++ 3 files changed, 378 insertions(+) create mode 100644 hw/gpio/nrf51_gpio.c create mode 100644 include/hw/gpio/nrf51_gpio.h
hw/gpio/Makefile.objs +1 -0
@@ -8,3 +8,4 @@ common-obj-$(CONFIG_GPIO_KEY) += gpio_key.o obj-$(CONFIG_OMAP) += omap_gpio.o obj-$(CONFIG_IMX) += imx_gpio.o obj-$(CONFIG_RASPI) += bcm2835_gpio.o +obj-$(CONFIG_NRF51_SOC) += nrf51_gpio.o
hw/gpio/nrf51_gpio.c new file +320 -0
320 lines not on this page · raw message
include/hw/gpio/nrf51_gpio.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.18.0
RFC v2 2/2 arm: Add nRF51 GPIO tests
--- tests/microbit-test.c | 7 +++++++ 1 file changed, 7 insertions(+)
tests/microbit-test.c +7 -0
@@ -101,6 +101,12 @@ static void test_nrf51_nvmc(void) } } +static void test_nrf51_gpio (void ) +{ +/* TODO add tests for GPIO */ +g_assert_true (false); +} +int main (int argc,char **argv) {int ret;
@@ -110,6 +116,7 @@ int main(int argc, char **argv) global_qtest =qtest_startf ("-machine microbit" );qtest_add_func ("/microbit/nrf51/nvmc" , test_nrf51_nvmc); +qtest_add_func ("/microbit/nrf51/gpio" , test_nrf51_gpio); ret =g_test_run ();
Signature · 1 line
2.18.0
Quoted 7 lines · Steffen Görtz
Signed-off-by Steffen Görtz <[email protected]>---
Changes in v2:
- Only call QEMU GPIO update handlers if value changes
- Code style changes
- Removed unused includes
Quoted 6 lines
hw/gpio/Makefile.objs | 1 + hw/gpio/nrf51_gpio.c | 320 +++++++++++++++++++++++++++++++++++ include/hw/gpio/nrf51_gpio.h | 57 +++++++ 3 files changed, 378 insertions(+) create mode 100644 hw/gpio/nrf51_gpio.c create mode 100644 include/hw/gpio/nrf51_gpio.h
Hi Steffen,
Sorry I didn't see this patch series. Please email [email protected] in the future. The way I have GMail set up means qemu-devel threads with [email protected] CCed are not brought to my attention immediately.
I have checked the nRF51 GPIO documentation and your implementation looks good.
Quoted 22 lines
hw/gpio/nrf51_gpio.c new file +22
-0+static void gpio_write (void *opaque,hwaddr offset, +uint64_t value,unsigned int size) +{ +Nrf51GPIOState *s =NRF51_GPIO (opaque); +size_t idx; + +switch (offset) { +case NRF51_GPIO_REG_OUT : +DPRINTF ("write out=0x%" PRIx32"\n" , (uint32_t )value); + s->out = value; +gpio_update_state (s); +break ; +case NRF51_GPIO_REG_OUTSET : +DPRINTF ("set out=0x%" PRIx32"\n" , (uint32_t )value); + s->out |= value; +gpio_update_state (s); +break ; +case NRF51_GPIO_REG_OUTCLR : +DPRINTF ("clr out=0x%" PRIx32"\n" , (uint32_t )value); + s->out &= ~value; +gpio_update_state (s); +break ;
hw/gpio/nrf51_gpio.c line 206
Quoted 10 lines
hw/gpio/nrf51_gpio.c new file +10
-0+case NRF51_GPIO_REG_DIR : +DPRINTF ("write dir=0x%" PRIx32"\n" , (uint32_t )value); + s->dir = value; +/* direction is exposed in both the DIR register and the DIR bit +* of each PINs CNF configuration register. */ +for (size_t i =0 ; i <NRF51_GPIO_PINS ; i++) { + s->cnf[i] = (s->cnf[i] & ~(1UL )) | ((value >> i) &0x01 ); + } +gpio_update_state (s); +break ;
Missing DIRSET and DIRCLR?