/* Library includes. */\r
#include <asf.h>\r
\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Hardware and driver initialisation can be done in this function.\r
+ */\r
static void prvSetupHardware( void );\r
+\r
+/* \r
+ * Prototypes for the FreeRTOS hook/callback functions. See the comments in\r
+ * the implementation of each function for more information.\r
+ */\r
void vApplicationMallocFailedHook( void );\r
void vApplicationIdleHook( void );\r
void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );\r
void vApplicationTickHook( void );\r
\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Used in the run time stats calculations. */\r
+static unsigned long ulClocksPer10thOfAMilliSecond = 0UL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
int main (void)\r
{\r
prvSetupHardware();\r
code must not attempt to block, and only the interrupt safe FreeRTOS API\r
functions can be used (those that end in FromISR()). */\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vMainConfigureTimerForRunTimeStats( void )\r
+{\r
+ /* How many clocks are there per tenth of a millisecond? */\r
+ ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ / 10000UL;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+unsigned long ulMainGetRunTimeCounterValue( void )\r
+{\r
+unsigned long ulSysTickCounts, ulTickCount, ulReturn;\r
+const unsigned long ulSysTickReloadValue = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;\r
+volatile unsigned long * const pulCurrentSysTickCount = ( ( volatile unsigned long *) 0xe000e018 );\r
+volatile unsigned long * const pulInterruptCTRLState = ( ( volatile unsigned long *) 0xe000ed04 );\r
+const unsigned long ulSysTickPendingBit = 0x04000000UL;\r
+\r
+ /* NOTE: There are potentially race conditions here. However, it is used\r
+ anyway to keep the examples simple, and to avoid reliance on a separate\r
+ timer peripheral. */\r
+\r
+\r
+ /* The SysTick is a down counter. How many clocks have passed since it was\r
+ last reloaded? */\r
+ ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;\r
+ \r
+ /* How many times has it overflowed? */\r
+ ulTickCount = xTaskGetTickCountFromISR();\r
+\r
+ /* This is called from the context switch, so will be called from a\r
+ critical section. xTaskGetTickCountFromISR() contains its own critical\r
+ section, and the ISR safe critical sections are not designed to nest,\r
+ so reset the critical section. */\r
+ portSET_INTERRUPT_MASK_FROM_ISR();\r
+ \r
+ /* Is there a SysTick interrupt pending? */\r
+ if( ( *pulInterruptCTRLState & ulSysTickPendingBit ) != 0UL )\r
+ {\r
+ /* There is a SysTick interrupt pending, so the SysTick has overflowed\r
+ but the tick count not yet incremented. */\r
+ ulTickCount++;\r
+ \r
+ /* Read the SysTick again, as the overflow might have occurred since\r
+ it was read last. */\r
+ ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;\r
+ } \r
+ \r
+ /* Convert the tick count into tenths of a millisecond. THIS ASSUMES\r
+ configTICK_RATE_HZ is 1000! */\r
+ ulReturn = ( ulTickCount * 10UL ) ;\r
+ \r
+ /* Add on the number of tenths of a millisecond that have passed since the\r
+ tick count last got updated. */\r
+ ulReturn += ( ulSysTickCounts / ulClocksPer10thOfAMilliSecond );\r
+ \r
+ return ulReturn; \r
+}\r
\r