--- /dev/null
+/*\r
+ FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify\r
+ it under the terms of the GNU General Public License as published by\r
+ the Free Software Foundation; either version 2 of the License, or\r
+ (at your option) any later version.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with FreeRTOS.org; if not, write to the Free Software\r
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+\r
+ A special exception to the GPL can be applied should you wish to distribute\r
+ a combined work that includes FreeRTOS.org, without being obliged to provide\r
+ the source code for any proprietary components. See the licensing section\r
+ of http://www.FreeRTOS.org for full details of how and when the exception\r
+ can be applied.\r
+\r
+ ***************************************************************************\r
+ See http://www.FreeRTOS.org for documentation, latest information, license\r
+ and contact details. Please ensure to read the configuration and relevant\r
+ port sections of the online documentation.\r
+\r
+ Also see http://www.SafeRTOS.com a version that has been certified for use\r
+ in safety critical systems, plus commercial licensing, development and\r
+ support options.\r
+ ***************************************************************************\r
+*/\r
+\r
+\r
+/* \r
+ * Simple demonstration of the usage of counting semaphore.\r
+ */\r
+\r
+/* Scheduler include files. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
+/* Demo program include files. */\r
+#include "countsem.h"\r
+\r
+/* The maximum count value that the semaphore used for the demo can hold. */\r
+#define countMAX_COUNT_VALUE ( 200 )\r
+\r
+/* Constants used to indicate whether or not the semaphore should have been\r
+created with its maximum count value, or its minimum count value. These \r
+numbers are used to ensure that the pointers passed in as the task parameters\r
+are valid. */\r
+#define countSTART_AT_MAX_COUNT ( 0xaa )\r
+#define countSTART_AT_ZERO ( 0x55 )\r
+\r
+/* Two tasks are created for the test. One uses a semaphore created with its\r
+count value set to the maximum, and one with the count value set to zero. */\r
+#define countNUM_TEST_TASKS ( 2 )\r
+#define countDONT_BLOCK ( 0 )\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
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * The demo task. This simply counts the semaphore up to its maximum value,\r
+ * the counts it back down again. The result of each semaphore 'give' and\r
+ * 'take' is inspected, with an error being flagged if it is found not to be\r
+ * the expected result.\r
+ */\r
+static void prvCountingSemaphoreTask( void *pvParameters );\r
+\r
+/*\r
+ * Utility function to increment the semaphore count value up from zero to\r
+ * countMAX_COUNT_VALUE.\r
+ */\r
+static void prvIncrementSemaphoreCount( xSemaphoreHandle xSemaphore, unsigned portBASE_TYPE *puxLoopCounter );\r
+\r
+/*\r
+ * Utility function to decrement the semaphore count value up from \r
+ * countMAX_COUNT_VALUE to zero.\r
+ */\r
+static void prvDecrementSemaphoreCount( xSemaphoreHandle xSemaphore, unsigned portBASE_TYPE *puxLoopCounter );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The structure that is passed into the task as the task parameter. */\r
+typedef struct COUNT_SEM_STRUCT\r
+{\r
+ /* The semaphore to be used for the demo. */\r
+ xSemaphoreHandle xSemaphore;\r
+\r
+ /* Set to countSTART_AT_MAX_COUNT if the semaphore should be created with\r
+ its count value set to its max count value, or countSTART_AT_ZERO if it\r
+ should have been created with its count value set to 0. */\r
+ unsigned portBASE_TYPE uxExpectedStartCount; \r
+\r
+ /* Incremented on each cycle of the demo task. Used to detect a stalled\r
+ task. */\r
+ unsigned portBASE_TYPE uxLoopCounter; \r
+} xCountSemStruct;\r
+\r
+/* Two structures are defined, one is passed to each test task. */\r
+static xCountSemStruct xParameters[ countNUM_TEST_TASKS ];\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vStartCountingSemaphoreTasks( void )\r
+{\r
+ /* Create the semaphores that we are going to use for the test/demo. The\r
+ first should be created such that it starts at its maximum count value,\r
+ the second should be created such that it starts with a count value of zero. */\r
+ xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE );\r
+ xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT;\r
+ xParameters[ 0 ].uxLoopCounter = 0;\r
+\r
+ xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );\r
+ xParameters[ 1 ].uxExpectedStartCount = 0;\r
+ xParameters[ 1 ].uxLoopCounter = 0;\r
+\r
+ /* Were the semaphores created? */\r
+ if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) )\r
+ {\r
+ /* Create the demo tasks, passing in the semaphore to use as the parameter. */\r
+ xTaskCreate( prvCountingSemaphoreTask, "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL );\r
+ xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL ); \r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvDecrementSemaphoreCount( xSemaphoreHandle xSemaphore, unsigned portBASE_TYPE *puxLoopCounter )\r
+{\r
+unsigned portBASE_TYPE ux;\r
+\r
+ /* If the semaphore count is at its maximum then we should not be able to\r
+ 'give' the semaphore. */\r
+ if( xSemaphoreGive( xSemaphore ) == pdPASS )\r
+ {\r
+ xErrorDetected = pdTRUE;\r
+ }\r
+\r
+ /* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */\r
+ for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )\r
+ {\r
+ if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS )\r
+ {\r
+ /* We expected to be able to take the semaphore. */\r
+ xErrorDetected = pdTRUE;\r
+ }\r
+\r
+ ( *puxLoopCounter )++;\r
+ }\r
+\r
+ /* If the semaphore count is zero then we should not be able to 'take' \r
+ the semaphore. */\r
+ if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )\r
+ {\r
+ xErrorDetected = pdTRUE;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvIncrementSemaphoreCount( xSemaphoreHandle xSemaphore, unsigned portBASE_TYPE *puxLoopCounter )\r
+{\r
+unsigned portBASE_TYPE ux;\r
+\r
+ /* If the semaphore count is zero then we should not be able to 'take' \r
+ the semaphore. */\r
+ if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )\r
+ {\r
+ xErrorDetected = pdTRUE;\r
+ }\r
+\r
+ /* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */\r
+ for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )\r
+ {\r
+ if( xSemaphoreGive( xSemaphore ) != pdPASS )\r
+ {\r
+ /* We expected to be able to take the semaphore. */\r
+ xErrorDetected = pdTRUE;\r
+ }\r
+\r
+ ( *puxLoopCounter )++;\r
+ }\r
+\r
+ /* If the semaphore count is at its maximum then we should not be able to\r
+ 'give' the semaphore. */\r
+ if( xSemaphoreGive( xSemaphore ) == pdPASS )\r
+ {\r
+ xErrorDetected = pdTRUE;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCountingSemaphoreTask( void *pvParameters )\r
+{\r
+xCountSemStruct *pxParameter;\r
+\r
+ #ifdef USE_STDIO\r
+ void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );\r
+ \r
+ const portCHAR * const pcTaskStartMsg = "Counting semaphore demo started.\r\n";\r
+\r
+ /* Queue a message for printing to say the task has started. */\r
+ vPrintDisplayMessage( &pcTaskStartMsg );\r
+ #endif\r
+\r
+ /* The semaphore to be used was passed as the parameter. */\r
+ pxParameter = ( xCountSemStruct * ) pvParameters;\r
+\r
+ /* Did we expect to find the semaphore already at its max count value, or\r
+ at zero? */\r
+ if( pxParameter->uxExpectedStartCount == countSTART_AT_MAX_COUNT )\r
+ {\r
+ prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );\r
+ }\r
+\r
+ /* Now we expect the semaphore count to be 0, so this time there is an\r
+ error if we can take the semaphore. */\r
+ if( xSemaphoreTake( pxParameter->xSemaphore, 0 ) == pdPASS )\r
+ {\r
+ xErrorDetected = pdTRUE;\r
+ }\r
+\r
+ for( ;; )\r
+ {\r
+ prvIncrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );\r
+ prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+portBASE_TYPE xAreCountingSemaphoreTasksStillRunning( void )\r
+{\r
+static unsigned portBASE_TYPE uxLastCount0 = 0, uxLastCount1 = 0;\r
+portBASE_TYPE xReturn = pdPASS;\r
+\r
+ /* Return fail if any 'give' or 'take' did not result in the expected\r
+ behaviour. */\r
+ if( xErrorDetected != pdFALSE )\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
+\r
+ /* Return fail if either task is not still incrementing its loop counter. */\r
+ if( uxLastCount0 == xParameters[ 0 ].uxLoopCounter )\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
+ else\r
+ {\r
+ uxLastCount0 = xParameters[ 0 ].uxLoopCounter;\r
+ }\r
+\r
+ if( uxLastCount1 == xParameters[ 1 ].uxLoopCounter )\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
+ else\r
+ {\r
+ uxLastCount1 = xParameters[ 1 ].uxLoopCounter;\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+\r
+\r
--- /dev/null
+/*\r
+ FreeRTOS.org V4.6.1 - Copyright (C) 2003-2007 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify\r
+ it under the terms of the GNU General Public License as published by\r
+ the Free Software Foundation; either version 2 of the License, or\r
+ (at your option) any later version.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU General Public License for more details.\r
+\r
+ You should have received a copy of the GNU General Public License\r
+ along with FreeRTOS.org; if not, write to the Free Software\r
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+\r
+ A special exception to the GPL can be applied should you wish to distribute\r
+ a combined work that includes FreeRTOS.org, without being obliged to provide\r
+ the source code for any proprietary components. See the licensing section \r
+ of http://www.FreeRTOS.org for full details of how and when the exception\r
+ can be applied.\r
+\r
+ ***************************************************************************\r
+ See http://www.FreeRTOS.org for documentation, latest information, license \r
+ and contact details. Please ensure to read the configuration and relevant \r
+ port sections of the online documentation.\r
+\r
+ Also see http://www.SafeRTOS.com a version that has been certified for use\r
+ in safety critical systems, plus commercial licensing, development and\r
+ support options.\r
+ ***************************************************************************\r
+*/\r
+\r
+#ifndef COUNT_SEMAPHORE_TEST_H\r
+#define COUNT_SEMAPHORE_TEST_H\r
+\r
+void vStartCountingSemaphoreTasks( void );\r
+portBASE_TYPE xAreCountingSemaphoreTasksStillRunning( void );\r
+\r
+#endif\r
+\r
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. \r
*----------------------------------------------------------*/\r
\r
-#define configUSE_PREEMPTION 1\r
-#define configUSE_IDLE_HOOK 1\r
-#define configUSE_TICK_HOOK 1\r
-#define configTICK_RATE_HZ ( ( portTickType ) 1000 )\r
-#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 256 ) /* This can be made smaller if required. */\r
-#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) ) \r
-#define configMAX_TASK_NAME_LEN ( 16 )\r
-#define configUSE_TRACE_FACILITY 1\r
-#define configUSE_16_BIT_TICKS 1\r
-#define configIDLE_SHOULD_YIELD 1\r
-#define configUSE_CO_ROUTINES 1\r
-#define configUSE_MUTEXES 1\r
+#define configUSE_PREEMPTION 1\r
+#define configUSE_IDLE_HOOK 1\r
+#define configUSE_TICK_HOOK 1\r
+#define configTICK_RATE_HZ ( ( portTickType ) 1000 )\r
+#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 256 ) /* This can be made smaller if required. */\r
+#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) ) \r
+#define configMAX_TASK_NAME_LEN ( 16 )\r
+#define configUSE_TRACE_FACILITY 1\r
+#define configUSE_16_BIT_TICKS 1\r
+#define configIDLE_SHOULD_YIELD 1\r
+#define configUSE_CO_ROUTINES 1\r
+#define configUSE_MUTEXES 1\r
+#define configUSE_COUNTING_SEMAPHORES 1\r
\r
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 10 )\r
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )\r
* <HR>\r
*/\r
\r
-/*\r
-Changes from V1.00:\r
-\r
- + Prevent the call to kbhit() for debug builds as the debugger seems to\r
- have problems stepping over the call.\r
-\r
-Changes from V1.2.3\r
-\r
- + The integer and comtest tasks are now used when the cooperative scheduler \r
- is being used. Previously they were only used with the preemptive\r
- scheduler.\r
-\r
-Changes from V1.2.6\r
-\r
- + Create new tasks as defined by the new demo application file dynamic.c.\r
-\r
-Changes from V2.0.0\r
-\r
- + Delay periods are now specified using variables and constants of\r
- portTickType rather than unsigned portLONG.\r
-\r
-Changes from V3.1.1\r
-\r
- + The tasks defined in the new file "events.c" are now created and \r
- monitored for errors. \r
-\r
-Changes from V3.2.4\r
-\r
- + Now includes the flash co-routine demo rather than the flash task demo.\r
- This is to demonstrate the co-routine functionality.\r
-*/\r
-\r
#include <stdlib.h>\r
#include <conio.h>\r
#include "FreeRTOS.h"\r
#include "blocktim.h"\r
#include "GenQTest.h"\r
#include "QPeek.h"\r
+#include "countsem.h"\r
\r
/* Priority definitions for the tasks in the demo application. */\r
#define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
vStartDynamicPriorityTasks();\r
vStartMultiEventTasks();\r
vStartQueuePeekTasks();\r
+ vStartCountingSemaphoreTasks();\r
\r
/* Create the "Print" task as described at the top of the file. */\r
xTaskCreate( vErrorChecks, "Print", mainPRINT_STACK_SIZE, NULL, mainPRINT_TASK_PRIORITY, NULL );\r
sErrorHasOccurred = pdTRUE;\r
}\r
\r
+ if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
+ {\r
+ vDisplayMessage( "Error in counting semaphore demo task!\r\n" );\r
+ sErrorHasOccurred = pdTRUE;\r
+ }\r
+\r
if( sErrorHasOccurred == pdFALSE )\r
{\r
vDisplayMessage( "OK " );\r
0\r
19\r
WPickList\r
-53\r
+55\r
20\r
MItem\r
3\r
0\r
172\r
MItem\r
-27\r
-..\COMMON\MINIMAL\crflash.c\r
+28\r
+..\COMMON\MINIMAL\countsem.c\r
173\r
WString\r
4\r
0\r
176\r
MItem\r
-26\r
-..\COMMON\MINIMAL\crhook.c\r
+27\r
+..\COMMON\MINIMAL\crflash.c\r
177\r
WString\r
4\r
0\r
180\r
MItem\r
-28\r
-..\COMMON\MINIMAL\GenQTest.c\r
+26\r
+..\COMMON\MINIMAL\crhook.c\r
181\r
WString\r
4\r
0\r
184\r
MItem\r
-25\r
-..\COMMON\MINIMAL\QPeek.c\r
+28\r
+..\COMMON\MINIMAL\GenQTest.c\r
185\r
WString\r
4\r
0\r
188\r
MItem\r
-15\r
-fileio\fileio.c\r
+25\r
+..\COMMON\MINIMAL\QPeek.c\r
189\r
WString\r
4\r
0\r
192\r
MItem\r
-6\r
-main.c\r
+15\r
+fileio\fileio.c\r
193\r
WString\r
4\r
0\r
196\r
MItem\r
-17\r
-partest\partest.c\r
+6\r
+main.c\r
197\r
WString\r
4\r
0\r
200\r
MItem\r
-15\r
-serial\serial.c\r
+17\r
+partest\partest.c\r
201\r
WString\r
4\r
0\r
204\r
MItem\r
-3\r
-*.h\r
+15\r
+serial\serial.c\r
205\r
WString\r
-3\r
-NIL\r
+4\r
+COBJ\r
206\r
WVList\r
0\r
207\r
WVList\r
0\r
--1\r
+20\r
+1\r
1\r
-0\r
0\r
208\r
MItem\r
-31\r
-..\..\SOURCE\INCLUDE\croutine.h\r
+3\r
+*.h\r
209\r
WString\r
3\r
211\r
WVList\r
0\r
-204\r
-1\r
+-1\r
1\r
0\r
+0\r
212\r
MItem\r
-27\r
-..\..\source\include\list.h\r
+31\r
+..\..\SOURCE\INCLUDE\croutine.h\r
213\r
WString\r
3\r
215\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
216\r
MItem\r
-31\r
-..\..\source\include\portable.h\r
+27\r
+..\..\source\include\list.h\r
217\r
WString\r
3\r
219\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
220\r
MItem\r
31\r
-..\..\source\include\projdefs.h\r
+..\..\source\include\portable.h\r
221\r
WString\r
3\r
223\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
224\r
MItem\r
-28\r
-..\..\source\include\queue.h\r
+31\r
+..\..\source\include\projdefs.h\r
225\r
WString\r
3\r
227\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
228\r
MItem\r
-29\r
-..\..\source\include\semphr.h\r
+28\r
+..\..\source\include\queue.h\r
229\r
WString\r
3\r
231\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
232\r
MItem\r
-27\r
-..\..\source\include\task.h\r
+29\r
+..\..\source\include\semphr.h\r
233\r
WString\r
3\r
235\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
236\r
MItem\r
-55\r
-..\..\source\portable\owatcom\16bitdos\common\portasm.h\r
+27\r
+..\..\source\include\task.h\r
237\r
WString\r
3\r
239\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
240\r
MItem\r
-53\r
-..\..\source\portable\owatcom\16bitdos\pc\portmacro.h\r
+55\r
+..\..\source\portable\owatcom\16bitdos\common\portasm.h\r
241\r
WString\r
3\r
243\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
244\r
MItem\r
-26\r
-..\common\include\blockq.h\r
+53\r
+..\..\source\portable\owatcom\16bitdos\pc\portmacro.h\r
245\r
WString\r
3\r
247\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
248\r
MItem\r
-28\r
-..\COMMON\INCLUDE\blocktim.h\r
+26\r
+..\common\include\blockq.h\r
249\r
WString\r
3\r
251\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
252\r
MItem\r
-27\r
-..\common\include\comtest.h\r
+28\r
+..\COMMON\INCLUDE\blocktim.h\r
253\r
WString\r
3\r
255\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
256\r
MItem\r
-26\r
-..\COMMON\INCLUDE\crhook.h\r
+27\r
+..\common\include\comtest.h\r
257\r
WString\r
3\r
259\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
260\r
MItem\r
-25\r
-..\common\include\death.h\r
+28\r
+..\COMMON\INCLUDE\countsem.h\r
261\r
WString\r
3\r
263\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
264\r
MItem\r
-27\r
-..\COMMON\INCLUDE\dynamic.h\r
+26\r
+..\COMMON\INCLUDE\crhook.h\r
265\r
WString\r
3\r
267\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
268\r
MItem\r
-26\r
-..\common\include\fileio.h\r
+25\r
+..\common\include\death.h\r
269\r
WString\r
3\r
271\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
272\r
MItem\r
-25\r
-..\common\include\flash.h\r
+27\r
+..\COMMON\INCLUDE\dynamic.h\r
273\r
WString\r
3\r
275\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
276\r
MItem\r
-24\r
-..\common\include\flop.h\r
+26\r
+..\common\include\fileio.h\r
277\r
WString\r
3\r
279\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
280\r
MItem\r
-28\r
-..\COMMON\INCLUDE\GenQTest.h\r
+25\r
+..\common\include\flash.h\r
281\r
WString\r
3\r
283\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
284\r
MItem\r
-27\r
-..\common\include\partest.h\r
+24\r
+..\common\include\flop.h\r
285\r
WString\r
3\r
287\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
288\r
MItem\r
-25\r
-..\common\include\pollq.h\r
+28\r
+..\COMMON\INCLUDE\GenQTest.h\r
289\r
WString\r
3\r
291\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
292\r
MItem\r
-25\r
-..\common\include\print.h\r
+27\r
+..\common\include\partest.h\r
293\r
WString\r
3\r
295\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
296\r
MItem\r
-27\r
-..\common\include\semtest.h\r
+25\r
+..\common\include\pollq.h\r
297\r
WString\r
3\r
299\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
300\r
MItem\r
-26\r
-..\common\include\serial.h\r
+25\r
+..\common\include\print.h\r
301\r
WString\r
3\r
303\r
WVList\r
0\r
-204\r
+208\r
1\r
1\r
0\r
304\r
MItem\r
-16\r
-FreeRTOSConfig.h\r
+27\r
+..\common\include\semtest.h\r
305\r
WString\r
3\r
307\r
WVList\r
0\r
-204\r
+208\r
+1\r
+1\r
+0\r
+308\r
+MItem\r
+26\r
+..\common\include\serial.h\r
+309\r
+WString\r
+3\r
+NIL\r
+310\r
+WVList\r
+0\r
+311\r
+WVList\r
+0\r
+208\r
+1\r
+1\r
+0\r
+312\r
+MItem\r
+16\r
+FreeRTOSConfig.h\r
+313\r
+WString\r
+3\r
+NIL\r
+314\r
+WVList\r
+0\r
+315\r
+WVList\r
+0\r
+208\r
1\r
1\r
0\r
VpeMain\r
1\r
WRect\r
-0\r
-0\r
-7680\r
-9216\r
+6\r
+9\r
+6229\r
+7197\r
2\r
MProject\r
3\r
0\r
0\r
7168\r
-8474\r
+8270\r
0\r
0\r
9\r
12\r
rtosdemo.tgt\r
0\r
-24\r
+25\r
7\r
#define configUSE_MUTEXES 0\r
#endif\r
\r
+#ifndef configUSE_COUNTING_SEMAPHORES\r
+ #define configUSE_COUNTING_SEMAPHORES 0\r
+#endif\r
+\r
#if ( configUSE_MUTEXES == 1 )\r
/* xTaskGetCurrentTaskHandle is used by the priority inheritance mechanism\r
within the mutex implementation so must be available if mutexes are used. */\r
signed portBASE_TYPE xQueueCRReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait );\r
\r
/*\r
- * For internal use only. Use xSemaphoreCreateMutex() instead of calling\r
- * this function directly.\r
+ * For internal use only. Use xSemaphoreCreateMutex() or\r
+ * xSemaphoreCreateCounting() instead of calling these functions directly.\r
*/\r
xQueueHandle xQueueCreateMutex( void );\r
+xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );\r
\r
#ifdef __cplusplus\r
}\r
***************************************************************************\r
*/\r
\r
-#include "queue.h"\r
-\r
#ifndef SEMAPHORE_H\r
#define SEMAPHORE_H\r
\r
+#include "queue.h"\r
+\r
typedef xQueueHandle xSemaphoreHandle;\r
\r
#define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( unsigned portCHAR ) 1 )\r
* \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary\r
* \ingroup Semaphores\r
*/\r
-#define vSemaphoreCreateBinary( xSemaphore ) { \\r
- xSemaphore = xQueueCreate( ( unsigned portCHAR ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH ); \\r
- if( xSemaphore != NULL ) \\r
- { \\r
- xSemaphoreGive( xSemaphore ); \\r
- } \\r
+#define vSemaphoreCreateBinary( xSemaphore ) { \\r
+ xSemaphore = xQueueCreate( ( unsigned portBASE_TYPE ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH ); \\r
+ if( xSemaphore != NULL ) \\r
+ { \\r
+ xSemaphoreGive( xSemaphore ); \\r
+ } \\r
}\r
\r
/**\r
*/\r
#define xSemaphoreCreateMutex() xQueueCreateMutex()\r
\r
+/**\r
+ * semphr. h\r
+ * <pre>vSemaphoreCreateCounting( xSemaphoreHandle xSemaphore, unsigned portBASE_TYPE uxMaxCount )</pre>\r
+ *\r
+ * <i>Macro</i> that creates a counting semaphore by using the existing \r
+ * queue mechanism. The queue length is used as the maximum count. The data \r
+ * size is 0 as we don't want to actually store any data - we just want to \r
+ * know if the queue is empty or full.\r
+ *\r
+ * Counting semaphores are typically used for two things:\r
+ *\r
+ * 1) Counting events. \r
+ *\r
+ * In this usage scenario an event handler will 'give' a semphore each time\r
+ * an event occurs (incrementing the semaphore count value), and a handler \r
+ * task will 'take' a semaphore each time it processes an event \r
+ * (decrementing the semaphore count value). The count value is therefore \r
+ * the difference between the number of events that have occurred and the \r
+ * number that have been processed. In this case it is desirable for the \r
+ * initial count value to be zero.\r
+ *\r
+ * 2) Resource management.\r
+ *\r
+ * In this usage scenario the count value indicates the number of resources\r
+ * available. To obtain control of a resource a task must first obtain a \r
+ * semphoare - decrementing the semaphore count value. When the count value\r
+ * reaches zero there are no free resources. When a task finishes with the\r
+ * resource it 'gives' the semahore back - incrementing the semaphore count\r
+ * value. In this case it is desirable for the initial count value to be\r
+ * equal to the maximum count value, indicating that all resources are free.\r
+ *\r
+ * @param uxMaxCount The maximum count value that can be reached. When the \r
+ * semaphore reaches this value it can nolonger be 'given'.\r
+ * @param uxInitialCount\r
+ *\r
+ * @return Handle to the created semaphore. Should be of type xSemaphoreHandle.\r
+ * \r
+ * Example usage:\r
+ <pre>\r
+ xSemaphoreHandle xSemaphore;\r
+\r
+ void vATask( void * pvParameters )\r
+ {\r
+ xSemaphoreHandle xSemaphore = NULL;\r
+\r
+ // Semaphore cannot be used before a call to vSemaphoreCreateCounting().\r
+ // This is a macro so pass the variable in directly.\r
+ vSemaphoreCreateBinary( xSemaphore, );\r
+\r
+ if( xSemaphore != NULL )\r
+ {\r
+ // The semaphore was created successfully.\r
+ // The semaphore can now be used. \r
+ }\r
+ }\r
+ </pre>\r
+ * \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting\r
+ * \ingroup Semaphores\r
+ */\r
+#define xSemaphoreCreateCounting( uxCountValue, uxInitialCount ) xQueueCreateCountingSemaphore( uxCountValue, uxInitialCount )\r
\r
#endif /* SEMAPHORE_H */\r
\r
*pxTopOfStack = ( portSTACK_TYPE ) pxCode + portINSTRUCTION_SIZE; \r
pxTopOfStack--;\r
\r
- *pxTopOfStack = ( portSTACK_TYPE ) 0xaaaaaaaa; /* R14 */\r
+ *pxTopOfStack = ( portSTACK_TYPE ) 0x00000000; /* R14 */\r
pxTopOfStack--; \r
*pxTopOfStack = ( portSTACK_TYPE ) pxOriginalTOS; /* Stack used when task starts goes in R13. */\r
pxTopOfStack--;\r
***************************************************************************\r
*/\r
\r
-/*\r
-Changes from V1.01\r
-\r
- + More use of 8bit data types.\r
- + Function name prefixes changed where the data type returned has changed.\r
-\r
-Changed from V2.0.0\r
-\r
- + Added the queue locking mechanism and make more use of the scheduler\r
- suspension feature to minimise the time interrupts have to be disabled\r
- when accessing a queue.\r
-\r
-Changed from V2.2.0\r
-\r
- + Explicit use of 'signed' qualifier on portCHAR types added.\r
-\r
-Changes from V3.0.0\r
-\r
- + API changes as described on the FreeRTOS.org WEB site.\r
-\r
-Changes from V3.2.3\r
-\r
- + Added the queue functions that can be used from co-routines.\r
-\r
-Changes from V4.0.5\r
-\r
- + Added a loop within xQueueSend() and xQueueReceive() to prevent the\r
- functions exiting when a block time remains and the function has\r
- not completed.\r
-\r
-Changes from V4.1.2:\r
-\r
- + BUG FIX: Removed the call to prvIsQueueEmpty from within xQueueCRReceive\r
- as it exited with interrupts enabled. Thanks Paul Katz.\r
-\r
-Changes from V4.1.3:\r
-\r
- + Modified xQueueSend() and xQueueReceive() to handle the (very unlikely)\r
- case whereby a task unblocking due to a temporal event can remove/send an\r
- item from/to a queue when a higher priority task is still blocked on the\r
- queue. This modification is a result of the SafeRTOS testing.\r
-*/\r
-\r
#include <stdlib.h>\r
#include <string.h>\r
#include "FreeRTOS.h"\r
#define uxQueueType pcHead\r
#define queueQUEUE_IS_MUTEX NULL\r
\r
+/* Semaphores do not actually store or copy data, so have an items size of\r
+zero. */\r
+#define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( 0 )\r
+#define queueDONT_BLOCK ( ( portTickType ) 0 )\r
+\r
/*\r
* Definition of the queue used by the scheduler.\r
* Items are queued by copy, not reference.\r
signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking );\r
signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, const void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken );\r
xQueueHandle xQueueCreateMutex( void );\r
+xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount );\r
\r
#if configUSE_CO_ROUTINES == 1\r
signed portBASE_TYPE xQueueCRSendFromISR( xQueueHandle pxQueue, const void *pvItemToQueue, signed portBASE_TYPE xCoRoutinePreviouslyWoken );\r
#endif /* configUSE_MUTEXES */\r
/*-----------------------------------------------------------*/\r
\r
+#if configUSE_COUNTING_SEMAPHORES == 1\r
+\r
+ xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount )\r
+ {\r
+ xQueueHandle pxHandle;\r
+ \r
+ pxHandle = xQueueCreate( ( unsigned portBASE_TYPE ) uxCountValue, queueSEMAPHORE_QUEUE_ITEM_LENGTH );\r
+\r
+ if( pxHandle != NULL )\r
+ {\r
+ pxHandle->uxMessagesWaiting = uxInitialCount;\r
+ }\r
+\r
+ return pxHandle;\r
+ }\r
+\r
+#endif /* configUSE_COUNTING_SEMAPHORES */\r
+/*-----------------------------------------------------------*/\r
+\r
signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition )\r
{\r
signed portBASE_TYPE xReturn = pdPASS;\r