2013-05-06 12:33:30 +00:00
|
|
|
/*
|
|
|
|
* \brief GPIO-session component
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-05-03
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2015-04-14 11:56:26 +00:00
|
|
|
* Copyright (C) 2011-2015 Genode Labs GmbH
|
2013-05-06 12:33:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
|
|
|
* under the terms of the GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__GPIO__COMPONENT_H_
|
|
|
|
#define _INCLUDE__GPIO__COMPONENT_H_
|
|
|
|
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <root/component.h>
|
|
|
|
#include <gpio_session/gpio_session.h>
|
|
|
|
#include <gpio/driver.h>
|
|
|
|
|
|
|
|
namespace Gpio {
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2013-05-06 12:33:30 +00:00
|
|
|
class Session_component;
|
|
|
|
class Root;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Gpio::Session_component : public Genode::Rpc_object<Gpio::Session>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
struct Irq_session_component : public Genode::Rpc_object<Genode::Irq_session>
|
|
|
|
{
|
|
|
|
Driver &_driver;
|
|
|
|
unsigned long _pin;
|
|
|
|
|
|
|
|
Irq_session_component(Driver &driver, unsigned long pin)
|
|
|
|
: _driver(driver), _pin(pin) { }
|
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
** Irq_session interface **
|
|
|
|
***************************/
|
|
|
|
|
|
|
|
void ack_irq() override { _driver.ack_irq(_pin); }
|
|
|
|
void sigh(Genode::Signal_context_capability sigh) override {
|
|
|
|
_driver.register_signal(_pin, sigh); }
|
2015-04-27 10:17:20 +00:00
|
|
|
Info info() override {
|
|
|
|
return { .type = Genode::Irq_session::Info::Type::INVALID }; }
|
2015-04-14 11:56:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Genode::Rpc_entrypoint &_ep;
|
|
|
|
Driver &_driver;
|
|
|
|
unsigned long _pin;
|
|
|
|
|
|
|
|
Irq_session_component _irq_component;
|
|
|
|
Genode::Irq_session_capability _irq_cap;
|
|
|
|
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
Session_component(Genode::Rpc_entrypoint &ep,
|
|
|
|
Driver &driver,
|
|
|
|
unsigned long gpio_pin)
|
|
|
|
: _ep(ep), _driver(driver), _pin(gpio_pin),
|
|
|
|
_irq_component(_driver, _pin),
|
|
|
|
_irq_cap(_ep.manage(&_irq_component)) { }
|
|
|
|
|
|
|
|
~Session_component() { _ep.dissolve(&_irq_component); }
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
/*****************************
|
2013-05-06 12:33:30 +00:00
|
|
|
** Gpio::Session interface **
|
2015-04-14 11:56:26 +00:00
|
|
|
*****************************/
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
void direction(Direction d) { _driver.direction(_pin, (d == IN)); }
|
|
|
|
void write(bool level) { _driver.write(_pin, level); }
|
|
|
|
bool read() { return _driver.read(_pin); }
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
void debouncing(unsigned int us)
|
2013-05-06 12:33:30 +00:00
|
|
|
{
|
2015-04-14 11:56:26 +00:00
|
|
|
if (us) {
|
|
|
|
_driver.debounce_time(_pin, us);
|
|
|
|
_driver.debounce_enable(_pin, true);
|
|
|
|
} else
|
|
|
|
_driver.debounce_enable(_pin, false);
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
Genode::Irq_session_capability irq_session(Irq_type type)
|
2013-05-06 12:33:30 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case HIGH_LEVEL:
|
|
|
|
_driver.high_detect(_pin);
|
|
|
|
break;
|
|
|
|
case LOW_LEVEL:
|
|
|
|
_driver.low_detect(_pin);
|
|
|
|
break;
|
|
|
|
case RISING_EDGE:
|
|
|
|
_driver.rising_detect(_pin);
|
|
|
|
break;
|
|
|
|
case FALLING_EDGE:
|
|
|
|
_driver.falling_detect(_pin);
|
|
|
|
};
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
_driver.irq_enable(_pin, true);
|
|
|
|
|
|
|
|
return _irq_cap;
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Gpio::Root : public Genode::Root_component<Gpio::Session_component>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
Genode::Rpc_entrypoint &_ep;
|
|
|
|
Driver &_driver;
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Session_component *_create_session(const char *args)
|
|
|
|
{
|
|
|
|
unsigned long pin =
|
|
|
|
Genode::Arg_string::find_arg(args, "gpio").ulong_value(0);
|
|
|
|
Genode::size_t ram_quota =
|
|
|
|
Genode::Arg_string::find_arg(args, "ram_quota").ulong_value(0);
|
|
|
|
|
|
|
|
if (!_driver.gpio_valid(pin))
|
|
|
|
throw Invalid_args();
|
|
|
|
|
|
|
|
if (ram_quota < sizeof(Session_component)) {
|
|
|
|
PWRN("Insufficient dontated ram_quota (%zd bytes), require %zd bytes",
|
|
|
|
ram_quota, sizeof(Session_component));
|
|
|
|
throw Genode::Root::Quota_exceeded();
|
|
|
|
}
|
|
|
|
|
2015-04-14 11:56:26 +00:00
|
|
|
return new (md_alloc()) Session_component(_ep, _driver, pin);
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Root(Genode::Rpc_entrypoint *session_ep,
|
|
|
|
Genode::Allocator *md_alloc, Driver &driver)
|
|
|
|
: Genode::Root_component<Gpio::Session_component>(session_ep, md_alloc),
|
2015-04-14 11:56:26 +00:00
|
|
|
_ep(*session_ep), _driver(driver) { }
|
2013-05-06 12:33:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__GPIO__COMPONENT_H_ */
|