From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Tue, 28 Jun 2011 21:40:59 -0700 Subject: [U-Boot] [PATCH v1 (WIP) 09/16] [Timer]Replace get_timer() usage in drivers/block/ In-Reply-To: <1309261269-4363-10-git-send-email-graeme.russ@gmail.com> References: <1309261269-4363-1-git-send-email-graeme.russ@gmail.com> <1309261269-4363-10-git-send-email-graeme.russ@gmail.com> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Graeme, On Tue, Jun 28, 2011 at 4:41 AM, Graeme Russ wrote: > > Signed-off-by: Graeme Russ > --- > ?drivers/block/mg_disk.c | ? ?9 ++++----- > ?1 files changed, 4 insertions(+), 5 deletions(-) > > diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c > index 2198017..c8cc195 100644 > --- a/drivers/block/mg_disk.c > +++ b/drivers/block/mg_disk.c > @@ -88,17 +88,16 @@ static void mg_dump_status (const char *msg, unsigned int stat, unsigned err) > ?static unsigned int mg_wait (u32 expect, u32 msec) > ?{ > ? ? ? ?u8 status; > - ? ? ? u32 from, cur, err; > + ? ? ? u32 ts, err; > > ? ? ? ?err = MG_ERR_NONE; > ?#ifdef CONFIG_NIOS2 > ? ? ? ?reset_timer(); > ?#endif > - ? ? ? from = get_timer(0); > + ? ? ? ts = time_now_ms(); > > ? ? ? ?status = readb(mg_base() + MG_REG_STATUS); > ? ? ? ?do { > - ? ? ? ? ? ? ? cur = get_timer(from); ... > - ? ? ? } while (cur < msec); > + ? ? ? } while (time_since_ms(ts) < msec); > Well I know i have asked this before, but I feel I should ask again because I didn't like the answer much. Imagine we change this code to: ts = time_now_ms() + msec do { ... } while (time_since_ms(ts) < 0); That should be legal, right? But I don't think this can work since the 'since' functions return an unsigned. [aside: this provides for another idiom that I think we talked about: ts = time_future_ms(msec) do { ... } while (!time_passed(ts)) which I am not@all suggesting should be in the API :-) end aside] Regards. Simon > - ? ? ? if (cur >= msec) > + ? ? ? if (time_since_ms(ts) >= msec) > ? ? ? ? ? ? ? ?err = MG_ERR_TIMEOUT; > > ? ? ? ?return err; > -- > 1.7.5.2.317.g391b14 > > _______________________________________________ > U-Boot mailing list > U-Boot at lists.denx.de > http://lists.denx.de/mailman/listinfo/u-boot >