mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: Re: [PATCH 1/7] Add generic poll infrastructure
Date: Sat, 18 Dec 2010 16:28:18 +0100	[thread overview]
Message-ID: <20101218152818.GI6017@pengutronix.de> (raw)
In-Reply-To: <1292685309-32326-2-git-send-email-s.hauer@pengutronix.de>

Hi Marc (Kleine-Budde),

I took the version of this patch I had lying around, please let
me know if you have an updated version.

Sascha

On Sat, Dec 18, 2010 at 04:15:03PM +0100, Sascha Hauer wrote:
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> 
> Barebox does not have interrupt functionality. Nevertheless it's
> sometimes useful to periodically call functions, like for example
> a heartbeat LED or watchdog reset. Instead of cluttering the code
> with calls to these functions this patch adds a generic polling
> infrastructure. Code which might run for longer now can call
> poller_call() periodically which in turn will call all registered
> pollers.
> This patch adds a call to poller_call in two generic pathes. First
> of them is getc() which covers waiting for uart input. Second is
> ctrlc() which should be called anyway from code which might run
> for longer. So instead adding poller_call directly to your code,
> consider checking ctrlc instead which also gives additional
> convenience to the user.
> The poller code is safe against reentrancy which means that it's
> safe to call poller_call inside a poller.
> 
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  common/Kconfig   |    3 +++
>  common/Makefile  |    1 +
>  common/console.c |    5 +++++
>  common/poller.c  |   45 +++++++++++++++++++++++++++++++++++++++++++++
>  include/poller.h |   31 +++++++++++++++++++++++++++++++
>  5 files changed, 85 insertions(+), 0 deletions(-)
>  create mode 100644 common/poller.c
>  create mode 100644 include/poller.h
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index 617f640..02bc67e 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -414,6 +414,9 @@ config DEFAULT_ENVIRONMENT_PATH
>  	  Relative pathes will be relative to the barebox Toplevel dir, but absolute
>  	  pathes are fine aswell.
>  
> +config POLLER
> +	bool "generic polling infrastructure"
> +
>  endmenu
>  
>  menu "Debugging                     "
> diff --git a/common/Makefile b/common/Makefile
> index 753455b..98c9d36 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -5,6 +5,7 @@ obj-$(CONFIG_OF_FLAT_TREE)	+= ft_build.o
>  obj-$(CONFIG_KALLSYMS)		+= kallsyms.o
>  obj-$(CONFIG_ENV_HANDLING)	+= environment.o
>  obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
> +obj-$(CONFIG_POLLER)		+= poller.o
>  
>  obj-y += dlmalloc.o
>  obj-y += clock.o
> diff --git a/common/console.c b/common/console.c
> index 82786f2..39ead4b 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -34,6 +34,7 @@
>  #include <clock.h>
>  #include <kfifo.h>
>  #include <module.h>
> +#include <poller.h>
>  #include <linux/list.h>
>  
>  LIST_HEAD(console_list);
> @@ -205,6 +206,8 @@ int getc(void)
>  	 */
>  	start = get_time_ns();
>  	while (1) {
> +		poller_call();
> +
>  		if (tstc()) {
>  			kfifo_putc(console_input_buffer, getc_raw());
>  
> @@ -397,6 +400,8 @@ EXPORT_SYMBOL(vprintf);
>  /* test if ctrl-c was pressed */
>  int ctrlc (void)
>  {
> +	poller_call();
> +
>  	if (tstc() && getc() == 3)
>  		return 1;
>  	return 0;
> diff --git a/common/poller.c b/common/poller.c
> new file mode 100644
> index 0000000..0583a53
> --- /dev/null
> +++ b/common/poller.c
> @@ -0,0 +1,45 @@
> +/*
> + * Copyright (C) 2010 Marc Kleine-Budde <mkl@pengutronix.de>
> + *
> + * This file is released under the GPLv2
> + *
> + */
> +
> +#include <common.h>
> +#include <driver.h>
> +#include <malloc.h>
> +#include <module.h>
> +#include <param.h>
> +#include <poller.h>
> +
> +static LIST_HEAD(poller_list);
> +static int poller_active;
> +
> +int poller_register(struct poller_struct *poller)
> +{
> +	list_add_tail(&poller->list, &poller_list);
> +
> +	return 0;
> +}
> +
> +int poller_unregister(struct poller_struct *poller)
> +{
> +	list_del(&poller->list);
> +
> +	return 0;
> +}
> +
> +void poller_call(void)
> +{
> +	struct poller_struct *poller, *tmp;
> +
> +	if (poller_active)
> +		return;
> +
> +	poller_active = 1;
> +
> +	list_for_each_entry_safe(poller, tmp, &poller_list, list)
> +		poller->func(poller);
> +
> +	poller_active = 0;
> +}
> diff --git a/include/poller.h b/include/poller.h
> new file mode 100644
> index 0000000..dc98155
> --- /dev/null
> +++ b/include/poller.h
> @@ -0,0 +1,31 @@
> +/*
> + * Copyright (C) 2010 Marc Kleine-Budde <mkl@pengutronix.de>
> + *
> + * This file is released under the GPLv2
> + *
> + */
> +
> +#ifndef POLLER_H
> +#define POLLER_H
> +
> +#include <linux/list.h>
> +
> +struct poller_struct {
> +	void (*func)(struct poller_struct *poller);
> +
> +	struct list_head list;
> +};
> +
> +int poller_register(struct poller_struct *poller);
> +int poller_unregister(struct poller_struct *poller);
> +
> +
> +#ifdef CONFIG_POLLER
> +void poller_call(void);
> +#else
> +static inline void poller_call(void)
> +{
> +}
> +#endif	/* CONFIG_POLLER */
> +
> +#endif	/* !POLLER_H */
> -- 
> 1.7.2.3
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  reply	other threads:[~2010-12-18 15:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-18 15:15 LED framework Sascha Hauer
2010-12-18 15:15 ` [PATCH 1/7] Add generic poll infrastructure Sascha Hauer
2010-12-18 15:28   ` Sascha Hauer [this message]
2010-12-18 15:15 ` [PATCH 2/7] basic LED support Sascha Hauer
2010-12-18 16:38   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 17:18     ` Sascha Hauer
2010-12-18 16:48   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 19:06   ` Belisko Marek
2010-12-19 21:31   ` Marc Reilly
2010-12-20  8:27     ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 3/7] LED: Add gpio " Sascha Hauer
2010-12-18 16:41   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 17:18     ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 4/7] LED: Add LED trigger support Sascha Hauer
2010-12-18 16:51   ` Belisko Marek
2010-12-18 17:21     ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 5/7] LED: Add led command Sascha Hauer
2010-12-18 16:45   ` Jean-Christophe PLAGNIOL-VILLARD
2010-12-18 17:24     ` Sascha Hauer
2010-12-18 15:15 ` [PATCH 6/7] LED: Add trigger command Sascha Hauer
2010-12-18 15:15 ` [PATCH 7/7] pcm038: led testing. Not to be committed Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101218152818.GI6017@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox