From 1c38667a9635a9c6518647d1d688ba0e591631fe Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Sat, 18 May 2013 10:14:20 +0200 Subject: [PATCH] base: Mmio::wait_for(...) for whole registers Ref #706 --- base/include/util/mmio.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/base/include/util/mmio.h b/base/include/util/mmio.h index 39a4e01be6..e1fd8a15ba 100644 --- a/base/include/util/mmio.h +++ b/base/include/util/mmio.h @@ -476,6 +476,30 @@ namespace Genode virtual void usleep(unsigned us) = 0; }; + /** + * Wait until register 'T' contains the specified 'value' + * + * \param value value to wait for + * \param delayer sleeping facility to be used when the + * value is not reached yet + * \param max_attempts number of register probing attempts + * \param us number of microseconds between attempts + */ + template + inline bool + wait_for(typename T::Register_base::access_t const value, + Delayer & delayer, + unsigned max_attempts = 500, + unsigned us = 1000) + { + typedef typename T::Register_base Register; + for (unsigned i = 0; i < max_attempts; i++, delayer.usleep(us)) + { + if (read() == value) return true; + } + return false; + } + /** * Wait until bitfield 'T' contains the specified 'value' *