+++ /dev/null
-/*\r
- FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
- \r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-\r
-/* \r
- * Tests the extra queue functionality introduced in FreeRTOS.org V4.5.0 - \r
- * including xQueueSendToFront(), xQueueSendToBack(), xQueuePeek() and \r
- * mutex behaviour. \r
- *\r
- * See the comments above the prvSendFrontAndBackTest() and \r
- * prvLowPriorityMutexTask() prototypes below for more information.\r
- */\r
-\r
-\r
-#include <stdlib.h>\r
-\r
-/* Scheduler include files. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-#include "queue.h"\r
-#include "semphr.h"\r
-\r
-/* Demo program include files. */\r
-#include "GenQTest.h"\r
-\r
-#define genqQUEUE_LENGTH ( 5 )\r
-#define genqNO_BLOCK ( 0 )\r
-\r
-#define genqMUTEX_LOW_PRIORITY ( tskIDLE_PRIORITY )\r
-#define genqMUTEX_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
-#define genqMUTEX_MEDIUM_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define genqMUTEX_HIGH_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Tests the behaviour of the xQueueSendToFront() and xQueueSendToBack()\r
- * macros by using both to fill a queue, then reading from the queue to\r
- * check the resultant queue order is as expected. Queue data is also\r
- * peeked.\r
- */\r
-static void prvSendFrontAndBackTest( void *pvParameters );\r
-\r
-/*\r
- * The following three tasks are used to demonstrate the mutex behaviour.\r
- * Each task is given a different priority to demonstrate the priority\r
- * inheritance mechanism.\r
- *\r
- * The low priority task obtains a mutex. After this a high priority task\r
- * attempts to obtain the same mutex, causing its priority to be inherited\r
- * by the low priority task. The task with the inherited high priority then\r
- * resumes a medium priority task to ensure it is not blocked by the medium\r
- * priority task while it holds the inherited high priority. Once the mutex\r
- * is returned the task with the inherited priority returns to its original\r
- * low priority, and is therefore immediately preempted by first the high\r
- * priority task and then the medium prioroity task before it can continue.\r
- */\r
-static void prvLowPriorityMutexTask( void *pvParameters );\r
-static void prvMediumPriorityMutexTask( void *pvParameters );\r
-static void prvHighPriorityMutexTask( void *pvParameters );\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* Flag that will be latched to pdTRUE should any unexpected behaviour be\r
-detected in any of the tasks. */\r
-static portBASE_TYPE xErrorDetected = pdFALSE;\r
-\r
-/* Counters that are incremented on each cycle of a test. This is used to\r
-detect a stalled task - a test that is no longer running. */\r
-static volatile unsigned portLONG ulLoopCounter = 0;\r
-static volatile unsigned portLONG ulLoopCounter2 = 0;\r
-\r
-/* The variable that is guarded by the mutex in the mutex demo tasks. */\r
-static volatile unsigned portLONG ulGuardedVariable = 0;\r
-\r
-/* Handles used in the mutext test to suspend and resume the high and medium\r
-priority mutex test tasks. */\r
-static xTaskHandle xHighPriorityMutexTask, xMediumPriorityMutexTask;\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-void vStartGenericQueueTasks( unsigned portBASE_TYPE uxPriority )\r
-{\r
-xQueueHandle xQueue;\r
-xSemaphoreHandle xMutex;\r
-\r
- /* Create the queue that we are going to use for the\r
- prvSendFrontAndBackTest demo. */\r
- xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );\r
-\r
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one is\r
- in use. The queue registry is provided as a means for kernel aware \r
- debuggers to locate queues and has no purpose if a kernel aware debugger\r
- is not being used. The call to vQueueAddToRegistry() will be removed\r
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
- defined to be less than 1. */\r
- vQueueAddToRegistry( xQueue, ( signed portCHAR * ) "Gen_Queue_Test" );\r
-\r
- /* Create the demo task and pass it the queue just created. We are\r
- passing the queue handle by value so it does not matter that it is\r
- declared on the stack here. */\r
- xTaskCreate( prvSendFrontAndBackTest, ( signed portCHAR * )"GenQ", configMINIMAL_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );\r
-\r
- /* Create the mutex used by the prvMutexTest task. */\r
- xMutex = xSemaphoreCreateMutex();\r
-\r
- /* vQueueAddToRegistry() adds the mutex to the registry, if one is\r
- in use. The registry is provided as a means for kernel aware \r
- debuggers to locate mutexes and has no purpose if a kernel aware debugger\r
- is not being used. The call to vQueueAddToRegistry() will be removed\r
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
- defined to be less than 1. */\r
- vQueueAddToRegistry( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Gen_Queue_Mutex" );\r
-\r
- /* Create the mutex demo tasks and pass it the mutex just created. We are\r
- passing the mutex handle by value so it does not matter that it is declared\r
- on the stack here. */\r
- xTaskCreate( prvLowPriorityMutexTask, ( signed portCHAR * )"MuLow", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );\r
- xTaskCreate( prvMediumPriorityMutexTask, ( signed portCHAR * )"MuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );\r
- xTaskCreate( prvHighPriorityMutexTask, ( signed portCHAR * )"MuHigh", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvSendFrontAndBackTest( void *pvParameters )\r
-{\r
-unsigned portLONG ulData, ulData2;\r
-xQueueHandle xQueue;\r
-\r
- #ifdef USE_STDIO\r
- void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
- \r
- const portCHAR * const pcTaskStartMsg = "Queue SendToFront/SendToBack/Peek test started.\r\n";\r
-\r
- /* Queue a message for printing to say the task has started. */\r
- vPrintDisplayMessage( &pcTaskStartMsg );\r
- #endif\r
-\r
- xQueue = ( xQueueHandle ) pvParameters;\r
-\r
- for( ;; )\r
- {\r
- /* The queue is empty, so sending an item to the back of the queue\r
- should have the same efect as sending it to the front of the queue.\r
-\r
- First send to the front and check everything is as expected. */\r
- xQueueSendToFront( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
-\r
- if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( xQueueReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* The data we sent to the queue should equal the data we just received\r
- from the queue. */\r
- if( ulLoopCounter != ulData )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* Then do the same, sending the data to the back, checking everything\r
- is as expected. */\r
- if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- xQueueSendToBack( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
-\r
- if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( xQueueReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* The data we sent to the queue should equal the data we just received\r
- from the queue. */\r
- if( ulLoopCounter != ulData )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- #if configUSE_PREEMPTION == 0\r
- taskYIELD();\r
- #endif\r
-\r
-\r
-\r
- /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */\r
- for( ulData = 2; ulData < 5; ulData++ )\r
- {\r
- xQueueSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
- }\r
-\r
- /* Now the order in the queue should be 2, 3, 4, with 2 being the first\r
- thing to be read out. Now add 1 then 0 to the front of the queue. */\r
- if( uxQueueMessagesWaiting( xQueue ) != 3 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
- ulData = 1;\r
- xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
- ulData = 0;\r
- xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
-\r
- /* Now the queue should be full, and when we read the data out we\r
- should receive 0, 1, 2, 3, 4. */\r
- if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( xQueueSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- #if configUSE_PREEMPTION == 0\r
- taskYIELD();\r
- #endif\r
-\r
- /* Check the data we read out is in the expected order. */\r
- for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )\r
- {\r
- /* Try peeking the data first. */\r
- if( xQueuePeek( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( ulData != ulData2 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
- \r
-\r
- /* Now try receiving the data for real. The value should be the\r
- same. Clobber the value first so we know we really received it. */\r
- ulData2 = ~ulData2;\r
- if( xQueueReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( ulData != ulData2 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
- }\r
-\r
- /* The queue should now be empty again. */\r
- if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- #if configUSE_PREEMPTION == 0\r
- taskYIELD();\r
- #endif\r
-\r
-\r
- /* Our queue is empty once more, add 10, 11 to the back. */\r
- ulData = 10;\r
- if( xQueueSend( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
- ulData = 11;\r
- if( xQueueSend( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( uxQueueMessagesWaiting( xQueue ) != 2 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* Now we should have 10, 11 in the queue. Add 7, 8, 9 to the\r
- front. */\r
- for( ulData = 9; ulData >= 7; ulData-- )\r
- {\r
- if( xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
- }\r
-\r
- /* Now check that the queue is full, and that receiving data provides\r
- the expected sequence of 7, 8, 9, 10, 11. */\r
- if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( xQueueSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( xQueueSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- #if configUSE_PREEMPTION == 0\r
- taskYIELD();\r
- #endif\r
-\r
- /* Check the data we read out is in the expected order. */\r
- for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )\r
- {\r
- if( xQueueReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( ulData != ulData2 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
- }\r
-\r
- if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- ulLoopCounter++;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvLowPriorityMutexTask( void *pvParameters )\r
-{\r
-xSemaphoreHandle xMutex = ( xSemaphoreHandle ) pvParameters;\r
-\r
- #ifdef USE_STDIO\r
- void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
- \r
- const portCHAR * const pcTaskStartMsg = "Mutex with priority inheritance test started.\r\n";\r
-\r
- /* Queue a message for printing to say the task has started. */\r
- vPrintDisplayMessage( &pcTaskStartMsg );\r
- #endif\r
-\r
- for( ;; )\r
- {\r
- /* Take the mutex. It should be available now. */\r
- if( xSemaphoreTake( xMutex, genqNO_BLOCK ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* Set our guarded variable to a known start value. */\r
- ulGuardedVariable = 0;\r
-\r
- /* Our priority should be as per that assigned when the task was\r
- created. */\r
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* Now unsuspend the high priority task. This will attempt to take the\r
- mutex, and block when it finds it cannot obtain it. */\r
- vTaskResume( xHighPriorityMutexTask );\r
-\r
- /* We should now have inherited the prioritoy of the high priority task,\r
- as by now it will have attempted to get the mutex. */\r
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* We can attempt to set our priority to the test priority - between the\r
- idle priority and the medium/high test priorities, but our actual\r
- prioroity should remain at the high priority. */\r
- vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );\r
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* Now unsuspend the medium priority task. This should not run as our\r
- inherited priority is above that of the medium priority task. */\r
- vTaskResume( xMediumPriorityMutexTask );\r
-\r
- /* If the did run then it will have incremented our guarded variable. */\r
- if( ulGuardedVariable != 0 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* When we give back the semaphore our priority should be disinherited\r
- back to the priority to which we attempted to set ourselves. This means\r
- that when the high priority task next blocks, the medium priority task\r
- should execute and increment the guarded variable. When we next run\r
- both the high and medium priority tasks will have been suspended again. */\r
- if( xSemaphoreGive( xMutex ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* Check that the guarded variable did indeed increment... */\r
- if( ulGuardedVariable != 1 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* ... and that our priority has been disinherited to\r
- genqMUTEX_TEST_PRIORITY. */\r
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* Set our priority back to our original priority ready for the next\r
- loop around this test. */\r
- vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );\r
-\r
- /* Just to show we are still running. */\r
- ulLoopCounter2++;\r
-\r
- #if configUSE_PREEMPTION == 0\r
- taskYIELD();\r
- #endif \r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvMediumPriorityMutexTask( void *pvParameters )\r
-{\r
- ( void ) pvParameters;\r
-\r
- for( ;; )\r
- {\r
- /* The medium priority task starts by suspending itself. The low\r
- priority task will unsuspend this task when required. */\r
- vTaskSuspend( NULL );\r
-\r
- /* When this task unsuspends all it does is increment the guarded\r
- variable, this is so the low priority task knows that it has\r
- executed. */\r
- ulGuardedVariable++;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvHighPriorityMutexTask( void *pvParameters )\r
-{\r
-xSemaphoreHandle xMutex = ( xSemaphoreHandle ) pvParameters;\r
-\r
- for( ;; )\r
- {\r
- /* The high priority task starts by suspending itself. The low\r
- priority task will unsuspend this task when required. */\r
- vTaskSuspend( NULL );\r
-\r
- /* When this task unsuspends all it does is attempt to obtain\r
- the mutex. It should find the mutex is not available so a\r
- block time is specified. */\r
- if( xSemaphoreTake( xMutex, portMAX_DELAY ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- /* When we eventually obtain the mutex we just give it back then\r
- return to suspend ready for the next test. */\r
- if( xSemaphoreGive( xMutex ) != pdPASS )\r
- {\r
- xErrorDetected = pdTRUE;\r
- } \r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-/* This is called to check that all the created tasks are still running. */\r
-portBASE_TYPE xAreGenericQueueTasksStillRunning( void )\r
-{\r
-static unsigned portLONG ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;\r
-\r
- /* If the demo task is still running then we expect the loopcounters to\r
- have incremented since this function was last called. */\r
- if( ulLastLoopCounter == ulLoopCounter )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- if( ulLastLoopCounter2 == ulLoopCounter2 )\r
- {\r
- xErrorDetected = pdTRUE;\r
- }\r
-\r
- ulLastLoopCounter = ulLoopCounter;\r
- ulLastLoopCounter2 = ulLoopCounter2; \r
-\r
- /* Errors detected in the task itself will have latched xErrorDetected\r
- to true. */\r
-\r
- return !xErrorDetected;\r
-}\r
-\r
-\r
+++ /dev/null
-/*\r
- FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
-\r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-/*\r
- * The first test creates three tasks - two counter tasks (one continuous count\r
- * and one limited count) and one controller. A "count" variable is shared\r
- * between all three tasks. The two counter tasks should never be in a "ready"\r
- * state at the same time. The controller task runs at the same priority as\r
- * the continuous count task, and at a lower priority than the limited count\r
- * task.\r
- *\r
- * One counter task loops indefinitely, incrementing the shared count variable\r
- * on each iteration. To ensure it has exclusive access to the variable it\r
- * raises it's priority above that of the controller task before each\r
- * increment, lowering it again to it's original priority before starting the\r
- * next iteration.\r
- *\r
- * The other counter task increments the shared count variable on each\r
- * iteration of it's loop until the count has reached a limit of 0xff - at\r
- * which point it suspends itself. It will not start a new loop until the\r
- * controller task has made it "ready" again by calling vTaskResume ().\r
- * This second counter task operates at a higher priority than controller\r
- * task so does not need to worry about mutual exclusion of the counter\r
- * variable.\r
- *\r
- * The controller task is in two sections. The first section controls and\r
- * monitors the continuous count task. When this section is operational the\r
- * limited count task is suspended. Likewise, the second section controls\r
- * and monitors the limited count task. When this section is operational the\r
- * continuous count task is suspended.\r
- *\r
- * In the first section the controller task first takes a copy of the shared\r
- * count variable. To ensure mutual exclusion on the count variable it\r
- * suspends the continuous count task, resuming it again when the copy has been\r
- * taken. The controller task then sleeps for a fixed period - during which\r
- * the continuous count task will execute and increment the shared variable.\r
- * When the controller task wakes it checks that the continuous count task\r
- * has executed by comparing the copy of the shared variable with its current\r
- * value. This time, to ensure mutual exclusion, the scheduler itself is\r
- * suspended with a call to vTaskSuspendAll (). This is for demonstration\r
- * purposes only and is not a recommended technique due to its inefficiency.\r
- *\r
- * After a fixed number of iterations the controller task suspends the\r
- * continuous count task, and moves on to its second section.\r
- *\r
- * At the start of the second section the shared variable is cleared to zero.\r
- * The limited count task is then woken from it's suspension by a call to\r
- * vTaskResume (). As this counter task operates at a higher priority than\r
- * the controller task the controller task should not run again until the\r
- * shared variable has been counted up to the limited value causing the counter\r
- * task to suspend itself. The next line after vTaskResume () is therefore\r
- * a check on the shared variable to ensure everything is as expected.\r
- *\r
- *\r
- * The second test consists of a couple of very simple tasks that post onto a\r
- * queue while the scheduler is suspended. This test was added to test parts\r
- * of the scheduler not exercised by the first test.\r
- *\r
- */\r
-\r
-#include <stdlib.h>\r
-\r
-/* Scheduler include files. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-#include "semphr.h"\r
-\r
-/* Demo app include files. */\r
-#include "dynamic.h"\r
-\r
-/* Function that implements the "limited count" task as described above. */\r
-static portTASK_FUNCTION_PROTO( vLimitedIncrementTask, pvParameters );\r
-\r
-/* Function that implements the "continuous count" task as described above. */\r
-static portTASK_FUNCTION_PROTO( vContinuousIncrementTask, pvParameters );\r
-\r
-/* Function that implements the controller task as described above. */\r
-static portTASK_FUNCTION_PROTO( vCounterControlTask, pvParameters );\r
-\r
-static portTASK_FUNCTION_PROTO( vQueueReceiveWhenSuspendedTask, pvParameters );\r
-static portTASK_FUNCTION_PROTO( vQueueSendWhenSuspendedTask, pvParameters );\r
-\r
-/* Demo task specific constants. */\r
-#define priSTACK_SIZE ( configMINIMAL_STACK_SIZE )\r
-#define priSLEEP_TIME ( ( portTickType ) 128 / portTICK_RATE_MS )\r
-#define priLOOPS ( 5 )\r
-#define priMAX_COUNT ( ( unsigned long ) 0xff )\r
-#define priNO_BLOCK ( ( portTickType ) 0 )\r
-#define priSUSPENDED_QUEUE_LENGTH ( 1 )\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* Handles to the two counter tasks. These could be passed in as parameters\r
-to the controller task to prevent them having to be file scope. */\r
-static xTaskHandle xContinousIncrementHandle, xLimitedIncrementHandle;\r
-\r
-/* The shared counter variable. This is passed in as a parameter to the two\r
-counter variables for demonstration purposes. */\r
-static unsigned long ulCounter;\r
-\r
-/* Variables used to check that the tasks are still operating without error.\r
-Each complete iteration of the controller task increments this variable\r
-provided no errors have been found. The variable maintaining the same value\r
-is therefore indication of an error. */\r
-static volatile unsigned short usCheckVariable = ( unsigned short ) 0;\r
-static volatile portBASE_TYPE xSuspendedQueueSendError = pdFALSE;\r
-static volatile portBASE_TYPE xSuspendedQueueReceiveError = pdFALSE;\r
-\r
-/* Queue used by the second test. */\r
-xQueueHandle xSuspendedTestQueue;\r
-\r
-/*-----------------------------------------------------------*/\r
-/*\r
- * Start the three tasks as described at the top of the file.\r
- * Note that the limited count task is given a higher priority.\r
- */\r
-void vStartDynamicPriorityTasks( void )\r
-{\r
- xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned long ) );\r
-\r
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one is\r
- in use. The queue registry is provided as a means for kernel aware\r
- debuggers to locate queues and has no purpose if a kernel aware debugger\r
- is not being used. The call to vQueueAddToRegistry() will be removed\r
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is\r
- defined to be less than 1. */\r
- vQueueAddToRegistry( xSuspendedTestQueue, ( signed char * ) "Suspended_Test_Queue" );\r
-\r
- xTaskCreate( vContinuousIncrementTask, ( signed char * ) "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinousIncrementHandle );\r
- xTaskCreate( vLimitedIncrementTask, ( signed char * ) "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );\r
- xTaskCreate( vCounterControlTask, ( signed char * ) "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
- xTaskCreate( vQueueSendWhenSuspendedTask, ( signed char * ) "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
- xTaskCreate( vQueueReceiveWhenSuspendedTask, ( signed char * ) "SUSP_RX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Just loops around incrementing the shared variable until the limit has been\r
- * reached. Once the limit has been reached it suspends itself.\r
- */\r
-static portTASK_FUNCTION( vLimitedIncrementTask, pvParameters )\r
-{\r
-unsigned long *pulCounter;\r
-\r
- /* Take a pointer to the shared variable from the parameters passed into\r
- the task. */\r
- pulCounter = ( unsigned long * ) pvParameters;\r
-\r
- /* This will run before the control task, so the first thing it does is\r
- suspend - the control task will resume it when ready. */\r
- vTaskSuspend( NULL );\r
-\r
- for( ;; )\r
- {\r
- /* Just count up to a value then suspend. */\r
- ( *pulCounter )++;\r
-\r
- if( *pulCounter >= priMAX_COUNT )\r
- {\r
- vTaskSuspend( NULL );\r
- }\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Just keep counting the shared variable up. The control task will suspend\r
- * this task when it wants.\r
- */\r
-static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )\r
-{\r
-unsigned long *pulCounter;\r
-unsigned portBASE_TYPE uxOurPriority;\r
-\r
- /* Take a pointer to the shared variable from the parameters passed into\r
- the task. */\r
- pulCounter = ( unsigned long * ) pvParameters;\r
-\r
- /* Query our priority so we can raise it when exclusive access to the\r
- shared variable is required. */\r
- uxOurPriority = uxTaskPriorityGet( NULL );\r
-\r
- for( ;; )\r
- {\r
- /* Raise our priority above the controller task to ensure a context\r
- switch does not occur while we are accessing this variable. */\r
- vTaskPrioritySet( NULL, uxOurPriority + 1 );\r
- ( *pulCounter )++;\r
- vTaskPrioritySet( NULL, uxOurPriority );\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Controller task as described above.\r
- */\r
-static portTASK_FUNCTION( vCounterControlTask, pvParameters )\r
-{\r
-unsigned long ulLastCounter;\r
-short sLoops;\r
-short sError = pdFALSE;\r
-\r
- /* Just to stop warning messages. */\r
- ( void ) pvParameters;\r
-\r
- for( ;; )\r
- {\r
- /* Start with the counter at zero. */\r
- ulCounter = ( unsigned long ) 0;\r
-\r
- /* First section : */\r
-\r
- /* Check the continuous count task is running. */\r
- for( sLoops = 0; sLoops < priLOOPS; sLoops++ )\r
- {\r
- /* Suspend the continuous count task so we can take a mirror of the\r
- shared variable without risk of corruption. */\r
- vTaskSuspend( xContinousIncrementHandle );\r
- ulLastCounter = ulCounter;\r
- vTaskResume( xContinousIncrementHandle );\r
-\r
- /* Now delay to ensure the other task has processor time. */\r
- vTaskDelay( priSLEEP_TIME );\r
-\r
- /* Check the shared variable again. This time to ensure mutual\r
- exclusion the whole scheduler will be locked. This is just for\r
- demo purposes! */\r
- vTaskSuspendAll();\r
- {\r
- if( ulLastCounter == ulCounter )\r
- {\r
- /* The shared variable has not changed. There is a problem\r
- with the continuous count task so flag an error. */\r
- sError = pdTRUE;\r
- }\r
- }\r
- xTaskResumeAll();\r
- }\r
-\r
-\r
- /* Second section: */\r
-\r
- /* Suspend the continuous counter task so it stops accessing the shared variable. */\r
- vTaskSuspend( xContinousIncrementHandle );\r
-\r
- /* Reset the variable. */\r
- ulCounter = ( unsigned long ) 0;\r
-\r
- /* Resume the limited count task which has a higher priority than us.\r
- We should therefore not return from this call until the limited count\r
- task has suspended itself with a known value in the counter variable. */\r
- vTaskResume( xLimitedIncrementHandle );\r
-\r
- /* Does the counter variable have the expected value? */\r
- if( ulCounter != priMAX_COUNT )\r
- {\r
- sError = pdTRUE;\r
- }\r
-\r
- if( sError == pdFALSE )\r
- {\r
- /* If no errors have occurred then increment the check variable. */\r
- portENTER_CRITICAL();\r
- usCheckVariable++;\r
- portEXIT_CRITICAL();\r
- }\r
-\r
- /* Resume the continuous count task and do it all again. */\r
- vTaskResume( xContinousIncrementHandle );\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static portTASK_FUNCTION( vQueueSendWhenSuspendedTask, pvParameters )\r
-{\r
-static unsigned long ulValueToSend = ( unsigned long ) 0;\r
-\r
- /* Just to stop warning messages. */\r
- ( void ) pvParameters;\r
-\r
- for( ;; )\r
- {\r
- vTaskSuspendAll();\r
- {\r
- /* We must not block while the scheduler is suspended! */\r
- if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )\r
- {\r
- xSuspendedQueueSendError = pdTRUE;\r
- }\r
- }\r
- xTaskResumeAll();\r
-\r
- vTaskDelay( priSLEEP_TIME );\r
-\r
- ++ulValueToSend;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static portTASK_FUNCTION( vQueueReceiveWhenSuspendedTask, pvParameters )\r
-{\r
-static unsigned long ulExpectedValue = ( unsigned long ) 0, ulReceivedValue;\r
-portBASE_TYPE xGotValue;\r
-\r
- /* Just to stop warning messages. */\r
- ( void ) pvParameters;\r
-\r
- for( ;; )\r
- {\r
- do\r
- {\r
- /* Suspending the scheduler here is fairly pointless and\r
- undesirable for a normal application. It is done here purely\r
- to test the scheduler. The inner xTaskResumeAll() should\r
- never return pdTRUE as the scheduler is still locked by the\r
- outer call. */\r
- vTaskSuspendAll();\r
- {\r
- vTaskSuspendAll();\r
- {\r
- xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );\r
- }\r
- if( xTaskResumeAll() )\r
- {\r
- xSuspendedQueueReceiveError = pdTRUE;\r
- }\r
- }\r
- xTaskResumeAll();\r
-\r
- #if configUSE_PREEMPTION == 0\r
- {\r
- taskYIELD();\r
- }\r
- #endif\r
-\r
- } while( xGotValue == pdFALSE );\r
-\r
- if( ulReceivedValue != ulExpectedValue )\r
- {\r
- xSuspendedQueueReceiveError = pdTRUE;\r
- }\r
-\r
- ++ulExpectedValue;\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-/* Called to check that all the created tasks are still running without error. */\r
-portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void )\r
-{\r
-/* Keep a history of the check variables so we know if it has been incremented\r
-since the last call. */\r
-static unsigned short usLastTaskCheck = ( unsigned short ) 0;\r
-portBASE_TYPE xReturn = pdTRUE;\r
-\r
- /* Check the tasks are still running by ensuring the check variable\r
- is still incrementing. */\r
-\r
- if( usCheckVariable == usLastTaskCheck )\r
- {\r
- /* The check has not incremented so an error exists. */\r
- xReturn = pdFALSE;\r
- }\r
-\r
- if( xSuspendedQueueSendError == pdTRUE )\r
- {\r
- xReturn = pdFALSE;\r
- }\r
-\r
- if( xSuspendedQueueReceiveError == pdTRUE )\r
- {\r
- xReturn = pdFALSE;\r
- }\r
-\r
- usLastTaskCheck = usCheckVariable;\r
- return xReturn;\r
-}\r
+++ /dev/null
-/*\r
- FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
- \r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-#ifndef BLOCK_Q_H\r
-#define BLOCK_Q_H\r
-\r
-void vStartBlockingQueueTasks( unsigned portBASE_TYPE uxPriority );\r
-portBASE_TYPE xAreBlockingQueuesStillRunning( void );\r
-\r
-#endif\r
-\r
-\r
+++ /dev/null
-/*\r
- FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
- \r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-#ifndef GEN_Q_TEST_H\r
-#define GEN_Q_TEST_H\r
-\r
-void vStartGenericQueueTasks( unsigned portBASE_TYPE uxPriority );\r
-portBASE_TYPE xAreGenericQueueTasksStillRunning( void );\r
-\r
-#endif /* GEN_Q_TEST_H */\r
-\r
-\r
-\r
+++ /dev/null
-/*\r
- FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
- \r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-#ifndef DYNAMIC_MANIPULATION_H\r
-#define DYNAMIC_MANIPULATION_H\r
-\r
-void vStartDynamicPriorityTasks( void );\r
-portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void );\r
-\r
-#endif\r
-\r
-\r
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )\r
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )\r
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 )\r
-#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 6800 ) )\r
+#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 6500 ) )\r
#define configMAX_TASK_NAME_LEN ( 5 )\r
#define configUSE_TRACE_FACILITY 1\r
#define configUSE_16_BIT_TICKS 0\r
#define configQUEUE_REGISTRY_SIZE 8\r
#define configCHECK_FOR_STACK_OVERFLOW 2\r
#define configUSE_RECURSIVE_MUTEXES 1\r
-#define configUSE_MALLOC_FAILED_HOOK 2\r
+#define configUSE_MALLOC_FAILED_HOOK 1\r
#define configUSE_APPLICATION_TASK_TAG 0\r
#define configUSE_COUNTING_SEMAPHORES 1\r
#define configGENERATE_RUN_TIME_STATS 0\r
#define configUSE_TIMERS 1\r
#define configTIMER_TASK_PRIORITY ( 2 )\r
#define configTIMER_QUEUE_LENGTH 2\r
-#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE )\r
+#define configTIMER_TASK_STACK_DEPTH ( 80 )\r
\r
/* Set the following definitions to 1 to include the API function, or zero\r
to exclude the API function. */\r
--- /dev/null
+/*\r
+ FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details. You should have received a copy of the GNU General Public\r
+ License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+ by writing to Richard Barry, contact details for whom are available on the\r
+ FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/******************************************************************************\r
+ * NOTE 1: This project provides two demo applications. A simple blinky style\r
+ * project, and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
+ * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
+ * in main.c. This file implements the simply blinky style version.\r
+ *\r
+ * NOTE 2: This file only contains the source code that is specific to the\r
+ * full demo. Generic functions, such FreeRTOS hook functions, and functions\r
+ * required to configure the hardware, are defined in main.c.\r
+ ******************************************************************************\r
+ *\r
+ * main_blinky() creates one software timer, one queue, and two tasks. It then\r
+ * starts the scheduler.\r
+ *\r
+ * The Queue Send Task:\r
+ * The queue send task is implemented by the prvQueueSendTask() function in\r
+ * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly\r
+ * block for 200 milliseconds, before sending the value 100 to the queue that\r
+ * was created within main_blinky(). Once the value is sent, the task loops\r
+ * back around to block for another 200 milliseconds.\r
+ *\r
+ * The Queue Receive Task:\r
+ * The queue receive task is implemented by the prvQueueReceiveTask() function\r
+ * in this file. prvQueueReceiveTask() sits in a loop where it repeatedly\r
+ * blocks on attempts to read data from the queue that was created within\r
+ * main_blinky(). When data is received, the task checks the value of the\r
+ * data, and if the value equals the expected 100, toggles the LED. The 'block\r
+ * time' parameter passed to the queue receive function specifies that the\r
+ * task should be held in the Blocked state indefinitely to wait for data to\r
+ * be available on the queue. The queue receive task will only leave the\r
+ * Blocked state when the queue send task writes to the queue. As the queue\r
+ * send task writes to the queue every 200 milliseconds, the queue receive\r
+ * task leaves the Blocked state every 200 milliseconds, and therefore toggles\r
+ * the LED every 200 milliseconds.\r
+ */\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+\r
+/* Hardware specific includes. */\r
+#include "lpc11xx.h"\r
+\r
+/* Priorities at which the tasks are created. */\r
+#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+\r
+/* The rate at which data is sent to the queue. The 200ms value is converted\r
+to ticks using the portTICK_RATE_MS constant. */\r
+#define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_RATE_MS )\r
+\r
+/* The number of items the queue can hold. This is 1 as the receive task\r
+will remove items as they are added, meaning the send task should always find\r
+the queue empty. */\r
+#define mainQUEUE_LENGTH ( 1 )\r
+\r
+/* Values passed to the two tasks just to check the task parameter\r
+functionality. */\r
+#define mainQUEUE_SEND_PARAMETER ( 0x1111UL )\r
+#define mainQUEUE_RECEIVE_PARAMETER ( 0x22UL )\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * The tasks as described in the comments at the top of this file.\r
+ */\r
+static void prvQueueReceiveTask( void *pvParameters );\r
+static void prvQueueSendTask( void *pvParameters );\r
+\r
+/*\r
+ * Called by main() to create the simply blinky style application if\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
+ */\r
+void main_blinky( void );\r
+\r
+/*\r
+ * The hardware only has a single LED. Simply toggle it.\r
+ */\r
+extern void vMainToggleLED( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The queue used by both tasks. */\r
+static xQueueHandle xQueue = NULL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void main_blinky( void )\r
+{\r
+ /* Create the queue. */\r
+ xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
+\r
+ if( xQueue != NULL )\r
+ {\r
+ /* Start the two tasks as described in the comments at the top of this\r
+ file. */\r
+ xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */\r
+ ( signed char * ) "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
+ configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */\r
+ ( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */\r
+ mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */\r
+ NULL ); /* The task handle is not required, so NULL is passed. */\r
+\r
+ xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
+\r
+ /* Start the tasks and timer running. */\r
+ vTaskStartScheduler();\r
+ }\r
+\r
+ /* If all is well, the scheduler will now be running, and the following\r
+ line will never be reached. If the following line does execute, then\r
+ there was insufficient FreeRTOS heap memory available for the idle and/or\r
+ timer tasks to be created. See the memory management section on the\r
+ FreeRTOS web site for more details. */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueSendTask( void *pvParameters )\r
+{\r
+portTickType xNextWakeTime;\r
+const unsigned long ulValueToSend = 100UL;\r
+\r
+ /* Check the task parameter is as expected. */\r
+ configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER );\r
+\r
+ /* Initialise xNextWakeTime - this only needs to be done once. */\r
+ xNextWakeTime = xTaskGetTickCount();\r
+\r
+ for( ;; )\r
+ {\r
+ /* Place this task in the blocked state until it is time to run again.\r
+ The block time is specified in ticks, the constant used converts ticks\r
+ to ms. While in the Blocked state this task will not consume any CPU\r
+ time. */\r
+ vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
+\r
+ /* Send to the queue - causing the queue receive task to unblock and\r
+ toggle the LED. 0 is used as the block time so the sending operation\r
+ will not block - it shouldn't need to block as the queue should always\r
+ be empty at this point in the code. */\r
+ xQueueSend( xQueue, &ulValueToSend, 0U );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueReceiveTask( void *pvParameters )\r
+{\r
+unsigned long ulReceivedValue;\r
+\r
+ /* Check the task parameter is as expected. */\r
+ configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER );\r
+\r
+ for( ;; )\r
+ {\r
+ /* Wait until something arrives in the queue - this task will block\r
+ indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
+ FreeRTOSConfig.h. */\r
+ xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
+\r
+ /* To get here something must have been received from the queue, but\r
+ is it the expected value? If it is, toggle the LED. */\r
+ if( ulReceivedValue == 100UL )\r
+ {\r
+ vMainToggleLED();\r
+ ulReceivedValue = 0U;\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
--- /dev/null
+/*\r
+ FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details. You should have received a copy of the GNU General Public\r
+ License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+ by writing to Richard Barry, contact details for whom are available on the\r
+ FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+/******************************************************************************\r
+ * NOTE 1: This project provides two demo applications. A simple blinky style\r
+ * project, and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
+ * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
+ * in main.c. This file implements the comprehensive test and demo version.\r
+ *\r
+ * NOTE 2: This file only contains the source code that is specific to the\r
+ * full demo. Generic functions, such FreeRTOS hook functions, and functions\r
+ * required to configure the hardware, are defined in main.c.\r
+ ******************************************************************************\r
+ *\r
+ * main_full() creates all the demo application tasks (including a set of tasks\r
+ * that test the interrupt nesting behaviour) and a timer, then starts the\r
+ * scheduler. The web documentation provides more details of the standard demo\r
+ * application tasks, which provide no particular functionality, but do provide\r
+ * a good example of how to use the FreeRTOS API.\r
+ *\r
+ * The interrupt nesting test tasks require that two timers are configured to\r
+ * generate interrupts. The interrupt service routines are defined in\r
+ * IntQueueTimer.c, and can be used as examples for application writers. They\r
+ * do not, however, directly demonstrate the use of FreeRTOS safe API functions\r
+ * (those that end in "FromISR"). Therefore, a dummy interrupt implementation\r
+ * called Dummy_IRQHandler() is provided at the end of main.c.\r
+ *\r
+ * In addition to the standard demo tasks, the following tasks and timer are\r
+ * defined and/or created within this file:\r
+ *\r
+ * "Reg test" tasks - These fill the registers with known values, then check\r
+ * that each register maintains its expected value for the lifetime of the\r
+ * task. Each task uses a different set of values. The reg test tasks execute\r
+ * with a very low priority, so get preempted very frequently. A register\r
+ * containing an unexpected value is indicative of an error in the context\r
+ * switching mechanism.\r
+ *\r
+ * "Check" software timer - The check timer period is initially set to three\r
+ * seconds. Its callback function checks that all the standard demo tasks, and\r
+ * the register check tasks, are not only still executing, but are executing\r
+ * without reporting any errors. If the check timer callback discovers that a\r
+ * task has either stalled, or reported an error, then it changes the period of\r
+ * the check timer from the initial three seconds, to just 200ms. The callback\r
+ * function also toggles an LED each time it is called. This provides a visual\r
+ * indication of the system status: If the LED toggles every three seconds,\r
+ * then no issues have been discovered. If the LED toggles every 200ms, then\r
+ * an issue has been discovered with at least one task.\r
+ */\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+#include "timers.h"\r
+\r
+/* Common demo includes. */\r
+#include "blocktim.h"\r
+#include "countsem.h"\r
+#include "recmutex.h"\r
+#include "IntQueue.h"\r
+\r
+/* Hardware specific includes. */\r
+#include "lpc11xx.h"\r
+\r
+/* The period after which the check timer will expire provided no errors have\r
+been reported by any of the standard demo tasks. ms are converted to the\r
+equivalent in ticks using the portTICK_RATE_MS constant. */\r
+#define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )\r
+\r
+/* The period at which the check timer will expire if an error has been\r
+reported in one of the standard demo tasks. ms are converted to the equivalent\r
+in ticks using the portTICK_RATE_MS constant. */\r
+#define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )\r
+\r
+/* A block time of zero simply means "don't block". */\r
+#define mainDONT_BLOCK ( 0UL )\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Register check tasks, as described at the top of this file. The nature of\r
+ * these files necessitates that they are written in an assembly.\r
+ */\r
+extern void vRegTest1Task( void *pvParameters );\r
+extern void vRegTest2Task( void *pvParameters );\r
+\r
+/*\r
+ * The hardware only has a single LED. Simply toggle it.\r
+ */\r
+extern void vMainToggleLED( void );\r
+\r
+/*\r
+ * The check timer callback function, as described at the top of this file.\r
+ */\r
+static void prvCheckTimerCallback( xTimerHandle xTimer );\r
+\r
+/*\r
+ * Called by main() to create the comprehensive test/demo application if\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not set to 1.\r
+ */\r
+void main_full( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The following two variables are used to communicate the status of the\r
+register check tasks to the check software timer. If the variables keep\r
+incrementing, then the register check tasks has not discovered any errors. If\r
+a variable stops incrementing, then an error has been found. */\r
+volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void main_full( void )\r
+{\r
+xTimerHandle xCheckTimer = NULL;\r
+/* The register test tasks are asm functions that don't use a stack. The\r
+stack allocated just has to be large enough to hold the task context, and\r
+for the additional required for the stack overflow checking to work (if\r
+configured). */\r
+const size_t xRegTestStackSize = 25U;\r
+\r
+ /* Create the standard demo tasks, including the interrupt nesting test\r
+ tasks. */\r
+ vStartInterruptQueueTasks();\r
+ vCreateBlockTimeTasks();\r
+ vStartCountingSemaphoreTasks();\r
+ vStartRecursiveMutexTasks();\r
+\r
+ /* Create the register test tasks as described at the top of this file.\r
+ These are naked functions that don't use any stack. A stack still has\r
+ to be allocated to hold the task context. */\r
+ xTaskCreate( vRegTest1Task, /* Function that implements the task. */\r
+ ( signed char * ) "Reg1", /* Text name of the task. */\r
+ xRegTestStackSize, /* Stack allocated to the task. */\r
+ NULL, /* The task parameter is not used. */\r
+ tskIDLE_PRIORITY, /* The priority to assign to the task. */\r
+ NULL ); /* Don't receive a handle back, it is not needed. */\r
+\r
+ xTaskCreate( vRegTest2Task, /* Function that implements the task. */\r
+ ( signed char * ) "Reg2", /* Text name of the task. */\r
+ xRegTestStackSize, /* Stack allocated to the task. */\r
+ NULL, /* The task parameter is not used. */\r
+ tskIDLE_PRIORITY, /* The priority to assign to the task. */\r
+ NULL ); /* Don't receive a handle back, it is not needed. */\r
+\r
+ /* Create the software timer that performs the 'check' functionality,\r
+ as described at the top of this file. */\r
+ xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
+ ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */\r
+ pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
+ ( void * ) 0, /* The ID is not used, so can be set to anything. */\r
+ prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */\r
+ );\r
+\r
+ /* If the software timer was created successfully, start it. It won't\r
+ actually start running until the scheduler starts. A block time of\r
+ zero is used in this call, although any value could be used as the block\r
+ time will be ignored because the scheduler has not started yet. */\r
+ if( xCheckTimer != NULL )\r
+ {\r
+ xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
+ }\r
+\r
+ /* Start the kernel. From here on, only tasks and interrupts will run. */\r
+ vTaskStartScheduler();\r
+\r
+ /* If all is well, the scheduler will now be running, and the following\r
+ line will never be reached. If the following line does execute, then there\r
+ was insufficient FreeRTOS heap memory available for the idle and/or timer\r
+ tasks to be created. See the memory management section on the FreeRTOS web\r
+ site, or the FreeRTOS tutorial books for more details. */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* See the description at the top of this file. */\r
+static void prvCheckTimerCallback( xTimerHandle xTimer )\r
+{\r
+static long lChangedTimerPeriodAlready = pdFALSE;\r
+static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;\r
+unsigned long ulErrorFound = pdFALSE;\r
+\r
+ /* Check all the demo and test tasks to ensure that they are all still\r
+ running, and that none have detected an error. */\r
+ if( xAreIntQueueTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 0UL );\r
+ }\r
+\r
+ if( xAreBlockTimeTestTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 1UL );\r
+ }\r
+\r
+ if( xAreCountingSemaphoreTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 2UL );\r
+ }\r
+\r
+ if( xAreRecursiveMutexTasksStillRunning() != pdPASS )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 3UL );\r
+ }\r
+\r
+ /* Check that the register test 1 task is still running. */\r
+ if( ulLastRegTest1Value == ulRegTest1LoopCounter )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 4UL );\r
+ }\r
+ ulLastRegTest1Value = ulRegTest1LoopCounter;\r
+\r
+ /* Check that the register test 2 task is still running. */\r
+ if( ulLastRegTest2Value == ulRegTest2LoopCounter )\r
+ {\r
+ ulErrorFound |= ( 0x01UL << 5UL );\r
+ }\r
+ ulLastRegTest2Value = ulRegTest2LoopCounter;\r
+\r
+ /* Toggle the check LED to give an indication of the system status. If\r
+ the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
+ everything is ok. A faster toggle indicates an error. */\r
+ vMainToggleLED();\r
+\r
+ /* Have any errors been latched in ulErrorFound? If so, shorten the\r
+ period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
+ This will result in an increase in the rate at which mainCHECK_LED\r
+ toggles. */\r
+ if( ulErrorFound != pdFALSE )\r
+ {\r
+ if( lChangedTimerPeriodAlready == pdFALSE )\r
+ {\r
+ lChangedTimerPeriodAlready = pdTRUE;\r
+\r
+ /* This call to xTimerChangePeriod() uses a zero block time.\r
+ Functions called from inside of a timer callback function must\r
+ *never* attempt to block. */\r
+ xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
licensing and training services.\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
/* Standard includes. */\r
#include "string.h"\r
\r
-/* Kernel includes. */\r
+/* FreeRTOS includes. */\r
#include "FreeRTOS.h"\r
#include "task.h"\r
-#include "queue.h"\r
-#include "timers.h"\r
-\r
-/* Common demo includes. */\r
-#include "dynamic.h"\r
-#include "blocktim.h"\r
-#include "countsem.h"\r
-#include "GenQTest.h"\r
-#include "recmutex.h"\r
-#include "IntQueue.h"\r
\r
/* Hardware specific includes. */\r
#include "lpc11xx.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 1\r
+\r
/* The bit on port 0 to which the LED is wired. */\r
#define mainLED_BIT ( 1UL << 7UL )\r
\r
-/* The period after which the check timer will expire, in ms, provided no errors\r
-have been reported by any of the standard demo tasks. ms are converted to the\r
-equivalent in ticks using the portTICK_RATE_MS constant. */\r
-#define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )\r
-\r
-/* The period at which the check timer will expire, in ms, if an error has been\r
-reported in one of the standard demo tasks. ms are converted to the equivalent\r
-in ticks using the portTICK_RATE_MS constant. */\r
-#define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )\r
-\r
-/* A block time of zero simply means "don't block". */\r
-#define mainDONT_BLOCK ( 0UL )\r
-\r
+/* The configCHECK_FOR_STACK_OVERFLOW setting in FreeRTOSConifg can be used to\r
+check task stacks for overflows. It does not however check the stack used by\r
+interrupts. This demo has a simple addition that will also check the stack used\r
+by interrupts if mainCHECK_INTERRUPT_STACK is set to 1. Note that this check is\r
+only performed from the tick hook function (which runs in an interrupt context).\r
+It is a good debugging aid - but won't catch interrupt stack problems until the\r
+tick interrupt next executes. */\r
#define mainCHECK_INTERRUPT_STACK 1\r
-\r
#if mainCHECK_INTERRUPT_STACK == 1\r
const unsigned char ucExpectedInterruptStackValues[] = { 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC };\r
#endif\r
\r
/*-----------------------------------------------------------*/\r
\r
-/*\r
- * Register check tasks, as described at the top of this file. The nature of\r
- * these files necessitates that they are written in an assembly file.\r
- */\r
-extern void vRegTest1Task( void *pvParameters );\r
-extern void vRegTest2Task( void *pvParameters );\r
-\r
/*\r
* Perform any application specific hardware configuration. The clocks,\r
* memory, etc. are configured before main() is called.\r
/*\r
* The hardware only has a single LED. Simply toggle it.\r
*/\r
-static void prvToggleLED( void );\r
+void vMainToggleLED( void );\r
\r
-/*\r
- * The check timer callback function, as described at the top of this file.\r
- */\r
-static void prvCheckTimerCallback( xTimerHandle xTimer );\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
+void main_blinky( void );\r
+void main_full( void );\r
\r
/*-----------------------------------------------------------*/\r
\r
/* The GPIO port to which the LED is attached. */\r
static LPC_GPIO_TypeDef * const xGPIO0 = LPC_GPIO0;\r
\r
-/* The following two variables are used to communicate the status of the\r
-register check tasks to the check software timer. If the variables keep\r
-incrementing, then the register check tasks has not discovered any errors. If\r
-a variable stops incrementing, then an error has been found. */\r
-volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;\r
-\r
/*-----------------------------------------------------------*/\r
-\r
int main( void )\r
{\r
-xTimerHandle xCheckTimer = NULL;\r
-\r
+ /* Prepare the hardware to run this demo. */\r
prvSetupHardware();\r
\r
- /* Create the standard demo tasks. */\r
-// vStartDynamicPriorityTasks();\r
-// vCreateBlockTimeTasks();\r
-// vStartCountingSemaphoreTasks();\r
-// vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
-// vStartRecursiveMutexTasks();\r
- vStartInterruptQueueTasks();\r
-\r
- /* Create the register test tasks as described at the top of this file. */\r
- xTaskCreate( vRegTest1Task, /* Function that implements the task. */\r
- ( signed char * ) "Reg1", /* Text name of the task. */\r
- configMINIMAL_STACK_SIZE, /* Stack allocated to the task. */\r
- NULL, /* The task parameter is not used. */\r
- tskIDLE_PRIORITY, /* The priority to assign to the task. */\r
- NULL ); /* Don't receive a handle back, it is not needed. */\r
-\r
- xTaskCreate( vRegTest2Task, /* Function that implements the task. */\r
- ( signed char * ) "Reg2", /* Text name of the task. */\r
- configMINIMAL_STACK_SIZE, /* Stack allocated to the task. */\r
- NULL, /* The task parameter is not used. */\r
- tskIDLE_PRIORITY, /* The priority to assign to the task. */\r
- NULL ); /* Don't receive a handle back, it is not needed. */\r
-\r
- /* Create the software timer that performs the 'check' functionality,\r
- as described at the top of this file. */\r
- xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */\r
- ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */\r
- pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
- ( void * ) 0, /* The ID is not used, so can be set to anything. */\r
- prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */\r
- );\r
-\r
- if( xCheckTimer != NULL )\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
- xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
+ main_blinky();\r
}\r
-\r
- /* Start the kernel. From here on, only tasks and interrupts will run. */\r
- vTaskStartScheduler();\r
-\r
- /* If all is well, the scheduler will now be running, and the following\r
- line will never be reached. If the following line does execute, then there\r
- was insufficient FreeRTOS heap memory available for the idle and/or timer\r
- tasks to be created. See the memory management section on the FreeRTOS web\r
- site, or the FreeRTOS tutorial books for more details. */\r
- for( ;; );\r
+ #else\r
+ {\r
+ main_full();\r
+ }\r
+ #endif\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void prvCheckTimerCallback( xTimerHandle xTimer )\r
+void vMainToggleLED( void )\r
{\r
-static long lChangedTimerPeriodAlready = pdFALSE;\r
-static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;\r
-unsigned long ulErrorFound = pdFALSE;\r
+static unsigned long ulLEDState = 0UL;\r
\r
- /* Check all the demo and test tasks to ensure that they are all still\r
- running, and that none have detected an error. */\r
- if( xAreIntQueueTasksStillRunning() != pdPASS )\r
+ if( ulLEDState == 0UL )\r
{\r
- ulErrorFound |= ( 0x01UL << 0UL );\r
+ xGPIO0->MASKED_ACCESS[ mainLED_BIT ] = 0UL;\r
}\r
-\r
- /* Check that the register test 1 task is still running. */\r
- if( ulLastRegTest1Value == ulRegTest1LoopCounter )\r
+ else\r
{\r
- ulErrorFound |= ( 0x01UL << 10UL );\r
+ xGPIO0->MASKED_ACCESS[ mainLED_BIT ] = mainLED_BIT;\r
}\r
- ulLastRegTest1Value = ulRegTest1LoopCounter;\r
\r
- /* Check that the register test 2 task is still running. */\r
- if( ulLastRegTest2Value == ulRegTest2LoopCounter )\r
- {\r
- ulErrorFound |= ( 0x01UL << 11UL );\r
- }\r
- ulLastRegTest2Value = ulRegTest2LoopCounter;\r
-\r
- /* Toggle the check LED to give an indication of the system status. If\r
- the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
- everything is ok. A faster toggle indicates an error. */\r
- prvToggleLED();\r
-\r
- /* Have any errors been latched in ulErrorFound? If so, shorten the\r
- period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
- This will result in an increase in the rate at which mainCHECK_LED\r
- toggles. */\r
- if( ulErrorFound != pdFALSE )\r
- {\r
- if( lChangedTimerPeriodAlready == pdFALSE )\r
- {\r
- lChangedTimerPeriodAlready = pdTRUE;\r
-\r
- /* This call to xTimerChangePeriod() uses a zero block time.\r
- Functions called from inside of a timer callback function must\r
- *never* attempt to block. */\r
- xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
- }\r
- }\r
+ ulLEDState = !ulLEDState;\r
}\r
/*-----------------------------------------------------------*/\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void prvToggleLED( void )\r
-{\r
-static unsigned long ulLEDState = 0UL;\r
-\r
- if( ulLEDState == 0UL )\r
- {\r
- xGPIO0->MASKED_ACCESS[ mainLED_BIT ] = 0UL;\r
- }\r
- else\r
- {\r
- xGPIO0->MASKED_ACCESS[ mainLED_BIT ] = mainLED_BIT;\r
- }\r
-\r
- ulLEDState = !ulLEDState;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
void vApplicationMallocFailedHook( void )\r
{\r
/* vApplicationMallocFailedHook() will only be called if\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. */\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
\r
\r