123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #include <string.h>
- #include <device.h>
- #include <sys/atomic.h>
- #include <syscall_handler.h>
- extern const struct init_entry __init_start[];
- extern const struct init_entry __init_PRE_KERNEL_1_start[];
- extern const struct init_entry __init_PRE_KERNEL_2_start[];
- extern const struct init_entry __init_POST_KERNEL_start[];
- extern const struct init_entry __init_APPLICATION_start[];
- extern const struct init_entry __init_POWER_MAX_start[];
- extern const struct init_entry __init_end[];
- #ifdef CONFIG_SMP
- extern const struct init_entry __init_SMP_start[];
- #endif
- extern const struct device __device_start[];
- extern const struct device __device_end[];
- extern uint32_t __device_init_status_start[];
- void z_device_state_init(void)
- {
- const struct device *dev = __device_start;
- while (dev < __device_end) {
- z_object_init(dev);
- ++dev;
- }
- }
- void z_sys_init_run_level(int32_t level)
- {
- static const struct init_entry *levels[] = {
- __init_PRE_KERNEL_1_start,
- __init_PRE_KERNEL_2_start,
- __init_POST_KERNEL_start,
- __init_APPLICATION_start,
- #ifdef CONFIG_SMP
- __init_SMP_start,
- #endif
- __init_POWER_MAX_start,
-
- __init_end,
- };
- const struct init_entry *entry;
- for (entry = levels[level]; entry < levels[level+1]; entry++) {
- const struct device *dev = entry->dev;
- #ifdef CONFIG_DEVICE_DEBUG
- if(dev){
- printk("z_sys_init dev(%s) func:%p\n", dev->name, entry->init);
- }else{
- printk("z_sys_init entry(%p) func:%p\n", entry, entry->init);
- }
- #endif
- int rc = entry->init(dev);
- if (dev != NULL) {
-
- if (rc != 0) {
- if (rc < 0) {
- rc = -rc;
- }
- if (rc > UINT8_MAX) {
- rc = UINT8_MAX;
- }
- dev->state->init_res = rc;
- }
- dev->state->initialized = true;
- }
- }
- }
- const struct device *z_impl_device_get_binding(const char *name)
- {
- const struct device *dev;
-
- if ((name == NULL) || (name[0] == '\0')) {
- return NULL;
- }
-
- for (dev = __device_start; dev != __device_end; dev++) {
- if (z_device_ready(dev) && (dev->name == name)) {
- return dev;
- }
- }
- for (dev = __device_start; dev != __device_end; dev++) {
- if (z_device_ready(dev) && (strcmp(name, dev->name) == 0)) {
- return dev;
- }
- }
- #ifdef CONFIG_DEVICE_DEBUG
- printk("!!!ERR: dev %s not found\n", name);
- #endif
- return NULL;
- }
- #ifdef CONFIG_USERSPACE
- static inline const struct device *z_vrfy_device_get_binding(const char *name)
- {
- char name_copy[Z_DEVICE_MAX_NAME_LEN];
- if (z_user_string_copy(name_copy, (char *)name, sizeof(name_copy))
- != 0) {
- return NULL;
- }
- return z_impl_device_get_binding(name_copy);
- }
- #include <syscalls/device_get_binding_mrsh.c>
- static inline int z_vrfy_device_usable_check(const struct device *dev)
- {
- Z_OOPS(Z_SYSCALL_OBJ_INIT(dev, K_OBJ_ANY));
- return z_impl_device_usable_check(dev);
- }
- #include <syscalls/device_usable_check_mrsh.c>
- #endif
- size_t z_device_get_all_static(struct device const **devices)
- {
- *devices = __device_start;
- return __device_end - __device_start;
- }
- bool z_device_ready(const struct device *dev)
- {
-
- if (dev == NULL) {
- return false;
- }
- return dev->state->initialized && (dev->state->init_res == 0U);
- }
- int device_required_foreach(const struct device *dev,
- device_visitor_callback_t visitor_cb,
- void *context)
- {
- size_t handle_count = 0;
- const device_handle_t *handles =
- device_required_handles_get(dev, &handle_count);
-
- for (size_t i = 0; i < handle_count; ++i) {
- device_handle_t dh = handles[i];
- const struct device *rdev = device_from_handle(dh);
- int rc = visitor_cb(rdev, context);
- if (rc < 0) {
- return rc;
- }
- }
- return handle_count;
- }
|