@@ -266,6 +266,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
uint64_t etime = endtick(timeout);
while (!tstc()) { /* while no incoming data */
+ callback_run();
if (get_ticks() >= etime)
return -2; /* timed out */
WATCHDOG_RESET();
@@ -273,6 +274,11 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
first = 0;
}
+ do {
+ callback_run();
+ WATCHDOG_RESET();
+ } while (!tstc());
+
ichar = getcmd_getch();
/* ichar=0x0 when error occurs in U-Boot getc */
@@ -18,6 +18,27 @@
#include <version.h>
#include <efi_loader.h>
+static LIST_HEAD(callbacks);
+
+void callback_register(struct callback *cb)
+{
+ INIT_LIST_HEAD(&cb->list);
+ list_add_tail(&cb->list, &callbacks);
+}
+
+void callback_unregister(struct callback *cb)
+{
+ list_del(&cb->list);
+}
+
+void callback_run(void)
+{
+ struct callback *cb, *pos;
+
+ list_for_each_entry_safe(cb, pos, &callbacks, list)
+ cb->callback_func(cb);
+}
+
static void run_preboot_environment_command(void)
{
char *p;
@@ -334,6 +334,16 @@ void bdinfo_print_mhz(const char *name, unsigned long hz);
/* Show arch-specific information for the 'bd' command */
void arch_print_bdinfo(void);
+struct callback {
+ struct list_head list;
+ void (*callback_func)(struct callback *);
+ void *callback_arg;
+};
+
+void callback_register(struct callback *cb);
+void callback_unregister(struct callback *cb);
+void callback_run(void);
+
#endif /* __ASSEMBLY__ */
/* Put only stuff here that the assembler can digest */
Add initial code for registering callbacks into the main loop. These callbacks should be quick asynchronous functions executed in the background, useful e.g. for polling SD card detect line or for running USB state machine. Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com> --- common/cli_readline.c | 6 ++++++ common/main.c | 21 +++++++++++++++++++++ include/init.h | 10 ++++++++++ 3 files changed, 37 insertions(+)