From patchwork Sat Jan 30 17:55:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Vasut X-Patchwork-Id: 1433734 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=jbxO6sMU; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DShh634TGz9sWc for ; Sun, 31 Jan 2021 04:55:34 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B16C6824BB; Sat, 30 Jan 2021 18:55:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jbxO6sMU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7A7C0825D9; Sat, 30 Jan 2021 18:55:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 16FBD82483 for ; Sat, 30 Jan 2021 18:55:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=marek.vasut@gmail.com Received: by mail-ej1-x62e.google.com with SMTP id w1so17805076ejf.11 for ; Sat, 30 Jan 2021 09:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PYJkGaWB0SuYBTEhJW0EbY02OKwJykCgPHNRO89T2Y8=; b=jbxO6sMUR/qf/37kpSIxbwqaks37j0bWuIcolqsJtXoq7Aw6AeKZFMUZ1NCXwhFiHf vwjdfTZvm+I6Pluf/4woOoJzjbVf9me64nlvXOQWdju/JCWeiQgQyEY3UWWZlQNF07Ki Rft6fbJ3A40Yj/wjiMLV0ZnjjRgK6wNMUSVCgIuxbXr/owDYzQLJWq7okKCwyjohZJ1a 1UIlm0irfdOF571xmH0JLQgm94XL2qVrCsL54NA7OYlas8s4uD1jwEhHpWbFMbltqvXW l4bgPo+PYKvwh+G0z1UjEO4HCVwzqQsYtNu2a4ricrL7gfl19xZ4/VCeJl+fuc7Z1Ddf biqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PYJkGaWB0SuYBTEhJW0EbY02OKwJykCgPHNRO89T2Y8=; b=VqVX2Z0CkobwKvIQQohdvgOPin98CjapGz63X5yP4xAtRrdJ3ZNzTIcwQLThGN4L/1 xqfHvdrX3wdyr8ylm3jDRRhQoPAB2SKW1+kPX7BJCbwEM4n8rk1QJyPmTp8oVenm+JML xc6Z//gXG+gjN4qajLqFW+r9xwcVCGZe3ztTBCv2030INYdqn72GgFLAn6SKzdnIj54I PuIZpZe5N3DXmz3itZDGiM9bsSzGlnIs2m+VSWtK3Mp1tToje7z0H+BGabbfFF9tOQj9 F3w5sFI+GKjB02r5t5iXt93UXTnGjK0uuxn17qMlZI3x3fXc4v5bkPcBG928f+WAFSKW 9OYw== X-Gm-Message-State: AOAM531Xe8BxVIf4bpsHxyoyBuTJb2zsp0sqDzB132GkTpzFhti25J2j Wtwa77GLBDR5ZF7kaHJRzBtyUhoWIW0= X-Google-Smtp-Source: ABdhPJwfD/eZv2eExCqS+jF65vF9N5uVx0H6lLNMPfgmvv8DZ5bsA2QKuPdaOBCvJ6AJjwRpAPsSeA== X-Received: by 2002:a17:906:509:: with SMTP id j9mr9947701eja.89.1612029327763; Sat, 30 Jan 2021 09:55:27 -0800 (PST) Received: from tr.lan (ip-89-176-112-137.net.upcbroadband.cz. [89.176.112.137]) by smtp.gmail.com with ESMTPSA id gt18sm5473762ejb.104.2021.01.30.09.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jan 2021 09:55:26 -0800 (PST) From: Marek Vasut X-Google-Original-From: Marek Vasut To: u-boot@lists.denx.de Cc: Marek Vasut Subject: [PATCH 1/2] callback: Implement support for registering main loop callbacks Date: Sat, 30 Jan 2021 18:55:21 +0100 Message-Id: <20210130175522.114439-1-marek.vasut+renesas@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean 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 --- common/cli_readline.c | 6 ++++++ common/main.c | 21 +++++++++++++++++++++ include/init.h | 10 ++++++++++ 3 files changed, 37 insertions(+) diff --git a/common/cli_readline.c b/common/cli_readline.c index 5c158d03b4..5ace4724d2 100644 --- a/common/cli_readline.c +++ b/common/cli_readline.c @@ -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 */ diff --git a/common/main.c b/common/main.c index ae5bcdb32f..b408e82696 100644 --- a/common/main.c +++ b/common/main.c @@ -18,6 +18,27 @@ #include #include +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; diff --git a/include/init.h b/include/init.h index 980be27993..dcc4177316 100644 --- a/include/init.h +++ b/include/init.h @@ -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 */