]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
fix rounding in the scale function (see MeasureClockC tinyos-help discussion on feb...
authormmaroti <mmaroti>
Sat, 27 Mar 2010 21:27:33 +0000 (21:27 +0000)
committermmaroti <mmaroti>
Sat, 27 Mar 2010 21:27:33 +0000 (21:27 +0000)
Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/

tos/platforms/mica/MeasureClockC.nc
tos/system/scale.h

index fa82bbba34d5bd85fd24b4acce0ff7fcd0344d12..5518964d46ff169a7abd9aafdb0f397c740db5e9 100644 (file)
@@ -93,11 +93,11 @@ implementation
   }
 
   async command uint32_t Atm128Calibrate.calibrateMicro(uint32_t n) {
-    return scale32(n + MAGIC / 2, cycles, MAGIC);
+    return scale32(n, cycles, MAGIC);
   }
 
   async command uint32_t Atm128Calibrate.actualMicro(uint32_t n) {
-    return scale32(n + (cycles >> 1), MAGIC, cycles);
+    return scale32(n, MAGIC, cycles);
   }
 
   async command uint8_t Atm128Calibrate.adcPrescaler() {
index d249cf82b8a09bd8d1ddadb27779929bd3a994f9..8e251116009fb384ba694e6015c2265fbfb83d53 100644 (file)
@@ -8,7 +8,7 @@
  * @param x Number to scale
  * @param a Numerator of scaling value
  * @param b Denominator of scaling value
- * @return x * a/b
+ * @return round(x * a/b)
  */
 inline uint32_t scale32(uint32_t x, uint32_t a, uint32_t b) 
 {
@@ -16,7 +16,7 @@ inline uint32_t scale32(uint32_t x, uint32_t a, uint32_t b)
   uint32_t x_mod_b = x % b;
 
   x_mod_b *= a; // on a separate line just in case some compiler goes weird
-  return x_over_b * a + x_mod_b / b;
+  return x_over_b * a + (x_mod_b + (b>>1)) / b;
 }
 
 #endif