Skip to content

Introducing SAUL, the [S]ensor [A]ctuator [U]ber [L]ayer#3538

Merged
kaspar030 merged 14 commits intoRIOT-OS:masterfrom
haukepetersen:add_sensif_actif
Dec 1, 2015
Merged

Introducing SAUL, the [S]ensor [A]ctuator [U]ber [L]ayer#3538
kaspar030 merged 14 commits intoRIOT-OS:masterfrom
haukepetersen:add_sensif_actif

Conversation

@haukepetersen
Copy link
Copy Markdown
Contributor

Let me introduce to you RASI - the all new generic [R]IOT [A]ctuator [S]ensor [I]nterface.
EDIT Let me introduce to you SAUL - the all new generic [S]ensor [A]ctuator [U]ber [L]ayer.
I had a nice idea for making all sensors and actuator in a system available via a unified API, and here are the results.

The concepts are very similar to (grnc) netdev and netif - every actuator and sensor is accessible through the same API (read and write for now) with one single data structure used of parameter passing -> phydat_t. All devices register at a central location and can then be listed, queried, searched and accessed. By specifying unique classes of devices, one could search for: "give me all sensors, that read pressure values" or similar.

This data structure phydat_t is made for carrying up to 3 dimensions of physical values, e.g. values read by sensor or set values for actuators. It takes only ~8 byte and contains additional to the data the physical unit and a scaling factor.

Also I included the sensors for auto-initialization, exactly in the same way we do it for network interfaces: In the board or in the application you just define a set of parameters for a device, and auto-init takes care of the rest.

Testing this PR is best done on the iot-lab_M3, as I included all 4 sensors and 3 LED (actuators) into this PR. A little comparison:

Code size of the default example before:

   text    data     bss     dec     hex
  28592     168    7304   36064    8ce0

and after:

   text    data     bss     dec     hex
  27648     168    7408   35224    8998

We save ~900 byte of flash and lose ~100byte of RAM. The saved flash is mainly due to one unified shell command (instead of one for each sensor before). The lost RAM is spend on the RASI registry, in this setup there are 8 devices in it (5 sensor entries, 3 LEDs) and one entry is 12 byte...

EDIT
The amount of touched files looks worse than it is - this PR is based on #3535 and #3420.
Removed all dependencies

@haukepetersen haukepetersen added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: new feature The issue requests / The PR implemements a new feature for RIOT Impact: major The PR changes a significant part of the code base. It should be reviewed carefully State: waiting for other PR State: The PR requires another PR to be merged first Area: drivers Area: Device drivers Feature Request labels Jul 31, 2015
@haukepetersen haukepetersen added this to the Release 2015.06 milestone Jul 31, 2015
@miri64
Copy link
Copy Markdown
Member

miri64 commented Aug 1, 2015

You might want to overthink that name ;-)

@haukepetersen
Copy link
Copy Markdown
Contributor Author

possibly... Any better ideas?

@miri64
Copy link
Copy Markdown
Member

miri64 commented Aug 1, 2015

(U)ASAPI [(unified) actuator sensor API]?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no typedef for that? phydat_unit_t e.g.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an ex-chemist I see a worrying lack of UNIT_MOL ;-P

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or as a more practical approach UNIT_PERCENT, UNIT_PERMIL, and UNIT_PPM)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in the comment, extend the list when you need anything...

@haukepetersen
Copy link
Copy Markdown
Contributor Author

Thought about the name, how about arcade? just not sure about the meaning, maybe something like Awesome RIOT Control/Acquisition Device Extension? Ideas?

@kaspar030
Copy link
Copy Markdown
Contributor

Nice work!

I think we should try to get away with a static (compile-time)registry., though. Similar to how we did it for shell commands.

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Aug 3, 2015

I think we should try to get away with a static (compile-time)registry., though. Similar to how we did it for shell commands.

👍 - and once again I'm not in favor of introducing more function pointers. I find them super annoying for debugging.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

Actually I am against the static approach, as this does not allow for hot-plugging - and that is a feature that I see as quite interesting and more-then-nice-to-have for the future!

@haukepetersen haukepetersen changed the title Introducing RASI, the [R]IOT [A]ctuator [S]ensor [I]nterface Introducing SAUL, the [S]ensor [A]ctuator [U]ber [L]ayer Aug 12, 2015
@haukepetersen
Copy link
Copy Markdown
Contributor Author

Renamed the interface, now i's all good man :-)

Also I separated the actual interface (drivers/saul) from the device registry (sys/saul_reg). For the registry, I switched from a pre-allocated array to a linked list. Although the lookups are slightly less efficient, the memory handling is way easier. Also the lookup mostly only has to be done once and afterwards a module can interact with a device directly (exception are shell commands, but for these performance is not the top-most concern...).

@kaspar030, care to take a look?

@haukepetersen
Copy link
Copy Markdown
Contributor Author

rebased

@OlegHahm OlegHahm modified the milestones: Release 2015.09, Release NEXT MAJOR Sep 2, 2015
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference to saul_reg_t::name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no same name (both point to the same text most likely), saul_reg_t is located in RAM for holding a saul reg entry, saul_reg_info_t is used for defining additional information about a device, e.g. used by auto-init

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point we probably may decide to either get rid of this type and use a string directly or to let saul_reg_t point to this, dependent if there will be more information (fields) that is added to sauL_reg_info_t

@OlegHahm
Copy link
Copy Markdown
Member

Reviewed the latest commits fixing my minor remarks. Please squash.

@haukepetersen
Copy link
Copy Markdown
Contributor Author

squashed

@haukepetersen
Copy link
Copy Markdown
Contributor Author

Travis is happy - @kaspar030: do you ack?

@kaspar030
Copy link
Copy Markdown
Contributor

Yep. go!

kaspar030 added a commit that referenced this pull request Dec 1, 2015
Introducing SAUL, the [S]ensor [A]ctuator [U]ber [L]ayer
@kaspar030 kaspar030 merged commit e53dc6f into RIOT-OS:master Dec 1, 2015
@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Dec 1, 2015

Congrats!

@sgso
Copy link
Copy Markdown
Contributor

sgso commented Dec 1, 2015

Is this suitable to replace the awful LED-Macros some tests depend on? Instead of relying on LED_RED and other stuff to be defined (even if there aren't any red ones ;) use the 1st, 2nd, etc. actuator of type led?

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Dec 1, 2015

For LEDs I think there's no way around macros, because there are often inevitable for debugging where any overhead is not tolerable. I wouldn't object renaming to something like LED_DEBUG1 or the like, though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/express/expressed/

Sorry for being that late, I waited with reading the docs until now that SAUL is merged.

@haukepetersen haukepetersen deleted the add_sensif_actif branch December 1, 2015 13:29
@haukepetersen
Copy link
Copy Markdown
Contributor Author

good catches -> fixed in #4369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: major The PR changes a significant part of the code base. It should be reviewed carefully Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants