summaryrefslogtreecommitdiff
path: root/docs/library/time.rst
diff options
context:
space:
mode:
authordanicampora <daniel@wipy.io>2015-10-14 12:32:01 +0200
committerdanicampora <daniel@wipy.io>2015-10-17 23:29:04 +0200
commit4542643025c77a7272bde348b89d5039aea28d23 (patch)
treebf9fb006f46b96d2ea9ecf4aa190c4e4cc2abfc8 /docs/library/time.rst
parentfca3308cc376f2c1c66fa3cef82e30c55c9acca2 (diff)
docs: Update all WiPy docs to reflect the new API.
Diffstat (limited to 'docs/library/time.rst')
-rw-r--r--docs/library/time.rst40
1 files changed, 40 insertions, 0 deletions
diff --git a/docs/library/time.rst b/docs/library/time.rst
index 8af8e37ba..0dc18afb4 100644
--- a/docs/library/time.rst
+++ b/docs/library/time.rst
@@ -44,6 +44,46 @@ Functions
Sleep for the given number of seconds.
+.. only:: port_wipy
+
+ .. function:: sleep_ms(ms)
+
+ Delay for given number of milliseconds, should be positive or 0.
+
+ .. function:: sleep_us(us)
+
+ Delay for given number of microseconds, should be positive or 0
+
+ .. function:: ticks_ms()
+
+ Returns an increasing millisecond counter with arbitrary reference point,
+ that wraps after some (unspecified) value. The value should be treated as
+ opaque, suitable for use only with ticks_diff().
+
+ .. function:: ticks_us()
+
+ Just like ``ticks_ms`` above, but in microseconds.
+
+ .. function:: ticks_cpu()
+
+ Similar to ``ticks_ms`` and ``ticks_us``, but with higher resolution (usually CPU clocks).
+
+ .. function:: ticks_diff(old, new)
+
+ Measure period between consecutive calls to ticks_ms(), ticks_us(), or ticks_cpu().
+ The value returned by these functions may wrap around at any time, so directly
+ subtracting them is not supported. ticks_diff() should be used instead. "old" value should
+ actually precede "new" value in time, or result is undefined. This function should not be
+ used to measure arbitrarily long periods of time (because ticks_*() functions wrap around
+ and usually would have short period). The expected usage pattern is implementing event
+ polling with timeout::
+
+ # Wait for GPIO pin to be asserted, but at most 500us
+ start = time.ticks_us()
+ while pin.value() == 0:
+ if time.ticks_diff(start, time.ticks_us()) > 500:
+ raise TimeoutError
+
.. function:: time()
Returns the number of seconds, as an integer, since 1/1/2000.