diff --git a/configs/same70-xplained/README.txt b/configs/same70-xplained/README.txt index 3cfe6208351..238c296930b 100644 --- a/configs/same70-xplained/README.txt +++ b/configs/same70-xplained/README.txt @@ -921,8 +921,8 @@ Tickless OS will have an error of 0.6% and will have inaccuracies that will effect the time due to long term error build-up. - UPDATE: As of this writing (2015-12-03), the Tickless support is - functional. However, there are inaccuracies in delays. For example, + Using the slow clock clock input, the Tickless support is functional, + however, there are inaccuracies in delays. For example, nsh> sleep 10 @@ -936,10 +936,18 @@ Tickless OS piece has a large error in the calculation. The cumulative error is the cause of the problem. - Solution: 30.518 microseconds is not representable and the value of - CONFIG_USEC_PER_SEC is too inaccurate; error build-up is throwing off - long delays (short delays are probably still okay). We should driver - the interval timer with PCK6 with a period that is exactly representable. + Solution: The same70-xplained/src/sam_boot.c file has additional logic + to enable the programmable clock PCK6 as a clock source for the + timer/counters if the Tickless mode is selected. The ideal frequency + would 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. SAME70 Timer Usage ------------------ diff --git a/configs/same70-xplained/src/sam_boot.c b/configs/same70-xplained/src/sam_boot.c index bd3f7954ee4..2c0ef267612 100644 --- a/configs/same70-xplained/src/sam_boot.c +++ b/configs/same70-xplained/src/sam_boot.c @@ -39,23 +39,20 @@ #include +#include +#include +#include #include #include +#include #include #include "up_arch.h" #include "sam_start.h" +#include "sam_pck.h" #include "same70-xplained.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -73,6 +70,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. diff --git a/configs/samv71-xult/README.txt b/configs/samv71-xult/README.txt index 0f94108feb2..248a3624dfc 100644 --- a/configs/samv71-xult/README.txt +++ b/configs/samv71-xult/README.txt @@ -1506,8 +1506,8 @@ Tickless OS will have an error of 0.6% and will have inaccuracies that will effect the time due to long term error build-up. - UPDATE: As of this writing (2015-12-03), the Tickless support is - functional. However, there are inaccuracies in delays. For example, + Using the slow clock clock input, the Tickless support is functional, + however, there are inaccuracies in delays. For example, nsh> sleep 10 @@ -1521,10 +1521,18 @@ Tickless OS piece has a large error in the calculation. The cumulative error is the cause of the problem. - Solution: 30.518 microseconds is not representable and the value of - CONFIG_USEC_PER_SEC is too inaccurate; error build-up is throwing off - long delays (short delays are probably still okay). We should driver - the interval timer with PCK6 with a period that is exactly representable. + Solution: The samv71-xult/src/sam_boot.c file has additional logic + to enable the programmable clock PCK6 as a clock source for the + timer/counters if the Tickless mode is selected. The ideal frequency + would 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. SAMV7 Timer Usage ----------------- diff --git a/configs/samv71-xult/src/sam_boot.c b/configs/samv71-xult/src/sam_boot.c index 6c761e1249c..1384f435a71 100644 --- a/configs/samv71-xult/src/sam_boot.c +++ b/configs/samv71-xult/src/sam_boot.c @@ -53,14 +53,6 @@ #include "sam_pck.h" #include "samv71-xult.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/