kendryte / kendryte-standalone-sdk

Standalone SDK for kendryte K210
https://kendryte.com
Apache License 2.0
440 stars 161 forks source link

Question: `sysctl_cpu_set_freq` and `sysctl_clock_get_freq` for CPU seems not match #120

Open longfangsong opened 3 years ago

longfangsong commented 3 years ago

I'm not sure whether the implemention of sysctl_cpu_set_freq is right.

Expected behavior

Not sure

Actual behavior

Not sure

Code

In sysctl_cpu_set_freq, we set the pll0 like this:

sysctl_pll_set_freq(SYSCTL_PLL0, (sysctl->clk_sel0.aclk_divider_sel + 1) * 2 * freq);    

So PLL0_freq = (sysctl->clk_sel0.aclk_divider_sel + 1) * 2 * CPU_FREQ, ie. CPU_FREQ = PLL0_freq / (2 * (sysctl->clk_sel0.aclk_divider_sel + 1))

But in sysctl_clock_get_freq:

case SYSCTL_CLOCK_CPU:
  // ...
  source = sysctl_clock_source_get_freq(SYSCTL_SOURCE_PLL0) /
    (2ULL << sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ACLK));

sysctl_clock_get_threshold(SYSCTL_THRESHOLD_ACLK) eval to sysctl->clk_sel0.aclk_divider_sel here

So we have: CPU_FREQ = PLL0_freq / (2 << sysctl->clk_sel0.aclk_divider_sel)

Which is obviously different with the first fomula.

Did I missunderstood these code?

Document version

master

Hardware

NA

System

NA