| <!-- |
| Documentation/_templates/layout.html |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. The |
| ASF licenses this file to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance with the |
| License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| License for the specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| |
| |
| <!DOCTYPE html> |
| <html class="writer-html5" lang="en"> |
| <head> |
| <meta charset="utf-8" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" /> |
| |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| <title>Timer Drivers — NuttX latest documentation</title> |
| <link rel="stylesheet" type="text/css" href="../../../../_static/pygments.css" /> |
| <link rel="stylesheet" type="text/css" href="../../../../_static/css/theme.css" /> |
| <link rel="stylesheet" type="text/css" href="../../../../_static/copybutton.css" /> |
| <link rel="stylesheet" type="text/css" href="../../../../_static/sphinx_collapse.css" /> |
| <link rel="stylesheet" type="text/css" href="../../../../_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css" /> |
| <link rel="stylesheet" type="text/css" href="../../../../_static/custom.css" /> |
| |
| |
| <link rel="shortcut icon" href="../../../../_static/favicon.ico"/> |
| <script src="../../../../_static/jquery.js"></script> |
| <script src="../../../../_static/_sphinx_javascript_frameworks_compat.js"></script> |
| <script data-url_root="../../../../" id="documentation_options" src="../../../../_static/documentation_options.js"></script> |
| <script src="../../../../_static/doctools.js"></script> |
| <script src="../../../../_static/sphinx_highlight.js"></script> |
| <script src="../../../../_static/clipboard.min.js"></script> |
| <script src="../../../../_static/copybutton.js"></script> |
| <script src="../../../../_static/design-tabs.js"></script> |
| <script src="../../../../_static/js/theme.js"></script> |
| <link rel="index" title="Index" href="../../../../genindex.html" /> |
| <link rel="search" title="Search" href="../../../../search.html" /> |
| <link rel="next" title="PWM Drivers" href="pwm.html" /> |
| <link rel="prev" title="Timers Drivers" href="index.html" /> |
| </head> |
| |
| <body class="wy-body-for-nav"> |
| <div class="wy-grid-for-nav"> |
| <nav data-toggle="wy-nav-shift" class="wy-nav-side"> |
| <div class="wy-side-scroll"> |
| <div class="wy-side-nav-search" > |
| |
| <a href="../../../../index.html" class="icon icon-home"> NuttX |
| |
| |
| |
| </a> |
| |
| <!-- this version selector is quite ugly, should be probably replaced by something |
| more modern --> |
| |
| <div class="version-selector"> |
| <select onchange="javascript:location.href = this.value;"> |
| |
| <option value="../../../../../latest" selected="selected">latest</option> |
| |
| <option value="../../../../../10.0.0" >10.0.0</option> |
| |
| <option value="../../../../../10.0.1" >10.0.1</option> |
| |
| <option value="../../../../../10.1.0" >10.1.0</option> |
| |
| <option value="../../../../../10.2.0" >10.2.0</option> |
| |
| <option value="../../../../../10.3.0" >10.3.0</option> |
| |
| <option value="../../../../../11.0.0" >11.0.0</option> |
| |
| <option value="../../../../../12.0.0" >12.0.0</option> |
| |
| <option value="../../../../../12.1.0" >12.1.0</option> |
| |
| <option value="../../../../../12.2.0" >12.2.0</option> |
| |
| <option value="../../../../../12.2.1" >12.2.1</option> |
| |
| <option value="../../../../../12.3.0" >12.3.0</option> |
| |
| <option value="../../../../../12.4.0" >12.4.0</option> |
| |
| <option value="../../../../../12.5.0" >12.5.0</option> |
| |
| <option value="../../../../../12.5.1" >12.5.1</option> |
| |
| <option value="../../../../../12.6.0" >12.6.0</option> |
| |
| <option value="../../../../../12.7.0" >12.7.0</option> |
| |
| <option value="../../../../../12.8.0" >12.8.0</option> |
| |
| <option value="../../../../../12.9.0" >12.9.0</option> |
| |
| <option value="../../../../../12.10.0" >12.10.0</option> |
| |
| <option value="../../../../../12.11.0" >12.11.0</option> |
| |
| </select> |
| </div> |
| |
| |
| <div role="search"> |
| <form id="rtd-search-form" class="wy-form" action="../../../../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| |
| </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> |
| <p class="caption" role="heading"><span class="caption-text">Table of Contents</span></p> |
| <ul class="current"> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../index.html">Home</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../introduction/index.html">Introduction</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../quickstart/index.html">Getting Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../contributing/index.html">Contributing</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../platforms/index.html">Supported Platforms</a></li> |
| <li class="toctree-l1 current"><a class="reference internal" href="../../../index.html">OS Components</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="../../../binfmt.html">Binary Loader</a></li> |
| <li class="toctree-l2 current"><a class="reference internal" href="../../index.html">Device Drivers</a><ul class="current"> |
| <li class="toctree-l3 current"><a class="reference internal" href="../index.html">Character Device Drivers</a><ul class="current"> |
| <li class="toctree-l4"><a class="reference internal" href="../1wire.html">One Wire Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../analog/index.html">Analog (ADC/DAC) Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../bch.html">Block Driver to Character Driver</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../can.html">CAN Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../contactless.html">Constactless Devices</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../crypto/index.html">Crypto Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../efuse.html">EFUSE Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../i2s.html">I2S Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../input/index.html">Input Devices</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../ipcc.html">IPCC (Inter Processor Communication Controller) Driver</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../leds/index.html">LEDS</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../loop.html">Loop Device</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../math.html">Math Acceleration Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../modem.html">Modem Device</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../motor/index.html">Motor Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../note.html">Note Driver Interface</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../nullzero.html"><code class="docutils literal notranslate"><span class="pre">dev_null.c</span></code> and <code class="docutils literal notranslate"><span class="pre">dev_zero.c</span></code></a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../quadrature.html">Quadrature Encoder Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../rc.html">Remote Control Devices</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../rf.html">RF Devices</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../serial.html">Serial Device Drivers</a></li> |
| <li class="toctree-l4 current"><a class="reference internal" href="index.html">Timers Drivers</a><ul class="current"> |
| <li class="toctree-l5 current"><a class="current reference internal" href="#">Timer Drivers</a></li> |
| <li class="toctree-l5"><a class="reference internal" href="pwm.html">PWM Drivers</a></li> |
| <li class="toctree-l5"><a class="reference internal" href="watchdog.html">Watchdog Timer Drivers</a></li> |
| <li class="toctree-l5"><a class="reference internal" href="rtc.html">RTC Drivers</a></li> |
| <li class="toctree-l5"><a class="reference internal" href="capture.html">Capture</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l4"><a class="reference internal" href="../touchscreen.html">Touchscreen Device Drivers</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="../wireless/index.html">Wireless character drivers</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l3"><a class="reference internal" href="../../block/index.html">Block Device Drivers</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../../special/index.html">Specialized Device Drivers</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../../thermal/index.html">Thermal Framework</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../../index.html#lower-half-and-upper-half">Lower-half and upper-half</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../../index.html#subdirectories-of-nuttx-drivers">Subdirectories of <code class="docutils literal notranslate"><span class="pre">nuttx/drivers</span></code></a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../../index.html#skeleton-files">Skeleton Files</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="../../index.html#drivers-early-initialization">Drivers Early Initialization</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../nxflat.html">NXFLAT</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../nxgraphics/index.html">NX Graphics Subsystem</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../paging.html">On-Demand Paging</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../audio/index.html">Audio Subsystem</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../filesystem/index.html">NuttX File System</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../libs/index.html">NuttX libraries</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../net/index.html">Network Support</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../mm/index.html">Memory Management</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../syscall.html">Syscall Layer</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../tools/index.html"><code class="docutils literal notranslate"><span class="pre">/tools</span></code> Host Tools</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../arch/index.html">Architecture-Specific Code</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../boards.html">Boards Support</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../cmake.html">CMake Support</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../openamp.html">OpenAMP Support</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../video.html">Video Subsystem</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../crypto.html">Crypto API Subsystem</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../../../wireless.html">Wireless Subsystem</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../applications/index.html">Applications</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../implementation/index.html">Implementation Details</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../reference/index.html">API Reference</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../faq/index.html">FAQ</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../debugging/index.html">Debugging</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../guides/index.html">Guides</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../standards/index.html">Standards</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../glossary.html">Glossary</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../logos/index.html">NuttX Logos</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../../../_tags/tagsindex.html">Tags</a></li> |
| </ul> |
| |
| </div> |
| </div> |
| </nav> |
| |
| <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > |
| <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
| <a href="../../../../index.html">NuttX</a> |
| </nav> |
| |
| <div class="wy-nav-content"> |
| <div class="rst-content"> |
| <div role="navigation" aria-label="Page navigation"> |
| <ul class="wy-breadcrumbs"> |
| <li><a href="../../../../index.html" class="icon icon-home" aria-label="Home"></a></li> |
| <li class="breadcrumb-item"><a href="../../../index.html">OS Components</a></li> |
| <li class="breadcrumb-item"><a href="../../index.html">Device Drivers</a></li> |
| <li class="breadcrumb-item"><a href="../index.html">Character Device Drivers</a></li> |
| <li class="breadcrumb-item"><a href="index.html">Timers Drivers</a></li> |
| <li class="breadcrumb-item active">Timer Drivers</li> |
| <li class="wy-breadcrumbs-aside"> |
| <a href="https://github.com/apache/nuttx/blob/master/Documentation/components/drivers/character/timers/timer.rst" class="fa fa-github"> Edit on GitHub</a> |
| </li> |
| </ul> |
| <hr/> |
| </div> |
| <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| <div itemprop="articleBody"> |
| |
| <section id="timer-drivers"> |
| <h1>Timer Drivers<a class="headerlink" href="#timer-drivers" title="Permalink to this heading"></a></h1> |
| <p>Files supporting the timer driver can be found in the following |
| locations:</p> |
| <ul class="simple"> |
| <li><p><strong>Interface Definition</strong>. The header file for the NuttX timer |
| driver reside at <code class="docutils literal notranslate"><span class="pre">include/nuttx/timers/timer.h</span></code>. This header |
| file includes both the application level interface to the timer |
| driver as well as the interface between the “upper half” and |
| “lower half” drivers. The timer driver uses a standard |
| character driver framework.</p></li> |
| <li><p><strong>“Upper Half” Driver</strong>. The generic, “upper half” timer driver |
| resides at <code class="docutils literal notranslate"><span class="pre">drivers/timers/timer.c</span></code>.</p></li> |
| <li><p><strong>“Lower Half” Drivers</strong>. Platform-specific timer drivers |
| reside in <code class="docutils literal notranslate"><span class="pre">arch/<architecture>/src/<hardware></span></code> |
| directory for the specific processor <code class="docutils literal notranslate"><span class="pre"><architecture></span></code> and for |
| the specific <code class="docutils literal notranslate"><span class="pre"><chip></span></code> timer peripheral devices.</p></li> |
| </ul> |
| <p>There are two ways to enable Timer Support along with the Timer Example. The |
| first is faster and simpler. Just run the following command to use a ready |
| config file with timer support and example included. You need to check if there’s |
| a timer config file for your specific chip. You may check it at the specific |
| board’s path: <code class="docutils literal notranslate"><span class="pre">/boards/<arch>/<chip>/<variant>/config</span></code>.</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>./tools/configure.sh<span class="w"> </span><variant>:timer |
| </pre></div> |
| </div> |
| <p>And the second way is creating your own config file. To do so, follow the next |
| instructions.</p> |
| <section id="enabling-the-timer-support-and-example-in-menuconfing"> |
| <h2>Enabling the Timer Support and Example in <code class="docutils literal notranslate"><span class="pre">menuconfing</span></code><a class="headerlink" href="#enabling-the-timer-support-and-example-in-menuconfing" title="Permalink to this heading"></a></h2> |
| <blockquote> |
| <div><blockquote> |
| <div><ol class="arabic simple"> |
| <li><p>Select Timer Instances</p></li> |
| </ol> |
| </div></blockquote> |
| <p>To select these timers browse in the <code class="docutils literal notranslate"><span class="pre">menuconfig</span></code> using the following path:</p> |
| <blockquote> |
| <div><p>Go into menu <span class="menuselection">System Type ‣ <Chip> Peripheral Selection</span> and press <kbd class="kbd docutils literal notranslate">Enter</kbd>.</p> |
| <p>Then select one or more timers according to availability.</p> |
| <ol class="arabic simple" start="2"> |
| <li><p>Enable the Timer Support</p></li> |
| </ol> |
| <p>Go into menu <span class="menuselection">Device Drivers ‣ Timer Driver Support</span> and press <kbd class="kbd docutils literal notranslate">Enter</kbd>. Then enable:</p> |
| <ul class="simple"> |
| <li><p>[x] Timer Support</p></li> |
| <li><p>[x] Timer Arch Implementation</p></li> |
| </ul> |
| <ol class="arabic simple" start="3"> |
| <li><p>Include the Timer Example</p></li> |
| </ol> |
| <p>Go into menu <span class="menuselection">Application Configuration ‣ Examples</span> and press <kbd class="kbd docutils literal notranslate">Enter</kbd>. Then select the Timer Example.</p> |
| <ul class="simple"> |
| <li><p>[x] Timer example</p></li> |
| </ul> |
| <p>Below the option, it is possible to manually configure some parameters as the |
| standard timer device path, the timeout, the sample rate in which the counter |
| will be read, the number of samples to be executed, and other parameters.</p> |
| </div></blockquote> |
| </div></blockquote> |
| </section> |
| <section id="timer-example"> |
| <h2>Timer Example<a class="headerlink" href="#timer-example" title="Permalink to this heading"></a></h2> |
| <p>The previously selected example will basically consult the timer status, set a |
| timer alarm interval, set a timer signal handler function to be notified at the |
| alarm, which only increments a variable, and then it will start the timer. The |
| application will periodically consult the timer status at the sample rate |
| previously configured through the <code class="docutils literal notranslate"><span class="pre">menuconfig</span></code> to follow the time left until |
| the timer expires. After the samples have been read, the application stops the |
| timer.</p> |
| <p>The <a class="reference external" href="https://github.com/apache/nuttx-apps/blob/master/examples/timer/timer_main.c">example code</a> |
| may be explored, its path is at <code class="docutils literal notranslate"><span class="pre">/examples/timer/timer_main.c</span></code> in the apps’ repository.</p> |
| <p>In NuttX, the timer driver is a character driver and when a chip supports multiple |
| timers, each one is accessible through its respective file in <code class="docutils literal notranslate"><span class="pre">/dev</span></code> directory. |
| Each timer is registered using a unique numeric identifier (i.e. <code class="docutils literal notranslate"><span class="pre">/dev/timer0</span></code>, |
| <code class="docutils literal notranslate"><span class="pre">/dev/timer1</span></code>, …).</p> |
| <p>Use the following command to run the example:</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">`nsh> timer`</span> |
| </pre></div> |
| </div> |
| <p>This command will use the timer 0. To use the others, specify it through a |
| parameter (where x is the timer number):</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">`nsh> timer -d /dev/timerx`</span> |
| </pre></div> |
| </div> |
| </section> |
| <section id="application-level-interface"> |
| <h2>Application Level Interface<a class="headerlink" href="#application-level-interface" title="Permalink to this heading"></a></h2> |
| <p>The first necessary thing to be done in order to use the timer driver in an |
| application is to include the header file for the NuttX timer driver. It contains |
| the Application Level Interface to the timer driver. To do so, include:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><nuttx/timers/timer.h></span> |
| </pre></div> |
| </div> |
| <p>At an application level, the timer functionalities may be accessed through <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> |
| systems calls. The available <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> commands are:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li><p><a class="reference internal" href="#c.TCIOC_START" title="TCIOC_START"><code class="xref c c-macro docutils literal notranslate"><span class="pre">TCIOC_START</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.TCIOC_STOP" title="TCIOC_STOP"><code class="xref c c-macro docutils literal notranslate"><span class="pre">TCIOC_STOP</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.TCIOC_GETSTATUS" title="TCIOC_GETSTATUS"><code class="xref c c-macro docutils literal notranslate"><span class="pre">TCIOC_GETSTATUS</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.TCIOC_SETTIMEOUT" title="TCIOC_SETTIMEOUT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">TCIOC_SETTIMEOUT</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.TCIOC_NOTIFICATION" title="TCIOC_NOTIFICATION"><code class="xref c c-macro docutils literal notranslate"><span class="pre">TCIOC_NOTIFICATION</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.TCIOC_MAXTIMEOUT" title="TCIOC_MAXTIMEOUT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">TCIOC_MAXTIMEOUT</span></code></a></p></li> |
| </ul> |
| </div></blockquote> |
| <p>These <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> commands internally call lower-half layer operations and the |
| parameters are forwarded to these ops through the <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> system call. The return |
| of a system call is the return of an operation. |
| These <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">timer_ops_s</span></code> keeps pointers to the implementation of each operation. |
| Following is the struct.</p> |
| <dl class="c struct"> |
| <dt class="sig sig-object c" id="c.timer_ops_s"> |
| <span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">timer_ops_s</span></span></span><a class="headerlink" href="#c.timer_ops_s" title="Permalink to this definition"></a><br /></dt> |
| <dd></dd></dl> |
| |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_ops_s</span> |
| <span class="p">{</span> |
| <span class="w"> </span><span class="cm">/* Required methods *******************************************************/</span> |
| |
| <span class="w"> </span><span class="cm">/* Start the timer, resetting the time to the current timeout */</span> |
| |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="nf">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">start</span><span class="p">)(</span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_lowerhalf_s</span><span class="w"> </span><span class="o">*</span><span class="n">lower</span><span class="p">);</span> |
| |
| <span class="w"> </span><span class="cm">/* Stop the timer */</span> |
| |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="nf">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">stop</span><span class="p">)(</span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_lowerhalf_s</span><span class="w"> </span><span class="o">*</span><span class="n">lower</span><span class="p">);</span> |
| |
| <span class="w"> </span><span class="cm">/* Get the current timer status */</span> |
| |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="nf">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">getstatus</span><span class="p">)(</span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_lowerhalf_s</span><span class="w"> </span><span class="o">*</span><span class="n">lower</span><span class="p">,</span> |
| <span class="w"> </span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_status_s</span><span class="w"> </span><span class="o">*</span><span class="n">status</span><span class="p">);</span> |
| |
| <span class="w"> </span><span class="cm">/* Set a new timeout value (and reset the timer) */</span> |
| |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="nf">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">settimeout</span><span class="p">)(</span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_lowerhalf_s</span><span class="w"> </span><span class="o">*</span><span class="n">lower</span><span class="p">,</span> |
| <span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span> |
| |
| <span class="w"> </span><span class="cm">/* Call the NuttX INTERNAL timeout callback on timeout.</span> |
| <span class="cm"> * NOTE: Providing callback==NULL disable.</span> |
| <span class="cm"> * NOT to call back into applications.</span> |
| <span class="cm"> */</span> |
| |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="nf">void</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">setcallback</span><span class="p">)(</span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_lowerhalf_s</span><span class="w"> </span><span class="o">*</span><span class="n">lower</span><span class="p">,</span> |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="n">tccb_t</span><span class="w"> </span><span class="n">callback</span><span class="p">,</span><span class="w"> </span><span class="n">FAR</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">);</span> |
| |
| <span class="w"> </span><span class="cm">/* Any ioctl commands that are not recognized by the "upper-half" driver</span> |
| <span class="cm"> * are forwarded to the lower half driver through this method.</span> |
| <span class="cm"> */</span> |
| |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="nf">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">ioctl</span><span class="p">)(</span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_lowerhalf_s</span><span class="w"> </span><span class="o">*</span><span class="n">lower</span><span class="p">,</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">cmd</span><span class="p">,</span> |
| <span class="w"> </span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">long</span><span class="w"> </span><span class="n">arg</span><span class="p">);</span> |
| |
| <span class="w"> </span><span class="cm">/* Get the maximum supported timeout value */</span> |
| |
| <span class="w"> </span><span class="n">CODE</span><span class="w"> </span><span class="nf">int</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">maxtimeout</span><span class="p">)(</span><span class="n">FAR</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">timer_lowerhalf_s</span><span class="w"> </span><span class="o">*</span><span class="n">lower</span><span class="p">,</span> |
| <span class="w"> </span><span class="n">FAR</span><span class="w"> </span><span class="kt">uint32_t</span><span class="w"> </span><span class="o">*</span><span class="n">maxtimeout</span><span class="p">);</span> |
| <span class="p">};</span> |
| </pre></div> |
| </div> |
| <p>Since <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> system calls expect a file descriptor, before using these commands, |
| it’s necessary to open the timer device special file in order to get a file descriptor. |
| The following snippet demonstrates how to do so:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/* Open the timer device */</span> |
| |
| <span class="n">printf</span><span class="p">(</span><span class="s">"Open %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">devname</span><span class="p">);</span> |
| |
| <span class="n">fd</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">open</span><span class="p">(</span><span class="n">devname</span><span class="p">,</span><span class="w"> </span><span class="n">O_RDONLY</span><span class="p">);</span> |
| <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">fd</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"ERROR: Failed to open %s: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> |
| <span class="w"> </span><span class="n">devname</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> |
| <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">EXIT_FAILURE</span><span class="p">;</span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| <dl class="c macro"> |
| <dt class="sig sig-object c" id="c.TCIOC_START"> |
| <span class="sig-name descname"><span class="n"><span class="pre">TCIOC_START</span></span></span><a class="headerlink" href="#c.TCIOC_START" title="Permalink to this definition"></a><br /></dt> |
| <dd></dd></dl> |
| |
| <p>The <code class="docutils literal notranslate"><span class="pre">TCIOC_START</span></code> command calls the <code class="docutils literal notranslate"><span class="pre">start</span></code> operation, which is described below.</p> |
| <dl class="c function"> |
| <dt class="sig sig-object c" id="c.start"> |
| <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">start</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.start" title="Permalink to this definition"></a><br /></dt> |
| <dd><p>The start operation configures the timer, enables the interrupt if <code class="docutils literal notranslate"><span class="pre">TCIOC_NOTIFICATION</span></code> |
| has already been called and finally starts the timer.</p> |
| <dl class="field-list simple"> |
| <dt class="field-odd">Returns<span class="colon">:</span></dt> |
| <dd class="field-odd"><p>A Linux System Error Code for failing or 0 for success.</p> |
| </dd> |
| </dl> |
| </dd></dl> |
| |
| <p>This command may be used like so:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/* Start the timer */</span> |
| |
| <span class="n">printf</span><span class="p">(</span><span class="s">"Start the timer</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> |
| |
| <span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ioctl</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span><span class="w"> </span><span class="n">TCIOC_START</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span> |
| <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ret</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"ERROR: Failed to start the timer: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">);</span> |
| <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">EXIT_FAILURE</span><span class="p">;</span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| <dl class="c macro"> |
| <dt class="sig sig-object c" id="c.TCIOC_STOP"> |
| <span class="sig-name descname"><span class="n"><span class="pre">TCIOC_STOP</span></span></span><a class="headerlink" href="#c.TCIOC_STOP" title="Permalink to this definition"></a><br /></dt> |
| <dd></dd></dl> |
| |
| <p>The <code class="docutils literal notranslate"><span class="pre">TCIOC_STOP</span></code> command calls the <code class="docutils literal notranslate"><span class="pre">stop</span></code> operation, which is described below.</p> |
| <dl class="c function"> |
| <dt class="sig sig-object c" id="c.stop"> |
| <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">stop</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.stop" title="Permalink to this definition"></a><br /></dt> |
| <dd><p>The stop operation stops the timer and disables the interrupt.</p> |
| <dl class="field-list simple"> |
| <dt class="field-odd">Returns<span class="colon">:</span></dt> |
| <dd class="field-odd"><p>A Linux System Error Code for failing or 0 for success.</p> |
| </dd> |
| </dl> |
| </dd></dl> |
| |
| <p>This command may be used like so:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/* Stop the timer */</span> |
| |
| <span class="n">printf</span><span class="p">(</span><span class="s">"</span><span class="se">\n</span><span class="s">Stop the timer</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> |
| |
| <span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ioctl</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span><span class="w"> </span><span class="n">TCIOC_STOP</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span> |
| <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ret</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"ERROR: Failed to stop the timer: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">);</span> |
| <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">EXIT_FAILURE</span><span class="p">;</span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| <dl class="c macro"> |
| <dt class="sig sig-object c" id="c.TCIOC_GETSTATUS"> |
| <span class="sig-name descname"><span class="n"><span class="pre">TCIOC_GETSTATUS</span></span></span><a class="headerlink" href="#c.TCIOC_GETSTATUS" title="Permalink to this definition"></a><br /></dt> |
| <dd></dd></dl> |
| |
| <p>The <code class="docutils literal notranslate"><span class="pre">TCIOC_GETSTATUS</span></code> command calls the <code class="docutils literal notranslate"><span class="pre">getstatus</span></code> operation, which is described below.</p> |
| <dl class="c function"> |
| <dt class="sig sig-object c" id="c.getstatus"> |
| <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">getstatus</span></span></span><span class="sig-paren">(</span><span class="pre">FAR</span><span class="w"> </span><span class="k"><span class="pre">struct</span></span><span class="w"> </span><span class="n"><span class="pre">timer_status_s</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">status</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.getstatus" title="Permalink to this definition"></a><br /></dt> |
| <dd><p>The getstatus operation gathers the timer’s current information.</p> |
| <dl class="field-list simple"> |
| <dt class="field-odd">Parameters<span class="colon">:</span></dt> |
| <dd class="field-odd"><ul class="simple"> |
| <li><p><strong>status</strong> – A writable pointer to a struct <code class="docutils literal notranslate"><span class="pre">timer_status_s</span></code>. This struct |
| contains 3 fields: <code class="docutils literal notranslate"><span class="pre">flags</span></code> (<code class="docutils literal notranslate"><span class="pre">uint32_t</span></code>), <code class="docutils literal notranslate"><span class="pre">timeout</span></code> (<code class="docutils literal notranslate"><span class="pre">uint32_t</span></code>) |
| and <code class="docutils literal notranslate"><span class="pre">timeleft</span></code> (<code class="docutils literal notranslate"><span class="pre">uint32_t</span></code>). Bit 0 from <cite>flags</cite> indicates the timer’s |
| status, 1 indicates that the timer is running, zero it is stopped. Bit 1 |
| from <cite>flags</cite> indicates if there’s a callback registered. The <cite>timeout</cite> |
| indicates the time interval that was configured to trigger an alarm, it |
| is in microseconds. The <cite>timeleft</cite> interval indicates how many microseconds |
| it’s missing to trigger the alarm. The following snippet demonstrates how |
| to use it and how to access these fields.</p></li> |
| </ul> |
| </dd> |
| <dt class="field-even">Returns<span class="colon">:</span></dt> |
| <dd class="field-even"><p>A Linux System Error Code for failing or 0 for success.</p> |
| </dd> |
| </dl> |
| </dd></dl> |
| |
| <p>This command may be used like so:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/* Get timer status */</span> |
| |
| <span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ioctl</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span><span class="w"> </span><span class="n">TCIOC_GETSTATUS</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">long</span><span class="p">)((</span><span class="kt">uintptr_t</span><span class="p">)</span><span class="o">&</span><span class="n">status</span><span class="p">));</span> |
| <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ret</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"ERROR: Failed to get timer status: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">exit</span><span class="p">(</span><span class="n">EXIT_FAILURE</span><span class="p">);</span> |
| <span class="w"> </span><span class="p">}</span> |
| |
| <span class="cm">/* Print the timer status */</span> |
| |
| <span class="n">printf</span><span class="p">(</span><span class="s">" flags: %08lx timeout: %lu timeleft: %lu</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> |
| <span class="w"> </span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">long</span><span class="p">)</span><span class="n">status</span><span class="p">.</span><span class="n">flags</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">long</span><span class="p">)</span><span class="n">status</span><span class="p">.</span><span class="n">timeout</span><span class="p">,</span> |
| <span class="w"> </span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">long</span><span class="p">)</span><span class="n">status</span><span class="p">.</span><span class="n">timeleft</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <dl class="c macro"> |
| <dt class="sig sig-object c" id="c.TCIOC_SETTIMEOUT"> |
| <span class="sig-name descname"><span class="n"><span class="pre">TCIOC_SETTIMEOUT</span></span></span><a class="headerlink" href="#c.TCIOC_SETTIMEOUT" title="Permalink to this definition"></a><br /></dt> |
| <dd></dd></dl> |
| |
| <p>The <code class="docutils literal notranslate"><span class="pre">TCIOC_SETTIMEOUT</span></code> command calls the <code class="docutils literal notranslate"><span class="pre">settimeout</span></code> operation, which is described below.</p> |
| <dl class="c function"> |
| <dt class="sig sig-object c" id="c.settimeout"> |
| <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">settimeout</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">uint32_t</span></span><span class="w"> </span><span class="n"><span class="pre">timeout</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.settimeout" title="Permalink to this definition"></a><br /></dt> |
| <dd><p>The getstatus operation sets a timeout interval to trigger the alarm and then |
| trigger an interrupt. It defines the timer interval in which the handler will |
| be called.</p> |
| <dl class="field-list simple"> |
| <dt class="field-odd">Parameters<span class="colon">:</span></dt> |
| <dd class="field-odd"><ul class="simple"> |
| <li><p><strong>timeout</strong> – An argument of type <code class="docutils literal notranslate"><span class="pre">uint32_t</span></code> with the timeout value in microseconds.</p></li> |
| </ul> |
| </dd> |
| <dt class="field-even">Returns<span class="colon">:</span></dt> |
| <dd class="field-even"><p>A Linux System Error Code for failing or 0 for success.</p> |
| </dd> |
| </dl> |
| </dd></dl> |
| |
| <p>This command may be used like so:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/* Set the timer interval */</span> |
| |
| <span class="n">printf</span><span class="p">(</span><span class="s">"Set timer interval to %lu</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> |
| <span class="w"> </span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">long</span><span class="p">)</span><span class="n">CONFIG_EXAMPLES_TIMER_INTERVAL</span><span class="p">);</span> |
| |
| <span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ioctl</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span><span class="w"> </span><span class="n">TCIOC_SETTIMEOUT</span><span class="p">,</span><span class="w"> </span><span class="n">CONFIG_EXAMPLES_TIMER_INTERVAL</span><span class="p">);</span> |
| <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ret</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"ERROR: Failed to set the timer interval: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">);</span> |
| <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">EXIT_FAILURE</span><span class="p">;</span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| <dl class="c macro"> |
| <dt class="sig sig-object c" id="c.TCIOC_NOTIFICATION"> |
| <span class="sig-name descname"><span class="n"><span class="pre">TCIOC_NOTIFICATION</span></span></span><a class="headerlink" href="#c.TCIOC_NOTIFICATION" title="Permalink to this definition"></a><br /></dt> |
| <dd></dd></dl> |
| |
| <p>The <code class="docutils literal notranslate"><span class="pre">TCIOC_NOTIFICATION</span></code> is used to configure the timer callback to notify the |
| application via a signal when the timer expires. This command calls the <code class="docutils literal notranslate"><span class="pre">setcallback</span></code> |
| operation. Which will not be described here, since the application does not set a |
| callback directly. Instead, the user should configure a signal handler to catch |
| notifications, and then, configure a timer notifier to notify and to signal the |
| previously configured signal handler. For a better performance, a separate pthread |
| may be configured to wait on sigwaitinfo() for timer events.</p> |
| <p>In any case, this command expects a read-only pointer to a struct <cite>timer_notify_s</cite>. |
| This struct contains 2 fields: <code class="docutils literal notranslate"><span class="pre">pid</span></code> (<code class="docutils literal notranslate"><span class="pre">pid_t</span></code>), that indicates the ID of the |
| task/thread to receive the signal and <code class="docutils literal notranslate"><span class="pre">event</span></code> (<code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">sigevent</span></code>), which |
| describes the way a task will be notified.</p> |
| <p>This command may be used like so:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">printf</span><span class="p">(</span><span class="s">"Configure the notification</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> |
| |
| <span class="n">notify</span><span class="p">.</span><span class="n">pid</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">getpid</span><span class="p">();</span> |
| <span class="n">notify</span><span class="p">.</span><span class="n">event</span><span class="p">.</span><span class="n">sigev_notify</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">SIGEV_SIGNAL</span><span class="p">;</span> |
| <span class="n">notify</span><span class="p">.</span><span class="n">event</span><span class="p">.</span><span class="n">sigev_signo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">CONFIG_EXAMPLES_TIMER_SIGNO</span><span class="p">;</span> |
| <span class="n">notify</span><span class="p">.</span><span class="n">event</span><span class="p">.</span><span class="n">sigev_value</span><span class="p">.</span><span class="n">sival_ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span> |
| |
| <span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ioctl</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span><span class="w"> </span><span class="n">TCIOC_NOTIFICATION</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="kt">unsigned</span><span class="w"> </span><span class="kt">long</span><span class="p">)((</span><span class="kt">uintptr_t</span><span class="p">)</span><span class="o">&</span><span class="n">notify</span><span class="p">));</span> |
| <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ret</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"ERROR: Failed to set the timer handler: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">);</span> |
| <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">EXIT_FAILURE</span><span class="p">;</span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| <dl class="c macro"> |
| <dt class="sig sig-object c" id="c.TCIOC_MAXTIMEOUT"> |
| <span class="sig-name descname"><span class="n"><span class="pre">TCIOC_MAXTIMEOUT</span></span></span><a class="headerlink" href="#c.TCIOC_MAXTIMEOUT" title="Permalink to this definition"></a><br /></dt> |
| <dd></dd></dl> |
| |
| <p>The <code class="docutils literal notranslate"><span class="pre">TCIOC_MAXTIMEOUT</span></code> command calls the <code class="docutils literal notranslate"><span class="pre">maxtimeout</span></code> operation, which is described below.</p> |
| <dl class="c function"> |
| <dt class="sig sig-object c" id="c.maxtimeout"> |
| <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">maxtimeout</span></span></span><span class="sig-paren">(</span><span class="n"><span class="pre">uint32_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">status</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.maxtimeout" title="Permalink to this definition"></a><br /></dt> |
| <dd><p>The maxtimeout operation gets the maximum timeout value that can be configured.</p> |
| <dl class="field-list simple"> |
| <dt class="field-odd">Parameters<span class="colon">:</span></dt> |
| <dd class="field-odd"><ul class="simple"> |
| <li><p><strong>maxtimeout</strong> – A writable pointer to a variable of <code class="docutils literal notranslate"><span class="pre">uint32_t</span></code> type in |
| which the value will be stored.</p></li> |
| </ul> |
| </dd> |
| <dt class="field-even">Returns<span class="colon">:</span></dt> |
| <dd class="field-even"><p>A Linux System Error Code for failing or 0 for success.</p> |
| </dd> |
| </dl> |
| </dd></dl> |
| |
| <p>This command may be used like so:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cm">/* Get the maximum timer timeout */</span> |
| |
| <span class="n">printf</span><span class="p">(</span><span class="s">"Get the maximum timer timeout</span><span class="se">\n</span><span class="s">"</span><span class="p">);</span> |
| |
| <span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ioctl</span><span class="p">(</span><span class="n">fd</span><span class="p">,</span><span class="w"> </span><span class="n">TCIOC_MAXTIMEOUT</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="kt">uint32_t</span><span class="o">*</span><span class="p">)(</span><span class="o">&</span><span class="n">max_timeout</span><span class="p">));</span> |
| <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ret</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="w"> </span><span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span><span class="w"> </span><span class="s">"ERROR: Failed to reat the timer's maximum timeout: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">errno</span><span class="p">);</span> |
| <span class="w"> </span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">);</span> |
| <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">EXIT_FAILURE</span><span class="p">;</span> |
| <span class="w"> </span><span class="p">}</span> |
| |
| <span class="cm">/* Print the maximum supported timeout */</span> |
| |
| <span class="n">printf</span><span class="p">(</span><span class="s">"Maximum supported timeout: %"</span><span class="w"> </span><span class="n">PRIu32</span><span class="w"> </span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">max_timeout</span><span class="p">);</span> |
| </pre></div> |
| </div> |
| <p>Those snippets were taken from the Example which provides a great resource to |
| demonstrate how to use those <code class="docutils literal notranslate"><span class="pre">ioctl</span></code> commands.</p> |
| </section> |
| </section> |
| |
| |
| </div> |
| </div> |
| <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer"> |
| <a href="index.html" class="btn btn-neutral float-left" title="Timers Drivers" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> |
| <a href="pwm.html" class="btn btn-neutral float-right" title="PWM Drivers" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> |
| </div> |
| |
| <hr/> |
| |
| <div role="contentinfo"> |
| <p>© Copyright 2023, The Apache Software Foundation.</p> |
| </div> |
| |
| |
| |
| </footer> |
| </div> |
| </div> |
| </section> |
| </div> |
| <script> |
| jQuery(function () { |
| SphinxRtdTheme.Navigation.enable(true); |
| }); |
| </script> |
| |
| </body> |
| </html> |