<trclass="memdesc:ga22f7d235bc9f783933bd5a981fd79696"><tdclass="mdescLeft"> </td><tdclass="mdescRight">main thread 1=main can be thread, 0=not available <ahref="#ga22f7d235bc9f783933bd5a981fd79696">More...</a><br/></td></tr>
<trclass="memdesc:gab78dce646fabec479c5f34bc5175b7de"><tdclass="mdescLeft"> </td><tdclass="mdescRight">RTOS identification and version (main [31:16] .sub [15:0]) <ahref="#gab78dce646fabec479c5f34bc5175b7de">More...</a><br/></td></tr>
<trclass="memdesc:ga9e0954d52722673e2031233a2ab99960"><tdclass="mdescLeft"> </td><tdclass="mdescRight">The RTOS kernel system timer frequency in Hz. <ahref="#ga9e0954d52722673e2031233a2ab99960">More...</a><br/></td></tr>
<trclass="memdesc:gae12c190af42d7310d8006d64f4ed5a88"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Convert a microseconds value to a RTOS kernel system timer value. <ahref="#gae12c190af42d7310d8006d64f4ed5a88">More...</a><br/></td></tr>
<trclass="memdesc:ga53d078a801022e202e8115c083ece68e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Initialize the RTOS Kernel for creating objects. <ahref="#ga53d078a801022e202e8115c083ece68e">More...</a><br/></td></tr>
<trclass="memdesc:gaab668ffd2ea76bb0a77ab0ab385eaef2"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Start the RTOS Kernel. <ahref="#gaab668ffd2ea76bb0a77ab0ab385eaef2">More...</a><br/></td></tr>
<trclass="memdesc:ga3b571de44cd3094c643247a7397f86b5"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Check if the RTOS kernel is already started. <ahref="#ga3b571de44cd3094c643247a7397f86b5">More...</a><br/></td></tr>
<trclass="memdesc:gad0262e4688e95d1e9038afd9bcc16001"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Get the RTOS kernel system timer counter. <ahref="#gad0262e4688e95d1e9038afd9bcc16001">More...</a><br/></td></tr>
<p>The Kernel Information and Control function group allows to:</p>
<ul>
<li>obtain information about the system and the underlying kernel.</li>
<li>obtain version information about the CMSIS-RTOS API.</li>
<li>initialize of the RTOS kernel for creating objects.</li>
<li>start the RTOS kernel and thread switching.</li>
<li>check the execution status of the RTOS kernel.</li>
</ul>
<p>The function <b>main</b> is a special thread function that may be started at system initialization. In this case it has the initial priority <em>osPriorityNormal</em>.</p>
<p>When reaching <b>main</b>, it is necessary to:</p>
<li>Call <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#ga53d078a801022e202e8115c083ece68e"title="Initialize the RTOS Kernel for creating objects. ">osKernelInitialize()</a> to initialize the CMSIS-RTOS Kernel</li>
<li>Start the Kernel and begin thread switching by calling <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2"title="Start the RTOS Kernel. ">osKernelStart()</a>.</li>
<p>Version information of the CMSIS-RTOS API whereby major version is in bits [31:16] and sub version in bits [15:0]. The value 0x10000 represents version 1.00.</p>
<dlclass="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osCMSIS</b> identifies the CMSIS-RTOS API version. </dd></dl>
<p>Identifies the underlying RTOS kernel and version number. The actual name of that define depends on the RTOS Kernel used in the implementation. For example, <b>osCMSIS_FreeRTOS</b> identifies the FreeRTOS kernel and the value indicates the version number of that kernel whereby the major version is in bits [31:16] and sub version in bits [15:0]. The value 0x10000 represents version 1.00.</p>
<dlclass="section note"><dt>Note</dt><dd>CAN BE CHANGED: <b>osCMSIS_KERNEL</b> identifies the underlying RTOS kernel and version number. </dd></dl>
<li>When <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#ga22f7d235bc9f783933bd5a981fd79696">osFeature_MainThread</a> is 1 the RTOS offers to start with 'main'. The RTOS kernel is in this case already started.</li>
<li>When <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#ga22f7d235bc9f783933bd5a981fd79696">osFeature_MainThread</a> is 0 the RTOS requires explicit start with <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2">osKernelStart</a>.</li>
<li>When <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gae554ec16c23c5b7d65affade2a351891">osFeature_SysTick</a> is 1 access to the RTOS kernel system timer is provided with <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gad0262e4688e95d1e9038afd9bcc16001">osKernelSysTick</a>, <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#ga9e0954d52722673e2031233a2ab99960">osKernelSysTickFrequency</a>, and <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gae12c190af42d7310d8006d64f4ed5a88">osKernelSysTickMicroSec</a>.</li>
<li>When <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gae554ec16c23c5b7d65affade2a351891">osFeature_SysTick</a> is 0 access to the RTOS kernel system timer is not implemented.</li>
<p>Defines a string that identifies the underlying RTOS Kernel and provides version information. The length of that string is limited to 21 bytes. A valid identification string is for example, <b>"FreeRTOS V1.00"</b>.</p>
<dlclass="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osKernelSystemId</b> shall be consistent in every CMSIS-RTOS. </dd></dl>
<p>Specifies the frequency of the Kernel SysTick timer in Hz. The value is typically use to scale a time value and is for example used in <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gae12c190af42d7310d8006d64f4ed5a88">osKernelSysTickMicroSec</a>.</p>
<dlclass="section see"><dt>See Also</dt><dd><aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gad0262e4688e95d1e9038afd9bcc16001"title="Get the RTOS kernel system timer counter. ">osKernelSysTick</a></dd></dl>
<p>Allows you to scale a microsecond value to the frequency of the Kernel SysTick timer. This macro is typically used to check for short timeouts in polling loops.</p>
<dlclass="section see"><dt>See Also</dt><dd><aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gad0262e4688e95d1e9038afd9bcc16001"title="Get the RTOS kernel system timer counter. ">osKernelSysTick</a></dd></dl>
<dlclass="section return"><dt>Returns</dt><dd>time value normalized to the <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#ga9e0954d52722673e2031233a2ab99960">osKernelSysTickFrequency</a></dd></dl>
<li><aclass="el"href="group__CMSIS__RTOS__ThreadMgmt.html#gac59b5713cb083702dce759c73fd90dff">osThreadCreate</a> : Create a thread function.</li>
<li><aclass="el"href="group__CMSIS__RTOS__TimerMgmt.html#gaedd312bfdca04e0b8162b666e09a1ae6">osTimerCreate</a> : Define attributes of the timer callback function.</li>
<li><aclass="el"href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a> : Define and initialize a mutex.</li>
<li><aclass="el"href="group__CMSIS__RTOS__SemaphoreMgmt.html#ga97381e8e55cd47cec390bf57c96d6edb">osSemaphoreCreate</a> : Define and initialize a semaphore.</li>
<li><aclass="el"href="group__CMSIS__RTOS__PoolMgmt.html#ga34af5c4f4ab38f4138ea7f1f9ece3a1a">osPoolCreate</a> : Define and initialize a fix-size memory pool.</li>
<li><aclass="el"href="group__CMSIS__RTOS__Message.html#gaf3b9345cf426304d46565152bc26fb78">osMessageCreate</a> : Define and initialize a message queue.</li>
<li><aclass="el"href="group__CMSIS__RTOS__Mail.html#gaa177e7fe5820dd70d8c9e46ded131174">osMailCreate</a> : Define and initialize a mail queue with fix-size memory blocks.</li>
<p>The RTOS kernel does not start thread switching until the function <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2">osKernelStart</a> is called.</p>
<dlclass="section note"><dt>Note</dt><dd>In case that the RTOS Kernel starts thread execution with the function <em>main</em> the function osKernelInitialize stops thread switching. This allows you to setup the system to a defined state before thread switching is resumed with <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2">osKernelStart</a>.</dd></dl>
<divclass="line"><spanclass="keywordflow">if</span> (!<aclass="code"href="group__CMSIS__RTOS__KernelCtrl.html#ga3b571de44cd3094c643247a7397f86b5">osKernelRunning</a> ()) { <spanclass="comment">// if kernel is not running, initialize the kernel</span></div>
<divclass="line"><spanclass="keywordflow">if</span> (<aclass="code"href="group__CMSIS__RTOS__KernelCtrl.html#ga53d078a801022e202e8115c083ece68e">osKernelInitialize</a> () != <aclass="code"href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) { <spanclass="comment">// check osStatus for other possible valid values</span></div>
<dlclass="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osKernelRunning</b> shall be consistent in every CMSIS-RTOS. </dd></dl>
<dlclass="section return"><dt>Returns</dt><dd>0 RTOS is not started, 1 RTOS is started.</dd></dl>
<p>Identifies if the RTOS kernel is started. For systems with the option to start the <em>main</em> function as a thread this allows you to identify that the RTOS kernel is already running.</p>
<dlclass="section note"><dt>Note</dt><dd><aclass="el"href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a> can call this function.</dd></dl>
<divclass="line"><spanclass="keywordtype">int</span> main (<spanclass="keywordtype">void</span>) { <spanclass="comment">// program execution starts here</span></div>
<dlclass="section note"><dt>Note</dt><dd>When the CMSIS-RTOS starts thread execution with the function <em>main</em> this function resumes thread switching. The <em>main</em> thread will continue executing after <aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2">osKernelStart</a>.</dd></dl>
<p><b><aclass="el"href="group__CMSIS__RTOS__Status.html">Status and Error Codes</a></b><br/>
<li><em>osErrorISR:</em><aclass="el"href="group__CMSIS__RTOS__KernelCtrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2">osKernelStart</a> cannot be called from interrupt service routines.</li>
<dlclass="section note"><dt>Note</dt><dd>Cannot be called from <aclass="el"href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<divclass="line"><spanclass="keywordflow">if</span> (<aclass="code"href="group__CMSIS__RTOS__KernelCtrl.html#ga53d078a801022e202e8115c083ece68e">osKernelInitialize</a> () != <aclass="code"href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) { <spanclass="comment">// check osStatus for other possible valid values</span></div>
<divclass="line"><spanclass="keywordflow">if</span> (!<aclass="code"href="group__CMSIS__RTOS__KernelCtrl.html#ga3b571de44cd3094c643247a7397f86b5">osKernelRunning</a> ()) { <spanclass="comment">// is the kernel running ?</span></div>
<divclass="line"><spanclass="keywordflow">if</span> (<aclass="code"href="group__CMSIS__RTOS__KernelCtrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2">osKernelStart</a> () != <aclass="code"href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) { <spanclass="comment">// start the kernel</span></div>
<dlclass="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osKernelSysTick</b> shall be consistent in every CMSIS-RTOS. </dd></dl>
<dlclass="section return"><dt>Returns</dt><dd>RTOS kernel system timer as 32-bit value</dd></dl>
<p>Get the value of the Kernel SysTick timer for time comparison. The value is a rolling 32-bit counter that is typically composed of the kernel system interrupt timer value and an counter that counts these interrupts.</p>
<p>This function allows the implementation of timeout checks. These are for example required when checking for a busy status in a device or peripheral initialization routine.</p>
<dlclass="section note"><dt>Note</dt><dd>Cannot be called from <aclass="el"href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<divclass="line"> tick = <aclass="code"href="group__CMSIS__RTOS__KernelCtrl.html#gad0262e4688e95d1e9038afd9bcc16001">osKernelSysTick</a>(); <spanclass="comment">// get start value of the Kernel system tick</span></div>
<divclass="line"> Device.Setup (); <spanclass="comment">// initialize a device or peripheral</span></div>
<divclass="line"><spanclass="keywordflow">do</span> { <spanclass="comment">// poll device busy status for 100 microseconds</span></div>
<divclass="line"><spanclass="keywordflow">if</span> (!Device.Busy) <spanclass="keywordflow">break</span>; <spanclass="comment">// check if device is correctly initialized</span></div>