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