2019-02-05 00:04:05 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Alexander Wachter
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-06-26 22:33:49 +08:00
|
|
|
#include <sys/printk.h>
|
2019-02-05 00:04:05 +08:00
|
|
|
#include <shell/shell.h>
|
2019-06-26 03:53:53 +08:00
|
|
|
#include <drivers/hwinfo.h>
|
2019-02-05 00:04:05 +08:00
|
|
|
#include <zephyr/types.h>
|
|
|
|
#include <logging/log.h>
|
|
|
|
|
|
|
|
static int cmd_get_device_id(const struct shell *shell, size_t argc, char **argv)
|
|
|
|
{
|
2020-05-28 00:26:57 +08:00
|
|
|
uint8_t dev_id[16];
|
2019-02-05 00:04:05 +08:00
|
|
|
ssize_t length;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
length = hwinfo_get_device_id(dev_id, sizeof(dev_id));
|
|
|
|
|
|
|
|
if (length == -ENOTSUP) {
|
|
|
|
shell_error(shell, "Not supported by hardware");
|
|
|
|
return -ENOTSUP;
|
|
|
|
} else if (length < 0) {
|
|
|
|
shell_error(shell, "Error: %d", length);
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
shell_fprintf(shell, SHELL_NORMAL, "Length: %d\n", length);
|
|
|
|
shell_fprintf(shell, SHELL_NORMAL, "ID: 0x");
|
|
|
|
|
|
|
|
for (i = 0 ; i < length ; i++) {
|
2019-03-08 20:43:05 +08:00
|
|
|
shell_fprintf(shell, SHELL_NORMAL, "%02x", dev_id[i]);
|
2019-02-05 00:04:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
shell_fprintf(shell, SHELL_NORMAL, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-13 21:53:29 +08:00
|
|
|
SHELL_STATIC_SUBCMD_SET_CREATE(sub_hwinfo,
|
2019-02-05 00:04:05 +08:00
|
|
|
SHELL_CMD_ARG(devid, NULL, "Show device id", cmd_get_device_id, 1, 0),
|
|
|
|
SHELL_SUBCMD_SET_END /* Array terminated. */
|
2019-02-13 21:53:29 +08:00
|
|
|
);
|
2019-02-05 00:04:05 +08:00
|
|
|
|
|
|
|
SHELL_CMD_ARG_REGISTER(hwinfo, &sub_hwinfo, "HWINFO commands", NULL, 2, 0);
|