From: Reinhard Meyer Date: Tue, 31 May 2011 06:07:41 +0200 Subject: [U-Boot] [RFC][Timer API] Revised Specification - Implementation details In-Reply-To: References: <4DDE5548.3020906@gmail.com> <4DDE8639.3090909@comcast.net> <20110527071355.5DA8014EF7F@gemini.denx.de> <4DDF543D.6020506@gmail.com> <20110527074832.5B98E1354FC@gemini.denx.de> <20110527112721.9023C101D7A@gemini.denx.de> <4DDFA206.5050101@psyent.com> <20110529155530.09A5F14EF7F@gemini.denx.de> <20110530105704.0C83F14EBCB@gemini.denx.de> <4DE3E890.5030402@emk-elektronik.de> Message-ID: <4DE4698D.2090206@emk-elektronik.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Graeme Russ, > Hi Reinhard, > > On Tue, May 31, 2011 at 4:57 AM, Reinhard Meyer > wrote: >> Dear ALL, >> >> it still escapes me why everyone tries to make things so complicated INSIDE the loop. >> >> Why not just define an API like this: >> >> u32 timeout = make_timeout(5); /* minimum 5 millisecond timeout */ >> u32 start = get_timer(); >> >> while ((get_timer() - start)< timeout) >> ... > > The would work if we typedef'd 'timeout'. Otherwise, one runs the risk of > not calling make_timeout() and assuming get_timer() always has a 1ms > resolution If you think people cannot follow API conventions, then typedef it... > >> make_timeout() can be arch/soc/platform specific and take into account to return at least >> such a value that the timeout is never cut short. (In case of a 10 ms NIOS timer, >> make_timeout(5) would have to return the value 20, resulting in a real timeout of at least >> 10 ms but upto 20 ms ) > > What about this: > > u32 start = get_timer(); > > while (!timer_expired(start, timeout)) > ... Again.. why put the complicated calculations INSIDE the loop? > >> If anyone sees the need, make_timeout (or what ever it might be called) could have >> a second parameter, indicating whether round up or round down is desired. >> >> ... >> >> I also agree to remove the parameter of get_timer(), but we should also get rid of >> CONFIG_SYS_HZ. > > Wholeheartedly agree Regards, Reinhard