MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / TIMER_Init

Function TIMER_Init

bsp/efm32/Libraries/emlib/src/em_timer.c:130–165  ·  view source on GitHub ↗

/ * @brief * Initialize TIMER. * * @details * Notice that counter top must be configured separately with for instance * TIMER_TopSet(). In addition, compare/capture and dead-time insertion * init must be initialized separately if used. That should probably * be done prior to the use of this function if configuring the TIMER to * start when initialization is completed. * * @pa

Source from the content-addressed store, hash-verified

128 * Pointer to TIMER initialization structure.
129 ******************************************************************************/
130void TIMER_Init(TIMER_TypeDef *timer, const TIMER_Init_TypeDef *init)
131{
132 EFM_ASSERT(TIMER_REF_VALID(timer));
133
134 /* Stop timer if specified to be disabled (dosn't hurt if already stopped) */
135 if (!(init->enable))
136 {
137 timer->CMD = TIMER_CMD_STOP;
138 }
139
140 /* Reset counter */
141 timer->CNT = _TIMER_CNT_RESETVALUE;
142
143 timer->CTRL =
144 ((uint32_t)(init->prescale) << _TIMER_CTRL_PRESC_SHIFT) |
145 ((uint32_t)(init->clkSel) << _TIMER_CTRL_CLKSEL_SHIFT) |
146 ((uint32_t)(init->fallAction) << _TIMER_CTRL_FALLA_SHIFT) |
147 ((uint32_t)(init->riseAction) << _TIMER_CTRL_RISEA_SHIFT) |
148 ((uint32_t)(init->mode) << _TIMER_CTRL_MODE_SHIFT) |
149 (init->debugRun ? TIMER_CTRL_DEBUGRUN : 0) |
150 (init->dmaClrAct ? TIMER_CTRL_DMACLRACT : 0) |
151 (init->quadModeX4 ? TIMER_CTRL_QDM_X4 : 0) |
152 (init->oneShot ? TIMER_CTRL_OSMEN : 0) |
153
154#if defined(_EFM32_GIANT_FAMILY) || defined(_EFM32_TINY_FAMILY)
155 (init->count2x ? TIMER_CTRL_X2CNT : 0) |
156 (init->ati ? TIMER_CTRL_ATI : 0) |
157#endif
158 (init->sync ? TIMER_CTRL_SYNC : 0);
159
160 /* Start timer if specified to be enabled (dosn't hurt if already started) */
161 if (init->enable)
162 {
163 timer->CMD = TIMER_CMD_START;
164 }
165}
166
167
168/***************************************************************************//**

Callers 1

rt_hw_timer_unit_initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected