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