/ * @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 ******************************************************************************/
| 227 | * Pointer to TIMER device |
| 228 | ******************************************************************************/ |
| 229 | static 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; |
no test coverage detected