[En-Nut-Discussion] Defining NUT_HWCLK_*

Thiago A. Corrêa thiago.correa at gmail.com
Sun Jan 18 21:14:35 CET 2009


Hi,

   I'm porting timer code to AVR32 and I'm looking at NutArchClockGet
in the ARM port as reference.

   That function accepts either NUT_HWCLK_CPU or NUT_HWCLK_PERIPHERAL.
The problem is that it's only defined in timers.h with default to
NUT_HWCLK_PERIPHERAL == NUT_HWCLK_CPU.
I will have to define them to be different for AVR32. Also, I will
need a second peripheral value, because AVR32 has PBA and PBB clocks
for peripherals and they might have different divisors, so USART can
use one value while USB uses a different value, all based on the value
of the main clock.

   The snippet bellow might clarify it a bit :)

Kind Regards,
   Thiago A. Correa

/*!
 * \brief Return the CPU clock in Hertz.
 *
 * On AVR32 CPUs the processor clock may differ from the clock
 * driving the peripherals. In this case NutArchClockGet() will
 * provide the correct clock depending on it's argument.
 *
 * \return CPU clock frequency in Hertz.
 */
uint32_t NutArchClockGet(int idx)
{
    uint32_t rc = AVR32_PM_PBA_MAX_FREQ;

	if ( idx == NUT_HWCLK_CPU ) {
		rc = Avr32GetProcessorClock();
	}
	else if ( idx == NUT_HWCLK_PERIPHERAL ) {
		/* Get PBA Clock */
		rc = Avr32GetProcessorClock();

		if ( AVR32_PM.CKSEL.pbadiv )
		{
			rc >>=  AVR32_PM.CKSEL.pbasel + 1;
		}
	}
       else if ( idx == ??? ) {
		/* Get PBA Clock */
		rc = Avr32GetProcessorClock();

		if ( AVR32_PM.CKSEL.pbbdiv )
		{
			rc >>=  AVR32_PM.CKSEL.pbbsel + 1;
		}
       }
 	
	return rc;
}



More information about the En-Nut-Discussion mailing list