/* Retrieve the frequency of a clock source. 
Determines the current operating frequency of a given clock source. */
uint32_t system_clock_source_get_hz(const enum system_clock_source clock_source)
/* Retrieve the frequency of a clock source. 
Determines the current operating frequency of a given clock source. */
uint32_t system_clock_source_get_hz(const enum system_clock_source clock_source)
{
	switch (clock_source) {
	case SYSTEM_CLOCK_SOURCE_XOSC:
		return _system_clock_inst.xosc.frequency;
	case SYSTEM_CLOCK_SOURCE_OSC48M:
		return 48000000UL / (OSCCTRL->OSC48MDIV.bit.DIV + 1);
	case SYSTEM_CLOCK_SOURCE_OSC32K:
		return 32768UL;
	case SYSTEM_CLOCK_SOURCE_ULP32K:
		return 32768UL;
	case SYSTEM_CLOCK_SOURCE_XOSC32K:
		return _system_clock_inst.xosc32k.frequency;
	case SYSTEM_CLOCK_SOURCE_DPLL:
		if (!(OSCCTRL->DPLLCTRLA.reg & OSCCTRL_DPLLCTRLA_ENABLE)) {
			return 0;
		}
		return _system_clock_inst.dpll.frequency;
	default:
		return 0;
	}
}