diff --git a/configs/samv71-xult/src/sam_boot.c b/configs/samv71-xult/src/sam_boot.c index f15ba8cf956..6c761e1249c 100644 --- a/configs/samv71-xult/src/sam_boot.c +++ b/configs/samv71-xult/src/sam_boot.c @@ -39,13 +39,18 @@ #include +#include +#include +#include #include #include +#include #include #include "up_arch.h" #include "sam_start.h" +#include "sam_pck.h" #include "samv71-xult.h" /**************************************************************************** @@ -73,6 +78,37 @@ void sam_boardinitialize(void) { +#ifdef CONFIG_SCHED_TICKLESS + uint32_t frequency; + uint32_t actual; + + /* If Tickless mode is selected then enabled PCK6 as a possible clock + * source for the timer/counters. The ideal frequency could be: + * + * frequency = 1,000,000 / CONFIG_USEC_PER_TICK + * + * The main crystal is selected as the frequency source. The maximum + * prescaler value is 256 so the minimum frequency is 46,875 Hz which + * corresponds to a period of 21.3 microseconds. A value of + * CONFIG_USEC_PER_TICK=20, or 50KHz, would give an exact solution with + * a divider of 240. + */ + + frequency = USEC_PER_SEC / CONFIG_USEC_PER_TICK; + DEBUGASSERT(frequency >= (BOARD_MAINOSC_FREQUENCY / 256)); + + actual = sam_pck_configure(PCK6, PCKSRC_MAINCK, frequency); + + /* We expect to achieve this frequency exactly */ + + DEBUGASSERT(actual == frequency); + UNUSED(actual); + + /* Enable PCK6 */ + + (void)sam_pck_enable(PCK6, true); +#endif + #ifdef CONFIG_SAMV7_SDRAMC /* Configure SDRAM if it has been enabled in the NuttX configuration. * Here we assume, of course, that we are not running out SDRAM.