Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZIO channel and attribute rework WIP #16456

Closed

Conversation

pollend
Copy link

@pollend pollend commented May 28, 2019

I've been looking at the zio api and I have a rework of the api that defines all the attributes and channels through anonymous nested structs. you use ZIO_ATTR(id) and ZIO_CHANNEL(id) to retrieve the accessor type. attributes can either be nested within the definition of a channel or at the root of the api struct for device attribute configurations. At the moment this does not quite work and I was looking for some suggestions. I realize this is a pretty large departure from the original api.

I think this could address some of my problems with the current zio sensor api. The definitions and for attributes and channels are more defined. this removes the need for the setter functions in the base api. I was also looking into storing the attributes and channels into nested arrays but I think this is more defined. I'm not sure about using the preprocessor in this way, but I think these could be tweaked and reworked.

The majority of the interesting changes are in synth.c and synth.h file.

teburd and others added 6 commits May 23, 2019 07:59
Add a new sensor device API called zio_dev along with supporting
interface and implmentations needed to better encapsulate a large range
of functionality typical sampled input/output (sensor and signal
generator) type devices commonly provide.

Every device has a set of channels and attributes associated with it.
Channels may be attached to a fifo like interface (zio_buf) which
provides a pollable mechanism for obtaining the raw channel data at
a designated watermark level.

Signed-off-by: Tom Burdick <thomas.burdick@gmail.com>
Provide a software only example driver and sample application which
generates a left and right sine wave at CD quality bit width
and rate.

Signed-off-by: Tom Burdick <thomas.burdick@gmail.com>
Rather than providing the attribute values directly in get_attrs
for zio devices and channels, provide descriptions of each attribute.

This should allow a driver to map many attributes directly to registers
or internalized struct members and avoid storing these values in a
zio_variant which is confusing.

Signed-off-by: Tom Burdick <thomas.burdick@gmail.com>
@pollend pollend changed the base branch from master to topic-sensors May 28, 2019 16:39
@zephyrbot
Copy link
Collaborator

zephyrbot commented May 28, 2019

Found the following issues, please fix and resubmit:

Identity/Emails issues

5c34ec6785b8512c2148a81a204be7b63b43ce52: author email (Michael polli104@mail.chapman.edu) needs to match one of the signed-off-by entries.
5c34ec6785b8512c2148a81a204be7b63b43ce52: author email (Michael polli104@mail.chapman.edu) does not follow the syntax: First Last .

4178b64146430615e5bf854566429bc974bb81f9: author email (Michael polli104@mail.chapman.edu) needs to match one of the signed-off-by entries.
4178b64146430615e5bf854566429bc974bb81f9: author email (Michael polli104@mail.chapman.edu) does not follow the syntax: First Last .

375621015c1313bf8ad03942ab9091d718498b92: author email (Michael polli104@mail.chapman.edu) needs to match one of the signed-off-by entries.
375621015c1313bf8ad03942ab9091d718498b92: author email (Michael polli104@mail.chapman.edu) does not follow the syntax: First Last .

checkpatch issues

-:242: WARNING:LONG_LINE: line over 80 characters
#242: FILE: drivers/zio/synth/synth.c:49:
+	.fifo = ZIO_FIFO_BUF_INITIALIZER(synth_data.fifo, struct synth_datum, CONFIG_SYNTH_FIFO_SIZE),

-:256: WARNING:LONG_LINE: line over 80 characters
#256: FILE: drivers/zio/synth/synth.c:63:
+			float sample = sin(2.0 * M_PI * (freq / sample_rate) * drv_data->t + phase);

-:298: WARNING:LONG_LINE: line over 80 characters
#298: FILE: drivers/zio/synth/synth.c:105:
+static int synth_dev_sample_set_attr(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, const struct zio_variant val)

-:309: WARNING:LONG_LINE: line over 80 characters
#309: FILE: drivers/zio/synth/synth.c:116:
+static int synth_dev_sample_get_attr(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, struct zio_variant *attr)

