With the new idle slice there is no longer a need to have a dedicated hook
for RATP inside readline. Switch to a poller that depends on the idle
slice to execute the commands received over RATP.

Signed-off-by: Daniel Glöckner <d...@emlix.com>
---
 common/ratp/ratp.c | 12 +++++++++++-
 include/ratp_bb.h  |  1 -
 lib/Kconfig        |  1 +
 lib/readline.c     |  9 +--------
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/common/ratp/ratp.c b/common/ratp/ratp.c
index 9625a31b1..9b3ea0f98 100644
--- a/common/ratp/ratp.c
+++ b/common/ratp/ratp.c
@@ -53,6 +53,7 @@ struct ratp_ctx {
        struct ratp_bb_pkt *fs_rx;
 
        struct poller_struct poller;
+       struct poller_struct execution_poller;
 };
 
 static int compare_ratp_command(struct list_head *a, struct list_head *b)
@@ -302,7 +303,7 @@ static int ratp_console_register(struct ratp_ctx *ctx)
        return 0;
 }
 
-void barebox_ratp_command_run(void)
+static void barebox_ratp_command_run(struct poller_struct *poller)
 {
        int ret;
 
@@ -336,6 +337,7 @@ static void ratp_console_unregister(struct ratp_ctx *ctx)
        int ret;
 
        console_set_active(&ctx->ratp_console, 0);
+       poller_unregister(&ctx->execution_poller);
        poller_unregister(&ctx->poller);
        ratp_close(&ctx->ratp);
        console_set_active(ctx->cdev, ctx->old_active);
@@ -436,6 +438,7 @@ int barebox_ratp(struct console_device *cdev)
                ctx->console_recv_fifo = kfifo_alloc(512);
                ctx->console_transmit_fifo = kfifo_alloc(SZ_128K);
                ctx->poller.func = ratp_poller;
+               ctx->execution_poller.func = barebox_ratp_command_run;
                ratp_console_register(ctx);
        }
 
@@ -458,11 +461,18 @@ int barebox_ratp(struct console_device *cdev)
        if (ret)
                goto out1;
 
+       ret = poller_register(&ctx->execution_poller, "ratp-exec");
+       if (ret)
+               goto out2;
+
+       slice_add(&ctx->execution_poller.slice, &idle_slice);
        console_set_active(&ctx->ratp_console, CONSOLE_STDOUT | CONSOLE_STDERR |
                        CONSOLE_STDIN);
 
        return 0;
 
+out2:
+       poller_unregister(&ctx->poller);
 out1:
        ratp_close(ratp);
 out:
diff --git a/include/ratp_bb.h b/include/ratp_bb.h
index a4f28c642..b710f99bf 100644
--- a/include/ratp_bb.h
+++ b/include/ratp_bb.h
@@ -41,7 +41,6 @@ struct ratp_bb_pkt {
 };
 
 int  barebox_ratp(struct console_device *cdev);
-void barebox_ratp_command_run(void);
 int  barebox_ratp_fs_call(struct ratp_bb_pkt *tx, struct ratp_bb_pkt **rx);
 int  barebox_ratp_fs_mount(const char *path);
 
diff --git a/lib/Kconfig b/lib/Kconfig
index 9a8078018..d60c6ce2d 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -108,6 +108,7 @@ config RATP
        select COMPILE_MEMORY
        select COMMAND_SUPPORT
        select POLLER
+       select IDLE_SLICE
        depends on CONSOLE_FULL
        depends on !SHELL_NONE
        bool "RATP protocol support"
diff --git a/lib/readline.c b/lib/readline.c
index 709efb375..79bac6f42 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -4,7 +4,6 @@
 #include <libbb.h>
 #include <poller.h>
 #include <slice.h>
-#include <ratp_bb.h>
 #include <xfuncs.h>
 #include <complete.h>
 #include <linux/ctype.h>
@@ -202,14 +201,8 @@ int readline(const char *prompt, char *buf, int len)
 
        while (1) {
                idle_slice_release();
-               while (!tstc()) {
+               while (!tstc())
                        poller_call();
-                       if (IS_ENABLED(CONFIG_CONSOLE_RATP)) {
-                               idle_slice_acquire();
-                               barebox_ratp_command_run();
-                               idle_slice_release();
-                       }
-               }
                idle_slice_acquire();
 
                ichar = read_key();
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to