From: Wolfgang Denk Date: Tue, 24 May 2011 21:19:48 +0200 Subject: [U-Boot] [RFC] Review of U-Boot timer API In-Reply-To: <4DDBE22D.6050806@gmail.com> References: <4DD7B245.5000008@gmail.com> <201105240024.26511.vapier@gentoo.org> <4DDB42B1.2010206@emk-elektronik.de> <4DDBB29D.2050102@psyent.com> <20110524141950.2AB1CCF5DBF@gemini.denx.de> <4DDBE22D.6050806@gmail.com> Message-ID: <20110524191948.401CBCF5DBF@gemini.denx.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, In message <4DDBE22D.6050806@gmail.com> you wrote: > > >> Why must get_timer() be used to perform "meaningful time measurement?" > > > > Excellent question! It was never intended to be used as such. > > Because get_timer() as it currently stands can as it is assumed to return > milliseconds Yes, but without any guarantee for accuracy or resolution. This is good enough for timeouts, but nothing for time measurements. > OK, let's wind back - My original suggestion made no claim towards changing > what the API is used for, or how it looks to those who use it (for all > practical intents and purposes). I suggested: > - Removing set_timer() and reset_timer() > - Implement get_timer() as a platform independent function Trying to remember what I have read in this thread I believe we have an agreement on these. > Exposing ticks and tick_frequency to everyone via a 'tick' HAL I skip this. I don't even read it. > ======================= > Not exposing ticks and tick_frequency to everyone > > In /lib/timer.c > > void prescaler(u32 ticks, u32 tick_frequency) > { > u32 current_ms; > > /* Bill's algorithm */ > > /* result stored in gd->timer_in_ms; */ > } > > In /arch/cpu/soc/timer.c or /arch/cpu/timer.c or /board//timer.c > > static u32 get_ticks(void) Currently we have unsigned long long get_ticks(void) which is better as it matches existing hardware. Note that we also have void wait_ticks(u32) as needed for udelay(). > static u32 get_tick_frequency(void) > { > u32 tick_frequency; > > /* Determine tick frequency */ > > return tick_frequency; > } Note that we also have u32 usec2ticks(u32 usec) and u32 ticks2usec(u32 ticks). Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Madness has no purpose. Or reason. But it may have a goal. -- Spock, "The Alternative Factor", stardate 3088.7