2013-05-06 12:33:30 +00:00
|
|
|
/*
|
|
|
|
* \brief Access to GPIO driver configuration
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2013-05-06
|
|
|
|
*
|
|
|
|
* Taken from the OMAP4 GPIO driver written by Ivan Loskutov.
|
|
|
|
*
|
|
|
|
* Configure GPIO
|
|
|
|
* Example:
|
|
|
|
* <config>
|
|
|
|
* <gpio num="123" mode="I"/>
|
|
|
|
* <gpio num="124" mode="O" value="0"/>
|
|
|
|
* </config>
|
|
|
|
*
|
|
|
|
* num - GPIO pin number
|
|
|
|
* mode - input(I) or output(O)
|
|
|
|
* value - output level (1 or 0), only for output mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2010-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__CONFIG_H_
|
|
|
|
#define _INCLUDE__GPIO__CONFIG_H_
|
|
|
|
|
2017-02-23 13:32:20 +00:00
|
|
|
/* Genode includes */
|
2013-05-06 12:33:30 +00:00
|
|
|
#include <base/exception.h>
|
|
|
|
#include <gpio/driver.h>
|
2017-02-23 13:32:20 +00:00
|
|
|
#include <util/xml_node.h>
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
namespace Gpio {
|
2015-03-04 20:12:14 +00:00
|
|
|
|
2013-05-06 12:33:30 +00:00
|
|
|
class Invalid_gpio_number : Genode::Exception {};
|
|
|
|
class Invalid_mode : Genode::Exception {};
|
|
|
|
|
2017-02-23 13:32:20 +00:00
|
|
|
static void process_config(Genode::Xml_node const &config, Gpio::Driver &driver);
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-23 13:32:20 +00:00
|
|
|
void Gpio::process_config(Genode::Xml_node const &config, Gpio::Driver &driver)
|
2015-03-04 20:12:14 +00:00
|
|
|
{
|
2013-05-06 12:33:30 +00:00
|
|
|
try {
|
2017-02-23 13:32:20 +00:00
|
|
|
Genode::Xml_node gpio_node = config.sub_node("gpio");
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
for (;; gpio_node = gpio_node.next("gpio")) {
|
|
|
|
unsigned num = 0;
|
|
|
|
char mode[2] = {0};
|
|
|
|
unsigned value = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
gpio_node.attribute("num").value(&num);
|
|
|
|
if (!driver.gpio_valid(num)) throw Invalid_gpio_number();
|
|
|
|
gpio_node.attribute("mode").value(mode, sizeof(mode));
|
|
|
|
if (mode[0] == 'O' || mode[0] == 'o') {
|
|
|
|
gpio_node.attribute("value").value(&value);
|
|
|
|
driver.write(num, value);
|
|
|
|
driver.direction(num, false);
|
|
|
|
} else if (mode[0] == 'I' || mode[0] == 'i') {
|
|
|
|
driver.direction(num, true);
|
|
|
|
} else throw Invalid_mode();
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::log("gpio ", num, " "
|
|
|
|
"mode ", Genode::Cstring(mode), " "
|
|
|
|
"value=", value);
|
2013-05-06 12:33:30 +00:00
|
|
|
|
|
|
|
} catch(Genode::Xml_node::Nonexistent_attribute) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::warning("missing attribute. Ignore node.");
|
2013-05-06 12:33:30 +00:00
|
|
|
} catch(Gpio::Invalid_gpio_number) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::warning("invalid GPIO number ", num, ", ignore node");
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
2016-05-11 16:21:47 +00:00
|
|
|
if (gpio_node.last("gpio")) break;
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Genode::Xml_node::Nonexistent_sub_node) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::warning("no GPIO config");
|
2013-05-06 12:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__GPIO__CONFIG_H_ */
|