/* Retrieves the clock frequency of a Generic Clock generator. 
Determines the clock frequency (in Hz) of a specified Generic Clock generator, used as a source to a Generic Clock Channel module. */
uint32_t system_gclk_gen_get_hz(const uint8_t generator)
/* Retrieves the clock frequency of a Generic Clock generator. 
Determines the clock frequency (in Hz) of a specified Generic Clock generator, used as a source to a Generic Clock Channel module. */
uint32_t system_gclk_gen_get_hz(const uint8_t generator)
{
	while (system_gclk_is_syncing(generator)) {
	};
	system_interrupt_enter_critical_section();
	uint32_t gen_input_hz = system_clock_source_get_hz(
			(enum system_clock_source)GCLK->GENCTRL[generator].bit.SRC);
	uint8_t divsel = GCLK->GENCTRL[generator].bit.DIVSEL;
	uint32_t divider = GCLK->GENCTRL[generator].bit.DIV;
	system_interrupt_leave_critical_section();
	if (!divsel && divider > 1) {
		gen_input_hz /= divider;
	} else if (divsel) {
		gen_input_hz >>= (divider+1);
	}
	return gen_input_hz;
}