2013-05-06 12:33:30 +00:00
|
|
|
/*
|
|
|
|
* \brief GPIO-session component
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-05-03
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2011-2017 Genode Labs GmbH
|
2013-05-06 12:33:30 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2013-05-06 12:33:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__GPIO__COMPONENT_H_
|
|
|
|
#define _INCLUDE__GPIO__COMPONENT_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;
|
2020-10-05 07:17:58 +00:00
|
|
|
Pin const &_pin;
|
2015-04-14 11:56:26 +00:00
|
|
|
|
2020-10-05 07:17:58 +00:00
|
|
|
Irq_session_component(Driver &driver, Pin const &pin)
|
2015-04-14 11:56:26 +00:00
|
|
|
: _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 {
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
return { .type = Info::Type::INVALID, .address = 0, .value = 0 }; }
|
2015-04-14 11:56:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Genode::Rpc_entrypoint &_ep;
|
|
|
|
Driver &_driver;
|
2020-10-05 07:17:58 +00:00
|
|
|
Pin const _pin;
|
2015-04-14 11:56:26 +00:00
|
|
|
|
|
|
|
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,
|
2020-10-05 07:17:58 +00:00
|
|
|
unsigned gpio_pin)
|
|
|
|
: _ep(ep), _driver(driver), _pin(Pin { gpio_pin }),
|
2015-04-14 11:56:26 +00:00
|
|
|
_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
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void direction(Direction d) override { _driver.direction(_pin, (d == IN)); }
|
|
|
|
void write(bool level) override { _driver.write(_pin, level); }
|
|
|
|
bool read() override { return _driver.read(_pin); }
|
2013-05-06 12:33:30 +00:00
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
void debouncing(unsigned int us) override
|
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
|
|
|
}
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Genode::Irq_session_capability irq_session(Irq_type type) override
|
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:
|
|
|
|
|
2019-02-14 21:39:08 +00:00
|
|
|
Session_component *_create_session(const char *args) override
|
2013-05-06 12:33:30 +00:00
|
|
|
{
|
2020-10-05 07:17:58 +00:00
|
|
|
unsigned pin =
|
2013-05-06 12:33:30 +00:00
|
|
|
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);
|
|
|
|
|
2020-10-05 07:17:58 +00:00
|
|
|
if (!_driver.gpio_valid(Pin { pin }))
|
Streamline exception types
This patch reduces the number of exception types by facilitating
globally defined exceptions for common usage patterns shared by most
services. In particular, RPC functions that demand a session-resource
upgrade not longer reflect this condition via a session-specific
exception but via the 'Out_of_ram' or 'Out_of_caps' types.
Furthermore, the 'Parent::Service_denied', 'Parent::Unavailable',
'Root::Invalid_args', 'Root::Unavailable', 'Service::Invalid_args',
'Service::Unavailable', and 'Local_service::Factory::Denied' types have
been replaced by the single 'Service_denied' exception type defined in
'session/session.h'.
This consolidation eases the error handling (there are fewer exceptions
to handle), alleviates the need to convert exceptions along the
session-creation call chain, and avoids possible aliasing problems
(catching the wrong type with the same name but living in a different
scope).
2017-05-07 20:03:22 +00:00
|
|
|
throw Genode::Service_denied();
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
if (ram_quota < sizeof(Session_component)) {
|
2016-09-15 12:40:37 +00:00
|
|
|
Genode::warning("insufficient dontated ram_quota "
|
|
|
|
"(", ram_quota, " bytes), "
|
|
|
|
"require ", sizeof(Session_component), " bytes");
|
2017-05-08 12:32:03 +00:00
|
|
|
throw Genode::Insufficient_ram_quota();
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
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_ */
|