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