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

Function rt_hw_timer_unit_init

bsp/efm32/drv_timer.c:229–324  ·  view source on GitHub ↗

/ * @brief * Initialize the specified TIMER unit * * @details * * @note * * @param[in] device * Pointer to device descriptor * * @param[in] unitNumber * Unit number * * @return * Pointer to TIMER device ******************************************************************************/

Source from the content-addressed store, hash-verified

227 * Pointer to TIMER device
228 ******************************************************************************/
229static struct efm32_timer_device_t *rt_hw_timer_unit_init(
230 rt_device_t device,
231 rt_uint8_t unitNumber,
232 rt_uint8_t mode)
233{
234 struct efm32_timer_device_t *timer;
235 TIMER_Init_TypeDef init;
236 efm32_irq_hook_init_t hook;
237 CMU_Clock_TypeDef timerClock;
238 IRQn_Type timerIrq;
239
240 do
241 {
242 /* Allocate device */
243 timer = rt_malloc(sizeof(struct efm32_timer_device_t));
244 if (timer == RT_NULL)
245 {
246 timer_debug("no memory for TIMER%d driver\n", unitNumber);
247 break;
248 }
249
250 /* Initialization */
251 if (unitNumber >= TIMER_COUNT)
252 {
253 break;
254 }
255 switch (unitNumber)
256 {
257 case 0:
258 timer->timer_device = TIMER0;
259 timerClock = (CMU_Clock_TypeDef)cmuClock_TIMER0;
260 timerIrq = TIMER0_IRQn;
261 break;
262
263 case 1:
264 timer->timer_device = TIMER1;
265 timerClock = (CMU_Clock_TypeDef)cmuClock_TIMER1;
266 timerIrq = TIMER1_IRQn;
267 break;
268
269 case 2:
270 timer->timer_device = TIMER2;
271 timerClock = (CMU_Clock_TypeDef)cmuClock_TIMER2;
272 timerIrq = TIMER2_IRQn;
273 break;
274
275 default:
276 break;
277 }
278
279 /* Enable TIMER clock */
280 CMU_ClockEnable(timerClock, true);
281
282 /* Reset */
283 TIMER_Reset(timer->timer_device);
284
285 /* Init specified TIMER unit */
286 init.enable = false;

Callers 1

rt_hw_timer_initFunction · 0.85

Calls 12

rt_mallocFunction · 0.85
CMU_ClockEnableFunction · 0.85
TIMER_ResetFunction · 0.85
TIMER_InitFunction · 0.85
efm32_irq_hook_registerFunction · 0.85
TIMER_IntEnableFunction · 0.85
TIMER_IntClearFunction · 0.85
rt_freeFunction · 0.85
rt_kprintfFunction · 0.85
NVIC_ClearPendingIRQFunction · 0.50
NVIC_SetPriorityFunction · 0.50
NVIC_EnableIRQFunction · 0.50

Tested by

no test coverage detected