mbed library sources. Supersedes mbed-src. Fixed broken STM32F1xx RTC on rtc_api.c
Dependents: Nucleo_F103RB_RTC_battery_bkup_pwr_off_okay
Fork of mbed-dev by
targets/TARGET_Maxim/TARGET_MAX32625/mxc/tmr.h@150:02e0a0aed4ec, 2016-11-08 (annotated)
- Committer:
- <>
- Date:
- Tue Nov 08 17:45:16 2016 +0000
- Revision:
- 150:02e0a0aed4ec
This updates the lib to the mbed lib v129
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 150:02e0a0aed4ec | 1 | /******************************************************************************* |
<> | 150:02e0a0aed4ec | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
<> | 150:02e0a0aed4ec | 3 | * |
<> | 150:02e0a0aed4ec | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
<> | 150:02e0a0aed4ec | 5 | * copy of this software and associated documentation files (the "Software"), |
<> | 150:02e0a0aed4ec | 6 | * to deal in the Software without restriction, including without limitation |
<> | 150:02e0a0aed4ec | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
<> | 150:02e0a0aed4ec | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
<> | 150:02e0a0aed4ec | 9 | * Software is furnished to do so, subject to the following conditions: |
<> | 150:02e0a0aed4ec | 10 | * |
<> | 150:02e0a0aed4ec | 11 | * The above copyright notice and this permission notice shall be included |
<> | 150:02e0a0aed4ec | 12 | * in all copies or substantial portions of the Software. |
<> | 150:02e0a0aed4ec | 13 | * |
<> | 150:02e0a0aed4ec | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
<> | 150:02e0a0aed4ec | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
<> | 150:02e0a0aed4ec | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
<> | 150:02e0a0aed4ec | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
<> | 150:02e0a0aed4ec | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
<> | 150:02e0a0aed4ec | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
<> | 150:02e0a0aed4ec | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
<> | 150:02e0a0aed4ec | 21 | * |
<> | 150:02e0a0aed4ec | 22 | * Except as contained in this notice, the name of Maxim Integrated |
<> | 150:02e0a0aed4ec | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
<> | 150:02e0a0aed4ec | 24 | * Products, Inc. Branding Policy. |
<> | 150:02e0a0aed4ec | 25 | * |
<> | 150:02e0a0aed4ec | 26 | * The mere transfer of this software does not imply any licenses |
<> | 150:02e0a0aed4ec | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
<> | 150:02e0a0aed4ec | 28 | * trademarks, maskwork rights, or any other form of intellectual |
<> | 150:02e0a0aed4ec | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
<> | 150:02e0a0aed4ec | 30 | * ownership rights. |
<> | 150:02e0a0aed4ec | 31 | * |
<> | 150:02e0a0aed4ec | 32 | * $Date: 2016-03-21 14:44:55 -0500 (Mon, 21 Mar 2016) $ |
<> | 150:02e0a0aed4ec | 33 | * $Revision: 22017 $ |
<> | 150:02e0a0aed4ec | 34 | * |
<> | 150:02e0a0aed4ec | 35 | ******************************************************************************/ |
<> | 150:02e0a0aed4ec | 36 | |
<> | 150:02e0a0aed4ec | 37 | /** |
<> | 150:02e0a0aed4ec | 38 | * @file tmr.h |
<> | 150:02e0a0aed4ec | 39 | * @addtogroup timer Timer |
<> | 150:02e0a0aed4ec | 40 | * @{ |
<> | 150:02e0a0aed4ec | 41 | * @brief This is the high level API for the general purpose timer module |
<> | 150:02e0a0aed4ec | 42 | * |
<> | 150:02e0a0aed4ec | 43 | */ |
<> | 150:02e0a0aed4ec | 44 | |
<> | 150:02e0a0aed4ec | 45 | #ifndef _TIMER_H |
<> | 150:02e0a0aed4ec | 46 | #define _TIMER_H |
<> | 150:02e0a0aed4ec | 47 | |
<> | 150:02e0a0aed4ec | 48 | #include "mxc_config.h" |
<> | 150:02e0a0aed4ec | 49 | #include "tmr_regs.h" |
<> | 150:02e0a0aed4ec | 50 | #include "mxc_sys.h" |
<> | 150:02e0a0aed4ec | 51 | |
<> | 150:02e0a0aed4ec | 52 | #ifdef __cplusplus |
<> | 150:02e0a0aed4ec | 53 | extern "C" { |
<> | 150:02e0a0aed4ec | 54 | #endif |
<> | 150:02e0a0aed4ec | 55 | |
<> | 150:02e0a0aed4ec | 56 | ///@brief Define values for units of time |
<> | 150:02e0a0aed4ec | 57 | typedef enum { |
<> | 150:02e0a0aed4ec | 58 | /** nanosecond */ |
<> | 150:02e0a0aed4ec | 59 | TMR_UNIT_NANOSEC = 0, |
<> | 150:02e0a0aed4ec | 60 | /** microsecond */ |
<> | 150:02e0a0aed4ec | 61 | TMR_UNIT_MICROSEC, |
<> | 150:02e0a0aed4ec | 62 | /** millisecond */ |
<> | 150:02e0a0aed4ec | 63 | TMR_UNIT_MILLISEC, |
<> | 150:02e0a0aed4ec | 64 | /** second */ |
<> | 150:02e0a0aed4ec | 65 | TMR_UNIT_SEC, |
<> | 150:02e0a0aed4ec | 66 | } tmr_unit_t; |
<> | 150:02e0a0aed4ec | 67 | |
<> | 150:02e0a0aed4ec | 68 | ///@brief Defines timer modes for 32-bit timers |
<> | 150:02e0a0aed4ec | 69 | typedef enum { |
<> | 150:02e0a0aed4ec | 70 | TMR32_MODE_ONE_SHOT = MXC_V_TMR_CTRL_MODE_ONE_SHOT, |
<> | 150:02e0a0aed4ec | 71 | TMR32_MODE_CONTINUOUS = MXC_V_TMR_CTRL_MODE_CONTINUOUS, |
<> | 150:02e0a0aed4ec | 72 | TMR32_MODE_COUNTER = MXC_V_TMR_CTRL_MODE_COUNTER, |
<> | 150:02e0a0aed4ec | 73 | TMR32_MODE_PWM = MXC_V_TMR_CTRL_MODE_PWM, |
<> | 150:02e0a0aed4ec | 74 | TMR32_MODE_CAPTURE = MXC_V_TMR_CTRL_MODE_CAPTURE, |
<> | 150:02e0a0aed4ec | 75 | TMR32_MODE_COMPARE = MXC_V_TMR_CTRL_MODE_COMPARE, |
<> | 150:02e0a0aed4ec | 76 | TMR32_MODE_GATED = MXC_V_TMR_CTRL_MODE_GATED, |
<> | 150:02e0a0aed4ec | 77 | TMR32_MODE_MEASURE = MXC_V_TMR_CTRL_MODE_MEASURE |
<> | 150:02e0a0aed4ec | 78 | } tmr32_mode_t; |
<> | 150:02e0a0aed4ec | 79 | |
<> | 150:02e0a0aed4ec | 80 | ///@brief Defines timer modes for 16-bit timers |
<> | 150:02e0a0aed4ec | 81 | ///@note 16-bit times only support One Shot and Continuous timers |
<> | 150:02e0a0aed4ec | 82 | typedef enum { |
<> | 150:02e0a0aed4ec | 83 | TMR16_MODE_ONE_SHOT = MXC_V_TMR_CTRL_MODE_ONE_SHOT, |
<> | 150:02e0a0aed4ec | 84 | TMR16_MODE_CONTINUOUS = MXC_V_TMR_CTRL_MODE_CONTINUOUS |
<> | 150:02e0a0aed4ec | 85 | } tmr16_mode_t; |
<> | 150:02e0a0aed4ec | 86 | |
<> | 150:02e0a0aed4ec | 87 | /// @brief Defines prescaler clock divider |
<> | 150:02e0a0aed4ec | 88 | typedef enum { |
<> | 150:02e0a0aed4ec | 89 | // divide input clock by 2^0 = 1 |
<> | 150:02e0a0aed4ec | 90 | TMR_PRESCALE_DIV_2_0 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1, |
<> | 150:02e0a0aed4ec | 91 | // divide input clock by 2^1 = 2 |
<> | 150:02e0a0aed4ec | 92 | TMR_PRESCALE_DIV_2_1 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2, |
<> | 150:02e0a0aed4ec | 93 | // divide input clock by 2^2 = 4 |
<> | 150:02e0a0aed4ec | 94 | TMR_PRESCALE_DIV_2_2 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4, |
<> | 150:02e0a0aed4ec | 95 | // divide input clock by 2^3 = 8 |
<> | 150:02e0a0aed4ec | 96 | TMR_PRESCALE_DIV_2_3 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_8, |
<> | 150:02e0a0aed4ec | 97 | // divide input clock by 2^4 = 16 |
<> | 150:02e0a0aed4ec | 98 | TMR_PRESCALE_DIV_2_4 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_16, |
<> | 150:02e0a0aed4ec | 99 | // divide input clock by 2^5 = 32 |
<> | 150:02e0a0aed4ec | 100 | TMR_PRESCALE_DIV_2_5 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_32, |
<> | 150:02e0a0aed4ec | 101 | // divide input clock by 2^6 = 64 |
<> | 150:02e0a0aed4ec | 102 | TMR_PRESCALE_DIV_2_6 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_64, |
<> | 150:02e0a0aed4ec | 103 | // divide input clock by 2^7 = 128 |
<> | 150:02e0a0aed4ec | 104 | TMR_PRESCALE_DIV_2_7 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_128, |
<> | 150:02e0a0aed4ec | 105 | // divide input clock by 2^8 = 256 |
<> | 150:02e0a0aed4ec | 106 | TMR_PRESCALE_DIV_2_8 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_256, |
<> | 150:02e0a0aed4ec | 107 | // divide input clock by 2^9 = 512 |
<> | 150:02e0a0aed4ec | 108 | TMR_PRESCALE_DIV_2_9 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_512, |
<> | 150:02e0a0aed4ec | 109 | // divide input clock by 2^10 = 1024 |
<> | 150:02e0a0aed4ec | 110 | TMR_PRESCALE_DIV_2_10 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_1024, |
<> | 150:02e0a0aed4ec | 111 | // divide input clock by 2^11 = 2048 |
<> | 150:02e0a0aed4ec | 112 | TMR_PRESCALE_DIV_2_11 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_2048, |
<> | 150:02e0a0aed4ec | 113 | // divide input clock by 2^12 = 4096 |
<> | 150:02e0a0aed4ec | 114 | TMR_PRESCALE_DIV_2_12 = MXC_V_TMR_CTRL_PRESCALE_DIVIDE_BY_4096, |
<> | 150:02e0a0aed4ec | 115 | } tmr_prescale_t; |
<> | 150:02e0a0aed4ec | 116 | |
<> | 150:02e0a0aed4ec | 117 | /// @brief Defines the polarity bit for pwm timer |
<> | 150:02e0a0aed4ec | 118 | typedef enum { |
<> | 150:02e0a0aed4ec | 119 | TMR_POLARITY_UNUSED = 0, |
<> | 150:02e0a0aed4ec | 120 | |
<> | 150:02e0a0aed4ec | 121 | TMR_POLARITY_INIT_LOW = 0, ///GPIO initial output level = low |
<> | 150:02e0a0aed4ec | 122 | TMR_POLARITY_INIT_HIGH = 1, ///GPIO initial output level = high |
<> | 150:02e0a0aed4ec | 123 | |
<> | 150:02e0a0aed4ec | 124 | TMR_POLARITY_RISING_EDGE = 0, ///timer trigger on GPIO rising edge |
<> | 150:02e0a0aed4ec | 125 | TMR_POLARITY_FALLING_EDGE = 1, ///timer trigger on GPIO falling edge |
<> | 150:02e0a0aed4ec | 126 | } tmr_polarity_t; |
<> | 150:02e0a0aed4ec | 127 | |
<> | 150:02e0a0aed4ec | 128 | /// @brief Defines the polarity bit for pwm timer |
<> | 150:02e0a0aed4ec | 129 | typedef enum { |
<> | 150:02e0a0aed4ec | 130 | TMR_PWM_INVERTED = 0, ///duty cycle = low pulse |
<> | 150:02e0a0aed4ec | 131 | TMR_PWM_NONINVERTED, ///duty cycle = high pulse |
<> | 150:02e0a0aed4ec | 132 | } tmr_pwm_polarity_t; |
<> | 150:02e0a0aed4ec | 133 | |
<> | 150:02e0a0aed4ec | 134 | /// @brief 32bit Timer Configurations (non-PWM) |
<> | 150:02e0a0aed4ec | 135 | typedef struct { |
<> | 150:02e0a0aed4ec | 136 | tmr32_mode_t mode; /// Desired timer mode |
<> | 150:02e0a0aed4ec | 137 | tmr_polarity_t polarity; /// Polarity for GPIO |
<> | 150:02e0a0aed4ec | 138 | uint32_t compareCount; /// Ticks to stop, reset back to 1, or compare timer |
<> | 150:02e0a0aed4ec | 139 | } tmr32_cfg_t; |
<> | 150:02e0a0aed4ec | 140 | |
<> | 150:02e0a0aed4ec | 141 | /// @brief PWM Mode Configurations |
<> | 150:02e0a0aed4ec | 142 | typedef struct { |
<> | 150:02e0a0aed4ec | 143 | tmr_pwm_polarity_t polarity; /// PWM polarity |
<> | 150:02e0a0aed4ec | 144 | uint32_t periodCount; /// PWM period in timer counts |
<> | 150:02e0a0aed4ec | 145 | uint32_t dutyCount; /// PWM duty in timer counts |
<> | 150:02e0a0aed4ec | 146 | } tmr32_cfg_pwm_t; |
<> | 150:02e0a0aed4ec | 147 | |
<> | 150:02e0a0aed4ec | 148 | /// @brief 16bit Timer Configurations |
<> | 150:02e0a0aed4ec | 149 | typedef struct { |
<> | 150:02e0a0aed4ec | 150 | tmr16_mode_t mode; /// Desired timer mode (only supports one shot or continuous timers) |
<> | 150:02e0a0aed4ec | 151 | uint16_t compareCount; /// Ticks to stop or reset timer |
<> | 150:02e0a0aed4ec | 152 | } tmr16_cfg_t; |
<> | 150:02e0a0aed4ec | 153 | |
<> | 150:02e0a0aed4ec | 154 | |
<> | 150:02e0a0aed4ec | 155 | |
<> | 150:02e0a0aed4ec | 156 | /** |
<> | 150:02e0a0aed4ec | 157 | * @brief Initializes the timer to a known state. |
<> | 150:02e0a0aed4ec | 158 | * @details This function initializes the timer to a known state and saves the |
<> | 150:02e0a0aed4ec | 159 | * prescaler. The timer will be left disabled. TMR_Init should be called |
<> | 150:02e0a0aed4ec | 160 | * before TMR_Config. |
<> | 150:02e0a0aed4ec | 161 | * |
<> | 150:02e0a0aed4ec | 162 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 163 | * @param prescale clock divider for the timer clock |
<> | 150:02e0a0aed4ec | 164 | * @param cfg pointer to timer system GPIO configuration |
<> | 150:02e0a0aed4ec | 165 | * (can be NULL if not using GPIO timer input/output functions) |
<> | 150:02e0a0aed4ec | 166 | * |
<> | 150:02e0a0aed4ec | 167 | * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. |
<> | 150:02e0a0aed4ec | 168 | */ |
<> | 150:02e0a0aed4ec | 169 | int TMR_Init(mxc_tmr_regs_t *tmr, tmr_prescale_t prescale, const sys_cfg_tmr_t *sysCfg); |
<> | 150:02e0a0aed4ec | 170 | |
<> | 150:02e0a0aed4ec | 171 | /** |
<> | 150:02e0a0aed4ec | 172 | * @brief Configures the timer in the specified mode. |
<> | 150:02e0a0aed4ec | 173 | * @details The parameters in config structure must be set before calling this function. |
<> | 150:02e0a0aed4ec | 174 | * This function should be used for configuring the timer in all 32 bit modes other than PWM. |
<> | 150:02e0a0aed4ec | 175 | * @note The timer cannot be running when this function is called |
<> | 150:02e0a0aed4ec | 176 | * |
<> | 150:02e0a0aed4ec | 177 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 178 | * @param config pointer to timer configuration |
<> | 150:02e0a0aed4ec | 179 | * |
<> | 150:02e0a0aed4ec | 180 | */ |
<> | 150:02e0a0aed4ec | 181 | void TMR32_Config(mxc_tmr_regs_t *tmr, const tmr32_cfg_t *config); |
<> | 150:02e0a0aed4ec | 182 | |
<> | 150:02e0a0aed4ec | 183 | /** |
<> | 150:02e0a0aed4ec | 184 | * @brief Configures the timer in PWM mode. |
<> | 150:02e0a0aed4ec | 185 | * @details The parameters in config structure must be set before calling this function. |
<> | 150:02e0a0aed4ec | 186 | * This function should be used for configuring the timer in PWM mode only. |
<> | 150:02e0a0aed4ec | 187 | * @note The timer cannot be running when this function is called |
<> | 150:02e0a0aed4ec | 188 | * |
<> | 150:02e0a0aed4ec | 189 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 190 | * @param config pointer to timer configuration |
<> | 150:02e0a0aed4ec | 191 | * |
<> | 150:02e0a0aed4ec | 192 | */ |
<> | 150:02e0a0aed4ec | 193 | void TMR32_PWMConfig(mxc_tmr_regs_t *tmr, const tmr32_cfg_pwm_t *config); |
<> | 150:02e0a0aed4ec | 194 | |
<> | 150:02e0a0aed4ec | 195 | /** |
<> | 150:02e0a0aed4ec | 196 | * @brief Configures the timer in the specified mode. |
<> | 150:02e0a0aed4ec | 197 | * @details The parameters in config structure must be set before calling this function. |
<> | 150:02e0a0aed4ec | 198 | * This function should be used for configuring the timer in all 16 bit modes. |
<> | 150:02e0a0aed4ec | 199 | * @note The timer cannot be running when this function is called |
<> | 150:02e0a0aed4ec | 200 | * |
<> | 150:02e0a0aed4ec | 201 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 202 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 203 | * @param config pointer to timer configuration |
<> | 150:02e0a0aed4ec | 204 | * |
<> | 150:02e0a0aed4ec | 205 | */ |
<> | 150:02e0a0aed4ec | 206 | void TMR16_Config(mxc_tmr_regs_t *tmr, uint8_t index, const tmr16_cfg_t *config); |
<> | 150:02e0a0aed4ec | 207 | |
<> | 150:02e0a0aed4ec | 208 | /** |
<> | 150:02e0a0aed4ec | 209 | * @brief Starts the specified timer. |
<> | 150:02e0a0aed4ec | 210 | * |
<> | 150:02e0a0aed4ec | 211 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 212 | * |
<> | 150:02e0a0aed4ec | 213 | */ |
<> | 150:02e0a0aed4ec | 214 | void TMR32_Start(mxc_tmr_regs_t *tmr); |
<> | 150:02e0a0aed4ec | 215 | |
<> | 150:02e0a0aed4ec | 216 | /** |
<> | 150:02e0a0aed4ec | 217 | * @brief Starts the specified timer. |
<> | 150:02e0a0aed4ec | 218 | * |
<> | 150:02e0a0aed4ec | 219 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 220 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 221 | * |
<> | 150:02e0a0aed4ec | 222 | */ |
<> | 150:02e0a0aed4ec | 223 | void TMR16_Start(mxc_tmr_regs_t *tmr, uint8_t index); |
<> | 150:02e0a0aed4ec | 224 | |
<> | 150:02e0a0aed4ec | 225 | /** |
<> | 150:02e0a0aed4ec | 226 | * @brief Stops the specified 32 bit timer. |
<> | 150:02e0a0aed4ec | 227 | * @details All other timer states are left unchanged. |
<> | 150:02e0a0aed4ec | 228 | * |
<> | 150:02e0a0aed4ec | 229 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 230 | * |
<> | 150:02e0a0aed4ec | 231 | */ |
<> | 150:02e0a0aed4ec | 232 | __STATIC_INLINE void TMR32_Stop(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 233 | { |
<> | 150:02e0a0aed4ec | 234 | tmr->ctrl &= ~MXC_F_TMR_CTRL_ENABLE0; |
<> | 150:02e0a0aed4ec | 235 | } |
<> | 150:02e0a0aed4ec | 236 | |
<> | 150:02e0a0aed4ec | 237 | /** |
<> | 150:02e0a0aed4ec | 238 | * @brief Stop the specified 16 bit timer. |
<> | 150:02e0a0aed4ec | 239 | * @details All other timer states are left unchanged. |
<> | 150:02e0a0aed4ec | 240 | * |
<> | 150:02e0a0aed4ec | 241 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 242 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 243 | * |
<> | 150:02e0a0aed4ec | 244 | */ |
<> | 150:02e0a0aed4ec | 245 | __STATIC_INLINE void TMR16_Stop(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 246 | { |
<> | 150:02e0a0aed4ec | 247 | if(index) |
<> | 150:02e0a0aed4ec | 248 | tmr->ctrl &= ~MXC_F_TMR_CTRL_ENABLE1; |
<> | 150:02e0a0aed4ec | 249 | else |
<> | 150:02e0a0aed4ec | 250 | tmr->ctrl &= ~MXC_F_TMR_CTRL_ENABLE0; |
<> | 150:02e0a0aed4ec | 251 | } |
<> | 150:02e0a0aed4ec | 252 | |
<> | 150:02e0a0aed4ec | 253 | /** |
<> | 150:02e0a0aed4ec | 254 | * @brief Determines if the timer is running |
<> | 150:02e0a0aed4ec | 255 | * |
<> | 150:02e0a0aed4ec | 256 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 257 | * |
<> | 150:02e0a0aed4ec | 258 | * @return 0 = timer is off, non-zero = timer is on |
<> | 150:02e0a0aed4ec | 259 | */ |
<> | 150:02e0a0aed4ec | 260 | __STATIC_INLINE uint32_t TMR32_IsActive(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 261 | { |
<> | 150:02e0a0aed4ec | 262 | return (tmr->ctrl & MXC_F_TMR_CTRL_ENABLE0); |
<> | 150:02e0a0aed4ec | 263 | } |
<> | 150:02e0a0aed4ec | 264 | |
<> | 150:02e0a0aed4ec | 265 | /** |
<> | 150:02e0a0aed4ec | 266 | * @brief Determines if the timer is running |
<> | 150:02e0a0aed4ec | 267 | * |
<> | 150:02e0a0aed4ec | 268 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 269 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 270 | * |
<> | 150:02e0a0aed4ec | 271 | * @return 0 = timer is off, non-zero = timer is on |
<> | 150:02e0a0aed4ec | 272 | */ |
<> | 150:02e0a0aed4ec | 273 | __STATIC_INLINE uint32_t TMR16_IsActive(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 274 | { |
<> | 150:02e0a0aed4ec | 275 | if(index) |
<> | 150:02e0a0aed4ec | 276 | return (tmr->ctrl & MXC_F_TMR_CTRL_ENABLE1); |
<> | 150:02e0a0aed4ec | 277 | else |
<> | 150:02e0a0aed4ec | 278 | return (tmr->ctrl & MXC_F_TMR_CTRL_ENABLE0); |
<> | 150:02e0a0aed4ec | 279 | } |
<> | 150:02e0a0aed4ec | 280 | |
<> | 150:02e0a0aed4ec | 281 | /** |
<> | 150:02e0a0aed4ec | 282 | * @brief Enables the timer's interrupt |
<> | 150:02e0a0aed4ec | 283 | * |
<> | 150:02e0a0aed4ec | 284 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 285 | * |
<> | 150:02e0a0aed4ec | 286 | */ |
<> | 150:02e0a0aed4ec | 287 | __STATIC_INLINE void TMR32_EnableINT(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 288 | { |
<> | 150:02e0a0aed4ec | 289 | tmr->inten |= MXC_F_TMR_INTEN_TIMER0; |
<> | 150:02e0a0aed4ec | 290 | } |
<> | 150:02e0a0aed4ec | 291 | |
<> | 150:02e0a0aed4ec | 292 | /** |
<> | 150:02e0a0aed4ec | 293 | * @brief Enables the timer's interrupt |
<> | 150:02e0a0aed4ec | 294 | * |
<> | 150:02e0a0aed4ec | 295 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 296 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 297 | * |
<> | 150:02e0a0aed4ec | 298 | */ |
<> | 150:02e0a0aed4ec | 299 | __STATIC_INLINE void TMR16_EnableINT(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 300 | { |
<> | 150:02e0a0aed4ec | 301 | if(index) |
<> | 150:02e0a0aed4ec | 302 | tmr->inten |= MXC_F_TMR_INTEN_TIMER1; |
<> | 150:02e0a0aed4ec | 303 | else |
<> | 150:02e0a0aed4ec | 304 | tmr->inten |= MXC_F_TMR_INTEN_TIMER0; |
<> | 150:02e0a0aed4ec | 305 | } |
<> | 150:02e0a0aed4ec | 306 | |
<> | 150:02e0a0aed4ec | 307 | /** |
<> | 150:02e0a0aed4ec | 308 | * @brief Disables the timer's interrupt |
<> | 150:02e0a0aed4ec | 309 | * |
<> | 150:02e0a0aed4ec | 310 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 311 | * |
<> | 150:02e0a0aed4ec | 312 | */ |
<> | 150:02e0a0aed4ec | 313 | __STATIC_INLINE void TMR32_DisableINT(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 314 | { |
<> | 150:02e0a0aed4ec | 315 | tmr->inten &= ~MXC_F_TMR_INTEN_TIMER0; |
<> | 150:02e0a0aed4ec | 316 | } |
<> | 150:02e0a0aed4ec | 317 | |
<> | 150:02e0a0aed4ec | 318 | /** |
<> | 150:02e0a0aed4ec | 319 | * @brief Disables the timer's interrupt |
<> | 150:02e0a0aed4ec | 320 | * |
<> | 150:02e0a0aed4ec | 321 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 322 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 323 | * |
<> | 150:02e0a0aed4ec | 324 | */ |
<> | 150:02e0a0aed4ec | 325 | __STATIC_INLINE void TMR16_DisableINT(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 326 | { |
<> | 150:02e0a0aed4ec | 327 | if(index) |
<> | 150:02e0a0aed4ec | 328 | tmr->inten &= ~MXC_F_TMR_INTEN_TIMER1; |
<> | 150:02e0a0aed4ec | 329 | else |
<> | 150:02e0a0aed4ec | 330 | tmr->inten &= ~MXC_F_TMR_INTEN_TIMER0; |
<> | 150:02e0a0aed4ec | 331 | } |
<> | 150:02e0a0aed4ec | 332 | |
<> | 150:02e0a0aed4ec | 333 | /** |
<> | 150:02e0a0aed4ec | 334 | * @brief Gets the timer's interrupt flag |
<> | 150:02e0a0aed4ec | 335 | * |
<> | 150:02e0a0aed4ec | 336 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 337 | * |
<> | 150:02e0a0aed4ec | 338 | * @return 0 = flag not set, non-zero = flag is set |
<> | 150:02e0a0aed4ec | 339 | */ |
<> | 150:02e0a0aed4ec | 340 | __STATIC_INLINE uint32_t TMR32_GetFlag(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 341 | { |
<> | 150:02e0a0aed4ec | 342 | return (tmr->intfl & MXC_F_TMR_INTFL_TIMER0); |
<> | 150:02e0a0aed4ec | 343 | } |
<> | 150:02e0a0aed4ec | 344 | |
<> | 150:02e0a0aed4ec | 345 | /** |
<> | 150:02e0a0aed4ec | 346 | * @brief Gets the timer's interrupt flag |
<> | 150:02e0a0aed4ec | 347 | * |
<> | 150:02e0a0aed4ec | 348 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 349 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 350 | * |
<> | 150:02e0a0aed4ec | 351 | * @return 0 = flag not set, non-zero = flag is set |
<> | 150:02e0a0aed4ec | 352 | */ |
<> | 150:02e0a0aed4ec | 353 | __STATIC_INLINE uint32_t TMR16_GetFlag(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 354 | { |
<> | 150:02e0a0aed4ec | 355 | if(index) |
<> | 150:02e0a0aed4ec | 356 | return (tmr->intfl & MXC_F_TMR_INTFL_TIMER1); |
<> | 150:02e0a0aed4ec | 357 | else |
<> | 150:02e0a0aed4ec | 358 | return (tmr->intfl & MXC_F_TMR_INTFL_TIMER0); |
<> | 150:02e0a0aed4ec | 359 | } |
<> | 150:02e0a0aed4ec | 360 | |
<> | 150:02e0a0aed4ec | 361 | /** |
<> | 150:02e0a0aed4ec | 362 | * @brief Clears the timer interrupt flag |
<> | 150:02e0a0aed4ec | 363 | * |
<> | 150:02e0a0aed4ec | 364 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 365 | * |
<> | 150:02e0a0aed4ec | 366 | */ |
<> | 150:02e0a0aed4ec | 367 | __STATIC_INLINE void TMR32_ClearFlag(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 368 | { |
<> | 150:02e0a0aed4ec | 369 | tmr->intfl = MXC_F_TMR_INTFL_TIMER0; |
<> | 150:02e0a0aed4ec | 370 | } |
<> | 150:02e0a0aed4ec | 371 | |
<> | 150:02e0a0aed4ec | 372 | /** |
<> | 150:02e0a0aed4ec | 373 | * @brief Clears the timer interrupt flag for the specified index |
<> | 150:02e0a0aed4ec | 374 | * |
<> | 150:02e0a0aed4ec | 375 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 376 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 377 | * |
<> | 150:02e0a0aed4ec | 378 | */ |
<> | 150:02e0a0aed4ec | 379 | __STATIC_INLINE void TMR16_ClearFlag(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 380 | { |
<> | 150:02e0a0aed4ec | 381 | if(index) |
<> | 150:02e0a0aed4ec | 382 | tmr->intfl = MXC_F_TMR_INTFL_TIMER1; |
<> | 150:02e0a0aed4ec | 383 | else |
<> | 150:02e0a0aed4ec | 384 | tmr->intfl = MXC_F_TMR_INTFL_TIMER0; |
<> | 150:02e0a0aed4ec | 385 | } |
<> | 150:02e0a0aed4ec | 386 | |
<> | 150:02e0a0aed4ec | 387 | /** |
<> | 150:02e0a0aed4ec | 388 | * @brief Set the current tick value to start counting from. |
<> | 150:02e0a0aed4ec | 389 | * |
<> | 150:02e0a0aed4ec | 390 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 391 | * @param count value to set the current ticks |
<> | 150:02e0a0aed4ec | 392 | * |
<> | 150:02e0a0aed4ec | 393 | */ |
<> | 150:02e0a0aed4ec | 394 | __STATIC_INLINE void TMR32_SetCount(mxc_tmr_regs_t *tmr, uint32_t count) |
<> | 150:02e0a0aed4ec | 395 | { |
<> | 150:02e0a0aed4ec | 396 | tmr->count32 = count; |
<> | 150:02e0a0aed4ec | 397 | } |
<> | 150:02e0a0aed4ec | 398 | |
<> | 150:02e0a0aed4ec | 399 | /** |
<> | 150:02e0a0aed4ec | 400 | * @brief Set the current tick value to start counting from. |
<> | 150:02e0a0aed4ec | 401 | * |
<> | 150:02e0a0aed4ec | 402 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 403 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 404 | * @param count value to set the current ticks |
<> | 150:02e0a0aed4ec | 405 | * |
<> | 150:02e0a0aed4ec | 406 | */ |
<> | 150:02e0a0aed4ec | 407 | __STATIC_INLINE void TMR16_SetCount(mxc_tmr_regs_t *tmr, uint8_t index, uint16_t count) |
<> | 150:02e0a0aed4ec | 408 | { |
<> | 150:02e0a0aed4ec | 409 | if (index) |
<> | 150:02e0a0aed4ec | 410 | tmr->count16_1 = count; |
<> | 150:02e0a0aed4ec | 411 | else |
<> | 150:02e0a0aed4ec | 412 | tmr->count16_0 = count; |
<> | 150:02e0a0aed4ec | 413 | } |
<> | 150:02e0a0aed4ec | 414 | |
<> | 150:02e0a0aed4ec | 415 | /** |
<> | 150:02e0a0aed4ec | 416 | * @brief Gets the most current count value. |
<> | 150:02e0a0aed4ec | 417 | * |
<> | 150:02e0a0aed4ec | 418 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 419 | * |
<> | 150:02e0a0aed4ec | 420 | * @return current count value in ticks |
<> | 150:02e0a0aed4ec | 421 | */ |
<> | 150:02e0a0aed4ec | 422 | __STATIC_INLINE uint32_t TMR32_GetCount(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 423 | { |
<> | 150:02e0a0aed4ec | 424 | return (tmr->count32); |
<> | 150:02e0a0aed4ec | 425 | } |
<> | 150:02e0a0aed4ec | 426 | |
<> | 150:02e0a0aed4ec | 427 | /** |
<> | 150:02e0a0aed4ec | 428 | * @brief Gets the most current count value. |
<> | 150:02e0a0aed4ec | 429 | * |
<> | 150:02e0a0aed4ec | 430 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 431 | * @param index selects which 16 bit timer(0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 432 | * |
<> | 150:02e0a0aed4ec | 433 | * @return current count value in ticks |
<> | 150:02e0a0aed4ec | 434 | */ |
<> | 150:02e0a0aed4ec | 435 | __STATIC_INLINE uint32_t TMR16_GetCount(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 436 | { |
<> | 150:02e0a0aed4ec | 437 | if(index) |
<> | 150:02e0a0aed4ec | 438 | return tmr->count16_1; |
<> | 150:02e0a0aed4ec | 439 | else |
<> | 150:02e0a0aed4ec | 440 | return tmr->count16_0; |
<> | 150:02e0a0aed4ec | 441 | } |
<> | 150:02e0a0aed4ec | 442 | |
<> | 150:02e0a0aed4ec | 443 | /** |
<> | 150:02e0a0aed4ec | 444 | * @brief Gets the most recent capture value. |
<> | 150:02e0a0aed4ec | 445 | * @details Used in Capture or Measure timer modes |
<> | 150:02e0a0aed4ec | 446 | * |
<> | 150:02e0a0aed4ec | 447 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 448 | * |
<> | 150:02e0a0aed4ec | 449 | * @return capture value in ticks |
<> | 150:02e0a0aed4ec | 450 | */ |
<> | 150:02e0a0aed4ec | 451 | __STATIC_INLINE uint32_t TMR32_GetCapture(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 452 | { |
<> | 150:02e0a0aed4ec | 453 | return (tmr->pwm_cap32); |
<> | 150:02e0a0aed4ec | 454 | } |
<> | 150:02e0a0aed4ec | 455 | |
<> | 150:02e0a0aed4ec | 456 | /** |
<> | 150:02e0a0aed4ec | 457 | * @brief Set a new compare tick value for timer |
<> | 150:02e0a0aed4ec | 458 | * @details Depending on the timer mode this is the tick value to |
<> | 150:02e0a0aed4ec | 459 | * stop the timer, reset ticks to 1, or compare the timer |
<> | 150:02e0a0aed4ec | 460 | * |
<> | 150:02e0a0aed4ec | 461 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 462 | * @param count new terminal/compare value in timer counts |
<> | 150:02e0a0aed4ec | 463 | * |
<> | 150:02e0a0aed4ec | 464 | */ |
<> | 150:02e0a0aed4ec | 465 | __STATIC_INLINE void TMR32_SetCompare(mxc_tmr_regs_t *tmr, uint32_t count) |
<> | 150:02e0a0aed4ec | 466 | { |
<> | 150:02e0a0aed4ec | 467 | tmr->term_cnt32 = count; |
<> | 150:02e0a0aed4ec | 468 | } |
<> | 150:02e0a0aed4ec | 469 | |
<> | 150:02e0a0aed4ec | 470 | /** |
<> | 150:02e0a0aed4ec | 471 | * @brief Get compare tick value for timer |
<> | 150:02e0a0aed4ec | 472 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 473 | * @return compare value in ticks |
<> | 150:02e0a0aed4ec | 474 | * |
<> | 150:02e0a0aed4ec | 475 | */ |
<> | 150:02e0a0aed4ec | 476 | __STATIC_INLINE uint32_t TMR32_GetCompare(mxc_tmr_regs_t *tmr) |
<> | 150:02e0a0aed4ec | 477 | { |
<> | 150:02e0a0aed4ec | 478 | return tmr->term_cnt32; |
<> | 150:02e0a0aed4ec | 479 | } |
<> | 150:02e0a0aed4ec | 480 | |
<> | 150:02e0a0aed4ec | 481 | /** |
<> | 150:02e0a0aed4ec | 482 | * @brief Set a new compare tick value for timer |
<> | 150:02e0a0aed4ec | 483 | * @details Depending on the timer mode this is the tick value to |
<> | 150:02e0a0aed4ec | 484 | * stop the timer, reset ticks to 1, or compare the timer |
<> | 150:02e0a0aed4ec | 485 | * |
<> | 150:02e0a0aed4ec | 486 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 487 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 488 | * @param count new terminal/compare value in timer counts |
<> | 150:02e0a0aed4ec | 489 | * |
<> | 150:02e0a0aed4ec | 490 | */ |
<> | 150:02e0a0aed4ec | 491 | __STATIC_INLINE void TMR16_SetCompare(mxc_tmr_regs_t *tmr, uint8_t index, uint16_t count) |
<> | 150:02e0a0aed4ec | 492 | { |
<> | 150:02e0a0aed4ec | 493 | if (index) |
<> | 150:02e0a0aed4ec | 494 | tmr->term_cnt16_1 = count; |
<> | 150:02e0a0aed4ec | 495 | else |
<> | 150:02e0a0aed4ec | 496 | tmr->term_cnt16_0 = count; |
<> | 150:02e0a0aed4ec | 497 | } |
<> | 150:02e0a0aed4ec | 498 | |
<> | 150:02e0a0aed4ec | 499 | /** |
<> | 150:02e0a0aed4ec | 500 | * @brief Get compare tick value for timer |
<> | 150:02e0a0aed4ec | 501 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 502 | * @param index selects which 16 bit timer (0 = 16_0 or 1 = 16_1) |
<> | 150:02e0a0aed4ec | 503 | * @return compare value in ticks |
<> | 150:02e0a0aed4ec | 504 | * |
<> | 150:02e0a0aed4ec | 505 | */ |
<> | 150:02e0a0aed4ec | 506 | __STATIC_INLINE uint32_t TMR16_GetCompare(mxc_tmr_regs_t *tmr, uint8_t index) |
<> | 150:02e0a0aed4ec | 507 | { |
<> | 150:02e0a0aed4ec | 508 | if (index) |
<> | 150:02e0a0aed4ec | 509 | return tmr->term_cnt16_1; |
<> | 150:02e0a0aed4ec | 510 | return tmr->term_cnt16_0; |
<> | 150:02e0a0aed4ec | 511 | } |
<> | 150:02e0a0aed4ec | 512 | |
<> | 150:02e0a0aed4ec | 513 | /** |
<> | 150:02e0a0aed4ec | 514 | * @brief Returns the prescale value used by the timer |
<> | 150:02e0a0aed4ec | 515 | * |
<> | 150:02e0a0aed4ec | 516 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 517 | * |
<> | 150:02e0a0aed4ec | 518 | * @returns prescaler |
<> | 150:02e0a0aed4ec | 519 | */ |
<> | 150:02e0a0aed4ec | 520 | uint32_t TMR_GetPrescaler(mxc_tmr_regs_t *tmr); |
<> | 150:02e0a0aed4ec | 521 | |
<> | 150:02e0a0aed4ec | 522 | /** |
<> | 150:02e0a0aed4ec | 523 | * @brief Set a new duty cycle when the timer is used in PWM mode. |
<> | 150:02e0a0aed4ec | 524 | * |
<> | 150:02e0a0aed4ec | 525 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 526 | * @param dutyCount duty cycle value in timer counts |
<> | 150:02e0a0aed4ec | 527 | * |
<> | 150:02e0a0aed4ec | 528 | */ |
<> | 150:02e0a0aed4ec | 529 | __STATIC_INLINE void TMR32_SetDuty(mxc_tmr_regs_t *tmr, uint32_t dutyCount) |
<> | 150:02e0a0aed4ec | 530 | { |
<> | 150:02e0a0aed4ec | 531 | tmr->pwm_cap32 = dutyCount; |
<> | 150:02e0a0aed4ec | 532 | } |
<> | 150:02e0a0aed4ec | 533 | |
<> | 150:02e0a0aed4ec | 534 | /** |
<> | 150:02e0a0aed4ec | 535 | * @brief Set a new duty cycle when the timer is used in PWM mode. |
<> | 150:02e0a0aed4ec | 536 | * |
<> | 150:02e0a0aed4ec | 537 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 538 | * @param dutyPercent duty cycle value in percent (0 to 100%) |
<> | 150:02e0a0aed4ec | 539 | * |
<> | 150:02e0a0aed4ec | 540 | */ |
<> | 150:02e0a0aed4ec | 541 | __STATIC_INLINE void TMR32_SetDutyPer(mxc_tmr_regs_t *tmr, uint32_t dutyPercent) |
<> | 150:02e0a0aed4ec | 542 | { |
<> | 150:02e0a0aed4ec | 543 | uint32_t periodCount = tmr->term_cnt32; |
<> | 150:02e0a0aed4ec | 544 | tmr->pwm_cap32 = ((uint64_t)periodCount * dutyPercent) / 100; |
<> | 150:02e0a0aed4ec | 545 | } |
<> | 150:02e0a0aed4ec | 546 | |
<> | 150:02e0a0aed4ec | 547 | /** |
<> | 150:02e0a0aed4ec | 548 | * @brief Set a new period value for PWM timer |
<> | 150:02e0a0aed4ec | 549 | * |
<> | 150:02e0a0aed4ec | 550 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 551 | * @param count new period value in timer counts |
<> | 150:02e0a0aed4ec | 552 | * |
<> | 150:02e0a0aed4ec | 553 | */ |
<> | 150:02e0a0aed4ec | 554 | __STATIC_INLINE void TMR32_SetPeriod(mxc_tmr_regs_t *tmr, uint32_t period) |
<> | 150:02e0a0aed4ec | 555 | { |
<> | 150:02e0a0aed4ec | 556 | tmr->term_cnt32 = period; |
<> | 150:02e0a0aed4ec | 557 | } |
<> | 150:02e0a0aed4ec | 558 | |
<> | 150:02e0a0aed4ec | 559 | /** |
<> | 150:02e0a0aed4ec | 560 | * @brief Converts frequency and duty cycle % to period and duty ticks |
<> | 150:02e0a0aed4ec | 561 | * @note TMR_Init should be called before this function to set the prescaler |
<> | 150:02e0a0aed4ec | 562 | * |
<> | 150:02e0a0aed4ec | 563 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 564 | * @param dutyPercent duty cycle in percent (0 to 100%) |
<> | 150:02e0a0aed4ec | 565 | * @param freq frequency of pwm signal in Hz |
<> | 150:02e0a0aed4ec | 566 | * @param dutyTicks calculated duty cycle in ticks |
<> | 150:02e0a0aed4ec | 567 | * @param periodTicks calculated period in ticks |
<> | 150:02e0a0aed4ec | 568 | * |
<> | 150:02e0a0aed4ec | 569 | * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. |
<> | 150:02e0a0aed4ec | 570 | * |
<> | 150:02e0a0aed4ec | 571 | */ |
<> | 150:02e0a0aed4ec | 572 | int TMR32_GetPWMTicks(mxc_tmr_regs_t *tmr, uint8_t dutyPercent, uint32_t freq, uint32_t *dutyTicks, uint32_t *periodTicks); |
<> | 150:02e0a0aed4ec | 573 | |
<> | 150:02e0a0aed4ec | 574 | /** |
<> | 150:02e0a0aed4ec | 575 | * @brief Converts a time and units to a number of ticks for the 32-bit timer. |
<> | 150:02e0a0aed4ec | 576 | * @note TMR_Init should be called before this function to set the prescaler |
<> | 150:02e0a0aed4ec | 577 | * |
<> | 150:02e0a0aed4ec | 578 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 579 | * @param time time value. |
<> | 150:02e0a0aed4ec | 580 | * @param unit time units. |
<> | 150:02e0a0aed4ec | 581 | * @param ticks calculated number of ticks. |
<> | 150:02e0a0aed4ec | 582 | * |
<> | 150:02e0a0aed4ec | 583 | * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. |
<> | 150:02e0a0aed4ec | 584 | */ |
<> | 150:02e0a0aed4ec | 585 | int TMR32_TimeToTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint32_t *ticks); |
<> | 150:02e0a0aed4ec | 586 | |
<> | 150:02e0a0aed4ec | 587 | /** |
<> | 150:02e0a0aed4ec | 588 | * @brief Converts a time and units to a number of ticks for the 16-bit timer. |
<> | 150:02e0a0aed4ec | 589 | * @note TMR_Init should be called before this function to set the prescaler |
<> | 150:02e0a0aed4ec | 590 | * |
<> | 150:02e0a0aed4ec | 591 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 592 | * @param time time value. |
<> | 150:02e0a0aed4ec | 593 | * @param unit time units. |
<> | 150:02e0a0aed4ec | 594 | * @param ticks calculated number of ticks. |
<> | 150:02e0a0aed4ec | 595 | * |
<> | 150:02e0a0aed4ec | 596 | * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. |
<> | 150:02e0a0aed4ec | 597 | */ |
<> | 150:02e0a0aed4ec | 598 | int TMR16_TimeToTicks(mxc_tmr_regs_t *tmr, uint32_t time, tmr_unit_t units, uint16_t *ticks); |
<> | 150:02e0a0aed4ec | 599 | |
<> | 150:02e0a0aed4ec | 600 | /** |
<> | 150:02e0a0aed4ec | 601 | * @brief Converts a number of ticks to a time and units for the timer. |
<> | 150:02e0a0aed4ec | 602 | * @note TMR_Init should be called before this function to set the prescaler |
<> | 150:02e0a0aed4ec | 603 | * |
<> | 150:02e0a0aed4ec | 604 | * @param tmr timer module to operate on |
<> | 150:02e0a0aed4ec | 605 | * @param ticks number of ticks. |
<> | 150:02e0a0aed4ec | 606 | * @param time calculated time value. |
<> | 150:02e0a0aed4ec | 607 | * @param units calculated time units. |
<> | 150:02e0a0aed4ec | 608 | * |
<> | 150:02e0a0aed4ec | 609 | * @returns #E_NO_ERROR if everything is successful, error if unsuccessful. |
<> | 150:02e0a0aed4ec | 610 | */ |
<> | 150:02e0a0aed4ec | 611 | int TMR_TicksToTime(mxc_tmr_regs_t *tmr, uint32_t ticks, uint32_t *time, tmr_unit_t *units); |
<> | 150:02e0a0aed4ec | 612 | |
<> | 150:02e0a0aed4ec | 613 | /** @} */ |
<> | 150:02e0a0aed4ec | 614 | |
<> | 150:02e0a0aed4ec | 615 | #ifdef __cplusplus |
<> | 150:02e0a0aed4ec | 616 | } |
<> | 150:02e0a0aed4ec | 617 | #endif |
<> | 150:02e0a0aed4ec | 618 | |
<> | 150:02e0a0aed4ec | 619 | #endif /* _TIMER_H */ |