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