/* IRQ handler to handle updates to the HCLK frequency. * This updates the SysTick scales. */ static void stm32_rcc_hclk_upd_irq_handler(void *opaque, int n, int level) { Stm32Rcc *s = (Stm32Rcc *)opaque; uint32_t hclk_freq, ext_ref_freq; hclk_freq = clktree_get_output_freq(s->HCLK); /* Only update the scales if the frequency is not zero. */ if(hclk_freq > 0) { ext_ref_freq = hclk_freq / 8; /* Update the scales - these are the ratio of QEMU clock ticks * (which is an unchanging number independent of the CPU frequency) to * system/external clock ticks. */ system_clock_scale = get_ticks_per_sec() / hclk_freq; external_ref_clock_scale = get_ticks_per_sec() / ext_ref_freq; } #ifdef DEBUG_STM32_RCC DPRINTF("Cortex SYSTICK frequency set to %lu Hz (scale set to %d).\n", (unsigned long)hclk_freq, system_clock_scale); DPRINTF("Cortex SYSTICK ext ref frequency set to %lu Hz " "(scale set to %d).\n", (unsigned long)ext_ref_freq, external_ref_clock_scale); #endif }
uint32_t stm32_rcc_get_periph_freq( Stm32Rcc *s, stm32_periph_t periph) { Clk clk; clk = s->PERIPHCLK[periph]; assert(clk != NULL); return clktree_get_output_freq(clk); }