mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-18 17:00:26 +00:00
gpio: examples for GPIO driver
This commit is contained in:
parent
98da445269
commit
750b10b957
73
repos/os/run/gpio_led.run
Normal file
73
repos/os/run/gpio_led.run
Normal file
@ -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 {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
<service name="RAM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="CAP"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="SIGNAL"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>
|
||||
<start name="gpio_drv">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Gpio"/></provides>
|
||||
<config>
|
||||
<gpio num="16" mode="O" value="0"/>
|
||||
</config>
|
||||
</start>
|
||||
<start name="led_gpio_drv">
|
||||
<config gpio_pin="16" delay="500" times="5"/>
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
</start>
|
||||
</config>}
|
||||
|
||||
install_config $config
|
||||
|
||||
#
|
||||
# Boot modules
|
||||
#
|
||||
|
||||
# generic modules
|
||||
set boot_modules {
|
||||
core init
|
||||
timer
|
||||
gpio_drv
|
||||
led_gpio_drv
|
||||
}
|
||||
|
||||
build_boot_image $boot_modules
|
76
repos/os/run/gpio_signal.run
Normal file
76
repos/os/run/gpio_signal.run
Normal file
@ -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 {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
<service name="RAM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="CAP"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="SIGNAL"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>
|
||||
<start name="gpio_drv">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Gpio"/></provides>
|
||||
<config async_events="0">
|
||||
<gpio num="14" function="0"/>
|
||||
<gpio num="15" function="0"/>
|
||||
<gpio num="17" mode="I"/>
|
||||
<gpio num="16" mode="O" value="0"/>
|
||||
</config>
|
||||
</start>
|
||||
<start name="signal_gpio_drv">
|
||||
<config gpio_pin="16" gpio_pin_in="17" gpio_pin_out="18" state="1"/>
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
</start>
|
||||
</config>}
|
||||
|
||||
install_config $config
|
||||
|
||||
#
|
||||
# Boot modules
|
||||
#
|
||||
|
||||
# generic modules
|
||||
set boot_modules {
|
||||
core init
|
||||
timer
|
||||
gpio_drv
|
||||
signal_gpio_drv
|
||||
}
|
||||
|
||||
build_boot_image $boot_modules
|
57
repos/os/src/test/gpio_led/main.cc
Normal file
57
repos/os/src/test/gpio_led/main.cc
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* \brief Test GPIO driver with Leds
|
||||
* \author Reinier Millo Sánchez <rmillo@uclv.cu>
|
||||
* \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 <base/printf.h>
|
||||
#include <base/signal.h>
|
||||
#include <gpio_session/connection.h>
|
||||
#include <irq_session/client.h>
|
||||
#include <util/mmio.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
#include <os/config.h>
|
||||
|
||||
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;
|
||||
}
|
6
repos/os/src/test/gpio_led/target.mk
Normal file
6
repos/os/src/test/gpio_led/target.mk
Normal file
@ -0,0 +1,6 @@
|
||||
TARGET = led_gpio_drv
|
||||
REQUIRES = gpio
|
||||
SRC_CC = main.cc
|
||||
LIBS = base config
|
||||
|
||||
vpath main.cc $(PRG_DIR)
|
111
repos/os/src/test/gpio_signal/main.cc
Normal file
111
repos/os/src/test/gpio_signal/main.cc
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* \brief Test GPIO driver
|
||||
* \author Reinier Millo Sánchez <rmillo@uclv.cu>
|
||||
* \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 <base/printf.h>
|
||||
#include <base/signal.h>
|
||||
#include <gpio_session/connection.h>
|
||||
#include <irq_session/client.h>
|
||||
#include <util/mmio.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
#include <os/config.h>
|
||||
|
||||
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;
|
||||
}
|
7
repos/os/src/test/gpio_signal/target.mk
Normal file
7
repos/os/src/test/gpio_signal/target.mk
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user