1.1 --- a/pkg/devices/lib/cpm/src/x1600.cc Sat Sep 16 14:16:21 2023 +0200
1.2 +++ b/pkg/devices/lib/cpm/src/x1600.cc Sat Sep 16 14:28:01 2023 +0200
1.3 @@ -171,6 +171,10 @@
1.4
1.5 uint8_t get_source(Cpm_regs ®s);
1.6 void set_source(Cpm_regs ®s, uint8_t source);
1.7 +
1.8 + // Clock source frequency.
1.9 +
1.10 + uint32_t get_frequency(Cpm_regs ®s);
1.11 };
1.12
1.13 // Undefined sources.
1.14 @@ -801,6 +805,34 @@
1.15 _source.set_field(regs, source);
1.16 }
1.17
1.18 +// Clock source frequencies.
1.19 +
1.20 +uint32_t
1.21 +Source::get_frequency(Cpm_regs ®s)
1.22 +{
1.23 + // Return the external clock frequency without any input clock.
1.24 +
1.25 + if (get_number() == 0)
1.26 + return regs.exclk_freq;
1.27 +
1.28 + // Clocks with one source yield that input frequency.
1.29 +
1.30 + else if (get_number() == 1)
1.31 + return clocks[get_input(0)]->get_frequency(regs);
1.32 +
1.33 + // With multiple sources, obtain the selected source for the clock.
1.34 +
1.35 + uint8_t source = get_source(regs);
1.36 + enum Clock_identifiers input = get_input(source);
1.37 +
1.38 + // Return the frequency of the source.
1.39 +
1.40 + if (input != Clock_undefined)
1.41 + return clocks[input]->get_frequency(regs);
1.42 + else
1.43 + return 0;
1.44 +}
1.45 +
1.46
1.47
1.48 // Clock control.
1.49 @@ -859,27 +891,7 @@
1.50 uint32_t
1.51 Clock_base::get_source_frequency(Cpm_regs ®s)
1.52 {
1.53 - // Return the external clock frequency without any input clock.
1.54 -
1.55 - if (_source.get_number() == 0)
1.56 - return regs.exclk_freq;
1.57 -
1.58 - // Clocks with one source yield that input frequency.
1.59 -
1.60 - else if (_source.get_number() == 1)
1.61 - return clocks[_source.get_input(0)]->get_frequency(regs);
1.62 -
1.63 - // With multiple sources, obtain the selected source for the clock.
1.64 -
1.65 - uint8_t source = get_source(regs);
1.66 - enum Clock_identifiers input = _source.get_input(source);
1.67 -
1.68 - // Return the frequency of the source.
1.69 -
1.70 - if (input != Clock_undefined)
1.71 - return clocks[input]->get_frequency(regs);
1.72 - else
1.73 - return 0;
1.74 + return _source.get_frequency(regs);
1.75 }
1.76
1.77 // Output clock frequencies.