/** * * @brief Initialize and enable the system clock * * This routine is used to program the systick to deliver interrupts at the * rate specified via the 'sys_clock_us_per_tick' global variable. * * @return 0 */ int _sys_clock_driver_init(struct device *device) { /* enable counter, interrupt and set clock src to system clock */ u32_t ctrl = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_CLKSOURCE_Msk; ARG_UNUSED(device); /* * Determine the reload value to achieve the configured tick rate. */ /* systick supports 24-bit H/W counter */ __ASSERT(sys_clock_hw_cycles_per_tick <= (1 << 24), "sys_clock_hw_cycles_per_tick too large"); sysTickReloadSet(sys_clock_hw_cycles_per_tick - 1); #ifdef CONFIG_TICKLESS_IDLE /* calculate hardware-specific parameters for tickless idle */ sysTickTicklessIdleInit(); #endif /* CONFIG_TICKLESS_IDLE */ NVIC_SetPriority(SysTick_IRQn, _IRQ_PRIO_OFFSET); SysTick->CTRL = ctrl; SysTick->VAL = 0; /* triggers immediate reload of count */ return 0; }
/** * * @brief Initialize and enable the system clock * * This routine is used to program the systick to deliver interrupts at the * rate specified via the 'sys_clock_us_per_tick' global variable. * * @return 0 */ int _sys_clock_driver_init(struct device *device) { /* enable counter, interrupt and set clock src to system clock */ union __stcsr stcsr = {.bit = {1, 1, 1, 0, 0, 0} }; ARG_UNUSED(device); /* * Determine the reload value to achieve the configured tick rate. */ /* systick supports 24-bit H/W counter */ __ASSERT(sys_clock_hw_cycles_per_tick <= (1 << 24), "sys_clock_hw_cycles_per_tick too large"); sysTickReloadSet(sys_clock_hw_cycles_per_tick - 1); #ifdef CONFIG_TICKLESS_IDLE /* calculate hardware-specific parameters for tickless idle */ sysTickTicklessIdleInit(); #endif /* CONFIG_TICKLESS_IDLE */ _ScbExcPrioSet(_EXC_SYSTICK, _EXC_IRQ_DEFAULT_PRIO); __scs.systick.stcsr.val = stcsr.val; return 0; }