summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig16
-rw-r--r--cmd/Makefile1
-rw-r--r--cmd/cyclic.c84
3 files changed, 101 insertions, 0 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 67c7d2512f..7d574d4ab7 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2511,6 +2511,22 @@ config CMD_CBSYSINFO
memory by coreboot before jumping to U-Boot. It can be useful for
debugging the beaaviour of coreboot or U-Boot.
+config CMD_CYCLIC
+ bool "cyclic - Show information about cyclic functions"
+ depends on CYCLIC
+ default y
+ help
+ This enables the 'cyclic' command which provides information about
+ cyclic execution functions. This infrastructure allows registering
+ functions to be executed cyclically, e.g. every 100ms. These commands
+ are supported:
+
+ cyclic list - list cyclic functions
+ cyclic cyclic demo <cycletime_ms> <delay_us> - register cyclic
+ demo function
+
+ See doc/develop/cyclic.rst for more details.
+
config CMD_DIAG
bool "diag - Board diagnostics"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index 7abe1d3630..b2df59baef 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -56,6 +56,7 @@ obj-$(CONFIG_CMD_DIAG) += diag.o
endif
obj-$(CONFIG_CMD_ADTIMG) += adtimg.o
obj-$(CONFIG_CMD_ABOOTIMG) += abootimg.o
+obj-$(CONFIG_CMD_CYCLIC) += cyclic.o
obj-$(CONFIG_CMD_EVENT) += event.o
obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
obj-$(CONFIG_CMD_ECHO) += echo.o
diff --git a/cmd/cyclic.c b/cmd/cyclic.c
new file mode 100644
index 0000000000..c1bc556aad
--- /dev/null
+++ b/cmd/cyclic.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * A general-purpose cyclic execution infrastructure, to allow "small"
+ * (run-time wise) functions to be executed at a specified frequency.
+ * Things like LED blinking or watchdog triggering are examples for such
+ * tasks.
+ *
+ * Copyright (C) 2022 Stefan Roese <sr@denx.de>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <cyclic.h>
+#include <div64.h>
+#include <malloc.h>
+#include <linux/delay.h>
+
+struct cyclic_demo_info {
+ uint delay_us;
+};
+
+static void cyclic_demo(void *ctx)
+{
+ struct cyclic_demo_info *info = ctx;
+
+ /* Just a small dummy delay here */
+ udelay(info->delay_us);
+}
+
+static int do_cyclic_demo(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct cyclic_demo_info *info;
+ struct cyclic_info *cyclic;
+ uint time_ms;
+
+ if (argc < 3)
+ return CMD_RET_USAGE;
+
+ info = malloc(sizeof(struct cyclic_demo_info));
+ if (!info) {
+ printf("out of memory\n");
+ return CMD_RET_FAILURE;
+ }
+
+ time_ms = simple_strtoul(argv[1], NULL, 0);
+ info->delay_us = simple_strtoul(argv[2], NULL, 0);
+
+ /* Register demo cyclic function */
+ cyclic = cyclic_register(cyclic_demo, time_ms * 1000, "cyclic_demo",
+ info);
+ if (!cyclic)
+ printf("Registering of cyclic_demo failed\n");
+
+ printf("Registered function \"%s\" to be executed all %dms\n",
+ "cyclic_demo", time_ms);
+
+ return 0;
+}
+
+static int do_cyclic_list(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ struct cyclic_info *cyclic, *tmp;
+ u64 cnt, freq;
+
+ list_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
+ cnt = cyclic->run_cnt * 1000000ULL * 100ULL;
+ freq = lldiv(cnt, timer_get_us() - cyclic->start_time_us);
+ printf("function: %s, cpu-time: %lld us, frequency: %lld.%02d times/s\n",
+ cyclic->name, cyclic->cpu_time_us,
+ lldiv(freq, 100), do_div(freq, 100));
+ }
+
+ return 0;
+}
+
+static char cyclic_help_text[] =
+ "cyclic demo <cycletime_ms> <delay_us> - register cyclic demo function\n"
+ "cyclic list - list cyclic functions\n";
+
+U_BOOT_CMD_WITH_SUBCMDS(cyclic, "Cyclic", cyclic_help_text,
+ U_BOOT_SUBCMD_MKENT(demo, 3, 1, do_cyclic_demo),
+ U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cyclic_list));