| |
| |
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| |
| |
| |
| <title>OS Time — Apache Mynewt latest documentation</title> |
| |
| |
| |
| |
| <link rel="shortcut icon" href="../../../_static/mynewt-logo-only-newt32x32.png"/> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" /> |
| |
| |
| <link rel="stylesheet" href="../../../_static/css/sphinx_theme.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/bootstrap-3.0.3.min.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/v2.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../../_static/css/restructuredtext.css" type="text/css" /> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../../_static/css/overrides.css" type="text/css" /> |
| <link rel="index" title="Index" |
| href="../../../genindex.html"/> |
| <link rel="search" title="Search" href="../../../search.html"/> |
| <link rel="top" title="Apache Mynewt latest documentation" href="../../../index.html"/> |
| <link rel="up" title="Apache Mynewt Operating System Kernel" href="../mynewt_os.html"/> |
| <link rel="next" title="Sanity" href="../sanity/sanity.html"/> |
| <link rel="prev" title="CPU Time" href="../cputime/os_cputime.html"/> |
| |
| |
| <script src="../../../_static/js/modernizr.min.js"></script> |
| |
| |
| <script> |
| (function(i, s, o, g, r, a, m) { |
| i["GoogleAnalyticsObject"] = r; |
| (i[r] = |
| i[r] || |
| function() { |
| (i[r].q = i[r].q || []).push(arguments); |
| }), |
| (i[r].l = 1 * new Date()); |
| (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); |
| a.async = 1; |
| a.src = g; |
| m.parentNode.insertBefore(a, m); |
| })(window, document, "script", "//www.google-analytics.com/analytics.js", "ga"); |
| |
| ga("create", "UA-72162311-1", "auto"); |
| ga("send", "pageview"); |
| </script> |
| |
| |
| </head> |
| |
| <body class="not-front page-documentation" role="document" > |
| <div id="wrapper"> |
| <div class="container"> |
| <div id="banner" class="row v2-main-banner"> |
| <a class="logo-cell" href="/"> |
| <img class="logo" src="../../../_static/img/logo.png"> |
| </a> |
| <div class="tagline-cell"> |
| <h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4> |
| </div> |
| <div class="news-cell"> |
| <div class="well"> |
| <h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.12.0, Apache NimBLE 1.7.0 </a> released April 4, 2024) |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <header> |
| <nav id="navbar" class="navbar navbar-inverse" role="navigation"> |
| <div class="container"> |
| <!-- Collapsed navigation --> |
| <div class="navbar-header"> |
| <!-- Expander button --> |
| <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| |
| </div> |
| |
| <!-- Expanded navigation --> |
| <div class="navbar-collapse collapse"> |
| <!-- Main navigation --> |
| <ul class="nav navbar-nav navbar-right"> |
| <li> |
| <a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a> |
| </li> |
| <li class="important"> |
| <a href="/quick-start/">Quick Start</a> |
| </li> |
| <li> |
| <a href="/about/">About</a> |
| </li> |
| <li> |
| <a href="/talks/">Talks</a> |
| </li> |
| <li class="active"> |
| <a href="/documentation/">Documentation</a> |
| </li> |
| <li> |
| <a href="/download/">Download</a> |
| </li> |
| <li> |
| <a href="/community/">Community</a> |
| </li> |
| <li> |
| <a href="/events/">Events</a> |
| </li> |
| </ul> |
| |
| <!-- Search, Navigation and Repo links --> |
| <ul class="nav navbar-nav navbar-right"> |
| |
| </ul> |
| </div> |
| </div> |
| </nav> |
| </header> |
| <!-- STARTS MAIN CONTENT --> |
| <div id="main-content"> |
| |
| |
| |
| |
| |
| |
| <div id="breadcrumb"> |
| <div class="container"> |
| <a href="/documentation/">Docs</a> / |
| |
| <a href="../../os_user_guide.html">OS User Guide</a> / |
| |
| <a href="../mynewt_os.html">Apache Mynewt Operating System Kernel</a> / |
| |
| OS Time |
| |
| <div class="sourcelink"> |
| <a href="https://github.com/apache/mynewt-core/edit/master/docs/os/core_os/time/os_time.rst" class="icon icon-github" |
| rel="nofollow"> Edit on GitHub</a> |
| </div> |
| </div> |
| </div> |
| <!-- STARTS CONTAINER --> |
| <div class="container"> |
| <!-- STARTS .content --> |
| <div id="content" class="row"> |
| |
| <!-- STARTS .container-sidebar --> |
| <div class="container-sidebar col-xs-12 col-sm-3"> |
| <div id="docSidebar" class="sticky-container"> |
| <div role="search" class="sphinx-search"> |
| <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search documentation" class="search-documentation" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| <!-- Note: only works when deployed --> |
| <select class="form-control" onchange="if (this.value) window.location.href=this.value"> |
| <option value="/latest" selected> |
| Version: latest |
| </option> |
| <option value="/v1_12_0" > |
| Version: 1.12.0 |
| </option> |
| <option value="/v1_11_0" > |
| Version: 1.11.0 |
| </option> |
| <option value="/v1_10_0" > |
| Version: 1.10.0 |
| </option> |
| <option value="/v1_9_0" > |
| Version: 1.9.0 |
| </option> |
| <option value="/v1_8_0" > |
| Version: 1.8.0 |
| </option> |
| <option value="/v1_7_0" > |
| Version: 1.7.0 |
| </option> |
| <option value="/v1_6_0" > |
| Version: 1.6.0 |
| </option> |
| <option value="/v1_5_0" > |
| Version: 1.5.0 |
| </option> |
| <option value="/v1_4_0" selected="selected" > |
| Version: 1.4.0 |
| </option> |
| <option value="/v1_3_0/os/introduction" > |
| Version: 1.3.0 |
| </option> |
| <option value="/v1_2_0/os/introduction" > |
| Version: 1.2.0 |
| </option> |
| <option value="/v1_1_0/os/introduction" > |
| Version: 1.1.0 |
| </option> |
| <option value="/v1_0_0/os/introduction" > |
| Version: 1.0.0 |
| </option> |
| <option value="/v0_9_0/os/introduction" > |
| Version: 0.9.0 |
| </option> |
| </select> |
| <div class="region region-sidebar"> |
| <div class="docs-menu"> |
| |
| |
| |
| <ul class="current"> |
| <li class="toctree-l1"><a class="reference internal" href="../../../index.html">Introduction</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../get_started/index.html">Setup & Get Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../concepts.html">Concepts</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../tutorials/tutorials.html">Tutorials</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../external_links.html">Third-party Resources</a></li> |
| <li class="toctree-l1 current"><a class="reference internal" href="../../os_user_guide.html">OS User Guide</a><ul class="current"> |
| <li class="toctree-l2 current"><a class="reference internal" href="../mynewt_os.html">Kernel</a><ul class="current"> |
| <li class="toctree-l3"><a class="reference internal" href="../context_switch/context_switch.html">Scheduler</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../task/task.html">Task</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../mutex/mutex.html">Mutex</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../semaphore/semaphore.html">Semaphore</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../event_queue/event_queue.html">Event Queues</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../callout/callout.html">Callout</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../heap/heap.html">Heap</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../memory_pool/memory_pool.html">Memory Pools</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../mbuf/mbuf.html">Mbufs</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../cputime/os_cputime.html">CPU Time</a></li> |
| <li class="toctree-l3 current"><a class="current reference internal" href="#">OS Time</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../sanity/sanity.html">Sanity</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/system_modules.html">System</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/hal/hal.html">Hardware Abstraction</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/bootloader/bootloader.html">Secure Bootloader</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/split/split.html">Split Images</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../porting/port_os.html">Porting Guide</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/sysinitconfig/sysinitconfig.html">Compile-Time Configuration</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/console/console.html">Console</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/shell/shell.html">Shell</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/testutil/testutil.html">Test Utilities</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/json/json.html">JSON</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/stats/stats.html">Statistics</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../modules/logs/logs.html">Logs</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../network/index.html">BLE User Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../newt/index.html">Newt Tool Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../newtmgr/index.html">Newt Manager Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../mynewt_faq/index.html">Mynewt FAQ</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../misc/index.html">Appendix</a></li> |
| </ul> |
| |
| |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS STICKY CONTAINER --> |
| </div> |
| <!-- ENDS .container-sidebar --> |
| |
| <div class="col-xs-12 col-sm-9"> |
| |
| <div class="alert alert-warning"> |
| <p> |
| Version 1.4.0 is not the most recent version of the |
| Apache Mynewt documentation. Click <a href="/latest">here</a> to |
| read the latest version. |
| </p> |
| </div> |
| |
| |
| |
| <div class=""> |
| <div class="rst-content"> |
| <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| <div itemprop="articleBody"> |
| |
| <div class="section" id="os-time"> |
| <h1>OS Time<a class="headerlink" href="#os-time" title="Permalink to this headline">¶</a></h1> |
| <p>The system time for the Mynewt OS.</p> |
| <div class="contents local topic" id="contents"> |
| <ul class="simple"> |
| <li><p><a class="reference internal" href="#description" id="id1">Description</a></p></li> |
| <li><p><a class="reference internal" href="#data-structures" id="id2">Data Structures</a></p></li> |
| <li><p><a class="reference internal" href="#functions" id="id3">Functions</a></p></li> |
| <li><p><a class="reference internal" href="#macros" id="id4">Macros</a></p></li> |
| <li><p><a class="reference internal" href="#special-notes" id="id5">Special Notes</a></p></li> |
| <li><p><a class="reference internal" href="#api" id="id6">API</a></p></li> |
| </ul> |
| </div> |
| <div class="section" id="description"> |
| <h2><a class="toc-backref" href="#id1">Description</a><a class="headerlink" href="#description" title="Permalink to this headline">¶</a></h2> |
| <p>The Mynewt OS contains an incrementing time that drives the OS scheduler |
| and time delays. The time is a fixed size (e.g. 32 bits) and will |
| eventually wrap back to zero. The time to wrap from zero back to zero is |
| called the <strong>OS time epoch</strong>.</p> |
| <p>The frequency of the OS time tick is specified in the |
| architecture-specific OS code <code class="docutils literal notranslate"><span class="pre">os_arch.h</span></code> and is named |
| <code class="docutils literal notranslate"><span class="pre">OS_TICKS_PER_SEC</span></code>.</p> |
| <p>The Mynewt OS also provides APIs for setting and retrieving the |
| wallclock time (also known as local time or time-of-day in other |
| operating systems).</p> |
| </div> |
| <div class="section" id="data-structures"> |
| <h2><a class="toc-backref" href="#id2">Data Structures</a><a class="headerlink" href="#data-structures" title="Permalink to this headline">¶</a></h2> |
| <p>Time is stored in Mynewt as an <a class="reference internal" href="#c.os_time_t" title="os_time_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">os_time_t</span></code></a> value.</p> |
| <p>Wallclock time is represented using the <a class="reference internal" href="#c.os_timeval" title="os_timeval"><code class="xref c c-data docutils literal notranslate"><span class="pre">struct</span> <span class="pre">os_timeval</span></code></a> and |
| <a class="reference internal" href="#c.os_timezone" title="os_timezone"><code class="xref c c-data docutils literal notranslate"><span class="pre">struct</span> <span class="pre">os_timezone</span></code></a> tuple.</p> |
| <p><a class="reference internal" href="#c.os_timeval" title="os_timeval"><code class="xref c c-data docutils literal notranslate"><span class="pre">struct</span> <span class="pre">os_timeval</span></code></a> represents the number of seconds elapsed since |
| 00:00:00 Jan 1, 1970 UTC.</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">os_timeval</span><span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="kt">int64_t</span><span class="w"> </span><span class="n">tv_sec</span><span class="p">;</span><span class="w"> </span><span class="cm">/* seconds since Jan 1 1970 UTC */</span> |
| <span class="w"> </span><span class="kt">int32_t</span><span class="w"> </span><span class="n">tv_usec</span><span class="p">;</span><span class="w"> </span><span class="cm">/* fractional seconds */</span> |
| <span class="p">};</span> |
| |
| <span class="k">struct</span><span class="w"> </span><span class="nc">os_timeval</span><span class="w"> </span><span class="n">tv</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">1457400000</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">};</span><span class="w"> </span><span class="cm">/* 01:20:00 Mar 8 2016 UTC */</span> |
| </pre></div> |
| </div> |
| <p><a class="reference internal" href="#c.os_timezone" title="os_timezone"><code class="xref c c-data docutils literal notranslate"><span class="pre">struct</span> <span class="pre">os_timezone</span></code></a> is used to specify the offset of local time from |
| UTC and whether daylight savings is in effect. Note that <code class="docutils literal notranslate"><span class="pre">tz_minuteswest</span></code> is a positive number |
| if the local time is <em>behind</em> UTC and a negative number if the local time is <em>ahead</em> of UTC.</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">os_timezone</span><span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="kt">int16_t</span><span class="w"> </span><span class="n">tz_minuteswest</span><span class="p">;</span> |
| <span class="w"> </span><span class="kt">int16_t</span><span class="w"> </span><span class="n">tz_dsttime</span><span class="p">;</span> |
| <span class="p">};</span> |
| |
| <span class="cm">/* Pacific Standard Time is 08:00 hours west of UTC */</span> |
| <span class="k">struct</span><span class="w"> </span><span class="nc">os_timezone</span><span class="w"> </span><span class="n">PST</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">480</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">};</span> |
| <span class="k">struct</span><span class="w"> </span><span class="nc">os_timezone</span><span class="w"> </span><span class="n">PDT</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">480</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">};</span> |
| |
| <span class="cm">/* Indian Standard Time is 05:30 hours east of UTC */</span> |
| <span class="k">struct</span><span class="w"> </span><span class="nc">os_timezone</span><span class="w"> </span><span class="n">IST</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="mi">-330</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">};</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="functions"> |
| <h2><a class="toc-backref" href="#id3">Functions</a><a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h2> |
| <table class="docutils align-default"> |
| <colgroup> |
| <col style="width: 29%" /> |
| <col style="width: 71%" /> |
| </colgroup> |
| <thead> |
| <tr class="row-odd"><th class="head"><p>Function</p></th> |
| <th class="head"><p>Description</p></th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr class="row-even"><td><p><a class="reference internal" href="#c.os_time_advance" title="os_time_advance"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_time_advance()</span></code></a></p></td> |
| <td><p>Increments the OS time tick for the system.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><a class="reference internal" href="#c.os_time_delay" title="os_time_delay"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_time_delay()</span></code></a></p></td> |
| <td><p>Put the current task to sleep for the given number of ticks.</p></td> |
| </tr> |
| <tr class="row-even"><td><p><a class="reference internal" href="#c.os_time_get" title="os_time_get"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_time_get()</span></code></a></p></td> |
| <td><p>Get the current value of OS time.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><a class="reference internal" href="#c.os_time_ms_to_ticks" title="os_time_ms_to_ticks"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_time_ms_to_ticks()</span></code></a></p></td> |
| <td><p>Converts milliseconds to os ticks.</p></td> |
| </tr> |
| <tr class="row-even"><td><p><a class="reference internal" href="#c.os_get_uptime_usec" title="os_get_uptime_usec"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_get_uptime_usec()</span></code></a></p></td> |
| <td><p>Gets the time duration since boot.</p></td> |
| </tr> |
| <tr class="row-odd"><td><p><a class="reference internal" href="#c.os_gettimeofday" title="os_gettimeofday"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_gettimeofday()</span></code></a></p></td> |
| <td><p>Populate the given timeval and timezone structs with current time data.</p></td> |
| </tr> |
| <tr class="row-even"><td><p><a class="reference internal" href="#c.os_settimeofday" title="os_settimeofday"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_settimeofday()</span></code></a></p></td> |
| <td><p>Set the current time of day to the given time structs.</p></td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="section" id="macros"> |
| <h2><a class="toc-backref" href="#id4">Macros</a><a class="headerlink" href="#macros" title="Permalink to this headline">¶</a></h2> |
| <p>Several macros help with the evalution of times with respect to each |
| other.</p> |
| <ul class="simple"> |
| <li><p><a class="reference internal" href="#c.OS_TIME_TICK_LT" title="OS_TIME_TICK_LT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">OS_TIME_TICK_LT</span></code></a> – evaluates to true if t1 is before t2 in |
| time.</p></li> |
| <li><p><a class="reference internal" href="#c.OS_TIME_TICK_GT" title="OS_TIME_TICK_GT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">OS_TIME_TICK_GT</span></code></a> – evaluates to true if t1 is after t2 in |
| time</p></li> |
| <li><p><a class="reference internal" href="#c.OS_TIME_TICK_GEQ" title="OS_TIME_TICK_GEQ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">OS_TIME_TICK_GEQ</span></code></a> – evaluates to true if t1 is on or after |
| t2 in time.</p></li> |
| </ul> |
| <p>NOTE: For all of these macros the calculations are done modulo |
| ‘os_time_t’.</p> |
| <p>Ensure that comparison of OS time always uses the macros above (to |
| compensate for the possible wrap of OS time).</p> |
| <p>The following macros help adding or subtracting time when represented as |
| <a class="reference internal" href="#c.os_timeval" title="os_timeval"><code class="xref c c-data docutils literal notranslate"><span class="pre">struct</span> <span class="pre">os_timeval</span></code></a>. All parameters to the following macros are |
| pointers to <a class="reference internal" href="#c.os_timeval" title="os_timeval"><code class="xref c c-data docutils literal notranslate"><span class="pre">struct</span> <span class="pre">os_timeval</span></code></a>.</p> |
| <ul class="simple"> |
| <li><p><a class="reference internal" href="#c.os_timeradd" title="os_timeradd"><code class="xref c c-macro docutils literal notranslate"><span class="pre">os_timeradd</span></code></a> – Add <code class="docutils literal notranslate"><span class="pre">uvp</span></code> to <code class="docutils literal notranslate"><span class="pre">tvp</span></code> and store |
| result in <code class="docutils literal notranslate"><span class="pre">vvp</span></code>.</p></li> |
| <li><p><a class="reference internal" href="#c.os_timersub" title="os_timersub"><code class="xref c c-macro docutils literal notranslate"><span class="pre">os_timersub</span></code></a> – Subtract <code class="docutils literal notranslate"><span class="pre">uvp</span></code> from <code class="docutils literal notranslate"><span class="pre">tvp</span></code> and |
| store result in <code class="docutils literal notranslate"><span class="pre">vvp</span></code>.</p></li> |
| </ul> |
| </div> |
| <div class="section" id="special-notes"> |
| <h2><a class="toc-backref" href="#id5">Special Notes</a><a class="headerlink" href="#special-notes" title="Permalink to this headline">¶</a></h2> |
| <p>Its important to understand how quickly the time wraps especially when |
| doing time comparison using the macros above (or by any other means).</p> |
| <p>For example, if a tick is 1 millisecond and <a class="reference internal" href="#c.os_time_t" title="os_time_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">os_time_t</span></code></a> is 32-bits the |
| OS time will wrap back to zero in about 49.7 days or stated another way, |
| the OS time epoch is 49.7 days.</p> |
| <p>If two times are more than 1/2 the OS time epoch apart, any time |
| comparison will be incorrect. Ensure at design time that comparisons |
| will not occur between times that are more than half the OS time epoch.</p> |
| </div> |
| <div class="section" id="api"> |
| <h2><a class="toc-backref" href="#id6">API</a><a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2> |
| <dl class="c type"> |
| <dt id="c.os_time_t"> |
| <span class="target" id="group___o_s_time_1gaa2378cafc0f8fbfb44633036348bfe64"></span><em class="property"><span class="pre">typedef</span> </em><span class="pre">uint32_t</span> <code class="sig-name descname"><span class="pre">os_time_t</span></code><a class="headerlink" href="#c.os_time_t" title="Permalink to this definition">¶</a><br /></dt> |
| <dd></dd></dl> |
| |
| <dl class="c type"> |
| <dt id="c.os_stime_t"> |
| <span class="target" id="group___o_s_time_1ga7557d3ce9091f57daa64e5d3187067f4"></span><em class="property"><span class="pre">typedef</span> </em><span class="pre">int32_t</span> <code class="sig-name descname"><span class="pre">os_stime_t</span></code><a class="headerlink" href="#c.os_stime_t" title="Permalink to this definition">¶</a><br /></dt> |
| <dd></dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_time_get"> |
| <span class="target" id="group___o_s_time_1gac20647237280640f96f61558fb7f0762"></span><a class="reference internal" href="#c.os_time_t" title="os_time_t"><span class="pre">os_time_t</span></a> <code class="sig-name descname"><span class="pre">os_time_get</span></code><span class="sig-paren">(</span><span class="pre">void</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_time_get" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Get the current OS time in ticks. </p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>OS time in ticks </p> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_time_advance"> |
| <span class="target" id="group___o_s_time_1ga1804fd98423ee3fb364cd7394de12c58"></span><span class="pre">void</span> <code class="sig-name descname"><span class="pre">os_time_advance</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">ticks</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_time_advance" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Move OS time forward ticks. </p> |
| <p><dl class="simple"> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ticks</span></code>: The number of ticks to move time forward. </p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_time_delay"> |
| <span class="target" id="group___o_s_time_1ga7213d633b86da8e00d13061d12a1f075"></span><span class="pre">void</span> <code class="sig-name descname"><span class="pre">os_time_delay</span></code><span class="sig-paren">(</span><span class="pre">int32_t</span> <em><span class="pre">osticks</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_time_delay" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Puts the current task to sleep for the specified number of os ticks. </p> |
| <p>There is no delay if ticks is <= 0.</p> |
| <p><dl class="simple"> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">osticks</span></code>: Number of ticks to delay (<= 0 means no delay). </p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_settimeofday"> |
| <span class="target" id="group___o_s_time_1ga51fe1688dd54af6c0f8f564f4cad2f0e"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_settimeofday</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_timeval" title="os_timeval"><span class="pre">os_timeval</span></a> <span class="pre">*</span><em><span class="pre">utctime</span></em>, <em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_timezone" title="os_timezone"><span class="pre">os_timezone</span></a> <span class="pre">*</span><em><span class="pre">tz</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_settimeofday" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Set the time of day. </p> |
| <p>This does not modify os time, but rather just modifies the offset by which we are tracking real time against os time.</p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>0 on success, non-zero on failure. </p> |
| </dd> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">utctime</span></code>: A timeval representing the UTC time we are setting </p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">tz</span></code>: The time-zone to apply against the utctime being set.</p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_gettimeofday"> |
| <span class="target" id="group___o_s_time_1gab552d38ffef88c59f99d40e6c960f10b"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_gettimeofday</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_timeval" title="os_timeval"><span class="pre">os_timeval</span></a> <span class="pre">*</span><em><span class="pre">utctime</span></em>, <em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_timezone" title="os_timezone"><span class="pre">os_timezone</span></a> <span class="pre">*</span><em><span class="pre">tz</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_gettimeofday" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Get the current time of day. </p> |
| <p>Returns the time of day in UTC into the tv argument, and returns the timezone (if set) into tz.</p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>0 on success, non-zero on failure </p> |
| </dd> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">tv</span></code>: The structure to put the UTC time of day into </p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">tz</span></code>: The structure to put the timezone information into</p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_get_uptime_usec"> |
| <span class="target" id="group___o_s_time_1ga68328fcd56f96d4af71ad36d6b90abe2"></span><span class="pre">int64_t</span> <code class="sig-name descname"><span class="pre">os_get_uptime_usec</span></code><span class="sig-paren">(</span><span class="pre">void</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_get_uptime_usec" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Get time since boot in microseconds. </p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>time since boot in microseconds </p> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_get_uptime"> |
| <span class="target" id="group___o_s_time_1gacb19775faa258691ed6451aab8a546ec"></span><span class="pre">void</span> <code class="sig-name descname"><span class="pre">os_get_uptime</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_timeval" title="os_timeval"><span class="pre">os_timeval</span></a> <span class="pre">*</span><em><span class="pre">tvp</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_get_uptime" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Get time since boot as <a class="reference internal" href="#structos__timeval"><span class="std std-ref">os_timeval</span></a>. </p> |
| <p><dl class="simple"> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">tv</span></code>: Structure to put the time since boot. </p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_time_ms_to_ticks"> |
| <span class="target" id="group___o_s_time_1gae5d9e53dfa7e8fd721766271ea003ac7"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_time_ms_to_ticks</span></code><span class="sig-paren">(</span><span class="pre">uint32_t</span> <em><span class="pre">ms</span></em>, <span class="pre">uint32_t</span> <span class="pre">*</span><em><span class="pre">out_ticks</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_time_ms_to_ticks" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Converts milliseconds to OS ticks. </p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>0 on success; OS_EINVAL if the result is too large to fit in a uint32_t. </p> |
| </dd> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ms</span></code>: The milliseconds input. </p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">out_ticks</span></code>: The OS ticks output.</p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_time_ticks_to_ms"> |
| <span class="target" id="group___o_s_time_1gaa240a9884c7f644eb16ff2fddfdb8663"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_time_ticks_to_ms</span></code><span class="sig-paren">(</span><span class="pre">uint32_t</span> <em><span class="pre">ticks</span></em>, <span class="pre">uint32_t</span> <span class="pre">*</span><em><span class="pre">out_ms</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_time_ticks_to_ms" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Converts OS ticks to milliseconds. </p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>0 on success; OS_EINVAL if the result is too large to fit in a uint32_t. </p> |
| </dd> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ticks</span></code>: The OS ticks input. </p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">out_ms</span></code>: The milliseconds output.</p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_time_ms_to_ticks32"> |
| <span class="target" id="group___o_s_time_1ga7f031891d626a0f6514dcc501aef2db3"></span><span class="pre">uint32_t</span> <code class="sig-name descname"><span class="pre">os_time_ms_to_ticks32</span></code><span class="sig-paren">(</span><span class="pre">uint32_t</span> <em><span class="pre">ms</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_time_ms_to_ticks32" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Converts milliseconds to OS ticks. </p> |
| <p>This function does not check if conversion overflows and should be only used in cases where input is known to be small enough not to overflow.</p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>result on success </p> |
| </dd> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ms</span></code>: The milliseconds input.</p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.os_time_ticks_to_ms32"> |
| <span class="target" id="group___o_s_time_1ga7b5192898af1f14e5df94d7eaf94103b"></span><span class="pre">uint32_t</span> <code class="sig-name descname"><span class="pre">os_time_ticks_to_ms32</span></code><span class="sig-paren">(</span><span class="pre">uint32_t</span> <em><span class="pre">ticks</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_time_ticks_to_ms32" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Converts OS ticks to milliseconds. </p> |
| <p>This function does not check if conversion overflows and should be only used in cases where input is known to be small enough not to overflow.</p> |
| <p><dl class="simple"> |
| <dt><strong>Return</strong></dt><dd><p>result on success </p> |
| </dd> |
| <dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ticks</span></code>: The OS ticks input.</p></li> |
| </ul> |
| </dd> |
| </dl> |
| </p> |
| </dd></dl> |
| |
| <dl class="c macro"> |
| <dt id="c.OS_TIME_MAX"> |
| <span class="target" id="group___o_s_time_1ga7d9d6efeb91296092166d7f9e1b82cc3"></span><code class="sig-name descname"><span class="pre">OS_TIME_MAX</span></code><a class="headerlink" href="#c.OS_TIME_MAX" title="Permalink to this definition">¶</a><br /></dt> |
| <dd></dd></dl> |
| |
| <dl class="c macro"> |
| <dt id="c.OS_TIMEOUT_NEVER"> |
| <span class="target" id="group___o_s_time_1gae28c55062f853e4feb13b3c61a04099c"></span><code class="sig-name descname"><span class="pre">OS_TIMEOUT_NEVER</span></code><a class="headerlink" href="#c.OS_TIMEOUT_NEVER" title="Permalink to this definition">¶</a><br /></dt> |
| <dd></dd></dl> |
| |
| <dl class="c macro"> |
| <dt id="c.OS_TIME_TICK_LT"> |
| <span class="target" id="group___o_s_time_1ga9ea6181f50d4452091125926891dd6c7"></span><code class="sig-name descname"><span class="pre">OS_TIME_TICK_LT</span></code><span class="sig-paren">(</span><em><span class="pre">__t1</span></em>, <em><span class="pre">__t2</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.OS_TIME_TICK_LT" title="Permalink to this definition">¶</a><br /></dt> |
| <dd></dd></dl> |
| |
| <dl class="c macro"> |
| <dt id="c.OS_TIME_TICK_GT"> |
| <span class="target" id="group___o_s_time_1gacd74602e3bed14014f4e1854aff8bf92"></span><code class="sig-name descname"><span class="pre">OS_TIME_TICK_GT</span></code><span class="sig-paren">(</span><em><span class="pre">__t1</span></em>, <em><span class="pre">__t2</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.OS_TIME_TICK_GT" title="Permalink to this definition">¶</a><br /></dt> |
| <dd></dd></dl> |
| |
| <dl class="c macro"> |
| <dt id="c.OS_TIME_TICK_GEQ"> |
| <span class="target" id="group___o_s_time_1ga3b96d8bc74b2771519ea74c3cc775b58"></span><code class="sig-name descname"><span class="pre">OS_TIME_TICK_GEQ</span></code><span class="sig-paren">(</span><em><span class="pre">__t1</span></em>, <em><span class="pre">__t2</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.OS_TIME_TICK_GEQ" title="Permalink to this definition">¶</a><br /></dt> |
| <dd></dd></dl> |
| |
| <dl class="c macro"> |
| <dt id="c.os_timeradd"> |
| <span class="target" id="group___o_s_time_1ga1e206e1b6cad723bb4bde169cf4f8423"></span><code class="sig-name descname"><span class="pre">os_timeradd</span></code><span class="sig-paren">(</span><em><span class="pre">tvp</span></em>, <em><span class="pre">uvp</span></em>, <em><span class="pre">vvp</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_timeradd" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Add first two timeval arguments and place results in third timeval argument. </p> |
| </dd></dl> |
| |
| <dl class="c macro"> |
| <dt id="c.os_timersub"> |
| <span class="target" id="group___o_s_time_1ga9b5b5bf81fac37a92de28d93ec6d0935"></span><code class="sig-name descname"><span class="pre">os_timersub</span></code><span class="sig-paren">(</span><em><span class="pre">tvp</span></em>, <em><span class="pre">uvp</span></em>, <em><span class="pre">vvp</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.os_timersub" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Subtract first two timeval arguments and place results in third timeval argument. </p> |
| </dd></dl> |
| |
| <dl class="c struct"> |
| <dt id="c.os_timeval"> |
| <span class="target" id="structos__timeval"></span><em class="property"><span class="pre">struct</span> </em><code class="sig-name descname"><span class="pre">os_timeval</span></code><a class="headerlink" href="#c.os_timeval" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><em>#include <os_time.h></em><p>Structure representing time since Jan 1 1970 with microsecond granularity. </p> |
| </dd></dl> |
| |
| <dl class="c struct"> |
| <dt id="c.os_timezone"> |
| <span class="target" id="structos__timezone"></span><em class="property"><span class="pre">struct</span> </em><code class="sig-name descname"><span class="pre">os_timezone</span></code><a class="headerlink" href="#c.os_timezone" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><em>#include <os_time.h></em><p>Structure representing a timezone offset. </p> |
| <div class="breathe-sectiondef docutils container"> |
| <p class="breathe-sectiondef-title rubric" id="breathe-section-title-public-members">Public Members</p> |
| <dl class="c var"> |
| <dt id="c.os_timezone.tz_minuteswest"> |
| <span class="target" id="structos__timezone_1aa49a54e62d0e87482130d87c5eab0022"></span><span class="pre">int16_t</span> <code class="sig-name descname"><span class="pre">tz_minuteswest</span></code><a class="headerlink" href="#c.os_timezone.tz_minuteswest" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Minutes west of GMT. </p> |
| </dd></dl> |
| |
| <dl class="c var"> |
| <dt id="c.os_timezone.tz_dsttime"> |
| <span class="target" id="structos__timezone_1a2644f6e4558f08da4d94b4dc27d6d5e5"></span><span class="pre">int16_t</span> <code class="sig-name descname"><span class="pre">tz_dsttime</span></code><a class="headerlink" href="#c.os_timezone.tz_dsttime" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Daylight savings time correction (if any) </p> |
| </dd></dl> |
| |
| </div> |
| </dd></dl> |
| |
| </div> |
| </div> |
| |
| |
| </div> |
| </div> |
| |
| <div class="rst-footer-buttons row" role="navigation" aria-label="footer navigation"> |
| |
| <a href="../sanity/sanity.html" class="btn btn-neutral float-right" title="Sanity" accesskey="n">Next: Sanity <span class="fa fa-arrow-circle-right"></span></a> |
| |
| |
| <a href="../cputime/os_cputime.html" class="btn btn-neutral" title="CPU Time" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous: CPU Time</a> |
| |
| </div> |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS CONTENT SECTION --> |
| </div> |
| <!-- ENDS .content --> |
| </div> |
| </div> |
| <footer> |
| <div class="container"> |
| <div class="row"> |
| <div class="col-xs-12"> |
| |
| <p class="copyright">Apache Mynewt is available under Apache License, version 2.0.</p> |
| |
| </div> |
| <div class="col-xs-12"> |
| <div class="logos"> |
| <img src="../../../_static/img/asf_logo_wide_small.png" alt="Apache" title="Apache"> |
| <small class="footnote"> |
| Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt project logo are either |
| registered trademarks or trademarks of the Apache Software Foundation in the United States and other countries. |
| </small> |
| <a href=""> |
| <img src="../../../_static/img/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" /> |
| </a> |
| </div> |
| </div> |
| </div> |
| </div> |
| </footer> |
| </div> |
| <!-- ENDS #wrapper --> |
| |
| |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT:'../../../', |
| VERSION:'latest', |
| COLLAPSE_INDEX:false, |
| FILE_SUFFIX:'.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '.txt', |
| LINK_SUFFIX: '.html' |
| }; |
| </script> |
| <script type="text/javascript" src="../../../_static/jquery.js"></script> |
| <script type="text/javascript" src="../../../_static/underscore.js"></script> |
| <script type="text/javascript" src="../../../_static/doctools.js"></script> |
| <script type="text/javascript" src="../../../_static/js/bootstrap-3.0.3.min.js"></script> |
| <script type="text/javascript" src="../../../_static/js/affix.js"></script> |
| <script type="text/javascript" src="../../../_static/js/main.js"></script> |
| |
| |
| |
| </body> |
| </html> |