ISSDK  1.7
IoT Sensing Software Development Kit
driver_pit.c
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*! \file driver_pit.c
36  \brief Provides a simple abstraction for a periodic interval timer.
37 
38  Bare metal implementations of the sensor fusion library require at least
39  one periodic interrupt for use as a timebase for sensor fusion functions.
40  The Periodic Interval Timer (PIT) is one such module that is commonly
41  found on NXP Kinetis MCUs. The PIT functions are only referenced at the
42  main() level. There is no interaction within the fusion routines themselves.
43 */
44 #include "issdk_hal.h"
45 #include "board.h"
46 #include "fsl_pit.h"
47 #include "pin_mux.h"
48 #include "clock_config.h"
49 
50 /*******************************************************************************
51  * Definitions
52  ******************************************************************************/
53 #ifndef PIT_LED_HANDLER
54 #define PIT_LED_HANDLER PIT0_IRQHandler
55 #endif
56 #ifndef PIT_IRQ_ID
57 #define PIT_IRQ_ID PIT0_IRQn
58 #endif
59 #define PIT_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)
60 
61 volatile bool pitIsrFlag = false;
62 
63 void PIT_LED_HANDLER(void)
64 {
65  /* Clear interrupt flag.*/
66  PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, PIT_TFLG_TIF_MASK);
67  pitIsrFlag = true;
68 }
69 
70 void pit_init(uint32_t microseconds)
71 {
72  /* initialize PIT */
73  pit_config_t pitConfig; // Declare KSDK PIT configuration structure
74  PIT_GetDefaultConfig(&pitConfig); // Fill out that structure with defaults
75  PIT_Init(PIT, &pitConfig); // PIT is declared by the KSDK
76  // We choose to use Channel 0 of the PIT. That can obviously be changed
77  PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, USEC_TO_COUNT(microseconds, PIT_SOURCE_CLOCK));
78  PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);
79  EnableIRQ(PIT_IRQ_ID);
80  PIT_StartTimer(PIT, kPIT_Chnl_0);
81 }
#define PIT_IRQ_ID
Definition: driver_pit.c:57
void pit_init(uint32_t microseconds)
Definition: driver_pit.c:70
volatile bool pitIsrFlag
Definition: driver_pit.c:61
#define PIT_LED_HANDLER
Definition: driver_pit.c:54
#define PIT_SOURCE_CLOCK
Definition: driver_pit.c:59