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

device: add api to check if device initialized or not #25053

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,18 @@ void z_sys_device_do_config_level(s32_t level);
*/
__syscall struct device *device_get_binding(const char *name);

/**
* @brief device initialization success or not
*
* @param device Pointer to device structure.
*
* @return true if device successfully initialized; false if not.
*/
static inline bool device_is_initialized(struct device *device)
{
return device->driver_api != NULL;
}

/**
* @}
*/
Expand Down
23 changes: 18 additions & 5 deletions subsys/power/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,25 @@ void sys_pm_create_device_list(void)
*/
device_list_get(&pm_device_list, &count);

/* Reserve for 32KHz, 16MHz, system clock, etc... */
device_count = NUM_CORE_DEVICES;
for (i = 0; (i < count) && (device_count < MAX_PM_DEVICES); i++) {
if (device_is_initialized(&pm_device_list[i]) == false) {
continue;
}

/* Check if the device is core device */
for (j = 0, is_core_dev = false; j < NUM_CORE_DEVICES; j++) {
if (!strcmp(pm_device_list[i].config->name,
&core_devices[j][0])) {
device_ordered_list[device_count++] = i;
break;
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this loop repeated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is this loop repeated?

@pabigot we should put the core devices at the first, but we don't know how many core devices are initialized like before. The first loop is to find the core devices and then other devices.


for (i = 0; (i < count) && (device_count < MAX_PM_DEVICES); i++) {
if (device_is_initialized(&pm_device_list[i]) == false) {
continue;
}

/* Check if the device is core device */
for (j = 0, is_core_dev = false; j < NUM_CORE_DEVICES; j++) {
Expand All @@ -125,9 +140,7 @@ void sys_pm_create_device_list(void)
}
}

if (is_core_dev) {
device_ordered_list[j] = i;
} else {
if (!is_core_dev) {
device_ordered_list[device_count++] = i;
}
}
Expand Down