2020-08-20 22:07:29 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
* Copyright (c) 2020 Nordic Semiconductor ASA
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_LEVEL CONFIG_EMUL_LOG_LEVEL
|
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(emul);
|
|
|
|
|
|
|
|
#include <device.h>
|
2021-03-24 22:12:30 +08:00
|
|
|
#include <drivers/emul.h>
|
2020-08-20 22:07:29 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2021-09-08 04:00:17 +08:00
|
|
|
const struct emul *emul_get_binding(const char *name)
|
2020-08-20 22:07:29 +08:00
|
|
|
{
|
2021-09-08 04:00:17 +08:00
|
|
|
const struct emul *emul_it;
|
2020-08-20 22:07:29 +08:00
|
|
|
|
2021-09-08 04:00:17 +08:00
|
|
|
for (emul_it = __emul_list_start; emul_it < __emul_list_end; emul_it++) {
|
|
|
|
if (strcmp(emul_it->dev_label, name) == 0) {
|
|
|
|
return emul_it;
|
2020-08-20 22:07:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
int emul_init_for_bus_from_list(const struct device *dev,
|
2020-08-20 22:07:29 +08:00
|
|
|
const struct emul_list_for_bus *list)
|
|
|
|
{
|
|
|
|
const struct emul_list_for_bus *cfg = dev->config;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Walk the list of children, find the corresponding emulator and
|
|
|
|
* initialise it.
|
|
|
|
*/
|
|
|
|
const struct emul_link_for_bus *elp;
|
|
|
|
const struct emul_link_for_bus *const end =
|
|
|
|
cfg->children + cfg->num_children;
|
|
|
|
|
2020-09-26 05:50:39 +08:00
|
|
|
LOG_INF("Registering %d emulator(s) for %s", cfg->num_children,
|
|
|
|
dev->name);
|
2020-08-20 22:07:29 +08:00
|
|
|
for (elp = cfg->children; elp < end; elp++) {
|
2021-09-08 04:00:17 +08:00
|
|
|
const struct emul *emul = emul_get_binding(elp->label);
|
2020-08-20 22:07:29 +08:00
|
|
|
|
2020-09-26 05:50:39 +08:00
|
|
|
__ASSERT(emul, "Cannot find emulator for '%s'", elp->label);
|
2020-08-20 22:07:29 +08:00
|
|
|
|
|
|
|
int rc = emul->init(emul, dev);
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
LOG_WRN("Init %s emulator failed: %d\n",
|
|
|
|
elp->label, rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|