blob: 9104e7559121114f5aa64edcb7f4b3507162e277 [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>Apache Mynewt Operating System Kernel &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="OS User Guide" href="../os_user_guide.html"/>
<link rel="next" title="Scheduler" href="context_switch/context_switch.html"/>
<link rel="prev" title="OS User Guide" href="../os_user_guide.html"/>
<script src="../../_static/js/modernizr.min.js"></script>
<script>
(function(i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, "script", "//www.google-analytics.com/analytics.js", "ga");
ga("create", "UA-72162311-1", "auto");
ga("send", "pageview");
</script>
</head>
<body class="not-front page-documentation" role="document" >
<div id="wrapper">
<div class="container">
<div id="banner" class="row v2-main-banner">
<a class="logo-cell" href="/">
<img class="logo" src="../../_static/img/logo.png">
</a>
<div class="tagline-cell">
<h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4>
</div>
<div class="news-cell">
<div class="well">
<h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.12.0, Apache NimBLE 1.7.0 </a> released April 4, 2024)
</div>
</div>
</div>
</div>
<header>
<nav id="navbar" class="navbar navbar-inverse" role="navigation">
<div class="container">
<!-- Collapsed navigation -->
<div class="navbar-header">
<!-- Expander button -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Expanded navigation -->
<div class="navbar-collapse collapse">
<!-- Main navigation -->
<ul class="nav navbar-nav navbar-right">
<li>
<a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a>
</li>
<li class="important">
<a href="/quick-start/">Quick Start</a>
</li>
<li>
<a href="/about/">About</a>
</li>
<li>
<a href="/talks/">Talks</a>
</li>
<li class="active">
<a href="/documentation/">Documentation</a>
</li>
<li>
<a href="/download/">Download</a>
</li>
<li>
<a href="/community/">Community</a>
</li>
<li>
<a href="/events/">Events</a>
</li>
</ul>
<!-- Search, Navigation and Repo links -->
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
</div>
</nav>
</header>
<!-- STARTS MAIN CONTENT -->
<div id="main-content">
<div id="breadcrumb">
<div class="container">
<a href="/documentation/">Docs</a> /
<a href="../os_user_guide.html">OS User Guide</a> /
Apache Mynewt Operating System Kernel
<div class="sourcelink">
<a href="https://github.com/apache/mynewt-core/edit/master/docs/os/core_os/mynewt_os.rst" class="icon icon-github"
rel="nofollow"> Edit on GitHub</a>
</div>
</div>
</div>
<!-- STARTS CONTAINER -->
<div class="container">
<!-- STARTS .content -->
<div id="content" class="row">
<!-- STARTS .container-sidebar -->
<div class="container-sidebar col-xs-12 col-sm-3">
<div id="docSidebar" class="sticky-container">
<div role="search" class="sphinx-search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search documentation" class="search-documentation" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<!-- Note: only works when deployed -->
<select class="form-control" onchange="if (this.value) window.location.href=this.value">
<option value="/latest" selected>
Version: latest
</option>
<option value="/v1_12_0" >
Version: 1.12.0
</option>
<option value="/v1_11_0" >
Version: 1.11.0
</option>
<option value="/v1_10_0" >
Version: 1.10.0
</option>
<option value="/v1_9_0" >
Version: 1.9.0
</option>
<option value="/v1_8_0" >
Version: 1.8.0
</option>
<option value="/v1_7_0" selected="selected" >
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="current reference internal" href="#">Kernel</a><ul>
<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"><a class="reference internal" href="sanity/sanity.html">Sanity</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../modules/system_modules.html">System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../modules/hal/hal.html">Hardware Abstraction</a></li>
<li class="toctree-l2"><a class="reference internal" href="../modules/bootloader/bootloader.html">Secure Bootloader</a></li>
<li class="toctree-l2"><a class="reference internal" href="../modules/split/split.html">Split Images</a></li>
<li class="toctree-l2"><a class="reference internal" href="porting/port_os.html">Porting Guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../modules/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.7.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="apache-mynewt-operating-system-kernel">
<h1>Apache Mynewt Operating System Kernel<a class="headerlink" href="#apache-mynewt-operating-system-kernel" title="Permalink to this headline"></a></h1>
<div class="toctree-wrapper compound">
</div>
<p>The Mynewt Core OS is a multitasking, preemptive real-time operating
system combining a scheduler with typical RTOS features such as mutexes,
semaphores, memory pools, etc. The Mynewt Core OS also provides a number
of useful utilities such as a task watchdog, networking stack memory
buffers and time management API. Each of these features is described in
detail in its own section of the manual.</p>
<p>A multitasking, preemptive operating system is one in which a number of
different tasks can be instantiated and assigned a priority, with higher
priority tasks running before lower priority tasks. Furthermore, if a
lower priority task is running and a higher priority task wants to run,
the lower priority task is halted and the higher priority task is
allowed to run. In other words, the lower priority task is preempted by
the higher priority task.</p>
<div class="section" id="why-use-an-os">
<h2>Why use an OS?<a class="headerlink" href="#why-use-an-os" title="Permalink to this headline"></a></h2>
<p>You may ask yourself “why do I need a multitasking preemptive OS”? The
answer may indeed be that you do not. Some applications are simple and
only require a polling loop. Others are more complex and may require
that certain jobs are executed in a timely manner or before other jobs
are executed. If you have a simple polling loop, you cannot move on to
service a job until the current job is done being serviced. With the
Mynewt OS, the application developer need not worry about certain jobs
taking too long or not executing in a timely fashion; the OS provides
mechanisms to deal with these situations. Another benefit of using an OS
is that it helps shield application developers from other application
code being written; the developer does not have to worry (or has to
worry less) about other application code behaving badly and causing
undesirable behavior or preventing their code from executing properly.
Other benefits of using an OS (and the Mynewt OS in particular) is that
it also provides features that the developer would otherwise need to
create on his/her own.</p>
</div>
<div class="section" id="core-os-features">
<h2>Core OS Features<a class="headerlink" href="#core-os-features" title="Permalink to this headline"></a></h2>
<ul class="simple">
<li><p><a class="reference internal" href="context_switch/context_switch.html"><span class="doc">Scheduler/context switching</span></a></p></li>
<li><p><a class="reference internal" href="time/os_time.html"><span class="doc">Time</span></a></p></li>
<li><p><a class="reference internal" href="task/task.html"><span class="doc">Tasks</span></a></p></li>
<li><p><a class="reference internal" href="event_queue/event_queue.html"><span class="doc">Event queues/callouts</span></a></p></li>
<li><p><a class="reference internal" href="semaphore/semaphore.html"><span class="doc">Semaphores</span></a></p></li>
<li><p><a class="reference internal" href="mutex/mutex.html"><span class="doc">Mutexes</span></a></p></li>
<li><p><a class="reference internal" href="memory_pool/memory_pool.html"><span class="doc">Memory pools</span></a></p></li>
<li><p><a class="reference internal" href="heap/heap.html"><span class="doc">Heap</span></a></p></li>
<li><p><a class="reference internal" href="mbuf/mbuf.html"><span class="doc">Mbufs</span></a></p></li>
<li><p><a class="reference internal" href="sanity/sanity.html"><span class="doc">Sanity</span></a></p></li>
<li><p><a class="reference internal" href="callout/callout.html"><span class="doc">Callouts</span></a></p></li>
<li><p><a class="reference internal" href="porting/port_os.html"><span class="doc">Porting OS to other platforms</span></a></p></li>
</ul>
</div>
<div class="section" id="basic-os-application-creation">
<h2>Basic OS Application Creation<a class="headerlink" href="#basic-os-application-creation" title="Permalink to this headline"></a></h2>
<p>Creating an application using the Mynewt Core OS is a relatively simple
task. The main steps are:</p>
<ol class="arabic simple">
<li><p>Install the basic Newt Tool structure (build structure) for your
application.</p></li>
<li><p>Create your BSP (Board Support Package).</p></li>
<li><p>In your application <code class="docutils literal notranslate"><span class="pre">main()</span></code> function, call the <code class="docutils literal notranslate"><span class="pre">sysinit()</span></code>
function to initialize the system and packages, perform application
specific initialization, then wait and dispatch events from the OS
default event queue in an infinite loop. (See <a class="reference internal" href="../modules/sysinitconfig/sysinitconfig.html"><span class="doc">Compile-Time Configuration and Initialization</span></a>
for more details.)</p></li>
</ol>
<p>Initializing application modules and tasks can get somewhat complicated
with RTOS’s similar to Mynewt. Care must be taken that the API provided
by a task are initialized prior to being called by another (higher
priority) task.</p>
<p>For example, take a simple application with two tasks (tasks 1 and 2,
with task 1 higher priority than task 2). Task 2 provides an API which
has a semaphore lock and this semaphore is initialized by task 2 when
the task handler for task 2 is called. Task 1 is expected to call this
API.</p>
<p>Consider the sequence of events when the OS is started. The scheduler
starts running and picks the highest priority task (task 1 in this
case). The task handler function for task 1 is called and will keep
running until it yields execution. Before yielding, code in the task 1
handler function calls the API provided by task 2. The semaphore being
accessed in the task 2 API has yet to be initialized since the task 2
handler function has not had a chance to run! This will lead to
undesirable behavior and will need to be addressed by the application
developer. Note that the Mynewt OS does guard against internal API being
called before the OS has started (they will return error) but it does
not safeguard application defined objects from access prior to
initialization.</p>
</div>
<div class="section" id="example">
<h2>Example<a class="headerlink" href="#example" title="Permalink to this headline"></a></h2>
<p>One way to avoid initialization issues like the one described above is
for the application to initialize the objects that are accessed by
multiple tasks before it initializes the tasks with the OS.</p>
<p>The code example shown below illustrates this concept. The application
initializes system and packages, calls an application specific “task
initialization” function, and dispatches events from the default event
queue. The application task initialization function is responsible for
initializing all the data objects that each task exposes to the other
tasks. The tasks themselves are also initialized at this time (by
calling <a class="reference internal" href="task/task.html#c.os_task_init" title="os_task_init"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_task_init()</span></code></a>).</p>
<p>In the example, each task works in a ping-pong like fashion: task 1
wakes up, adds a token to semaphore 1 and then waits for a token from
semaphore 2. Task 2 waits for a token on semaphore 1 and once it gets
it, adds a token to semaphore 2. Notice that the semaphores are
initialized by the application specific task initialization functions
and not inside the task handler functions. If task 2 (being lower in
priority than task 1) had called <a class="reference internal" href="semaphore/semaphore.html#c.os_sem_init" title="os_sem_init"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_sem_init()</span></code></a> for task2_sem inside
task2_handler(), task 1 would have called <a class="reference internal" href="semaphore/semaphore.html#c.os_sem_pend" title="os_sem_pend"><code class="xref c c-func docutils literal notranslate"><span class="pre">os_sem_pend()</span></code></a> using
task2_sem before task2_sem was initialized.</p>
<div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_sem</span><span class="w"> </span><span class="n">task1_sem</span><span class="p">;</span>
<span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">os_sem</span><span class="w"> </span><span class="n">task2_sem</span><span class="p">;</span>
<span class="w"> </span><span class="cm">/* Task 1 handler function */</span>
<span class="w"> </span><span class="kt">void</span>
<span class="w"> </span><span class="nf">task1_handler</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="w"> </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="cm">/* Release semaphore to task 2 */</span>
<span class="w"> </span><span class="n">os_sem_release</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task1_sem</span><span class="p">);</span>
<span class="w"> </span><span class="cm">/* Wait for semaphore from task 2 */</span>
<span class="w"> </span><span class="n">os_sem_pend</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task2_sem</span><span class="p">,</span><span class="w"> </span><span class="n">OS_TIMEOUT_NEVER</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">/* Task 2 handler function */</span>
<span class="w"> </span><span class="kt">void</span>
<span class="w"> </span><span class="nf">task2_handler</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="w"> </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">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="cm">/* Wait for semaphore from task1 */</span>
<span class="w"> </span><span class="n">os_sem_pend</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task1_sem</span><span class="p">,</span><span class="w"> </span><span class="n">OS_TIMEOUT_NEVER</span><span class="p">);</span>
<span class="w"> </span><span class="cm">/* Release task2 semaphore */</span>
<span class="w"> </span><span class="n">os_sem_release</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task2_sem</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">/* Initialize task 1 exposed data objects */</span>
<span class="w"> </span><span class="kt">void</span>
<span class="w"> </span><span class="nf">task1_init</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="cm">/* Initialize task1 semaphore */</span>
<span class="w"> </span><span class="n">os_sem_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task1_sem</span><span class="p">,</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="cm">/* Initialize task 2 exposed data objects */</span>
<span class="w"> </span><span class="kt">void</span>
<span class="w"> </span><span class="nf">task2_init</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="cm">/* Initialize task1 semaphore */</span>
<span class="w"> </span><span class="n">os_sem_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task2_sem</span><span class="p">,</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="cm">/**</span>
<span class="cm"> * init_app_tasks</span>
<span class="cm"> *</span>
<span class="cm"> * This function performs initializations that are required before tasks run.</span>
<span class="cm"> *</span>
<span class="cm"> * @return int 0 success; error otherwise.</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">int</span>
<span class="w"> </span><span class="nf">init_app_tasks</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="cm">/*</span>
<span class="cm"> * Call task specific initialization functions to initialize any shared objects</span>
<span class="cm"> * before initializing the tasks with the OS.</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="n">task1_init</span><span class="p">();</span>
<span class="w"> </span><span class="n">task2_init</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/*</span>
<span class="cm"> * Initialize tasks 1 and 2 with the OS.</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="n">os_task_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task1</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;task1&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">task1_handler</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="n">TASK1_PRIO</span><span class="p">,</span>
<span class="w"> </span><span class="n">OS_WAIT_FOREVER</span><span class="p">,</span><span class="w"> </span><span class="n">task1_stack</span><span class="p">,</span><span class="w"> </span><span class="n">TASK1_STACK_SIZE</span><span class="p">);</span>
<span class="w"> </span><span class="n">os_task_init</span><span class="p">(</span><span class="o">&amp;</span><span class="n">task2</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;task2&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">task2_handler</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="n">TASK2_PRIO</span><span class="p">,</span>
<span class="w"> </span><span class="n">OS_WAIT_FOREVER</span><span class="p">,</span><span class="w"> </span><span class="n">task2_stack</span><span class="p">,</span><span class="w"> </span><span class="n">TASK2_STACK_SIZE</span><span class="p">);</span>
<span class="w"> </span><span class="k">return</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="cm">/**</span>
<span class="cm"> * main</span>
<span class="cm"> *</span>
<span class="cm"> * The main function for the application. This function initializes the system and packages,</span>
<span class="cm"> * calls the application specific task initialization function, then waits and dispatches</span>
<span class="cm"> * events from the OS default event queue in an infinite loop.</span>
<span class="cm"> */</span>
<span class="w"> </span><span class="kt">int</span>
<span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</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">arg</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="cm">/* Perform system and package initialization */</span>
<span class="w"> </span><span class="n">sysinit</span><span class="p">();</span>
<span class="w"> </span><span class="cm">/* Initialize application specific tasks */</span>
<span class="w"> </span><span class="n">init_app_tasks</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">os_eventq_run</span><span class="p">(</span><span class="n">os_eventq_dflt_get</span><span class="p">());</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="cm">/* main never returns */</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="rst-footer-buttons row" role="navigation" aria-label="footer navigation">
<a href="context_switch/context_switch.html" class="btn btn-neutral float-right" title="Scheduler" accesskey="n">Next: Scheduler <span class="fa fa-arrow-circle-right"></span></a>
<a href="../os_user_guide.html" class="btn btn-neutral" title="OS User Guide" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous: OS User Guide</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>