# HG changeset patch # User Paul Boddie # Date 1694867281 -7200 # Node ID 0473eab69c6d5358b7cc5e5074b510f4927bfdec # Parent 384d97264cbc350d8ecdd12ea7d5695c1973c858 Move source frequency calculation into the source abstraction. diff -r 384d97264cbc -r 0473eab69c6d pkg/devices/lib/cpm/src/x1600.cc --- a/pkg/devices/lib/cpm/src/x1600.cc Sat Sep 16 14:16:21 2023 +0200 +++ b/pkg/devices/lib/cpm/src/x1600.cc Sat Sep 16 14:28:01 2023 +0200 @@ -171,6 +171,10 @@ uint8_t get_source(Cpm_regs ®s); void set_source(Cpm_regs ®s, uint8_t source); + + // Clock source frequency. + + uint32_t get_frequency(Cpm_regs ®s); }; // Undefined sources. @@ -801,6 +805,34 @@ _source.set_field(regs, source); } +// Clock source frequencies. + +uint32_t +Source::get_frequency(Cpm_regs ®s) +{ + // Return the external clock frequency without any input clock. + + if (get_number() == 0) + return regs.exclk_freq; + + // Clocks with one source yield that input frequency. + + else if (get_number() == 1) + return clocks[get_input(0)]->get_frequency(regs); + + // With multiple sources, obtain the selected source for the clock. + + uint8_t source = get_source(regs); + enum Clock_identifiers input = get_input(source); + + // Return the frequency of the source. + + if (input != Clock_undefined) + return clocks[input]->get_frequency(regs); + else + return 0; +} + // Clock control. @@ -859,27 +891,7 @@ uint32_t Clock_base::get_source_frequency(Cpm_regs ®s) { - // Return the external clock frequency without any input clock. - - if (_source.get_number() == 0) - return regs.exclk_freq; - - // Clocks with one source yield that input frequency. - - else if (_source.get_number() == 1) - return clocks[_source.get_input(0)]->get_frequency(regs); - - // With multiple sources, obtain the selected source for the clock. - - uint8_t source = get_source(regs); - enum Clock_identifiers input = _source.get_input(source); - - // Return the frequency of the source. - - if (input != Clock_undefined) - return clocks[input]->get_frequency(regs); - else - return 0; + return _source.get_frequency(regs); } // Output clock frequencies.