jviki / dtree Goto Github PK
View Code? Open in Web Editor NEWLibrary to access /proc/device-tree from userspace in an embedded Linux. Under GNU GPL license.
License: GNU Lesser General Public License v3.0
Library to access /proc/device-tree from userspace in an embedded Linux. Under GNU GPL license.
License: GNU Lesser General Public License v3.0
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.