On Mon, 2015-02-02 at 11:45 -0600, Joel Sherrill wrote: > Hi > > Last week while teaching an RTEMS class, we looked at a SPARC BSP's > get nanoseconds since last tick handler. They all follow this pattern: > > clicks = Read Counter > if ( clock interrupt pending ) { > clicks = Read Counter; > time =(2 * time per tick) - (clicks); > } else { > time = time per tick - clicks > } > > return time; > > The code is correct but I would like to add a comment to all three > versions > of this code so it is clear what was intended. > > I think it is something like. Read the counter. If there is not an > interrupt pending, > then we are in the same clock tick. If there is one pending, then see > how long > past that tick we are. The handler has to report from slightly > 0 to > slightly > less than 2 ticks depending on where we are relative to the next clock > tick. > > Just wanting to make the code more understandable for the next person. > Help > writing the comment is appreciated.
For what it's worth, Sebastian and I were looking at similar code in the PowerPC tree recently and added some comments that are in this sort-of area: https://devel.rtems.org/changeset/d11b711b3ed6b4a053a298cf4e9f1209748fae5e/rtems > -- > Joel Sherrill, Ph.D. Director of Research & Development > joel.sherr...@oarcorp.com On-Line Applications Research > Ask me about RTEMS: a free RTOS Huntsville AL 35805 > Support Available (256) 722-9985 -- Nick Withers Embedded Systems Programmer Department of Nuclear Physics Research School of Physics and Engineering The Australian National University _______________________________________________ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel