1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xmlns="http://www.w3.org/1999/xhtml"> 3<head> 4<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> 5<meta http-equiv="X-UA-Compatible" content="IE=9"/> 6<meta name="generator" content="Doxygen 1.8.13"/> 7<meta name="viewport" content="width=device-width, initial-scale=1"/> 8<title>ISSDK: algorithms/sensorfusion/sources/driver_pit.c Source File</title> 9<link href="tabs.css" rel="stylesheet" type="text/css"/> 10<script type="text/javascript" src="jquery.js"></script> 11<script type="text/javascript" src="dynsections.js"></script> 12<link href="issdk_stylesheet.css" rel="stylesheet" type="text/css" /> 13</head> 14<body> 15<div id="top"><!-- do not remove this div, it is closed by doxygen! --> 16<div id="titlearea"> 17<table cellspacing="0" cellpadding="0"> 18 <tbody> 19 <tr style="height: 56px;"> 20 <td id="projectlogo"><img alt="Logo" src="nxp_logo_small.png"/></td> 21 <td id="projectalign" style="padding-left: 0.5em;"> 22 <div id="projectname">ISSDK 23  <span id="projectnumber">1.8</span> 24 </div> 25 <div id="projectbrief">IoT Sensing Software Development Kit</div> 26 </td> 27 </tr> 28 </tbody> 29</table> 30</div> 31<!-- end header part --> 32<!-- Generated by Doxygen 1.8.13 --> 33<script type="text/javascript" src="menudata.js"></script> 34<script type="text/javascript" src="menu.js"></script> 35<script type="text/javascript"> 36$(function() { 37 initMenu('',false,false,'search.php','Search'); 38}); 39</script> 40<div id="main-nav"></div> 41<div id="nav-path" class="navpath"> 42 <ul> 43<li class="navelem"><a class="el" href="dir_c0ce462e37efe0a8d60c01d75f78f8a0.html">algorithms</a></li><li class="navelem"><a class="el" href="dir_cb8ed5ffd1f20a5af7e420f81f312621.html">sensorfusion</a></li><li class="navelem"><a class="el" href="dir_c60867674b20e7d761cd401b87ce879d.html">sources</a></li> </ul> 44</div> 45</div><!-- top --> 46<div class="header"> 47 <div class="headertitle"> 48<div class="title">driver_pit.c</div> </div> 49</div><!--header--> 50<div class="contents"> 51<a href="a00833.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno"> 2</span> <span class="comment"> * Copyright (c) 2015, Freescale Semiconductor, Inc.</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment"> * Copyright 2016-2017 NXP</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment"> * All rights reserved.</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment"> *</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment"> * SPDX-License-Identifier: BSD-3-Clause</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment"> */</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment"></span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">/*! \file driver_pit.c</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment"> \brief Provides a simple abstraction for a periodic interval timer.</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment"></span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment"> Bare metal implementations of the sensor fusion library require at least</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment"> one periodic interrupt for use as a timebase for sensor fusion functions.</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment"> The Periodic Interval Timer (PIT) is one such module that is commonly</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment"> found on NXP Kinetis MCUs. The PIT functions are only referenced at the</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment"> main() level. There is no interaction within the fusion routines themselves.</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">*/</span></div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span> <span class="preprocessor">#include "issdk_hal.h"</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="preprocessor">#include "board.h"</span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#include "fsl_pit.h"</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="preprocessor">#include "pin_mux.h"</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="preprocessor">#include "clock_config.h"</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> </div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="comment">/*******************************************************************************</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="comment"> * Definitions</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="comment"> ******************************************************************************/</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#ifndef PIT_LED_HANDLER</span></div><div class="line"><a name="l00028"></a><span class="lineno"><a class="line" href="a00833.html#ad856669f6cb00c21152914f238a5b13a"> 28</a></span> <span class="preprocessor">#define PIT_LED_HANDLER PIT0_IRQHandler</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#ifndef PIT_IRQ_ID</span></div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="a00833.html#a5e2f2a63c91f6a3fc3efaa78c0f40e62"> 31</a></span> <span class="preprocessor">#define PIT_IRQ_ID PIT0_IRQn</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="a00833.html#a411cc0f5ce23365479e23727ea7e27a9"> 33</a></span> <span class="preprocessor">#define PIT_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> </div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="a00833.html#a4bd7666380e01cee8eb7cd5f0df5e3bf"> 35</a></span> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> <a class="code" href="a00833.html#a4bd7666380e01cee8eb7cd5f0df5e3bf">pitIsrFlag</a> = <span class="keyword">false</span>;</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> </div><div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="a00833.html#a06fa5975f12d96fe146671dfd5af4b2f"> 37</a></span> <span class="keywordtype">void</span> <a class="code" href="a00833.html#ad856669f6cb00c21152914f238a5b13a">PIT_LED_HANDLER</a>(<span class="keywordtype">void</span>)</div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> {</div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>  <span class="comment">/* Clear interrupt flag.*/</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>  PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, PIT_TFLG_TIF_MASK);</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>  <a class="code" href="a00833.html#a4bd7666380e01cee8eb7cd5f0df5e3bf">pitIsrFlag</a> = <span class="keyword">true</span>;</div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> }</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span> </div><div class="line"><a name="l00044"></a><span class="lineno"><a class="line" href="a00833.html#aa9242caadd99e8ac4fdce86681b61740"> 44</a></span> <span class="keywordtype">void</span> <a class="code" href="a00833.html#aa9242caadd99e8ac4fdce86681b61740">pit_init</a>(uint32_t microseconds)</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> {</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>  <span class="comment">/* initialize PIT */</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>  pit_config_t pitConfig; <span class="comment">// Declare KSDK PIT configuration structure</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span>  PIT_GetDefaultConfig(&pitConfig); <span class="comment">// Fill out that structure with defaults</span></div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>  PIT_Init(PIT, &pitConfig); <span class="comment">// PIT is declared by the KSDK</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>  <span class="comment">// We choose to use Channel 0 of the PIT. That can obviously be changed</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>  PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(microseconds, <a class="code" href="a00833.html#a411cc0f5ce23365479e23727ea7e27a9">PIT_SOURCE_CLOCK</a>));</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span>  PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  EnableIRQ(<a class="code" href="a00833.html#a5e2f2a63c91f6a3fc3efaa78c0f40e62">PIT_IRQ_ID</a>);</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  PIT_StartTimer(PIT, kPIT_Chnl_0);</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> }</div><div class="ttc" id="a00833_html_a4bd7666380e01cee8eb7cd5f0df5e3bf"><div class="ttname"><a href="a00833.html#a4bd7666380e01cee8eb7cd5f0df5e3bf">pitIsrFlag</a></div><div class="ttdeci">volatile bool pitIsrFlag</div><div class="ttdef"><b>Definition:</b> <a href="a00833_source.html#l00035">driver_pit.c:35</a></div></div> 52<div class="ttc" id="a00833_html_a5e2f2a63c91f6a3fc3efaa78c0f40e62"><div class="ttname"><a href="a00833.html#a5e2f2a63c91f6a3fc3efaa78c0f40e62">PIT_IRQ_ID</a></div><div class="ttdeci">#define PIT_IRQ_ID</div><div class="ttdef"><b>Definition:</b> <a href="a00833_source.html#l00031">driver_pit.c:31</a></div></div> 53<div class="ttc" id="a00833_html_a411cc0f5ce23365479e23727ea7e27a9"><div class="ttname"><a href="a00833.html#a411cc0f5ce23365479e23727ea7e27a9">PIT_SOURCE_CLOCK</a></div><div class="ttdeci">#define PIT_SOURCE_CLOCK</div><div class="ttdef"><b>Definition:</b> <a href="a00833_source.html#l00033">driver_pit.c:33</a></div></div> 54<div class="ttc" id="a00833_html_aa9242caadd99e8ac4fdce86681b61740"><div class="ttname"><a href="a00833.html#aa9242caadd99e8ac4fdce86681b61740">pit_init</a></div><div class="ttdeci">void pit_init(uint32_t microseconds)</div><div class="ttdef"><b>Definition:</b> <a href="a00833_source.html#l00044">driver_pit.c:44</a></div></div> 55<div class="ttc" id="a00833_html_ad856669f6cb00c21152914f238a5b13a"><div class="ttname"><a href="a00833.html#ad856669f6cb00c21152914f238a5b13a">PIT_LED_HANDLER</a></div><div class="ttdeci">#define PIT_LED_HANDLER</div><div class="ttdef"><b>Definition:</b> <a href="a00833_source.html#l00028">driver_pit.c:28</a></div></div> 56</div><!-- fragment --></div><!-- contents --> 57 58<hr class="footer"/><address class="footer"><small> 59© Copyright 2016-2022 NXP. All Rights Reserved. SPDX-License-Identifier: BSD-3-Clause 60</small></address> 61</body> 62</html> 63