Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_timer.h@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file timer.h |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V3.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 10 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 15/08/11 10:26a $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief M451 series Timer driver header file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #ifndef __TIMER_H__ |
sahilmgandhi | 18:6a4db94011d3 | 12 | #define __TIMER_H__ |
sahilmgandhi | 18:6a4db94011d3 | 13 | |
sahilmgandhi | 18:6a4db94011d3 | 14 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 15 | extern "C" |
sahilmgandhi | 18:6a4db94011d3 | 16 | { |
sahilmgandhi | 18:6a4db94011d3 | 17 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | |
sahilmgandhi | 18:6a4db94011d3 | 20 | /** @addtogroup Standard_Driver Standard Driver |
sahilmgandhi | 18:6a4db94011d3 | 21 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 22 | */ |
sahilmgandhi | 18:6a4db94011d3 | 23 | |
sahilmgandhi | 18:6a4db94011d3 | 24 | /** @addtogroup TIMER_Driver TIMER Driver |
sahilmgandhi | 18:6a4db94011d3 | 25 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 26 | */ |
sahilmgandhi | 18:6a4db94011d3 | 27 | |
sahilmgandhi | 18:6a4db94011d3 | 28 | /** @addtogroup TIMER_EXPORTED_CONSTANTS TIMER Exported Constants |
sahilmgandhi | 18:6a4db94011d3 | 29 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 30 | */ |
sahilmgandhi | 18:6a4db94011d3 | 31 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 32 | /* TIMER Operation Mode, External Counter and Capture Mode Constant Definitions */ |
sahilmgandhi | 18:6a4db94011d3 | 33 | /*---------------------------------------------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 34 | #define TIMER_ONESHOT_MODE (0UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in one-shot mode */ |
sahilmgandhi | 18:6a4db94011d3 | 35 | #define TIMER_PERIODIC_MODE (1UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in periodic mode */ |
sahilmgandhi | 18:6a4db94011d3 | 36 | #define TIMER_TOGGLE_MODE (2UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in toggle-output mode */ |
sahilmgandhi | 18:6a4db94011d3 | 37 | #define TIMER_CONTINUOUS_MODE (3UL << TIMER_CTL_OPMODE_Pos) /*!< Timer working in continuous counting mode */ |
sahilmgandhi | 18:6a4db94011d3 | 38 | #define TIMER_TOUT_PIN_FROM_TX (0UL << TIMER_CTL_TGLPINSEL_Pos) /*!< Timer toggle-output pin is from Tx pin */ |
sahilmgandhi | 18:6a4db94011d3 | 39 | #define TIMER_TOUT_PIN_FROM_TX_EXT (1UL << TIMER_CTL_TGLPINSEL_Pos) /*!< Timer toggle-output pin is from Tx_EXT pin */ |
sahilmgandhi | 18:6a4db94011d3 | 40 | #define TIMER_CAPTURE_FREE_COUNTING_MODE (0UL << TIMER_EXTCTL_CAPFUNCS_Pos) /*!< Timer capture event to get timer counter value */ |
sahilmgandhi | 18:6a4db94011d3 | 41 | #define TIMER_CAPTURE_COUNTER_RESET_MODE (1UL << TIMER_EXTCTL_CAPFUNCS_Pos) /*!< Timer capture event to reset timer counter */ |
sahilmgandhi | 18:6a4db94011d3 | 42 | #define TIMER_CAPTURE_FALLING_EDGE (0UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< Falling edge detection to trigger timer capture */ |
sahilmgandhi | 18:6a4db94011d3 | 43 | #define TIMER_CAPTURE_RISING_EDGE (1UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< Rising edge detection to trigger timer capture */ |
sahilmgandhi | 18:6a4db94011d3 | 44 | #define TIMER_CAPTURE_FALLING_AND_RISING_EDGE (2UL << TIMER_EXTCTL_CAPEDGE_Pos) /*!< Both falling and rising edge detection to trigger timer capture */ |
sahilmgandhi | 18:6a4db94011d3 | 45 | #define TIMER_COUNTER_FALLING_EDGE (0UL << TIMER_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on falling edge detection */ |
sahilmgandhi | 18:6a4db94011d3 | 46 | #define TIMER_COUNTER_RISING_EDGE (1UL << TIMER_EXTCTL_CNTPHASE_Pos) /*!< Counter increase on rising edge detection */ |
sahilmgandhi | 18:6a4db94011d3 | 47 | |
sahilmgandhi | 18:6a4db94011d3 | 48 | /*@}*/ /* end of group TIMER_EXPORTED_CONSTANTS */ |
sahilmgandhi | 18:6a4db94011d3 | 49 | |
sahilmgandhi | 18:6a4db94011d3 | 50 | |
sahilmgandhi | 18:6a4db94011d3 | 51 | /** @addtogroup TIMER_EXPORTED_FUNCTIONS TIMER Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 52 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 53 | */ |
sahilmgandhi | 18:6a4db94011d3 | 54 | |
sahilmgandhi | 18:6a4db94011d3 | 55 | /** |
sahilmgandhi | 18:6a4db94011d3 | 56 | * @brief Set Timer Compared Value |
sahilmgandhi | 18:6a4db94011d3 | 57 | * |
sahilmgandhi | 18:6a4db94011d3 | 58 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 59 | * @param[in] u32Value Timer compare value. Valid values are between 2 to 0xFFFFFF. |
sahilmgandhi | 18:6a4db94011d3 | 60 | * |
sahilmgandhi | 18:6a4db94011d3 | 61 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 62 | * |
sahilmgandhi | 18:6a4db94011d3 | 63 | * @details This macro is used to set timer compared value to adjust timer time-out interval. |
sahilmgandhi | 18:6a4db94011d3 | 64 | * @note 1. Never write 0x0 or 0x1 in this field, or the core will run into unknown state. \n |
sahilmgandhi | 18:6a4db94011d3 | 65 | * 2. If update timer compared value in continuous counting mode, timer counter value will keep counting continuously. \n |
sahilmgandhi | 18:6a4db94011d3 | 66 | * But if timer is operating at other modes, the timer up counter will restart counting and start from 0. |
sahilmgandhi | 18:6a4db94011d3 | 67 | */ |
sahilmgandhi | 18:6a4db94011d3 | 68 | #define TIMER_SET_CMP_VALUE(timer, u32Value) ((timer)->CMP = (u32Value)) |
sahilmgandhi | 18:6a4db94011d3 | 69 | |
sahilmgandhi | 18:6a4db94011d3 | 70 | /** |
sahilmgandhi | 18:6a4db94011d3 | 71 | * @brief Set Timer Prescale Value |
sahilmgandhi | 18:6a4db94011d3 | 72 | * |
sahilmgandhi | 18:6a4db94011d3 | 73 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 74 | * @param[in] u32Value Timer prescale value. Valid values are between 0 to 0xFF. |
sahilmgandhi | 18:6a4db94011d3 | 75 | * |
sahilmgandhi | 18:6a4db94011d3 | 76 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 77 | * |
sahilmgandhi | 18:6a4db94011d3 | 78 | * @details This macro is used to set timer prescale value and timer source clock will be divided by (prescale + 1) \n |
sahilmgandhi | 18:6a4db94011d3 | 79 | * before it is fed into timer. |
sahilmgandhi | 18:6a4db94011d3 | 80 | */ |
sahilmgandhi | 18:6a4db94011d3 | 81 | #define TIMER_SET_PRESCALE_VALUE(timer, u32Value) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_PSC_Msk) | (u32Value)) |
sahilmgandhi | 18:6a4db94011d3 | 82 | |
sahilmgandhi | 18:6a4db94011d3 | 83 | /** |
sahilmgandhi | 18:6a4db94011d3 | 84 | * @brief Check specify Timer Status |
sahilmgandhi | 18:6a4db94011d3 | 85 | * |
sahilmgandhi | 18:6a4db94011d3 | 86 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 87 | * |
sahilmgandhi | 18:6a4db94011d3 | 88 | * @retval 0 Timer 24-bit up counter is inactive |
sahilmgandhi | 18:6a4db94011d3 | 89 | * @retval 1 Timer 24-bit up counter is active |
sahilmgandhi | 18:6a4db94011d3 | 90 | * |
sahilmgandhi | 18:6a4db94011d3 | 91 | * @details This macro is used to check if specify Timer counter is inactive or active. |
sahilmgandhi | 18:6a4db94011d3 | 92 | */ |
sahilmgandhi | 18:6a4db94011d3 | 93 | #define TIMER_IS_ACTIVE(timer) (((timer)->CTL & TIMER_CTL_ACTSTS_Msk)? 1 : 0) |
sahilmgandhi | 18:6a4db94011d3 | 94 | |
sahilmgandhi | 18:6a4db94011d3 | 95 | /** |
sahilmgandhi | 18:6a4db94011d3 | 96 | * @brief Select Toggle-output Pin |
sahilmgandhi | 18:6a4db94011d3 | 97 | * |
sahilmgandhi | 18:6a4db94011d3 | 98 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 99 | * @param[in] u32ToutSel Toggle-output pin selection, valid values are: |
sahilmgandhi | 18:6a4db94011d3 | 100 | * - \ref TIMER_TOUT_PIN_FROM_TX |
sahilmgandhi | 18:6a4db94011d3 | 101 | * - \ref TIMER_TOUT_PIN_FROM_TX_EXT |
sahilmgandhi | 18:6a4db94011d3 | 102 | * |
sahilmgandhi | 18:6a4db94011d3 | 103 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 104 | * |
sahilmgandhi | 18:6a4db94011d3 | 105 | * @details This macro is used to select timer toggle-output pin is output on Tx or Tx_EXT pin. |
sahilmgandhi | 18:6a4db94011d3 | 106 | */ |
sahilmgandhi | 18:6a4db94011d3 | 107 | #define TIMER_SELECT_TOUT_PIN(timer, u32ToutSel) ((timer)->CTL = ((timer)->CTL & ~TIMER_CTL_TGLPINSEL_Msk) | (u32ToutSel)) |
sahilmgandhi | 18:6a4db94011d3 | 108 | |
sahilmgandhi | 18:6a4db94011d3 | 109 | /** |
sahilmgandhi | 18:6a4db94011d3 | 110 | * @brief Start Timer Counting |
sahilmgandhi | 18:6a4db94011d3 | 111 | * |
sahilmgandhi | 18:6a4db94011d3 | 112 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 113 | * |
sahilmgandhi | 18:6a4db94011d3 | 114 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 115 | * |
sahilmgandhi | 18:6a4db94011d3 | 116 | * @details This function is used to start Timer counting. |
sahilmgandhi | 18:6a4db94011d3 | 117 | */ |
sahilmgandhi | 18:6a4db94011d3 | 118 | static __INLINE void TIMER_Start(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 119 | { |
sahilmgandhi | 18:6a4db94011d3 | 120 | timer->CTL |= TIMER_CTL_CNTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 121 | } |
sahilmgandhi | 18:6a4db94011d3 | 122 | |
sahilmgandhi | 18:6a4db94011d3 | 123 | /** |
sahilmgandhi | 18:6a4db94011d3 | 124 | * @brief Stop Timer Counting |
sahilmgandhi | 18:6a4db94011d3 | 125 | * |
sahilmgandhi | 18:6a4db94011d3 | 126 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 127 | * |
sahilmgandhi | 18:6a4db94011d3 | 128 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 129 | * |
sahilmgandhi | 18:6a4db94011d3 | 130 | * @details This function is used to stop/suspend Timer counting. |
sahilmgandhi | 18:6a4db94011d3 | 131 | */ |
sahilmgandhi | 18:6a4db94011d3 | 132 | static __INLINE void TIMER_Stop(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 133 | { |
sahilmgandhi | 18:6a4db94011d3 | 134 | timer->CTL &= ~TIMER_CTL_CNTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 135 | } |
sahilmgandhi | 18:6a4db94011d3 | 136 | |
sahilmgandhi | 18:6a4db94011d3 | 137 | /** |
sahilmgandhi | 18:6a4db94011d3 | 138 | * @brief Enable Timer Interrupt Wake-up Function |
sahilmgandhi | 18:6a4db94011d3 | 139 | * |
sahilmgandhi | 18:6a4db94011d3 | 140 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 141 | * |
sahilmgandhi | 18:6a4db94011d3 | 142 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 143 | * |
sahilmgandhi | 18:6a4db94011d3 | 144 | * @details This function is used to enable the timer interrupt wake-up function and interrupt source could be time-out interrupt, \n |
sahilmgandhi | 18:6a4db94011d3 | 145 | * counter event interrupt or capture trigger interrupt. |
sahilmgandhi | 18:6a4db94011d3 | 146 | * @note To wake the system from Power-down mode, timer clock source must be ether LXT or LIRC. |
sahilmgandhi | 18:6a4db94011d3 | 147 | */ |
sahilmgandhi | 18:6a4db94011d3 | 148 | static __INLINE void TIMER_EnableWakeup(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 149 | { |
sahilmgandhi | 18:6a4db94011d3 | 150 | timer->CTL |= TIMER_CTL_WKEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 151 | } |
sahilmgandhi | 18:6a4db94011d3 | 152 | |
sahilmgandhi | 18:6a4db94011d3 | 153 | /** |
sahilmgandhi | 18:6a4db94011d3 | 154 | * @brief Disable Timer Wake-up Function |
sahilmgandhi | 18:6a4db94011d3 | 155 | * |
sahilmgandhi | 18:6a4db94011d3 | 156 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 157 | * |
sahilmgandhi | 18:6a4db94011d3 | 158 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 159 | * |
sahilmgandhi | 18:6a4db94011d3 | 160 | * @details This function is used to disable the timer interrupt wake-up function. |
sahilmgandhi | 18:6a4db94011d3 | 161 | */ |
sahilmgandhi | 18:6a4db94011d3 | 162 | static __INLINE void TIMER_DisableWakeup(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 163 | { |
sahilmgandhi | 18:6a4db94011d3 | 164 | timer->CTL &= ~TIMER_CTL_WKEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 165 | } |
sahilmgandhi | 18:6a4db94011d3 | 166 | |
sahilmgandhi | 18:6a4db94011d3 | 167 | /** |
sahilmgandhi | 18:6a4db94011d3 | 168 | * @brief Enable Capture Pin De-bounce |
sahilmgandhi | 18:6a4db94011d3 | 169 | * |
sahilmgandhi | 18:6a4db94011d3 | 170 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 171 | * |
sahilmgandhi | 18:6a4db94011d3 | 172 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 173 | * |
sahilmgandhi | 18:6a4db94011d3 | 174 | * @details This function is used to enable the detect de-bounce function of capture pin. |
sahilmgandhi | 18:6a4db94011d3 | 175 | */ |
sahilmgandhi | 18:6a4db94011d3 | 176 | static __INLINE void TIMER_EnableCaptureDebounce(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 177 | { |
sahilmgandhi | 18:6a4db94011d3 | 178 | timer->EXTCTL |= TIMER_EXTCTL_CAPDBEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 179 | } |
sahilmgandhi | 18:6a4db94011d3 | 180 | |
sahilmgandhi | 18:6a4db94011d3 | 181 | /** |
sahilmgandhi | 18:6a4db94011d3 | 182 | * @brief Disable Capture Pin De-bounce |
sahilmgandhi | 18:6a4db94011d3 | 183 | * |
sahilmgandhi | 18:6a4db94011d3 | 184 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 185 | * |
sahilmgandhi | 18:6a4db94011d3 | 186 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 187 | * |
sahilmgandhi | 18:6a4db94011d3 | 188 | * @details This function is used to disable the detect de-bounce function of capture pin. |
sahilmgandhi | 18:6a4db94011d3 | 189 | */ |
sahilmgandhi | 18:6a4db94011d3 | 190 | static __INLINE void TIMER_DisableCaptureDebounce(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 191 | { |
sahilmgandhi | 18:6a4db94011d3 | 192 | timer->EXTCTL &= ~TIMER_EXTCTL_CAPDBEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 193 | } |
sahilmgandhi | 18:6a4db94011d3 | 194 | |
sahilmgandhi | 18:6a4db94011d3 | 195 | /** |
sahilmgandhi | 18:6a4db94011d3 | 196 | * @brief Enable Counter Pin De-bounce |
sahilmgandhi | 18:6a4db94011d3 | 197 | * |
sahilmgandhi | 18:6a4db94011d3 | 198 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 199 | * |
sahilmgandhi | 18:6a4db94011d3 | 200 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 201 | * |
sahilmgandhi | 18:6a4db94011d3 | 202 | * @details This function is used to enable the detect de-bounce function of counter pin. |
sahilmgandhi | 18:6a4db94011d3 | 203 | */ |
sahilmgandhi | 18:6a4db94011d3 | 204 | static __INLINE void TIMER_EnableEventCounterDebounce(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 205 | { |
sahilmgandhi | 18:6a4db94011d3 | 206 | timer->EXTCTL |= TIMER_EXTCTL_CNTDBEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 207 | } |
sahilmgandhi | 18:6a4db94011d3 | 208 | |
sahilmgandhi | 18:6a4db94011d3 | 209 | /** |
sahilmgandhi | 18:6a4db94011d3 | 210 | * @brief Disable Counter Pin De-bounce |
sahilmgandhi | 18:6a4db94011d3 | 211 | * |
sahilmgandhi | 18:6a4db94011d3 | 212 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 213 | * |
sahilmgandhi | 18:6a4db94011d3 | 214 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 215 | * |
sahilmgandhi | 18:6a4db94011d3 | 216 | * @details This function is used to disable the detect de-bounce function of counter pin. |
sahilmgandhi | 18:6a4db94011d3 | 217 | */ |
sahilmgandhi | 18:6a4db94011d3 | 218 | static __INLINE void TIMER_DisableEventCounterDebounce(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 219 | { |
sahilmgandhi | 18:6a4db94011d3 | 220 | timer->EXTCTL &= ~TIMER_EXTCTL_CNTDBEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 221 | } |
sahilmgandhi | 18:6a4db94011d3 | 222 | |
sahilmgandhi | 18:6a4db94011d3 | 223 | /** |
sahilmgandhi | 18:6a4db94011d3 | 224 | * @brief Enable Timer Time-out Interrupt |
sahilmgandhi | 18:6a4db94011d3 | 225 | * |
sahilmgandhi | 18:6a4db94011d3 | 226 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 227 | * |
sahilmgandhi | 18:6a4db94011d3 | 228 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 229 | * |
sahilmgandhi | 18:6a4db94011d3 | 230 | * @details This function is used to enable the timer time-out interrupt function. |
sahilmgandhi | 18:6a4db94011d3 | 231 | */ |
sahilmgandhi | 18:6a4db94011d3 | 232 | static __INLINE void TIMER_EnableInt(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 233 | { |
sahilmgandhi | 18:6a4db94011d3 | 234 | timer->CTL |= TIMER_CTL_INTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 235 | } |
sahilmgandhi | 18:6a4db94011d3 | 236 | |
sahilmgandhi | 18:6a4db94011d3 | 237 | /** |
sahilmgandhi | 18:6a4db94011d3 | 238 | * @brief Disable Timer Time-out Interrupt |
sahilmgandhi | 18:6a4db94011d3 | 239 | * |
sahilmgandhi | 18:6a4db94011d3 | 240 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 241 | * |
sahilmgandhi | 18:6a4db94011d3 | 242 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 243 | * |
sahilmgandhi | 18:6a4db94011d3 | 244 | * @details This function is used to disable the timer time-out interrupt function. |
sahilmgandhi | 18:6a4db94011d3 | 245 | */ |
sahilmgandhi | 18:6a4db94011d3 | 246 | static __INLINE void TIMER_DisableInt(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 247 | { |
sahilmgandhi | 18:6a4db94011d3 | 248 | timer->CTL &= ~TIMER_CTL_INTEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 249 | } |
sahilmgandhi | 18:6a4db94011d3 | 250 | |
sahilmgandhi | 18:6a4db94011d3 | 251 | /** |
sahilmgandhi | 18:6a4db94011d3 | 252 | * @brief Enable Capture Trigger Interrupt |
sahilmgandhi | 18:6a4db94011d3 | 253 | * |
sahilmgandhi | 18:6a4db94011d3 | 254 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 255 | * |
sahilmgandhi | 18:6a4db94011d3 | 256 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 257 | * |
sahilmgandhi | 18:6a4db94011d3 | 258 | * @details This function is used to enable the timer capture trigger interrupt function. |
sahilmgandhi | 18:6a4db94011d3 | 259 | */ |
sahilmgandhi | 18:6a4db94011d3 | 260 | static __INLINE void TIMER_EnableCaptureInt(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 261 | { |
sahilmgandhi | 18:6a4db94011d3 | 262 | timer->EXTCTL |= TIMER_EXTCTL_CAPIEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 263 | } |
sahilmgandhi | 18:6a4db94011d3 | 264 | |
sahilmgandhi | 18:6a4db94011d3 | 265 | /** |
sahilmgandhi | 18:6a4db94011d3 | 266 | * @brief Disable Capture Trigger Interrupt |
sahilmgandhi | 18:6a4db94011d3 | 267 | * |
sahilmgandhi | 18:6a4db94011d3 | 268 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 269 | * |
sahilmgandhi | 18:6a4db94011d3 | 270 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 271 | * |
sahilmgandhi | 18:6a4db94011d3 | 272 | * @details This function is used to disable the timer capture trigger interrupt function. |
sahilmgandhi | 18:6a4db94011d3 | 273 | */ |
sahilmgandhi | 18:6a4db94011d3 | 274 | static __INLINE void TIMER_DisableCaptureInt(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 275 | { |
sahilmgandhi | 18:6a4db94011d3 | 276 | timer->EXTCTL &= ~TIMER_EXTCTL_CAPIEN_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 277 | } |
sahilmgandhi | 18:6a4db94011d3 | 278 | |
sahilmgandhi | 18:6a4db94011d3 | 279 | /** |
sahilmgandhi | 18:6a4db94011d3 | 280 | * @brief Get Timer Time-out Interrupt Flag |
sahilmgandhi | 18:6a4db94011d3 | 281 | * |
sahilmgandhi | 18:6a4db94011d3 | 282 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 283 | * |
sahilmgandhi | 18:6a4db94011d3 | 284 | * @retval 0 Timer time-out interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 285 | * @retval 1 Timer time-out interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 286 | * |
sahilmgandhi | 18:6a4db94011d3 | 287 | * @details This function indicates timer time-out interrupt occurred or not. |
sahilmgandhi | 18:6a4db94011d3 | 288 | */ |
sahilmgandhi | 18:6a4db94011d3 | 289 | static __INLINE uint32_t TIMER_GetIntFlag(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 290 | { |
sahilmgandhi | 18:6a4db94011d3 | 291 | return ((timer->INTSTS & TIMER_INTSTS_TIF_Msk) ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 292 | } |
sahilmgandhi | 18:6a4db94011d3 | 293 | |
sahilmgandhi | 18:6a4db94011d3 | 294 | /** |
sahilmgandhi | 18:6a4db94011d3 | 295 | * @brief Clear Timer Time-out Interrupt Flag |
sahilmgandhi | 18:6a4db94011d3 | 296 | * |
sahilmgandhi | 18:6a4db94011d3 | 297 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 298 | * |
sahilmgandhi | 18:6a4db94011d3 | 299 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 300 | * |
sahilmgandhi | 18:6a4db94011d3 | 301 | * @details This function clears timer time-out interrupt flag to 0. |
sahilmgandhi | 18:6a4db94011d3 | 302 | */ |
sahilmgandhi | 18:6a4db94011d3 | 303 | static __INLINE void TIMER_ClearIntFlag(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 304 | { |
sahilmgandhi | 18:6a4db94011d3 | 305 | timer->INTSTS = (timer->INTSTS & ~TIMER_INTSTS_TWKF_Msk) | TIMER_INTSTS_TIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 306 | } |
sahilmgandhi | 18:6a4db94011d3 | 307 | |
sahilmgandhi | 18:6a4db94011d3 | 308 | /** |
sahilmgandhi | 18:6a4db94011d3 | 309 | * @brief Get Timer Capture Interrupt Flag |
sahilmgandhi | 18:6a4db94011d3 | 310 | * |
sahilmgandhi | 18:6a4db94011d3 | 311 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 312 | * |
sahilmgandhi | 18:6a4db94011d3 | 313 | * @retval 0 Timer capture interrupt did not occur |
sahilmgandhi | 18:6a4db94011d3 | 314 | * @retval 1 Timer capture interrupt occurred |
sahilmgandhi | 18:6a4db94011d3 | 315 | * |
sahilmgandhi | 18:6a4db94011d3 | 316 | * @details This function indicates timer capture trigger interrupt occurred or not. |
sahilmgandhi | 18:6a4db94011d3 | 317 | */ |
sahilmgandhi | 18:6a4db94011d3 | 318 | static __INLINE uint32_t TIMER_GetCaptureIntFlag(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 319 | { |
sahilmgandhi | 18:6a4db94011d3 | 320 | return timer->EINTSTS; |
sahilmgandhi | 18:6a4db94011d3 | 321 | } |
sahilmgandhi | 18:6a4db94011d3 | 322 | |
sahilmgandhi | 18:6a4db94011d3 | 323 | /** |
sahilmgandhi | 18:6a4db94011d3 | 324 | * @brief Clear Timer Capture Interrupt Flag |
sahilmgandhi | 18:6a4db94011d3 | 325 | * |
sahilmgandhi | 18:6a4db94011d3 | 326 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 327 | * |
sahilmgandhi | 18:6a4db94011d3 | 328 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 329 | * |
sahilmgandhi | 18:6a4db94011d3 | 330 | * @details This function clears timer capture trigger interrupt flag to 0. |
sahilmgandhi | 18:6a4db94011d3 | 331 | */ |
sahilmgandhi | 18:6a4db94011d3 | 332 | static __INLINE void TIMER_ClearCaptureIntFlag(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 333 | { |
sahilmgandhi | 18:6a4db94011d3 | 334 | timer->EINTSTS = TIMER_EINTSTS_CAPIF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 335 | } |
sahilmgandhi | 18:6a4db94011d3 | 336 | |
sahilmgandhi | 18:6a4db94011d3 | 337 | /** |
sahilmgandhi | 18:6a4db94011d3 | 338 | * @brief Get Timer Wake-up Flag |
sahilmgandhi | 18:6a4db94011d3 | 339 | * |
sahilmgandhi | 18:6a4db94011d3 | 340 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 341 | * |
sahilmgandhi | 18:6a4db94011d3 | 342 | * @retval 0 Timer does not cause CPU wake-up |
sahilmgandhi | 18:6a4db94011d3 | 343 | * @retval 1 Timer interrupt event cause CPU wake-up |
sahilmgandhi | 18:6a4db94011d3 | 344 | * |
sahilmgandhi | 18:6a4db94011d3 | 345 | * @details This function indicates timer interrupt event has waked up system or not. |
sahilmgandhi | 18:6a4db94011d3 | 346 | */ |
sahilmgandhi | 18:6a4db94011d3 | 347 | static __INLINE uint32_t TIMER_GetWakeupFlag(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 348 | { |
sahilmgandhi | 18:6a4db94011d3 | 349 | return (timer->INTSTS & TIMER_INTSTS_TWKF_Msk ? 1 : 0); |
sahilmgandhi | 18:6a4db94011d3 | 350 | } |
sahilmgandhi | 18:6a4db94011d3 | 351 | |
sahilmgandhi | 18:6a4db94011d3 | 352 | /** |
sahilmgandhi | 18:6a4db94011d3 | 353 | * @brief Clear Timer Wake-up Flag |
sahilmgandhi | 18:6a4db94011d3 | 354 | * |
sahilmgandhi | 18:6a4db94011d3 | 355 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 356 | * |
sahilmgandhi | 18:6a4db94011d3 | 357 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 358 | * |
sahilmgandhi | 18:6a4db94011d3 | 359 | * @details This function clears the timer wake-up system flag to 0. |
sahilmgandhi | 18:6a4db94011d3 | 360 | */ |
sahilmgandhi | 18:6a4db94011d3 | 361 | static __INLINE void TIMER_ClearWakeupFlag(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 362 | { |
sahilmgandhi | 18:6a4db94011d3 | 363 | timer->INTSTS = (timer->INTSTS & ~TIMER_INTSTS_TIF_Msk) | TIMER_INTSTS_TWKF_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 364 | } |
sahilmgandhi | 18:6a4db94011d3 | 365 | |
sahilmgandhi | 18:6a4db94011d3 | 366 | /** |
sahilmgandhi | 18:6a4db94011d3 | 367 | * @brief Get Capture value |
sahilmgandhi | 18:6a4db94011d3 | 368 | * |
sahilmgandhi | 18:6a4db94011d3 | 369 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 370 | * |
sahilmgandhi | 18:6a4db94011d3 | 371 | * @return 24-bit Capture Value |
sahilmgandhi | 18:6a4db94011d3 | 372 | * |
sahilmgandhi | 18:6a4db94011d3 | 373 | * @details This function reports the current 24-bit timer capture value. |
sahilmgandhi | 18:6a4db94011d3 | 374 | */ |
sahilmgandhi | 18:6a4db94011d3 | 375 | static __INLINE uint32_t TIMER_GetCaptureData(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 376 | { |
sahilmgandhi | 18:6a4db94011d3 | 377 | return timer->CAP; |
sahilmgandhi | 18:6a4db94011d3 | 378 | } |
sahilmgandhi | 18:6a4db94011d3 | 379 | |
sahilmgandhi | 18:6a4db94011d3 | 380 | /** |
sahilmgandhi | 18:6a4db94011d3 | 381 | * @brief Get Counter value |
sahilmgandhi | 18:6a4db94011d3 | 382 | * |
sahilmgandhi | 18:6a4db94011d3 | 383 | * @param[in] timer The pointer of the specified Timer module. It could be TIMER0, TIMER1, TIMER2, TIMER3. |
sahilmgandhi | 18:6a4db94011d3 | 384 | * |
sahilmgandhi | 18:6a4db94011d3 | 385 | * @return 24-bit Counter Value |
sahilmgandhi | 18:6a4db94011d3 | 386 | * |
sahilmgandhi | 18:6a4db94011d3 | 387 | * @details This function reports the current 24-bit timer counter value. |
sahilmgandhi | 18:6a4db94011d3 | 388 | */ |
sahilmgandhi | 18:6a4db94011d3 | 389 | static __INLINE uint32_t TIMER_GetCounter(TIMER_T *timer) |
sahilmgandhi | 18:6a4db94011d3 | 390 | { |
sahilmgandhi | 18:6a4db94011d3 | 391 | return timer->CNT; |
sahilmgandhi | 18:6a4db94011d3 | 392 | } |
sahilmgandhi | 18:6a4db94011d3 | 393 | |
sahilmgandhi | 18:6a4db94011d3 | 394 | uint32_t TIMER_Open(TIMER_T *timer, uint32_t u32Mode, uint32_t u32Freq); |
sahilmgandhi | 18:6a4db94011d3 | 395 | void TIMER_Close(TIMER_T *timer); |
sahilmgandhi | 18:6a4db94011d3 | 396 | void TIMER_Delay(TIMER_T *timer, uint32_t u32Usec); |
sahilmgandhi | 18:6a4db94011d3 | 397 | void TIMER_EnableCapture(TIMER_T *timer, uint32_t u32CapMode, uint32_t u32Edge); |
sahilmgandhi | 18:6a4db94011d3 | 398 | void TIMER_DisableCapture(TIMER_T *timer); |
sahilmgandhi | 18:6a4db94011d3 | 399 | void TIMER_EnableEventCounter(TIMER_T *timer, uint32_t u32Edge); |
sahilmgandhi | 18:6a4db94011d3 | 400 | void TIMER_DisableEventCounter(TIMER_T *timer); |
sahilmgandhi | 18:6a4db94011d3 | 401 | uint32_t TIMER_GetModuleClock(TIMER_T *timer); |
sahilmgandhi | 18:6a4db94011d3 | 402 | |
sahilmgandhi | 18:6a4db94011d3 | 403 | /*@}*/ /* end of group TIMER_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 404 | |
sahilmgandhi | 18:6a4db94011d3 | 405 | /*@}*/ /* end of group TIMER_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 406 | |
sahilmgandhi | 18:6a4db94011d3 | 407 | /*@}*/ /* end of group Standard_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 408 | |
sahilmgandhi | 18:6a4db94011d3 | 409 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 410 | } |
sahilmgandhi | 18:6a4db94011d3 | 411 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 412 | |
sahilmgandhi | 18:6a4db94011d3 | 413 | #endif //__TIMER_H__ |
sahilmgandhi | 18:6a4db94011d3 | 414 | |
sahilmgandhi | 18:6a4db94011d3 | 415 | /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/ |