Skip to content

Conversation

@tbursztyka
Copy link

This are necessary changes to handle non-initialized devices. I.e. devices which 'zephyr,deferred-init' DTS attribute was set.

Later on, such utility will prove to be useful on improving devices shell module.

Comment on lines 132 to 133
if (!device_is_ready(dev)) {
shell_info(sh, "Device %s is already initialized", argv[1]);

Choose a reason for hiding this comment

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

I think the logic is flipped here. You want if (device_is_ready(dev)) without negating it

Copy link
Author

Choose a reason for hiding this comment

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

good catch, I did not test this module (as I used the beo-shell-device one intstead in the end)

const char *prefix,
shell_device_filter_t filter)
shell_device_filter_t filter,
bool ready)

Choose a reason for hiding this comment

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

Suggested change
bool ready)
bool show_all)

If you flip the logically intention here, I think the conditional later on simplifies.
Alternatively keep the current logic, but then I suggest renaming to something like only_ready to show the intended use a bit more from the get-go.

Copy link
Author

@tbursztyka tbursztyka Jun 11, 2025

Choose a reason for hiding this comment

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

I first agreed on this, and then I remembered that I wanted a way to auto-complete on non-ready devices... which means I miss a function to do so like shell_device_lookup_non_ready() of some sort.

So looks like I forgot that feature at some point (which also means the logic I made is wrong anyway...)

Copy link
Author

Choose a reason for hiding this comment

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

Actually what I did is pretty stupid...


while (dev < dev_end) {
if (device_is_ready(dev)
if (((ready && device_is_ready(dev)) || !ready)

Choose a reason for hiding this comment

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

If you did flip the logic of ready to be a show_all flag:

Suggested change
if (((ready && device_is_ready(dev)) || !ready)
if ((show_all || device_is_ready(dev))

const struct device *dev_end = dev + len;

while (dev < dev_end) {
if ((dev->name != NULL) &&

Choose a reason for hiding this comment

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

Suggested change
if ((dev->name != NULL) &&
if (dev->name &&

Isn't this the common approach in zephyr as well when checking non-null?

Copy link
Author

Choose a reason for hiding this comment

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

I c/p shell_device_internal().
In linux it is the way yes (like testing any integer if it has a value or 0) but in zephyr... I thought there might be some MISRA rule for this, but looking at https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html I am not so sure anymore (could not find anything related to this)

size_t len = z_device_get_all_static(&dev);
const struct device *dev_end = dev + len;

while (dev < dev_end) {

Choose a reason for hiding this comment

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

Alternatively you can substitute a for-loop to get the ++dev right here :)

@tbursztyka tbursztyka force-pushed the tobu/improve_shell_utils_on_devices branch 2 times, most recently from ef5b993 to accdb4d Compare June 11, 2025 11:07
This are necessary changes to handle non-initialized devices. I.e.
devices which 'zephyr,deferred-init' DTS attribute was set.

Later on, such utility will prove to be useful on improving devices
shell module.

Signed-off-by: Tomasz Bursztyka <[email protected]>
@tbursztyka tbursztyka force-pushed the tobu/improve_shell_utils_on_devices branch from accdb4d to 572f3de Compare June 11, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants