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