device: add API to check whether a device is ready to use

Currently this is useful only for some internal applications that
iterate over the device table, since applications can't get access to
a device that isn't ready, and devices can't be made unready.  So it's
introduced as internal API that may be exposed as device_ready() when
those conditions change.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2020-06-22 10:01:39 -05:00 committed by Carles Cufí
commit d8b86cba3c
4 changed files with 16 additions and 7 deletions

View file

@ -39,7 +39,7 @@ static bool device_get_config_level(const struct shell *shell, int level)
bool devices = false;
for (dev = levels[level]; dev < levels[level+1]; dev++) {
if (dev->driver_api != NULL) {
if (z_device_ready(dev)) {
devices = true;
shell_fprintf(shell, SHELL_NORMAL, "- %s\n", dev->name);
@ -92,7 +92,7 @@ static int cmd_device_list(const struct shell *shell,
shell_fprintf(shell, SHELL_NORMAL, "devices:\n");
for (dev = __device_start; dev != __device_end; dev++) {
if (dev->driver_api == NULL) {
if (!z_device_ready(dev)) {
continue;
}

View file

@ -470,7 +470,7 @@ struct device *shell_device_lookup(size_t idx,
struct device *dev_end = dev + len;
while (dev < dev_end) {
if ((dev->driver_api != NULL)
if (z_device_ready(dev)
&& (dev->name != NULL)
&& (strlen(dev->name) != 0)
&& ((prefix == NULL)