-:318: WARNING:LONG_LINE: line over 80 characters
#318: FILE: drivers/zio/synth/synth.c:125:
+static int synth_channel_phase_set_attr(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, const struct zio_variant val)

-:329: WARNING:LONG_LINE: line over 80 characters
#329: FILE: drivers/zio/synth/synth.c:136:
+static int synth_channel_phase_get_attr(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, struct zio_variant *attr)

-:344: WARNING:LONG_LINE: line over 80 characters
#344: FILE: drivers/zio/synth/synth.c:151:
+static int synth_channel_phase_set_attr(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, const struct zio_variant val)

-:365: WARNING:LONG_LINE: line over 80 characters
#365: FILE: drivers/zio/synth/synth.c:172:
+static int synth_channel_frequency_get_attr(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, struct zio_variant *attr)

-:380: WARNING:LONG_LINE: line over 80 characters
#380: FILE: drivers/zio/synth/synth.c:187:
+static int synth_channel_frequency_set_attr(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, const struct zio_variant val)

-:401: WARNING:LINE_CONTINUATIONS: Avoid unnecessary line continuations
#401: FILE: drivers/zio/synth/synth.c:208:
+	ZIO_DEFINE_CHANNEL(SYNTH_LEFT_CHANNEL,			       \

-:405: WARNING:LINE_CONTINUATIONS: Avoid unnecessary line continuations
#405: FILE: drivers/zio/synth/synth.c:212:
+	ZIO_DEFINE_CHANNEL(SYNTH_RIGHT_CHANNEL,			       \

-:961: ERROR:C99_COMMENTS: do not use C99 // comments
#961: FILE: include/zio/zio_dev.h:85:
+// zio attribute types

-:964: WARNING:TRAILING_SEMICOLON: macros should not use a trailing semicolon
#964: FILE: include/zio/zio_dev.h:88:
+#define ZIO_API() api;

-:966: ERROR:C99_COMMENTS: do not use C99 // comments
#966: FILE: include/zio/zio_dev.h:90:
+// zio definitions

-:967: WARNING:TRAILING_SEMICOLON: macros should not use a trailing semicolon
#967: FILE: include/zio/zio_dev.h:91:
+#define ZIO_DEFINE_ATTRIBUTE(id) \
+	struct zio_attr_desc ZIO_ATTR(id);

-:970: WARNING:TRAILING_SEMICOLON: macros should not use a trailing semicolon
#970: FILE: include/zio/zio_dev.h:94:
+#define ZIO_DEFINE_CHANNEL(id, attributes)    \
+	struct {			      \
+		struct zio_chan_desc channel; \
+		attributes		      \
+	}				      \
+	ZIO_CHANNEL(id);

-:977: WARNING:TRAILING_SEMICOLON: macros should not use a trailing semicolon
#977: FILE: include/zio/zio_dev.h:101:
+#define ZIO_DEFINE_API() struct zio_dev_api api;

-:986: WARNING:LONG_LINE: line over 80 characters
#986: FILE: include/zio/zio_dev.h:110:
+#define ZIO_GET_CHANNEL(dev, channel_idx)							    \

-:987: WARNING:LONG_LINE: line over 80 characters
#987: FILE: include/zio/zio_dev.h:111:
+	({											    \

-:988: WARNING:LONG_LINE: line over 80 characters
#988: FILE: include/zio/zio_dev.h:112:
+		struct zio_chan_desc *channel = &dev->driver_data.ZIO_CHANNEL(channel_idx).channel; \

-:989: WARNING:LONG_LINE: line over 80 characters
#989: FILE: include/zio/zio_dev.h:113:
+		channel;									    \

-:999: WARNING:LONG_LINE: line over 80 characters
#999: FILE: include/zio/zio_dev.h:123:
+#define ZIO_GET_CHANNEL_ATTRIBUTE(dev, channel_idx, attribute_idx)						 \

-:1000: WARNING:LONG_LINE: line over 80 characters
#1000: FILE: include/zio/zio_dev.h:124:
+	({													 \

-:1001: WARNING:LONG_LINE: line over 80 characters
#1001: FILE: include/zio/zio_dev.h:125:
+		struct zio_attr_desc *attr = &dev->driver_data.ZIO_CHANNEL(channel_idx).ZIO_ATTR(attribute_idx); \

-:1002: WARNING:LONG_LINE: line over 80 characters
#1002: FILE: include/zio/zio_dev.h:126:
+		attr;												 \

-:1011: WARNING:LONG_LINE: line over 80 characters
#1011: FILE: include/zio/zio_dev.h:135:
+#define ZIO_GET_DEV_ATTRIBUTE(dev, attribute_idx)					\

-:1012: WARNING:LONG_LINE: line over 80 characters
#1012: FILE: include/zio/zio_dev.h:136:
+	({										\

-:1013: WARNING:LONG_LINE: line over 80 characters
#1013: FILE: include/zio/zio_dev.h:137:
+		struct zio_attr_desc *attr = &dev->driver_data.ZIO_ATTR(attribute_idx);	\

-:1014: WARNING:LONG_LINE: line over 80 characters
#1014: FILE: include/zio/zio_dev.h:138:
+		attr;									\

-:1074: WARNING:LONG_LINE: line over 80 characters
#1074: FILE: include/zio/zio_dev.h:198:
+typedef int (*zio_set_attr_t)(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, const struct zio_variant var);

-:1081: WARNING:LONG_LINE: line over 80 characters
#1081: FILE: include/zio/zio_dev.h:205:
+typedef int (*zio_get_attr_t)(struct device *dev, const u16_t channel_idx, const u16_t attribute_idx, struct zio_variant *attr);

-:1193: WARNING:LONG_LINE: line over 80 characters
#1193: FILE: include/zio/zio_dev.h:317:
+typedef int (*zio_dev_set_attr_t)(struct device *dev, const u16_t attr_idx, const struct zio_variant var);

-:1201: WARNING:LONG_LINE: line over 80 characters
#1201: FILE: include/zio/zio_dev.h:325:
+typedef int (*zio_dev_get_attr_t)(struct device *dev, const u16_t attr_idx, struct zio_variant *attr);

-:1257: WARNING:LONG_LINE: line over 80 characters
#1257: FILE: include/zio/zio_dev.h:381:
+#define zio_dev_get_attr(dev, attr_idx, val)					\

-:1258: WARNING:LONG_LINE: line over 80 characters
#1258: FILE: include/zio/zio_dev.h:382:
+	({									\

-:1259: WARNING:LONG_LINE: line over 80 characters
#1259: FILE: include/zio/zio_dev.h:383:
+		int res = 0;							\

-:1260: WARNING:LONG_LINE: line over 80 characters
#1260: FILE: include/zio/zio_dev.h:384:
+		zio_attr_desc *attr = ZIO_GET_DEV_ATTRIBUTE(dev, attr_idx);	\

-:1261: WARNING:LONG_LINE: line over 80 characters
#1261: FILE: include/zio/zio_dev.h:385:
+		if (!attr->set_attr) {						\

-:1262: WARNING:LONG_LINE: line over 80 characters
#1262: FILE: include/zio/zio_dev.h:386:
+			res = -ENOTSUP;						\

-:1263: WARNING:LONG_LINE: line over 80 characters
#1263: FILE: include/zio/zio_dev.h:387:
+		} else {							\

-:1264: WARNING:LONG_LINE: line over 80 characters
#1264: FILE: include/zio/zio_dev.h:388:
+			struct zio_variant data;				\

-:1265: WARNING:LONG_LINE: line over 80 characters
#1265: FILE: include/zio/zio_dev.h:389:
+			res = attr->get_attr(dev, ZIO_DEVICE, attr_idx, &data);	\

-:1266: WARNING:LONG_LINE: line over 80 characters
#1266: FILE: include/zio/zio_dev.h:390:
+			if (res == 0) {						\

-:1267: WARNING:LONG_LINE: line over 80 characters
#1267: FILE: include/zio/zio_dev.h:391:
+				res = zio_variant_unwrap(data, val);		\

-:1268: WARNING:LONG_LINE: line over 80 characters
#1268: FILE: include/zio/zio_dev.h:392:
+			}							\

-:1269: WARNING:LONG_LINE: line over 80 characters
#1269: FILE: include/zio/zio_dev.h:393:
+			res;							\

-:1270: WARNING:LONG_LINE: line over 80 characters
#1270: FILE: include/zio/zio_dev.h:394:
+		}								\

-:1408: WARNING:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses
#1408: FILE: include/zio/zio_fifo.h:72:
+#define ZIO_FIFO_DEFINE(name, type, pow)    \
+	ZIO_FIFO_DECLARE(name, type, pow) = \
+		ZIO_FIFO_INITIALIZER(name, type, pow)

-:1662: WARNING:COMPLEX_MACRO: Macros with complex values should be enclosed in parentheses
#1662: FILE: include/zio/zio_fifo_buf.h:76:
+#define ZIO_FIFO_BUF_DEFINE(name, type, pow) \
+	ZIO_FIFO_BUF_DECLARE(name, type, pow) =	\
+		ZIO_FIFO_BUF_INITIALIZER(name, type, pow)

- total: 2 errors, 47 warnings, 2348 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Your patch has style problems, please review.

NOTE: Ignored message types: AVOID_EXTERNS BRACES CONFIG_EXPERIMENTAL CONST_STRUCT DATE_TIME FILE_PATH_CHANGES MINMAX NETWORKING_BLOCK_COMMENT_STYLE PRINTK_WITHOUT_KERN_LEVEL SPLIT_STRING VOLATILE

NOTE: If any of the errors are false positives, please report
      them to the maintainers.



Gitlint issues

Commit 5c34ec6785:
1: UC2 Body does not contain a 'Signed-off-by:' line
1: UC3 Title does not follow [subsystem]: [subject] (and should not start with literal subsys:): "cleaned up code"
1: UC6 Body has no content, should at least have 1 line.
3: B6 Body message is missing

Commit 4178b64146:
1: UC2 Body does not contain a 'Signed-off-by:' line
1: UC3 Title does not follow [subsystem]: [subject] (and should not start with literal subsys:): "updated synth"
1: UC6 Body has no content, should at least have 1 line.
3: B6 Body message is missing

Commit 375621015c:
1: UC2 Body does not contain a 'Signed-off-by:' line
1: UC3 Title does not follow [subsystem]: [subject] (and should not start with literal subsys:): "reworking attribute api"
1: UC6 Body has no content, should at least have 1 line.
3: B6 Body message is missing

Documentation issues

/var/lib/shippable/build/IN/main_repo/zephyr/doc/_build/rst/doc/samples/zio/synth/README.rst:4: WARNING: duplicate label lsm6dsl, other instance in /var/lib/shippable/build/IN/main_repo/zephyr/doc/_build/rst/doc/samples/sensor/lsm6dsl/README.rst


Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

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

I don't see any docs (.rst file) for review, I suspect because zio isn't a public interface. Is there a documentation impact for this change?

@pollend
Copy link
Author

pollend commented May 28, 2019

This is just an early wip. Its a significant change from where zio was going at the moment. I kind want to see what people think about this change first before putting in significant effort to develop something more complete.

@microbuilder microbuilder added area: API Changes to public APIs area: Sensors Sensors labels May 28, 2019
@dbkinder
Copy link
Contributor

OK. I also see a PR for Documentation for zio #16384

@microbuilder
Copy link
Member

@dbkinder Yeah, I made a boilerplate PR just to get started, but haven't invested time into documenting the details until the dust settles on this a bit.

@microbuilder microbuilder requested a review from teburd May 28, 2019 17:56
@microbuilder microbuilder added this to In progress in Sensors May 28, 2019
struct zio_attr_desc {
/* Attribute data type describing the expected data type. */
enum zio_variant_type data_type;
zio_set_attr_t set_attr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

These two function pointers are I think the most significant part of this change set and I definitely agree that they make the device driver API clearer, avoids unnecessary switch/case function wrappers, and generally makes for a nicer API

*
* @return -EINVAL if an invalid attribute id was given, 0 otherwise
*/
typedef int (*zio_dev_set_attr_t)(struct device *dev, const u16_t attr_idx, const struct zio_variant var);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like it'd be unnecessary given each attribute description has a get/set function pointer

*/
typedef int (*zio_chan_set_attr_t)(struct device *dev, const u32_t chan_idx,
const u32_t attr_idx,
const struct zio_variant var);
/**
* @brief Function to get a channel attribute for a device
*
* @return -EINVAL if an invalid attribute id was given, 0 otherwise
*/
typedef int (*zio_chan_get_attr_t)(struct device *dev, const u32_t chan_idx,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this, or any of the other get/set attr function pointer defs are needed anymore with your change, where each attribute has its own getter/setter

Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

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

I think the general idea of putting the setter/getter function pointers into the attribute description makes a lot of sense. What to pass into those function pointers is another issue, the callback might just need a parameter to give it the context it needs. I don't think CONTAINER_OF would solve the problem, you would need something like it that could understand pointer math for array members where the ptr is pointing to one thing in that array. Maybe that already exists somewhere.

Another thing I would keep in mind is that the current API has some faults I think, we don't support the idea of related sets of channels where for example the x,y,z accelerometer channels of a 9 axis sensor like the one I believe your writing a driver for share a lot of attributes such as value ranges (+/- 2g, 8g, 16g, etc).

This changeset seems like its on the right track to creating the building block to help solve that problem as well.

@pfalcon
Copy link
Contributor

pfalcon commented May 28, 2019

@BFrog: Some feedback re: 4fe8819 :

Add a new sensor device API called zio_dev

I find "zio" naming to be confusing. Which letter exactly in "zio" stands for "sensor"? And why someone would need to decipher letters, why not call it with "sensor" in name for clarity? We already have one cryptic, confusing, conflicting name like that: #16114 .

@teburd
Copy link
Collaborator

teburd commented Jun 25, 2019

@BFrog: Some feedback re: 4fe8819 :

Add a new sensor device API called zio_dev

I find "zio" naming to be confusing. Which letter exactly in "zio" stands for "sensor"? And why someone would need to decipher letters, why not call it with "sensor" in name for clarity? We already have one cryptic, confusing, conflicting name like that: #16114 .

I don't disagree, I needed a name, and I wanted something short, zephyr io abbreviated to zio seemed easy enough.

The general problem with naming it sensors is that this API is meant to encompass more of what IIO does in Linux, provide an input/output stream with attributes and triggers. I'm open to suggestions.

@mbolivar
Copy link
Contributor

mbolivar commented Jun 25, 2019

The general problem with naming it sensors is that this API is meant to encompass more of what IIO does in Linux, provide an input/output stream with attributes and triggers. I'm open to suggestions.

I'm still +1 on rtio for real time input/output.

I believe that this I/O framework is meant to cover actuators as well, so I disagree that "sensor" should be in the name, as that would be misleading. If I'm wrong about that, then never mind.

Edit: or maybe "zesa" (zephyr sensors/actuators)?

@WilliamGFish
Copy link
Collaborator

Hi All,
I have come across this whilst working on a implementation of the BT Mesh Sensor Model which has a requirement for exposing sensor descriptions and attributes which appears to have a significant overlap.

I'm not sure if anyone has reviewed the BT documentation to consider potential relevance? I think it would valuable to have a look.

Billy..

@mbolivar
Copy link
Contributor

The initial ZIO work has since been replaced by RTIO; see the branch by the same name on @BFrog's zephyr fork.

@WilliamGFish
Copy link
Collaborator

The initial ZIO work has since been replaced by RTIO; see the branch by the same name on @BFrog's zephyr fork.

Thanks, I'll have a look.

@teburd
Copy link
Collaborator

teburd commented Feb 3, 2020

I think since zio has become a dead end, it might be worth considering closing this.

@pollend pollend closed this Feb 4, 2020
@teburd teburd moved this from In progress to Done in Sensors Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: API Changes to public APIs area: Sensors Sensors
Projects
No open projects
Sensors
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants