blob: a503de85111d1674d35e0456cdb7bdfc14738bec [file] [log] [blame]
<!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>Sanity &mdash; 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="System Modules" href="../../modules/system_modules.html"/>
<link rel="prev" title="OS Time" href="../time/os_time.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.11.0, Apache NimBLE 1.6.0 </a> released September 7, 2023)
</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> /
Sanity
<div class="sourcelink">
<a href="https://github.com/apache/mynewt-core/edit/master/docs/os/core_os/sanity/sanity.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_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" selected="selected" >
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" >
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 &amp; 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"><a class="reference internal" href="../time/os_time.html">OS Time</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">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/baselibc.html">Baselibc</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/drivers/driver.html">Drivers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/devmgmt/newtmgr.html">Device Management with Newt Manager</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/mcumgr/mcumgr.html">Device Management with MCUmgr</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/imgmgr/imgmgr.html">Image Manager</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/fs/fs.html">File System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/fcb/fcb.html">Flash Circular Buffer</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../modules/sensor_framework/sensor_framework.html">Sensor Framework</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/mfg/mfg.html">Manufacturing support</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.8.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="sanity">
<h1>Sanity<a class="headerlink" href="#sanity" title="Permalink to this headline"></a></h1>
<p>The Sanity task is a software watchdog task, which runs periodically to
check system state, and ensure that everything is still operating
properly.</p>
<p>In a typical system design, there are multiple stages of watchdog:</p>
<ul class="simple">
<li><p>Internal Watchdog</p></li>
<li><p>External Watchdog</p></li>
<li><p>Sanity Watchdog</p></li>
</ul>
<p>The <em>Internal Watchdog</em> is typically an MCU watchdog, which is tickled
in the core of the OS. The internal watchdog is tickled frequently, and
is meant to be an indicator the OS is running.</p>
<p>The <em>External Watchdog</em> is a watchdog that’s typically run slower. The
purpose of an external watchdog is to provide the system with a hard
reset when it has lost its mind.</p>
<p>The <em>Sanity Watchdog</em> is the least frequently run watchdog, and is meant
as an application watchdog.</p>
<p>This document is about the operation of the Mynewt Sanity Watchdog.</p>
<div class="section" id="description">
<h2>Description<a class="headerlink" href="#description" title="Permalink to this headline"></a></h2>
</div>
<div class="section" id="sanity-task">
<h2>Sanity Task<a class="headerlink" href="#sanity-task" title="Permalink to this headline"></a></h2>
<p>Mynewt OS uses the OS Idle task to check sanity. The <code class="xref c c-macro docutils literal notranslate"><span class="pre">SANITY_INTERVAL</span></code>
syscfg setting specifies the interval in seconds to perform the sanity
checks.</p>
<p>By default, every operating system task provides the frequency it will
check in with the sanity task, with the <code class="docutils literal notranslate"><span class="pre">sanity_itvl</span></code> parameter in the
c:func:<cite>os_task_init()</cite> function:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="nf">os_task_init</span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">os_task</span><span class="w"> </span><span class="o">*</span><span class="n">t</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">os_task_func_t</span><span class="w"> </span><span class="n">func</span><span class="p">,</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="kt">uint8_t</span><span class="w"> </span><span class="n">prio</span><span class="p">,</span><span class="w"> </span><span class="n">os_time_t</span><span class="w"> </span><span class="n">sanity_itvl</span><span class="p">,</span><span class="w"> </span><span class="n">os_stack_t</span><span class="w"> </span><span class="o">*</span><span class="n">bottom</span><span class="p">,</span>
<span class="w"> </span><span class="kt">uint16_t</span><span class="w"> </span><span class="n">stack_size</span><span class="p">);</span>
</pre></div>
</div>
<p>c:var:<cite>sanity_itvl</cite> is the time in OS time ticks that the task being created
must register in with the sanity task.</p>
</div>
<div class="section" id="checking-in-with-sanity-task">
<h2>Checking in with Sanity Task<a class="headerlink" href="#checking-in-with-sanity-task" title="Permalink to this headline"></a></h2>
<p>The task must then register in with the sanity task every
<code class="docutils literal notranslate"><span class="pre">sanity_itvl</span></code> seconds. In order to do that, the task should call the
<a class="reference internal" href="#c.os_sanity_task_checkin" title="os_sanity_task_checkin"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_sanity_task_checkin()</span></code></a> function, which will reset the sanity check
associated with this task. Here is an example of a task that uses a
callout to checkin with the sanity task every 50 seconds:</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#define TASK1_SANITY_CHECKIN_ITVL (50 * OS_TICKS_PER_SEC)</span>
<span class="k">struct</span><span class="w"> </span><span class="nc">os_eventq</span><span class="w"> </span><span class="n">task1_evq</span><span class="p">;</span>
<span class="k">static</span><span class="w"> </span><span class="kt">void</span>
<span class="nf">task1</span><span class="p">(</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="p">{</span>
<span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_task</span><span class="w"> </span><span class="o">*</span><span class="n">t</span><span class="p">;</span>
<span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_event</span><span class="w"> </span><span class="o">*</span><span class="n">ev</span><span class="p">;</span>
<span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_callout</span><span class="w"> </span><span class="n">c</span><span class="p">;</span>
<span class="w"> </span><span class="cm">/* Get current OS task */</span>
<span class="w"> </span><span class="n">t</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">os_sched_get_current_task</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/* Initialize the event queue. */</span>
<span class="w"> </span><span class="n">os_eventq_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task1_evq</span><span class="p">);</span>
<span class="w"> </span><span class="cm">/* Initialize the callout */</span>
<span class="w"> </span><span class="n">os_callout_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">task1_evq</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span>
<span class="w"> </span><span class="cm">/* reset the callout to checkin with the sanity task</span>
<span class="cm"> * in 50 seconds to kick off timing.</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="n">os_callout_reset</span><span class="p">(</span><span class="o">&amp;</span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="n">TASK1_SANITY_CHECKIN_ITVL</span><span class="p">);</span>
<span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">ev</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">os_eventq_get</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task1_evq</span><span class="p">);</span>
<span class="w"> </span><span class="cm">/* The sanity timer has reset */</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">ev</span><span class="o">-&gt;</span><span class="n">ev_arg</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="o">&amp;</span><span class="n">c</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">os_sanity_task_checkin</span><span class="p">(</span><span class="n">t</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="cm">/* not expecting any other events */</span>
<span class="w"> </span><span class="n">assert</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="cm">/* Should never reach */</span>
<span class="w"> </span><span class="n">assert</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="registering-a-custom-sanity-check">
<h2>Registering a Custom Sanity Check<a class="headerlink" href="#registering-a-custom-sanity-check" title="Permalink to this headline"></a></h2>
<p>If a particular task wants to further hook into the sanity framework to
perform other checks during the sanity task’s operation, it can do so by
registering a <code class="xref c c-type docutils literal notranslate"><span class="pre">struct</span> <span class="pre">os_sanity_check</span></code> using the
<a class="reference internal" href="#c.os_sanity_check_register" title="os_sanity_check_register"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_sanity_check_register()</span></code></a> function.</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="kt">int</span>
<span class="nf">mymodule_perform_sanity_check</span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">os_sanity_check</span><span class="w"> </span><span class="o">*</span><span class="n">sc</span><span class="p">,</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="p">{</span>
<span class="w"> </span><span class="cm">/* Perform your checking here. In this case, we check if there</span>
<span class="cm"> * are available buffers in mymodule, and return 0 (all good)</span>
<span class="cm"> * if true, and -1 (error) if not.</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">mymodule_has_buffers</span><span class="p">())</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="mi">-1</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
<span class="k">static</span><span class="w"> </span><span class="kt">int</span>
<span class="nf">mymodule_register_sanity_check</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_sanity_check</span><span class="w"> </span><span class="n">sc</span><span class="p">;</span>
<span class="w"> </span><span class="n">os_sanity_check_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sc</span><span class="p">);</span>
<span class="w"> </span><span class="cm">/* Only assert() if mymodule_perform_sanity_check() fails 50</span>
<span class="cm"> * times. SANITY_TASK_INTERVAL is defined by the user, and</span>
<span class="cm"> * is the frequency at which the sanity_task runs in seconds.</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="n">OS_SANITY_CHECK_SETFUNC</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sc</span><span class="p">,</span><span class="w"> </span><span class="n">mymodule_perform_sanity_check</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span>
<span class="w"> </span><span class="mi">50</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">SANITY_TASK_INTERVAL</span><span class="p">);</span>
<span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">os_sanity_check_register</span><span class="p">(</span><span class="o">&amp;</span><span class="n">sc</span><span class="p">);</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">rc</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="k">goto</span><span class="w"> </span><span class="n">err</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
<span class="nl">err</span><span class="p">:</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="p">(</span><span class="n">rc</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</div>
<p>In the above example, every time the custom sanity check
<code class="docutils literal notranslate"><span class="pre">mymodule_perform_sanity_check</span></code> returns successfully (0), the sanity
check is reset. In the c:macro:<cite>OS_SANITY_CHECK_SETFUNC</cite> macro, the sanity
checkin interval is specified as 50 * <code class="xref c c-macro docutils literal notranslate"><span class="pre">SANITY_TASK_INTERVAL</span></code> (which is
the interval at which the sanity task runs.) This means that the
<code class="docutils literal notranslate"><span class="pre">mymodule_perform_sanity_check()</span></code> function needs to fail 50 times
consecutively before the sanity task will crash the system.</p>
<p><strong>TIP:</strong> When checking things like memory buffers, which can be
temporarily be exhausted, it’s a good idea to have the sanity check fail
multiple consecutive times before crashing the system. This will avoid
crashing for temporary failures.</p>
</div>
<div class="section" id="api">
<h2>API<a class="headerlink" href="#api" title="Permalink to this headline"></a></h2>
<dl class="c type">
<dt id="c.os_sanity_check_func_t">
<span class="target" id="group___o_s_sanity_1ga354458457ad42d0bab3d8d08de482fc9"></span><em class="property"><span class="pre">typedef</span> </em><span class="pre">int</span> <span class="pre">(</span><span class="pre">*</span><code class="sig-name descname"><span class="pre">os_sanity_check_func_t</span></code><span class="pre">)</span><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_sanity_check" title="os_sanity_check"><span class="pre">os_sanity_check</span></a><span class="pre">*</span>, <span class="pre">void</span><span class="pre">*</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_sanity_check_func_t" title="Permalink to this definition"></a><br /></dt>
<dd></dd></dl>
<dl class="c function">
<dt id="c.os_sanity_task_checkin">
<span class="target" id="group___o_s_sanity_1ga048cde3537cb470594fc2528201572ba"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_sanity_task_checkin</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="../task/task.html#c.os_task" title="os_task"><span class="pre">os_task</span></a><span class="pre">*</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_sanity_task_checkin" title="Permalink to this definition"></a><br /></dt>
<dd><p>Provide a “task checkin” for the sanity task. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>0 on success, error code on failure </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">t</span></code>: The task to check in</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_sanity_check_init">
<span class="target" id="group___o_s_sanity_1ga34eb185813afec28e2d61059e2fdd064"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_sanity_check_init</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_sanity_check" title="os_sanity_check"><span class="pre">os_sanity_check</span></a><span class="pre">*</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_sanity_check_init" title="Permalink to this definition"></a><br /></dt>
<dd><p>Initialize a sanity check. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>0 on success, error code on failure. </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">sc</span></code>: The sanity check to initialize</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_sanity_check_register">
<span class="target" id="group___o_s_sanity_1ga2c5ad3969bf12870a0adfa7b9a8a8611"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_sanity_check_register</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_sanity_check" title="os_sanity_check"><span class="pre">os_sanity_check</span></a><span class="pre">*</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_sanity_check_register" title="Permalink to this definition"></a><br /></dt>
<dd><p>Register a sanity check. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>0 on success, error code on failure </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">sc</span></code>: The sanity check to register</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c function">
<dt id="c.os_sanity_check_reset">
<span class="target" id="group___o_s_sanity_1ga92ea98a26001d84aee06d600c62b7140"></span><span class="pre">int</span> <code class="sig-name descname"><span class="pre">os_sanity_check_reset</span></code><span class="sig-paren">(</span><em class="property"><span class="pre">struct</span></em> <a class="reference internal" href="#c.os_sanity_check" title="os_sanity_check"><span class="pre">os_sanity_check</span></a><span class="pre">*</span><span class="sig-paren">)</span><a class="headerlink" href="#c.os_sanity_check_reset" title="Permalink to this definition"></a><br /></dt>
<dd><p>Reset the os sanity check, so that it doesn’t trip up the sanity timer. </p>
<p><dl class="simple">
<dt><strong>Return</strong></dt><dd><p>0 on success, error code on failure </p>
</dd>
<dt><strong>Parameters</strong></dt><dd><ul class="breatheparameterlist simple">
<li><p><code class="docutils literal notranslate"><span class="pre">sc</span></code>: The sanity check to reset</p></li>
</ul>
</dd>
</dl>
</p>
</dd></dl>
<dl class="c macro">
<dt id="c.OS_SANITY_CHECK_SETFUNC">
<span class="target" id="group___o_s_sanity_1ga53501a44869b9cda63c92f031d8a46c5"></span><code class="sig-name descname"><span class="pre">OS_SANITY_CHECK_SETFUNC</span></code><span class="sig-paren">(</span><em><span class="pre">__sc</span></em>, <em><span class="pre">__f</span></em>, <em><span class="pre">__arg</span></em>, <em><span class="pre">__itvl</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.OS_SANITY_CHECK_SETFUNC" title="Permalink to this definition"></a><br /></dt>
<dd></dd></dl>
<dl class="c struct">
<dt id="c.os_sanity_check">
<span class="target" id="structos__sanity__check"></span><em class="property"><span class="pre">struct</span> </em><code class="sig-name descname"><span class="pre">os_sanity_check</span></code><a class="headerlink" href="#c.os_sanity_check" title="Permalink to this definition"></a><br /></dt>
<dd><em>#include &lt;os_sanity.h&gt;</em><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_sanity_check.sc_checkin_last">
<span class="target" id="structos__sanity__check_1a7701ac67d9e7ba081cef9a6540a35003"></span><a class="reference internal" href="../time/os_time.html#c.os_time_t" title="os_time_t"><span class="pre">os_time_t</span></a> <code class="sig-name descname"><span class="pre">sc_checkin_last</span></code><a class="headerlink" href="#c.os_sanity_check.sc_checkin_last" title="Permalink to this definition"></a><br /></dt>
<dd><p>Time this check last ran successfully. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_sanity_check.sc_checkin_itvl">
<span class="target" id="structos__sanity__check_1ad9b79d0e7c0dcc9fcbfe57d2b7d43c53"></span><a class="reference internal" href="../time/os_time.html#c.os_time_t" title="os_time_t"><span class="pre">os_time_t</span></a> <code class="sig-name descname"><span class="pre">sc_checkin_itvl</span></code><a class="headerlink" href="#c.os_sanity_check.sc_checkin_itvl" title="Permalink to this definition"></a><br /></dt>
<dd><p>Interval this task should check in at. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_sanity_check.sc_func">
<span class="target" id="structos__sanity__check_1ab5be2cbf4891bc9f42f25b7f4cfb9b45"></span><a class="reference internal" href="#c.os_sanity_check_func_t" title="os_sanity_check_func_t"><span class="pre">os_sanity_check_func_t</span></a> <code class="sig-name descname"><span class="pre">sc_func</span></code><a class="headerlink" href="#c.os_sanity_check.sc_func" title="Permalink to this definition"></a><br /></dt>
<dd><p>Sanity check to run. </p>
</dd></dl>
<dl class="c var">
<dt id="c.os_sanity_check.sc_arg">
<span class="target" id="structos__sanity__check_1a5b22c20409427a0561fb2418a251706a"></span><span class="pre">void</span> <span class="pre">*</span><code class="sig-name descname"><span class="pre">sc_arg</span></code><a class="headerlink" href="#c.os_sanity_check.sc_arg" title="Permalink to this definition"></a><br /></dt>
<dd><p>Argument to pass to sanity check. </p>
</dd></dl>
</div>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="rst-footer-buttons row" role="navigation" aria-label="footer navigation">
<a href="../../modules/system_modules.html" class="btn btn-neutral float-right" title="System Modules" accesskey="n">Next: System Modules <span class="fa fa-arrow-circle-right"></span></a>
<a href="../time/os_time.html" class="btn btn-neutral" title="OS Time" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous: OS 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>