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_hal.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #ifndef __FSL_PIT_HAL_H__
31 #define __FSL_PIT_HAL_H__
32 
33 #include <assert.h>
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include "isf_types.h"
37 
38 #define bool uint32
39 
40 /*******************************************************************************
41  * API
42  ******************************************************************************/
43 
44 #if defined(__cplusplus)
45 extern "C" {
46 #endif
47 
48 /*!
49  * @brief Enable PIT module.
50  *
51  * This function enables PIT timer clock (Note: this function will not un-gate
52  * the system clock gating control). It should be called before any other timer
53  * related setup.
54  */
55 void pit_hal_enable(void);
56 
57 /*!
58  * @brief Disable PIT module.
59  *
60  * This function disables all PIT timer clocks(Note: it will not affect
61  * SIM clock gating control).
62  */
63 void pit_hal_disable(void);
64 
65 /*!
66  * @brief Configure timers to continue to run or stop in debug mode.
67  *
68  * In debug mode, the timers will or will not be frozen, based on the configuration of
69  * this function. This is intended to aid software development, allowing the developer
70  * to halt the processor, investigate the current state of the system (for example,
71  * the timer values) and then continue the operation.
72  *
73  * @param timerRun Timers run or stop in debug mode.
74  * - true: Timers continue to run in debug mode.
75  * - false: Timers stop in debug mode.
76  */
77 void pit_hal_configure_timer_run_in_debug(bool timerRun);
78 
79 /*!
80  * @brief Start timer counting.
81  *
82  * After calling this function, timers load the start value as specified by function
83  * pit_hal_set_timer_period_count(uint32_t timer, uint32_t count), count down to
84  * 0 and then load the respective start value again. Each time a timer reaches 0,
85  * it generates a trigger pulse and set the timeout interrupt flag.
86  *
87  * @param timer Timer channel number.
88  */
89 void pit_hal_timer_start(uint32_t timer);
90 
91 /*!
92  * @brief Stop timer counting.
93  *
94  * This function stops every timer counting. Timers reload their periods
95  * respectively after they call pit_hal_timer_start the next time.
96  *
97  * @param timer Timer channel number.
98  */
99 void pit_hal_timer_stop(uint32_t timer);
100 
101 /*!
102  * @brief Start timer counting.
103  *
104  * After calling this function, timers load the start value as specified by function
105  * pit_hal_set_timer_period_count(uint32_t timer, uint32_t count), count down to
106  * 0 and then load the respective start value again. Each time a timer reaches 0,
107  * it generates a trigger pulse and set the timeout interrupt flag.
108  *
109  * @param timer Timer channel number.
110  */
111 void pit_hal_timer_reset(uint32_t timer);
112 
113 /*!
114  * @brief Set timer period in units of count.
115  *
116  * Timers begin counting from the value set by this function.
117  * The counter period of a running timer can be modified by first stopping
118  * the timer, setting a new load value, and then starting the timer again. If
119  * timers are not restarted, the new value is loaded after the next trigger
120  * event.
121  *
122  * @param timer Timer channel number.
123  * @param count Timer period in units of count.
124  */
125 void pit_hal_set_timer_period_count(uint32_t timer, uint32_t count);
126 
127 /*!
128  * @brief Return current timer period in units of count.
129  *
130  * @param timer Timer channel number.
131  * @return Timer period in units of count.
132  */
133 uint32_t pit_hal_read_timer_period_count(uint32_t timer);
134 
135 /*!
136  * @brief Read current timer counting value.
137  *
138  * This function returns the real-time timer counting value, in a range from 0 to
139  * timer period.
140  *
141  * @param timer Timer channel number.
142  * @return Current timer counting value.
143  */
144 uint32_t pit_hal_read_timer_count(uint32_t timer);
145 
146 /*!
147  * @brief Enable or disable timer interrupt.
148  *
149  * If enabled, an interrupt happens when a timeout event occurs
150  * (Note: NVIC should be called to enable pit interrupt in system level).
151  *
152  * @param timer Timer channel number.
153  * @param enable Enable or disable interrupt.
154  * - true: Generate interrupt when timer counts to 0.
155  * - false: No interrupt is generated.
156  */
157 void pit_hal_configure_interrupt(uint32_t timer, bool enable);
158 
159 /*!
160  * @brief Clear timer interrupt flag.
161  *
162  * This function clears the timer interrupt flag after a timeout event
163  * occurs.
164  *
165  * @param timer Timer channel number.
166  */
167 void pit_hal_clear_interrupt_flag(uint32_t timer);
168 
169 /*!
170  * @brief Read current timer timeout flag.
171  *
172  * Every time the timer counts to 0, this flag is set.
173  *
174  * @param timer Timer channel number.
175  * @return Current status of timeout flag.
176  * - true: Timeout has occurred.
177  * - false: Timeout has not yet occurred.
178  */
179 bool pit_hal_is_timeout_occurred(uint32_t timer);
180 
181 /* @} */
182 
183 #if defined(__cplusplus)
184 }
185 #endif
186 
187 /*! @}*/
188 
189 #endif /* __FSL_PIT_HAL_H__*/
190 /*******************************************************************************
191 * EOF
192 *******************************************************************************/
193 
194 
195 
uint32_t pit_hal_read_timer_period_count(uint32_t timer)
Return current timer period in units of count.
Definition: fsl_pit_hal.c:76
void pit_hal_configure_interrupt(uint32_t timer, bool enable)
Enable or disable timer interrupt.
Definition: fsl_pit_hal.c:92
The isf_types.h file contains the ISF data type definitions and some of the globally used macros...
void pit_hal_clear_interrupt_flag(uint32_t timer)
Clear timer interrupt flag.
Definition: fsl_pit_hal.c:105
void pit_hal_timer_start(uint32_t timer)
Start timer counting.
Definition: fsl_pit_hal.c:56
void pit_hal_set_timer_period_count(uint32_t timer, uint32_t count)
Set timer period in units of count.
Definition: fsl_pit_hal.c:71
uint32_t pit_hal_read_timer_count(uint32_t timer)
Read current timer counting value.
Definition: fsl_pit_hal.c:83
void pit_hal_enable(void)
Enable PIT module.
Definition: fsl_pit_hal.c:41
void pit_hal_configure_timer_run_in_debug(bool timerRun)
Configure timers to continue to run or stop in debug mode.
Definition: fsl_pit_hal.c:51
bool pit_hal_is_timeout_occurred(uint32_t timer)
Read current timer timeout flag.
Definition: fsl_pit_hal.c:112
void pit_hal_timer_reset(uint32_t timer)
Start timer counting.
Definition: fsl_pit_hal.c:66
void pit_hal_timer_stop(uint32_t timer)
Stop timer counting.
Definition: fsl_pit_hal.c:61
void pit_hal_disable(void)
Disable PIT module.
Definition: fsl_pit_hal.c:46