RISC-V operating system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rovo/kernel/platform/FU740/clock.c

27 lines
682 B

1 year ago
#include <stdint.h>
#include "clock.h"
static struct prci_mem_map *const prci_mm = (struct prci_mem_map *const)PRCI_MEMORY_BLOCK;
// Sets the hfpclkpll register to the appropriate value for the freqency, returns
// -1 on error
// TODO: for higher frequencies use the internal PLLs
int set_hfp_frequency(uint32_t f)
{
// test if the correct register is present
if (!prci_mm->prci_plls.hfpclkpll)
return -1;
// make sure that the clock source is set to external
prci_mm->hfpclkpllsel = 1;
// the external clock source is 26MHz, the formula for the baud rate is:
// f_baud = f_hfclk / (1 + hfpclk_div_reg)
prci_mm->hfpclk_div_reg = (HFCLK_FREQ_HZ/f + 1);
return 0;
}