]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/RL78_E2Studio_GCC/src/Common-Demo-Tasks/blocktim.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / RL78_E2Studio_GCC / src / Common-Demo-Tasks / blocktim.c
diff --git a/FreeRTOS/Demo/RL78_E2Studio_GCC/src/Common-Demo-Tasks/blocktim.c b/FreeRTOS/Demo/RL78_E2Studio_GCC/src/Common-Demo-Tasks/blocktim.c
deleted file mode 100644 (file)
index 932fb68..0000000
+++ /dev/null
@@ -1,467 +0,0 @@
-/*\r
- * FreeRTOS Kernel V10.1.0\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://www.FreeRTOS.org\r
- * http://aws.amazon.com/freertos\r
- *\r
- * 1 tab == 4 spaces!\r
- */\r
-\r
-/*\r
- * This file contains some test scenarios that ensure tasks do not exit queue\r
- * send or receive functions prematurely.  A description of the tests is\r
- * included within the code.\r
- */\r
-\r
-/* Kernel includes. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-#include "queue.h"\r
-\r
-/* Demo includes. */\r
-#include "blocktim.h"\r
-\r
-/* Task priorities.  Allow these to be overridden. */\r
-#ifndef bktPRIMARY_PRIORITY\r
-       #define bktPRIMARY_PRIORITY             ( configMAX_PRIORITIES - 3 )\r
-#endif\r
-\r
-#ifndef bktSECONDARY_PRIORITY\r
-       #define bktSECONDARY_PRIORITY   ( configMAX_PRIORITIES - 4 )\r
-#endif\r
-\r
-/* Task behaviour. */\r
-#define bktQUEUE_LENGTH                                ( 5 )\r
-#define bktSHORT_WAIT                          ( ( ( TickType_t ) 20 ) / portTICK_PERIOD_MS )\r
-#define bktPRIMARY_BLOCK_TIME          ( 10 )\r
-#define bktALLOWABLE_MARGIN                    ( 15 )\r
-#define bktTIME_TO_BLOCK                       ( 175 )\r
-#define bktDONT_BLOCK                          ( ( TickType_t ) 0 )\r
-#define bktRUN_INDICATOR                       ( ( unsigned portBASE_TYPE ) 0x55 )\r
-\r
-/* The queue on which the tasks block. */\r
-static QueueHandle_t xTestQueue;\r
-\r
-/* Handle to the secondary task is required by the primary task for calls\r
-to vTaskSuspend/Resume(). */\r
-static TaskHandle_t xSecondary;\r
-\r
-/* Used to ensure that tasks are still executing without error. */\r
-static volatile portBASE_TYPE xPrimaryCycles = 0, xSecondaryCycles = 0;\r
-static volatile portBASE_TYPE xErrorOccurred = pdFALSE;\r
-\r
-/* Provides a simple mechanism for the primary task to know when the\r
-secondary task has executed. */\r
-static volatile unsigned portBASE_TYPE xRunIndicator;\r
-\r
-/* The two test tasks.  Their behaviour is commented within the files. */\r
-static void vPrimaryBlockTimeTestTask( void *pvParameters );\r
-static void vSecondaryBlockTimeTestTask( void *pvParameters );\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-void vCreateBlockTimeTasks( void )\r
-{\r
-       /* Create the queue on which the two tasks block. */\r
-    xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( portBASE_TYPE ) );\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( xTestQueue, ( signed char * ) "Block_Time_Queue" );\r
-\r
-       /* Create the two test tasks. */\r
-       xTaskCreate( vPrimaryBlockTimeTestTask, "BTest1", configMINIMAL_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );\r
-       xTaskCreate( vSecondaryBlockTimeTestTask, "BTest2", configMINIMAL_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void vPrimaryBlockTimeTestTask( void *pvParameters )\r
-{\r
-portBASE_TYPE xItem, xData;\r
-TickType_t xTimeWhenBlocking;\r
-TickType_t xTimeToBlock, xBlockedTime;\r
-\r
-       ( void ) pvParameters;\r
-\r
-       for( ;; )\r
-       {\r
-               /*********************************************************************\r
-        Test 1\r
-\r
-        Simple block time wakeup test on queue receives. */\r
-               for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )\r
-               {\r
-                       /* The queue is empty. Attempt to read from the queue using a block\r
-                       time.  When we wake, ensure the delta in time is as expected. */\r
-                       xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;\r
-\r
-                       xTimeWhenBlocking = xTaskGetTickCount();\r
-\r
-                       /* We should unblock after xTimeToBlock having not received\r
-                       anything on the queue. */\r
-                       if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       /* How long were we blocked for? */\r
-                       xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;\r
-\r
-                       if( xBlockedTime < xTimeToBlock )\r
-                       {\r
-                               /* Should not have blocked for less than we requested. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )\r
-                       {\r
-                               /* Should not have blocked for longer than we requested,\r
-                               although we would not necessarily run as soon as we were\r
-                               unblocked so a margin is allowed. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-               }\r
-\r
-               /*********************************************************************\r
-        Test 2\r
-\r
-        Simple block time wakeup test on queue sends.\r
-\r
-               First fill the queue.  It should be empty so all sends should pass. */\r
-               for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )\r
-               {\r
-                       if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       #if configUSE_PREEMPTION == 0\r
-                               taskYIELD();\r
-                       #endif\r
-               }\r
-\r
-               for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )\r
-               {\r
-                       /* The queue is full. Attempt to write to the queue using a block\r
-                       time.  When we wake, ensure the delta in time is as expected. */\r
-                       xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;\r
-\r
-                       xTimeWhenBlocking = xTaskGetTickCount();\r
-\r
-                       /* We should unblock after xTimeToBlock having not received\r
-                       anything on the queue. */\r
-                       if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       /* How long were we blocked for? */\r
-                       xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;\r
-\r
-                       if( xBlockedTime < xTimeToBlock )\r
-                       {\r
-                               /* Should not have blocked for less than we requested. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )\r
-                       {\r
-                               /* Should not have blocked for longer than we requested,\r
-                               although we would not necessarily run as soon as we were\r
-                               unblocked so a margin is allowed. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-               }\r
-\r
-               /*********************************************************************\r
-        Test 3\r
-\r
-               Wake the other task, it will block attempting to post to the queue.\r
-               When we read from the queue the other task will wake, but before it\r
-               can run we will post to the queue again.  When the other task runs it\r
-               will find the queue still full, even though it was woken.  It should\r
-               recognise that its block time has not expired and return to block for\r
-               the remains of its block time.\r
-\r
-               Wake the other task so it blocks attempting to post to the already\r
-               full queue. */\r
-               xRunIndicator = 0;\r
-               vTaskResume( xSecondary );\r
-\r
-               /* We need to wait a little to ensure the other task executes. */\r
-               while( xRunIndicator != bktRUN_INDICATOR )\r
-               {\r
-                       /* The other task has not yet executed. */\r
-                       vTaskDelay( bktSHORT_WAIT );\r
-               }\r
-               /* Make sure the other task is blocked on the queue. */\r
-               vTaskDelay( bktSHORT_WAIT );\r
-               xRunIndicator = 0;\r
-\r
-               for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )\r
-               {\r
-                       /* Now when we make space on the queue the other task should wake\r
-                       but not execute as this task has higher priority. */\r
-                       if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       /* Now fill the queue again before the other task gets a chance to\r
-                       execute.  If the other task had executed we would find the queue\r
-                       full ourselves, and the other task have set xRunIndicator. */\r
-                       if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       if( xRunIndicator == bktRUN_INDICATOR )\r
-                       {\r
-                               /* The other task should not have executed. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       /* Raise the priority of the other task so it executes and blocks\r
-                       on the queue again. */\r
-                       vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );\r
-\r
-                       /* The other task should now have re-blocked without exiting the\r
-                       queue function. */\r
-                       if( xRunIndicator == bktRUN_INDICATOR )\r
-                       {\r
-                               /* The other task should not have executed outside of the\r
-                               queue function. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       /* Set the priority back down. */\r
-                       vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );\r
-               }\r
-\r
-               /* Let the other task timeout.  When it unblockes it will check that it\r
-               unblocked at the correct time, then suspend itself. */\r
-               while( xRunIndicator != bktRUN_INDICATOR )\r
-               {\r
-                       vTaskDelay( bktSHORT_WAIT );\r
-               }\r
-               vTaskDelay( bktSHORT_WAIT );\r
-               xRunIndicator = 0;\r
-\r
-\r
-               /*********************************************************************\r
-        Test 4\r
-\r
-               As per test 3 - but with the send and receive the other way around.\r
-               The other task blocks attempting to read from the queue.\r
-\r
-               Empty the queue.  We should find that it is full. */\r
-               for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )\r
-               {\r
-                       if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-               }\r
-\r
-               /* Wake the other task so it blocks attempting to read from  the\r
-               already empty queue. */\r
-               vTaskResume( xSecondary );\r
-\r
-               /* We need to wait a little to ensure the other task executes. */\r
-               while( xRunIndicator != bktRUN_INDICATOR )\r
-               {\r
-                       vTaskDelay( bktSHORT_WAIT );\r
-               }\r
-               vTaskDelay( bktSHORT_WAIT );\r
-               xRunIndicator = 0;\r
-\r
-               for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )\r
-               {\r
-                       /* Now when we place an item on the queue the other task should\r
-                       wake but not execute as this task has higher priority. */\r
-                       if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       /* Now empty the queue again before the other task gets a chance to\r
-                       execute.  If the other task had executed we would find the queue\r
-                       empty ourselves, and the other task would be suspended. */\r
-                       if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )\r
-                       {\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       if( xRunIndicator == bktRUN_INDICATOR )\r
-                       {\r
-                               /* The other task should not have executed. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-\r
-                       /* Raise the priority of the other task so it executes and blocks\r
-                       on the queue again. */\r
-                       vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );\r
-\r
-                       /* The other task should now have re-blocked without exiting the\r
-                       queue function. */\r
-                       if( xRunIndicator == bktRUN_INDICATOR )\r
-                       {\r
-                               /* The other task should not have executed outside of the\r
-                               queue function. */\r
-                               xErrorOccurred = pdTRUE;\r
-                       }\r
-                       vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );\r
-               }\r
-\r
-               /* Let the other task timeout.  When it unblockes it will check that it\r
-               unblocked at the correct time, then suspend itself. */\r
-               while( xRunIndicator != bktRUN_INDICATOR )\r
-               {\r
-                       vTaskDelay( bktSHORT_WAIT );\r
-               }\r
-               vTaskDelay( bktSHORT_WAIT );\r
-\r
-               xPrimaryCycles++;\r
-       }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void vSecondaryBlockTimeTestTask( void *pvParameters )\r
-{\r
-TickType_t xTimeWhenBlocking, xBlockedTime;\r
-portBASE_TYPE xData;\r
-\r
-       ( void ) pvParameters;\r
-\r
-       for( ;; )\r
-       {\r
-               /*********************************************************************\r
-        Test 1 and 2\r
-\r
-               This task does does not participate in these tests. */\r
-               vTaskSuspend( NULL );\r
-\r
-               /*********************************************************************\r
-        Test 3\r
-\r
-               The first thing we do is attempt to read from the queue.  It should be\r
-               full so we block.  Note the time before we block so we can check the\r
-               wake time is as per that expected. */\r
-               xTimeWhenBlocking = xTaskGetTickCount();\r
-\r
-               /* We should unblock after bktTIME_TO_BLOCK having not sent\r
-               anything to the queue. */\r
-               xData = 0;\r
-               xRunIndicator = bktRUN_INDICATOR;\r
-               if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )\r
-               {\r
-                       xErrorOccurred = pdTRUE;\r
-               }\r
-\r
-               /* How long were we inside the send function? */\r
-               xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;\r
-\r
-               /* We should not have blocked for less time than bktTIME_TO_BLOCK. */\r
-               if( xBlockedTime < bktTIME_TO_BLOCK )\r
-               {\r
-                       xErrorOccurred = pdTRUE;\r
-               }\r
-\r
-               /* We should of not blocked for much longer than bktALLOWABLE_MARGIN\r
-               either.  A margin is permitted as we would not necessarily run as\r
-               soon as we unblocked. */\r
-               if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )\r
-               {\r
-                       xErrorOccurred = pdTRUE;\r
-               }\r
-\r
-               /* Suspend ready for test 3. */\r
-               xRunIndicator = bktRUN_INDICATOR;\r
-               vTaskSuspend( NULL );\r
-\r
-               /*********************************************************************\r
-        Test 4\r
-\r
-               As per test three, but with the send and receive reversed. */\r
-               xTimeWhenBlocking = xTaskGetTickCount();\r
-\r
-               /* We should unblock after bktTIME_TO_BLOCK having not received\r
-               anything on the queue. */\r
-               xRunIndicator = bktRUN_INDICATOR;\r
-               if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )\r
-               {\r
-                       xErrorOccurred = pdTRUE;\r
-               }\r
-\r
-               xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;\r
-\r
-               /* We should not have blocked for less time than bktTIME_TO_BLOCK. */\r
-               if( xBlockedTime < bktTIME_TO_BLOCK )\r
-               {\r
-                       xErrorOccurred = pdTRUE;\r
-               }\r
-\r
-               /* We should of not blocked for much longer than bktALLOWABLE_MARGIN\r
-               either.  A margin is permitted as we would not necessarily run as soon\r
-               as we unblocked. */\r
-               if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )\r
-               {\r
-                       xErrorOccurred = pdTRUE;\r
-               }\r
-\r
-               xRunIndicator = bktRUN_INDICATOR;\r
-\r
-               xSecondaryCycles++;\r
-       }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-portBASE_TYPE xAreBlockTimeTestTasksStillRunning( void )\r
-{\r
-static portBASE_TYPE xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;\r
-portBASE_TYPE xReturn = pdPASS;\r
-\r
-       /* Have both tasks performed at least one cycle since this function was\r
-       last called? */\r
-       if( xPrimaryCycles == xLastPrimaryCycleCount )\r
-       {\r
-               xReturn = pdFAIL;\r
-       }\r
-\r
-       if( xSecondaryCycles == xLastSecondaryCycleCount )\r
-       {\r
-               xReturn = pdFAIL;\r
-       }\r
-\r
-       if( xErrorOccurred == pdTRUE )\r
-       {\r
-               xReturn = pdFAIL;\r
-       }\r
-\r
-       xLastSecondaryCycleCount = xSecondaryCycles;\r
-       xLastPrimaryCycleCount = xPrimaryCycles;\r
-\r
-       return xReturn;\r
-}\r