Coder Social home page Coder Social logo

jviki / dtree Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 8.0 123 KB

Library to access /proc/device-tree from userspace in an embedded Linux. Under GNU GPL license.

License: GNU Lesser General Public License v3.0

C 94.57% C++ 1.18% Lua 0.78% Makefile 3.47%

dtree's Introduction

Library dtree
=============

The library can be used to read information about devices that is
located in _device tree_ structure. In Linux this is usually placed
at `/proc/device-tree`. Device tree is available in embedded devices.


Tutorial
--------

The public API of the library is located in `dtree.h`. It contains a lot of
documentation that should be up to date. The API consists of several functions
to access the tree. Currently there is only one implementation of that API:
`dtree_procfs.c` that is used to parse the directory structure of `/proc/device-tree`.

The core of the library is structure `dtree_dev_t`. It contains the information
about the device. Currently it offers these properties:

* `name` - name of the device
* `base` - base address of the device
* `high` - highest address of the device (not mandatory, can be set to be <= `base`, if not available)
* `compat` - array of compatible device types (finished with NULL)

The library is not reentrant and thus not thread safe. If it is successfully
initialized by call dtree_open() it has to be closed by dtree_close() before
program exit to free resources (even on die call...).


### Look up a device

	int err = dtree_open("/proc/device-tree");
	die_on_error(err);

	struct dtree_dev_t *eth = dtree_byname("ethernet");
	if(eth == 0)
		die_no_ethernet();

	process_eth(eth);
	dtree_dev_free(eth);

	dtree_close();

Note call to `dtree_dev_free()` after the device information
is not used anymore.


### List available devices

	int err = dtree_open("/proc/device-tree");
	die_on_error(err);

	struct dtree_dev_t *dev = NULL;
	while((dev = dtree_next()) != NULL) {
		process_dev(dev);
		dtree_dev_free(dev);
	}

	dtree_close();

### Search again with reset

	// declarations, open dtree...
	
	eth = dtree_byname("ethernet");
	dtree_reset();
	serial = dtree_byname("serial");

	process(eth, serial);
	dtree_dev_free(eth);
	dtree_dev_free(serial);

	// go on and finally close dtree...


### Error handling

	// declarations...

	if(dtree_open(DT_PATH) != 0) {
		die(dtree_errstr());
	}

	eth = dtree_byname("ethernet");
	if(eth == NULL) {
		if(dtree_iserror())
			die(dtree_errstr());
		else
			die("Ethernet device is not present in the system");
	}

	dtree_close();


Testing
-------

Testing of the library is done in `test/` directory. There are few simple tests based
on fake `device-tree` directory structure.

dtree's People

Contributors

jviki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dtree's Issues

Using LGPLv3 as license

Hi jviki.

I am intending to use dtree library. This fit very well to my needs. However I have one suggestion about the license that dtree was release. It's possible to use LGPLv3 instead of GPLv3 ?.

Please, if this request will cause some trouble discard it.

Thanks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.