]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_M0+_Atmel_SAMD20_XPlained/RTOSDemo/src/main.c
Update version number to V8.0.0 (without the release candidate number).
[freertos] / FreeRTOS / Demo / CORTEX_M0+_Atmel_SAMD20_XPlained / RTOSDemo / src / main.c
index c69fc589f8ea647c0a31abceac12c8e6c5dcd6d7..0bb72243408274219826238b9b2f301e9dd60447 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
-    FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+    FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. \r
+    All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
     1 tab == 4 spaces!\r
 */\r
 \r
+/******************************************************************************\r
+ * This project provides two demo applications.  A simple blinky style project,\r
+ * and a more comprehensive test and demo application.  The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
+ * select between the two.  The simply blinky demo is implemented and described\r
+ * in main_blinky.c.  The more comprehensive test and demo application is\r
+ * implemented and described in main_full.c.\r
+ *\r
+ * This file implements the code that is not demo specific, including the\r
+ * hardware setup and FreeRTOS hook functions.  It also contains a dummy\r
+ * interrupt service routine called Dummy_IRQHandler() that is provided as an\r
+ * example of how to use interrupt safe FreeRTOS API functions (those that end\r
+ * in "FromISR").\r
+ *\r
+ *****************************************************************************/\r
+\r
 /* FreeRTOS includes. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
 /* Demo app includes. */\r
 #include "UARTCommandConsole.h"\r
 \r
+/* Demo application include. */\r
+#include "QueueSet.h"\r
+\r
 /* Library includes. */\r
 #include <asf.h>\r
 \r
+/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
+or 0 to run the more comprehensive test and demo application. */\r
+#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY     0\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Perform any application specific hardware configuration.  \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 vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
 void vApplicationTickHook( void );\r
 \r
+/*\r
+ * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
+ * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
+ */\r
+extern void main_blinky( void );\r
+extern void main_full( 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
+       /* Prepare the hardware for the demo. */\r
        prvSetupHardware();\r
-       vUARTCommandConsoleStart( ( configMINIMAL_STACK_SIZE * 3 ), tskIDLE_PRIORITY ); \r
-       \r
-       /* Start the scheduler. */\r
-       vTaskStartScheduler();\r
-\r
-       /* If all is well, the scheduler will now be running, and the following line\r
-       will never be reached.  If the following line does execute, then there was\r
-       insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
-       to be created.  See the memory management section on the FreeRTOS web site\r
-       for more details. */\r
-       for( ;; );\r
+\r
+       /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
+       of this file. */\r
+       #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
+       {\r
+               main_blinky();\r
+       }\r
+       #else\r
+       {\r
+               main_full();\r
+       }\r
+       #endif\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 static void prvSetupHardware( void )\r
 {\r
+       /* Initialisation is performed by the Atmel board support package. */\r
        system_init();\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -132,7 +183,7 @@ void vApplicationIdleHook( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
 {\r
        ( void ) pcTaskName;\r
        ( void ) pxTask;\r
@@ -152,5 +203,106 @@ void vApplicationTickHook( void )
        added here, but the tick hook is called from an interrupt context, so\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
+       /* The semaphore and associated task are not created when the simple blinky\r
+       demo is used. */\r
+       #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
+       {\r
+               /* Write to a queue that is in use as part of the queue set demo to\r
+               demonstrate using queue sets from an ISR. */\r
+               vQueueSetAccessQueueSetFromISR();\r
+       }\r
+       #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vMainConfigureTimerForRunTimeStats( void )\r
+{\r
+       /* Used by the optional run-time stats gathering functionality. */\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
+       /* Used by the optional run-time stats gathering functionality. */\r
+\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
+\r
+#ifdef JUST_AN_EXAMPLE_ISR\r
+\r
+void Dummy_IRQHandler(void)\r
+{\r
+long lHigherPriorityTaskWoken = pdFALSE;\r
+\r
+       /* Clear the interrupt if necessary. */\r
+       Dummy_ClearITPendingBit();\r
+\r
+       /* This interrupt does nothing more than demonstrate how to synchronise a\r
+       task with an interrupt.  A semaphore is used for this purpose.  Note\r
+       lHigherPriorityTaskWoken is initialised to zero. Only FreeRTOS API functions\r
+       that end in "FromISR" can be called from an ISR. */\r
+       xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );\r
+\r
+       /* If there was a task that was blocked on the semaphore, and giving the\r
+       semaphore caused the task to unblock, and the unblocked task has a priority\r
+       higher than the current Running state task (the task that this interrupt\r
+       interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE\r
+       internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the\r
+       portEND_SWITCHING_ISR() macro will result in a context switch being pended to\r
+       ensure this interrupt returns directly to the unblocked, higher priority,\r
+       task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */\r
+       portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );\r
+}\r
+\r
+#endif /* JUST_AN_EXAMPLE_ISR */\r
 \r