ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
fsl_pit_driver.h
Go to the documentation of this file.
1 /*!
2 ********************************************************************************
3 * File: fsl_pit_driver.h
4 *
5 * Copyright (c) 2014, Freescale Semiconductor, Inc.
6 *
7 *******************************************************************************/
8 /*!
9 * @file fsl_pit_driver.h
10 * @brief \b fsl_pit_driver.h defines structures and types for the PIT driver.
11 */
12 #ifndef __FSL_PIT_DRIVER_H__
13 #define __FSL_PIT_DRIVER_H__
14 
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include "fsl_pit_hal.h"
18 
19 /*!
20  * @addtogroup pit_driver
21  * @{
22  */
23 
24 /*******************************************************************************
25  * Definitions
26  ******************************************************************************/
27 
28 /*!
29  * @brief PIT timer configuration structure
30  *
31  * Define structure PitConfig and use pit_init_channel() to make necessary
32  * initializations. You may also use remaining functions for PIT configuration.
33  *
34  * @note the timer chain feature is not valid in all devices, please check
35  * fsl_pit_features.h for accurate setting. If it's not valid, the value set here
36  * will be bypassed inside function pit_init_channel().
37  */
38 typedef struct PitUserConfig {
39  bool isInterruptEnabled; /*!< Timer interrupt 0-disable/1-enable*/
40  bool isTimerChained; /*!< Chained with previous timer, 0-not/1-chained*/
41  uint32_t periodUs; /*!< Timer period in unit of microseconds*/
43 
44 /*! @brief PIT ISR callback function typedef */
45 typedef void (*pit_isr_callback_t)(void);
46 
47 /*******************************************************************************
48  * API
49  ******************************************************************************/
50 
51 #if defined(__cplusplus)
52 extern "C" {
53 #endif
54 
55 /*!
56  * @brief Initialize PIT module.
57  *
58  * This function must be called before calling all the other PIT driver functions.
59  * This function un-gates the PIT clock and enables the PIT module. The isRunInDebug
60  * passed into function will affect all timer channels.
61  *
62  * @param isRunInDebug Timers run or stop in debug mode.
63  * - true: Timers continue to run in debug mode.
64  * - false: Timers stop in debug mode.
65  */
66 void pit_init_module(bool isRunInDebug);
67 
68 /*!
69  * @brief Initialize PIT channel.
70  *
71  * This function initialize PIT timers by channel. Pass in timer number and its
72  * config structure. Timers do not start counting by default after calling this
73  * function. Function pit_timer_start must be called to start timer counting.
74  * Call pit_set_timer_period_us to re-set the period.
75  *
76  * Here is an example demonstrating how to define a PIT channel config structure:
77  @code
78  pit_user_config_t pitTestInit = {
79  .isInterruptEnabled = true,
80  // Only takes effect when chain feature is available.
81  // Otherwise, pass in arbitrary value(true/false).
82  .isTimerChained = false,
83  // In unit of microseconds.
84  .periodUs = 1000,
85  };
86  @endcode
87  *
88  * @param timer Timer channel number.
89  * @param config PIT channel configuration structure.
90  */
91 void pit_init_channel(uint32_t timer, const pit_user_config_t * config);
92 
93 /*!
94  * @brief Disable PIT module and gate control.
95  *
96  * This function disables all PIT interrupts and PIT clock. It then gates the
97  * PIT clock control. pit_init_module must be called if you want to use PIT again.
98  */
99 void pit_shutdown(void);
100 
101 /*!
102  * @brief Start timer counting.
103  *
104  * After calling this function, timers load period value, count down to 0 and
105  * then load the respective start value again. Each time a timer reaches 0,
106  * it generates a trigger pulse and sets the timeout interrupt flag.
107  *
108  * @param timer Timer channel number.
109  */
110 void pit_timer_start(uint32_t timer);
111 
112 /*!
113  * @brief Stop timer counting.
114  *
115  * This function stops every timer counting. Timers reload their periods
116  * respectively after the next time they call pit_timer_start.
117  *
118  * @param timer Timer channel number.
119  */
120 void pit_timer_stop(uint32_t timer);
121 
122 /*!
123  * @brief Set timer period in microsecond units.
124  *
125  * The period range depends on the frequency of PIT source clock. If the required period
126  * is out of range, use the lifetime timer, if applicable.
127  *
128  * @param timer Timer channel number.
129  * @param us Timer period in microseconds.
130  */
131 void pit_set_timer_period_us(uint32_t timer, uint32_t us);
132 
133 /*!
134  * @brief Read current timer value in microsecond units.
135  *
136  * This function returns an absolute time stamp in microsecond units.
137  * One common use of this function is to measure the running time of a part of
138  * code. Call this function at both the beginning and end of code; the time
139  * difference between these two time stamps is the running time (Make sure the
140  * running time will not exceed the timer period). The time stamp returned is
141  * up-counting.
142  *
143  * @param timer Timer channel number.
144  * @return Current timer value in microseconds.
145  */
146 uint32_t pit_read_timer_us(uint32_t timer);
147 
148 #if FSL_FEATURE_PIT_HAS_LIFETIME_TIMER
149 /*!
150  * @brief Set lifetime timer period.
151  *
152  * Timer 1 must be chained with timer 0 before using the lifetime timer. The period
153  * range is restricted by "period * pitSourceClock < max of an uint64_t integer",
154  * or it may cause an overflow and be unable to set the correct period.
155  *
156  * @param period Lifetime timer period in microseconds.
157  */
158 void pit_set_lifetime_timer_period_us(uint64_t us);
159 
160 /*!
161  * @brief Read current lifetime value in microseconds.
162  *
163  * This feature returns an absolute time stamp in microsecond units. The time stamp
164  * value will not exceed the timer period. The timer is up-counting.
165  *
166  * @return Current lifetime timer value in microseconds.
167  */
168 uint64_t pit_read_lifetime_timer_us(void);
169 #endif /*FSL_FEATURE_PIT_HAS_LIFETIME_TIMER*/
170 
171 /*!
172  * @brief Complete initialization of the PIT timer.
173  *
174  */
175 void pit_init(bool bEnableirq, uint32 usec);
176 
177 /*!
178  * @brief Register pit isr callback function.
179  *
180  * System default ISR interfaces are already defined in fsl_pit_irq.c. Users
181  * can either edit these ISRs or use this function to register a callback
182  * function. The default ISR runs the callback function if there is one
183  * installed.
184  *
185  * @param timer Timer channel number.
186  * @param function Pointer to pit isr callback function.
187  */
188 void pit_register_isr_callback_function(uint32_t timer, pit_isr_callback_t function);
189 
190 #if defined(__cplusplus)
191 }
192 #endif
193 
194 /*! @}*/
195 
196 #endif /* __FSL_PIT_DRIVER_H__*/
197 /*******************************************************************************
198  * EOF
199  ******************************************************************************/
200 
201 
202 
203 
void pit_shutdown(void)
Disable PIT module and gate control.
void pit_set_timer_period_us(uint32_t timer, uint32_t us)
Set timer period in microsecond units.
void pit_init_module(bool isRunInDebug)
Initialize PIT module.
unsigned long uint32
This defines uint32 as unsigned long.
Definition: isf_types.h:36
void pit_init(bool bEnableirq, uint32 usec)
Complete initialization of the PIT timer.
uint32_t periodUs
void pit_init_channel(uint32_t timer, const pit_user_config_t *config)
Initialize PIT channel.
void pit_timer_stop(uint32_t timer)
Stop timer counting.
bool isInterruptEnabled
void(* pit_isr_callback_t)(void)
PIT ISR callback function typedef.
struct PitUserConfig pit_user_config_t
PIT timer configuration structure.
void pit_timer_start(uint32_t timer)
Start timer counting.
uint32_t pit_read_timer_us(uint32_t timer)
Read current timer value in microsecond units.
void pit_register_isr_callback_function(uint32_t timer, pit_isr_callback_t function)
Register pit isr callback function.
Definition: fsl_pit_irq.c:160
PIT timer configuration structure.