From 750b10b9579fecaf52d70221c80f4e843c68c028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinier=20Millo=20S=C3=A1nchez?= Date: Mon, 24 Aug 2015 16:35:01 -0400 Subject: [PATCH] gpio: examples for GPIO driver --- repos/os/run/gpio_led.run | 73 ++++++++++++++++ repos/os/run/gpio_signal.run | 76 ++++++++++++++++ repos/os/src/test/gpio_led/main.cc | 57 ++++++++++++ repos/os/src/test/gpio_led/target.mk | 6 ++ repos/os/src/test/gpio_signal/main.cc | 111 ++++++++++++++++++++++++ repos/os/src/test/gpio_signal/target.mk | 7 ++ 6 files changed, 330 insertions(+) create mode 100644 repos/os/run/gpio_led.run create mode 100644 repos/os/run/gpio_signal.run create mode 100644 repos/os/src/test/gpio_led/main.cc create mode 100644 repos/os/src/test/gpio_led/target.mk create mode 100644 repos/os/src/test/gpio_signal/main.cc create mode 100644 repos/os/src/test/gpio_signal/target.mk diff --git a/repos/os/run/gpio_led.run b/repos/os/run/gpio_led.run new file mode 100644 index 0000000000..f4109bcdcd --- /dev/null +++ b/repos/os/run/gpio_led.run @@ -0,0 +1,73 @@ +# +# Build +# +if {[have_spec gpio] == 0} { + puts "Runs only on platforms with GPIO" + exit 0 +} + +set build_components { + core init + drivers/timer drivers/gpio + test/gpio_led +} + +build $build_components + +create_boot_directory + +# +# Generate config +# Example preconfigured for RaspberryPI ACT Led +# + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init + timer + gpio_drv + led_gpio_drv +} + +build_boot_image $boot_modules diff --git a/repos/os/run/gpio_signal.run b/repos/os/run/gpio_signal.run new file mode 100644 index 0000000000..a412d4fee5 --- /dev/null +++ b/repos/os/run/gpio_signal.run @@ -0,0 +1,76 @@ +# +# Build +# +if {[have_spec gpio] == 0} { + puts "Runs only on platforms with GPIO" + exit 0 +} + +set build_components { + core init + drivers/timer drivers/gpio + test/gpio_signal +} + +build $build_components + +create_boot_directory + +# +# Generate config +# Example preconfigured for RaspberryPI ACT Led +# + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init + timer + gpio_drv + signal_gpio_drv +} + +build_boot_image $boot_modules diff --git a/repos/os/src/test/gpio_led/main.cc b/repos/os/src/test/gpio_led/main.cc new file mode 100644 index 0000000000..cb0379ddc9 --- /dev/null +++ b/repos/os/src/test/gpio_led/main.cc @@ -0,0 +1,57 @@ +/* + * \brief Test GPIO driver with Leds + * \author Reinier Millo Sánchez + * \date 2015-07-26 + */ + +/* + * Copyright (C) 2012-2015 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#include +#include +#include +#include +#include +#include + +#include + +int main(int, char **) +{ + unsigned int _delay = 1000; + unsigned int _gpio_pin = 16; + unsigned int _times = 10; + + try { + Genode::config()->xml_node().attribute("gpio_pin").value(&_gpio_pin); + } catch (...) { } + + try { + Genode::config()->xml_node().attribute("delay").value(&_delay); + } catch (...) { } + + try { + Genode::config()->xml_node().attribute("times").value(&_times); + } catch (...) { } + + PDBG("--- GPIO Led test [GPIO Pin: %d, Timer delay: %d, Times: %d] ---",_gpio_pin, _delay, _times); + + Gpio::Connection _led(_gpio_pin); + Timer::Connection _timer; + + while(_times--) + { + PDBG("Remains blinks: %d",_times); + _led.write(false); + _timer.msleep(_delay); + _led.write(true); + _timer.msleep(_delay); + } + + Genode::printf("Test finished\n"); + return 0; +} diff --git a/repos/os/src/test/gpio_led/target.mk b/repos/os/src/test/gpio_led/target.mk new file mode 100644 index 0000000000..9a94cad9cd --- /dev/null +++ b/repos/os/src/test/gpio_led/target.mk @@ -0,0 +1,6 @@ +TARGET = led_gpio_drv +REQUIRES = gpio +SRC_CC = main.cc +LIBS = base config + +vpath main.cc $(PRG_DIR) diff --git a/repos/os/src/test/gpio_signal/main.cc b/repos/os/src/test/gpio_signal/main.cc new file mode 100644 index 0000000000..33bcc83d1d --- /dev/null +++ b/repos/os/src/test/gpio_signal/main.cc @@ -0,0 +1,111 @@ +/* + * \brief Test GPIO driver + * \author Reinier Millo Sánchez + * \date 2015-07-26 + */ + +/* + * Copyright (C) 2012-2015 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#include +#include +#include +#include +#include +#include + +#include + +using namespace Genode; + +int main(int, char **) +{ + Signal_receiver sig_rec; + Signal_context sig_ctx; + Timer::Connection _timer; + + unsigned _gpio_pin = 16; + unsigned _gpio_pin_in = 17; + unsigned _gpio_pin_out = 18; + unsigned _tmp = 0; + bool _state = false; + + try { + Genode::config()->xml_node().attribute("gpio_pin").value(&_gpio_pin); + } catch (...) { } + + try { + Genode::config()->xml_node().attribute("gpio_pin_in").value(&_gpio_pin_in); + } catch (...) { } + + try { + Genode::config()->xml_node().attribute("gpio_pin_out").value(&_gpio_pin_out); + } catch (...) { } + + try { + Genode::config()->xml_node().attribute("state").value(&_tmp); + } catch (...) { } + _state = _tmp>0; + + PDBG("--- GPIO Signals test [LED pin: %d, Input pin: %d, Output pin: %d, Initial state: %d] ---", _gpio_pin, _gpio_pin_in, _gpio_pin_out, _state); + + Gpio::Connection _led(_gpio_pin); + Gpio::Connection _signal_input(_gpio_pin_in); + Gpio::Connection _signal_output(_gpio_pin_out); + + /* + * Set pins direction. + * This values can be set by configuration + */ + _signal_input.direction(Gpio::Session::IN); + _signal_output.direction(Gpio::Session::OUT); + + + /* + * Power on the signal output + */ + _signal_output.write(true); + + + /* + * Initialize the pin IRQ signal + */ + Genode::Irq_session_client irq(_signal_input.irq_session(Gpio::Session::HIGH_LEVEL)); + irq.sigh(sig_rec.manage(&sig_ctx)); + irq.ack_irq(); + + while(1) + { + _state = !_state; + _led.write(_state); + + /* + * Wait for a GIO signal on _signal_input + */ + sig_rec.wait_for_signal(); + + /* + * Small delay between push button actions + */ + _timer.msleep(100); + + /* + * Switch the LED state + */ + if(!_state) + { + PDBG("Led going OFF"); + }else + { + PDBG("Led going ON"); + } + + irq.ack_irq(); + } + + return 0; +} diff --git a/repos/os/src/test/gpio_signal/target.mk b/repos/os/src/test/gpio_signal/target.mk new file mode 100644 index 0000000000..235be5b186 --- /dev/null +++ b/repos/os/src/test/gpio_signal/target.mk @@ -0,0 +1,7 @@ +TARGET = signal_gpio_drv +REQUIRES = gpio +SRC_CC = main.cc +INC_DIR += $(PRG_DIR) +LIBS = base config + +vpath main.cc $(PRG_DIR)