mbed(SerialHalfDuplex入り)
Fork of mbed by
TARGET_K64F/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/drivers/pit/fsl_pit_driver.h@83:8a40adfe8776, 2014-04-28 (annotated)
- Committer:
- bogdanm
- Date:
- Mon Apr 28 17:39:05 2014 +0100
- Revision:
- 83:8a40adfe8776
- Child:
- 90:cb3d968589d8
Release 83 of the mbed library
Main changes:
- updated tests
- K64F TCP/IP support
- lots of fixes in various targets
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 83:8a40adfe8776 | 1 | /* |
bogdanm | 83:8a40adfe8776 | 2 | * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc. |
bogdanm | 83:8a40adfe8776 | 3 | * All rights reserved. |
bogdanm | 83:8a40adfe8776 | 4 | * |
bogdanm | 83:8a40adfe8776 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
bogdanm | 83:8a40adfe8776 | 6 | * are permitted provided that the following conditions are met: |
bogdanm | 83:8a40adfe8776 | 7 | * |
bogdanm | 83:8a40adfe8776 | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
bogdanm | 83:8a40adfe8776 | 9 | * of conditions and the following disclaimer. |
bogdanm | 83:8a40adfe8776 | 10 | * |
bogdanm | 83:8a40adfe8776 | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
bogdanm | 83:8a40adfe8776 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
bogdanm | 83:8a40adfe8776 | 13 | * other materials provided with the distribution. |
bogdanm | 83:8a40adfe8776 | 14 | * |
bogdanm | 83:8a40adfe8776 | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
bogdanm | 83:8a40adfe8776 | 16 | * contributors may be used to endorse or promote products derived from this |
bogdanm | 83:8a40adfe8776 | 17 | * software without specific prior written permission. |
bogdanm | 83:8a40adfe8776 | 18 | * |
bogdanm | 83:8a40adfe8776 | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
bogdanm | 83:8a40adfe8776 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
bogdanm | 83:8a40adfe8776 | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bogdanm | 83:8a40adfe8776 | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
bogdanm | 83:8a40adfe8776 | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
bogdanm | 83:8a40adfe8776 | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
bogdanm | 83:8a40adfe8776 | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
bogdanm | 83:8a40adfe8776 | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
bogdanm | 83:8a40adfe8776 | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
bogdanm | 83:8a40adfe8776 | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bogdanm | 83:8a40adfe8776 | 29 | */ |
bogdanm | 83:8a40adfe8776 | 30 | #ifndef __FSL_PIT_DRIVER_H__ |
bogdanm | 83:8a40adfe8776 | 31 | #define __FSL_PIT_DRIVER_H__ |
bogdanm | 83:8a40adfe8776 | 32 | |
bogdanm | 83:8a40adfe8776 | 33 | #include <stdint.h> |
bogdanm | 83:8a40adfe8776 | 34 | #include <stdbool.h> |
bogdanm | 83:8a40adfe8776 | 35 | #include "fsl_pit_hal.h" |
bogdanm | 83:8a40adfe8776 | 36 | |
bogdanm | 83:8a40adfe8776 | 37 | /*! |
bogdanm | 83:8a40adfe8776 | 38 | * @addtogroup pit_driver |
bogdanm | 83:8a40adfe8776 | 39 | * @{ |
bogdanm | 83:8a40adfe8776 | 40 | */ |
bogdanm | 83:8a40adfe8776 | 41 | |
bogdanm | 83:8a40adfe8776 | 42 | /******************************************************************************* |
bogdanm | 83:8a40adfe8776 | 43 | * Definitions |
bogdanm | 83:8a40adfe8776 | 44 | ******************************************************************************/ |
bogdanm | 83:8a40adfe8776 | 45 | |
bogdanm | 83:8a40adfe8776 | 46 | /*! |
bogdanm | 83:8a40adfe8776 | 47 | * @brief PIT timer configuration structure |
bogdanm | 83:8a40adfe8776 | 48 | * |
bogdanm | 83:8a40adfe8776 | 49 | * Define structure PitConfig and use pit_init_channel() to make necessary |
bogdanm | 83:8a40adfe8776 | 50 | * initializations. You may also use remaining functions for PIT configuration. |
bogdanm | 83:8a40adfe8776 | 51 | * |
bogdanm | 83:8a40adfe8776 | 52 | * @note the timer chain feature is not valid in all devices, please check |
bogdanm | 83:8a40adfe8776 | 53 | * fsl_pit_features.h for accurate setting. If it's not valid, the value set here |
bogdanm | 83:8a40adfe8776 | 54 | * will be bypassed inside function pit_init_channel(). |
bogdanm | 83:8a40adfe8776 | 55 | */ |
bogdanm | 83:8a40adfe8776 | 56 | typedef struct PitUserConfig { |
bogdanm | 83:8a40adfe8776 | 57 | bool isInterruptEnabled; /*!< Timer interrupt 0-disable/1-enable*/ |
bogdanm | 83:8a40adfe8776 | 58 | bool isTimerChained; /*!< Chained with previous timer, 0-not/1-chained*/ |
bogdanm | 83:8a40adfe8776 | 59 | uint32_t periodUs; /*!< Timer period in unit of microseconds*/ |
bogdanm | 83:8a40adfe8776 | 60 | } pit_user_config_t; |
bogdanm | 83:8a40adfe8776 | 61 | |
bogdanm | 83:8a40adfe8776 | 62 | /*! @brief PIT ISR callback function typedef */ |
bogdanm | 83:8a40adfe8776 | 63 | typedef void (*pit_isr_callback_t)(void); |
bogdanm | 83:8a40adfe8776 | 64 | |
bogdanm | 83:8a40adfe8776 | 65 | /******************************************************************************* |
bogdanm | 83:8a40adfe8776 | 66 | * API |
bogdanm | 83:8a40adfe8776 | 67 | ******************************************************************************/ |
bogdanm | 83:8a40adfe8776 | 68 | |
bogdanm | 83:8a40adfe8776 | 69 | #if defined(__cplusplus) |
bogdanm | 83:8a40adfe8776 | 70 | extern "C" { |
bogdanm | 83:8a40adfe8776 | 71 | #endif |
bogdanm | 83:8a40adfe8776 | 72 | |
bogdanm | 83:8a40adfe8776 | 73 | /*! |
bogdanm | 83:8a40adfe8776 | 74 | * @name Initialize and Shutdown |
bogdanm | 83:8a40adfe8776 | 75 | * @{ |
bogdanm | 83:8a40adfe8776 | 76 | */ |
bogdanm | 83:8a40adfe8776 | 77 | |
bogdanm | 83:8a40adfe8776 | 78 | /*! |
bogdanm | 83:8a40adfe8776 | 79 | * @brief Initialize PIT module. |
bogdanm | 83:8a40adfe8776 | 80 | * |
bogdanm | 83:8a40adfe8776 | 81 | * This function must be called before calling all the other PIT driver functions. |
bogdanm | 83:8a40adfe8776 | 82 | * This function un-gates the PIT clock and enables the PIT module. The isRunInDebug |
bogdanm | 83:8a40adfe8776 | 83 | * passed into function will affect all timer channels. |
bogdanm | 83:8a40adfe8776 | 84 | * |
bogdanm | 83:8a40adfe8776 | 85 | * @param isRunInDebug Timers run or stop in debug mode. |
bogdanm | 83:8a40adfe8776 | 86 | * - true: Timers continue to run in debug mode. |
bogdanm | 83:8a40adfe8776 | 87 | * - false: Timers stop in debug mode. |
bogdanm | 83:8a40adfe8776 | 88 | */ |
bogdanm | 83:8a40adfe8776 | 89 | void pit_init_module(bool isRunInDebug); |
bogdanm | 83:8a40adfe8776 | 90 | |
bogdanm | 83:8a40adfe8776 | 91 | /*! |
bogdanm | 83:8a40adfe8776 | 92 | * @brief Initialize PIT channel. |
bogdanm | 83:8a40adfe8776 | 93 | * |
bogdanm | 83:8a40adfe8776 | 94 | * This function initialize PIT timers by channel. Pass in timer number and its |
bogdanm | 83:8a40adfe8776 | 95 | * config structure. Timers do not start counting by default after calling this |
bogdanm | 83:8a40adfe8776 | 96 | * function. Function pit_timer_start must be called to start timer counting. |
bogdanm | 83:8a40adfe8776 | 97 | * Call pit_set_timer_period_us to re-set the period. |
bogdanm | 83:8a40adfe8776 | 98 | * |
bogdanm | 83:8a40adfe8776 | 99 | * Here is an example demonstrating how to define a PIT channel config structure: |
bogdanm | 83:8a40adfe8776 | 100 | @code |
bogdanm | 83:8a40adfe8776 | 101 | pit_user_config_t pitTestInit = { |
bogdanm | 83:8a40adfe8776 | 102 | .isInterruptEnabled = true, |
bogdanm | 83:8a40adfe8776 | 103 | // Only takes effect when chain feature is available. |
bogdanm | 83:8a40adfe8776 | 104 | // Otherwise, pass in arbitrary value(true/false). |
bogdanm | 83:8a40adfe8776 | 105 | .isTimerChained = false, |
bogdanm | 83:8a40adfe8776 | 106 | // In unit of microseconds. |
bogdanm | 83:8a40adfe8776 | 107 | .periodUs = 1000, |
bogdanm | 83:8a40adfe8776 | 108 | }; |
bogdanm | 83:8a40adfe8776 | 109 | @endcode |
bogdanm | 83:8a40adfe8776 | 110 | * |
bogdanm | 83:8a40adfe8776 | 111 | * @param timer Timer channel number. |
bogdanm | 83:8a40adfe8776 | 112 | * @param config PIT channel configuration structure. |
bogdanm | 83:8a40adfe8776 | 113 | */ |
bogdanm | 83:8a40adfe8776 | 114 | void pit_init_channel(uint32_t timer, const pit_user_config_t * config); |
bogdanm | 83:8a40adfe8776 | 115 | |
bogdanm | 83:8a40adfe8776 | 116 | /*! |
bogdanm | 83:8a40adfe8776 | 117 | * @brief Disable PIT module and gate control. |
bogdanm | 83:8a40adfe8776 | 118 | * |
bogdanm | 83:8a40adfe8776 | 119 | * This function disables all PIT interrupts and PIT clock. It then gates the |
bogdanm | 83:8a40adfe8776 | 120 | * PIT clock control. pit_init_module must be called if you want to use PIT again. |
bogdanm | 83:8a40adfe8776 | 121 | */ |
bogdanm | 83:8a40adfe8776 | 122 | void pit_shutdown(void); |
bogdanm | 83:8a40adfe8776 | 123 | |
bogdanm | 83:8a40adfe8776 | 124 | /* @} */ |
bogdanm | 83:8a40adfe8776 | 125 | |
bogdanm | 83:8a40adfe8776 | 126 | /*! |
bogdanm | 83:8a40adfe8776 | 127 | * @name Timer Start and Stop |
bogdanm | 83:8a40adfe8776 | 128 | * @{ |
bogdanm | 83:8a40adfe8776 | 129 | */ |
bogdanm | 83:8a40adfe8776 | 130 | |
bogdanm | 83:8a40adfe8776 | 131 | /*! |
bogdanm | 83:8a40adfe8776 | 132 | * @brief Start timer counting. |
bogdanm | 83:8a40adfe8776 | 133 | * |
bogdanm | 83:8a40adfe8776 | 134 | * After calling this function, timers load period value, count down to 0 and |
bogdanm | 83:8a40adfe8776 | 135 | * then load the respective start value again. Each time a timer reaches 0, |
bogdanm | 83:8a40adfe8776 | 136 | * it generates a trigger pulse and sets the timeout interrupt flag. |
bogdanm | 83:8a40adfe8776 | 137 | * |
bogdanm | 83:8a40adfe8776 | 138 | * @param timer Timer channel number. |
bogdanm | 83:8a40adfe8776 | 139 | */ |
bogdanm | 83:8a40adfe8776 | 140 | void pit_timer_start(uint32_t timer); |
bogdanm | 83:8a40adfe8776 | 141 | |
bogdanm | 83:8a40adfe8776 | 142 | /*! |
bogdanm | 83:8a40adfe8776 | 143 | * @brief Stop timer counting. |
bogdanm | 83:8a40adfe8776 | 144 | * |
bogdanm | 83:8a40adfe8776 | 145 | * This function stops every timer counting. Timers reload their periods |
bogdanm | 83:8a40adfe8776 | 146 | * respectively after the next time they call pit_timer_start. |
bogdanm | 83:8a40adfe8776 | 147 | * |
bogdanm | 83:8a40adfe8776 | 148 | * @param timer Timer channel number. |
bogdanm | 83:8a40adfe8776 | 149 | */ |
bogdanm | 83:8a40adfe8776 | 150 | void pit_timer_stop(uint32_t timer); |
bogdanm | 83:8a40adfe8776 | 151 | |
bogdanm | 83:8a40adfe8776 | 152 | /* @} */ |
bogdanm | 83:8a40adfe8776 | 153 | |
bogdanm | 83:8a40adfe8776 | 154 | /*! |
bogdanm | 83:8a40adfe8776 | 155 | * @name Timer Period |
bogdanm | 83:8a40adfe8776 | 156 | * @{ |
bogdanm | 83:8a40adfe8776 | 157 | */ |
bogdanm | 83:8a40adfe8776 | 158 | |
bogdanm | 83:8a40adfe8776 | 159 | /*! |
bogdanm | 83:8a40adfe8776 | 160 | * @brief Set timer period in microsecond units. |
bogdanm | 83:8a40adfe8776 | 161 | * |
bogdanm | 83:8a40adfe8776 | 162 | * The period range depends on the frequency of PIT source clock. If the required period |
bogdanm | 83:8a40adfe8776 | 163 | * is out of range, use the lifetime timer, if applicable. |
bogdanm | 83:8a40adfe8776 | 164 | * |
bogdanm | 83:8a40adfe8776 | 165 | * @param timer Timer channel number. |
bogdanm | 83:8a40adfe8776 | 166 | * @param us Timer period in microseconds. |
bogdanm | 83:8a40adfe8776 | 167 | */ |
bogdanm | 83:8a40adfe8776 | 168 | void pit_set_timer_period_us(uint32_t timer, uint32_t us); |
bogdanm | 83:8a40adfe8776 | 169 | |
bogdanm | 83:8a40adfe8776 | 170 | /*! |
bogdanm | 83:8a40adfe8776 | 171 | * @brief Read current timer value in microsecond units. |
bogdanm | 83:8a40adfe8776 | 172 | * |
bogdanm | 83:8a40adfe8776 | 173 | * This function returns an absolute time stamp in microsecond units. |
bogdanm | 83:8a40adfe8776 | 174 | * One common use of this function is to measure the running time of a part of |
bogdanm | 83:8a40adfe8776 | 175 | * code. Call this function at both the beginning and end of code; the time |
bogdanm | 83:8a40adfe8776 | 176 | * difference between these two time stamps is the running time (Make sure the |
bogdanm | 83:8a40adfe8776 | 177 | * running time will not exceed the timer period). The time stamp returned is |
bogdanm | 83:8a40adfe8776 | 178 | * up-counting. |
bogdanm | 83:8a40adfe8776 | 179 | * |
bogdanm | 83:8a40adfe8776 | 180 | * @param timer Timer channel number. |
bogdanm | 83:8a40adfe8776 | 181 | * @return Current timer value in microseconds. |
bogdanm | 83:8a40adfe8776 | 182 | */ |
bogdanm | 83:8a40adfe8776 | 183 | uint32_t pit_read_timer_us(uint32_t timer); |
bogdanm | 83:8a40adfe8776 | 184 | |
bogdanm | 83:8a40adfe8776 | 185 | #if FSL_FEATURE_PIT_HAS_LIFETIME_TIMER |
bogdanm | 83:8a40adfe8776 | 186 | /*! |
bogdanm | 83:8a40adfe8776 | 187 | * @brief Set lifetime timer period. |
bogdanm | 83:8a40adfe8776 | 188 | * |
bogdanm | 83:8a40adfe8776 | 189 | * Timer 1 must be chained with timer 0 before using the lifetime timer. The period |
bogdanm | 83:8a40adfe8776 | 190 | * range is restricted by "period * pitSourceClock < max of an uint64_t integer", |
bogdanm | 83:8a40adfe8776 | 191 | * or it may cause an overflow and be unable to set the correct period. |
bogdanm | 83:8a40adfe8776 | 192 | * |
bogdanm | 83:8a40adfe8776 | 193 | * @param period Lifetime timer period in microseconds. |
bogdanm | 83:8a40adfe8776 | 194 | */ |
bogdanm | 83:8a40adfe8776 | 195 | void pit_set_lifetime_timer_period_us(uint64_t us); |
bogdanm | 83:8a40adfe8776 | 196 | |
bogdanm | 83:8a40adfe8776 | 197 | /*! |
bogdanm | 83:8a40adfe8776 | 198 | * @brief Read current lifetime value in microseconds. |
bogdanm | 83:8a40adfe8776 | 199 | * |
bogdanm | 83:8a40adfe8776 | 200 | * This feature returns an absolute time stamp in microsecond units. The time stamp |
bogdanm | 83:8a40adfe8776 | 201 | * value will not exceed the timer period. The timer is up-counting. |
bogdanm | 83:8a40adfe8776 | 202 | * |
bogdanm | 83:8a40adfe8776 | 203 | * @return Current lifetime timer value in microseconds. |
bogdanm | 83:8a40adfe8776 | 204 | */ |
bogdanm | 83:8a40adfe8776 | 205 | uint64_t pit_read_lifetime_timer_us(void); |
bogdanm | 83:8a40adfe8776 | 206 | #endif /*FSL_FEATURE_PIT_HAS_LIFETIME_TIMER*/ |
bogdanm | 83:8a40adfe8776 | 207 | |
bogdanm | 83:8a40adfe8776 | 208 | /* @} */ |
bogdanm | 83:8a40adfe8776 | 209 | |
bogdanm | 83:8a40adfe8776 | 210 | /*! |
bogdanm | 83:8a40adfe8776 | 211 | * @name ISR Callback Function |
bogdanm | 83:8a40adfe8776 | 212 | * @{ |
bogdanm | 83:8a40adfe8776 | 213 | */ |
bogdanm | 83:8a40adfe8776 | 214 | |
bogdanm | 83:8a40adfe8776 | 215 | /*! |
bogdanm | 83:8a40adfe8776 | 216 | * @brief Register pit isr callback function. |
bogdanm | 83:8a40adfe8776 | 217 | * |
bogdanm | 83:8a40adfe8776 | 218 | * System default ISR interfaces are already defined in fsl_pit_irq.c. Users |
bogdanm | 83:8a40adfe8776 | 219 | * can either edit these ISRs or use this function to register a callback |
bogdanm | 83:8a40adfe8776 | 220 | * function. The default ISR runs the callback function if there is one |
bogdanm | 83:8a40adfe8776 | 221 | * installed. |
bogdanm | 83:8a40adfe8776 | 222 | * |
bogdanm | 83:8a40adfe8776 | 223 | * @param timer Timer channel number. |
bogdanm | 83:8a40adfe8776 | 224 | * @param function Pointer to pit isr callback function. |
bogdanm | 83:8a40adfe8776 | 225 | */ |
bogdanm | 83:8a40adfe8776 | 226 | void pit_register_isr_callback_function(uint32_t timer, pit_isr_callback_t function); |
bogdanm | 83:8a40adfe8776 | 227 | |
bogdanm | 83:8a40adfe8776 | 228 | /* @} */ |
bogdanm | 83:8a40adfe8776 | 229 | |
bogdanm | 83:8a40adfe8776 | 230 | #if defined(__cplusplus) |
bogdanm | 83:8a40adfe8776 | 231 | } |
bogdanm | 83:8a40adfe8776 | 232 | #endif |
bogdanm | 83:8a40adfe8776 | 233 | |
bogdanm | 83:8a40adfe8776 | 234 | /*! @}*/ |
bogdanm | 83:8a40adfe8776 | 235 | |
bogdanm | 83:8a40adfe8776 | 236 | #endif /* __FSL_PIT_DRIVER_H__*/ |
bogdanm | 83:8a40adfe8776 | 237 | /******************************************************************************* |
bogdanm | 83:8a40adfe8776 | 238 | * EOF |
bogdanm | 83:8a40adfe8776 | 239 | ******************************************************************************/ |
bogdanm | 83:8a40adfe8776 | 240 |