summaryrefslogtreecommitdiff
path: root/FreeRTOS
diff options
context:
space:
mode:
authoralfred gedeon <28123637+alfred2g@users.noreply.github.com>2021-07-22 14:23:48 -0700
committerGitHub <noreply@github.com>2021-07-22 14:23:48 -0700
commitae92d8c6ee8f725b552c236bf0f9f919a27ea074 (patch)
treedc40bd672241901a2b7a9bf761871c74cb24d466 /FreeRTOS
parentdd80d615b5364bee9f23c05ad15feb91a4ec167e (diff)
downloadfreertos-git-ae92d8c6ee8f725b552c236bf0f9f919a27ea074.tar.gz
Add uncrustify github workflow (#659)
* Add uncrustify github workflow * Fix exclusion pattern * fix find expression * exclude uncrustify files * Uncrustify common demo and test files * exlude white space checking files * Fix EOL whitespace checker * Remove whitespaces from EOL * Fix space at EOL * Fix find spaces at EOL Co-authored-by: Archit Aggarwal <architag@amazon.com>
Diffstat (limited to 'FreeRTOS')
-rw-r--r--FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c1
-rw-r--r--FreeRTOS/Demo/Common/ARMv8M/mpu_demo/mpu_demo.c258
-rw-r--r--FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.c20
-rw-r--r--FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.h2
-rw-r--r--FreeRTOS/Demo/Common/ARMv8M/tz_demo/tz_demo.c93
-rw-r--r--FreeRTOS/Demo/Common/Full/BlockQ.c404
-rw-r--r--FreeRTOS/Demo/Common/Full/PollQ.c272
-rw-r--r--FreeRTOS/Demo/Common/Full/comtest.c471
-rw-r--r--FreeRTOS/Demo/Common/Full/death.c101
-rw-r--r--FreeRTOS/Demo/Common/Full/dynamic.c797
-rw-r--r--FreeRTOS/Demo/Common/Full/events.c513
-rw-r--r--FreeRTOS/Demo/Common/Full/flash.c103
-rw-r--r--FreeRTOS/Demo/Common/Full/flop.c497
-rw-r--r--FreeRTOS/Demo/Common/Full/integer.c493
-rw-r--r--FreeRTOS/Demo/Common/Full/print.c68
-rw-r--r--FreeRTOS/Demo/Common/Full/semtest.c389
-rw-r--r--FreeRTOS/Demo/Common/Minimal/AbortDelay.c1299
-rw-r--r--FreeRTOS/Demo/Common/Minimal/BlockQ.c332
-rw-r--r--FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c1758
-rw-r--r--FreeRTOS/Demo/Common/Minimal/GenQTest.c1759
-rw-r--r--FreeRTOS/Demo/Common/Minimal/IntQueue.c1111
-rw-r--r--FreeRTOS/Demo/Common/Minimal/IntSemTest.c738
-rw-r--r--FreeRTOS/Demo/Common/Minimal/MessageBufferAMP.c377
-rw-r--r--FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c1645
-rw-r--r--FreeRTOS/Demo/Common/Minimal/PollQ.c262
-rw-r--r--FreeRTOS/Demo/Common/Minimal/QPeek.c689
-rw-r--r--FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c314
-rw-r--r--FreeRTOS/Demo/Common/Minimal/QueueSet.c1914
-rw-r--r--FreeRTOS/Demo/Common/Minimal/QueueSetPolling.c187
-rw-r--r--FreeRTOS/Demo/Common/Minimal/StaticAllocation.c1751
-rw-r--r--FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c2128
-rw-r--r--FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c275
-rw-r--r--FreeRTOS/Demo/Common/Minimal/TaskNotify.c1123
-rw-r--r--FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c2071
-rw-r--r--FreeRTOS/Demo/Common/Minimal/TimerDemo.c1967
-rw-r--r--FreeRTOS/Demo/Common/Minimal/blocktim.c974
-rw-r--r--FreeRTOS/Demo/Common/Minimal/comtest.c303
-rw-r--r--FreeRTOS/Demo/Common/Minimal/comtest_strings.c372
-rw-r--r--FreeRTOS/Demo/Common/Minimal/countsem.c371
-rw-r--r--FreeRTOS/Demo/Common/Minimal/crflash.c205
-rw-r--r--FreeRTOS/Demo/Common/Minimal/crhook.c242
-rw-r--r--FreeRTOS/Demo/Common/Minimal/death.c200
-rw-r--r--FreeRTOS/Demo/Common/Minimal/dynamic.c599
-rw-r--r--FreeRTOS/Demo/Common/Minimal/flash.c101
-rw-r--r--FreeRTOS/Demo/Common/Minimal/flash_timer.c62
-rw-r--r--FreeRTOS/Demo/Common/Minimal/flop.c506
-rw-r--r--FreeRTOS/Demo/Common/Minimal/integer.c181
-rw-r--r--FreeRTOS/Demo/Common/Minimal/recmutex.c662
-rw-r--r--FreeRTOS/Demo/Common/Minimal/semtest.c350
-rw-r--r--FreeRTOS/Demo/Common/Minimal/sp_flop.c468
-rw-r--r--FreeRTOS/Demo/Common/include/AbortDelay.h2
-rw-r--r--FreeRTOS/Demo/Common/include/BlockQ.h2
-rw-r--r--FreeRTOS/Demo/Common/include/EventGroupsDemo.h1
-rw-r--r--FreeRTOS/Demo/Common/include/GenQTest.h3
-rw-r--r--FreeRTOS/Demo/Common/include/IntQueue.h6
-rw-r--r--FreeRTOS/Demo/Common/include/IntSemTest.h3
-rw-r--r--FreeRTOS/Demo/Common/include/MessageBufferDemo.h5
-rw-r--r--FreeRTOS/Demo/Common/include/PollQ.h2
-rw-r--r--FreeRTOS/Demo/Common/include/QPeek.h3
-rw-r--r--FreeRTOS/Demo/Common/include/QueueOverwrite.h2
-rw-r--r--FreeRTOS/Demo/Common/include/QueueSet.h2
-rw-r--r--FreeRTOS/Demo/Common/include/QueueSetPolling.h2
-rw-r--r--FreeRTOS/Demo/Common/include/StaticAllocation.h5
-rw-r--r--FreeRTOS/Demo/Common/include/StreamBufferDemo.h3
-rw-r--r--FreeRTOS/Demo/Common/include/TaskNotify.h5
-rw-r--r--FreeRTOS/Demo/Common/include/TaskNotifyArray.h5
-rw-r--r--FreeRTOS/Demo/Common/include/TimerDemo.h3
-rw-r--r--FreeRTOS/Demo/Common/include/blocktim.h2
-rw-r--r--FreeRTOS/Demo/Common/include/comtest.h11
-rw-r--r--FreeRTOS/Demo/Common/include/comtest2.h5
-rw-r--r--FreeRTOS/Demo/Common/include/comtest_strings.h5
-rw-r--r--FreeRTOS/Demo/Common/include/countsem.h1
-rw-r--r--FreeRTOS/Demo/Common/include/crflash.h1
-rw-r--r--FreeRTOS/Demo/Common/include/crhook.h1
-rw-r--r--FreeRTOS/Demo/Common/include/death.h2
-rw-r--r--FreeRTOS/Demo/Common/include/dynamic.h2
-rw-r--r--FreeRTOS/Demo/Common/include/fileIO.h4
-rw-r--r--FreeRTOS/Demo/Common/include/flash.h1
-rw-r--r--FreeRTOS/Demo/Common/include/flash_timer.h2
-rw-r--r--FreeRTOS/Demo/Common/include/flop.h2
-rw-r--r--FreeRTOS/Demo/Common/include/integer.h2
-rw-r--r--FreeRTOS/Demo/Common/include/mevents.h2
-rw-r--r--FreeRTOS/Demo/Common/include/partest.h6
-rw-r--r--FreeRTOS/Demo/Common/include/print.h4
-rw-r--r--FreeRTOS/Demo/Common/include/recmutex.h1
-rw-r--r--FreeRTOS/Demo/Common/include/semtest.h1
-rw-r--r--FreeRTOS/Demo/Common/include/serial.h115
-rw-r--r--FreeRTOS/README.md6
-rw-r--r--FreeRTOS/Test/CBMC/include/aws_freertos_ip_verification_access_ip_define.h6
-rw-r--r--FreeRTOS/Test/CBMC/include/aws_freertos_tcp_verification_access_tcp_define.h22
-rw-r--r--FreeRTOS/Test/CBMC/include/cbmc.h28
-rw-r--r--FreeRTOS/Test/CBMC/include/queue_init.h274
-rw-r--r--FreeRTOS/Test/CBMC/include/tasksStubs.h3
-rw-r--r--FreeRTOS/Test/CBMC/patches/FreeRTOSConfig.h36
-rw-r--r--FreeRTOS/Test/CBMC/patches/FreeRTOSIPConfig.h56
-rw-r--r--FreeRTOS/Test/CBMC/proofs/CBMCStubLibrary/tasksStubs.c48
-rw-r--r--FreeRTOS/Test/CBMC/proofs/CMakeLists.txt2
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueCreateMutex/QueueCreateMutex_harness.c7
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSend/QueueGenericSend_harness.c186
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSendFromISR/QueueGenericSendFromISR_harness.c105
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolder/QueueGetMutexHolder_harness.c15
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolderFromISR/QueueGetMutexHolderFromISR_harness.c14
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveFromISR/QueueGiveFromISR_harness.c16
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveMutexRecursive/QueueGiveMutexRecursive_harness.c30
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueMessagesWaiting/QueueMessagesWaiting_harness.c12
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueuePeek/QueuePeek_harness.c56
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueReceive/QueueReceive_harness.c67
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueReceiveFromISR/QueueReceiveFromISR_harness.c31
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueSemaphoreTake/QueueSemaphoreTake_harness.c78
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueSpacesAvailable/QueueSpacesAvailable_harness.c11
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/QueueTakeMutexRecursive/QueueTakeMutexRecursive_harness.c58
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/prvCopyDataToQueue/prvCopyDataToQueue_harness.c44
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c116
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c131
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/TaskCheckForTimeOut_harness.c16
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/tasks_test_access_functions.h10
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/TaskCreate_harness.c39
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/tasks_test_access_functions.h35
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/TaskDelay_harness.c23
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/tasks_test_access_functions.h160
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/TaskDelete_harness.c16
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/tasks_test_access_functions.h247
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/TaskGetCurrentTaskHandle_harness.c16
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/tasks_test_access_functions.h25
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/TaskGetSchedulerState_harness.c6
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/tasks_test_access_functions.h4
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/TaskGetTaskNumber_harness.c8
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/tasks_test_access_functions.h14
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskGetTickCount/TaskGetTickCount_harness.c4
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/TaskIncrementTick_harness.c14
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/tasks_test_access_functions.h155
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/TaskPrioritySet_harness.c20
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/tasks_test_access_functions.h164
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/TaskResumeAll_harness.c14
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/tasks_test_access_functions.h182
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskSetTimeOutState/TaskSetTimeOutState_harness.c4
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/TaskStartScheduler_harness.c12
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/tasks_test_access_functions.h84
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskSuspendAll/TaskSuspendAll_harness.c2
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/TaskSwitchContext_harness.c14
-rw-r--r--FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/tasks_test_access_functions.h100
-rw-r--r--FreeRTOS/Test/CBMC/proofs/utility/memory_assignments.c36
-rw-r--r--FreeRTOS/Test/CBMC/windows/direct.h1
-rw-r--r--FreeRTOS/Test/CMock/config/FreeRTOSConfig.h2
-rw-r--r--FreeRTOS/Test/CMock/event_groups/event_groups_utest.c20
-rw-r--r--FreeRTOS/Test/CMock/message_buffer/message_buffer_utest.c2
-rw-r--r--FreeRTOS/Test/CMock/queue/dynamic/FreeRTOSConfig.h2
-rw-r--r--FreeRTOS/Test/CMock/queue/generic/FreeRTOSConfig.h2
-rw-r--r--FreeRTOS/Test/CMock/queue/queue_utest_common.c4
-rw-r--r--FreeRTOS/Test/CMock/queue/queue_utest_common.h4
-rw-r--r--FreeRTOS/Test/CMock/queue/semaphore/FreeRTOSConfig.h2
-rw-r--r--FreeRTOS/Test/CMock/queue/sets/FreeRTOSConfig.h2
-rw-r--r--FreeRTOS/Test/CMock/queue/static/FreeRTOSConfig.h2
-rw-r--r--FreeRTOS/Test/CMock/queue/tracing/FreeRTOSConfig.h2
-rw-r--r--FreeRTOS/Test/CMock/stream_buffer/stream_buffer_utest.c2
-rw-r--r--FreeRTOS/Test/README.md4
-rw-r--r--FreeRTOS/Test/VeriFast/include/proof/list.h618
-rw-r--r--FreeRTOS/Test/VeriFast/include/proof/queue.h706
-rw-r--r--FreeRTOS/Test/VeriFast/include/proof/queuecontracts.h36
-rw-r--r--FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c5
-rw-r--r--FreeRTOS/Test/VeriFast/list/uxListRemove.c402
-rw-r--r--FreeRTOS/Test/VeriFast/list/vListInitialise.c26
-rw-r--r--FreeRTOS/Test/VeriFast/list/vListInsert.c430
-rw-r--r--FreeRTOS/Test/VeriFast/list/vListInsertEnd.c348
-rw-r--r--FreeRTOS/Test/VeriFast/queue/create.c206
-rw-r--r--FreeRTOS/Test/VeriFast/queue/prvCopyDataFromQueue.c53
-rw-r--r--FreeRTOS/Test/VeriFast/queue/prvCopyDataToQueue.c143
-rw-r--r--FreeRTOS/Test/VeriFast/queue/prvLockQueue.c15
-rw-r--r--FreeRTOS/Test/VeriFast/queue/prvUnlockQueue.c26
-rw-r--r--FreeRTOS/Test/VeriFast/queue/uxQueueMessagesWaiting.c10
-rw-r--r--FreeRTOS/Test/VeriFast/queue/uxQueueSpacesAvailable.c10
-rw-r--r--FreeRTOS/Test/VeriFast/queue/vQueueDelete.c27
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueueGenericSend.c103
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueueGenericSendFromISR.c89
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueueIsQueueEmptyFromISR.c13
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueueIsQueueFullFromISR.c13
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueuePeek.c76
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueuePeekFromISR.c23
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueueReceive.c82
-rw-r--r--FreeRTOS/Test/VeriFast/queue/xQueueReceiveFromISR.c25
180 files changed, 19413 insertions, 19007 deletions
diff --git a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c
index 18ef9c293..0d7fcf22c 100644
--- a/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c
+++ b/FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC/main.c
@@ -68,6 +68,7 @@ int main()
#error "Invalid Selection...\nPlease Select a Demo application from the main command"
}
#endif /* if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 ) */
+ snprint
return 0;
}
diff --git a/FreeRTOS/Demo/Common/ARMv8M/mpu_demo/mpu_demo.c b/FreeRTOS/Demo/Common/ARMv8M/mpu_demo/mpu_demo.c
index 802c85a3f..0dfb04e96 100644
--- a/FreeRTOS/Demo/Common/ARMv8M/mpu_demo/mpu_demo.c
+++ b/FreeRTOS/Demo/Common/ARMv8M/mpu_demo/mpu_demo.c
@@ -32,7 +32,7 @@
/**
* @brief Size of the shared memory region.
*/
-#define SHARED_MEMORY_SIZE 32
+#define SHARED_MEMORY_SIZE 32
/**
* @brief Memory region shared between two tasks.
@@ -74,153 +74,155 @@ static void prvRWAccessTask( void * pvParameters );
static void prvROAccessTask( void * pvParameters )
{
-uint8_t ucVal;
+ uint8_t ucVal;
- /* Unused parameters. */
- ( void ) pvParameters;
+ /* Unused parameters. */
+ ( void ) pvParameters;
- for( ; ; )
- {
- /* This task has RO access to ucSharedMemory and therefore it can read
- * it but cannot modify it. */
- ucVal = ucSharedMemory[ 0 ];
+ for( ; ; )
+ {
+ /* This task has RO access to ucSharedMemory and therefore it can read
+ * it but cannot modify it. */
+ ucVal = ucSharedMemory[ 0 ];
- /* Silent compiler warnings about unused variables. */
- ( void ) ucVal;
+ /* Silent compiler warnings about unused variables. */
+ ( void ) ucVal;
- /* Since this task has Read Only access to the ucSharedMemory region,
- * writing to it results in Memory Fault. Set ucROTaskFaultTracker[ 0 ]
- * to 1 to tell the Memory Fault Handler that this is an expected fault.
- * The handler will recover from this fault gracefully by jumping to the
- * next instruction. */
- ucROTaskFaultTracker[ 0 ] = 1;
+ /* Since this task has Read Only access to the ucSharedMemory region,
+ * writing to it results in Memory Fault. Set ucROTaskFaultTracker[ 0 ]
+ * to 1 to tell the Memory Fault Handler that this is an expected fault.
+ * The handler will recover from this fault gracefully by jumping to the
+ * next instruction. */
+ ucROTaskFaultTracker[ 0 ] = 1;
- /* Illegal access to generate Memory Fault. */
- ucSharedMemory[ 0 ] = 0;
+ /* Illegal access to generate Memory Fault. */
+ ucSharedMemory[ 0 ] = 0;
- /* Wait for a second. */
- vTaskDelay( pdMS_TO_TICKS( 1000 ) );
- }
+ /* Wait for a second. */
+ vTaskDelay( pdMS_TO_TICKS( 1000 ) );
+ }
}
/*-----------------------------------------------------------*/
static void prvRWAccessTask( void * pvParameters )
{
- /* Unused parameters. */
- ( void ) pvParameters;
-
- for( ; ; )
- {
- /* This task has RW access to ucSharedMemory and therefore can write to
- * it. */
- ucSharedMemory[ 0 ] = 0;
-
- /* Wait for a second. */
- vTaskDelay( pdMS_TO_TICKS( 1000 ) );
- }
+ /* Unused parameters. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* This task has RW access to ucSharedMemory and therefore can write to
+ * it. */
+ ucSharedMemory[ 0 ] = 0;
+
+ /* Wait for a second. */
+ vTaskDelay( pdMS_TO_TICKS( 1000 ) );
+ }
}
/*-----------------------------------------------------------*/
void vStartMPUDemo( void )
{
-static StackType_t xROAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
-static StackType_t xRWAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
-TaskParameters_t xROAccessTaskParameters =
-{
- .pvTaskCode = prvROAccessTask,
- .pcName = "ROAccess",
- .usStackDepth = configMINIMAL_STACK_SIZE,
- .pvParameters = NULL,
- .uxPriority = tskIDLE_PRIORITY,
- .puxStackBuffer = xROAccessTaskStack,
- .xRegions = {
- { ucSharedMemory, 32, tskMPU_REGION_READ_ONLY | tskMPU_REGION_EXECUTE_NEVER },
- { ucROTaskFaultTracker, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
- { 0, 0, 0 },
- }
-};
-TaskParameters_t xRWAccessTaskParameters =
-{
- .pvTaskCode = prvRWAccessTask,
- .pcName = "RWAccess",
- .usStackDepth = configMINIMAL_STACK_SIZE,
- .pvParameters = NULL,
- .uxPriority = tskIDLE_PRIORITY,
- .puxStackBuffer = xRWAccessTaskStack,
- .xRegions = {
- { ucSharedMemory, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
- { 0, 0, 0 },
- { 0, 0, 0 },
- }
-};
-
- /* Create an unprivileged task with RO access to ucSharedMemory. */
- xTaskCreateRestricted( &( xROAccessTaskParameters ), NULL );
-
- /* Create an unprivileged task with RW access to ucSharedMemory. */
- xTaskCreateRestricted( &( xRWAccessTaskParameters ), NULL );
+ static StackType_t xROAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
+ static StackType_t xRWAccessTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
+ TaskParameters_t xROAccessTaskParameters =
+ {
+ .pvTaskCode = prvROAccessTask,
+ .pcName = "ROAccess",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = NULL,
+ .uxPriority = tskIDLE_PRIORITY,
+ .puxStackBuffer = xROAccessTaskStack,
+ .xRegions =
+ {
+ { ucSharedMemory, 32, tskMPU_REGION_READ_ONLY | tskMPU_REGION_EXECUTE_NEVER },
+ { ucROTaskFaultTracker, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
+ { 0, 0, 0 },
+ }
+ };
+ TaskParameters_t xRWAccessTaskParameters =
+ {
+ .pvTaskCode = prvRWAccessTask,
+ .pcName = "RWAccess",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = NULL,
+ .uxPriority = tskIDLE_PRIORITY,
+ .puxStackBuffer = xRWAccessTaskStack,
+ .xRegions =
+ {
+ { ucSharedMemory, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ }
+ };
+
+ /* Create an unprivileged task with RO access to ucSharedMemory. */
+ xTaskCreateRestricted( &( xROAccessTaskParameters ), NULL );
+
+ /* Create an unprivileged task with RW access to ucSharedMemory. */
+ xTaskCreateRestricted( &( xRWAccessTaskParameters ), NULL );
}
/*-----------------------------------------------------------*/
portDONT_DISCARD void vHandleMemoryFault( uint32_t * pulFaultStackAddress )
{
-uint32_t ulPC;
-uint16_t usOffendingInstruction;
-
- /* Is this an expected fault? */
- if( ucROTaskFaultTracker[ 0 ] == 1 )
- {
- /* Read program counter. */
- ulPC = pulFaultStackAddress[ 6 ];
-
- /* Read the offending instruction. */
- usOffendingInstruction = *( uint16_t * )ulPC;
-
- /* From ARM docs:
- * If the value of bits[15:11] of the halfword being decoded is one of
- * the following, the halfword is the first halfword of a 32-bit
- * instruction:
- * - 0b11101.
- * - 0b11110.
- * - 0b11111.
- * Otherwise, the halfword is a 16-bit instruction.
- */
-
- /* Extract bits[15:11] of the offending instruction. */
- usOffendingInstruction = usOffendingInstruction & 0xF800;
- usOffendingInstruction = ( usOffendingInstruction >> 11 );
-
- /* Determine if the offending instruction is a 32-bit instruction or
- * a 16-bit instruction. */
- if( usOffendingInstruction == 0x001F ||
- usOffendingInstruction == 0x001E ||
- usOffendingInstruction == 0x001D )
- {
- /* Since the offending instruction is a 32-bit instruction,
- * increment the program counter by 4 to move to the next
- * instruction. */
- ulPC += 4;
- }
- else
- {
- /* Since the offending instruction is a 16-bit instruction,
- * increment the program counter by 2 to move to the next
- * instruction. */
- ulPC += 2;
- }
-
- /* Save the new program counter on the stack. */
- pulFaultStackAddress[ 6 ] = ulPC;
-
- /* Mark the fault as handled. */
- ucROTaskFaultTracker[ 0 ] = 0;
- }
- else
- {
- /* This is an unexpected fault - loop forever. */
- for( ; ; )
- {
- }
- }
+ uint32_t ulPC;
+ uint16_t usOffendingInstruction;
+
+ /* Is this an expected fault? */
+ if( ucROTaskFaultTracker[ 0 ] == 1 )
+ {
+ /* Read program counter. */
+ ulPC = pulFaultStackAddress[ 6 ];
+
+ /* Read the offending instruction. */
+ usOffendingInstruction = *( uint16_t * ) ulPC;
+
+ /* From ARM docs:
+ * If the value of bits[15:11] of the halfword being decoded is one of
+ * the following, the halfword is the first halfword of a 32-bit
+ * instruction:
+ * - 0b11101.
+ * - 0b11110.
+ * - 0b11111.
+ * Otherwise, the halfword is a 16-bit instruction.
+ */
+
+ /* Extract bits[15:11] of the offending instruction. */
+ usOffendingInstruction = usOffendingInstruction & 0xF800;
+ usOffendingInstruction = ( usOffendingInstruction >> 11 );
+
+ /* Determine if the offending instruction is a 32-bit instruction or
+ * a 16-bit instruction. */
+ if( ( usOffendingInstruction == 0x001F ) ||
+ ( usOffendingInstruction == 0x001E ) ||
+ ( usOffendingInstruction == 0x001D ) )
+ {
+ /* Since the offending instruction is a 32-bit instruction,
+ * increment the program counter by 4 to move to the next
+ * instruction. */
+ ulPC += 4;
+ }
+ else
+ {
+ /* Since the offending instruction is a 16-bit instruction,
+ * increment the program counter by 2 to move to the next
+ * instruction. */
+ ulPC += 2;
+ }
+
+ /* Save the new program counter on the stack. */
+ pulFaultStackAddress[ 6 ] = ulPC;
+
+ /* Mark the fault as handled. */
+ ucROTaskFaultTracker[ 0 ] = 0;
+ }
+ else
+ {
+ /* This is an unexpected fault - loop forever. */
+ for( ; ; )
+ {
+ }
+ }
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.c b/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.c
index 598ef426c..eddb6ae56 100644
--- a/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.c
+++ b/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.c
@@ -37,23 +37,23 @@ static uint32_t ulSecureCounter = 0;
/**
* @brief typedef for non-secure callback.
*/
-typedef void ( *NonSecureCallback_t ) ( void ) __attribute__( ( cmse_nonsecure_call ) );
+typedef void ( *NonSecureCallback_t )( void ) __attribute__( ( cmse_nonsecure_call ) );
/*-----------------------------------------------------------*/
secureportNON_SECURE_CALLABLE uint32_t NSCFunction( Callback_t pxCallback )
{
-NonSecureCallback_t pxNonSecureCallback;
+ NonSecureCallback_t pxNonSecureCallback;
- /* Return function pointer with cleared LSB. */
- pxNonSecureCallback = ( NonSecureCallback_t ) cmse_nsfptr_create( pxCallback );
+ /* Return function pointer with cleared LSB. */
+ pxNonSecureCallback = ( NonSecureCallback_t ) cmse_nsfptr_create( pxCallback );
- /* Invoke the supplied callback. */
- pxNonSecureCallback();
+ /* Invoke the supplied callback. */
+ pxNonSecureCallback();
- /* Increment the secure side counter. */
- ulSecureCounter += 1;
+ /* Increment the secure side counter. */
+ ulSecureCounter += 1;
- /* Return the secure side counter. */
- return ulSecureCounter;
+ /* Return the secure side counter. */
+ return ulSecureCounter;
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.h b/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.h
index 0f0113bc4..67cb2a1e9 100644
--- a/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.h
+++ b/FreeRTOS/Demo/Common/ARMv8M/tz_demo/nsc_functions.h
@@ -33,7 +33,7 @@
/**
* @brief Callback function pointer definition.
*/
-typedef void ( *Callback_t ) ( void );
+typedef void ( * Callback_t ) ( void );
/**
* @brief Invokes the supplied callback which is on the non-secure side.
diff --git a/FreeRTOS/Demo/Common/ARMv8M/tz_demo/tz_demo.c b/FreeRTOS/Demo/Common/ARMv8M/tz_demo/tz_demo.c
index bb9a2eb44..f0a7bc067 100644
--- a/FreeRTOS/Demo/Common/ARMv8M/tz_demo/tz_demo.c
+++ b/FreeRTOS/Demo/Common/ARMv8M/tz_demo/tz_demo.c
@@ -42,7 +42,7 @@
* 4 bytes and upto 32 bytes will also fall in the same MPU region and the task
* having access to ulNonSecureCounter will also have access to all those items.
*/
-static uint32_t ulNonSecureCounter[8] __attribute__( ( aligned( 32 ) ) ) = { 0 };
+static uint32_t ulNonSecureCounter[ 8 ] __attribute__( ( aligned( 32 ) ) ) = { 0 };
/*-----------------------------------------------------------*/
/**
@@ -68,66 +68,67 @@ static void prvSecureCallingTask( void * pvParameters );
void vStartTZDemo( void )
{
-static StackType_t xSecureCallingTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
-TaskParameters_t xSecureCallingTaskParameters =
-{
- .pvTaskCode = prvSecureCallingTask,
- .pcName = "SecCalling",
- .usStackDepth = configMINIMAL_STACK_SIZE,
- .pvParameters = NULL,
- .uxPriority = tskIDLE_PRIORITY,
- .puxStackBuffer = xSecureCallingTaskStack,
- .xRegions = {
- { ulNonSecureCounter, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
- { 0, 0, 0 },
- { 0, 0, 0 },
- }
-};
+ static StackType_t xSecureCallingTaskStack[ configMINIMAL_STACK_SIZE ] __attribute__( ( aligned( 32 ) ) );
+ TaskParameters_t xSecureCallingTaskParameters =
+ {
+ .pvTaskCode = prvSecureCallingTask,
+ .pcName = "SecCalling",
+ .usStackDepth = configMINIMAL_STACK_SIZE,
+ .pvParameters = NULL,
+ .uxPriority = tskIDLE_PRIORITY,
+ .puxStackBuffer = xSecureCallingTaskStack,
+ .xRegions =
+ {
+ { ulNonSecureCounter, 32, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
+ { 0, 0, 0 },
+ { 0, 0, 0 },
+ }
+ };
- /* Create an unprivileged task which calls secure functions. */
- xTaskCreateRestricted( &( xSecureCallingTaskParameters ), NULL );
+ /* Create an unprivileged task which calls secure functions. */
+ xTaskCreateRestricted( &( xSecureCallingTaskParameters ), NULL );
}
/*-----------------------------------------------------------*/
static void prvCallback( void )
{
- /* This function is called from the secure side. Just increment the counter
- * here. The check that this counter keeps incrementing is performed in the
- * prvSecureCallingTask. */
- ulNonSecureCounter[ 0 ] += 1;
+ /* This function is called from the secure side. Just increment the counter
+ * here. The check that this counter keeps incrementing is performed in the
+ * prvSecureCallingTask. */
+ ulNonSecureCounter[ 0 ] += 1;
}
/*-----------------------------------------------------------*/
static void prvSecureCallingTask( void * pvParameters )
{
-uint32_t ulLastSecureCounter = 0, ulLastNonSecureCounter = 0;
-uint32_t ulCurrentSecureCounter = 0;
+ uint32_t ulLastSecureCounter = 0, ulLastNonSecureCounter = 0;
+ uint32_t ulCurrentSecureCounter = 0;
- /* This task calls secure side functions. So allocate a secure context for
- * it. */
- portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
+ /* This task calls secure side functions. So allocate a secure context for
+ * it. */
+ portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
- for( ; ; )
- {
- /* Call the secure side function. It does two things:
- * - It calls the supplied function (prvCallback) which in turn
- * increments the non-secure counter.
- * - It increments the secure counter and returns the incremented value.
- * Therefore at the end of this function call both the secure and
- * non-secure counters must have been incremented.
- */
- ulCurrentSecureCounter = NSCFunction( prvCallback );
+ for( ; ; )
+ {
+ /* Call the secure side function. It does two things:
+ * - It calls the supplied function (prvCallback) which in turn
+ * increments the non-secure counter.
+ * - It increments the secure counter and returns the incremented value.
+ * Therefore at the end of this function call both the secure and
+ * non-secure counters must have been incremented.
+ */
+ ulCurrentSecureCounter = NSCFunction( prvCallback );
- /* Make sure that both the counters are incremented. */
- configASSERT( ulCurrentSecureCounter == ulLastSecureCounter + 1 );
- configASSERT( ulNonSecureCounter[ 0 ] == ulLastNonSecureCounter + 1 );
+ /* Make sure that both the counters are incremented. */
+ configASSERT( ulCurrentSecureCounter == ulLastSecureCounter + 1 );
+ configASSERT( ulNonSecureCounter[ 0 ] == ulLastNonSecureCounter + 1 );
- /* Update the last values for both the counters. */
- ulLastSecureCounter = ulCurrentSecureCounter;
- ulLastNonSecureCounter = ulNonSecureCounter[ 0 ];
+ /* Update the last values for both the counters. */
+ ulLastSecureCounter = ulCurrentSecureCounter;
+ ulLastNonSecureCounter = ulNonSecureCounter[ 0 ];
- /* Wait for a second. */
- vTaskDelay( pdMS_TO_TICKS( 1000 ) );
- }
+ /* Wait for a second. */
+ vTaskDelay( pdMS_TO_TICKS( 1000 ) );
+ }
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Common/Full/BlockQ.c b/FreeRTOS/Demo/Common/Full/BlockQ.c
index a3c41cb14..548e5e762 100644
--- a/FreeRTOS/Demo/Common/Full/BlockQ.c
+++ b/FreeRTOS/Demo/Common/Full/BlockQ.c
@@ -28,23 +28,23 @@
/**
* Creates six tasks that operate on three queues as follows:
*
- * The first two tasks send and receive an incrementing number to/from a queue.
- * One task acts as a producer and the other as the consumer. The consumer is a
- * higher priority than the producer and is set to block on queue reads. The queue
- * only has space for one item - as soon as the producer posts a message on the
+ * The first two tasks send and receive an incrementing number to/from a queue.
+ * One task acts as a producer and the other as the consumer. The consumer is a
+ * higher priority than the producer and is set to block on queue reads. The queue
+ * only has space for one item - as soon as the producer posts a message on the
* queue the consumer will unblock, pre-empt the producer, and remove the item.
- *
+ *
* The second two tasks work the other way around. Again the queue used only has
- * enough space for one item. This time the consumer has a lower priority than the
- * producer. The producer will try to post on the queue blocking when the queue is
- * full. When the consumer wakes it will remove the item from the queue, causing
- * the producer to unblock, pre-empt the consumer, and immediately re-fill the
+ * enough space for one item. This time the consumer has a lower priority than the
+ * producer. The producer will try to post on the queue blocking when the queue is
+ * full. When the consumer wakes it will remove the item from the queue, causing
+ * the producer to unblock, pre-empt the consumer, and immediately re-fill the
* queue.
- *
+ *
* The last two tasks use the same queue producer and consumer functions. This time the queue has
- * enough space for lots of items and the tasks operate at the same priority. The
- * producer will execute, placing items into the queue. The consumer will start
- * executing when either the queue becomes full (causing the producer to block) or
+ * enough space for lots of items and the tasks operate at the same priority. The
+ * producer will execute, placing items into the queue. The consumer will start
+ * executing when either the queue becomes full (causing the producer to block) or
* a context switch occurs (tasks of the same priority will time slice).
*
* \page BlockQC blockQ.c
@@ -53,21 +53,21 @@
*/
/*
-Changes from V1.00:
-
- + Reversed the priority and block times of the second two demo tasks so
- they operate as per the description above.
-
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
-
-Changes from V4.0.2
-
- + The second set of tasks were created the wrong way around. This has been
- corrected.
-*/
+ * Changes from V1.00:
+ *
+ + Reversed the priority and block times of the second two demo tasks so
+ + they operate as per the description above.
+ +
+ + Changes from V2.0.0
+ +
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ +
+ + Changes from V4.0.2
+ +
+ + The second set of tasks were created the wrong way around. This has been
+ + corrected.
+ */
#include <stdlib.h>
@@ -81,228 +81,228 @@ Changes from V4.0.2
#include "BlockQ.h"
#include "print.h"
-#define blckqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
-#define blckqNUM_TASK_SETS ( 3 )
+#define blckqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
+#define blckqNUM_TASK_SETS ( 3 )
/* Structure used to pass parameters to the blocking queue tasks. */
typedef struct BLOCKING_QUEUE_PARAMETERS
{
- QueueHandle_t xQueue; /*< The queue to be used by the task. */
- TickType_t xBlockTime; /*< The block time to use on queue reads/writes. */
- volatile short *psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
+ QueueHandle_t xQueue; /*< The queue to be used by the task. */
+ TickType_t xBlockTime; /*< The block time to use on queue reads/writes. */
+ volatile short * psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
} xBlockingQueueParameters;
/* Task function that creates an incrementing number and posts it on a queue. */
-static void vBlockingQueueProducer( void *pvParameters );
+static void vBlockingQueueProducer( void * pvParameters );
-/* Task function that removes the incrementing number from a queue and checks that
-it is the expected number. */
-static void vBlockingQueueConsumer( void *pvParameters );
+/* Task function that removes the incrementing number from a queue and checks that
+ * it is the expected number. */
+static void vBlockingQueueConsumer( void * pvParameters );
-/* Variables which are incremented each time an item is removed from a queue, and
-found to be the expected value.
-These are used to check that the tasks are still running. */
+/* Variables which are incremented each time an item is removed from a queue, and
+ * found to be the expected value.
+ * These are used to check that the tasks are still running. */
static volatile short sBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
-/* Variable which are incremented each time an item is posted on a queue. These
-are used to check that the tasks are still running. */
+/* Variable which are incremented each time an item is posted on a queue. These
+ * are used to check that the tasks are still running. */
static volatile short sBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
/*-----------------------------------------------------------*/
void vStartBlockingQueueTasks( unsigned portBASE_TYPE uxPriority )
{
-xBlockingQueueParameters *pxQueueParameters1, *pxQueueParameters2;
-xBlockingQueueParameters *pxQueueParameters3, *pxQueueParameters4;
-xBlockingQueueParameters *pxQueueParameters5, *pxQueueParameters6;
-const unsigned portBASE_TYPE uxQueueSize1 = 1, uxQueueSize5 = 5;
-const TickType_t xBlockTime = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
-const TickType_t xDontBlock = ( TickType_t ) 0;
+ xBlockingQueueParameters * pxQueueParameters1, * pxQueueParameters2;
+ xBlockingQueueParameters * pxQueueParameters3, * pxQueueParameters4;
+ xBlockingQueueParameters * pxQueueParameters5, * pxQueueParameters6;
+ const unsigned portBASE_TYPE uxQueueSize1 = 1, uxQueueSize5 = 5;
+ const TickType_t xBlockTime = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
+ const TickType_t xDontBlock = ( TickType_t ) 0;
+
+ /* Create the first two tasks as described at the top of the file. */
- /* Create the first two tasks as described at the top of the file. */
-
- /* First create the structure used to pass parameters to the consumer tasks. */
- pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ /* First create the structure used to pass parameters to the consumer tasks. */
+ pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- /* Create the queue used by the first two tasks to pass the incrementing number.
- Pass a pointer to the queue in the parameter structure. */
- pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
+ /* Create the queue used by the first two tasks to pass the incrementing number.
+ * Pass a pointer to the queue in the parameter structure. */
+ pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
- /* The consumer is created first so gets a block time as described above. */
- pxQueueParameters1->xBlockTime = xBlockTime;
+ /* The consumer is created first so gets a block time as described above. */
+ pxQueueParameters1->xBlockTime = xBlockTime;
- /* Pass in the variable that this task is going to increment so we can check it
- is still running. */
- pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
-
- /* Create the structure used to pass parameters to the producer task. */
- pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ /* Pass in the variable that this task is going to increment so we can check it
+ * is still running. */
+ pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
- /* Pass the queue to this task also, using the parameter structure. */
- pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
+ /* Create the structure used to pass parameters to the producer task. */
+ pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- /* The producer is not going to block - as soon as it posts the consumer will
- wake and remove the item so the producer should always have room to post. */
- pxQueueParameters2->xBlockTime = xDontBlock;
+ /* Pass the queue to this task also, using the parameter structure. */
+ pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
- /* Pass in the variable that this task is going to increment so we can check
- it is still running. */
- pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
+ /* The producer is not going to block - as soon as it posts the consumer will
+ * wake and remove the item so the producer should always have room to post. */
+ pxQueueParameters2->xBlockTime = xDontBlock;
+ /* Pass in the variable that this task is going to increment so we can check
+ * it is still running. */
+ pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
- /* Note the producer has a lower priority than the consumer when the tasks are
- spawned. */
- xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
- xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
-
+ /* Note the producer has a lower priority than the consumer when the tasks are
+ * spawned. */
+ xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
+ xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
- /* Create the second two tasks as described at the top of the file. This uses
- the same mechanism but reverses the task priorities. */
- pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
- pxQueueParameters3->xBlockTime = xDontBlock;
- pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
- pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
- pxQueueParameters4->xBlockTime = xBlockTime;
- pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
+ /* Create the second two tasks as described at the top of the file. This uses
+ * the same mechanism but reverses the task priorities. */
- xTaskCreate( vBlockingQueueProducer, "QProdB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vBlockingQueueConsumer, "QConsB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
+ pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
+ pxQueueParameters3->xBlockTime = xDontBlock;
+ pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
+ pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
+ pxQueueParameters4->xBlockTime = xBlockTime;
+ pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
+ xTaskCreate( vBlockingQueueProducer, "QProdB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vBlockingQueueConsumer, "QConsB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
- /* Create the last two tasks as described above. The mechanism is again just
- the same. This time both parameter structures are given a block time. */
- pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
- pxQueueParameters5->xBlockTime = xBlockTime;
- pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
- pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
- pxQueueParameters6->xBlockTime = xBlockTime;
- pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
- xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
+ /* Create the last two tasks as described above. The mechanism is again just
+ * the same. This time both parameter structures are given a block time. */
+ pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
+ pxQueueParameters5->xBlockTime = xBlockTime;
+ pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
+
+ pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
+ pxQueueParameters6->xBlockTime = xBlockTime;
+ pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
+
+ xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
}
/*-----------------------------------------------------------*/
-static void vBlockingQueueProducer( void *pvParameters )
+static void vBlockingQueueProducer( void * pvParameters )
{
-unsigned short usValue = 0;
-xBlockingQueueParameters *pxQueueParameters;
-const char * const pcTaskStartMsg = "Blocking queue producer started.\r\n";
-const char * const pcTaskErrorMsg = "Could not post on blocking queue\r\n";
-short sErrorEverOccurred = pdFALSE;
-
- pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- if( xQueueSendToBack( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
- {
- vPrintDisplayMessage( &pcTaskErrorMsg );
- sErrorEverOccurred = pdTRUE;
- }
- else
- {
- /* We have successfully posted a message, so increment the variable
- used to check we are still running. */
- if( sErrorEverOccurred == pdFALSE )
- {
- ( *pxQueueParameters->psCheckVariable )++;
- }
-
- /* Increment the variable we are going to post next time round. The
- consumer will expect the numbers to follow in numerical order. */
- ++usValue;
- }
- }
+ unsigned short usValue = 0;
+ xBlockingQueueParameters * pxQueueParameters;
+ const char * const pcTaskStartMsg = "Blocking queue producer started.\r\n";
+ const char * const pcTaskErrorMsg = "Could not post on blocking queue\r\n";
+ short sErrorEverOccurred = pdFALSE;
+
+ pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ if( xQueueSendToBack( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
+ {
+ vPrintDisplayMessage( &pcTaskErrorMsg );
+ sErrorEverOccurred = pdTRUE;
+ }
+ else
+ {
+ /* We have successfully posted a message, so increment the variable
+ * used to check we are still running. */
+ if( sErrorEverOccurred == pdFALSE )
+ {
+ ( *pxQueueParameters->psCheckVariable )++;
+ }
+
+ /* Increment the variable we are going to post next time round. The
+ * consumer will expect the numbers to follow in numerical order. */
+ ++usValue;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void vBlockingQueueConsumer( void *pvParameters )
+static void vBlockingQueueConsumer( void * pvParameters )
{
-unsigned short usData, usExpectedValue = 0;
-xBlockingQueueParameters *pxQueueParameters;
-const char * const pcTaskStartMsg = "Blocking queue consumer started.\r\n";
-const char * const pcTaskErrorMsg = "Incorrect value received on blocking queue.\r\n";
-short sErrorEverOccurred = pdFALSE;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
-
- for( ;; )
- {
- if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
- {
- if( usData != usExpectedValue )
- {
- vPrintDisplayMessage( &pcTaskErrorMsg );
-
- /* Catch-up. */
- usExpectedValue = usData;
-
- sErrorEverOccurred = pdTRUE;
- }
- else
- {
- /* We have successfully received a message, so increment the
- variable used to check we are still running. */
- if( sErrorEverOccurred == pdFALSE )
- {
- ( *pxQueueParameters->psCheckVariable )++;
- }
-
- /* Increment the value we expect to remove from the queue next time
- round. */
- ++usExpectedValue;
- }
- }
- }
+ unsigned short usData, usExpectedValue = 0;
+ xBlockingQueueParameters * pxQueueParameters;
+ const char * const pcTaskStartMsg = "Blocking queue consumer started.\r\n";
+ const char * const pcTaskErrorMsg = "Incorrect value received on blocking queue.\r\n";
+ short sErrorEverOccurred = pdFALSE;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
+
+ for( ; ; )
+ {
+ if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
+ {
+ if( usData != usExpectedValue )
+ {
+ vPrintDisplayMessage( &pcTaskErrorMsg );
+
+ /* Catch-up. */
+ usExpectedValue = usData;
+
+ sErrorEverOccurred = pdTRUE;
+ }
+ else
+ {
+ /* We have successfully received a message, so increment the
+ * variable used to check we are still running. */
+ if( sErrorEverOccurred == pdFALSE )
+ {
+ ( *pxQueueParameters->psCheckVariable )++;
+ }
+
+ /* Increment the value we expect to remove from the queue next time
+ * round. */
+ ++usExpectedValue;
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
portBASE_TYPE xAreBlockingQueuesStillRunning( void )
{
-static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
-static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
-portBASE_TYPE xReturn = pdPASS, xTasks;
-
- /* Not too worried about mutual exclusion on these variables as they are 16
- bits and we are only reading them. We also only care to see if they have
- changed or not.
-
- Loop through each check variable and return pdFALSE if any are found not
- to have changed since the last call. */
-
- for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
- {
- if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
- {
- xReturn = pdFALSE;
- }
- sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
-
-
- if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
- {
- xReturn = pdFALSE;
- }
- sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
- }
-
- return xReturn;
+ static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
+ static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( short ) 0, ( short ) 0, ( short ) 0 };
+ portBASE_TYPE xReturn = pdPASS, xTasks;
+
+ /* Not too worried about mutual exclusion on these variables as they are 16
+ * bits and we are only reading them. We also only care to see if they have
+ * changed or not.
+ *
+ * Loop through each check variable and return pdFALSE if any are found not
+ * to have changed since the last call. */
+
+ for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
+ {
+ if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
+ {
+ xReturn = pdFALSE;
+ }
+
+ sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
+
+ if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
+ {
+ xReturn = pdFALSE;
+ }
+
+ sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
+ }
+
+ return xReturn;
}
-
diff --git a/FreeRTOS/Demo/Common/Full/PollQ.c b/FreeRTOS/Demo/Common/Full/PollQ.c
index 048d7e90e..d4cd7c0f5 100644
--- a/FreeRTOS/Demo/Common/Full/PollQ.c
+++ b/FreeRTOS/Demo/Common/Full/PollQ.c
@@ -27,24 +27,24 @@
/**
- * This is a very simple queue test. See the BlockQ. c documentation for a more
+ * This is a very simple queue test. See the BlockQ. c documentation for a more
* comprehensive version.
*
- * Creates two tasks that communicate over a single queue. One task acts as a
- * producer, the other a consumer.
+ * Creates two tasks that communicate over a single queue. One task acts as a
+ * producer, the other a consumer.
*
- * The producer loops for three iteration, posting an incrementing number onto the
- * queue each cycle. It then delays for a fixed period before doing exactly the
+ * The producer loops for three iteration, posting an incrementing number onto the
+ * queue each cycle. It then delays for a fixed period before doing exactly the
* same again.
*
- * The consumer loops emptying the queue. Each item removed from the queue is
- * checked to ensure it contains the expected value. When the queue is empty it
+ * The consumer loops emptying the queue. Each item removed from the queue is
+ * checked to ensure it contains the expected value. When the queue is empty it
* blocks for a fixed period, then does the same again.
*
- * All queue access is performed without blocking. The consumer completely empties
- * the queue each time it runs so the producer should never find the queue full.
+ * All queue access is performed without blocking. The consumer completely empties
+ * the queue each time it runs so the producer should never find the queue full.
*
- * An error is flagged if the consumer obtains an unexpected value or the producer
+ * An error is flagged if the consumer obtains an unexpected value or the producer
* find the queue is full.
*
* \page PollQC pollQ.c
@@ -53,11 +53,11 @@
*/
/*
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
-*/
+ * Changes from V2.0.0
+ *
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ */
#include <stdlib.h>
@@ -70,13 +70,13 @@ Changes from V2.0.0
/* Demo program include files. */
#include "PollQ.h"
-#define pollqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
+#define pollqSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
/* The task that posts the incrementing number onto the queue. */
-static void vPolledQueueProducer( void *pvParameters );
+static void vPolledQueueProducer( void * pvParameters );
/* The task that empties the queue. */
-static void vPolledQueueConsumer( void *pvParameters );
+static void vPolledQueueConsumer( void * pvParameters );
/* Variables that are used to check that the tasks are still running with no errors. */
static volatile short sPollingConsumerCount = 0, sPollingProducerCount = 0;
@@ -84,137 +84,139 @@ static volatile short sPollingConsumerCount = 0, sPollingProducerCount = 0;
void vStartPolledQueueTasks( unsigned portBASE_TYPE uxPriority )
{
-static QueueHandle_t xPolledQueue;
-const unsigned portBASE_TYPE uxQueueSize = 10;
+ static QueueHandle_t xPolledQueue;
+ const unsigned portBASE_TYPE uxQueueSize = 10;
- /* Create the queue used by the producer and consumer. */
- xPolledQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
+ /* Create the queue used by the producer and consumer. */
+ xPolledQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( unsigned short ) );
- /* Spawn the producer and consumer. */
- xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
- xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
+ /* Spawn the producer and consumer. */
+ xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
+ xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, NULL );
}
/*-----------------------------------------------------------*/
-static void vPolledQueueProducer( void *pvParameters )
+static void vPolledQueueProducer( void * pvParameters )
{
-unsigned short usValue = 0, usLoop;
-QueueHandle_t *pxQueue;
-const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
-const unsigned short usNumToProduce = 3;
-const char * const pcTaskStartMsg = "Polled queue producer started.\r\n";
-const char * const pcTaskErrorMsg = "Could not post on polled queue.\r\n";
-short sError = pdFALSE;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The queue being used is passed in as the parameter. */
- pxQueue = ( QueueHandle_t * ) pvParameters;
-
- for( ;; )
- {
- for( usLoop = 0; usLoop < usNumToProduce; ++usLoop )
- {
- /* Send an incrementing number on the queue without blocking. */
- if( xQueueSendToBack( *pxQueue, ( void * ) &usValue, ( TickType_t ) 0 ) != pdPASS )
- {
- /* We should never find the queue full - this is an error. */
- vPrintDisplayMessage( &pcTaskErrorMsg );
- sError = pdTRUE;
- }
- else
- {
- if( sError == pdFALSE )
- {
- /* If an error has ever been recorded we stop incrementing the
- check variable. */
- ++sPollingProducerCount;
- }
-
- /* Update the value we are going to post next time around. */
- ++usValue;
- }
- }
-
- /* Wait before we start posting again to ensure the consumer runs and
- empties the queue. */
- vTaskDelay( xDelay );
- }
+ unsigned short usValue = 0, usLoop;
+ QueueHandle_t * pxQueue;
+ const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
+ const unsigned short usNumToProduce = 3;
+ const char * const pcTaskStartMsg = "Polled queue producer started.\r\n";
+ const char * const pcTaskErrorMsg = "Could not post on polled queue.\r\n";
+ short sError = pdFALSE;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The queue being used is passed in as the parameter. */
+ pxQueue = ( QueueHandle_t * ) pvParameters;
+
+ for( ; ; )
+ {
+ for( usLoop = 0; usLoop < usNumToProduce; ++usLoop )
+ {
+ /* Send an incrementing number on the queue without blocking. */
+ if( xQueueSendToBack( *pxQueue, ( void * ) &usValue, ( TickType_t ) 0 ) != pdPASS )
+ {
+ /* We should never find the queue full - this is an error. */
+ vPrintDisplayMessage( &pcTaskErrorMsg );
+ sError = pdTRUE;
+ }
+ else
+ {
+ if( sError == pdFALSE )
+ {
+ /* If an error has ever been recorded we stop incrementing the
+ * check variable. */
+ ++sPollingProducerCount;
+ }
+
+ /* Update the value we are going to post next time around. */
+ ++usValue;
+ }
+ }
+
+ /* Wait before we start posting again to ensure the consumer runs and
+ * empties the queue. */
+ vTaskDelay( xDelay );
+ }
}
/*-----------------------------------------------------------*/
-static void vPolledQueueConsumer( void *pvParameters )
+static void vPolledQueueConsumer( void * pvParameters )
{
-unsigned short usData, usExpectedValue = 0;
-QueueHandle_t *pxQueue;
-const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
-const char * const pcTaskStartMsg = "Polled queue consumer started.\r\n";
-const char * const pcTaskErrorMsg = "Incorrect value received on polled queue.\r\n";
-short sError = pdFALSE;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The queue being used is passed in as the parameter. */
- pxQueue = ( QueueHandle_t * ) pvParameters;
-
- for( ;; )
- {
- /* Loop until the queue is empty. */
- while( uxQueueMessagesWaiting( *pxQueue ) )
- {
- if( xQueueReceive( *pxQueue, &usData, ( TickType_t ) 0 ) == pdPASS )
- {
- if( usData != usExpectedValue )
- {
- /* This is not what we expected to receive so an error has
- occurred. */
- vPrintDisplayMessage( &pcTaskErrorMsg );
- sError = pdTRUE;
- /* Catch-up to the value we received so our next expected value
- should again be correct. */
- usExpectedValue = usData;
- }
- else
- {
- if( sError == pdFALSE )
- {
- /* Only increment the check variable if no errors have
- occurred. */
- ++sPollingConsumerCount;
- }
- }
- ++usExpectedValue;
- }
- }
-
- /* Now the queue is empty we block, allowing the producer to place more
- items in the queue. */
- vTaskDelay( xDelay );
- }
+ unsigned short usData, usExpectedValue = 0;
+ QueueHandle_t * pxQueue;
+ const TickType_t xDelay = ( TickType_t ) 200 / portTICK_PERIOD_MS;
+ const char * const pcTaskStartMsg = "Polled queue consumer started.\r\n";
+ const char * const pcTaskErrorMsg = "Incorrect value received on polled queue.\r\n";
+ short sError = pdFALSE;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The queue being used is passed in as the parameter. */
+ pxQueue = ( QueueHandle_t * ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Loop until the queue is empty. */
+ while( uxQueueMessagesWaiting( *pxQueue ) )
+ {
+ if( xQueueReceive( *pxQueue, &usData, ( TickType_t ) 0 ) == pdPASS )
+ {
+ if( usData != usExpectedValue )
+ {
+ /* This is not what we expected to receive so an error has
+ * occurred. */
+ vPrintDisplayMessage( &pcTaskErrorMsg );
+ sError = pdTRUE;
+
+ /* Catch-up to the value we received so our next expected value
+ * should again be correct. */
+ usExpectedValue = usData;
+ }
+ else
+ {
+ if( sError == pdFALSE )
+ {
+ /* Only increment the check variable if no errors have
+ * occurred. */
+ ++sPollingConsumerCount;
+ }
+ }
+
+ ++usExpectedValue;
+ }
+ }
+
+ /* Now the queue is empty we block, allowing the producer to place more
+ * items in the queue. */
+ vTaskDelay( xDelay );
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running with no errors. */
portBASE_TYPE xArePollingQueuesStillRunning( void )
{
-static short sLastPollingConsumerCount = 0, sLastPollingProducerCount = 0;
-portBASE_TYPE xReturn;
-
- if( ( sLastPollingConsumerCount == sPollingConsumerCount ) ||
- ( sLastPollingProducerCount == sPollingProducerCount )
- )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- sLastPollingConsumerCount = sPollingConsumerCount;
- sLastPollingProducerCount = sPollingProducerCount;
-
- return xReturn;
+ static short sLastPollingConsumerCount = 0, sLastPollingProducerCount = 0;
+ portBASE_TYPE xReturn;
+
+ if( ( sLastPollingConsumerCount == sPollingConsumerCount ) ||
+ ( sLastPollingProducerCount == sPollingProducerCount )
+ )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ xReturn = pdTRUE;
+ }
+
+ sLastPollingConsumerCount = sPollingConsumerCount;
+ sLastPollingProducerCount = sPollingProducerCount;
+
+ return xReturn;
}
diff --git a/FreeRTOS/Demo/Common/Full/comtest.c b/FreeRTOS/Demo/Common/Full/comtest.c
index 45897dedd..24f07a1f1 100644
--- a/FreeRTOS/Demo/Common/Full/comtest.c
+++ b/FreeRTOS/Demo/Common/Full/comtest.c
@@ -19,72 +19,72 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * https://www.FreeRTOS.org
- * https://github.com/FreeRTOS
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
/**
- * Creates two tasks that operate on an interrupt driven serial port. A loopback
- * connector should be used so that everything that is transmitted is also received.
- * The serial port does not use any flow control. On a standard 9way 'D' connector
+ * Creates two tasks that operate on an interrupt driven serial port. A loopback
+ * connector should be used so that everything that is transmitted is also received.
+ * The serial port does not use any flow control. On a standard 9way 'D' connector
* pins two and three should be connected together.
*
- * The first task repeatedly sends a string to a queue, character at a time. The
- * serial port interrupt will empty the queue and transmit the characters. The
+ * The first task repeatedly sends a string to a queue, character at a time. The
+ * serial port interrupt will empty the queue and transmit the characters. The
* task blocks for a pseudo random period before resending the string.
*
- * The second task blocks on a queue waiting for a character to be received.
- * Characters received by the serial port interrupt routine are posted onto the
- * queue - unblocking the task making it ready to execute. If this is then the
- * highest priority task ready to run it will run immediately - with a context
- * switch occurring at the end of the interrupt service routine. The task
- * receiving characters is spawned with a higher priority than the task
+ * The second task blocks on a queue waiting for a character to be received.
+ * Characters received by the serial port interrupt routine are posted onto the
+ * queue - unblocking the task making it ready to execute. If this is then the
+ * highest priority task ready to run it will run immediately - with a context
+ * switch occurring at the end of the interrupt service routine. The task
+ * receiving characters is spawned with a higher priority than the task
* transmitting the characters.
*
- * With the loop back connector in place, one task will transmit a string and the
- * other will immediately receive it. The receiving task knows the string it
+ * With the loop back connector in place, one task will transmit a string and the
+ * other will immediately receive it. The receiving task knows the string it
* expects to receive so can detect an error.
*
* This also creates a third task. This is used to test semaphore usage from an
- * ISR and does nothing interesting.
- *
+ * ISR and does nothing interesting.
+ *
* \page ComTestC comtest.c
* \ingroup DemoFiles
* <HR>
*/
/*
-Changes from V1.00:
-
- + The priority of the Rx task has been lowered. Received characters are
- now processed (read from the queue) at the idle priority, allowing low
- priority tasks to run evenly at times of a high communications overhead.
-
-Changes from V1.01:
-
- + The Tx task now waits a pseudo random time between transmissions.
- Previously a fixed period was used but this was not such a good test as
- interrupts fired at regular intervals.
-
-Changes From V1.2.0:
-
- + Use vSerialPutString() instead of single character puts.
- + Only stop the check variable incrementing after two consecutive errors.
-
-Changed from V1.2.5
-
- + Made the Rx task 2 priorities higher than the Tx task. Previously it was
- only 1. This is done to tie in better with the other demo application
- tasks.
-
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
- + Slight modification to task priorities.
-
-*/
+ * Changes from V1.00:
+ *
+ + The priority of the Rx task has been lowered. Received characters are
+ + now processed (read from the queue) at the idle priority, allowing low
+ + priority tasks to run evenly at times of a high communications overhead.
+ +
+ + Changes from V1.01:
+ +
+ + The Tx task now waits a pseudo random time between transmissions.
+ + Previously a fixed period was used but this was not such a good test as
+ + interrupts fired at regular intervals.
+ +
+ + Changes From V1.2.0:
+ +
+ + Use vSerialPutString() instead of single character puts.
+ + Only stop the check variable incrementing after two consecutive errors.
+ +
+ + Changed from V1.2.5
+ +
+ + Made the Rx task 2 priorities higher than the Tx task. Previously it was
+ + only 1. This is done to tie in better with the other demo application
+ + tasks.
+ +
+ + Changes from V2.0.0
+ +
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ + Slight modification to task priorities.
+ +
+ */
/* Scheduler include files. */
@@ -99,34 +99,34 @@ Changes from V2.0.0
#include "print.h"
/* The Tx task will transmit the sequence of characters at a pseudo random
-interval. This is the maximum and minimum block time between sends. */
-#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x15e )
-#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0xc8 )
+ * interval. This is the maximum and minimum block time between sends. */
+#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x15e )
+#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0xc8 )
-#define comMAX_CONSECUTIVE_ERRORS ( 2 )
+#define comMAX_CONSECUTIVE_ERRORS ( 2 )
-#define comSTACK_SIZE ( ( unsigned short ) 256 )
+#define comSTACK_SIZE ( ( unsigned short ) 256 )
-#define comRX_RELATIVE_PRIORITY ( 1 )
+#define comRX_RELATIVE_PRIORITY ( 1 )
/* Handle to the com port used by both tasks. */
static xComPortHandle xPort;
/* The transmit function as described at the top of the file. */
-static void vComTxTask( void *pvParameters );
+static void vComTxTask( void * pvParameters );
/* The receive function as described at the top of the file. */
-static void vComRxTask( void *pvParameters );
+static void vComRxTask( void * pvParameters );
/* The semaphore test function as described at the top of the file. */
static void vSemTestTask( void * pvParameters );
/* The string that is repeatedly transmitted. */
-const char * const pcMessageToExchange = "Send this message over and over again to check communications interrupts. "
- "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
+const char * const pcMessageToExchange = "Send this message over and over again to check communications interrupts. "
+ "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n";
-/* Variables that are incremented on each cycle of each task. These are used to
-check that both tasks are still executing. */
+/* Variables that are incremented on each cycle of each task. These are used to
+ * check that both tasks are still executing. */
volatile short sTxCount = 0, sRxCount = 0, sSemCount = 0;
/* The handle to the semaphore test task. */
@@ -134,212 +134,217 @@ static TaskHandle_t xSemTestTaskHandle = NULL;
/*-----------------------------------------------------------*/
-void vStartComTestTasks( unsigned portBASE_TYPE uxPriority, eCOMPort ePort, eBaud eBaudRate )
+void vStartComTestTasks( unsigned portBASE_TYPE uxPriority,
+ eCOMPort ePort,
+ eBaud eBaudRate )
{
-const unsigned portBASE_TYPE uxBufferLength = 255;
+ const unsigned portBASE_TYPE uxBufferLength = 255;
- /* Initialise the com port then spawn both tasks. */
- xPort = xSerialPortInit( ePort, eBaudRate, serNO_PARITY, serBITS_8, serSTOP_1, uxBufferLength );
- xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority, NULL );
- xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority + comRX_RELATIVE_PRIORITY, NULL );
- xTaskCreate( vSemTestTask, "ISRSem", comSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xSemTestTaskHandle );
+ /* Initialise the com port then spawn both tasks. */
+ xPort = xSerialPortInit( ePort, eBaudRate, serNO_PARITY, serBITS_8, serSTOP_1, uxBufferLength );
+ xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority, NULL );
+ xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority + comRX_RELATIVE_PRIORITY, NULL );
+ xTaskCreate( vSemTestTask, "ISRSem", comSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xSemTestTaskHandle );
}
/*-----------------------------------------------------------*/
-static void vComTxTask( void *pvParameters )
+static void vComTxTask( void * pvParameters )
{
-const char * const pcTaskStartMsg = "COM Tx task started.\r\n";
-TickType_t xTimeToWait;
+ const char * const pcTaskStartMsg = "COM Tx task started.\r\n";
+ TickType_t xTimeToWait;
- /* Stop warnings. */
- ( void ) pvParameters;
+ /* Stop warnings. */
+ ( void ) pvParameters;
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
- for( ;; )
- {
- /* Send the string to the serial port. */
- vSerialPutString( xPort, pcMessageToExchange, strlen( pcMessageToExchange ) );
+ for( ; ; )
+ {
+ /* Send the string to the serial port. */
+ vSerialPutString( xPort, pcMessageToExchange, strlen( pcMessageToExchange ) );
- /* We have posted all the characters in the string - increment the variable
- used to check that this task is still running, then wait before re-sending
- the string. */
- sTxCount++;
+ /* We have posted all the characters in the string - increment the variable
+ * used to check that this task is still running, then wait before re-sending
+ * the string. */
+ sTxCount++;
- xTimeToWait = xTaskGetTickCount();
+ xTimeToWait = xTaskGetTickCount();
- /* Make sure we don't wait too long... */
- xTimeToWait %= comTX_MAX_BLOCK_TIME;
+ /* Make sure we don't wait too long... */
+ xTimeToWait %= comTX_MAX_BLOCK_TIME;
- /* ...but we do want to wait. */
- if( xTimeToWait < comTX_MIN_BLOCK_TIME )
- {
- xTimeToWait = comTX_MIN_BLOCK_TIME;
- }
+ /* ...but we do want to wait. */
+ if( xTimeToWait < comTX_MIN_BLOCK_TIME )
+ {
+ xTimeToWait = comTX_MIN_BLOCK_TIME;
+ }
- vTaskDelay( xTimeToWait );
- }
+ vTaskDelay( xTimeToWait );
+ }
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/*-----------------------------------------------------------*/
-static void vComRxTask( void *pvParameters )
+static void vComRxTask( void * pvParameters )
{
-const char * const pcTaskStartMsg = "COM Rx task started.\r\n";
-const char * const pcTaskErrorMsg = "COM read error\r\n";
-const char * const pcTaskRestartMsg = "COM resynced\r\n";
-const char * const pcTaskTimeoutMsg = "COM Rx timed out\r\n";
-const TickType_t xBlockTime = ( TickType_t ) 0xffff / portTICK_PERIOD_MS;
-const char *pcExpectedChar;
-portBASE_TYPE xGotChar;
-char cRxedChar;
-short sResyncRequired, sConsecutiveErrors, sLatchedError;
-
- /* Stop warnings. */
- ( void ) pvParameters;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The first expected character is the first character in the string. */
- pcExpectedChar = pcMessageToExchange;
- sResyncRequired = pdFALSE;
- sConsecutiveErrors = 0;
- sLatchedError = pdFALSE;
-
- for( ;; )
- {
- /* Receive a message from the com port interrupt routine. If a message is
- not yet available the call will block the task. */
- xGotChar = xSerialGetChar( xPort, &cRxedChar, xBlockTime );
- if( xGotChar == pdTRUE )
- {
- if( sResyncRequired == pdTRUE )
- {
- /* We got out of sequence and are waiting for the start of the next
- transmission of the string. */
- if( cRxedChar == '\n' )
- {
- /* This is the end of the message so we can start again - with
- the first character in the string being the next thing we expect
- to receive. */
- pcExpectedChar = pcMessageToExchange;
- sResyncRequired = pdFALSE;
-
- /* Queue a message for printing to say that we are going to try
- again. */
- vPrintDisplayMessage( &pcTaskRestartMsg );
-
- /* Stop incrementing the check variable, if consecutive errors occur. */
- sConsecutiveErrors++;
- if( sConsecutiveErrors >= comMAX_CONSECUTIVE_ERRORS )
- {
- sLatchedError = pdTRUE;
- }
- }
- }
- else
- {
- /* We have received a character, but is it the expected character? */
- if( cRxedChar != *pcExpectedChar )
- {
- /* This was not the expected character so post a message for
- printing to say that an error has occurred. We will then wait
- to resynchronise. */
- vPrintDisplayMessage( &pcTaskErrorMsg );
- sResyncRequired = pdTRUE;
- }
- else
- {
- /* This was the expected character so next time we will expect
- the next character in the string. Wrap back to the beginning
- of the string when the null terminator has been reached. */
- pcExpectedChar++;
- if( *pcExpectedChar == '\0' )
- {
- pcExpectedChar = pcMessageToExchange;
-
- /* We have got through the entire string without error. */
- sConsecutiveErrors = 0;
- }
- }
- }
-
- /* Increment the count that is used to check that this task is still
- running. This is only done if an error has never occurred. */
- if( sLatchedError == pdFALSE )
- {
- sRxCount++;
- }
- }
- else
- {
- vPrintDisplayMessage( &pcTaskTimeoutMsg );
- }
- }
+ const char * const pcTaskStartMsg = "COM Rx task started.\r\n";
+ const char * const pcTaskErrorMsg = "COM read error\r\n";
+ const char * const pcTaskRestartMsg = "COM resynced\r\n";
+ const char * const pcTaskTimeoutMsg = "COM Rx timed out\r\n";
+ const TickType_t xBlockTime = ( TickType_t ) 0xffff / portTICK_PERIOD_MS;
+ const char * pcExpectedChar;
+ portBASE_TYPE xGotChar;
+ char cRxedChar;
+ short sResyncRequired, sConsecutiveErrors, sLatchedError;
+
+ /* Stop warnings. */
+ ( void ) pvParameters;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The first expected character is the first character in the string. */
+ pcExpectedChar = pcMessageToExchange;
+ sResyncRequired = pdFALSE;
+ sConsecutiveErrors = 0;
+ sLatchedError = pdFALSE;
+
+ for( ; ; )
+ {
+ /* Receive a message from the com port interrupt routine. If a message is
+ * not yet available the call will block the task. */
+ xGotChar = xSerialGetChar( xPort, &cRxedChar, xBlockTime );
+
+ if( xGotChar == pdTRUE )
+ {
+ if( sResyncRequired == pdTRUE )
+ {
+ /* We got out of sequence and are waiting for the start of the next
+ * transmission of the string. */
+ if( cRxedChar == '\n' )
+ {
+ /* This is the end of the message so we can start again - with
+ * the first character in the string being the next thing we expect
+ * to receive. */
+ pcExpectedChar = pcMessageToExchange;
+ sResyncRequired = pdFALSE;
+
+ /* Queue a message for printing to say that we are going to try
+ * again. */
+ vPrintDisplayMessage( &pcTaskRestartMsg );
+
+ /* Stop incrementing the check variable, if consecutive errors occur. */
+ sConsecutiveErrors++;
+
+ if( sConsecutiveErrors >= comMAX_CONSECUTIVE_ERRORS )
+ {
+ sLatchedError = pdTRUE;
+ }
+ }
+ }
+ else
+ {
+ /* We have received a character, but is it the expected character? */
+ if( cRxedChar != *pcExpectedChar )
+ {
+ /* This was not the expected character so post a message for
+ * printing to say that an error has occurred. We will then wait
+ * to resynchronise. */
+ vPrintDisplayMessage( &pcTaskErrorMsg );
+ sResyncRequired = pdTRUE;
+ }
+ else
+ {
+ /* This was the expected character so next time we will expect
+ * the next character in the string. Wrap back to the beginning
+ * of the string when the null terminator has been reached. */
+ pcExpectedChar++;
+
+ if( *pcExpectedChar == '\0' )
+ {
+ pcExpectedChar = pcMessageToExchange;
+
+ /* We have got through the entire string without error. */
+ sConsecutiveErrors = 0;
+ }
+ }
+ }
+
+ /* Increment the count that is used to check that this task is still
+ * running. This is only done if an error has never occurred. */
+ if( sLatchedError == pdFALSE )
+ {
+ sRxCount++;
+ }
+ }
+ else
+ {
+ vPrintDisplayMessage( &pcTaskTimeoutMsg );
+ }
+ }
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/*-----------------------------------------------------------*/
static void vSemTestTask( void * pvParameters )
{
-const char * const pcTaskStartMsg = "ISR Semaphore test started.\r\n";
-portBASE_TYPE xError = pdFALSE;
-
- /* Stop warnings. */
- ( void ) pvParameters;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- if( xSerialWaitForSemaphore( xPort ) )
- {
- if( xError == pdFALSE )
- {
- sSemCount++;
- }
- }
- else
- {
- xError = pdTRUE;
- }
- }
+ const char * const pcTaskStartMsg = "ISR Semaphore test started.\r\n";
+ portBASE_TYPE xError = pdFALSE;
+
+ /* Stop warnings. */
+ ( void ) pvParameters;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ if( xSerialWaitForSemaphore( xPort ) )
+ {
+ if( xError == pdFALSE )
+ {
+ sSemCount++;
+ }
+ }
+ else
+ {
+ xError = pdTRUE;
+ }
+ }
} /*lint !e715 !e830 !e818 pvParameters not used but function prototype must be standard for task function. */
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
portBASE_TYPE xAreComTestTasksStillRunning( void )
{
-static short sLastTxCount = 0, sLastRxCount = 0, sLastSemCount = 0;
-portBASE_TYPE xReturn;
-
- /* Not too worried about mutual exclusion on these variables as they are 16
- bits and we are only reading them. We also only care to see if they have
- changed or not. */
-
- if( ( sTxCount == sLastTxCount ) || ( sRxCount == sLastRxCount ) || ( sSemCount == sLastSemCount ) )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- sLastTxCount = sTxCount;
- sLastRxCount = sRxCount;
- sLastSemCount = sSemCount;
-
- return xReturn;
+ static short sLastTxCount = 0, sLastRxCount = 0, sLastSemCount = 0;
+ portBASE_TYPE xReturn;
+
+ /* Not too worried about mutual exclusion on these variables as they are 16
+ * bits and we are only reading them. We also only care to see if they have
+ * changed or not. */
+
+ if( ( sTxCount == sLastTxCount ) || ( sRxCount == sLastRxCount ) || ( sSemCount == sLastSemCount ) )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ xReturn = pdTRUE;
+ }
+
+ sLastTxCount = sTxCount;
+ sLastRxCount = sRxCount;
+ sLastSemCount = sSemCount;
+
+ return xReturn;
}
/*-----------------------------------------------------------*/
void vComTestUnsuspendTask( void )
{
- /* The task that is suspended on the semaphore will be referenced from the
- Suspended list as it is blocking indefinitely. This call just checks that
- the kernel correctly detects this and does not attempt to unsuspend the
- task. */
- xTaskResumeFromISR( xSemTestTaskHandle );
+ /* The task that is suspended on the semaphore will be referenced from the
+ * Suspended list as it is blocking indefinitely. This call just checks that
+ * the kernel correctly detects this and does not attempt to unsuspend the
+ * task. */
+ xTaskResumeFromISR( xSemTestTaskHandle );
}
diff --git a/FreeRTOS/Demo/Common/Full/death.c b/FreeRTOS/Demo/Common/Full/death.c
index ffd3e0653..ce3ba1c14 100644
--- a/FreeRTOS/Demo/Common/Full/death.c
+++ b/FreeRTOS/Demo/Common/Full/death.c
@@ -25,17 +25,17 @@
*/
/**
- * Create a single persistent task which periodically dynamically creates another
- * four tasks. The original task is called the creator task, the four tasks it
+ * Create a single persistent task which periodically dynamically creates another
+ * four tasks. The original task is called the creator task, the four tasks it
* creates are called suicidal tasks.
*
- * Two of the created suicidal tasks kill one other suicidal task before killing
- * themselves - leaving just the original task remaining.
+ * Two of the created suicidal tasks kill one other suicidal task before killing
+ * themselves - leaving just the original task remaining.
*
- * The creator task must be spawned after all of the other demo application tasks
- * as it keeps a check on the number of tasks under the scheduler control. The
- * number of tasks it expects to see running should never be greater than the
- * number of tasks that were in existence when the creator task was spawned, plus
+ * The creator task must be spawned after all of the other demo application tasks
+ * as it keeps a check on the number of tasks under the scheduler control. The
+ * number of tasks it expects to see running should never be greater than the
+ * number of tasks that were in existence when the creator task was spawned, plus
* one set of four suicidal tasks. If this number is exceeded an error is flagged.
*
* \page DeathC death.c
@@ -44,11 +44,11 @@
*/
/*
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
-*/
+ * Changes from V2.0.0
+ *
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ */
#include <stdlib.h>
@@ -60,66 +60,66 @@ Changes from V2.0.0
#include "death.h"
#include "print.h"
-#define deathSTACK_SIZE ( ( unsigned short ) 512 )
+#define deathSTACK_SIZE ( ( unsigned short ) 512 )
-/* The task originally created which is responsible for periodically dynamically
-creating another four tasks. */
-static void vCreateTasks( void *pvParameters );
+/* The task originally created which is responsible for periodically dynamically
+ * creating another four tasks. */
+static void vCreateTasks( void * pvParameters );
/* The task function of the dynamically created tasks. */
-static void vSuicidalTask( void *pvParameters );
+static void vSuicidalTask( void * pvParameters );
-/* A variable which is incremented every time the dynamic tasks are created. This
-is used to check that the task is still running. */
+/* A variable which is incremented every time the dynamic tasks are created. This
+ * is used to check that the task is still running. */
static volatile short sCreationCount = 0;
-/* Used to store the number of tasks that were originally running so the creator
-task can tell if any of the suicidal tasks have failed to die. */
+/* Used to store the number of tasks that were originally running so the creator
+ * task can tell if any of the suicidal tasks have failed to die. */
static volatile unsigned portBASE_TYPE uxTasksRunningAtStart = 0;
static const unsigned portBASE_TYPE uxMaxNumberOfExtraTasksRunning = 5;
-/* Used to store a handle to the tasks that should be killed by a suicidal task,
-before it kills itself. */
+/* Used to store a handle to the tasks that should be killed by a suicidal task,
+ * before it kills itself. */
TaskHandle_t xCreatedTask1, xCreatedTask2;
/*-----------------------------------------------------------*/
void vCreateSuicidalTasks( unsigned portBASE_TYPE uxPriority )
{
-unsigned portBASE_TYPE *puxPriority;
+ unsigned portBASE_TYPE * puxPriority;
- /* Create the Creator tasks - passing in as a parameter the priority at which
- the suicidal tasks should be created. */
+ /* Create the Creator tasks - passing in as a parameter the priority at which
+ * the suicidal tasks should be created. */
puxPriority = ( unsigned portBASE_TYPE * ) pvPortMalloc( sizeof( unsigned portBASE_TYPE ) );
*puxPriority = uxPriority;
xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) puxPriority, uxPriority, NULL );
- /* Record the number of tasks that are running now so we know if any of the
- suicidal tasks have failed to be killed. */
+ /* Record the number of tasks that are running now so we know if any of the
+ * suicidal tasks have failed to be killed. */
uxTasksRunningAtStart = uxTaskGetNumberOfTasks();
}
/*-----------------------------------------------------------*/
-static void vSuicidalTask( void *pvParameters )
+static void vSuicidalTask( void * pvParameters )
{
-portDOUBLE d1, d2;
-TaskHandle_t xTaskToKill;
-const TickType_t xDelay = ( TickType_t ) 500 / portTICK_PERIOD_MS;
+ portDOUBLE d1, d2;
+ TaskHandle_t xTaskToKill;
+ const TickType_t xDelay = ( TickType_t ) 500 / portTICK_PERIOD_MS;
if( pvParameters != NULL )
{
- /* This task is periodically created four times. Tow created tasks are
- passed a handle to the other task so it can kill it before killing itself.
- The other task is passed in null. */
- xTaskToKill = *( TaskHandle_t* )pvParameters;
+ /* This task is periodically created four times. Tow created tasks are
+ * passed a handle to the other task so it can kill it before killing itself.
+ * The other task is passed in null. */
+ xTaskToKill = *( TaskHandle_t * ) pvParameters;
}
else
{
xTaskToKill = NULL;
}
- for( ;; )
+ for( ; ; )
{
/* Do something random just to use some stack and registers. */
d1 = 2.4;
@@ -137,14 +137,14 @@ const TickType_t xDelay = ( TickType_t ) 500 / portTICK_PERIOD_MS;
vTaskDelete( NULL );
}
}
-}/*lint !e818 !e550 Function prototype must be as per standard for task functions. */
+} /*lint !e818 !e550 Function prototype must be as per standard for task functions. */
/*-----------------------------------------------------------*/
-static void vCreateTasks( void *pvParameters )
+static void vCreateTasks( void * pvParameters )
{
-const TickType_t xDelay = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
-unsigned portBASE_TYPE uxPriority;
-const char * const pcTaskStartMsg = "Create task started.\r\n";
+ const TickType_t xDelay = ( TickType_t ) 1000 / portTICK_PERIOD_MS;
+ unsigned portBASE_TYPE uxPriority;
+ const char * const pcTaskStartMsg = "Create task started.\r\n";
/* Queue a message for printing to say the task has started. */
vPrintDisplayMessage( &pcTaskStartMsg );
@@ -152,7 +152,7 @@ const char * const pcTaskStartMsg = "Create task started.\r\n";
uxPriority = *( unsigned portBASE_TYPE * ) pvParameters;
vPortFree( pvParameters );
- for( ;; )
+ for( ; ; )
{
/* Just loop round, delaying then creating the four suicidal tasks. */
vTaskDelay( xDelay );
@@ -168,18 +168,19 @@ const char * const pcTaskStartMsg = "Create task started.\r\n";
}
/*-----------------------------------------------------------*/
-/* This is called to check that the creator task is still running and that there
-are not any more than four extra tasks. */
+/* This is called to check that the creator task is still running and that there
+ * are not any more than four extra tasks. */
portBASE_TYPE xIsCreateTaskStillRunning( void )
{
-static short sLastCreationCount = 0;
-short sReturn = pdTRUE;
-unsigned portBASE_TYPE uxTasksRunningNow;
+ static short sLastCreationCount = 0;
+ short sReturn = pdTRUE;
+ unsigned portBASE_TYPE uxTasksRunningNow;
if( sLastCreationCount == sCreationCount )
{
sReturn = pdFALSE;
}
+
sLastCreationCount = sCreationCount;
uxTasksRunningNow = uxTaskGetNumberOfTasks();
@@ -199,5 +200,3 @@ unsigned portBASE_TYPE uxTasksRunningNow;
return sReturn;
}
-
-
diff --git a/FreeRTOS/Demo/Common/Full/dynamic.c b/FreeRTOS/Demo/Common/Full/dynamic.c
index 86010e13a..a3c983c37 100644
--- a/FreeRTOS/Demo/Common/Full/dynamic.c
+++ b/FreeRTOS/Demo/Common/Full/dynamic.c
@@ -26,31 +26,31 @@
*/
/**
- * The first test creates three tasks - two counter tasks (one continuous count
- * and one limited count) and one controller. A "count" variable is shared
- * between all three tasks. The two counter tasks should never be in a "ready"
- * state at the same time. The controller task runs at the same priority as
- * the continuous count task, and at a lower priority than the limited count
+ * The first test creates three tasks - two counter tasks (one continuous count
+ * and one limited count) and one controller. A "count" variable is shared
+ * between all three tasks. The two counter tasks should never be in a "ready"
+ * state at the same time. The controller task runs at the same priority as
+ * the continuous count task, and at a lower priority than the limited count
* task.
*
* One counter task loops indefinitely, incrementing the shared count variable
* on each iteration. To ensure it has exclusive access to the variable it
- * raises it's priority above that of the controller task before each
+ * raises it's priority above that of the controller task before each
* increment, lowering it again to it's original priority before starting the
* next iteration.
*
* The other counter task increments the shared count variable on each
* iteration of it's loop until the count has reached a limit of 0xff - at
- * which point it suspends itself. It will not start a new loop until the
- * controller task has made it "ready" again by calling vTaskResume ().
- * This second counter task operates at a higher priority than controller
- * task so does not need to worry about mutual exclusion of the counter
+ * which point it suspends itself. It will not start a new loop until the
+ * controller task has made it "ready" again by calling vTaskResume ().
+ * This second counter task operates at a higher priority than controller
+ * task so does not need to worry about mutual exclusion of the counter
* variable.
*
* The controller task is in two sections. The first section controls and
- * monitors the continuous count task. When this section is operational the
- * limited count task is suspended. Likewise, the second section controls
- * and monitors the limited count task. When this section is operational the
+ * monitors the continuous count task. When this section is operational the
+ * limited count task is suspended. Likewise, the second section controls
+ * and monitors the limited count task. When this section is operational the
* continuous count task is suspended.
*
* In the first section the controller task first takes a copy of the shared
@@ -60,11 +60,11 @@
* the continuous count task will execute and increment the shared variable.
* When the controller task wakes it checks that the continuous count task
* has executed by comparing the copy of the shared variable with its current
- * value. This time, to ensure mutual exclusion, the scheduler itself is
- * suspended with a call to vTaskSuspendAll (). This is for demonstration
+ * value. This time, to ensure mutual exclusion, the scheduler itself is
+ * suspended with a call to vTaskSuspendAll (). This is for demonstration
* purposes only and is not a recommended technique due to its inefficiency.
*
- * After a fixed number of iterations the controller task suspends the
+ * After a fixed number of iterations the controller task suspends the
* continuous count task, and moves on to its second section.
*
* At the start of the second section the shared variable is cleared to zero.
@@ -76,7 +76,7 @@
* a check on the shared variable to ensure everything is as expected.
*
*
- * The second test consists of a couple of very simple tasks that post onto a
+ * The second test consists of a couple of very simple tasks that post onto a
* queue while the scheduler is suspended. This test was added to test parts
* of the scheduler not exercised by the first test.
*
@@ -91,20 +91,20 @@
*/
/*
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
- + Added a second, simple test that uses the functions
- vQueueReceiveWhenSuspendedTask() and vQueueSendWhenSuspendedTask().
-
-Changes from V3.1.1
-
- + Added a third simple test that uses the vTaskPrioritySet() function
- while the scheduler is suspended.
- + Modified the controller task slightly to test the calling of
- vTaskResumeAll() while the scheduler is suspended.
-*/
+ * Changes from V2.0.0
+ *
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ + Added a second, simple test that uses the functions
+ + vQueueReceiveWhenSuspendedTask() and vQueueSendWhenSuspendedTask().
+ +
+ + Changes from V3.1.1
+ +
+ + Added a third simple test that uses the vTaskPrioritySet() function
+ + while the scheduler is suspended.
+ + Modified the controller task slightly to test the calling of
+ + vTaskResumeAll() while the scheduler is suspended.
+ */
#include <stdlib.h>
@@ -127,42 +127,42 @@ static void vContinuousIncrementTask( void * pvParameters );
static void vCounterControlTask( void * pvParameters );
/* The simple test functions that check sending and receiving while the
-scheduler is suspended. */
-static void vQueueReceiveWhenSuspendedTask( void *pvParameters );
-static void vQueueSendWhenSuspendedTask( void *pvParameters );
+ * scheduler is suspended. */
+static void vQueueReceiveWhenSuspendedTask( void * pvParameters );
+static void vQueueSendWhenSuspendedTask( void * pvParameters );
/* The simple test functions that check raising and lowering of task priorities
-while the scheduler is suspended. */
-static void prvChangePriorityWhenSuspendedTask( void *pvParameters );
-static void prvChangePriorityHelperTask( void *pvParameters );
+ * while the scheduler is suspended. */
+static void prvChangePriorityWhenSuspendedTask( void * pvParameters );
+static void prvChangePriorityHelperTask( void * pvParameters );
/* Demo task specific constants. */
-#define priSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
-#define priSLEEP_TIME ( ( TickType_t ) 50 )
-#define priLOOPS ( 5 )
-#define priMAX_COUNT ( ( unsigned long ) 0xff )
-#define priNO_BLOCK ( ( TickType_t ) 0 )
-#define priSUSPENDED_QUEUE_LENGTH ( 1 )
+#define priSTACK_SIZE ( ( unsigned short ) configMINIMAL_STACK_SIZE )
+#define priSLEEP_TIME ( ( TickType_t ) 50 )
+#define priLOOPS ( 5 )
+#define priMAX_COUNT ( ( unsigned long ) 0xff )
+#define priNO_BLOCK ( ( TickType_t ) 0 )
+#define priSUSPENDED_QUEUE_LENGTH ( 1 )
/*-----------------------------------------------------------*/
/* Handles to the two counter tasks. These could be passed in as parameters
-to the controller task to prevent them having to be file scope. */
+ * to the controller task to prevent them having to be file scope. */
static TaskHandle_t xContinuousIncrementHandle, xLimitedIncrementHandle, xChangePriorityWhenSuspendedHandle;
-/* The shared counter variable. This is passed in as a parameter to the two
-counter variables for demonstration purposes. */
+/* The shared counter variable. This is passed in as a parameter to the two
+ * counter variables for demonstration purposes. */
static unsigned long ulCounter;
/* Variable used in a similar way by the test that checks the raising and
-lowering of task priorities while the scheduler is suspended. */
+ * lowering of task priorities while the scheduler is suspended. */
static unsigned long ulPrioritySetCounter;
/* Variables used to check that the tasks are still operating without error.
-Each complete iteration of the controller task increments this variable
-provided no errors have been found. The variable maintaining the same value
-is therefore indication of an error. */
+ * Each complete iteration of the controller task increments this variable
+ * provided no errors have been found. The variable maintaining the same value
+ * is therefore indication of an error. */
static unsigned short usCheckVariable = ( unsigned short ) 0;
static portBASE_TYPE xSuspendedQueueSendError = pdFALSE;
static portBASE_TYPE xSuspendedQueueReceiveError = pdFALSE;
@@ -172,49 +172,50 @@ static portBASE_TYPE xPriorityRaiseWhenSuspendedError = pdFALSE;
QueueHandle_t xSuspendedTestQueue;
/*-----------------------------------------------------------*/
+
/*
* Start the seven tasks as described at the top of the file.
* Note that the limited count task is given a higher priority.
*/
void vStartDynamicPriorityTasks( void )
{
- xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned long ) );
- xTaskCreate( vContinuousIncrementTask, "CONT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
- xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
- xTaskCreate( vCounterControlTask, "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_SEND", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RECV", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- xTaskCreate( prvChangePriorityWhenSuspendedTask, "1st_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
- xTaskCreate( prvChangePriorityHelperTask, "2nd_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xChangePriorityWhenSuspendedHandle );
+ xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( unsigned long ) );
+ xTaskCreate( vContinuousIncrementTask, "CONT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
+ xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
+ xTaskCreate( vCounterControlTask, "C_CTRL", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_SEND", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RECV", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( prvChangePriorityWhenSuspendedTask, "1st_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL );
+ xTaskCreate( prvChangePriorityHelperTask, "2nd_P_CHANGE", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xChangePriorityWhenSuspendedHandle );
}
/*-----------------------------------------------------------*/
/*
* Just loops around incrementing the shared variable until the limit has been
- * reached. Once the limit has been reached it suspends itself.
+ * reached. Once the limit has been reached it suspends itself.
*/
static void vLimitedIncrementTask( void * pvParameters )
{
-unsigned long *pulCounter;
-
- /* Take a pointer to the shared variable from the parameters passed into
- the task. */
- pulCounter = ( unsigned long * ) pvParameters;
-
- /* This will run before the control task, so the first thing it does is
- suspend - the control task will resume it when ready. */
- vTaskSuspend( NULL );
-
- for( ;; )
- {
- /* Just count up to a value then suspend. */
- ( *pulCounter )++;
-
- if( *pulCounter >= priMAX_COUNT )
- {
- vTaskSuspend( NULL );
- }
- }
+ unsigned long * pulCounter;
+
+ /* Take a pointer to the shared variable from the parameters passed into
+ * the task. */
+ pulCounter = ( unsigned long * ) pvParameters;
+
+ /* This will run before the control task, so the first thing it does is
+ * suspend - the control task will resume it when ready. */
+ vTaskSuspend( NULL );
+
+ for( ; ; )
+ {
+ /* Just count up to a value then suspend. */
+ ( *pulCounter )++;
+
+ if( *pulCounter >= priMAX_COUNT )
+ {
+ vTaskSuspend( NULL );
+ }
+ }
}
/*-----------------------------------------------------------*/
@@ -224,29 +225,29 @@ unsigned long *pulCounter;
*/
static void vContinuousIncrementTask( void * pvParameters )
{
-unsigned long *pulCounter;
-unsigned portBASE_TYPE uxOurPriority;
-
- /* Take a pointer to the shared variable from the parameters passed into
- the task. */
- pulCounter = ( unsigned long * ) pvParameters;
-
- /* Query our priority so we can raise it when exclusive access to the
- shared variable is required. */
- uxOurPriority = uxTaskPriorityGet( NULL );
-
- for( ;; )
- {
- /* Raise our priority above the controller task to ensure a context
- switch does not occur while we are accessing this variable. */
- vTaskPrioritySet( NULL, uxOurPriority + 1 );
- ( *pulCounter )++;
- vTaskPrioritySet( NULL, uxOurPriority );
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
- }
+ unsigned long * pulCounter;
+ unsigned portBASE_TYPE uxOurPriority;
+
+ /* Take a pointer to the shared variable from the parameters passed into
+ * the task. */
+ pulCounter = ( unsigned long * ) pvParameters;
+
+ /* Query our priority so we can raise it when exclusive access to the
+ * shared variable is required. */
+ uxOurPriority = uxTaskPriorityGet( NULL );
+
+ for( ; ; )
+ {
+ /* Raise our priority above the controller task to ensure a context
+ * switch does not occur while we are accessing this variable. */
+ vTaskPrioritySet( NULL, uxOurPriority + 1 );
+ ( *pulCounter )++;
+ vTaskPrioritySet( NULL, uxOurPriority );
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ }
}
/*-----------------------------------------------------------*/
@@ -255,324 +256,320 @@ unsigned portBASE_TYPE uxOurPriority;
*/
static void vCounterControlTask( void * pvParameters )
{
-unsigned long ulLastCounter;
-short sLoops;
-short sError = pdFALSE;
-const char * const pcTaskStartMsg = "Priority manipulation tasks started.\r\n";
-const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
-
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- /* Start with the counter at zero. */
- ulCounter = ( unsigned long ) 0;
-
- /* First section : */
-
- /* Check the continuous count task is running. */
- for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
- {
- /* Suspend the continuous count task so we can take a mirror of the
- shared variable without risk of corruption. */
- vTaskSuspend( xContinuousIncrementHandle );
- ulLastCounter = ulCounter;
- vTaskResume( xContinuousIncrementHandle );
-
- /* Now delay to ensure the other task has processor time. */
- vTaskDelay( priSLEEP_TIME );
-
- /* Check the shared variable again. This time to ensure mutual
- exclusion the whole scheduler will be locked. This is just for
- demo purposes! */
- vTaskSuspendAll();
- {
- if( ulLastCounter == ulCounter )
- {
- /* The shared variable has not changed. There is a problem
- with the continuous count task so flag an error. */
- sError = pdTRUE;
- xTaskResumeAll();
- vPrintDisplayMessage( &pcTaskFailMsg );
- vTaskSuspendAll();
- }
- }
- xTaskResumeAll();
- }
-
-
- /* Second section: */
-
- /* Suspend the continuous counter task so it stops accessing the shared variable. */
- vTaskSuspend( xContinuousIncrementHandle );
-
- /* Reset the variable. */
- ulCounter = ( unsigned long ) 0;
-
- /* Resume the limited count task which has a higher priority than us.
- We should therefore not return from this call until the limited count
- task has suspended itself with a known value in the counter variable.
- The scheduler suspension is not necessary but is included for test
- purposes. */
- vTaskSuspendAll();
- vTaskResume( xLimitedIncrementHandle );
- xTaskResumeAll();
-
- /* Does the counter variable have the expected value? */
- if( ulCounter != priMAX_COUNT )
- {
- sError = pdTRUE;
- vPrintDisplayMessage( &pcTaskFailMsg );
- }
-
- if( sError == pdFALSE )
- {
- /* If no errors have occurred then increment the check variable. */
- portENTER_CRITICAL();
- usCheckVariable++;
- portEXIT_CRITICAL();
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* Resume the continuous count task and do it all again. */
- vTaskResume( xContinuousIncrementHandle );
- }
+ unsigned long ulLastCounter;
+ short sLoops;
+ short sError = pdFALSE;
+ const char * const pcTaskStartMsg = "Priority manipulation tasks started.\r\n";
+ const char * const pcTaskFailMsg = "Priority manipulation Task Failed\r\n";
+
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ /* Start with the counter at zero. */
+ ulCounter = ( unsigned long ) 0;
+
+ /* First section : */
+
+ /* Check the continuous count task is running. */
+ for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
+ {
+ /* Suspend the continuous count task so we can take a mirror of the
+ * shared variable without risk of corruption. */
+ vTaskSuspend( xContinuousIncrementHandle );
+ ulLastCounter = ulCounter;
+ vTaskResume( xContinuousIncrementHandle );
+
+ /* Now delay to ensure the other task has processor time. */
+ vTaskDelay( priSLEEP_TIME );
+
+ /* Check the shared variable again. This time to ensure mutual
+ * exclusion the whole scheduler will be locked. This is just for
+ * demo purposes! */
+ vTaskSuspendAll();
+ {
+ if( ulLastCounter == ulCounter )
+ {
+ /* The shared variable has not changed. There is a problem
+ * with the continuous count task so flag an error. */
+ sError = pdTRUE;
+ xTaskResumeAll();
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ vTaskSuspendAll();
+ }
+ }
+ xTaskResumeAll();
+ }
+
+ /* Second section: */
+
+ /* Suspend the continuous counter task so it stops accessing the shared variable. */
+ vTaskSuspend( xContinuousIncrementHandle );
+
+ /* Reset the variable. */
+ ulCounter = ( unsigned long ) 0;
+
+ /* Resume the limited count task which has a higher priority than us.
+ * We should therefore not return from this call until the limited count
+ * task has suspended itself with a known value in the counter variable.
+ * The scheduler suspension is not necessary but is included for test
+ * purposes. */
+ vTaskSuspendAll();
+ vTaskResume( xLimitedIncrementHandle );
+ xTaskResumeAll();
+
+ /* Does the counter variable have the expected value? */
+ if( ulCounter != priMAX_COUNT )
+ {
+ sError = pdTRUE;
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If no errors have occurred then increment the check variable. */
+ portENTER_CRITICAL();
+ usCheckVariable++;
+ portEXIT_CRITICAL();
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Resume the continuous count task and do it all again. */
+ vTaskResume( xContinuousIncrementHandle );
+ }
}
/*-----------------------------------------------------------*/
-static void vQueueSendWhenSuspendedTask( void *pvParameters )
+static void vQueueSendWhenSuspendedTask( void * pvParameters )
{
-static unsigned long ulValueToSend = ( unsigned long ) 0;
-const char * const pcTaskStartMsg = "Queue send while suspended task started.\r\n";
-const char * const pcTaskFailMsg = "Queue send while suspended failed.\r\n";
-
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- vTaskSuspendAll();
- {
- /* We must not block while the scheduler is suspended! */
- if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
- {
- if( xSuspendedQueueSendError == pdFALSE )
- {
- xTaskResumeAll();
- vPrintDisplayMessage( &pcTaskFailMsg );
- vTaskSuspendAll();
- }
-
- xSuspendedQueueSendError = pdTRUE;
- }
- }
- xTaskResumeAll();
-
- vTaskDelay( priSLEEP_TIME );
-
- ++ulValueToSend;
- }
+ static unsigned long ulValueToSend = ( unsigned long ) 0;
+ const char * const pcTaskStartMsg = "Queue send while suspended task started.\r\n";
+ const char * const pcTaskFailMsg = "Queue send while suspended failed.\r\n";
+
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ vTaskSuspendAll();
+ {
+ /* We must not block while the scheduler is suspended! */
+ if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
+ {
+ if( xSuspendedQueueSendError == pdFALSE )
+ {
+ xTaskResumeAll();
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ vTaskSuspendAll();
+ }
+
+ xSuspendedQueueSendError = pdTRUE;
+ }
+ }
+ xTaskResumeAll();
+
+ vTaskDelay( priSLEEP_TIME );
+
+ ++ulValueToSend;
+ }
}
/*-----------------------------------------------------------*/
-static void vQueueReceiveWhenSuspendedTask( void *pvParameters )
+static void vQueueReceiveWhenSuspendedTask( void * pvParameters )
{
-static unsigned long ulExpectedValue = ( unsigned long ) 0, ulReceivedValue;
-const char * const pcTaskStartMsg = "Queue receive while suspended task started.\r\n";
-const char * const pcTaskFailMsg = "Queue receive while suspended failed.\r\n";
-portBASE_TYPE xGotValue;
-
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- do
- {
- /* Suspending the scheduler here is fairly pointless and
- undesirable for a normal application. It is done here purely
- to test the scheduler. The inner xTaskResumeAll() should
- never return pdTRUE as the scheduler is still locked by the
- outer call. */
- vTaskSuspendAll();
- {
- vTaskSuspendAll();
- {
- xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
- }
- if( xTaskResumeAll() )
- {
- xSuspendedQueueReceiveError = pdTRUE;
- }
- }
- xTaskResumeAll();
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- } while( xGotValue == pdFALSE );
-
- if( ulReceivedValue != ulExpectedValue )
- {
- if( xSuspendedQueueReceiveError == pdFALSE )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- }
- xSuspendedQueueReceiveError = pdTRUE;
- }
-
- ++ulExpectedValue;
- }
+ static unsigned long ulExpectedValue = ( unsigned long ) 0, ulReceivedValue;
+ const char * const pcTaskStartMsg = "Queue receive while suspended task started.\r\n";
+ const char * const pcTaskFailMsg = "Queue receive while suspended failed.\r\n";
+ portBASE_TYPE xGotValue;
+
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ do
+ {
+ /* Suspending the scheduler here is fairly pointless and
+ * undesirable for a normal application. It is done here purely
+ * to test the scheduler. The inner xTaskResumeAll() should
+ * never return pdTRUE as the scheduler is still locked by the
+ * outer call. */
+ vTaskSuspendAll();
+ {
+ vTaskSuspendAll();
+ {
+ xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
+ }
+
+ if( xTaskResumeAll() )
+ {
+ xSuspendedQueueReceiveError = pdTRUE;
+ }
+ }
+ xTaskResumeAll();
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ } while( xGotValue == pdFALSE );
+
+ if( ulReceivedValue != ulExpectedValue )
+ {
+ if( xSuspendedQueueReceiveError == pdFALSE )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ }
+
+ xSuspendedQueueReceiveError = pdTRUE;
+ }
+
+ ++ulExpectedValue;
+ }
}
/*-----------------------------------------------------------*/
-static void prvChangePriorityWhenSuspendedTask( void *pvParameters )
+static void prvChangePriorityWhenSuspendedTask( void * pvParameters )
{
-const char * const pcTaskStartMsg = "Priority change when suspended task started.\r\n";
-const char * const pcTaskFailMsg = "Priority change when suspended task failed.\r\n";
-
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- /* Start with the counter at 0 so we know what the counter should be
- when we check it next. */
- ulPrioritySetCounter = ( unsigned long ) 0;
-
- /* Resume the helper task. At this time it has a priority lower than
- ours so no context switch should occur. */
- vTaskResume( xChangePriorityWhenSuspendedHandle );
-
- /* Check to ensure the task just resumed has not executed. */
- portENTER_CRITICAL();
- {
- if( ulPrioritySetCounter != ( unsigned long ) 0 )
- {
- xPriorityRaiseWhenSuspendedError = pdTRUE;
- vPrintDisplayMessage( &pcTaskFailMsg );
- }
- }
- portEXIT_CRITICAL();
-
- /* Now try raising the priority while the scheduler is suspended. */
- vTaskSuspendAll();
- {
- vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, ( configMAX_PRIORITIES - 1 ) );
-
- /* Again, even though the helper task has a priority greater than
- ours, it should not have executed yet because the scheduler is
- suspended. */
- portENTER_CRITICAL();
- {
- if( ulPrioritySetCounter != ( unsigned long ) 0 )
- {
- xPriorityRaiseWhenSuspendedError = pdTRUE;
- vPrintDisplayMessage( &pcTaskFailMsg );
- }
- }
- portEXIT_CRITICAL();
- }
- xTaskResumeAll();
-
- /* Now the scheduler has been resumed the helper task should
- immediately preempt us and execute. When it executes it will increment
- the ulPrioritySetCounter exactly once before suspending itself.
-
- We should now always find the counter set to 1. */
- portENTER_CRITICAL();
- {
- if( ulPrioritySetCounter != ( unsigned long ) 1 )
- {
- xPriorityRaiseWhenSuspendedError = pdTRUE;
- vPrintDisplayMessage( &pcTaskFailMsg );
- }
- }
- portEXIT_CRITICAL();
-
- /* Delay until we try this again. */
- vTaskDelay( priSLEEP_TIME * 2 );
-
- /* Set the priority of the helper task back ready for the next
- execution of this task. */
- vTaskSuspendAll();
- vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, tskIDLE_PRIORITY );
- xTaskResumeAll();
- }
+ const char * const pcTaskStartMsg = "Priority change when suspended task started.\r\n";
+ const char * const pcTaskFailMsg = "Priority change when suspended task failed.\r\n";
+
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ /* Start with the counter at 0 so we know what the counter should be
+ * when we check it next. */
+ ulPrioritySetCounter = ( unsigned long ) 0;
+
+ /* Resume the helper task. At this time it has a priority lower than
+ * ours so no context switch should occur. */
+ vTaskResume( xChangePriorityWhenSuspendedHandle );
+
+ /* Check to ensure the task just resumed has not executed. */
+ portENTER_CRITICAL();
+ {
+ if( ulPrioritySetCounter != ( unsigned long ) 0 )
+ {
+ xPriorityRaiseWhenSuspendedError = pdTRUE;
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ }
+ }
+ portEXIT_CRITICAL();
+
+ /* Now try raising the priority while the scheduler is suspended. */
+ vTaskSuspendAll();
+ {
+ vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, ( configMAX_PRIORITIES - 1 ) );
+
+ /* Again, even though the helper task has a priority greater than
+ * ours, it should not have executed yet because the scheduler is
+ * suspended. */
+ portENTER_CRITICAL();
+ {
+ if( ulPrioritySetCounter != ( unsigned long ) 0 )
+ {
+ xPriorityRaiseWhenSuspendedError = pdTRUE;
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ }
+ }
+ portEXIT_CRITICAL();
+ }
+ xTaskResumeAll();
+
+ /* Now the scheduler has been resumed the helper task should
+ * immediately preempt us and execute. When it executes it will increment
+ * the ulPrioritySetCounter exactly once before suspending itself.
+ *
+ * We should now always find the counter set to 1. */
+ portENTER_CRITICAL();
+ {
+ if( ulPrioritySetCounter != ( unsigned long ) 1 )
+ {
+ xPriorityRaiseWhenSuspendedError = pdTRUE;
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ }
+ }
+ portEXIT_CRITICAL();
+
+ /* Delay until we try this again. */
+ vTaskDelay( priSLEEP_TIME * 2 );
+
+ /* Set the priority of the helper task back ready for the next
+ * execution of this task. */
+ vTaskSuspendAll();
+ vTaskPrioritySet( xChangePriorityWhenSuspendedHandle, tskIDLE_PRIORITY );
+ xTaskResumeAll();
+ }
}
/*-----------------------------------------------------------*/
-static void prvChangePriorityHelperTask( void *pvParameters )
+static void prvChangePriorityHelperTask( void * pvParameters )
{
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* This is the helper task for prvChangePriorityWhenSuspendedTask().
- It has it's priority raised and lowered. When it runs it simply
- increments the counter then suspends itself again. This allows
- prvChangePriorityWhenSuspendedTask() to know how many times it has
- executed. */
- ulPrioritySetCounter++;
- vTaskSuspend( NULL );
- }
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* This is the helper task for prvChangePriorityWhenSuspendedTask().
+ * It has it's priority raised and lowered. When it runs it simply
+ * increments the counter then suspends itself again. This allows
+ * prvChangePriorityWhenSuspendedTask() to know how many times it has
+ * executed. */
+ ulPrioritySetCounter++;
+ vTaskSuspend( NULL );
+ }
}
/*-----------------------------------------------------------*/
/* Called to check that all the created tasks are still running without error. */
portBASE_TYPE xAreDynamicPriorityTasksStillRunning( void )
{
-/* Keep a history of the check variables so we know if it has been incremented
-since the last call. */
-static unsigned short usLastTaskCheck = ( unsigned short ) 0;
-portBASE_TYPE xReturn = pdTRUE;
-
- /* Check the tasks are still running by ensuring the check variable
- is still incrementing. */
-
- if( usCheckVariable == usLastTaskCheck )
- {
- /* The check has not incremented so an error exists. */
- xReturn = pdFALSE;
- }
-
- if( xSuspendedQueueSendError == pdTRUE )
- {
- xReturn = pdFALSE;
- }
-
- if( xSuspendedQueueReceiveError == pdTRUE )
- {
- xReturn = pdFALSE;
- }
-
- if( xPriorityRaiseWhenSuspendedError == pdTRUE )
- {
- xReturn = pdFALSE;
- }
-
- usLastTaskCheck = usCheckVariable;
- return xReturn;
+/* Keep a history of the check variables so we know if it has been incremented
+ * since the last call. */
+ static unsigned short usLastTaskCheck = ( unsigned short ) 0;
+ portBASE_TYPE xReturn = pdTRUE;
+
+ /* Check the tasks are still running by ensuring the check variable
+ * is still incrementing. */
+
+ if( usCheckVariable == usLastTaskCheck )
+ {
+ /* The check has not incremented so an error exists. */
+ xReturn = pdFALSE;
+ }
+
+ if( xSuspendedQueueSendError == pdTRUE )
+ {
+ xReturn = pdFALSE;
+ }
+
+ if( xSuspendedQueueReceiveError == pdTRUE )
+ {
+ xReturn = pdFALSE;
+ }
+
+ if( xPriorityRaiseWhenSuspendedError == pdTRUE )
+ {
+ xReturn = pdFALSE;
+ }
+
+ usLastTaskCheck = usCheckVariable;
+ return xReturn;
}
-
-
-
-
diff --git a/FreeRTOS/Demo/Common/Full/events.c b/FreeRTOS/Demo/Common/Full/events.c
index 1ed7fbfd5..5d884190f 100644
--- a/FreeRTOS/Demo/Common/Full/events.c
+++ b/FreeRTOS/Demo/Common/Full/events.c
@@ -60,309 +60,310 @@
#include "print.h"
/* Demo specific constants. */
-#define evtSTACK_SIZE ( ( unsigned portBASE_TYPE ) configMINIMAL_STACK_SIZE )
-#define evtNUM_TASKS ( 4 )
-#define evtQUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 3 )
-#define evtNO_DELAY 0
+#define evtSTACK_SIZE ( ( unsigned portBASE_TYPE ) configMINIMAL_STACK_SIZE )
+#define evtNUM_TASKS ( 4 )
+#define evtQUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 3 )
+#define evtNO_DELAY 0
/* Just indexes used to uniquely identify the tasks. Note that two tasks are
-'highest' priority. */
-#define evtHIGHEST_PRIORITY_INDEX_2 3
-#define evtHIGHEST_PRIORITY_INDEX_1 2
-#define evtMEDIUM_PRIORITY_INDEX 1
-#define evtLOWEST_PRIORITY_INDEX 0
+ * 'highest' priority. */
+#define evtHIGHEST_PRIORITY_INDEX_2 3
+#define evtHIGHEST_PRIORITY_INDEX_1 2
+#define evtMEDIUM_PRIORITY_INDEX 1
+#define evtLOWEST_PRIORITY_INDEX 0
/* Each event task increments one of these counters each time it reads data
-from the queue. */
+ * from the queue. */
static volatile portBASE_TYPE xTaskCounters[ evtNUM_TASKS ] = { 0, 0, 0, 0 };
-/* Each time the controlling task posts onto the queue it increments the
-expected count of the task that it expected to read the data from the queue
-(i.e. the task with the highest priority that should be blocked on the queue).
-
-xExpectedTaskCounters are incremented from the controlling task, and
-xTaskCounters are incremented from the individual event tasks - therefore
-comparing xTaskCounters to xExpectedTaskCounters shows whether or not the
-correct task was unblocked by the post. */
+/* Each time the controlling task posts onto the queue it increments the
+ * expected count of the task that it expected to read the data from the queue
+ * (i.e. the task with the highest priority that should be blocked on the queue).
+ *
+ * xExpectedTaskCounters are incremented from the controlling task, and
+ * xTaskCounters are incremented from the individual event tasks - therefore
+ * comparing xTaskCounters to xExpectedTaskCounters shows whether or not the
+ * correct task was unblocked by the post. */
static portBASE_TYPE xExpectedTaskCounters[ evtNUM_TASKS ] = { 0, 0, 0, 0 };
/* Handles to the four event tasks. These are required to suspend and resume
-the tasks. */
+ * the tasks. */
static TaskHandle_t xCreatedTasks[ evtNUM_TASKS ];
/* The single queue onto which the controlling task posts, and the four event
-tasks block. */
+ * tasks block. */
static QueueHandle_t xQueue;
/* Flag used to indicate whether or not an error has occurred at any time.
-An error is either the queue being full when not expected, or an unexpected
-task reading data from the queue. */
+ * An error is either the queue being full when not expected, or an unexpected
+ * task reading data from the queue. */
static portBASE_TYPE xHealthStatus = pdPASS;
/*-----------------------------------------------------------*/
/* Function that implements the event task. This is created four times. */
-static void prvMultiEventTask( void *pvParameters );
+static void prvMultiEventTask( void * pvParameters );
/* Function that implements the controlling task. */
-static void prvEventControllerTask( void *pvParameters );
-
-/* This is a utility function that posts data to the queue, then compares
-xExpectedTaskCounters with xTaskCounters to ensure everything worked as
-expected.
+static void prvEventControllerTask( void * pvParameters );
-The event tasks all have higher priorities the controlling task. Therefore
-the controlling task will always get preempted between writhing to the queue
-and checking the task counters.
-
-@param xExpectedTask The index to the task that the controlling task thinks
- should be the highest priority task waiting for data, and
- therefore the task that will unblock.
-
-@param xIncrement The number of items that should be written to the queue.
-*/
-static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask, portBASE_TYPE xIncrement );
+/* This is a utility function that posts data to the queue, then compares
+ * xExpectedTaskCounters with xTaskCounters to ensure everything worked as
+ * expected.
+ *
+ * The event tasks all have higher priorities the controlling task. Therefore
+ * the controlling task will always get preempted between writhing to the queue
+ * and checking the task counters.
+ *
+ * @param xExpectedTask The index to the task that the controlling task thinks
+ * should be the highest priority task waiting for data, and
+ * therefore the task that will unblock.
+ *
+ * @param xIncrement The number of items that should be written to the queue.
+ */
+static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask,
+ portBASE_TYPE xIncrement );
/* This is just incremented each cycle of the controlling tasks function so
-the main application can ensure the test is still running. */
+ * the main application can ensure the test is still running. */
static portBASE_TYPE xCheckVariable = 0;
/*-----------------------------------------------------------*/
void vStartMultiEventTasks( void )
{
- /* Create the queue to be used for all the communications. */
- xQueue = xQueueCreate( evtQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
-
- /* Start the controlling task. This has the idle priority to ensure it is
- always preempted by the event tasks. */
- xTaskCreate( prvEventControllerTask, "EvntCTRL", evtSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
-
- /* Start the four event tasks. Note that two have priority 3, one
- priority 2 and the other priority 1. */
- xTaskCreate( prvMultiEventTask, "Event0", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 0 ] ), 1, &( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] ) );
- xTaskCreate( prvMultiEventTask, "Event1", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 1 ] ), 2, &( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] ) );
- xTaskCreate( prvMultiEventTask, "Event2", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 2 ] ), 3, &( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] ) );
- xTaskCreate( prvMultiEventTask, "Event3", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 3 ] ), 3, &( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] ) );
+ /* Create the queue to be used for all the communications. */
+ xQueue = xQueueCreate( evtQUEUE_LENGTH, ( unsigned portBASE_TYPE ) sizeof( unsigned portBASE_TYPE ) );
+
+ /* Start the controlling task. This has the idle priority to ensure it is
+ * always preempted by the event tasks. */
+ xTaskCreate( prvEventControllerTask, "EvntCTRL", evtSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+
+ /* Start the four event tasks. Note that two have priority 3, one
+ * priority 2 and the other priority 1. */
+ xTaskCreate( prvMultiEventTask, "Event0", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 0 ] ), 1, &( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] ) );
+ xTaskCreate( prvMultiEventTask, "Event1", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 1 ] ), 2, &( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] ) );
+ xTaskCreate( prvMultiEventTask, "Event2", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 2 ] ), 3, &( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] ) );
+ xTaskCreate( prvMultiEventTask, "Event3", evtSTACK_SIZE, ( void * ) &( xTaskCounters[ 3 ] ), 3, &( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] ) );
}
/*-----------------------------------------------------------*/
-static void prvMultiEventTask( void *pvParameters )
+static void prvMultiEventTask( void * pvParameters )
{
-portBASE_TYPE *pxCounter;
-unsigned portBASE_TYPE uxDummy;
-const char * const pcTaskStartMsg = "Multi event task started.\r\n";
-
- /* The variable this task will increment is passed in as a parameter. */
- pxCounter = ( portBASE_TYPE * ) pvParameters;
-
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- /* Block on the queue. */
- if( xQueueReceive( xQueue, &uxDummy, portMAX_DELAY ) )
- {
- /* We unblocked by reading the queue - so simply increment
- the counter specific to this task instance. */
- ( *pxCounter )++;
- }
- else
- {
- xHealthStatus = pdFAIL;
- }
- }
+ portBASE_TYPE * pxCounter;
+ unsigned portBASE_TYPE uxDummy;
+ const char * const pcTaskStartMsg = "Multi event task started.\r\n";
+
+ /* The variable this task will increment is passed in as a parameter. */
+ pxCounter = ( portBASE_TYPE * ) pvParameters;
+
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ /* Block on the queue. */
+ if( xQueueReceive( xQueue, &uxDummy, portMAX_DELAY ) )
+ {
+ /* We unblocked by reading the queue - so simply increment
+ * the counter specific to this task instance. */
+ ( *pxCounter )++;
+ }
+ else
+ {
+ xHealthStatus = pdFAIL;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prvEventControllerTask( void *pvParameters )
+static void prvEventControllerTask( void * pvParameters )
{
-const char * const pcTaskStartMsg = "Multi event controller task started.\r\n";
-portBASE_TYPE xDummy = 0;
-
- /* Just to stop warnings. */
- ( void ) pvParameters;
-
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- for( ;; )
- {
- /* All tasks are blocked on the queue. When a message is posted one of
- the two tasks that share the highest priority should unblock to read
- the queue. The next message written should unblock the other task with
- the same high priority, and so on in order. No other task should
- unblock to read data as they have lower priorities. */
-
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
-
- /* For the rest of these tests we don't need the second 'highest'
- priority task - so it is suspended. */
- vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
-
-
-
- /* Now suspend the other highest priority task. The medium priority
- task will then be the task with the highest priority that remains
- blocked on the queue. */
- vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
-
- /* This time, when we post onto the queue we will expect the medium
- priority task to unblock and preempt us. */
- prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
-
- /* Now try resuming the highest priority task while the scheduler is
- suspended. The task should start executing as soon as the scheduler
- is resumed - therefore when we post to the queue again, the highest
- priority task should again preempt us. */
- vTaskSuspendAll();
- vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
- xTaskResumeAll();
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
-
- /* Now we are going to suspend the high and medium priority tasks. The
- low priority task should then preempt us. Again the task suspension is
- done with the whole scheduler suspended just for test purposes. */
- vTaskSuspendAll();
- vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
- vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
- xTaskResumeAll();
- prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 1 );
-
- /* Do the same basic test another few times - selectively suspending
- and resuming tasks and each time calling prvCheckTaskCounters() passing
- to the function the number of the task we expected to be unblocked by
- the post. */
-
- vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
-
- vTaskSuspendAll(); /* Just for test. */
- vTaskSuspendAll(); /* Just for test. */
- vTaskSuspendAll(); /* Just for even more test. */
- vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
- xTaskResumeAll();
- xTaskResumeAll();
- xTaskResumeAll();
- prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 1 );
-
- vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
- prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
-
- vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
- prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
-
- /* Now a slight change, first suspend all tasks. */
- vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
- vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
- vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
-
- /* Now when we resume the low priority task and write to the queue 3
- times. We expect the low priority task to service the queue three
- times. */
- vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
- prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, evtQUEUE_LENGTH );
-
- /* Again suspend all tasks (only the low priority task is not suspended
- already). */
- vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
-
- /* This time we are going to suspend the scheduler, resume the low
- priority task, then resume the high priority task. In this state we
- will write to the queue three times. When the scheduler is resumed
- we expect the high priority task to service all three messages. */
- vTaskSuspendAll();
- {
- vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
- vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
-
- for( xDummy = 0; xDummy < evtQUEUE_LENGTH; xDummy++ )
- {
- if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
- {
- xHealthStatus = pdFAIL;
- }
- }
-
- /* The queue should not have been serviced yet!. The scheduler
- is still suspended. */
- if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
- {
- xHealthStatus = pdFAIL;
- }
- }
- xTaskResumeAll();
-
- /* We should have been preempted by resuming the scheduler - so by the
- time we are running again we expect the high priority task to have
- removed three items from the queue. */
- xExpectedTaskCounters[ evtHIGHEST_PRIORITY_INDEX_1 ] += evtQUEUE_LENGTH;
- if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
- {
- xHealthStatus = pdFAIL;
- }
-
- /* The medium priority and second high priority tasks are still
- suspended. Make sure to resume them before starting again. */
- vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
- vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
-
- /* Just keep incrementing to show the task is still executing. */
- xCheckVariable++;
- }
+ const char * const pcTaskStartMsg = "Multi event controller task started.\r\n";
+ portBASE_TYPE xDummy = 0;
+
+ /* Just to stop warnings. */
+ ( void ) pvParameters;
+
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ for( ; ; )
+ {
+ /* All tasks are blocked on the queue. When a message is posted one of
+ * the two tasks that share the highest priority should unblock to read
+ * the queue. The next message written should unblock the other task with
+ * the same high priority, and so on in order. No other task should
+ * unblock to read data as they have lower priorities. */
+
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_2, 1 );
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
+
+ /* For the rest of these tests we don't need the second 'highest'
+ * priority task - so it is suspended. */
+ vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
+
+
+
+ /* Now suspend the other highest priority task. The medium priority
+ * task will then be the task with the highest priority that remains
+ * blocked on the queue. */
+ vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+
+ /* This time, when we post onto the queue we will expect the medium
+ * priority task to unblock and preempt us. */
+ prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
+
+ /* Now try resuming the highest priority task while the scheduler is
+ * suspended. The task should start executing as soon as the scheduler
+ * is resumed - therefore when we post to the queue again, the highest
+ * priority task should again preempt us. */
+ vTaskSuspendAll();
+ vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+ xTaskResumeAll();
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
+
+ /* Now we are going to suspend the high and medium priority tasks. The
+ * low priority task should then preempt us. Again the task suspension is
+ * done with the whole scheduler suspended just for test purposes. */
+ vTaskSuspendAll();
+ vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+ vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
+ xTaskResumeAll();
+ prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 1 );
+
+ /* Do the same basic test another few times - selectively suspending
+ * and resuming tasks and each time calling prvCheckTaskCounters() passing
+ * to the function the number of the task we expected to be unblocked by
+ * the post. */
+
+ vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
+
+ vTaskSuspendAll(); /* Just for test. */
+ vTaskSuspendAll(); /* Just for test. */
+ vTaskSuspendAll(); /* Just for even more test. */
+ vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+ xTaskResumeAll();
+ xTaskResumeAll();
+ xTaskResumeAll();
+ prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, 1 );
+
+ vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
+ prvCheckTaskCounters( evtMEDIUM_PRIORITY_INDEX, 1 );
+
+ vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+ prvCheckTaskCounters( evtHIGHEST_PRIORITY_INDEX_1, 1 );
+
+ /* Now a slight change, first suspend all tasks. */
+ vTaskSuspend( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+ vTaskSuspend( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
+ vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
+
+ /* Now when we resume the low priority task and write to the queue 3
+ * times. We expect the low priority task to service the queue three
+ * times. */
+ vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
+ prvCheckTaskCounters( evtLOWEST_PRIORITY_INDEX, evtQUEUE_LENGTH );
+
+ /* Again suspend all tasks (only the low priority task is not suspended
+ * already). */
+ vTaskSuspend( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
+
+ /* This time we are going to suspend the scheduler, resume the low
+ * priority task, then resume the high priority task. In this state we
+ * will write to the queue three times. When the scheduler is resumed
+ * we expect the high priority task to service all three messages. */
+ vTaskSuspendAll();
+ {
+ vTaskResume( xCreatedTasks[ evtLOWEST_PRIORITY_INDEX ] );
+ vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_1 ] );
+
+ for( xDummy = 0; xDummy < evtQUEUE_LENGTH; xDummy++ )
+ {
+ if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
+ {
+ xHealthStatus = pdFAIL;
+ }
+ }
+
+ /* The queue should not have been serviced yet!. The scheduler
+ * is still suspended. */
+ if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
+ {
+ xHealthStatus = pdFAIL;
+ }
+ }
+ xTaskResumeAll();
+
+ /* We should have been preempted by resuming the scheduler - so by the
+ * time we are running again we expect the high priority task to have
+ * removed three items from the queue. */
+ xExpectedTaskCounters[ evtHIGHEST_PRIORITY_INDEX_1 ] += evtQUEUE_LENGTH;
+
+ if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
+ {
+ xHealthStatus = pdFAIL;
+ }
+
+ /* The medium priority and second high priority tasks are still
+ * suspended. Make sure to resume them before starting again. */
+ vTaskResume( xCreatedTasks[ evtMEDIUM_PRIORITY_INDEX ] );
+ vTaskResume( xCreatedTasks[ evtHIGHEST_PRIORITY_INDEX_2 ] );
+
+ /* Just keep incrementing to show the task is still executing. */
+ xCheckVariable++;
+ }
}
/*-----------------------------------------------------------*/
-static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask, portBASE_TYPE xIncrement )
+static void prvCheckTaskCounters( portBASE_TYPE xExpectedTask,
+ portBASE_TYPE xIncrement )
{
-portBASE_TYPE xDummy = 0;
-
- /* Write to the queue the requested number of times. The data written is
- not important. */
- for( xDummy = 0; xDummy < xIncrement; xDummy++ )
- {
- if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
- {
- /* Did not expect to ever find the queue full. */
- xHealthStatus = pdFAIL;
- }
- }
-
- /* All the tasks blocked on the queue have a priority higher than the
- controlling task. Writing to the queue will therefore have caused this
- task to be preempted. By the time this line executes the event task will
- have executed and incremented its counter. Increment the expected counter
- to the same value. */
- ( xExpectedTaskCounters[ xExpectedTask ] ) += xIncrement;
-
- /* Check the actual counts and expected counts really are the same. */
- if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
- {
- /* The counters were not the same. This means a task we did not expect
- to unblock actually did unblock. */
- xHealthStatus = pdFAIL;
- }
+ portBASE_TYPE xDummy = 0;
+
+ /* Write to the queue the requested number of times. The data written is
+ * not important. */
+ for( xDummy = 0; xDummy < xIncrement; xDummy++ )
+ {
+ if( xQueueSend( xQueue, &xDummy, evtNO_DELAY ) != pdTRUE )
+ {
+ /* Did not expect to ever find the queue full. */
+ xHealthStatus = pdFAIL;
+ }
+ }
+
+ /* All the tasks blocked on the queue have a priority higher than the
+ * controlling task. Writing to the queue will therefore have caused this
+ * task to be preempted. By the time this line executes the event task will
+ * have executed and incremented its counter. Increment the expected counter
+ * to the same value. */
+ ( xExpectedTaskCounters[ xExpectedTask ] ) += xIncrement;
+
+ /* Check the actual counts and expected counts really are the same. */
+ if( memcmp( ( void * ) xExpectedTaskCounters, ( void * ) xTaskCounters, sizeof( xExpectedTaskCounters ) ) )
+ {
+ /* The counters were not the same. This means a task we did not expect
+ * to unblock actually did unblock. */
+ xHealthStatus = pdFAIL;
+ }
}
/*-----------------------------------------------------------*/
portBASE_TYPE xAreMultiEventTasksStillRunning( void )
{
-static portBASE_TYPE xPreviousCheckVariable = 0;
-
- /* Called externally to periodically check that this test is still
- operational. */
-
- if( xPreviousCheckVariable == xCheckVariable )
- {
- xHealthStatus = pdFAIL;
- }
-
- xPreviousCheckVariable = xCheckVariable;
-
- return xHealthStatus;
-}
+ static portBASE_TYPE xPreviousCheckVariable = 0;
+ /* Called externally to periodically check that this test is still
+ * operational. */
+ if( xPreviousCheckVariable == xCheckVariable )
+ {
+ xHealthStatus = pdFAIL;
+ }
+
+ xPreviousCheckVariable = xCheckVariable;
+
+ return xHealthStatus;
+}
diff --git a/FreeRTOS/Demo/Common/Full/flash.c b/FreeRTOS/Demo/Common/Full/flash.c
index 67f3137f7..0b9686f75 100644
--- a/FreeRTOS/Demo/Common/Full/flash.c
+++ b/FreeRTOS/Demo/Common/Full/flash.c
@@ -27,13 +27,13 @@
/**
- * Creates eight tasks, each of which flash an LED at a different rate. The first
+ * Creates eight tasks, each of which flash an LED at a different rate. The first
* LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.
*
- * The LED flash tasks provide instant visual feedback. They show that the scheduler
+ * The LED flash tasks provide instant visual feedback. They show that the scheduler
* is still operational.
*
- * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
+ * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
* uses IO port F.
*
* \page flashC flash.c
@@ -42,16 +42,16 @@
*/
/*
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
-
-Changes from V2.1.1
-
- + The stack size now uses configMINIMAL_STACK_SIZE.
- + String constants made file scope to decrease stack depth on 8051 port.
-*/
+ * Changes from V2.0.0
+ *
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ +
+ + Changes from V2.1.1
+ +
+ + The stack size now uses configMINIMAL_STACK_SIZE.
+ + String constants made file scope to decrease stack depth on 8051 port.
+ */
#include <stdlib.h>
@@ -64,18 +64,18 @@ Changes from V2.1.1
#include "flash.h"
#include "print.h"
-#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
+#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
/* Structure used to pass parameters to the LED tasks. */
typedef struct LED_PARAMETERS
{
- unsigned portBASE_TYPE uxLED; /*< The output the task should use. */
- TickType_t xFlashRate; /*< The rate at which the LED should flash. */
+ unsigned portBASE_TYPE uxLED; /*< The output the task should use. */
+ TickType_t xFlashRate; /*< The rate at which the LED should flash. */
} xLEDParameters;
-/* The task that is created eight times - each time with a different xLEDParaemtes
-structure passed in as the parameter. */
-static void vLEDFlashTask( void *pvParameters );
+/* The task that is created eight times - each time with a different xLEDParaemtes
+ * structure passed in as the parameter. */
+static void vLEDFlashTask( void * pvParameters );
/* String to print if USE_STDIO is defined. */
const char * const pcTaskStartMsg = "LED flash task started.\r\n";
@@ -84,45 +84,44 @@ const char * const pcTaskStartMsg = "LED flash task started.\r\n";
void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
{
-unsigned portBASE_TYPE uxLEDTask;
-xLEDParameters *pxLEDParameters;
-const unsigned portBASE_TYPE uxNumOfLEDs = 8;
-const TickType_t xFlashRate = 125;
-
- /* Create the eight tasks. */
- for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
- {
- /* Create and complete the structure used to pass parameters to the next
- created task. */
- pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
- pxLEDParameters->uxLED = uxLEDTask;
- pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( TickType_t ) uxLEDTask ) );
- pxLEDParameters->xFlashRate /= portTICK_PERIOD_MS;
-
- /* Spawn the task. */
- xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( TaskHandle_t * ) NULL );
- }
+ unsigned portBASE_TYPE uxLEDTask;
+ xLEDParameters * pxLEDParameters;
+ const unsigned portBASE_TYPE uxNumOfLEDs = 8;
+ const TickType_t xFlashRate = 125;
+
+ /* Create the eight tasks. */
+ for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
+ {
+ /* Create and complete the structure used to pass parameters to the next
+ * created task. */
+ pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
+ pxLEDParameters->uxLED = uxLEDTask;
+ pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( TickType_t ) uxLEDTask ) );
+ pxLEDParameters->xFlashRate /= portTICK_PERIOD_MS;
+
+ /* Spawn the task. */
+ xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( TaskHandle_t * ) NULL );
+ }
}
/*-----------------------------------------------------------*/
-static void vLEDFlashTask( void *pvParameters )
+static void vLEDFlashTask( void * pvParameters )
{
-xLEDParameters *pxParameters;
+ xLEDParameters * pxParameters;
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
- pxParameters = ( xLEDParameters * ) pvParameters;
+ pxParameters = ( xLEDParameters * ) pvParameters;
- for(;;)
- {
- /* Delay for half the flash period then turn the LED on. */
- vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
- vParTestToggleLED( pxParameters->uxLED );
+ for( ; ; )
+ {
+ /* Delay for half the flash period then turn the LED on. */
+ vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
+ vParTestToggleLED( pxParameters->uxLED );
- /* Delay for half the flash period then turn the LED off. */
- vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
- vParTestToggleLED( pxParameters->uxLED );
- }
+ /* Delay for half the flash period then turn the LED off. */
+ vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
+ vParTestToggleLED( pxParameters->uxLED );
+ }
}
-
diff --git a/FreeRTOS/Demo/Common/Full/flop.c b/FreeRTOS/Demo/Common/Full/flop.c
index 95a105efc..57cfabfce 100644
--- a/FreeRTOS/Demo/Common/Full/flop.c
+++ b/FreeRTOS/Demo/Common/Full/flop.c
@@ -26,22 +26,22 @@
*/
/*
-Changes from V1.2.3
-
- + The created tasks now include calls to tskYIELD(), allowing them to be used
- with the cooperative scheduler.
-*/
+ * Changes from V1.2.3
+ *
+ + The created tasks now include calls to tskYIELD(), allowing them to be used
+ + with the cooperative scheduler.
+ */
/**
- * Creates eight tasks, each of which loops continuously performing an (emulated)
+ * Creates eight tasks, each of which loops continuously performing an (emulated)
* floating point calculation.
*
- * All the tasks run at the idle priority and never block or yield. This causes
- * all eight tasks to time slice with the idle task. Running at the idle priority
+ * All the tasks run at the idle priority and never block or yield. This causes
+ * all eight tasks to time slice with the idle task. Running at the idle priority
* means that these tasks will get pre-empted any time another task is ready to run
- * or a time slice occurs. More often than not the pre-emption will occur mid
- * calculation, creating a good test of the schedulers context switch mechanism - a
- * calculation producing an unexpected result could be a symptom of a corruption in
+ * or a time slice occurs. More often than not the pre-emption will occur mid
+ * calculation, creating a good test of the schedulers context switch mechanism - a
+ * calculation producing an unexpected result could be a symptom of a corruption in
* the context of a task.
*
* \page FlopC flop.c
@@ -60,272 +60,271 @@ Changes from V1.2.3
/* Demo program include files. */
#include "flop.h"
-#define mathSTACK_SIZE ( ( unsigned short ) 512 )
-#define mathNUMBER_OF_TASKS ( 8 )
+#define mathSTACK_SIZE ( ( unsigned short ) 512 )
+#define mathNUMBER_OF_TASKS ( 8 )
-/* Four tasks, each of which performs a different floating point calculation.
-Each of the four is created twice. */
-static void vCompetingMathTask1( void *pvParameters );
-static void vCompetingMathTask2( void *pvParameters );
-static void vCompetingMathTask3( void *pvParameters );
-static void vCompetingMathTask4( void *pvParameters );
+/* Four tasks, each of which performs a different floating point calculation.
+ * Each of the four is created twice. */
+static void vCompetingMathTask1( void * pvParameters );
+static void vCompetingMathTask2( void * pvParameters );
+static void vCompetingMathTask3( void * pvParameters );
+static void vCompetingMathTask4( void * pvParameters );
-/* These variables are used to check that all the tasks are still running. If a
-task gets a calculation wrong it will
-stop incrementing its check variable. */
+/* These variables are used to check that all the tasks are still running. If a
+ * task gets a calculation wrong it will
+ * stop incrementing its check variable. */
static volatile unsigned short usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
/*-----------------------------------------------------------*/
void vStartMathTasks( unsigned portBASE_TYPE uxPriority )
{
- xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
-static void vCompetingMathTask1( void *pvParameters )
+static void vCompetingMathTask1( void * pvParameters )
{
-portDOUBLE d1, d2, d3, d4;
-volatile unsigned short *pusTaskCheckVariable;
-const portDOUBLE dAnswer = ( 123.4567 + 2345.6789 ) * -918.222;
-const char * const pcTaskStartMsg = "Math task 1 started.\r\n";
-const char * const pcTaskFailMsg = "Math task 1 failed.\r\n";
-short sError = pdFALSE;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for(;;)
- {
- d1 = 123.4567;
- d2 = 2345.6789;
- d3 = -918.222;
-
- d4 = ( d1 + d2 ) * d3;
-
- taskYIELD();
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( fabs( d4 - dAnswer ) > 0.001 )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
-
- taskYIELD();
- }
+ portDOUBLE d1, d2, d3, d4;
+ volatile unsigned short * pusTaskCheckVariable;
+ const portDOUBLE dAnswer = ( 123.4567 + 2345.6789 ) * -918.222;
+ const char * const pcTaskStartMsg = "Math task 1 started.\r\n";
+ const char * const pcTaskFailMsg = "Math task 1 failed.\r\n";
+ short sError = pdFALSE;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ d1 = 123.4567;
+ d2 = 2345.6789;
+ d3 = -918.222;
+
+ d4 = ( d1 + d2 ) * d3;
+
+ taskYIELD();
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( fabs( d4 - dAnswer ) > 0.001 )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+
+ taskYIELD();
+ }
}
/*-----------------------------------------------------------*/
-static void vCompetingMathTask2( void *pvParameters )
+static void vCompetingMathTask2( void * pvParameters )
{
-portDOUBLE d1, d2, d3, d4;
-volatile unsigned short *pusTaskCheckVariable;
-const portDOUBLE dAnswer = ( -389.38 / 32498.2 ) * -2.0001;
-const char * const pcTaskStartMsg = "Math task 2 started.\r\n";
-const char * const pcTaskFailMsg = "Math task 2 failed.\r\n";
-short sError = pdFALSE;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for( ;; )
- {
- d1 = -389.38;
- d2 = 32498.2;
- d3 = -2.0001;
-
- d4 = ( d1 / d2 ) * d3;
-
- taskYIELD();
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( fabs( d4 - dAnswer ) > 0.001 )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know
- this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
-
- taskYIELD();
- }
+ portDOUBLE d1, d2, d3, d4;
+ volatile unsigned short * pusTaskCheckVariable;
+ const portDOUBLE dAnswer = ( -389.38 / 32498.2 ) * -2.0001;
+ const char * const pcTaskStartMsg = "Math task 2 started.\r\n";
+ const char * const pcTaskFailMsg = "Math task 2 failed.\r\n";
+ short sError = pdFALSE;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ d1 = -389.38;
+ d2 = 32498.2;
+ d3 = -2.0001;
+
+ d4 = ( d1 / d2 ) * d3;
+
+ taskYIELD();
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( fabs( d4 - dAnswer ) > 0.001 )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know
+ * this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+
+ taskYIELD();
+ }
}
/*-----------------------------------------------------------*/
-static void vCompetingMathTask3( void *pvParameters )
+static void vCompetingMathTask3( void * pvParameters )
{
-portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
-volatile unsigned short *pusTaskCheckVariable;
-const unsigned short usArraySize = 250;
-unsigned short usPosition;
-const char * const pcTaskStartMsg = "Math task 3 started.\r\n";
-const char * const pcTaskFailMsg = "Math task 3 failed.\r\n";
-short sError = pdFALSE;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
-
- /* Keep filling an array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- dTotal1 = 0.0;
- dTotal2 = 0.0;
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- pdArray[ usPosition ] = ( portDOUBLE ) usPosition + 5.5;
- dTotal1 += ( portDOUBLE ) usPosition + 5.5;
- }
-
- taskYIELD();
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- dTotal2 += pdArray[ usPosition ];
- }
-
- dDifference = dTotal1 - dTotal2;
- if( fabs( dDifference ) > 0.001 )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- taskYIELD();
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
+ volatile unsigned short * pusTaskCheckVariable;
+ const unsigned short usArraySize = 250;
+ unsigned short usPosition;
+ const char * const pcTaskStartMsg = "Math task 3 started.\r\n";
+ const char * const pcTaskFailMsg = "Math task 3 failed.\r\n";
+ short sError = pdFALSE;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
+
+ /* Keep filling an array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ dTotal1 = 0.0;
+ dTotal2 = 0.0;
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ pdArray[ usPosition ] = ( portDOUBLE ) usPosition + 5.5;
+ dTotal1 += ( portDOUBLE ) usPosition + 5.5;
+ }
+
+ taskYIELD();
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ dTotal2 += pdArray[ usPosition ];
+ }
+
+ dDifference = dTotal1 - dTotal2;
+
+ if( fabs( dDifference ) > 0.001 )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ taskYIELD();
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void vCompetingMathTask4( void *pvParameters )
+static void vCompetingMathTask4( void * pvParameters )
{
-portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
-volatile unsigned short *pusTaskCheckVariable;
-const unsigned short usArraySize = 250;
-unsigned short usPosition;
-const char * const pcTaskStartMsg = "Math task 4 started.\r\n";
-const char * const pcTaskFailMsg = "Math task 4 failed.\r\n";
-short sError = pdFALSE;
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
-
- /* Keep filling an array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- dTotal1 = 0.0;
- dTotal2 = 0.0;
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- pdArray[ usPosition ] = ( portDOUBLE ) usPosition * 12.123;
- dTotal1 += ( portDOUBLE ) usPosition * 12.123;
- }
-
- taskYIELD();
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- dTotal2 += pdArray[ usPosition ];
- }
-
- dDifference = dTotal1 - dTotal2;
- if( fabs( dDifference ) > 0.001 )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- taskYIELD();
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
+ volatile unsigned short * pusTaskCheckVariable;
+ const unsigned short usArraySize = 250;
+ unsigned short usPosition;
+ const char * const pcTaskStartMsg = "Math task 4 started.\r\n";
+ const char * const pcTaskFailMsg = "Math task 4 failed.\r\n";
+ short sError = pdFALSE;
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ pdArray = ( portDOUBLE * ) pvPortMalloc( ( size_t ) 250 * sizeof( portDOUBLE ) );
+
+ /* Keep filling an array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ dTotal1 = 0.0;
+ dTotal2 = 0.0;
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ pdArray[ usPosition ] = ( portDOUBLE ) usPosition * 12.123;
+ dTotal1 += ( portDOUBLE ) usPosition * 12.123;
+ }
+
+ taskYIELD();
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ dTotal2 += pdArray[ usPosition ];
+ }
+
+ dDifference = dTotal1 - dTotal2;
+
+ if( fabs( dDifference ) > 0.001 )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ taskYIELD();
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
portBASE_TYPE xAreMathsTaskStillRunning( void )
{
-/* Keep a history of the check variables so we know if they have been incremented
-since the last call. */
-static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
-portBASE_TYPE xReturn = pdTRUE, xTask;
-
- /* Check the maths tasks are still running by ensuring their check variables
- are still incrementing. */
- for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
- {
- if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
- {
- /* The check has not incremented so an error exists. */
- xReturn = pdFALSE;
- }
-
- usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
- }
-
- return xReturn;
+/* Keep a history of the check variables so we know if they have been incremented
+ * since the last call. */
+ static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
+ portBASE_TYPE xReturn = pdTRUE, xTask;
+
+ /* Check the maths tasks are still running by ensuring their check variables
+ * are still incrementing. */
+ for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
+ {
+ if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
+ {
+ /* The check has not incremented so an error exists. */
+ xReturn = pdFALSE;
+ }
+
+ usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
+ }
+
+ return xReturn;
}
-
-
-
diff --git a/FreeRTOS/Demo/Common/Full/integer.c b/FreeRTOS/Demo/Common/Full/integer.c
index f96b29f9a..a6012ef40 100644
--- a/FreeRTOS/Demo/Common/Full/integer.c
+++ b/FreeRTOS/Demo/Common/Full/integer.c
@@ -26,21 +26,21 @@
*/
/*
-Changes from V1.2.3
-
- + The created tasks now include calls to tskYIELD(), allowing them to be used
- with the cooperative scheduler.
-*/
+ * Changes from V1.2.3
+ *
+ + The created tasks now include calls to tskYIELD(), allowing them to be used
+ + with the cooperative scheduler.
+ */
/**
- * This does the same as flop. c, but uses variables of type long instead of
- * type double.
+ * This does the same as flop. c, but uses variables of type long instead of
+ * type double.
*
- * As with flop. c, the tasks created in this file are a good test of the
- * scheduler context switch mechanism. The processor has to access 32bit
- * variables in two or four chunks (depending on the processor). The low
- * priority of these tasks means there is a high probability that a context
- * switch will occur mid calculation. See the flop. c documentation for
+ * As with flop. c, the tasks created in this file are a good test of the
+ * scheduler context switch mechanism. The processor has to access 32bit
+ * variables in two or four chunks (depending on the processor). The low
+ * priority of these tasks means there is a high probability that a context
+ * switch will occur mid calculation. See the flop. c documentation for
* more information.
*
* \page IntegerC integer.c
@@ -49,11 +49,11 @@ Changes from V1.2.3
*/
/*
-Changes from V1.2.1
-
- + The constants used in the calculations are larger to ensure the
- optimiser does not truncate them to 16 bits.
-*/
+ * Changes from V1.2.1
+ *
+ + The constants used in the calculations are larger to ensure the
+ + optimiser does not truncate them to 16 bits.
+ */
#include <stdlib.h>
@@ -65,263 +65,262 @@ Changes from V1.2.1
/* Demo program include files. */
#include "integer.h"
-#define intgSTACK_SIZE ( ( unsigned short ) 256 )
-#define intgNUMBER_OF_TASKS ( 8 )
+#define intgSTACK_SIZE ( ( unsigned short ) 256 )
+#define intgNUMBER_OF_TASKS ( 8 )
-/* Four tasks, each of which performs a different calculation on four byte
-variables. Each of the four is created twice. */
-static void vCompeteingIntMathTask1( void *pvParameters );
-static void vCompeteingIntMathTask2( void *pvParameters );
-static void vCompeteingIntMathTask3( void *pvParameters );
-static void vCompeteingIntMathTask4( void *pvParameters );
+/* Four tasks, each of which performs a different calculation on four byte
+ * variables. Each of the four is created twice. */
+static void vCompeteingIntMathTask1( void * pvParameters );
+static void vCompeteingIntMathTask2( void * pvParameters );
+static void vCompeteingIntMathTask3( void * pvParameters );
+static void vCompeteingIntMathTask4( void * pvParameters );
-/* These variables are used to check that all the tasks are still running. If a
-task gets a calculation wrong it will stop incrementing its check variable. */
+/* These variables are used to check that all the tasks are still running. If a
+* task gets a calculation wrong it will stop incrementing its check variable. */
static volatile unsigned short usTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
/*-----------------------------------------------------------*/
void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
{
- xTaskCreate( vCompeteingIntMathTask1, "IntMath1", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
- xTaskCreate( vCompeteingIntMathTask2, "IntMath2", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
- xTaskCreate( vCompeteingIntMathTask3, "IntMath3", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
- xTaskCreate( vCompeteingIntMathTask4, "IntMath4", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
- xTaskCreate( vCompeteingIntMathTask1, "IntMath5", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
- xTaskCreate( vCompeteingIntMathTask2, "IntMath6", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
- xTaskCreate( vCompeteingIntMathTask3, "IntMath7", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
- xTaskCreate( vCompeteingIntMathTask4, "IntMath8", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask1, "IntMath1", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask2, "IntMath2", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask3, "IntMath3", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask4, "IntMath4", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask1, "IntMath5", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask2, "IntMath6", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask3, "IntMath7", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
+ xTaskCreate( vCompeteingIntMathTask4, "IntMath8", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
-static void vCompeteingIntMathTask1( void *pvParameters )
+static void vCompeteingIntMathTask1( void * pvParameters )
{
-long l1, l2, l3, l4;
-short sError = pdFALSE;
-volatile unsigned short *pusTaskCheckVariable;
-const long lAnswer = ( ( long ) 74565L + ( long ) 1234567L ) * ( long ) -918L;
-const char * const pcTaskStartMsg = "Integer math task 1 started.\r\n";
-const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for(;;)
- {
- l1 = ( long ) 74565L;
- l2 = ( long ) 1234567L;
- l3 = ( long ) -918L;
-
- l4 = ( l1 + l2 ) * l3;
-
- taskYIELD();
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( l4 != lAnswer )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ long l1, l2, l3, l4;
+ short sError = pdFALSE;
+ volatile unsigned short * pusTaskCheckVariable;
+ const long lAnswer = ( ( long ) 74565L + ( long ) 1234567L ) * ( long ) -918L;
+ const char * const pcTaskStartMsg = "Integer math task 1 started.\r\n";
+ const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ l1 = ( long ) 74565L;
+ l2 = ( long ) 1234567L;
+ l3 = ( long ) -918L;
+
+ l4 = ( l1 + l2 ) * l3;
+
+ taskYIELD();
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( l4 != lAnswer )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void vCompeteingIntMathTask2( void *pvParameters )
+static void vCompeteingIntMathTask2( void * pvParameters )
{
-long l1, l2, l3, l4;
-short sError = pdFALSE;
-volatile unsigned short *pusTaskCheckVariable;
-const long lAnswer = ( ( long ) -389000L / ( long ) 329999L ) * ( long ) -89L;
-const char * const pcTaskStartMsg = "Integer math task 2 started.\r\n";
-const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for( ;; )
- {
- l1 = -389000L;
- l2 = 329999L;
- l3 = -89L;
-
- l4 = ( l1 / l2 ) * l3;
-
- taskYIELD();
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( l4 != lAnswer )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ long l1, l2, l3, l4;
+ short sError = pdFALSE;
+ volatile unsigned short * pusTaskCheckVariable;
+ const long lAnswer = ( ( long ) -389000L / ( long ) 329999L ) * ( long ) -89L;
+ const char * const pcTaskStartMsg = "Integer math task 2 started.\r\n";
+ const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ l1 = -389000L;
+ l2 = 329999L;
+ l3 = -89L;
+
+ l4 = ( l1 / l2 ) * l3;
+
+ taskYIELD();
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( l4 != lAnswer )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void vCompeteingIntMathTask3( void *pvParameters )
+static void vCompeteingIntMathTask3( void * pvParameters )
{
-long *plArray, lTotal1, lTotal2;
-short sError = pdFALSE;
-volatile unsigned short *pusTaskCheckVariable;
-const unsigned short usArraySize = ( unsigned short ) 250;
-unsigned short usPosition;
-const char * const pcTaskStartMsg = "Integer math task 3 started.\r\n";
-const char * const pcTaskFailMsg = "Integer math task 3 failed.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- /* Create the array we are going to use for our check calculation. */
- plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
-
- /* Keep filling the array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- lTotal1 = ( long ) 0;
- lTotal2 = ( long ) 0;
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- plArray[ usPosition ] = ( long ) usPosition + ( long ) 5;
- lTotal1 += ( long ) usPosition + ( long ) 5;
- }
-
- taskYIELD();
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- lTotal2 += plArray[ usPosition ];
- }
-
- if( lTotal1 != lTotal2 )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- taskYIELD();
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ long * plArray, lTotal1, lTotal2;
+ short sError = pdFALSE;
+ volatile unsigned short * pusTaskCheckVariable;
+ const unsigned short usArraySize = ( unsigned short ) 250;
+ unsigned short usPosition;
+ const char * const pcTaskStartMsg = "Integer math task 3 started.\r\n";
+ const char * const pcTaskFailMsg = "Integer math task 3 failed.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ /* Create the array we are going to use for our check calculation. */
+ plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
+
+ /* Keep filling the array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ lTotal1 = ( long ) 0;
+ lTotal2 = ( long ) 0;
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ plArray[ usPosition ] = ( long ) usPosition + ( long ) 5;
+ lTotal1 += ( long ) usPosition + ( long ) 5;
+ }
+
+ taskYIELD();
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ lTotal2 += plArray[ usPosition ];
+ }
+
+ if( lTotal1 != lTotal2 )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ taskYIELD();
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void vCompeteingIntMathTask4( void *pvParameters )
+static void vCompeteingIntMathTask4( void * pvParameters )
{
-long *plArray, lTotal1, lTotal2;
-short sError = pdFALSE;
-volatile unsigned short *pusTaskCheckVariable;
-const unsigned short usArraySize = 250;
-unsigned short usPosition;
-const char * const pcTaskStartMsg = "Integer math task 4 started.\r\n";
-const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( unsigned short * ) pvParameters;
-
- /* Create the array we are going to use for our check calculation. */
- plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
-
- /* Keep filling the array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- lTotal1 = ( long ) 0;
- lTotal2 = ( long ) 0;
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- plArray[ usPosition ] = ( long ) usPosition * ( long ) 12;
- lTotal1 += ( long ) usPosition * ( long ) 12;
- }
-
- taskYIELD();
-
- for( usPosition = 0; usPosition < usArraySize; usPosition++ )
- {
- lTotal2 += plArray[ usPosition ];
- }
-
-
- if( lTotal1 != lTotal2 )
- {
- vPrintDisplayMessage( &pcTaskFailMsg );
- sError = pdTRUE;
- }
-
- taskYIELD();
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ long * plArray, lTotal1, lTotal2;
+ short sError = pdFALSE;
+ volatile unsigned short * pusTaskCheckVariable;
+ const unsigned short usArraySize = 250;
+ unsigned short usPosition;
+ const char * const pcTaskStartMsg = "Integer math task 4 started.\r\n";
+ const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( unsigned short * ) pvParameters;
+
+ /* Create the array we are going to use for our check calculation. */
+ plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
+
+ /* Keep filling the array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ lTotal1 = ( long ) 0;
+ lTotal2 = ( long ) 0;
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ plArray[ usPosition ] = ( long ) usPosition * ( long ) 12;
+ lTotal1 += ( long ) usPosition * ( long ) 12;
+ }
+
+ taskYIELD();
+
+ for( usPosition = 0; usPosition < usArraySize; usPosition++ )
+ {
+ lTotal2 += plArray[ usPosition ];
+ }
+
+ if( lTotal1 != lTotal2 )
+ {
+ vPrintDisplayMessage( &pcTaskFailMsg );
+ sError = pdTRUE;
+ }
+
+ taskYIELD();
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
{
-/* Keep a history of the check variables so we know if they have been incremented
-since the last call. */
-static unsigned short usLastTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
-portBASE_TYPE xReturn = pdTRUE, xTask;
-
- /* Check the maths tasks are still running by ensuring their check variables
- are still incrementing. */
- for( xTask = 0; xTask < intgNUMBER_OF_TASKS; xTask++ )
- {
- if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
- {
- /* The check has not incremented so an error exists. */
- xReturn = pdFALSE;
- }
-
- usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
- }
-
- return xReturn;
+/* Keep a history of the check variables so we know if they have been incremented
+ * since the last call. */
+ static unsigned short usLastTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
+ portBASE_TYPE xReturn = pdTRUE, xTask;
+
+ /* Check the maths tasks are still running by ensuring their check variables
+ * are still incrementing. */
+ for( xTask = 0; xTask < intgNUMBER_OF_TASKS; xTask++ )
+ {
+ if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
+ {
+ /* The check has not incremented so an error exists. */
+ xReturn = pdFALSE;
+ }
+
+ usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
+ }
+
+ return xReturn;
}
diff --git a/FreeRTOS/Demo/Common/Full/print.c b/FreeRTOS/Demo/Common/Full/print.c
index 3ba942d45..dac0cdc9b 100644
--- a/FreeRTOS/Demo/Common/Full/print.c
+++ b/FreeRTOS/Demo/Common/Full/print.c
@@ -26,22 +26,22 @@
*/
/**
- * Manages a queue of strings that are waiting to be displayed. This is used to
+ * Manages a queue of strings that are waiting to be displayed. This is used to
* ensure mutual exclusion of console output.
*
- * A task wishing to display a message will call vPrintDisplayMessage (), with a
- * pointer to the string as the parameter. The pointer is posted onto the
+ * A task wishing to display a message will call vPrintDisplayMessage (), with a
+ * pointer to the string as the parameter. The pointer is posted onto the
* xPrintQueue queue.
*
- * The task spawned in main. c blocks on xPrintQueue. When a message becomes
- * available it calls pcPrintGetNextMessage () to obtain a pointer to the next
- * string, then uses the functions defined in the portable layer FileIO. c to
+ * The task spawned in main. c blocks on xPrintQueue. When a message becomes
+ * available it calls pcPrintGetNextMessage () to obtain a pointer to the next
+ * string, then uses the functions defined in the portable layer FileIO. c to
* display the message.
*
* <b>NOTE:</b>
- * Using console IO can disrupt real time performance - depending on the port.
- * Standard C IO routines are not designed for real time applications. While
- * standard IO is useful for demonstration and debugging an alternative method
+ * Using console IO can disrupt real time performance - depending on the port.
+ * Standard C IO routines are not designed for real time applications. While
+ * standard IO is useful for demonstration and debugging an alternative method
* should be used if you actually require console IO as part of your application.
*
* \page PrintC print.c
@@ -50,11 +50,11 @@
*/
/*
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
-*/
+ * Changes from V2.0.0
+ *
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ */
#include <stdlib.h>
@@ -71,36 +71,34 @@ static QueueHandle_t xPrintQueue;
void vPrintInitialise( void )
{
-const unsigned portBASE_TYPE uxQueueSize = 20;
+ const unsigned portBASE_TYPE uxQueueSize = 20;
- /* Create the queue on which errors will be reported. */
- xPrintQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( char * ) );
+ /* Create the queue on which errors will be reported. */
+ xPrintQueue = xQueueCreate( uxQueueSize, ( unsigned portBASE_TYPE ) sizeof( char * ) );
}
/*-----------------------------------------------------------*/
void vPrintDisplayMessage( const char * const * ppcMessageToSend )
{
- #ifdef USE_STDIO
- xQueueSend( xPrintQueue, ( void * ) ppcMessageToSend, ( TickType_t ) 0 );
- #else
- /* Stop warnings. */
- ( void ) ppcMessageToSend;
- #endif
+ #ifdef USE_STDIO
+ xQueueSend( xPrintQueue, ( void * ) ppcMessageToSend, ( TickType_t ) 0 );
+ #else
+ /* Stop warnings. */
+ ( void ) ppcMessageToSend;
+ #endif
}
/*-----------------------------------------------------------*/
-const char *pcPrintGetNextMessage( TickType_t xPrintRate )
+const char * pcPrintGetNextMessage( TickType_t xPrintRate )
{
-char *pcMessage;
+ char * pcMessage;
- if( xQueueReceive( xPrintQueue, &pcMessage, xPrintRate ) == pdPASS )
- {
- return pcMessage;
- }
- else
- {
- return NULL;
- }
+ if( xQueueReceive( xPrintQueue, &pcMessage, xPrintRate ) == pdPASS )
+ {
+ return pcMessage;
+ }
+ else
+ {
+ return NULL;
+ }
}
-
-
diff --git a/FreeRTOS/Demo/Common/Full/semtest.c b/FreeRTOS/Demo/Common/Full/semtest.c
index b8100ee26..b9d090cd4 100644
--- a/FreeRTOS/Demo/Common/Full/semtest.c
+++ b/FreeRTOS/Demo/Common/Full/semtest.c
@@ -26,24 +26,24 @@
*/
/**
- * Creates two sets of two tasks. The tasks within a set share a variable, access
+ * Creates two sets of two tasks. The tasks within a set share a variable, access
* to which is guarded by a semaphore.
- *
- * Each task starts by attempting to obtain the semaphore. On obtaining a
- * semaphore a task checks to ensure that the guarded variable has an expected
- * value. It then clears the variable to zero before counting it back up to the
- * expected value in increments of 1. After each increment the variable is checked
- * to ensure it contains the value to which it was just set. When the starting
- * value is again reached the task releases the semaphore giving the other task in
- * the set a chance to do exactly the same thing. The starting value is high
+ *
+ * Each task starts by attempting to obtain the semaphore. On obtaining a
+ * semaphore a task checks to ensure that the guarded variable has an expected
+ * value. It then clears the variable to zero before counting it back up to the
+ * expected value in increments of 1. After each increment the variable is checked
+ * to ensure it contains the value to which it was just set. When the starting
+ * value is again reached the task releases the semaphore giving the other task in
+ * the set a chance to do exactly the same thing. The starting value is high
* enough to ensure that a tick is likely to occur during the incrementing loop.
*
- * An error is flagged if at any time during the process a shared variable is
- * found to have a value other than that expected. Such an occurrence would
- * suggest an error in the mutual exclusion mechanism by which access to the
+ * An error is flagged if at any time during the process a shared variable is
+ * found to have a value other than that expected. Such an occurrence would
+ * suggest an error in the mutual exclusion mechanism by which access to the
* variable is restricted.
*
- * The first set of two tasks poll their semaphore. The second set use blocking
+ * The first set of two tasks poll their semaphore. The second set use blocking
* calls.
*
* \page SemTestC semtest.c
@@ -52,24 +52,24 @@
*/
/*
-Changes from V1.2.0:
-
- + The tasks that operate at the idle priority now use a lower expected
- count than those running at a higher priority. This prevents the low
- priority tasks from signaling an error because they have not been
- scheduled enough time for each of them to count the shared variable to
- the high value.
-
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than unsigned long.
-
-Changes from V2.1.1
-
- + The stack size now uses configMINIMAL_STACK_SIZE.
- + String constants made file scope to decrease stack depth on 8051 port.
-*/
+ * Changes from V1.2.0:
+ *
+ + The tasks that operate at the idle priority now use a lower expected
+ + count than those running at a higher priority. This prevents the low
+ + priority tasks from signaling an error because they have not been
+ + scheduled enough time for each of them to count the shared variable to
+ + the high value.
+ +
+ + Changes from V2.0.0
+ +
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than unsigned long.
+ +
+ + Changes from V2.1.1
+ +
+ + The stack size now uses configMINIMAL_STACK_SIZE.
+ + String constants made file scope to decrease stack depth on 8051 port.
+ */
#include <stdlib.h>
@@ -83,24 +83,24 @@ Changes from V2.1.1
#include "print.h"
/* The value to which the shared variables are counted. */
-#define semtstBLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xfff )
-#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xff )
+#define semtstBLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xfff )
+#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( unsigned long ) 0xff )
-#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
+#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
-#define semtstNUM_TASKS ( 4 )
+#define semtstNUM_TASKS ( 4 )
-#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
+#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
/* The task function as described at the top of the file. */
-static void prvSemaphoreTest( void *pvParameters );
+static void prvSemaphoreTest( void * pvParameters );
/* Structure used to pass parameters to each task. */
typedef struct SEMAPHORE_PARAMETERS
{
- SemaphoreHandle_t xSemaphore;
- volatile unsigned long *pulSharedVariable;
- TickType_t xBlockTime;
+ SemaphoreHandle_t xSemaphore;
+ volatile unsigned long * pulSharedVariable;
+ TickType_t xBlockTime;
} xSemaphoreParameters;
/* Variables used to check that all the tasks are still running without errors. */
@@ -115,171 +115,172 @@ const char * const pcSemaphoreTaskStart = "Guarded shared variable task started.
void vStartSemaphoreTasks( unsigned portBASE_TYPE uxPriority )
{
-xSemaphoreParameters *pxFirstSemaphoreParameters, *pxSecondSemaphoreParameters;
-const TickType_t xBlockTime = ( TickType_t ) 100;
-
- /* Create the structure used to pass parameters to the first two tasks. */
- pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
-
- if( pxFirstSemaphoreParameters != NULL )
- {
- /* Create the semaphore used by the first two tasks. */
- vSemaphoreCreateBinary( pxFirstSemaphoreParameters->xSemaphore );
-
- if( pxFirstSemaphoreParameters->xSemaphore != NULL )
- {
- /* Create the variable which is to be shared by the first two tasks. */
- pxFirstSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
-
- /* Initialise the share variable to the value the tasks expect. */
- *( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
-
- /* The first two tasks do not block on semaphore calls. */
- pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
-
- /* Spawn the first two tasks. As they poll they operate at the idle priority. */
- xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
- xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
- }
- }
-
- /* Do exactly the same to create the second set of tasks, only this time
- provide a block time for the semaphore calls. */
- pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
- if( pxSecondSemaphoreParameters != NULL )
- {
- vSemaphoreCreateBinary( pxSecondSemaphoreParameters->xSemaphore );
-
- if( pxSecondSemaphoreParameters->xSemaphore != NULL )
- {
- pxSecondSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
- *( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
- pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
-
- xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
- xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
- }
- }
+ xSemaphoreParameters * pxFirstSemaphoreParameters, * pxSecondSemaphoreParameters;
+ const TickType_t xBlockTime = ( TickType_t ) 100;
+
+ /* Create the structure used to pass parameters to the first two tasks. */
+ pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
+
+ if( pxFirstSemaphoreParameters != NULL )
+ {
+ /* Create the semaphore used by the first two tasks. */
+ vSemaphoreCreateBinary( pxFirstSemaphoreParameters->xSemaphore );
+
+ if( pxFirstSemaphoreParameters->xSemaphore != NULL )
+ {
+ /* Create the variable which is to be shared by the first two tasks. */
+ pxFirstSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
+
+ /* Initialise the share variable to the value the tasks expect. */
+ *( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
+
+ /* The first two tasks do not block on semaphore calls. */
+ pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
+
+ /* Spawn the first two tasks. As they poll they operate at the idle priority. */
+ xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
+ xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
+ }
+ }
+
+ /* Do exactly the same to create the second set of tasks, only this time
+ * provide a block time for the semaphore calls. */
+ pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
+
+ if( pxSecondSemaphoreParameters != NULL )
+ {
+ vSemaphoreCreateBinary( pxSecondSemaphoreParameters->xSemaphore );
+
+ if( pxSecondSemaphoreParameters->xSemaphore != NULL )
+ {
+ pxSecondSemaphoreParameters->pulSharedVariable = ( unsigned long * ) pvPortMalloc( sizeof( unsigned long ) );
+ *( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
+ pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
+
+ xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
+ xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prvSemaphoreTest( void *pvParameters )
+static void prvSemaphoreTest( void * pvParameters )
{
-xSemaphoreParameters *pxParameters;
-volatile unsigned long *pulSharedVariable, ulExpectedValue;
-unsigned long ulCounter;
-short sError = pdFALSE, sCheckVariableToUse;
-
- /* See which check variable to use. sNextCheckVariable is not semaphore
- protected! */
- portENTER_CRITICAL();
- sCheckVariableToUse = sNextCheckVariable;
- sNextCheckVariable++;
- portEXIT_CRITICAL();
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcSemaphoreTaskStart );
-
- /* A structure is passed in as the parameter. This contains the shared
- variable being guarded. */
- pxParameters = ( xSemaphoreParameters * ) pvParameters;
- pulSharedVariable = pxParameters->pulSharedVariable;
-
- /* If we are blocking we use a much higher count to ensure loads of context
- switches occur during the count. */
- if( pxParameters->xBlockTime > ( TickType_t ) 0 )
- {
- ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
- }
- else
- {
- ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
- }
-
- for( ;; )
- {
- /* Try to obtain the semaphore. */
- if( xSemaphoreTake( pxParameters->xSemaphore, pxParameters->xBlockTime ) == pdPASS )
- {
- /* We have the semaphore and so expect any other tasks using the
- shared variable to have left it in the state we expect to find
- it. */
- if( *pulSharedVariable != ulExpectedValue )
- {
- vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
- sError = pdTRUE;
- }
-
- /* Clear the variable, then count it back up to the expected value
- before releasing the semaphore. Would expect a context switch or
- two during this time. */
- for( ulCounter = ( unsigned long ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
- {
- *pulSharedVariable = ulCounter;
- if( *pulSharedVariable != ulCounter )
- {
- if( sError == pdFALSE )
- {
- vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
- }
- sError = pdTRUE;
- }
- }
-
- /* Release the semaphore, and if no errors have occurred increment the check
- variable. */
- if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
- {
- vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- if( sCheckVariableToUse < semtstNUM_TASKS )
- {
- ( sCheckVariables[ sCheckVariableToUse ] )++;
- }
- }
-
- /* If we have a block time then we are running at a priority higher
- than the idle priority. This task takes a long time to complete
- a cycle (deliberately so to test the guarding) so will be starving
- out lower priority tasks. Block for some time to allow give lower
- priority tasks some processor time. */
- vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
- }
- else
- {
- if( pxParameters->xBlockTime == ( TickType_t ) 0 )
- {
- /* We have not got the semaphore yet, so no point using the
- processor. We are not blocking when attempting to obtain the
- semaphore. */
- taskYIELD();
- }
- }
- }
+ xSemaphoreParameters * pxParameters;
+ volatile unsigned long * pulSharedVariable, ulExpectedValue;
+ unsigned long ulCounter;
+ short sError = pdFALSE, sCheckVariableToUse;
+
+ /* See which check variable to use. sNextCheckVariable is not semaphore
+ * protected! */
+ portENTER_CRITICAL();
+ sCheckVariableToUse = sNextCheckVariable;
+ sNextCheckVariable++;
+ portEXIT_CRITICAL();
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcSemaphoreTaskStart );
+
+ /* A structure is passed in as the parameter. This contains the shared
+ * variable being guarded. */
+ pxParameters = ( xSemaphoreParameters * ) pvParameters;
+ pulSharedVariable = pxParameters->pulSharedVariable;
+
+ /* If we are blocking we use a much higher count to ensure loads of context
+ * switches occur during the count. */
+ if( pxParameters->xBlockTime > ( TickType_t ) 0 )
+ {
+ ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
+ }
+ else
+ {
+ ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
+ }
+
+ for( ; ; )
+ {
+ /* Try to obtain the semaphore. */
+ if( xSemaphoreTake( pxParameters->xSemaphore, pxParameters->xBlockTime ) == pdPASS )
+ {
+ /* We have the semaphore and so expect any other tasks using the
+ * shared variable to have left it in the state we expect to find
+ * it. */
+ if( *pulSharedVariable != ulExpectedValue )
+ {
+ vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
+ sError = pdTRUE;
+ }
+
+ /* Clear the variable, then count it back up to the expected value
+ * before releasing the semaphore. Would expect a context switch or
+ * two during this time. */
+ for( ulCounter = ( unsigned long ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
+ {
+ *pulSharedVariable = ulCounter;
+
+ if( *pulSharedVariable != ulCounter )
+ {
+ if( sError == pdFALSE )
+ {
+ vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
+ }
+
+ sError = pdTRUE;
+ }
+ }
+
+ /* Release the semaphore, and if no errors have occurred increment the check
+ * variable. */
+ if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
+ {
+ vPrintDisplayMessage( &pcPollingSemaphoreTaskError );
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ if( sCheckVariableToUse < semtstNUM_TASKS )
+ {
+ ( sCheckVariables[ sCheckVariableToUse ] )++;
+ }
+ }
+
+ /* If we have a block time then we are running at a priority higher
+ * than the idle priority. This task takes a long time to complete
+ * a cycle (deliberately so to test the guarding) so will be starving
+ * out lower priority tasks. Block for some time to allow give lower
+ * priority tasks some processor time. */
+ vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
+ }
+ else
+ {
+ if( pxParameters->xBlockTime == ( TickType_t ) 0 )
+ {
+ /* We have not got the semaphore yet, so no point using the
+ * processor. We are not blocking when attempting to obtain the
+ * semaphore. */
+ taskYIELD();
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreSemaphoreTasksStillRunning( void )
{
-static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
-portBASE_TYPE xTask, xReturn = pdTRUE;
+ static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
+ portBASE_TYPE xTask, xReturn = pdTRUE;
- for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
- {
- if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
- {
- xReturn = pdFALSE;
- }
+ for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
+ {
+ if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
+ {
+ xReturn = pdFALSE;
+ }
- sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
- }
+ sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
+ }
- return xReturn;
+ return xReturn;
}
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/AbortDelay.c b/FreeRTOS/Demo/Common/Minimal/AbortDelay.c
index b82223b2e..6cc8acc36 100644
--- a/FreeRTOS/Demo/Common/Minimal/AbortDelay.c
+++ b/FreeRTOS/Demo/Common/Minimal/AbortDelay.c
@@ -47,32 +47,32 @@
#include "AbortDelay.h"
/* This file can only be used if the functionality it tests is included in the
-build. Remove the whole file if this is not the case. */
-#if( INCLUDE_xTaskAbortDelay == 1 )
+ * build. Remove the whole file if this is not the case. */
+#if ( INCLUDE_xTaskAbortDelay == 1 )
-#if( INCLUDE_xTaskGetHandle != 1 )
- #error This test file uses the xTaskGetHandle() API function so INCLUDE_xTaskGetHandle must be set to 1 in FreeRTOSConfig.h.
-#endif
+ #if ( INCLUDE_xTaskGetHandle != 1 )
+ #error This test file uses the xTaskGetHandle() API function so INCLUDE_xTaskGetHandle must be set to 1 in FreeRTOSConfig.h.
+ #endif
/* Task priorities. Allow these to be overridden. */
-#ifndef abtCONTROLLING_PRIORITY
- #define abtCONTROLLING_PRIORITY ( configMAX_PRIORITIES - 3 )
-#endif
+ #ifndef abtCONTROLLING_PRIORITY
+ #define abtCONTROLLING_PRIORITY ( configMAX_PRIORITIES - 3 )
+ #endif
-#ifndef abtBLOCKING_PRIORITY
- #define abtBLOCKING_PRIORITY ( configMAX_PRIORITIES - 2 )
-#endif
+ #ifndef abtBLOCKING_PRIORITY
+ #define abtBLOCKING_PRIORITY ( configMAX_PRIORITIES - 2 )
+ #endif
/* The tests that are performed. */
-#define abtNOTIFY_WAIT_ABORTS 0
-#define abtNOTIFY_TAKE_ABORTS 1
-#define abtDELAY_ABORTS 2
-#define abtDELAY_UNTIL_ABORTS 3
-#define abtSEMAPHORE_TAKE_ABORTS 4
-#define abtEVENT_GROUP_ABORTS 5
-#define abtQUEUE_SEND_ABORTS 6
-#define abtSTREAM_BUFFER_RECEIVE 7
-#define abtMAX_TESTS 8
+ #define abtNOTIFY_WAIT_ABORTS 0
+ #define abtNOTIFY_TAKE_ABORTS 1
+ #define abtDELAY_ABORTS 2
+ #define abtDELAY_UNTIL_ABORTS 3
+ #define abtSEMAPHORE_TAKE_ABORTS 4
+ #define abtEVENT_GROUP_ABORTS 5
+ #define abtQUEUE_SEND_ABORTS 6
+ #define abtSTREAM_BUFFER_RECEIVE 7
+ #define abtMAX_TESTS 8
/*-----------------------------------------------------------*/
@@ -80,8 +80,8 @@ build. Remove the whole file if this is not the case. */
* The two test tasks. The controlling task specifies which test to executed.
* More information is provided in the comments within the tasks.
*/
-static void prvControllingTask( void *pvParameters );
-static void prvBlockingTask( void *pvParameters );
+ static void prvControllingTask( void * pvParameters );
+ static void prvBlockingTask( void * pvParameters );
/*
* Test functions called by the blocking task. Each function follows the same
@@ -92,666 +92,709 @@ static void prvBlockingTask( void *pvParameters );
* expected to be aborted by the controlling task half way through the block
* time.
*/
-static void prvTestAbortingTaskNotifyWait( void );
-static void prvTestAbortingTaskNotifyTake( void );
-static void prvTestAbortingTaskDelay( void );
-static void prvTestAbortingTaskDelayUntil( void );
-static void prvTestAbortingSemaphoreTake( void );
-static void prvTestAbortingEventGroupWait( void );
-static void prvTestAbortingQueueSend( void );
-static void prvTestAbortingStreamBufferReceive( void );
+ static void prvTestAbortingTaskNotifyWait( void );
+ static void prvTestAbortingTaskNotifyTake( void );
+ static void prvTestAbortingTaskDelay( void );
+ static void prvTestAbortingTaskDelayUntil( void );
+ static void prvTestAbortingSemaphoreTake( void );
+ static void prvTestAbortingEventGroupWait( void );
+ static void prvTestAbortingQueueSend( void );
+ static void prvTestAbortingStreamBufferReceive( void );
/*
* Performs a few tests to cover code paths not otherwise covered by the continuous
* tests.
*/
-static void prvPerformSingleTaskTests( void );
+ static void prvPerformSingleTaskTests( void );
/*
* Checks the amount of time a task spent in the Blocked state is within the
* expected bounds.
*/
-static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime, TickType_t xExpectedBlockTime );
+ static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime,
+ TickType_t xExpectedBlockTime );
/*-----------------------------------------------------------*/
/* Used to ensure that tasks are still executing without error. */
-static volatile BaseType_t xControllingCycles = 0, xBlockingCycles = 0;
-static volatile BaseType_t xErrorOccurred = pdFALSE;
+ static volatile BaseType_t xControllingCycles = 0, xBlockingCycles = 0;
+ static volatile BaseType_t xErrorOccurred = pdFALSE;
/* Each task needs to know the other tasks handle so they can send signals to
-each other. The handle is obtained from the task's name. */
-static const char *pcControllingTaskName = "AbtCtrl", *pcBlockingTaskName = "AbtBlk";
+ * each other. The handle is obtained from the task's name. */
+ static const char * pcControllingTaskName = "AbtCtrl", * pcBlockingTaskName = "AbtBlk";
/* The maximum amount of time a task will block for. */
-const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 100 );
-const TickType_t xHalfMaxBlockTime = pdMS_TO_TICKS( 50 );
+ const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 100 );
+ const TickType_t xHalfMaxBlockTime = pdMS_TO_TICKS( 50 );
/* The actual block time is dependent on the priority of other tasks in the
-system so the actual block time might be greater than that expected, but it
-should be within an acceptable upper bound. */
-const TickType_t xAllowableMargin = pdMS_TO_TICKS( 7 );
+ * system so the actual block time might be greater than that expected, but it
+ * should be within an acceptable upper bound. */
+ const TickType_t xAllowableMargin = pdMS_TO_TICKS( 7 );
/*-----------------------------------------------------------*/
-void vCreateAbortDelayTasks( void )
-{
- /* Create the two test tasks described above. */
- xTaskCreate( prvControllingTask, pcControllingTaskName, configMINIMAL_STACK_SIZE, NULL, abtCONTROLLING_PRIORITY, NULL );
- xTaskCreate( prvBlockingTask, pcBlockingTaskName, configMINIMAL_STACK_SIZE, NULL, abtBLOCKING_PRIORITY, NULL );
-}
+ void vCreateAbortDelayTasks( void )
+ {
+ /* Create the two test tasks described above. */
+ xTaskCreate( prvControllingTask, pcControllingTaskName, configMINIMAL_STACK_SIZE, NULL, abtCONTROLLING_PRIORITY, NULL );
+ xTaskCreate( prvBlockingTask, pcBlockingTaskName, configMINIMAL_STACK_SIZE, NULL, abtBLOCKING_PRIORITY, NULL );
+ }
/*-----------------------------------------------------------*/
-static void prvControllingTask( void *pvParameters )
-{
-TaskHandle_t xBlockingTask;
-uint32_t ulTestToPerform = abtNOTIFY_WAIT_ABORTS;
-TickType_t xTimeAtStart;
-const TickType_t xStartMargin = 2UL;
-
- /* Just to remove compiler warnings. */
- ( void ) pvParameters;
-
- xBlockingTask = xTaskGetHandle( pcBlockingTaskName );
- configASSERT( xBlockingTask );
-
- for( ;; )
- {
- /* Tell the secondary task to perform the next test. */
- xTimeAtStart = xTaskGetTickCount();
- xTaskNotify( xBlockingTask, ulTestToPerform, eSetValueWithOverwrite );
-
- /* The secondary task has a higher priority, so will now be in the
- Blocked state to wait for a maximum of xMaxBlockTime. It expects that
- period to complete with a timeout. It will then block for
- xMaxBlockTimeAgain, but this time it expects to the block time to abort
- half way through. Block until it is time to send the abort to the
- secondary task. xStartMargin is used because this task takes timing
- from the beginning of the test, whereas the blocking task takes timing
- from the entry into the Blocked state - and as the tasks run at
- different priorities, there may be some discrepancy. Also, temporarily
- raise the priority of the controlling task to that of the blocking
- task to minimise discrepancies. */
- vTaskPrioritySet( NULL, abtBLOCKING_PRIORITY );
- vTaskDelay( xMaxBlockTime + xHalfMaxBlockTime + xStartMargin );
- if( xTaskAbortDelay( xBlockingTask ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Reset the priority to the normal controlling priority. */
- vTaskPrioritySet( NULL, abtCONTROLLING_PRIORITY );
-
- /* Now wait to be notified that the secondary task has completed its
- test. */
- ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
-
- /* Did the entire test run for the expected time, which is two full
- block times plus the half block time caused by calling
- xTaskAbortDelay()? */
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, ( xMaxBlockTime + xMaxBlockTime + xHalfMaxBlockTime ) );
-
- /* Move onto the next test. */
- ulTestToPerform++;
-
- if( ulTestToPerform >= abtMAX_TESTS )
- {
- ulTestToPerform = 0;
- }
-
- /* To indicate this task is still executing. */
- xControllingCycles++;
- }
-}
+ static void prvControllingTask( void * pvParameters )
+ {
+ TaskHandle_t xBlockingTask;
+ uint32_t ulTestToPerform = abtNOTIFY_WAIT_ABORTS;
+ TickType_t xTimeAtStart;
+ const TickType_t xStartMargin = 2UL;
+
+ /* Just to remove compiler warnings. */
+ ( void ) pvParameters;
+
+ xBlockingTask = xTaskGetHandle( pcBlockingTaskName );
+ configASSERT( xBlockingTask );
+
+ for( ; ; )
+ {
+ /* Tell the secondary task to perform the next test. */
+ xTimeAtStart = xTaskGetTickCount();
+ xTaskNotify( xBlockingTask, ulTestToPerform, eSetValueWithOverwrite );
+
+ /* The secondary task has a higher priority, so will now be in the
+ * Blocked state to wait for a maximum of xMaxBlockTime. It expects that
+ * period to complete with a timeout. It will then block for
+ * xMaxBlockTimeAgain, but this time it expects to the block time to abort
+ * half way through. Block until it is time to send the abort to the
+ * secondary task. xStartMargin is used because this task takes timing
+ * from the beginning of the test, whereas the blocking task takes timing
+ * from the entry into the Blocked state - and as the tasks run at
+ * different priorities, there may be some discrepancy. Also, temporarily
+ * raise the priority of the controlling task to that of the blocking
+ * task to minimise discrepancies. */
+ vTaskPrioritySet( NULL, abtBLOCKING_PRIORITY );
+ vTaskDelay( xMaxBlockTime + xHalfMaxBlockTime + xStartMargin );
+
+ if( xTaskAbortDelay( xBlockingTask ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Reset the priority to the normal controlling priority. */
+ vTaskPrioritySet( NULL, abtCONTROLLING_PRIORITY );
+
+ /* Now wait to be notified that the secondary task has completed its
+ * test. */
+ ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
+
+ /* Did the entire test run for the expected time, which is two full
+ * block times plus the half block time caused by calling
+ * xTaskAbortDelay()? */
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, ( xMaxBlockTime + xMaxBlockTime + xHalfMaxBlockTime ) );
+
+ /* Move onto the next test. */
+ ulTestToPerform++;
+
+ if( ulTestToPerform >= abtMAX_TESTS )
+ {
+ ulTestToPerform = 0;
+ }
+
+ /* To indicate this task is still executing. */
+ xControllingCycles++;
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvBlockingTask( void *pvParameters )
-{
-TaskHandle_t xControllingTask;
-uint32_t ulNotificationValue;
-const uint32_t ulMax = 0xffffffffUL;
-
- /* Just to remove compiler warnings. */
- ( void ) pvParameters;
-
- /* Start by performing a few tests to cover code not exercised in the loops
- below. */
- prvPerformSingleTaskTests();
-
- xControllingTask = xTaskGetHandle( pcControllingTaskName );
- configASSERT( xControllingTask );
-
- for( ;; )
- {
- /* Wait to be notified of the test that is to be performed next. */
- xTaskNotifyWait( 0, ulMax, &ulNotificationValue, portMAX_DELAY );
-
- switch( ulNotificationValue )
- {
- case abtNOTIFY_WAIT_ABORTS:
- prvTestAbortingTaskNotifyWait();
- break;
-
- case abtNOTIFY_TAKE_ABORTS:
- prvTestAbortingTaskNotifyTake();
- break;
-
- case abtDELAY_ABORTS:
- prvTestAbortingTaskDelay();
- break;
-
- case abtDELAY_UNTIL_ABORTS:
- prvTestAbortingTaskDelayUntil();
- break;
-
- case abtSEMAPHORE_TAKE_ABORTS:
- prvTestAbortingSemaphoreTake();
- break;
-
- case abtEVENT_GROUP_ABORTS:
- prvTestAbortingEventGroupWait();
- break;
-
- case abtQUEUE_SEND_ABORTS:
- prvTestAbortingQueueSend();
- break;
-
- case abtSTREAM_BUFFER_RECEIVE:
- prvTestAbortingStreamBufferReceive();
- break;
-
- default:
- /* Should not get here. */
- break;
- }
-
- /* Let the primary task know the test is complete. */
- xTaskNotifyGive( xControllingTask );
-
- /* To indicate this task is still executing. */
- xBlockingCycles++;
- }
-}
+ static void prvBlockingTask( void * pvParameters )
+ {
+ TaskHandle_t xControllingTask;
+ uint32_t ulNotificationValue;
+ const uint32_t ulMax = 0xffffffffUL;
+
+ /* Just to remove compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Start by performing a few tests to cover code not exercised in the loops
+ * below. */
+ prvPerformSingleTaskTests();
+
+ xControllingTask = xTaskGetHandle( pcControllingTaskName );
+ configASSERT( xControllingTask );
+
+ for( ; ; )
+ {
+ /* Wait to be notified of the test that is to be performed next. */
+ xTaskNotifyWait( 0, ulMax, &ulNotificationValue, portMAX_DELAY );
+
+ switch( ulNotificationValue )
+ {
+ case abtNOTIFY_WAIT_ABORTS:
+ prvTestAbortingTaskNotifyWait();
+ break;
+
+ case abtNOTIFY_TAKE_ABORTS:
+ prvTestAbortingTaskNotifyTake();
+ break;
+
+ case abtDELAY_ABORTS:
+ prvTestAbortingTaskDelay();
+ break;
+
+ case abtDELAY_UNTIL_ABORTS:
+ prvTestAbortingTaskDelayUntil();
+ break;
+
+ case abtSEMAPHORE_TAKE_ABORTS:
+ prvTestAbortingSemaphoreTake();
+ break;
+
+ case abtEVENT_GROUP_ABORTS:
+ prvTestAbortingEventGroupWait();
+ break;
+
+ case abtQUEUE_SEND_ABORTS:
+ prvTestAbortingQueueSend();
+ break;
+
+ case abtSTREAM_BUFFER_RECEIVE:
+ prvTestAbortingStreamBufferReceive();
+ break;
+
+ default:
+ /* Should not get here. */
+ break;
+ }
+
+ /* Let the primary task know the test is complete. */
+ xTaskNotifyGive( xControllingTask );
+
+ /* To indicate this task is still executing. */
+ xBlockingCycles++;
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvPerformSingleTaskTests( void )
-{
-TaskHandle_t xThisTask;
-BaseType_t xReturned;
-
- /* Try unblocking this task using both the task and ISR versions of the API -
- both should return false as this task is not blocked. */
- xThisTask = xTaskGetCurrentTaskHandle();
-
- xReturned = xTaskAbortDelay( xThisTask );
- if( xReturned != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
-}
+ static void prvPerformSingleTaskTests( void )
+ {
+ TaskHandle_t xThisTask;
+ BaseType_t xReturned;
+
+ /* Try unblocking this task using both the task and ISR versions of the API -
+ * both should return false as this task is not blocked. */
+ xThisTask = xTaskGetCurrentTaskHandle();
+
+ xReturned = xTaskAbortDelay( xThisTask );
+
+ if( xReturned != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingTaskDelayUntil( void )
-{
-TickType_t xTimeAtStart, xLastBlockTime;
-BaseType_t xReturned;
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* Take a copy of the time as it is updated in the call to
- xTaskDelayUntil() but its original value is needed to determine the actual
- time spend in the Blocked state. */
- xLastBlockTime = xTimeAtStart;
-
- /* This first delay should just time out. */
- xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
- configASSERT( xReturned == pdTRUE );
- /* Remove compiler warning about value being set but not used in the case
- configASSERT() is not defined. */
- ( void ) xReturned;
-
- /* This second delay should be aborted by the primary task half way
- through. Again take a copy of the time as it is updated in the call to
- vTaskDelayUntil() buts its original value is needed to determine the amount
- of time actually spent in the Blocked state. This uses vTaskDelayUntil()
- in place of xTaskDelayUntil() for test coverage. */
- xTimeAtStart = xTaskGetTickCount();
- xLastBlockTime = xTimeAtStart;
- vTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
-
- /* As with the other tests, the third block period should not time out. */
- xTimeAtStart = xTaskGetTickCount();
- xLastBlockTime = xTimeAtStart;
- xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
- configASSERT( xReturned == pdTRUE );
- /* Remove compiler warning about value being set but not used in the case
- configASSERT() is not defined. */
- ( void ) xReturned;
-}
+ static void prvTestAbortingTaskDelayUntil( void )
+ {
+ TickType_t xTimeAtStart, xLastBlockTime;
+ BaseType_t xReturned;
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* Take a copy of the time as it is updated in the call to
+ * xTaskDelayUntil() but its original value is needed to determine the actual
+ * time spend in the Blocked state. */
+ xLastBlockTime = xTimeAtStart;
+
+ /* This first delay should just time out. */
+ xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+ configASSERT( xReturned == pdTRUE );
+
+ /* Remove compiler warning about value being set but not used in the case
+ * configASSERT() is not defined. */
+ ( void ) xReturned;
+
+ /* This second delay should be aborted by the primary task half way
+ * through. Again take a copy of the time as it is updated in the call to
+ * vTaskDelayUntil() buts its original value is needed to determine the amount
+ * of time actually spent in the Blocked state. This uses vTaskDelayUntil()
+ * in place of xTaskDelayUntil() for test coverage. */
+ xTimeAtStart = xTaskGetTickCount();
+ xLastBlockTime = xTimeAtStart;
+ vTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+
+ /* As with the other tests, the third block period should not time out. */
+ xTimeAtStart = xTaskGetTickCount();
+ xLastBlockTime = xTimeAtStart;
+ xReturned = xTaskDelayUntil( &xLastBlockTime, xMaxBlockTime );
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+ configASSERT( xReturned == pdTRUE );
+
+ /* Remove compiler warning about value being set but not used in the case
+ * configASSERT() is not defined. */
+ ( void ) xReturned;
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingTaskDelay( void )
-{
-TickType_t xTimeAtStart;
+ static void prvTestAbortingTaskDelay( void )
+ {
+ TickType_t xTimeAtStart;
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
- /* This first delay should just time out. */
- vTaskDelay( xMaxBlockTime );
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+ /* This first delay should just time out. */
+ vTaskDelay( xMaxBlockTime );
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
- /* This second delay should be aborted by the primary task half way
- through. */
- vTaskDelay( xMaxBlockTime );
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+ /* This second delay should be aborted by the primary task half way
+ * through. */
+ vTaskDelay( xMaxBlockTime );
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
- /* This third delay should just time out again. */
- vTaskDelay( xMaxBlockTime );
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-}
+ /* This third delay should just time out again. */
+ vTaskDelay( xMaxBlockTime );
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingTaskNotifyTake( void )
-{
-TickType_t xTimeAtStart;
-uint32_t ulReturn;
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This first delay should just time out. */
- ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
- if( ulReturn != 0 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This second delay should be aborted by the primary task half way
- through. */
- ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
- if( ulReturn != 0 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This third delay should just time out again. */
- ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
- if( ulReturn != 0 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-}
+ static void prvTestAbortingTaskNotifyTake( void )
+ {
+ TickType_t xTimeAtStart;
+ uint32_t ulReturn;
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This first delay should just time out. */
+ ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
+
+ if( ulReturn != 0 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This second delay should be aborted by the primary task half way
+ * through. */
+ ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
+
+ if( ulReturn != 0 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This third delay should just time out again. */
+ ulReturn = ulTaskNotifyTake( pdFALSE, xMaxBlockTime );
+
+ if( ulReturn != 0 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingEventGroupWait( void )
-{
-TickType_t xTimeAtStart;
-EventGroupHandle_t xEventGroup;
-EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn;
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- static StaticEventGroup_t xEventGroupBuffer;
-
- /* Create the event group. Statically allocated memory is used so the
- creation cannot fail. */
- xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
- }
- #else
- {
- xEventGroup = xEventGroupCreate();
- configASSERT( xEventGroup );
- }
- #endif
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This first delay should just time out. */
- xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
- if( xReturn != 0x00 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This second delay should be aborted by the primary task half way
- through. */
- xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
- if( xReturn != 0x00 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This third delay should just time out again. */
- xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
- if( xReturn != 0x00 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Not really necessary in this case, but for completeness. */
- vEventGroupDelete( xEventGroup );
-}
+ static void prvTestAbortingEventGroupWait( void )
+ {
+ TickType_t xTimeAtStart;
+ EventGroupHandle_t xEventGroup;
+ EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn;
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ static StaticEventGroup_t xEventGroupBuffer;
+
+ /* Create the event group. Statically allocated memory is used so the
+ * creation cannot fail. */
+ xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
+ }
+ #else
+ {
+ xEventGroup = xEventGroupCreate();
+ configASSERT( xEventGroup );
+ }
+ #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This first delay should just time out. */
+ xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
+
+ if( xReturn != 0x00 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This second delay should be aborted by the primary task half way
+ * through. */
+ xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
+
+ if( xReturn != 0x00 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This third delay should just time out again. */
+ xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
+
+ if( xReturn != 0x00 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Not really necessary in this case, but for completeness. */
+ vEventGroupDelete( xEventGroup );
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingStreamBufferReceive( void )
-{
-TickType_t xTimeAtStart;
-StreamBufferHandle_t xStreamBuffer;
-size_t xReturn;
-const size_t xTriggerLevelBytes = ( size_t ) 1;
-uint8_t uxRxData;
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- /* Defines the memory that will actually hold the streams within the
- stream buffer. */
- static uint8_t ucStorageBuffer[ sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) + 1 ];
-
- /* The variable used to hold the stream buffer structure. */
- StaticStreamBuffer_t xStreamBufferStruct;
-
-
- xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucStorageBuffer ),
- xTriggerLevelBytes,
- ucStorageBuffer,
- &xStreamBufferStruct );
- }
- #else
- {
- xStreamBuffer = xStreamBufferCreate( sizeof( uint8_t ), xTriggerLevelBytes );
- configASSERT( xStreamBuffer );
- }
- #endif
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This first delay should just time out. */
- xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
- if( xReturn != 0x00 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This second delay should be aborted by the primary task half way
- through xMaxBlockTime. */
- xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
- if( xReturn != 0x00 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This third delay should just time out again. */
- xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
- if( xReturn != 0x00 )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Not really necessary in this case, but for completeness. */
- vStreamBufferDelete( xStreamBuffer );
-}
+ static void prvTestAbortingStreamBufferReceive( void )
+ {
+ TickType_t xTimeAtStart;
+ StreamBufferHandle_t xStreamBuffer;
+ size_t xReturn;
+ const size_t xTriggerLevelBytes = ( size_t ) 1;
+ uint8_t uxRxData;
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ /* Defines the memory that will actually hold the streams within the
+ * stream buffer. */
+ static uint8_t ucStorageBuffer[ sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) + 1 ];
+
+ /* The variable used to hold the stream buffer structure. */
+ StaticStreamBuffer_t xStreamBufferStruct;
+
+
+ xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucStorageBuffer ),
+ xTriggerLevelBytes,
+ ucStorageBuffer,
+ &xStreamBufferStruct );
+ }
+ #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
+ {
+ xStreamBuffer = xStreamBufferCreate( sizeof( uint8_t ), xTriggerLevelBytes );
+ configASSERT( xStreamBuffer );
+ }
+ #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This first delay should just time out. */
+ xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
+
+ if( xReturn != 0x00 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This second delay should be aborted by the primary task half way
+ * through xMaxBlockTime. */
+ xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
+
+ if( xReturn != 0x00 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This third delay should just time out again. */
+ xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime );
+
+ if( xReturn != 0x00 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Not really necessary in this case, but for completeness. */
+ vStreamBufferDelete( xStreamBuffer );
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingQueueSend( void )
-{
-TickType_t xTimeAtStart;
-BaseType_t xReturn;
-const UBaseType_t xQueueLength = ( UBaseType_t ) 1;
-QueueHandle_t xQueue;
-uint8_t ucItemToQueue;
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- static StaticQueue_t xQueueBuffer;
- static uint8_t ucQueueStorage[ sizeof( uint8_t ) ];
-
- /* Create the queue. Statically allocated memory is used so the
- creation cannot fail. */
- xQueue = xQueueCreateStatic( xQueueLength, sizeof( uint8_t ), ucQueueStorage, &xQueueBuffer );
- }
- #else
- {
- xQueue = xQueueCreate( xQueueLength, sizeof( uint8_t ) );
- configASSERT( xQueue );
- }
- #endif
-
- /* This function tests aborting when in the blocked state waiting to send,
- so the queue must be full. There is only one space in the queue. */
- xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
- if( xReturn != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This first delay should just time out. */
- xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This second delay should be aborted by the primary task half way
- through. */
- xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This third delay should just time out again. */
- xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Not really necessary in this case, but for completeness. */
- vQueueDelete( xQueue );
-}
+ static void prvTestAbortingQueueSend( void )
+ {
+ TickType_t xTimeAtStart;
+ BaseType_t xReturn;
+ const UBaseType_t xQueueLength = ( UBaseType_t ) 1;
+ QueueHandle_t xQueue;
+ uint8_t ucItemToQueue;
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ static StaticQueue_t xQueueBuffer;
+ static uint8_t ucQueueStorage[ sizeof( uint8_t ) ];
+
+ /* Create the queue. Statically allocated memory is used so the
+ * creation cannot fail. */
+ xQueue = xQueueCreateStatic( xQueueLength, sizeof( uint8_t ), ucQueueStorage, &xQueueBuffer );
+ }
+ #else
+ {
+ xQueue = xQueueCreate( xQueueLength, sizeof( uint8_t ) );
+ configASSERT( xQueue );
+ }
+ #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
+
+ /* This function tests aborting when in the blocked state waiting to send,
+ * so the queue must be full. There is only one space in the queue. */
+ xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
+
+ if( xReturn != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This first delay should just time out. */
+ xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This second delay should be aborted by the primary task half way
+ * through. */
+ xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This third delay should just time out again. */
+ xReturn = xQueueSend( xQueue, &ucItemToQueue, xMaxBlockTime );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Not really necessary in this case, but for completeness. */
+ vQueueDelete( xQueue );
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingSemaphoreTake( void )
-{
-TickType_t xTimeAtStart;
-BaseType_t xReturn;
-SemaphoreHandle_t xSemaphore;
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- static StaticSemaphore_t xSemaphoreBuffer;
-
- /* Create the semaphore. Statically allocated memory is used so the
- creation cannot fail. */
- xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
- }
- #else
- {
- xSemaphore = xSemaphoreCreateBinary();
- }
- #endif
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This first delay should just time out. */
- xReturn = xSemaphoreTake( xSemaphore, xMaxBlockTime );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This second delay should be aborted by the primary task half way
- through xMaxBlockTime. */
- xReturn = xSemaphoreTake( xSemaphore, portMAX_DELAY );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This third delay should just time out again. */
- xReturn = xSemaphoreTake( xSemaphore, xMaxBlockTime );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Not really necessary in this case, but for completeness. */
- vSemaphoreDelete( xSemaphore );
-}
+ static void prvTestAbortingSemaphoreTake( void )
+ {
+ TickType_t xTimeAtStart;
+ BaseType_t xReturn;
+ SemaphoreHandle_t xSemaphore;
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ static StaticSemaphore_t xSemaphoreBuffer;
+
+ /* Create the semaphore. Statically allocated memory is used so the
+ * creation cannot fail. */
+ xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
+ }
+ #else
+ {
+ xSemaphore = xSemaphoreCreateBinary();
+ }
+ #endif
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This first delay should just time out. */
+ xReturn = xSemaphoreTake( xSemaphore, xMaxBlockTime );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This second delay should be aborted by the primary task half way
+ * through xMaxBlockTime. */
+ xReturn = xSemaphoreTake( xSemaphore, portMAX_DELAY );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This third delay should just time out again. */
+ xReturn = xSemaphoreTake( xSemaphore, xMaxBlockTime );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Not really necessary in this case, but for completeness. */
+ vSemaphoreDelete( xSemaphore );
+ }
/*-----------------------------------------------------------*/
-static void prvTestAbortingTaskNotifyWait( void )
-{
-TickType_t xTimeAtStart;
-BaseType_t xReturn;
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This first delay should just time out. */
- xReturn = xTaskNotifyWait( 0, 0, NULL, xMaxBlockTime );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This second delay should be aborted by the primary task half way
- through xMaxBlockTime. */
- xReturn = xTaskNotifyWait( 0, 0, NULL, portMAX_DELAY );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
-
- /* Note the time before the delay so the length of the delay is known. */
- xTimeAtStart = xTaskGetTickCount();
-
- /* This third delay should just time out again. */
- xReturn = xTaskNotifyWait( 0, 0, NULL, xMaxBlockTime );
- if( xReturn != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
- prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
-}
+ static void prvTestAbortingTaskNotifyWait( void )
+ {
+ TickType_t xTimeAtStart;
+ BaseType_t xReturn;
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This first delay should just time out. */
+ xReturn = xTaskNotifyWait( 0, 0, NULL, xMaxBlockTime );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This second delay should be aborted by the primary task half way
+ * through xMaxBlockTime. */
+ xReturn = xTaskNotifyWait( 0, 0, NULL, portMAX_DELAY );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
+
+ /* Note the time before the delay so the length of the delay is known. */
+ xTimeAtStart = xTaskGetTickCount();
+
+ /* This third delay should just time out again. */
+ xReturn = xTaskNotifyWait( 0, 0, NULL, xMaxBlockTime );
+
+ if( xReturn != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
+ }
/*-----------------------------------------------------------*/
-static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime, TickType_t xExpectedBlockTime )
-{
-TickType_t xTimeNow, xActualBlockTime;
-
- xTimeNow = xTaskGetTickCount();
- xActualBlockTime = xTimeNow - xStartTime;
-
- /* The actual block time should not be less than the expected block time. */
- if( xActualBlockTime < xExpectedBlockTime )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* The actual block time can be greater than the expected block time, as it
- depends on the priority of the other tasks, but it should be within an
- acceptable margin. */
- if( xActualBlockTime > ( xExpectedBlockTime + xAllowableMargin ) )
- {
- xErrorOccurred = pdTRUE;
- }
-}
+ static void prvCheckExpectedTimeIsWithinAnAcceptableMargin( TickType_t xStartTime,
+ TickType_t xExpectedBlockTime )
+ {
+ TickType_t xTimeNow, xActualBlockTime;
+
+ xTimeNow = xTaskGetTickCount();
+ xActualBlockTime = xTimeNow - xStartTime;
+
+ /* The actual block time should not be less than the expected block time. */
+ if( xActualBlockTime < xExpectedBlockTime )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* The actual block time can be greater than the expected block time, as it
+ * depends on the priority of the other tasks, but it should be within an
+ * acceptable margin. */
+ if( xActualBlockTime > ( xExpectedBlockTime + xAllowableMargin ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
/*-----------------------------------------------------------*/
-BaseType_t xAreAbortDelayTestTasksStillRunning( void )
-{
-static BaseType_t xLastControllingCycleCount = 0, xLastBlockingCycleCount = 0;
-BaseType_t xReturn = pdPASS;
-
- /* Have both tasks performed at least one cycle since this function was
- last called? */
- if( xControllingCycles == xLastControllingCycleCount )
- {
- xReturn = pdFAIL;
- }
-
- if( xBlockingCycles == xLastBlockingCycleCount )
- {
- xReturn = pdFAIL;
- }
-
- if( xErrorOccurred == pdTRUE )
- {
- xReturn = pdFAIL;
- }
-
- xLastBlockingCycleCount = xBlockingCycles;
- xLastControllingCycleCount = xControllingCycles;
-
- return xReturn;
-}
+ BaseType_t xAreAbortDelayTestTasksStillRunning( void )
+ {
+ static BaseType_t xLastControllingCycleCount = 0, xLastBlockingCycleCount = 0;
+ BaseType_t xReturn = pdPASS;
+
+ /* Have both tasks performed at least one cycle since this function was
+ * last called? */
+ if( xControllingCycles == xLastControllingCycleCount )
+ {
+ xReturn = pdFAIL;
+ }
+
+ if( xBlockingCycles == xLastBlockingCycleCount )
+ {
+ xReturn = pdFAIL;
+ }
+
+ if( xErrorOccurred == pdTRUE )
+ {
+ xReturn = pdFAIL;
+ }
+
+ xLastBlockingCycleCount = xBlockingCycles;
+ xLastControllingCycleCount = xControllingCycles;
+
+ return xReturn;
+ }
#endif /* INCLUDE_xTaskAbortDelay == 1 */
diff --git a/FreeRTOS/Demo/Common/Minimal/BlockQ.c b/FreeRTOS/Demo/Common/Minimal/BlockQ.c
index fe076c56d..030d7de83 100644
--- a/FreeRTOS/Demo/Common/Minimal/BlockQ.c
+++ b/FreeRTOS/Demo/Common/Minimal/BlockQ.c
@@ -59,232 +59,232 @@
/* Demo program include files. */
#include "BlockQ.h"
-#define blckqSTACK_SIZE configMINIMAL_STACK_SIZE
-#define blckqNUM_TASK_SETS ( 3 )
+#define blckqSTACK_SIZE configMINIMAL_STACK_SIZE
+#define blckqNUM_TASK_SETS ( 3 )
-#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
- #error This example cannot be used if dynamic allocation is not allowed.
+#if ( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
+ #error This example cannot be used if dynamic allocation is not allowed.
#endif
/* Structure used to pass parameters to the blocking queue tasks. */
typedef struct BLOCKING_QUEUE_PARAMETERS
{
- QueueHandle_t xQueue; /*< The queue to be used by the task. */
- TickType_t xBlockTime; /*< The block time to use on queue reads/writes. */
- volatile short *psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
+ QueueHandle_t xQueue; /*< The queue to be used by the task. */
+ TickType_t xBlockTime; /*< The block time to use on queue reads/writes. */
+ volatile short * psCheckVariable; /*< Incremented on each successful cycle to check the task is still running. */
} xBlockingQueueParameters;
/* Task function that creates an incrementing number and posts it on a queue. */
static portTASK_FUNCTION_PROTO( vBlockingQueueProducer, pvParameters );
/* Task function that removes the incrementing number from a queue and checks that
-it is the expected number. */
+ * it is the expected number. */
static portTASK_FUNCTION_PROTO( vBlockingQueueConsumer, pvParameters );
/* Variables which are incremented each time an item is removed from a queue, and
-found to be the expected value.
-These are used to check that the tasks are still running. */
+ * found to be the expected value.
+ * These are used to check that the tasks are still running. */
static volatile short sBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
/* Variable which are incremented each time an item is posted on a queue. These
-are used to check that the tasks are still running. */
+ * are used to check that the tasks are still running. */
static volatile short sBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
/*-----------------------------------------------------------*/
void vStartBlockingQueueTasks( UBaseType_t uxPriority )
{
-xBlockingQueueParameters *pxQueueParameters1, *pxQueueParameters2;
-xBlockingQueueParameters *pxQueueParameters3, *pxQueueParameters4;
-xBlockingQueueParameters *pxQueueParameters5, *pxQueueParameters6;
-const UBaseType_t uxQueueSize1 = 1, uxQueueSize5 = 5;
-const TickType_t xBlockTime = pdMS_TO_TICKS( ( TickType_t ) 1000 );
-const TickType_t xDontBlock = ( TickType_t ) 0;
+ xBlockingQueueParameters * pxQueueParameters1, * pxQueueParameters2;
+ xBlockingQueueParameters * pxQueueParameters3, * pxQueueParameters4;
+ xBlockingQueueParameters * pxQueueParameters5, * pxQueueParameters6;
+ const UBaseType_t uxQueueSize1 = 1, uxQueueSize5 = 5;
+ const TickType_t xBlockTime = pdMS_TO_TICKS( ( TickType_t ) 1000 );
+ const TickType_t xDontBlock = ( TickType_t ) 0;
- /* Create the first two tasks as described at the top of the file. */
+ /* Create the first two tasks as described at the top of the file. */
- /* First create the structure used to pass parameters to the consumer tasks. */
- pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ /* First create the structure used to pass parameters to the consumer tasks. */
+ pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- /* Create the queue used by the first two tasks to pass the incrementing number.
- Pass a pointer to the queue in the parameter structure. */
- pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
+ /* Create the queue used by the first two tasks to pass the incrementing number.
+ * Pass a pointer to the queue in the parameter structure. */
+ pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
- /* The consumer is created first so gets a block time as described above. */
- pxQueueParameters1->xBlockTime = xBlockTime;
+ /* The consumer is created first so gets a block time as described above. */
+ pxQueueParameters1->xBlockTime = xBlockTime;
- /* Pass in the variable that this task is going to increment so we can check it
- is still running. */
- pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
+ /* Pass in the variable that this task is going to increment so we can check it
+ * is still running. */
+ pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] );
- /* Create the structure used to pass parameters to the producer task. */
- pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ /* Create the structure used to pass parameters to the producer task. */
+ pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- /* Pass the queue to this task also, using the parameter structure. */
- pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
+ /* Pass the queue to this task also, using the parameter structure. */
+ pxQueueParameters2->xQueue = pxQueueParameters1->xQueue;
- /* The producer is not going to block - as soon as it posts the consumer will
- wake and remove the item so the producer should always have room to post. */
- pxQueueParameters2->xBlockTime = xDontBlock;
+ /* The producer is not going to block - as soon as it posts the consumer will
+ * wake and remove the item so the producer should always have room to post. */
+ pxQueueParameters2->xBlockTime = xDontBlock;
- /* Pass in the variable that this task is going to increment so we can check
- it is still running. */
- pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
+ /* Pass in the variable that this task is going to increment so we can check
+ * it is still running. */
+ pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] );
- /* Note the producer has a lower priority than the consumer when the tasks are
- spawned. */
- xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
- xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
+ /* Note the producer has a lower priority than the consumer when the tasks are
+ * spawned. */
+ xTaskCreate( vBlockingQueueConsumer, "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL );
+ xTaskCreate( vBlockingQueueProducer, "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL );
- /* Create the second two tasks as described at the top of the file. This uses
- the same mechanism but reverses the task priorities. */
+ /* Create the second two tasks as described at the top of the file. This uses
+ * the same mechanism but reverses the task priorities. */
- pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
- pxQueueParameters3->xBlockTime = xDontBlock;
- pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
+ pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( UBaseType_t ) sizeof( uint16_t ) );
+ pxQueueParameters3->xBlockTime = xDontBlock;
+ pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] );
- pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
- pxQueueParameters4->xBlockTime = xBlockTime;
- pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
+ pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters4->xQueue = pxQueueParameters3->xQueue;
+ pxQueueParameters4->xBlockTime = xBlockTime;
+ pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] );
- xTaskCreate( vBlockingQueueConsumer, "QConsB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vBlockingQueueProducer, "QProdB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
+ xTaskCreate( vBlockingQueueConsumer, "QConsB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vBlockingQueueProducer, "QProdB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL );
- /* Create the last two tasks as described above. The mechanism is again just
- the same. This time both parameter structures are given a block time. */
- pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( UBaseType_t ) sizeof( uint16_t ) );
- pxQueueParameters5->xBlockTime = xBlockTime;
- pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
+ /* Create the last two tasks as described above. The mechanism is again just
+ * the same. This time both parameter structures are given a block time. */
+ pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( UBaseType_t ) sizeof( uint16_t ) );
+ pxQueueParameters5->xBlockTime = xBlockTime;
+ pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] );
- pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
- pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
- pxQueueParameters6->xBlockTime = xBlockTime;
- pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
+ pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) );
+ pxQueueParameters6->xQueue = pxQueueParameters5->xQueue;
+ pxQueueParameters6->xBlockTime = xBlockTime;
+ pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] );
- xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vBlockingQueueProducer, "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vBlockingQueueConsumer, "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vBlockingQueueProducer, pvParameters )
{
-uint16_t usValue = 0;
-xBlockingQueueParameters *pxQueueParameters;
-short sErrorEverOccurred = pdFALSE;
-
- pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
-
- for( ;; )
- {
- if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
- {
- sErrorEverOccurred = pdTRUE;
- }
- else
- {
- /* We have successfully posted a message, so increment the variable
- used to check we are still running. */
- if( sErrorEverOccurred == pdFALSE )
- {
- ( *pxQueueParameters->psCheckVariable )++;
- }
-
- /* Increment the variable we are going to post next time round. The
- consumer will expect the numbers to follow in numerical order. */
- ++usValue;
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
- }
- }
+ uint16_t usValue = 0;
+ xBlockingQueueParameters * pxQueueParameters;
+ short sErrorEverOccurred = pdFALSE;
+
+ pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
+
+ for( ; ; )
+ {
+ if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
+ {
+ sErrorEverOccurred = pdTRUE;
+ }
+ else
+ {
+ /* We have successfully posted a message, so increment the variable
+ * used to check we are still running. */
+ if( sErrorEverOccurred == pdFALSE )
+ {
+ ( *pxQueueParameters->psCheckVariable )++;
+ }
+
+ /* Increment the variable we are going to post next time round. The
+ * consumer will expect the numbers to follow in numerical order. */
+ ++usValue;
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ }
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vBlockingQueueConsumer, pvParameters )
{
-uint16_t usData, usExpectedValue = 0;
-xBlockingQueueParameters *pxQueueParameters;
-short sErrorEverOccurred = pdFALSE;
-
- pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
-
- for( ;; )
- {
- if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
- {
- if( usData != usExpectedValue )
- {
- /* Catch-up. */
- usExpectedValue = usData;
-
- sErrorEverOccurred = pdTRUE;
- }
- else
- {
- /* We have successfully received a message, so increment the
- variable used to check we are still running. */
- if( sErrorEverOccurred == pdFALSE )
- {
- ( *pxQueueParameters->psCheckVariable )++;
- }
-
- /* Increment the value we expect to remove from the queue next time
- round. */
- ++usExpectedValue;
- }
-
- #if configUSE_PREEMPTION == 0
- {
- if( pxQueueParameters->xBlockTime == 0 )
- {
- taskYIELD();
- }
- }
- #endif
- }
- }
+ uint16_t usData, usExpectedValue = 0;
+ xBlockingQueueParameters * pxQueueParameters;
+ short sErrorEverOccurred = pdFALSE;
+
+ pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
+
+ for( ; ; )
+ {
+ if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
+ {
+ if( usData != usExpectedValue )
+ {
+ /* Catch-up. */
+ usExpectedValue = usData;
+
+ sErrorEverOccurred = pdTRUE;
+ }
+ else
+ {
+ /* We have successfully received a message, so increment the
+ * variable used to check we are still running. */
+ if( sErrorEverOccurred == pdFALSE )
+ {
+ ( *pxQueueParameters->psCheckVariable )++;
+ }
+
+ /* Increment the value we expect to remove from the queue next time
+ * round. */
+ ++usExpectedValue;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ {
+ if( pxQueueParameters->xBlockTime == 0 )
+ {
+ taskYIELD();
+ }
+ }
+ #endif
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreBlockingQueuesStillRunning( void )
{
-static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
-static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
-BaseType_t xReturn = pdPASS, xTasks;
-
- /* Not too worried about mutual exclusion on these variables as they are 16
- bits and we are only reading them. We also only care to see if they have
- changed or not.
-
- Loop through each check variable to and return pdFALSE if any are found not
- to have changed since the last call. */
-
- for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
- {
- if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
- {
- xReturn = pdFALSE;
- }
- sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
-
-
- if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
- {
- xReturn = pdFALSE;
- }
- sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
- }
-
- return xReturn;
+ static short sLastBlockingConsumerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
+ static short sLastBlockingProducerCount[ blckqNUM_TASK_SETS ] = { ( uint16_t ) 0, ( uint16_t ) 0, ( uint16_t ) 0 };
+ BaseType_t xReturn = pdPASS, xTasks;
+
+ /* Not too worried about mutual exclusion on these variables as they are 16
+ * bits and we are only reading them. We also only care to see if they have
+ * changed or not.
+ *
+ * Loop through each check variable to and return pdFALSE if any are found not
+ * to have changed since the last call. */
+
+ for( xTasks = 0; xTasks < blckqNUM_TASK_SETS; xTasks++ )
+ {
+ if( sBlockingConsumerCount[ xTasks ] == sLastBlockingConsumerCount[ xTasks ] )
+ {
+ xReturn = pdFALSE;
+ }
+
+ sLastBlockingConsumerCount[ xTasks ] = sBlockingConsumerCount[ xTasks ];
+
+ if( sBlockingProducerCount[ xTasks ] == sLastBlockingProducerCount[ xTasks ] )
+ {
+ xReturn = pdFALSE;
+ }
+
+ sLastBlockingProducerCount[ xTasks ] = sBlockingProducerCount[ xTasks ];
+ }
+
+ return xReturn;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c b/FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c
index 978b8f45e..50696dd4a 100644
--- a/FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c
+++ b/FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c
@@ -28,14 +28,14 @@
/*
-* This file contains fairly comprehensive checks on the behaviour of event
-* groups. It is not intended to be a user friendly demonstration of the
-* event groups API.
-*
-* NOTE: The tests implemented in this file are informal 'sanity' tests
-* only and are not part of the module tests that make use of the
-* mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
-*/
+ * This file contains fairly comprehensive checks on the behaviour of event
+ * groups. It is not intended to be a user friendly demonstration of the
+ * event groups API.
+ *
+ * NOTE: The tests implemented in this file are informal 'sanity' tests
+ * only and are not part of the module tests that make use of the
+ * mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
+ */
/* Scheduler include files. */
@@ -46,53 +46,53 @@
/* Demo app includes. */
#include "EventGroupsDemo.h"
-#if( INCLUDE_eTaskGetState != 1 )
- #error INCLUDE_eTaskGetState must be set to 1 in FreeRTOSConfig.h to use this demo file.
+#if ( INCLUDE_eTaskGetState != 1 )
+ #error INCLUDE_eTaskGetState must be set to 1 in FreeRTOSConfig.h to use this demo file.
#endif
/* Priorities used by the tasks. */
-#define ebSET_BIT_TASK_PRIORITY ( tskIDLE_PRIORITY )
-#define ebWAIT_BIT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
+#define ebSET_BIT_TASK_PRIORITY ( tskIDLE_PRIORITY )
+#define ebWAIT_BIT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Generic bit definitions. */
-#define ebBIT_0 ( 0x01 )
-#define ebBIT_1 ( 0x02 )
-#define ebBIT_2 ( 0x04 )
-#define ebBIT_3 ( 0x08 )
-#define ebBIT_4 ( 0x10 )
-#define ebBIT_5 ( 0x20 )
-#define ebBIT_6 ( 0x40 )
-#define ebBIT_7 ( 0x80 )
+#define ebBIT_0 ( 0x01 )
+#define ebBIT_1 ( 0x02 )
+#define ebBIT_2 ( 0x04 )
+#define ebBIT_3 ( 0x08 )
+#define ebBIT_4 ( 0x10 )
+#define ebBIT_5 ( 0x20 )
+#define ebBIT_6 ( 0x40 )
+#define ebBIT_7 ( 0x80 )
/* Combinations of bits used in the demo. */
-#define ebCOMBINED_BITS ( ebBIT_1 | ebBIT_5 | ebBIT_7 )
-#define ebALL_BITS ( ebBIT_0 | ebBIT_1 | ebBIT_2 | ebBIT_3 | ebBIT_4 | ebBIT_5 | ebBIT_6 | ebBIT_7 )
+#define ebCOMBINED_BITS ( ebBIT_1 | ebBIT_5 | ebBIT_7 )
+#define ebALL_BITS ( ebBIT_0 | ebBIT_1 | ebBIT_2 | ebBIT_3 | ebBIT_4 | ebBIT_5 | ebBIT_6 | ebBIT_7 )
/* Associate a bit to each task. These bits are used to identify all the tasks
-that synchronise with the xEventGroupSync() function. */
-#define ebSET_BIT_TASK_SYNC_BIT ebBIT_0
-#define ebWAIT_BIT_TASK_SYNC_BIT ebBIT_1
-#define ebRENDESVOUS_TASK_1_SYNC_BIT ebBIT_2
-#define ebRENDESVOUS_TASK_2_SYNC_BIT ebBIT_3
-#define ebALL_SYNC_BITS ( ebSET_BIT_TASK_SYNC_BIT | ebWAIT_BIT_TASK_SYNC_BIT | ebRENDESVOUS_TASK_1_SYNC_BIT | ebRENDESVOUS_TASK_2_SYNC_BIT )
+ * that synchronise with the xEventGroupSync() function. */
+#define ebSET_BIT_TASK_SYNC_BIT ebBIT_0
+#define ebWAIT_BIT_TASK_SYNC_BIT ebBIT_1
+#define ebRENDESVOUS_TASK_1_SYNC_BIT ebBIT_2
+#define ebRENDESVOUS_TASK_2_SYNC_BIT ebBIT_3
+#define ebALL_SYNC_BITS ( ebSET_BIT_TASK_SYNC_BIT | ebWAIT_BIT_TASK_SYNC_BIT | ebRENDESVOUS_TASK_1_SYNC_BIT | ebRENDESVOUS_TASK_2_SYNC_BIT )
/* A block time of zero simply means "don't block". */
-#define ebDONT_BLOCK ( 0 )
+#define ebDONT_BLOCK ( 0 )
/* A 5ms delay. */
-#define ebSHORT_DELAY pdMS_TO_TICKS( ( TickType_t ) 5 )
+#define ebSHORT_DELAY pdMS_TO_TICKS( ( TickType_t ) 5 )
/* Used in the selective bits test which checks no, one or both tasks blocked on
-event bits in a group are unblocked as appropriate as different bits get set. */
-#define ebSELECTIVE_BITS_1 0x03
-#define ebSELECTIVE_BITS_2 0x05
+ * event bits in a group are unblocked as appropriate as different bits get set. */
+#define ebSELECTIVE_BITS_1 0x03
+#define ebSELECTIVE_BITS_2 0x05
#ifndef ebRENDESVOUS_TEST_TASK_STACK_SIZE
- #define ebRENDESVOUS_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define ebRENDESVOUS_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
#ifndef ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE
- #define ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
/*-----------------------------------------------------------*/
@@ -116,27 +116,29 @@ event bits in a group are unblocked as appropriate as different bits get set. */
*
* 3) Calls prvPerformTaskSyncTests() to test task synchronisation behaviour.
*/
-static void prvTestMasterTask( void *pvParameters );
+static void prvTestMasterTask( void * pvParameters );
/*
* A helper task that enables the 'test master' task to perform several
* behavioural tests. See the comments above the prvTestMasterTask() prototype
* above.
*/
-static void prvTestSlaveTask( void *pvParameters );
+static void prvTestSlaveTask( void * pvParameters );
/*
* The part of the test that is performed between the 'test master' task and the
* 'test slave' task to test the behaviour when the slave blocks on various
* event bit combinations.
*/
-static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle );
+static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError,
+ TaskHandle_t xTestSlaveTaskHandle );
/*
* The part of the test that uses all the tasks to test the task synchronisation
* behaviour.
*/
-static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle );
+static BaseType_t prvPerformTaskSyncTests( BaseType_t xError,
+ TaskHandle_t xTestSlaveTaskHandle );
/*
* Two instances of prvSyncTask() are created. They start by calling
@@ -144,7 +146,7 @@ static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTest
* executing the prvSelectiveBitsTestMasterFunction() function. They then loop
* to test the task synchronisation (rendezvous) behaviour.
*/
-static void prvSyncTask( void *pvParameters );
+static void prvSyncTask( void * pvParameters );
/*
* Functions used in a test that blocks two tasks on various different bits
@@ -157,7 +159,7 @@ static void prvSelectiveBitsTestSlaveFunction( void );
/*-----------------------------------------------------------*/
/* Variables that are incremented by the tasks on each cycle provided no errors
-have been found. Used to detect an error or stall in the test cycling. */
+ * have been found. Used to detect an error or stall in the test cycling. */
static volatile uint32_t ulTestMasterCycles = 0, ulTestSlaveCycles = 0, ulISRCycles = 0;
/* The event group used by all the task based tests. */
@@ -173,887 +175,885 @@ static TaskHandle_t xSyncTask1 = NULL, xSyncTask2 = NULL;
void vStartEventGroupTasks( void )
{
-TaskHandle_t xTestSlaveTaskHandle;
-
- /*
- * This file contains fairly comprehensive checks on the behaviour of event
- * groups. It is not intended to be a user friendly demonstration of the
- * event groups API.
- *
- * NOTE: The tests implemented in this file are informal 'sanity' tests
- * only and are not part of the module tests that make use of the
- * mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
- *
- * Create the test tasks as described at the top of this file.
- */
- xTaskCreate( prvTestSlaveTask, "WaitO", ebRENDESVOUS_TEST_TASK_STACK_SIZE, NULL, ebWAIT_BIT_TASK_PRIORITY, &xTestSlaveTaskHandle );
- xTaskCreate( prvTestMasterTask, "SetB", ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE, ( void * ) xTestSlaveTaskHandle, ebSET_BIT_TASK_PRIORITY, NULL );
- xTaskCreate( prvSyncTask, "Rndv", ebRENDESVOUS_TEST_TASK_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_1_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask1 );
- xTaskCreate( prvSyncTask, "Rndv", ebRENDESVOUS_TEST_TASK_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_2_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask2 );
-
- /* If the last task was created then the others will have been too. */
- configASSERT( xSyncTask2 );
-
- /* Create the event group used by the ISR tests. The event group used by
- the tasks is created by the tasks themselves. */
- xISREventGroup = xEventGroupCreate();
- configASSERT( xISREventGroup );
+ TaskHandle_t xTestSlaveTaskHandle;
+
+ /*
+ * This file contains fairly comprehensive checks on the behaviour of event
+ * groups. It is not intended to be a user friendly demonstration of the
+ * event groups API.
+ *
+ * NOTE: The tests implemented in this file are informal 'sanity' tests
+ * only and are not part of the module tests that make use of the
+ * mtCOVERAGE_TEST_MARKER macro within the event groups implementation.
+ *
+ * Create the test tasks as described at the top of this file.
+ */
+ xTaskCreate( prvTestSlaveTask, "WaitO", ebRENDESVOUS_TEST_TASK_STACK_SIZE, NULL, ebWAIT_BIT_TASK_PRIORITY, &xTestSlaveTaskHandle );
+ xTaskCreate( prvTestMasterTask, "SetB", ebEVENT_GROUP_SET_BITS_TEST_TASK_STACK_SIZE, ( void * ) xTestSlaveTaskHandle, ebSET_BIT_TASK_PRIORITY, NULL );
+ xTaskCreate( prvSyncTask, "Rndv", ebRENDESVOUS_TEST_TASK_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_1_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask1 );
+ xTaskCreate( prvSyncTask, "Rndv", ebRENDESVOUS_TEST_TASK_STACK_SIZE, ( void * ) ebRENDESVOUS_TASK_2_SYNC_BIT, ebWAIT_BIT_TASK_PRIORITY, &xSyncTask2 );
+
+ /* If the last task was created then the others will have been too. */
+ configASSERT( xSyncTask2 );
+
+ /* Create the event group used by the ISR tests. The event group used by
+ * the tasks is created by the tasks themselves. */
+ xISREventGroup = xEventGroupCreate();
+ configASSERT( xISREventGroup );
}
/*-----------------------------------------------------------*/
-static void prvTestMasterTask( void *pvParameters )
+static void prvTestMasterTask( void * pvParameters )
{
-BaseType_t xError;
+ BaseType_t xError;
/* The handle to the slave task is passed in as the task parameter. */
-TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
-
- /* Avoid compiler warnings. */
- ( void ) pvParameters;
-
- /* Create the event group used by the tasks ready for the initial tests. */
- xEventGroup = xEventGroupCreate();
- configASSERT( xEventGroup );
-
- /* Perform the tests that block two tasks on different combinations of bits,
- then set each bit in turn and check the correct tasks unblock at the correct
- times. */
- xError = prvSelectiveBitsTestMasterFunction();
-
- for( ;; )
- {
- /* Recreate the event group ready for the next cycle. */
- xEventGroup = xEventGroupCreate();
- configASSERT( xEventGroup );
-
- /* Perform the tests that check the behaviour when a single task is
- blocked on various combinations of event bits. */
- xError = prvBitCombinationTestMasterFunction( xError, xTestSlaveTaskHandle );
-
- /* Perform the task synchronisation tests. */
- xError = prvPerformTaskSyncTests( xError, xTestSlaveTaskHandle );
-
- /* Delete the event group. */
- vEventGroupDelete( xEventGroup );
-
- /* Now all the other tasks should have completed and suspended
- themselves ready for the next go around the loop. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask1 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- /* Only increment the cycle variable if no errors have been detected. */
- if( xError == pdFALSE )
- {
- ulTestMasterCycles++;
- }
-
- configASSERT( xError == pdFALSE );
- }
+ TaskHandle_t xTestSlaveTaskHandle = ( TaskHandle_t ) pvParameters;
+
+ /* Avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Create the event group used by the tasks ready for the initial tests. */
+ xEventGroup = xEventGroupCreate();
+ configASSERT( xEventGroup );
+
+ /* Perform the tests that block two tasks on different combinations of bits,
+ * then set each bit in turn and check the correct tasks unblock at the correct
+ * times. */
+ xError = prvSelectiveBitsTestMasterFunction();
+
+ for( ; ; )
+ {
+ /* Recreate the event group ready for the next cycle. */
+ xEventGroup = xEventGroupCreate();
+ configASSERT( xEventGroup );
+
+ /* Perform the tests that check the behaviour when a single task is
+ * blocked on various combinations of event bits. */
+ xError = prvBitCombinationTestMasterFunction( xError, xTestSlaveTaskHandle );
+
+ /* Perform the task synchronisation tests. */
+ xError = prvPerformTaskSyncTests( xError, xTestSlaveTaskHandle );
+
+ /* Delete the event group. */
+ vEventGroupDelete( xEventGroup );
+
+ /* Now all the other tasks should have completed and suspended
+ * themselves ready for the next go around the loop. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask1 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Only increment the cycle variable if no errors have been detected. */
+ if( xError == pdFALSE )
+ {
+ ulTestMasterCycles++;
+ }
+
+ configASSERT( xError == pdFALSE );
+ }
}
/*-----------------------------------------------------------*/
-static void prvSyncTask( void *pvParameters )
+static void prvSyncTask( void * pvParameters )
{
-EventBits_t uxSynchronisationBit, uxReturned;
-
- /* A few tests that check the behaviour when two tasks are blocked on
- various different bits within an event group are performed before this task
- enters its infinite loop to carry out its main demo function. */
- prvSelectiveBitsTestSlaveFunction();
-
- /* The bit to use to indicate this task is at the synchronisation point is
- passed in as the task parameter. */
- uxSynchronisationBit = ( EventBits_t ) pvParameters;
-
- for( ;; )
- {
- /* Now this task takes part in a task synchronisation - sometimes known
- as a 'rendezvous'. Its execution pattern is controlled by the 'test
- master' task, which is responsible for taking this task out of the
- Suspended state when it is time to test the synchronisation behaviour.
- See: http://www.freertos.org/xEventGroupSync.html. */
- vTaskSuspend( NULL );
-
- /* Set the bit that indicates this task is at the synchronisation
- point. The first time this is done the 'test master' task has a lower
- priority than this task so this task will get to the sync point before
- the set bits task - test this by calling xEventGroupSync() with a zero
- block time before calling again with a max delay - the first call should
- return before the rendezvous completes, the second only after the
- rendezvous is complete. */
- uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
- uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
- ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
- ebDONT_BLOCK ); /* The maximum time to wait for the sync condition to be met before giving up. */
-
- /* No block time was specified, so as per the comments above, the
- rendezvous is not expected to have completed yet. */
- configASSERT( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS );
-
- uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
- uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
- ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
- portMAX_DELAY );/* The maximum time to wait for the sync condition to be met before giving up. */
-
- /* A max delay was used, so this task should only exit the above
- function call when the sync condition is met. Check this is the
- case. */
- configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
-
- /* Remove compiler warning if configASSERT() is not defined. */
- ( void ) uxReturned;
-
- /* Wait until the 'test master' task unsuspends this task again. */
- vTaskSuspend( NULL );
-
- /* Set the bit that indicates this task is at the synchronisation
- point again. This time the 'test master' task has a higher priority
- than this task so will get to the sync point before this task. */
- uxReturned = xEventGroupSync( xEventGroup, uxSynchronisationBit, ebALL_SYNC_BITS, portMAX_DELAY );
-
- /* Again a max delay was used, so this task should only exit the above
- function call when the sync condition is met. Check this is the
- case. */
- configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
-
- /* Block on the event group again. This time the event group is going
- to be deleted while this task is blocked on it so it is expected that 0
- be returned. */
- uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
- configASSERT( uxReturned == 0 );
- }
+ EventBits_t uxSynchronisationBit, uxReturned;
+
+ /* A few tests that check the behaviour when two tasks are blocked on
+ * various different bits within an event group are performed before this task
+ * enters its infinite loop to carry out its main demo function. */
+ prvSelectiveBitsTestSlaveFunction();
+
+ /* The bit to use to indicate this task is at the synchronisation point is
+ * passed in as the task parameter. */
+ uxSynchronisationBit = ( EventBits_t ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Now this task takes part in a task synchronisation - sometimes known
+ * as a 'rendezvous'. Its execution pattern is controlled by the 'test
+ * master' task, which is responsible for taking this task out of the
+ * Suspended state when it is time to test the synchronisation behaviour.
+ * See: http://www.freertos.org/xEventGroupSync.html. */
+ vTaskSuspend( NULL );
+
+ /* Set the bit that indicates this task is at the synchronisation
+ * point. The first time this is done the 'test master' task has a lower
+ * priority than this task so this task will get to the sync point before
+ * the set bits task - test this by calling xEventGroupSync() with a zero
+ * block time before calling again with a max delay - the first call should
+ * return before the rendezvous completes, the second only after the
+ * rendezvous is complete. */
+ uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
+ uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
+ ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
+ ebDONT_BLOCK ); /* The maximum time to wait for the sync condition to be met before giving up. */
+
+ /* No block time was specified, so as per the comments above, the
+ * rendezvous is not expected to have completed yet. */
+ configASSERT( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS );
+
+ uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
+ uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
+ ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
+ portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met before giving up. */
+
+ /* A max delay was used, so this task should only exit the above
+ * function call when the sync condition is met. Check this is the
+ * case. */
+ configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
+
+ /* Remove compiler warning if configASSERT() is not defined. */
+ ( void ) uxReturned;
+
+ /* Wait until the 'test master' task unsuspends this task again. */
+ vTaskSuspend( NULL );
+
+ /* Set the bit that indicates this task is at the synchronisation
+ * point again. This time the 'test master' task has a higher priority
+ * than this task so will get to the sync point before this task. */
+ uxReturned = xEventGroupSync( xEventGroup, uxSynchronisationBit, ebALL_SYNC_BITS, portMAX_DELAY );
+
+ /* Again a max delay was used, so this task should only exit the above
+ * function call when the sync condition is met. Check this is the
+ * case. */
+ configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
+
+ /* Block on the event group again. This time the event group is going
+ * to be deleted while this task is blocked on it so it is expected that 0
+ * be returned. */
+ uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
+ configASSERT( uxReturned == 0 );
+ }
}
/*-----------------------------------------------------------*/
-static void prvTestSlaveTask( void *pvParameters )
+static void prvTestSlaveTask( void * pvParameters )
{
-EventBits_t uxReturned;
-BaseType_t xError = pdFALSE;
-
- /* Avoid compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /**********************************************************************
- * Part 1: This section is the counterpart to the
- * prvBitCombinationTestMasterFunction() function which is called by the
- * test master task.
- ***********************************************************************
-
- This task is controller by the 'test master' task (which is
- implemented by prvTestMasterTask()). Suspend until resumed by the
- 'test master' task. */
- vTaskSuspend( NULL );
-
- /* Wait indefinitely for one of the bits in ebCOMBINED_BITS to get
- set. Clear the bit on exit. */
- uxReturned = xEventGroupWaitBits( xEventGroup, /* The event group that contains the event bits being queried. */
- ebBIT_1, /* The bit to wait for. */
- pdTRUE, /* Clear the bit on exit. */
- pdTRUE, /* Wait for all the bits (only one in this case anyway). */
- portMAX_DELAY ); /* Block indefinitely to wait for the condition to be met. */
-
- /* The 'test master' task set all the bits defined by ebCOMBINED_BITS,
- only one of which was being waited for by this task. The return value
- shows the state of the event bits when the task was unblocked, however
- because the task was waiting for ebBIT_1 and 'clear on exit' was set to
- the current state of the event bits will have ebBIT_1 clear. */
- if( uxReturned != ebCOMBINED_BITS )
- {
- xError = pdTRUE;
- }
-
- /* Now call xEventGroupWaitBits() again, this time waiting for all the
- bits in ebCOMBINED_BITS to be set. This call should block until the
- 'test master' task sets ebBIT_1 - which was the bit cleared in the call
- to xEventGroupWaitBits() above. */
- uxReturned = xEventGroupWaitBits( xEventGroup,
- ebCOMBINED_BITS, /* The bits being waited on. */
- pdFALSE, /* Don't clear the bits on exit. */
- pdTRUE, /* All the bits must be set to unblock. */
- portMAX_DELAY );
-
- /* Were all the bits set? */
- if( ( uxReturned & ebCOMBINED_BITS ) != ebCOMBINED_BITS )
- {
- xError = pdTRUE;
- }
-
- /* Suspend again to wait for the 'test master' task. */
- vTaskSuspend( NULL );
-
- /* Now call xEventGroupWaitBits() again, again waiting for all the bits
- in ebCOMBINED_BITS to be set, but this time clearing the bits when the
- task is unblocked. */
- uxReturned = xEventGroupWaitBits( xEventGroup,
- ebCOMBINED_BITS, /* The bits being waited on. */
- pdTRUE, /* Clear the bits on exit. */
- pdTRUE, /* All the bits must be set to unblock. */
- portMAX_DELAY );
-
- /* The 'test master' task set all the bits in the event group, so that
- is the value that should have been returned. The bits defined by
- ebCOMBINED_BITS will have been clear again in the current value though
- as 'clear on exit' was set to pdTRUE. */
- if( uxReturned != ebALL_BITS )
- {
- xError = pdTRUE;
- }
-
-
-
-
-
- /**********************************************************************
- * Part 2: This section is the counterpart to the
- * prvPerformTaskSyncTests() function which is called by the
- * test master task.
- ***********************************************************************
-
-
- Once again wait for the 'test master' task to unsuspend this task
- when it is time for the next test. */
- vTaskSuspend( NULL );
-
- /* Now peform a synchronisation with all the other tasks. At this point
- the 'test master' task has the lowest priority so will get to the sync
- point after all the other synchronising tasks. */
- uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the sync. */
- ebWAIT_BIT_TASK_SYNC_BIT, /* The bit in the event group used to indicate this task is at the sync point. */
- ebALL_SYNC_BITS, /* The bits to wait for. These bits are set by the other tasks taking part in the sync. */
- portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met before giving up. */
-
- /* A sync with a max delay should only exit when all the synchronisation
- bits are set... */
- if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
- {
- xError = pdTRUE;
- }
-
- /* ...but now the synchronisation bits should be clear again. Read back
- the current value of the bits within the event group to check that is
- the case. Setting the bits to zero will return the bits previous value
- then leave all the bits clear. */
- if( xEventGroupSetBits( xEventGroup, 0x00 ) != 0 )
- {
- xError = pdTRUE;
- }
-
- /* Check the bits are indeed 0 now by simply reading then. */
- if( xEventGroupGetBits( xEventGroup ) != 0 )
- {
- xError = pdTRUE;
- }
-
- if( xError == pdFALSE )
- {
- /* This task is still cycling without finding an error. */
- ulTestSlaveCycles++;
- }
-
- vTaskSuspend( NULL );
-
- /* This time sync when the 'test master' task has the highest priority
- at the point where it sets its sync bit - so this time the 'test master'
- task will get to the sync point before this task. */
- uxReturned = xEventGroupSync( xEventGroup, ebWAIT_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
-
- /* A sync with a max delay should only exit when all the synchronisation
- bits are set... */
- if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
- {
- xError = pdTRUE;
- }
-
- /* ...but now the sync bits should be clear again. */
- if( xEventGroupSetBits( xEventGroup, 0x00 ) != 0 )
- {
- xError = pdTRUE;
- }
-
- /* Block on the event group again. This time the event group is going
- to be deleted while this task is blocked on it, so it is expected that 0
- will be returned. */
- uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
-
- if( uxReturned != 0 )
- {
- xError = pdTRUE;
- }
-
- if( xError == pdFALSE )
- {
- /* This task is still cycling without finding an error. */
- ulTestSlaveCycles++;
- }
-
- configASSERT( xError == pdFALSE );
- }
+ EventBits_t uxReturned;
+ BaseType_t xError = pdFALSE;
+
+ /* Avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /**********************************************************************
+ * Part 1: This section is the counterpart to the
+ * prvBitCombinationTestMasterFunction() function which is called by the
+ * test master task.
+ ***********************************************************************
+ *
+ * This task is controller by the 'test master' task (which is
+ * implemented by prvTestMasterTask()). Suspend until resumed by the
+ * 'test master' task. */
+ vTaskSuspend( NULL );
+
+ /* Wait indefinitely for one of the bits in ebCOMBINED_BITS to get
+ * set. Clear the bit on exit. */
+ uxReturned = xEventGroupWaitBits( xEventGroup, /* The event group that contains the event bits being queried. */
+ ebBIT_1, /* The bit to wait for. */
+ pdTRUE, /* Clear the bit on exit. */
+ pdTRUE, /* Wait for all the bits (only one in this case anyway). */
+ portMAX_DELAY ); /* Block indefinitely to wait for the condition to be met. */
+
+ /* The 'test master' task set all the bits defined by ebCOMBINED_BITS,
+ * only one of which was being waited for by this task. The return value
+ * shows the state of the event bits when the task was unblocked, however
+ * because the task was waiting for ebBIT_1 and 'clear on exit' was set to
+ * the current state of the event bits will have ebBIT_1 clear. */
+ if( uxReturned != ebCOMBINED_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Now call xEventGroupWaitBits() again, this time waiting for all the
+ * bits in ebCOMBINED_BITS to be set. This call should block until the
+ * 'test master' task sets ebBIT_1 - which was the bit cleared in the call
+ * to xEventGroupWaitBits() above. */
+ uxReturned = xEventGroupWaitBits( xEventGroup,
+ ebCOMBINED_BITS, /* The bits being waited on. */
+ pdFALSE, /* Don't clear the bits on exit. */
+ pdTRUE, /* All the bits must be set to unblock. */
+ portMAX_DELAY );
+
+ /* Were all the bits set? */
+ if( ( uxReturned & ebCOMBINED_BITS ) != ebCOMBINED_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Suspend again to wait for the 'test master' task. */
+ vTaskSuspend( NULL );
+
+ /* Now call xEventGroupWaitBits() again, again waiting for all the bits
+ * in ebCOMBINED_BITS to be set, but this time clearing the bits when the
+ * task is unblocked. */
+ uxReturned = xEventGroupWaitBits( xEventGroup,
+ ebCOMBINED_BITS, /* The bits being waited on. */
+ pdTRUE, /* Clear the bits on exit. */
+ pdTRUE, /* All the bits must be set to unblock. */
+ portMAX_DELAY );
+
+ /* The 'test master' task set all the bits in the event group, so that
+ * is the value that should have been returned. The bits defined by
+ * ebCOMBINED_BITS will have been clear again in the current value though
+ * as 'clear on exit' was set to pdTRUE. */
+ if( uxReturned != ebALL_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /**********************************************************************
+ * Part 2: This section is the counterpart to the
+ * prvPerformTaskSyncTests() function which is called by the
+ * test master task.
+ ***********************************************************************
+ *
+ *
+ * Once again wait for the 'test master' task to unsuspend this task
+ * when it is time for the next test. */
+ vTaskSuspend( NULL );
+
+ /* Now peform a synchronisation with all the other tasks. At this point
+ * the 'test master' task has the lowest priority so will get to the sync
+ * point after all the other synchronising tasks. */
+ uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the sync. */
+ ebWAIT_BIT_TASK_SYNC_BIT, /* The bit in the event group used to indicate this task is at the sync point. */
+ ebALL_SYNC_BITS, /* The bits to wait for. These bits are set by the other tasks taking part in the sync. */
+ portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met before giving up. */
+
+ /* A sync with a max delay should only exit when all the synchronisation
+ * bits are set... */
+ if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* ...but now the synchronisation bits should be clear again. Read back
+ * the current value of the bits within the event group to check that is
+ * the case. Setting the bits to zero will return the bits previous value
+ * then leave all the bits clear. */
+ if( xEventGroupSetBits( xEventGroup, 0x00 ) != 0 )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Check the bits are indeed 0 now by simply reading then. */
+ if( xEventGroupGetBits( xEventGroup ) != 0 )
+ {
+ xError = pdTRUE;
+ }
+
+ if( xError == pdFALSE )
+ {
+ /* This task is still cycling without finding an error. */
+ ulTestSlaveCycles++;
+ }
+
+ vTaskSuspend( NULL );
+
+ /* This time sync when the 'test master' task has the highest priority
+ * at the point where it sets its sync bit - so this time the 'test master'
+ * task will get to the sync point before this task. */
+ uxReturned = xEventGroupSync( xEventGroup, ebWAIT_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
+
+ /* A sync with a max delay should only exit when all the synchronisation
+ * bits are set... */
+ if( ( uxReturned & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* ...but now the sync bits should be clear again. */
+ if( xEventGroupSetBits( xEventGroup, 0x00 ) != 0 )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Block on the event group again. This time the event group is going
+ * to be deleted while this task is blocked on it, so it is expected that 0
+ * will be returned. */
+ uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
+
+ if( uxReturned != 0 )
+ {
+ xError = pdTRUE;
+ }
+
+ if( xError == pdFALSE )
+ {
+ /* This task is still cycling without finding an error. */
+ ulTestSlaveCycles++;
+ }
+
+ configASSERT( xError == pdFALSE );
+ }
}
/*-----------------------------------------------------------*/
-static BaseType_t prvPerformTaskSyncTests( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle )
+static BaseType_t prvPerformTaskSyncTests( BaseType_t xError,
+ TaskHandle_t xTestSlaveTaskHandle )
{
-EventBits_t uxBits;
-
- /* The three tasks that take part in the synchronisation (rendezvous) are
- expected to be in the suspended state at the start of the test. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask1 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- /* Try a synch with no other tasks involved. First set all the bits other
- than this task's bit. */
- xEventGroupSetBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
-
- /* Then wait on just one bit - the bit that is being set. */
- uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
- ebSET_BIT_TASK_SYNC_BIT,/* The bit set by this task when it reaches the sync point. */
- ebSET_BIT_TASK_SYNC_BIT,/* The bits to wait for - in this case it is just waiting for itself. */
- portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
-
- /* A sync with a max delay should only exit when all the synchronise
- bits are set...check that is the case. In this case there is only one
- sync bit anyway. */
- if( ( uxBits & ebSET_BIT_TASK_SYNC_BIT ) != ebSET_BIT_TASK_SYNC_BIT )
- {
- xError = pdTRUE;
- }
-
- /* ...but now the sync bits should be clear again, leaving all the other
- bits set (as only one bit was being waited for). */
- if( xEventGroupGetBits( xEventGroup ) != ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) )
- {
- xError = pdTRUE;
- }
-
- /* Clear all the bits to zero again. */
- xEventGroupClearBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
- if( xEventGroupGetBits( xEventGroup ) != 0 )
- {
- xError = pdTRUE;
- }
-
- /* Unsuspend the other tasks then check they have executed up to the
- synchronisation point. */
- vTaskResume( xTestSlaveTaskHandle );
- vTaskResume( xSyncTask1 );
- vTaskResume( xSyncTask2 );
-
- if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask1 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- /* Set this task's sync bit. */
- uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
- ebSET_BIT_TASK_SYNC_BIT,/* The bit set by this task when it reaches the sync point. */
- ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks that take part in the sync. */
- portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
-
- /* A sync with a max delay should only exit when all the synchronise
- bits are set...check that is the case. */
- if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
- {
- xError = pdTRUE;
- }
-
- /* ...but now the sync bits should be clear again. */
- if( xEventGroupGetBits( xEventGroup ) != 0 )
- {
- xError = pdTRUE;
- }
-
-
- /* The other tasks should now all be suspended again, ready for the next
- synchronisation. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask1 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
-
- /* Sync again - but this time set the last necessary bit as the
- highest priority task, rather than the lowest priority task. Unsuspend
- the other tasks then check they have executed up to the synchronisation
- point. */
- vTaskResume( xTestSlaveTaskHandle );
- vTaskResume( xSyncTask1 );
- vTaskResume( xSyncTask2 );
-
- if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask1 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- /* Raise the priority of this task above that of the other tasks. */
- vTaskPrioritySet( NULL, ebWAIT_BIT_TASK_PRIORITY + 1 );
-
- /* Set this task's sync bit. */
- uxBits = xEventGroupSync( xEventGroup, ebSET_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
-
- /* A sync with a max delay should only exit when all the synchronisation
- bits are set... */
- if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
- {
- xError = pdTRUE;
- }
-
- /* ...but now the sync bits should be clear again. */
- if( xEventGroupGetBits( xEventGroup ) != 0 )
- {
- xError = pdTRUE;
- }
-
-
- /* The other tasks should now all be in the ready state again, but not
- executed yet as this task still has a higher relative priority. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eReady )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask1 ) != eReady )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eReady )
- {
- xError = pdTRUE;
- }
-
-
- /* Reset the priority of this task back to its original value. */
- vTaskPrioritySet( NULL, ebSET_BIT_TASK_PRIORITY );
-
- /* Now all the other tasks should have reblocked on the event bits
- to test the behaviour when the event bits are deleted. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask1 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- return xError;
+ EventBits_t uxBits;
+
+ /* The three tasks that take part in the synchronisation (rendezvous) are
+ * expected to be in the suspended state at the start of the test. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask1 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Try a synch with no other tasks involved. First set all the bits other
+ * than this task's bit. */
+ xEventGroupSetBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
+
+ /* Then wait on just one bit - the bit that is being set. */
+ uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
+ ebSET_BIT_TASK_SYNC_BIT, /* The bit set by this task when it reaches the sync point. */
+ ebSET_BIT_TASK_SYNC_BIT, /* The bits to wait for - in this case it is just waiting for itself. */
+ portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
+
+ /* A sync with a max delay should only exit when all the synchronise
+ * bits are set...check that is the case. In this case there is only one
+ * sync bit anyway. */
+ if( ( uxBits & ebSET_BIT_TASK_SYNC_BIT ) != ebSET_BIT_TASK_SYNC_BIT )
+ {
+ xError = pdTRUE;
+ }
+
+ /* ...but now the sync bits should be clear again, leaving all the other
+ * bits set (as only one bit was being waited for). */
+ if( xEventGroupGetBits( xEventGroup ) != ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Clear all the bits to zero again. */
+ xEventGroupClearBits( xEventGroup, ( ebALL_SYNC_BITS & ~ebSET_BIT_TASK_SYNC_BIT ) );
+
+ if( xEventGroupGetBits( xEventGroup ) != 0 )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Unsuspend the other tasks then check they have executed up to the
+ * synchronisation point. */
+ vTaskResume( xTestSlaveTaskHandle );
+ vTaskResume( xSyncTask1 );
+ vTaskResume( xSyncTask2 );
+
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask1 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Set this task's sync bit. */
+ uxBits = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
+ ebSET_BIT_TASK_SYNC_BIT, /* The bit set by this task when it reaches the sync point. */
+ ebALL_SYNC_BITS, /* The bits to wait for - these bits are set by the other tasks that take part in the sync. */
+ portMAX_DELAY ); /* The maximum time to wait for the sync condition to be met. */
+
+ /* A sync with a max delay should only exit when all the synchronise
+ * bits are set...check that is the case. */
+ if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* ...but now the sync bits should be clear again. */
+ if( xEventGroupGetBits( xEventGroup ) != 0 )
+ {
+ xError = pdTRUE;
+ }
+
+ /* The other tasks should now all be suspended again, ready for the next
+ * synchronisation. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask1 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Sync again - but this time set the last necessary bit as the
+ * highest priority task, rather than the lowest priority task. Unsuspend
+ * the other tasks then check they have executed up to the synchronisation
+ * point. */
+ vTaskResume( xTestSlaveTaskHandle );
+ vTaskResume( xSyncTask1 );
+ vTaskResume( xSyncTask2 );
+
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask1 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Raise the priority of this task above that of the other tasks. */
+ vTaskPrioritySet( NULL, ebWAIT_BIT_TASK_PRIORITY + 1 );
+
+ /* Set this task's sync bit. */
+ uxBits = xEventGroupSync( xEventGroup, ebSET_BIT_TASK_SYNC_BIT, ebALL_SYNC_BITS, portMAX_DELAY );
+
+ /* A sync with a max delay should only exit when all the synchronisation
+ * bits are set... */
+ if( ( uxBits & ebALL_SYNC_BITS ) != ebALL_SYNC_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* ...but now the sync bits should be clear again. */
+ if( xEventGroupGetBits( xEventGroup ) != 0 )
+ {
+ xError = pdTRUE;
+ }
+
+ /* The other tasks should now all be in the ready state again, but not
+ * executed yet as this task still has a higher relative priority. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eReady )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask1 ) != eReady )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eReady )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Reset the priority of this task back to its original value. */
+ vTaskPrioritySet( NULL, ebSET_BIT_TASK_PRIORITY );
+
+ /* Now all the other tasks should have reblocked on the event bits
+ * to test the behaviour when the event bits are deleted. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask1 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ return xError;
}
/*-----------------------------------------------------------*/
-static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError, TaskHandle_t xTestSlaveTaskHandle )
+static BaseType_t prvBitCombinationTestMasterFunction( BaseType_t xError,
+ TaskHandle_t xTestSlaveTaskHandle )
{
-EventBits_t uxBits;
-
- /* Resume the other task. It will block, pending a single bit from
- within ebCOMBINED_BITS. */
- vTaskResume( xTestSlaveTaskHandle );
-
- /* Ensure the other task is blocked on the task. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- /* Set all the bits in ebCOMBINED_BITS - the 'test slave' task is only
- blocked waiting for one of them. */
- xEventGroupSetBits( xEventGroup, ebCOMBINED_BITS );
-
- /* The 'test slave' task should now have executed, clearing ebBIT_1 (the
- bit it was blocked on), then re-entered the Blocked state to wait for
- all the other bits in ebCOMBINED_BITS to be set again. First check
- ebBIT_1 is clear. */
- uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
-
- if( uxBits != ( ebCOMBINED_BITS & ~ebBIT_1 ) )
- {
- xError = pdTRUE;
- }
-
- /* Ensure the other task is still in the blocked state. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- /* Set all the bits other than ebBIT_1 - which is the bit that must be
- set before the other task unblocks. */
- xEventGroupSetBits( xEventGroup, ebALL_BITS & ~ebBIT_1 );
-
- /* Ensure all the expected bits are still set. */
- uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
-
- if( uxBits != ( ebALL_BITS & ~ebBIT_1 ) )
- {
- xError = pdTRUE;
- }
-
- /* Ensure the other task is still in the blocked state. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- /* Now also set ebBIT_1, which should unblock the other task, which will
- then suspend itself. */
- xEventGroupSetBits( xEventGroup, ebBIT_1 );
-
- /* Ensure the other task is suspended. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- /* The other task should not have cleared the bits - so all the bits
- should still be set. */
- if( xEventGroupSetBits( xEventGroup, 0x00 ) != ebALL_BITS )
- {
- xError = pdTRUE;
- }
-
- /* Clear ebBIT_1 again. */
- if( xEventGroupClearBits( xEventGroup, ebBIT_1 ) != ebALL_BITS )
- {
- xError = pdTRUE;
- }
-
- /* Resume the other task - which will wait on all the ebCOMBINED_BITS
- again - this time clearing the bits when it is unblocked. */
- vTaskResume( xTestSlaveTaskHandle );
-
- /* Ensure the other task is blocked once again. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- /* Set the bit the other task is waiting for. */
- xEventGroupSetBits( xEventGroup, ebBIT_1 );
-
- /* Ensure the other task is suspended once again. */
- if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- /* The other task should have cleared the bits in ebCOMBINED_BITS.
- Clear the remaining bits. */
- uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
-
- if( uxBits != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
- {
- xError = pdTRUE;
- }
-
- /* Clear all bits ready for the sync with the other three tasks. The
- value returned is the value prior to the bits being cleared. */
- if( xEventGroupClearBits( xEventGroup, ebALL_BITS ) != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
- {
- xError = pdTRUE;
- }
-
- /* The bits should be clear now. */
- if( xEventGroupGetBits( xEventGroup ) != 0x00 )
- {
- xError = pdTRUE;
- }
-
- return xError;
+ EventBits_t uxBits;
+
+ /* Resume the other task. It will block, pending a single bit from
+ * within ebCOMBINED_BITS. */
+ vTaskResume( xTestSlaveTaskHandle );
+
+ /* Ensure the other task is blocked on the task. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Set all the bits in ebCOMBINED_BITS - the 'test slave' task is only
+ * blocked waiting for one of them. */
+ xEventGroupSetBits( xEventGroup, ebCOMBINED_BITS );
+
+ /* The 'test slave' task should now have executed, clearing ebBIT_1 (the
+ * bit it was blocked on), then re-entered the Blocked state to wait for
+ * all the other bits in ebCOMBINED_BITS to be set again. First check
+ * ebBIT_1 is clear. */
+ uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
+
+ if( uxBits != ( ebCOMBINED_BITS & ~ebBIT_1 ) )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Ensure the other task is still in the blocked state. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Set all the bits other than ebBIT_1 - which is the bit that must be
+ * set before the other task unblocks. */
+ xEventGroupSetBits( xEventGroup, ebALL_BITS & ~ebBIT_1 );
+
+ /* Ensure all the expected bits are still set. */
+ uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
+
+ if( uxBits != ( ebALL_BITS & ~ebBIT_1 ) )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Ensure the other task is still in the blocked state. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Now also set ebBIT_1, which should unblock the other task, which will
+ * then suspend itself. */
+ xEventGroupSetBits( xEventGroup, ebBIT_1 );
+
+ /* Ensure the other task is suspended. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ /* The other task should not have cleared the bits - so all the bits
+ * should still be set. */
+ if( xEventGroupSetBits( xEventGroup, 0x00 ) != ebALL_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Clear ebBIT_1 again. */
+ if( xEventGroupClearBits( xEventGroup, ebBIT_1 ) != ebALL_BITS )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Resume the other task - which will wait on all the ebCOMBINED_BITS
+ * again - this time clearing the bits when it is unblocked. */
+ vTaskResume( xTestSlaveTaskHandle );
+
+ /* Ensure the other task is blocked once again. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Set the bit the other task is waiting for. */
+ xEventGroupSetBits( xEventGroup, ebBIT_1 );
+
+ /* Ensure the other task is suspended once again. */
+ if( eTaskGetState( xTestSlaveTaskHandle ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ /* The other task should have cleared the bits in ebCOMBINED_BITS.
+ * Clear the remaining bits. */
+ uxBits = xEventGroupWaitBits( xEventGroup, ebALL_BITS, pdFALSE, pdFALSE, ebDONT_BLOCK );
+
+ if( uxBits != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Clear all bits ready for the sync with the other three tasks. The
+ * value returned is the value prior to the bits being cleared. */
+ if( xEventGroupClearBits( xEventGroup, ebALL_BITS ) != ( ebALL_BITS & ~ebCOMBINED_BITS ) )
+ {
+ xError = pdTRUE;
+ }
+
+ /* The bits should be clear now. */
+ if( xEventGroupGetBits( xEventGroup ) != 0x00 )
+ {
+ xError = pdTRUE;
+ }
+
+ return xError;
}
/*-----------------------------------------------------------*/
static void prvSelectiveBitsTestSlaveFunction( void )
{
-EventBits_t uxPendBits, uxReturned;
-
- /* Used in a test that blocks two tasks on various different bits within an
- event group - then sets each bit in turn and checks that the correct tasks
- unblock at the correct times.
-
- This function is called by two different tasks - each of which will use a
- different bit. Check the task handle to see which task the function was
- called by. */
- if( xTaskGetCurrentTaskHandle() == xSyncTask1 )
- {
- uxPendBits = ebSELECTIVE_BITS_1;
- }
- else
- {
- uxPendBits = ebSELECTIVE_BITS_2;
- }
-
- for( ;; )
- {
- /* Wait until it is time to perform the next cycle of the test. The
- task is unsuspended by the tests implemented in the
- prvSelectiveBitsTestMasterFunction() function. */
- vTaskSuspend( NULL );
- uxReturned = xEventGroupWaitBits( xEventGroup, uxPendBits, pdTRUE, pdFALSE, portMAX_DELAY );
-
- if( uxReturned == ( EventBits_t ) 0 )
- {
- break;
- }
- }
+ EventBits_t uxPendBits, uxReturned;
+
+ /* Used in a test that blocks two tasks on various different bits within an
+ * event group - then sets each bit in turn and checks that the correct tasks
+ * unblock at the correct times.
+ *
+ * This function is called by two different tasks - each of which will use a
+ * different bit. Check the task handle to see which task the function was
+ * called by. */
+ if( xTaskGetCurrentTaskHandle() == xSyncTask1 )
+ {
+ uxPendBits = ebSELECTIVE_BITS_1;
+ }
+ else
+ {
+ uxPendBits = ebSELECTIVE_BITS_2;
+ }
+
+ for( ; ; )
+ {
+ /* Wait until it is time to perform the next cycle of the test. The
+ * task is unsuspended by the tests implemented in the
+ * prvSelectiveBitsTestMasterFunction() function. */
+ vTaskSuspend( NULL );
+ uxReturned = xEventGroupWaitBits( xEventGroup, uxPendBits, pdTRUE, pdFALSE, portMAX_DELAY );
+
+ if( uxReturned == ( EventBits_t ) 0 )
+ {
+ break;
+ }
+ }
}
/*-----------------------------------------------------------*/
static BaseType_t prvSelectiveBitsTestMasterFunction( void )
{
-BaseType_t xError = pdFALSE;
-EventBits_t uxBit;
-
- /* Used in a test that blocks two tasks on various different bits within an
- event group - then sets each bit in turn and checks that the correct tasks
- unblock at the correct times. The two other tasks (xSyncTask1 and
- xSyncTask2) call prvSelectiveBitsTestSlaveFunction() to perform their parts in
- this test.
-
- Both other tasks should start in the suspended state. */
- if( eTaskGetState( xSyncTask1 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eSuspended )
- {
- xError = pdTRUE;
- }
-
- /* Test each bit in the byte individually. */
- for( uxBit = 0x01; uxBit < 0x100; uxBit <<= 1 )
- {
- /* Resume both tasks. */
- vTaskResume( xSyncTask1 );
- vTaskResume( xSyncTask2 );
-
- /* Now both tasks should be blocked on the event group. */
- if( eTaskGetState( xSyncTask1 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- if( eTaskGetState( xSyncTask2 ) != eBlocked )
- {
- xError = pdTRUE;
- }
-
- /* Set one bit. */
- xEventGroupSetBits( xEventGroup, uxBit );
-
- /* Is the bit set in the first set of selective bits? If so the first
- sync task should have unblocked and returned to the suspended state. */
- if( ( uxBit & ebSELECTIVE_BITS_1 ) == 0 )
- {
- /* Task should not have unblocked. */
- if( eTaskGetState( xSyncTask1 ) != eBlocked )
- {
- xError = pdTRUE;
- }
- }
- else
- {
- /* Task should have unblocked and returned to the suspended state. */
- if( eTaskGetState( xSyncTask1 ) != eSuspended )
- {
- xError = pdTRUE;
- }
- }
-
- /* Same checks for the second sync task. */
- if( ( uxBit & ebSELECTIVE_BITS_2 ) == 0 )
- {
- /* Task should not have unblocked. */
- if( eTaskGetState( xSyncTask2 ) != eBlocked )
- {
- xError = pdTRUE;
- }
- }
- else
- {
- /* Task should have unblocked and returned to the suspended state. */
- if( eTaskGetState( xSyncTask2 ) != eSuspended )
- {
- xError = pdTRUE;
- }
- }
- }
-
- /* Ensure both tasks are blocked on the event group again, then delete the
- event group so the other tasks leave this portion of the test. */
- vTaskResume( xSyncTask1 );
- vTaskResume( xSyncTask2 );
-
- /* Deleting the event group is the signal that the two other tasks should
- leave the prvSelectiveBitsTestSlaveFunction() function and continue to the main
- part of their functionality. */
- vEventGroupDelete( xEventGroup );
-
- return xError;
+ BaseType_t xError = pdFALSE;
+ EventBits_t uxBit;
+
+ /* Used in a test that blocks two tasks on various different bits within an
+ * event group - then sets each bit in turn and checks that the correct tasks
+ * unblock at the correct times. The two other tasks (xSyncTask1 and
+ * xSyncTask2) call prvSelectiveBitsTestSlaveFunction() to perform their parts in
+ * this test.
+ *
+ * Both other tasks should start in the suspended state. */
+ if( eTaskGetState( xSyncTask1 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Test each bit in the byte individually. */
+ for( uxBit = 0x01; uxBit < 0x100; uxBit <<= 1 )
+ {
+ /* Resume both tasks. */
+ vTaskResume( xSyncTask1 );
+ vTaskResume( xSyncTask2 );
+
+ /* Now both tasks should be blocked on the event group. */
+ if( eTaskGetState( xSyncTask1 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ if( eTaskGetState( xSyncTask2 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+
+ /* Set one bit. */
+ xEventGroupSetBits( xEventGroup, uxBit );
+
+ /* Is the bit set in the first set of selective bits? If so the first
+ * sync task should have unblocked and returned to the suspended state. */
+ if( ( uxBit & ebSELECTIVE_BITS_1 ) == 0 )
+ {
+ /* Task should not have unblocked. */
+ if( eTaskGetState( xSyncTask1 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+ }
+ else
+ {
+ /* Task should have unblocked and returned to the suspended state. */
+ if( eTaskGetState( xSyncTask1 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+ }
+
+ /* Same checks for the second sync task. */
+ if( ( uxBit & ebSELECTIVE_BITS_2 ) == 0 )
+ {
+ /* Task should not have unblocked. */
+ if( eTaskGetState( xSyncTask2 ) != eBlocked )
+ {
+ xError = pdTRUE;
+ }
+ }
+ else
+ {
+ /* Task should have unblocked and returned to the suspended state. */
+ if( eTaskGetState( xSyncTask2 ) != eSuspended )
+ {
+ xError = pdTRUE;
+ }
+ }
+ }
+
+ /* Ensure both tasks are blocked on the event group again, then delete the
+ * event group so the other tasks leave this portion of the test. */
+ vTaskResume( xSyncTask1 );
+ vTaskResume( xSyncTask2 );
+
+ /* Deleting the event group is the signal that the two other tasks should
+ * leave the prvSelectiveBitsTestSlaveFunction() function and continue to the main
+ * part of their functionality. */
+ vEventGroupDelete( xEventGroup );
+
+ return xError;
}
/*-----------------------------------------------------------*/
void vPeriodicEventGroupsProcessing( void )
{
-static BaseType_t xCallCount = 0, xISRTestError = pdFALSE;
-const BaseType_t xSetBitCount = 100, xGetBitsCount = 200, xClearBitsCount = 300;
-const EventBits_t uxBitsToSet = 0x12U;
-EventBits_t uxReturned;
-BaseType_t xMessagePosted;
-
- /* Called periodically from the tick hook to exercise the "FromISR"
- functions. */
-
- /* Check the even group tasks were actually created. */
- configASSERT( xISREventGroup );
-
- xCallCount++;
-
- if( xCallCount == xSetBitCount )
- {
- /* All the event bits should start clear. */
- uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
- if( uxReturned != 0x00 )
- {
- xISRTestError = pdTRUE;
- }
- else
- {
- /* Set the bits. This is called from the tick hook so it is not
- necessary to use the last parameter to ensure a context switch
- occurs immediately. */
- xMessagePosted = xEventGroupSetBitsFromISR( xISREventGroup, uxBitsToSet, NULL );
- if( xMessagePosted != pdPASS )
- {
- xISRTestError = pdTRUE;
- }
- }
- }
- else if( xCallCount == xGetBitsCount )
- {
- /* Check the bits were set as expected. */
- uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
- if( uxReturned != uxBitsToSet )
- {
- xISRTestError = pdTRUE;
- }
- }
- else if( xCallCount == xClearBitsCount )
- {
- /* Clear the bits again. */
- uxReturned = ( EventBits_t ) xEventGroupClearBitsFromISR( xISREventGroup, uxBitsToSet );
-
- /* Check the message was posted. */
- if( uxReturned != pdPASS )
- {
- xISRTestError = pdTRUE;
- }
-
- /* Go back to the start. */
- xCallCount = 0;
-
- /* If no errors have been detected then increment the count of test
- cycles. */
- if( xISRTestError == pdFALSE )
- {
- ulISRCycles++;
- }
- }
- else
- {
- /* Nothing else to do. */
- }
+ static BaseType_t xCallCount = 0, xISRTestError = pdFALSE;
+ const BaseType_t xSetBitCount = 100, xGetBitsCount = 200, xClearBitsCount = 300;
+ const EventBits_t uxBitsToSet = 0x12U;
+ EventBits_t uxReturned;
+ BaseType_t xMessagePosted;
+
+ /* Called periodically from the tick hook to exercise the "FromISR"
+ * functions. */
+
+ /* Check the even group tasks were actually created. */
+ configASSERT( xISREventGroup );
+
+ xCallCount++;
+
+ if( xCallCount == xSetBitCount )
+ {
+ /* All the event bits should start clear. */
+ uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
+
+ if( uxReturned != 0x00 )
+ {
+ xISRTestError = pdTRUE;
+ }
+ else
+ {
+ /* Set the bits. This is called from the tick hook so it is not
+ * necessary to use the last parameter to ensure a context switch
+ * occurs immediately. */
+ xMessagePosted = xEventGroupSetBitsFromISR( xISREventGroup, uxBitsToSet, NULL );
+
+ if( xMessagePosted != pdPASS )
+ {
+ xISRTestError = pdTRUE;
+ }
+ }
+ }
+ else if( xCallCount == xGetBitsCount )
+ {
+ /* Check the bits were set as expected. */
+ uxReturned = xEventGroupGetBitsFromISR( xISREventGroup );
+
+ if( uxReturned != uxBitsToSet )
+ {
+ xISRTestError = pdTRUE;
+ }
+ }
+ else if( xCallCount == xClearBitsCount )
+ {
+ /* Clear the bits again. */
+ uxReturned = ( EventBits_t ) xEventGroupClearBitsFromISR( xISREventGroup, uxBitsToSet );
+
+ /* Check the message was posted. */
+ if( uxReturned != pdPASS )
+ {
+ xISRTestError = pdTRUE;
+ }
+
+ /* Go back to the start. */
+ xCallCount = 0;
+
+ /* If no errors have been detected then increment the count of test
+ * cycles. */
+ if( xISRTestError == pdFALSE )
+ {
+ ulISRCycles++;
+ }
+ }
+ else
+ {
+ /* Nothing else to do. */
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreEventGroupTasksStillRunning( void )
{
-static uint32_t ulPreviousWaitBitCycles = 0, ulPreviousSetBitCycles = 0, ulPreviousISRCycles = 0;
-BaseType_t xStatus = pdPASS;
-
- /* Check the tasks are still cycling without finding any errors. */
- if( ulPreviousSetBitCycles == ulTestMasterCycles )
- {
- xStatus = pdFAIL;
- }
- ulPreviousSetBitCycles = ulTestMasterCycles;
-
- if( ulPreviousWaitBitCycles == ulTestSlaveCycles )
- {
- xStatus = pdFAIL;
- }
- ulPreviousWaitBitCycles = ulTestSlaveCycles;
-
- if( ulPreviousISRCycles == ulISRCycles )
- {
- xStatus = pdFAIL;
- }
- ulPreviousISRCycles = ulISRCycles;
-
- return xStatus;
-}
+ static uint32_t ulPreviousWaitBitCycles = 0, ulPreviousSetBitCycles = 0, ulPreviousISRCycles = 0;
+ BaseType_t xStatus = pdPASS;
+ /* Check the tasks are still cycling without finding any errors. */
+ if( ulPreviousSetBitCycles == ulTestMasterCycles )
+ {
+ xStatus = pdFAIL;
+ }
+ ulPreviousSetBitCycles = ulTestMasterCycles;
+ if( ulPreviousWaitBitCycles == ulTestSlaveCycles )
+ {
+ xStatus = pdFAIL;
+ }
+
+ ulPreviousWaitBitCycles = ulTestSlaveCycles;
+
+ if( ulPreviousISRCycles == ulISRCycles )
+ {
+ xStatus = pdFAIL;
+ }
+
+ ulPreviousISRCycles = ulISRCycles;
+
+ return xStatus;
+}
diff --git a/FreeRTOS/Demo/Common/Minimal/GenQTest.c b/FreeRTOS/Demo/Common/Minimal/GenQTest.c
index 60b2754b8..3b32e4f8b 100644
--- a/FreeRTOS/Demo/Common/Minimal/GenQTest.c
+++ b/FreeRTOS/Demo/Common/Minimal/GenQTest.c
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * https://www.FreeRTOS.org
- * https://github.com/FreeRTOS
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -46,21 +46,21 @@
/* Demo program include files. */
#include "GenQTest.h"
-#define genqQUEUE_LENGTH ( 5 )
-#define intsemNO_BLOCK ( 0 )
-#define genqSHORT_BLOCK ( pdMS_TO_TICKS( 2 ) )
+#define genqQUEUE_LENGTH ( 5 )
+#define intsemNO_BLOCK ( 0 )
+#define genqSHORT_BLOCK ( pdMS_TO_TICKS( 2 ) )
-#define genqMUTEX_LOW_PRIORITY ( tskIDLE_PRIORITY )
-#define genqMUTEX_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
-#define genqMUTEX_MEDIUM_PRIORITY ( tskIDLE_PRIORITY + 2 )
-#define genqMUTEX_HIGH_PRIORITY ( tskIDLE_PRIORITY + 3 )
+#define genqMUTEX_LOW_PRIORITY ( tskIDLE_PRIORITY )
+#define genqMUTEX_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
+#define genqMUTEX_MEDIUM_PRIORITY ( tskIDLE_PRIORITY + 2 )
+#define genqMUTEX_HIGH_PRIORITY ( tskIDLE_PRIORITY + 3 )
#ifndef genqMUTEX_TEST_TASK_STACK_SIZE
- #define genqMUTEX_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define genqMUTEX_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
#ifndef genqGENERIC_QUEUE_TEST_TASK_STACK_SIZE
- #define genqGENERIC_QUEUE_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define genqGENERIC_QUEUE_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
/*-----------------------------------------------------------*/
@@ -70,7 +70,7 @@
* check the resultant queue order is as expected. Queue data is also
* peeked.
*/
-static void prvSendFrontAndBackTest( void *pvParameters );
+static void prvSendFrontAndBackTest( void * pvParameters );
/*
* The following three tasks are used to demonstrate the mutex behaviour.
@@ -86,9 +86,9 @@ static void prvSendFrontAndBackTest( void *pvParameters );
* low priority, and is therefore immediately preempted by first the high
* priority task and then the medium priority task before it can continue.
*/
-static void prvLowPriorityMutexTask( void *pvParameters );
-static void prvMediumPriorityMutexTask( void *pvParameters );
-static void prvHighPriorityMutexTask( void *pvParameters );
+static void prvLowPriorityMutexTask( void * pvParameters );
+static void prvMediumPriorityMutexTask( void * pvParameters );
+static void prvHighPriorityMutexTask( void * pvParameters );
/*
* Tests the behaviour when a low priority task inherits the priority of a
@@ -96,29 +96,31 @@ static void prvHighPriorityMutexTask( void *pvParameters );
* first the same order as the two mutexes were obtained, and second the
* opposite order as the two mutexes were obtained.
*/
-static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex );
-static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex );
+static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex,
+ SemaphoreHandle_t xLocalMutex );
+static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex,
+ SemaphoreHandle_t xLocalMutex );
-#if( INCLUDE_xTaskAbortDelay == 1 )
+#if ( INCLUDE_xTaskAbortDelay == 1 )
- #if( configUSE_PREEMPTION == 0 )
- #error The additional tests included when INCLUDE_xTaskAbortDelay is 1 expect preemption to be used.
- #endif
+ #if ( configUSE_PREEMPTION == 0 )
+ #error The additional tests included when INCLUDE_xTaskAbortDelay is 1 expect preemption to be used.
+ #endif
- /* Tests the behaviour when a low priority task inherits the priority of a
- high priority task only for the high priority task to timeout before
- obtaining the mutex. */
- static void prvHighPriorityTimeout( SemaphoreHandle_t xMutex );
+/* Tests the behaviour when a low priority task inherits the priority of a
+ * high priority task only for the high priority task to timeout before
+ * obtaining the mutex. */
+ static void prvHighPriorityTimeout( SemaphoreHandle_t xMutex );
#endif
/*-----------------------------------------------------------*/
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
-detected in any of the tasks. */
+ * detected in any of the tasks. */
static volatile BaseType_t xErrorDetected = pdFALSE;
/* Counters that are incremented on each cycle of a test. This is used to
-detect a stalled task - a test that is no longer running. */
+ * detect a stalled task - a test that is no longer running. */
static volatile uint32_t ulLoopCounter = 0;
static volatile uint32_t ulLoopCounter2 = 0;
@@ -126,875 +128,886 @@ static volatile uint32_t ulLoopCounter2 = 0;
static volatile uint32_t ulGuardedVariable = 0;
/* Handles used in the mutex test to suspend and resume the high and medium
-priority mutex test tasks. */
+ * priority mutex test tasks. */
static TaskHandle_t xHighPriorityMutexTask, xMediumPriorityMutexTask;
/* If INCLUDE_xTaskAbortDelay is 1 additional tests are performed, requiring an
-additional task. */
-#if( INCLUDE_xTaskAbortDelay == 1 )
- static TaskHandle_t xSecondMediumPriorityMutexTask;
+ * additional task. */
+#if ( INCLUDE_xTaskAbortDelay == 1 )
+ static TaskHandle_t xSecondMediumPriorityMutexTask;
#endif
/* Lets the high priority semaphore task know that its wait for the semaphore
-was aborted, in which case not being able to obtain the semaphore is not to be
-considered an error. */
+ * was aborted, in which case not being able to obtain the semaphore is not to be
+ * considered an error. */
static volatile BaseType_t xBlockWasAborted = pdFALSE;
/*-----------------------------------------------------------*/
void vStartGenericQueueTasks( UBaseType_t uxPriority )
{
-QueueHandle_t xQueue;
-SemaphoreHandle_t xMutex;
-
- /* Create the queue that we are going to use for the
- prvSendFrontAndBackTest demo. */
- xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( uint32_t ) );
-
- if( xQueue != NULL )
- {
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one
- is in use. The queue registry is provided as a means for kernel aware
- debuggers to locate queues and has no purpose if a kernel aware debugger
- is not being used. The call to vQueueAddToRegistry() will be removed
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
- defined to be less than 1. */
- vQueueAddToRegistry( xQueue, "Gen_Queue_Test" );
-
- /* Create the demo task and pass it the queue just created. We are
- passing the queue handle by value so it does not matter that it is
- declared on the stack here. */
- xTaskCreate( prvSendFrontAndBackTest, "GenQ", genqGENERIC_QUEUE_TEST_TASK_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );
- }
-
- /* Create the mutex used by the prvMutexTest task. */
- xMutex = xSemaphoreCreateMutex();
-
- if( xMutex != NULL )
- {
- /* vQueueAddToRegistry() adds the mutex to the registry, if one is
- in use. The registry is provided as a means for kernel aware
- debuggers to locate mutexes and has no purpose if a kernel aware
- debugger is not being used. The call to vQueueAddToRegistry() will be
- removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
- defined or is defined to be less than 1. */
- vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Gen_Queue_Mutex" );
-
- /* Create the mutex demo tasks and pass it the mutex just created. We
- are passing the mutex handle by value so it does not matter that it is
- declared on the stack here. */
- xTaskCreate( prvLowPriorityMutexTask, "MuLow", genqMUTEX_TEST_TASK_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );
- xTaskCreate( prvMediumPriorityMutexTask, "MuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );
- xTaskCreate( prvHighPriorityMutexTask, "MuHigh", genqMUTEX_TEST_TASK_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );
-
- /* If INCLUDE_xTaskAbortDelay is set then additional tests are performed,
- requiring two instances of prvHighPriorityMutexTask(). */
- #if( INCLUDE_xTaskAbortDelay == 1 )
- {
- xTaskCreate( prvHighPriorityMutexTask, "MuHigh2", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_MEDIUM_PRIORITY, &xSecondMediumPriorityMutexTask );
- }
- #endif /* INCLUDE_xTaskAbortDelay */
- }
+ QueueHandle_t xQueue;
+ SemaphoreHandle_t xMutex;
+
+ /* Create the queue that we are going to use for the
+ * prvSendFrontAndBackTest demo. */
+ xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( uint32_t ) );
+
+ if( xQueue != NULL )
+ {
+ /* vQueueAddToRegistry() adds the queue to the queue registry, if one
+ * is in use. The queue registry is provided as a means for kernel aware
+ * debuggers to locate queues and has no purpose if a kernel aware debugger
+ * is not being used. The call to vQueueAddToRegistry() will be removed
+ * by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
+ * defined to be less than 1. */
+ vQueueAddToRegistry( xQueue, "Gen_Queue_Test" );
+
+ /* Create the demo task and pass it the queue just created. We are
+ * passing the queue handle by value so it does not matter that it is
+ * declared on the stack here. */
+ xTaskCreate( prvSendFrontAndBackTest, "GenQ", genqGENERIC_QUEUE_TEST_TASK_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );
+ }
+
+ /* Create the mutex used by the prvMutexTest task. */
+ xMutex = xSemaphoreCreateMutex();
+
+ if( xMutex != NULL )
+ {
+ /* vQueueAddToRegistry() adds the mutex to the registry, if one is
+ * in use. The registry is provided as a means for kernel aware
+ * debuggers to locate mutexes and has no purpose if a kernel aware
+ * debugger is not being used. The call to vQueueAddToRegistry() will be
+ * removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
+ * defined or is defined to be less than 1. */
+ vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Gen_Queue_Mutex" );
+
+ /* Create the mutex demo tasks and pass it the mutex just created. We
+ * are passing the mutex handle by value so it does not matter that it is
+ * declared on the stack here. */
+ xTaskCreate( prvLowPriorityMutexTask, "MuLow", genqMUTEX_TEST_TASK_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );
+ xTaskCreate( prvMediumPriorityMutexTask, "MuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );
+ xTaskCreate( prvHighPriorityMutexTask, "MuHigh", genqMUTEX_TEST_TASK_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );
+
+ /* If INCLUDE_xTaskAbortDelay is set then additional tests are performed,
+ * requiring two instances of prvHighPriorityMutexTask(). */
+ #if ( INCLUDE_xTaskAbortDelay == 1 )
+ {
+ xTaskCreate( prvHighPriorityMutexTask, "MuHigh2", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_MEDIUM_PRIORITY, &xSecondMediumPriorityMutexTask );
+ }
+ #endif /* INCLUDE_xTaskAbortDelay */
+ }
}
/*-----------------------------------------------------------*/
-static void prvSendFrontAndBackTest( void *pvParameters )
+static void prvSendFrontAndBackTest( void * pvParameters )
{
-uint32_t ulData, ulData2, ulLoopCounterSnapshot;
-QueueHandle_t xQueue;
-
- #ifdef USE_STDIO
- void vPrintDisplayMessage( const char * const * ppcMessageToSend );
-
- const char * const pcTaskStartMsg = "Queue SendToFront/SendToBack/Peek test started.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
- #endif
-
- xQueue = ( QueueHandle_t ) pvParameters;
-
- for( ;; )
- {
- /* The queue is empty, so sending an item to the back of the queue
- should have the same effect as sending it to the front of the queue.
-
- First send to the front and check everything is as expected. */
- ulLoopCounterSnapshot = ulLoopCounter;
- xQueueSendToFront( xQueue, ( void * ) &ulLoopCounterSnapshot, intsemNO_BLOCK );
-
- if( uxQueueMessagesWaiting( xQueue ) != 1 )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( xQueueReceive( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* The data we sent to the queue should equal the data we just received
- from the queue. */
- if( ulLoopCounter != ulData )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Then do the same, sending the data to the back, checking everything
- is as expected. */
- if( uxQueueMessagesWaiting( xQueue ) != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- ulLoopCounterSnapshot = ulLoopCounter;
- xQueueSendToBack( xQueue, ( void * ) &ulLoopCounterSnapshot, intsemNO_BLOCK );
-
- if( uxQueueMessagesWaiting( xQueue ) != 1 )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( xQueueReceive( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxQueueMessagesWaiting( xQueue ) != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* The data sent to the queue should equal the data just received from
- the queue. */
- if( ulLoopCounter != ulData )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
-
-
- /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */
- for( ulData = 2; ulData < 5; ulData++ )
- {
- xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
- }
-
- /* Now the order in the queue should be 2, 3, 4, with 2 being the first
- thing to be read out. Now add 1 then 0 to the front of the queue. */
- if( uxQueueMessagesWaiting( xQueue ) != 3 )
- {
- xErrorDetected = pdTRUE;
- }
- ulData = 1;
- xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
- ulData = 0;
- xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
-
- /* Now the queue should be full, and when we read the data out we
- should receive 0, 1, 2, 3, 4. */
- if( uxQueueMessagesWaiting( xQueue ) != 5 )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* Check the data we read out is in the expected order. */
- for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )
- {
- /* Try peeking the data first. */
- if( xQueuePeek( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( ulData != ulData2 )
- {
- xErrorDetected = pdTRUE;
- }
-
-
- /* Now try receiving the data for real. The value should be the
- same. Clobber the value first so we know we really received it. */
- ulData2 = ~ulData2;
- if( xQueueReceive( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( ulData != ulData2 )
- {
- xErrorDetected = pdTRUE;
- }
- }
-
- /* The queue should now be empty again. */
- if( uxQueueMessagesWaiting( xQueue ) != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
-
- /* Our queue is empty once more, add 10, 11 to the back. */
- ulData = 10;
- if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
- ulData = 11;
- if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxQueueMessagesWaiting( xQueue ) != 2 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now we should have 10, 11 in the queue. Add 7, 8, 9 to the
- front. */
- for( ulData = 9; ulData >= 7; ulData-- )
- {
- if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
- }
-
- /* Now check that the queue is full, and that receiving data provides
- the expected sequence of 7, 8, 9, 10, 11. */
- if( uxQueueMessagesWaiting( xQueue ) != 5 )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* Check the data we read out is in the expected order. */
- for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )
- {
- if( xQueueReceive( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( ulData != ulData2 )
- {
- xErrorDetected = pdTRUE;
- }
- }
-
- if( uxQueueMessagesWaiting( xQueue ) != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Increment the loop counter to indicate these tasks are still
- executing. */
- ulLoopCounter++;
- }
+ uint32_t ulData, ulData2, ulLoopCounterSnapshot;
+ QueueHandle_t xQueue;
+
+ #ifdef USE_STDIO
+ void vPrintDisplayMessage( const char * const * ppcMessageToSend );
+
+ const char * const pcTaskStartMsg = "Queue SendToFront/SendToBack/Peek test started.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+ #endif
+
+ xQueue = ( QueueHandle_t ) pvParameters;
+
+ for( ; ; )
+ {
+ /* The queue is empty, so sending an item to the back of the queue
+ * should have the same effect as sending it to the front of the queue.
+ *
+ * First send to the front and check everything is as expected. */
+ ulLoopCounterSnapshot = ulLoopCounter;
+ xQueueSendToFront( xQueue, ( void * ) &ulLoopCounterSnapshot, intsemNO_BLOCK );
+
+ if( uxQueueMessagesWaiting( xQueue ) != 1 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xQueueReceive( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* The data we sent to the queue should equal the data we just received
+ * from the queue. */
+ if( ulLoopCounter != ulData )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Then do the same, sending the data to the back, checking everything
+ * is as expected. */
+ if( uxQueueMessagesWaiting( xQueue ) != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ ulLoopCounterSnapshot = ulLoopCounter;
+ xQueueSendToBack( xQueue, ( void * ) &ulLoopCounterSnapshot, intsemNO_BLOCK );
+
+ if( uxQueueMessagesWaiting( xQueue ) != 1 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xQueueReceive( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxQueueMessagesWaiting( xQueue ) != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* The data sent to the queue should equal the data just received from
+ * the queue. */
+ if( ulLoopCounter != ulData )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */
+ for( ulData = 2; ulData < 5; ulData++ )
+ {
+ xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
+ }
+
+ /* Now the order in the queue should be 2, 3, 4, with 2 being the first
+ * thing to be read out. Now add 1 then 0 to the front of the queue. */
+ if( uxQueueMessagesWaiting( xQueue ) != 3 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ ulData = 1;
+ xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
+ ulData = 0;
+ xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK );
+
+ /* Now the queue should be full, and when we read the data out we
+ * should receive 0, 1, 2, 3, 4. */
+ if( uxQueueMessagesWaiting( xQueue ) != 5 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Check the data we read out is in the expected order. */
+ for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )
+ {
+ /* Try peeking the data first. */
+ if( xQueuePeek( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( ulData != ulData2 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now try receiving the data for real. The value should be the
+ * same. Clobber the value first so we know we really received it. */
+ ulData2 = ~ulData2;
+
+ if( xQueueReceive( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( ulData != ulData2 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+
+ /* The queue should now be empty again. */
+ if( uxQueueMessagesWaiting( xQueue ) != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+
+ /* Our queue is empty once more, add 10, 11 to the back. */
+ ulData = 10;
+
+ if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ ulData = 11;
+
+ if( xQueueSend( xQueue, &ulData, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxQueueMessagesWaiting( xQueue ) != 2 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now we should have 10, 11 in the queue. Add 7, 8, 9 to the
+ * front. */
+ for( ulData = 9; ulData >= 7; ulData-- )
+ {
+ if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+
+ /* Now check that the queue is full, and that receiving data provides
+ * the expected sequence of 7, 8, 9, 10, 11. */
+ if( uxQueueMessagesWaiting( xQueue ) != 5 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xQueueSendToFront( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xQueueSendToBack( xQueue, ( void * ) &ulData, intsemNO_BLOCK ) != errQUEUE_FULL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Check the data we read out is in the expected order. */
+ for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )
+ {
+ if( xQueueReceive( xQueue, &ulData2, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( ulData != ulData2 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+
+ if( uxQueueMessagesWaiting( xQueue ) != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Increment the loop counter to indicate these tasks are still
+ * executing. */
+ ulLoopCounter++;
+ }
}
/*-----------------------------------------------------------*/
-#if( INCLUDE_xTaskAbortDelay == 1 )
-
- static void prvHighPriorityTimeout( SemaphoreHandle_t xMutex )
- {
- static UBaseType_t uxLoopCount = 0;
-
- /* The tests in this function are very similar, the slight variations
- are for code coverage purposes. */
-
- /* Take the mutex. It should be available now. Check before and after
- taking that the holder is reported correctly. */
- if( xSemaphoreGetMutexHolder( xMutex ) != NULL )
- {
- xErrorDetected = pdTRUE;
- }
- if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
- if( xSemaphoreGetMutexHolder( xMutex ) != xTaskGetCurrentTaskHandle() )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This task's priority should be as per that assigned when the task was
- created. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now unsuspend the high priority task. This will attempt to take the
- mutex, and block when it finds it cannot obtain it. */
- vTaskResume( xHighPriorityMutexTask );
-
- /* This task should now have inherited the priority of the high priority
- task as by now the high priority task will have attempted to obtain the
- mutex. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Unblock a second medium priority task. It too will attempt to take
- the mutex and enter the Blocked state - it won't run yet though as this
- task has inherited a priority above it. */
- vTaskResume( xSecondMediumPriorityMutexTask );
-
- /* This task should still have the priority of the high priority task as
- that had already been inherited as is the highest priority of the three
- tasks using the mutex. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* On some loops, block for a short while to provide additional
- code coverage. Blocking here will allow the medium priority task to
- execute and so also block on the mutex so when the high priority task
- causes this task to disinherit the high priority it is inherited down to
- the priority of the medium priority task. When there is no delay the
- medium priority task will not run until after the disinheritance, so
- this task will disinherit back to its base priority, then only up to the
- medium priority after the medium priority has executed. */
- vTaskDelay( uxLoopCount & ( UBaseType_t ) 0x07 );
-
- /* Now force the high priority task to unblock. It will fail to obtain
- the mutex and go back to the suspended state - allowing this task to
- execute again. xBlockWasAborted is set to pdTRUE so the higher priority
- task knows that its failure to obtain the semaphore is not an error. */
- xBlockWasAborted = pdTRUE;
- if( xTaskAbortDelay( xHighPriorityMutexTask ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This task has inherited the priority of xHighPriorityMutexTask so
- could still be running even though xHighPriorityMutexTask is no longer
- blocked. Delay for a short while to ensure xHighPriorityMutexTask gets
- a chance to run - indicated by this task changing priority. It should
- disinherit the high priority task, but then inherit the priority of the
- medium priority task that is waiting for the same mutex. */
- while( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
- {
- /* If this task gets stuck here then the check variables will stop
- incrementing and the check task will detect the error. */
- vTaskDelay( genqSHORT_BLOCK );
- }
-
- /* Now force the medium priority task to unblock. xBlockWasAborted is
- set to pdTRUE so the medium priority task knows that its failure to
- obtain the semaphore is not an error. */
- xBlockWasAborted = pdTRUE;
- if( xTaskAbortDelay( xSecondMediumPriorityMutexTask ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This time no other tasks are waiting for the mutex, so this task
- should return to its base priority. This might not happen straight
- away as it is running at the same priority as the task it just
- unblocked. */
- while( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
- {
- /* If this task gets stuck here then the check variables will stop
- incrementing and the check task will detect the error. */
- vTaskDelay( genqSHORT_BLOCK );
- }
-
- /* Give the semaphore back ready for the next test. Check the mutex
- holder before and after using the "FromISR" version for code coverage. */
- if( xSemaphoreGetMutexHolderFromISR( xMutex ) != xTaskGetCurrentTaskHandle() )
- {
- xErrorDetected = pdTRUE;
- }
- xSemaphoreGive( xMutex );
- if( xSemaphoreGetMutexHolderFromISR( xMutex ) != NULL )
- {
- xErrorDetected = pdTRUE;
- }
-
- configASSERT( xErrorDetected == pdFALSE );
-
-
-
- /* Now do the same again, but this time unsuspend the tasks in the
- opposite order. This takes a different path though the code because
- when the high priority task has its block aborted there is already
- another task in the list of tasks waiting for the mutex, and the
- low priority task drops down to that priority, rather than dropping
- down to its base priority before inheriting the priority of the medium
- priority task. */
- if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This time unsuspend the medium priority task first. This will
- attempt to take the mutex, and block when it finds it cannot obtain it. */
- vTaskResume( xSecondMediumPriorityMutexTask );
-
- /* This time this task should now have inherited the priority of the
- medium task. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This time the high priority task in unsuspended second. */
- vTaskResume( xHighPriorityMutexTask );
-
- /* The high priority task should already have run, causing this task to
- inherit a priority for the second time. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This time, when the high priority task has its delay aborted and it
- fails to obtain the mutex this task will immediately have its priority
- lowered down to that of the highest priority task waiting on the mutex,
- which is the medium priority task. */
- xBlockWasAborted = pdTRUE;
- if( xTaskAbortDelay( xHighPriorityMutexTask ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- while( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
- {
- /* If this task gets stuck here then the check variables will stop
- incrementing and the check task will detect the error. */
- vTaskDelay( genqSHORT_BLOCK );
- }
-
- /* And finally, when the medium priority task also have its delay
- aborted there are no other tasks waiting for the mutex so this task
- returns to its base priority. */
- xBlockWasAborted = pdTRUE;
- if( xTaskAbortDelay( xSecondMediumPriorityMutexTask ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- while( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
- {
- /* If this task gets stuck here then the check variables will stop
- incrementing and the check task will detect the error. */
- vTaskDelay( genqSHORT_BLOCK );
- }
-
- /* Give the semaphore back ready for the next test. */
- xSemaphoreGive( xMutex );
-
- configASSERT( xErrorDetected == pdFALSE );
-
- /* uxLoopCount is used to add a variable delay, and in-so-doing provide
- additional code coverage. */
- uxLoopCount++;
- }
+#if ( INCLUDE_xTaskAbortDelay == 1 )
+
+ static void prvHighPriorityTimeout( SemaphoreHandle_t xMutex )
+ {
+ static UBaseType_t uxLoopCount = 0;
+
+ /* The tests in this function are very similar, the slight variations
+ * are for code coverage purposes. */
+
+ /* Take the mutex. It should be available now. Check before and after
+ * taking that the holder is reported correctly. */
+ if( xSemaphoreGetMutexHolder( xMutex ) != NULL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xSemaphoreGetMutexHolder( xMutex ) != xTaskGetCurrentTaskHandle() )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This task's priority should be as per that assigned when the task was
+ * created. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now unsuspend the high priority task. This will attempt to take the
+ * mutex, and block when it finds it cannot obtain it. */
+ vTaskResume( xHighPriorityMutexTask );
+
+ /* This task should now have inherited the priority of the high priority
+ * task as by now the high priority task will have attempted to obtain the
+ * mutex. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Unblock a second medium priority task. It too will attempt to take
+ * the mutex and enter the Blocked state - it won't run yet though as this
+ * task has inherited a priority above it. */
+ vTaskResume( xSecondMediumPriorityMutexTask );
+
+ /* This task should still have the priority of the high priority task as
+ * that had already been inherited as is the highest priority of the three
+ * tasks using the mutex. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* On some loops, block for a short while to provide additional
+ * code coverage. Blocking here will allow the medium priority task to
+ * execute and so also block on the mutex so when the high priority task
+ * causes this task to disinherit the high priority it is inherited down to
+ * the priority of the medium priority task. When there is no delay the
+ * medium priority task will not run until after the disinheritance, so
+ * this task will disinherit back to its base priority, then only up to the
+ * medium priority after the medium priority has executed. */
+ vTaskDelay( uxLoopCount & ( UBaseType_t ) 0x07 );
+
+ /* Now force the high priority task to unblock. It will fail to obtain
+ * the mutex and go back to the suspended state - allowing this task to
+ * execute again. xBlockWasAborted is set to pdTRUE so the higher priority
+ * task knows that its failure to obtain the semaphore is not an error. */
+ xBlockWasAborted = pdTRUE;
+
+ if( xTaskAbortDelay( xHighPriorityMutexTask ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This task has inherited the priority of xHighPriorityMutexTask so
+ * could still be running even though xHighPriorityMutexTask is no longer
+ * blocked. Delay for a short while to ensure xHighPriorityMutexTask gets
+ * a chance to run - indicated by this task changing priority. It should
+ * disinherit the high priority task, but then inherit the priority of the
+ * medium priority task that is waiting for the same mutex. */
+ while( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
+ {
+ /* If this task gets stuck here then the check variables will stop
+ * incrementing and the check task will detect the error. */
+ vTaskDelay( genqSHORT_BLOCK );
+ }
+
+ /* Now force the medium priority task to unblock. xBlockWasAborted is
+ * set to pdTRUE so the medium priority task knows that its failure to
+ * obtain the semaphore is not an error. */
+ xBlockWasAborted = pdTRUE;
+
+ if( xTaskAbortDelay( xSecondMediumPriorityMutexTask ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This time no other tasks are waiting for the mutex, so this task
+ * should return to its base priority. This might not happen straight
+ * away as it is running at the same priority as the task it just
+ * unblocked. */
+ while( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
+ {
+ /* If this task gets stuck here then the check variables will stop
+ * incrementing and the check task will detect the error. */
+ vTaskDelay( genqSHORT_BLOCK );
+ }
+
+ /* Give the semaphore back ready for the next test. Check the mutex
+ * holder before and after using the "FromISR" version for code coverage. */
+ if( xSemaphoreGetMutexHolderFromISR( xMutex ) != xTaskGetCurrentTaskHandle() )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ xSemaphoreGive( xMutex );
+
+ if( xSemaphoreGetMutexHolderFromISR( xMutex ) != NULL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ configASSERT( xErrorDetected == pdFALSE );
+
+ /* Now do the same again, but this time unsuspend the tasks in the
+ * opposite order. This takes a different path though the code because
+ * when the high priority task has its block aborted there is already
+ * another task in the list of tasks waiting for the mutex, and the
+ * low priority task drops down to that priority, rather than dropping
+ * down to its base priority before inheriting the priority of the medium
+ * priority task. */
+ if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This time unsuspend the medium priority task first. This will
+ * attempt to take the mutex, and block when it finds it cannot obtain it. */
+ vTaskResume( xSecondMediumPriorityMutexTask );
+
+ /* This time this task should now have inherited the priority of the
+ * medium task. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This time the high priority task in unsuspended second. */
+ vTaskResume( xHighPriorityMutexTask );
+
+ /* The high priority task should already have run, causing this task to
+ * inherit a priority for the second time. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This time, when the high priority task has its delay aborted and it
+ * fails to obtain the mutex this task will immediately have its priority
+ * lowered down to that of the highest priority task waiting on the mutex,
+ * which is the medium priority task. */
+ xBlockWasAborted = pdTRUE;
+
+ if( xTaskAbortDelay( xHighPriorityMutexTask ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ while( uxTaskPriorityGet( NULL ) != genqMUTEX_MEDIUM_PRIORITY )
+ {
+ /* If this task gets stuck here then the check variables will stop
+ * incrementing and the check task will detect the error. */
+ vTaskDelay( genqSHORT_BLOCK );
+ }
+
+ /* And finally, when the medium priority task also have its delay
+ * aborted there are no other tasks waiting for the mutex so this task
+ * returns to its base priority. */
+ xBlockWasAborted = pdTRUE;
+
+ if( xTaskAbortDelay( xSecondMediumPriorityMutexTask ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ while( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
+ {
+ /* If this task gets stuck here then the check variables will stop
+ * incrementing and the check task will detect the error. */
+ vTaskDelay( genqSHORT_BLOCK );
+ }
+
+ /* Give the semaphore back ready for the next test. */
+ xSemaphoreGive( xMutex );
+
+ configASSERT( xErrorDetected == pdFALSE );
+
+ /* uxLoopCount is used to add a variable delay, and in-so-doing provide
+ * additional code coverage. */
+ uxLoopCount++;
+ }
#endif /* INCLUDE_xTaskAbortDelay == 1 */
/*-----------------------------------------------------------*/
-static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex )
+static void prvTakeTwoMutexesReturnInDifferentOrder( SemaphoreHandle_t xMutex,
+ SemaphoreHandle_t xLocalMutex )
{
- /* Take the mutex. It should be available now. */
- if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Set the guarded variable to a known start value. */
- ulGuardedVariable = 0;
-
- /* This task's priority should be as per that assigned when the task was
- created. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now unsuspend the high priority task. This will attempt to take the
- mutex, and block when it finds it cannot obtain it. */
- vTaskResume( xHighPriorityMutexTask );
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* Ensure the task is reporting its priority as blocked and not
- suspended (as it would have done in versions up to V7.5.3). */
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* This task should now have inherited the priority of the high priority
- task as by now the high priority task will have attempted to obtain the
- mutex. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Attempt to set the priority of this task to the test priority -
- between the idle priority and the medium/high test priorities, but the
- actual priority should remain at the high priority. */
- vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now unsuspend the medium priority task. This should not run as the
- inherited priority of this task is above that of the medium priority
- task. */
- vTaskResume( xMediumPriorityMutexTask );
-
- /* If the medium priority task did run then it will have incremented the
- guarded variable. */
- if( ulGuardedVariable != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Take the local mutex too, so two mutexes are now held. */
- if( xSemaphoreTake( xLocalMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* When the semaphore is given back the priority of this task should not
- yet be disinherited because the local mutex is still held. This is a
- simplification to allow FreeRTOS to be integrated with middleware that
- attempts to hold multiple mutexes without bloating the code with complex
- algorithms. It is possible that the high priority mutex task will
- execute as it shares a priority with this task. */
- if( xSemaphoreGive( xMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* The guarded variable is only incremented by the medium priority task,
- which still should not have executed as this task should remain at the
- higher priority, ensure this is the case. */
- if( ulGuardedVariable != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now also give back the local mutex, taking the held count back to 0.
- This time the priority of this task should be disinherited back to the
- priority to which it was set while the mutex was held. This means
- the medium priority task should execute and increment the guarded
- variable. When this task next runs both the high and medium priority
- tasks will have been suspended again. */
- if( xSemaphoreGive( xLocalMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* Check the guarded variable did indeed increment... */
- if( ulGuardedVariable != 1 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* ... and that the priority of this task has been disinherited to
- genqMUTEX_TEST_PRIORITY. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Set the priority of this task back to its original value, ready for
- the next loop around this test. */
- vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );
+ /* Take the mutex. It should be available now. */
+ if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Set the guarded variable to a known start value. */
+ ulGuardedVariable = 0;
+
+ /* This task's priority should be as per that assigned when the task was
+ * created. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now unsuspend the high priority task. This will attempt to take the
+ * mutex, and block when it finds it cannot obtain it. */
+ vTaskResume( xHighPriorityMutexTask );
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Ensure the task is reporting its priority as blocked and not
+ * suspended (as it would have done in versions up to V7.5.3). */
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* This task should now have inherited the priority of the high priority
+ * task as by now the high priority task will have attempted to obtain the
+ * mutex. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Attempt to set the priority of this task to the test priority -
+ * between the idle priority and the medium/high test priorities, but the
+ * actual priority should remain at the high priority. */
+ vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );
+
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now unsuspend the medium priority task. This should not run as the
+ * inherited priority of this task is above that of the medium priority
+ * task. */
+ vTaskResume( xMediumPriorityMutexTask );
+
+ /* If the medium priority task did run then it will have incremented the
+ * guarded variable. */
+ if( ulGuardedVariable != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Take the local mutex too, so two mutexes are now held. */
+ if( xSemaphoreTake( xLocalMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* When the semaphore is given back the priority of this task should not
+ * yet be disinherited because the local mutex is still held. This is a
+ * simplification to allow FreeRTOS to be integrated with middleware that
+ * attempts to hold multiple mutexes without bloating the code with complex
+ * algorithms. It is possible that the high priority mutex task will
+ * execute as it shares a priority with this task. */
+ if( xSemaphoreGive( xMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* The guarded variable is only incremented by the medium priority task,
+ * which still should not have executed as this task should remain at the
+ * higher priority, ensure this is the case. */
+ if( ulGuardedVariable != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now also give back the local mutex, taking the held count back to 0.
+ * This time the priority of this task should be disinherited back to the
+ * priority to which it was set while the mutex was held. This means
+ * the medium priority task should execute and increment the guarded
+ * variable. When this task next runs both the high and medium priority
+ * tasks will have been suspended again. */
+ if( xSemaphoreGive( xLocalMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Check the guarded variable did indeed increment... */
+ if( ulGuardedVariable != 1 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* ... and that the priority of this task has been disinherited to
+ * genqMUTEX_TEST_PRIORITY. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Set the priority of this task back to its original value, ready for
+ * the next loop around this test. */
+ vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );
}
/*-----------------------------------------------------------*/
-static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex, SemaphoreHandle_t xLocalMutex )
+static void prvTakeTwoMutexesReturnInSameOrder( SemaphoreHandle_t xMutex,
+ SemaphoreHandle_t xLocalMutex )
{
- /* Take the mutex. It should be available now. */
- if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Set the guarded variable to a known start value. */
- ulGuardedVariable = 0;
-
- /* This task's priority should be as per that assigned when the task was
- created. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now unsuspend the high priority task. This will attempt to take the
- mutex, and block when it finds it cannot obtain it. */
- vTaskResume( xHighPriorityMutexTask );
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* Ensure the task is reporting its priority as blocked and not
- suspended (as it would have done in versions up to V7.5.3). */
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* This task should now have inherited the priority of the high priority
- task as by now the high priority task will have attempted to obtain the
- mutex. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now unsuspend the medium priority task. This should not run as the
- inherited priority of this task is above that of the medium priority
- task. */
- vTaskResume( xMediumPriorityMutexTask );
-
- /* If the medium priority task did run then it will have incremented the
- guarded variable. */
- if( ulGuardedVariable != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Take the local mutex too, so two mutexes are now held. */
- if( xSemaphoreTake( xLocalMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* When the local semaphore is given back the priority of this task should
- not yet be disinherited because the shared mutex is still held. This is a
- simplification to allow FreeRTOS to be integrated with middleware that
- attempts to hold multiple mutexes without bloating the code with complex
- algorithms. It is possible that the high priority mutex task will
- execute as it shares a priority with this task. */
- if( xSemaphoreGive( xLocalMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* The guarded variable is only incremented by the medium priority task,
- which still should not have executed as this task should remain at the
- higher priority, ensure this is the case. */
- if( ulGuardedVariable != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now also give back the shared mutex, taking the held count back to 0.
- This time the priority of this task should be disinherited back to the
- priority at which it was created. This means the medium priority task
- should execute and increment the guarded variable. When this task next runs
- both the high and medium priority tasks will have been suspended again. */
- if( xSemaphoreGive( xMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* Check the guarded variable did indeed increment... */
- if( ulGuardedVariable != 1 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* ... and that the priority of this task has been disinherited to
- genqMUTEX_LOW_PRIORITY. */
- if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
+ /* Take the mutex. It should be available now. */
+ if( xSemaphoreTake( xMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Set the guarded variable to a known start value. */
+ ulGuardedVariable = 0;
+
+ /* This task's priority should be as per that assigned when the task was
+ * created. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now unsuspend the high priority task. This will attempt to take the
+ * mutex, and block when it finds it cannot obtain it. */
+ vTaskResume( xHighPriorityMutexTask );
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Ensure the task is reporting its priority as blocked and not
+ * suspended (as it would have done in versions up to V7.5.3). */
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xHighPriorityMutexTask ) == eBlocked );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* This task should now have inherited the priority of the high priority
+ * task as by now the high priority task will have attempted to obtain the
+ * mutex. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now unsuspend the medium priority task. This should not run as the
+ * inherited priority of this task is above that of the medium priority
+ * task. */
+ vTaskResume( xMediumPriorityMutexTask );
+
+ /* If the medium priority task did run then it will have incremented the
+ * guarded variable. */
+ if( ulGuardedVariable != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Take the local mutex too, so two mutexes are now held. */
+ if( xSemaphoreTake( xLocalMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* When the local semaphore is given back the priority of this task should
+ * not yet be disinherited because the shared mutex is still held. This is a
+ * simplification to allow FreeRTOS to be integrated with middleware that
+ * attempts to hold multiple mutexes without bloating the code with complex
+ * algorithms. It is possible that the high priority mutex task will
+ * execute as it shares a priority with this task. */
+ if( xSemaphoreGive( xLocalMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* The guarded variable is only incremented by the medium priority task,
+ * which still should not have executed as this task should remain at the
+ * higher priority, ensure this is the case. */
+ if( ulGuardedVariable != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now also give back the shared mutex, taking the held count back to 0.
+ * This time the priority of this task should be disinherited back to the
+ * priority at which it was created. This means the medium priority task
+ * should execute and increment the guarded variable. When this task next runs
+ * both the high and medium priority tasks will have been suspended again. */
+ if( xSemaphoreGive( xMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* Check the guarded variable did indeed increment... */
+ if( ulGuardedVariable != 1 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* ... and that the priority of this task has been disinherited to
+ * genqMUTEX_LOW_PRIORITY. */
+ if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
}
/*-----------------------------------------------------------*/
-static void prvLowPriorityMutexTask( void *pvParameters )
+static void prvLowPriorityMutexTask( void * pvParameters )
{
-SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
-
- #ifdef USE_STDIO
- void vPrintDisplayMessage( const char * const * ppcMessageToSend );
-
- const char * const pcTaskStartMsg = "Mutex with priority inheritance test started.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
- #endif
-
- /* The local mutex is used to check the 'mutex held' count. */
- xLocalMutex = xSemaphoreCreateMutex();
- configASSERT( xLocalMutex );
-
- for( ;; )
- {
- /* The first tests exercise the priority inheritance when two mutexes
- are taken then returned in a different order to which they were
- taken. */
- prvTakeTwoMutexesReturnInDifferentOrder( xMutex, xLocalMutex );
-
- /* Just to show this task is still running. */
- ulLoopCounter2++;
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* The second tests exercise the priority inheritance when two mutexes
- are taken then returned in the same order in which they were taken. */
- prvTakeTwoMutexesReturnInSameOrder( xMutex, xLocalMutex );
-
- /* Just to show this task is still running. */
- ulLoopCounter2++;
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- #if( INCLUDE_xTaskAbortDelay == 1 )
- {
- /* Tests the behaviour when a low priority task inherits the
- priority of a high priority task only for the high priority task to
- timeout before obtaining the mutex. */
- prvHighPriorityTimeout( xMutex );
- }
- #endif
- }
+ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters, xLocalMutex;
+
+ #ifdef USE_STDIO
+ void vPrintDisplayMessage( const char * const * ppcMessageToSend );
+
+ const char * const pcTaskStartMsg = "Mutex with priority inheritance test started.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+ #endif
+
+ /* The local mutex is used to check the 'mutex held' count. */
+ xLocalMutex = xSemaphoreCreateMutex();
+ configASSERT( xLocalMutex );
+
+ for( ; ; )
+ {
+ /* The first tests exercise the priority inheritance when two mutexes
+ * are taken then returned in a different order to which they were
+ * taken. */
+ prvTakeTwoMutexesReturnInDifferentOrder( xMutex, xLocalMutex );
+
+ /* Just to show this task is still running. */
+ ulLoopCounter2++;
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* The second tests exercise the priority inheritance when two mutexes
+ * are taken then returned in the same order in which they were taken. */
+ prvTakeTwoMutexesReturnInSameOrder( xMutex, xLocalMutex );
+
+ /* Just to show this task is still running. */
+ ulLoopCounter2++;
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ #if ( INCLUDE_xTaskAbortDelay == 1 )
+ {
+ /* Tests the behaviour when a low priority task inherits the
+ * priority of a high priority task only for the high priority task to
+ * timeout before obtaining the mutex. */
+ prvHighPriorityTimeout( xMutex );
+ }
+ #endif
+ }
}
/*-----------------------------------------------------------*/
-static void prvMediumPriorityMutexTask( void *pvParameters )
+static void prvMediumPriorityMutexTask( void * pvParameters )
{
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* The medium priority task starts by suspending itself. The low
- priority task will unsuspend this task when required. */
- vTaskSuspend( NULL );
-
- /* When this task unsuspends all it does is increment the guarded
- variable, this is so the low priority task knows that it has
- executed. */
- ulGuardedVariable++;
- }
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* The medium priority task starts by suspending itself. The low
+ * priority task will unsuspend this task when required. */
+ vTaskSuspend( NULL );
+
+ /* When this task unsuspends all it does is increment the guarded
+ * variable, this is so the low priority task knows that it has
+ * executed. */
+ ulGuardedVariable++;
+ }
}
/*-----------------------------------------------------------*/
-static void prvHighPriorityMutexTask( void *pvParameters )
+static void prvHighPriorityMutexTask( void * pvParameters )
{
-SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
-
- for( ;; )
- {
- /* The high priority task starts by suspending itself. The low
- priority task will unsuspend this task when required. */
- vTaskSuspend( NULL );
-
- /* When this task unsuspends all it does is attempt to obtain the
- mutex. It should find the mutex is not available so a block time is
- specified. */
- if( xSemaphoreTake( xMutex, portMAX_DELAY ) != pdPASS )
- {
- /* This task would expect to obtain the mutex unless its wait for
- the mutex was aborted. */
- if( xBlockWasAborted == pdFALSE )
- {
- xErrorDetected = pdTRUE;
- }
- else
- {
- xBlockWasAborted = pdFALSE;
- }
- }
- else
- {
- /* When the mutex is eventually obtained it is just given back before
- returning to suspend ready for the next cycle. */
- if( xSemaphoreGive( xMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
- }
- }
+ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
+
+ for( ; ; )
+ {
+ /* The high priority task starts by suspending itself. The low
+ * priority task will unsuspend this task when required. */
+ vTaskSuspend( NULL );
+
+ /* When this task unsuspends all it does is attempt to obtain the
+ * mutex. It should find the mutex is not available so a block time is
+ * specified. */
+ if( xSemaphoreTake( xMutex, portMAX_DELAY ) != pdPASS )
+ {
+ /* This task would expect to obtain the mutex unless its wait for
+ * the mutex was aborted. */
+ if( xBlockWasAborted == pdFALSE )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ else
+ {
+ xBlockWasAborted = pdFALSE;
+ }
+ }
+ else
+ {
+ /* When the mutex is eventually obtained it is just given back before
+ * returning to suspend ready for the next cycle. */
+ if( xSemaphoreGive( xMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
@@ -1002,27 +1015,25 @@ SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreGenericQueueTasksStillRunning( void )
{
-static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;
+ static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;
- /* If the demo task is still running then we expect the loop counters to
- have incremented since this function was last called. */
- if( ulLastLoopCounter == ulLoopCounter )
- {
- xErrorDetected = pdTRUE;
- }
+ /* If the demo task is still running then we expect the loop counters to
+ * have incremented since this function was last called. */
+ if( ulLastLoopCounter == ulLoopCounter )
+ {
+ xErrorDetected = pdTRUE;
+ }
- if( ulLastLoopCounter2 == ulLoopCounter2 )
- {
- xErrorDetected = pdTRUE;
- }
+ if( ulLastLoopCounter2 == ulLoopCounter2 )
+ {
+ xErrorDetected = pdTRUE;
+ }
- ulLastLoopCounter = ulLoopCounter;
- ulLastLoopCounter2 = ulLoopCounter2;
+ ulLastLoopCounter = ulLoopCounter;
+ ulLastLoopCounter2 = ulLoopCounter2;
- /* Errors detected in the task itself will have latched xErrorDetected
- to true. */
+ /* Errors detected in the task itself will have latched xErrorDetected
+ * to true. */
- return ( BaseType_t ) !xErrorDetected;
+ return ( BaseType_t ) !xErrorDetected;
}
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/IntQueue.c b/FreeRTOS/Demo/Common/Minimal/IntQueue.c
index 3e4452048..a728e66a8 100644
--- a/FreeRTOS/Demo/Common/Minimal/IntQueue.c
+++ b/FreeRTOS/Demo/Common/Minimal/IntQueue.c
@@ -52,99 +52,101 @@
#include "IntQueue.h"
#include "IntQueueTimer.h"
-#if( INCLUDE_eTaskGetState != 1 )
- #error INCLUDE_eTaskGetState must be set to 1 in FreeRTOSConfig.h to use this demo file.
+#if ( INCLUDE_eTaskGetState != 1 )
+ #error INCLUDE_eTaskGetState must be set to 1 in FreeRTOSConfig.h to use this demo file.
#endif
/* Priorities used by test tasks. */
#ifndef intqHIGHER_PRIORITY
- #define intqHIGHER_PRIORITY ( configMAX_PRIORITIES - 2 )
+ #define intqHIGHER_PRIORITY ( configMAX_PRIORITIES - 2 )
#endif
-#define intqLOWER_PRIORITY ( tskIDLE_PRIORITY )
+#define intqLOWER_PRIORITY ( tskIDLE_PRIORITY )
/* The number of values to send/receive before checking that all values were
-processed as expected. */
-#define intqNUM_VALUES_TO_LOG ( 200 )
-#define intqSHORT_DELAY ( 140 )
+ * processed as expected. */
+#define intqNUM_VALUES_TO_LOG ( 200 )
+#define intqSHORT_DELAY ( 140 )
/* The value by which the value being sent to or received from a queue should
-increment past intqNUM_VALUES_TO_LOG before we check that all values have been
-sent/received correctly. This is done to ensure that all tasks and interrupts
-accessing the queue have completed their accesses with the
-intqNUM_VALUES_TO_LOG range. */
-#define intqVALUE_OVERRUN ( 50 )
+ * increment past intqNUM_VALUES_TO_LOG before we check that all values have been
+ * sent/received correctly. This is done to ensure that all tasks and interrupts
+ * accessing the queue have completed their accesses with the
+ * intqNUM_VALUES_TO_LOG range. */
+#define intqVALUE_OVERRUN ( 50 )
/* The delay used by the polling task. A short delay is used for code
-coverage. */
-#define intqONE_TICK_DELAY ( 1 )
+ * coverage. */
+#define intqONE_TICK_DELAY ( 1 )
/* Each task and interrupt is given a unique identifier. This value is used to
-identify which task sent or received each value. The identifier is also used
-to distinguish between two tasks that are running the same task function. */
-#define intqHIGH_PRIORITY_TASK1 ( ( UBaseType_t ) 1 )
-#define intqHIGH_PRIORITY_TASK2 ( ( UBaseType_t ) 2 )
-#define intqLOW_PRIORITY_TASK ( ( UBaseType_t ) 3 )
-#define intqFIRST_INTERRUPT ( ( UBaseType_t ) 4 )
-#define intqSECOND_INTERRUPT ( ( UBaseType_t ) 5 )
-#define intqQUEUE_LENGTH ( ( UBaseType_t ) 10 )
+ * identify which task sent or received each value. The identifier is also used
+ * to distinguish between two tasks that are running the same task function. */
+#define intqHIGH_PRIORITY_TASK1 ( ( UBaseType_t ) 1 )
+#define intqHIGH_PRIORITY_TASK2 ( ( UBaseType_t ) 2 )
+#define intqLOW_PRIORITY_TASK ( ( UBaseType_t ) 3 )
+#define intqFIRST_INTERRUPT ( ( UBaseType_t ) 4 )
+#define intqSECOND_INTERRUPT ( ( UBaseType_t ) 5 )
+#define intqQUEUE_LENGTH ( ( UBaseType_t ) 10 )
/* At least intqMIN_ACCEPTABLE_TASK_COUNT values should be sent to/received
-from each queue by each task, otherwise an error is detected. */
-#define intqMIN_ACCEPTABLE_TASK_COUNT ( 5 )
+ * from each queue by each task, otherwise an error is detected. */
+#define intqMIN_ACCEPTABLE_TASK_COUNT ( 5 )
/* Send the next value to the queue that is normally empty. This is called
-from within the interrupts. */
-#define timerNORMALLY_EMPTY_TX() \
- if( xQueueIsQueueFullFromISR( xNormallyEmptyQueue ) != pdTRUE ) \
- { \
- UBaseType_t uxSavedInterruptStatus; \
- uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); \
- { \
- uxValueForNormallyEmptyQueue++; \
- if( xQueueSendFromISR( xNormallyEmptyQueue, ( void * ) &uxValueForNormallyEmptyQueue, &xHigherPriorityTaskWoken ) != pdPASS ) \
- { \
- uxValueForNormallyEmptyQueue--; \
- } \
- } \
- portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
- } \
+ * from within the interrupts. */
+#define timerNORMALLY_EMPTY_TX() \
+ if( xQueueIsQueueFullFromISR( xNormallyEmptyQueue ) != pdTRUE ) \
+ { \
+ UBaseType_t uxSavedInterruptStatus; \
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); \
+ { \
+ uxValueForNormallyEmptyQueue++; \
+ if( xQueueSendFromISR( xNormallyEmptyQueue, ( void * ) &uxValueForNormallyEmptyQueue, &xHigherPriorityTaskWoken ) != pdPASS ) \
+ { \
+ uxValueForNormallyEmptyQueue--; \
+ } \
+ } \
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
+ } \
+
/* Send the next value to the queue that is normally full. This is called
-from within the interrupts. */
-#define timerNORMALLY_FULL_TX() \
- if( xQueueIsQueueFullFromISR( xNormallyFullQueue ) != pdTRUE ) \
- { \
- UBaseType_t uxSavedInterruptStatus; \
- uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); \
- { \
- uxValueForNormallyFullQueue++; \
- if( xQueueSendFromISR( xNormallyFullQueue, ( void * ) &uxValueForNormallyFullQueue, &xHigherPriorityTaskWoken ) != pdPASS ) \
- { \
- uxValueForNormallyFullQueue--; \
- } \
- } \
- portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
- } \
+ * from within the interrupts. */
+#define timerNORMALLY_FULL_TX() \
+ if( xQueueIsQueueFullFromISR( xNormallyFullQueue ) != pdTRUE ) \
+ { \
+ UBaseType_t uxSavedInterruptStatus; \
+ uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); \
+ { \
+ uxValueForNormallyFullQueue++; \
+ if( xQueueSendFromISR( xNormallyFullQueue, ( void * ) &uxValueForNormallyFullQueue, &xHigherPriorityTaskWoken ) != pdPASS ) \
+ { \
+ uxValueForNormallyFullQueue--; \
+ } \
+ } \
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); \
+ } \
+
/* Receive a value from the normally empty queue. This is called from within
-an interrupt. */
-#define timerNORMALLY_EMPTY_RX() \
- if( xQueueReceiveFromISR( xNormallyEmptyQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) != pdPASS ) \
- { \
- prvQueueAccessLogError( __LINE__ ); \
- } \
- else \
- { \
- prvRecordValue_NormallyEmpty( uxRxedValue, intqSECOND_INTERRUPT ); \
- }
+ * an interrupt. */
+#define timerNORMALLY_EMPTY_RX() \
+ if( xQueueReceiveFromISR( xNormallyEmptyQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) != pdPASS ) \
+ { \
+ prvQueueAccessLogError( __LINE__ ); \
+ } \
+ else \
+ { \
+ prvRecordValue_NormallyEmpty( uxRxedValue, intqSECOND_INTERRUPT ); \
+ }
/* Receive a value from the normally full queue. This is called from within
-an interrupt. */
-#define timerNORMALLY_FULL_RX() \
- if( xQueueReceiveFromISR( xNormallyFullQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) == pdPASS ) \
- { \
- prvRecordValue_NormallyFull( uxRxedValue, intqSECOND_INTERRUPT ); \
- } \
+ * an interrupt. */
+#define timerNORMALLY_FULL_RX() \
+ if( xQueueReceiveFromISR( xNormallyFullQueue, &uxRxedValue, &xHigherPriorityTaskWoken ) == pdPASS ) \
+ { \
+ prvRecordValue_NormallyFull( uxRxedValue, intqSECOND_INTERRUPT ); \
+ } \
/*-----------------------------------------------------------*/
@@ -156,7 +158,7 @@ static QueueHandle_t xNormallyEmptyQueue, xNormallyFullQueue;
static volatile UBaseType_t uxHighPriorityLoops1 = 0, uxHighPriorityLoops2 = 0, uxLowPriorityLoops1 = 0, uxLowPriorityLoops2 = 0;
/* Any unexpected behaviour sets xErrorStatus to fail and log the line that
-caused the error in xErrorLine. */
+ * caused the error in xErrorLine. */
static BaseType_t xErrorStatus = pdPASS;
static volatile UBaseType_t xErrorLine = ( UBaseType_t ) 0;
@@ -164,30 +166,32 @@ static volatile UBaseType_t xErrorLine = ( UBaseType_t ) 0;
static BaseType_t xWasSuspended = pdFALSE;
/* The values that are sent to the queues. An incremented value is sent each
-time to each queue. */
+ * time to each queue. */
static volatile UBaseType_t uxValueForNormallyEmptyQueue = 0, uxValueForNormallyFullQueue = 0;
/* A handle to some of the tasks is required so they can be suspended/resumed. */
TaskHandle_t xHighPriorityNormallyEmptyTask1, xHighPriorityNormallyEmptyTask2, xHighPriorityNormallyFullTask1, xHighPriorityNormallyFullTask2;
/* When a value is received in a queue the value is ticked off in the array
-the array position of the value is set to a the identifier of the task or
-interrupt that accessed the queue. This way missing or duplicate values can be
-detected. */
+ * the array position of the value is set to a the identifier of the task or
+ * interrupt that accessed the queue. This way missing or duplicate values can be
+ * detected. */
static uint8_t ucNormallyEmptyReceivedValues[ intqNUM_VALUES_TO_LOG ] = { 0 };
static uint8_t ucNormallyFullReceivedValues[ intqNUM_VALUES_TO_LOG ] = { 0 };
/* The test tasks themselves. */
-static void prvLowerPriorityNormallyEmptyTask( void *pvParameters );
-static void prvLowerPriorityNormallyFullTask( void *pvParameters );
-static void prvHigherPriorityNormallyEmptyTask( void *pvParameters );
-static void prv1stHigherPriorityNormallyFullTask( void *pvParameters );
-static void prv2ndHigherPriorityNormallyFullTask( void *pvParameters );
+static void prvLowerPriorityNormallyEmptyTask( void * pvParameters );
+static void prvLowerPriorityNormallyFullTask( void * pvParameters );
+static void prvHigherPriorityNormallyEmptyTask( void * pvParameters );
+static void prv1stHigherPriorityNormallyFullTask( void * pvParameters );
+static void prv2ndHigherPriorityNormallyFullTask( void * pvParameters );
/* Used to mark the positions within the ucNormallyEmptyReceivedValues and
-ucNormallyFullReceivedValues arrays, while checking for duplicates. */
-static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue, UBaseType_t uxSource );
-static void prvRecordValue_NormallyFull( UBaseType_t uxValue, UBaseType_t uxSource );
+ * ucNormallyFullReceivedValues arrays, while checking for duplicates. */
+static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue,
+ UBaseType_t uxSource );
+static void prvRecordValue_NormallyFull( UBaseType_t uxValue,
+ UBaseType_t uxSource );
/* Logs the line on which an error occurred. */
static void prvQueueAccessLogError( UBaseType_t uxLine );
@@ -196,532 +200,535 @@ static void prvQueueAccessLogError( UBaseType_t uxLine );
void vStartInterruptQueueTasks( void )
{
- /* Start the test tasks. */
- xTaskCreate( prvHigherPriorityNormallyEmptyTask, "H1QRx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK1, intqHIGHER_PRIORITY, &xHighPriorityNormallyEmptyTask1 );
- xTaskCreate( prvHigherPriorityNormallyEmptyTask, "H2QRx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK2, intqHIGHER_PRIORITY, &xHighPriorityNormallyEmptyTask2 );
- xTaskCreate( prvLowerPriorityNormallyEmptyTask, "L1QRx", configMINIMAL_STACK_SIZE, NULL, intqLOWER_PRIORITY, NULL );
- xTaskCreate( prv1stHigherPriorityNormallyFullTask, "H1QTx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK1, intqHIGHER_PRIORITY, &xHighPriorityNormallyFullTask1 );
- xTaskCreate( prv2ndHigherPriorityNormallyFullTask, "H2QTx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK2, intqHIGHER_PRIORITY, &xHighPriorityNormallyFullTask2 );
- xTaskCreate( prvLowerPriorityNormallyFullTask, "L2QRx", configMINIMAL_STACK_SIZE, NULL, intqLOWER_PRIORITY, NULL );
-
- /* Create the queues that are accessed by multiple tasks and multiple
- interrupts. */
- xNormallyFullQueue = xQueueCreate( intqQUEUE_LENGTH, ( UBaseType_t ) sizeof( UBaseType_t ) );
- xNormallyEmptyQueue = xQueueCreate( intqQUEUE_LENGTH, ( UBaseType_t ) sizeof( UBaseType_t ) );
-
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
- in use. The queue registry is provided as a means for kernel aware
- debuggers to locate queues and has no purpose if a kernel aware debugger
- is not being used. The call to vQueueAddToRegistry() will be removed
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
- defined to be less than 1. */
- vQueueAddToRegistry( xNormallyFullQueue, "NormallyFull" );
- vQueueAddToRegistry( xNormallyEmptyQueue, "NormallyEmpty" );
+ /* Start the test tasks. */
+ xTaskCreate( prvHigherPriorityNormallyEmptyTask, "H1QRx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK1, intqHIGHER_PRIORITY, &xHighPriorityNormallyEmptyTask1 );
+ xTaskCreate( prvHigherPriorityNormallyEmptyTask, "H2QRx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK2, intqHIGHER_PRIORITY, &xHighPriorityNormallyEmptyTask2 );
+ xTaskCreate( prvLowerPriorityNormallyEmptyTask, "L1QRx", configMINIMAL_STACK_SIZE, NULL, intqLOWER_PRIORITY, NULL );
+ xTaskCreate( prv1stHigherPriorityNormallyFullTask, "H1QTx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK1, intqHIGHER_PRIORITY, &xHighPriorityNormallyFullTask1 );
+ xTaskCreate( prv2ndHigherPriorityNormallyFullTask, "H2QTx", configMINIMAL_STACK_SIZE, ( void * ) intqHIGH_PRIORITY_TASK2, intqHIGHER_PRIORITY, &xHighPriorityNormallyFullTask2 );
+ xTaskCreate( prvLowerPriorityNormallyFullTask, "L2QRx", configMINIMAL_STACK_SIZE, NULL, intqLOWER_PRIORITY, NULL );
+
+ /* Create the queues that are accessed by multiple tasks and multiple
+ * interrupts. */
+ xNormallyFullQueue = xQueueCreate( intqQUEUE_LENGTH, ( UBaseType_t ) sizeof( UBaseType_t ) );
+ xNormallyEmptyQueue = xQueueCreate( intqQUEUE_LENGTH, ( UBaseType_t ) sizeof( UBaseType_t ) );
+
+ /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
+ * in use. The queue registry is provided as a means for kernel aware
+ * debuggers to locate queues and has no purpose if a kernel aware debugger
+ * is not being used. The call to vQueueAddToRegistry() will be removed
+ * by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
+ * defined to be less than 1. */
+ vQueueAddToRegistry( xNormallyFullQueue, "NormallyFull" );
+ vQueueAddToRegistry( xNormallyEmptyQueue, "NormallyEmpty" );
}
/*-----------------------------------------------------------*/
-static void prvRecordValue_NormallyFull( UBaseType_t uxValue, UBaseType_t uxSource )
+static void prvRecordValue_NormallyFull( UBaseType_t uxValue,
+ UBaseType_t uxSource )
{
- if( uxValue < intqNUM_VALUES_TO_LOG )
- {
- /* We don't expect to receive the same value twice, so if the value
- has already been marked as received an error has occurred. */
- if( ucNormallyFullReceivedValues[ uxValue ] != 0x00 )
- {
- prvQueueAccessLogError( __LINE__ );
- }
-
- /* Log that this value has been received. */
- ucNormallyFullReceivedValues[ uxValue ] = ( uint8_t ) uxSource;
- }
+ if( uxValue < intqNUM_VALUES_TO_LOG )
+ {
+ /* We don't expect to receive the same value twice, so if the value
+ * has already been marked as received an error has occurred. */
+ if( ucNormallyFullReceivedValues[ uxValue ] != 0x00 )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ /* Log that this value has been received. */
+ ucNormallyFullReceivedValues[ uxValue ] = ( uint8_t ) uxSource;
+ }
}
/*-----------------------------------------------------------*/
-static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue, UBaseType_t uxSource )
+static void prvRecordValue_NormallyEmpty( UBaseType_t uxValue,
+ UBaseType_t uxSource )
{
- if( uxValue < intqNUM_VALUES_TO_LOG )
- {
- /* We don't expect to receive the same value twice, so if the value
- has already been marked as received an error has occurred. */
- if( ucNormallyEmptyReceivedValues[ uxValue ] != 0x00 )
- {
- prvQueueAccessLogError( __LINE__ );
- }
-
- /* Log that this value has been received. */
- ucNormallyEmptyReceivedValues[ uxValue ] = ( uint8_t ) uxSource;
- }
+ if( uxValue < intqNUM_VALUES_TO_LOG )
+ {
+ /* We don't expect to receive the same value twice, so if the value
+ * has already been marked as received an error has occurred. */
+ if( ucNormallyEmptyReceivedValues[ uxValue ] != 0x00 )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ /* Log that this value has been received. */
+ ucNormallyEmptyReceivedValues[ uxValue ] = ( uint8_t ) uxSource;
+ }
}
/*-----------------------------------------------------------*/
static void prvQueueAccessLogError( UBaseType_t uxLine )
{
- /* Latch the line number that caused the error. */
- xErrorLine = uxLine;
- xErrorStatus = pdFAIL;
+ /* Latch the line number that caused the error. */
+ xErrorLine = uxLine;
+ xErrorStatus = pdFAIL;
}
/*-----------------------------------------------------------*/
-static void prvHigherPriorityNormallyEmptyTask( void *pvParameters )
+static void prvHigherPriorityNormallyEmptyTask( void * pvParameters )
{
-UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErrorCount2 = 0;
-
- /* The timer should not be started until after the scheduler has started.
- More than one task is running this code so we check the parameter value
- to determine which task should start the timer. */
- if( ( UBaseType_t ) pvParameters == intqHIGH_PRIORITY_TASK1 )
- {
- vInitialiseTimerForIntQueueTest();
- }
-
- for( ;; )
- {
- /* Block waiting to receive a value from the normally empty queue.
- Interrupts will write to the queue so we should receive a value. */
- if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqSHORT_DELAY ) != pdPASS )
- {
- prvQueueAccessLogError( __LINE__ );
- }
- else
- {
- /* Note which value was received so we can check all expected
- values are received and no values are duplicated. */
- prvRecordValue_NormallyEmpty( uxRxed, ( UBaseType_t ) pvParameters );
- }
-
- /* Ensure the other task running this code gets a chance to execute. */
- taskYIELD();
-
- if( ( UBaseType_t ) pvParameters == intqHIGH_PRIORITY_TASK1 )
- {
- /* Have we received all the expected values? */
- if( uxValueForNormallyEmptyQueue > ( intqNUM_VALUES_TO_LOG + intqVALUE_OVERRUN ) )
- {
- vTaskSuspend( xHighPriorityNormallyEmptyTask2 );
-
- uxTask1 = 0;
- uxTask2 = 0;
- uxInterrupts = 0;
-
- /* Loop through the array, checking that both tasks have
- placed values into the array, and that no values are missing.
- Start at 1 as we expect position 0 to be unused. */
- for( ux = 1; ux < intqNUM_VALUES_TO_LOG; ux++ )
- {
- if( ucNormallyEmptyReceivedValues[ ux ] == 0 )
- {
- /* A value is missing. */
- prvQueueAccessLogError( __LINE__ );
- }
- else
- {
- if( ucNormallyEmptyReceivedValues[ ux ] == intqHIGH_PRIORITY_TASK1 )
- {
- /* Value was placed into the array by task 1. */
- uxTask1++;
- }
- else if( ucNormallyEmptyReceivedValues[ ux ] == intqHIGH_PRIORITY_TASK2 )
- {
- /* Value was placed into the array by task 2. */
- uxTask2++;
- }
- else if( ucNormallyEmptyReceivedValues[ ux ] == intqSECOND_INTERRUPT )
- {
- uxInterrupts++;
- }
- }
- }
-
- if( uxTask1 < intqMIN_ACCEPTABLE_TASK_COUNT )
- {
- /* Only task 2 seemed to log any values. */
- uxErrorCount1++;
- if( uxErrorCount1 > 2 )
- {
- prvQueueAccessLogError( __LINE__ );
- }
- }
- else
- {
- uxErrorCount1 = 0;
- }
-
- if( uxTask2 < intqMIN_ACCEPTABLE_TASK_COUNT )
- {
- /* Only task 1 seemed to log any values. */
- uxErrorCount2++;
- if( uxErrorCount2 > 2 )
- {
- prvQueueAccessLogError( __LINE__ );
- }
- }
- else
- {
- uxErrorCount2 = 0;
- }
-
- if( uxInterrupts == 0 )
- {
- prvQueueAccessLogError( __LINE__ );
- }
-
- /* Clear the array again, ready to start a new cycle. */
- memset( ucNormallyEmptyReceivedValues, 0x00, sizeof( ucNormallyEmptyReceivedValues ) );
-
- uxHighPriorityLoops1++;
- uxValueForNormallyEmptyQueue = 0;
-
- /* Suspend ourselves, allowing the lower priority task to
- actually receive something from the queue. Until now it
- will have been prevented from doing so by the higher
- priority tasks. The lower priority task will resume us
- if it receives something. We will then resume the other
- higher priority task. */
- vTaskSuspend( NULL );
- vTaskResume( xHighPriorityNormallyEmptyTask2 );
- }
- }
- }
+ UBaseType_t uxRxed, ux, uxTask1, uxTask2, uxInterrupts, uxErrorCount1 = 0, uxErrorCount2 = 0;
+
+ /* The timer should not be started until after the scheduler has started.
+ * More than one task is running this code so we check the parameter value
+ * to determine which task should start the timer. */
+ if( ( UBaseType_t ) pvParameters == intqHIGH_PRIORITY_TASK1 )
+ {
+ vInitialiseTimerForIntQueueTest();
+ }
+
+ for( ; ; )
+ {
+ /* Block waiting to receive a value from the normally empty queue.
+ * Interrupts will write to the queue so we should receive a value. */
+ if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqSHORT_DELAY ) != pdPASS )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+ else
+ {
+ /* Note which value was received so we can check all expected
+ * values are received and no values are duplicated. */
+ prvRecordValue_NormallyEmpty( uxRxed, ( UBaseType_t ) pvParameters );
+ }
+
+ /* Ensure the other task running this code gets a chance to execute. */
+ taskYIELD();
+
+ if( ( UBaseType_t ) pvParameters == intqHIGH_PRIORITY_TASK1 )
+ {
+ /* Have we received all the expected values? */
+ if( uxValueForNormallyEmptyQueue > ( intqNUM_VALUES_TO_LOG + intqVALUE_OVERRUN ) )
+ {
+ vTaskSuspend( xHighPriorityNormallyEmptyTask2 );
+
+ uxTask1 = 0;
+ uxTask2 = 0;
+ uxInterrupts = 0;
+
+ /* Loop through the array, checking that both tasks have
+ * placed values into the array, and that no values are missing.
+ * Start at 1 as we expect position 0 to be unused. */
+ for( ux = 1; ux < intqNUM_VALUES_TO_LOG; ux++ )
+ {
+ if( ucNormallyEmptyReceivedValues[ ux ] == 0 )
+ {
+ /* A value is missing. */
+ prvQueueAccessLogError( __LINE__ );
+ }
+ else
+ {
+ if( ucNormallyEmptyReceivedValues[ ux ] == intqHIGH_PRIORITY_TASK1 )
+ {
+ /* Value was placed into the array by task 1. */
+ uxTask1++;
+ }
+ else if( ucNormallyEmptyReceivedValues[ ux ] == intqHIGH_PRIORITY_TASK2 )
+ {
+ /* Value was placed into the array by task 2. */
+ uxTask2++;
+ }
+ else if( ucNormallyEmptyReceivedValues[ ux ] == intqSECOND_INTERRUPT )
+ {
+ uxInterrupts++;
+ }
+ }
+ }
+
+ if( uxTask1 < intqMIN_ACCEPTABLE_TASK_COUNT )
+ {
+ /* Only task 2 seemed to log any values. */
+ uxErrorCount1++;
+
+ if( uxErrorCount1 > 2 )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+ }
+ else
+ {
+ uxErrorCount1 = 0;
+ }
+
+ if( uxTask2 < intqMIN_ACCEPTABLE_TASK_COUNT )
+ {
+ /* Only task 1 seemed to log any values. */
+ uxErrorCount2++;
+
+ if( uxErrorCount2 > 2 )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+ }
+ else
+ {
+ uxErrorCount2 = 0;
+ }
+
+ if( uxInterrupts == 0 )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ /* Clear the array again, ready to start a new cycle. */
+ memset( ucNormallyEmptyReceivedValues, 0x00, sizeof( ucNormallyEmptyReceivedValues ) );
+
+ uxHighPriorityLoops1++;
+ uxValueForNormallyEmptyQueue = 0;
+
+ /* Suspend ourselves, allowing the lower priority task to
+ * actually receive something from the queue. Until now it
+ * will have been prevented from doing so by the higher
+ * priority tasks. The lower priority task will resume us
+ * if it receives something. We will then resume the other
+ * higher priority task. */
+ vTaskSuspend( NULL );
+ vTaskResume( xHighPriorityNormallyEmptyTask2 );
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prvLowerPriorityNormallyEmptyTask( void *pvParameters )
+static void prvLowerPriorityNormallyEmptyTask( void * pvParameters )
{
-UBaseType_t uxValue, uxRxed;
-
- /* The parameters are not being used so avoid compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqONE_TICK_DELAY ) != errQUEUE_EMPTY )
- {
- /* A value should only be obtained when the high priority task is
- suspended. */
- if( eTaskGetState( xHighPriorityNormallyEmptyTask1 ) != eSuspended )
- {
- prvQueueAccessLogError( __LINE__ );
- }
-
- prvRecordValue_NormallyEmpty( uxRxed, intqLOW_PRIORITY_TASK );
-
- /* Wake the higher priority task again. */
- vTaskResume( xHighPriorityNormallyEmptyTask1 );
- uxLowPriorityLoops1++;
- }
- else
- {
- /* Raise our priority while we send so we can preempt the higher
- priority task, and ensure we get the Tx value into the queue. */
- vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
-
- portENTER_CRITICAL();
- {
- uxValueForNormallyEmptyQueue++;
- uxValue = uxValueForNormallyEmptyQueue;
- }
- portEXIT_CRITICAL();
-
- if( xQueueSend( xNormallyEmptyQueue, &uxValue, portMAX_DELAY ) != pdPASS )
- {
- prvQueueAccessLogError( __LINE__ );
- }
-
- vTaskPrioritySet( NULL, intqLOWER_PRIORITY );
- }
- }
+ UBaseType_t uxValue, uxRxed;
+
+ /* The parameters are not being used so avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ if( xQueueReceive( xNormallyEmptyQueue, &uxRxed, intqONE_TICK_DELAY ) != errQUEUE_EMPTY )
+ {
+ /* A value should only be obtained when the high priority task is
+ * suspended. */
+ if( eTaskGetState( xHighPriorityNormallyEmptyTask1 ) != eSuspended )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ prvRecordValue_NormallyEmpty( uxRxed, intqLOW_PRIORITY_TASK );
+
+ /* Wake the higher priority task again. */
+ vTaskResume( xHighPriorityNormallyEmptyTask1 );
+ uxLowPriorityLoops1++;
+ }
+ else
+ {
+ /* Raise our priority while we send so we can preempt the higher
+ * priority task, and ensure we get the Tx value into the queue. */
+ vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
+
+ portENTER_CRITICAL();
+ {
+ uxValueForNormallyEmptyQueue++;
+ uxValue = uxValueForNormallyEmptyQueue;
+ }
+ portEXIT_CRITICAL();
+
+ if( xQueueSend( xNormallyEmptyQueue, &uxValue, portMAX_DELAY ) != pdPASS )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ vTaskPrioritySet( NULL, intqLOWER_PRIORITY );
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prv1stHigherPriorityNormallyFullTask( void *pvParameters )
+static void prv1stHigherPriorityNormallyFullTask( void * pvParameters )
{
-UBaseType_t uxValueToTx, ux, uxInterrupts;
-
- /* The parameters are not being used so avoid compiler warnings. */
- ( void ) pvParameters;
-
- /* Make sure the queue starts full or near full. >> 1 as there are two
- high priority tasks. */
- for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
- {
- portENTER_CRITICAL();
- {
- uxValueForNormallyFullQueue++;
- uxValueToTx = uxValueForNormallyFullQueue;
- }
- portEXIT_CRITICAL();
-
- xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
- }
-
- for( ;; )
- {
- portENTER_CRITICAL();
- {
- uxValueForNormallyFullQueue++;
- uxValueToTx = uxValueForNormallyFullQueue;
- }
- portEXIT_CRITICAL();
-
- if( xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY ) != pdPASS )
- {
- /* intqHIGH_PRIORITY_TASK2 is never suspended so we would not
- expect it to ever time out. */
- prvQueueAccessLogError( __LINE__ );
- }
-
- /* Allow the other task running this code to run. */
- taskYIELD();
-
- /* Have all the expected values been sent to the queue? */
- if( uxValueToTx > ( intqNUM_VALUES_TO_LOG + intqVALUE_OVERRUN ) )
- {
- /* Make sure the other high priority task completes its send of
- any values below intqNUM_VALUE_TO_LOG. */
- vTaskDelay( intqSHORT_DELAY );
-
- vTaskSuspend( xHighPriorityNormallyFullTask2 );
-
- if( xWasSuspended == pdTRUE )
- {
- /* We would have expected the other high priority task to have
- set this back to false by now. */
- prvQueueAccessLogError( __LINE__ );
- }
-
- /* Set the suspended flag so an error is not logged if the other
- task recognises a time out when it is unsuspended. */
- xWasSuspended = pdTRUE;
-
- /* Check interrupts are also sending. */
- uxInterrupts = 0U;
-
- /* Start at 1 as we expect position 0 to be unused. */
- for( ux = 1; ux < intqNUM_VALUES_TO_LOG; ux++ )
- {
- if( ucNormallyFullReceivedValues[ ux ] == 0 )
- {
- /* A value was missing. */
- prvQueueAccessLogError( __LINE__ );
- }
- else if( ucNormallyFullReceivedValues[ ux ] == intqSECOND_INTERRUPT )
- {
- uxInterrupts++;
- }
- }
-
- if( uxInterrupts == 0 )
- {
- /* No writes from interrupts were found. Are interrupts
- actually running? */
- prvQueueAccessLogError( __LINE__ );
- }
-
- /* Reset the array ready for the next cycle. */
- memset( ucNormallyFullReceivedValues, 0x00, sizeof( ucNormallyFullReceivedValues ) );
-
- uxHighPriorityLoops2++;
- uxValueForNormallyFullQueue = 0;
-
- /* Suspend ourselves, allowing the lower priority task to
- actually receive something from the queue. Until now it
- will have been prevented from doing so by the higher
- priority tasks. The lower priority task will resume us
- if it receives something. We will then resume the other
- higher priority task. */
- vTaskSuspend( NULL );
- vTaskResume( xHighPriorityNormallyFullTask2 );
- }
- }
+ UBaseType_t uxValueToTx, ux, uxInterrupts;
+
+ /* The parameters are not being used so avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Make sure the queue starts full or near full. >> 1 as there are two
+ * high priority tasks. */
+ for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
+ {
+ portENTER_CRITICAL();
+ {
+ uxValueForNormallyFullQueue++;
+ uxValueToTx = uxValueForNormallyFullQueue;
+ }
+ portEXIT_CRITICAL();
+
+ xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
+ }
+
+ for( ; ; )
+ {
+ portENTER_CRITICAL();
+ {
+ uxValueForNormallyFullQueue++;
+ uxValueToTx = uxValueForNormallyFullQueue;
+ }
+ portEXIT_CRITICAL();
+
+ if( xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY ) != pdPASS )
+ {
+ /* intqHIGH_PRIORITY_TASK2 is never suspended so we would not
+ * expect it to ever time out. */
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ /* Allow the other task running this code to run. */
+ taskYIELD();
+
+ /* Have all the expected values been sent to the queue? */
+ if( uxValueToTx > ( intqNUM_VALUES_TO_LOG + intqVALUE_OVERRUN ) )
+ {
+ /* Make sure the other high priority task completes its send of
+ * any values below intqNUM_VALUE_TO_LOG. */
+ vTaskDelay( intqSHORT_DELAY );
+
+ vTaskSuspend( xHighPriorityNormallyFullTask2 );
+
+ if( xWasSuspended == pdTRUE )
+ {
+ /* We would have expected the other high priority task to have
+ * set this back to false by now. */
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ /* Set the suspended flag so an error is not logged if the other
+ * task recognises a time out when it is unsuspended. */
+ xWasSuspended = pdTRUE;
+
+ /* Check interrupts are also sending. */
+ uxInterrupts = 0U;
+
+ /* Start at 1 as we expect position 0 to be unused. */
+ for( ux = 1; ux < intqNUM_VALUES_TO_LOG; ux++ )
+ {
+ if( ucNormallyFullReceivedValues[ ux ] == 0 )
+ {
+ /* A value was missing. */
+ prvQueueAccessLogError( __LINE__ );
+ }
+ else if( ucNormallyFullReceivedValues[ ux ] == intqSECOND_INTERRUPT )
+ {
+ uxInterrupts++;
+ }
+ }
+
+ if( uxInterrupts == 0 )
+ {
+ /* No writes from interrupts were found. Are interrupts
+ * actually running? */
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ /* Reset the array ready for the next cycle. */
+ memset( ucNormallyFullReceivedValues, 0x00, sizeof( ucNormallyFullReceivedValues ) );
+
+ uxHighPriorityLoops2++;
+ uxValueForNormallyFullQueue = 0;
+
+ /* Suspend ourselves, allowing the lower priority task to
+ * actually receive something from the queue. Until now it
+ * will have been prevented from doing so by the higher
+ * priority tasks. The lower priority task will resume us
+ * if it receives something. We will then resume the other
+ * higher priority task. */
+ vTaskSuspend( NULL );
+ vTaskResume( xHighPriorityNormallyFullTask2 );
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prv2ndHigherPriorityNormallyFullTask( void *pvParameters )
+static void prv2ndHigherPriorityNormallyFullTask( void * pvParameters )
{
-UBaseType_t uxValueToTx, ux;
-
- /* The parameters are not being used so avoid compiler warnings. */
- ( void ) pvParameters;
-
- /* Make sure the queue starts full or near full. >> 1 as there are two
- high priority tasks. */
- for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
- {
- portENTER_CRITICAL();
- {
- uxValueForNormallyFullQueue++;
- uxValueToTx = uxValueForNormallyFullQueue;
- }
- portEXIT_CRITICAL();
-
- xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
- }
-
- for( ;; )
- {
- portENTER_CRITICAL();
- {
- uxValueForNormallyFullQueue++;
- uxValueToTx = uxValueForNormallyFullQueue;
- }
- portEXIT_CRITICAL();
-
- if( xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY ) != pdPASS )
- {
- if( xWasSuspended != pdTRUE )
- {
- /* It is ok to time out if the task has been suspended. */
- prvQueueAccessLogError( __LINE__ );
- }
- }
-
- xWasSuspended = pdFALSE;
-
- taskYIELD();
- }
+ UBaseType_t uxValueToTx, ux;
+
+ /* The parameters are not being used so avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Make sure the queue starts full or near full. >> 1 as there are two
+ * high priority tasks. */
+ for( ux = 0; ux < ( intqQUEUE_LENGTH >> 1 ); ux++ )
+ {
+ portENTER_CRITICAL();
+ {
+ uxValueForNormallyFullQueue++;
+ uxValueToTx = uxValueForNormallyFullQueue;
+ }
+ portEXIT_CRITICAL();
+
+ xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY );
+ }
+
+ for( ; ; )
+ {
+ portENTER_CRITICAL();
+ {
+ uxValueForNormallyFullQueue++;
+ uxValueToTx = uxValueForNormallyFullQueue;
+ }
+ portEXIT_CRITICAL();
+
+ if( xQueueSend( xNormallyFullQueue, &uxValueToTx, intqSHORT_DELAY ) != pdPASS )
+ {
+ if( xWasSuspended != pdTRUE )
+ {
+ /* It is ok to time out if the task has been suspended. */
+ prvQueueAccessLogError( __LINE__ );
+ }
+ }
+
+ xWasSuspended = pdFALSE;
+
+ taskYIELD();
+ }
}
/*-----------------------------------------------------------*/
-static void prvLowerPriorityNormallyFullTask( void *pvParameters )
+static void prvLowerPriorityNormallyFullTask( void * pvParameters )
{
-UBaseType_t uxValue, uxTxed = 9999;
-
- /* The parameters are not being used so avoid compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- if( xQueueSend( xNormallyFullQueue, &uxTxed, intqONE_TICK_DELAY ) != errQUEUE_FULL )
- {
- /* Should only succeed when the higher priority task is suspended */
- if( eTaskGetState( xHighPriorityNormallyFullTask1 ) != eSuspended )
- {
- prvQueueAccessLogError( __LINE__ );
- }
-
- vTaskResume( xHighPriorityNormallyFullTask1 );
- uxLowPriorityLoops2++;
- }
- else
- {
- /* Raise our priority while we receive so we can preempt the higher
- priority task, and ensure we get the value from the queue. */
- vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
-
- if( xQueueReceive( xNormallyFullQueue, &uxValue, portMAX_DELAY ) != pdPASS )
- {
- prvQueueAccessLogError( __LINE__ );
- }
- else
- {
- prvRecordValue_NormallyFull( uxValue, intqLOW_PRIORITY_TASK );
- }
-
- vTaskPrioritySet( NULL, intqLOWER_PRIORITY );
- }
- }
+ UBaseType_t uxValue, uxTxed = 9999;
+
+ /* The parameters are not being used so avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ if( xQueueSend( xNormallyFullQueue, &uxTxed, intqONE_TICK_DELAY ) != errQUEUE_FULL )
+ {
+ /* Should only succeed when the higher priority task is suspended */
+ if( eTaskGetState( xHighPriorityNormallyFullTask1 ) != eSuspended )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+
+ vTaskResume( xHighPriorityNormallyFullTask1 );
+ uxLowPriorityLoops2++;
+ }
+ else
+ {
+ /* Raise our priority while we receive so we can preempt the higher
+ * priority task, and ensure we get the value from the queue. */
+ vTaskPrioritySet( NULL, intqHIGHER_PRIORITY + 1 );
+
+ if( xQueueReceive( xNormallyFullQueue, &uxValue, portMAX_DELAY ) != pdPASS )
+ {
+ prvQueueAccessLogError( __LINE__ );
+ }
+ else
+ {
+ prvRecordValue_NormallyFull( uxValue, intqLOW_PRIORITY_TASK );
+ }
+
+ vTaskPrioritySet( NULL, intqLOWER_PRIORITY );
+ }
+ }
}
/*-----------------------------------------------------------*/
BaseType_t xFirstTimerHandler( void )
{
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-UBaseType_t uxRxedValue;
-static UBaseType_t uxNextOperation = 0;
-
- /* Called from a timer interrupt. Perform various read and write
- accesses on the queues. */
-
- uxNextOperation++;
-
- if( uxNextOperation & ( UBaseType_t ) 0x01 )
- {
- timerNORMALLY_EMPTY_TX();
- timerNORMALLY_EMPTY_TX();
- timerNORMALLY_EMPTY_TX();
- }
- else
- {
- timerNORMALLY_FULL_RX();
- timerNORMALLY_FULL_RX();
- timerNORMALLY_FULL_RX();
- }
-
- return xHigherPriorityTaskWoken;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+ UBaseType_t uxRxedValue;
+ static UBaseType_t uxNextOperation = 0;
+
+ /* Called from a timer interrupt. Perform various read and write
+ * accesses on the queues. */
+
+ uxNextOperation++;
+
+ if( uxNextOperation & ( UBaseType_t ) 0x01 )
+ {
+ timerNORMALLY_EMPTY_TX();
+ timerNORMALLY_EMPTY_TX();
+ timerNORMALLY_EMPTY_TX();
+ }
+ else
+ {
+ timerNORMALLY_FULL_RX();
+ timerNORMALLY_FULL_RX();
+ timerNORMALLY_FULL_RX();
+ }
+
+ return xHigherPriorityTaskWoken;
}
/*-----------------------------------------------------------*/
BaseType_t xSecondTimerHandler( void )
{
-UBaseType_t uxRxedValue;
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-static UBaseType_t uxNextOperation = 0;
-
- /* Called from a timer interrupt. Perform various read and write
- accesses on the queues. */
-
- uxNextOperation++;
-
- if( uxNextOperation & ( UBaseType_t ) 0x01 )
- {
- timerNORMALLY_EMPTY_TX();
- timerNORMALLY_EMPTY_TX();
-
- timerNORMALLY_EMPTY_RX();
- timerNORMALLY_EMPTY_RX();
- }
- else
- {
- timerNORMALLY_FULL_RX();
- timerNORMALLY_FULL_TX();
- timerNORMALLY_FULL_TX();
- timerNORMALLY_FULL_TX();
- }
-
- return xHigherPriorityTaskWoken;
+ UBaseType_t uxRxedValue;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+ static UBaseType_t uxNextOperation = 0;
+
+ /* Called from a timer interrupt. Perform various read and write
+ * accesses on the queues. */
+
+ uxNextOperation++;
+
+ if( uxNextOperation & ( UBaseType_t ) 0x01 )
+ {
+ timerNORMALLY_EMPTY_TX();
+ timerNORMALLY_EMPTY_TX();
+
+ timerNORMALLY_EMPTY_RX();
+ timerNORMALLY_EMPTY_RX();
+ }
+ else
+ {
+ timerNORMALLY_FULL_RX();
+ timerNORMALLY_FULL_TX();
+ timerNORMALLY_FULL_TX();
+ timerNORMALLY_FULL_TX();
+ }
+
+ return xHigherPriorityTaskWoken;
}
/*-----------------------------------------------------------*/
BaseType_t xAreIntQueueTasksStillRunning( void )
{
-static UBaseType_t uxLastHighPriorityLoops1 = 0, uxLastHighPriorityLoops2 = 0, uxLastLowPriorityLoops1 = 0, uxLastLowPriorityLoops2 = 0;
+ static UBaseType_t uxLastHighPriorityLoops1 = 0, uxLastHighPriorityLoops2 = 0, uxLastLowPriorityLoops1 = 0, uxLastLowPriorityLoops2 = 0;
- /* xErrorStatus can be set outside of this function. This function just
- checks that all the tasks are still cycling. */
+ /* xErrorStatus can be set outside of this function. This function just
+ * checks that all the tasks are still cycling. */
- if( uxHighPriorityLoops1 == uxLastHighPriorityLoops1 )
- {
- /* The high priority 1 task has stalled. */
- prvQueueAccessLogError( __LINE__ );
- }
+ if( uxHighPriorityLoops1 == uxLastHighPriorityLoops1 )
+ {
+ /* The high priority 1 task has stalled. */
+ prvQueueAccessLogError( __LINE__ );
+ }
- uxLastHighPriorityLoops1 = uxHighPriorityLoops1;
+ uxLastHighPriorityLoops1 = uxHighPriorityLoops1;
- if( uxHighPriorityLoops2 == uxLastHighPriorityLoops2 )
- {
- /* The high priority 2 task has stalled. */
- prvQueueAccessLogError( __LINE__ );
- }
+ if( uxHighPriorityLoops2 == uxLastHighPriorityLoops2 )
+ {
+ /* The high priority 2 task has stalled. */
+ prvQueueAccessLogError( __LINE__ );
+ }
- uxLastHighPriorityLoops2 = uxHighPriorityLoops2;
+ uxLastHighPriorityLoops2 = uxHighPriorityLoops2;
- if( uxLowPriorityLoops1 == uxLastLowPriorityLoops1 )
- {
- /* The low priority 1 task has stalled. */
- prvQueueAccessLogError( __LINE__ );
- }
+ if( uxLowPriorityLoops1 == uxLastLowPriorityLoops1 )
+ {
+ /* The low priority 1 task has stalled. */
+ prvQueueAccessLogError( __LINE__ );
+ }
- uxLastLowPriorityLoops1 = uxLowPriorityLoops1;
+ uxLastLowPriorityLoops1 = uxLowPriorityLoops1;
- if( uxLowPriorityLoops2 == uxLastLowPriorityLoops2 )
- {
- /* The low priority 2 task has stalled. */
- prvQueueAccessLogError( __LINE__ );
- }
+ if( uxLowPriorityLoops2 == uxLastLowPriorityLoops2 )
+ {
+ /* The low priority 2 task has stalled. */
+ prvQueueAccessLogError( __LINE__ );
+ }
- uxLastLowPriorityLoops2 = uxLowPriorityLoops2;
+ uxLastLowPriorityLoops2 = uxLowPriorityLoops2;
- return xErrorStatus;
+ return xErrorStatus;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/IntSemTest.c b/FreeRTOS/Demo/Common/Minimal/IntSemTest.c
index 744c8bcee..50836c032 100644
--- a/FreeRTOS/Demo/Common/Minimal/IntSemTest.c
+++ b/FreeRTOS/Demo/Common/Minimal/IntSemTest.c
@@ -44,18 +44,18 @@
/*-----------------------------------------------------------*/
/* The priorities of the test tasks. */
-#define intsemMASTER_PRIORITY ( tskIDLE_PRIORITY )
-#define intsemSLAVE_PRIORITY ( tskIDLE_PRIORITY + 1 )
+#define intsemMASTER_PRIORITY ( tskIDLE_PRIORITY )
+#define intsemSLAVE_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* The rate at which the tick hook will give the mutex. */
-#define intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ( 100 )
+#define intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ( 100 )
/* A block time of 0 means 'don't block'. */
-#define intsemNO_BLOCK 0
+#define intsemNO_BLOCK 0
/* The maximum count value for the counting semaphore given from an
-interrupt. */
-#define intsemMAX_COUNT 3
+ * interrupt. */
+#define intsemMAX_COUNT 3
/*-----------------------------------------------------------*/
@@ -69,8 +69,8 @@ interrupt. */
* on a mutex that is shared between the master and the slave - which is a
* separate mutex to that given by the interrupt.
*/
-static void vInterruptMutexSlaveTask( void *pvParameters );
-static void vInterruptMutexMasterTask( void *pvParameters );
+static void vInterruptMutexSlaveTask( void * pvParameters );
+static void vInterruptMutexMasterTask( void * pvParameters );
/*
* A test whereby the master takes the shared and interrupt mutexes in that
@@ -90,37 +90,37 @@ static void prvTakeAndGiveInTheOppositeOrder( void );
* A simple task that interacts with an interrupt using a counting semaphore,
* primarily for code coverage purposes.
*/
-static void vInterruptCountingSemaphoreTask( void *pvParameters );
+static void vInterruptCountingSemaphoreTask( void * pvParameters );
/*-----------------------------------------------------------*/
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
-detected in any of the tasks. */
+ * detected in any of the tasks. */
static volatile BaseType_t xErrorDetected = pdFALSE;
/* Counters that are incremented on each cycle of a test. This is used to
-detect a stalled task - a test that is no longer running. */
+ * detect a stalled task - a test that is no longer running. */
static volatile uint32_t ulMasterLoops = 0, ulCountingSemaphoreLoops = 0;
/* Handles of the test tasks that must be accessed from other test tasks. */
static TaskHandle_t xSlaveHandle;
/* A mutex which is given from an interrupt - although generally mutexes should
-not be used given in interrupts (and definitely never taken in an interrupt)
-there are some circumstances when it may be desirable. */
+ * not be used given in interrupts (and definitely never taken in an interrupt)
+ * there are some circumstances when it may be desirable. */
static SemaphoreHandle_t xISRMutex = NULL;
/* A counting semaphore which is given from an interrupt. */
static SemaphoreHandle_t xISRCountingSemaphore = NULL;
/* A mutex which is shared between the master and slave tasks - the master
-does both sharing of this mutex with the slave and receiving a mutex from the
-interrupt. */
+ * does both sharing of this mutex with the slave and receiving a mutex from the
+ * interrupt. */
static SemaphoreHandle_t xMasterSlaveMutex = NULL;
/* Flag that allows the master task to control when the interrupt gives or does
-not give the mutex. There is no mutual exclusion on this variable, but this is
-only test code and it should be fine in the 32=bit test environment. */
+ * not give the mutex. There is no mutual exclusion on this variable, but this is
+ * only test code and it should be fine in the 32=bit test environment. */
static BaseType_t xOkToGiveMutex = pdFALSE, xOkToGiveCountingSemaphore = pdFALSE;
/* Used to coordinate timing between tasks and the interrupt. */
@@ -130,396 +130,402 @@ const TickType_t xInterruptGivePeriod = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIV
void vStartInterruptSemaphoreTasks( void )
{
- /* Create the semaphores that are given from an interrupt. */
- xISRMutex = xSemaphoreCreateMutex();
- configASSERT( xISRMutex );
- xISRCountingSemaphore = xSemaphoreCreateCounting( intsemMAX_COUNT, 0 );
- configASSERT( xISRCountingSemaphore );
-
- /* Create the mutex that is shared between the master and slave tasks (the
- master receives a mutex from an interrupt and shares a mutex with the
- slave. */
- xMasterSlaveMutex = xSemaphoreCreateMutex();
- configASSERT( xMasterSlaveMutex );
-
- /* Create the tasks that share mutexes between then and with interrupts. */
- xTaskCreate( vInterruptMutexSlaveTask, "IntMuS", configMINIMAL_STACK_SIZE, NULL, intsemSLAVE_PRIORITY, &xSlaveHandle );
- xTaskCreate( vInterruptMutexMasterTask, "IntMuM", configMINIMAL_STACK_SIZE, NULL, intsemMASTER_PRIORITY, NULL );
-
- /* Create the task that blocks on the counting semaphore. */
- xTaskCreate( vInterruptCountingSemaphoreTask, "IntCnt", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ /* Create the semaphores that are given from an interrupt. */
+ xISRMutex = xSemaphoreCreateMutex();
+ configASSERT( xISRMutex );
+ xISRCountingSemaphore = xSemaphoreCreateCounting( intsemMAX_COUNT, 0 );
+ configASSERT( xISRCountingSemaphore );
+
+ /* Create the mutex that is shared between the master and slave tasks (the
+ * master receives a mutex from an interrupt and shares a mutex with the
+ * slave. */
+ xMasterSlaveMutex = xSemaphoreCreateMutex();
+ configASSERT( xMasterSlaveMutex );
+
+ /* Create the tasks that share mutexes between then and with interrupts. */
+ xTaskCreate( vInterruptMutexSlaveTask, "IntMuS", configMINIMAL_STACK_SIZE, NULL, intsemSLAVE_PRIORITY, &xSlaveHandle );
+ xTaskCreate( vInterruptMutexMasterTask, "IntMuM", configMINIMAL_STACK_SIZE, NULL, intsemMASTER_PRIORITY, NULL );
+
+ /* Create the task that blocks on the counting semaphore. */
+ xTaskCreate( vInterruptCountingSemaphoreTask, "IntCnt", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
}
/*-----------------------------------------------------------*/
-static void vInterruptMutexMasterTask( void *pvParameters )
+static void vInterruptMutexMasterTask( void * pvParameters )
{
- /* Just to avoid compiler warnings. */
- ( void ) pvParameters;
+ /* Just to avoid compiler warnings. */
+ ( void ) pvParameters;
- for( ;; )
- {
- prvTakeAndGiveInTheSameOrder();
+ for( ; ; )
+ {
+ prvTakeAndGiveInTheSameOrder();
- /* Ensure not to starve out other tests. */
- ulMasterLoops++;
- vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
+ /* Ensure not to starve out other tests. */
+ ulMasterLoops++;
+ vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
- prvTakeAndGiveInTheOppositeOrder();
+ prvTakeAndGiveInTheOppositeOrder();
- /* Ensure not to starve out other tests. */
- ulMasterLoops++;
- vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
- }
+ /* Ensure not to starve out other tests. */
+ ulMasterLoops++;
+ vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );
+ }
}
/*-----------------------------------------------------------*/
static void prvTakeAndGiveInTheSameOrder( void )
{
- /* Ensure the slave is suspended, and that this task is running at the
- lower priority as expected as the start conditions. */
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Take the semaphore that is shared with the slave. */
- if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This task now has the mutex. Unsuspend the slave so it too
- attempts to take the mutex. */
- vTaskResume( xSlaveHandle );
-
- /* The slave has the higher priority so should now have executed and
- blocked on the semaphore. */
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* This task should now have inherited the priority of the slave
- task. */
- if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now wait a little longer than the time between ISR gives to also
- obtain the ISR mutex. */
- xOkToGiveMutex = pdTRUE;
- if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
- xOkToGiveMutex = pdFALSE;
-
- /* Attempting to take again immediately should fail as the mutex is
- already held. */
- if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Should still be at the priority of the slave task. */
- if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Give back the ISR semaphore to ensure the priority is not
- disinherited as the shared mutex (which the higher priority task is
- attempting to obtain) is still held. */
- if( xSemaphoreGive( xISRMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Finally give back the shared mutex. This time the higher priority
- task should run before this task runs again - so this task should have
- disinherited the priority and the higher priority task should be in the
- suspended state again. */
- if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* Reset the mutex ready for the next round. */
- xQueueReset( xISRMutex );
+ /* Ensure the slave is suspended, and that this task is running at the
+ * lower priority as expected as the start conditions. */
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Take the semaphore that is shared with the slave. */
+ if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This task now has the mutex. Unsuspend the slave so it too
+ * attempts to take the mutex. */
+ vTaskResume( xSlaveHandle );
+
+ /* The slave has the higher priority so should now have executed and
+ * blocked on the semaphore. */
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* This task should now have inherited the priority of the slave
+ * task. */
+ if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now wait a little longer than the time between ISR gives to also
+ * obtain the ISR mutex. */
+ xOkToGiveMutex = pdTRUE;
+
+ if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ xOkToGiveMutex = pdFALSE;
+
+ /* Attempting to take again immediately should fail as the mutex is
+ * already held. */
+ if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Should still be at the priority of the slave task. */
+ if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Give back the ISR semaphore to ensure the priority is not
+ * disinherited as the shared mutex (which the higher priority task is
+ * attempting to obtain) is still held. */
+ if( xSemaphoreGive( xISRMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Finally give back the shared mutex. This time the higher priority
+ * task should run before this task runs again - so this task should have
+ * disinherited the priority and the higher priority task should be in the
+ * suspended state again. */
+ if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* Reset the mutex ready for the next round. */
+ xQueueReset( xISRMutex );
}
/*-----------------------------------------------------------*/
static void prvTakeAndGiveInTheOppositeOrder( void )
{
- /* Ensure the slave is suspended, and that this task is running at the
- lower priority as expected as the start conditions. */
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Take the semaphore that is shared with the slave. */
- if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* This task now has the mutex. Unsuspend the slave so it too
- attempts to take the mutex. */
- vTaskResume( xSlaveHandle );
-
- /* The slave has the higher priority so should now have executed and
- blocked on the semaphore. */
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* This task should now have inherited the priority of the slave
- task. */
- if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now wait a little longer than the time between ISR gives to also
- obtain the ISR mutex. */
- xOkToGiveMutex = pdTRUE;
- if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
- xOkToGiveMutex = pdFALSE;
-
- /* Attempting to take again immediately should fail as the mutex is
- already held. */
- if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Should still be at the priority of the slave task. */
- if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Give back the shared semaphore to ensure the priority is not disinherited
- as the ISR mutex is still held. The higher priority slave task should run
- before this task runs again. */
- if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Should still be at the priority of the slave task as this task still
- holds one semaphore (this is a simplification in the priority inheritance
- mechanism. */
- if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Give back the ISR semaphore, which should result in the priority being
- disinherited as it was the last mutex held. */
- if( xSemaphoreGive( xISRMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Reset the mutex ready for the next round. */
- xQueueReset( xISRMutex );
+ /* Ensure the slave is suspended, and that this task is running at the
+ * lower priority as expected as the start conditions. */
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Take the semaphore that is shared with the slave. */
+ if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* This task now has the mutex. Unsuspend the slave so it too
+ * attempts to take the mutex. */
+ vTaskResume( xSlaveHandle );
+
+ /* The slave has the higher priority so should now have executed and
+ * blocked on the semaphore. */
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* This task should now have inherited the priority of the slave
+ * task. */
+ if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now wait a little longer than the time between ISR gives to also
+ * obtain the ISR mutex. */
+ xOkToGiveMutex = pdTRUE;
+
+ if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ xOkToGiveMutex = pdFALSE;
+
+ /* Attempting to take again immediately should fail as the mutex is
+ * already held. */
+ if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Should still be at the priority of the slave task. */
+ if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Give back the shared semaphore to ensure the priority is not disinherited
+ * as the ISR mutex is still held. The higher priority slave task should run
+ * before this task runs again. */
+ if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Should still be at the priority of the slave task as this task still
+ * holds one semaphore (this is a simplification in the priority inheritance
+ * mechanism. */
+ if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Give back the ISR semaphore, which should result in the priority being
+ * disinherited as it was the last mutex held. */
+ if( xSemaphoreGive( xISRMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Reset the mutex ready for the next round. */
+ xQueueReset( xISRMutex );
}
/*-----------------------------------------------------------*/
-static void vInterruptMutexSlaveTask( void *pvParameters )
+static void vInterruptMutexSlaveTask( void * pvParameters )
{
- /* Just to avoid compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* This task starts by suspending itself so when it executes can be
- controlled by the master task. */
- vTaskSuspend( NULL );
-
- /* This task will execute when the master task already holds the mutex.
- Attempting to take the mutex will place this task in the Blocked
- state. */
- if( xSemaphoreTake( xMasterSlaveMutex, portMAX_DELAY ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
- }
+ /* Just to avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* This task starts by suspending itself so when it executes can be
+ * controlled by the master task. */
+ vTaskSuspend( NULL );
+
+ /* This task will execute when the master task already holds the mutex.
+ * Attempting to take the mutex will place this task in the Blocked
+ * state. */
+ if( xSemaphoreTake( xMasterSlaveMutex, portMAX_DELAY ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void vInterruptCountingSemaphoreTask( void *pvParameters )
+static void vInterruptCountingSemaphoreTask( void * pvParameters )
{
-BaseType_t xCount;
-const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) * ( intsemMAX_COUNT + 1 );
-
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Expect to start with the counting semaphore empty. */
- if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Wait until it is expected that the interrupt will have filled the
- counting semaphore. */
- xOkToGiveCountingSemaphore = pdTRUE;
- vTaskDelay( xDelay );
- xOkToGiveCountingSemaphore = pdFALSE;
-
- /* Now it is expected that the counting semaphore is full. */
- if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != intsemMAX_COUNT )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( uxQueueSpacesAvailable( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- ulCountingSemaphoreLoops++;
-
- /* Expect to be able to take the counting semaphore intsemMAX_COUNT
- times. A block time of 0 is used as the semaphore should already be
- there. */
- xCount = 0;
- while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS )
- {
- xCount++;
- }
-
- if( xCount != intsemMAX_COUNT )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Now raise the priority of this task so it runs immediately that the
- semaphore is given from the interrupt. */
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
-
- /* Block to wait for the semaphore to be given from the interrupt. */
- xOkToGiveCountingSemaphore = pdTRUE;
- xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
- xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
- xOkToGiveCountingSemaphore = pdFALSE;
-
- /* Reset the priority so as not to disturbe other tests too much. */
- vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
-
- ulCountingSemaphoreLoops++;
- }
+ BaseType_t xCount;
+ const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) * ( intsemMAX_COUNT + 1 );
+
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Expect to start with the counting semaphore empty. */
+ if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Wait until it is expected that the interrupt will have filled the
+ * counting semaphore. */
+ xOkToGiveCountingSemaphore = pdTRUE;
+ vTaskDelay( xDelay );
+ xOkToGiveCountingSemaphore = pdFALSE;
+
+ /* Now it is expected that the counting semaphore is full. */
+ if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != intsemMAX_COUNT )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxQueueSpacesAvailable( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ ulCountingSemaphoreLoops++;
+
+ /* Expect to be able to take the counting semaphore intsemMAX_COUNT
+ * times. A block time of 0 is used as the semaphore should already be
+ * there. */
+ xCount = 0;
+
+ while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS )
+ {
+ xCount++;
+ }
+
+ if( xCount != intsemMAX_COUNT )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now raise the priority of this task so it runs immediately that the
+ * semaphore is given from the interrupt. */
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+
+ /* Block to wait for the semaphore to be given from the interrupt. */
+ xOkToGiveCountingSemaphore = pdTRUE;
+ xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
+ xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );
+ xOkToGiveCountingSemaphore = pdFALSE;
+
+ /* Reset the priority so as not to disturbe other tests too much. */
+ vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
+
+ ulCountingSemaphoreLoops++;
+ }
}
/*-----------------------------------------------------------*/
void vInterruptSemaphorePeriodicTest( void )
{
-static TickType_t xLastGiveTime = 0;
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-TickType_t xTimeNow;
-
- /* No mutual exclusion on xOkToGiveMutex, but this is only test code (and
- only executed on a 32-bit architecture) so ignore that in this case. */
- xTimeNow = xTaskGetTickCountFromISR();
- if( ( ( TickType_t ) ( xTimeNow - xLastGiveTime ) ) >= pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) )
- {
- configASSERT( xISRMutex );
- if( xOkToGiveMutex != pdFALSE )
- {
- /* Null is used as the second parameter in this give, and non-NULL
- in the other gives for code coverage reasons. */
- xSemaphoreGiveFromISR( xISRMutex, NULL );
-
- /* Second give attempt should fail. */
- configASSERT( xSemaphoreGiveFromISR( xISRMutex, &xHigherPriorityTaskWoken ) == pdFAIL );
- }
-
- if( xOkToGiveCountingSemaphore != pdFALSE )
- {
- xSemaphoreGiveFromISR( xISRCountingSemaphore, &xHigherPriorityTaskWoken );
- }
- xLastGiveTime = xTimeNow;
- }
-
- /* Remove compiler warnings about the value being set but not used. */
- ( void ) xHigherPriorityTaskWoken;
+ static TickType_t xLastGiveTime = 0;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+ TickType_t xTimeNow;
+
+ /* No mutual exclusion on xOkToGiveMutex, but this is only test code (and
+ * only executed on a 32-bit architecture) so ignore that in this case. */
+ xTimeNow = xTaskGetTickCountFromISR();
+
+ if( ( ( TickType_t ) ( xTimeNow - xLastGiveTime ) ) >= pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) )
+ {
+ configASSERT( xISRMutex );
+
+ if( xOkToGiveMutex != pdFALSE )
+ {
+ /* Null is used as the second parameter in this give, and non-NULL
+ * in the other gives for code coverage reasons. */
+ xSemaphoreGiveFromISR( xISRMutex, NULL );
+
+ /* Second give attempt should fail. */
+ configASSERT( xSemaphoreGiveFromISR( xISRMutex, &xHigherPriorityTaskWoken ) == pdFAIL );
+ }
+
+ if( xOkToGiveCountingSemaphore != pdFALSE )
+ {
+ xSemaphoreGiveFromISR( xISRCountingSemaphore, &xHigherPriorityTaskWoken );
+ }
+
+ xLastGiveTime = xTimeNow;
+ }
+
+ /* Remove compiler warnings about the value being set but not used. */
+ ( void ) xHigherPriorityTaskWoken;
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreInterruptSemaphoreTasksStillRunning( void )
{
-static uint32_t ulLastMasterLoopCounter = 0, ulLastCountingSemaphoreLoops = 0;
+ static uint32_t ulLastMasterLoopCounter = 0, ulLastCountingSemaphoreLoops = 0;
- /* If the demo tasks are running then it is expected that the loop counters
- will have changed since this function was last called. */
- if( ulLastMasterLoopCounter == ulMasterLoops )
- {
- xErrorDetected = pdTRUE;
- }
+ /* If the demo tasks are running then it is expected that the loop counters
+ * will have changed since this function was last called. */
+ if( ulLastMasterLoopCounter == ulMasterLoops )
+ {
+ xErrorDetected = pdTRUE;
+ }
- ulLastMasterLoopCounter = ulMasterLoops;
+ ulLastMasterLoopCounter = ulMasterLoops;
- if( ulLastCountingSemaphoreLoops == ulCountingSemaphoreLoops )
- {
- xErrorDetected = pdTRUE;
- }
+ if( ulLastCountingSemaphoreLoops == ulCountingSemaphoreLoops )
+ {
+ xErrorDetected = pdTRUE;
+ }
- ulLastCountingSemaphoreLoops = ulCountingSemaphoreLoops++;
+ ulLastCountingSemaphoreLoops = ulCountingSemaphoreLoops++;
- /* Errors detected in the task itself will have latched xErrorDetected
- to true. */
+ /* Errors detected in the task itself will have latched xErrorDetected
+ * to true. */
- return ( BaseType_t ) !xErrorDetected;
+ return ( BaseType_t ) !xErrorDetected;
}
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/MessageBufferAMP.c b/FreeRTOS/Demo/Common/Minimal/MessageBufferAMP.c
index c9b939f36..63378d59f 100644
--- a/FreeRTOS/Demo/Common/Minimal/MessageBufferAMP.c
+++ b/FreeRTOS/Demo/Common/Minimal/MessageBufferAMP.c
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * https://www.FreeRTOS.org
- * https://github.com/FreeRTOS
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -68,22 +68,22 @@
#include "MessageBufferAMP.h"
/* Enough for 3 4 byte pointers, including the additional 4 bytes per message
-overhead of message buffers. */
-#define mbaCONTROL_MESSAGE_BUFFER_SIZE ( 24 )
+ * overhead of message buffers. */
+#define mbaCONTROL_MESSAGE_BUFFER_SIZE ( 24 )
/* Enough four 4 8 byte strings, plus the additional 4 bytes per message
-overhead of message buffers. */
-#define mbaTASK_MESSAGE_BUFFER_SIZE ( 60 )
+ * overhead of message buffers. */
+#define mbaTASK_MESSAGE_BUFFER_SIZE ( 60 )
/* The number of instances of prvCoreBTasks that are created. */
-#define mbaNUMBER_OF_CORE_B_TASKS 2
+#define mbaNUMBER_OF_CORE_B_TASKS 2
/* A block time of 0 simply means, don't block. */
-#define mbaDONT_BLOCK 0
+#define mbaDONT_BLOCK 0
/* Macro that mimics an interrupt service routine executing by simply calling
-the routine inline. */
-#define mbaGENERATE_CORE_B_INTERRUPT() prvCoreBInterruptHandler()
+ * the routine inline. */
+#define mbaGENERATE_CORE_B_INTERRUPT() prvCoreBInterruptHandler()
/*-----------------------------------------------------------*/
@@ -91,14 +91,14 @@ the routine inline. */
* Implementation of the task that, on a real dual core device, would run on
* core A and send message to tasks running on core B.
*/
-static void prvCoreATask( void *pvParameters );
+static void prvCoreATask( void * pvParameters );
/*
* Implementation of the task that, on a real dual core device, would run on
* core B and receive message from core A. The demo creates two instances of
* this task.
*/
-static void prvCoreBTasks( void *pvParameters );
+static void prvCoreBTasks( void * pvParameters );
/*
* The function that, on a real dual core device, would handle inter-core
@@ -112,218 +112,217 @@ static void prvCoreBInterruptHandler( void );
static MessageBufferHandle_t xCoreBMessageBuffers[ mbaNUMBER_OF_CORE_B_TASKS ];
/* The control message buffer. This is used to pass the handle of the message
-message buffer that holds application data into the core to core interrupt
-service routine. */
+ * message buffer that holds application data into the core to core interrupt
+ * service routine. */
static MessageBufferHandle_t xControlMessageBuffer;
/* Counters used to indicate to the check that the tasks are still executing. */
static uint32_t ulCycleCounters[ mbaNUMBER_OF_CORE_B_TASKS ];
/* Set to pdFALSE if any errors are detected. Used to inform the check task
-that something might be wrong. */
+ * that something might be wrong. */
BaseType_t xDemoStatus = pdPASS;
/*-----------------------------------------------------------*/
void vStartMessageBufferAMPTasks( configSTACK_DEPTH_TYPE xStackSize )
{
-BaseType_t x;
-
- xControlMessageBuffer = xMessageBufferCreate( mbaCONTROL_MESSAGE_BUFFER_SIZE );
-
- xTaskCreate( prvCoreATask, /* The function that implements the task. */
- "AMPCoreA", /* Human readable name for the task. */
- xStackSize, /* Stack size (in words!). */
- NULL, /* Task parameter is not used. */
- tskIDLE_PRIORITY, /* The priority at which the task is created. */
- NULL ); /* No use for the task handle. */
-
- for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
- {
- xCoreBMessageBuffers[ x ] = xMessageBufferCreate( mbaTASK_MESSAGE_BUFFER_SIZE );
- configASSERT( xCoreBMessageBuffers[ x ] );
-
- /* Pass the loop counter into the created task using the task's
- parameter. The task then uses the value as an index into the
- ulCycleCounters and xCoreBMessageBuffers arrays. */
- xTaskCreate( prvCoreBTasks,
- "AMPCoreB1",
- xStackSize,
- ( void * ) x,
- tskIDLE_PRIORITY + 1,
- NULL );
- }
+ BaseType_t x;
+
+ xControlMessageBuffer = xMessageBufferCreate( mbaCONTROL_MESSAGE_BUFFER_SIZE );
+
+ xTaskCreate( prvCoreATask, /* The function that implements the task. */
+ "AMPCoreA", /* Human readable name for the task. */
+ xStackSize, /* Stack size (in words!). */
+ NULL, /* Task parameter is not used. */
+ tskIDLE_PRIORITY, /* The priority at which the task is created. */
+ NULL ); /* No use for the task handle. */
+
+ for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
+ {
+ xCoreBMessageBuffers[ x ] = xMessageBufferCreate( mbaTASK_MESSAGE_BUFFER_SIZE );
+ configASSERT( xCoreBMessageBuffers[ x ] );
+
+ /* Pass the loop counter into the created task using the task's
+ * parameter. The task then uses the value as an index into the
+ * ulCycleCounters and xCoreBMessageBuffers arrays. */
+ xTaskCreate( prvCoreBTasks,
+ "AMPCoreB1",
+ xStackSize,
+ ( void * ) x,
+ tskIDLE_PRIORITY + 1,
+ NULL );
+ }
}
/*-----------------------------------------------------------*/
-static void prvCoreATask( void *pvParameters )
+static void prvCoreATask( void * pvParameters )
{
-BaseType_t x;
-uint32_t ulNextValue = 0;
-const TickType_t xDelay = pdMS_TO_TICKS( 250 );
-char cString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
-
- /* Remove warning about unused parameters. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Create the next string to send. The value is incremented on each
- loop iteration, and the length of the string changes as the number of
- digits in the value increases. */
- sprintf( cString, "%lu", ( unsigned long ) ulNextValue );
-
- /* Send the value from this (pseudo) Core A to the tasks on the (pseudo)
- Core B via the message buffers. This will result in sbSEND_COMPLETED()
- being executed, which in turn will write the handle of the message
- buffer written to into xControlMessageBuffer then generate an interrupt
- in core B. */
- for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
- {
- xMessageBufferSend( /* The message buffer to write to. */
- xCoreBMessageBuffers[ x ],
- /* The source of the data to send. */
- ( void * ) cString,
- /* The length of the data to send. */
- strlen( cString ),
- /* The block time, should the buffer be full. */
- mbaDONT_BLOCK );
- }
-
- /* Delay before repeating with a different and potentially different
- length string. */
- vTaskDelay( xDelay );
- ulNextValue++;
- }
+ BaseType_t x;
+ uint32_t ulNextValue = 0;
+ const TickType_t xDelay = pdMS_TO_TICKS( 250 );
+ char cString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
+
+ /* Remove warning about unused parameters. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Create the next string to send. The value is incremented on each
+ * loop iteration, and the length of the string changes as the number of
+ * digits in the value increases. */
+ sprintf( cString, "%lu", ( unsigned long ) ulNextValue );
+
+ /* Send the value from this (pseudo) Core A to the tasks on the (pseudo)
+ * Core B via the message buffers. This will result in sbSEND_COMPLETED()
+ * being executed, which in turn will write the handle of the message
+ * buffer written to into xControlMessageBuffer then generate an interrupt
+ * in core B. */
+ for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
+ {
+ xMessageBufferSend( /* The message buffer to write to. */
+ xCoreBMessageBuffers[ x ],
+ /* The source of the data to send. */
+ ( void * ) cString,
+ /* The length of the data to send. */
+ strlen( cString ),
+ /* The block time, should the buffer be full. */
+ mbaDONT_BLOCK );
+ }
+
+ /* Delay before repeating with a different and potentially different
+ * length string. */
+ vTaskDelay( xDelay );
+ ulNextValue++;
+ }
}
/*-----------------------------------------------------------*/
-static void prvCoreBTasks( void *pvParameters )
+static void prvCoreBTasks( void * pvParameters )
{
-BaseType_t x;
-size_t xReceivedBytes;
-uint32_t ulNextValue = 0;
-char cExpectedString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
-char cReceivedString[ 15 ];
-
- /* The index into the xCoreBMessageBuffers and ulLoopCounter arrays is
- passed into this task using the task's parameter. */
- x = ( BaseType_t ) pvParameters;
- configASSERT( x < mbaNUMBER_OF_CORE_B_TASKS );
-
- for( ;; )
- {
- /* Create the string that is expected to be received this time round. */
- sprintf( cExpectedString, "%lu", ( unsigned long ) ulNextValue );
-
- /* Wait to receive the next message from core A. */
- memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
- xReceivedBytes = xMessageBufferReceive( /* The message buffer to receive from. */
- xCoreBMessageBuffers[ x ],
- /* Location to store received data. */
- cReceivedString,
- /* Maximum number of bytes to receive. */
- sizeof( cReceivedString ),
- /* Ticks to wait if buffer is empty. */
- portMAX_DELAY );
-
- /* Check the number of bytes received was as expected. */
- configASSERT( xReceivedBytes == strlen( cExpectedString ) );
- ( void ) xReceivedBytes; /* Incase configASSERT() is not defined. */
-
- /* If the received string matches that expected then increment the loop
- counter so the check task knows this task is still running. */
- if( strcmp( cReceivedString, cExpectedString ) == 0 )
- {
- ( ulCycleCounters[ x ] )++;
- }
- else
- {
- xDemoStatus = pdFAIL;
- }
-
- /* Expect the next string in sequence the next time around. */
- ulNextValue++;
- }
+ BaseType_t x;
+ size_t xReceivedBytes;
+ uint32_t ulNextValue = 0;
+ char cExpectedString[ 15 ]; /* At least large enough to hold "4294967295\0" (0xffffffff). */
+ char cReceivedString[ 15 ];
+
+ /* The index into the xCoreBMessageBuffers and ulLoopCounter arrays is
+ * passed into this task using the task's parameter. */
+ x = ( BaseType_t ) pvParameters;
+ configASSERT( x < mbaNUMBER_OF_CORE_B_TASKS );
+
+ for( ; ; )
+ {
+ /* Create the string that is expected to be received this time round. */
+ sprintf( cExpectedString, "%lu", ( unsigned long ) ulNextValue );
+
+ /* Wait to receive the next message from core A. */
+ memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
+ xReceivedBytes = xMessageBufferReceive( /* The message buffer to receive from. */
+ xCoreBMessageBuffers[ x ],
+ /* Location to store received data. */
+ cReceivedString,
+ /* Maximum number of bytes to receive. */
+ sizeof( cReceivedString ),
+ /* Ticks to wait if buffer is empty. */
+ portMAX_DELAY );
+
+ /* Check the number of bytes received was as expected. */
+ configASSERT( xReceivedBytes == strlen( cExpectedString ) );
+ ( void ) xReceivedBytes; /* Incase configASSERT() is not defined. */
+
+ /* If the received string matches that expected then increment the loop
+ * counter so the check task knows this task is still running. */
+ if( strcmp( cReceivedString, cExpectedString ) == 0 )
+ {
+ ( ulCycleCounters[ x ] )++;
+ }
+ else
+ {
+ xDemoStatus = pdFAIL;
+ }
+
+ /* Expect the next string in sequence the next time around. */
+ ulNextValue++;
+ }
}
/*-----------------------------------------------------------*/
/* Called by the reimplementation of sbSEND_COMPLETED(), which can be defined
-as follows in FreeRTOSConfig.h:
-#define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
-*/
+ * as follows in FreeRTOSConfig.h:
+ #define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer )
+ */
void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer )
{
-MessageBufferHandle_t xUpdatedBuffer = ( MessageBufferHandle_t ) xUpdatedMessageBuffer;
-
- /* If sbSEND_COMPLETED() has been implemented as above, then this function
- is called from within xMessageBufferSend(). As this function also calls
- xMessageBufferSend() itself it is necessary to guard against a recursive
- call. If the message buffer just updated is the message buffer written to
- by this function, then this is a recursive call, and the function can just
- exit without taking further action. */
- if( xUpdatedBuffer != xControlMessageBuffer )
- {
- /* Use xControlMessageBuffer to pass the handle of the message buffer
- written to by core A to the interrupt handler about to be generated in
- core B. */
- xMessageBufferSend( xControlMessageBuffer, &xUpdatedBuffer, sizeof( xUpdatedBuffer ), mbaDONT_BLOCK );
-
- /* This is where the interrupt would be generated. In this case it is
- not a genuine interrupt handler that executes, just a standard function
- call. */
- mbaGENERATE_CORE_B_INTERRUPT();
- }
+ MessageBufferHandle_t xUpdatedBuffer = ( MessageBufferHandle_t ) xUpdatedMessageBuffer;
+
+ /* If sbSEND_COMPLETED() has been implemented as above, then this function
+ * is called from within xMessageBufferSend(). As this function also calls
+ * xMessageBufferSend() itself it is necessary to guard against a recursive
+ * call. If the message buffer just updated is the message buffer written to
+ * by this function, then this is a recursive call, and the function can just
+ * exit without taking further action. */
+ if( xUpdatedBuffer != xControlMessageBuffer )
+ {
+ /* Use xControlMessageBuffer to pass the handle of the message buffer
+ * written to by core A to the interrupt handler about to be generated in
+ * core B. */
+ xMessageBufferSend( xControlMessageBuffer, &xUpdatedBuffer, sizeof( xUpdatedBuffer ), mbaDONT_BLOCK );
+
+ /* This is where the interrupt would be generated. In this case it is
+ * not a genuine interrupt handler that executes, just a standard function
+ * call. */
+ mbaGENERATE_CORE_B_INTERRUPT();
+ }
}
/*-----------------------------------------------------------*/
/* Handler for the interrupts that are triggered on core A but execute on core
-B. */
+ * B. */
static void prvCoreBInterruptHandler( void )
{
-MessageBufferHandle_t xUpdatedMessageBuffer;
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* xControlMessageBuffer contains the handle of the message buffer that
- contains data. */
- if( xMessageBufferReceive( xControlMessageBuffer,
- &xUpdatedMessageBuffer,
- sizeof( xUpdatedMessageBuffer ),
- mbaDONT_BLOCK ) == sizeof( xUpdatedMessageBuffer ) )
- {
- /* Call the API function that sends a notification to any task that is
- blocked on the xUpdatedMessageBuffer message buffer waiting for data to
- arrive. */
- xMessageBufferSendCompletedFromISR( xUpdatedMessageBuffer, &xHigherPriorityTaskWoken );
- }
-
- /* Normal FreeRTOS yield from interrupt semantics, where
- xHigherPriorityTaskWoken is initialized to pdFALSE and will then get set to
- pdTRUE if the interrupt safe API unblocks a task that has a priority above
- that of the currently executing task. */
- portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
+ MessageBufferHandle_t xUpdatedMessageBuffer;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+
+ /* xControlMessageBuffer contains the handle of the message buffer that
+ * contains data. */
+ if( xMessageBufferReceive( xControlMessageBuffer,
+ &xUpdatedMessageBuffer,
+ sizeof( xUpdatedMessageBuffer ),
+ mbaDONT_BLOCK ) == sizeof( xUpdatedMessageBuffer ) )
+ {
+ /* Call the API function that sends a notification to any task that is
+ * blocked on the xUpdatedMessageBuffer message buffer waiting for data to
+ * arrive. */
+ xMessageBufferSendCompletedFromISR( xUpdatedMessageBuffer, &xHigherPriorityTaskWoken );
+ }
+
+ /* Normal FreeRTOS yield from interrupt semantics, where
+ * xHigherPriorityTaskWoken is initialized to pdFALSE and will then get set to
+ * pdTRUE if the interrupt safe API unblocks a task that has a priority above
+ * that of the currently executing task. */
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
/*-----------------------------------------------------------*/
BaseType_t xAreMessageBufferAMPTasksStillRunning( void )
{
-static uint32_t ulLastCycleCounters[ mbaNUMBER_OF_CORE_B_TASKS ] = { 0 };
-BaseType_t x;
-
- /* Called by the check task to determine the health status of the tasks
- implemented in this demo. */
- for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
- {
- if( ulLastCycleCounters[ x ] == ulCycleCounters[ x ] )
- {
- xDemoStatus = pdFAIL;
- }
- else
- {
- ulLastCycleCounters[ x ] = ulCycleCounters[ x ];
- }
- }
-
- return xDemoStatus;
+ static uint32_t ulLastCycleCounters[ mbaNUMBER_OF_CORE_B_TASKS ] = { 0 };
+ BaseType_t x;
+
+ /* Called by the check task to determine the health status of the tasks
+ * implemented in this demo. */
+ for( x = 0; x < mbaNUMBER_OF_CORE_B_TASKS; x++ )
+ {
+ if( ulLastCycleCounters[ x ] == ulCycleCounters[ x ] )
+ {
+ xDemoStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastCycleCounters[ x ] = ulCycleCounters[ x ];
+ }
+ }
+
+ return xDemoStatus;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c
index 170646c4f..5d018a02e 100644
--- a/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c
+++ b/FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c
@@ -38,29 +38,29 @@
#include "MessageBufferDemo.h"
/* The number of bytes of storage in the message buffers used in this test. */
-#define mbMESSAGE_BUFFER_LENGTH_BYTES ( ( size_t ) 50 )
+#define mbMESSAGE_BUFFER_LENGTH_BYTES ( ( size_t ) 50 )
/* The number of additional bytes used to store the length of each message. */
-#define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
+#define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
/* Start and end ASCII characters used in messages sent to the buffers. */
-#define mbASCII_SPACE 32
-#define mbASCII_TILDA 126
+#define mbASCII_SPACE 32
+#define mbASCII_TILDA 126
/* Defines the number of tasks to create in this test and demo. */
-#define mbNUMBER_OF_ECHO_CLIENTS ( 2 )
-#define mbNUMBER_OF_SENDER_TASKS ( 2 )
+#define mbNUMBER_OF_ECHO_CLIENTS ( 2 )
+#define mbNUMBER_OF_SENDER_TASKS ( 2 )
/* Priority of the test tasks. The send and receive go from low to high
-priority tasks, and from high to low priority tasks. */
-#define mbLOWER_PRIORITY ( tskIDLE_PRIORITY )
-#define mbHIGHER_PRIORITY ( tskIDLE_PRIORITY + 1 )
+ * priority tasks, and from high to low priority tasks. */
+#define mbLOWER_PRIORITY ( tskIDLE_PRIORITY )
+#define mbHIGHER_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Block times used when sending and receiving from the message buffers. */
-#define mbRX_TX_BLOCK_TIME pdMS_TO_TICKS( 175UL )
+#define mbRX_TX_BLOCK_TIME pdMS_TO_TICKS( 175UL )
/* A block time of 0 means "don't block". */
-#define mbDONT_BLOCK ( 0 )
+#define mbDONT_BLOCK ( 0 )
/*-----------------------------------------------------------*/
@@ -75,771 +75,770 @@ static void prvSingleTaskTests( MessageBufferHandle_t xMessageBuffer );
* message back to the echo client which, checks it receives exactly what it
* sent.
*/
-static void prvEchoClient( void *pvParameters );
-static void prvEchoServer( void *pvParameters );
+static void prvEchoClient( void * pvParameters );
+static void prvEchoServer( void * pvParameters );
/*
* Tasks that send and receive to a message buffer at a low priority and without
* blocking, so the send and receive functions interleave in time as the tasks
* are switched in and out.
*/
-static void prvNonBlockingReceiverTask( void *pvParameters );
-static void prvNonBlockingSenderTask( void *pvParameters );
-
-#if( configSUPPORT_STATIC_ALLOCATION == 1 )
- /* This file tests both statically and dynamically allocated message buffers.
- Allocate the structures and buffers to be used by the statically allocated
- objects, which get used in the echo tests. */
- static void prvReceiverTask( void *pvParameters );
- static void prvSenderTask( void *pvParameters );
-
- static StaticMessageBuffer_t xStaticMessageBuffers[ mbNUMBER_OF_ECHO_CLIENTS ];
- static uint8_t ucBufferStorage[ mbNUMBER_OF_SENDER_TASKS ][ mbMESSAGE_BUFFER_LENGTH_BYTES + 1 ];
- static uint32_t ulSenderLoopCounters[ mbNUMBER_OF_SENDER_TASKS ] = { 0 };
+static void prvNonBlockingReceiverTask( void * pvParameters );
+static void prvNonBlockingSenderTask( void * pvParameters );
+
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+
+/* This file tests both statically and dynamically allocated message buffers.
+ * Allocate the structures and buffers to be used by the statically allocated
+ * objects, which get used in the echo tests. */
+ static void prvReceiverTask( void * pvParameters );
+ static void prvSenderTask( void * pvParameters );
+
+ static StaticMessageBuffer_t xStaticMessageBuffers[ mbNUMBER_OF_ECHO_CLIENTS ];
+ static uint8_t ucBufferStorage[ mbNUMBER_OF_SENDER_TASKS ][ mbMESSAGE_BUFFER_LENGTH_BYTES + 1 ];
+ static uint32_t ulSenderLoopCounters[ mbNUMBER_OF_SENDER_TASKS ] = { 0 };
#endif /* configSUPPORT_STATIC_ALLOCATION */
-#if( configRUN_ADDITIONAL_TESTS == 1 )
- #define mbCOHERENCE_TEST_BUFFER_SIZE 20
- #define mbCOHERENCE_TEST_BYTES_WRITTEN 5
- #define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
- #define mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ( mbCOHERENCE_TEST_BUFFER_SIZE - ( mbCOHERENCE_TEST_BYTES_WRITTEN + mbBYTES_TO_STORE_MESSAGE_LENGTH ) )
+#if ( configRUN_ADDITIONAL_TESTS == 1 )
+ #define mbCOHERENCE_TEST_BUFFER_SIZE 20
+ #define mbCOHERENCE_TEST_BYTES_WRITTEN 5
+ #define mbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )
+ #define mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ( mbCOHERENCE_TEST_BUFFER_SIZE - ( mbCOHERENCE_TEST_BYTES_WRITTEN + mbBYTES_TO_STORE_MESSAGE_LENGTH ) )
- static void prvSpaceAvailableCoherenceActor( void *pvParameters );
- static void prvSpaceAvailableCoherenceTester( void *pvParameters );
- static MessageBufferHandle_t xCoherenceTestMessageBuffer = NULL;
+ static void prvSpaceAvailableCoherenceActor( void * pvParameters );
+ static void prvSpaceAvailableCoherenceTester( void * pvParameters );
+ static MessageBufferHandle_t xCoherenceTestMessageBuffer = NULL;
- static uint32_t ulSizeCoherencyTestCycles = 0UL;
-#endif
+ static uint32_t ulSizeCoherencyTestCycles = 0UL;
+#endif /* if ( configRUN_ADDITIONAL_TESTS == 1 ) */
/*-----------------------------------------------------------*/
/* The buffers used by the echo client and server tasks. */
typedef struct ECHO_MESSAGE_BUFFERS
{
- /* Handles to the data structures that describe the message buffers. */
- MessageBufferHandle_t xEchoClientBuffer;
- MessageBufferHandle_t xEchoServerBuffer;
+ /* Handles to the data structures that describe the message buffers. */
+ MessageBufferHandle_t xEchoClientBuffer;
+ MessageBufferHandle_t xEchoServerBuffer;
} EchoMessageBuffers_t;
static uint32_t ulEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
/* The non-blocking tasks monitor their operation, and if no errors have been
-found, increment ulNonBlockingRxCounter. xAreMessageBufferTasksStillRunning()
-then checks ulNonBlockingRxCounter and only returns pdPASS if
-ulNonBlockingRxCounter is still incrementing. */
+ * found, increment ulNonBlockingRxCounter. xAreMessageBufferTasksStillRunning()
+ * then checks ulNonBlockingRxCounter and only returns pdPASS if
+ * ulNonBlockingRxCounter is still incrementing. */
static uint32_t ulNonBlockingRxCounter = 0;
/* A message that is longer than the buffer, parts of which are written to the
-message buffer to test writing different lengths at different offsets. */
-static const char *pc55ByteString = "One two three four five six seven eight nine ten eleve";
+ * message buffer to test writing different lengths at different offsets. */
+static const char * pc55ByteString = "One two three four five six seven eight nine ten eleve";
/* Remember the required stack size so tasks can be created at run time (after
-initialisation time. */
+ * initialisation time. */
static configSTACK_DEPTH_TYPE xBlockingStackSize = 0;
/*-----------------------------------------------------------*/
-void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize )
+void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize )
{
-MessageBufferHandle_t xMessageBuffer;
-
-#ifndef configMESSAGE_BUFFER_BLOCK_TASK_STACK_SIZE
- xBlockingStackSize = ( xStackSize + ( xStackSize >> 1U ) );
-#else
- xBlockingStackSize = configMESSAGE_BUFFER_BLOCK_TASK_STACK_SIZE;
-#endif
-
- /* The echo servers sets up the message buffers before creating the echo
- client tasks. One set of tasks has the server as the higher priority, and
- the other has the client as the higher priority. */
- xTaskCreate( prvEchoServer, "1EchoServer", xBlockingStackSize, NULL, mbHIGHER_PRIORITY, NULL );
- xTaskCreate( prvEchoServer, "2EchoServer", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
-
- /* The non blocking tasks run continuously and will interleave with each
- other, so must be created at the lowest priority. The message buffer they
- use is created and passed in using the task's parameter. */
- xMessageBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
- xTaskCreate( prvNonBlockingReceiverTask, "NonBlkRx", xStackSize, ( void * ) xMessageBuffer, tskIDLE_PRIORITY, NULL );
- xTaskCreate( prvNonBlockingSenderTask, "NonBlkTx", xStackSize, ( void * ) xMessageBuffer, tskIDLE_PRIORITY, NULL );
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- /* The sender tasks set up the message buffers before creating the
- receiver tasks. Priorities must be 0 and 1 as the priority is used to
- index into the xStaticMessageBuffers and ucBufferStorage arrays. */
- xTaskCreate( prvSenderTask, "1Sender", xBlockingStackSize, NULL, mbHIGHER_PRIORITY, NULL );
- xTaskCreate( prvSenderTask, "2Sender", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
- }
- #endif /* configSUPPORT_STATIC_ALLOCATION */
-
- #if( configRUN_ADDITIONAL_TESTS == 1 )
- {
- xCoherenceTestMessageBuffer = xMessageBufferCreate( mbCOHERENCE_TEST_BUFFER_SIZE );
- configASSERT( xCoherenceTestMessageBuffer );
-
- xTaskCreate( prvSpaceAvailableCoherenceActor, "mbsanity1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- xTaskCreate( prvSpaceAvailableCoherenceTester, "mbsanity2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- }
- #endif
+ MessageBufferHandle_t xMessageBuffer;
+
+ #ifndef configMESSAGE_BUFFER_BLOCK_TASK_STACK_SIZE
+ xBlockingStackSize = ( xStackSize + ( xStackSize >> 1U ) );
+ #else
+ xBlockingStackSize = configMESSAGE_BUFFER_BLOCK_TASK_STACK_SIZE;
+ #endif
+
+ /* The echo servers sets up the message buffers before creating the echo
+ * client tasks. One set of tasks has the server as the higher priority, and
+ * the other has the client as the higher priority. */
+ xTaskCreate( prvEchoServer, "1EchoServer", xBlockingStackSize, NULL, mbHIGHER_PRIORITY, NULL );
+ xTaskCreate( prvEchoServer, "2EchoServer", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
+
+ /* The non blocking tasks run continuously and will interleave with each
+ * other, so must be created at the lowest priority. The message buffer they
+ * use is created and passed in using the task's parameter. */
+ xMessageBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
+ xTaskCreate( prvNonBlockingReceiverTask, "NonBlkRx", xStackSize, ( void * ) xMessageBuffer, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( prvNonBlockingSenderTask, "NonBlkTx", xStackSize, ( void * ) xMessageBuffer, tskIDLE_PRIORITY, NULL );
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ /* The sender tasks set up the message buffers before creating the
+ * receiver tasks. Priorities must be 0 and 1 as the priority is used to
+ * index into the xStaticMessageBuffers and ucBufferStorage arrays. */
+ xTaskCreate( prvSenderTask, "1Sender", xBlockingStackSize, NULL, mbHIGHER_PRIORITY, NULL );
+ xTaskCreate( prvSenderTask, "2Sender", xBlockingStackSize, NULL, mbLOWER_PRIORITY, NULL );
+ }
+ #endif /* configSUPPORT_STATIC_ALLOCATION */
+
+ #if ( configRUN_ADDITIONAL_TESTS == 1 )
+ {
+ xCoherenceTestMessageBuffer = xMessageBufferCreate( mbCOHERENCE_TEST_BUFFER_SIZE );
+ configASSERT( xCoherenceTestMessageBuffer );
+
+ xTaskCreate( prvSpaceAvailableCoherenceActor, "mbsanity1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( prvSpaceAvailableCoherenceTester, "mbsanity2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ }
+ #endif
}
/*-----------------------------------------------------------*/
static void prvSingleTaskTests( MessageBufferHandle_t xMessageBuffer )
{
-size_t xReturned, xItem, xExpectedSpace, xNextLength;
-const size_t xMax6ByteMessages = mbMESSAGE_BUFFER_LENGTH_BYTES / ( 6 + mbBYTES_TO_STORE_MESSAGE_LENGTH );
-const size_t x6ByteLength = 6, x17ByteLength = 17;
-uint8_t *pucFullBuffer, *pucData, *pucReadData;
-TickType_t xTimeBeforeCall, xTimeAfterCall;
-const TickType_t xBlockTime = pdMS_TO_TICKS( 25 ), xAllowableMargin = pdMS_TO_TICKS( 3 );
-UBaseType_t uxOriginalPriority;
-
- /* Remove warning in case configASSERT() is not defined. */
- ( void ) xAllowableMargin;
-
- /* To minimise stack and heap usage a full size buffer is allocated from
- the heap, then buffers which hold smaller amounts of data are overlayed
- with the larger buffer - just make sure not to use both at once!. */
- pucFullBuffer = pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
- configASSERT( pucFullBuffer );
-
- pucData = pucFullBuffer;
- pucReadData = pucData + x17ByteLength;
-
- /* Nothing has been added or removed yet, so expect the free space to be
- exactly as created and the length of the next message to be 0. */
- xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );
- configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
- configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == 0 );
- /* In case configASSERT() is not define. */
- ( void ) xExpectedSpace;
- ( void ) xNextLength;
-
- /* Try sending more bytes than possible, first using the FromISR version, then
- with an infinite block time to ensure this task does not lock up. */
- xReturned = xMessageBufferSendFromISR( xMessageBuffer, ( void * ) pucData, mbMESSAGE_BUFFER_LENGTH_BYTES + sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ), NULL );
- configASSERT( xReturned == ( size_t ) 0 );
- /* In case configASSERT() is not defined. */
- ( void ) xReturned;
- xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, mbMESSAGE_BUFFER_LENGTH_BYTES + sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ), portMAX_DELAY );
- configASSERT( xReturned == ( size_t ) 0 );
- /* In case configASSERT() is not defined. */
- ( void ) xReturned;
-
- /* The buffer is 50 bytes long. When an item is added to the buffer an
- additional 4 bytes are added to hold the item's size. That means adding
- 6 bytes to the buffer will actually add 10 bytes to the buffer. Therefore,
- with a 50 byte buffer, a maximum of 5 6 bytes items can be added before the
- buffer is completely full. NOTE: The numbers in this paragraph assume
- sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) == 4. */
- for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
- {
- configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdFALSE );
-
- /* Generate recognisable data to write to the buffer. This is just
- ascii characters that shows which loop iteration the data was written
- in. The 'FromISR' version is used to give it some exercise as a block
- time is not used. That requires the call to be in a critical section
- so this code can also run on FreeRTOS ports that do not support
- interrupt nesting (and so don't have interrupt safe critical
- sections).*/
- memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
- taskENTER_CRITICAL();
- {
- xReturned = xMessageBufferSendFromISR( xMessageBuffer, ( void * ) pucData, x6ByteLength, NULL );
- }
- taskEXIT_CRITICAL();
- configASSERT( xReturned == x6ByteLength );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* The space in the buffer will have reduced by the amount of user data
- written into the buffer and the amount of space used to store the length
- of the data written into the buffer. */
- xExpectedSpace -= ( x6ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
- xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
- configASSERT( xReturned == xExpectedSpace );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Only 6 byte messages are written. */
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == x6ByteLength );
- ( void ) xNextLength; /* In case configASSERT() is not defined. */
- }
-
- /* Now the buffer should be full, and attempting to add anything will should
- fail. */
- configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdTRUE );
- xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), mbDONT_BLOCK );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Adding with a timeout should also fail after the appropriate time. The
- priority is temporarily boosted in this part of the test to keep the
- allowable margin to a minimum. */
- uxOriginalPriority = uxTaskPriorityGet( NULL );
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
- xTimeBeforeCall = xTaskGetTickCount();
- xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), xBlockTime );
- xTimeAfterCall = xTaskGetTickCount();
- vTaskPrioritySet( NULL, uxOriginalPriority );
- configASSERT( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );
- configASSERT( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- ( void ) xTimeBeforeCall;
- ( void ) xTimeAfterCall;
-
-
- /* The buffer is now full of data in the form "000000", "111111", etc. Make
- sure the data is read out as expected. */
- for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
- {
- /* Generate the data that is expected to be read out for this loop
- iteration. */
- memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
-
- /* Try reading the message into a buffer that is too small. The message
- should remain in the buffer. */
- xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x6ByteLength - 1, mbDONT_BLOCK );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Should still be at least one 6 byte message still available. */
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == x6ByteLength );
- ( void ) xNextLength; /* In case configASSERT() is not defined. */
-
- /* Read the next 6 bytes out. The 'FromISR' version is used to give it
- some exercise as a block time is not used. THa requires the code to be
- in a critical section so this test can be run with FreeRTOS ports that
- do not support interrupt nesting (and therefore don't have interrupt
- safe critical sections). */
- taskENTER_CRITICAL();
- {
- xReturned = xMessageBufferReceiveFromISR( xMessageBuffer, ( void * ) pucReadData, x6ByteLength, NULL );
- }
- taskEXIT_CRITICAL();
- configASSERT( xReturned == x6ByteLength );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Does the data read out match that expected? */
- configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x6ByteLength ) == 0 );
-
- /* The space in the buffer will have increased by the amount of user
- data read from into the buffer and the amount of space used to store the
- length of the data read into the buffer. */
- xExpectedSpace += ( x6ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
- xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
- configASSERT( xReturned == xExpectedSpace );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- }
-
- /* The buffer should be empty again. */
- configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );
- xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );
- configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
- ( void ) xExpectedSpace; /* In case configASSERT() is not defined. */
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == 0 );
- ( void ) xNextLength; /* In case configASSERT() is not defined. */
-
-
- /* Reading with a timeout should also fail after the appropriate time. The
- priority is temporarily boosted in this part of the test to keep the
- allowable margin to a minimum. */
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
- xTimeBeforeCall = xTaskGetTickCount();
- xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x6ByteLength, xBlockTime );
- xTimeAfterCall = xTaskGetTickCount();
- vTaskPrioritySet( NULL, uxOriginalPriority );
- configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) >= xBlockTime );
- configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) < ( xBlockTime + xAllowableMargin ) );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- ( void ) xTimeBeforeCall;
- ( void ) xTimeAfterCall;
-
-
- /* In the next loop 17 bytes are written to then read out on each iteration.
- The expected length variable is always used after 17 bytes have been written
- into the buffer - the length of the message is also written, making a total
- of 21 bytes consumed for each 17 byte message. */
- xExpectedSpace = mbMESSAGE_BUFFER_LENGTH_BYTES - ( x17ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
-
- /* Reading and writing 17 bytes at a time will result in 21 bytes being
- written into the buffer, and as 50 is not divisible by 21, writing multiple
- times will cause the data to wrap in the buffer.*/
- for( xItem = 0; xItem < 100; xItem++ )
- {
- /* Generate recognisable data to write to the queue. This is just
- ascii characters that shows which loop iteration the data was written
- in. */
- memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x17ByteLength );
- xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, x17ByteLength, mbDONT_BLOCK );
- configASSERT( xReturned == x17ByteLength );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Only 17 byte messages are written. */
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == x17ByteLength );
- ( void ) xNextLength; /* In case configASSERT() is not defined. */
-
- /* The space in the buffer will have reduced by the amount of user data
- written into the buffer and the amount of space used to store the length
- of the data written into the buffer. */
- xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
- configASSERT( xReturned == xExpectedSpace );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Read the 17 bytes out again. */
- xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x17ByteLength, mbDONT_BLOCK );
- configASSERT( xReturned == x17ByteLength );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Does the data read out match that expected? */
- configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );
-
- /* Don't expect any messages to be available as the data was read out
- again. */
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == 0 );
- ( void ) xNextLength; /* In case configASSERT() is not defined. */
- }
-
- /* The buffer should be empty again. */
- configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );
- xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );
- configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
-
- /* Cannot write within sizeof( size_t ) (assumed to be 4 bytes in this test)
- bytes of the full 50 bytes, as that would not leave space for the four bytes
- taken by the data length. */
- xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES, mbDONT_BLOCK );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- #ifndef configMESSAGE_BUFFER_LENGTH_TYPE
- {
- /* The following will fail if configMESSAGE_BUFFER_LENGTH_TYPE is set
- to a non 32-bit type. */
- xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 1, mbDONT_BLOCK );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 2, mbDONT_BLOCK );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 3, mbDONT_BLOCK );
- configASSERT( xReturned == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- }
- #endif
-
- /* Don't expect any messages to be available as the above were too large to
- get written. */
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == 0 );
- ( void ) xNextLength; /* In case configASSERT() is not defined. */
-
- /* Can write mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) bytes though. */
- xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ), mbDONT_BLOCK );
- configASSERT( xReturned == mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
- configASSERT( xNextLength == ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) );
- ( void ) xNextLength; /* In case configASSERT() is not defined. */
- xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucFullBuffer, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ), mbDONT_BLOCK );
- configASSERT( xReturned == ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- configASSERT( memcmp( ( const void * ) pucFullBuffer, pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) == 0 );
-
- /* Clean up. */
- vPortFree( pucFullBuffer );
- xMessageBufferReset( xMessageBuffer );
+ size_t xReturned, xItem, xExpectedSpace, xNextLength;
+ const size_t xMax6ByteMessages = mbMESSAGE_BUFFER_LENGTH_BYTES / ( 6 + mbBYTES_TO_STORE_MESSAGE_LENGTH );
+ const size_t x6ByteLength = 6, x17ByteLength = 17;
+ uint8_t * pucFullBuffer, * pucData, * pucReadData;
+ TickType_t xTimeBeforeCall, xTimeAfterCall;
+ const TickType_t xBlockTime = pdMS_TO_TICKS( 25 ), xAllowableMargin = pdMS_TO_TICKS( 3 );
+ UBaseType_t uxOriginalPriority;
+
+ /* Remove warning in case configASSERT() is not defined. */
+ ( void ) xAllowableMargin;
+
+ /* To minimise stack and heap usage a full size buffer is allocated from
+ * the heap, then buffers which hold smaller amounts of data are overlayed
+ * with the larger buffer - just make sure not to use both at once!. */
+ pucFullBuffer = pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
+ configASSERT( pucFullBuffer );
+
+ pucData = pucFullBuffer;
+ pucReadData = pucData + x17ByteLength;
+
+ /* Nothing has been added or removed yet, so expect the free space to be
+ * exactly as created and the length of the next message to be 0. */
+ xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );
+ configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
+ configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == 0 );
+ /* In case configASSERT() is not define. */
+ ( void ) xExpectedSpace;
+ ( void ) xNextLength;
+
+ /* Try sending more bytes than possible, first using the FromISR version, then
+ * with an infinite block time to ensure this task does not lock up. */
+ xReturned = xMessageBufferSendFromISR( xMessageBuffer, ( void * ) pucData, mbMESSAGE_BUFFER_LENGTH_BYTES + sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ), NULL );
+ configASSERT( xReturned == ( size_t ) 0 );
+ /* In case configASSERT() is not defined. */
+ ( void ) xReturned;
+ xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, mbMESSAGE_BUFFER_LENGTH_BYTES + sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ), portMAX_DELAY );
+ configASSERT( xReturned == ( size_t ) 0 );
+ /* In case configASSERT() is not defined. */
+ ( void ) xReturned;
+
+ /* The buffer is 50 bytes long. When an item is added to the buffer an
+ * additional 4 bytes are added to hold the item's size. That means adding
+ * 6 bytes to the buffer will actually add 10 bytes to the buffer. Therefore,
+ * with a 50 byte buffer, a maximum of 5 6 bytes items can be added before the
+ * buffer is completely full. NOTE: The numbers in this paragraph assume
+ * sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) == 4. */
+ for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
+ {
+ configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdFALSE );
+
+ /* Generate recognisable data to write to the buffer. This is just
+ * ascii characters that shows which loop iteration the data was written
+ * in. The 'FromISR' version is used to give it some exercise as a block
+ * time is not used. That requires the call to be in a critical section
+ * so this code can also run on FreeRTOS ports that do not support
+ * interrupt nesting (and so don't have interrupt safe critical
+ * sections).*/
+ memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
+ taskENTER_CRITICAL();
+ {
+ xReturned = xMessageBufferSendFromISR( xMessageBuffer, ( void * ) pucData, x6ByteLength, NULL );
+ }
+ taskEXIT_CRITICAL();
+ configASSERT( xReturned == x6ByteLength );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* The space in the buffer will have reduced by the amount of user data
+ * written into the buffer and the amount of space used to store the length
+ * of the data written into the buffer. */
+ xExpectedSpace -= ( x6ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
+ xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
+ configASSERT( xReturned == xExpectedSpace );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Only 6 byte messages are written. */
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == x6ByteLength );
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */
+ }
+
+ /* Now the buffer should be full, and attempting to add anything will should
+ * fail. */
+ configASSERT( xMessageBufferIsFull( xMessageBuffer ) == pdTRUE );
+ xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), mbDONT_BLOCK );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Adding with a timeout should also fail after the appropriate time. The
+ * priority is temporarily boosted in this part of the test to keep the
+ * allowable margin to a minimum. */
+ uxOriginalPriority = uxTaskPriorityGet( NULL );
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+ xTimeBeforeCall = xTaskGetTickCount();
+ xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), xBlockTime );
+ xTimeAfterCall = xTaskGetTickCount();
+ vTaskPrioritySet( NULL, uxOriginalPriority );
+ configASSERT( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );
+ configASSERT( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ ( void ) xTimeBeforeCall;
+ ( void ) xTimeAfterCall;
+
+ /* The buffer is now full of data in the form "000000", "111111", etc. Make
+ * sure the data is read out as expected. */
+ for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
+ {
+ /* Generate the data that is expected to be read out for this loop
+ * iteration. */
+ memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
+
+ /* Try reading the message into a buffer that is too small. The message
+ * should remain in the buffer. */
+ xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x6ByteLength - 1, mbDONT_BLOCK );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Should still be at least one 6 byte message still available. */
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == x6ByteLength );
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */
+
+ /* Read the next 6 bytes out. The 'FromISR' version is used to give it
+ * some exercise as a block time is not used. THa requires the code to be
+ * in a critical section so this test can be run with FreeRTOS ports that
+ * do not support interrupt nesting (and therefore don't have interrupt
+ * safe critical sections). */
+ taskENTER_CRITICAL();
+ {
+ xReturned = xMessageBufferReceiveFromISR( xMessageBuffer, ( void * ) pucReadData, x6ByteLength, NULL );
+ }
+ taskEXIT_CRITICAL();
+ configASSERT( xReturned == x6ByteLength );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Does the data read out match that expected? */
+ configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x6ByteLength ) == 0 );
+
+ /* The space in the buffer will have increased by the amount of user
+ * data read from into the buffer and the amount of space used to store the
+ * length of the data read into the buffer. */
+ xExpectedSpace += ( x6ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
+ xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
+ configASSERT( xReturned == xExpectedSpace );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ }
+
+ /* The buffer should be empty again. */
+ configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );
+ xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );
+ configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
+ ( void ) xExpectedSpace; /* In case configASSERT() is not defined. */
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == 0 );
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */
+
+
+ /* Reading with a timeout should also fail after the appropriate time. The
+ * priority is temporarily boosted in this part of the test to keep the
+ * allowable margin to a minimum. */
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+ xTimeBeforeCall = xTaskGetTickCount();
+ xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x6ByteLength, xBlockTime );
+ xTimeAfterCall = xTaskGetTickCount();
+ vTaskPrioritySet( NULL, uxOriginalPriority );
+ configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) >= xBlockTime );
+ configASSERT( ( xTimeAfterCall - xTimeBeforeCall ) < ( xBlockTime + xAllowableMargin ) );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ ( void ) xTimeBeforeCall;
+ ( void ) xTimeAfterCall;
+
+
+ /* In the next loop 17 bytes are written to then read out on each iteration.
+ * The expected length variable is always used after 17 bytes have been written
+ * into the buffer - the length of the message is also written, making a total
+ * of 21 bytes consumed for each 17 byte message. */
+ xExpectedSpace = mbMESSAGE_BUFFER_LENGTH_BYTES - ( x17ByteLength + mbBYTES_TO_STORE_MESSAGE_LENGTH );
+
+ /* Reading and writing 17 bytes at a time will result in 21 bytes being
+ * written into the buffer, and as 50 is not divisible by 21, writing multiple
+ * times will cause the data to wrap in the buffer.*/
+ for( xItem = 0; xItem < 100; xItem++ )
+ {
+ /* Generate recognisable data to write to the queue. This is just
+ * ascii characters that shows which loop iteration the data was written
+ * in. */
+ memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x17ByteLength );
+ xReturned = xMessageBufferSend( xMessageBuffer, ( void * ) pucData, x17ByteLength, mbDONT_BLOCK );
+ configASSERT( xReturned == x17ByteLength );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Only 17 byte messages are written. */
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == x17ByteLength );
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */
+
+ /* The space in the buffer will have reduced by the amount of user data
+ * written into the buffer and the amount of space used to store the length
+ * of the data written into the buffer. */
+ xReturned = xMessageBufferSpaceAvailable( xMessageBuffer );
+ configASSERT( xReturned == xExpectedSpace );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Read the 17 bytes out again. */
+ xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucReadData, x17ByteLength, mbDONT_BLOCK );
+ configASSERT( xReturned == x17ByteLength );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Does the data read out match that expected? */
+ configASSERT( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );
+
+ /* Don't expect any messages to be available as the data was read out
+ * again. */
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == 0 );
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */
+ }
+
+ /* The buffer should be empty again. */
+ configASSERT( xMessageBufferIsEmpty( xMessageBuffer ) == pdTRUE );
+ xExpectedSpace = xMessageBufferSpaceAvailable( xMessageBuffer );
+ configASSERT( xExpectedSpace == mbMESSAGE_BUFFER_LENGTH_BYTES );
+
+ /* Cannot write within sizeof( size_t ) (assumed to be 4 bytes in this test)
+ * bytes of the full 50 bytes, as that would not leave space for the four bytes
+ * taken by the data length. */
+ xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES, mbDONT_BLOCK );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ #ifndef configMESSAGE_BUFFER_LENGTH_TYPE
+ {
+ /* The following will fail if configMESSAGE_BUFFER_LENGTH_TYPE is set
+ * to a non 32-bit type. */
+ xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 1, mbDONT_BLOCK );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 2, mbDONT_BLOCK );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - 3, mbDONT_BLOCK );
+ configASSERT( xReturned == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ }
+ #endif /* ifndef configMESSAGE_BUFFER_LENGTH_TYPE */
+
+ /* Don't expect any messages to be available as the above were too large to
+ * get written. */
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == 0 );
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */
+
+ /* Can write mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) bytes though. */
+ xReturned = xMessageBufferSend( xMessageBuffer, ( const void * ) pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ), mbDONT_BLOCK );
+ configASSERT( xReturned == mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ xNextLength = xMessageBufferNextLengthBytes( xMessageBuffer );
+ configASSERT( xNextLength == ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) );
+ ( void ) xNextLength; /* In case configASSERT() is not defined. */
+ xReturned = xMessageBufferReceive( xMessageBuffer, ( void * ) pucFullBuffer, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ), mbDONT_BLOCK );
+ configASSERT( xReturned == ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ configASSERT( memcmp( ( const void * ) pucFullBuffer, pc55ByteString, mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) == 0 );
+
+ /* Clean up. */
+ vPortFree( pucFullBuffer );
+ xMessageBufferReset( xMessageBuffer );
}
/*-----------------------------------------------------------*/
-static void prvNonBlockingSenderTask( void *pvParameters )
+static void prvNonBlockingSenderTask( void * pvParameters )
{
-MessageBufferHandle_t xMessageBuffer;
-int32_t iDataToSend = 0;
-size_t xStringLength;
-const int32_t iMaxValue = 1500;
-char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
-
- /* In this case the message buffer has already been created and is passed
- into the task using the task's parameter. */
- xMessageBuffer = ( MessageBufferHandle_t ) pvParameters;
-
- /* Create a string from an incrementing number. The length of the
- string will increase and decrease as the value of the number increases
- then overflows. */
- memset( cTxString, 0x00, sizeof( cTxString ) );
- sprintf( cTxString, "%d", ( int ) iDataToSend );
- xStringLength = strlen( cTxString );
-
- for( ;; )
- {
- /* Doesn't block so calls can interleave with the non-blocking
- receives performed by prvNonBlockingReceiverTask(). */
- if( xMessageBufferSend( xMessageBuffer, ( void * ) cTxString, strlen( cTxString ), mbDONT_BLOCK ) == xStringLength )
- {
- iDataToSend++;
-
- if( iDataToSend > iMaxValue )
- {
- /* The value sent is reset back to 0 to ensure the string being sent
- does not remain at the same length for too long. */
- iDataToSend = 0;
- }
-
- /* Create the next string. */
- memset( cTxString, 0x00, sizeof( cTxString ) );
- sprintf( cTxString, "%d", ( int ) iDataToSend );
- xStringLength = strlen( cTxString );
- }
- }
+ MessageBufferHandle_t xMessageBuffer;
+ int32_t iDataToSend = 0;
+ size_t xStringLength;
+ const int32_t iMaxValue = 1500;
+ char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
+
+ /* In this case the message buffer has already been created and is passed
+ * into the task using the task's parameter. */
+
+ xMessageBuffer = ( MessageBufferHandle_t ) pvParameters;
+
+ /* Create a string from an incrementing number. The length of the
+ * string will increase and decrease as the value of the number increases
+ * then overflows. */
+ memset( cTxString, 0x00, sizeof( cTxString ) );
+ sprintf( cTxString, "%d", ( int ) iDataToSend );
+ xStringLength = strlen( cTxString );
+
+ for( ; ; )
+ {
+ /* Doesn't block so calls can interleave with the non-blocking
+ * receives performed by prvNonBlockingReceiverTask(). */
+ if( xMessageBufferSend( xMessageBuffer, ( void * ) cTxString, strlen( cTxString ), mbDONT_BLOCK ) == xStringLength )
+ {
+ iDataToSend++;
+
+ if( iDataToSend > iMaxValue )
+ {
+ /* The value sent is reset back to 0 to ensure the string being sent
+ * does not remain at the same length for too long. */
+ iDataToSend = 0;
+ }
+
+ /* Create the next string. */
+ memset( cTxString, 0x00, sizeof( cTxString ) );
+ sprintf( cTxString, "%d", ( int ) iDataToSend );
+ xStringLength = strlen( cTxString );
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prvNonBlockingReceiverTask( void *pvParameters )
+static void prvNonBlockingReceiverTask( void * pvParameters )
{
-MessageBufferHandle_t xMessageBuffer;
-BaseType_t xNonBlockingReceiveError = pdFALSE;
-int32_t iDataToSend = 0;
-size_t xStringLength, xReceiveLength;
-const int32_t iMaxValue = 1500;
-char cExpectedString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
-char cRxString[ 12 ];
-
- /* In this case the message buffer has already been created and is passed
- into the task using the task's parameter. */
- xMessageBuffer = ( MessageBufferHandle_t ) pvParameters;
-
- /* Create a string from an incrementing number. The length of the
- string will increase and decrease as the value of the number increases
- then overflows. This should always match the string sent to the buffer by
- the non blocking sender task. */
- memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
- memset( cRxString, 0x00, sizeof( cRxString ) );
- sprintf( cExpectedString, "%d", ( int ) iDataToSend );
- xStringLength = strlen( cExpectedString );
-
- for( ;; )
- {
- /* Doesn't block so calls can interleave with the non-blocking
- receives performed by prvNonBlockingReceiverTask(). */
- xReceiveLength = xMessageBufferReceive( xMessageBuffer, ( void * ) cRxString, sizeof( cRxString ), mbDONT_BLOCK );
-
- /* Should only ever receive no data is available, or the expected
- length of data is available. */
- if( ( xReceiveLength != 0 ) && ( xReceiveLength != xStringLength ) )
- {
- xNonBlockingReceiveError = pdTRUE;
- }
-
- if( xReceiveLength == xStringLength )
- {
- /* Ensure the received data was that expected, then generate the
- next expected string. */
- if( strcmp( cRxString, cExpectedString ) != 0 )
- {
- xNonBlockingReceiveError = pdTRUE;
- }
-
- iDataToSend++;
-
- if( iDataToSend > iMaxValue )
- {
- /* The value sent is reset back to 0 to ensure the string being sent
- does not remain at the same length for too long. */
- iDataToSend = 0;
- }
-
- memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
- memset( cRxString, 0x00, sizeof( cRxString ) );
- sprintf( cExpectedString, "%d", ( int ) iDataToSend );
- xStringLength = strlen( cExpectedString );
-
- if( xNonBlockingReceiveError == pdFALSE )
- {
- /* No errors detected so increment the counter that lets the
- check task know this test is still functioning correctly. */
- ulNonBlockingRxCounter++;
- }
- }
- }
+ MessageBufferHandle_t xMessageBuffer;
+ BaseType_t xNonBlockingReceiveError = pdFALSE;
+ int32_t iDataToSend = 0;
+ size_t xStringLength, xReceiveLength;
+ const int32_t iMaxValue = 1500;
+ char cExpectedString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
+ char cRxString[ 12 ];
+
+ /* In this case the message buffer has already been created and is passed
+ * into the task using the task's parameter. */
+ xMessageBuffer = ( MessageBufferHandle_t ) pvParameters;
+
+ /* Create a string from an incrementing number. The length of the
+ * string will increase and decrease as the value of the number increases
+ * then overflows. This should always match the string sent to the buffer by
+ * the non blocking sender task. */
+ memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
+ memset( cRxString, 0x00, sizeof( cRxString ) );
+ sprintf( cExpectedString, "%d", ( int ) iDataToSend );
+ xStringLength = strlen( cExpectedString );
+
+ for( ; ; )
+ {
+ /* Doesn't block so calls can interleave with the non-blocking
+ * receives performed by prvNonBlockingReceiverTask(). */
+ xReceiveLength = xMessageBufferReceive( xMessageBuffer, ( void * ) cRxString, sizeof( cRxString ), mbDONT_BLOCK );
+
+ /* Should only ever receive no data is available, or the expected
+ * length of data is available. */
+ if( ( xReceiveLength != 0 ) && ( xReceiveLength != xStringLength ) )
+ {
+ xNonBlockingReceiveError = pdTRUE;
+ }
+
+ if( xReceiveLength == xStringLength )
+ {
+ /* Ensure the received data was that expected, then generate the
+ * next expected string. */
+ if( strcmp( cRxString, cExpectedString ) != 0 )
+ {
+ xNonBlockingReceiveError = pdTRUE;
+ }
+
+ iDataToSend++;
+
+ if( iDataToSend > iMaxValue )
+ {
+ /* The value sent is reset back to 0 to ensure the string being sent
+ * does not remain at the same length for too long. */
+ iDataToSend = 0;
+ }
+
+ memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
+ memset( cRxString, 0x00, sizeof( cRxString ) );
+ sprintf( cExpectedString, "%d", ( int ) iDataToSend );
+ xStringLength = strlen( cExpectedString );
+
+ if( xNonBlockingReceiveError == pdFALSE )
+ {
+ /* No errors detected so increment the counter that lets the
+ * check task know this test is still functioning correctly. */
+ ulNonBlockingRxCounter++;
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
-#if( configSUPPORT_STATIC_ALLOCATION == 1 )
-
- static void prvSenderTask( void *pvParameters )
- {
- MessageBufferHandle_t xMessageBuffer, xTempMessageBuffer;
- int32_t iDataToSend = 0;
- const int32_t iSendsBetweenIncrements = 100;
- char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
- const TickType_t xTicksToWait = mbRX_TX_BLOCK_TIME, xShortDelay = pdMS_TO_TICKS( 50 );
- StaticMessageBuffer_t xStaticMessageBuffer;
- size_t xBytesSent;
-
-
- /* The task's priority is used as an index into the loop counters used to
- indicate this task is still running. */
- UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
-
- /* Make sure a change in priority does not inadvertently result in an
- invalid array index. */
- configASSERT( uxIndex < mbNUMBER_OF_ECHO_CLIENTS );
-
- /* Avoid compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucBufferStorage ) / mbNUMBER_OF_SENDER_TASKS, /* The number of bytes in each buffer in the array. */
- &( ucBufferStorage[ uxIndex ][ 0 ] ), /* The address of the buffer to use within the array. */
- &( xStaticMessageBuffers[ uxIndex ] ) ); /* The static message buffer structure to use within the array. */
-
- /* Now the message buffer has been created the receiver task can be created.
- If this sender task has the higher priority then the receiver task is
- created at the lower priority - if this sender task has the lower priority
- then the receiver task is created at the higher priority. */
- if( uxTaskPriorityGet( NULL ) == mbLOWER_PRIORITY )
- {
- /* Here prvSingleTaskTests() performs various tests on a message buffer
- that was created statically. */
- prvSingleTaskTests( xMessageBuffer );
- xTaskCreate( prvReceiverTask, "MsgReceiver", xBlockingStackSize, ( void * ) xMessageBuffer, mbHIGHER_PRIORITY, NULL );
- }
- else
- {
- xTaskCreate( prvReceiverTask, "MsgReceiver", xBlockingStackSize, ( void * ) xMessageBuffer, mbLOWER_PRIORITY, NULL );
- }
-
- for( ;; )
- {
- /* Create a string from an incrementing number. The length of the
- string will increase and decrease as the value of the number increases
- then overflows. */
- memset( cTxString, 0x00, sizeof( cTxString ) );
- sprintf( cTxString, "%d", ( int ) iDataToSend );
-
- do
- {
- xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) cTxString, strlen( cTxString ), xTicksToWait );
- } while ( xBytesSent == 0 ); /* Buffer may become full when receiver is running at the idle priority. */
-
- iDataToSend++;
-
- if( ( iDataToSend % iSendsBetweenIncrements ) == 0 )
- {
- /* Increment a loop counter so a check task can tell this task is
- still running as expected. */
- ulSenderLoopCounters[ uxIndex ]++;
-
- if( uxTaskPriorityGet( NULL ) == mbHIGHER_PRIORITY )
- {
- /* Allow other tasks to run. */
- vTaskDelay( xShortDelay );
- }
-
- /* This message buffer is just created and deleted to ensure no
- issues when attempting to delete a message buffer that was
- created using statically allocated memory. To save stack space
- the buffer is set to point to the cTxString array - this is
- ok because nothing is actually written to the memory. */
- xTempMessageBuffer = xMessageBufferCreateStatic( sizeof( cTxString ), ( uint8_t * ) cTxString, &xStaticMessageBuffer );
- vMessageBufferDelete( xTempMessageBuffer );
- }
- }
- }
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+
+ static void prvSenderTask( void * pvParameters )
+ {
+ MessageBufferHandle_t xMessageBuffer, xTempMessageBuffer;
+ int32_t iDataToSend = 0;
+ const int32_t iSendsBetweenIncrements = 100;
+ char cTxString[ 12 ]; /* Large enough to hold a 32 number in ASCII. */
+ const TickType_t xTicksToWait = mbRX_TX_BLOCK_TIME, xShortDelay = pdMS_TO_TICKS( 50 );
+ StaticMessageBuffer_t xStaticMessageBuffer;
+ size_t xBytesSent;
+
+
+ /* The task's priority is used as an index into the loop counters used to
+ * indicate this task is still running. */
+ UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
+
+ /* Make sure a change in priority does not inadvertently result in an
+ * invalid array index. */
+ configASSERT( uxIndex < mbNUMBER_OF_ECHO_CLIENTS );
+
+ /* Avoid compiler warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ xMessageBuffer = xMessageBufferCreateStatic( sizeof( ucBufferStorage ) / mbNUMBER_OF_SENDER_TASKS, /* The number of bytes in each buffer in the array. */
+ &( ucBufferStorage[ uxIndex ][ 0 ] ), /* The address of the buffer to use within the array. */
+ &( xStaticMessageBuffers[ uxIndex ] ) ); /* The static message buffer structure to use within the array. */
+
+ /* Now the message buffer has been created the receiver task can be created.
+ * If this sender task has the higher priority then the receiver task is
+ * created at the lower priority - if this sender task has the lower priority
+ * then the receiver task is created at the higher priority. */
+ if( uxTaskPriorityGet( NULL ) == mbLOWER_PRIORITY )
+ {
+ /* Here prvSingleTaskTests() performs various tests on a message buffer
+ * that was created statically. */
+ prvSingleTaskTests( xMessageBuffer );
+ xTaskCreate( prvReceiverTask, "MsgReceiver", xBlockingStackSize, ( void * ) xMessageBuffer, mbHIGHER_PRIORITY, NULL );
+ }
+ else
+ {
+ xTaskCreate( prvReceiverTask, "MsgReceiver", xBlockingStackSize, ( void * ) xMessageBuffer, mbLOWER_PRIORITY, NULL );
+ }
+
+ for( ; ; )
+ {
+ /* Create a string from an incrementing number. The length of the
+ * string will increase and decrease as the value of the number increases
+ * then overflows. */
+ memset( cTxString, 0x00, sizeof( cTxString ) );
+ sprintf( cTxString, "%d", ( int ) iDataToSend );
+
+ do
+ {
+ xBytesSent = xMessageBufferSend( xMessageBuffer, ( void * ) cTxString, strlen( cTxString ), xTicksToWait );
+ } while( xBytesSent == 0 ); /* Buffer may become full when receiver is running at the idle priority. */
+
+ iDataToSend++;
+
+ if( ( iDataToSend % iSendsBetweenIncrements ) == 0 )
+ {
+ /* Increment a loop counter so a check task can tell this task is
+ * still running as expected. */
+ ulSenderLoopCounters[ uxIndex ]++;
+
+ if( uxTaskPriorityGet( NULL ) == mbHIGHER_PRIORITY )
+ {
+ /* Allow other tasks to run. */
+ vTaskDelay( xShortDelay );
+ }
+
+ /* This message buffer is just created and deleted to ensure no
+ * issues when attempting to delete a message buffer that was
+ * created using statically allocated memory. To save stack space
+ * the buffer is set to point to the cTxString array - this is
+ * ok because nothing is actually written to the memory. */
+ xTempMessageBuffer = xMessageBufferCreateStatic( sizeof( cTxString ), ( uint8_t * ) cTxString, &xStaticMessageBuffer );
+ vMessageBufferDelete( xTempMessageBuffer );
+ }
+ }
+ }
#endif /* configSUPPORT_STATIC_ALLOCATION */
/*-----------------------------------------------------------*/
-#if( configSUPPORT_STATIC_ALLOCATION == 1 )
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
- static void prvReceiverTask( void *pvParameters )
- {
- MessageBufferHandle_t * const pxMessageBuffer = ( MessageBufferHandle_t * ) pvParameters;
- char cExpectedString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */
- char cReceivedString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */
- int32_t iExpectedData = 0;
- const TickType_t xTicksToWait = pdMS_TO_TICKS( 5UL );
- size_t xReceivedBytes;
+ static void prvReceiverTask( void * pvParameters )
+ {
+ MessageBufferHandle_t * const pxMessageBuffer = ( MessageBufferHandle_t * ) pvParameters;
+ char cExpectedString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */
+ char cReceivedString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */
+ int32_t iExpectedData = 0;
+ const TickType_t xTicksToWait = pdMS_TO_TICKS( 5UL );
+ size_t xReceivedBytes;
- for( ;; )
- {
- /* Generate the next expected string in the cExpectedString buffer. */
- memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
- sprintf( cExpectedString, "%d", ( int ) iExpectedData );
+ for( ; ; )
+ {
+ /* Generate the next expected string in the cExpectedString buffer. */
+ memset( cExpectedString, 0x00, sizeof( cExpectedString ) );
+ sprintf( cExpectedString, "%d", ( int ) iExpectedData );
- /* Receive the next string from the message buffer. */
- memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
+ /* Receive the next string from the message buffer. */
+ memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
- do
- {
- xReceivedBytes = xMessageBufferReceive( pxMessageBuffer, ( void * ) cReceivedString, sizeof( cExpectedString ), xTicksToWait );
+ do
+ {
+ xReceivedBytes = xMessageBufferReceive( pxMessageBuffer, ( void * ) cReceivedString, sizeof( cExpectedString ), xTicksToWait );
+ } while( xReceivedBytes == 0 );
- } while( xReceivedBytes == 0 );
+ /* Ensure the received string matches the expected string. */
+ configASSERT( strcmp( cExpectedString, cReceivedString ) == 0 );
- /* Ensure the received string matches the expected string. */
- configASSERT( strcmp( cExpectedString, cReceivedString ) == 0 );
-
- iExpectedData++;
- }
- }
+ iExpectedData++;
+ }
+ }
#endif /* configSUPPORT_STATIC_ALLOCATION */
/*-----------------------------------------------------------*/
-static void prvEchoClient( void *pvParameters )
+static void prvEchoClient( void * pvParameters )
{
-size_t xSendLength = 0, ux;
-char *pcStringToSend, *pcStringReceived, cNextChar = mbASCII_SPACE;
-const TickType_t xTicksToWait = pdMS_TO_TICKS( 50 );
+ size_t xSendLength = 0, ux;
+ char * pcStringToSend, * pcStringReceived, cNextChar = mbASCII_SPACE;
+ const TickType_t xTicksToWait = pdMS_TO_TICKS( 50 );
/* The task's priority is used as an index into the loop counters used to
-indicate this task is still running. */
-UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
+ * indicate this task is still running. */
+ UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
/* Pointers to the client and server message buffers are passed into this task
-using the task's parameter. */
-EchoMessageBuffers_t *pxMessageBuffers = ( EchoMessageBuffers_t * ) pvParameters;
-
- /* Prevent compiler warnings. */
- ( void ) pvParameters;
-
- /* Create the buffer into which strings to send to the server will be
- created, and the buffer into which strings echoed back from the server will
- be copied. */
- pcStringToSend = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
- pcStringReceived = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
-
- configASSERT( pcStringToSend );
- configASSERT( pcStringReceived );
-
- for( ;; )
- {
- /* Generate the length of the next string to send. */
- xSendLength++;
-
- /* The message buffer is being used to hold variable length data, so
- each data item requires sizeof( size_t ) bytes to hold the data's
- length, hence the sizeof() in the if() condition below. */
- if( xSendLength > ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) )
- {
- /* Back to a string length of 1. */
- xSendLength = sizeof( char );
-
- /* Maintain a count of the number of times this code executes so a
- check task can determine if this task is still functioning as
- expected or not. As there are two client tasks, and the priorities
- used are 0 and 1, the task's priority is used as an index into the
- loop count array. */
- ulEchoLoopCounters[ uxIndex ]++;
- }
-
- memset( pcStringToSend, 0x00, mbMESSAGE_BUFFER_LENGTH_BYTES );
-
- for( ux = 0; ux < xSendLength; ux++ )
- {
- pcStringToSend[ ux ] = cNextChar;
-
- cNextChar++;
-
- if( cNextChar > mbASCII_TILDA )
- {
- cNextChar = mbASCII_SPACE;
- }
- }
-
- /* Send the generated string to the buffer. */
- do
- {
- ux = xMessageBufferSend( pxMessageBuffers->xEchoClientBuffer, ( void * ) pcStringToSend, xSendLength, xTicksToWait );
-
- if( ux == 0 )
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
- } while( ux == 0 );
-
- /* Wait for the string to be echoed back. */
- memset( pcStringReceived, 0x00, mbMESSAGE_BUFFER_LENGTH_BYTES );
- xMessageBufferReceive( pxMessageBuffers->xEchoServerBuffer, ( void * ) pcStringReceived, xSendLength, portMAX_DELAY );
-
- configASSERT( strcmp( pcStringToSend, pcStringReceived ) == 0 );
- }
+ * using the task's parameter. */
+ EchoMessageBuffers_t * pxMessageBuffers = ( EchoMessageBuffers_t * ) pvParameters;
+
+ /* Prevent compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Create the buffer into which strings to send to the server will be
+ * created, and the buffer into which strings echoed back from the server will
+ * be copied. */
+ pcStringToSend = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
+ pcStringReceived = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
+
+ configASSERT( pcStringToSend );
+ configASSERT( pcStringReceived );
+
+ for( ; ; )
+ {
+ /* Generate the length of the next string to send. */
+ xSendLength++;
+
+ /* The message buffer is being used to hold variable length data, so
+ * each data item requires sizeof( size_t ) bytes to hold the data's
+ * length, hence the sizeof() in the if() condition below. */
+ if( xSendLength > ( mbMESSAGE_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) )
+ {
+ /* Back to a string length of 1. */
+ xSendLength = sizeof( char );
+
+ /* Maintain a count of the number of times this code executes so a
+ * check task can determine if this task is still functioning as
+ * expected or not. As there are two client tasks, and the priorities
+ * used are 0 and 1, the task's priority is used as an index into the
+ * loop count array. */
+ ulEchoLoopCounters[ uxIndex ]++;
+ }
+
+ memset( pcStringToSend, 0x00, mbMESSAGE_BUFFER_LENGTH_BYTES );
+
+ for( ux = 0; ux < xSendLength; ux++ )
+ {
+ pcStringToSend[ ux ] = cNextChar;
+
+ cNextChar++;
+
+ if( cNextChar > mbASCII_TILDA )
+ {
+ cNextChar = mbASCII_SPACE;
+ }
+ }
+
+ /* Send the generated string to the buffer. */
+ do
+ {
+ ux = xMessageBufferSend( pxMessageBuffers->xEchoClientBuffer, ( void * ) pcStringToSend, xSendLength, xTicksToWait );
+
+ if( ux == 0 )
+ {
+ mtCOVERAGE_TEST_MARKER();
+ }
+ } while( ux == 0 );
+
+ /* Wait for the string to be echoed back. */
+ memset( pcStringReceived, 0x00, mbMESSAGE_BUFFER_LENGTH_BYTES );
+ xMessageBufferReceive( pxMessageBuffers->xEchoServerBuffer, ( void * ) pcStringReceived, xSendLength, portMAX_DELAY );
+
+ configASSERT( strcmp( pcStringToSend, pcStringReceived ) == 0 );
+ }
}
/*-----------------------------------------------------------*/
-static void prvEchoServer( void *pvParameters )
+static void prvEchoServer( void * pvParameters )
{
-MessageBufferHandle_t xTempMessageBuffer;
-size_t xReceivedLength;
-char *pcReceivedString;
-EchoMessageBuffers_t xMessageBuffers;
-TickType_t xTimeOnEntering;
-const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
-
- /* Prevent compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- /* Create the message buffer used to send data from the client to the server,
- and the message buffer used to echo the data from the server back to the
- client. */
- xMessageBuffers.xEchoClientBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
- xMessageBuffers.xEchoServerBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
- configASSERT( xMessageBuffers.xEchoClientBuffer );
- configASSERT( xMessageBuffers.xEchoServerBuffer );
-
- /* Create the buffer into which received strings will be copied. */
- pcReceivedString = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
- configASSERT( pcReceivedString );
-
- /* Don't expect to receive anything yet! */
- xTimeOnEntering = xTaskGetTickCount();
- xReceivedLength = xMessageBufferReceive( xMessageBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, mbMESSAGE_BUFFER_LENGTH_BYTES, xTicksToBlock );
- configASSERT( ( ( TickType_t ) ( xTaskGetTickCount() - xTimeOnEntering ) ) >= xTicksToBlock );
- configASSERT( xReceivedLength == 0 );
- ( void ) xTimeOnEntering; /* In case configASSERT() is not defined. */
-
- /* Now the message buffers have been created the echo client task can be
- created. If this server task has the higher priority then the client task
- is created at the lower priority - if this server task has the lower
- priority then the client task is created at the higher priority. */
- if( uxTaskPriorityGet( NULL ) == mbLOWER_PRIORITY )
- {
- xTaskCreate( prvEchoClient, "EchoClient", configMINIMAL_STACK_SIZE, ( void * ) &xMessageBuffers, mbHIGHER_PRIORITY, NULL );
- }
- else
- {
- /* Here prvSingleTaskTests() performs various tests on a message buffer
- that was created dynamically. */
- prvSingleTaskTests( xMessageBuffers.xEchoClientBuffer );
- xTaskCreate( prvEchoClient, "EchoClient", configMINIMAL_STACK_SIZE, ( void * ) &xMessageBuffers, mbLOWER_PRIORITY, NULL );
- }
-
- for( ;; )
- {
- memset( pcReceivedString, 0x00, mbMESSAGE_BUFFER_LENGTH_BYTES );
-
- /* Has any data been sent by the client? */
- xReceivedLength = xMessageBufferReceive( xMessageBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, mbMESSAGE_BUFFER_LENGTH_BYTES, portMAX_DELAY );
-
- /* Should always receive data as max delay was used. */
- configASSERT( xReceivedLength > 0 );
-
- /* Echo the received data back to the client. */
- xMessageBufferSend( xMessageBuffers.xEchoServerBuffer, ( void * ) pcReceivedString, xReceivedLength, portMAX_DELAY );
-
- /* This message buffer is just created and deleted to ensure no memory
- leaks. */
- xTempMessageBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
- vMessageBufferDelete( xTempMessageBuffer );
- }
+ MessageBufferHandle_t xTempMessageBuffer;
+ size_t xReceivedLength;
+ char * pcReceivedString;
+ EchoMessageBuffers_t xMessageBuffers;
+ TickType_t xTimeOnEntering;
+ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
+
+ /* Prevent compiler warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ /* Create the message buffer used to send data from the client to the server,
+ * and the message buffer used to echo the data from the server back to the
+ * client. */
+ xMessageBuffers.xEchoClientBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
+ xMessageBuffers.xEchoServerBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
+ configASSERT( xMessageBuffers.xEchoClientBuffer );
+ configASSERT( xMessageBuffers.xEchoServerBuffer );
+
+ /* Create the buffer into which received strings will be copied. */
+ pcReceivedString = ( char * ) pvPortMalloc( mbMESSAGE_BUFFER_LENGTH_BYTES );
+ configASSERT( pcReceivedString );
+
+ /* Don't expect to receive anything yet! */
+ xTimeOnEntering = xTaskGetTickCount();
+ xReceivedLength = xMessageBufferReceive( xMessageBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, mbMESSAGE_BUFFER_LENGTH_BYTES, xTicksToBlock );
+ configASSERT( ( ( TickType_t ) ( xTaskGetTickCount() - xTimeOnEntering ) ) >= xTicksToBlock );
+ configASSERT( xReceivedLength == 0 );
+ ( void ) xTimeOnEntering; /* In case configASSERT() is not defined. */
+
+ /* Now the message buffers have been created the echo client task can be
+ * created. If this server task has the higher priority then the client task
+ * is created at the lower priority - if this server task has the lower
+ * priority then the client task is created at the higher priority. */
+ if( uxTaskPriorityGet( NULL ) == mbLOWER_PRIORITY )
+ {
+ xTaskCreate( prvEchoClient, "EchoClient", configMINIMAL_STACK_SIZE, ( void * ) &xMessageBuffers, mbHIGHER_PRIORITY, NULL );
+ }
+ else
+ {
+ /* Here prvSingleTaskTests() performs various tests on a message buffer
+ * that was created dynamically. */
+ prvSingleTaskTests( xMessageBuffers.xEchoClientBuffer );
+ xTaskCreate( prvEchoClient, "EchoClient", configMINIMAL_STACK_SIZE, ( void * ) &xMessageBuffers, mbLOWER_PRIORITY, NULL );
+ }
+
+ for( ; ; )
+ {
+ memset( pcReceivedString, 0x00, mbMESSAGE_BUFFER_LENGTH_BYTES );
+
+ /* Has any data been sent by the client? */
+ xReceivedLength = xMessageBufferReceive( xMessageBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, mbMESSAGE_BUFFER_LENGTH_BYTES, portMAX_DELAY );
+
+ /* Should always receive data as max delay was used. */
+ configASSERT( xReceivedLength > 0 );
+
+ /* Echo the received data back to the client. */
+ xMessageBufferSend( xMessageBuffers.xEchoServerBuffer, ( void * ) pcReceivedString, xReceivedLength, portMAX_DELAY );
+
+ /* This message buffer is just created and deleted to ensure no memory
+ * leaks. */
+ xTempMessageBuffer = xMessageBufferCreate( mbMESSAGE_BUFFER_LENGTH_BYTES );
+ vMessageBufferDelete( xTempMessageBuffer );
+ }
}
/*-----------------------------------------------------------*/
@@ -847,129 +846,127 @@ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 250UL );
* platforms or have been added to pre-existing files that are already in use
* by other test projects without ensuring they don't cause those pre-existing
* projects to run out of program or data memory. */
-#if( configRUN_ADDITIONAL_TESTS == 1 )
-
- static void prvSpaceAvailableCoherenceActor( void *pvParameters )
- {
- static char *cTxString = "12345";
- char cRxString[ mbCOHERENCE_TEST_BYTES_WRITTEN + 1 ]; /* +1 for NULL terminator. */
-
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Add bytes to the buffer so the other task should see
- mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING bytes free. */
- xMessageBufferSend( xCoherenceTestMessageBuffer, ( void * ) cTxString, strlen( cTxString ), 0 );
- configASSERT( xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer ) == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING );
-
- /* Read out message again so the other task should read the full
- mbCOHERENCE_TEST_BUFFER_SIZE bytes free again. */
- memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
- xMessageBufferReceive( xCoherenceTestMessageBuffer, ( void * ) cRxString, mbCOHERENCE_TEST_BYTES_WRITTEN, 0 );
- configASSERT( strcmp( cTxString, cRxString ) == 0 );
- }
- }
- /*-----------------------------------------------------------*/
-
- static void prvSpaceAvailableCoherenceTester( void *pvParameters )
- {
- size_t xSpaceAvailable;
- BaseType_t xErrorFound = pdFALSE;
-
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* This message buffer is only ever empty or contains 5 bytes. So all
- queries of its free space should result in one of the two values tested
- below. */
- xSpaceAvailable = xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer );
-
- if( ( xSpaceAvailable == mbCOHERENCE_TEST_BUFFER_SIZE ) ||
- ( xSpaceAvailable == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ) )
- {
- /* Only continue to increment the variable that shows this task
- is still executing if no errors have been found. */
- if( xErrorFound == pdFALSE )
- {
- ulSizeCoherencyTestCycles++;
- }
- }
- else
- {
- xErrorFound = pdTRUE;
- }
-
- configASSERT( xErrorFound == pdFALSE );
- }
- }
+#if ( configRUN_ADDITIONAL_TESTS == 1 )
+
+ static void prvSpaceAvailableCoherenceActor( void * pvParameters )
+ {
+ static char * cTxString = "12345";
+ char cRxString[ mbCOHERENCE_TEST_BYTES_WRITTEN + 1 ]; /* +1 for NULL terminator. */
+
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Add bytes to the buffer so the other task should see
+ * mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING bytes free. */
+ xMessageBufferSend( xCoherenceTestMessageBuffer, ( void * ) cTxString, strlen( cTxString ), 0 );
+ configASSERT( xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer ) == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING );
+
+ /* Read out message again so the other task should read the full
+ * mbCOHERENCE_TEST_BUFFER_SIZE bytes free again. */
+ memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
+ xMessageBufferReceive( xCoherenceTestMessageBuffer, ( void * ) cRxString, mbCOHERENCE_TEST_BYTES_WRITTEN, 0 );
+ configASSERT( strcmp( cTxString, cRxString ) == 0 );
+ }
+ }
+ /*-----------------------------------------------------------*/
+
+ static void prvSpaceAvailableCoherenceTester( void * pvParameters )
+ {
+ size_t xSpaceAvailable;
+ BaseType_t xErrorFound = pdFALSE;
+
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* This message buffer is only ever empty or contains 5 bytes. So all
+ * queries of its free space should result in one of the two values tested
+ * below. */
+ xSpaceAvailable = xMessageBufferSpacesAvailable( xCoherenceTestMessageBuffer );
+
+ if( ( xSpaceAvailable == mbCOHERENCE_TEST_BUFFER_SIZE ) ||
+ ( xSpaceAvailable == mbEXPECTED_FREE_BYTES_AFTER_WRITING_STRING ) )
+ {
+ /* Only continue to increment the variable that shows this task
+ * is still executing if no errors have been found. */
+ if( xErrorFound == pdFALSE )
+ {
+ ulSizeCoherencyTestCycles++;
+ }
+ }
+ else
+ {
+ xErrorFound = pdTRUE;
+ }
+
+ configASSERT( xErrorFound == pdFALSE );
+ }
+ }
#endif /* configRUN_ADDITIONAL_TESTS == 1 */
/*-----------------------------------------------------------*/
BaseType_t xAreMessageBufferTasksStillRunning( void )
{
-static uint32_t ulLastEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
-static uint32_t ulLastNonBlockingRxCounter = 0;
-BaseType_t xReturn = pdPASS, x;
-
- for( x = 0; x < mbNUMBER_OF_ECHO_CLIENTS; x++ )
- {
- if( ulLastEchoLoopCounters[ x ] == ulEchoLoopCounters[ x ] )
- {
- xReturn = pdFAIL;
- }
- else
- {
- ulLastEchoLoopCounters[ x ] = ulEchoLoopCounters[ x ];
- }
- }
-
- if( ulNonBlockingRxCounter == ulLastNonBlockingRxCounter )
- {
- xReturn = pdFAIL;
- }
- else
- {
- ulLastNonBlockingRxCounter = ulNonBlockingRxCounter;
- }
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- static uint32_t ulLastSenderLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
-
- for( x = 0; x < mbNUMBER_OF_SENDER_TASKS; x++ )
- {
- if( ulLastSenderLoopCounters[ x ] == ulSenderLoopCounters[ x ] )
- {
- xReturn = pdFAIL;
- }
- else
- {
- ulLastSenderLoopCounters[ x ] = ulSenderLoopCounters[ x ];
- }
- }
- }
- #endif /* configSUPPORT_STATIC_ALLOCATION */
-
- #if( configRUN_ADDITIONAL_TESTS == 1 )
- {
- static uint32_t ullastSizeCoherencyTestCycles = 0UL;
-
- if( ullastSizeCoherencyTestCycles == ulSizeCoherencyTestCycles )
- {
- xReturn = pdFAIL;
- }
- else
- {
- ullastSizeCoherencyTestCycles = ulSizeCoherencyTestCycles;
- }
- }
- #endif
-
- return xReturn;
+ static uint32_t ulLastEchoLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
+ static uint32_t ulLastNonBlockingRxCounter = 0;
+ BaseType_t xReturn = pdPASS, x;
+
+ for( x = 0; x < mbNUMBER_OF_ECHO_CLIENTS; x++ )
+ {
+ if( ulLastEchoLoopCounters[ x ] == ulEchoLoopCounters[ x ] )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ ulLastEchoLoopCounters[ x ] = ulEchoLoopCounters[ x ];
+ }
+ }
+
+ if( ulNonBlockingRxCounter == ulLastNonBlockingRxCounter )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ ulLastNonBlockingRxCounter = ulNonBlockingRxCounter;
+ }
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ static uint32_t ulLastSenderLoopCounters[ mbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
+
+ for( x = 0; x < mbNUMBER_OF_SENDER_TASKS; x++ )
+ {
+ if( ulLastSenderLoopCounters[ x ] == ulSenderLoopCounters[ x ] )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ ulLastSenderLoopCounters[ x ] = ulSenderLoopCounters[ x ];
+ }
+ }
+ }
+ #endif /* configSUPPORT_STATIC_ALLOCATION */
+
+ #if ( configRUN_ADDITIONAL_TESTS == 1 )
+ {
+ static uint32_t ullastSizeCoherencyTestCycles = 0UL;
+
+ if( ullastSizeCoherencyTestCycles == ulSizeCoherencyTestCycles )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ ullastSizeCoherencyTestCycles = ulSizeCoherencyTestCycles;
+ }
+ }
+ #endif /* if ( configRUN_ADDITIONAL_TESTS == 1 ) */
+
+ return xReturn;
}
/*-----------------------------------------------------------*/
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/PollQ.c b/FreeRTOS/Demo/Common/Minimal/PollQ.c
index e57c5158d..da3f9219c 100644
--- a/FreeRTOS/Demo/Common/Minimal/PollQ.c
+++ b/FreeRTOS/Demo/Common/Minimal/PollQ.c
@@ -49,11 +49,11 @@
*/
/*
-Changes from V2.0.0
-
- + Delay periods are now specified using variables and constants of
- TickType_t rather than uint32_t.
-*/
+ * Changes from V2.0.0
+ *
+ + Delay periods are now specified using variables and constants of
+ + TickType_t rather than uint32_t.
+ */
#include <stdlib.h>
@@ -65,13 +65,13 @@ Changes from V2.0.0
/* Demo program include files. */
#include "PollQ.h"
-#define pollqSTACK_SIZE configMINIMAL_STACK_SIZE
-#define pollqQUEUE_SIZE ( 10 )
-#define pollqPRODUCER_DELAY ( pdMS_TO_TICKS( ( TickType_t ) 200 ) )
-#define pollqCONSUMER_DELAY ( pollqPRODUCER_DELAY - ( TickType_t ) ( 20 / portTICK_PERIOD_MS ) )
-#define pollqNO_DELAY ( ( TickType_t ) 0 )
-#define pollqVALUES_TO_PRODUCE ( ( BaseType_t ) 3 )
-#define pollqINITIAL_VALUE ( ( BaseType_t ) 0 )
+#define pollqSTACK_SIZE configMINIMAL_STACK_SIZE
+#define pollqQUEUE_SIZE ( 10 )
+#define pollqPRODUCER_DELAY ( pdMS_TO_TICKS( ( TickType_t ) 200 ) )
+#define pollqCONSUMER_DELAY ( pollqPRODUCER_DELAY - ( TickType_t ) ( 20 / portTICK_PERIOD_MS ) )
+#define pollqNO_DELAY ( ( TickType_t ) 0 )
+#define pollqVALUES_TO_PRODUCE ( ( BaseType_t ) 3 )
+#define pollqINITIAL_VALUE ( ( BaseType_t ) 0 )
/* The task that posts the incrementing number onto the queue. */
static portTASK_FUNCTION_PROTO( vPolledQueueProducer, pvParameters );
@@ -80,144 +80,144 @@ static portTASK_FUNCTION_PROTO( vPolledQueueProducer, pvParameters );
static portTASK_FUNCTION_PROTO( vPolledQueueConsumer, pvParameters );
/* Variables that are used to check that the tasks are still running with no
-errors. */
+ * errors. */
static volatile BaseType_t xPollingConsumerCount = pollqINITIAL_VALUE, xPollingProducerCount = pollqINITIAL_VALUE;
/*-----------------------------------------------------------*/
void vStartPolledQueueTasks( UBaseType_t uxPriority )
{
-static QueueHandle_t xPolledQueue;
-
- /* Create the queue used by the producer and consumer. */
- xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( UBaseType_t ) sizeof( uint16_t ) );
-
- if( xPolledQueue != NULL )
- {
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
- in use. The queue registry is provided as a means for kernel aware
- debuggers to locate queues and has no purpose if a kernel aware debugger
- is not being used. The call to vQueueAddToRegistry() will be removed
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
- defined to be less than 1. */
- vQueueAddToRegistry( xPolledQueue, "Poll_Test_Queue" );
-
- /* Spawn the producer and consumer. */
- xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
- xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
- }
+ static QueueHandle_t xPolledQueue;
+
+ /* Create the queue used by the producer and consumer. */
+ xPolledQueue = xQueueCreate( pollqQUEUE_SIZE, ( UBaseType_t ) sizeof( uint16_t ) );
+
+ if( xPolledQueue != NULL )
+ {
+ /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
+ * in use. The queue registry is provided as a means for kernel aware
+ * debuggers to locate queues and has no purpose if a kernel aware debugger
+ * is not being used. The call to vQueueAddToRegistry() will be removed
+ * by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
+ * defined to be less than 1. */
+ vQueueAddToRegistry( xPolledQueue, "Poll_Test_Queue" );
+
+ /* Spawn the producer and consumer. */
+ xTaskCreate( vPolledQueueConsumer, "QConsNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
+ xTaskCreate( vPolledQueueProducer, "QProdNB", pollqSTACK_SIZE, ( void * ) &xPolledQueue, uxPriority, ( TaskHandle_t * ) NULL );
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vPolledQueueProducer, pvParameters )
{
-uint16_t usValue = ( uint16_t ) 0;
-BaseType_t xError = pdFALSE, xLoop;
-
- for( ;; )
- {
- for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ )
- {
- /* Send an incrementing number on the queue without blocking. */
- if( xQueueSend( *( ( QueueHandle_t * ) pvParameters ), ( void * ) &usValue, pollqNO_DELAY ) != pdPASS )
- {
- /* We should never find the queue full so if we get here there
- has been an error. */
- xError = pdTRUE;
- }
- else
- {
- if( xError == pdFALSE )
- {
- /* If an error has ever been recorded we stop incrementing the
- check variable. */
- portENTER_CRITICAL();
- xPollingProducerCount++;
- portEXIT_CRITICAL();
- }
-
- /* Update the value we are going to post next time around. */
- usValue++;
- }
- }
-
- /* Wait before we start posting again to ensure the consumer runs and
- empties the queue. */
- vTaskDelay( pollqPRODUCER_DELAY );
- }
-} /*lint !e818 Function prototype must conform to API. */
+ uint16_t usValue = ( uint16_t ) 0;
+ BaseType_t xError = pdFALSE, xLoop;
+
+ for( ; ; )
+ {
+ for( xLoop = 0; xLoop < pollqVALUES_TO_PRODUCE; xLoop++ )
+ {
+ /* Send an incrementing number on the queue without blocking. */
+ if( xQueueSend( *( ( QueueHandle_t * ) pvParameters ), ( void * ) &usValue, pollqNO_DELAY ) != pdPASS )
+ {
+ /* We should never find the queue full so if we get here there
+ * has been an error. */
+ xError = pdTRUE;
+ }
+ else
+ {
+ if( xError == pdFALSE )
+ {
+ /* If an error has ever been recorded we stop incrementing the
+ * check variable. */
+ portENTER_CRITICAL();
+ xPollingProducerCount++;
+ portEXIT_CRITICAL();
+ }
+
+ /* Update the value we are going to post next time around. */
+ usValue++;
+ }
+ }
+
+ /* Wait before we start posting again to ensure the consumer runs and
+ * empties the queue. */
+ vTaskDelay( pollqPRODUCER_DELAY );
+ }
+} /*lint !e818 Function prototype must conform to API. */
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vPolledQueueConsumer, pvParameters )
{
-uint16_t usData, usExpectedValue = ( uint16_t ) 0;
-BaseType_t xError = pdFALSE;
-
- for( ;; )
- {
- /* Loop until the queue is empty. */
- while( uxQueueMessagesWaiting( *( ( QueueHandle_t * ) pvParameters ) ) )
- {
- if( xQueueReceive( *( ( QueueHandle_t * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS )
- {
- if( usData != usExpectedValue )
- {
- /* This is not what we expected to receive so an error has
- occurred. */
- xError = pdTRUE;
-
- /* Catch-up to the value we received so our next expected
- value should again be correct. */
- usExpectedValue = usData;
- }
- else
- {
- if( xError == pdFALSE )
- {
- /* Only increment the check variable if no errors have
- occurred. */
- portENTER_CRITICAL();
- xPollingConsumerCount++;
- portEXIT_CRITICAL();
- }
- }
-
- /* Next time round we would expect the number to be one higher. */
- usExpectedValue++;
- }
- }
-
- /* Now the queue is empty we block, allowing the producer to place more
- items in the queue. */
- vTaskDelay( pollqCONSUMER_DELAY );
- }
+ uint16_t usData, usExpectedValue = ( uint16_t ) 0;
+ BaseType_t xError = pdFALSE;
+
+ for( ; ; )
+ {
+ /* Loop until the queue is empty. */
+ while( uxQueueMessagesWaiting( *( ( QueueHandle_t * ) pvParameters ) ) )
+ {
+ if( xQueueReceive( *( ( QueueHandle_t * ) pvParameters ), &usData, pollqNO_DELAY ) == pdPASS )
+ {
+ if( usData != usExpectedValue )
+ {
+ /* This is not what we expected to receive so an error has
+ * occurred. */
+ xError = pdTRUE;
+
+ /* Catch-up to the value we received so our next expected
+ * value should again be correct. */
+ usExpectedValue = usData;
+ }
+ else
+ {
+ if( xError == pdFALSE )
+ {
+ /* Only increment the check variable if no errors have
+ * occurred. */
+ portENTER_CRITICAL();
+ xPollingConsumerCount++;
+ portEXIT_CRITICAL();
+ }
+ }
+
+ /* Next time round we would expect the number to be one higher. */
+ usExpectedValue++;
+ }
+ }
+
+ /* Now the queue is empty we block, allowing the producer to place more
+ * items in the queue. */
+ vTaskDelay( pollqCONSUMER_DELAY );
+ }
} /*lint !e818 Function prototype must conform to API. */
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running with no errors. */
BaseType_t xArePollingQueuesStillRunning( void )
{
-BaseType_t xReturn;
-
- /* Check both the consumer and producer poll count to check they have both
- been changed since out last trip round. We do not need a critical section
- around the check variables as this is called from a higher priority than
- the other tasks that access the same variables. */
- if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) ||
- ( xPollingProducerCount == pollqINITIAL_VALUE )
- )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- /* Set the check variables back down so we know if they have been
- incremented the next time around. */
- xPollingConsumerCount = pollqINITIAL_VALUE;
- xPollingProducerCount = pollqINITIAL_VALUE;
-
- return xReturn;
+ BaseType_t xReturn;
+
+ /* Check both the consumer and producer poll count to check they have both
+ * been changed since out last trip round. We do not need a critical section
+ * around the check variables as this is called from a higher priority than
+ * the other tasks that access the same variables. */
+ if( ( xPollingConsumerCount == pollqINITIAL_VALUE ) ||
+ ( xPollingProducerCount == pollqINITIAL_VALUE )
+ )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ xReturn = pdTRUE;
+ }
+
+ /* Set the check variables back down so we know if they have been
+ * incremented the next time around. */
+ xPollingConsumerCount = pollqINITIAL_VALUE;
+ xPollingProducerCount = pollqINITIAL_VALUE;
+
+ return xReturn;
}
diff --git a/FreeRTOS/Demo/Common/Minimal/QPeek.c b/FreeRTOS/Demo/Common/Minimal/QPeek.c
index c036c3d55..27b6b5916 100644
--- a/FreeRTOS/Demo/Common/Minimal/QPeek.c
+++ b/FreeRTOS/Demo/Common/Minimal/QPeek.c
@@ -43,14 +43,14 @@
/* Demo program include files. */
#include "QPeek.h"
-#define qpeekQUEUE_LENGTH ( 5 )
-#define qpeekNO_BLOCK ( 0 )
-#define qpeekSHORT_DELAY ( 10 )
+#define qpeekQUEUE_LENGTH ( 5 )
+#define qpeekNO_BLOCK ( 0 )
+#define qpeekSHORT_DELAY ( 10 )
-#define qpeekLOW_PRIORITY ( tskIDLE_PRIORITY + 0 )
-#define qpeekMEDIUM_PRIORITY ( tskIDLE_PRIORITY + 1 )
-#define qpeekHIGH_PRIORITY ( tskIDLE_PRIORITY + 2 )
-#define qpeekHIGHEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
+#define qpeekLOW_PRIORITY ( tskIDLE_PRIORITY + 0 )
+#define qpeekMEDIUM_PRIORITY ( tskIDLE_PRIORITY + 1 )
+#define qpeekHIGH_PRIORITY ( tskIDLE_PRIORITY + 2 )
+#define qpeekHIGHEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
/*-----------------------------------------------------------*/
@@ -59,19 +59,19 @@
* Each task is given a different priority to demonstrate the order in which
* tasks are woken as data is peeked from a queue.
*/
-static void prvLowPriorityPeekTask( void *pvParameters );
-static void prvMediumPriorityPeekTask( void *pvParameters );
-static void prvHighPriorityPeekTask( void *pvParameters );
-static void prvHighestPriorityPeekTask( void *pvParameters );
+static void prvLowPriorityPeekTask( void * pvParameters );
+static void prvMediumPriorityPeekTask( void * pvParameters );
+static void prvHighPriorityPeekTask( void * pvParameters );
+static void prvHighestPriorityPeekTask( void * pvParameters );
/*-----------------------------------------------------------*/
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
-detected in any of the tasks. */
+ * detected in any of the tasks. */
static volatile BaseType_t xErrorDetected = pdFALSE;
/* Counter that is incremented on each cycle of a test. This is used to
-detect a stalled task - a test that is no longer running. */
+ * detect a stalled task - a test that is no longer running. */
static volatile uint32_t ulLoopCounter = 0;
/* Handles to the test tasks. */
@@ -80,361 +80,362 @@ TaskHandle_t xMediumPriorityTask, xHighPriorityTask, xHighestPriorityTask;
void vStartQueuePeekTasks( void )
{
-QueueHandle_t xQueue;
-
- /* Create the queue that we are going to use for the test/demo. */
- xQueue = xQueueCreate( qpeekQUEUE_LENGTH, sizeof( uint32_t ) );
-
- if( xQueue != NULL )
- {
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
- in use. The queue registry is provided as a means for kernel aware
- debuggers to locate queues and has no purpose if a kernel aware debugger
- is not being used. The call to vQueueAddToRegistry() will be removed
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
- defined to be less than 1. */
- vQueueAddToRegistry( xQueue, "QPeek_Test_Queue" );
-
- /* Create the demo tasks and pass it the queue just created. We are
- passing the queue handle by value so it does not matter that it is declared
- on the stack here. */
- xTaskCreate( prvLowPriorityPeekTask, "PeekL", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekLOW_PRIORITY, NULL );
- xTaskCreate( prvMediumPriorityPeekTask, "PeekM", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekMEDIUM_PRIORITY, &xMediumPriorityTask );
- xTaskCreate( prvHighPriorityPeekTask, "PeekH1", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGH_PRIORITY, &xHighPriorityTask );
- xTaskCreate( prvHighestPriorityPeekTask, "PeekH2", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGHEST_PRIORITY, &xHighestPriorityTask );
- }
+ QueueHandle_t xQueue;
+
+ /* Create the queue that we are going to use for the test/demo. */
+ xQueue = xQueueCreate( qpeekQUEUE_LENGTH, sizeof( uint32_t ) );
+
+ if( xQueue != NULL )
+ {
+ /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
+ * in use. The queue registry is provided as a means for kernel aware
+ * debuggers to locate queues and has no purpose if a kernel aware debugger
+ * is not being used. The call to vQueueAddToRegistry() will be removed
+ * by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
+ * defined to be less than 1. */
+ vQueueAddToRegistry( xQueue, "QPeek_Test_Queue" );
+
+ /* Create the demo tasks and pass it the queue just created. We are
+ * passing the queue handle by value so it does not matter that it is declared
+ * on the stack here. */
+ xTaskCreate( prvLowPriorityPeekTask, "PeekL", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekLOW_PRIORITY, NULL );
+ xTaskCreate( prvMediumPriorityPeekTask, "PeekM", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekMEDIUM_PRIORITY, &xMediumPriorityTask );
+ xTaskCreate( prvHighPriorityPeekTask, "PeekH1", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGH_PRIORITY, &xHighPriorityTask );
+ xTaskCreate( prvHighestPriorityPeekTask, "PeekH2", configMINIMAL_STACK_SIZE, ( void * ) xQueue, qpeekHIGHEST_PRIORITY, &xHighestPriorityTask );
+ }
}
/*-----------------------------------------------------------*/
-static void prvHighestPriorityPeekTask( void *pvParameters )
+static void prvHighestPriorityPeekTask( void * pvParameters )
{
-QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
-uint32_t ulValue;
-
- #ifdef USE_STDIO
- {
- void vPrintDisplayMessage( const char * const * ppcMessageToSend );
-
- const char * const pcTaskStartMsg = "Queue peek test started.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
- }
- #endif
-
- for( ;; )
- {
- /* Try peeking from the queue. The queue should be empty so we will
- block, allowing the high priority task to execute. */
- if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
- {
- /* We expected to have received something by the time we unblock. */
- xErrorDetected = pdTRUE;
- }
-
- /* When we reach here the high and medium priority tasks should still
- be blocked on the queue. We unblocked because the low priority task
- wrote a value to the queue, which we should have peeked. Peeking the
- data (rather than receiving it) will leave the data on the queue, so
- the high priority task should then have also been unblocked, but not
- yet executed. */
- if( ulValue != 0x11223344 )
- {
- /* We did not receive the expected value. */
- xErrorDetected = pdTRUE;
- }
-
- if( uxQueueMessagesWaiting( xQueue ) != 1 )
- {
- /* The message should have been left on the queue. */
- xErrorDetected = pdTRUE;
- }
-
- /* Now we are going to actually receive the data, so when the high
- priority task runs it will find the queue empty and return to the
- blocked state. */
- ulValue = 0;
- if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
- {
- /* We expected to receive the value. */
- xErrorDetected = pdTRUE;
- }
-
- if( ulValue != 0x11223344 )
- {
- /* We did not receive the expected value - which should have been
- the same value as was peeked. */
- xErrorDetected = pdTRUE;
- }
-
- /* Now we will block again as the queue is once more empty. The low
- priority task can then execute again. */
- if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
- {
- /* We expected to have received something by the time we unblock. */
- xErrorDetected = pdTRUE;
- }
-
- /* When we get here the low priority task should have again written to the
- queue. */
- if( ulValue != 0x01234567 )
- {
- /* We did not receive the expected value. */
- xErrorDetected = pdTRUE;
- }
-
- if( uxQueueMessagesWaiting( xQueue ) != 1 )
- {
- /* The message should have been left on the queue. */
- xErrorDetected = pdTRUE;
- }
-
- /* We only peeked the data, so suspending ourselves now should enable
- the high priority task to also peek the data. The high priority task
- will have been unblocked when we peeked the data as we left the data
- in the queue. */
- vTaskSuspend( NULL );
-
-
-
- /* This time we are going to do the same as the above test, but the
- high priority task is going to receive the data, rather than peek it.
- This means that the medium priority task should never peek the value. */
- if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( ulValue != 0xaabbaabb )
- {
- xErrorDetected = pdTRUE;
- }
-
- vTaskSuspend( NULL );
- }
+ QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
+ uint32_t ulValue;
+
+ #ifdef USE_STDIO
+ {
+ void vPrintDisplayMessage( const char * const * ppcMessageToSend );
+
+ const char * const pcTaskStartMsg = "Queue peek test started.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+ }
+ #endif
+
+ for( ; ; )
+ {
+ /* Try peeking from the queue. The queue should be empty so we will
+ * block, allowing the high priority task to execute. */
+ if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
+ {
+ /* We expected to have received something by the time we unblock. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* When we reach here the high and medium priority tasks should still
+ * be blocked on the queue. We unblocked because the low priority task
+ * wrote a value to the queue, which we should have peeked. Peeking the
+ * data (rather than receiving it) will leave the data on the queue, so
+ * the high priority task should then have also been unblocked, but not
+ * yet executed. */
+ if( ulValue != 0x11223344 )
+ {
+ /* We did not receive the expected value. */
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxQueueMessagesWaiting( xQueue ) != 1 )
+ {
+ /* The message should have been left on the queue. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now we are going to actually receive the data, so when the high
+ * priority task runs it will find the queue empty and return to the
+ * blocked state. */
+ ulValue = 0;
+
+ if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
+ {
+ /* We expected to receive the value. */
+ xErrorDetected = pdTRUE;
+ }
+
+ if( ulValue != 0x11223344 )
+ {
+ /* We did not receive the expected value - which should have been
+ * the same value as was peeked. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Now we will block again as the queue is once more empty. The low
+ * priority task can then execute again. */
+ if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
+ {
+ /* We expected to have received something by the time we unblock. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* When we get here the low priority task should have again written to the
+ * queue. */
+ if( ulValue != 0x01234567 )
+ {
+ /* We did not receive the expected value. */
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxQueueMessagesWaiting( xQueue ) != 1 )
+ {
+ /* The message should have been left on the queue. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* We only peeked the data, so suspending ourselves now should enable
+ * the high priority task to also peek the data. The high priority task
+ * will have been unblocked when we peeked the data as we left the data
+ * in the queue. */
+ vTaskSuspend( NULL );
+
+ /* This time we are going to do the same as the above test, but the
+ * high priority task is going to receive the data, rather than peek it.
+ * This means that the medium priority task should never peek the value. */
+ if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( ulValue != 0xaabbaabb )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ vTaskSuspend( NULL );
+ }
}
/*-----------------------------------------------------------*/
-static void prvHighPriorityPeekTask( void *pvParameters )
+static void prvHighPriorityPeekTask( void * pvParameters )
{
-QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
-uint32_t ulValue;
-
- for( ;; )
- {
- /* Try peeking from the queue. The queue should be empty so we will
- block, allowing the medium priority task to execute. Both the high
- and highest priority tasks will then be blocked on the queue. */
- if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
- {
- /* We expected to have received something by the time we unblock. */
- xErrorDetected = pdTRUE;
- }
-
- /* When we get here the highest priority task should have peeked the data
- (unblocking this task) then suspended (allowing this task to also peek
- the data). */
- if( ulValue != 0x01234567 )
- {
- /* We did not receive the expected value. */
- xErrorDetected = pdTRUE;
- }
-
- if( uxQueueMessagesWaiting( xQueue ) != 1 )
- {
- /* The message should have been left on the queue. */
- xErrorDetected = pdTRUE;
- }
-
- /* We only peeked the data, so suspending ourselves now should enable
- the medium priority task to also peek the data. The medium priority task
- will have been unblocked when we peeked the data as we left the data
- in the queue. */
- vTaskSuspend( NULL );
-
-
- /* This time we are going actually receive the value, so the medium
- priority task will never peek the data - we removed it from the queue. */
- if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- if( ulValue != 0xaabbaabb )
- {
- xErrorDetected = pdTRUE;
- }
-
- vTaskSuspend( NULL );
- }
+ QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
+ uint32_t ulValue;
+
+ for( ; ; )
+ {
+ /* Try peeking from the queue. The queue should be empty so we will
+ * block, allowing the medium priority task to execute. Both the high
+ * and highest priority tasks will then be blocked on the queue. */
+ if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
+ {
+ /* We expected to have received something by the time we unblock. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* When we get here the highest priority task should have peeked the data
+ * (unblocking this task) then suspended (allowing this task to also peek
+ * the data). */
+ if( ulValue != 0x01234567 )
+ {
+ /* We did not receive the expected value. */
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxQueueMessagesWaiting( xQueue ) != 1 )
+ {
+ /* The message should have been left on the queue. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* We only peeked the data, so suspending ourselves now should enable
+ * the medium priority task to also peek the data. The medium priority task
+ * will have been unblocked when we peeked the data as we left the data
+ * in the queue. */
+ vTaskSuspend( NULL );
+
+ /* This time we are going actually receive the value, so the medium
+ * priority task will never peek the data - we removed it from the queue. */
+ if( xQueueReceive( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ if( ulValue != 0xaabbaabb )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ vTaskSuspend( NULL );
+ }
}
/*-----------------------------------------------------------*/
-static void prvMediumPriorityPeekTask( void *pvParameters )
+static void prvMediumPriorityPeekTask( void * pvParameters )
{
-QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
-uint32_t ulValue;
-
- for( ;; )
- {
- /* Try peeking from the queue. The queue should be empty so we will
- block, allowing the low priority task to execute. The highest, high
- and medium priority tasks will then all be blocked on the queue. */
- if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
- {
- /* We expected to have received something by the time we unblock. */
- xErrorDetected = pdTRUE;
- }
-
- /* When we get here the high priority task should have peeked the data
- (unblocking this task) then suspended (allowing this task to also peek
- the data). */
- if( ulValue != 0x01234567 )
- {
- /* We did not receive the expected value. */
- xErrorDetected = pdTRUE;
- }
-
- if( uxQueueMessagesWaiting( xQueue ) != 1 )
- {
- /* The message should have been left on the queue. */
- xErrorDetected = pdTRUE;
- }
-
- /* Just so we know the test is still running. */
- ulLoopCounter++;
-
- /* Now we can suspend ourselves so the low priority task can execute
- again. */
- vTaskSuspend( NULL );
- }
+ QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
+ uint32_t ulValue;
+
+ for( ; ; )
+ {
+ /* Try peeking from the queue. The queue should be empty so we will
+ * block, allowing the low priority task to execute. The highest, high
+ * and medium priority tasks will then all be blocked on the queue. */
+ if( xQueuePeek( xQueue, &ulValue, portMAX_DELAY ) != pdPASS )
+ {
+ /* We expected to have received something by the time we unblock. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* When we get here the high priority task should have peeked the data
+ * (unblocking this task) then suspended (allowing this task to also peek
+ * the data). */
+ if( ulValue != 0x01234567 )
+ {
+ /* We did not receive the expected value. */
+ xErrorDetected = pdTRUE;
+ }
+
+ if( uxQueueMessagesWaiting( xQueue ) != 1 )
+ {
+ /* The message should have been left on the queue. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Just so we know the test is still running. */
+ ulLoopCounter++;
+
+ /* Now we can suspend ourselves so the low priority task can execute
+ * again. */
+ vTaskSuspend( NULL );
+ }
}
/*-----------------------------------------------------------*/
-static void prvLowPriorityPeekTask( void *pvParameters )
+static void prvLowPriorityPeekTask( void * pvParameters )
{
-QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
-uint32_t ulValue;
-
- for( ;; )
- {
- /* Write some data to the queue. This should unblock the highest
- priority task that is waiting to peek data from the queue. */
- ulValue = 0x11223344;
- if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
- {
- /* We were expecting the queue to be empty so we should not of
- had a problem writing to the queue. */
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* By the time we get here the data should have been removed from
- the queue. */
- if( uxQueueMessagesWaiting( xQueue ) != 0 )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* Write another value to the queue, again waking the highest priority
- task that is blocked on the queue. */
- ulValue = 0x01234567;
- if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
- {
- /* We were expecting the queue to be empty so we should not of
- had a problem writing to the queue. */
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* All the other tasks should now have successfully peeked the data.
- The data is still in the queue so we should be able to receive it. */
- ulValue = 0;
- if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
- {
- /* We expected to receive the data. */
- xErrorDetected = pdTRUE;
- }
-
- if( ulValue != 0x01234567 )
- {
- /* We did not receive the expected value. */
- xErrorDetected = pdTRUE;
- }
-
- /* Lets just delay a while as this is an intensive test as we don't
- want to starve other tests of processing time. */
- vTaskDelay( qpeekSHORT_DELAY );
-
- /* Unsuspend the other tasks so we can repeat the test - this time
- however not all the other tasks will peek the data as the high
- priority task is actually going to remove it from the queue. Send
- to front is used just to be different. As the queue is empty it
- makes no difference to the result. */
- vTaskResume( xMediumPriorityTask );
- vTaskResume( xHighPriorityTask );
- vTaskResume( xHighestPriorityTask );
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
-
- ulValue = 0xaabbaabb;
- if( xQueueSendToFront( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
- {
- /* We were expecting the queue to be empty so we should not of
- had a problem writing to the queue. */
- xErrorDetected = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* This time we should find that the queue is empty. The high priority
- task actually removed the data rather than just peeking it. */
- if( xQueuePeek( xQueue, &ulValue, qpeekNO_BLOCK ) != errQUEUE_EMPTY )
- {
- /* We expected to receive the data. */
- xErrorDetected = pdTRUE;
- }
-
- /* Unsuspend the highest and high priority tasks so we can go back
- and repeat the whole thing. The medium priority task should not be
- suspended as it was not able to peek the data in this last case. */
- vTaskResume( xHighPriorityTask );
- vTaskResume( xHighestPriorityTask );
-
- /* Lets just delay a while as this is an intensive test as we don't
- want to starve other tests of processing time. */
- vTaskDelay( qpeekSHORT_DELAY );
- }
+ QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;
+ uint32_t ulValue;
+
+ for( ; ; )
+ {
+ /* Write some data to the queue. This should unblock the highest
+ * priority task that is waiting to peek data from the queue. */
+ ulValue = 0x11223344;
+
+ if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
+ {
+ /* We were expecting the queue to be empty so we should not of
+ * had a problem writing to the queue. */
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* By the time we get here the data should have been removed from
+ * the queue. */
+ if( uxQueueMessagesWaiting( xQueue ) != 0 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Write another value to the queue, again waking the highest priority
+ * task that is blocked on the queue. */
+ ulValue = 0x01234567;
+
+ if( xQueueSendToBack( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
+ {
+ /* We were expecting the queue to be empty so we should not of
+ * had a problem writing to the queue. */
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* All the other tasks should now have successfully peeked the data.
+ * The data is still in the queue so we should be able to receive it. */
+ ulValue = 0;
+
+ if( xQueueReceive( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
+ {
+ /* We expected to receive the data. */
+ xErrorDetected = pdTRUE;
+ }
+
+ if( ulValue != 0x01234567 )
+ {
+ /* We did not receive the expected value. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Lets just delay a while as this is an intensive test as we don't
+ * want to starve other tests of processing time. */
+ vTaskDelay( qpeekSHORT_DELAY );
+
+ /* Unsuspend the other tasks so we can repeat the test - this time
+ * however not all the other tasks will peek the data as the high
+ * priority task is actually going to remove it from the queue. Send
+ * to front is used just to be different. As the queue is empty it
+ * makes no difference to the result. */
+ vTaskResume( xMediumPriorityTask );
+ vTaskResume( xHighPriorityTask );
+ vTaskResume( xHighestPriorityTask );
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+
+ ulValue = 0xaabbaabb;
+
+ if( xQueueSendToFront( xQueue, &ulValue, qpeekNO_BLOCK ) != pdPASS )
+ {
+ /* We were expecting the queue to be empty so we should not of
+ * had a problem writing to the queue. */
+ xErrorDetected = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* This time we should find that the queue is empty. The high priority
+ * task actually removed the data rather than just peeking it. */
+ if( xQueuePeek( xQueue, &ulValue, qpeekNO_BLOCK ) != errQUEUE_EMPTY )
+ {
+ /* We expected to receive the data. */
+ xErrorDetected = pdTRUE;
+ }
+
+ /* Unsuspend the highest and high priority tasks so we can go back
+ * and repeat the whole thing. The medium priority task should not be
+ * suspended as it was not able to peek the data in this last case. */
+ vTaskResume( xHighPriorityTask );
+ vTaskResume( xHighestPriorityTask );
+
+ /* Lets just delay a while as this is an intensive test as we don't
+ * want to starve other tests of processing time. */
+ vTaskDelay( qpeekSHORT_DELAY );
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreQueuePeekTasksStillRunning( void )
{
-static uint32_t ulLastLoopCounter = 0;
+ static uint32_t ulLastLoopCounter = 0;
- /* If the demo task is still running then we expect the loopcounter to
- have incremented since this function was last called. */
- if( ulLastLoopCounter == ulLoopCounter )
- {
- xErrorDetected = pdTRUE;
- }
+ /* If the demo task is still running then we expect the loopcounter to
+ * have incremented since this function was last called. */
+ if( ulLastLoopCounter == ulLoopCounter )
+ {
+ xErrorDetected = pdTRUE;
+ }
- ulLastLoopCounter = ulLoopCounter;
+ ulLastLoopCounter = ulLoopCounter;
- /* Errors detected in the task itself will have latched xErrorDetected
- to true. */
+ /* Errors detected in the task itself will have latched xErrorDetected
+ * to true. */
- return ( BaseType_t ) !xErrorDetected;
+ return ( BaseType_t ) !xErrorDetected;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c b/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c
index 7198fede3..01978fb54 100644
--- a/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c
+++ b/FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c
@@ -39,192 +39,198 @@
#include "QueueOverwrite.h"
/* A block time of 0 just means "don't block". */
-#define qoDONT_BLOCK 0
+#define qoDONT_BLOCK 0
/* Number of times to overwrite the value in the queue. */
-#define qoLOOPS 5
+#define qoLOOPS 5
/* The task that uses the queue. */
-static void prvQueueOverwriteTask( void *pvParameters );
+static void prvQueueOverwriteTask( void * pvParameters );
/* Variable that is incremented on each loop of prvQueueOverwriteTask() provided
-prvQueueOverwriteTask() has not found any errors. */
+ * prvQueueOverwriteTask() has not found any errors. */
static uint32_t ulLoopCounter = 0;
/* Set to pdFALSE if an error is discovered by the
-vQueueOverwritePeriodicISRDemo() function. */
+ * vQueueOverwritePeriodicISRDemo() function. */
static BaseType_t xISRTestStatus = pdPASS;
/* The queue that is accessed from the ISR. The queue accessed by the task is
-created inside the task itself. */
+ * created inside the task itself. */
static QueueHandle_t xISRQueue = NULL;
/*-----------------------------------------------------------*/
void vStartQueueOverwriteTask( UBaseType_t uxPriority )
{
-const UBaseType_t uxQueueLength = 1;
+ const UBaseType_t uxQueueLength = 1;
- /* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
- be used on queues that have a length of 1. */
- xISRQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
+ /* Create the queue used by the ISR. xQueueOverwriteFromISR() should only
+ * be used on queues that have a length of 1. */
+ xISRQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
- /* Create the test task. The queue used by the test task is created inside
- the task itself. */
- xTaskCreate( prvQueueOverwriteTask, "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
+ /* Create the test task. The queue used by the test task is created inside
+ * the task itself. */
+ xTaskCreate( prvQueueOverwriteTask, "QOver", configMINIMAL_STACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
}
/*-----------------------------------------------------------*/
-static void prvQueueOverwriteTask( void *pvParameters )
+static void prvQueueOverwriteTask( void * pvParameters )
{
-QueueHandle_t xTaskQueue;
-const UBaseType_t uxQueueLength = 1;
-uint32_t ulValue, ulStatus = pdPASS, x;
-
- /* The parameter is not used. */
- ( void ) pvParameters;
-
- /* Create the queue. xQueueOverwrite() should only be used on queues that
- have a length of 1. */
- xTaskQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
- configASSERT( xTaskQueue );
-
- for( ;; )
- {
- /* The queue is empty. Writing to the queue then reading from the queue
- should return the item written. */
- ulValue = 10;
- xQueueOverwrite( xTaskQueue, &ulValue );
-
- ulValue = 0;
- xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
-
- if( ulValue != 10 )
- {
- ulStatus = pdFAIL;
- }
-
- /* Now try writing to the queue several times. Each time the value
- in the queue should get overwritten. */
- for( x = 0; x < qoLOOPS; x++ )
- {
- /* Write to the queue. */
- xQueueOverwrite( xTaskQueue, &x );
-
- /* Check the value in the queue is that written, even though the
- queue was not necessarily empty. */
- xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
- if( ulValue != x )
- {
- ulStatus = pdFAIL;
- }
-
- /* There should always be one item in the queue. */
- if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
- {
- ulStatus = pdFAIL;
- }
- }
-
- /* Empty the queue again. */
- xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
-
- if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
- {
- ulStatus = pdFAIL;
- }
-
- if( ulStatus != pdFAIL )
- {
- /* Increment a counter to show this task is still running without
- error. */
- ulLoopCounter++;
- }
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
- }
+ QueueHandle_t xTaskQueue;
+ const UBaseType_t uxQueueLength = 1;
+ uint32_t ulValue, ulStatus = pdPASS, x;
+
+ /* The parameter is not used. */
+ ( void ) pvParameters;
+
+ /* Create the queue. xQueueOverwrite() should only be used on queues that
+ * have a length of 1. */
+ xTaskQueue = xQueueCreate( uxQueueLength, ( UBaseType_t ) sizeof( uint32_t ) );
+ configASSERT( xTaskQueue );
+
+ for( ; ; )
+ {
+ /* The queue is empty. Writing to the queue then reading from the queue
+ * should return the item written. */
+ ulValue = 10;
+ xQueueOverwrite( xTaskQueue, &ulValue );
+
+ ulValue = 0;
+ xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
+
+ if( ulValue != 10 )
+ {
+ ulStatus = pdFAIL;
+ }
+
+ /* Now try writing to the queue several times. Each time the value
+ * in the queue should get overwritten. */
+ for( x = 0; x < qoLOOPS; x++ )
+ {
+ /* Write to the queue. */
+ xQueueOverwrite( xTaskQueue, &x );
+
+ /* Check the value in the queue is that written, even though the
+ * queue was not necessarily empty. */
+ xQueuePeek( xTaskQueue, &ulValue, qoDONT_BLOCK );
+
+ if( ulValue != x )
+ {
+ ulStatus = pdFAIL;
+ }
+
+ /* There should always be one item in the queue. */
+ if( uxQueueMessagesWaiting( xTaskQueue ) != uxQueueLength )
+ {
+ ulStatus = pdFAIL;
+ }
+ }
+
+ /* Empty the queue again. */
+ xQueueReceive( xTaskQueue, &ulValue, qoDONT_BLOCK );
+
+ if( uxQueueMessagesWaiting( xTaskQueue ) != 0 )
+ {
+ ulStatus = pdFAIL;
+ }
+
+ if( ulStatus != pdFAIL )
+ {
+ /* Increment a counter to show this task is still running without
+ * error. */
+ ulLoopCounter++;
+ }
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+ }
}
/*-----------------------------------------------------------*/
BaseType_t xIsQueueOverwriteTaskStillRunning( void )
{
-BaseType_t xReturn;
-
- if( xISRTestStatus != pdPASS )
- {
- xReturn = pdFAIL;
- }
- else if( ulLoopCounter > 0 )
- {
- xReturn = pdPASS;
- }
- else
- {
- /* The task has either stalled of discovered an error. */
- xReturn = pdFAIL;
- }
-
- ulLoopCounter = 0;
-
- return xReturn;
+ BaseType_t xReturn;
+
+ if( xISRTestStatus != pdPASS )
+ {
+ xReturn = pdFAIL;
+ }
+ else if( ulLoopCounter > 0 )
+ {
+ xReturn = pdPASS;
+ }
+ else
+ {
+ /* The task has either stalled of discovered an error. */
+ xReturn = pdFAIL;
+ }
+
+ ulLoopCounter = 0;
+
+ return xReturn;
}
/*-----------------------------------------------------------*/
void vQueueOverwritePeriodicISRDemo( void )
{
-static uint32_t ulCallCount = 0;
-const uint32_t ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
-uint32_t ulRx;
-
- /* This function should be called from an interrupt, such as the tick hook
- function vApplicationTickHook(). */
-
- configASSERT( xISRQueue );
-
- switch( ulCallCount )
- {
- case 0:
- /* The queue is empty. Write ulTx1 to the queue. In this demo the
- last parameter is not used because there are no tasks blocked on
- this queue. */
- xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
-
- /* Peek the queue to check it holds the expected value. */
- xQueuePeekFromISR( xISRQueue, &ulRx );
- if( ulRx != ulTx1 )
- {
- xISRTestStatus = pdFAIL;
- }
- break;
-
- case 1:
- /* The queue already holds ulTx1. Overwrite the value in the queue
- with ulTx2. */
- xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
- break;
-
- case 2:
- /* Read from the queue to empty the queue again. The value read
- should be ulTx2. */
- xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
-
- if( ulRx != ulTx2 )
- {
- xISRTestStatus = pdFAIL;
- }
- break;
- }
-
- /* Run the next case in the switch statement above next time this function
- is called. */
- ulCallCount++;
-
- if( ulCallCount >= ulNumberOfSwitchCases )
- {
- /* Go back to the start. */
- ulCallCount = 0;
- }
-}
+ static uint32_t ulCallCount = 0;
+ const uint32_t ulTx1 = 10UL, ulTx2 = 20UL, ulNumberOfSwitchCases = 3UL;
+ uint32_t ulRx;
+
+ /* This function should be called from an interrupt, such as the tick hook
+ * function vApplicationTickHook(). */
+
+ configASSERT( xISRQueue );
+
+ switch( ulCallCount )
+ {
+ case 0:
+
+ /* The queue is empty. Write ulTx1 to the queue. In this demo the
+ * last parameter is not used because there are no tasks blocked on
+ * this queue. */
+ xQueueOverwriteFromISR( xISRQueue, &ulTx1, NULL );
+
+ /* Peek the queue to check it holds the expected value. */
+ xQueuePeekFromISR( xISRQueue, &ulRx );
+
+ if( ulRx != ulTx1 )
+ {
+ xISRTestStatus = pdFAIL;
+ }
+
+ break;
+ case 1:
+
+ /* The queue already holds ulTx1. Overwrite the value in the queue
+ * with ulTx2. */
+ xQueueOverwriteFromISR( xISRQueue, &ulTx2, NULL );
+ break;
+
+ case 2:
+
+ /* Read from the queue to empty the queue again. The value read
+ * should be ulTx2. */
+ xQueueReceiveFromISR( xISRQueue, &ulRx, NULL );
+
+ if( ulRx != ulTx2 )
+ {
+ xISRTestStatus = pdFAIL;
+ }
+
+ break;
+ }
+
+ /* Run the next case in the switch statement above next time this function
+ * is called. */
+ ulCallCount++;
+
+ if( ulCallCount >= ulNumberOfSwitchCases )
+ {
+ /* Go back to the start. */
+ ulCallCount = 0;
+ }
+}
diff --git a/FreeRTOS/Demo/Common/Minimal/QueueSet.c b/FreeRTOS/Demo/Common/Minimal/QueueSet.c
index bd9eb493a..ca32f9e81 100644
--- a/FreeRTOS/Demo/Common/Minimal/QueueSet.c
+++ b/FreeRTOS/Demo/Common/Minimal/QueueSet.c
@@ -52,66 +52,66 @@
#include "QueueSet.h"
-#if( configUSE_QUEUE_SETS == 1 ) /* Remove the tests if queue sets are not defined. */
+#if ( configUSE_QUEUE_SETS == 1 ) /* Remove the tests if queue sets are not defined. */
/* The number of queues that are created and added to the queue set. */
-#define queuesetNUM_QUEUES_IN_SET 3
+ #define queuesetNUM_QUEUES_IN_SET 3
/* The length of each created queue. */
-#define queuesetQUEUE_LENGTH 3
+ #define queuesetQUEUE_LENGTH 3
/* Block times used in this demo. A block time or 0 means "don't block". */
-#define queuesetSHORT_DELAY 200
-#define queuesetDONT_BLOCK 0
+ #define queuesetSHORT_DELAY 200
+ #define queuesetDONT_BLOCK 0
/* Messages are sent in incrementing order from both a task and an interrupt.
-The task sends values in the range 0 to 0xfffe, and the interrupt sends values
-in the range of 0xffff to ULONG_MAX. */
-#define queuesetINITIAL_ISR_TX_VALUE 0xffffUL
+ * The task sends values in the range 0 to 0xfffe, and the interrupt sends values
+ * in the range of 0xffff to ULONG_MAX. */
+ #define queuesetINITIAL_ISR_TX_VALUE 0xffffUL
/* The priorities used in this demo. */
-#define queuesetLOW_PRIORITY ( tskIDLE_PRIORITY )
-#define queuesetMEDIUM_PRIORITY ( queuesetLOW_PRIORITY + 1 )
+ #define queuesetLOW_PRIORITY ( tskIDLE_PRIORITY )
+ #define queuesetMEDIUM_PRIORITY ( queuesetLOW_PRIORITY + 1 )
/* For test purposes the priority of the sending task is changed after every
-queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
-#define queuesetPRIORITY_CHANGE_LOOPS ( ( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH ) * 2 )
+ * queuesetPRIORITY_CHANGE_LOOPS number of values are sent to a queue. */
+ #define queuesetPRIORITY_CHANGE_LOOPS ( ( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH ) * 2 )
/* The ISR sends to the queue every queuesetISR_TX_PERIOD ticks. */
-#define queuesetISR_TX_PERIOD ( 100UL )
+ #define queuesetISR_TX_PERIOD ( 100UL )
/* A delay inserted when the Tx task changes its priority to be above the idle
-task priority to ensure the idle priority tasks get some CPU time before the
-next iteration of the queue set Tx task. */
-#define queuesetTX_LOOP_DELAY pdMS_TO_TICKS( ( TickType_t ) 200 )
+ * task priority to ensure the idle priority tasks get some CPU time before the
+ * next iteration of the queue set Tx task. */
+ #define queuesetTX_LOOP_DELAY pdMS_TO_TICKS( ( TickType_t ) 200 )
/* The allowable maximum deviation between a received value and the expected
-received value. A deviation will occur when data is received from a queue
-inside an ISR in between a task receiving from a queue and the task checking
-the received value. */
-#define queuesetALLOWABLE_RX_DEVIATION 3
+ * received value. A deviation will occur when data is received from a queue
+ * inside an ISR in between a task receiving from a queue and the task checking
+ * the received value. */
+ #define queuesetALLOWABLE_RX_DEVIATION 3
/* Ignore values that are at the boundaries of allowable values to make the
-testing of limits easier (don't have to deal with wrapping values). */
-#define queuesetIGNORED_BOUNDARY ( queuesetALLOWABLE_RX_DEVIATION * 2 )
+ * testing of limits easier (don't have to deal with wrapping values). */
+ #define queuesetIGNORED_BOUNDARY ( queuesetALLOWABLE_RX_DEVIATION * 2 )
-typedef enum
-{
- eEqualPriority = 0, /* Tx and Rx tasks have the same priority. */
- eTxHigherPriority, /* The priority of the Tx task is above that of the Rx task. */
- eTxLowerPriority /* The priority of the Tx task is below that of the Rx task. */
-} eRelativePriorities;
+ typedef enum
+ {
+ eEqualPriority = 0, /* Tx and Rx tasks have the same priority. */
+ eTxHigherPriority, /* The priority of the Tx task is above that of the Rx task. */
+ eTxLowerPriority /* The priority of the Tx task is below that of the Rx task. */
+ } eRelativePriorities;
/*
* The task that periodically sends to the queue set.
*/
-static void prvQueueSetSendingTask( void *pvParameters );
+ static void prvQueueSetSendingTask( void * pvParameters );
/*
* The task that reads from the queue set.
*/
-static void prvQueueSetReceivingTask( void *pvParameters );
+ static void prvQueueSetReceivingTask( void * pvParameters );
/*
* Check the value received from a queue is the expected value. Some values
@@ -119,999 +119,1043 @@ static void prvQueueSetReceivingTask( void *pvParameters );
* range of the value being used to distinguish between the two message
* sources.
*/
-static void prvCheckReceivedValue( uint32_t ulReceived );
+ static void prvCheckReceivedValue( uint32_t ulReceived );
/*
* For purposes of test coverage, functions that read from and write to a
* queue set from an ISR respectively.
*/
-static void prvReceiveFromQueueInSetFromISR( void );
-static void prvSendToQueueInSetFromISR( void );
+ static void prvReceiveFromQueueInSetFromISR( void );
+ static void prvSendToQueueInSetFromISR( void );
/*
* Create the queues and add them to a queue set before resuming the Tx
* task.
*/
-static void prvSetupTest( void );
+ static void prvSetupTest( void );
/*
* Checks a value received from a queue falls within the range of expected
* values.
*/
-static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived );
+ static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived,
+ uint32_t ulExpectedReceived );
/*
* Increase test coverage by occasionally change the priorities of the two tasks
* relative to each other.
*/
-static void prvChangeRelativePriorities( void );
+ static void prvChangeRelativePriorities( void );
/*
* Queue overwrites can only be performed on queues of length of one, requiring
* a special test function so a queue of length 1 can temporarily be added to a
* set.
*/
-static void prvTestQueueOverwriteWithQueueSet( void );
+ static void prvTestQueueOverwriteWithQueueSet( void );
/*
* Test the case where two queues within a set are written to with
* xQueueOverwrite().
*/
-static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void );
-static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void );
+ static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void );
+ static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void );
/*
* Local pseudo random number seed and return functions. Used to avoid calls
* to the standard library.
*/
-static size_t prvRand( void );
-static void prvSRand( size_t uxSeed );
+ static size_t prvRand( void );
+ static void prvSRand( size_t uxSeed );
/*-----------------------------------------------------------*/
/* The queues that are added to the set. */
-static QueueHandle_t xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
+ static QueueHandle_t xQueues[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
/* Counts how many times each queue in the set is used to ensure all the
-queues are used. */
-static uint32_t ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
+ * queues are used. */
+ static uint32_t ulQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
/* The handle of the queue set to which the queues are added. */
-static QueueSetHandle_t xQueueSet;
+ static QueueSetHandle_t xQueueSet;
/* If the prvQueueSetReceivingTask() task has not detected any errors then
-it increments ulCycleCounter on each iteration.
-xAreQueueSetTasksStillRunning() returns pdPASS if the value of
-ulCycleCounter has changed between consecutive calls, and pdFALSE if
-ulCycleCounter has stopped incrementing (indicating an error condition). */
-static volatile uint32_t ulCycleCounter = 0UL;
+ * it increments ulCycleCounter on each iteration.
+ * xAreQueueSetTasksStillRunning() returns pdPASS if the value of
+ * ulCycleCounter has changed between consecutive calls, and pdFALSE if
+ * ulCycleCounter has stopped incrementing (indicating an error condition). */
+ static volatile uint32_t ulCycleCounter = 0UL;
/* Set to pdFAIL if an error is detected by any queue set task.
-ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
-static volatile BaseType_t xQueueSetTasksStatus = pdPASS;
+ * ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
+ static volatile BaseType_t xQueueSetTasksStatus = pdPASS;
/* Just a flag to let the function that writes to a queue from an ISR know that
-the queues are setup and can be used. */
-static volatile BaseType_t xSetupComplete = pdFALSE;
+ * the queues are setup and can be used. */
+ static volatile BaseType_t xSetupComplete = pdFALSE;
/* The value sent to the queue from the ISR is file scope so the
-xAreQueeuSetTasksStillRunning() function can check it is incrementing as
-expected. */
-static volatile uint32_t ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
+ * xAreQueeuSetTasksStillRunning() function can check it is incrementing as
+ * expected. */
+ static volatile uint32_t ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
/* Used by the pseudo random number generator. */
-static size_t uxNextRand = 0;
+ static size_t uxNextRand = 0;
/* The task handles are stored so their priorities can be changed. */
-TaskHandle_t xQueueSetSendingTask, xQueueSetReceivingTask;
+ TaskHandle_t xQueueSetSendingTask, xQueueSetReceivingTask;
/*-----------------------------------------------------------*/
-void vStartQueueSetTasks( void )
-{
- /* Create the tasks. */
- xTaskCreate( prvQueueSetSendingTask, "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );
-
- if( xQueueSetSendingTask != NULL )
- {
- xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );
-
- /* It is important that the sending task does not attempt to write to a
- queue before the queue has been created. It is therefore placed into
- the suspended state before the scheduler has started. It is resumed by
- the receiving task after the receiving task has created the queues and
- added the queues to the queue set. */
- vTaskSuspend( xQueueSetSendingTask );
- }
-}
+ void vStartQueueSetTasks( void )
+ {
+ /* Create the tasks. */
+ xTaskCreate( prvQueueSetSendingTask, "SetTx", configMINIMAL_STACK_SIZE, NULL, queuesetMEDIUM_PRIORITY, &xQueueSetSendingTask );
+
+ if( xQueueSetSendingTask != NULL )
+ {
+ xTaskCreate( prvQueueSetReceivingTask, "SetRx", configMINIMAL_STACK_SIZE, ( void * ) xQueueSetSendingTask, queuesetMEDIUM_PRIORITY, &xQueueSetReceivingTask );
+
+ /* It is important that the sending task does not attempt to write to a
+ * queue before the queue has been created. It is therefore placed into
+ * the suspended state before the scheduler has started. It is resumed by
+ * the receiving task after the receiving task has created the queues and
+ * added the queues to the queue set. */
+ vTaskSuspend( xQueueSetSendingTask );
+ }
+ }
/*-----------------------------------------------------------*/
-BaseType_t xAreQueueSetTasksStillRunning( void )
-{
-static uint32_t ulLastCycleCounter, ulLastISRTxValue = 0;
-static uint32_t ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
-BaseType_t xReturn = pdPASS, x;
-
- if( ulLastCycleCounter == ulCycleCounter )
- {
- /* The cycle counter is no longer being incremented. Either one of the
- tasks is stalled or an error has been detected. */
- xReturn = pdFAIL;
- }
-
- ulLastCycleCounter = ulCycleCounter;
-
- /* Ensure that all the queues in the set have been used. This ensures the
- test is working as intended and guards against the rand() in the Tx task
- missing some values. */
- for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
- {
- if( ulLastQueueUsedCounter[ x ] == ulQueueUsedCounter[ x ] )
- {
- xReturn = pdFAIL;
- }
-
- ulLastQueueUsedCounter[ x ] = ulQueueUsedCounter[ x ];
- }
-
- /* Check the global status flag. */
- if( xQueueSetTasksStatus != pdPASS )
- {
- xReturn = pdFAIL;
- }
-
- /* Check that the ISR is still sending values to the queues too. */
- if( ulISRTxValue == ulLastISRTxValue )
- {
- xReturn = pdFAIL;
- }
- else
- {
- ulLastISRTxValue = ulISRTxValue;
- }
-
- return xReturn;
-}
+ BaseType_t xAreQueueSetTasksStillRunning( void )
+ {
+ static uint32_t ulLastCycleCounter, ulLastISRTxValue = 0;
+ static uint32_t ulLastQueueUsedCounter[ queuesetNUM_QUEUES_IN_SET ] = { 0 };
+ BaseType_t xReturn = pdPASS, x;
+
+ if( ulLastCycleCounter == ulCycleCounter )
+ {
+ /* The cycle counter is no longer being incremented. Either one of the
+ * tasks is stalled or an error has been detected. */
+ xReturn = pdFAIL;
+ }
+
+ ulLastCycleCounter = ulCycleCounter;
+
+ /* Ensure that all the queues in the set have been used. This ensures the
+ * test is working as intended and guards against the rand() in the Tx task
+ * missing some values. */
+ for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
+ {
+ if( ulLastQueueUsedCounter[ x ] == ulQueueUsedCounter[ x ] )
+ {
+ xReturn = pdFAIL;
+ }
+
+ ulLastQueueUsedCounter[ x ] = ulQueueUsedCounter[ x ];
+ }
+
+ /* Check the global status flag. */
+ if( xQueueSetTasksStatus != pdPASS )
+ {
+ xReturn = pdFAIL;
+ }
+
+ /* Check that the ISR is still sending values to the queues too. */
+ if( ulISRTxValue == ulLastISRTxValue )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ ulLastISRTxValue = ulISRTxValue;
+ }
+
+ return xReturn;
+ }
/*-----------------------------------------------------------*/
-static void prvQueueSetSendingTask( void *pvParameters )
-{
-uint32_t ulTaskTxValue = 0;
-size_t uxQueueToWriteTo;
-QueueHandle_t xQueueInUse;
-
- /* Remove compiler warning about the unused parameter. */
- ( void ) pvParameters;
-
- /* Seed mini pseudo random number generator. */
- prvSRand( ( size_t ) &ulTaskTxValue );
-
- for( ;; )
- {
- /* Generate the index for the queue to which a value is to be sent. */
- uxQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;
- xQueueInUse = xQueues[ uxQueueToWriteTo ];
-
- /* Note which index is being written to to ensure all the queues are
- used. */
- ( ulQueueUsedCounter[ uxQueueToWriteTo ] )++;
-
- /* Send to the queue to unblock the task that is waiting for data to
- arrive on a queue within the queue set to which this queue belongs. */
- if( xQueueSendToBack( xQueueInUse, &ulTaskTxValue, portMAX_DELAY ) != pdPASS )
- {
- /* The send should always pass as an infinite block time was
- used. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
-
- ulTaskTxValue++;
-
- /* If the Tx value has reached the range used by the ISR then set it
- back to 0. */
- if( ulTaskTxValue == queuesetINITIAL_ISR_TX_VALUE )
- {
- ulTaskTxValue = 0;
- }
-
- /* Increase test coverage by occasionally change the priorities of the
- two tasks relative to each other. */
- prvChangeRelativePriorities();
- }
-}
+ static void prvQueueSetSendingTask( void * pvParameters )
+ {
+ uint32_t ulTaskTxValue = 0;
+ size_t uxQueueToWriteTo;
+ QueueHandle_t xQueueInUse;
+
+ /* Remove compiler warning about the unused parameter. */
+ ( void ) pvParameters;
+
+ /* Seed mini pseudo random number generator. */
+ prvSRand( ( size_t ) &ulTaskTxValue );
+
+ for( ; ; )
+ {
+ /* Generate the index for the queue to which a value is to be sent. */
+ uxQueueToWriteTo = prvRand() % queuesetNUM_QUEUES_IN_SET;
+ xQueueInUse = xQueues[ uxQueueToWriteTo ];
+
+ /* Note which index is being written to to ensure all the queues are
+ * used. */
+ ( ulQueueUsedCounter[ uxQueueToWriteTo ] )++;
+
+ /* Send to the queue to unblock the task that is waiting for data to
+ * arrive on a queue within the queue set to which this queue belongs. */
+ if( xQueueSendToBack( xQueueInUse, &ulTaskTxValue, portMAX_DELAY ) != pdPASS )
+ {
+ /* The send should always pass as an infinite block time was
+ * used. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+
+ ulTaskTxValue++;
+
+ /* If the Tx value has reached the range used by the ISR then set it
+ * back to 0. */
+ if( ulTaskTxValue == queuesetINITIAL_ISR_TX_VALUE )
+ {
+ ulTaskTxValue = 0;
+ }
+
+ /* Increase test coverage by occasionally change the priorities of the
+ * two tasks relative to each other. */
+ prvChangeRelativePriorities();
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvChangeRelativePriorities( void )
-{
-static UBaseType_t ulLoops = 0;
-static eRelativePriorities ePriorities = eEqualPriority;
-
- /* Occasionally change the task priority relative to the priority of
- the receiving task. */
- ulLoops++;
- if( ulLoops >= queuesetPRIORITY_CHANGE_LOOPS )
- {
- ulLoops = 0;
-
- switch( ePriorities )
- {
- case eEqualPriority:
- /* Both tasks are running with medium priority. Now lower the
- priority of the receiving task so the Tx task has the higher
- relative priority. */
- vTaskPrioritySet( xQueueSetReceivingTask, queuesetLOW_PRIORITY );
- ePriorities = eTxHigherPriority;
- break;
-
- case eTxHigherPriority:
- /* The Tx task is running with a higher priority than the Rx
- task. Switch the priorities around so the Rx task has the
- higher relative priority. */
- vTaskPrioritySet( xQueueSetReceivingTask, queuesetMEDIUM_PRIORITY );
- vTaskPrioritySet( xQueueSetSendingTask, queuesetLOW_PRIORITY );
- ePriorities = eTxLowerPriority;
- break;
-
- case eTxLowerPriority:
- /* The Tx task is running with a lower priority than the Rx
- task. Make the priorities equal again. */
- vTaskPrioritySet( xQueueSetSendingTask, queuesetMEDIUM_PRIORITY );
- ePriorities = eEqualPriority;
-
- /* When both tasks are using a non-idle priority the queue set
- tasks will starve idle priority tasks of execution time - so
- relax a bit before the next iteration to minimise the impact. */
- vTaskDelay( queuesetTX_LOOP_DELAY );
-
- break;
- }
- }
-}
+ static void prvChangeRelativePriorities( void )
+ {
+ static UBaseType_t ulLoops = 0;
+ static eRelativePriorities ePriorities = eEqualPriority;
+
+ /* Occasionally change the task priority relative to the priority of
+ * the receiving task. */
+ ulLoops++;
+
+ if( ulLoops >= queuesetPRIORITY_CHANGE_LOOPS )
+ {
+ ulLoops = 0;
+
+ switch( ePriorities )
+ {
+ case eEqualPriority:
+
+ /* Both tasks are running with medium priority. Now lower the
+ * priority of the receiving task so the Tx task has the higher
+ * relative priority. */
+ vTaskPrioritySet( xQueueSetReceivingTask, queuesetLOW_PRIORITY );
+ ePriorities = eTxHigherPriority;
+ break;
+
+ case eTxHigherPriority:
+
+ /* The Tx task is running with a higher priority than the Rx
+ * task. Switch the priorities around so the Rx task has the
+ * higher relative priority. */
+ vTaskPrioritySet( xQueueSetReceivingTask, queuesetMEDIUM_PRIORITY );
+ vTaskPrioritySet( xQueueSetSendingTask, queuesetLOW_PRIORITY );
+ ePriorities = eTxLowerPriority;
+ break;
+
+ case eTxLowerPriority:
+
+ /* The Tx task is running with a lower priority than the Rx
+ * task. Make the priorities equal again. */
+ vTaskPrioritySet( xQueueSetSendingTask, queuesetMEDIUM_PRIORITY );
+ ePriorities = eEqualPriority;
+
+ /* When both tasks are using a non-idle priority the queue set
+ * tasks will starve idle priority tasks of execution time - so
+ * relax a bit before the next iteration to minimise the impact. */
+ vTaskDelay( queuesetTX_LOOP_DELAY );
+
+ break;
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvQueueSetReceivingTask( void *pvParameters )
-{
-uint32_t ulReceived;
-QueueHandle_t xActivatedQueue;
-TickType_t xBlockTime;
-
- /* Remove compiler warnings. */
- ( void ) pvParameters;
-
- /* Create the queues and add them to the queue set before resuming the Tx
- task. */
- prvSetupTest();
-
- for( ;; )
- {
- /* For test coverage reasons, the block time is dependent on the
- priority of this task - which changes during the test. When the task
- is at the idle priority it polls the queue set. */
- if( uxTaskPriorityGet( NULL ) == tskIDLE_PRIORITY )
- {
- xBlockTime = 0;
- }
- else
- {
- xBlockTime = portMAX_DELAY;
- }
-
- /* Wait for a message to arrive on one of the queues in the set. */
- xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );
-
- if( xActivatedQueue == NULL )
- {
- if( xBlockTime != 0 )
- {
- /* This should not happen as an infinite delay was used. */
- xQueueSetTasksStatus = pdFAIL;
- }
- }
- else
- {
- /* Reading from the queue should pass with a zero block time as
- this task will only run when something has been posted to a task
- in the queue set. */
- if( xQueueReceive( xActivatedQueue, &ulReceived, queuesetDONT_BLOCK ) != pdPASS )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Ensure the value received was the value expected. This function
- manipulates file scope data and is also called from an ISR, hence
- the critical section. */
- taskENTER_CRITICAL();
- {
- prvCheckReceivedValue( ulReceived );
- }
- taskEXIT_CRITICAL();
-
- if( xQueueSetTasksStatus == pdPASS )
- {
- ulCycleCounter++;
- }
- }
- }
-}
+ static void prvQueueSetReceivingTask( void * pvParameters )
+ {
+ uint32_t ulReceived;
+ QueueHandle_t xActivatedQueue;
+ TickType_t xBlockTime;
+
+ /* Remove compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Create the queues and add them to the queue set before resuming the Tx
+ * task. */
+ prvSetupTest();
+
+ for( ; ; )
+ {
+ /* For test coverage reasons, the block time is dependent on the
+ * priority of this task - which changes during the test. When the task
+ * is at the idle priority it polls the queue set. */
+ if( uxTaskPriorityGet( NULL ) == tskIDLE_PRIORITY )
+ {
+ xBlockTime = 0;
+ }
+ else
+ {
+ xBlockTime = portMAX_DELAY;
+ }
+
+ /* Wait for a message to arrive on one of the queues in the set. */
+ xActivatedQueue = xQueueSelectFromSet( xQueueSet, portMAX_DELAY );
+
+ if( xActivatedQueue == NULL )
+ {
+ if( xBlockTime != 0 )
+ {
+ /* This should not happen as an infinite delay was used. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+ }
+ else
+ {
+ /* Reading from the queue should pass with a zero block time as
+ * this task will only run when something has been posted to a task
+ * in the queue set. */
+ if( xQueueReceive( xActivatedQueue, &ulReceived, queuesetDONT_BLOCK ) != pdPASS )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Ensure the value received was the value expected. This function
+ * manipulates file scope data and is also called from an ISR, hence
+ * the critical section. */
+ taskENTER_CRITICAL();
+ {
+ prvCheckReceivedValue( ulReceived );
+ }
+ taskEXIT_CRITICAL();
+
+ if( xQueueSetTasksStatus == pdPASS )
+ {
+ ulCycleCounter++;
+ }
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-void vQueueSetAccessQueueSetFromISR( void )
-{
-static uint32_t ulCallCount = 0;
-
- /* xSetupComplete is set to pdTRUE when the queues have been created and
- are available for use. */
- if( xSetupComplete == pdTRUE )
- {
- /* It is intended that this function is called from the tick hook
- function, so each call is one tick period apart. */
- ulCallCount++;
- if( ulCallCount > queuesetISR_TX_PERIOD )
- {
- ulCallCount = 0;
-
- /* First attempt to read from the queue set. */
- prvReceiveFromQueueInSetFromISR();
-
- /* Then write to the queue set. */
- prvSendToQueueInSetFromISR();
- }
- }
-}
+ void vQueueSetAccessQueueSetFromISR( void )
+ {
+ static uint32_t ulCallCount = 0;
+
+ /* xSetupComplete is set to pdTRUE when the queues have been created and
+ * are available for use. */
+ if( xSetupComplete == pdTRUE )
+ {
+ /* It is intended that this function is called from the tick hook
+ * function, so each call is one tick period apart. */
+ ulCallCount++;
+
+ if( ulCallCount > queuesetISR_TX_PERIOD )
+ {
+ ulCallCount = 0;
+
+ /* First attempt to read from the queue set. */
+ prvReceiveFromQueueInSetFromISR();
+
+ /* Then write to the queue set. */
+ prvSendToQueueInSetFromISR();
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvCheckReceivedValue( uint32_t ulReceived )
-{
-static uint32_t ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
-
- /* Values are received in tasks and interrupts. It is likely that the
- receiving task will sometimes get preempted by the receiving interrupt
- between reading a value from the queue and calling this function. When
- that happens, if the receiving interrupt calls this function the values
- will get passed into this function slightly out of order. For that
- reason the value passed in is tested against a small range of expected
- values, rather than a single absolute value. To make the range testing
- easier values in the range limits are ignored. */
-
- /* If the received value is equal to or greater than
- queuesetINITIAL_ISR_TX_VALUE then it was sent by an ISR. */
- if( ulReceived >= queuesetINITIAL_ISR_TX_VALUE )
- {
- /* The value was sent from the ISR. */
- if( ( ulReceived - queuesetINITIAL_ISR_TX_VALUE ) < queuesetIGNORED_BOUNDARY )
- {
- /* The value received is at the lower limit of the expected range.
- Don't test it and expect to receive one higher next time. */
- }
- else if( ( ULONG_MAX - ulReceived ) <= queuesetIGNORED_BOUNDARY )
- {
- /* The value received is at the higher limit of the expected range.
- Don't test it and expect to wrap soon. */
- }
- else
- {
- /* Check the value against its expected value range. */
- if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromISR ) != pdPASS )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
- }
-
- configASSERT( xQueueSetTasksStatus );
-
- /* It is expected to receive an incrementing number. */
- ulExpectedReceivedFromISR++;
- if( ulExpectedReceivedFromISR == 0 )
- {
- ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
- }
- }
- else
- {
- /* The value was sent from the Tx task. */
- if( ulReceived < queuesetIGNORED_BOUNDARY )
- {
- /* The value received is at the lower limit of the expected range.
- Don't test it, and expect to receive one higher next time. */
- }
- else if( ( ( queuesetINITIAL_ISR_TX_VALUE - 1 ) - ulReceived ) <= queuesetIGNORED_BOUNDARY )
- {
- /* The value received is at the higher limit of the expected range.
- Don't test it and expect to wrap soon. */
- }
- else
- {
- /* Check the value against its expected value range. */
- if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromTask ) != pdPASS )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
- }
-
- configASSERT( xQueueSetTasksStatus );
-
- /* It is expected to receive an incrementing number. */
- ulExpectedReceivedFromTask++;
- if( ulExpectedReceivedFromTask >= queuesetINITIAL_ISR_TX_VALUE )
- {
- ulExpectedReceivedFromTask = 0;
- }
- }
-}
+ static void prvCheckReceivedValue( uint32_t ulReceived )
+ {
+ static uint32_t ulExpectedReceivedFromTask = 0, ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
+
+ /* Values are received in tasks and interrupts. It is likely that the
+ * receiving task will sometimes get preempted by the receiving interrupt
+ * between reading a value from the queue and calling this function. When
+ * that happens, if the receiving interrupt calls this function the values
+ * will get passed into this function slightly out of order. For that
+ * reason the value passed in is tested against a small range of expected
+ * values, rather than a single absolute value. To make the range testing
+ * easier values in the range limits are ignored. */
+
+ /* If the received value is equal to or greater than
+ * queuesetINITIAL_ISR_TX_VALUE then it was sent by an ISR. */
+ if( ulReceived >= queuesetINITIAL_ISR_TX_VALUE )
+ {
+ /* The value was sent from the ISR. */
+ if( ( ulReceived - queuesetINITIAL_ISR_TX_VALUE ) < queuesetIGNORED_BOUNDARY )
+ {
+ /* The value received is at the lower limit of the expected range.
+ * Don't test it and expect to receive one higher next time. */
+ }
+ else if( ( ULONG_MAX - ulReceived ) <= queuesetIGNORED_BOUNDARY )
+ {
+ /* The value received is at the higher limit of the expected range.
+ * Don't test it and expect to wrap soon. */
+ }
+ else
+ {
+ /* Check the value against its expected value range. */
+ if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromISR ) != pdPASS )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+ }
+
+ configASSERT( xQueueSetTasksStatus );
+
+ /* It is expected to receive an incrementing number. */
+ ulExpectedReceivedFromISR++;
+
+ if( ulExpectedReceivedFromISR == 0 )
+ {
+ ulExpectedReceivedFromISR = queuesetINITIAL_ISR_TX_VALUE;
+ }
+ }
+ else
+ {
+ /* The value was sent from the Tx task. */
+ if( ulReceived < queuesetIGNORED_BOUNDARY )
+ {
+ /* The value received is at the lower limit of the expected range.
+ * Don't test it, and expect to receive one higher next time. */
+ }
+ else if( ( ( queuesetINITIAL_ISR_TX_VALUE - 1 ) - ulReceived ) <= queuesetIGNORED_BOUNDARY )
+ {
+ /* The value received is at the higher limit of the expected range.
+ * Don't test it and expect to wrap soon. */
+ }
+ else
+ {
+ /* Check the value against its expected value range. */
+ if( prvCheckReceivedValueWithinExpectedRange( ulReceived, ulExpectedReceivedFromTask ) != pdPASS )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+ }
+
+ configASSERT( xQueueSetTasksStatus );
+
+ /* It is expected to receive an incrementing number. */
+ ulExpectedReceivedFromTask++;
+
+ if( ulExpectedReceivedFromTask >= queuesetINITIAL_ISR_TX_VALUE )
+ {
+ ulExpectedReceivedFromTask = 0;
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived, uint32_t ulExpectedReceived )
-{
-BaseType_t xReturn = pdPASS;
-
- if( ulReceived > ulExpectedReceived )
- {
- configASSERT( ( ulReceived - ulExpectedReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
- if( ( ulReceived - ulExpectedReceived ) > queuesetALLOWABLE_RX_DEVIATION )
- {
- xReturn = pdFALSE;
- }
- }
- else
- {
- configASSERT( ( ulExpectedReceived - ulReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
- if( ( ulExpectedReceived - ulReceived ) > queuesetALLOWABLE_RX_DEVIATION )
- {
- xReturn = pdFALSE;
- }
- }
-
- return xReturn;
-}
+ static BaseType_t prvCheckReceivedValueWithinExpectedRange( uint32_t ulReceived,
+ uint32_t ulExpectedReceived )
+ {
+ BaseType_t xReturn = pdPASS;
+
+ if( ulReceived > ulExpectedReceived )
+ {
+ configASSERT( ( ulReceived - ulExpectedReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
+
+ if( ( ulReceived - ulExpectedReceived ) > queuesetALLOWABLE_RX_DEVIATION )
+ {
+ xReturn = pdFALSE;
+ }
+ }
+ else
+ {
+ configASSERT( ( ulExpectedReceived - ulReceived ) <= queuesetALLOWABLE_RX_DEVIATION );
+
+ if( ( ulExpectedReceived - ulReceived ) > queuesetALLOWABLE_RX_DEVIATION )
+ {
+ xReturn = pdFALSE;
+ }
+ }
+
+ return xReturn;
+ }
/*-----------------------------------------------------------*/
-static void prvReceiveFromQueueInSetFromISR( void )
-{
-QueueSetMemberHandle_t xActivatedQueue;
-uint32_t ulReceived;
-
- /* See if any of the queues in the set contain data. */
- xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );
-
- if( xActivatedQueue != NULL )
- {
- /* Reading from the queue for test purposes only. */
- if( xQueueReceiveFromISR( xActivatedQueue, &ulReceived, NULL ) != pdPASS )
- {
- /* Data should have been available as the handle was returned from
- xQueueSelectFromSetFromISR(). */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Ensure the value received was the value expected. */
- prvCheckReceivedValue( ulReceived );
- }
-}
+ static void prvReceiveFromQueueInSetFromISR( void )
+ {
+ QueueSetMemberHandle_t xActivatedQueue;
+ uint32_t ulReceived;
+
+ /* See if any of the queues in the set contain data. */
+ xActivatedQueue = xQueueSelectFromSetFromISR( xQueueSet );
+
+ if( xActivatedQueue != NULL )
+ {
+ /* Reading from the queue for test purposes only. */
+ if( xQueueReceiveFromISR( xActivatedQueue, &ulReceived, NULL ) != pdPASS )
+ {
+ /* Data should have been available as the handle was returned from
+ * xQueueSelectFromSetFromISR(). */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Ensure the value received was the value expected. */
+ prvCheckReceivedValue( ulReceived );
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvSendToQueueInSetFromISR( void )
-{
-static BaseType_t xQueueToWriteTo = 0;
-uint32_t ulTxValueSnapshot = ulISRTxValue;
-
- if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulTxValueSnapshot, NULL ) == pdPASS )
- {
- ulISRTxValue++;
-
- /* If the Tx value has wrapped then set it back to its initial value. */
- if( ulISRTxValue == 0UL )
- {
- ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
- }
-
- /* Use a different queue next time. */
- xQueueToWriteTo++;
- if( xQueueToWriteTo >= queuesetNUM_QUEUES_IN_SET )
- {
- xQueueToWriteTo = 0;
- }
- }
-}
+ static void prvSendToQueueInSetFromISR( void )
+ {
+ static BaseType_t xQueueToWriteTo = 0;
+ uint32_t ulTxValueSnapshot = ulISRTxValue;
+
+ if( xQueueSendFromISR( xQueues[ xQueueToWriteTo ], ( void * ) &ulTxValueSnapshot, NULL ) == pdPASS )
+ {
+ ulISRTxValue++;
+
+ /* If the Tx value has wrapped then set it back to its initial value. */
+ if( ulISRTxValue == 0UL )
+ {
+ ulISRTxValue = queuesetINITIAL_ISR_TX_VALUE;
+ }
+
+ /* Use a different queue next time. */
+ xQueueToWriteTo++;
+
+ if( xQueueToWriteTo >= queuesetNUM_QUEUES_IN_SET )
+ {
+ xQueueToWriteTo = 0;
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvTestQueueOverwriteWithQueueSet( void )
-{
-uint32_t ulValueToSend = 0, ulValueReceived = 0;
-QueueHandle_t xQueueHandle = NULL, xReceivedHandle = NULL;
-const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;
-
- /* Create a queue that has a length of one - a requirement in order to call
- xQueueOverwrite. This will get deleted again when this test completes. */
- xQueueHandle = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
- configASSERT( xQueueHandle );
-
- if( xQueueHandle != NULL )
- {
- xQueueAddToSet( xQueueHandle, xQueueSet );
-
- /* Add an item to the queue then ensure the queue set correctly
- indicates that one item is available, and that item is indeed the
- queue written to. */
- xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
- {
- /* Expected one item in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle )
- {
- /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
- held in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Now overwrite the value in the queue and ensure the queue set state
- doesn't change as the number of items in the queues within the set have
- not changed. */
- ulValueToSend++;
- xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
- {
- /* Still expected one item in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle )
- {
- /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
- held in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Also ensure the value received from the queue is the overwritten
- value, not the value originally written. */
- xQueueReceive( xQueueHandle, &ulValueReceived, queuesetDONT_BLOCK );
- if( ulValueReceived != ulValueToSend )
- {
- /* Unexpected value received from the queue. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Should be anything in the queue set now. */
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != NULL )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Clean up. */
- xQueueRemoveFromSet( xQueueHandle, xQueueSet );
- vQueueDelete( xQueueHandle );
- }
-}
+ static void prvTestQueueOverwriteWithQueueSet( void )
+ {
+ uint32_t ulValueToSend = 0, ulValueReceived = 0;
+ QueueHandle_t xQueueHandle = NULL, xReceivedHandle = NULL;
+ const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;
+
+ /* Create a queue that has a length of one - a requirement in order to call
+ * xQueueOverwrite. This will get deleted again when this test completes. */
+ xQueueHandle = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
+ configASSERT( xQueueHandle );
+
+ if( xQueueHandle != NULL )
+ {
+ xQueueAddToSet( xQueueHandle, xQueueSet );
+
+ /* Add an item to the queue then ensure the queue set correctly
+ * indicates that one item is available, and that item is indeed the
+ * queue written to. */
+ xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
+ {
+ /* Expected one item in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle )
+ {
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
+ * held in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Now overwrite the value in the queue and ensure the queue set state
+ * doesn't change as the number of items in the queues within the set have
+ * not changed. */
+ ulValueToSend++;
+ xQueueOverwrite( xQueueHandle, ( void * ) &ulValueToSend );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
+ {
+ /* Still expected one item in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle )
+ {
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
+ * held in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Also ensure the value received from the queue is the overwritten
+ * value, not the value originally written. */
+ xQueueReceive( xQueueHandle, &ulValueReceived, queuesetDONT_BLOCK );
+
+ if( ulValueReceived != ulValueToSend )
+ {
+ /* Unexpected value received from the queue. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Should be anything in the queue set now. */
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != NULL )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Clean up. */
+ xQueueRemoveFromSet( xQueueHandle, xQueueSet );
+ vQueueDelete( xQueueHandle );
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void )
-{
-uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;
-QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;
-const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;
-
- /* Create two queues that have a length of one - a requirement in order to call
- xQueueOverwrite. These will get deleted again when this test completes. */
- xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
- configASSERT( xQueueHandle1 );
- xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
- configASSERT( xQueueHandle2 );
-
- if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )
- {
- /* Add both queues to the queue set. */
- xQueueAddToSet( xQueueHandle1, xQueueSet );
- xQueueAddToSet( xQueueHandle2, xQueueSet );
-
- /* Add an item using the first queue. */
- xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend1 );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
- {
- /* Expected one item in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle1 )
- {
- /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
- held in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
- /* Next add an item to the second queue. */
- xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend2 );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* The head of the queue set should not have changed though. */
- xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle1 )
- {
- /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
- held in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
-
-
- /* Now overwrite the value in the queue and ensure the queue set state
- doesn't change as the number of items in the queues within the set have
- not changed. NOTE: after this queue 1 should hold ulValueToSend2 and queue
- 2 should hold the value ulValueToSend1. */
- xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
- /* Repeat the above to ensure the queue set state doesn't change. */
- xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
- /* Now when reading from the queue set we expect the handle to the first
- queue to be received first, and for that queue to hold ulValueToSend2 as the
- originally written value was overwritten. Likewise the second handle received
- from the set should be that of the second queue, and that queue should hold
- ulValueToSend1 as the originally written value was overwritten. */
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle1 )
- {
- /* Wrote to xQueueHandle1 first so expected that handle to be read from
- the set first. */
- xQueueSetTasksStatus = pdFAIL;
- }
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
- {
- /* One value was read from the set, so now only expect a single value
- in the set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
- if( ulValueReceived != ulValueToSend2 )
- {
- /* Unexpected value received from the queue. ulValueToSend1 was written
- first, but then overwritten with ulValueToSend2; */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle2 )
- {
- /* xQueueHandle1 has already been removed from the set so expect only
- xQueueHandle2 to be left. */
- xQueueSetTasksStatus = pdFAIL;
- }
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )
- {
- /* The last value was read from the set so don't expect any more. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
- if( ulValueReceived != ulValueToSend1 )
- {
- /* Unexpected value received from the queue. ulValueToSend2 was written
- first, but then overwritten with ulValueToSend1. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
-
-
- /* Should be anything in the queue set now. */
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != NULL )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Clean up. */
- xQueueRemoveFromSet( xQueueHandle1, xQueueSet );
- xQueueRemoveFromSet( xQueueHandle2, xQueueSet );
- vQueueDelete( xQueueHandle1 );
- vQueueDelete( xQueueHandle2 );
- }
-}
+ static void prvTestQueueOverwriteOnTwoQueusInQueueSet( void )
+ {
+ uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;
+ QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;
+ const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;
+
+ /* Create two queues that have a length of one - a requirement in order to call
+ * xQueueOverwrite. These will get deleted again when this test completes. */
+ xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
+ configASSERT( xQueueHandle1 );
+ xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
+ configASSERT( xQueueHandle2 );
+
+ if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )
+ {
+ /* Add both queues to the queue set. */
+ xQueueAddToSet( xQueueHandle1, xQueueSet );
+ xQueueAddToSet( xQueueHandle2, xQueueSet );
+
+ /* Add an item using the first queue. */
+ xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend1 );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
+ {
+ /* Expected one item in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle1 )
+ {
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
+ * held in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Next add an item to the second queue. */
+ xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend2 );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* The head of the queue set should not have changed though. */
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle1 )
+ {
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
+ * held in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Now overwrite the value in the queue and ensure the queue set state
+ * doesn't change as the number of items in the queues within the set have
+ * not changed. NOTE: after this queue 1 should hold ulValueToSend2 and queue
+ * 2 should hold the value ulValueToSend1. */
+ xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Repeat the above to ensure the queue set state doesn't change. */
+ xQueueOverwrite( xQueueHandle1, ( void * ) &ulValueToSend2 );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueOverwrite( xQueueHandle2, ( void * ) &ulValueToSend1 );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Now when reading from the queue set we expect the handle to the first
+ * queue to be received first, and for that queue to hold ulValueToSend2 as the
+ * originally written value was overwritten. Likewise the second handle received
+ * from the set should be that of the second queue, and that queue should hold
+ * ulValueToSend1 as the originally written value was overwritten. */
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle1 )
+ {
+ /* Wrote to xQueueHandle1 first so expected that handle to be read from
+ * the set first. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
+ {
+ /* One value was read from the set, so now only expect a single value
+ * in the set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
+
+ if( ulValueReceived != ulValueToSend2 )
+ {
+ /* Unexpected value received from the queue. ulValueToSend1 was written
+ * first, but then overwritten with ulValueToSend2; */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle2 )
+ {
+ /* xQueueHandle1 has already been removed from the set so expect only
+ * xQueueHandle2 to be left. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )
+ {
+ /* The last value was read from the set so don't expect any more. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
+
+ if( ulValueReceived != ulValueToSend1 )
+ {
+ /* Unexpected value received from the queue. ulValueToSend2 was written
+ * first, but then overwritten with ulValueToSend1. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Should be anything in the queue set now. */
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != NULL )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Clean up. */
+ xQueueRemoveFromSet( xQueueHandle1, xQueueSet );
+ xQueueRemoveFromSet( xQueueHandle2, xQueueSet );
+ vQueueDelete( xQueueHandle1 );
+ vQueueDelete( xQueueHandle2 );
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void )
-{
-uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;
-QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;
-const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;
-
- /* Create two queues that have a length of one - a requirement in order to call
- xQueueOverwrite. These will get deleted again when this test completes. */
- xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
- configASSERT( xQueueHandle1 );
- xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
- configASSERT( xQueueHandle2 );
-
- if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )
- {
- /* Add both queues to the queue set. */
- xQueueAddToSet( xQueueHandle1, xQueueSet );
- xQueueAddToSet( xQueueHandle2, xQueueSet );
-
- /* Add an item using the first queue using the 'FromISR' version of the
- overwrite function. */
- xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend1, NULL );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
- {
- /* Expected one item in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle1 )
- {
- /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
- held in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
- /* Next add an item to the second queue using the 'FromISR' version of the
- overwrite function. */
- xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend2, NULL );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* The head of the queue set should not have changed though. */
- xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle1 )
- {
- /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
- held in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
-
-
- /* Now overwrite the value in the queue and ensure the queue set state
- doesn't change as the number of items in the queues within the set have
- not changed. NOTE: after this queue 1 should hold ulValueToSend2 and queue
- 2 should hold the value ulValueToSend1. */
- xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
- /* Repeat the above to ensure the queue set state doesn't change. */
- xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
- {
- /* Still expected two items in the queue set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
- /* Now when reading from the queue set we expect the handle to the first
- queue to be received first, and for that queue to hold ulValueToSend2 as the
- originally written value was overwritten. Likewise the second handle received
- from the set should be that of the second queue, and that queue should hold
- ulValueToSend1 as the originally written value was overwritten. */
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle1 )
- {
- /* Wrote to xQueueHandle1 first so expected that handle to be read from
- the set first. */
- xQueueSetTasksStatus = pdFAIL;
- }
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
- {
- /* One value was read from the set, so now only expect a single value
- in the set. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
- if( ulValueReceived != ulValueToSend2 )
- {
- /* Unexpected value received from the queue. ulValueToSend1 was written
- first, but then overwritten with ulValueToSend2; */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != xQueueHandle2 )
- {
- /* xQueueHandle1 has already been removed from the set so expect only
- xQueueHandle2 to be left. */
- xQueueSetTasksStatus = pdFAIL;
- }
- if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )
- {
- /* The last value was read from the set so don't expect any more. */
- xQueueSetTasksStatus = pdFAIL;
- }
- xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
- if( ulValueReceived != ulValueToSend1 )
- {
- /* Unexpected value received from the queue. ulValueToSend2 was written
- first, but then overwritten with ulValueToSend1. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
-
-
-
- /* Should be anything in the queue set now. */
- xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
- if( xReceivedHandle != NULL )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Clean up. */
- xQueueRemoveFromSet( xQueueHandle1, xQueueSet );
- xQueueRemoveFromSet( xQueueHandle2, xQueueSet );
- vQueueDelete( xQueueHandle1 );
- vQueueDelete( xQueueHandle2 );
- }
-}
+ static void prvTestQueueOverwriteFromISROnTwoQueusInQueueSet( void )
+ {
+ uint32_t ulValueToSend1 = 1, ulValueToSend2 = 2UL, ulValueReceived = 0;
+ QueueHandle_t xQueueHandle1 = NULL, xQueueHandle2 = NULL, xReceivedHandle = NULL;
+ const UBaseType_t xLengthOfOne = ( UBaseType_t ) 1;
+
+ /* Create two queues that have a length of one - a requirement in order to call
+ * xQueueOverwrite. These will get deleted again when this test completes. */
+ xQueueHandle1 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
+ configASSERT( xQueueHandle1 );
+ xQueueHandle2 = xQueueCreate( xLengthOfOne, sizeof( uint32_t ) );
+ configASSERT( xQueueHandle2 );
+
+ if( ( xQueueHandle1 != NULL ) && ( xQueueHandle2 != NULL ) )
+ {
+ /* Add both queues to the queue set. */
+ xQueueAddToSet( xQueueHandle1, xQueueSet );
+ xQueueAddToSet( xQueueHandle2, xQueueSet );
+
+ /* Add an item using the first queue using the 'FromISR' version of the
+ * overwrite function. */
+ xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend1, NULL );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
+ {
+ /* Expected one item in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle1 )
+ {
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
+ * held in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Next add an item to the second queue using the 'FromISR' version of the
+ * overwrite function. */
+ xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend2, NULL );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* The head of the queue set should not have changed though. */
+ xQueuePeek( xQueueSet, &xReceivedHandle, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle1 )
+ {
+ /* Wrote to xQueueHandle so expected xQueueHandle to be the handle
+ * held in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Now overwrite the value in the queue and ensure the queue set state
+ * doesn't change as the number of items in the queues within the set have
+ * not changed. NOTE: after this queue 1 should hold ulValueToSend2 and queue
+ * 2 should hold the value ulValueToSend1. */
+ xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Repeat the above to ensure the queue set state doesn't change. */
+ xQueueOverwriteFromISR( xQueueHandle1, ( void * ) &ulValueToSend2, NULL );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueOverwriteFromISR( xQueueHandle2, ( void * ) &ulValueToSend1, NULL );
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 2 )
+ {
+ /* Still expected two items in the queue set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Now when reading from the queue set we expect the handle to the first
+ * queue to be received first, and for that queue to hold ulValueToSend2 as the
+ * originally written value was overwritten. Likewise the second handle received
+ * from the set should be that of the second queue, and that queue should hold
+ * ulValueToSend1 as the originally written value was overwritten. */
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle1 )
+ {
+ /* Wrote to xQueueHandle1 first so expected that handle to be read from
+ * the set first. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 1 )
+ {
+ /* One value was read from the set, so now only expect a single value
+ * in the set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
+
+ if( ulValueReceived != ulValueToSend2 )
+ {
+ /* Unexpected value received from the queue. ulValueToSend1 was written
+ * first, but then overwritten with ulValueToSend2; */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != xQueueHandle2 )
+ {
+ /* xQueueHandle1 has already been removed from the set so expect only
+ * xQueueHandle2 to be left. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ if( uxQueueMessagesWaiting( xQueueSet ) != ( UBaseType_t ) 0 )
+ {
+ /* The last value was read from the set so don't expect any more. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ xQueueReceive( xReceivedHandle, &ulValueReceived, queuesetDONT_BLOCK );
+
+ if( ulValueReceived != ulValueToSend1 )
+ {
+ /* Unexpected value received from the queue. ulValueToSend2 was written
+ * first, but then overwritten with ulValueToSend1. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Should be anything in the queue set now. */
+ xReceivedHandle = xQueueSelectFromSet( xQueueSet, queuesetDONT_BLOCK );
+
+ if( xReceivedHandle != NULL )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Clean up. */
+ xQueueRemoveFromSet( xQueueHandle1, xQueueSet );
+ xQueueRemoveFromSet( xQueueHandle2, xQueueSet );
+ vQueueDelete( xQueueHandle1 );
+ vQueueDelete( xQueueHandle2 );
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvSetupTest( void )
-{
-BaseType_t x;
-uint32_t ulValueToSend = 0;
-
- /* Ensure the queues are created and the queue set configured before the
- sending task is unsuspended.
-
- First Create the queue set such that it will be able to hold a message for
- every space in every queue in the set. */
- xQueueSet = xQueueCreateSet( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH );
-
- for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
- {
- /* Create the queue and add it to the set. The queue is just holding
- uint32_t value. */
- xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( uint32_t ) );
- configASSERT( xQueues[ x ] );
- if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
- else
- {
- /* The queue has now been added to the queue set and cannot be added to
- another. */
- if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdFAIL )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
- }
- }
-
- /* Attempt to remove a queue from a queue set it does not belong
- to (NULL being passed as the queue set in this case). */
- if( xQueueRemoveFromSet( xQueues[ 0 ], NULL ) != pdFAIL )
- {
- /* It is not possible to successfully remove a queue from a queue
- set it does not belong to. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Attempt to remove a queue from the queue set it does belong to. */
- if( xQueueRemoveFromSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
- {
- /* It should be possible to remove the queue from the queue set it
- does belong to. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Add an item to the queue before attempting to add it back into the
- set. */
- xQueueSend( xQueues[ 0 ], ( void * ) &ulValueToSend, 0 );
- if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdFAIL )
- {
- /* Should not be able to add a non-empty queue to a set. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Remove the item from the queue before adding the queue back into the
- set so the dynamic tests can begin. */
- xQueueReceive( xQueues[ 0 ], &ulValueToSend, 0 );
- if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
- {
- /* If the queue was successfully removed from the queue set then it
- should be possible to add it back in again. */
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* The task that sends to the queues is not running yet, so attempting to
- read from the queue set should fail. */
- if( xQueueSelectFromSet( xQueueSet, queuesetSHORT_DELAY ) != NULL )
- {
- xQueueSetTasksStatus = pdFAIL;
- }
-
- /* Testing the behaviour of queue sets when a queue overwrite operation is
- performed on a set member requires a special test as overwrites can only
- be performed on queues that have a length of 1. */
- prvTestQueueOverwriteWithQueueSet();
-
- /* Test the case where two queues within a set are written to with
- xQueueOverwrite(). */
- prvTestQueueOverwriteOnTwoQueusInQueueSet();
- prvTestQueueOverwriteFromISROnTwoQueusInQueueSet();
-
- /* In case any of the above have already indicated a failure. */
- configASSERT( xQueueSetTasksStatus != pdFAIL );
-
- /* Resume the task that writes to the queues. */
- vTaskResume( xQueueSetSendingTask );
-
- /* Let the ISR access the queues also. */
- xSetupComplete = pdTRUE;
-}
+ static void prvSetupTest( void )
+ {
+ BaseType_t x;
+ uint32_t ulValueToSend = 0;
+
+ /* Ensure the queues are created and the queue set configured before the
+ * sending task is unsuspended.
+ *
+ * First Create the queue set such that it will be able to hold a message for
+ * every space in every queue in the set. */
+ xQueueSet = xQueueCreateSet( queuesetNUM_QUEUES_IN_SET * queuesetQUEUE_LENGTH );
+
+ for( x = 0; x < queuesetNUM_QUEUES_IN_SET; x++ )
+ {
+ /* Create the queue and add it to the set. The queue is just holding
+ * uint32_t value. */
+ xQueues[ x ] = xQueueCreate( queuesetQUEUE_LENGTH, sizeof( uint32_t ) );
+ configASSERT( xQueues[ x ] );
+
+ if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdPASS )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+ else
+ {
+ /* The queue has now been added to the queue set and cannot be added to
+ * another. */
+ if( xQueueAddToSet( xQueues[ x ], xQueueSet ) != pdFAIL )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+ }
+ }
+
+ /* Attempt to remove a queue from a queue set it does not belong
+ * to (NULL being passed as the queue set in this case). */
+ if( xQueueRemoveFromSet( xQueues[ 0 ], NULL ) != pdFAIL )
+ {
+ /* It is not possible to successfully remove a queue from a queue
+ * set it does not belong to. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Attempt to remove a queue from the queue set it does belong to. */
+ if( xQueueRemoveFromSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
+ {
+ /* It should be possible to remove the queue from the queue set it
+ * does belong to. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Add an item to the queue before attempting to add it back into the
+ * set. */
+ xQueueSend( xQueues[ 0 ], ( void * ) &ulValueToSend, 0 );
+
+ if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdFAIL )
+ {
+ /* Should not be able to add a non-empty queue to a set. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Remove the item from the queue before adding the queue back into the
+ * set so the dynamic tests can begin. */
+ xQueueReceive( xQueues[ 0 ], &ulValueToSend, 0 );
+
+ if( xQueueAddToSet( xQueues[ 0 ], xQueueSet ) != pdPASS )
+ {
+ /* If the queue was successfully removed from the queue set then it
+ * should be possible to add it back in again. */
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* The task that sends to the queues is not running yet, so attempting to
+ * read from the queue set should fail. */
+ if( xQueueSelectFromSet( xQueueSet, queuesetSHORT_DELAY ) != NULL )
+ {
+ xQueueSetTasksStatus = pdFAIL;
+ }
+
+ /* Testing the behaviour of queue sets when a queue overwrite operation is
+ * performed on a set member requires a special test as overwrites can only
+ * be performed on queues that have a length of 1. */
+ prvTestQueueOverwriteWithQueueSet();
+
+ /* Test the case where two queues within a set are written to with
+ * xQueueOverwrite(). */
+ prvTestQueueOverwriteOnTwoQueusInQueueSet();
+ prvTestQueueOverwriteFromISROnTwoQueusInQueueSet();
+
+ /* In case any of the above have already indicated a failure. */
+ configASSERT( xQueueSetTasksStatus != pdFAIL );
+
+ /* Resume the task that writes to the queues. */
+ vTaskResume( xQueueSetSendingTask );
+
+ /* Let the ISR access the queues also. */
+ xSetupComplete = pdTRUE;
+ }
/*-----------------------------------------------------------*/
-static size_t prvRand( void )
-{
- uxNextRand = ( uxNextRand * ( size_t ) 1103515245 ) + ( size_t ) 12345;
- return ( uxNextRand / ( size_t ) 65536 ) % ( size_t ) 32768;
-}
+ static size_t prvRand( void )
+ {
+ uxNextRand = ( uxNextRand * ( size_t ) 1103515245 ) + ( size_t ) 12345;
+ return ( uxNextRand / ( size_t ) 65536 ) % ( size_t ) 32768;
+ }
/*-----------------------------------------------------------*/
-static void prvSRand( size_t uxSeed )
-{
- uxNextRand = uxSeed;
-}
+ static void prvSRand( size_t uxSeed )
+ {
+ uxNextRand = uxSeed;
+ }
#endif /* ( configUSE_QUEUE_SETS == 1 ) */
diff --git a/FreeRTOS/Demo/Common/Minimal/QueueSetPolling.c b/FreeRTOS/Demo/Common/Minimal/QueueSetPolling.c
index 88399eb57..80e9e1957 100644
--- a/FreeRTOS/Demo/Common/Minimal/QueueSetPolling.c
+++ b/FreeRTOS/Demo/Common/Minimal/QueueSetPolling.c
@@ -51,131 +51,132 @@
/* Demo includes. */
#include "QueueSetPolling.h"
-#if( configUSE_QUEUE_SETS == 1 ) /* Remove tests if queue sets are not defined. */
+#if ( configUSE_QUEUE_SETS == 1 ) /* Remove tests if queue sets are not defined. */
/* The length of each created queue. */
-#define setpollQUEUE_LENGTH 10
+ #define setpollQUEUE_LENGTH 10
/* Block times used in this demo. A block time or 0 means "don't block". */
-#define setpollDONT_BLOCK 0
+ #define setpollDONT_BLOCK 0
/* The ISR sends to the queue every setpollISR_TX_PERIOD ticks. */
-#define queuesetISR_TX_PERIOD ( 50UL )
+ #define queuesetISR_TX_PERIOD ( 50UL )
/*
* The task that reads from the queue set.
*/
-static void prvQueueSetReceivingTask( void *pvParameters );
+ static void prvQueueSetReceivingTask( void * pvParameters );
/*-----------------------------------------------------------*/
/* The queue that is added to the set. */
-static QueueHandle_t xQueue = NULL;
+ static QueueHandle_t xQueue = NULL;
/* The handle of the queue set to which the queue is added. */
-static QueueSetHandle_t xQueueSet = NULL;
+ static QueueSetHandle_t xQueueSet = NULL;
/* Set to pdFAIL if an error is detected by any queue set task.
-ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
-static volatile BaseType_t xQueueSetPollStatus = pdPASS;
+ * ulCycleCounter will only be incremented if xQueueSetTasksSatus equals pdPASS. */
+ static volatile BaseType_t xQueueSetPollStatus = pdPASS;
/* Counter used to ensure the task is still running. */
-static uint32_t ulCycleCounter = 0;
+ static uint32_t ulCycleCounter = 0;
/*-----------------------------------------------------------*/
-void vStartQueueSetPollingTask( void )
-{
- /* Create the queue that is added to the set, the set, and add the queue to
- the set. */
- xQueue = xQueueCreate( setpollQUEUE_LENGTH, sizeof( uint32_t ) );
- xQueueSet = xQueueCreateSet( setpollQUEUE_LENGTH );
-
- if( ( xQueue != NULL ) && ( xQueueSet != NULL ) )
- {
- xQueueAddToSet( xQueue, xQueueSet );
-
- /* Create the task. */
- xTaskCreate( prvQueueSetReceivingTask, "SetPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- }
-}
+ void vStartQueueSetPollingTask( void )
+ {
+ /* Create the queue that is added to the set, the set, and add the queue to
+ * the set. */
+ xQueue = xQueueCreate( setpollQUEUE_LENGTH, sizeof( uint32_t ) );
+ xQueueSet = xQueueCreateSet( setpollQUEUE_LENGTH );
+
+ if( ( xQueue != NULL ) && ( xQueueSet != NULL ) )
+ {
+ xQueueAddToSet( xQueue, xQueueSet );
+
+ /* Create the task. */
+ xTaskCreate( prvQueueSetReceivingTask, "SetPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvQueueSetReceivingTask( void *pvParameters )
-{
-uint32_t ulReceived, ulExpected = 0;
-QueueHandle_t xActivatedQueue;
-
- /* Remove compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Is a message waiting? A block time is not used to ensure the queue
- set is polled while it is being written to from an interrupt. */
- xActivatedQueue = xQueueSelectFromSet( xQueueSet, setpollDONT_BLOCK );
-
- if( xActivatedQueue != NULL )
- {
- /* Reading from the queue should pass with a zero block time as
- this task will only run when something has been posted to a task
- in the queue set. */
- if( xQueueReceive( xActivatedQueue, &ulReceived, setpollDONT_BLOCK ) != pdPASS )
- {
- xQueueSetPollStatus = pdFAIL;
- }
-
- if( ulReceived == ulExpected )
- {
- ulExpected++;
- }
- else
- {
- xQueueSetPollStatus = pdFAIL;
- }
-
- if( xQueueSetPollStatus == pdPASS )
- {
- ulCycleCounter++;
- }
- }
- }
-}
+ static void prvQueueSetReceivingTask( void * pvParameters )
+ {
+ uint32_t ulReceived, ulExpected = 0;
+ QueueHandle_t xActivatedQueue;
+
+ /* Remove compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Is a message waiting? A block time is not used to ensure the queue
+ * set is polled while it is being written to from an interrupt. */
+ xActivatedQueue = xQueueSelectFromSet( xQueueSet, setpollDONT_BLOCK );
+
+ if( xActivatedQueue != NULL )
+ {
+ /* Reading from the queue should pass with a zero block time as
+ * this task will only run when something has been posted to a task
+ * in the queue set. */
+ if( xQueueReceive( xActivatedQueue, &ulReceived, setpollDONT_BLOCK ) != pdPASS )
+ {
+ xQueueSetPollStatus = pdFAIL;
+ }
+
+ if( ulReceived == ulExpected )
+ {
+ ulExpected++;
+ }
+ else
+ {
+ xQueueSetPollStatus = pdFAIL;
+ }
+
+ if( xQueueSetPollStatus == pdPASS )
+ {
+ ulCycleCounter++;
+ }
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-void vQueueSetPollingInterruptAccess( void )
-{
-static uint32_t ulCallCount = 0, ulValueToSend = 0;
-
- /* It is intended that this function is called from the tick hook
- function, so each call is one tick period apart. */
- ulCallCount++;
- if( ulCallCount > queuesetISR_TX_PERIOD )
- {
- ulCallCount = 0;
-
- if( xQueueSendFromISR( xQueue, ( void * ) &ulValueToSend, NULL ) == pdPASS )
- {
- /* Send the next value next time. */
- ulValueToSend++;
- }
- }
-}
+ void vQueueSetPollingInterruptAccess( void )
+ {
+ static uint32_t ulCallCount = 0, ulValueToSend = 0;
+
+ /* It is intended that this function is called from the tick hook
+ * function, so each call is one tick period apart. */
+ ulCallCount++;
+
+ if( ulCallCount > queuesetISR_TX_PERIOD )
+ {
+ ulCallCount = 0;
+
+ if( xQueueSendFromISR( xQueue, ( void * ) &ulValueToSend, NULL ) == pdPASS )
+ {
+ /* Send the next value next time. */
+ ulValueToSend++;
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-BaseType_t xAreQueueSetPollTasksStillRunning( void )
-{
-static uint32_t ulLastCycleCounter = 0;
+ BaseType_t xAreQueueSetPollTasksStillRunning( void )
+ {
+ static uint32_t ulLastCycleCounter = 0;
- if( ulLastCycleCounter == ulCycleCounter )
- {
- xQueueSetPollStatus = pdFAIL;
- }
+ if( ulLastCycleCounter == ulCycleCounter )
+ {
+ xQueueSetPollStatus = pdFAIL;
+ }
- ulLastCycleCounter = ulCycleCounter;
+ ulLastCycleCounter = ulCycleCounter;
- return xQueueSetPollStatus;
-}
+ return xQueueSetPollStatus;
+ }
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Common/Minimal/StaticAllocation.c b/FreeRTOS/Demo/Common/Minimal/StaticAllocation.c
index 736fab0ad..80b67419f 100644
--- a/FreeRTOS/Demo/Common/Minimal/StaticAllocation.c
+++ b/FreeRTOS/Demo/Common/Minimal/StaticAllocation.c
@@ -47,26 +47,26 @@
#include "StaticAllocation.h"
/* Exclude the entire file if configSUPPORT_STATIC_ALLOCATION is 0. */
-#if( configSUPPORT_STATIC_ALLOCATION == 1 )
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
/* The priority at which the task that performs the tests is created. */
-#define staticTASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
+ #define staticTASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
/* The length of the queue, in items, not bytes, used in the queue static
-allocation tests. */
-#define staticQUEUE_LENGTH_IN_ITEMS ( 5 )
+ * allocation tests. */
+ #define staticQUEUE_LENGTH_IN_ITEMS ( 5 )
/* A block time of 0 simply means "don't block". */
-#define staticDONT_BLOCK ( ( TickType_t ) 0 )
+ #define staticDONT_BLOCK ( ( TickType_t ) 0 )
/* Binary semaphores have a maximum count of 1. */
-#define staticBINARY_SEMAPHORE_MAX_COUNT ( 1 )
+ #define staticBINARY_SEMAPHORE_MAX_COUNT ( 1 )
/* The size of the stack used by the task that runs the tests. */
-#define staticCREATOR_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
+ #define staticCREATOR_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
/* The number of times the software timer will execute before stopping itself. */
-#define staticMAX_TIMER_CALLBACK_EXECUTIONS ( 5 )
+ #define staticMAX_TIMER_CALLBACK_EXECUTIONS ( 5 )
/*-----------------------------------------------------------*/
@@ -75,73 +75,73 @@ allocation tests. */
* The task that repeatedly creates and deletes statically allocated tasks, and
* other RTOS objects.
*/
-static void prvStaticallyAllocatedCreator( void *pvParameters );
+ static void prvStaticallyAllocatedCreator( void * pvParameters );
/*
* The callback function used by the software timer that is repeatedly created
* and deleted using both static and dynamically allocated memory.
*/
-static void prvTimerCallback( TimerHandle_t xExpiredTimer );
+ static void prvTimerCallback( TimerHandle_t xExpiredTimer );
/*
* A task that is created and deleted multiple times, using both statically and
* dynamically allocated stack and TCB.
*/
-static void prvStaticallyAllocatedTask( void *pvParameters );
+ static void prvStaticallyAllocatedTask( void * pvParameters );
/*
* A function that demonstrates and tests the API functions that create and
* delete tasks using both statically and dynamically allocated TCBs and stacks.
*/
-static void prvCreateAndDeleteStaticallyAllocatedTasks( void );
+ static void prvCreateAndDeleteStaticallyAllocatedTasks( void );
/*
* A function that demonstrates and tests the API functions that create and
* delete event groups using both statically and dynamically allocated RAM.
*/
-static void prvCreateAndDeleteStaticallyAllocatedEventGroups( void );
+ static void prvCreateAndDeleteStaticallyAllocatedEventGroups( void );
/*
* A function that demonstrates and tests the API functions that create and
* delete queues using both statically and dynamically allocated RAM.
*/
-static void prvCreateAndDeleteStaticallyAllocatedQueues( void );
+ static void prvCreateAndDeleteStaticallyAllocatedQueues( void );
/*
* A function that demonstrates and tests the API functions that create and
* delete binary semaphores using both statically and dynamically allocated RAM.
*/
-static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void );
+ static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void );
/*
* A function that demonstrates and tests the API functions that create and
* delete software timers using both statically and dynamically allocated RAM.
*/
-static void prvCreateAndDeleteStaticallyAllocatedTimers( void );
+ static void prvCreateAndDeleteStaticallyAllocatedTimers( void );
/*
* A function that demonstrates and tests the API functions that create and
* delete mutexes using both statically and dynamically allocated RAM.
*/
-static void prvCreateAndDeleteStaticallyAllocatedMutexes( void );
+ static void prvCreateAndDeleteStaticallyAllocatedMutexes( void );
/*
* A function that demonstrates and tests the API functions that create and
* delete counting semaphores using both statically and dynamically allocated
* RAM.
*/
-static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void );
+ static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void );
/*
* A function that demonstrates and tests the API functions that create and
* delete recursive mutexes using both statically and dynamically allocated RAM.
*/
-static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void );
+ static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void );
/*
* Utility function to create pseudo random numbers.
*/
-static UBaseType_t prvRand( void );
+ static UBaseType_t prvRand( void );
/*
* The task that creates and deletes other tasks has to delay occasionally to
@@ -149,958 +149,965 @@ static UBaseType_t prvRand( void );
* random delay time is used just to add a little bit of randomisation into the
* execution pattern. prvGetNextDelayTime() generates the pseudo random delay.
*/
-static TickType_t prvGetNextDelayTime( void );
+ static TickType_t prvGetNextDelayTime( void );
/*
* Checks the basic operation of a queue after it has been created.
*/
-static void prvSanityCheckCreatedQueue( QueueHandle_t xQueue );
+ static void prvSanityCheckCreatedQueue( QueueHandle_t xQueue );
/*
* Checks the basic operation of a recursive mutex after it has been created.
*/
-static void prvSanityCheckCreatedRecursiveMutex( SemaphoreHandle_t xSemaphore );
+ static void prvSanityCheckCreatedRecursiveMutex( SemaphoreHandle_t xSemaphore );
/*
* Checks the basic operation of a binary semaphore after it has been created.
*/
-static void prvSanityCheckCreatedSemaphore( SemaphoreHandle_t xSemaphore, UBaseType_t uxMaxCount );
+ static void prvSanityCheckCreatedSemaphore( SemaphoreHandle_t xSemaphore,
+ UBaseType_t uxMaxCount );
/*
* Checks the basic operation of an event group after it has been created.
*/
-static void prvSanityCheckCreatedEventGroup( EventGroupHandle_t xEventGroup );
+ static void prvSanityCheckCreatedEventGroup( EventGroupHandle_t xEventGroup );
/*-----------------------------------------------------------*/
/* StaticTask_t is a publicly accessible structure that has the same size and
-alignment requirements as the real TCB structure. It is provided as a mechanism
-for applications to know the size of the TCB (which is dependent on the
-architecture and configuration file settings) without breaking the strict data
-hiding policy by exposing the real TCB. This StaticTask_t variable is passed
-into the xTaskCreateStatic() function that creates the
-prvStaticallyAllocatedCreator() task, and will hold the TCB of the created
-tasks. */
-static StaticTask_t xCreatorTaskTCBBuffer;
+ * alignment requirements as the real TCB structure. It is provided as a mechanism
+ * for applications to know the size of the TCB (which is dependent on the
+ * architecture and configuration file settings) without breaking the strict data
+ * hiding policy by exposing the real TCB. This StaticTask_t variable is passed
+ * into the xTaskCreateStatic() function that creates the
+ * prvStaticallyAllocatedCreator() task, and will hold the TCB of the created
+ * tasks. */
+ static StaticTask_t xCreatorTaskTCBBuffer;
/* This is the stack that will be used by the prvStaticallyAllocatedCreator()
-task, which is itself created using statically allocated buffers (so without any
-dynamic memory allocation). */
-static StackType_t uxCreatorTaskStackBuffer[ staticCREATOR_TASK_STACK_SIZE ];
+ * task, which is itself created using statically allocated buffers (so without any
+ * dynamic memory allocation). */
+ static StackType_t uxCreatorTaskStackBuffer[ staticCREATOR_TASK_STACK_SIZE ];
/* Used by the pseudo random number generating function. */
-static uint32_t ulNextRand = 0;
+ static uint32_t ulNextRand = 0;
/* Used so a check task can ensure this test is still executing, and not
-stalled. */
-static volatile UBaseType_t uxCycleCounter = 0;
+ * stalled. */
+ static volatile UBaseType_t uxCycleCounter = 0;
/* A variable that gets set to pdTRUE if an error is detected. */
-static volatile BaseType_t xErrorOccurred = pdFALSE;
+ static volatile BaseType_t xErrorOccurred = pdFALSE;
/*-----------------------------------------------------------*/
-void vStartStaticallyAllocatedTasks( void )
-{
- /* Create a single task, which then repeatedly creates and deletes the other
- RTOS objects using both statically and dynamically allocated RAM. */
- xTaskCreateStatic( prvStaticallyAllocatedCreator, /* The function that implements the task being created. */
- "StatCreate", /* Text name for the task - not used by the RTOS, its just to assist debugging. */
- staticCREATOR_TASK_STACK_SIZE, /* Size of the buffer passed in as the stack - in words, not bytes! */
- NULL, /* Parameter passed into the task - not used in this case. */
- staticTASK_PRIORITY, /* Priority of the task. */
- &( uxCreatorTaskStackBuffer[ 0 ] ), /* The buffer to use as the task's stack. */
- &xCreatorTaskTCBBuffer ); /* The variable that will hold the task's TCB. */
-}
+ void vStartStaticallyAllocatedTasks( void )
+ {
+ /* Create a single task, which then repeatedly creates and deletes the other
+ * RTOS objects using both statically and dynamically allocated RAM. */
+ xTaskCreateStatic( prvStaticallyAllocatedCreator, /* The function that implements the task being created. */
+ "StatCreate", /* Text name for the task - not used by the RTOS, its just to assist debugging. */
+ staticCREATOR_TASK_STACK_SIZE, /* Size of the buffer passed in as the stack - in words, not bytes! */
+ NULL, /* Parameter passed into the task - not used in this case. */
+ staticTASK_PRIORITY, /* Priority of the task. */
+ &( uxCreatorTaskStackBuffer[ 0 ] ), /* The buffer to use as the task's stack. */
+ &xCreatorTaskTCBBuffer ); /* The variable that will hold the task's TCB. */
+ }
/*-----------------------------------------------------------*/
-static void prvStaticallyAllocatedCreator( void *pvParameters )
-{
- /* Avoid compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Loop, running functions that create and delete the various RTOS
- objects that can be optionally created using either static or dynamic
- memory allocation. */
- prvCreateAndDeleteStaticallyAllocatedTasks();
- prvCreateAndDeleteStaticallyAllocatedQueues();
-
- /* Delay to ensure lower priority tasks get CPU time, and increment the
- cycle counter so a 'check' task can determine that this task is still
- executing. */
- vTaskDelay( prvGetNextDelayTime() );
- uxCycleCounter++;
-
- prvCreateAndDeleteStaticallyAllocatedBinarySemaphores();
- prvCreateAndDeleteStaticallyAllocatedCountingSemaphores();
-
- vTaskDelay( prvGetNextDelayTime() );
- uxCycleCounter++;
-
- prvCreateAndDeleteStaticallyAllocatedMutexes();
- prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes();
-
- vTaskDelay( prvGetNextDelayTime() );
- uxCycleCounter++;
-
- prvCreateAndDeleteStaticallyAllocatedEventGroups();
- prvCreateAndDeleteStaticallyAllocatedTimers();
- }
-}
+ static void prvStaticallyAllocatedCreator( void * pvParameters )
+ {
+ /* Avoid compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Loop, running functions that create and delete the various RTOS
+ * objects that can be optionally created using either static or dynamic
+ * memory allocation. */
+ prvCreateAndDeleteStaticallyAllocatedTasks();
+ prvCreateAndDeleteStaticallyAllocatedQueues();
+
+ /* Delay to ensure lower priority tasks get CPU time, and increment the
+ * cycle counter so a 'check' task can determine that this task is still
+ * executing. */
+ vTaskDelay( prvGetNextDelayTime() );
+ uxCycleCounter++;
+
+ prvCreateAndDeleteStaticallyAllocatedBinarySemaphores();
+ prvCreateAndDeleteStaticallyAllocatedCountingSemaphores();
+
+ vTaskDelay( prvGetNextDelayTime() );
+ uxCycleCounter++;
+
+ prvCreateAndDeleteStaticallyAllocatedMutexes();
+ prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes();
+
+ vTaskDelay( prvGetNextDelayTime() );
+ uxCycleCounter++;
+
+ prvCreateAndDeleteStaticallyAllocatedEventGroups();
+ prvCreateAndDeleteStaticallyAllocatedTimers();
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void )
-{
-SemaphoreHandle_t xSemaphore;
-const UBaseType_t uxMaxCount = ( UBaseType_t ) 10;
+ static void prvCreateAndDeleteStaticallyAllocatedCountingSemaphores( void )
+ {
+ SemaphoreHandle_t xSemaphore;
+ const UBaseType_t uxMaxCount = ( UBaseType_t ) 10;
/* StaticSemaphore_t is a publicly accessible structure that has the same size
-and alignment requirements as the real semaphore structure. It is provided as a
-mechanism for applications to know the size of the semaphore (which is dependent
-on the architecture and configuration file settings) without breaking the strict
-data hiding policy by exposing the real semaphore internals. This
-StaticSemaphore_t variable is passed into the xSemaphoreCreateCountingStatic()
-function calls within this function. NOTE: In most usage scenarios now it is
-faster and more memory efficient to use a direct to task notification instead of
-a counting semaphore. http://www.freertos.org/RTOS-task-notifications.html */
-StaticSemaphore_t xSemaphoreBuffer;
-
- /* Create the semaphore. xSemaphoreCreateCountingStatic() has one more
- parameter than the usual xSemaphoreCreateCounting() function. The parameter
- is a pointer to the pre-allocated StaticSemaphore_t structure, which will
- hold information on the semaphore in an anonymous way. If the pointer is
- passed as NULL then the structure will be allocated dynamically, just as
- when xSemaphoreCreateCounting() is called. */
- xSemaphore = xSemaphoreCreateCountingStatic( uxMaxCount, 0, &xSemaphoreBuffer );
-
- /* The semaphore handle should equal the static semaphore structure passed
- into the xSemaphoreCreateBinaryStatic() function. */
- configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
-
- /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
- prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );
-
- /* Delete the semaphore again so the buffers can be reused. */
- vSemaphoreDelete( xSemaphore );
-
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- /* Now do the same but using dynamically allocated buffers to ensure the
- delete functions are working correctly in both the static and dynamic
- allocation cases. */
- xSemaphore = xSemaphoreCreateCounting( uxMaxCount, 0 );
- configASSERT( xSemaphore != NULL );
- prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );
- vSemaphoreDelete( xSemaphore );
- }
- #endif
-}
+ * and alignment requirements as the real semaphore structure. It is provided as a
+ * mechanism for applications to know the size of the semaphore (which is dependent
+ * on the architecture and configuration file settings) without breaking the strict
+ * data hiding policy by exposing the real semaphore internals. This
+ * StaticSemaphore_t variable is passed into the xSemaphoreCreateCountingStatic()
+ * function calls within this function. NOTE: In most usage scenarios now it is
+ * faster and more memory efficient to use a direct to task notification instead of
+ * a counting semaphore. http://www.freertos.org/RTOS-task-notifications.html */
+ StaticSemaphore_t xSemaphoreBuffer;
+
+ /* Create the semaphore. xSemaphoreCreateCountingStatic() has one more
+ * parameter than the usual xSemaphoreCreateCounting() function. The parameter
+ * is a pointer to the pre-allocated StaticSemaphore_t structure, which will
+ * hold information on the semaphore in an anonymous way. If the pointer is
+ * passed as NULL then the structure will be allocated dynamically, just as
+ * when xSemaphoreCreateCounting() is called. */
+ xSemaphore = xSemaphoreCreateCountingStatic( uxMaxCount, 0, &xSemaphoreBuffer );
+
+ /* The semaphore handle should equal the static semaphore structure passed
+ * into the xSemaphoreCreateBinaryStatic() function. */
+ configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
+
+ /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
+ prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );
+
+ /* Delete the semaphore again so the buffers can be reused. */
+ vSemaphoreDelete( xSemaphore );
+
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ /* Now do the same but using dynamically allocated buffers to ensure the
+ * delete functions are working correctly in both the static and dynamic
+ * allocation cases. */
+ xSemaphore = xSemaphoreCreateCounting( uxMaxCount, 0 );
+ configASSERT( xSemaphore != NULL );
+ prvSanityCheckCreatedSemaphore( xSemaphore, uxMaxCount );
+ vSemaphoreDelete( xSemaphore );
+ }
+ #endif
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void )
-{
-SemaphoreHandle_t xSemaphore;
+ static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void )
+ {
+ SemaphoreHandle_t xSemaphore;
/* StaticSemaphore_t is a publicly accessible structure that has the same size
-and alignment requirements as the real semaphore structure. It is provided as a
-mechanism for applications to know the size of the semaphore (which is dependent
-on the architecture and configuration file settings) without breaking the strict
-data hiding policy by exposing the real semaphore internals. This
-StaticSemaphore_t variable is passed into the
-xSemaphoreCreateRecursiveMutexStatic() function calls within this function. */
-StaticSemaphore_t xSemaphoreBuffer;
-
- /* Create the semaphore. xSemaphoreCreateRecursiveMutexStatic() has one
- more parameter than the usual xSemaphoreCreateRecursiveMutex() function.
- The parameter is a pointer to the pre-allocated StaticSemaphore_t structure,
- which will hold information on the semaphore in an anonymous way. If the
- pointer is passed as NULL then the structure will be allocated dynamically,
- just as when xSemaphoreCreateRecursiveMutex() is called. */
- xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xSemaphoreBuffer );
-
- /* The semaphore handle should equal the static semaphore structure passed
- into the xSemaphoreCreateBinaryStatic() function. */
- configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
-
- /* Ensure the semaphore passes a few sanity checks as a valid
- recursive semaphore. */
- prvSanityCheckCreatedRecursiveMutex( xSemaphore );
-
- /* Delete the semaphore again so the buffers can be reused. */
- vSemaphoreDelete( xSemaphore );
-
- /* Now do the same using dynamically allocated buffers to ensure the delete
- functions are working correctly in both the static and dynamic memory
- allocation cases. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- xSemaphore = xSemaphoreCreateRecursiveMutex();
- configASSERT( xSemaphore != NULL );
- prvSanityCheckCreatedRecursiveMutex( xSemaphore );
- vSemaphoreDelete( xSemaphore );
- }
- #endif
-}
+ * and alignment requirements as the real semaphore structure. It is provided as a
+ * mechanism for applications to know the size of the semaphore (which is dependent
+ * on the architecture and configuration file settings) without breaking the strict
+ * data hiding policy by exposing the real semaphore internals. This
+ * StaticSemaphore_t variable is passed into the
+ * xSemaphoreCreateRecursiveMutexStatic() function calls within this function. */
+ StaticSemaphore_t xSemaphoreBuffer;
+
+ /* Create the semaphore. xSemaphoreCreateRecursiveMutexStatic() has one
+ * more parameter than the usual xSemaphoreCreateRecursiveMutex() function.
+ * The parameter is a pointer to the pre-allocated StaticSemaphore_t structure,
+ * which will hold information on the semaphore in an anonymous way. If the
+ * pointer is passed as NULL then the structure will be allocated dynamically,
+ * just as when xSemaphoreCreateRecursiveMutex() is called. */
+ xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xSemaphoreBuffer );
+
+ /* The semaphore handle should equal the static semaphore structure passed
+ * into the xSemaphoreCreateBinaryStatic() function. */
+ configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
+
+ /* Ensure the semaphore passes a few sanity checks as a valid
+ * recursive semaphore. */
+ prvSanityCheckCreatedRecursiveMutex( xSemaphore );
+
+ /* Delete the semaphore again so the buffers can be reused. */
+ vSemaphoreDelete( xSemaphore );
+
+ /* Now do the same using dynamically allocated buffers to ensure the delete
+ * functions are working correctly in both the static and dynamic memory
+ * allocation cases. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ xSemaphore = xSemaphoreCreateRecursiveMutex();
+ configASSERT( xSemaphore != NULL );
+ prvSanityCheckCreatedRecursiveMutex( xSemaphore );
+ vSemaphoreDelete( xSemaphore );
+ }
+ #endif
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedQueues( void )
-{
-QueueHandle_t xQueue;
+ static void prvCreateAndDeleteStaticallyAllocatedQueues( void )
+ {
+ QueueHandle_t xQueue;
/* StaticQueue_t is a publicly accessible structure that has the same size and
-alignment requirements as the real queue structure. It is provided as a
-mechanism for applications to know the size of the queue (which is dependent on
-the architecture and configuration file settings) without breaking the strict
-data hiding policy by exposing the real queue internals. This StaticQueue_t
-variable is passed into the xQueueCreateStatic() function calls within this
-function. */
-static StaticQueue_t xStaticQueue;
+ * alignment requirements as the real queue structure. It is provided as a
+ * mechanism for applications to know the size of the queue (which is dependent on
+ * the architecture and configuration file settings) without breaking the strict
+ * data hiding policy by exposing the real queue internals. This StaticQueue_t
+ * variable is passed into the xQueueCreateStatic() function calls within this
+ * function. */
+ static StaticQueue_t xStaticQueue;
/* The queue storage area must be large enough to hold the maximum number of
-items it is possible for the queue to hold at any one time, which equals the
-queue length (in items, not bytes) multiplied by the size of each item. In this
-case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items. See
-http://www.freertos.org/Embedded-RTOS-Queues.html */
-static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ];
-
- /* Create the queue. xQueueCreateStatic() has two more parameters than the
- usual xQueueCreate() function. The first new parameter is a pointer to the
- pre-allocated queue storage area. The second new parameter is a pointer to
- the StaticQueue_t structure that will hold the queue state information in
- an anonymous way. If the two pointers are passed as NULL then the data
- will be allocated dynamically as if xQueueCreate() had been called. */
- xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
- sizeof( uint64_t ), /* The size of each item. */
- ucQueueStorageArea, /* The buffer used to hold items within the queue. */
- &xStaticQueue ); /* The static queue structure that will hold the state of the queue. */
-
- /* The queue handle should equal the static queue structure passed into the
- xQueueCreateStatic() function. */
- configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );
-
- /* Ensure the queue passes a few sanity checks as a valid queue. */
- prvSanityCheckCreatedQueue( xQueue );
-
- /* Delete the queue again so the buffers can be reused. */
- vQueueDelete( xQueue );
-
- /* Now do the same using a dynamically allocated queue to ensure the delete
- function is working correctly in both the static and dynamic memory
- allocation cases. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- xQueue = xQueueCreate( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
- sizeof( uint64_t ) ); /* The size of each item. */
-
- /* The queue handle should equal the static queue structure passed into the
- xQueueCreateStatic() function. */
- configASSERT( xQueue != NULL );
-
- /* Ensure the queue passes a few sanity checks as a valid queue. */
- prvSanityCheckCreatedQueue( xQueue );
-
- /* Delete the queue again so the buffers can be reused. */
- vQueueDelete( xQueue );
- }
- #endif
-}
+ * items it is possible for the queue to hold at any one time, which equals the
+ * queue length (in items, not bytes) multiplied by the size of each item. In this
+ * case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items. See
+ * http://www.freertos.org/Embedded-RTOS-Queues.html */
+ static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ];
+
+ /* Create the queue. xQueueCreateStatic() has two more parameters than the
+ * usual xQueueCreate() function. The first new parameter is a pointer to the
+ * pre-allocated queue storage area. The second new parameter is a pointer to
+ * the StaticQueue_t structure that will hold the queue state information in
+ * an anonymous way. If the two pointers are passed as NULL then the data
+ * will be allocated dynamically as if xQueueCreate() had been called. */
+ xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
+ sizeof( uint64_t ), /* The size of each item. */
+ ucQueueStorageArea, /* The buffer used to hold items within the queue. */
+ &xStaticQueue ); /* The static queue structure that will hold the state of the queue. */
+
+ /* The queue handle should equal the static queue structure passed into the
+ * xQueueCreateStatic() function. */
+ configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );
+
+ /* Ensure the queue passes a few sanity checks as a valid queue. */
+ prvSanityCheckCreatedQueue( xQueue );
+
+ /* Delete the queue again so the buffers can be reused. */
+ vQueueDelete( xQueue );
+
+ /* Now do the same using a dynamically allocated queue to ensure the delete
+ * function is working correctly in both the static and dynamic memory
+ * allocation cases. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ xQueue = xQueueCreate( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */
+ sizeof( uint64_t ) ); /* The size of each item. */
+
+ /* The queue handle should equal the static queue structure passed into the
+ * xQueueCreateStatic() function. */
+ configASSERT( xQueue != NULL );
+
+ /* Ensure the queue passes a few sanity checks as a valid queue. */
+ prvSanityCheckCreatedQueue( xQueue );
+
+ /* Delete the queue again so the buffers can be reused. */
+ vQueueDelete( xQueue );
+ }
+ #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedMutexes( void )
-{
-SemaphoreHandle_t xSemaphore;
-BaseType_t xReturned;
+ static void prvCreateAndDeleteStaticallyAllocatedMutexes( void )
+ {
+ SemaphoreHandle_t xSemaphore;
+ BaseType_t xReturned;
/* StaticSemaphore_t is a publicly accessible structure that has the same size
-and alignment requirements as the real semaphore structure. It is provided as a
-mechanism for applications to know the size of the semaphore (which is dependent
-on the architecture and configuration file settings) without breaking the strict
-data hiding policy by exposing the real semaphore internals. This
-StaticSemaphore_t variable is passed into the xSemaphoreCreateMutexStatic()
-function calls within this function. */
-StaticSemaphore_t xSemaphoreBuffer;
-
- /* Create the semaphore. xSemaphoreCreateMutexStatic() has one more
- parameter than the usual xSemaphoreCreateMutex() function. The parameter
- is a pointer to the pre-allocated StaticSemaphore_t structure, which will
- hold information on the semaphore in an anonymous way. If the pointer is
- passed as NULL then the structure will be allocated dynamically, just as
- when xSemaphoreCreateMutex() is called. */
- xSemaphore = xSemaphoreCreateMutexStatic( &xSemaphoreBuffer );
-
- /* The semaphore handle should equal the static semaphore structure passed
- into the xSemaphoreCreateMutexStatic() function. */
- configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
-
- /* Take the mutex so the mutex is in the state expected by the
- prvSanityCheckCreatedSemaphore() function. */
- xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
- prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
-
- /* Delete the semaphore again so the buffers can be reused. */
- vSemaphoreDelete( xSemaphore );
-
- /* Now do the same using a dynamically allocated mutex to ensure the delete
- function is working correctly in both the static and dynamic allocation
- cases. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- xSemaphore = xSemaphoreCreateMutex();
-
- /* The semaphore handle should equal the static semaphore structure
- passed into the xSemaphoreCreateMutexStatic() function. */
- configASSERT( xSemaphore != NULL );
-
- /* Take the mutex so the mutex is in the state expected by the
- prvSanityCheckCreatedSemaphore() function. */
- xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
- prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
-
- /* Delete the semaphore again so the buffers can be reused. */
- vSemaphoreDelete( xSemaphore );
- }
- #endif
-}
+ * and alignment requirements as the real semaphore structure. It is provided as a
+ * mechanism for applications to know the size of the semaphore (which is dependent
+ * on the architecture and configuration file settings) without breaking the strict
+ * data hiding policy by exposing the real semaphore internals. This
+ * StaticSemaphore_t variable is passed into the xSemaphoreCreateMutexStatic()
+ * function calls within this function. */
+ StaticSemaphore_t xSemaphoreBuffer;
+
+ /* Create the semaphore. xSemaphoreCreateMutexStatic() has one more
+ * parameter than the usual xSemaphoreCreateMutex() function. The parameter
+ * is a pointer to the pre-allocated StaticSemaphore_t structure, which will
+ * hold information on the semaphore in an anonymous way. If the pointer is
+ * passed as NULL then the structure will be allocated dynamically, just as
+ * when xSemaphoreCreateMutex() is called. */
+ xSemaphore = xSemaphoreCreateMutexStatic( &xSemaphoreBuffer );
+
+ /* The semaphore handle should equal the static semaphore structure passed
+ * into the xSemaphoreCreateMutexStatic() function. */
+ configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
+
+ /* Take the mutex so the mutex is in the state expected by the
+ * prvSanityCheckCreatedSemaphore() function. */
+ xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
+ prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
+
+ /* Delete the semaphore again so the buffers can be reused. */
+ vSemaphoreDelete( xSemaphore );
+
+ /* Now do the same using a dynamically allocated mutex to ensure the delete
+ * function is working correctly in both the static and dynamic allocation
+ * cases. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ xSemaphore = xSemaphoreCreateMutex();
+
+ /* The semaphore handle should equal the static semaphore structure
+ * passed into the xSemaphoreCreateMutexStatic() function. */
+ configASSERT( xSemaphore != NULL );
+
+ /* Take the mutex so the mutex is in the state expected by the
+ * prvSanityCheckCreatedSemaphore() function. */
+ xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
+ prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
+
+ /* Delete the semaphore again so the buffers can be reused. */
+ vSemaphoreDelete( xSemaphore );
+ }
+ #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void )
-{
-SemaphoreHandle_t xSemaphore;
+ static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void )
+ {
+ SemaphoreHandle_t xSemaphore;
/* StaticSemaphore_t is a publicly accessible structure that has the same size
-and alignment requirements as the real semaphore structure. It is provided as a
-mechanism for applications to know the size of the semaphore (which is dependent
-on the architecture and configuration file settings) without breaking the strict
-data hiding policy by exposing the real semaphore internals. This
-StaticSemaphore_t variable is passed into the xSemaphoreCreateBinaryStatic()
-function calls within this function. NOTE: In most usage scenarios now it is
-faster and more memory efficient to use a direct to task notification instead of
-a binary semaphore. http://www.freertos.org/RTOS-task-notifications.html */
-StaticSemaphore_t xSemaphoreBuffer;
-
- /* Create the semaphore. xSemaphoreCreateBinaryStatic() has one more
- parameter than the usual xSemaphoreCreateBinary() function. The parameter
- is a pointer to the pre-allocated StaticSemaphore_t structure, which will
- hold information on the semaphore in an anonymous way. If the pointer is
- passed as NULL then the structure will be allocated dynamically, just as
- when xSemaphoreCreateBinary() is called. */
- xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
-
- /* The semaphore handle should equal the static semaphore structure passed
- into the xSemaphoreCreateBinaryStatic() function. */
- configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
-
- /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
- prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
-
- /* Delete the semaphore again so the buffers can be reused. */
- vSemaphoreDelete( xSemaphore );
-
- /* Now do the same using a dynamically allocated semaphore to check the
- delete function is working correctly in both the static and dynamic
- allocation cases. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- xSemaphore = xSemaphoreCreateBinary();
- configASSERT( xSemaphore != NULL );
- prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
- vSemaphoreDelete( xSemaphore );
- }
- #endif
-
- /* There isn't a static version of the old and deprecated
- vSemaphoreCreateBinary() macro (because its deprecated!), but check it is
- still functioning correctly. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- vSemaphoreCreateBinary( xSemaphore );
-
- /* The macro starts with the binary semaphore available, but the test
- function expects it to be unavailable. */
- if( xSemaphoreTake( xSemaphore, staticDONT_BLOCK ) == pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
- vSemaphoreDelete( xSemaphore );
- }
- #endif
-}
+* and alignment requirements as the real semaphore structure. It is provided as a
+* mechanism for applications to know the size of the semaphore (which is dependent
+* on the architecture and configuration file settings) without breaking the strict
+* data hiding policy by exposing the real semaphore internals. This
+* StaticSemaphore_t variable is passed into the xSemaphoreCreateBinaryStatic()
+* function calls within this function. NOTE: In most usage scenarios now it is
+* faster and more memory efficient to use a direct to task notification instead of
+* a binary semaphore. http://www.freertos.org/RTOS-task-notifications.html */
+ StaticSemaphore_t xSemaphoreBuffer;
+
+ /* Create the semaphore. xSemaphoreCreateBinaryStatic() has one more
+ * parameter than the usual xSemaphoreCreateBinary() function. The parameter
+ * is a pointer to the pre-allocated StaticSemaphore_t structure, which will
+ * hold information on the semaphore in an anonymous way. If the pointer is
+ * passed as NULL then the structure will be allocated dynamically, just as
+ * when xSemaphoreCreateBinary() is called. */
+ xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );
+
+ /* The semaphore handle should equal the static semaphore structure passed
+ * into the xSemaphoreCreateBinaryStatic() function. */
+ configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );
+
+ /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */
+ prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
+
+ /* Delete the semaphore again so the buffers can be reused. */
+ vSemaphoreDelete( xSemaphore );
+
+ /* Now do the same using a dynamically allocated semaphore to check the
+ * delete function is working correctly in both the static and dynamic
+ * allocation cases. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ xSemaphore = xSemaphoreCreateBinary();
+ configASSERT( xSemaphore != NULL );
+ prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
+ vSemaphoreDelete( xSemaphore );
+ }
+ #endif
+
+ /* There isn't a static version of the old and deprecated
+ * vSemaphoreCreateBinary() macro (because its deprecated!), but check it is
+ * still functioning correctly. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ vSemaphoreCreateBinary( xSemaphore );
+
+ /* The macro starts with the binary semaphore available, but the test
+ * function expects it to be unavailable. */
+ if( xSemaphoreTake( xSemaphore, staticDONT_BLOCK ) == pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ prvSanityCheckCreatedSemaphore( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );
+ vSemaphoreDelete( xSemaphore );
+ }
+ #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
+ }
/*-----------------------------------------------------------*/
-static void prvTimerCallback( TimerHandle_t xExpiredTimer )
-{
-UBaseType_t *puxVariableToIncrement;
-BaseType_t xReturned;
-
- /* The timer callback just demonstrates it is executing by incrementing a
- variable - the address of which is passed into the timer as its ID. Obtain
- the address of the variable to increment. */
- puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
-
- /* Increment the variable to show the timer callback has executed. */
- ( *puxVariableToIncrement )++;
-
- /* If this callback has executed the required number of times, stop the
- timer. */
- if( *puxVariableToIncrement == staticMAX_TIMER_CALLBACK_EXECUTIONS )
- {
- /* This is called from a timer callback so must not block. See
- http://www.FreeRTOS.org/FreeRTOS-timers-xTimerStop.html */
- xReturned = xTimerStop( xExpiredTimer, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-}
+ static void prvTimerCallback( TimerHandle_t xExpiredTimer )
+ {
+ UBaseType_t * puxVariableToIncrement;
+ BaseType_t xReturned;
+
+ /* The timer callback just demonstrates it is executing by incrementing a
+ * variable - the address of which is passed into the timer as its ID. Obtain
+ * the address of the variable to increment. */
+ puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
+
+ /* Increment the variable to show the timer callback has executed. */
+ ( *puxVariableToIncrement )++;
+
+ /* If this callback has executed the required number of times, stop the
+ * timer. */
+ if( *puxVariableToIncrement == staticMAX_TIMER_CALLBACK_EXECUTIONS )
+ {
+ /* This is called from a timer callback so must not block. See
+ * http://www.FreeRTOS.org/FreeRTOS-timers-xTimerStop.html */
+ xReturned = xTimerStop( xExpiredTimer, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedTimers( void )
-{
-TimerHandle_t xTimer;
-UBaseType_t uxVariableToIncrement;
-const TickType_t xTimerPeriod = pdMS_TO_TICKS( 20 );
-BaseType_t xReturned;
+ static void prvCreateAndDeleteStaticallyAllocatedTimers( void )
+ {
+ TimerHandle_t xTimer;
+ UBaseType_t uxVariableToIncrement;
+ const TickType_t xTimerPeriod = pdMS_TO_TICKS( 20 );
+ BaseType_t xReturned;
/* StaticTimer_t is a publicly accessible structure that has the same size
-and alignment requirements as the real timer structure. It is provided as a
-mechanism for applications to know the size of the timer structure (which is
-dependent on the architecture and configuration file settings) without breaking
-the strict data hiding policy by exposing the real timer internals. This
-StaticTimer_t variable is passed into the xTimerCreateStatic() function calls
-within this function. */
-StaticTimer_t xTimerBuffer;
-
- /* Create the software time. xTimerCreateStatic() has an extra parameter
- than the normal xTimerCreate() API function. The parameter is a pointer to
- the StaticTimer_t structure that will hold the software timer structure. If
- the parameter is passed as NULL then the structure will be allocated
- dynamically, just as if xTimerCreate() had been called. */
- xTimer = xTimerCreateStatic( "T1", /* Text name for the task. Helps debugging only. Not used by FreeRTOS. */
- xTimerPeriod, /* The period of the timer in ticks. */
- pdTRUE, /* This is an auto-reload timer. */
- ( void * ) &uxVariableToIncrement, /* The variable incremented by the test is passed into the timer callback using the timer ID. */
- prvTimerCallback, /* The function to execute when the timer expires. */
- &xTimerBuffer ); /* The buffer that will hold the software timer structure. */
-
- /* The timer handle should equal the static timer structure passed into the
- xTimerCreateStatic() function. */
- configASSERT( xTimer == ( TimerHandle_t ) &xTimerBuffer );
-
- /* Set the variable to 0, wait for a few timer periods to expire, then check
- the timer callback has incremented the variable to the expected value. */
- uxVariableToIncrement = 0;
-
- /* This is a low priority so a block time should not be needed. */
- xReturned = xTimerStart( xTimer, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );
-
- /* By now the timer should have expired staticMAX_TIMER_CALLBACK_EXECUTIONS
- times, and then stopped itself. */
- if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Finished with the timer, delete it. */
- xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );
-
- /* Again, as this is a low priority task it is expected that the timer
- command will have been sent even without a block time being used. */
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Just to show the check task that this task is still executing. */
- uxCycleCounter++;
-
- /* Now do the same using a dynamically allocated software timer to ensure
- the delete function is working correctly in both the static and dynamic
- allocation cases. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- xTimer = xTimerCreate( "T1", /* Text name for the task. Helps debugging only. Not used by FreeRTOS. */
- xTimerPeriod, /* The period of the timer in ticks. */
- pdTRUE, /* This is an auto-reload timer. */
- ( void * ) &uxVariableToIncrement, /* The variable incremented by the test is passed into the timer callback using the timer ID. */
- prvTimerCallback ); /* The function to execute when the timer expires. */
-
- configASSERT( xTimer != NULL );
-
- uxVariableToIncrement = 0;
- xReturned = xTimerStart( xTimer, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );
-
- if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
- }
- #endif
-}
+ * and alignment requirements as the real timer structure. It is provided as a
+ * mechanism for applications to know the size of the timer structure (which is
+ * dependent on the architecture and configuration file settings) without breaking
+ * the strict data hiding policy by exposing the real timer internals. This
+ * StaticTimer_t variable is passed into the xTimerCreateStatic() function calls
+ * within this function. */
+ StaticTimer_t xTimerBuffer;
+
+ /* Create the software time. xTimerCreateStatic() has an extra parameter
+ * than the normal xTimerCreate() API function. The parameter is a pointer to
+ * the StaticTimer_t structure that will hold the software timer structure. If
+ * the parameter is passed as NULL then the structure will be allocated
+ * dynamically, just as if xTimerCreate() had been called. */
+ xTimer = xTimerCreateStatic( "T1", /* Text name for the task. Helps debugging only. Not used by FreeRTOS. */
+ xTimerPeriod, /* The period of the timer in ticks. */
+ pdTRUE, /* This is an auto-reload timer. */
+ ( void * ) &uxVariableToIncrement, /* The variable incremented by the test is passed into the timer callback using the timer ID. */
+ prvTimerCallback, /* The function to execute when the timer expires. */
+ &xTimerBuffer ); /* The buffer that will hold the software timer structure. */
+
+ /* The timer handle should equal the static timer structure passed into the
+ * xTimerCreateStatic() function. */
+ configASSERT( xTimer == ( TimerHandle_t ) &xTimerBuffer );
+
+ /* Set the variable to 0, wait for a few timer periods to expire, then check
+ * the timer callback has incremented the variable to the expected value. */
+ uxVariableToIncrement = 0;
+
+ /* This is a low priority so a block time should not be needed. */
+ xReturned = xTimerStart( xTimer, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );
+
+ /* By now the timer should have expired staticMAX_TIMER_CALLBACK_EXECUTIONS
+ * times, and then stopped itself. */
+ if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Finished with the timer, delete it. */
+ xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );
+
+ /* Again, as this is a low priority task it is expected that the timer
+ * command will have been sent even without a block time being used. */
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Just to show the check task that this task is still executing. */
+ uxCycleCounter++;
+
+ /* Now do the same using a dynamically allocated software timer to ensure
+ * the delete function is working correctly in both the static and dynamic
+ * allocation cases. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ xTimer = xTimerCreate( "T1", /* Text name for the task. Helps debugging only. Not used by FreeRTOS. */
+ xTimerPeriod, /* The period of the timer in ticks. */
+ pdTRUE, /* This is an auto-reload timer. */
+ ( void * ) &uxVariableToIncrement, /* The variable incremented by the test is passed into the timer callback using the timer ID. */
+ prvTimerCallback ); /* The function to execute when the timer expires. */
+
+ configASSERT( xTimer != NULL );
+
+ uxVariableToIncrement = 0;
+ xReturned = xTimerStart( xTimer, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ vTaskDelay( xTimerPeriod * staticMAX_TIMER_CALLBACK_EXECUTIONS );
+
+ if( uxVariableToIncrement != staticMAX_TIMER_CALLBACK_EXECUTIONS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ xReturned = xTimerDelete( xTimer, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+ #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedEventGroups( void )
-{
-EventGroupHandle_t xEventGroup;
+ static void prvCreateAndDeleteStaticallyAllocatedEventGroups( void )
+ {
+ EventGroupHandle_t xEventGroup;
/* StaticEventGroup_t is a publicly accessible structure that has the same size
-and alignment requirements as the real event group structure. It is provided as
-a mechanism for applications to know the size of the event group (which is
-dependent on the architecture and configuration file settings) without breaking
-the strict data hiding policy by exposing the real event group internals. This
-StaticEventGroup_t variable is passed into the xSemaphoreCreateEventGroupStatic()
-function calls within this function. */
-StaticEventGroup_t xEventGroupBuffer;
-
- /* Create the event group. xEventGroupCreateStatic() has an extra parameter
- than the normal xEventGroupCreate() API function. The parameter is a
- pointer to the StaticEventGroup_t structure that will hold the event group
- structure. */
- xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
-
- /* The event group handle should equal the static event group structure
- passed into the xEventGroupCreateStatic() function. */
- configASSERT( xEventGroup == ( EventGroupHandle_t ) &xEventGroupBuffer );
-
- /* Ensure the event group passes a few sanity checks as a valid event
- group. */
- prvSanityCheckCreatedEventGroup( xEventGroup );
-
- /* Delete the event group again so the buffers can be reused. */
- vEventGroupDelete( xEventGroup );
-
- /* Now do the same using a dynamically allocated event group to ensure the
- delete function is working correctly in both the static and dynamic
- allocation cases. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- xEventGroup = xEventGroupCreate();
- configASSERT( xEventGroup != NULL );
- prvSanityCheckCreatedEventGroup( xEventGroup );
- vEventGroupDelete( xEventGroup );
- }
- #endif
-}
+ * and alignment requirements as the real event group structure. It is provided as
+ * a mechanism for applications to know the size of the event group (which is
+ * dependent on the architecture and configuration file settings) without breaking
+ * the strict data hiding policy by exposing the real event group internals. This
+ * StaticEventGroup_t variable is passed into the xSemaphoreCreateEventGroupStatic()
+ * function calls within this function. */
+ StaticEventGroup_t xEventGroupBuffer;
+
+ /* Create the event group. xEventGroupCreateStatic() has an extra parameter
+ * than the normal xEventGroupCreate() API function. The parameter is a
+ * pointer to the StaticEventGroup_t structure that will hold the event group
+ * structure. */
+ xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
+
+ /* The event group handle should equal the static event group structure
+ * passed into the xEventGroupCreateStatic() function. */
+ configASSERT( xEventGroup == ( EventGroupHandle_t ) &xEventGroupBuffer );
+
+ /* Ensure the event group passes a few sanity checks as a valid event
+ * group. */
+ prvSanityCheckCreatedEventGroup( xEventGroup );
+
+ /* Delete the event group again so the buffers can be reused. */
+ vEventGroupDelete( xEventGroup );
+
+ /* Now do the same using a dynamically allocated event group to ensure the
+ * delete function is working correctly in both the static and dynamic
+ * allocation cases. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ xEventGroup = xEventGroupCreate();
+ configASSERT( xEventGroup != NULL );
+ prvSanityCheckCreatedEventGroup( xEventGroup );
+ vEventGroupDelete( xEventGroup );
+ }
+ #endif
+ }
/*-----------------------------------------------------------*/
-static void prvCreateAndDeleteStaticallyAllocatedTasks( void )
-{
-TaskHandle_t xCreatedTask;
+ static void prvCreateAndDeleteStaticallyAllocatedTasks( void )
+ {
+ TaskHandle_t xCreatedTask;
/* The variable that will hold the TCB of tasks created by this function. See
-the comments above the declaration of the xCreatorTaskTCBBuffer variable for
-more information. NOTE: This is not static so relies on the tasks that use it
-being deleted before this function returns and deallocates its stack. That will
-only be the case if configUSE_PREEMPTION is set to 1. */
-StaticTask_t xTCBBuffer;
+ * the comments above the declaration of the xCreatorTaskTCBBuffer variable for
+ * more information. NOTE: This is not static so relies on the tasks that use it
+ * being deleted before this function returns and deallocates its stack. That will
+ * only be the case if configUSE_PREEMPTION is set to 1. */
+ StaticTask_t xTCBBuffer;
/* This buffer that will be used as the stack of tasks created by this function.
-See the comments above the declaration of the uxCreatorTaskStackBuffer[] array
-above for more information. */
-static StackType_t uxStackBuffer[ configMINIMAL_STACK_SIZE ];
-
- /* Create the task. xTaskCreateStatic() has two more parameters than
- the usual xTaskCreate() function. The first new parameter is a pointer to
- the pre-allocated stack. The second new parameter is a pointer to the
- StaticTask_t structure that will hold the task's TCB. If both pointers are
- passed as NULL then the respective object will be allocated dynamically as
- if xTaskCreate() had been called. */
- xCreatedTask = xTaskCreateStatic(
- prvStaticallyAllocatedTask, /* Function that implements the task. */
- "Static", /* Human readable name for the task. */
- configMINIMAL_STACK_SIZE, /* Task's stack size, in words (not bytes!). */
- NULL, /* Parameter to pass into the task. */
- uxTaskPriorityGet( NULL ) + 1, /* The priority of the task. */
- &( uxStackBuffer[ 0 ] ), /* The buffer to use as the task's stack. */
- &xTCBBuffer ); /* The variable that will hold that task's TCB. */
-
- /* Check the task was created correctly, then delete the task. */
- if( xCreatedTask == NULL )
- {
- xErrorOccurred = pdTRUE;
- }
- else if( eTaskGetState( xCreatedTask ) != eSuspended )
- {
- /* The created task had a higher priority so should have executed and
- suspended itself by now. */
- xErrorOccurred = pdTRUE;
- }
- else
- {
- vTaskDelete( xCreatedTask );
- }
-
- /* Now do the same using a dynamically allocated task to ensure the delete
- function is working correctly in both the static and dynamic allocation
- cases. */
- #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- BaseType_t xReturned;
-
- xReturned = xTaskCreate(
- prvStaticallyAllocatedTask, /* Function that implements the task - the same function is used but is actually dynamically allocated this time. */
- "Static", /* Human readable name for the task. */
- configMINIMAL_STACK_SIZE, /* Task's stack size, in words (not bytes!). */
- NULL, /* Parameter to pass into the task. */
- uxTaskPriorityGet( NULL ) + 1, /* The priority of the task. */
- &xCreatedTask ); /* Handle of the task being created. */
-
- if( eTaskGetState( xCreatedTask ) != eSuspended )
- {
- xErrorOccurred = pdTRUE;
- }
-
- configASSERT( xReturned == pdPASS );
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
- vTaskDelete( xCreatedTask );
- }
- #endif
-}
+ * See the comments above the declaration of the uxCreatorTaskStackBuffer[] array
+ * above for more information. */
+ static StackType_t uxStackBuffer[ configMINIMAL_STACK_SIZE ];
+
+ /* Create the task. xTaskCreateStatic() has two more parameters than
+ * the usual xTaskCreate() function. The first new parameter is a pointer to
+ * the pre-allocated stack. The second new parameter is a pointer to the
+ * StaticTask_t structure that will hold the task's TCB. If both pointers are
+ * passed as NULL then the respective object will be allocated dynamically as
+ * if xTaskCreate() had been called. */
+ xCreatedTask = xTaskCreateStatic(
+ prvStaticallyAllocatedTask, /* Function that implements the task. */
+ "Static", /* Human readable name for the task. */
+ configMINIMAL_STACK_SIZE, /* Task's stack size, in words (not bytes!). */
+ NULL, /* Parameter to pass into the task. */
+ uxTaskPriorityGet( NULL ) + 1, /* The priority of the task. */
+ &( uxStackBuffer[ 0 ] ), /* The buffer to use as the task's stack. */
+ &xTCBBuffer ); /* The variable that will hold that task's TCB. */
+
+ /* Check the task was created correctly, then delete the task. */
+ if( xCreatedTask == NULL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ else if( eTaskGetState( xCreatedTask ) != eSuspended )
+ {
+ /* The created task had a higher priority so should have executed and
+ * suspended itself by now. */
+ xErrorOccurred = pdTRUE;
+ }
+ else
+ {
+ vTaskDelete( xCreatedTask );
+ }
+
+ /* Now do the same using a dynamically allocated task to ensure the delete
+ * function is working correctly in both the static and dynamic allocation
+ * cases. */
+ #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+ {
+ BaseType_t xReturned;
+
+ xReturned = xTaskCreate(
+ prvStaticallyAllocatedTask, /* Function that implements the task - the same function is used but is actually dynamically allocated this time. */
+ "Static", /* Human readable name for the task. */
+ configMINIMAL_STACK_SIZE, /* Task's stack size, in words (not bytes!). */
+ NULL, /* Parameter to pass into the task. */
+ uxTaskPriorityGet( NULL ) + 1, /* The priority of the task. */
+ &xCreatedTask ); /* Handle of the task being created. */
+
+ if( eTaskGetState( xCreatedTask ) != eSuspended )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ configASSERT( xReturned == pdPASS );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ vTaskDelete( xCreatedTask );
+ }
+ #endif /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
+ }
/*-----------------------------------------------------------*/
-static void prvStaticallyAllocatedTask( void *pvParameters )
-{
- ( void ) pvParameters;
+ static void prvStaticallyAllocatedTask( void * pvParameters )
+ {
+ ( void ) pvParameters;
- /* The created task just suspends itself to wait to get deleted. The task
- that creates this task checks this task is in the expected Suspended state
- before deleting it. */
- vTaskSuspend( NULL );
-}
+ /* The created task just suspends itself to wait to get deleted. The task
+ * that creates this task checks this task is in the expected Suspended state
+ * before deleting it. */
+ vTaskSuspend( NULL );
+ }
/*-----------------------------------------------------------*/
-static UBaseType_t prvRand( void )
-{
-const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
+ static UBaseType_t prvRand( void )
+ {
+ const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
- /* Utility function to generate a pseudo random number. */
- ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
- return( ( ulNextRand >> 16UL ) & 0x7fffUL );
-}
+ /* Utility function to generate a pseudo random number. */
+ ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
+ return( ( ulNextRand >> 16UL ) & 0x7fffUL );
+ }
/*-----------------------------------------------------------*/
-static TickType_t prvGetNextDelayTime( void )
-{
-TickType_t xNextDelay;
-const TickType_t xMaxDelay = pdMS_TO_TICKS( ( TickType_t ) 150 );
-const TickType_t xMinDelay = pdMS_TO_TICKS( ( TickType_t ) 75 );
-const TickType_t xTinyDelay = pdMS_TO_TICKS( ( TickType_t ) 2 );
-
- /* Generate the next delay time. This is kept within a narrow band so as
- not to disturb the timing of other tests - but does add in some pseudo
- randomisation into the tests. */
- do
- {
- xNextDelay = prvRand() % xMaxDelay;
-
- /* Just in case this loop is executed lots of times. */
- vTaskDelay( xTinyDelay );
-
- } while ( xNextDelay < xMinDelay );
-
- return xNextDelay;
-}
+ static TickType_t prvGetNextDelayTime( void )
+ {
+ TickType_t xNextDelay;
+ const TickType_t xMaxDelay = pdMS_TO_TICKS( ( TickType_t ) 150 );
+ const TickType_t xMinDelay = pdMS_TO_TICKS( ( TickType_t ) 75 );
+ const TickType_t xTinyDelay = pdMS_TO_TICKS( ( TickType_t ) 2 );
+
+ /* Generate the next delay time. This is kept within a narrow band so as
+ * not to disturb the timing of other tests - but does add in some pseudo
+ * randomisation into the tests. */
+ do
+ {
+ xNextDelay = prvRand() % xMaxDelay;
+
+ /* Just in case this loop is executed lots of times. */
+ vTaskDelay( xTinyDelay );
+ } while( xNextDelay < xMinDelay );
+
+ return xNextDelay;
+ }
/*-----------------------------------------------------------*/
-static void prvSanityCheckCreatedEventGroup( EventGroupHandle_t xEventGroup )
-{
-EventBits_t xEventBits;
-const EventBits_t xFirstTestBits = ( EventBits_t ) 0xaa, xSecondTestBits = ( EventBits_t ) 0x55;
+ static void prvSanityCheckCreatedEventGroup( EventGroupHandle_t xEventGroup )
+ {
+ EventBits_t xEventBits;
+ const EventBits_t xFirstTestBits = ( EventBits_t ) 0xaa, xSecondTestBits = ( EventBits_t ) 0x55;
- /* The event group should not have any bits set yet. */
- xEventBits = xEventGroupGetBits( xEventGroup );
+ /* The event group should not have any bits set yet. */
+ xEventBits = xEventGroupGetBits( xEventGroup );
- if( xEventBits != ( EventBits_t ) 0 )
- {
- xErrorOccurred = pdTRUE;
- }
+ if( xEventBits != ( EventBits_t ) 0 )
+ {
+ xErrorOccurred = pdTRUE;
+ }
- /* Some some bits, then read them back to check they are as expected. */
- xEventGroupSetBits( xEventGroup, xFirstTestBits );
+ /* Some some bits, then read them back to check they are as expected. */
+ xEventGroupSetBits( xEventGroup, xFirstTestBits );
- xEventBits = xEventGroupGetBits( xEventGroup );
+ xEventBits = xEventGroupGetBits( xEventGroup );
- if( xEventBits != xFirstTestBits )
- {
- xErrorOccurred = pdTRUE;
- }
+ if( xEventBits != xFirstTestBits )
+ {
+ xErrorOccurred = pdTRUE;
+ }
- xEventGroupSetBits( xEventGroup, xSecondTestBits );
+ xEventGroupSetBits( xEventGroup, xSecondTestBits );
- xEventBits = xEventGroupGetBits( xEventGroup );
+ xEventBits = xEventGroupGetBits( xEventGroup );
- if( xEventBits != ( xFirstTestBits | xSecondTestBits ) )
- {
- xErrorOccurred = pdTRUE;
- }
+ if( xEventBits != ( xFirstTestBits | xSecondTestBits ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
- /* Finally try clearing some bits too and check that operation proceeds as
- expected. */
- xEventGroupClearBits( xEventGroup, xFirstTestBits );
+ /* Finally try clearing some bits too and check that operation proceeds as
+ * expected. */
+ xEventGroupClearBits( xEventGroup, xFirstTestBits );
- xEventBits = xEventGroupGetBits( xEventGroup );
+ xEventBits = xEventGroupGetBits( xEventGroup );
- if( xEventBits != xSecondTestBits )
- {
- xErrorOccurred = pdTRUE;
- }
-}
+ if( xEventBits != xSecondTestBits )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvSanityCheckCreatedSemaphore( SemaphoreHandle_t xSemaphore, UBaseType_t uxMaxCount )
-{
-BaseType_t xReturned;
-UBaseType_t x;
-const TickType_t xShortBlockTime = pdMS_TO_TICKS( 10 );
-TickType_t xTickCount;
-
- /* The binary semaphore should start 'empty', so a call to xSemaphoreTake()
- should fail. */
- xTickCount = xTaskGetTickCount();
- xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );
-
- if( ( ( TickType_t ) ( xTaskGetTickCount() - xTickCount ) ) < xShortBlockTime )
- {
- /* Did not block on the semaphore as long as expected. */
- xErrorOccurred = pdTRUE;
- }
-
- if( xReturned != pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Should be possible to 'give' the semaphore up to a maximum of uxMaxCount
- times. */
- for( x = 0; x < uxMaxCount; x++ )
- {
- xReturned = xSemaphoreGive( xSemaphore );
-
- if( xReturned == pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-
- /* Giving the semaphore again should fail, as it is 'full'. */
- xReturned = xSemaphoreGive( xSemaphore );
-
- if( xReturned != pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- configASSERT( uxSemaphoreGetCount( xSemaphore ) == uxMaxCount );
-
- /* Should now be possible to 'take' the semaphore up to a maximum of
- uxMaxCount times without blocking. */
- for( x = 0; x < uxMaxCount; x++ )
- {
- xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
-
- if( xReturned == pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-
- /* Back to the starting condition, where the semaphore should not be
- available. */
- xTickCount = xTaskGetTickCount();
- xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );
-
- if( ( ( TickType_t ) ( xTaskGetTickCount() - xTickCount ) ) < xShortBlockTime )
- {
- /* Did not block on the semaphore as long as expected. */
- xErrorOccurred = pdTRUE;
- }
-
- if( xReturned != pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
-}
+ static void prvSanityCheckCreatedSemaphore( SemaphoreHandle_t xSemaphore,
+ UBaseType_t uxMaxCount )
+ {
+ BaseType_t xReturned;
+ UBaseType_t x;
+ const TickType_t xShortBlockTime = pdMS_TO_TICKS( 10 );
+ TickType_t xTickCount;
+
+ /* The binary semaphore should start 'empty', so a call to xSemaphoreTake()
+ * should fail. */
+ xTickCount = xTaskGetTickCount();
+ xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );
+
+ if( ( ( TickType_t ) ( xTaskGetTickCount() - xTickCount ) ) < xShortBlockTime )
+ {
+ /* Did not block on the semaphore as long as expected. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ if( xReturned != pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Should be possible to 'give' the semaphore up to a maximum of uxMaxCount
+ * times. */
+ for( x = 0; x < uxMaxCount; x++ )
+ {
+ xReturned = xSemaphoreGive( xSemaphore );
+
+ if( xReturned == pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /* Giving the semaphore again should fail, as it is 'full'. */
+ xReturned = xSemaphoreGive( xSemaphore );
+
+ if( xReturned != pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ configASSERT( uxSemaphoreGetCount( xSemaphore ) == uxMaxCount );
+
+ /* Should now be possible to 'take' the semaphore up to a maximum of
+ * uxMaxCount times without blocking. */
+ for( x = 0; x < uxMaxCount; x++ )
+ {
+ xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );
+
+ if( xReturned == pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /* Back to the starting condition, where the semaphore should not be
+ * available. */
+ xTickCount = xTaskGetTickCount();
+ xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );
+
+ if( ( ( TickType_t ) ( xTaskGetTickCount() - xTickCount ) ) < xShortBlockTime )
+ {
+ /* Did not block on the semaphore as long as expected. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ if( xReturned != pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
+ }
/*-----------------------------------------------------------*/
-static void prvSanityCheckCreatedQueue( QueueHandle_t xQueue )
-{
-uint64_t ull, ullRead;
-BaseType_t xReturned, xLoop;
-
- /* This test is done twice to ensure the queue storage area wraps. */
- for( xLoop = 0; xLoop < 2; xLoop++ )
- {
- /* A very basic test that the queue can be written to and read from as
- expected. First the queue should be empty. */
- xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );
- if( xReturned != errQUEUE_EMPTY )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Now it should be possible to write to the queue staticQUEUE_LENGTH_IN_ITEMS
- times. */
- for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )
- {
- xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-
- /* Should not now be possible to write to the queue again. */
- xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );
- if( xReturned != errQUEUE_FULL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Now read back from the queue to ensure the data read back matches that
- written. */
- for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )
- {
- xReturned = xQueueReceive( xQueue, &ullRead, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- if( ullRead != ull )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-
- /* The queue should be empty again. */
- xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );
- if( xReturned != errQUEUE_EMPTY )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-}
+ static void prvSanityCheckCreatedQueue( QueueHandle_t xQueue )
+ {
+ uint64_t ull, ullRead;
+ BaseType_t xReturned, xLoop;
+
+ /* This test is done twice to ensure the queue storage area wraps. */
+ for( xLoop = 0; xLoop < 2; xLoop++ )
+ {
+ /* A very basic test that the queue can be written to and read from as
+ * expected. First the queue should be empty. */
+ xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );
+
+ if( xReturned != errQUEUE_EMPTY )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Now it should be possible to write to the queue staticQUEUE_LENGTH_IN_ITEMS
+ * times. */
+ for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )
+ {
+ xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /* Should not now be possible to write to the queue again. */
+ xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );
+
+ if( xReturned != errQUEUE_FULL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Now read back from the queue to ensure the data read back matches that
+ * written. */
+ for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )
+ {
+ xReturned = xQueueReceive( xQueue, &ullRead, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ if( ullRead != ull )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /* The queue should be empty again. */
+ xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );
+
+ if( xReturned != errQUEUE_EMPTY )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+ }
/*-----------------------------------------------------------*/
-static void prvSanityCheckCreatedRecursiveMutex( SemaphoreHandle_t xSemaphore )
-{
-const BaseType_t xLoops = 5;
-BaseType_t x, xReturned;
-
- /* A very basic test that the recursive semaphore behaved like a recursive
- semaphore. First the semaphore should not be able to be given, as it has not
- yet been taken. */
- xReturned = xSemaphoreGiveRecursive( xSemaphore );
-
- if( xReturned != pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Now it should be possible to take the mutex a number of times. */
- for( x = 0; x < xLoops; x++ )
- {
- xReturned = xSemaphoreTakeRecursive( xSemaphore, staticDONT_BLOCK );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-
- /* Should be possible to give the semaphore the same number of times as it
- was given in the loop above. */
- for( x = 0; x < xLoops; x++ )
- {
- xReturned = xSemaphoreGiveRecursive( xSemaphore );
-
- if( xReturned != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-
- /* No more gives should be possible though. */
- xReturned = xSemaphoreGiveRecursive( xSemaphore );
-
- if( xReturned != pdFAIL )
- {
- xErrorOccurred = pdTRUE;
- }
-}
+ static void prvSanityCheckCreatedRecursiveMutex( SemaphoreHandle_t xSemaphore )
+ {
+ const BaseType_t xLoops = 5;
+ BaseType_t x, xReturned;
+
+ /* A very basic test that the recursive semaphore behaved like a recursive
+ * semaphore. First the semaphore should not be able to be given, as it has not
+ * yet been taken. */
+ xReturned = xSemaphoreGiveRecursive( xSemaphore );
+
+ if( xReturned != pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Now it should be possible to take the mutex a number of times. */
+ for( x = 0; x < xLoops; x++ )
+ {
+ xReturned = xSemaphoreTakeRecursive( xSemaphore, staticDONT_BLOCK );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /* Should be possible to give the semaphore the same number of times as it
+ * was given in the loop above. */
+ for( x = 0; x < xLoops; x++ )
+ {
+ xReturned = xSemaphoreGiveRecursive( xSemaphore );
+
+ if( xReturned != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /* No more gives should be possible though. */
+ xReturned = xSemaphoreGiveRecursive( xSemaphore );
+
+ if( xReturned != pdFAIL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
/*-----------------------------------------------------------*/
-BaseType_t xAreStaticAllocationTasksStillRunning( void )
-{
-static UBaseType_t uxLastCycleCounter = 0;
-BaseType_t xReturn;
-
- if( uxCycleCounter == uxLastCycleCounter )
- {
- xErrorOccurred = pdTRUE;
- }
- else
- {
- uxLastCycleCounter = uxCycleCounter;
- }
-
- if( xErrorOccurred != pdFALSE )
- {
- xReturn = pdFAIL;
- }
- else
- {
- xReturn = pdPASS;
- }
-
- return xReturn;
-}
+ BaseType_t xAreStaticAllocationTasksStillRunning( void )
+ {
+ static UBaseType_t uxLastCycleCounter = 0;
+ BaseType_t xReturn;
+
+ if( uxCycleCounter == uxLastCycleCounter )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ else
+ {
+ uxLastCycleCounter = uxCycleCounter;
+ }
+
+ if( xErrorOccurred != pdFALSE )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ xReturn = pdPASS;
+ }
+
+ return xReturn;
+ }
/*-----------------------------------------------------------*/
/* Exclude the entire file if configSUPPORT_STATIC_ALLOCATION is 0. */
diff --git a/FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c b/FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c
index 228904b04..044dcd9d9 100644
--- a/FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c
+++ b/FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c
@@ -37,47 +37,47 @@
#include "StreamBufferDemo.h"
/* The number of bytes of storage in the stream buffers used in this test. */
-#define sbSTREAM_BUFFER_LENGTH_BYTES ( ( size_t ) 30 )
+#define sbSTREAM_BUFFER_LENGTH_BYTES ( ( size_t ) 30 )
/* Stream buffer length one. */
-#define sbSTREAM_BUFFER_LENGTH_ONE ( ( size_t ) 1 )
+#define sbSTREAM_BUFFER_LENGTH_ONE ( ( size_t ) 1 )
/* Start and end ASCII characters used in data sent to the buffers. */
-#define sbASCII_SPACE 32
-#define sbASCII_TILDA 126
+#define sbASCII_SPACE 32
+#define sbASCII_TILDA 126
/* Defines the number of tasks to create in this test and demo. */
-#define sbNUMBER_OF_ECHO_CLIENTS ( 2 )
-#define sbNUMBER_OF_SENDER_TASKS ( 2 )
+#define sbNUMBER_OF_ECHO_CLIENTS ( 2 )
+#define sbNUMBER_OF_SENDER_TASKS ( 2 )
/* Priority of the test tasks. The send and receive go from low to high
-priority tasks, and from high to low priority tasks. */
-#define sbLOWER_PRIORITY ( tskIDLE_PRIORITY )
-#define sbHIGHER_PRIORITY ( tskIDLE_PRIORITY + 1 )
+ * priority tasks, and from high to low priority tasks. */
+#define sbLOWER_PRIORITY ( tskIDLE_PRIORITY )
+#define sbHIGHER_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Block times used when sending and receiving from the stream buffers. */
-#define sbRX_TX_BLOCK_TIME pdMS_TO_TICKS( 125UL )
+#define sbRX_TX_BLOCK_TIME pdMS_TO_TICKS( 125UL )
/* A block time of 0 means "don't block". */
-#define sbDONT_BLOCK ( 0 )
+#define sbDONT_BLOCK ( 0 )
/* The trigger level sets the number of bytes that must be present in the
-stream buffer before a task that is blocked on the stream buffer is moved out of
-the Blocked state so it can read the bytes. */
-#define sbTRIGGER_LEVEL_1 ( 1 )
+ * stream buffer before a task that is blocked on the stream buffer is moved out of
+ * the Blocked state so it can read the bytes. */
+#define sbTRIGGER_LEVEL_1 ( 1 )
/* The size of the stack allocated to the tasks that run as part of this demo/
-test. The stack size is over generous in most cases. */
+ * test. The stack size is over generous in most cases. */
#ifndef configSTREAM_BUFFER_SENDER_TASK_STACK_SIZE
- #define sbSTACK_SIZE ( configMINIMAL_STACK_SIZE + ( configMINIMAL_STACK_SIZE >> 1 ) )
+ #define sbSTACK_SIZE ( configMINIMAL_STACK_SIZE + ( configMINIMAL_STACK_SIZE >> 1 ) )
#else
- #define sbSTACK_SIZE configSTREAM_BUFFER_SENDER_TASK_STACK_SIZE
+ #define sbSTACK_SIZE configSTREAM_BUFFER_SENDER_TASK_STACK_SIZE
#endif
#ifndef configSTREAM_BUFFER_SMALLER_TASK_STACK_SIZE
- #define sbSMALLER_STACK_SIZE sbSTACK_SIZE
+ #define sbSMALLER_STACK_SIZE sbSTACK_SIZE
#else
- #define sbSMALLER_STACK_SIZE configSTREAM_BUFFER_SMALLER_TASK_STACK_SIZE
+ #define sbSMALLER_STACK_SIZE configSTREAM_BUFFER_SMALLER_TASK_STACK_SIZE
#endif
/*-----------------------------------------------------------*/
@@ -93,19 +93,19 @@ static void prvSingleTaskTests( StreamBufferHandle_t xStreamBuffer );
* data back to the echo client, which checks it receives exactly what it
* sent.
*/
-static void prvEchoClient( void *pvParameters );
-static void prvEchoServer( void *pvParameters );
+static void prvEchoClient( void * pvParameters );
+static void prvEchoServer( void * pvParameters );
/*
* Tasks that send and receive to a stream buffer at a low priority and without
* blocking, so the send and receive functions interleave in time as the tasks
* are switched in and out.
*/
-static void prvNonBlockingReceiverTask( void *pvParameters );
-static void prvNonBlockingSenderTask( void *pvParameters );
+static void prvNonBlockingReceiverTask( void * pvParameters );
+static void prvNonBlockingSenderTask( void * pvParameters );
/* Performs an assert() like check in a way that won't get removed when
-performing a code coverage analysis. */
+ * performing a code coverage analysis. */
static void prvCheckExpectedState( BaseType_t xState );
/*
@@ -113,24 +113,25 @@ static void prvCheckExpectedState( BaseType_t xState );
* receives a string from an interrupt (the RTOS tick hook) byte by byte to
* check it is only unblocked when the specified trigger level is reached.
*/
-static void prvInterruptTriggerLevelTest( void *pvParameters );
+static void prvInterruptTriggerLevelTest( void * pvParameters );
-#if( configSUPPORT_STATIC_ALLOCATION == 1 )
- /* This file tests both statically and dynamically allocated stream buffers.
- Allocate the structures and buffers to be used by the statically allocated
- objects, which get used in the echo tests. */
- static void prvReceiverTask( void *pvParameters );
- static void prvSenderTask( void *pvParameters );
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
- static StaticStreamBuffer_t xStaticStreamBuffers[ sbNUMBER_OF_ECHO_CLIENTS ];
- static uint32_t ulSenderLoopCounters[ sbNUMBER_OF_SENDER_TASKS ] = { 0 };
+/* This file tests both statically and dynamically allocated stream buffers.
+ * Allocate the structures and buffers to be used by the statically allocated
+ * objects, which get used in the echo tests. */
+ static void prvReceiverTask( void * pvParameters );
+ static void prvSenderTask( void * pvParameters );
+
+ static StaticStreamBuffer_t xStaticStreamBuffers[ sbNUMBER_OF_ECHO_CLIENTS ];
+ static uint32_t ulSenderLoopCounters[ sbNUMBER_OF_SENDER_TASKS ] = { 0 };
#endif /* configSUPPORT_STATIC_ALLOCATION */
/* The +1 is to make the test logic easier as the function that calculates the
-free space will return one less than the actual free space - adding a 1 to the
-actual length makes it appear to the tests as if the free space is returned as
-it might logically be expected. Returning 1 less than the actual free space is
-fine as it can never result in an overrun. */
+ * free space will return one less than the actual free space - adding a 1 to the
+ * actual length makes it appear to the tests as if the free space is returned as
+ * it might logically be expected. Returning 1 less than the actual free space is
+ * fine as it can never result in an overrun. */
static uint8_t ucBufferStorage[ sbNUMBER_OF_SENDER_TASKS ][ sbSTREAM_BUFFER_LENGTH_BYTES + 1 ];
/*-----------------------------------------------------------*/
@@ -138,1104 +139,1109 @@ static uint8_t ucBufferStorage[ sbNUMBER_OF_SENDER_TASKS ][ sbSTREAM_BUFFER_LENG
/* The buffers used by the echo client and server tasks. */
typedef struct ECHO_STREAM_BUFFERS
{
- /* Handles to the data structures that describe the stream buffers. */
- StreamBufferHandle_t xEchoClientBuffer;
- StreamBufferHandle_t xEchoServerBuffer;
+ /* Handles to the data structures that describe the stream buffers. */
+ StreamBufferHandle_t xEchoClientBuffer;
+ StreamBufferHandle_t xEchoServerBuffer;
} EchoStreamBuffers_t;
static volatile uint32_t ulEchoLoopCounters[ sbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
/* The non-blocking tasks monitor their operation, and if no errors have been
-found, increment ulNonBlockingRxCounter. xAreStreamBufferTasksStillRunning()
-then checks ulNonBlockingRxCounter and only returns pdPASS if
-ulNonBlockingRxCounter is still incrementing. */
+ * found, increment ulNonBlockingRxCounter. xAreStreamBufferTasksStillRunning()
+ * then checks ulNonBlockingRxCounter and only returns pdPASS if
+ * ulNonBlockingRxCounter is still incrementing. */
static volatile uint32_t ulNonBlockingRxCounter = 0;
/* The task that receives characters from the tick interrupt in order to test
-different trigger levels monitors its own behaviour. If it has not detected any
-error then it increments ulInterruptTriggerCounter to indicate to the check task
-that it is still operating correctly. */
+ * different trigger levels monitors its own behaviour. If it has not detected any
+ * error then it increments ulInterruptTriggerCounter to indicate to the check task
+ * that it is still operating correctly. */
static volatile uint32_t ulInterruptTriggerCounter = 0UL;
/* The stream buffer used from the tick interrupt. This sends one byte at a time
-to a test task to test the trigger level operation. The variable is set to NULL
-in between test runs. */
+ * to a test task to test the trigger level operation. The variable is set to NULL
+ * in between test runs. */
static volatile StreamBufferHandle_t xInterruptStreamBuffer = NULL;
/* The data sent from the tick interrupt to the task that tests the trigger
-level functionality. */
-static const char *pcDataSentFromInterrupt = "0123456789";
+ * level functionality. */
+static const char * pcDataSentFromInterrupt = "0123456789";
/* Data that is longer than the buffer that is sent to the buffers as a stream
-of bytes. Parts of which are written to the stream buffer to test writing
-different lengths at different offsets, to many bytes, part streams, streams
-that wrap, etc.. Two messages are defined to ensure left over data is not
-accidentally read out of the buffer. */
-static const char *pc55ByteString = "One two three four five six seven eight nine ten eleven";
-static const char *pc54ByteString = "01234567891abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ";
+ * of bytes. Parts of which are written to the stream buffer to test writing
+ * different lengths at different offsets, to many bytes, part streams, streams
+ * that wrap, etc.. Two messages are defined to ensure left over data is not
+ * accidentally read out of the buffer. */
+static const char * pc55ByteString = "One two three four five six seven eight nine ten eleven";
+static const char * pc54ByteString = "01234567891abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ";
/* Used to log the status of the tests contained within this file for reporting
-to a monitoring task ('check' task). */
+ * to a monitoring task ('check' task). */
static BaseType_t xErrorStatus = pdPASS;
/*-----------------------------------------------------------*/
void vStartStreamBufferTasks( void )
{
-StreamBufferHandle_t xStreamBuffer;
-
- /* The echo servers sets up the stream buffers before creating the echo
- client tasks. One set of tasks has the server as the higher priority, and
- the other has the client as the higher priority. */
- xTaskCreate( prvEchoServer, "1StrEchoServer", sbSMALLER_STACK_SIZE, NULL, sbHIGHER_PRIORITY, NULL );
- xTaskCreate( prvEchoServer, "2StrEchoServer", sbSMALLER_STACK_SIZE, NULL, sbLOWER_PRIORITY, NULL );
-
- /* The non blocking tasks run continuously and will interleave with each
- other, so must be created at the lowest priority. The stream buffer they
- use is created and passed in using the task's parameter. */
- xStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
- xTaskCreate( prvNonBlockingReceiverTask, "StrNonBlkRx", configMINIMAL_STACK_SIZE, ( void * ) xStreamBuffer, tskIDLE_PRIORITY, NULL );
- xTaskCreate( prvNonBlockingSenderTask, "StrNonBlkTx", configMINIMAL_STACK_SIZE, ( void * ) xStreamBuffer, tskIDLE_PRIORITY, NULL );
-
- /* The task that receives bytes from an interrupt to test that it unblocks
- at a specific trigger level must run at a high priority to minimise the risk
- of it receiving more characters before it can execute again after being
- unblocked. */
- xTaskCreate( prvInterruptTriggerLevelTest, "StrTrig", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- /* The sender tasks set up the stream buffers before creating the
- receiver tasks. Priorities must be 0 and 1 as the priority is used to
- index into the xStaticStreamBuffers and ucBufferStorage arrays. */
- xTaskCreate( prvSenderTask, "Str1Sender", sbSMALLER_STACK_SIZE, NULL, sbHIGHER_PRIORITY, NULL );
- xTaskCreate( prvSenderTask, "Str2Sender", sbSMALLER_STACK_SIZE, NULL, sbLOWER_PRIORITY, NULL );
- }
- #endif /* configSUPPORT_STATIC_ALLOCATION */
+ StreamBufferHandle_t xStreamBuffer;
+
+ /* The echo servers sets up the stream buffers before creating the echo
+ * client tasks. One set of tasks has the server as the higher priority, and
+ * the other has the client as the higher priority. */
+ xTaskCreate( prvEchoServer, "1StrEchoServer", sbSMALLER_STACK_SIZE, NULL, sbHIGHER_PRIORITY, NULL );
+ xTaskCreate( prvEchoServer, "2StrEchoServer", sbSMALLER_STACK_SIZE, NULL, sbLOWER_PRIORITY, NULL );
+
+ /* The non blocking tasks run continuously and will interleave with each
+ * other, so must be created at the lowest priority. The stream buffer they
+ * use is created and passed in using the task's parameter. */
+ xStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
+ xTaskCreate( prvNonBlockingReceiverTask, "StrNonBlkRx", configMINIMAL_STACK_SIZE, ( void * ) xStreamBuffer, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( prvNonBlockingSenderTask, "StrNonBlkTx", configMINIMAL_STACK_SIZE, ( void * ) xStreamBuffer, tskIDLE_PRIORITY, NULL );
+
+ /* The task that receives bytes from an interrupt to test that it unblocks
+ * at a specific trigger level must run at a high priority to minimise the risk
+ * of it receiving more characters before it can execute again after being
+ * unblocked. */
+ xTaskCreate( prvInterruptTriggerLevelTest, "StrTrig", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ /* The sender tasks set up the stream buffers before creating the
+ * receiver tasks. Priorities must be 0 and 1 as the priority is used to
+ * index into the xStaticStreamBuffers and ucBufferStorage arrays. */
+ xTaskCreate( prvSenderTask, "Str1Sender", sbSMALLER_STACK_SIZE, NULL, sbHIGHER_PRIORITY, NULL );
+ xTaskCreate( prvSenderTask, "Str2Sender", sbSMALLER_STACK_SIZE, NULL, sbLOWER_PRIORITY, NULL );
+ }
+ #endif /* configSUPPORT_STATIC_ALLOCATION */
}
/*-----------------------------------------------------------*/
static void prvCheckExpectedState( BaseType_t xState )
{
- configASSERT( xState );
- if( xState == pdFAIL )
- {
- xErrorStatus = pdFAIL;
- }
+ configASSERT( xState );
+
+ if( xState == pdFAIL )
+ {
+ xErrorStatus = pdFAIL;
+ }
}
/*-----------------------------------------------------------*/
static void prvSingleTaskTests( StreamBufferHandle_t xStreamBuffer )
{
-size_t xReturned, xItem, xExpected, xExpectedSpaces, xExpectedBytes;
-const size_t xMax6ByteMessages = sbSTREAM_BUFFER_LENGTH_BYTES / 6;
-const size_t xTrueSize = ( sizeof( ucBufferStorage ) / sbNUMBER_OF_SENDER_TASKS );
-const size_t x6ByteLength = 6, x17ByteLength = 17, xFullBufferSize = sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2;
-uint8_t *pucFullBuffer, *pucData, *pucReadData;
-TickType_t xTimeBeforeCall, xTimeAfterCall;
-const TickType_t xBlockTime = pdMS_TO_TICKS( 15 ), xAllowableMargin = pdMS_TO_TICKS( 3 ), xMinimalBlockTime = 2;
-UBaseType_t uxOriginalPriority;
-
- /* Remove warning in case configASSERT() is not defined. */
- ( void ) xAllowableMargin;
-
- /* To minimise stack and heap usage a full size buffer is allocated from the
- heap, then buffers which hold smaller amounts of data are overlayed with the
- larger buffer - just make sure not to use both at once! */
- pucFullBuffer = pvPortMalloc( xFullBufferSize );
- configASSERT( pucFullBuffer );
-
- pucData = pucFullBuffer;
- pucReadData = pucData + x17ByteLength;
-
- /* Nothing has been added or removed yet, so expect the free space to be
- exactly as created. Head and tail are both at 0. */
- xExpectedSpaces = sbSTREAM_BUFFER_LENGTH_BYTES;
- xExpectedBytes = 0;
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedBytes );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
- /* Add a single item - number of bytes available should go up by one and spaces
- available down by one. Head is in front of tail. */
- xExpectedSpaces--;
- xExpectedBytes++;
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
- prvCheckExpectedState( xReturned == sizeof( *pucData ) );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedBytes );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
- /* Now fill the buffer by adding another 29 bytes. Head is 30 tail is at 0. */
- xExpectedSpaces -= 29;
- xExpectedBytes += 29;
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, ( sbSTREAM_BUFFER_LENGTH_BYTES - 1 ), ( TickType_t ) 0 );
- prvCheckExpectedState( xReturned == ( sbSTREAM_BUFFER_LENGTH_BYTES - 1 ) );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedBytes );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
-
- /* Should not be able to add another byte now. */
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
- prvCheckExpectedState( xReturned == ( size_t ) 0 );
-
- /* Remove a byte so the tail pointer moves off 0. Head pointer remains at the
- end of the buffer. */
- xExpectedSpaces += 1;
- xExpectedBytes -= 1;
- xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
- prvCheckExpectedState( xReturned == sizeof( *pucData ) );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedBytes );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
- /* Should be able to add another byte to fill the buffer again now. */
- xExpectedSpaces -= 1;
- xExpectedBytes += 1;
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
- prvCheckExpectedState( xReturned == sizeof( *pucData ) );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedBytes );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
-
- /* Now the head pointer is behind the tail pointer. Read another 29 bytes so
- the tail pointer moves to the end of the buffer. */
- xExpectedSpaces += 29;
- xExpectedBytes -= 29;
- xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, ( size_t ) 29, ( TickType_t ) 0 );
- prvCheckExpectedState( xReturned == ( size_t ) 29 );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedBytes );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
- /* Read out one more byte to wrap the tail back around to the start, to get back
- to where we started. */
- xExpectedSpaces += 1;
- xExpectedBytes -= 1;
- xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
- prvCheckExpectedState( xReturned == sizeof( *pucData ) );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedBytes );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
- /* Try filling the message buffer in one write, blocking indefinitely. Expect to
- have written one byte less. */
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, xTrueSize, portMAX_DELAY );
- xExpectedSpaces = ( size_t ) 0;
- prvCheckExpectedState( xReturned == ( xTrueSize - ( size_t ) 1 ) );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == xExpectedSpaces );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
-
- /* Empty the buffer again ready for the rest of the tests. Again block
- indefinitely to ensure reading more than there can possible be won't lock this
- task up, so expect to actually receive one byte less than requested. */
- xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, xTrueSize, portMAX_DELAY );
- prvCheckExpectedState( xReturned == ( xTrueSize - ( size_t ) 1 ) );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == sbSTREAM_BUFFER_LENGTH_BYTES );
- xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == ( size_t ) 0 );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
-
- /* The buffer is 30 bytes long. 6 5 byte messages should fit before the
- buffer is completely full. */
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
- {
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
- /* Generate recognisable data to write to the buffer. This is just
- ascii characters that shows which loop iteration the data was written
- in. The 'FromISR' version is used to give it some exercise as a block
- time is not used, so the call must be inside a critical section so it
- runs with ports that don't support interrupt nesting (and therefore
- don't have interrupt safe critical sections). */
- memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
- taskENTER_CRITICAL();
- {
- xReturned = xStreamBufferSendFromISR( xStreamBuffer, ( void * ) pucData, x6ByteLength, NULL );
- }
- taskEXIT_CRITICAL();
- prvCheckExpectedState( xReturned == x6ByteLength );
-
- /* The space in the buffer will have reduced by the amount of user data
- written into the buffer. */
- xExpected -= x6ByteLength;
- xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xReturned == xExpected );
- xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
- /* +1 as it is zero indexed. */
- prvCheckExpectedState( xReturned == ( ( xItem + 1 ) * x6ByteLength ) );
- }
-
- /* Now the buffer should be full, and attempting to add anything should fail. */
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), sbDONT_BLOCK );
- prvCheckExpectedState( xReturned == 0 );
-
- /* Adding with a timeout should also fail after the appropriate time. The
- priority is temporarily boosted in this part of the test to keep the
- allowable margin to a minimum. */
- uxOriginalPriority = uxTaskPriorityGet( NULL );
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
- xTimeBeforeCall = xTaskGetTickCount();
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), xBlockTime );
- xTimeAfterCall = xTaskGetTickCount();
- vTaskPrioritySet( NULL, uxOriginalPriority );
- prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );
- prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );
- prvCheckExpectedState( xReturned == 0 );
-
- /* The buffer is now full of data in the form "000000", "111111", etc. Make
- sure the data is read out as expected. */
- for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
- {
- /* Generate the data that is expected to be read out for this loop
- iteration. */
- memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
-
- /* Read the next 6 bytes out. The 'FromISR' version is used to give it
- some exercise as a block time is not used, so a it must be called from
- a critical section so this will work on ports that don't support
- interrupt nesting (so don't have interrupt safe critical sections). */
- taskENTER_CRITICAL();
- {
- xReturned = xStreamBufferReceiveFromISR( xStreamBuffer, ( void * ) pucReadData, x6ByteLength, NULL );
- }
- taskEXIT_CRITICAL();
- prvCheckExpectedState( xReturned == x6ByteLength );
-
- /* Does the data read out match that expected? */
- prvCheckExpectedState( memcmp( ( void * ) pucData, ( void * ) pucReadData, x6ByteLength ) == 0 );
-
- /* The space in the buffer will have increased by the amount of user
- data removed from the buffer. */
- xExpected += x6ByteLength;
- xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xReturned == xExpected );
- xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xReturned == ( sbSTREAM_BUFFER_LENGTH_BYTES - xExpected ) );
- }
-
- /* The buffer should be empty again. */
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
- xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xExpected == sbSTREAM_BUFFER_LENGTH_BYTES );
-
- /* Reading with a timeout should also fail after the appropriate time. The
- priority is temporarily boosted in this part of the test to keep the
- allowable margin to a minimum. */
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
- xTimeBeforeCall = xTaskGetTickCount();
- xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucReadData, x6ByteLength, xBlockTime );
- xTimeAfterCall = xTaskGetTickCount();
- vTaskPrioritySet( NULL, uxOriginalPriority );
- prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );
- prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );
- prvCheckExpectedState( xReturned == 0 );
-
-
- /* In the next loop 17 bytes are written to then read out on each
- iteration. As 30 is not divisible by 17 the data will wrap around. */
- xExpected = sbSTREAM_BUFFER_LENGTH_BYTES - x17ByteLength;
-
- for( xItem = 0; xItem < 100; xItem++ )
- {
- /* Generate recognisable data to write to the queue. This is just
- ascii characters that shows which loop iteration the data was written
- in. */
- memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x17ByteLength );
- xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, x17ByteLength, sbDONT_BLOCK );
- prvCheckExpectedState( xReturned == x17ByteLength );
-
- /* The space in the buffer will have reduced by the amount of user data
- written into the buffer. */
- xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xReturned == xExpected );
- xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xReturned == x17ByteLength );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
-
- /* Read the 17 bytes out again. */
- xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucReadData, x17ByteLength, sbDONT_BLOCK );
- prvCheckExpectedState( xReturned == x17ByteLength );
-
- /* Does the data read out match that expected? */
- prvCheckExpectedState( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );
-
- /* Full buffer space available again. */
- xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
- prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
- xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
- prvCheckExpectedState( xReturned == 0 );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
- }
-
- /* Fill the buffer with one message, check it is full, then read it back
- again and check the correct data is received. */
- xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES, sbDONT_BLOCK );
- xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES, sbDONT_BLOCK );
- prvCheckExpectedState( memcmp( pc55ByteString, pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
-
- /* Fill the buffer one bytes at a time. */
- for( xItem = 0; xItem < sbSTREAM_BUFFER_LENGTH_BYTES; xItem++ )
- {
- /* Block time is only for test coverage, the task should never actually
- block here. */
- xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc54ByteString[ xItem ] ), sizeof( char ), sbRX_TX_BLOCK_TIME );
- }
-
- /* The buffer should now be full. */
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
-
- /* Read the message out in one go, even though it was written in individual
- bytes. Try reading much more data than is actually available to ensure only
- the available bytes are returned (otherwise this read will write outside of
- the memory allocated anyway!). */
- xReturned = xStreamBufferReceive( xStreamBuffer, pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, sbRX_TX_BLOCK_TIME );
- prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
- prvCheckExpectedState( memcmp( ( const void * ) pc54ByteString, ( const void * ) pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
-
- /* Now do the opposite, write in one go and read out in single bytes. */
- xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES, sbRX_TX_BLOCK_TIME );
- prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferBytesAvailable( xStreamBuffer ) == sbSTREAM_BUFFER_LENGTH_BYTES );
- prvCheckExpectedState( xStreamBufferSpacesAvailable( xStreamBuffer ) == 0 );
-
- /* Read from the buffer one byte at a time. */
- for( xItem = 0; xItem < sbSTREAM_BUFFER_LENGTH_BYTES; xItem++ )
- {
- /* Block time is only for test coverage, the task should never actually
- block here. */
- xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, sizeof( char ), sbRX_TX_BLOCK_TIME );
- prvCheckExpectedState( pc55ByteString[ xItem ] == pucFullBuffer[ 0 ] );
- }
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
-
- /* Try writing more bytes than there is space. */
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
- xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, xMinimalBlockTime );
- vTaskPrioritySet( NULL, uxOriginalPriority );
- prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
-
- /* No space now though. */
- xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, xMinimalBlockTime );
- prvCheckExpectedState( xReturned == 0 );
-
- /* Ensure data was written as expected even when there was an attempt to
- write more than was available. This also tries to read more bytes than are
- available. */
- xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, xFullBufferSize, xMinimalBlockTime );
- prvCheckExpectedState( memcmp( ( const void * ) pucFullBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
- prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
- prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
-
- /* Clean up with data in the buffer to ensure the tests that follow don't
- see the data (the data should be discarded). */
- ( void ) xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES / ( size_t ) 2, sbDONT_BLOCK );
- vPortFree( pucFullBuffer );
- xStreamBufferReset( xStreamBuffer );
+ size_t xReturned, xItem, xExpected, xExpectedSpaces, xExpectedBytes;
+ const size_t xMax6ByteMessages = sbSTREAM_BUFFER_LENGTH_BYTES / 6;
+ const size_t xTrueSize = ( sizeof( ucBufferStorage ) / sbNUMBER_OF_SENDER_TASKS );
+ const size_t x6ByteLength = 6, x17ByteLength = 17, xFullBufferSize = sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2;
+ uint8_t * pucFullBuffer, * pucData, * pucReadData;
+ TickType_t xTimeBeforeCall, xTimeAfterCall;
+ const TickType_t xBlockTime = pdMS_TO_TICKS( 15 ), xAllowableMargin = pdMS_TO_TICKS( 3 ), xMinimalBlockTime = 2;
+ UBaseType_t uxOriginalPriority;
+
+ /* Remove warning in case configASSERT() is not defined. */
+ ( void ) xAllowableMargin;
+
+ /* To minimise stack and heap usage a full size buffer is allocated from the
+ * heap, then buffers which hold smaller amounts of data are overlayed with the
+ * larger buffer - just make sure not to use both at once! */
+ pucFullBuffer = pvPortMalloc( xFullBufferSize );
+ configASSERT( pucFullBuffer );
+
+ pucData = pucFullBuffer;
+ pucReadData = pucData + x17ByteLength;
+
+ /* Nothing has been added or removed yet, so expect the free space to be
+ * exactly as created. Head and tail are both at 0. */
+ xExpectedSpaces = sbSTREAM_BUFFER_LENGTH_BYTES;
+ xExpectedBytes = 0;
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedBytes );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+ /* Add a single item - number of bytes available should go up by one and spaces
+ * available down by one. Head is in front of tail. */
+ xExpectedSpaces--;
+ xExpectedBytes++;
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
+ prvCheckExpectedState( xReturned == sizeof( *pucData ) );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedBytes );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+ /* Now fill the buffer by adding another 29 bytes. Head is 30 tail is at 0. */
+ xExpectedSpaces -= 29;
+ xExpectedBytes += 29;
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, ( sbSTREAM_BUFFER_LENGTH_BYTES - 1 ), ( TickType_t ) 0 );
+ prvCheckExpectedState( xReturned == ( sbSTREAM_BUFFER_LENGTH_BYTES - 1 ) );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedBytes );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
+
+ /* Should not be able to add another byte now. */
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
+ prvCheckExpectedState( xReturned == ( size_t ) 0 );
+
+ /* Remove a byte so the tail pointer moves off 0. Head pointer remains at the
+ * end of the buffer. */
+ xExpectedSpaces += 1;
+ xExpectedBytes -= 1;
+ xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
+ prvCheckExpectedState( xReturned == sizeof( *pucData ) );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedBytes );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+ /* Should be able to add another byte to fill the buffer again now. */
+ xExpectedSpaces -= 1;
+ xExpectedBytes += 1;
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
+ prvCheckExpectedState( xReturned == sizeof( *pucData ) );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedBytes );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
+
+ /* Now the head pointer is behind the tail pointer. Read another 29 bytes so
+ * the tail pointer moves to the end of the buffer. */
+ xExpectedSpaces += 29;
+ xExpectedBytes -= 29;
+ xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, ( size_t ) 29, ( TickType_t ) 0 );
+ prvCheckExpectedState( xReturned == ( size_t ) 29 );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedBytes );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+ /* Read out one more byte to wrap the tail back around to the start, to get back
+ * to where we started. */
+ xExpectedSpaces += 1;
+ xExpectedBytes -= 1;
+ xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, sizeof( *pucData ), ( TickType_t ) 0 );
+ prvCheckExpectedState( xReturned == sizeof( *pucData ) );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedBytes );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+ /* Try filling the message buffer in one write, blocking indefinitely. Expect to
+ * have written one byte less. */
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, xTrueSize, portMAX_DELAY );
+ xExpectedSpaces = ( size_t ) 0;
+ prvCheckExpectedState( xReturned == ( xTrueSize - ( size_t ) 1 ) );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == xExpectedSpaces );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
+
+ /* Empty the buffer again ready for the rest of the tests. Again block
+ * indefinitely to ensure reading more than there can possible be won't lock this
+ * task up, so expect to actually receive one byte less than requested. */
+ xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucData, xTrueSize, portMAX_DELAY );
+ prvCheckExpectedState( xReturned == ( xTrueSize - ( size_t ) 1 ) );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == sbSTREAM_BUFFER_LENGTH_BYTES );
+ xExpected = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == ( size_t ) 0 );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+
+ /* The buffer is 30 bytes long. 6 5 byte messages should fit before the
+ * buffer is completely full. */
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+
+ for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
+ {
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+ /* Generate recognisable data to write to the buffer. This is just
+ * ascii characters that shows which loop iteration the data was written
+ * in. The 'FromISR' version is used to give it some exercise as a block
+ * time is not used, so the call must be inside a critical section so it
+ * runs with ports that don't support interrupt nesting (and therefore
+ * don't have interrupt safe critical sections). */
+ memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
+ taskENTER_CRITICAL();
+ {
+ xReturned = xStreamBufferSendFromISR( xStreamBuffer, ( void * ) pucData, x6ByteLength, NULL );
+ }
+ taskEXIT_CRITICAL();
+ prvCheckExpectedState( xReturned == x6ByteLength );
+
+ /* The space in the buffer will have reduced by the amount of user data
+ * written into the buffer. */
+ xExpected -= x6ByteLength;
+ xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xReturned == xExpected );
+ xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
+ /* +1 as it is zero indexed. */
+ prvCheckExpectedState( xReturned == ( ( xItem + 1 ) * x6ByteLength ) );
+ }
+
+ /* Now the buffer should be full, and attempting to add anything should fail. */
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), sbDONT_BLOCK );
+ prvCheckExpectedState( xReturned == 0 );
+
+ /* Adding with a timeout should also fail after the appropriate time. The
+ * priority is temporarily boosted in this part of the test to keep the
+ * allowable margin to a minimum. */
+ uxOriginalPriority = uxTaskPriorityGet( NULL );
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+ xTimeBeforeCall = xTaskGetTickCount();
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, sizeof( pucData[ 0 ] ), xBlockTime );
+ xTimeAfterCall = xTaskGetTickCount();
+ vTaskPrioritySet( NULL, uxOriginalPriority );
+ prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );
+ prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );
+ prvCheckExpectedState( xReturned == 0 );
+
+ /* The buffer is now full of data in the form "000000", "111111", etc. Make
+ * sure the data is read out as expected. */
+ for( xItem = 0; xItem < xMax6ByteMessages; xItem++ )
+ {
+ /* Generate the data that is expected to be read out for this loop
+ * iteration. */
+ memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x6ByteLength );
+
+ /* Read the next 6 bytes out. The 'FromISR' version is used to give it
+ * some exercise as a block time is not used, so a it must be called from
+ * a critical section so this will work on ports that don't support
+ * interrupt nesting (so don't have interrupt safe critical sections). */
+ taskENTER_CRITICAL();
+ {
+ xReturned = xStreamBufferReceiveFromISR( xStreamBuffer, ( void * ) pucReadData, x6ByteLength, NULL );
+ }
+ taskEXIT_CRITICAL();
+ prvCheckExpectedState( xReturned == x6ByteLength );
+
+ /* Does the data read out match that expected? */
+ prvCheckExpectedState( memcmp( ( void * ) pucData, ( void * ) pucReadData, x6ByteLength ) == 0 );
+
+ /* The space in the buffer will have increased by the amount of user
+ * data removed from the buffer. */
+ xExpected += x6ByteLength;
+ xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xReturned == xExpected );
+ xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xReturned == ( sbSTREAM_BUFFER_LENGTH_BYTES - xExpected ) );
+ }
+
+ /* The buffer should be empty again. */
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
+ xExpected = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xExpected == sbSTREAM_BUFFER_LENGTH_BYTES );
+
+ /* Reading with a timeout should also fail after the appropriate time. The
+ * priority is temporarily boosted in this part of the test to keep the
+ * allowable margin to a minimum. */
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+ xTimeBeforeCall = xTaskGetTickCount();
+ xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucReadData, x6ByteLength, xBlockTime );
+ xTimeAfterCall = xTaskGetTickCount();
+ vTaskPrioritySet( NULL, uxOriginalPriority );
+ prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) >= xBlockTime );
+ prvCheckExpectedState( ( ( TickType_t ) ( xTimeAfterCall - xTimeBeforeCall ) ) < ( xBlockTime + xAllowableMargin ) );
+ prvCheckExpectedState( xReturned == 0 );
+
+
+ /* In the next loop 17 bytes are written to then read out on each
+ * iteration. As 30 is not divisible by 17 the data will wrap around. */
+ xExpected = sbSTREAM_BUFFER_LENGTH_BYTES - x17ByteLength;
+
+ for( xItem = 0; xItem < 100; xItem++ )
+ {
+ /* Generate recognisable data to write to the queue. This is just
+ * ascii characters that shows which loop iteration the data was written
+ * in. */
+ memset( ( void * ) pucData, ( ( int ) '0' ) + ( int ) xItem, x17ByteLength );
+ xReturned = xStreamBufferSend( xStreamBuffer, ( void * ) pucData, x17ByteLength, sbDONT_BLOCK );
+ prvCheckExpectedState( xReturned == x17ByteLength );
+
+ /* The space in the buffer will have reduced by the amount of user data
+ * written into the buffer. */
+ xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xReturned == xExpected );
+ xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xReturned == x17ByteLength );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+
+ /* Read the 17 bytes out again. */
+ xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucReadData, x17ByteLength, sbDONT_BLOCK );
+ prvCheckExpectedState( xReturned == x17ByteLength );
+
+ /* Does the data read out match that expected? */
+ prvCheckExpectedState( memcmp( ( void * ) pucData, ( void * ) pucReadData, x17ByteLength ) == 0 );
+
+ /* Full buffer space available again. */
+ xReturned = xStreamBufferSpacesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
+ xReturned = xStreamBufferBytesAvailable( xStreamBuffer );
+ prvCheckExpectedState( xReturned == 0 );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
+ }
+
+ /* Fill the buffer with one message, check it is full, then read it back
+ * again and check the correct data is received. */
+ xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES, sbDONT_BLOCK );
+ xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES, sbDONT_BLOCK );
+ prvCheckExpectedState( memcmp( pc55ByteString, pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
+
+ /* Fill the buffer one bytes at a time. */
+ for( xItem = 0; xItem < sbSTREAM_BUFFER_LENGTH_BYTES; xItem++ )
+ {
+ /* Block time is only for test coverage, the task should never actually
+ * block here. */
+ xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc54ByteString[ xItem ] ), sizeof( char ), sbRX_TX_BLOCK_TIME );
+ }
+
+ /* The buffer should now be full. */
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
+
+ /* Read the message out in one go, even though it was written in individual
+ * bytes. Try reading much more data than is actually available to ensure only
+ * the available bytes are returned (otherwise this read will write outside of
+ * the memory allocated anyway!). */
+ xReturned = xStreamBufferReceive( xStreamBuffer, pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, sbRX_TX_BLOCK_TIME );
+ prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
+ prvCheckExpectedState( memcmp( ( const void * ) pc54ByteString, ( const void * ) pucFullBuffer, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
+
+ /* Now do the opposite, write in one go and read out in single bytes. */
+ xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES, sbRX_TX_BLOCK_TIME );
+ prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferBytesAvailable( xStreamBuffer ) == sbSTREAM_BUFFER_LENGTH_BYTES );
+ prvCheckExpectedState( xStreamBufferSpacesAvailable( xStreamBuffer ) == 0 );
+
+ /* Read from the buffer one byte at a time. */
+ for( xItem = 0; xItem < sbSTREAM_BUFFER_LENGTH_BYTES; xItem++ )
+ {
+ /* Block time is only for test coverage, the task should never actually
+ * block here. */
+ xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, sizeof( char ), sbRX_TX_BLOCK_TIME );
+ prvCheckExpectedState( pc55ByteString[ xItem ] == pucFullBuffer[ 0 ] );
+ }
+
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+
+ /* Try writing more bytes than there is space. */
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+ xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, xMinimalBlockTime );
+ vTaskPrioritySet( NULL, uxOriginalPriority );
+ prvCheckExpectedState( xReturned == sbSTREAM_BUFFER_LENGTH_BYTES );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdTRUE );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdFALSE );
+
+ /* No space now though. */
+ xReturned = xStreamBufferSend( xStreamBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES * ( size_t ) 2, xMinimalBlockTime );
+ prvCheckExpectedState( xReturned == 0 );
+
+ /* Ensure data was written as expected even when there was an attempt to
+ * write more than was available. This also tries to read more bytes than are
+ * available. */
+ xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, xFullBufferSize, xMinimalBlockTime );
+ prvCheckExpectedState( memcmp( ( const void * ) pucFullBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
+ prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
+ prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
+
+ /* Clean up with data in the buffer to ensure the tests that follow don't
+ * see the data (the data should be discarded). */
+ ( void ) xStreamBufferSend( xStreamBuffer, ( const void * ) pc55ByteString, sbSTREAM_BUFFER_LENGTH_BYTES / ( size_t ) 2, sbDONT_BLOCK );
+ vPortFree( pucFullBuffer );
+ xStreamBufferReset( xStreamBuffer );
}
/*-----------------------------------------------------------*/
-static void prvNonBlockingSenderTask( void *pvParameters )
+static void prvNonBlockingSenderTask( void * pvParameters )
{
-StreamBufferHandle_t xStreamBuffer;
-size_t xNextChar = 0, xBytesToSend, xBytesActuallySent;
-const size_t xStringLength = strlen( pc54ByteString );
-
- /* In this case the stream buffer has already been created and is passed
- into the task using the task's parameter. */
- xStreamBuffer = ( StreamBufferHandle_t ) pvParameters;
-
- /* Keep sending the string to the stream buffer as many bytes as possible in
- each go. Doesn't block so calls can interleave with the non-blocking
- receives performed by prvNonBlockingReceiverTask(). */
- for( ;; )
- {
- /* The whole string cannot be sent at once, so xNextChar is an index to
- the position within the string that has been sent so far. How many
- bytes are there left to send before the end of the string? */
- xBytesToSend = xStringLength - xNextChar;
-
- /* Attempt to send right up to the end of the string. */
- xBytesActuallySent = xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc54ByteString[ xNextChar ] ), xBytesToSend, sbDONT_BLOCK );
- prvCheckExpectedState( xBytesActuallySent <= xBytesToSend );
-
- /* Move the index up the string to the next character to be sent,
- wrapping if the end of the string has been reached. */
- xNextChar += xBytesActuallySent;
- prvCheckExpectedState( xNextChar <= xStringLength );
-
- if( xNextChar == xStringLength )
- {
- xNextChar = 0;
- }
- }
+ StreamBufferHandle_t xStreamBuffer;
+ size_t xNextChar = 0, xBytesToSend, xBytesActuallySent;
+ const size_t xStringLength = strlen( pc54ByteString );
+
+ /* In this case the stream buffer has already been created and is passed
+ * into the task using the task's parameter. */
+ xStreamBuffer = ( StreamBufferHandle_t ) pvParameters;
+
+ /* Keep sending the string to the stream buffer as many bytes as possible in
+ * each go. Doesn't block so calls can interleave with the non-blocking
+ * receives performed by prvNonBlockingReceiverTask(). */
+ for( ; ; )
+ {
+ /* The whole string cannot be sent at once, so xNextChar is an index to
+ * the position within the string that has been sent so far. How many
+ * bytes are there left to send before the end of the string? */
+ xBytesToSend = xStringLength - xNextChar;
+
+ /* Attempt to send right up to the end of the string. */
+ xBytesActuallySent = xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc54ByteString[ xNextChar ] ), xBytesToSend, sbDONT_BLOCK );
+ prvCheckExpectedState( xBytesActuallySent <= xBytesToSend );
+
+ /* Move the index up the string to the next character to be sent,
+ * wrapping if the end of the string has been reached. */
+ xNextChar += xBytesActuallySent;
+ prvCheckExpectedState( xNextChar <= xStringLength );
+
+ if( xNextChar == xStringLength )
+ {
+ xNextChar = 0;
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prvNonBlockingReceiverTask( void *pvParameters )
+static void prvNonBlockingReceiverTask( void * pvParameters )
{
-StreamBufferHandle_t xStreamBuffer;
-size_t xNextChar = 0, xReceiveLength, xBytesToTest, xStartIndex;
-const size_t xStringLength = strlen( pc54ByteString );
-char cRxString[ 12 ]; /* Holds received characters. */
-BaseType_t xNonBlockingReceiveError = pdFALSE;
-
- /* In this case the stream buffer has already been created and is passed
- into the task using the task's parameter. */
- xStreamBuffer = ( StreamBufferHandle_t ) pvParameters;
-
- /* Expects to receive the pc54ByteString over and over again. Sends and
- receives are not blocking so will interleave. */
- for( ;; )
- {
- /* Attempt to receive as many bytes as possible, up to the limit of the
- Rx buffer size. */
- xReceiveLength = xStreamBufferReceive( xStreamBuffer, ( void * ) cRxString, sizeof( cRxString ), sbDONT_BLOCK );
-
- if( xReceiveLength > 0 )
- {
- /* xNextChar is the index into pc54ByteString that has been received
- already. If xReceiveLength bytes are added to that, will it go off
- the end of the string? If so, then first test up to the end of the
- string, then go back to the start of pc54ByteString to test the
- remains of the received data. */
- xBytesToTest = xReceiveLength;
- if( ( xNextChar + xBytesToTest ) > xStringLength )
- {
- /* Cap to test the received data to the end of the string. */
- xBytesToTest = xStringLength - xNextChar;
-
- if( memcmp( ( const void * ) &( pc54ByteString[ xNextChar ] ), ( const void * ) cRxString, xBytesToTest ) != 0 )
- {
- xNonBlockingReceiveError = pdTRUE;
- }
-
- /* Then move back to the start of the string to test the
- remaining received bytes. */
- xNextChar = 0;
- xStartIndex = xBytesToTest;
- xBytesToTest = xReceiveLength - xBytesToTest;
- }
- else
- {
- /* The string didn't wrap in the buffer, so start comparing from
- the start of the received data. */
- xStartIndex = 0;
- }
-
- /* Test the received bytes are as expected, then move the index
- along the string to the next expected char to receive. */
- if( memcmp( ( const void * ) &( pc54ByteString[ xNextChar ] ), ( const void * ) &( cRxString[ xStartIndex ] ), xBytesToTest ) != 0 )
- {
- xNonBlockingReceiveError = pdTRUE;
- }
-
- if( xNonBlockingReceiveError == pdFALSE )
- {
- /* No errors detected so increment the counter that lets the
- check task know this test is still functioning correctly. */
- ulNonBlockingRxCounter++;
- }
-
- xNextChar += xBytesToTest;
- if( xNextChar >= xStringLength )
- {
- xNextChar = 0;
- }
- }
- }
+ StreamBufferHandle_t xStreamBuffer;
+ size_t xNextChar = 0, xReceiveLength, xBytesToTest, xStartIndex;
+ const size_t xStringLength = strlen( pc54ByteString );
+ char cRxString[ 12 ]; /* Holds received characters. */
+ BaseType_t xNonBlockingReceiveError = pdFALSE;
+
+ /* In this case the stream buffer has already been created and is passed
+ * into the task using the task's parameter. */
+ xStreamBuffer = ( StreamBufferHandle_t ) pvParameters;
+
+ /* Expects to receive the pc54ByteString over and over again. Sends and
+ * receives are not blocking so will interleave. */
+ for( ; ; )
+ {
+ /* Attempt to receive as many bytes as possible, up to the limit of the
+ * Rx buffer size. */
+ xReceiveLength = xStreamBufferReceive( xStreamBuffer, ( void * ) cRxString, sizeof( cRxString ), sbDONT_BLOCK );
+
+ if( xReceiveLength > 0 )
+ {
+ /* xNextChar is the index into pc54ByteString that has been received
+ * already. If xReceiveLength bytes are added to that, will it go off
+ * the end of the string? If so, then first test up to the end of the
+ * string, then go back to the start of pc54ByteString to test the
+ * remains of the received data. */
+ xBytesToTest = xReceiveLength;
+
+ if( ( xNextChar + xBytesToTest ) > xStringLength )
+ {
+ /* Cap to test the received data to the end of the string. */
+ xBytesToTest = xStringLength - xNextChar;
+
+ if( memcmp( ( const void * ) &( pc54ByteString[ xNextChar ] ), ( const void * ) cRxString, xBytesToTest ) != 0 )
+ {
+ xNonBlockingReceiveError = pdTRUE;
+ }
+
+ /* Then move back to the start of the string to test the
+ * remaining received bytes. */
+ xNextChar = 0;
+ xStartIndex = xBytesToTest;
+ xBytesToTest = xReceiveLength - xBytesToTest;
+ }
+ else
+ {
+ /* The string didn't wrap in the buffer, so start comparing from
+ * the start of the received data. */
+ xStartIndex = 0;
+ }
+
+ /* Test the received bytes are as expected, then move the index
+ * along the string to the next expected char to receive. */
+ if( memcmp( ( const void * ) &( pc54ByteString[ xNextChar ] ), ( const void * ) &( cRxString[ xStartIndex ] ), xBytesToTest ) != 0 )
+ {
+ xNonBlockingReceiveError = pdTRUE;
+ }
+
+ if( xNonBlockingReceiveError == pdFALSE )
+ {
+ /* No errors detected so increment the counter that lets the
+ * check task know this test is still functioning correctly. */
+ ulNonBlockingRxCounter++;
+ }
+
+ xNextChar += xBytesToTest;
+
+ if( xNextChar >= xStringLength )
+ {
+ xNextChar = 0;
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
-#if( configSUPPORT_STATIC_ALLOCATION == 1 )
-
- static void prvSenderTask( void *pvParameters )
- {
- StreamBufferHandle_t xStreamBuffer, xTempStreamBuffer;
- static uint8_t ucTempBuffer[ 10 ]; /* Just used to exercise stream buffer creating and deletion. */
- const TickType_t xTicksToWait = sbRX_TX_BLOCK_TIME, xShortDelay = pdMS_TO_TICKS( 50 );
- StaticStreamBuffer_t xStaticStreamBuffer;
- size_t xNextChar = 0, xBytesToSend, xBytesActuallySent;
- const size_t xStringLength = strlen( pc55ByteString );
-
- /* The task's priority is used as an index into the loop counters used to
- indicate this task is still running. */
- UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
-
- /* Make sure a change in priority does not inadvertently result in an
- invalid array index. */
- prvCheckExpectedState( uxIndex < sbNUMBER_OF_ECHO_CLIENTS );
-
- /* Avoid compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucBufferStorage ) / sbNUMBER_OF_SENDER_TASKS, /* The number of bytes in each buffer in the array. */
- sbTRIGGER_LEVEL_1, /* The number of bytes to be in the buffer before a task blocked to wait for data is unblocked. */
- &( ucBufferStorage[ uxIndex ][ 0 ] ), /* The address of the buffer to use within the array. */
- &( xStaticStreamBuffers[ uxIndex ] ) ); /* The static stream buffer structure to use within the array. */
-
- /* Now the stream buffer has been created the receiver task can be
- created. If this sender task has the higher priority then the receiver
- task is created at the lower priority - if this sender task has the
- lower priority then the receiver task is created at the higher
- priority. */
- if( uxTaskPriorityGet( NULL ) == sbLOWER_PRIORITY )
- {
- /* Here prvSingleTaskTests() performs various tests on a stream buffer
- that was created statically. */
- prvSingleTaskTests( xStreamBuffer );
- xTaskCreate( prvReceiverTask, "StrReceiver", sbSMALLER_STACK_SIZE, ( void * ) xStreamBuffer, sbHIGHER_PRIORITY, NULL );
- }
- else
- {
- xTaskCreate( prvReceiverTask, "StrReceiver", sbSMALLER_STACK_SIZE, ( void * ) xStreamBuffer, sbLOWER_PRIORITY, NULL );
- }
-
- for( ;; )
- {
- /* The whole string cannot be sent at once, so xNextChar is an index
- to the position within the string that has been sent so far. How
- many bytes are there left to send before the end of the string? */
- xBytesToSend = xStringLength - xNextChar;
-
- /* Attempt to send right up to the end of the string. */
- xBytesActuallySent = xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc55ByteString[ xNextChar ] ), xBytesToSend, xTicksToWait );
- prvCheckExpectedState( xBytesActuallySent <= xBytesToSend );
-
- /* Move the index up the string to the next character to be sent,
- wrapping if the end of the string has been reached. */
- xNextChar += xBytesActuallySent;
- prvCheckExpectedState( xNextChar <= xStringLength );
-
- if( xNextChar == xStringLength )
- {
- xNextChar = 0;
- }
-
- /* Increment a loop counter so a check task can tell this task is
- still running as expected. */
- ulSenderLoopCounters[ uxIndex ]++;
-
- if( uxTaskPriorityGet( NULL ) == sbHIGHER_PRIORITY )
- {
- /* Allow other tasks to run. */
- vTaskDelay( xShortDelay );
- }
-
- /* This stream buffer is just created and deleted to ensure no
- issues when attempting to delete a stream buffer that was
- created using statically allocated memory. To save stack space
- the buffer is set to point to the pc55ByteString, which is a const
- string, but no data is written into the buffer so any valid address
- will do. */
- xTempStreamBuffer = xStreamBufferCreateStatic( sizeof( ucTempBuffer ), sbTRIGGER_LEVEL_1, ucTempBuffer, &xStaticStreamBuffer );
- xStreamBufferReset( xTempStreamBuffer );
- vStreamBufferDelete( xTempStreamBuffer );
- }
- }
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+
+ static void prvSenderTask( void * pvParameters )
+ {
+ StreamBufferHandle_t xStreamBuffer, xTempStreamBuffer;
+ static uint8_t ucTempBuffer[ 10 ]; /* Just used to exercise stream buffer creating and deletion. */
+ const TickType_t xTicksToWait = sbRX_TX_BLOCK_TIME, xShortDelay = pdMS_TO_TICKS( 50 );
+ StaticStreamBuffer_t xStaticStreamBuffer;
+ size_t xNextChar = 0, xBytesToSend, xBytesActuallySent;
+ const size_t xStringLength = strlen( pc55ByteString );
+
+ /* The task's priority is used as an index into the loop counters used to
+ * indicate this task is still running. */
+ UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
+
+ /* Make sure a change in priority does not inadvertently result in an
+ * invalid array index. */
+ prvCheckExpectedState( uxIndex < sbNUMBER_OF_ECHO_CLIENTS );
+
+ /* Avoid compiler warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucBufferStorage ) / sbNUMBER_OF_SENDER_TASKS, /* The number of bytes in each buffer in the array. */
+ sbTRIGGER_LEVEL_1, /* The number of bytes to be in the buffer before a task blocked to wait for data is unblocked. */
+ &( ucBufferStorage[ uxIndex ][ 0 ] ), /* The address of the buffer to use within the array. */
+ &( xStaticStreamBuffers[ uxIndex ] ) ); /* The static stream buffer structure to use within the array. */
+
+ /* Now the stream buffer has been created the receiver task can be
+ * created. If this sender task has the higher priority then the receiver
+ * task is created at the lower priority - if this sender task has the
+ * lower priority then the receiver task is created at the higher
+ * priority. */
+ if( uxTaskPriorityGet( NULL ) == sbLOWER_PRIORITY )
+ {
+ /* Here prvSingleTaskTests() performs various tests on a stream buffer
+ * that was created statically. */
+ prvSingleTaskTests( xStreamBuffer );
+ xTaskCreate( prvReceiverTask, "StrReceiver", sbSMALLER_STACK_SIZE, ( void * ) xStreamBuffer, sbHIGHER_PRIORITY, NULL );
+ }
+ else
+ {
+ xTaskCreate( prvReceiverTask, "StrReceiver", sbSMALLER_STACK_SIZE, ( void * ) xStreamBuffer, sbLOWER_PRIORITY, NULL );
+ }
+
+ for( ; ; )
+ {
+ /* The whole string cannot be sent at once, so xNextChar is an index
+ * to the position within the string that has been sent so far. How
+ * many bytes are there left to send before the end of the string? */
+ xBytesToSend = xStringLength - xNextChar;
+
+ /* Attempt to send right up to the end of the string. */
+ xBytesActuallySent = xStreamBufferSend( xStreamBuffer, ( const void * ) &( pc55ByteString[ xNextChar ] ), xBytesToSend, xTicksToWait );
+ prvCheckExpectedState( xBytesActuallySent <= xBytesToSend );
+
+ /* Move the index up the string to the next character to be sent,
+ * wrapping if the end of the string has been reached. */
+ xNextChar += xBytesActuallySent;
+ prvCheckExpectedState( xNextChar <= xStringLength );
+
+ if( xNextChar == xStringLength )
+ {
+ xNextChar = 0;
+ }
+
+ /* Increment a loop counter so a check task can tell this task is
+ * still running as expected. */
+ ulSenderLoopCounters[ uxIndex ]++;
+
+ if( uxTaskPriorityGet( NULL ) == sbHIGHER_PRIORITY )
+ {
+ /* Allow other tasks to run. */
+ vTaskDelay( xShortDelay );
+ }
+
+ /* This stream buffer is just created and deleted to ensure no
+ * issues when attempting to delete a stream buffer that was
+ * created using statically allocated memory. To save stack space
+ * the buffer is set to point to the pc55ByteString, which is a const
+ * string, but no data is written into the buffer so any valid address
+ * will do. */
+ xTempStreamBuffer = xStreamBufferCreateStatic( sizeof( ucTempBuffer ), sbTRIGGER_LEVEL_1, ucTempBuffer, &xStaticStreamBuffer );
+ xStreamBufferReset( xTempStreamBuffer );
+ vStreamBufferDelete( xTempStreamBuffer );
+ }
+ }
#endif /* configSUPPORT_STATIC_ALLOCATION */
/*-----------------------------------------------------------*/
-#if( configSUPPORT_STATIC_ALLOCATION == 1 )
-
- static void prvReceiverTask( void *pvParameters )
- {
- StreamBufferHandle_t const pxStreamBuffer = ( StreamBufferHandle_t ) pvParameters;
- char cRxString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */
- const TickType_t xTicksToWait = pdMS_TO_TICKS( 5UL );
- const size_t xStringLength = strlen( pc55ByteString );
- size_t xNextChar = 0, xReceivedLength, xBytesToReceive;
-
- for( ;; )
- {
- /* Attempt to receive the number of bytes to the end of the string,
- or the number of byte that can be placed into the rx buffer,
- whichever is smallest. */
- xBytesToReceive = configMIN( ( xStringLength - xNextChar ), sizeof( cRxString ) );
-
- do
- {
- xReceivedLength = xStreamBufferReceive( pxStreamBuffer, ( void * ) cRxString, xBytesToReceive, xTicksToWait );
-
- } while( xReceivedLength == 0 );
-
- /* Ensure the received string matches the expected string. */
- prvCheckExpectedState( memcmp( ( void * ) cRxString, ( const void * ) &( pc55ByteString[ xNextChar ] ), xReceivedLength ) == 0 );
-
- /* Move the index into the string up to the end of the bytes
- received so far - wrapping if the end of the string has been
- reached. */
- xNextChar += xReceivedLength;
- if( xNextChar >= xStringLength )
- {
- xNextChar = 0;
- }
- }
- }
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+
+ static void prvReceiverTask( void * pvParameters )
+ {
+ StreamBufferHandle_t const pxStreamBuffer = ( StreamBufferHandle_t ) pvParameters;
+ char cRxString[ 12 ]; /* Large enough to hold a 32-bit number in ASCII. */
+ const TickType_t xTicksToWait = pdMS_TO_TICKS( 5UL );
+ const size_t xStringLength = strlen( pc55ByteString );
+ size_t xNextChar = 0, xReceivedLength, xBytesToReceive;
+
+ for( ; ; )
+ {
+ /* Attempt to receive the number of bytes to the end of the string,
+ * or the number of byte that can be placed into the rx buffer,
+ * whichever is smallest. */
+ xBytesToReceive = configMIN( ( xStringLength - xNextChar ), sizeof( cRxString ) );
+
+ do
+ {
+ xReceivedLength = xStreamBufferReceive( pxStreamBuffer, ( void * ) cRxString, xBytesToReceive, xTicksToWait );
+ } while( xReceivedLength == 0 );
+
+ /* Ensure the received string matches the expected string. */
+ prvCheckExpectedState( memcmp( ( void * ) cRxString, ( const void * ) &( pc55ByteString[ xNextChar ] ), xReceivedLength ) == 0 );
+
+ /* Move the index into the string up to the end of the bytes
+ * received so far - wrapping if the end of the string has been
+ * reached. */
+ xNextChar += xReceivedLength;
+
+ if( xNextChar >= xStringLength )
+ {
+ xNextChar = 0;
+ }
+ }
+ }
#endif /* configSUPPORT_STATIC_ALLOCATION */
/*-----------------------------------------------------------*/
-static void prvEchoClient( void *pvParameters )
+static void prvEchoClient( void * pvParameters )
{
-size_t xSendLength = 0, ux;
-char *pcStringToSend, *pcStringReceived, cNextChar = sbASCII_SPACE;
-const TickType_t xTicksToWait = pdMS_TO_TICKS( 50 );
-StreamBufferHandle_t xTempStreamBuffer;
+ size_t xSendLength = 0, ux;
+ char * pcStringToSend, * pcStringReceived, cNextChar = sbASCII_SPACE;
+ const TickType_t xTicksToWait = pdMS_TO_TICKS( 50 );
+ StreamBufferHandle_t xTempStreamBuffer;
/* The task's priority is used as an index into the loop counters used to
-indicate this task is still running. */
-UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
+ * indicate this task is still running. */
+ UBaseType_t uxIndex = uxTaskPriorityGet( NULL );
/* Pointers to the client and server stream buffers are passed into this task
-using the task's parameter. */
-EchoStreamBuffers_t *pxStreamBuffers = ( EchoStreamBuffers_t * ) pvParameters;
-
- /* Prevent compiler warnings. */
- ( void ) pvParameters;
-
- /* Create the buffer into which strings to send to the server will be
- created, and the buffer into which strings echoed back from the server will
- be copied. */
- pcStringToSend = ( char * ) pvPortMalloc( sbSTREAM_BUFFER_LENGTH_BYTES );
- pcStringReceived = ( char * ) pvPortMalloc( sbSTREAM_BUFFER_LENGTH_BYTES );
-
- configASSERT( pcStringToSend );
- configASSERT( pcStringReceived );
-
- for( ;; )
- {
- /* Generate the length of the next string to send. */
- xSendLength++;
-
- /* The stream buffer is being used to hold variable length data, so
- each data item requires sizeof( size_t ) bytes to hold the data's
- length, hence the sizeof() in the if() condition below. */
- if( xSendLength > ( sbSTREAM_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) )
- {
- /* Back to a string length of 1. */
- xSendLength = sizeof( char );
- }
-
- memset( pcStringToSend, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
-
- for( ux = 0; ux < xSendLength; ux++ )
- {
- pcStringToSend[ ux ] = cNextChar;
-
- cNextChar++;
-
- if( cNextChar > sbASCII_TILDA )
- {
- cNextChar = sbASCII_SPACE;
- }
- }
-
- /* Send the generated string to the buffer. */
- do
- {
- ux = xStreamBufferSend( pxStreamBuffers->xEchoClientBuffer, ( void * ) pcStringToSend, xSendLength, xTicksToWait );
-
- } while( ux == 0 );
-
- /* Wait for the string to be echoed back. */
- memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
- xStreamBufferReceive( pxStreamBuffers->xEchoServerBuffer, ( void * ) pcStringReceived, xSendLength, portMAX_DELAY );
-
- prvCheckExpectedState( strcmp( pcStringToSend, pcStringReceived ) == 0 );
-
- /* Maintain a count of the number of times this code executes so a
- check task can determine if this task is still functioning as
- expected or not. As there are two client tasks, and the priorities
- used are 0 and 1, the task's priority is used as an index into the
- loop count array. */
- ulEchoLoopCounters[ uxIndex ]++;
-
- /* This stream buffer is just created and deleted to ensure no memory
- leaks. */
- xTempStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
- vStreamBufferDelete( xTempStreamBuffer );
-
- /* The following are tests for a stream buffer of size one. */
- /* Create a buffer of size one. */
- xTempStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_ONE, sbTRIGGER_LEVEL_1 );
- /* Ensure that the buffer was created successfully. */
- configASSERT( xTempStreamBuffer );
-
- /* Send one byte to the buffer. */
- ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 1, sbDONT_BLOCK );
- /* Ensure that the byte was sent successfully. */
- configASSERT( ux == 1 );
- /* Try sending another byte to the buffer. */
- ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 1, sbDONT_BLOCK );
- /* Make sure that send failed as the buffer is full. */
- configASSERT( ux == 0 );
-
- /* Receive one byte from the buffer. */
- memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
- ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 1, sbDONT_BLOCK );
- /* Ensure that the receive was successful. */
- configASSERT( ux == 1 );
- /* Ensure that the correct data was received. */
- configASSERT( pcStringToSend[ 0 ] == pcStringReceived[ 0 ] );
- /* Try receiving another byte from the buffer. */
- ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 1, sbDONT_BLOCK );
- /* Ensure that the receive failed as the buffer is empty. */
- configASSERT( ux == 0 );
-
- /* Try sending two bytes to the buffer. Since the size of the
- * buffer is one, we must not be able to send more than one. */
- ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 2, sbDONT_BLOCK );
- /* Ensure that only one byte was sent. */
- configASSERT( ux == 1 );
-
- /* Try receiving two bytes from the buffer. Since the size of the
- * buffer is one, we must not be able to get more than one. */
- memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
- ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 2, sbDONT_BLOCK );
- /* Ensure that only one byte was received. */
- configASSERT( ux == 1 );
- /* Ensure that the correct data was received. */
- configASSERT( pcStringToSend[ 0 ] == pcStringReceived[ 0 ] );
-
- /* Delete the buffer. */
- vStreamBufferDelete( xTempStreamBuffer );
- }
+ * using the task's parameter. */
+ EchoStreamBuffers_t * pxStreamBuffers = ( EchoStreamBuffers_t * ) pvParameters;
+
+ /* Prevent compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Create the buffer into which strings to send to the server will be
+ * created, and the buffer into which strings echoed back from the server will
+ * be copied. */
+ pcStringToSend = ( char * ) pvPortMalloc( sbSTREAM_BUFFER_LENGTH_BYTES );
+ pcStringReceived = ( char * ) pvPortMalloc( sbSTREAM_BUFFER_LENGTH_BYTES );
+
+ configASSERT( pcStringToSend );
+ configASSERT( pcStringReceived );
+
+ for( ; ; )
+ {
+ /* Generate the length of the next string to send. */
+ xSendLength++;
+
+ /* The stream buffer is being used to hold variable length data, so
+ * each data item requires sizeof( size_t ) bytes to hold the data's
+ * length, hence the sizeof() in the if() condition below. */
+ if( xSendLength > ( sbSTREAM_BUFFER_LENGTH_BYTES - sizeof( size_t ) ) )
+ {
+ /* Back to a string length of 1. */
+ xSendLength = sizeof( char );
+ }
+
+ memset( pcStringToSend, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
+
+ for( ux = 0; ux < xSendLength; ux++ )
+ {
+ pcStringToSend[ ux ] = cNextChar;
+
+ cNextChar++;
+
+ if( cNextChar > sbASCII_TILDA )
+ {
+ cNextChar = sbASCII_SPACE;
+ }
+ }
+
+ /* Send the generated string to the buffer. */
+ do
+ {
+ ux = xStreamBufferSend( pxStreamBuffers->xEchoClientBuffer, ( void * ) pcStringToSend, xSendLength, xTicksToWait );
+ } while( ux == 0 );
+
+ /* Wait for the string to be echoed back. */
+ memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
+ xStreamBufferReceive( pxStreamBuffers->xEchoServerBuffer, ( void * ) pcStringReceived, xSendLength, portMAX_DELAY );
+
+ prvCheckExpectedState( strcmp( pcStringToSend, pcStringReceived ) == 0 );
+
+ /* Maintain a count of the number of times this code executes so a
+ * check task can determine if this task is still functioning as
+ * expected or not. As there are two client tasks, and the priorities
+ * used are 0 and 1, the task's priority is used as an index into the
+ * loop count array. */
+ ulEchoLoopCounters[ uxIndex ]++;
+
+ /* This stream buffer is just created and deleted to ensure no memory
+ * leaks. */
+ xTempStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
+ vStreamBufferDelete( xTempStreamBuffer );
+
+ /* The following are tests for a stream buffer of size one. */
+ /* Create a buffer of size one. */
+ xTempStreamBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_ONE, sbTRIGGER_LEVEL_1 );
+ /* Ensure that the buffer was created successfully. */
+ configASSERT( xTempStreamBuffer );
+
+ /* Send one byte to the buffer. */
+ ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 1, sbDONT_BLOCK );
+ /* Ensure that the byte was sent successfully. */
+ configASSERT( ux == 1 );
+ /* Try sending another byte to the buffer. */
+ ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 1, sbDONT_BLOCK );
+ /* Make sure that send failed as the buffer is full. */
+ configASSERT( ux == 0 );
+
+ /* Receive one byte from the buffer. */
+ memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
+ ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 1, sbDONT_BLOCK );
+ /* Ensure that the receive was successful. */
+ configASSERT( ux == 1 );
+ /* Ensure that the correct data was received. */
+ configASSERT( pcStringToSend[ 0 ] == pcStringReceived[ 0 ] );
+ /* Try receiving another byte from the buffer. */
+ ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 1, sbDONT_BLOCK );
+ /* Ensure that the receive failed as the buffer is empty. */
+ configASSERT( ux == 0 );
+
+ /* Try sending two bytes to the buffer. Since the size of the
+ * buffer is one, we must not be able to send more than one. */
+ ux = xStreamBufferSend( xTempStreamBuffer, ( void * ) pcStringToSend, ( size_t ) 2, sbDONT_BLOCK );
+ /* Ensure that only one byte was sent. */
+ configASSERT( ux == 1 );
+
+ /* Try receiving two bytes from the buffer. Since the size of the
+ * buffer is one, we must not be able to get more than one. */
+ memset( pcStringReceived, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
+ ux = xStreamBufferReceive( xTempStreamBuffer, ( void * ) pcStringReceived, ( size_t ) 2, sbDONT_BLOCK );
+ /* Ensure that only one byte was received. */
+ configASSERT( ux == 1 );
+ /* Ensure that the correct data was received. */
+ configASSERT( pcStringToSend[ 0 ] == pcStringReceived[ 0 ] );
+
+ /* Delete the buffer. */
+ vStreamBufferDelete( xTempStreamBuffer );
+ }
}
/*-----------------------------------------------------------*/
-static void prvEchoServer( void *pvParameters )
+static void prvEchoServer( void * pvParameters )
{
-size_t xReceivedLength;
-char *pcReceivedString;
-EchoStreamBuffers_t xStreamBuffers;
-TickType_t xTimeOnEntering;
-const TickType_t xTicksToBlock = pdMS_TO_TICKS( 350UL );
-
- /* Prevent compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- /* Create the stream buffer used to send data from the client to the server,
- and the stream buffer used to echo the data from the server back to the
- client. */
- xStreamBuffers.xEchoClientBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
- xStreamBuffers.xEchoServerBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
- configASSERT( xStreamBuffers.xEchoClientBuffer );
- configASSERT( xStreamBuffers.xEchoServerBuffer );
-
- /* Create the buffer into which received strings will be copied. */
- pcReceivedString = ( char * ) pvPortMalloc( sbSTREAM_BUFFER_LENGTH_BYTES );
- configASSERT( pcReceivedString );
-
- /* Don't expect to receive anything yet! */
- xTimeOnEntering = xTaskGetTickCount();
- xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, xTicksToBlock );
- prvCheckExpectedState( ( ( TickType_t ) ( xTaskGetTickCount() - xTimeOnEntering ) ) >= xTicksToBlock );
- prvCheckExpectedState( xReceivedLength == 0 );
-
- /* Now the stream buffers have been created the echo client task can be
- created. If this server task has the higher priority then the client task
- is created at the lower priority - if this server task has the lower
- priority then the client task is created at the higher priority. */
- if( uxTaskPriorityGet( NULL ) == sbLOWER_PRIORITY )
- {
- xTaskCreate( prvEchoClient, "EchoClient", sbSMALLER_STACK_SIZE, ( void * ) &xStreamBuffers, sbHIGHER_PRIORITY, NULL );
- }
- else
- {
- /* Here prvSingleTaskTests() performs various tests on a stream buffer
- that was created dynamically. */
- prvSingleTaskTests( xStreamBuffers.xEchoClientBuffer );
- xTaskCreate( prvEchoClient, "EchoClient", sbSMALLER_STACK_SIZE, ( void * ) &xStreamBuffers, sbLOWER_PRIORITY, NULL );
- }
-
- for( ;; )
- {
- memset( pcReceivedString, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
-
- /* Has any data been sent by the client? */
- xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, portMAX_DELAY );
-
- /* Should always receive data as max delay was used. */
- prvCheckExpectedState( xReceivedLength > 0 );
-
- /* Echo the received data back to the client. */
- xStreamBufferSend( xStreamBuffers.xEchoServerBuffer, ( void * ) pcReceivedString, xReceivedLength, portMAX_DELAY );
- }
+ size_t xReceivedLength;
+ char * pcReceivedString;
+ EchoStreamBuffers_t xStreamBuffers;
+ TickType_t xTimeOnEntering;
+ const TickType_t xTicksToBlock = pdMS_TO_TICKS( 350UL );
+
+ /* Prevent compiler warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ /* Create the stream buffer used to send data from the client to the server,
+ * and the stream buffer used to echo the data from the server back to the
+ * client. */
+ xStreamBuffers.xEchoClientBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
+ xStreamBuffers.xEchoServerBuffer = xStreamBufferCreate( sbSTREAM_BUFFER_LENGTH_BYTES, sbTRIGGER_LEVEL_1 );
+ configASSERT( xStreamBuffers.xEchoClientBuffer );
+ configASSERT( xStreamBuffers.xEchoServerBuffer );
+
+ /* Create the buffer into which received strings will be copied. */
+ pcReceivedString = ( char * ) pvPortMalloc( sbSTREAM_BUFFER_LENGTH_BYTES );
+ configASSERT( pcReceivedString );
+
+ /* Don't expect to receive anything yet! */
+ xTimeOnEntering = xTaskGetTickCount();
+ xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, xTicksToBlock );
+ prvCheckExpectedState( ( ( TickType_t ) ( xTaskGetTickCount() - xTimeOnEntering ) ) >= xTicksToBlock );
+ prvCheckExpectedState( xReceivedLength == 0 );
+
+ /* Now the stream buffers have been created the echo client task can be
+ * created. If this server task has the higher priority then the client task
+ * is created at the lower priority - if this server task has the lower
+ * priority then the client task is created at the higher priority. */
+ if( uxTaskPriorityGet( NULL ) == sbLOWER_PRIORITY )
+ {
+ xTaskCreate( prvEchoClient, "EchoClient", sbSMALLER_STACK_SIZE, ( void * ) &xStreamBuffers, sbHIGHER_PRIORITY, NULL );
+ }
+ else
+ {
+ /* Here prvSingleTaskTests() performs various tests on a stream buffer
+ * that was created dynamically. */
+ prvSingleTaskTests( xStreamBuffers.xEchoClientBuffer );
+ xTaskCreate( prvEchoClient, "EchoClient", sbSMALLER_STACK_SIZE, ( void * ) &xStreamBuffers, sbLOWER_PRIORITY, NULL );
+ }
+
+ for( ; ; )
+ {
+ memset( pcReceivedString, 0x00, sbSTREAM_BUFFER_LENGTH_BYTES );
+
+ /* Has any data been sent by the client? */
+ xReceivedLength = xStreamBufferReceive( xStreamBuffers.xEchoClientBuffer, ( void * ) pcReceivedString, sbSTREAM_BUFFER_LENGTH_BYTES, portMAX_DELAY );
+
+ /* Should always receive data as max delay was used. */
+ prvCheckExpectedState( xReceivedLength > 0 );
+
+ /* Echo the received data back to the client. */
+ xStreamBufferSend( xStreamBuffers.xEchoServerBuffer, ( void * ) pcReceivedString, xReceivedLength, portMAX_DELAY );
+ }
}
/*-----------------------------------------------------------*/
void vPeriodicStreamBufferProcessing( void )
{
-static size_t xNextChar = 0;
-BaseType_t xHigherPriorityTaskWoken = pdFALSE;
-
- /* Called from the tick interrupt hook. If the global stream buffer
- variable is not NULL then the prvInterruptTriggerTest() task expects a byte
- to be sent to the stream buffer on each tick interrupt. */
- if( xInterruptStreamBuffer != NULL )
- {
- /* One character from the pcDataSentFromInterrupt string is sent on each
- interrupt. The task blocked on the stream buffer should not be
- unblocked until the defined trigger level is hit. */
- xStreamBufferSendFromISR( xInterruptStreamBuffer, ( const void * ) &( pcDataSentFromInterrupt[ xNextChar ] ), sizeof( char ), &xHigherPriorityTaskWoken );
-
- if( xNextChar < strlen( pcDataSentFromInterrupt ) )
- {
- xNextChar++;
- }
- }
- else
- {
- /* Start at the beginning of the string being sent again. */
- xNextChar = 0;
- }
+ static size_t xNextChar = 0;
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+
+ /* Called from the tick interrupt hook. If the global stream buffer
+ * variable is not NULL then the prvInterruptTriggerTest() task expects a byte
+ * to be sent to the stream buffer on each tick interrupt. */
+ if( xInterruptStreamBuffer != NULL )
+ {
+ /* One character from the pcDataSentFromInterrupt string is sent on each
+ * interrupt. The task blocked on the stream buffer should not be
+ * unblocked until the defined trigger level is hit. */
+ xStreamBufferSendFromISR( xInterruptStreamBuffer, ( const void * ) &( pcDataSentFromInterrupt[ xNextChar ] ), sizeof( char ), &xHigherPriorityTaskWoken );
+
+ if( xNextChar < strlen( pcDataSentFromInterrupt ) )
+ {
+ xNextChar++;
+ }
+ }
+ else
+ {
+ /* Start at the beginning of the string being sent again. */
+ xNextChar = 0;
+ }
}
/*-----------------------------------------------------------*/
-static void prvInterruptTriggerLevelTest( void *pvParameters )
+static void prvInterruptTriggerLevelTest( void * pvParameters )
{
-StreamBufferHandle_t xStreamBuffer;
-size_t xTriggerLevel = 1, xBytesReceived;
-const size_t xStreamBufferSizeBytes = ( size_t ) 9, xMaxTriggerLevel = ( size_t ) 7, xMinTriggerLevel = ( size_t ) 2;
-const TickType_t xReadBlockTime = 5, xCycleBlockTime = pdMS_TO_TICKS( 100 );
-uint8_t ucRxData[ 9 ];
-BaseType_t xErrorDetected = pdFALSE;
-#ifndef configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN
- const size_t xAllowableMargin = ( size_t ) 0;
-#else
- const size_t xAllowableMargin = ( size_t ) configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN;
-#endif
-
- /* Remove compiler warning about unused parameter. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- for( xTriggerLevel = xMinTriggerLevel; xTriggerLevel < xMaxTriggerLevel; xTriggerLevel++ )
- {
- /* This test is very time sensitive so delay at the beginning to ensure
- the rest of the system is up and running before starting. Delay between
- each loop to ensure the interrupt that sends to the stream buffer
- detects it needs to start sending from the start of the strin again.. */
- vTaskDelay( xCycleBlockTime );
-
- /* Create the stream buffer that will be used from inside the tick
- interrupt. */
- memset( ucRxData, 0x00, sizeof( ucRxData ) );
- xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
- configASSERT( xStreamBuffer );
-
- /* Now the stream buffer has been created it can be assigned to the
- file scope variable, which will allow the tick interrupt to start
- using it. */
- taskENTER_CRITICAL();
- {
- xInterruptStreamBuffer = xStreamBuffer;
- }
- taskEXIT_CRITICAL();
-
- xBytesReceived = xStreamBufferReceive( xStreamBuffer, ( void * ) ucRxData, sizeof( ucRxData ), xReadBlockTime );
-
- /* Set the file scope variable back to NULL so the interrupt doesn't
- try to use it again. */
- taskENTER_CRITICAL();
- {
- xInterruptStreamBuffer = NULL;
- }
- taskEXIT_CRITICAL();
-
- /* Now check the number of bytes received equals the trigger level,
- except in the case that the read timed out before the trigger level
- was reached. */
- if( xTriggerLevel > xReadBlockTime )
- {
- /* Trigger level was greater than the block time so expect to
- time out having received xReadBlockTime bytes. */
- if( xBytesReceived > xReadBlockTime )
- {
- /* Received more bytes than expected. That could happen if
- this task unblocked at the right time, but an interrupt
- added another byte to the stream buffer before this task was
- able to run. */
- if( ( xBytesReceived - xReadBlockTime ) > xAllowableMargin )
- {
- xErrorDetected = pdTRUE;
- }
- }
- else if( xReadBlockTime != xBytesReceived )
- {
- /* It is possible the interrupt placed an item in the stream
- buffer before this task called xStreamBufferReceive(), but
- if that is the case then xBytesReceived will only every be
- 0 as the interrupt will only have executed once. */
- if( xBytesReceived != 1 )
- {
- xErrorDetected = pdTRUE;
- }
- }
- }
- else if( xTriggerLevel < xReadBlockTime )
- {
- /* Trigger level was less than the block time so we expect to
- have received the trigger level number of bytes - could be more
- though depending on other activity between the task being
- unblocked and the task reading the number of bytes received. It
- could also be less if the interrupt already put something in the
- stream buffer before this task attempted to read it - in which
- case the task would have returned the available bytes immediately
- without ever blocking - in that case the bytes received will
- only ever be 1 as the interrupt would not have executed more
- than one in that time unless this task has too low a priority. */
- if( xBytesReceived < xTriggerLevel )
- {
- if( xBytesReceived != 1 )
- {
- xErrorDetected = pdTRUE;
- }
- }
- else if( ( xBytesReceived - xTriggerLevel ) > xAllowableMargin )
- {
- xErrorDetected = pdTRUE;
- }
- }
- else
- {
- /* The trigger level equalled the block time, so expect to
- receive no greater than the block time. It could also be less
- if the interrupt already put something in the stream buffer
- before this task attempted to read it - in which case the task
- would have returned the available bytes immediately without ever
- blocking - in that case the bytes received would only ever be 1
- because the interrupt is not going to execute twice in that time
- unless this task is running a too low a priority. */
- if( xBytesReceived < xReadBlockTime )
- {
- if( xBytesReceived != 1 )
- {
- xErrorDetected = pdTRUE;
- }
- }
- else if( ( xBytesReceived - xReadBlockTime ) > xAllowableMargin )
- {
- xErrorDetected = pdTRUE;
- }
- }
-
- if( xBytesReceived > sizeof( ucRxData ) )
- {
- xErrorDetected = pdTRUE;
- }
- else if( memcmp( ( void * ) ucRxData, ( const void * ) pcDataSentFromInterrupt, xBytesReceived ) != 0 )
- {
- /* Received data didn't match that expected. */
- xErrorDetected = pdTRUE;
- }
-
- if( xErrorDetected == pdFALSE )
- {
- /* Increment the cycle counter so the 'check' task knows this test
- is still running without error. */
- ulInterruptTriggerCounter++;
- }
-
- /* Tidy up ready for the next loop. */
- vStreamBufferDelete( xStreamBuffer );
- }
- }
+ StreamBufferHandle_t xStreamBuffer;
+ size_t xTriggerLevel = 1, xBytesReceived;
+ const size_t xStreamBufferSizeBytes = ( size_t ) 9, xMaxTriggerLevel = ( size_t ) 7, xMinTriggerLevel = ( size_t ) 2;
+ const TickType_t xReadBlockTime = 5, xCycleBlockTime = pdMS_TO_TICKS( 100 );
+ uint8_t ucRxData[ 9 ];
+ BaseType_t xErrorDetected = pdFALSE;
+
+ #ifndef configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN
+ const size_t xAllowableMargin = ( size_t ) 0;
+ #else
+ const size_t xAllowableMargin = ( size_t ) configSTREAM_BUFFER_TRIGGER_LEVEL_TEST_MARGIN;
+ #endif
+
+ /* Remove compiler warning about unused parameter. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ for( xTriggerLevel = xMinTriggerLevel; xTriggerLevel < xMaxTriggerLevel; xTriggerLevel++ )
+ {
+ /* This test is very time sensitive so delay at the beginning to ensure
+ * the rest of the system is up and running before starting. Delay between
+ * each loop to ensure the interrupt that sends to the stream buffer
+ * detects it needs to start sending from the start of the strin again.. */
+ vTaskDelay( xCycleBlockTime );
+
+ /* Create the stream buffer that will be used from inside the tick
+ * interrupt. */
+ memset( ucRxData, 0x00, sizeof( ucRxData ) );
+ xStreamBuffer = xStreamBufferCreate( xStreamBufferSizeBytes, xTriggerLevel );
+ configASSERT( xStreamBuffer );
+
+ /* Now the stream buffer has been created it can be assigned to the
+ * file scope variable, which will allow the tick interrupt to start
+ * using it. */
+ taskENTER_CRITICAL();
+ {
+ xInterruptStreamBuffer = xStreamBuffer;
+ }
+ taskEXIT_CRITICAL();
+
+ xBytesReceived = xStreamBufferReceive( xStreamBuffer, ( void * ) ucRxData, sizeof( ucRxData ), xReadBlockTime );
+
+ /* Set the file scope variable back to NULL so the interrupt doesn't
+ * try to use it again. */
+ taskENTER_CRITICAL();
+ {
+ xInterruptStreamBuffer = NULL;
+ }
+ taskEXIT_CRITICAL();
+
+ /* Now check the number of bytes received equals the trigger level,
+ * except in the case that the read timed out before the trigger level
+ * was reached. */
+ if( xTriggerLevel > xReadBlockTime )
+ {
+ /* Trigger level was greater than the block time so expect to
+ * time out having received xReadBlockTime bytes. */
+ if( xBytesReceived > xReadBlockTime )
+ {
+ /* Received more bytes than expected. That could happen if
+ * this task unblocked at the right time, but an interrupt
+ * added another byte to the stream buffer before this task was
+ * able to run. */
+ if( ( xBytesReceived - xReadBlockTime ) > xAllowableMargin )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+ else if( xReadBlockTime != xBytesReceived )
+ {
+ /* It is possible the interrupt placed an item in the stream
+ * buffer before this task called xStreamBufferReceive(), but
+ * if that is the case then xBytesReceived will only every be
+ * 0 as the interrupt will only have executed once. */
+ if( xBytesReceived != 1 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+ }
+ else if( xTriggerLevel < xReadBlockTime )
+ {
+ /* Trigger level was less than the block time so we expect to
+ * have received the trigger level number of bytes - could be more
+ * though depending on other activity between the task being
+ * unblocked and the task reading the number of bytes received. It
+ * could also be less if the interrupt already put something in the
+ * stream buffer before this task attempted to read it - in which
+ * case the task would have returned the available bytes immediately
+ * without ever blocking - in that case the bytes received will
+ * only ever be 1 as the interrupt would not have executed more
+ * than one in that time unless this task has too low a priority. */
+ if( xBytesReceived < xTriggerLevel )
+ {
+ if( xBytesReceived != 1 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+ else if( ( xBytesReceived - xTriggerLevel ) > xAllowableMargin )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+ else
+ {
+ /* The trigger level equalled the block time, so expect to
+ * receive no greater than the block time. It could also be less
+ * if the interrupt already put something in the stream buffer
+ * before this task attempted to read it - in which case the task
+ * would have returned the available bytes immediately without ever
+ * blocking - in that case the bytes received would only ever be 1
+ * because the interrupt is not going to execute twice in that time
+ * unless this task is running a too low a priority. */
+ if( xBytesReceived < xReadBlockTime )
+ {
+ if( xBytesReceived != 1 )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+ else if( ( xBytesReceived - xReadBlockTime ) > xAllowableMargin )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ }
+
+ if( xBytesReceived > sizeof( ucRxData ) )
+ {
+ xErrorDetected = pdTRUE;
+ }
+ else if( memcmp( ( void * ) ucRxData, ( const void * ) pcDataSentFromInterrupt, xBytesReceived ) != 0 )
+ {
+ /* Received data didn't match that expected. */
+ xErrorDetected = pdTRUE;
+ }
+
+ if( xErrorDetected == pdFALSE )
+ {
+ /* Increment the cycle counter so the 'check' task knows this test
+ * is still running without error. */
+ ulInterruptTriggerCounter++;
+ }
+
+ /* Tidy up ready for the next loop. */
+ vStreamBufferDelete( xStreamBuffer );
+ }
+ }
}
/*-----------------------------------------------------------*/
BaseType_t xAreStreamBufferTasksStillRunning( void )
{
-static uint32_t ulLastEchoLoopCounters[ sbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
-static uint32_t ulLastNonBlockingRxCounter = 0;
-static uint32_t ulLastInterruptTriggerCounter = 0;
-BaseType_t x;
-
- for( x = 0; x < sbNUMBER_OF_ECHO_CLIENTS; x++ )
- {
- if( ulLastEchoLoopCounters[ x ] == ulEchoLoopCounters[ x ] )
- {
- xErrorStatus = pdFAIL;
- }
- else
- {
- ulLastEchoLoopCounters[ x ] = ulEchoLoopCounters[ x ];
- }
- }
-
- if( ulNonBlockingRxCounter == ulLastNonBlockingRxCounter )
- {
- xErrorStatus = pdFAIL;
- }
- else
- {
- ulLastNonBlockingRxCounter = ulNonBlockingRxCounter;
- }
-
- if( ulLastInterruptTriggerCounter == ulInterruptTriggerCounter )
- {
- xErrorStatus = pdFAIL;
- }
- else
- {
- ulLastInterruptTriggerCounter = ulInterruptTriggerCounter;
- }
-
- #if( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- static uint32_t ulLastSenderLoopCounters[ sbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
-
- for( x = 0; x < sbNUMBER_OF_SENDER_TASKS; x++ )
- {
- if( ulLastSenderLoopCounters[ x ] == ulSenderLoopCounters[ x ] )
- {
- xErrorStatus = pdFAIL;
- }
- else
- {
- ulLastSenderLoopCounters[ x ] = ulSenderLoopCounters[ x ];
- }
- }
- }
- #endif /* configSUPPORT_STATIC_ALLOCATION */
-
- return xErrorStatus;
+ static uint32_t ulLastEchoLoopCounters[ sbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
+ static uint32_t ulLastNonBlockingRxCounter = 0;
+ static uint32_t ulLastInterruptTriggerCounter = 0;
+ BaseType_t x;
+
+ for( x = 0; x < sbNUMBER_OF_ECHO_CLIENTS; x++ )
+ {
+ if( ulLastEchoLoopCounters[ x ] == ulEchoLoopCounters[ x ] )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastEchoLoopCounters[ x ] = ulEchoLoopCounters[ x ];
+ }
+ }
+
+ if( ulNonBlockingRxCounter == ulLastNonBlockingRxCounter )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastNonBlockingRxCounter = ulNonBlockingRxCounter;
+ }
+
+ if( ulLastInterruptTriggerCounter == ulInterruptTriggerCounter )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastInterruptTriggerCounter = ulInterruptTriggerCounter;
+ }
+
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ static uint32_t ulLastSenderLoopCounters[ sbNUMBER_OF_ECHO_CLIENTS ] = { 0 };
+
+ for( x = 0; x < sbNUMBER_OF_SENDER_TASKS; x++ )
+ {
+ if( ulLastSenderLoopCounters[ x ] == ulSenderLoopCounters[ x ] )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastSenderLoopCounters[ x ] = ulSenderLoopCounters[ x ];
+ }
+ }
+ }
+ #endif /* configSUPPORT_STATIC_ALLOCATION */
+
+ return xErrorStatus;
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c b/FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c
index 233febb72..0692bfb81 100644
--- a/FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c
+++ b/FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c
@@ -48,13 +48,13 @@
/* Demo app includes. */
#include "StreamBufferInterrupt.h"
-#define sbiSTREAM_BUFFER_LENGTH_BYTES ( ( size_t ) 100 )
-#define sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 ( ( BaseType_t ) 10 )
+#define sbiSTREAM_BUFFER_LENGTH_BYTES ( ( size_t ) 100 )
+#define sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 ( ( BaseType_t ) 10 )
/*-----------------------------------------------------------*/
/* Implements the task that receives a stream of bytes from the interrupt. */
-static void prvReceivingTask( void *pvParameters );
+static void prvReceivingTask( void * pvParameters );
/*-----------------------------------------------------------*/
@@ -62,167 +62,168 @@ static void prvReceivingTask( void *pvParameters );
static StreamBufferHandle_t xStreamBuffer = NULL;
/* The string that is sent from the interrupt to the task four bytes at a
-time. Must be multiple of 4 bytes long as the ISR sends 4 bytes at a time*/
+ * time. Must be multiple of 4 bytes long as the ISR sends 4 bytes at a time*/
static const char * pcStringToSend = "_____Hello FreeRTOS_____";
/* The string to task is looking for, which must be a substring of
-pcStringToSend. */
+ * pcStringToSend. */
static const char * pcStringToReceive = "Hello FreeRTOS";
/* Set to pdFAIL if anything unexpected happens. */
static BaseType_t xDemoStatus = pdPASS;
/* Incremented each time pcStringToReceive is correctly received, provided no
-errors have occurred. Used so the check task can check this task is still
-running as expected. */
+ * errors have occurred. Used so the check task can check this task is still
+ * running as expected. */
static uint32_t ulCycleCount = 0;
/*-----------------------------------------------------------*/
void vStartStreamBufferInterruptDemo( void )
{
- /* Create the stream buffer that sends data from the interrupt to the
- task, and create the task. */
- xStreamBuffer = xStreamBufferCreate( /* The buffer length in bytes. */
- sbiSTREAM_BUFFER_LENGTH_BYTES,
- /* The stream buffer's trigger level. */
- sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 );
-
- xTaskCreate( prvReceivingTask, /* The function that implements the task. */
- "StrIntRx", /* Human readable name for the task. */
- configMINIMAL_STACK_SIZE, /* Stack size (in words!). */
- NULL, /* Task parameter is not used. */
- tskIDLE_PRIORITY + 2, /* The priority at which the task is created. */
- NULL ); /* No use for the task handle. */
+ /* Create the stream buffer that sends data from the interrupt to the
+ * task, and create the task. */
+ xStreamBuffer = xStreamBufferCreate( /* The buffer length in bytes. */
+ sbiSTREAM_BUFFER_LENGTH_BYTES,
+ /* The stream buffer's trigger level. */
+ sbiSTREAM_BUFFER_TRIGGER_LEVEL_10 );
+
+ xTaskCreate( prvReceivingTask, /* The function that implements the task. */
+ "StrIntRx", /* Human readable name for the task. */
+ configMINIMAL_STACK_SIZE, /* Stack size (in words!). */
+ NULL, /* Task parameter is not used. */
+ tskIDLE_PRIORITY + 2, /* The priority at which the task is created. */
+ NULL ); /* No use for the task handle. */
}
/*-----------------------------------------------------------*/
-static void prvReceivingTask( void *pvParameters )
+static void prvReceivingTask( void * pvParameters )
{
-char cRxBuffer[ 20 ];
-BaseType_t xNextByte = 0;
-
- /* Remove warning about unused parameters. */
- ( void ) pvParameters;
-
- /* Make sure the string will fit in the Rx buffer, including the NULL
- terminator. */
- configASSERT( sizeof( cRxBuffer ) > strlen( pcStringToReceive ) );
-
- /* Make sure the stream buffer has been created. */
- configASSERT( xStreamBuffer != NULL );
-
- /* Start with the Rx buffer in a known state. */
- memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
-
- for( ;; )
- {
- /* Keep receiving characters until the end of the string is received.
- Note: An infinite block time is used to simplify the example. Infinite
- block times are not recommended in production code as they do not allow
- for error recovery. */
- xStreamBufferReceive( /* The stream buffer data is being received from. */
- xStreamBuffer,
- /* Where to place received data. */
- ( void * ) &( cRxBuffer[ xNextByte ] ),
- /* The number of bytes to receive. */
- sizeof( char ),
- /* The time to wait for the next data if the buffer
- is empty. */
- portMAX_DELAY );
-
- /* If xNextByte is 0 then this task is looking for the start of the
- string, which is 'H'. */
- if( xNextByte == 0 )
- {
- if( cRxBuffer[ xNextByte ] == 'H' )
- {
- /* The start of the string has been found. Now receive
- characters until the end of the string is found. */
- xNextByte++;
- }
- }
- else
- {
- /* Receiving characters while looking for the end of the string,
- which is an 'S'. */
- if( cRxBuffer[ xNextByte ] == 'S' )
- {
- /* The string has now been received. Check its validity. */
- if( strcmp( cRxBuffer, pcStringToReceive ) != 0 )
- {
- xDemoStatus = pdFAIL;
- }
-
- /* Return to start looking for the beginning of the string
- again. */
- memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
- xNextByte = 0;
-
- /* Increment the cycle count as an indication to the check task
- that this demo is still running. */
- if( xDemoStatus == pdPASS )
- {
- ulCycleCount++;
- }
- }
- else
- {
- /* Receive the next character the next time around, while
- continuing to look for the end of the string. */
- xNextByte++;
-
- configASSERT( ( size_t ) xNextByte < sizeof( cRxBuffer ) );
- }
- }
- }
+ char cRxBuffer[ 20 ];
+ BaseType_t xNextByte = 0;
+
+ /* Remove warning about unused parameters. */
+ ( void ) pvParameters;
+
+ /* Make sure the string will fit in the Rx buffer, including the NULL
+ * terminator. */
+ configASSERT( sizeof( cRxBuffer ) > strlen( pcStringToReceive ) );
+
+ /* Make sure the stream buffer has been created. */
+ configASSERT( xStreamBuffer != NULL );
+
+ /* Start with the Rx buffer in a known state. */
+ memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
+
+ for( ; ; )
+ {
+ /* Keep receiving characters until the end of the string is received.
+ * Note: An infinite block time is used to simplify the example. Infinite
+ * block times are not recommended in production code as they do not allow
+ * for error recovery. */
+ xStreamBufferReceive( /* The stream buffer data is being received from. */
+ xStreamBuffer,
+ /* Where to place received data. */
+ ( void * ) &( cRxBuffer[ xNextByte ] ),
+ /* The number of bytes to receive. */
+ sizeof( char ),
+
+ /* The time to wait for the next data if the buffer
+ * is empty. */
+ portMAX_DELAY );
+
+ /* If xNextByte is 0 then this task is looking for the start of the
+ * string, which is 'H'. */
+ if( xNextByte == 0 )
+ {
+ if( cRxBuffer[ xNextByte ] == 'H' )
+ {
+ /* The start of the string has been found. Now receive
+ * characters until the end of the string is found. */
+ xNextByte++;
+ }
+ }
+ else
+ {
+ /* Receiving characters while looking for the end of the string,
+ * which is an 'S'. */
+ if( cRxBuffer[ xNextByte ] == 'S' )
+ {
+ /* The string has now been received. Check its validity. */
+ if( strcmp( cRxBuffer, pcStringToReceive ) != 0 )
+ {
+ xDemoStatus = pdFAIL;
+ }
+
+ /* Return to start looking for the beginning of the string
+ * again. */
+ memset( cRxBuffer, 0x00, sizeof( cRxBuffer ) );
+ xNextByte = 0;
+
+ /* Increment the cycle count as an indication to the check task
+ * that this demo is still running. */
+ if( xDemoStatus == pdPASS )
+ {
+ ulCycleCount++;
+ }
+ }
+ else
+ {
+ /* Receive the next character the next time around, while
+ * continuing to look for the end of the string. */
+ xNextByte++;
+
+ configASSERT( ( size_t ) xNextByte < sizeof( cRxBuffer ) );
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
void vBasicStreamBufferSendFromISR( void )
{
-static size_t xNextByteToSend = 0;
-const BaseType_t xCallsBetweenSends = 100, xBytesToSend = 4;
-static BaseType_t xCallCount = 0;
-
- /* Is it time to write to the stream buffer again? */
- xCallCount++;
- if( xCallCount > xCallsBetweenSends )
- {
- xCallCount = 0;
-
- /* Send the next four bytes to the stream buffer. */
- xStreamBufferSendFromISR( xStreamBuffer,
- ( const void * ) ( pcStringToSend + xNextByteToSend ),
- xBytesToSend,
- NULL );
-
- /* Send the next four bytes the next time around, wrapping to the start
- of the string if necessary. */
- xNextByteToSend += xBytesToSend;
-
- if( xNextByteToSend >= strlen( pcStringToSend ) )
- {
- xNextByteToSend = 0;
- }
- }
+ static size_t xNextByteToSend = 0;
+ const BaseType_t xCallsBetweenSends = 100, xBytesToSend = 4;
+ static BaseType_t xCallCount = 0;
+
+ /* Is it time to write to the stream buffer again? */
+ xCallCount++;
+
+ if( xCallCount > xCallsBetweenSends )
+ {
+ xCallCount = 0;
+
+ /* Send the next four bytes to the stream buffer. */
+ xStreamBufferSendFromISR( xStreamBuffer,
+ ( const void * ) ( pcStringToSend + xNextByteToSend ),
+ xBytesToSend,
+ NULL );
+
+ /* Send the next four bytes the next time around, wrapping to the start
+ * of the string if necessary. */
+ xNextByteToSend += xBytesToSend;
+
+ if( xNextByteToSend >= strlen( pcStringToSend ) )
+ {
+ xNextByteToSend = 0;
+ }
+ }
}
/*-----------------------------------------------------------*/
BaseType_t xIsInterruptStreamBufferDemoStillRunning( void )
{
-uint32_t ulLastCycleCount = 0;
-
- /* Check the demo is still running. */
- if( ulLastCycleCount == ulCycleCount )
- {
- xDemoStatus = pdFAIL;
- }
- else
- {
- ulLastCycleCount = ulCycleCount;
- }
-
- return xDemoStatus;
+ uint32_t ulLastCycleCount = 0;
+
+ /* Check the demo is still running. */
+ if( ulLastCycleCount == ulCycleCount )
+ {
+ xDemoStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastCycleCount = ulCycleCount;
+ }
+
+ return xDemoStatus;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/TaskNotify.c b/FreeRTOS/Demo/Common/Minimal/TaskNotify.c
index 3a334da99..832ecebb9 100644
--- a/FreeRTOS/Demo/Common/Minimal/TaskNotify.c
+++ b/FreeRTOS/Demo/Common/Minimal/TaskNotify.c
@@ -43,24 +43,24 @@
/* Allow parameters to be overridden on a demo by demo basis. */
#ifndef notifyNOTIFIED_TASK_STACK_SIZE
- #define notifyNOTIFIED_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define notifyNOTIFIED_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
-#define notifyTASK_PRIORITY ( tskIDLE_PRIORITY )
+#define notifyTASK_PRIORITY ( tskIDLE_PRIORITY )
/* Constants used in tests when setting/clearing bits. */
-#define notifyUINT32_MAX ( ( uint32_t ) 0xffffffff )
-#define notifyUINT32_HIGH_BYTE ( ( uint32_t ) 0xff000000 )
-#define notifyUINT32_LOW_BYTE ( ( uint32_t ) 0x000000ff )
+#define notifyUINT32_MAX ( ( uint32_t ) 0xffffffff )
+#define notifyUINT32_HIGH_BYTE ( ( uint32_t ) 0xff000000 )
+#define notifyUINT32_LOW_BYTE ( ( uint32_t ) 0x000000ff )
-#define notifySUSPENDED_TEST_TIMER_PERIOD pdMS_TO_TICKS( 50 )
+#define notifySUSPENDED_TEST_TIMER_PERIOD pdMS_TO_TICKS( 50 )
/*-----------------------------------------------------------*/
/*
* Implementation of the task that gets notified.
*/
-static void prvNotifiedTask( void *pvParameters );
+static void prvNotifiedTask( void * pvParameters );
/*
* Performs a few initial tests that can be done prior to creating the second
@@ -98,8 +98,8 @@ static volatile uint32_t ulNotifyCycleCount = 0;
static TaskHandle_t xTaskToNotify = NULL;
/* Used to count the notifications sent to the task from a software timer and
-the number of notifications received by the task from the software timer. The
-two should stay synchronised. */
+ * the number of notifications received by the task from the software timer. The
+ * two should stay synchronised. */
static uint32_t ulTimerNotificationsReceived = 0UL, ulTimerNotificationsSent = 0UL;
/* The timer used to notify the task. */
@@ -110,623 +110,612 @@ static size_t uxNextRand = 0;
/*-----------------------------------------------------------*/
-void vStartTaskNotifyTask( void )
+void vStartTaskNotifyTask( void )
{
- /* Create the task that performs some tests by itself, then loops around
- being notified by both a software timer and an interrupt. */
- xTaskCreate( prvNotifiedTask, /* Function that implements the task. */
- "Notified", /* Text name for the task - for debugging only - not used by the kernel. */
- notifyNOTIFIED_TASK_STACK_SIZE, /* Task's stack size in words, not bytes!. */
- NULL, /* Task parameter, not used in this case. */
- notifyTASK_PRIORITY, /* Task priority, 0 is the lowest. */
- &xTaskToNotify ); /* Used to pass a handle to the task out is needed, otherwise set to NULL. */
-
- /* Pseudo seed the random number generator. */
- uxNextRand = ( size_t ) prvRand;
+ /* Create the task that performs some tests by itself, then loops around
+ * being notified by both a software timer and an interrupt. */
+ xTaskCreate( prvNotifiedTask, /* Function that implements the task. */
+ "Notified", /* Text name for the task - for debugging only - not used by the kernel. */
+ notifyNOTIFIED_TASK_STACK_SIZE, /* Task's stack size in words, not bytes!. */
+ NULL, /* Task parameter, not used in this case. */
+ notifyTASK_PRIORITY, /* Task priority, 0 is the lowest. */
+ &xTaskToNotify ); /* Used to pass a handle to the task out is needed, otherwise set to NULL. */
+
+ /* Pseudo seed the random number generator. */
+ uxNextRand = ( size_t ) prvRand;
}
/*-----------------------------------------------------------*/
static void prvSingleTaskTests( void )
{
-const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
-BaseType_t xReturned;
-uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
-TickType_t xTimeOnEntering;
-const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
-const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
-TimerHandle_t xSingleTaskTimer;
-
+ const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
+ BaseType_t xReturned;
+ uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
+ TickType_t xTimeOnEntering;
+ const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
+ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
+ TimerHandle_t xSingleTaskTimer;
+
+
+ /* ------------------------------------------------------------------------
+ * Check blocking when there are no notifications. */
+ xTimeOnEntering = xTaskGetTickCount();
+ xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Should have blocked for the entire block time. */
+ if( ( xTaskGetTickCount() - xTimeOnEntering ) < xTicksToWait )
+ {
+ xErrorStatus = pdFAIL;
+ }
+
+ configASSERT( xReturned == pdFAIL );
+ configASSERT( ulNotifiedValue == 0UL );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+
+
+ /* ------------------------------------------------------------------------
+ * Check no blocking when notifications are pending. First notify itself -
+ * this would not be a normal thing to do and is done here for test purposes
+ * only. */
+ xReturned = xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
+
+ /* Even through the 'without overwrite' action was used the update should
+ * have been successful. */
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* No bits should have been pending previously. */
+ configASSERT( ulPreviousValue == 0 );
+ ( void ) ulPreviousValue;
+
+ /* The task should now have a notification pending, and so not time out. */
+ xTimeOnEntering = xTaskGetTickCount();
+ xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
+
+ if( ( xTaskGetTickCount() - xTimeOnEntering ) >= xTicksToWait )
+ {
+ xErrorStatus = pdFAIL;
+ }
+
+ /* The task should have been notified, and the notified value should
+ * be equal to ulFirstNotifiedConst. */
+ configASSERT( xReturned == pdPASS );
+ configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+ /* Incremented to show the task is still running. */
+ ulNotifyCycleCount++;
+
+
+
+ /*-------------------------------------------------------------------------
+ * Check the non-overwriting functionality. The notification is done twice
+ * using two different notification values. The action says don't overwrite so
+ * only the first notification should pass and the value read back should also
+ * be that used with the first notification. */
+ xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithoutOverwrite );
+ configASSERT( xReturned == pdFAIL );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Waiting for the notification should now return immediately so a block
+ * time of zero is used. */
+ xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+
+ configASSERT( xReturned == pdPASS );
+ configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+
+
+ /*-------------------------------------------------------------------------
+ * Do the same again, only this time use the overwriting version. This time
+ * both notifications should pass, and the value written the second time should
+ * overwrite the value written the first time, and so be the value that is read
+ * back. */
+ xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
+ ( void ) ulNotifiedValue;
+
+
+
+ /*-------------------------------------------------------------------------
+ * Check notifications with no action pass without updating the value. Even
+ * though ulFirstNotifiedConst is used as the value the value read back should
+ * remain at ulSecondNotifiedConst. */
+ xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eNoAction );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+ configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
+ ( void ) ulNotifiedValue; /* In case configASSERT() is not defined. */
+
+ /*-------------------------------------------------------------------------
+ * Check incrementing values. Send ulMaxLoop increment notifications, then
+ * ensure the received value is as expected - which should be
+ * ulSecondNotificationValueConst plus how ever many times to loop iterated. */
+ for( ulLoop = 0; ulLoop < ulMaxLoops; ulLoop++ )
+ {
+ xReturned = xTaskNotify( xTaskToNotify, 0, eIncrement );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ }
+
+ xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdPASS );
+ configASSERT( ulNotifiedValue == ( ulSecondNotifiedValueConst + ulMaxLoops ) );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+ /* Should not be any notifications pending now. */
+ xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdFAIL );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+
+
+ /*-------------------------------------------------------------------------
+ * Check all bits can be set by notifying the task with one additional bit set
+ * on each notification, and exiting the loop when all the bits are found to be
+ * set. As there are 32-bits the loop should execute 32 times before all the
+ * bits are found to be set. */
+ ulNotifyingValue = 0x01;
+ ulLoop = 0;
+
+ /* Start with all bits clear. */
+ xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+
+ do
+ {
+ /* Set the next bit in the task's notified value. */
+ xTaskNotify( xTaskToNotify, ulNotifyingValue, eSetBits );
+
+ /* Wait for the notified value - which of course will already be
+ * available. Don't clear the bits on entry or exit as this loop is exited
+ * when all the bits are set. */
+ xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ ulLoop++;
+
+ /* Use the next bit on the next iteration around this loop. */
+ ulNotifyingValue <<= 1UL;
+ } while( ulNotifiedValue != notifyUINT32_MAX );
+
+ /* As a 32-bit value was used the loop should have executed 32 times before
+ * all the bits were set. */
+ configASSERT( ulLoop == 32 );
+
+
+
+ /*-------------------------------------------------------------------------
+ * Check bits are cleared on entry but not on exit when a notification fails
+ * to arrive before timing out - both with and without a timeout value. Wait
+ * for the notification again - but this time it is not given by anything and
+ * should return pdFAIL. The parameters are set to clear bit zero on entry and
+ * bit one on exit. As no notification was received only the bit cleared on
+ * entry should actually get cleared. */
+ xReturned = xTaskNotifyWait( ulBit0, ulBit1, &ulNotifiedValue, xTicksToWait );
+ configASSERT( xReturned == pdFAIL );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+ /* Notify the task with no action so as not to update the bits even though
+ * notifyUINT32_MAX is used as the notification value. */
+ xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eNoAction );
+
+ /* Reading back the value should should find bit 0 is clear, as this was
+ * cleared on entry, but bit 1 is not clear as it will not have been cleared on
+ * exit as no notification was received. */
+ xReturned = xTaskNotifyWait( 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdPASS );
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+
+
+ /*-------------------------------------------------------------------------
+ * Now try clearing the bit on exit. For that to happen a notification must be
+ * received, so the task is notified first. */
+ xTaskNotify( xTaskToNotify, 0, eNoAction );
+ xTaskNotifyWait( 0x00, ulBit1, &ulNotifiedValue, 0 );
+
+ /* However as the bit is cleared on exit, after the returned notification
+ * value is set, the returned notification value should not have the bit
+ * cleared... */
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
+
+ /* ...but reading the value back again should find that the bit was indeed
+ * cleared internally. The returned value should be pdFAIL however as nothing
+ * has notified the task in the mean time. */
+ xReturned = xTaskNotifyWait( 0x00, 0x00, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdFAIL );
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+
+
+
+ /*-------------------------------------------------------------------------
+ * Now try querying the previous value while notifying a task. */
+ xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
- /* ------------------------------------------------------------------------
- Check blocking when there are no notifications. */
- xTimeOnEntering = xTaskGetTickCount();
- xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
+ /* Clear all bits. */
+ xTaskNotifyWait( 0x00, notifyUINT32_MAX, &ulNotifiedValue, 0 );
+ xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );
+ configASSERT( ulPreviousValue == 0 );
- /* Should have blocked for the entire block time. */
- if( ( xTaskGetTickCount() - xTimeOnEntering ) < xTicksToWait )
- {
- xErrorStatus = pdFAIL;
- }
- configASSERT( xReturned == pdFAIL );
- configASSERT( ulNotifiedValue == 0UL );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
+ ulExpectedValue = 0;
+
+ for( ulLoop = 0x01; ulLoop < 0x80UL; ulLoop <<= 1UL )
+ {
+ /* Set the next bit up, and expect to receive the last bits set (so
+ * the previous value will not yet have the bit being set this time
+ * around). */
+ xTaskNotifyAndQuery( xTaskToNotify, ulLoop, eSetBits, &ulPreviousValue );
+ configASSERT( ulExpectedValue == ulPreviousValue );
+ ulExpectedValue |= ulLoop;
+ }
+
+ /* ------------------------------------------------------------------------
+ * Clear the previous notifications. */
+ xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+
+ /* The task should not have any notifications pending, so an attempt to clear
+ * the notification state should fail. */
+ configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
+
+ /* Get the task to notify itself. This is not a normal thing to do, and is
+ * only done here for test purposes. */
+ xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
+
+ /* Now the notification state should be eNotified, so it should now be
+ * possible to clear the notification state. */
+ configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
+ configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
+ /* ------------------------------------------------------------------------
+ * Clear bits in the notification value. */
- /* ------------------------------------------------------------------------
- Check no blocking when notifications are pending. First notify itself -
- this would not be a normal thing to do and is done here for test purposes
- only. */
- xReturned = xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
+ /* Get the task to set all bits its own notification value. This is not a
+ * normal thing to do, and is only done here for test purposes. */
+ xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eSetBits );
- /* Even through the 'without overwrite' action was used the update should
- have been successful. */
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
+ /* Now clear the top bytes - the returned value from the first call should
+ * indicate that previously all bits were set. */
+ configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_HIGH_BYTE ) == notifyUINT32_MAX );
- /* No bits should have been pending previously. */
- configASSERT( ulPreviousValue == 0 );
- ( void ) ulPreviousValue;
+ /* Next clear the bottom bytes - the returned value this time should indicate
+ * that the top byte was clear (before the bottom byte was cleared. */
+ configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_LOW_BYTE ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE ) );
+
+ /* Next clear all bytes - the returned value should indicate that previously the
+ * high and low bytes were clear. */
+ configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE & ~notifyUINT32_LOW_BYTE ) );
+
+ /* Now all bits should be clear. */
+ configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );
+ configASSERT( ulTaskNotifyValueClear( xTaskToNotify, 0UL ) == 0 );
+ configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );
+
+ /* Now the notification state should be eNotified, so it should now be
+ * possible to clear the notification state. */
+ configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
+ configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
- /* The task should now have a notification pending, and so not time out. */
- xTimeOnEntering = xTaskGetTickCount();
- xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
- if( ( xTaskGetTickCount() - xTimeOnEntering ) >= xTicksToWait )
- {
- xErrorStatus = pdFAIL;
- }
- /* The task should have been notified, and the notified value should
- be equal to ulFirstNotifiedConst. */
- configASSERT( xReturned == pdPASS );
- configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
+ /* ------------------------------------------------------------------------
+ * Create a timer that will try notifying this task while it is suspended. */
+ xSingleTaskTimer = xTimerCreate( "SingleNotify", notifySUSPENDED_TEST_TIMER_PERIOD, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );
+ configASSERT( xSingleTaskTimer );
- /* Incremented to show the task is still running. */
- ulNotifyCycleCount++;
+ /* Incremented to show the task is still running. */
+ ulNotifyCycleCount++;
+
+ /* Ensure no notifications are pending. */
+ xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );
+ /* Raise the task's priority so it can suspend itself before the timer
+ * expires. */
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+ /* Start the timer that will try notifying this task while it is
+ * suspended, then wait for a notification. The first time the callback
+ * executes the timer will suspend the task, then resume the task, without
+ * ever sending a notification to the task. */
+ ulNotifiedValue = 0;
+ xTimerStart( xSingleTaskTimer, portMAX_DELAY );
+ /* Check a notification is not received. */
+ xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );
+ configASSERT( xReturned == pdFALSE );
+ configASSERT( ulNotifiedValue == 0 );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ /* Incremented to show the task is still running. */
+ ulNotifyCycleCount++;
- /*-------------------------------------------------------------------------
- Check the non-overwriting functionality. The notification is done twice
- using two different notification values. The action says don't overwrite so
- only the first notification should pass and the value read back should also
- be that used with the first notification. */
- xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
+ /* Start the timer that will try notifying this task while it is
+ * suspended, then wait for a notification. The second time the callback
+ * executes the timer will suspend the task, notify the task, then resume the
+ * task (previously it was suspended and resumed without being notified). */
+ xTimerStart( xSingleTaskTimer, portMAX_DELAY );
- xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithoutOverwrite );
- configASSERT( xReturned == pdFAIL );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
+ /* Check a notification is received. */
+ xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* In case configASSERT() is not defined. */
+ configASSERT( ulNotifiedValue != 0 );
- /* Waiting for the notification should now return immediately so a block
- time of zero is used. */
- xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+ /* Return the task to its proper priority and delete the timer as it is
+ * not used again. */
+ vTaskPrioritySet( NULL, notifyTASK_PRIORITY );
+ xTimerDelete( xSingleTaskTimer, portMAX_DELAY );
- configASSERT( xReturned == pdPASS );
- configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
+ /* Incremented to show the task is still running. */
+ ulNotifyCycleCount++;
-
-
-
-
- /*-------------------------------------------------------------------------
- Do the same again, only this time use the overwriting version. This time
- both notifications should pass, and the value written the second time should
- overwrite the value written the first time, and so be the value that is read
- back. */
- xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithOverwrite );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- xReturned = xTaskNotify( xTaskToNotify, ulSecondNotifiedValueConst, eSetValueWithOverwrite );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
- ( void ) ulNotifiedValue;
-
-
-
-
- /*-------------------------------------------------------------------------
- Check notifications with no action pass without updating the value. Even
- though ulFirstNotifiedConst is used as the value the value read back should
- remain at ulSecondNotifiedConst. */
- xReturned = xTaskNotify( xTaskToNotify, ulFirstNotifiedConst, eNoAction );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
- configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
- ( void ) ulNotifiedValue; /* In case configASSERT() is not defined. */
-
-
-
-
- /*-------------------------------------------------------------------------
- Check incrementing values. Send ulMaxLoop increment notifications, then
- ensure the received value is as expected - which should be
- ulSecondNotificationValueConst plus how ever many times to loop iterated. */
- for( ulLoop = 0; ulLoop < ulMaxLoops; ulLoop++ )
- {
- xReturned = xTaskNotify( xTaskToNotify, 0, eIncrement );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- }
-
- xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdPASS );
- configASSERT( ulNotifiedValue == ( ulSecondNotifiedValueConst + ulMaxLoops ) );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
-
- /* Should not be any notifications pending now. */
- xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdFAIL );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
-
-
-
-
- /*-------------------------------------------------------------------------
- Check all bits can be set by notifying the task with one additional bit set
- on each notification, and exiting the loop when all the bits are found to be
- set. As there are 32-bits the loop should execute 32 times before all the
- bits are found to be set. */
- ulNotifyingValue = 0x01;
- ulLoop = 0;
-
- /* Start with all bits clear. */
- xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
-
- do
- {
- /* Set the next bit in the task's notified value. */
- xTaskNotify( xTaskToNotify, ulNotifyingValue, eSetBits );
-
- /* Wait for the notified value - which of course will already be
- available. Don't clear the bits on entry or exit as this loop is exited
- when all the bits are set. */
- xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- ulLoop++;
-
- /* Use the next bit on the next iteration around this loop. */
- ulNotifyingValue <<= 1UL;
-
- } while ( ulNotifiedValue != notifyUINT32_MAX );
-
- /* As a 32-bit value was used the loop should have executed 32 times before
- all the bits were set. */
- configASSERT( ulLoop == 32 );
-
-
-
-
- /*-------------------------------------------------------------------------
- Check bits are cleared on entry but not on exit when a notification fails
- to arrive before timing out - both with and without a timeout value. Wait
- for the notification again - but this time it is not given by anything and
- should return pdFAIL. The parameters are set to clear bit zero on entry and
- bit one on exit. As no notification was received only the bit cleared on
- entry should actually get cleared. */
- xReturned = xTaskNotifyWait( ulBit0, ulBit1, &ulNotifiedValue, xTicksToWait );
- configASSERT( xReturned == pdFAIL );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Notify the task with no action so as not to update the bits even though
- notifyUINT32_MAX is used as the notification value. */
- xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eNoAction );
-
- /* Reading back the value should should find bit 0 is clear, as this was
- cleared on entry, but bit 1 is not clear as it will not have been cleared on
- exit as no notification was received. */
- xReturned = xTaskNotifyWait( 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdPASS );
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
-
-
-
-
- /*-------------------------------------------------------------------------
- Now try clearing the bit on exit. For that to happen a notification must be
- received, so the task is notified first. */
- xTaskNotify( xTaskToNotify, 0, eNoAction );
- xTaskNotifyWait( 0x00, ulBit1, &ulNotifiedValue, 0 );
-
- /* However as the bit is cleared on exit, after the returned notification
- value is set, the returned notification value should not have the bit
- cleared... */
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
-
- /* ...but reading the value back again should find that the bit was indeed
- cleared internally. The returned value should be pdFAIL however as nothing
- has notified the task in the mean time. */
- xReturned = xTaskNotifyWait( 0x00, 0x00, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdFAIL );
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
-
-
-
- /*-------------------------------------------------------------------------
- Now try querying the previous value while notifying a task. */
- xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
-
- /* Clear all bits. */
- xTaskNotifyWait( 0x00, notifyUINT32_MAX, &ulNotifiedValue, 0 );
- xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );
- configASSERT( ulPreviousValue == 0 );
-
- ulExpectedValue = 0;
- for( ulLoop = 0x01; ulLoop < 0x80UL; ulLoop <<= 1UL )
- {
- /* Set the next bit up, and expect to receive the last bits set (so
- the previous value will not yet have the bit being set this time
- around). */
- xTaskNotifyAndQuery( xTaskToNotify, ulLoop, eSetBits, &ulPreviousValue );
- configASSERT( ulExpectedValue == ulPreviousValue );
- ulExpectedValue |= ulLoop;
- }
-
-
-
- /* ------------------------------------------------------------------------
- Clear the previous notifications. */
- xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
-
- /* The task should not have any notifications pending, so an attempt to clear
- the notification state should fail. */
- configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
-
- /* Get the task to notify itself. This is not a normal thing to do, and is
- only done here for test purposes. */
- xTaskNotifyAndQuery( xTaskToNotify, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
-
- /* Now the notification state should be eNotified, so it should now be
- possible to clear the notification state. */
- configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
- configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
-
-
-
- /* ------------------------------------------------------------------------
- Clear bits in the notification value. */
-
- /* Get the task to set all bits its own notification value. This is not a
- normal thing to do, and is only done here for test purposes. */
- xTaskNotify( xTaskToNotify, notifyUINT32_MAX, eSetBits );
-
- /* Now clear the top bytes - the returned value from the first call should
- indicate that previously all bits were set. */
- configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_HIGH_BYTE ) == notifyUINT32_MAX );
-
- /* Next clear the bottom bytes - the returned value this time should indicate
- that the top byte was clear (before the bottom byte was cleared. */
- configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_LOW_BYTE ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE ) );
-
- /* Next clear all bytes - the returned value should indicate that previously the
- high and low bytes were clear. */
- configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE & ~notifyUINT32_LOW_BYTE ) );
-
- /* Now all bits should be clear. */
- configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );
- configASSERT( ulTaskNotifyValueClear( xTaskToNotify, 0UL ) == 0 );
- configASSERT( ulTaskNotifyValueClear( xTaskToNotify, notifyUINT32_MAX ) == 0 );
-
- /* Now the notification state should be eNotified, so it should now be
- possible to clear the notification state. */
- configASSERT( xTaskNotifyStateClear( NULL ) == pdTRUE );
- configASSERT( xTaskNotifyStateClear( NULL ) == pdFALSE );
-
-
-
- /* ------------------------------------------------------------------------
- Create a timer that will try notifying this task while it is suspended. */
- xSingleTaskTimer = xTimerCreate( "SingleNotify", notifySUSPENDED_TEST_TIMER_PERIOD, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );
- configASSERT( xSingleTaskTimer );
-
- /* Incremented to show the task is still running. */
- ulNotifyCycleCount++;
-
- /* Ensure no notifications are pending. */
- xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );
-
- /* Raise the task's priority so it can suspend itself before the timer
- expires. */
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
-
- /* Start the timer that will try notifying this task while it is
- suspended, then wait for a notification. The first time the callback
- executes the timer will suspend the task, then resume the task, without
- ever sending a notification to the task. */
- ulNotifiedValue = 0;
- xTimerStart( xSingleTaskTimer, portMAX_DELAY );
-
- /* Check a notification is not received. */
- xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );
- configASSERT( xReturned == pdFALSE );
- configASSERT( ulNotifiedValue == 0 );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
-
- /* Incremented to show the task is still running. */
- ulNotifyCycleCount++;
-
- /* Start the timer that will try notifying this task while it is
- suspended, then wait for a notification. The second time the callback
- executes the timer will suspend the task, notify the task, then resume the
- task (previously it was suspended and resumed without being notified). */
- xTimerStart( xSingleTaskTimer, portMAX_DELAY );
-
- /* Check a notification is received. */
- xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* In case configASSERT() is not defined. */
- configASSERT( ulNotifiedValue != 0 );
-
- /* Return the task to its proper priority and delete the timer as it is
- not used again. */
- vTaskPrioritySet( NULL, notifyTASK_PRIORITY );
- xTimerDelete( xSingleTaskTimer, portMAX_DELAY );
-
- /* Incremented to show the task is still running. */
- ulNotifyCycleCount++;
-
- /* Leave all bits cleared. */
- xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );
+ /* Leave all bits cleared. */
+ xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );
}
/*-----------------------------------------------------------*/
static void prvSuspendedTaskTimerTestCallback( TimerHandle_t xExpiredTimer )
{
-static uint32_t ulCallCount = 0;
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) xExpiredTimer;
-
- /* Callback for a timer that is used during preliminary testing. The timer
- tests the behaviour when 1: a task waiting for a notification is suspended
- and then resumed without ever receiving a notification, and 2: when a task
- waiting for a notification receives a notification while it is suspended. */
-
- if( ulCallCount == 0 )
- {
- vTaskSuspend( xTaskToNotify );
- configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
- vTaskResume( xTaskToNotify );
- }
- else
- {
- vTaskSuspend( xTaskToNotify );
-
- /* Sending a notification while the task is suspended should pass, but
- not cause the task to resume. ulCallCount is just used as a convenient
- non-zero value. */
- xTaskNotify( xTaskToNotify, ulCallCount, eSetValueWithOverwrite );
-
- /* Make sure giving the notification didn't resume the task. */
- configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
-
- vTaskResume( xTaskToNotify );
- }
-
- ulCallCount++;
+ static uint32_t ulCallCount = 0;
+
+ /* Remove compiler warnings about unused parameters. */
+ ( void ) xExpiredTimer;
+
+ /* Callback for a timer that is used during preliminary testing. The timer
+ * tests the behaviour when 1: a task waiting for a notification is suspended
+ * and then resumed without ever receiving a notification, and 2: when a task
+ * waiting for a notification receives a notification while it is suspended. */
+
+ if( ulCallCount == 0 )
+ {
+ vTaskSuspend( xTaskToNotify );
+ configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
+ vTaskResume( xTaskToNotify );
+ }
+ else
+ {
+ vTaskSuspend( xTaskToNotify );
+
+ /* Sending a notification while the task is suspended should pass, but
+ * not cause the task to resume. ulCallCount is just used as a convenient
+ * non-zero value. */
+ xTaskNotify( xTaskToNotify, ulCallCount, eSetValueWithOverwrite );
+
+ /* Make sure giving the notification didn't resume the task. */
+ configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
+
+ vTaskResume( xTaskToNotify );
+ }
+
+ ulCallCount++;
}
/*-----------------------------------------------------------*/
static void prvNotifyingTimer( TimerHandle_t xNotUsed )
{
- ( void ) xNotUsed;
+ ( void ) xNotUsed;
- xTaskNotifyGive( xTaskToNotify );
+ xTaskNotifyGive( xTaskToNotify );
- /* This value is also incremented from an interrupt. */
- taskENTER_CRITICAL();
- {
- ulTimerNotificationsSent++;
- }
- taskEXIT_CRITICAL();
+ /* This value is also incremented from an interrupt. */
+ taskENTER_CRITICAL();
+ {
+ ulTimerNotificationsSent++;
+ }
+ taskEXIT_CRITICAL();
}
/*-----------------------------------------------------------*/
-static void prvNotifiedTask( void *pvParameters )
+static void prvNotifiedTask( void * pvParameters )
{
-const TickType_t xMaxPeriod = pdMS_TO_TICKS( 90 ), xMinPeriod = pdMS_TO_TICKS( 10 ), xDontBlock = 0;
-TickType_t xPeriod;
-const uint32_t ulCyclesToRaisePriority = 50UL;
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- /* Run a few tests that can be done from a single task before entering the
- main loop. */
- prvSingleTaskTests();
-
- /* Create the software timer that is used to send notifications to this
- task. Notifications are also received from an interrupt. */
- xTimer = xTimerCreate( "Notifier", xMaxPeriod, pdFALSE, NULL, prvNotifyingTimer );
-
- for( ;; )
- {
- /* Start the timer again with a different period. Sometimes the period
- will be higher than the task's block time, sometimes it will be lower
- than the task's block time. */
- xPeriod = prvRand() % xMaxPeriod;
- if( xPeriod < xMinPeriod )
- {
- xPeriod = xMinPeriod;
- }
-
- /* Change the timer period and start the timer. */
- xTimerChangePeriod( xTimer, xPeriod, portMAX_DELAY );
-
- /* Block waiting for the notification again with a different period.
- Sometimes the period will be higher than the task's block time,
- sometimes it will be lower than the task's block time. */
- xPeriod = prvRand() % xMaxPeriod;
- if( xPeriod < xMinPeriod )
- {
- xPeriod = xMinPeriod;
- }
-
- /* Block to wait for a notification but without clearing the
- notification count, so only add one to the count of received
- notifications as any other notifications will remain pending. */
- if( ulTaskNotifyTake( pdFALSE, xPeriod ) != 0 )
- {
- ulTimerNotificationsReceived++;
- }
-
-
- /* Take a notification without clearing again, but this time without a
- block time specified. */
- if( ulTaskNotifyTake( pdFALSE, xDontBlock ) != 0 )
- {
- ulTimerNotificationsReceived++;
- }
-
- /* Wait for the next notification from the timer, clearing all
- notifications if one is received, so this time adding the total number
- of notifications that were pending as none will be left pending after
- the function call. */
- ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, xPeriod );
-
- /* Occasionally raise the priority of the task being notified to test
- the path where the task is notified from an ISR and becomes the highest
- priority ready state task, but the pxHigherPriorityTaskWoken parameter
- is NULL (which it is in the tick hook that sends notifications to this
- task). */
- if( ( ulNotifyCycleCount % ulCyclesToRaisePriority ) == 0 )
- {
- vTaskPrioritySet( xTaskToNotify, configMAX_PRIORITIES - 1 );
-
- /* Wait for the next notification again, clearing all notifications
- if one is received, but this time blocking indefinitely. */
- ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
-
- /* Reset the priority. */
- vTaskPrioritySet( xTaskToNotify, notifyTASK_PRIORITY );
- }
- else
- {
- /* Wait for the next notification again, clearing all notifications
- if one is received, but this time blocking indefinitely. */
- ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
- }
-
- /* Incremented to show the task is still running. */
- ulNotifyCycleCount++;
- }
+ const TickType_t xMaxPeriod = pdMS_TO_TICKS( 90 ), xMinPeriod = pdMS_TO_TICKS( 10 ), xDontBlock = 0;
+ TickType_t xPeriod;
+ const uint32_t ulCyclesToRaisePriority = 50UL;
+
+ /* Remove compiler warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ /* Run a few tests that can be done from a single task before entering the
+ * main loop. */
+ prvSingleTaskTests();
+
+ /* Create the software timer that is used to send notifications to this
+ * task. Notifications are also received from an interrupt. */
+ xTimer = xTimerCreate( "Notifier", xMaxPeriod, pdFALSE, NULL, prvNotifyingTimer );
+
+ for( ; ; )
+ {
+ /* Start the timer again with a different period. Sometimes the period
+ * will be higher than the task's block time, sometimes it will be lower
+ * than the task's block time. */
+ xPeriod = prvRand() % xMaxPeriod;
+
+ if( xPeriod < xMinPeriod )
+ {
+ xPeriod = xMinPeriod;
+ }
+
+ /* Change the timer period and start the timer. */
+ xTimerChangePeriod( xTimer, xPeriod, portMAX_DELAY );
+
+ /* Block waiting for the notification again with a different period.
+ * Sometimes the period will be higher than the task's block time,
+ * sometimes it will be lower than the task's block time. */
+ xPeriod = prvRand() % xMaxPeriod;
+
+ if( xPeriod < xMinPeriod )
+ {
+ xPeriod = xMinPeriod;
+ }
+
+ /* Block to wait for a notification but without clearing the
+ * notification count, so only add one to the count of received
+ * notifications as any other notifications will remain pending. */
+ if( ulTaskNotifyTake( pdFALSE, xPeriod ) != 0 )
+ {
+ ulTimerNotificationsReceived++;
+ }
+
+ /* Take a notification without clearing again, but this time without a
+ * block time specified. */
+ if( ulTaskNotifyTake( pdFALSE, xDontBlock ) != 0 )
+ {
+ ulTimerNotificationsReceived++;
+ }
+
+ /* Wait for the next notification from the timer, clearing all
+ * notifications if one is received, so this time adding the total number
+ * of notifications that were pending as none will be left pending after
+ * the function call. */
+ ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, xPeriod );
+
+ /* Occasionally raise the priority of the task being notified to test
+ * the path where the task is notified from an ISR and becomes the highest
+ * priority ready state task, but the pxHigherPriorityTaskWoken parameter
+ * is NULL (which it is in the tick hook that sends notifications to this
+ * task). */
+ if( ( ulNotifyCycleCount % ulCyclesToRaisePriority ) == 0 )
+ {
+ vTaskPrioritySet( xTaskToNotify, configMAX_PRIORITIES - 1 );
+
+ /* Wait for the next notification again, clearing all notifications
+ * if one is received, but this time blocking indefinitely. */
+ ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
+
+ /* Reset the priority. */
+ vTaskPrioritySet( xTaskToNotify, notifyTASK_PRIORITY );
+ }
+ else
+ {
+ /* Wait for the next notification again, clearing all notifications
+ * if one is received, but this time blocking indefinitely. */
+ ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
+ }
+
+ /* Incremented to show the task is still running. */
+ ulNotifyCycleCount++;
+ }
}
/*-----------------------------------------------------------*/
void xNotifyTaskFromISR( void )
{
-static BaseType_t xCallCount = 0, xAPIToUse = 0;
-const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );
-uint32_t ulPreviousValue;
-const uint32_t ulUnexpectedValue = 0xff;
-
- /* Check the task notification demo tasks were actually created. */
- configASSERT( xTaskToNotify );
-
- /* The task performs some tests before starting the timer that gives the
- notification from this interrupt. If the timer has not been created yet
- then the initial tests have not yet completed and the notification should
- not be sent. */
- if( xTimer != NULL )
- {
- xCallCount++;
-
- if( xCallCount >= xCallInterval )
- {
- /* It is time to 'give' the notification again. */
- xCallCount = 0;
-
- /* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR()
- and xTaskNotifyAndQueryFromISR(). */
- switch( xAPIToUse )
- {
- case 0: vTaskNotifyGiveFromISR( xTaskToNotify, NULL );
- xAPIToUse++;
- break;
-
- case 1: xTaskNotifyFromISR( xTaskToNotify, 0, eIncrement, NULL );
- xAPIToUse++;
- break;
-
- case 2: ulPreviousValue = ulUnexpectedValue;
- xTaskNotifyAndQueryFromISR( xTaskToNotify, 0, eIncrement, &ulPreviousValue, NULL );
- configASSERT( ulPreviousValue != ulUnexpectedValue );
- xAPIToUse = 0;
- break;
-
- default:/* Should never get here!. */
- break;
- }
-
- ulTimerNotificationsSent++;
- }
- }
+ static BaseType_t xCallCount = 0, xAPIToUse = 0;
+ const BaseType_t xCallInterval = pdMS_TO_TICKS( 50 );
+ uint32_t ulPreviousValue;
+ const uint32_t ulUnexpectedValue = 0xff;
+
+ /* Check the task notification demo tasks were actually created. */
+ configASSERT( xTaskToNotify );
+
+ /* The task performs some tests before starting the timer that gives the
+ * notification from this interrupt. If the timer has not been created yet
+ * then the initial tests have not yet completed and the notification should
+ * not be sent. */
+ if( xTimer != NULL )
+ {
+ xCallCount++;
+
+ if( xCallCount >= xCallInterval )
+ {
+ /* It is time to 'give' the notification again. */
+ xCallCount = 0;
+
+ /* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR()
+ * and xTaskNotifyAndQueryFromISR(). */
+ switch( xAPIToUse )
+ {
+ case 0:
+ vTaskNotifyGiveFromISR( xTaskToNotify, NULL );
+ xAPIToUse++;
+ break;
+
+ case 1:
+ xTaskNotifyFromISR( xTaskToNotify, 0, eIncrement, NULL );
+ xAPIToUse++;
+ break;
+
+ case 2:
+ ulPreviousValue = ulUnexpectedValue;
+ xTaskNotifyAndQueryFromISR( xTaskToNotify, 0, eIncrement, &ulPreviousValue, NULL );
+ configASSERT( ulPreviousValue != ulUnexpectedValue );
+ xAPIToUse = 0;
+ break;
+
+ default: /* Should never get here!. */
+ break;
+ }
+
+ ulTimerNotificationsSent++;
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check the created tasks are still running and have not
-detected any errors. */
+ * detected any errors. */
BaseType_t xAreTaskNotificationTasksStillRunning( void )
{
-static uint32_t ulLastNotifyCycleCount = 0;
-const uint32_t ulMaxSendReceiveDeviation = 5UL;
-
- /* Check the cycle count is still incrementing to ensure the task is still
- actually running. */
- if( ulLastNotifyCycleCount == ulNotifyCycleCount )
- {
- xErrorStatus = pdFAIL;
- }
- else
- {
- ulLastNotifyCycleCount = ulNotifyCycleCount;
- }
-
- /* Check the count of 'takes' from the software timer is keeping track with
- the amount of 'gives'. */
- if( ulTimerNotificationsSent > ulTimerNotificationsReceived )
- {
- if( ( ulTimerNotificationsSent - ulTimerNotificationsReceived ) > ulMaxSendReceiveDeviation )
- {
- xErrorStatus = pdFAIL;
- }
- }
-
- return xErrorStatus;
+ static uint32_t ulLastNotifyCycleCount = 0;
+ const uint32_t ulMaxSendReceiveDeviation = 5UL;
+
+ /* Check the cycle count is still incrementing to ensure the task is still
+ * actually running. */
+ if( ulLastNotifyCycleCount == ulNotifyCycleCount )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastNotifyCycleCount = ulNotifyCycleCount;
+ }
+
+ /* Check the count of 'takes' from the software timer is keeping track with
+ * the amount of 'gives'. */
+ if( ulTimerNotificationsSent > ulTimerNotificationsReceived )
+ {
+ if( ( ulTimerNotificationsSent - ulTimerNotificationsReceived ) > ulMaxSendReceiveDeviation )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ }
+
+ return xErrorStatus;
}
/*-----------------------------------------------------------*/
static UBaseType_t prvRand( void )
{
-const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;
+ const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;
- /* Utility function to generate a pseudo random number. */
- uxNextRand = ( uxMultiplier * uxNextRand ) + uxIncrement;
- return( ( uxNextRand >> 16 ) & ( ( size_t ) 0x7fff ) );
+ /* Utility function to generate a pseudo random number. */
+ uxNextRand = ( uxMultiplier * uxNextRand ) + uxIncrement;
+ return( ( uxNextRand >> 16 ) & ( ( size_t ) 0x7fff ) );
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c b/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c
index be4758071..38a84e00a 100644
--- a/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c
+++ b/FreeRTOS/Demo/Common/Minimal/TaskNotifyArray.c
@@ -41,21 +41,21 @@
/* Demo program include files. */
#include "TaskNotifyArray.h"
-#if( configTASK_NOTIFICATION_ARRAY_ENTRIES < 3 )
- #error This file tests direct to task notification arrays and needs configTASK_NOTIFICATION_ARRAY_ENTRIES to be at least 3.
+#if ( configTASK_NOTIFICATION_ARRAY_ENTRIES < 3 )
+ #error This file tests direct to task notification arrays and needs configTASK_NOTIFICATION_ARRAY_ENTRIES to be at least 3.
#endif
/* Allow parameters to be overridden on a demo by demo basis. */
#ifndef notifyNOTIFY_ARRAY_TASK_STACK_SIZE
- #define notifyNOTIFY_ARRAY_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define notifyNOTIFY_ARRAY_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
-#define notifyTASK_PRIORITY ( tskIDLE_PRIORITY )
+#define notifyTASK_PRIORITY ( tskIDLE_PRIORITY )
/* Constants used in tests when setting/clearing bits. */
-#define notifyUINT32_MAX ( ( uint32_t ) 0xffffffff )
-#define notifyUINT32_HIGH_BYTE ( ( uint32_t ) 0xff000000 )
-#define notifyUINT32_LOW_BYTE ( ( uint32_t ) 0x000000ff )
+#define notifyUINT32_MAX ( ( uint32_t ) 0xffffffff )
+#define notifyUINT32_HIGH_BYTE ( ( uint32_t ) 0xff000000 )
+#define notifyUINT32_LOW_BYTE ( ( uint32_t ) 0x000000ff )
/*-----------------------------------------------------------*/
@@ -64,7 +64,7 @@
* itself, and others where notifications are sent from a software timer or
* an interrupt (specifically the tick hook function).
*/
-static void prvNotifiedTask( void *pvParameters );
+static void prvNotifiedTask( void * pvParameters );
/*
* Performs the tests that don't require notifications to be sent from a
@@ -122,14 +122,14 @@ static UBaseType_t prvRand( void );
/*-----------------------------------------------------------*/
/* Counters used to check the task has not stalled. ulFineCycleCount is
-incremented within each test. ulCourseCycleCounter is incremented one every
-loop of all the tests to ensure each test is actually executing. The check task
-calls xAreTaskNotificationArrayTasksStillRunning() (implemented within this
-file) to check both counters are changing. */
+ * incremented within each test. ulCourseCycleCounter is incremented one every
+ * loop of all the tests to ensure each test is actually executing. The check task
+ * calls xAreTaskNotificationArrayTasksStillRunning() (implemented within this
+ * file) to check both counters are changing. */
static volatile uint32_t ulFineCycleCount = 0, ulCourseCycleCounter = 0;
/* The handle of the task that runs the tests and receives the notifications
-from the software timers and interrupts. */
+ * from the software timers and interrupts. */
static TaskHandle_t xTaskToNotify = NULL;
/* The software timers used to send notifications to the main test task. */
@@ -144,1094 +144,1075 @@ static volatile BaseType_t xSendNotificationFromISR = pdFALSE;
/*-----------------------------------------------------------*/
-void vStartTaskNotifyArrayTask( void )
+void vStartTaskNotifyArrayTask( void )
{
-const TickType_t xIncrementingIndexTimerPeriod = pdMS_TO_TICKS( 100 );
-const TickType_t xSuspendTimerPeriod = pdMS_TO_TICKS( 50 );
-
- /* Create the software timers used for these tests. The timer callbacks send
- notifications to this task. */
- xNotifyWhileSuspendedTimer = xTimerCreate( "SingleNotify", xSuspendTimerPeriod, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );
- xIncrementingIndexTimer = xTimerCreate( "Notifier", xIncrementingIndexTimerPeriod, pdFALSE, NULL, prvNotifyingTimerCallback );
- configASSERT( xNotifyWhileSuspendedTimer );
- configASSERT( xIncrementingIndexTimer );
-
- /* Create the task that performs some tests by itself, then loops around
- being notified by both a software timer and an interrupt. */
- xTaskCreate( prvNotifiedTask, /* Function that implements the task. */
- "ArrayNotifed", /* Text name for the task - for debugging only - not used by the kernel. */
- notifyNOTIFY_ARRAY_TASK_STACK_SIZE, /* Task's stack size in words, not bytes!. */
- NULL, /* Task parameter, not used in this case. */
- notifyTASK_PRIORITY, /* Task priority, 0 is the lowest. */
- &xTaskToNotify ); /* Used to pass a handle to the task out if needed, otherwise set to NULL. */
-
- /* Pseudo seed the random number generator. */
- uxNextRand = ( size_t ) prvRand;
+ const TickType_t xIncrementingIndexTimerPeriod = pdMS_TO_TICKS( 100 );
+ const TickType_t xSuspendTimerPeriod = pdMS_TO_TICKS( 50 );
+
+ /* Create the software timers used for these tests. The timer callbacks send
+ * notifications to this task. */
+ xNotifyWhileSuspendedTimer = xTimerCreate( "SingleNotify", xSuspendTimerPeriod, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );
+ xIncrementingIndexTimer = xTimerCreate( "Notifier", xIncrementingIndexTimerPeriod, pdFALSE, NULL, prvNotifyingTimerCallback );
+ configASSERT( xNotifyWhileSuspendedTimer );
+ configASSERT( xIncrementingIndexTimer );
+
+ /* Create the task that performs some tests by itself, then loops around
+ * being notified by both a software timer and an interrupt. */
+ xTaskCreate( prvNotifiedTask, /* Function that implements the task. */
+ "ArrayNotifed", /* Text name for the task - for debugging only - not used by the kernel. */
+ notifyNOTIFY_ARRAY_TASK_STACK_SIZE, /* Task's stack size in words, not bytes!. */
+ NULL, /* Task parameter, not used in this case. */
+ notifyTASK_PRIORITY, /* Task priority, 0 is the lowest. */
+ &xTaskToNotify ); /* Used to pass a handle to the task out if needed, otherwise set to NULL. */
+
+ /* Pseudo seed the random number generator. */
+ uxNextRand = ( size_t ) prvRand;
}
/*-----------------------------------------------------------*/
-static void prvNotifiedTask( void *pvParameters )
+static void prvNotifiedTask( void * pvParameters )
{
- /* Remove compiler warnings about unused parameters. */
- ( void ) pvParameters;
-
- /* Loop through each set of test functions in turn. See the comments above
- the respective function prototypes above for more details. */
- for( ;; )
- {
- prvSingleTaskTests();
- prvTestNotifyTaskWhileSuspended();
- prvBlockOnTheNotifiedIndexed();
- prvBlockOnANonNotifiedIndexed();
- prvBlockOnNotificationsComingFromInterrupts();
- ulCourseCycleCounter++;
- }
+ /* Remove compiler warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ /* Loop through each set of test functions in turn. See the comments above
+ * the respective function prototypes above for more details. */
+ for( ; ; )
+ {
+ prvSingleTaskTests();
+ prvTestNotifyTaskWhileSuspended();
+ prvBlockOnTheNotifiedIndexed();
+ prvBlockOnANonNotifiedIndexed();
+ prvBlockOnNotificationsComingFromInterrupts();
+ ulCourseCycleCounter++;
+ }
}
/*-----------------------------------------------------------*/
static void prvSingleTaskTests( void )
{
-const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
-BaseType_t xReturned;
-uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
-TickType_t xTimeOnEntering, xTimeNow, xTimeDifference;
-const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
-const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
-UBaseType_t uxIndexToTest, uxOtherIndexes;
-
-
- /* ------------------------------------------------------------------------
- Check blocking when there are no notifications. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* Send notifications to the task notification in each index of the
- task notification array other than the one on which this task will
- block. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes != uxIndexToTest )
- {
- xTaskNotifyIndexed( xTaskToNotify, uxOtherIndexes, 0, eNoAction );
- }
- }
-
- xTimeOnEntering = xTaskGetTickCount();
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* Should have blocked for the entire block time. */
- xTimeNow = xTaskGetTickCount();
- xTimeDifference = xTimeNow - xTimeOnEntering;
- configASSERT( xTimeDifference >= xTicksToWait );
- configASSERT( xReturned == pdFAIL );
- configASSERT( ulNotifiedValue == 0UL );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
-
- /* Clear all the other notifications within the array of task
- notifications again ready for the next round. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes != uxIndexToTest )
- {
- xReturned = xTaskNotifyStateClearIndexed( xTaskToNotify, uxOtherIndexes );
-
- /* The notification state was set above so expect it to still be
- set. */
- configASSERT( xReturned == pdTRUE );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
- }
-
-
-
- /* ------------------------------------------------------------------------
- Check no blocking when notifications are pending. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* First notify the task notification at index uxIndexToTest within this
- task's own array of task notifications - this would not be a normal
- thing to do and is done here for test purposes only. */
- xReturned = xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
-
- /* Even through the 'without overwrite' action was used the update should
- have been successful. */
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* No bits should have been pending previously. */
- configASSERT( ulPreviousValue == 0 );
- ( void ) ulPreviousValue;
-
- /* The task should now have a notification pending in the task
- notification at index uxIndexToTest within the task notification array,
- and so not time out. */
- xTimeOnEntering = xTaskGetTickCount();
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
- xTimeNow = xTaskGetTickCount();
- xTimeDifference = xTimeNow - xTimeOnEntering;
- configASSERT( xTimeDifference < xTicksToWait );
-
- /* The task should have been notified, and the notified value should
- be equal to ulFirstNotifiedConst. */
- configASSERT( xReturned == pdPASS );
- configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
- }
-
-
-
-
- /*-------------------------------------------------------------------------
- Check the non-overwriting functionality. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* Send notifications to all indexes with the array of task
- notifications other than the one on which this task will block. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes != uxIndexToTest )
- {
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxOtherIndexes, ulFirstNotifiedConst, eSetValueWithOverwrite );
- configASSERT(xReturned == pdPASS);
- (void)xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
-
- /* The notification is performed twice using two different notification
- values. The action says don't overwrite so only the first notification
- should pass and the value read back should also be that used with the
- first notification. The notification is sent to the task notification at
- index uxIndexToTest within the array of task notifications. */
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithoutOverwrite );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulSecondNotifiedValueConst, eSetValueWithoutOverwrite );
- configASSERT( xReturned == pdFAIL );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* Waiting for the notification should now return immediately so a block
- time of zero is used. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
-
- configASSERT( xReturned == pdPASS );
- configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
-
- /* Clear all the other task notifications within the array of task
- notifications again ready for the next round. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes != uxIndexToTest )
- {
- xReturned = xTaskNotifyStateClearIndexed( xTaskToNotify, uxOtherIndexes );
- configASSERT( xReturned == pdTRUE );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- ulNotifiedValue = ulTaskNotifyValueClearIndexed( xTaskToNotify, uxOtherIndexes, notifyUINT32_MAX );
-
- /* The notification value was set to ulFirstNotifiedConst in all
- the other indexes, so expect it to still have that value. */
- configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
- }
-
-
-
-
- /*-------------------------------------------------------------------------
- Do the same again, only this time use the overwriting version. This time
- both notifications should pass, and the value written the second time should
- overwrite the value written the first time, and so be the value that is read
- back. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes != uxIndexToTest )
- {
- xTaskNotifyIndexed( xTaskToNotify, uxOtherIndexes, ulFirstNotifiedConst, eSetValueWithOverwrite );
- }
- }
-
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithOverwrite );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulSecondNotifiedValueConst, eSetValueWithOverwrite );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, notifyUINT32_MAX, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
- ( void ) ulNotifiedValue;
-
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes != uxIndexToTest )
- {
- xReturned = xTaskNotifyStateClearIndexed( xTaskToNotify, uxOtherIndexes );
- configASSERT( xReturned == pdTRUE );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- ulNotifiedValue = ulTaskNotifyValueClearIndexed( xTaskToNotify, uxOtherIndexes, notifyUINT32_MAX );
- configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
- }
-
-
-
-
- /*-------------------------------------------------------------------------
- For each task notification within the array of task notifications, check
- notifications with no action pass without updating the value. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* First set the notification values of the task notification at index
- uxIndexToTest of the array of task notification to
- ulSecondNotifiedValueConst. */
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulSecondNotifiedValueConst, eSetValueWithOverwrite );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* Even though ulFirstNotifiedConst is used as the value next, the value
- read back should remain at ulSecondNotifiedConst as the action is set
- to eNoAction. */
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eNoAction );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* All task notifications in the array of task notifications up to and
- including index uxIndexToTest should still contain the same value. */
- for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
- {
- /* First zero is bits to clear on entry, the second is bits to clear on
- exist, the last 0 is the block time. */
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
- configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
-
- /* All array indexes in the array of task notifications after index
- uxIndexToTest should still contain 0 as they have not been set in this
- loop yet. This time use ulTaskNotifyValueClearIndexed() instead of
- xTaskNotifyWaitIndexed(), just for test coverage. */
- for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- /* This time 0 is the bits to clear parameter - so clearing no bits. */
- ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
- configASSERT( ulNotifiedValue == 0 );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
-
-
-
-
- /*-------------------------------------------------------------------------
- Check incrementing values. For each task notification in the array of task
- notifications in turn, send ulMaxLoop increment notifications, then ensure
- the received value is as expected - which should be
- ulSecondNotificationValueConst plus how ever many times to loop iterated. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- for( ulLoop = 0; ulLoop < ulMaxLoops; ulLoop++ )
- {
- /* Increment the value of the task notification at index
- uxIndexToTest within the array of task notifications. */
- xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, 0, eIncrement );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
-
- /* All array indexes up to and including uxIndexToTest should still
- contain the updated value. */
- for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
- {
- /* First zero is bits to clear on entry, the second is bits to clear on
- exist, the last 0 is the block time. */
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
- configASSERT( ulNotifiedValue == ( ulSecondNotifiedValueConst + ulMaxLoops ) );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
-
- /* Should not be any notifications pending now. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdFAIL );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
-
- /* All notifications values in the array of task notifications after
- index uxIndexToTest should still contain the un-incremented
- ulSecondNotifiedValueConst as they have not been set in this loop yet.
- This time use ulTaskNotifyValueClearIndexed() instead of xTaskNotifyWaitIndexed(),
- just for test coverage. */
- for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- /* This time 0 is the bits to clear parameter - so clearing no bits. */
- ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
- configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
-
- /* Clear all bits ready for next test. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* Start with all bits clear. */
- ulTaskNotifyValueClearIndexed( NULL, uxIndexToTest, notifyUINT32_MAX );
- }
-
-
-
- /*-------------------------------------------------------------------------
- For each task notification in the array of task notifications in turn, check
- all bits in the notification's value can be set by notifying the task with
- one additional bit set on each notification, and exiting the loop when all
- the bits are found to be set. As there are 32-bits the loop should execute
- 32 times before all the bits are found to be set. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- ulNotifyingValue = 0x01;
- ulLoop = 0;
-
- do
- {
- /* Set the next bit in the value of the task notification at index
- uxIndexToTest within the array of task notifications. */
- xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulNotifyingValue, eSetBits );
-
- /* Wait for the notified value - which of course will already be
- available. Don't clear the bits on entry or exit as this loop is
- exited when all the bits are set. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- ulLoop++;
-
- /* Use the next bit on the next iteration around this loop. */
- ulNotifyingValue <<= 1UL;
-
- } while ( ulNotifiedValue != notifyUINT32_MAX );
-
- /* As a 32-bit value was used the loop should have executed 32 times before
- all the bits were set. */
- configASSERT( ulLoop == 32 );
-
- /* The value of each task notification within the array of task
- notifications up to and including index uxIndexToTest should still have
- all bits set. */
- for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
- {
- /* First zero is bits to clear on entry, the second is bits to clear on
- exist, the last 0 is the block time. */
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
- configASSERT( ulNotifiedValue == notifyUINT32_MAX );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
-
- /* The value of each task notification within the array of task
- notifications after index uxIndexToTest should still contain 0 as they
- have not been set in this loop yet. This time use ulTaskNotifyValueClearIndexed()
- instead of xTaskNotifyWaitIndexed(), just for test coverage. */
- for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- /* This time 0 is the bits to clear parameter - so clearing no bits. */
- ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
- configASSERT( ulNotifiedValue == 0 );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
-
-
-
- /*-------------------------------------------------------------------------
- For each task notification within the array of task notifications in turn,
- check bits are cleared on entry but not on exit when a notification fails
- to arrive before timing out - both with and without a timeout value. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* Wait for the notification - but this time it is not given by anything
- and should return pdFAIL. The parameters are set to clear bit zero on
- entry and bit one on exit. As no notification was received only the bit
- cleared on entry should actually get cleared. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, ulBit0, ulBit1, &ulNotifiedValue, xTicksToWait );
- configASSERT( xReturned == pdFAIL );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* Send a notification with no action to the task notification at index
- uxIndexToTest within the array of task notifications. This should not
- update the bits even though notifyUINT32_MAX is used as the notification
- value. */
- xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX, eNoAction );
-
- /* All array indexes up to and including uxIndexToTest within the array
- of task notifications should have the modified value. */
- for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
- {
- /* Reading back the value should find bit 0 is clear, as this was cleared
- on entry, but bit 1 is not clear as it will not have been cleared on exit
- as no notification was received. */
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
- if( uxOtherIndexes == uxIndexToTest )
- {
- /* This is the index being used this time round the loop and its
- notification state was set immediately above. */
- configASSERT( xReturned == pdPASS );
- }
- else
- {
- /* Nothing should have set this index's notification state again. */
- configASSERT( xReturned == pdFAIL );
- }
-
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
-
- /* All array indexes after uxIndexToTest should still contain notifyUINT32_MAX
- left over from the previous test. This time use xTaskNotifyValueClear()
- instead of xTaskNotifyWaitIndexed(), just for test coverage. */
- for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- /* This time 0 is the bits to clear parameter - so clearing no bits. */
- ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
- configASSERT( ulNotifiedValue == notifyUINT32_MAX );
- ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
-
-
-
-
- /*-------------------------------------------------------------------------
- Now try clearing the bit on exit. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* The task is notified first using the task notification at index
- uxIndexToTest within the array of task notifications. */
- xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, 0, eNoAction );
- xTaskNotifyWaitIndexed( uxIndexToTest, 0x00, ulBit1, &ulNotifiedValue, 0 );
-
- /* However as the bit is cleared on exit, after the returned notification
- value is set, the returned notification value should not have the bit
- cleared... */
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
-
- /* ...but reading the value back again should find that the bit was indeed
- cleared internally. The returned value should be pdFAIL however as nothing
- has notified the task in the mean time. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0x00, 0x00, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdFAIL );
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* No other indexes should have a notification pending. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes != uxIndexToTest )
- {
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdFAIL );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
- }
- }
-
-
-
- /*-------------------------------------------------------------------------
- For each task notification within the array of task notifications, try
- querying the previous value while notifying a task. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, 0x00, eSetBits, &ulPreviousValue );
- configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
-
- /* Clear all bits. */
- xTaskNotifyWaitIndexed( uxIndexToTest, 0x00, notifyUINT32_MAX, &ulNotifiedValue, 0 );
- xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, 0x00, eSetBits, &ulPreviousValue );
- configASSERT( ulPreviousValue == 0 );
-
- ulExpectedValue = 0;
- for( ulLoop = 0x01; ulLoop < 0x80UL; ulLoop <<= 1UL )
- {
- /* Set the next bit up, and expect to receive the last bits set (so
- the previous value will not yet have the bit being set this time
- around). */
- xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, ulLoop, eSetBits, &ulPreviousValue );
- configASSERT( ulExpectedValue == ulPreviousValue );
- ulExpectedValue |= ulLoop;
- }
- }
-
-
- /* ---------------------------------------------------------------------- */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* Clear the previous notifications. */
- xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
- }
-
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* No task notification within the array of task notifications should
- have any notification pending, so an attempt to clear the notification
- state should fail. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- configASSERT( xTaskNotifyStateClearIndexed( NULL, uxOtherIndexes ) == pdFALSE );
- }
-
- /* Get the task to notify itself using the task notification at index
- uxIndexToTest within the array of task notifications. This is not a
- normal thing to do, and is only done here for test purposes. */
- xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
-
- /* Now the notification state should be eNotified, so it should now be
- possible to clear the notification state. Other indexes should still
- not have a notification pending - likewise uxIndexToTest should not have
- a notification pending once it has been cleared. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- if( uxOtherIndexes == uxIndexToTest )
- {
- configASSERT( xTaskNotifyStateClearIndexed( NULL, uxOtherIndexes ) == pdTRUE );
- }
-
- configASSERT( xTaskNotifyStateClearIndexed( NULL, uxOtherIndexes ) == pdFALSE );
- }
- }
-
-
- /* ------------------------------------------------------------------------
- For each task notification within the array of task notifications, clear
- bits in the notification value. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* Get the task to set all bits in its task notification at index
- uxIndexToTest within its array of task notifications. This is not a
- normal thing to do, and is only done here for test purposes. */
- xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX, eSetBits );
-
- /* Now clear the top bytes - the returned value from the first call
- should indicate that previously all bits were set. */
- configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_HIGH_BYTE ) == notifyUINT32_MAX );
-
- /* Next clear the bottom bytes - the returned value this time should
- indicate that the top byte was clear (before the bottom byte was
- cleared. */
- configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_LOW_BYTE ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE ) );
-
- /* Next clear all bytes - the returned value should indicate that previously the
- high and low bytes were clear. */
- configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE & ~notifyUINT32_LOW_BYTE ) );
-
- /* Now all bits should be clear. */
- configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX ) == 0 );
- configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, 0UL ) == 0 );
- configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX ) == 0 );
-
- /* Now the notification state should be eNotified, so it should now be
- possible to clear the notification state. */
- configASSERT( xTaskNotifyStateClearIndexed( NULL, uxIndexToTest ) == pdTRUE );
- configASSERT( xTaskNotifyStateClearIndexed( NULL, uxIndexToTest ) == pdFALSE );
- }
-
-
-
-
- /* Incremented to show the task is still running. */
- ulFineCycleCount++;
-
- /* Leave all bits cleared. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, NULL, 0 );
- }
+ const TickType_t xTicksToWait = pdMS_TO_TICKS( 100UL );
+ BaseType_t xReturned;
+ uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedValue;
+ TickType_t xTimeOnEntering, xTimeNow, xTimeDifference;
+ const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;
+ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
+ UBaseType_t uxIndexToTest, uxOtherIndexes;
+
+
+ /* ------------------------------------------------------------------------
+ * Check blocking when there are no notifications. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* Send notifications to the task notification in each index of the
+ * task notification array other than the one on which this task will
+ * block. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes != uxIndexToTest )
+ {
+ xTaskNotifyIndexed( xTaskToNotify, uxOtherIndexes, 0, eNoAction );
+ }
+ }
+
+ xTimeOnEntering = xTaskGetTickCount();
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* Should have blocked for the entire block time. */
+ xTimeNow = xTaskGetTickCount();
+ xTimeDifference = xTimeNow - xTimeOnEntering;
+ configASSERT( xTimeDifference >= xTicksToWait );
+ configASSERT( xReturned == pdFAIL );
+ configASSERT( ulNotifiedValue == 0UL );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+ /* Clear all the other notifications within the array of task
+ * notifications again ready for the next round. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes != uxIndexToTest )
+ {
+ xReturned = xTaskNotifyStateClearIndexed( xTaskToNotify, uxOtherIndexes );
+
+ /* The notification state was set above so expect it to still be
+ * set. */
+ configASSERT( xReturned == pdTRUE );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+ }
+
+ /* ------------------------------------------------------------------------
+ * Check no blocking when notifications are pending. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* First notify the task notification at index uxIndexToTest within this
+ * task's own array of task notifications - this would not be a normal
+ * thing to do and is done here for test purposes only. */
+ xReturned = xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
+
+ /* Even through the 'without overwrite' action was used the update should
+ * have been successful. */
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* No bits should have been pending previously. */
+ configASSERT( ulPreviousValue == 0 );
+ ( void ) ulPreviousValue;
+
+ /* The task should now have a notification pending in the task
+ * notification at index uxIndexToTest within the task notification array,
+ * and so not time out. */
+ xTimeOnEntering = xTaskGetTickCount();
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );
+ xTimeNow = xTaskGetTickCount();
+ xTimeDifference = xTimeNow - xTimeOnEntering;
+ configASSERT( xTimeDifference < xTicksToWait );
+
+ /* The task should have been notified, and the notified value should
+ * be equal to ulFirstNotifiedConst. */
+ configASSERT( xReturned == pdPASS );
+ configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+ }
+
+ /*-------------------------------------------------------------------------
+ * Check the non-overwriting functionality. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* Send notifications to all indexes with the array of task
+ * notifications other than the one on which this task will block. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes != uxIndexToTest )
+ {
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxOtherIndexes, ulFirstNotifiedConst, eSetValueWithOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+
+ /* The notification is performed twice using two different notification
+ * values. The action says don't overwrite so only the first notification
+ * should pass and the value read back should also be that used with the
+ * first notification. The notification is sent to the task notification at
+ * index uxIndexToTest within the array of task notifications. */
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithoutOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulSecondNotifiedValueConst, eSetValueWithoutOverwrite );
+ configASSERT( xReturned == pdFAIL );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* Waiting for the notification should now return immediately so a block
+ * time of zero is used. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+
+ configASSERT( xReturned == pdPASS );
+ configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+ /* Clear all the other task notifications within the array of task
+ * notifications again ready for the next round. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes != uxIndexToTest )
+ {
+ xReturned = xTaskNotifyStateClearIndexed( xTaskToNotify, uxOtherIndexes );
+ configASSERT( xReturned == pdTRUE );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ ulNotifiedValue = ulTaskNotifyValueClearIndexed( xTaskToNotify, uxOtherIndexes, notifyUINT32_MAX );
+
+ /* The notification value was set to ulFirstNotifiedConst in all
+ * the other indexes, so expect it to still have that value. */
+ configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * Do the same again, only this time use the overwriting version. This time
+ * both notifications should pass, and the value written the second time should
+ * overwrite the value written the first time, and so be the value that is read
+ * back. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes != uxIndexToTest )
+ {
+ xTaskNotifyIndexed( xTaskToNotify, uxOtherIndexes, ulFirstNotifiedConst, eSetValueWithOverwrite );
+ }
+ }
+
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulSecondNotifiedValueConst, eSetValueWithOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, notifyUINT32_MAX, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
+ ( void ) ulNotifiedValue;
+
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes != uxIndexToTest )
+ {
+ xReturned = xTaskNotifyStateClearIndexed( xTaskToNotify, uxOtherIndexes );
+ configASSERT( xReturned == pdTRUE );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ulNotifiedValue = ulTaskNotifyValueClearIndexed( xTaskToNotify, uxOtherIndexes, notifyUINT32_MAX );
+ configASSERT( ulNotifiedValue == ulFirstNotifiedConst );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * For each task notification within the array of task notifications, check
+ * notifications with no action pass without updating the value. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* First set the notification values of the task notification at index
+ * uxIndexToTest of the array of task notification to
+ * ulSecondNotifiedValueConst. */
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulSecondNotifiedValueConst, eSetValueWithOverwrite );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* Even though ulFirstNotifiedConst is used as the value next, the value
+ * read back should remain at ulSecondNotifiedConst as the action is set
+ * to eNoAction. */
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eNoAction );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* All task notifications in the array of task notifications up to and
+ * including index uxIndexToTest should still contain the same value. */
+ for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
+ {
+ /* First zero is bits to clear on entry, the second is bits to clear on
+ * exist, the last 0 is the block time. */
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+
+ /* All array indexes in the array of task notifications after index
+ * uxIndexToTest should still contain 0 as they have not been set in this
+ * loop yet. This time use ulTaskNotifyValueClearIndexed() instead of
+ * xTaskNotifyWaitIndexed(), just for test coverage. */
+ for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ /* This time 0 is the bits to clear parameter - so clearing no bits. */
+ ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
+ configASSERT( ulNotifiedValue == 0 );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * Check incrementing values. For each task notification in the array of task
+ * notifications in turn, send ulMaxLoop increment notifications, then ensure
+ * the received value is as expected - which should be
+ * ulSecondNotificationValueConst plus how ever many times to loop iterated. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ for( ulLoop = 0; ulLoop < ulMaxLoops; ulLoop++ )
+ {
+ /* Increment the value of the task notification at index
+ * uxIndexToTest within the array of task notifications. */
+ xReturned = xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, 0, eIncrement );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+
+ /* All array indexes up to and including uxIndexToTest should still
+ * contain the updated value. */
+ for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
+ {
+ /* First zero is bits to clear on entry, the second is bits to clear on
+ * exist, the last 0 is the block time. */
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( ulNotifiedValue == ( ulSecondNotifiedValueConst + ulMaxLoops ) );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+
+ /* Should not be any notifications pending now. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdFAIL );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+
+ /* All notifications values in the array of task notifications after
+ * index uxIndexToTest should still contain the un-incremented
+ * ulSecondNotifiedValueConst as they have not been set in this loop yet.
+ * This time use ulTaskNotifyValueClearIndexed() instead of xTaskNotifyWaitIndexed(),
+ * just for test coverage. */
+ for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ /* This time 0 is the bits to clear parameter - so clearing no bits. */
+ ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
+ configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+
+ /* Clear all bits ready for next test. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* Start with all bits clear. */
+ ulTaskNotifyValueClearIndexed( NULL, uxIndexToTest, notifyUINT32_MAX );
+ }
+
+ /*-------------------------------------------------------------------------
+ * For each task notification in the array of task notifications in turn, check
+ * all bits in the notification's value can be set by notifying the task with
+ * one additional bit set on each notification, and exiting the loop when all
+ * the bits are found to be set. As there are 32-bits the loop should execute
+ * 32 times before all the bits are found to be set. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ ulNotifyingValue = 0x01;
+ ulLoop = 0;
+
+ do
+ {
+ /* Set the next bit in the value of the task notification at index
+ * uxIndexToTest within the array of task notifications. */
+ xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, ulNotifyingValue, eSetBits );
+
+ /* Wait for the notified value - which of course will already be
+ * available. Don't clear the bits on entry or exit as this loop is
+ * exited when all the bits are set. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ ulLoop++;
+
+ /* Use the next bit on the next iteration around this loop. */
+ ulNotifyingValue <<= 1UL;
+ } while( ulNotifiedValue != notifyUINT32_MAX );
+
+ /* As a 32-bit value was used the loop should have executed 32 times before
+ * all the bits were set. */
+ configASSERT( ulLoop == 32 );
+
+ /* The value of each task notification within the array of task
+ * notifications up to and including index uxIndexToTest should still have
+ * all bits set. */
+ for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
+ {
+ /* First zero is bits to clear on entry, the second is bits to clear on
+ * exist, the last 0 is the block time. */
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( ulNotifiedValue == notifyUINT32_MAX );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+
+ /* The value of each task notification within the array of task
+ * notifications after index uxIndexToTest should still contain 0 as they
+ * have not been set in this loop yet. This time use ulTaskNotifyValueClearIndexed()
+ * instead of xTaskNotifyWaitIndexed(), just for test coverage. */
+ for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ /* This time 0 is the bits to clear parameter - so clearing no bits. */
+ ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
+ configASSERT( ulNotifiedValue == 0 );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * For each task notification within the array of task notifications in turn,
+ * check bits are cleared on entry but not on exit when a notification fails
+ * to arrive before timing out - both with and without a timeout value. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* Wait for the notification - but this time it is not given by anything
+ * and should return pdFAIL. The parameters are set to clear bit zero on
+ * entry and bit one on exit. As no notification was received only the bit
+ * cleared on entry should actually get cleared. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, ulBit0, ulBit1, &ulNotifiedValue, xTicksToWait );
+ configASSERT( xReturned == pdFAIL );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* Send a notification with no action to the task notification at index
+ * uxIndexToTest within the array of task notifications. This should not
+ * update the bits even though notifyUINT32_MAX is used as the notification
+ * value. */
+ xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX, eNoAction );
+
+ /* All array indexes up to and including uxIndexToTest within the array
+ * of task notifications should have the modified value. */
+ for( uxOtherIndexes = 0; uxOtherIndexes <= uxIndexToTest; uxOtherIndexes++ )
+ {
+ /* Reading back the value should find bit 0 is clear, as this was cleared
+ * on entry, but bit 1 is not clear as it will not have been cleared on exit
+ * as no notification was received. */
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
+
+ if( uxOtherIndexes == uxIndexToTest )
+ {
+ /* This is the index being used this time round the loop and its
+ * notification state was set immediately above. */
+ configASSERT( xReturned == pdPASS );
+ }
+ else
+ {
+ /* Nothing should have set this index's notification state again. */
+ configASSERT( xReturned == pdFAIL );
+ }
+
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+
+ /* All array indexes after uxIndexToTest should still contain notifyUINT32_MAX
+ * left over from the previous test. This time use xTaskNotifyValueClear()
+ * instead of xTaskNotifyWaitIndexed(), just for test coverage. */
+ for( uxOtherIndexes = uxIndexToTest + 1; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ /* This time 0 is the bits to clear parameter - so clearing no bits. */
+ ulNotifiedValue = ulTaskNotifyValueClearIndexed( NULL, uxOtherIndexes, 0 );
+ configASSERT( ulNotifiedValue == notifyUINT32_MAX );
+ ( void ) ulNotifiedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * Now try clearing the bit on exit. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* The task is notified first using the task notification at index
+ * uxIndexToTest within the array of task notifications. */
+ xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, 0, eNoAction );
+ xTaskNotifyWaitIndexed( uxIndexToTest, 0x00, ulBit1, &ulNotifiedValue, 0 );
+
+ /* However as the bit is cleared on exit, after the returned notification
+ * value is set, the returned notification value should not have the bit
+ * cleared... */
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~ulBit0 ) );
+
+ /* ...but reading the value back again should find that the bit was indeed
+ * cleared internally. The returned value should be pdFAIL however as nothing
+ * has notified the task in the mean time. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0x00, 0x00, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdFAIL );
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* No other indexes should have a notification pending. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes != uxIndexToTest )
+ {
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0x00UL, 0x00UL, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdFAIL );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+ }
+ }
+
+ /*-------------------------------------------------------------------------
+ * For each task notification within the array of task notifications, try
+ * querying the previous value while notifying a task. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, 0x00, eSetBits, &ulPreviousValue );
+ configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );
+
+ /* Clear all bits. */
+ xTaskNotifyWaitIndexed( uxIndexToTest, 0x00, notifyUINT32_MAX, &ulNotifiedValue, 0 );
+ xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, 0x00, eSetBits, &ulPreviousValue );
+ configASSERT( ulPreviousValue == 0 );
+
+ ulExpectedValue = 0;
+
+ for( ulLoop = 0x01; ulLoop < 0x80UL; ulLoop <<= 1UL )
+ {
+ /* Set the next bit up, and expect to receive the last bits set (so
+ * the previous value will not yet have the bit being set this time
+ * around). */
+ xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, ulLoop, eSetBits, &ulPreviousValue );
+ configASSERT( ulExpectedValue == ulPreviousValue );
+ ulExpectedValue |= ulLoop;
+ }
+ }
+
+ /* ---------------------------------------------------------------------- */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* Clear the previous notifications. */
+ xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
+ }
+
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* No task notification within the array of task notifications should
+ * have any notification pending, so an attempt to clear the notification
+ * state should fail. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ configASSERT( xTaskNotifyStateClearIndexed( NULL, uxOtherIndexes ) == pdFALSE );
+ }
+
+ /* Get the task to notify itself using the task notification at index
+ * uxIndexToTest within the array of task notifications. This is not a
+ * normal thing to do, and is only done here for test purposes. */
+ xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToTest, ulFirstNotifiedConst, eSetValueWithoutOverwrite, &ulPreviousValue );
+
+ /* Now the notification state should be eNotified, so it should now be
+ * possible to clear the notification state. Other indexes should still
+ * not have a notification pending - likewise uxIndexToTest should not have
+ * a notification pending once it has been cleared. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ if( uxOtherIndexes == uxIndexToTest )
+ {
+ configASSERT( xTaskNotifyStateClearIndexed( NULL, uxOtherIndexes ) == pdTRUE );
+ }
+
+ configASSERT( xTaskNotifyStateClearIndexed( NULL, uxOtherIndexes ) == pdFALSE );
+ }
+ }
+
+ /* ------------------------------------------------------------------------
+ * For each task notification within the array of task notifications, clear
+ * bits in the notification value. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* Get the task to set all bits in its task notification at index
+ * uxIndexToTest within its array of task notifications. This is not a
+ * normal thing to do, and is only done here for test purposes. */
+ xTaskNotifyIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX, eSetBits );
+
+ /* Now clear the top bytes - the returned value from the first call
+ * should indicate that previously all bits were set. */
+ configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_HIGH_BYTE ) == notifyUINT32_MAX );
+
+ /* Next clear the bottom bytes - the returned value this time should
+ * indicate that the top byte was clear (before the bottom byte was
+ * cleared. */
+ configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_LOW_BYTE ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE ) );
+
+ /* Next clear all bytes - the returned value should indicate that previously the
+ * high and low bytes were clear. */
+ configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX ) == ( notifyUINT32_MAX & ~notifyUINT32_HIGH_BYTE & ~notifyUINT32_LOW_BYTE ) );
+
+ /* Now all bits should be clear. */
+ configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX ) == 0 );
+ configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, 0UL ) == 0 );
+ configASSERT( ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToTest, notifyUINT32_MAX ) == 0 );
+
+ /* Now the notification state should be eNotified, so it should now be
+ * possible to clear the notification state. */
+ configASSERT( xTaskNotifyStateClearIndexed( NULL, uxIndexToTest ) == pdTRUE );
+ configASSERT( xTaskNotifyStateClearIndexed( NULL, uxIndexToTest ) == pdFALSE );
+ }
+
+ /* Incremented to show the task is still running. */
+ ulFineCycleCount++;
+
+ /* Leave all bits cleared. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, NULL, 0 );
+ }
}
/*-----------------------------------------------------------*/
static void prvSuspendedTaskTimerTestCallback( TimerHandle_t xExpiredTimer )
{
-static uint32_t ulCallCount = 0;
-static UBaseType_t uxIndexToNotify = 0;
-
- /* Remove compiler warnings about unused parameters. */
- ( void ) xExpiredTimer;
-
- /* Callback for a timer that is used to send notifications to a task while
- it is suspended. The timer tests the behaviour when 1: a task waiting for a
- notification is suspended and then resumed without ever receiving a
- notification, and 2: when a task waiting for a notification receives a
- notification while it is suspended. Run one of two tests on every other
- invocation of this callback. The notification is sent to the task
- notification at index uxIndexToNotify. */
- if( ( ulCallCount & 0x01 ) == 0 )
- {
- vTaskSuspend( xTaskToNotify );
- configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
- vTaskResume( xTaskToNotify );
- }
- else
- {
- vTaskSuspend( xTaskToNotify );
-
- /* Sending a notification while the task is suspended should pass, but
- not cause the task to resume. */
- xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, 1, eSetValueWithOverwrite );
-
- /* Use the next task notification within the array of task notifications
- the next time around. */
- uxIndexToNotify++;
- if( uxIndexToNotify >= configTASK_NOTIFICATION_ARRAY_ENTRIES )
- {
- uxIndexToNotify = 0;
- }
-
- /* Make sure giving the notification didn't resume the task. */
- configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
-
- vTaskResume( xTaskToNotify );
- }
-
- ulCallCount++;
+ static uint32_t ulCallCount = 0;
+ static UBaseType_t uxIndexToNotify = 0;
+
+ /* Remove compiler warnings about unused parameters. */
+ ( void ) xExpiredTimer;
+
+ /* Callback for a timer that is used to send notifications to a task while
+ * it is suspended. The timer tests the behaviour when 1: a task waiting for a
+ * notification is suspended and then resumed without ever receiving a
+ * notification, and 2: when a task waiting for a notification receives a
+ * notification while it is suspended. Run one of two tests on every other
+ * invocation of this callback. The notification is sent to the task
+ * notification at index uxIndexToNotify. */
+ if( ( ulCallCount & 0x01 ) == 0 )
+ {
+ vTaskSuspend( xTaskToNotify );
+ configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
+ vTaskResume( xTaskToNotify );
+ }
+ else
+ {
+ vTaskSuspend( xTaskToNotify );
+
+ /* Sending a notification while the task is suspended should pass, but
+ * not cause the task to resume. */
+ xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, 1, eSetValueWithOverwrite );
+
+ /* Use the next task notification within the array of task notifications
+ * the next time around. */
+ uxIndexToNotify++;
+
+ if( uxIndexToNotify >= configTASK_NOTIFICATION_ARRAY_ENTRIES )
+ {
+ uxIndexToNotify = 0;
+ }
+
+ /* Make sure giving the notification didn't resume the task. */
+ configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );
+
+ vTaskResume( xTaskToNotify );
+ }
+
+ ulCallCount++;
}
/*-----------------------------------------------------------*/
static void prvNotifyingTimerCallback( TimerHandle_t xNotUsed )
{
-static BaseType_t uxIndexToNotify = 0;
-
- ( void ) xNotUsed;
-
- /* "Give" the task notification (which increments the target task
- notification value) at index uxIndexToNotify within the array of task
- notifications. */
- xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify );
-
- /* Use the next task notification within the array of task notifications the
- next time around. */
- uxIndexToNotify++;
- if( uxIndexToNotify >= configTASK_NOTIFICATION_ARRAY_ENTRIES )
- {
- uxIndexToNotify = 0;
- }
+ static BaseType_t uxIndexToNotify = 0;
+
+ ( void ) xNotUsed;
+
+ /* "Give" the task notification (which increments the target task
+ * notification value) at index uxIndexToNotify within the array of task
+ * notifications. */
+ xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify );
+
+ /* Use the next task notification within the array of task notifications the
+ * next time around. */
+ uxIndexToNotify++;
+
+ if( uxIndexToNotify >= configTASK_NOTIFICATION_ARRAY_ENTRIES )
+ {
+ uxIndexToNotify = 0;
+ }
}
/*-----------------------------------------------------------*/
static void prvTestNotifyTaskWhileSuspended( void )
{
-UBaseType_t uxIndexToTest, uxOtherIndexes;
-BaseType_t xReturned;
-uint32_t ulNotifiedValue;
-
- /* Raise the task's priority so it can suspend itself before the timer
- expires. */
- vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
-
- /* Perform the test on each task notification within the array or task
- notifications. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- /* Ensure no notifications within the array of task notifications are
- pending. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, NULL, 0 );
- configASSERT( xReturned == pdFALSE );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
-
- /* Start the timer that will try notifying this task while it is
- suspended, then wait for a notification. The first time the callback
- executes the timer will suspend the task, then resume the task, without
- ever sending a notification to the task. */
- ulNotifiedValue = 0;
- xTimerStart( xNotifyWhileSuspendedTimer, portMAX_DELAY );
-
- /* Check a notification is not received on the task notification at
- index uxIndexToTest within the array of task notifications. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, portMAX_DELAY );
- configASSERT( xReturned == pdFALSE );
- configASSERT( ulNotifiedValue == 0 );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* Check none of the task notifications within the array of task
- notifications as been notified. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdFALSE );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- }
-
- /* Start the timer that will try notifying this task while it is
- suspended, then wait for a notification at index uxIndexToTest within
- the array of task notifications. The second time the callback executes
- the timer will suspend the task, notify the task, then resume the task
- (previously it was suspended and resumed without being notified). */
- xTimerStart( xNotifyWhileSuspendedTimer, portMAX_DELAY );
-
- /* Check a notification is only received in the index within the array
- of task notifications under test. */
- xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, portMAX_DELAY );
- configASSERT( xReturned == pdPASS );
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- configASSERT( ulNotifiedValue != 0 );
-
- /* Check a notification is not received in any index within the array
- of task notifications at and below the index being tested have a notification
- value, and that indexes above the index being tested to not have
- notification values. */
- for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
- {
- xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
- configASSERT( xReturned == pdFALSE );
-
- if( uxOtherIndexes <= uxIndexToTest )
- {
- configASSERT( ulNotifiedValue == 1 );
- }
- else
- {
- configASSERT( ulNotifiedValue == 0 );
- }
- ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
- ( void ) ulNotifiedValue;
- }
- }
-
- /* Return the task to its proper priority */
- vTaskPrioritySet( NULL, notifyTASK_PRIORITY );
-
- /* Incremented to show the task is still running. */
- ulFineCycleCount++;
-
- /* Leave all bits cleared. */
- for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
- {
- xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, NULL, 0 );
- }
+ UBaseType_t uxIndexToTest, uxOtherIndexes;
+ BaseType_t xReturned;
+ uint32_t ulNotifiedValue;
+
+ /* Raise the task's priority so it can suspend itself before the timer
+ * expires. */
+ vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );
+
+ /* Perform the test on each task notification within the array or task
+ * notifications. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ /* Ensure no notifications within the array of task notifications are
+ * pending. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, NULL, 0 );
+ configASSERT( xReturned == pdFALSE );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+
+ /* Start the timer that will try notifying this task while it is
+ * suspended, then wait for a notification. The first time the callback
+ * executes the timer will suspend the task, then resume the task, without
+ * ever sending a notification to the task. */
+ ulNotifiedValue = 0;
+ xTimerStart( xNotifyWhileSuspendedTimer, portMAX_DELAY );
+
+ /* Check a notification is not received on the task notification at
+ * index uxIndexToTest within the array of task notifications. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, portMAX_DELAY );
+ configASSERT( xReturned == pdFALSE );
+ configASSERT( ulNotifiedValue == 0 );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* Check none of the task notifications within the array of task
+ * notifications as been notified. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdFALSE );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ }
+
+ /* Start the timer that will try notifying this task while it is
+ * suspended, then wait for a notification at index uxIndexToTest within
+ * the array of task notifications. The second time the callback executes
+ * the timer will suspend the task, notify the task, then resume the task
+ * (previously it was suspended and resumed without being notified). */
+ xTimerStart( xNotifyWhileSuspendedTimer, portMAX_DELAY );
+
+ /* Check a notification is only received in the index within the array
+ * of task notifications under test. */
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToTest, 0, 0, &ulNotifiedValue, portMAX_DELAY );
+ configASSERT( xReturned == pdPASS );
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ configASSERT( ulNotifiedValue != 0 );
+
+ /* Check a notification is not received in any index within the array
+ * of task notifications at and below the index being tested have a notification
+ * value, and that indexes above the index being tested to not have
+ * notification values. */
+ for( uxOtherIndexes = 0; uxOtherIndexes < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxOtherIndexes++ )
+ {
+ xReturned = xTaskNotifyWaitIndexed( uxOtherIndexes, 0, 0, &ulNotifiedValue, 0 );
+ configASSERT( xReturned == pdFALSE );
+
+ if( uxOtherIndexes <= uxIndexToTest )
+ {
+ configASSERT( ulNotifiedValue == 1 );
+ }
+ else
+ {
+ configASSERT( ulNotifiedValue == 0 );
+ }
+
+ ( void ) xReturned; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ( void ) ulNotifiedValue;
+ }
+ }
+
+ /* Return the task to its proper priority */
+ vTaskPrioritySet( NULL, notifyTASK_PRIORITY );
+
+ /* Incremented to show the task is still running. */
+ ulFineCycleCount++;
+
+ /* Leave all bits cleared. */
+ for( uxIndexToTest = 0; uxIndexToTest < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToTest++ )
+ {
+ xTaskNotifyWaitIndexed( uxIndexToTest, notifyUINT32_MAX, 0, NULL, 0 );
+ }
}
/* ------------------------------------------------------------------------ */
static void prvBlockOnTheNotifiedIndexed( void )
{
-const TickType_t xTimerPeriod = pdMS_TO_TICKS( 100 ), xMargin = pdMS_TO_TICKS( 50 ), xDontBlock = 0;
-UBaseType_t uxIndex, uxIndexToNotify;
-uint32_t ulReceivedValue;
-BaseType_t xReturned;
-
- /* Set the value of each notification in the array of task notifications to
- the value of its index position plus 1 so everything starts in a known
- state, then clear the notification state ready for the next test. Plus 1 is
- used because the index under test will use 0. */
- for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
- {
- xTaskNotifyIndexed( xTaskToNotify, uxIndex, uxIndex + 1, eSetValueWithOverwrite );
- xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndex );
- }
-
- /* Peform the test on each task notification within the array of task
- notifications. */
- for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
- {
- /* Set the notification value of the index being tested to 0 so the
- notification value increment/decrement functions can be tested. */
- xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, 0, eSetValueWithOverwrite );
- xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndexToNotify );
-
- /* Start the software timer then wait for it to notify this task. Block
- on the notification index we expect to receive the notification on. The
- margin is to ensure the task blocks longer than the timer period. */
- xTimerStart( xIncrementingIndexTimer, portMAX_DELAY );
- ulReceivedValue = ulTaskNotifyTakeIndexed( uxIndexToNotify, pdFALSE, xTimerPeriod + xMargin );
-
- /* The notification value was initially zero, and should have been
- incremented by the software timer, so now one. It will also have been
- decremented again by the call to ulTaskNotifyTakeIndexed() so gone back
- to 0. */
- configASSERT( ulReceivedValue == 1UL );
- ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* No other notification indexes should have changed, and therefore should
- still have their value set to their index plus 1 within the array of
- notifications. */
- for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
- {
- if( uxIndex != uxIndexToNotify )
- {
- xReturned = xTaskNotifyWaitIndexed( uxIndex, 0, 0, &ulReceivedValue, xDontBlock );
- configASSERT( xReturned == pdFALSE );
- configASSERT( ulReceivedValue == ( uxIndex + 1 ) );
- ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- ( void ) xReturned;
- }
- }
-
- /* Reset the notification value for the index just tested back to the
- index value plus 1 ready for the next iteration around this loop. */
- xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, uxIndexToNotify + 1, eSetValueWithOverwrite );
- xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndexToNotify );
-
- /* Incremented to show the task is still running. */
- ulFineCycleCount++;
- }
+ const TickType_t xTimerPeriod = pdMS_TO_TICKS( 100 ), xMargin = pdMS_TO_TICKS( 50 ), xDontBlock = 0;
+ UBaseType_t uxIndex, uxIndexToNotify;
+ uint32_t ulReceivedValue;
+ BaseType_t xReturned;
+
+ /* Set the value of each notification in the array of task notifications to
+ * the value of its index position plus 1 so everything starts in a known
+ * state, then clear the notification state ready for the next test. Plus 1 is
+ * used because the index under test will use 0. */
+ for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
+ {
+ xTaskNotifyIndexed( xTaskToNotify, uxIndex, uxIndex + 1, eSetValueWithOverwrite );
+ xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndex );
+ }
+
+ /* Peform the test on each task notification within the array of task
+ * notifications. */
+ for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
+ {
+ /* Set the notification value of the index being tested to 0 so the
+ * notification value increment/decrement functions can be tested. */
+ xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, 0, eSetValueWithOverwrite );
+ xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndexToNotify );
+
+ /* Start the software timer then wait for it to notify this task. Block
+ * on the notification index we expect to receive the notification on. The
+ * margin is to ensure the task blocks longer than the timer period. */
+ xTimerStart( xIncrementingIndexTimer, portMAX_DELAY );
+ ulReceivedValue = ulTaskNotifyTakeIndexed( uxIndexToNotify, pdFALSE, xTimerPeriod + xMargin );
+
+ /* The notification value was initially zero, and should have been
+ * incremented by the software timer, so now one. It will also have been
+ * decremented again by the call to ulTaskNotifyTakeIndexed() so gone back
+ * to 0. */
+ configASSERT( ulReceivedValue == 1UL );
+ ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* No other notification indexes should have changed, and therefore should
+ * still have their value set to their index plus 1 within the array of
+ * notifications. */
+ for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
+ {
+ if( uxIndex != uxIndexToNotify )
+ {
+ xReturned = xTaskNotifyWaitIndexed( uxIndex, 0, 0, &ulReceivedValue, xDontBlock );
+ configASSERT( xReturned == pdFALSE );
+ configASSERT( ulReceivedValue == ( uxIndex + 1 ) );
+ ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ( void ) xReturned;
+ }
+ }
+
+ /* Reset the notification value for the index just tested back to the
+ * index value plus 1 ready for the next iteration around this loop. */
+ xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, uxIndexToNotify + 1, eSetValueWithOverwrite );
+ xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndexToNotify );
+
+ /* Incremented to show the task is still running. */
+ ulFineCycleCount++;
+ }
}
/* ------------------------------------------------------------------------ */
static void prvBlockOnANonNotifiedIndexed( void )
{
-const TickType_t xTimerPeriod = pdMS_TO_TICKS( 100 ), xMargin = pdMS_TO_TICKS( 50 ), xDontBlock = 0;
-UBaseType_t uxIndex, uxIndexToNotify;
-uint32_t ulReceivedValue;
-BaseType_t xReturned;
-TickType_t xTimeBeforeBlocking, xTimeNow, xTimeDifference;
-
- /* Set all notify values within the array of tasks notifications to zero
- ready for the next test. */
- for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
- {
- ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToNotify, notifyUINT32_MAX );
- }
-
- /* Perform the test for each notification within the array of task
- notifications. */
- for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
- {
- /* Start the software timer then wait for it to notify this task. Block
- on a notification index that we do not expect to receive the notification
- on. The margin is to ensure the task blocks longer than the timer period. */
- xTimerStart( xIncrementingIndexTimer, portMAX_DELAY );
- xTimeBeforeBlocking = xTaskGetTickCount();
-
-
- if( uxIndexToNotify == ( configTASK_NOTIFICATION_ARRAY_ENTRIES - 1 ) )
- {
- /* configTASK_NOTIFICATION_ARRAY_ENTRIES - 1 is to be notified, so
- block on index 0. */
- uxIndex = 0;
- }
- else
- {
- /* The next index to get notified will be uxIndexToNotify, so block
- on uxIndexToNotify + 1 */
- uxIndex = uxIndexToNotify + 1;
- }
-
- xReturned = xTaskNotifyWaitIndexed( uxIndex, 0, 0, &ulReceivedValue, xTimerPeriod + xMargin );
-
- /* The notification will have been sent to task notification at index
- uxIndexToNotify in this task by the timer callback after xTimerPeriodTicks.
- The notification should not have woken this task, so xReturned should
- be false and at least xTimerPeriod + xMargin ticks should have passed. */
- configASSERT( xReturned == pdFALSE );
- xTimeNow = xTaskGetTickCount();
- xTimeDifference = xTimeNow - xTimeBeforeBlocking;
- configASSERT( xTimeDifference >= ( xTimerPeriod + xMargin ) );
- ( void ) xReturned; /* Remove compiler warnings if configASSERT() is not defined. */
- ( void ) xTimeBeforeBlocking;
- ( void ) xTimeDifference;
-
- /* Only the notification at index position uxIndexToNotify should be
- set. Calling this function will clear it again. */
- for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
- {
- xReturned = xTaskNotifyWaitIndexed( uxIndex, 0, 0, &ulReceivedValue, xDontBlock );
-
- if( uxIndex == uxIndexToNotify )
- {
- /* Expect the notification state to be set and the notification
- value to have been incremented. */
- configASSERT( xReturned == pdTRUE );
- configASSERT( ulReceivedValue == 1 );
-
- /* Set the notification value for this array index back to 0. */
- ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndex, notifyUINT32_MAX );
- }
- else
- {
- /* Expect the notification state to be clear and the notification
- value to remain at zer0. */
- configASSERT( xReturned == pdFALSE );
- configASSERT( ulReceivedValue == 0 );
- }
- }
-
- /* Incremented to show the task is still running. */
- ulFineCycleCount++;
- }
+ const TickType_t xTimerPeriod = pdMS_TO_TICKS( 100 ), xMargin = pdMS_TO_TICKS( 50 ), xDontBlock = 0;
+ UBaseType_t uxIndex, uxIndexToNotify;
+ uint32_t ulReceivedValue;
+ BaseType_t xReturned;
+ TickType_t xTimeBeforeBlocking, xTimeNow, xTimeDifference;
+
+ /* Set all notify values within the array of tasks notifications to zero
+ * ready for the next test. */
+ for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
+ {
+ ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndexToNotify, notifyUINT32_MAX );
+ }
+
+ /* Perform the test for each notification within the array of task
+ * notifications. */
+ for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
+ {
+ /* Start the software timer then wait for it to notify this task. Block
+ * on a notification index that we do not expect to receive the notification
+ * on. The margin is to ensure the task blocks longer than the timer period. */
+ xTimerStart( xIncrementingIndexTimer, portMAX_DELAY );
+ xTimeBeforeBlocking = xTaskGetTickCount();
+
+ if( uxIndexToNotify == ( configTASK_NOTIFICATION_ARRAY_ENTRIES - 1 ) )
+ {
+ /* configTASK_NOTIFICATION_ARRAY_ENTRIES - 1 is to be notified, so
+ * block on index 0. */
+ uxIndex = 0;
+ }
+ else
+ {
+ /* The next index to get notified will be uxIndexToNotify, so block
+ * on uxIndexToNotify + 1 */
+ uxIndex = uxIndexToNotify + 1;
+ }
+
+ xReturned = xTaskNotifyWaitIndexed( uxIndex, 0, 0, &ulReceivedValue, xTimerPeriod + xMargin );
+
+ /* The notification will have been sent to task notification at index
+ * uxIndexToNotify in this task by the timer callback after xTimerPeriodTicks.
+ * The notification should not have woken this task, so xReturned should
+ * be false and at least xTimerPeriod + xMargin ticks should have passed. */
+ configASSERT( xReturned == pdFALSE );
+ xTimeNow = xTaskGetTickCount();
+ xTimeDifference = xTimeNow - xTimeBeforeBlocking;
+ configASSERT( xTimeDifference >= ( xTimerPeriod + xMargin ) );
+ ( void ) xReturned; /* Remove compiler warnings if configASSERT() is not defined. */
+ ( void ) xTimeBeforeBlocking;
+ ( void ) xTimeDifference;
+
+ /* Only the notification at index position uxIndexToNotify should be
+ * set. Calling this function will clear it again. */
+ for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
+ {
+ xReturned = xTaskNotifyWaitIndexed( uxIndex, 0, 0, &ulReceivedValue, xDontBlock );
+
+ if( uxIndex == uxIndexToNotify )
+ {
+ /* Expect the notification state to be set and the notification
+ * value to have been incremented. */
+ configASSERT( xReturned == pdTRUE );
+ configASSERT( ulReceivedValue == 1 );
+
+ /* Set the notification value for this array index back to 0. */
+ ulTaskNotifyValueClearIndexed( xTaskToNotify, uxIndex, notifyUINT32_MAX );
+ }
+ else
+ {
+ /* Expect the notification state to be clear and the notification
+ * value to remain at zer0. */
+ configASSERT( xReturned == pdFALSE );
+ configASSERT( ulReceivedValue == 0 );
+ }
+ }
+
+ /* Incremented to show the task is still running. */
+ ulFineCycleCount++;
+ }
}
/* ------------------------------------------------------------------------ */
static void prvBlockOnNotificationsComingFromInterrupts( void )
{
-UBaseType_t uxIndex, uxIndexToNotify;
-uint32_t ulReceivedValue;
-BaseType_t xReturned;
-const TickType_t xDontBlock = 0;
-
- /* Set the value of each notification within the array of task notifications
- to zero so the task can block on xTaskNotifyTake(). */
- for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
- {
- xTaskNotifyIndexed( xTaskToNotify, uxIndex, 0, eSetValueWithOverwrite );
- xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndex );
- }
-
- /* Perform the test on each task notification within the array of task
- notifications. */
- for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
- {
- /* Tell the interrupt to send the next notification. */
- taskENTER_CRITICAL();
- {
- /* Don't expect to find xSendNotificationFromISR set at this time as
- the interrupt should have cleared it back to pdFALSE last time it
- executed. */
- configASSERT( xSendNotificationFromISR == pdFALSE );
- xSendNotificationFromISR = pdTRUE;
- }
- taskEXIT_CRITICAL();
-
- /* Wait for a notification on the task notification at index
- uxIndexToNotify within the array of task notifications. */
- ulReceivedValue = ulTaskNotifyTakeIndexed( uxIndexToNotify, pdTRUE, portMAX_DELAY );
-
- /* Interrupt should have reset xSendNotificationFromISR after it sent
- the notification. */
- configASSERT( xSendNotificationFromISR == pdFALSE );
-
- /* The notification value was initially zero, and should have been
- incremented by the interrupt, so now one. */
- configASSERT( ulReceivedValue == 1UL );
- ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
-
- /* No other notification indexes should have changed, and therefore should
- still have their value set to 0. The value in array index uxIndexToNotify
- should also have been decremented back to zero by the call to
- ulTaskNotifyTakeIndexed(). */
- for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
- {
- xReturned = xTaskNotifyWaitIndexed( uxIndexToNotify, 0, 0, &ulReceivedValue, xDontBlock );
- configASSERT( xReturned == pdFALSE );
- configASSERT( ulReceivedValue == 0 );
- ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
- ( void ) xReturned;
- }
-
- /* Incremented to show the task is still running. */
- ulFineCycleCount++;
- }
+ UBaseType_t uxIndex, uxIndexToNotify;
+ uint32_t ulReceivedValue;
+ BaseType_t xReturned;
+ const TickType_t xDontBlock = 0;
+
+ /* Set the value of each notification within the array of task notifications
+ * to zero so the task can block on xTaskNotifyTake(). */
+ for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
+ {
+ xTaskNotifyIndexed( xTaskToNotify, uxIndex, 0, eSetValueWithOverwrite );
+ xTaskNotifyStateClearIndexed( xTaskToNotify, uxIndex );
+ }
+
+ /* Perform the test on each task notification within the array of task
+ * notifications. */
+ for( uxIndexToNotify = 0; uxIndexToNotify < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndexToNotify++ )
+ {
+ /* Tell the interrupt to send the next notification. */
+ taskENTER_CRITICAL();
+ {
+ /* Don't expect to find xSendNotificationFromISR set at this time as
+ * the interrupt should have cleared it back to pdFALSE last time it
+ * executed. */
+ configASSERT( xSendNotificationFromISR == pdFALSE );
+ xSendNotificationFromISR = pdTRUE;
+ }
+ taskEXIT_CRITICAL();
+
+ /* Wait for a notification on the task notification at index
+ * uxIndexToNotify within the array of task notifications. */
+ ulReceivedValue = ulTaskNotifyTakeIndexed( uxIndexToNotify, pdTRUE, portMAX_DELAY );
+
+ /* Interrupt should have reset xSendNotificationFromISR after it sent
+ * the notification. */
+ configASSERT( xSendNotificationFromISR == pdFALSE );
+
+ /* The notification value was initially zero, and should have been
+ * incremented by the interrupt, so now one. */
+ configASSERT( ulReceivedValue == 1UL );
+ ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+
+ /* No other notification indexes should have changed, and therefore should
+ * still have their value set to 0. The value in array index uxIndexToNotify
+ * should also have been decremented back to zero by the call to
+ * ulTaskNotifyTakeIndexed(). */
+ for( uxIndex = 0; uxIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES; uxIndex++ )
+ {
+ xReturned = xTaskNotifyWaitIndexed( uxIndexToNotify, 0, 0, &ulReceivedValue, xDontBlock );
+ configASSERT( xReturned == pdFALSE );
+ configASSERT( ulReceivedValue == 0 );
+ ( void ) ulReceivedValue; /* Remove compiler warnings in case configASSERT() is not defined. */
+ ( void ) xReturned;
+ }
+
+ /* Incremented to show the task is still running. */
+ ulFineCycleCount++;
+ }
}
/*-----------------------------------------------------------*/
void xNotifyArrayTaskFromISR( void )
{
-static BaseType_t xAPIToUse = 0;
-uint32_t ulPreviousValue;
-const uint32_t ulUnexpectedValue = 0xff;
-static UBaseType_t uxIndexToNotify = 0;
-
- /* Check the task notification demo task was actually created. */
- configASSERT( xTaskToNotify );
-
- /* The task sets xSendNotificationFromISR to pdTRUE each time it wants this
- interrupt (this function runs in the RTOS tick hook) to send the next
- notification. */
- if( xSendNotificationFromISR == pdTRUE )
- {
- xSendNotificationFromISR = pdFALSE;
-
- /* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR()
- and xTaskNotifyAndQueryFromISR(). The notification is set to the task
- notification at index uxIndexToNotify within the array of task
- notifications. */
- switch( xAPIToUse )
- {
- case 0: vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, NULL );
- xAPIToUse++;
- break;
-
- case 1: xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, 0, eIncrement, NULL );
- xAPIToUse++;
- break;
-
- case 2: ulPreviousValue = ulUnexpectedValue;
- xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, 0, eIncrement, &ulPreviousValue, NULL );
- configASSERT( ulPreviousValue == 0 );
- xAPIToUse = 0;
- break;
-
- default:/* Should never get here!. */
- break;
- }
-
- /* Use the next index in the array of task notifications the next time
- around. */
- uxIndexToNotify++;
- if( uxIndexToNotify >= configTASK_NOTIFICATION_ARRAY_ENTRIES )
- {
- uxIndexToNotify = 0;
- }
- }
+ static BaseType_t xAPIToUse = 0;
+ uint32_t ulPreviousValue;
+ const uint32_t ulUnexpectedValue = 0xff;
+ static UBaseType_t uxIndexToNotify = 0;
+
+ /* Check the task notification demo task was actually created. */
+ configASSERT( xTaskToNotify );
+
+ /* The task sets xSendNotificationFromISR to pdTRUE each time it wants this
+ * interrupt (this function runs in the RTOS tick hook) to send the next
+ * notification. */
+ if( xSendNotificationFromISR == pdTRUE )
+ {
+ xSendNotificationFromISR = pdFALSE;
+
+ /* Test using both vTaskNotifyGiveFromISR(), xTaskNotifyFromISR()
+ * and xTaskNotifyAndQueryFromISR(). The notification is set to the task
+ * notification at index uxIndexToNotify within the array of task
+ * notifications. */
+ switch( xAPIToUse )
+ {
+ case 0:
+ vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, NULL );
+ xAPIToUse++;
+ break;
+
+ case 1:
+ xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, 0, eIncrement, NULL );
+ xAPIToUse++;
+ break;
+
+ case 2:
+ ulPreviousValue = ulUnexpectedValue;
+ xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, 0, eIncrement, &ulPreviousValue, NULL );
+ configASSERT( ulPreviousValue == 0 );
+ xAPIToUse = 0;
+ break;
+
+ default: /* Should never get here!. */
+ break;
+ }
+
+ /* Use the next index in the array of task notifications the next time
+ * around. */
+ uxIndexToNotify++;
+
+ if( uxIndexToNotify >= configTASK_NOTIFICATION_ARRAY_ENTRIES )
+ {
+ uxIndexToNotify = 0;
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check the created tasks are still running and have not
-detected any errors. */
+ * detected any errors. */
BaseType_t xAreTaskNotificationArrayTasksStillRunning( void )
{
-static uint32_t ulLastFineCycleCount = 0, ulLastCourseCycleCount = 0, ulCallCount = 0;
-const uint32_t ulCallsBetweenCourseCycleCountChecks = 3UL;
-static BaseType_t xErrorStatus = pdPASS;
-
- /* Check the cycle count is still incrementing to ensure the task is still
- actually running. The fine counter is incremented within individual test
- functions. The course counter is incremented one each time all the test
- functions have been executed to ensure all the tests are running. */
- if( ulLastFineCycleCount == ulFineCycleCount )
- {
- xErrorStatus = pdFAIL;
- }
- else
- {
- ulLastFineCycleCount = ulFineCycleCount;
- }
-
- ulCallCount++;
- if( ulCallCount >= ulCallsBetweenCourseCycleCountChecks )
- {
- ulCallCount = 0;
- if( ulLastCourseCycleCount == ulCourseCycleCounter )
- {
- xErrorStatus = pdFAIL;
- }
- else
- {
- ulLastCourseCycleCount = ulCourseCycleCounter;
- }
- }
-
- return xErrorStatus;
+ static uint32_t ulLastFineCycleCount = 0, ulLastCourseCycleCount = 0, ulCallCount = 0;
+ const uint32_t ulCallsBetweenCourseCycleCountChecks = 3UL;
+ static BaseType_t xErrorStatus = pdPASS;
+
+ /* Check the cycle count is still incrementing to ensure the task is still
+ * actually running. The fine counter is incremented within individual test
+ * functions. The course counter is incremented one each time all the test
+ * functions have been executed to ensure all the tests are running. */
+ if( ulLastFineCycleCount == ulFineCycleCount )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastFineCycleCount = ulFineCycleCount;
+ }
+
+ ulCallCount++;
+
+ if( ulCallCount >= ulCallsBetweenCourseCycleCountChecks )
+ {
+ ulCallCount = 0;
+
+ if( ulLastCourseCycleCount == ulCourseCycleCounter )
+ {
+ xErrorStatus = pdFAIL;
+ }
+ else
+ {
+ ulLastCourseCycleCount = ulCourseCycleCounter;
+ }
+ }
+
+ return xErrorStatus;
}
/*-----------------------------------------------------------*/
static UBaseType_t prvRand( void )
{
-const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;
+ const size_t uxMultiplier = ( size_t ) 0x015a4e35, uxIncrement = ( size_t ) 1;
- /* Utility function to generate a pseudo random number. */
- uxNextRand = ( uxMultiplier * uxNextRand ) + uxIncrement;
- return( ( uxNextRand >> 16 ) & ( ( size_t ) 0x7fff ) );
+ /* Utility function to generate a pseudo random number. */
+ uxNextRand = ( uxMultiplier * uxNextRand ) + uxIncrement;
+ return( ( uxNextRand >> 16 ) & ( ( size_t ) 0x7fff ) );
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Common/Minimal/TimerDemo.c b/FreeRTOS/Demo/Common/Minimal/TimerDemo.c
index dfb8c210a..4dd2f35b9 100644
--- a/FreeRTOS/Demo/Common/Minimal/TimerDemo.c
+++ b/FreeRTOS/Demo/Common/Minimal/TimerDemo.c
@@ -42,38 +42,38 @@
#include "TimerDemo.h"
#if ( configTIMER_TASK_PRIORITY < 1 )
- #error configTIMER_TASK_PRIORITY must be set to at least 1 for this test/demo to function correctly.
+ #error configTIMER_TASK_PRIORITY must be set to at least 1 for this test/demo to function correctly.
#endif
-#define tmrdemoDONT_BLOCK ( ( TickType_t ) 0 )
-#define tmrdemoONE_SHOT_TIMER_PERIOD ( xBasePeriod * ( TickType_t ) 3 )
-#define tmrdemoNUM_TIMER_RESETS ( ( uint8_t ) 10 )
+#define tmrdemoDONT_BLOCK ( ( TickType_t ) 0 )
+#define tmrdemoONE_SHOT_TIMER_PERIOD ( xBasePeriod * ( TickType_t ) 3 )
+#define tmrdemoNUM_TIMER_RESETS ( ( uint8_t ) 10 )
#ifndef tmrTIMER_TEST_TASK_STACK_SIZE
- #define tmrTIMER_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define tmrTIMER_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
/*-----------------------------------------------------------*/
/* The callback functions used by the timers. These each increment a counter
-to indicate which timer has expired. The auto-reload timers that are used by
-the test task (as opposed to being used from an ISR) all share the same
-prvAutoReloadTimerCallback() callback function, and use the ID of the
-pxExpiredTimer parameter passed into that function to know which counter to
-increment. The other timers all have their own unique callback function and
-simply increment their counters without using the callback function parameter. */
+ * to indicate which timer has expired. The auto-reload timers that are used by
+ * the test task (as opposed to being used from an ISR) all share the same
+ * prvAutoReloadTimerCallback() callback function, and use the ID of the
+ * pxExpiredTimer parameter passed into that function to know which counter to
+ * increment. The other timers all have their own unique callback function and
+ * simply increment their counters without using the callback function parameter. */
static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );
static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer );
-static void prvTimerTestTask( void *pvParameters );
+static void prvTimerTestTask( void * pvParameters );
static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer );
static void prvISROneShotTimerCallback( TimerHandle_t pxExpiredTimer );
/* The test functions used by the timer test task. These manipulate the auto
-reload and one-shot timers in various ways, then delay, then inspect the timers
-to ensure they have behaved as expected. */
+ * reload and one-shot timers in various ways, then delay, then inspect the timers
+ * to ensure they have behaved as expected. */
static void prvTest1_CreateTimersWithoutSchedulerRunning( void );
static void prvTest2_CheckTaskAndTimersInitialState( void );
-static void prvTest3_CheckAutoReloadExpireRates( void );
+static void prvTest3_CheckAutoReloadExpireRates( void );
static void prvTest4_CheckAutoReloadTimersCanBeStopped( void );
static void prvTest5_CheckBasicOneShotTimerBehaviour( void );
static void prvTest6_CheckAutoReloadResetBehaviour( void );
@@ -83,1015 +83,1021 @@ static void prvResetStartConditionsForNextIteration( void );
/*-----------------------------------------------------------*/
/* Flag that will be latched to pdFAIL should any unexpected behaviour be
-detected in any of the demo tests. */
+ * detected in any of the demo tests. */
static volatile BaseType_t xTestStatus = pdPASS;
/* Flag indicating whether the testing includes the backlog demo. The backlog
-demo can be disruptive to other demos because the timer backlog is created by
-calling xTaskCatchUpTicks(). */
+ * demo can be disruptive to other demos because the timer backlog is created by
+ * calling xTaskCatchUpTicks(). */
static uint8_t ucIsBacklogDemoEnabled = ( uint8_t ) pdFALSE;
/* Counter that is incremented on each cycle of a test. This is used to
-detect a stalled task - a test that is no longer running. */
+ * detect a stalled task - a test that is no longer running. */
static volatile uint32_t ulLoopCounter = 0;
/* A set of auto-reload timers - each of which use the same callback function.
-The callback function uses the timer ID to index into, and then increment, a
-counter in the ucAutoReloadTimerCounters[] array. The callback function stops
-xAutoReloadTimers[0] during its callback if ucIsStopNeededInTimerZeroCallback is
-pdTRUE. The auto-reload timers referenced from xAutoReloadTimers[] are used by
-the prvTimerTestTask task. */
+ * The callback function uses the timer ID to index into, and then increment, a
+ * counter in the ucAutoReloadTimerCounters[] array. The callback function stops
+ * xAutoReloadTimers[0] during its callback if ucIsStopNeededInTimerZeroCallback is
+ * pdTRUE. The auto-reload timers referenced from xAutoReloadTimers[] are used by
+ * the prvTimerTestTask task. */
static TimerHandle_t xAutoReloadTimers[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };
static uint8_t ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH + 1 ] = { 0 };
static uint8_t ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdFALSE;
/* The one-shot timer is configured to use a callback function that increments
-ucOneShotTimerCounter each time it gets called. */
+ * ucOneShotTimerCounter each time it gets called. */
static TimerHandle_t xOneShotTimer = NULL;
static uint8_t ucOneShotTimerCounter = ( uint8_t ) 0;
/* The ISR reload timer is controlled from the tick hook to exercise the timer
-API functions that can be used from an ISR. It is configured to increment
-ucISRReloadTimerCounter each time its callback function is executed. */
+ * API functions that can be used from an ISR. It is configured to increment
+ * ucISRReloadTimerCounter each time its callback function is executed. */
static TimerHandle_t xISRAutoReloadTimer = NULL;
static uint8_t ucISRAutoReloadTimerCounter = ( uint8_t ) 0;
/* The ISR one-shot timer is controlled from the tick hook to exercise the timer
-API functions that can be used from an ISR. It is configured to increment
-ucISRReloadTimerCounter each time its callback function is executed. */
+ * API functions that can be used from an ISR. It is configured to increment
+ * ucISRReloadTimerCounter each time its callback function is executed. */
static TimerHandle_t xISROneShotTimer = NULL;
static uint8_t ucISROneShotTimerCounter = ( uint8_t ) 0;
/* The period of all the timers are a multiple of the base period. The base
-period is configured by the parameter to vStartTimerDemoTask(). */
+ * period is configured by the parameter to vStartTimerDemoTask(). */
static TickType_t xBasePeriod = 0;
/*-----------------------------------------------------------*/
void vStartTimerDemoTask( TickType_t xBasePeriodIn )
{
- /* Start with the timer and counter arrays clear - this is only necessary
- where the compiler does not clear them automatically on start up. */
- memset( ucAutoReloadTimerCounters, 0x00, sizeof( ucAutoReloadTimerCounters ) );
- memset( xAutoReloadTimers, 0x00, sizeof( xAutoReloadTimers ) );
-
- /* Store the period from which all the timer periods will be generated from
- (multiples of). */
- xBasePeriod = xBasePeriodIn;
-
- /* Create a set of timers for use by this demo/test. */
- prvTest1_CreateTimersWithoutSchedulerRunning();
-
- /* Create the task that will control and monitor the timers. This is
- created at a lower priority than the timer service task to ensure, as
- far as it is concerned, commands on timers are acted on immediately
- (sending a command to the timer service task will unblock the timer service
- task, which will then preempt this task). */
- if( xTestStatus != pdFAIL )
- {
- xTaskCreate( prvTimerTestTask, "Tmr Tst", tmrTIMER_TEST_TASK_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );
- }
+ /* Start with the timer and counter arrays clear - this is only necessary
+ * where the compiler does not clear them automatically on start up. */
+ memset( ucAutoReloadTimerCounters, 0x00, sizeof( ucAutoReloadTimerCounters ) );
+ memset( xAutoReloadTimers, 0x00, sizeof( xAutoReloadTimers ) );
+
+ /* Store the period from which all the timer periods will be generated from
+ * (multiples of). */
+ xBasePeriod = xBasePeriodIn;
+
+ /* Create a set of timers for use by this demo/test. */
+ prvTest1_CreateTimersWithoutSchedulerRunning();
+
+ /* Create the task that will control and monitor the timers. This is
+ * created at a lower priority than the timer service task to ensure, as
+ * far as it is concerned, commands on timers are acted on immediately
+ * (sending a command to the timer service task will unblock the timer service
+ * task, which will then preempt this task). */
+ if( xTestStatus != pdFAIL )
+ {
+ xTaskCreate( prvTimerTestTask, "Tmr Tst", tmrTIMER_TEST_TASK_STACK_SIZE, NULL, configTIMER_TASK_PRIORITY - 1, NULL );
+ }
}
/*-----------------------------------------------------------*/
void vTimerDemoIncludeBacklogTests( BaseType_t includeBacklogTests )
{
- ucIsBacklogDemoEnabled = ( uint8_t ) includeBacklogTests;
+ ucIsBacklogDemoEnabled = ( uint8_t ) includeBacklogTests;
}
/*-----------------------------------------------------------*/
-static void prvTimerTestTask( void *pvParameters )
+static void prvTimerTestTask( void * pvParameters )
{
- ( void ) pvParameters;
-
- /* Create a one-shot timer for use later on in this test. For test purposes it
- is created as an auto-reload timer then converted to a one-shot timer. */
- xOneShotTimer = xTimerCreate( "Oneshot Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
- tmrdemoONE_SHOT_TIMER_PERIOD, /* The period for the timer. */
- pdFALSE, /* Autoreload is false, so created as a one-shot timer. */
- ( void * ) 0, /* The timer identifier. Initialise to 0, then increment each time it is called. */
- prvOneShotTimerCallback ); /* The callback to be called when the timer expires. */
-
- if( xOneShotTimer == NULL )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Purely for test coverage purposes - change and query the reload mode to
- auto-reload then back to one-shot. */
-
- /* Change timer to auto-reload. */
- vTimerSetReloadMode( xOneShotTimer, pdTRUE );
-
- /* Timer should now be auto-reload. */
- configASSERT( uxTimerGetReloadMode( xOneShotTimer ) == pdTRUE );
-
- /* Change timer to one-shot, which is what is needed for this test. */
- vTimerSetReloadMode( xOneShotTimer, pdFALSE );
-
- /* Check change to one-shot was successful. */
- configASSERT( uxTimerGetReloadMode( xOneShotTimer ) == pdFALSE );
-
- /* Ensure all the timers are in their expected initial state. This
- depends on the timer service task having a higher priority than this task. */
- prvTest2_CheckTaskAndTimersInitialState();
-
- for( ;; )
- {
- /* Check the auto-reload timers expire at the expected/correct rates. */
- prvTest3_CheckAutoReloadExpireRates();
-
- /* Check the auto-reload timers can be stopped correctly, and correctly
- report their state. */
- prvTest4_CheckAutoReloadTimersCanBeStopped();
-
- /* Check the one-shot timer only calls its callback once after it has been
- started, and that it reports its state correctly. */
- prvTest5_CheckBasicOneShotTimerBehaviour();
-
- /* Check timer reset behaviour. */
- prvTest6_CheckAutoReloadResetBehaviour();
-
- /* Check timer behaviour when the timer task gets behind in its work. */
- if ( ucIsBacklogDemoEnabled == ( uint8_t ) pdTRUE )
- {
- prvTest7_CheckBacklogBehaviour();
- }
-
- /* Start the timers again to restart all the tests over again. */
- prvResetStartConditionsForNextIteration();
- }
+ ( void ) pvParameters;
+
+ /* Create a one-shot timer for use later on in this test. For test purposes it
+ * is created as an auto-reload timer then converted to a one-shot timer. */
+ xOneShotTimer = xTimerCreate( "Oneshot Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
+ tmrdemoONE_SHOT_TIMER_PERIOD, /* The period for the timer. */
+ pdFALSE, /* Autoreload is false, so created as a one-shot timer. */
+ ( void * ) 0, /* The timer identifier. Initialise to 0, then increment each time it is called. */
+ prvOneShotTimerCallback ); /* The callback to be called when the timer expires. */
+
+ if( xOneShotTimer == NULL )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Purely for test coverage purposes - change and query the reload mode to
+ * auto-reload then back to one-shot. */
+
+ /* Change timer to auto-reload. */
+ vTimerSetReloadMode( xOneShotTimer, pdTRUE );
+
+ /* Timer should now be auto-reload. */
+ configASSERT( uxTimerGetReloadMode( xOneShotTimer ) == pdTRUE );
+
+ /* Change timer to one-shot, which is what is needed for this test. */
+ vTimerSetReloadMode( xOneShotTimer, pdFALSE );
+
+ /* Check change to one-shot was successful. */
+ configASSERT( uxTimerGetReloadMode( xOneShotTimer ) == pdFALSE );
+
+ /* Ensure all the timers are in their expected initial state. This
+ * depends on the timer service task having a higher priority than this task. */
+ prvTest2_CheckTaskAndTimersInitialState();
+
+ for( ; ; )
+ {
+ /* Check the auto-reload timers expire at the expected/correct rates. */
+ prvTest3_CheckAutoReloadExpireRates();
+
+ /* Check the auto-reload timers can be stopped correctly, and correctly
+ * report their state. */
+ prvTest4_CheckAutoReloadTimersCanBeStopped();
+
+ /* Check the one-shot timer only calls its callback once after it has been
+ * started, and that it reports its state correctly. */
+ prvTest5_CheckBasicOneShotTimerBehaviour();
+
+ /* Check timer reset behaviour. */
+ prvTest6_CheckAutoReloadResetBehaviour();
+
+ /* Check timer behaviour when the timer task gets behind in its work. */
+ if( ucIsBacklogDemoEnabled == ( uint8_t ) pdTRUE )
+ {
+ prvTest7_CheckBacklogBehaviour();
+ }
+
+ /* Start the timers again to restart all the tests over again. */
+ prvResetStartConditionsForNextIteration();
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that the created task is still running and has not
-detected any errors. */
+ * detected any errors. */
BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )
{
-static uint32_t ulLastLoopCounter = 0UL;
-TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
-static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCycleFrequency;
-
- if( xLastCycleFrequency != xCycleFrequency )
- {
- /* The cycle frequency has probably become much faster due to an error
- elsewhere. Start counting Iterations again. */
- xIterationsWithoutCounterIncrement = ( TickType_t ) 0;
- xLastCycleFrequency = xCycleFrequency;
- }
-
- /* Calculate the maximum number of times that it is permissible for this
- function to be called without ulLoopCounter being incremented. This is
- necessary because the tests in this file block for extended periods, and the
- block period might be longer than the time between calls to this function. */
- xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
- xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;
-
- /* If the demo task is still running then the loop counter is expected to
- have incremented every xLoopCounterIncrementTimeMax calls. */
- if( ulLastLoopCounter == ulLoopCounter )
- {
- xIterationsWithoutCounterIncrement++;
- if( xIterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )
- {
- /* The tests appear to be no longer running (stalled). */
- xTestStatus = pdFAIL;
- }
- }
- else
- {
- /* ulLoopCounter changed, so the count of times this function was called
- without a change can be reset to zero. */
- xIterationsWithoutCounterIncrement = ( TickType_t ) 0;
- }
-
- ulLastLoopCounter = ulLoopCounter;
-
- /* Errors detected in the task itself will have latched xTestStatus
- to pdFAIL. */
-
- return xTestStatus;
+ static uint32_t ulLastLoopCounter = 0UL;
+ TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
+ static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCycleFrequency;
+
+ if( xLastCycleFrequency != xCycleFrequency )
+ {
+ /* The cycle frequency has probably become much faster due to an error
+ * elsewhere. Start counting Iterations again. */
+ xIterationsWithoutCounterIncrement = ( TickType_t ) 0;
+ xLastCycleFrequency = xCycleFrequency;
+ }
+
+ /* Calculate the maximum number of times that it is permissible for this
+ * function to be called without ulLoopCounter being incremented. This is
+ * necessary because the tests in this file block for extended periods, and the
+ * block period might be longer than the time between calls to this function. */
+ xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
+ xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;
+
+ /* If the demo task is still running then the loop counter is expected to
+ * have incremented every xLoopCounterIncrementTimeMax calls. */
+ if( ulLastLoopCounter == ulLoopCounter )
+ {
+ xIterationsWithoutCounterIncrement++;
+
+ if( xIterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )
+ {
+ /* The tests appear to be no longer running (stalled). */
+ xTestStatus = pdFAIL;
+ }
+ }
+ else
+ {
+ /* ulLoopCounter changed, so the count of times this function was called
+ * without a change can be reset to zero. */
+ xIterationsWithoutCounterIncrement = ( TickType_t ) 0;
+ }
+
+ ulLastLoopCounter = ulLoopCounter;
+
+ /* Errors detected in the task itself will have latched xTestStatus
+ * to pdFAIL. */
+
+ return xTestStatus;
}
/*-----------------------------------------------------------*/
static void prvTest1_CreateTimersWithoutSchedulerRunning( void )
{
-TickType_t xTimer;
-
- for( xTimer = 0; xTimer < configTIMER_QUEUE_LENGTH; xTimer++ )
- {
- /* As the timer queue is not yet full, it should be possible to both
- create and start a timer. These timers are being started before the
- scheduler has been started, so their block times should get set to zero
- within the timer API itself. */
- xAutoReloadTimers[ xTimer ] = xTimerCreate( "FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
- ( ( xTimer + ( TickType_t ) 1 ) * xBasePeriod ),/* The period for the timer. The plus 1 ensures a period of zero is not specified. */
- pdTRUE, /* Auto-reload is set to true. */
- ( void * ) xTimer, /* An identifier for the timer as all the auto-reload timers use the same callback. */
- prvAutoReloadTimerCallback ); /* The callback to be called when the timer expires. */
-
- if( xAutoReloadTimers[ xTimer ] == NULL )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- else
- {
- configASSERT( strcmp( pcTimerGetName( xAutoReloadTimers[ xTimer ] ), "FR Timer" ) == 0 );
-
- /* The scheduler has not yet started, so the block period of
- portMAX_DELAY should just get set to zero in xTimerStart(). Also,
- the timer queue is not yet full so xTimerStart() should return
- pdPASS. */
- if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) != pdPASS )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- }
-
- /* The timers queue should now be full, so it should be possible to create
- another timer, but not possible to start it (the timer queue will not get
- drained until the scheduler has been started. */
- xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] = xTimerCreate( "FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
- ( configTIMER_QUEUE_LENGTH * xBasePeriod ), /* The period for the timer. */
- pdTRUE, /* Auto-reload is set to true. */
- ( void * ) xTimer, /* An identifier for the timer as all the auto-reload timers use the same callback. */
- prvAutoReloadTimerCallback ); /* The callback executed when the timer expires. */
-
- if( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] == NULL )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- else
- {
- if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) == pdPASS )
- {
- /* This time it would not be expected that the timer could be
- started at this point. */
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
-
- /* Create the timers that are used from the tick interrupt to test the timer
- API functions that can be called from an ISR. */
- xISRAutoReloadTimer = xTimerCreate( "ISR AR", /* The text name given to the timer. */
- 0xffff, /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */
- pdTRUE, /* This is an auto-reload timer. */
- ( void * ) NULL, /* The identifier is not required. */
- prvISRAutoReloadTimerCallback ); /* The callback that is executed when the timer expires. */
-
- xISROneShotTimer = xTimerCreate( "ISR OS", /* The text name given to the timer. */
- 0xffff, /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */
- pdFALSE, /* This is a one-shot timer. */
- ( void * ) NULL, /* The identifier is not required. */
- prvISROneShotTimerCallback ); /* The callback that is executed when the timer expires. */
-
- if( ( xISRAutoReloadTimer == NULL ) || ( xISROneShotTimer == NULL ) )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
+ TickType_t xTimer;
+
+ for( xTimer = 0; xTimer < configTIMER_QUEUE_LENGTH; xTimer++ )
+ {
+ /* As the timer queue is not yet full, it should be possible to both
+ * create and start a timer. These timers are being started before the
+ * scheduler has been started, so their block times should get set to zero
+ * within the timer API itself. */
+ xAutoReloadTimers[ xTimer ] = xTimerCreate( "FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
+ ( ( xTimer + ( TickType_t ) 1 ) * xBasePeriod ), /* The period for the timer. The plus 1 ensures a period of zero is not specified. */
+ pdTRUE, /* Auto-reload is set to true. */
+ ( void * ) xTimer, /* An identifier for the timer as all the auto-reload timers use the same callback. */
+ prvAutoReloadTimerCallback ); /* The callback to be called when the timer expires. */
+
+ if( xAutoReloadTimers[ xTimer ] == NULL )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ else
+ {
+ configASSERT( strcmp( pcTimerGetName( xAutoReloadTimers[ xTimer ] ), "FR Timer" ) == 0 );
+
+ /* The scheduler has not yet started, so the block period of
+ * portMAX_DELAY should just get set to zero in xTimerStart(). Also,
+ * the timer queue is not yet full so xTimerStart() should return
+ * pdPASS. */
+ if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) != pdPASS )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ }
+
+ /* The timers queue should now be full, so it should be possible to create
+ * another timer, but not possible to start it (the timer queue will not get
+ * drained until the scheduler has been started. */
+ xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] = xTimerCreate( "FR Timer", /* Text name to facilitate debugging. The kernel does not use this itself. */
+ ( configTIMER_QUEUE_LENGTH * xBasePeriod ), /* The period for the timer. */
+ pdTRUE, /* Auto-reload is set to true. */
+ ( void * ) xTimer, /* An identifier for the timer as all the auto-reload timers use the same callback. */
+ prvAutoReloadTimerCallback ); /* The callback executed when the timer expires. */
+
+ if( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] == NULL )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ else
+ {
+ if( xTimerStart( xAutoReloadTimers[ xTimer ], portMAX_DELAY ) == pdPASS )
+ {
+ /* This time it would not be expected that the timer could be
+ * started at this point. */
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+
+ /* Create the timers that are used from the tick interrupt to test the timer
+ * API functions that can be called from an ISR. */
+ xISRAutoReloadTimer = xTimerCreate( "ISR AR", /* The text name given to the timer. */
+ 0xffff, /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */
+ pdTRUE, /* This is an auto-reload timer. */
+ ( void * ) NULL, /* The identifier is not required. */
+ prvISRAutoReloadTimerCallback ); /* The callback that is executed when the timer expires. */
+
+ xISROneShotTimer = xTimerCreate( "ISR OS", /* The text name given to the timer. */
+ 0xffff, /* The timer is not given a period yet - this will be done from the tick hook, but a period of 0 is invalid. */
+ pdFALSE, /* This is a one-shot timer. */
+ ( void * ) NULL, /* The identifier is not required. */
+ prvISROneShotTimerCallback ); /* The callback that is executed when the timer expires. */
+
+ if( ( xISRAutoReloadTimer == NULL ) || ( xISROneShotTimer == NULL ) )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
}
/*-----------------------------------------------------------*/
static void prvTest2_CheckTaskAndTimersInitialState( void )
{
-uint8_t ucTimer;
-
- /* Ensure all the timers are in their expected initial state. This depends
- on the timer service task having a higher priority than this task.
-
- auto-reload timers 0 to ( configTIMER_QUEUE_LENGTH - 1 ) should now be active,
- and auto-reload timer configTIMER_QUEUE_LENGTH should not yet be active (it
- could not be started prior to the scheduler being started when it was
- created). */
- for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
- {
- if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
-
- if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
+ uint8_t ucTimer;
+
+ /* Ensure all the timers are in their expected initial state. This depends
+ * on the timer service task having a higher priority than this task.
+ *
+ * auto-reload timers 0 to ( configTIMER_QUEUE_LENGTH - 1 ) should now be active,
+ * and auto-reload timer configTIMER_QUEUE_LENGTH should not yet be active (it
+ * could not be started prior to the scheduler being started when it was
+ * created). */
+ for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
+ {
+ if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+
+ if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH ] ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
}
/*-----------------------------------------------------------*/
-static void prvTest3_CheckAutoReloadExpireRates( void )
+static void prvTest3_CheckAutoReloadExpireRates( void )
{
-uint8_t ucMaxAllowableValue, ucMinAllowableValue, ucTimer;
-TickType_t xBlockPeriod, xTimerPeriod, xExpectedNumber;
-UBaseType_t uxOriginalPriority;
-
- /* Check the auto-reload timers expire at the expected rates. Do this at a
- high priority for maximum accuracy. This is ok as most of the time is spent
- in the Blocked state. */
- uxOriginalPriority = uxTaskPriorityGet( NULL );
- vTaskPrioritySet( NULL, ( configMAX_PRIORITIES - 1 ) );
-
- /* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow
- all the auto-reload timers to expire at least once. */
- xBlockPeriod = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
- vTaskDelay( xBlockPeriod );
-
- /* Check that all the auto-reload timers have called their callback
- function the expected number of times. */
- for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
- {
- /* The expected number of expires is equal to the block period divided
- by the timer period. */
- xTimerPeriod = ( ( ( TickType_t ) ucTimer + ( TickType_t ) 1 ) * xBasePeriod );
- xExpectedNumber = xBlockPeriod / xTimerPeriod;
-
- ucMaxAllowableValue = ( ( uint8_t ) xExpectedNumber ) ;
- ucMinAllowableValue = ( uint8_t ) ( ( uint8_t ) xExpectedNumber - ( uint8_t ) 1 ); /* Weird casting to try and please all compilers. */
-
- if( ( ucAutoReloadTimerCounters[ ucTimer ] < ucMinAllowableValue ) ||
- ( ucAutoReloadTimerCounters[ ucTimer ] > ucMaxAllowableValue )
- )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
-
- /* Return to the original priority. */
- vTaskPrioritySet( NULL, uxOriginalPriority );
-
- if( xTestStatus == pdPASS )
- {
- /* No errors have been reported so increment the loop counter so the
- check task knows this task is still running. */
- ulLoopCounter++;
- }
+ uint8_t ucMaxAllowableValue, ucMinAllowableValue, ucTimer;
+ TickType_t xBlockPeriod, xTimerPeriod, xExpectedNumber;
+ UBaseType_t uxOriginalPriority;
+
+ /* Check the auto-reload timers expire at the expected rates. Do this at a
+ * high priority for maximum accuracy. This is ok as most of the time is spent
+ * in the Blocked state. */
+ uxOriginalPriority = uxTaskPriorityGet( NULL );
+ vTaskPrioritySet( NULL, ( configMAX_PRIORITIES - 1 ) );
+
+ /* Delaying for configTIMER_QUEUE_LENGTH * xBasePeriod ticks should allow
+ * all the auto-reload timers to expire at least once. */
+ xBlockPeriod = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
+ vTaskDelay( xBlockPeriod );
+
+ /* Check that all the auto-reload timers have called their callback
+ * function the expected number of times. */
+ for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
+ {
+ /* The expected number of expires is equal to the block period divided
+ * by the timer period. */
+ xTimerPeriod = ( ( ( TickType_t ) ucTimer + ( TickType_t ) 1 ) * xBasePeriod );
+ xExpectedNumber = xBlockPeriod / xTimerPeriod;
+
+ ucMaxAllowableValue = ( ( uint8_t ) xExpectedNumber );
+ ucMinAllowableValue = ( uint8_t ) ( ( uint8_t ) xExpectedNumber - ( uint8_t ) 1 ); /* Weird casting to try and please all compilers. */
+
+ if( ( ucAutoReloadTimerCounters[ ucTimer ] < ucMinAllowableValue ) ||
+ ( ucAutoReloadTimerCounters[ ucTimer ] > ucMaxAllowableValue )
+ )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+
+ /* Return to the original priority. */
+ vTaskPrioritySet( NULL, uxOriginalPriority );
+
+ if( xTestStatus == pdPASS )
+ {
+ /* No errors have been reported so increment the loop counter so the
+ * check task knows this task is still running. */
+ ulLoopCounter++;
+ }
}
/*-----------------------------------------------------------*/
static void prvTest4_CheckAutoReloadTimersCanBeStopped( void )
{
-uint8_t ucTimer;
-
- /* Check the auto-reload timers can be stopped correctly, and correctly
- report their state. */
-
- /* Stop all the active timers. */
- for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
- {
- /* The timer has not been stopped yet! */
- if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Now stop the timer. This will appear to happen immediately to
- this task because this task is running at a priority below the
- timer service task. */
- xTimerStop( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
-
- /* The timer should now be inactive. */
- if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
-
- taskENTER_CRITICAL();
- {
- /* The timer in array position configTIMER_QUEUE_LENGTH should not
- be active. The critical section is used to ensure the timer does
- not call its callback between the next line running and the array
- being cleared back to zero, as that would mask an error condition. */
- if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( uint8_t ) 0 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Clear the timer callback count. */
- memset( ( void * ) ucAutoReloadTimerCounters, 0, sizeof( ucAutoReloadTimerCounters ) );
- }
- taskEXIT_CRITICAL();
-
- /* The timers are now all inactive, so this time, after delaying, none
- of the callback counters should have incremented. */
- vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
- for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
- {
- if( ucAutoReloadTimerCounters[ ucTimer ] != ( uint8_t ) 0 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
-
- if( xTestStatus == pdPASS )
- {
- /* No errors have been reported so increment the loop counter so
- the check task knows this task is still running. */
- ulLoopCounter++;
- }
+ uint8_t ucTimer;
+
+ /* Check the auto-reload timers can be stopped correctly, and correctly
+ * report their state. */
+
+ /* Stop all the active timers. */
+ for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
+ {
+ /* The timer has not been stopped yet! */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Now stop the timer. This will appear to happen immediately to
+ * this task because this task is running at a priority below the
+ * timer service task. */
+ xTimerStop( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
+
+ /* The timer should now be inactive. */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+
+ taskENTER_CRITICAL();
+ {
+ /* The timer in array position configTIMER_QUEUE_LENGTH should not
+ * be active. The critical section is used to ensure the timer does
+ * not call its callback between the next line running and the array
+ * being cleared back to zero, as that would mask an error condition. */
+ if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH ] != ( uint8_t ) 0 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Clear the timer callback count. */
+ memset( ( void * ) ucAutoReloadTimerCounters, 0, sizeof( ucAutoReloadTimerCounters ) );
+ }
+ taskEXIT_CRITICAL();
+
+ /* The timers are now all inactive, so this time, after delaying, none
+ * of the callback counters should have incremented. */
+ vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
+
+ for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
+ {
+ if( ucAutoReloadTimerCounters[ ucTimer ] != ( uint8_t ) 0 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+
+ if( xTestStatus == pdPASS )
+ {
+ /* No errors have been reported so increment the loop counter so
+ * the check task knows this task is still running. */
+ ulLoopCounter++;
+ }
}
/*-----------------------------------------------------------*/
static void prvTest5_CheckBasicOneShotTimerBehaviour( void )
{
- /* Check the one-shot timer only calls its callback once after it has been
- started, and that it reports its state correctly. */
-
- /* The one-shot timer should not be active yet. */
- if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucOneShotTimerCounter != ( uint8_t ) 0 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Start the one-shot timer and check that it reports its state correctly. */
- xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
- if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Delay for three times as long as the one-shot timer period, then check
- to ensure it has only called its callback once, and is now not in the
- active state. */
- vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD * ( TickType_t ) 3 );
-
- if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucOneShotTimerCounter != ( uint8_t ) 1 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- else
- {
- /* Reset the one-shot timer callback count. */
- ucOneShotTimerCounter = ( uint8_t ) 0;
- }
-
- if( xTestStatus == pdPASS )
- {
- /* No errors have been reported so increment the loop counter so the
- check task knows this task is still running. */
- ulLoopCounter++;
- }
+ /* Check the one-shot timer only calls its callback once after it has been
+ * started, and that it reports its state correctly. */
+
+ /* The one-shot timer should not be active yet. */
+ if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucOneShotTimerCounter != ( uint8_t ) 0 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Start the one-shot timer and check that it reports its state correctly. */
+ xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
+
+ if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Delay for three times as long as the one-shot timer period, then check
+ * to ensure it has only called its callback once, and is now not in the
+ * active state. */
+ vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD * ( TickType_t ) 3 );
+
+ if( xTimerIsTimerActive( xOneShotTimer ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucOneShotTimerCounter != ( uint8_t ) 1 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ else
+ {
+ /* Reset the one-shot timer callback count. */
+ ucOneShotTimerCounter = ( uint8_t ) 0;
+ }
+
+ if( xTestStatus == pdPASS )
+ {
+ /* No errors have been reported so increment the loop counter so the
+ * check task knows this task is still running. */
+ ulLoopCounter++;
+ }
}
/*-----------------------------------------------------------*/
static void prvTest6_CheckAutoReloadResetBehaviour( void )
{
-uint8_t ucTimer;
-
- /* Check timer reset behaviour. */
-
- /* Restart the one-shot timer and check it reports its status correctly. */
- xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
- if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Restart one of the auto-reload timers and check that it reports its
- status correctly. */
- xTimerStart( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
- if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- for( ucTimer = 0; ucTimer < tmrdemoNUM_TIMER_RESETS; ucTimer++ )
- {
- /* Delay for half as long as the one-shot timer period, then reset it.
- It should never expire while this is done, so its callback count should
- never increment. */
- vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD / 2 );
-
- /* Check both running timers are still active, but have not called their
- callback functions. */
- if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucOneShotTimerCounter != ( uint8_t ) 0 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] != ( uint8_t ) 0 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Reset both running timers. */
- xTimerReset( xOneShotTimer, tmrdemoDONT_BLOCK );
- xTimerReset( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
-
- if( xTestStatus == pdPASS )
- {
- /* No errors have been reported so increment the loop counter so
- the check task knows this task is still running. */
- ulLoopCounter++;
- }
- }
-
- /* Finally delay long enough for both running timers to expire. */
- vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
-
- /* The timers were not reset during the above delay period so should now
- both have called their callback functions. */
- if( ucOneShotTimerCounter != ( uint8_t ) 1 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] == 0 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* The one-shot timer should no longer be active, while the auto-reload
- timer should still be active. */
- if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( xTimerIsTimerActive( xOneShotTimer ) == pdTRUE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Stop the auto-reload timer again. */
- xTimerStop( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
-
- if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Clear the timer callback counts, ready for another iteration of these
- tests. */
- ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] = ( uint8_t ) 0;
- ucOneShotTimerCounter = ( uint8_t ) 0;
-
- if( xTestStatus == pdPASS )
- {
- /* No errors have been reported so increment the loop counter so the check
- task knows this task is still running. */
- ulLoopCounter++;
- }
+ uint8_t ucTimer;
+
+ /* Check timer reset behaviour. */
+
+ /* Restart the one-shot timer and check it reports its status correctly. */
+ xTimerStart( xOneShotTimer, tmrdemoDONT_BLOCK );
+
+ if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Restart one of the auto-reload timers and check that it reports its
+ * status correctly. */
+ xTimerStart( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
+
+ if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ for( ucTimer = 0; ucTimer < tmrdemoNUM_TIMER_RESETS; ucTimer++ )
+ {
+ /* Delay for half as long as the one-shot timer period, then reset it.
+ * It should never expire while this is done, so its callback count should
+ * never increment. */
+ vTaskDelay( tmrdemoONE_SHOT_TIMER_PERIOD / 2 );
+
+ /* Check both running timers are still active, but have not called their
+ * callback functions. */
+ if( xTimerIsTimerActive( xOneShotTimer ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucOneShotTimerCounter != ( uint8_t ) 0 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] != ( uint8_t ) 0 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Reset both running timers. */
+ xTimerReset( xOneShotTimer, tmrdemoDONT_BLOCK );
+ xTimerReset( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
+
+ if( xTestStatus == pdPASS )
+ {
+ /* No errors have been reported so increment the loop counter so
+ * the check task knows this task is still running. */
+ ulLoopCounter++;
+ }
+ }
+
+ /* Finally delay long enough for both running timers to expire. */
+ vTaskDelay( ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod );
+
+ /* The timers were not reset during the above delay period so should now
+ * both have called their callback functions. */
+ if( ucOneShotTimerCounter != ( uint8_t ) 1 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] == 0 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* The one-shot timer should no longer be active, while the auto-reload
+ * timer should still be active. */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( xTimerIsTimerActive( xOneShotTimer ) == pdTRUE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Stop the auto-reload timer again. */
+ xTimerStop( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ], tmrdemoDONT_BLOCK );
+
+ if( xTimerIsTimerActive( xAutoReloadTimers[ configTIMER_QUEUE_LENGTH - 1 ] ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Clear the timer callback counts, ready for another iteration of these
+ * tests. */
+ ucAutoReloadTimerCounters[ configTIMER_QUEUE_LENGTH - 1 ] = ( uint8_t ) 0;
+ ucOneShotTimerCounter = ( uint8_t ) 0;
+
+ if( xTestStatus == pdPASS )
+ {
+ /* No errors have been reported so increment the loop counter so the check
+ * task knows this task is still running. */
+ ulLoopCounter++;
+ }
}
/*-----------------------------------------------------------*/
static void prvTest7_CheckBacklogBehaviour( void )
{
- /* Use the first auto-reload timer to test stopping a timer from a
- backlogged callback. */
-
- /* The timer has not been started yet! */
- if( xTimerIsTimerActive( xAutoReloadTimers[ 0 ] ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Prompt the callback function to stop the timer. */
- ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdTRUE;
-
- /* Now start the timer. This will appear to happen immediately to
- this task because this task is running at a priority below the timer
- service task. Use a timer period of one tick so the call to
- xTaskCatchUpTicks() below has minimal impact on other tests that might
- be running. */
- #define tmrdemoBACKLOG_TIMER_PERIOD ( ( TickType_t ) 1 )
- xTimerChangePeriod( xAutoReloadTimers[ 0 ], tmrdemoBACKLOG_TIMER_PERIOD, tmrdemoDONT_BLOCK );
-
- /* The timer should now be active. */
- if( xTimerIsTimerActive( xAutoReloadTimers[ 0 ] ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Arrange for the callback to execute late enough that it will execute
- twice, back-to-back. The timer must handle the stop request properly
- in spite of the backlog of callbacks. */
- #define tmrdemoEXPECTED_BACKLOG_EXPIRES ( ( TickType_t ) 2 )
- xTaskCatchUpTicks( tmrdemoBACKLOG_TIMER_PERIOD * tmrdemoEXPECTED_BACKLOG_EXPIRES );
-
- /* The timer should now be inactive. */
- if( xTimerIsTimerActive( xAutoReloadTimers[ 0 ] ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Restore the standard timer period, and leave the timer inactive. */
- xTimerChangePeriod( xAutoReloadTimers[ 0 ], xBasePeriod, tmrdemoDONT_BLOCK );
- xTimerStop( xAutoReloadTimers[ 0 ], tmrdemoDONT_BLOCK );
-
- /* Clear the reload count for the timer used in this test. */
- ucAutoReloadTimerCounters[ 0 ] = ( uint8_t ) 0;
-
- if( xTestStatus == pdPASS )
- {
- /* No errors have been reported so increment the loop counter so the check
- task knows this task is still running. */
- ulLoopCounter++;
- }
+ /* Use the first auto-reload timer to test stopping a timer from a
+ * backlogged callback. */
+
+ /* The timer has not been started yet! */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ 0 ] ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Prompt the callback function to stop the timer. */
+ ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdTRUE;
+
+ /* Now start the timer. This will appear to happen immediately to
+ * this task because this task is running at a priority below the timer
+ * service task. Use a timer period of one tick so the call to
+ * xTaskCatchUpTicks() below has minimal impact on other tests that might
+ * be running. */
+#define tmrdemoBACKLOG_TIMER_PERIOD ( ( TickType_t ) 1 )
+ xTimerChangePeriod( xAutoReloadTimers[ 0 ], tmrdemoBACKLOG_TIMER_PERIOD, tmrdemoDONT_BLOCK );
+
+ /* The timer should now be active. */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ 0 ] ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Arrange for the callback to execute late enough that it will execute
+ * twice, back-to-back. The timer must handle the stop request properly
+ * in spite of the backlog of callbacks. */
+#define tmrdemoEXPECTED_BACKLOG_EXPIRES ( ( TickType_t ) 2 )
+ xTaskCatchUpTicks( tmrdemoBACKLOG_TIMER_PERIOD * tmrdemoEXPECTED_BACKLOG_EXPIRES );
+
+ /* The timer should now be inactive. */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ 0 ] ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Restore the standard timer period, and leave the timer inactive. */
+ xTimerChangePeriod( xAutoReloadTimers[ 0 ], xBasePeriod, tmrdemoDONT_BLOCK );
+ xTimerStop( xAutoReloadTimers[ 0 ], tmrdemoDONT_BLOCK );
+
+ /* Clear the reload count for the timer used in this test. */
+ ucAutoReloadTimerCounters[ 0 ] = ( uint8_t ) 0;
+
+ if( xTestStatus == pdPASS )
+ {
+ /* No errors have been reported so increment the loop counter so the check
+ * task knows this task is still running. */
+ ulLoopCounter++;
+ }
}
/*-----------------------------------------------------------*/
static void prvResetStartConditionsForNextIteration( void )
{
-uint8_t ucTimer;
-
- /* Start the timers again to start all the tests over again. */
-
- /* Start the timers again. */
- for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
- {
- /* The timer has not been started yet! */
- if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Now start the timer. This will appear to happen immediately to
- this task because this task is running at a priority below the timer
- service task. */
- xTimerStart( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
-
- /* The timer should now be active. */
- if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
-
- if( xTestStatus == pdPASS )
- {
- /* No errors have been reported so increment the loop counter so the
- check task knows this task is still running. */
- ulLoopCounter++;
- }
+ uint8_t ucTimer;
+
+ /* Start the timers again to start all the tests over again. */
+
+ /* Start the timers again. */
+ for( ucTimer = 0; ucTimer < ( uint8_t ) configTIMER_QUEUE_LENGTH; ucTimer++ )
+ {
+ /* The timer has not been started yet! */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) != pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Now start the timer. This will appear to happen immediately to
+ * this task because this task is running at a priority below the timer
+ * service task. */
+ xTimerStart( xAutoReloadTimers[ ucTimer ], tmrdemoDONT_BLOCK );
+
+ /* The timer should now be active. */
+ if( xTimerIsTimerActive( xAutoReloadTimers[ ucTimer ] ) == pdFALSE )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+
+ if( xTestStatus == pdPASS )
+ {
+ /* No errors have been reported so increment the loop counter so the
+ * check task knows this task is still running. */
+ ulLoopCounter++;
+ }
}
/*-----------------------------------------------------------*/
void vTimerPeriodicISRTests( void )
{
-static TickType_t uxTick = ( TickType_t ) -1;
-
-#if( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )
- /* The timer service task is not the highest priority task, so it cannot
- be assumed that timings will be exact. Timers should never call their
- callback before their expiry time, but a margin is permissible for calling
- their callback after their expiry time. If exact timing is required then
- configTIMER_TASK_PRIORITY must be set to ensure the timer service task
- is the highest priority task in the system.
-
- This function is called from the tick hook. The tick hook is called
- even when the scheduler is suspended. Therefore it is possible that the
- uxTick count maintained in this function is temporarily ahead of the tick
- count maintained by the kernel. When this is the case a message posted from
- this function will assume a time stamp in advance of the real time stamp,
- which can result in a timer being processed before this function expects it
- to. For example, if the kernel's tick count was 100, and uxTick was 102,
- then this function will not expect the timer to have expired until the
- kernel's tick count is (102 + xBasePeriod), whereas in reality the timer
- will expire when the kernel's tick count is (100 + xBasePeriod). For this
- reason xMargin is used as an allowable margin for premature timer expires
- as well as late timer expires. */
- #ifdef _WINDOWS_
- /* Windows is not real real time. */
- const TickType_t xMargin = 20;
- #else
- const TickType_t xMargin = 6;
- #endif /* _WINDOWS_ */
-#else
- #ifdef _WINDOWS_
- /* Windows is not real real time. */
- const TickType_t xMargin = 20;
- #else
- const TickType_t xMargin = 4;
- #endif /* _WINDOWS_ */
-#endif
-
-
- uxTick++;
-
- if( uxTick == 0 )
- {
- /* The timers will have been created, but not started. Start them now
- by setting their period. */
- ucISRAutoReloadTimerCounter = 0;
- ucISROneShotTimerCounter = 0;
-
- /* It is possible that the timer task has not yet made room in the
- timer queue. If the timers cannot be started then reset uxTick so
- another attempt is made later. */
- uxTick = ( TickType_t ) -1;
-
- /* Try starting first timer. */
- if( xTimerChangePeriodFromISR( xISRAutoReloadTimer, xBasePeriod, NULL ) == pdPASS )
- {
- /* First timer was started, try starting the second timer. */
- if( xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, NULL ) == pdPASS )
- {
- /* Both timers were started, so set the uxTick back to its
- proper value. */
- uxTick = 0;
- }
- else
- {
- /* Second timer could not be started, so stop the first one
- again. */
- xTimerStopFromISR( xISRAutoReloadTimer, NULL );
- }
- }
- }
- else if( uxTick == ( xBasePeriod - xMargin ) )
- {
- /* Neither timer should have expired yet. */
- if( ( ucISRAutoReloadTimerCounter != 0 ) || ( ucISROneShotTimerCounter != 0 ) )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( xBasePeriod + xMargin ) )
- {
- /* Both timers should now have expired once. The auto-reload timer will
- still be active, but the one-shot timer should now have stopped. */
- if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( ( 2 * xBasePeriod ) - xMargin ) )
- {
- /* The auto-reload timer will still be active, but the one-shot timer
- should now have stopped - however, at this time neither of the timers
- should have expired again since the last test. */
- if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( ( 2 * xBasePeriod ) + xMargin ) )
- {
- /* The auto-reload timer will still be active, but the one-shot timer
- should now have stopped. At this time the auto-reload timer should have
- expired again, but the one-shot timer count should not have changed. */
- if( ucISRAutoReloadTimerCounter != 2 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 1 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( TickType_t ) 2U ) ) )
- {
- /* The auto-reload timer will still be active, but the one-shot timer
- should now have stopped. Again though, at this time, neither timer call
- back should have been called since the last test. */
- if( ucISRAutoReloadTimerCounter != 2 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 1 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( 3 * xBasePeriod ) )
- {
- /* Start the one-shot timer again. */
- xTimerStartFromISR( xISROneShotTimer, NULL );
- }
- else if( uxTick == ( ( 3 * xBasePeriod ) + xMargin ) )
- {
- /* The auto-reload timer and one-shot timer will be active. At
- this time the auto-reload timer should have expired again, but the one
- shot timer count should not have changed yet. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 1 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Now stop the auto-reload timer. The one-shot timer was started
- a few ticks ago. */
- xTimerStopFromISR( xISRAutoReloadTimer, NULL );
- }
- else if( uxTick == ( 4 * ( xBasePeriod - xMargin ) ) )
- {
- /* The auto-reload timer is now stopped, and the one-shot timer is
- active, but at this time neither timer should have expired since the
- last test. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 1 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( ( 4 * xBasePeriod ) + xMargin ) )
- {
- /* The auto-reload timer is now stopped, and the one-shot timer is
- active. The one-shot timer should have expired again, but the auto
- reload timer should not have executed its callback. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 2 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( 8 * xBasePeriod ) )
- {
- /* The auto-reload timer is now stopped, and the one-shot timer has
- already expired and then stopped itself. Both callback counters should
- not have incremented since the last test. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 2 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- /* Now reset the one-shot timer. */
- xTimerResetFromISR( xISROneShotTimer, NULL );
- }
- else if( uxTick == ( ( 9 * xBasePeriod ) - xMargin ) )
- {
- /* Only the one-shot timer should be running, but it should not have
- expired since the last test. Check the callback counters have not
- incremented, then reset the one-shot timer again. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 2 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- xTimerResetFromISR( xISROneShotTimer, NULL );
- }
- else if( uxTick == ( ( 10 * xBasePeriod ) - ( 2 * xMargin ) ) )
- {
- /* Only the one-shot timer should be running, but it should not have
- expired since the last test. Check the callback counters have not
- incremented, then reset the one-shot timer again. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 2 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- xTimerResetFromISR( xISROneShotTimer, NULL );
- }
- else if( uxTick == ( ( 11 * xBasePeriod ) - ( 3 * xMargin ) ) )
- {
- /* Only the one-shot timer should be running, but it should not have
- expired since the last test. Check the callback counters have not
- incremented, then reset the one-shot timer once again. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 2 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- xTimerResetFromISR( xISROneShotTimer, NULL );
- }
- else if( uxTick == ( ( 12 * xBasePeriod ) - ( 2 * xMargin ) ) )
- {
- /* Only the one-shot timer should have been running and this time it
- should have expired. Check its callback count has been incremented.
- The auto-reload timer is still not running so should still have the same
- count value. This time the one-shot timer is not reset so should not
- restart from its expiry period again. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
- }
- else if( uxTick == ( 15 * xBasePeriod ) )
- {
- /* Neither timer should be running now. Check neither callback count
- has incremented, then go back to the start to run these tests all
- over again. */
- if( ucISRAutoReloadTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- if( ucISROneShotTimerCounter != 3 )
- {
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
-
- uxTick = ( TickType_t ) -1;
- }
+ static TickType_t uxTick = ( TickType_t ) -1;
+
+ #if ( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) )
+
+ /* The timer service task is not the highest priority task, so it cannot
+ * be assumed that timings will be exact. Timers should never call their
+ * callback before their expiry time, but a margin is permissible for calling
+ * their callback after their expiry time. If exact timing is required then
+ * configTIMER_TASK_PRIORITY must be set to ensure the timer service task
+ * is the highest priority task in the system.
+ *
+ * This function is called from the tick hook. The tick hook is called
+ * even when the scheduler is suspended. Therefore it is possible that the
+ * uxTick count maintained in this function is temporarily ahead of the tick
+ * count maintained by the kernel. When this is the case a message posted from
+ * this function will assume a time stamp in advance of the real time stamp,
+ * which can result in a timer being processed before this function expects it
+ * to. For example, if the kernel's tick count was 100, and uxTick was 102,
+ * then this function will not expect the timer to have expired until the
+ * kernel's tick count is (102 + xBasePeriod), whereas in reality the timer
+ * will expire when the kernel's tick count is (100 + xBasePeriod). For this
+ * reason xMargin is used as an allowable margin for premature timer expires
+ * as well as late timer expires. */
+ #ifdef _WINDOWS_
+ /* Windows is not real real time. */
+ const TickType_t xMargin = 20;
+ #else
+ const TickType_t xMargin = 6;
+ #endif /* _WINDOWS_ */
+ #else
+ #ifdef _WINDOWS_
+ /* Windows is not real real time. */
+ const TickType_t xMargin = 20;
+ #else
+ const TickType_t xMargin = 4;
+ #endif /* _WINDOWS_ */
+ #endif /* if ( configTIMER_TASK_PRIORITY != ( configMAX_PRIORITIES - 1 ) ) */
+
+
+ uxTick++;
+
+ if( uxTick == 0 )
+ {
+ /* The timers will have been created, but not started. Start them now
+ * by setting their period. */
+ ucISRAutoReloadTimerCounter = 0;
+ ucISROneShotTimerCounter = 0;
+
+ /* It is possible that the timer task has not yet made room in the
+ * timer queue. If the timers cannot be started then reset uxTick so
+ * another attempt is made later. */
+ uxTick = ( TickType_t ) -1;
+
+ /* Try starting first timer. */
+ if( xTimerChangePeriodFromISR( xISRAutoReloadTimer, xBasePeriod, NULL ) == pdPASS )
+ {
+ /* First timer was started, try starting the second timer. */
+ if( xTimerChangePeriodFromISR( xISROneShotTimer, xBasePeriod, NULL ) == pdPASS )
+ {
+ /* Both timers were started, so set the uxTick back to its
+ * proper value. */
+ uxTick = 0;
+ }
+ else
+ {
+ /* Second timer could not be started, so stop the first one
+ * again. */
+ xTimerStopFromISR( xISRAutoReloadTimer, NULL );
+ }
+ }
+ }
+ else if( uxTick == ( xBasePeriod - xMargin ) )
+ {
+ /* Neither timer should have expired yet. */
+ if( ( ucISRAutoReloadTimerCounter != 0 ) || ( ucISROneShotTimerCounter != 0 ) )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( xBasePeriod + xMargin ) )
+ {
+ /* Both timers should now have expired once. The auto-reload timer will
+ * still be active, but the one-shot timer should now have stopped. */
+ if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( ( 2 * xBasePeriod ) - xMargin ) )
+ {
+ /* The auto-reload timer will still be active, but the one-shot timer
+ * should now have stopped - however, at this time neither of the timers
+ * should have expired again since the last test. */
+ if( ( ucISRAutoReloadTimerCounter != 1 ) || ( ucISROneShotTimerCounter != 1 ) )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( ( 2 * xBasePeriod ) + xMargin ) )
+ {
+ /* The auto-reload timer will still be active, but the one-shot timer
+ * should now have stopped. At this time the auto-reload timer should have
+ * expired again, but the one-shot timer count should not have changed. */
+ if( ucISRAutoReloadTimerCounter != 2 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 1 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( ( 2 * xBasePeriod ) + ( xBasePeriod >> ( TickType_t ) 2U ) ) )
+ {
+ /* The auto-reload timer will still be active, but the one-shot timer
+ * should now have stopped. Again though, at this time, neither timer call
+ * back should have been called since the last test. */
+ if( ucISRAutoReloadTimerCounter != 2 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 1 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( 3 * xBasePeriod ) )
+ {
+ /* Start the one-shot timer again. */
+ xTimerStartFromISR( xISROneShotTimer, NULL );
+ }
+ else if( uxTick == ( ( 3 * xBasePeriod ) + xMargin ) )
+ {
+ /* The auto-reload timer and one-shot timer will be active. At
+ * this time the auto-reload timer should have expired again, but the one
+ * shot timer count should not have changed yet. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 1 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Now stop the auto-reload timer. The one-shot timer was started
+ * a few ticks ago. */
+ xTimerStopFromISR( xISRAutoReloadTimer, NULL );
+ }
+ else if( uxTick == ( 4 * ( xBasePeriod - xMargin ) ) )
+ {
+ /* The auto-reload timer is now stopped, and the one-shot timer is
+ * active, but at this time neither timer should have expired since the
+ * last test. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 1 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( ( 4 * xBasePeriod ) + xMargin ) )
+ {
+ /* The auto-reload timer is now stopped, and the one-shot timer is
+ * active. The one-shot timer should have expired again, but the auto
+ * reload timer should not have executed its callback. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 2 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( 8 * xBasePeriod ) )
+ {
+ /* The auto-reload timer is now stopped, and the one-shot timer has
+ * already expired and then stopped itself. Both callback counters should
+ * not have incremented since the last test. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 2 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ /* Now reset the one-shot timer. */
+ xTimerResetFromISR( xISROneShotTimer, NULL );
+ }
+ else if( uxTick == ( ( 9 * xBasePeriod ) - xMargin ) )
+ {
+ /* Only the one-shot timer should be running, but it should not have
+ * expired since the last test. Check the callback counters have not
+ * incremented, then reset the one-shot timer again. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 2 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ xTimerResetFromISR( xISROneShotTimer, NULL );
+ }
+ else if( uxTick == ( ( 10 * xBasePeriod ) - ( 2 * xMargin ) ) )
+ {
+ /* Only the one-shot timer should be running, but it should not have
+ * expired since the last test. Check the callback counters have not
+ * incremented, then reset the one-shot timer again. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 2 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ xTimerResetFromISR( xISROneShotTimer, NULL );
+ }
+ else if( uxTick == ( ( 11 * xBasePeriod ) - ( 3 * xMargin ) ) )
+ {
+ /* Only the one-shot timer should be running, but it should not have
+ * expired since the last test. Check the callback counters have not
+ * incremented, then reset the one-shot timer once again. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 2 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ xTimerResetFromISR( xISROneShotTimer, NULL );
+ }
+ else if( uxTick == ( ( 12 * xBasePeriod ) - ( 2 * xMargin ) ) )
+ {
+ /* Only the one-shot timer should have been running and this time it
+ * should have expired. Check its callback count has been incremented.
+ * The auto-reload timer is still not running so should still have the same
+ * count value. This time the one-shot timer is not reset so should not
+ * restart from its expiry period again. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+ }
+ else if( uxTick == ( 15 * xBasePeriod ) )
+ {
+ /* Neither timer should be running now. Check neither callback count
+ * has incremented, then go back to the start to run these tests all
+ * over again. */
+ if( ucISRAutoReloadTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ if( ucISROneShotTimerCounter != 3 )
+ {
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
+
+ uxTick = ( TickType_t ) -1;
+ }
}
/*-----------------------------------------------------------*/
@@ -1099,72 +1105,69 @@ static TickType_t uxTick = ( TickType_t ) -1;
static void prvAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )
{
-size_t uxTimerID;
-
- uxTimerID = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );
- if( uxTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )
- {
- ( ucAutoReloadTimerCounters[ uxTimerID ] )++;
-
- /* Stop timer ID 0 if requested. */
- if ( ( uxTimerID == ( size_t ) 0 ) && ( ucIsStopNeededInTimerZeroCallback == ( uint8_t ) pdTRUE ) )
- {
- xTimerStop( pxExpiredTimer, tmrdemoDONT_BLOCK );
- ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdFALSE;
- }
- }
- else
- {
- /* The timer ID appears to be unexpected (invalid). */
- xTestStatus = pdFAIL;
- configASSERT( xTestStatus );
- }
+ size_t uxTimerID;
+
+ uxTimerID = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );
+
+ if( uxTimerID <= ( configTIMER_QUEUE_LENGTH + 1 ) )
+ {
+ ( ucAutoReloadTimerCounters[ uxTimerID ] )++;
+
+ /* Stop timer ID 0 if requested. */
+ if( ( uxTimerID == ( size_t ) 0 ) && ( ucIsStopNeededInTimerZeroCallback == ( uint8_t ) pdTRUE ) )
+ {
+ xTimerStop( pxExpiredTimer, tmrdemoDONT_BLOCK );
+ ucIsStopNeededInTimerZeroCallback = ( uint8_t ) pdFALSE;
+ }
+ }
+ else
+ {
+ /* The timer ID appears to be unexpected (invalid). */
+ xTestStatus = pdFAIL;
+ configASSERT( xTestStatus );
+ }
}
/*-----------------------------------------------------------*/
static void prvOneShotTimerCallback( TimerHandle_t pxExpiredTimer )
{
/* A count is kept of the number of times this callback function is executed.
-The count is stored as the timer's ID. This is only done to test the
-vTimerSetTimerID() function. */
-static size_t uxCallCount = 0;
-size_t uxLastCallCount;
-
- /* Obtain the timer's ID, which should be a count of the number of times
- this callback function has been executed. */
- uxLastCallCount = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );
- configASSERT( uxLastCallCount == uxCallCount );
-
- /* Increment the call count, then save it back as the timer's ID. This is
- only done to test the vTimerSetTimerID() API function. */
- uxLastCallCount++;
- vTimerSetTimerID( pxExpiredTimer, ( void * ) uxLastCallCount );
- uxCallCount++;
-
- ucOneShotTimerCounter++;
+ * The count is stored as the timer's ID. This is only done to test the
+ * vTimerSetTimerID() function. */
+ static size_t uxCallCount = 0;
+ size_t uxLastCallCount;
+
+ /* Obtain the timer's ID, which should be a count of the number of times
+ * this callback function has been executed. */
+ uxLastCallCount = ( size_t ) pvTimerGetTimerID( pxExpiredTimer );
+ configASSERT( uxLastCallCount == uxCallCount );
+
+ /* Increment the call count, then save it back as the timer's ID. This is
+ * only done to test the vTimerSetTimerID() API function. */
+ uxLastCallCount++;
+ vTimerSetTimerID( pxExpiredTimer, ( void * ) uxLastCallCount );
+ uxCallCount++;
+
+ ucOneShotTimerCounter++;
}
/*-----------------------------------------------------------*/
static void prvISRAutoReloadTimerCallback( TimerHandle_t pxExpiredTimer )
{
- /* The parameter is not used in this case as only one timer uses this
- callback function. */
- ( void ) pxExpiredTimer;
+ /* The parameter is not used in this case as only one timer uses this
+ * callback function. */
+ ( void ) pxExpiredTimer;
- ucISRAutoReloadTimerCounter++;
+ ucISRAutoReloadTimerCounter++;
}
/*-----------------------------------------------------------*/
static void prvISROneShotTimerCallback( TimerHandle_t pxExpiredTimer )
{
- /* The parameter is not used in this case as only one timer uses this
- callback function. */
- ( void ) pxExpiredTimer;
+ /* The parameter is not used in this case as only one timer uses this
+ * callback function. */
+ ( void ) pxExpiredTimer;
- ucISROneShotTimerCounter++;
+ ucISROneShotTimerCounter++;
}
/*-----------------------------------------------------------*/
-
-
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/blocktim.c b/FreeRTOS/Demo/Common/Minimal/blocktim.c
index 61826089b..de9716ac4 100644
--- a/FreeRTOS/Demo/Common/Minimal/blocktim.c
+++ b/FreeRTOS/Demo/Common/Minimal/blocktim.c
@@ -41,30 +41,30 @@
/* Task priorities and stack sizes. Allow these to be overridden. */
#ifndef bktPRIMARY_PRIORITY
- #define bktPRIMARY_PRIORITY ( configMAX_PRIORITIES - 3 )
+ #define bktPRIMARY_PRIORITY ( configMAX_PRIORITIES - 3 )
#endif
#ifndef bktSECONDARY_PRIORITY
- #define bktSECONDARY_PRIORITY ( configMAX_PRIORITIES - 4 )
+ #define bktSECONDARY_PRIORITY ( configMAX_PRIORITIES - 4 )
#endif
#ifndef bktBLOCK_TIME_TASK_STACK_SIZE
- #define bktBLOCK_TIME_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define bktBLOCK_TIME_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
/* Task behaviour. */
-#define bktQUEUE_LENGTH ( 5 )
-#define bktSHORT_WAIT pdMS_TO_TICKS( ( TickType_t ) 20 )
-#define bktPRIMARY_BLOCK_TIME ( 10 )
-#define bktALLOWABLE_MARGIN ( 15 )
-#define bktTIME_TO_BLOCK ( 175 )
-#define bktDONT_BLOCK ( ( TickType_t ) 0 )
-#define bktRUN_INDICATOR ( ( UBaseType_t ) 0x55 )
+#define bktQUEUE_LENGTH ( 5 )
+#define bktSHORT_WAIT pdMS_TO_TICKS( ( TickType_t ) 20 )
+#define bktPRIMARY_BLOCK_TIME ( 10 )
+#define bktALLOWABLE_MARGIN ( 15 )
+#define bktTIME_TO_BLOCK ( 175 )
+#define bktDONT_BLOCK ( ( TickType_t ) 0 )
+#define bktRUN_INDICATOR ( ( UBaseType_t ) 0x55 )
/* In case the demo does not have software timers enabled, as this file uses
-the configTIMER_TASK_PRIORITY setting. */
+ * the configTIMER_TASK_PRIORITY setting. */
#ifndef configTIMER_TASK_PRIORITY
- #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
+ #define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
#endif
/*-----------------------------------------------------------*/
@@ -72,8 +72,8 @@ the configTIMER_TASK_PRIORITY setting. */
/*
* The two test tasks. Their behaviour is commented within the functions.
*/
-static void vPrimaryBlockTimeTestTask( void *pvParameters );
-static void vSecondaryBlockTimeTestTask( void *pvParameters );
+static void vPrimaryBlockTimeTestTask( void * pvParameters );
+static void vSecondaryBlockTimeTestTask( void * pvParameters );
/*
* Very basic tests to verify the block times are as expected.
@@ -86,7 +86,7 @@ static void prvBasicDelayTests( void );
static QueueHandle_t xTestQueue;
/* Handle to the secondary task is required by the primary task for calls
-to vTaskSuspend/Resume(). */
+ * to vTaskSuspend/Resume(). */
static TaskHandle_t xSecondary;
/* Used to ensure that tasks are still executing without error. */
@@ -94,495 +94,505 @@ static volatile BaseType_t xPrimaryCycles = 0, xSecondaryCycles = 0;
static volatile BaseType_t xErrorOccurred = pdFALSE;
/* Provides a simple mechanism for the primary task to know when the
-secondary task has executed. */
+ * secondary task has executed. */
static volatile UBaseType_t xRunIndicator;
/*-----------------------------------------------------------*/
void vCreateBlockTimeTasks( void )
{
- /* Create the queue on which the two tasks block. */
- xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( BaseType_t ) );
-
- if( xTestQueue != NULL )
- {
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one
- is in use. The queue registry is provided as a means for kernel aware
- debuggers to locate queues and has no purpose if a kernel aware
- debugger is not being used. The call to vQueueAddToRegistry() will be
- removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
- defined or is defined to be less than 1. */
- vQueueAddToRegistry( xTestQueue, "Block_Time_Queue" );
-
- /* Create the two test tasks. */
- xTaskCreate( vPrimaryBlockTimeTestTask, "BTest1", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
- xTaskCreate( vSecondaryBlockTimeTestTask, "BTest2", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
- }
+ /* Create the queue on which the two tasks block. */
+ xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( BaseType_t ) );
+
+ if( xTestQueue != NULL )
+ {
+ /* vQueueAddToRegistry() adds the queue to the queue registry, if one
+ * is in use. The queue registry is provided as a means for kernel aware
+ * debuggers to locate queues and has no purpose if a kernel aware
+ * debugger is not being used. The call to vQueueAddToRegistry() will be
+ * removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
+ * defined or is defined to be less than 1. */
+ vQueueAddToRegistry( xTestQueue, "Block_Time_Queue" );
+
+ /* Create the two test tasks. */
+ xTaskCreate( vPrimaryBlockTimeTestTask, "BTest1", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
+ xTaskCreate( vSecondaryBlockTimeTestTask, "BTest2", bktBLOCK_TIME_TASK_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
+ }
}
/*-----------------------------------------------------------*/
-static void vPrimaryBlockTimeTestTask( void *pvParameters )
+static void vPrimaryBlockTimeTestTask( void * pvParameters )
{
-BaseType_t xItem, xData;
-TickType_t xTimeWhenBlocking;
-TickType_t xTimeToBlock, xBlockedTime;
-
- ( void ) pvParameters;
-
- for( ;; )
- {
- /*********************************************************************
- Test 0
-
- Basic vTaskDelay() and vTaskDelayUntil() tests. */
- prvBasicDelayTests();
-
-
- /*********************************************************************
- Test 1
-
- Simple block time wakeup test on queue receives. */
- for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
- {
- /* The queue is empty. Attempt to read from the queue using a block
- time. When we wake, ensure the delta in time is as expected. */
- xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
-
- xTimeWhenBlocking = xTaskGetTickCount();
-
- /* We should unblock after xTimeToBlock having not received
- anything on the queue. */
- if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* How long were we blocked for? */
- xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
-
- if( xBlockedTime < xTimeToBlock )
- {
- /* Should not have blocked for less than we requested. */
- xErrorOccurred = pdTRUE;
- }
-
- if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
- {
- /* Should not have blocked for longer than we requested,
- although we would not necessarily run as soon as we were
- unblocked so a margin is allowed. */
- xErrorOccurred = pdTRUE;
- }
- }
-
- /*********************************************************************
- Test 2
-
- Simple block time wakeup test on queue sends.
-
- First fill the queue. It should be empty so all sends should pass. */
- for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
- {
- if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
- }
-
- for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
- {
- /* The queue is full. Attempt to write to the queue using a block
- time. When we wake, ensure the delta in time is as expected. */
- xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
-
- xTimeWhenBlocking = xTaskGetTickCount();
-
- /* We should unblock after xTimeToBlock having not received
- anything on the queue. */
- if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* How long were we blocked for? */
- xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
-
- if( xBlockedTime < xTimeToBlock )
- {
- /* Should not have blocked for less than we requested. */
- xErrorOccurred = pdTRUE;
- }
-
- if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
- {
- /* Should not have blocked for longer than we requested,
- although we would not necessarily run as soon as we were
- unblocked so a margin is allowed. */
- xErrorOccurred = pdTRUE;
- }
- }
-
- /*********************************************************************
- Test 3
-
- Wake the other task, it will block attempting to post to the queue.
- When we read from the queue the other task will wake, but before it
- can run we will post to the queue again. When the other task runs it
- will find the queue still full, even though it was woken. It should
- recognise that its block time has not expired and return to block for
- the remains of its block time.
-
- Wake the other task so it blocks attempting to post to the already
- full queue. */
- xRunIndicator = 0;
- vTaskResume( xSecondary );
-
- /* We need to wait a little to ensure the other task executes. */
- while( xRunIndicator != bktRUN_INDICATOR )
- {
- /* The other task has not yet executed. */
- vTaskDelay( bktSHORT_WAIT );
- }
- /* Make sure the other task is blocked on the queue. */
- vTaskDelay( bktSHORT_WAIT );
- xRunIndicator = 0;
-
- for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
- {
- /* Now when we make space on the queue the other task should wake
- but not execute as this task has higher priority. */
- if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Now fill the queue again before the other task gets a chance to
- execute. If the other task had executed we would find the queue
- full ourselves, and the other task have set xRunIndicator. */
- if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- if( xRunIndicator == bktRUN_INDICATOR )
- {
- /* The other task should not have executed. */
- xErrorOccurred = pdTRUE;
- }
-
- /* Raise the priority of the other task so it executes and blocks
- on the queue again. */
- vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
-
- /* The other task should now have re-blocked without exiting the
- queue function. */
- if( xRunIndicator == bktRUN_INDICATOR )
- {
- /* The other task should not have executed outside of the
- queue function. */
- xErrorOccurred = pdTRUE;
- }
-
- /* Set the priority back down. */
- vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
- }
-
- /* Let the other task timeout. When it unblockes it will check that it
- unblocked at the correct time, then suspend itself. */
- while( xRunIndicator != bktRUN_INDICATOR )
- {
- vTaskDelay( bktSHORT_WAIT );
- }
- vTaskDelay( bktSHORT_WAIT );
- xRunIndicator = 0;
-
-
- /*********************************************************************
- Test 4
-
- As per test 3 - but with the send and receive the other way around.
- The other task blocks attempting to read from the queue.
-
- Empty the queue. We should find that it is full. */
- for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
- {
- if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
- }
-
- /* Wake the other task so it blocks attempting to read from the
- already empty queue. */
- vTaskResume( xSecondary );
-
- /* We need to wait a little to ensure the other task executes. */
- while( xRunIndicator != bktRUN_INDICATOR )
- {
- vTaskDelay( bktSHORT_WAIT );
- }
- vTaskDelay( bktSHORT_WAIT );
- xRunIndicator = 0;
-
- for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
- {
- /* Now when we place an item on the queue the other task should
- wake but not execute as this task has higher priority. */
- if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Now empty the queue again before the other task gets a chance to
- execute. If the other task had executed we would find the queue
- empty ourselves, and the other task would be suspended. */
- if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- if( xRunIndicator == bktRUN_INDICATOR )
- {
- /* The other task should not have executed. */
- xErrorOccurred = pdTRUE;
- }
-
- /* Raise the priority of the other task so it executes and blocks
- on the queue again. */
- vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
-
- /* The other task should now have re-blocked without exiting the
- queue function. */
- if( xRunIndicator == bktRUN_INDICATOR )
- {
- /* The other task should not have executed outside of the
- queue function. */
- xErrorOccurred = pdTRUE;
- }
- vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
- }
-
- /* Let the other task timeout. When it unblockes it will check that it
- unblocked at the correct time, then suspend itself. */
- while( xRunIndicator != bktRUN_INDICATOR )
- {
- vTaskDelay( bktSHORT_WAIT );
- }
- vTaskDelay( bktSHORT_WAIT );
-
- xPrimaryCycles++;
- }
+ BaseType_t xItem, xData;
+ TickType_t xTimeWhenBlocking;
+ TickType_t xTimeToBlock, xBlockedTime;
+
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /*********************************************************************
+ * Test 0
+ *
+ * Basic vTaskDelay() and vTaskDelayUntil() tests. */
+ prvBasicDelayTests();
+
+ /*********************************************************************
+ * Test 1
+ *
+ * Simple block time wakeup test on queue receives. */
+ for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
+ {
+ /* The queue is empty. Attempt to read from the queue using a block
+ * time. When we wake, ensure the delta in time is as expected. */
+ xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
+
+ xTimeWhenBlocking = xTaskGetTickCount();
+
+ /* We should unblock after xTimeToBlock having not received
+ * anything on the queue. */
+ if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* How long were we blocked for? */
+ xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
+
+ if( xBlockedTime < xTimeToBlock )
+ {
+ /* Should not have blocked for less than we requested. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
+ {
+ /* Should not have blocked for longer than we requested,
+ * although we would not necessarily run as soon as we were
+ * unblocked so a margin is allowed. */
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /*********************************************************************
+ * Test 2
+ *
+ * Simple block time wakeup test on queue sends.
+ *
+ * First fill the queue. It should be empty so all sends should pass. */
+ for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
+ {
+ if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ }
+
+ for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
+ {
+ /* The queue is full. Attempt to write to the queue using a block
+ * time. When we wake, ensure the delta in time is as expected. */
+ xTimeToBlock = ( TickType_t ) ( bktPRIMARY_BLOCK_TIME << xItem );
+
+ xTimeWhenBlocking = xTaskGetTickCount();
+
+ /* We should unblock after xTimeToBlock having not received
+ * anything on the queue. */
+ if( xQueueSend( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* How long were we blocked for? */
+ xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
+
+ if( xBlockedTime < xTimeToBlock )
+ {
+ /* Should not have blocked for less than we requested. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
+ {
+ /* Should not have blocked for longer than we requested,
+ * although we would not necessarily run as soon as we were
+ * unblocked so a margin is allowed. */
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /*********************************************************************
+ * Test 3
+ *
+ * Wake the other task, it will block attempting to post to the queue.
+ * When we read from the queue the other task will wake, but before it
+ * can run we will post to the queue again. When the other task runs it
+ * will find the queue still full, even though it was woken. It should
+ * recognise that its block time has not expired and return to block for
+ * the remains of its block time.
+ *
+ * Wake the other task so it blocks attempting to post to the already
+ * full queue. */
+ xRunIndicator = 0;
+ vTaskResume( xSecondary );
+
+ /* We need to wait a little to ensure the other task executes. */
+ while( xRunIndicator != bktRUN_INDICATOR )
+ {
+ /* The other task has not yet executed. */
+ vTaskDelay( bktSHORT_WAIT );
+ }
+
+ /* Make sure the other task is blocked on the queue. */
+ vTaskDelay( bktSHORT_WAIT );
+ xRunIndicator = 0;
+
+ for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
+ {
+ /* Now when we make space on the queue the other task should wake
+ * but not execute as this task has higher priority. */
+ if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Now fill the queue again before the other task gets a chance to
+ * execute. If the other task had executed we would find the queue
+ * full ourselves, and the other task have set xRunIndicator. */
+ if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ if( xRunIndicator == bktRUN_INDICATOR )
+ {
+ /* The other task should not have executed. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Raise the priority of the other task so it executes and blocks
+ * on the queue again. */
+ vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
+
+ /* The other task should now have re-blocked without exiting the
+ * queue function. */
+ if( xRunIndicator == bktRUN_INDICATOR )
+ {
+ /* The other task should not have executed outside of the
+ * queue function. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Set the priority back down. */
+ vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
+ }
+
+ /* Let the other task timeout. When it unblockes it will check that it
+ * unblocked at the correct time, then suspend itself. */
+ while( xRunIndicator != bktRUN_INDICATOR )
+ {
+ vTaskDelay( bktSHORT_WAIT );
+ }
+
+ vTaskDelay( bktSHORT_WAIT );
+ xRunIndicator = 0;
+
+ /*********************************************************************
+ * Test 4
+ *
+ * As per test 3 - but with the send and receive the other way around.
+ * The other task blocks attempting to read from the queue.
+ *
+ * Empty the queue. We should find that it is full. */
+ for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
+ {
+ if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ }
+
+ /* Wake the other task so it blocks attempting to read from the
+ * already empty queue. */
+ vTaskResume( xSecondary );
+
+ /* We need to wait a little to ensure the other task executes. */
+ while( xRunIndicator != bktRUN_INDICATOR )
+ {
+ vTaskDelay( bktSHORT_WAIT );
+ }
+
+ vTaskDelay( bktSHORT_WAIT );
+ xRunIndicator = 0;
+
+ for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
+ {
+ /* Now when we place an item on the queue the other task should
+ * wake but not execute as this task has higher priority. */
+ if( xQueueSend( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Now empty the queue again before the other task gets a chance to
+ * execute. If the other task had executed we would find the queue
+ * empty ourselves, and the other task would be suspended. */
+ if( xQueueReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ if( xRunIndicator == bktRUN_INDICATOR )
+ {
+ /* The other task should not have executed. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Raise the priority of the other task so it executes and blocks
+ * on the queue again. */
+ vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
+
+ /* The other task should now have re-blocked without exiting the
+ * queue function. */
+ if( xRunIndicator == bktRUN_INDICATOR )
+ {
+ /* The other task should not have executed outside of the
+ * queue function. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
+ }
+
+ /* Let the other task timeout. When it unblockes it will check that it
+ * unblocked at the correct time, then suspend itself. */
+ while( xRunIndicator != bktRUN_INDICATOR )
+ {
+ vTaskDelay( bktSHORT_WAIT );
+ }
+
+ vTaskDelay( bktSHORT_WAIT );
+
+ xPrimaryCycles++;
+ }
}
/*-----------------------------------------------------------*/
-static void vSecondaryBlockTimeTestTask( void *pvParameters )
+static void vSecondaryBlockTimeTestTask( void * pvParameters )
{
-TickType_t xTimeWhenBlocking, xBlockedTime;
-BaseType_t xData;
-
- ( void ) pvParameters;
-
- for( ;; )
- {
- /*********************************************************************
- Test 0, 1 and 2
-
- This task does not participate in these tests. */
- vTaskSuspend( NULL );
-
- /*********************************************************************
- Test 3
-
- The first thing we do is attempt to read from the queue. It should be
- full so we block. Note the time before we block so we can check the
- wake time is as per that expected. */
- xTimeWhenBlocking = xTaskGetTickCount();
-
- /* We should unblock after bktTIME_TO_BLOCK having not sent anything to
- the queue. */
- xData = 0;
- xRunIndicator = bktRUN_INDICATOR;
- if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* How long were we inside the send function? */
- xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
-
- /* We should not have blocked for less time than bktTIME_TO_BLOCK. */
- if( xBlockedTime < bktTIME_TO_BLOCK )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* We should of not blocked for much longer than bktALLOWABLE_MARGIN
- either. A margin is permitted as we would not necessarily run as
- soon as we unblocked. */
- if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Suspend ready for test 3. */
- xRunIndicator = bktRUN_INDICATOR;
- vTaskSuspend( NULL );
-
- /*********************************************************************
- Test 4
-
- As per test three, but with the send and receive reversed. */
- xTimeWhenBlocking = xTaskGetTickCount();
-
- /* We should unblock after bktTIME_TO_BLOCK having not received
- anything on the queue. */
- xRunIndicator = bktRUN_INDICATOR;
- if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
- {
- xErrorOccurred = pdTRUE;
- }
-
- xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
-
- /* We should not have blocked for less time than bktTIME_TO_BLOCK. */
- if( xBlockedTime < bktTIME_TO_BLOCK )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* We should of not blocked for much longer than bktALLOWABLE_MARGIN
- either. A margin is permitted as we would not necessarily run as soon
- as we unblocked. */
- if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
- {
- xErrorOccurred = pdTRUE;
- }
-
- xRunIndicator = bktRUN_INDICATOR;
-
- xSecondaryCycles++;
- }
+ TickType_t xTimeWhenBlocking, xBlockedTime;
+ BaseType_t xData;
+
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /*********************************************************************
+ * Test 0, 1 and 2
+ *
+ * This task does not participate in these tests. */
+ vTaskSuspend( NULL );
+
+ /*********************************************************************
+ * Test 3
+ *
+ * The first thing we do is attempt to read from the queue. It should be
+ * full so we block. Note the time before we block so we can check the
+ * wake time is as per that expected. */
+ xTimeWhenBlocking = xTaskGetTickCount();
+
+ /* We should unblock after bktTIME_TO_BLOCK having not sent anything to
+ * the queue. */
+ xData = 0;
+ xRunIndicator = bktRUN_INDICATOR;
+
+ if( xQueueSend( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* How long were we inside the send function? */
+ xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
+
+ /* We should not have blocked for less time than bktTIME_TO_BLOCK. */
+ if( xBlockedTime < bktTIME_TO_BLOCK )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* We should of not blocked for much longer than bktALLOWABLE_MARGIN
+ * either. A margin is permitted as we would not necessarily run as
+ * soon as we unblocked. */
+ if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Suspend ready for test 3. */
+ xRunIndicator = bktRUN_INDICATOR;
+ vTaskSuspend( NULL );
+
+ /*********************************************************************
+ * Test 4
+ *
+ * As per test three, but with the send and receive reversed. */
+ xTimeWhenBlocking = xTaskGetTickCount();
+
+ /* We should unblock after bktTIME_TO_BLOCK having not received
+ * anything on the queue. */
+ xRunIndicator = bktRUN_INDICATOR;
+
+ if( xQueueReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
+
+ /* We should not have blocked for less time than bktTIME_TO_BLOCK. */
+ if( xBlockedTime < bktTIME_TO_BLOCK )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* We should of not blocked for much longer than bktALLOWABLE_MARGIN
+ * either. A margin is permitted as we would not necessarily run as soon
+ * as we unblocked. */
+ if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ xRunIndicator = bktRUN_INDICATOR;
+
+ xSecondaryCycles++;
+ }
}
/*-----------------------------------------------------------*/
static void prvBasicDelayTests( void )
{
-TickType_t xPreTime, xPostTime, x, xLastUnblockTime, xExpectedUnblockTime;
-const TickType_t xPeriod = 75, xCycles = 5, xAllowableMargin = ( bktALLOWABLE_MARGIN >> 1 ), xHalfPeriod = xPeriod / ( TickType_t ) 2;
-BaseType_t xDidBlock;
-
- /* Temporarily increase priority so the timing is more accurate, but not so
- high as to disrupt the timer tests. */
- vTaskPrioritySet( NULL, configTIMER_TASK_PRIORITY - 1 );
-
- /* Crude check to too see that vTaskDelay() blocks for the expected
- period. */
- xPreTime = xTaskGetTickCount();
- vTaskDelay( bktTIME_TO_BLOCK );
- xPostTime = xTaskGetTickCount();
-
- /* The priority is higher, so the allowable margin is halved when compared
- to the other tests in this file. */
- if( ( xPostTime - xPreTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Now crude tests to check the vTaskDelayUntil() functionality. */
- xPostTime = xTaskGetTickCount();
- xLastUnblockTime = xPostTime;
-
- for( x = 0; x < xCycles; x++ )
- {
- /* Calculate the next expected unblock time from the time taken before
- this loop was entered. */
- xExpectedUnblockTime = xPostTime + ( x * xPeriod );
-
- vTaskDelayUntil( &xLastUnblockTime, xPeriod );
-
- if( ( xTaskGetTickCount() - xExpectedUnblockTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
- {
- xErrorOccurred = pdTRUE;
- }
-
- xPrimaryCycles++;
- }
-
- /* Crude tests for return value of xTaskDelayUntil(). First a standard block
- should return that the task does block. */
- xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
- if( xDidBlock != pdTRUE )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Now delay a few ticks so repeating the above block period will not block for
- the full amount of time, but will still block. */
- vTaskDelay( xHalfPeriod );
- xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
- if( xDidBlock != pdTRUE )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* This time block for longer than xPeriod before calling xTaskDelayUntil() so
- the call to xTaskDelayUntil() should not block. */
- vTaskDelay( xPeriod );
- xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
- if( xDidBlock != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Catch up. */
- xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
- if( xDidBlock != pdTRUE )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Again block for slightly longer than a period so ensure the time is in the
- past next time xTaskDelayUntil() gets called. */
- vTaskDelay( xPeriod + xAllowableMargin );
- xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
- if( xDidBlock != pdFALSE )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Reset to the original task priority ready for the other tests. */
- vTaskPrioritySet( NULL, bktPRIMARY_PRIORITY );
+ TickType_t xPreTime, xPostTime, x, xLastUnblockTime, xExpectedUnblockTime;
+ const TickType_t xPeriod = 75, xCycles = 5, xAllowableMargin = ( bktALLOWABLE_MARGIN >> 1 ), xHalfPeriod = xPeriod / ( TickType_t ) 2;
+ BaseType_t xDidBlock;
+
+ /* Temporarily increase priority so the timing is more accurate, but not so
+ * high as to disrupt the timer tests. */
+ vTaskPrioritySet( NULL, configTIMER_TASK_PRIORITY - 1 );
+
+ /* Crude check to too see that vTaskDelay() blocks for the expected
+ * period. */
+ xPreTime = xTaskGetTickCount();
+ vTaskDelay( bktTIME_TO_BLOCK );
+ xPostTime = xTaskGetTickCount();
+
+ /* The priority is higher, so the allowable margin is halved when compared
+ * to the other tests in this file. */
+ if( ( xPostTime - xPreTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Now crude tests to check the vTaskDelayUntil() functionality. */
+ xPostTime = xTaskGetTickCount();
+ xLastUnblockTime = xPostTime;
+
+ for( x = 0; x < xCycles; x++ )
+ {
+ /* Calculate the next expected unblock time from the time taken before
+ * this loop was entered. */
+ xExpectedUnblockTime = xPostTime + ( x * xPeriod );
+
+ vTaskDelayUntil( &xLastUnblockTime, xPeriod );
+
+ if( ( xTaskGetTickCount() - xExpectedUnblockTime ) > ( bktTIME_TO_BLOCK + xAllowableMargin ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ xPrimaryCycles++;
+ }
+
+ /* Crude tests for return value of xTaskDelayUntil(). First a standard block
+ * should return that the task does block. */
+ xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
+
+ if( xDidBlock != pdTRUE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Now delay a few ticks so repeating the above block period will not block for
+ * the full amount of time, but will still block. */
+ vTaskDelay( xHalfPeriod );
+ xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
+
+ if( xDidBlock != pdTRUE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* This time block for longer than xPeriod before calling xTaskDelayUntil() so
+ * the call to xTaskDelayUntil() should not block. */
+ vTaskDelay( xPeriod );
+ xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
+
+ if( xDidBlock != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Catch up. */
+ xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
+
+ if( xDidBlock != pdTRUE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Again block for slightly longer than a period so ensure the time is in the
+ * past next time xTaskDelayUntil() gets called. */
+ vTaskDelay( xPeriod + xAllowableMargin );
+ xDidBlock = xTaskDelayUntil( &xLastUnblockTime, xPeriod );
+
+ if( xDidBlock != pdFALSE )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Reset to the original task priority ready for the other tests. */
+ vTaskPrioritySet( NULL, bktPRIMARY_PRIORITY );
}
/*-----------------------------------------------------------*/
BaseType_t xAreBlockTimeTestTasksStillRunning( void )
{
-static BaseType_t xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
-BaseType_t xReturn = pdPASS;
-
- /* Have both tasks performed at least one cycle since this function was
- last called? */
- if( xPrimaryCycles == xLastPrimaryCycleCount )
- {
- xReturn = pdFAIL;
- }
-
- if( xSecondaryCycles == xLastSecondaryCycleCount )
- {
- xReturn = pdFAIL;
- }
-
- if( xErrorOccurred == pdTRUE )
- {
- xReturn = pdFAIL;
- }
-
- xLastSecondaryCycleCount = xSecondaryCycles;
- xLastPrimaryCycleCount = xPrimaryCycles;
-
- return xReturn;
+ static BaseType_t xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
+ BaseType_t xReturn = pdPASS;
+
+ /* Have both tasks performed at least one cycle since this function was
+ * last called? */
+ if( xPrimaryCycles == xLastPrimaryCycleCount )
+ {
+ xReturn = pdFAIL;
+ }
+
+ if( xSecondaryCycles == xLastSecondaryCycleCount )
+ {
+ xReturn = pdFAIL;
+ }
+
+ if( xErrorOccurred == pdTRUE )
+ {
+ xReturn = pdFAIL;
+ }
+
+ xLastSecondaryCycleCount = xSecondaryCycles;
+ xLastPrimaryCycleCount = xPrimaryCycles;
+
+ return xReturn;
}
diff --git a/FreeRTOS/Demo/Common/Minimal/comtest.c b/FreeRTOS/Demo/Common/Minimal/comtest.c
index ebdb07bd9..ab756973a 100644
--- a/FreeRTOS/Demo/Common/Minimal/comtest.c
+++ b/FreeRTOS/Demo/Common/Minimal/comtest.c
@@ -67,30 +67,30 @@
#include "comtest.h"
#include "partest.h"
-#define comSTACK_SIZE configMINIMAL_STACK_SIZE
-#define comTX_LED_OFFSET ( 0 )
-#define comRX_LED_OFFSET ( 1 )
-#define comTOTAL_PERMISSIBLE_ERRORS ( 2 )
+#define comSTACK_SIZE configMINIMAL_STACK_SIZE
+#define comTX_LED_OFFSET ( 0 )
+#define comRX_LED_OFFSET ( 1 )
+#define comTOTAL_PERMISSIBLE_ERRORS ( 2 )
/* The Tx task will transmit the sequence of characters at a pseudo random
-interval. This is the maximum and minimum block time between sends. */
-#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
-#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
-#define comOFFSET_TIME ( ( TickType_t ) 3 )
+ * interval. This is the maximum and minimum block time between sends. */
+#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
+#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
+#define comOFFSET_TIME ( ( TickType_t ) 3 )
/* We should find that each character can be queued for Tx immediately and we
-don't have to block to send. */
-#define comNO_BLOCK ( ( TickType_t ) 0 )
+ * don't have to block to send. */
+#define comNO_BLOCK ( ( TickType_t ) 0 )
/* The Rx task will block on the Rx queue for a long period. */
-#define comRX_BLOCK_TIME ( ( TickType_t ) 0xffff )
+#define comRX_BLOCK_TIME ( ( TickType_t ) 0xffff )
/* The sequence transmitted is from comFIRST_BYTE to and including comLAST_BYTE. */
-#define comFIRST_BYTE ( 'A' )
-#define comLAST_BYTE ( 'X' )
+#define comFIRST_BYTE ( 'A' )
+#define comLAST_BYTE ( 'X' )
-#define comBUFFER_LEN ( ( UBaseType_t ) ( comLAST_BYTE - comFIRST_BYTE ) + ( UBaseType_t ) 1 )
-#define comINITIAL_RX_COUNT_VALUE ( 0 )
+#define comBUFFER_LEN ( ( UBaseType_t ) ( comLAST_BYTE - comFIRST_BYTE ) + ( UBaseType_t ) 1 )
+#define comINITIAL_RX_COUNT_VALUE ( 0 )
/* Handle to the com port used by both tasks. */
static xComPortHandle xPort = NULL;
@@ -102,164 +102,165 @@ static portTASK_FUNCTION_PROTO( vComTxTask, pvParameters );
static portTASK_FUNCTION_PROTO( vComRxTask, pvParameters );
/* The LED that should be toggled by the Rx and Tx tasks. The Rx task will
-toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task will toggle LED
-( uxBaseLED + comTX_LED_OFFSET ). */
+ * toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task will toggle LED
+ * ( uxBaseLED + comTX_LED_OFFSET ). */
static UBaseType_t uxBaseLED = 0;
/* Check variable used to ensure no error have occurred. The Rx task will
-increment this variable after every successfully received sequence. If at any
-time the sequence is incorrect the the variable will stop being incremented. */
+ * increment this variable after every successfully received sequence. If at any
+ * time the sequence is incorrect the the variable will stop being incremented. */
static volatile UBaseType_t uxRxLoops = comINITIAL_RX_COUNT_VALUE;
/*-----------------------------------------------------------*/
-void vAltStartComTestTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED )
+void vAltStartComTestTasks( UBaseType_t uxPriority,
+ uint32_t ulBaudRate,
+ UBaseType_t uxLED )
{
- /* Initialise the com port then spawn the Rx and Tx tasks. */
- uxBaseLED = uxLED;
- xSerialPortInitMinimal( ulBaudRate, comBUFFER_LEN );
+ /* Initialise the com port then spawn the Rx and Tx tasks. */
+ uxBaseLED = uxLED;
+ xSerialPortInitMinimal( ulBaudRate, comBUFFER_LEN );
- /* The Tx task is spawned with a lower priority than the Rx task. */
- xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority - 1, ( TaskHandle_t * ) NULL );
- xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
+ /* The Tx task is spawned with a lower priority than the Rx task. */
+ xTaskCreate( vComTxTask, "COMTx", comSTACK_SIZE, NULL, uxPriority - 1, ( TaskHandle_t * ) NULL );
+ xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vComTxTask, pvParameters )
{
-char cByteToSend;
-TickType_t xTimeToWait;
-
- /* Just to stop compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Simply transmit a sequence of characters from comFIRST_BYTE to
- comLAST_BYTE. */
- for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
- {
- if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
- {
- vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
- }
- }
-
- /* Turn the LED off while we are not doing anything. */
- vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE );
-
- /* We have posted all the characters in the string - wait before
- re-sending. Wait a pseudo-random time as this will provide a better
- test. */
- xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
-
- /* Make sure we don't wait too long... */
- xTimeToWait %= comTX_MAX_BLOCK_TIME;
-
- /* ...but we do want to wait. */
- if( xTimeToWait < comTX_MIN_BLOCK_TIME )
- {
- xTimeToWait = comTX_MIN_BLOCK_TIME;
- }
-
- vTaskDelay( xTimeToWait );
- }
+ char cByteToSend;
+ TickType_t xTimeToWait;
+
+ /* Just to stop compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Simply transmit a sequence of characters from comFIRST_BYTE to
+ * comLAST_BYTE. */
+ for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ )
+ {
+ if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS )
+ {
+ vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
+ }
+ }
+
+ /* Turn the LED off while we are not doing anything. */
+ vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE );
+
+ /* We have posted all the characters in the string - wait before
+ * re-sending. Wait a pseudo-random time as this will provide a better
+ * test. */
+ xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
+
+ /* Make sure we don't wait too long... */
+ xTimeToWait %= comTX_MAX_BLOCK_TIME;
+
+ /* ...but we do want to wait. */
+ if( xTimeToWait < comTX_MIN_BLOCK_TIME )
+ {
+ xTimeToWait = comTX_MIN_BLOCK_TIME;
+ }
+
+ vTaskDelay( xTimeToWait );
+ }
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vComRxTask, pvParameters )
{
-signed char cExpectedByte, cByteRxed;
-BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
-
- /* Just to stop compiler warnings. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* We expect to receive the characters from comFIRST_BYTE to
- comLAST_BYTE in an incrementing order. Loop to receive each byte. */
- for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
- {
- /* Block on the queue that contains received bytes until a byte is
- available. */
- if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
- {
- /* Was this the byte we were expecting? If so, toggle the LED,
- otherwise we are out on sync and should break out of the loop
- until the expected character sequence is about to restart. */
- if( cByteRxed == cExpectedByte )
- {
- vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
- }
- else
- {
- xResyncRequired = pdTRUE;
- break; /*lint !e960 Non-switch break allowed. */
- }
- }
- }
-
- /* Turn the LED off while we are not doing anything. */
- vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
-
- /* Did we break out of the loop because the characters were received in
- an unexpected order? If so wait here until the character sequence is
- about to restart. */
- if( xResyncRequired == pdTRUE )
- {
- while( cByteRxed != comLAST_BYTE )
- {
- /* Block until the next char is available. */
- xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
- }
-
- /* Note that an error occurred which caused us to have to resync.
- We use this to stop incrementing the loop counter so
- sAreComTestTasksStillRunning() will return false - indicating an
- error. */
- xErrorOccurred++;
-
- /* We have now resynced with the Tx task and can continue. */
- xResyncRequired = pdFALSE;
- }
- else
- {
- if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
- {
- /* Increment the count of successful loops. As error
- occurring (i.e. an unexpected character being received) will
- prevent this counter being incremented for the rest of the
- execution. Don't worry about mutual exclusion on this
- variable - it doesn't really matter as we just want it
- to change. */
- uxRxLoops++;
- }
- }
- }
+ signed char cExpectedByte, cByteRxed;
+ BaseType_t xResyncRequired = pdFALSE, xErrorOccurred = pdFALSE;
+
+ /* Just to stop compiler warnings. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* We expect to receive the characters from comFIRST_BYTE to
+ * comLAST_BYTE in an incrementing order. Loop to receive each byte. */
+ for( cExpectedByte = comFIRST_BYTE; cExpectedByte <= comLAST_BYTE; cExpectedByte++ )
+ {
+ /* Block on the queue that contains received bytes until a byte is
+ * available. */
+ if( xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME ) )
+ {
+ /* Was this the byte we were expecting? If so, toggle the LED,
+ * otherwise we are out on sync and should break out of the loop
+ * until the expected character sequence is about to restart. */
+ if( cByteRxed == cExpectedByte )
+ {
+ vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
+ }
+ else
+ {
+ xResyncRequired = pdTRUE;
+ break; /*lint !e960 Non-switch break allowed. */
+ }
+ }
+ }
+
+ /* Turn the LED off while we are not doing anything. */
+ vParTestSetLED( uxBaseLED + comRX_LED_OFFSET, pdFALSE );
+
+ /* Did we break out of the loop because the characters were received in
+ * an unexpected order? If so wait here until the character sequence is
+ * about to restart. */
+ if( xResyncRequired == pdTRUE )
+ {
+ while( cByteRxed != comLAST_BYTE )
+ {
+ /* Block until the next char is available. */
+ xSerialGetChar( xPort, &cByteRxed, comRX_BLOCK_TIME );
+ }
+
+ /* Note that an error occurred which caused us to have to resync.
+ * We use this to stop incrementing the loop counter so
+ * sAreComTestTasksStillRunning() will return false - indicating an
+ * error. */
+ xErrorOccurred++;
+
+ /* We have now resynced with the Tx task and can continue. */
+ xResyncRequired = pdFALSE;
+ }
+ else
+ {
+ if( xErrorOccurred < comTOTAL_PERMISSIBLE_ERRORS )
+ {
+ /* Increment the count of successful loops. As error
+ * occurring (i.e. an unexpected character being received) will
+ * prevent this counter being incremented for the rest of the
+ * execution. Don't worry about mutual exclusion on this
+ * variable - it doesn't really matter as we just want it
+ * to change. */
+ uxRxLoops++;
+ }
+ }
+ }
} /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/*-----------------------------------------------------------*/
BaseType_t xAreComTestTasksStillRunning( void )
{
-BaseType_t xReturn;
-
- /* If the count of successful reception loops has not changed than at
- some time an error occurred (i.e. a character was received out of sequence)
- and we will return false. */
- if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- /* Reset the count of successful Rx loops. When this function is called
- again we expect this to have been incremented. */
- uxRxLoops = comINITIAL_RX_COUNT_VALUE;
-
- return xReturn;
+ BaseType_t xReturn;
+
+ /* If the count of successful reception loops has not changed than at
+ * some time an error occurred (i.e. a character was received out of sequence)
+ * and we will return false. */
+ if( uxRxLoops == comINITIAL_RX_COUNT_VALUE )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ xReturn = pdTRUE;
+ }
+
+ /* Reset the count of successful Rx loops. When this function is called
+ * again we expect this to have been incremented. */
+ uxRxLoops = comINITIAL_RX_COUNT_VALUE;
+
+ return xReturn;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/comtest_strings.c b/FreeRTOS/Demo/Common/Minimal/comtest_strings.c
index 598e137f6..f9d647676 100644
--- a/FreeRTOS/Demo/Common/Minimal/comtest_strings.c
+++ b/FreeRTOS/Demo/Common/Minimal/comtest_strings.c
@@ -19,8 +19,8 @@
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
- * https://www.FreeRTOS.org
- * https://github.com/FreeRTOS
+ * https://www.FreeRTOS.org
+ * https://github.com/FreeRTOS
*
*/
@@ -57,11 +57,11 @@
#include "timers.h"
#ifndef configUSE_TIMERS
- #error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
+ #error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
#endif
#if configUSE_TIMERS != 1
- #error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
+ #error This demo uses timers. configUSE_TIMERS must be set to 1 in FreeRTOSConfig.h.
#endif
@@ -71,240 +71,246 @@
#include "partest.h"
/* The size of the stack given to the Rx task. */
-#define comSTACK_SIZE configMINIMAL_STACK_SIZE
+#define comSTACK_SIZE configMINIMAL_STACK_SIZE
/* See the comment above the declaration of the uxBaseLED variable. */
-#define comTX_LED_OFFSET ( 0 )
-#define comRX_LED_OFFSET ( 1 )
+#define comTX_LED_OFFSET ( 0 )
+#define comRX_LED_OFFSET ( 1 )
/* The Tx timer transmits the sequence of characters at a pseudo random
-interval that is capped between comTX_MAX_BLOCK_TIME and
-comTX_MIN_BLOCK_TIME. */
-#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
-#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
-#define comOFFSET_TIME ( ( TickType_t ) 3 )
+ * interval that is capped between comTX_MAX_BLOCK_TIME and
+ * comTX_MIN_BLOCK_TIME. */
+#define comTX_MAX_BLOCK_TIME ( ( TickType_t ) 0x96 )
+#define comTX_MIN_BLOCK_TIME ( ( TickType_t ) 0x32 )
+#define comOFFSET_TIME ( ( TickType_t ) 3 )
/* States for the simple state machine implemented in the Rx task. */
-#define comtstWAITING_START_OF_STRING 0
-#define comtstWAITING_END_OF_STRING 1
+#define comtstWAITING_START_OF_STRING 0
+#define comtstWAITING_END_OF_STRING 1
/* A short delay in ticks - this delay is used to allow the Rx queue to fill up
-a bit so more than one character can be processed at a time. This is relative
-to comTX_MIN_BLOCK_TIME to ensure it is never longer than the shortest gap
-between transmissions. It could be worked out more scientifically from the
-baud rate being used. */
-#define comSHORT_DELAY ( comTX_MIN_BLOCK_TIME >> ( TickType_t ) 2 )
+ * a bit so more than one character can be processed at a time. This is relative
+ * to comTX_MIN_BLOCK_TIME to ensure it is never longer than the shortest gap
+ * between transmissions. It could be worked out more scientifically from the
+ * baud rate being used. */
+#define comSHORT_DELAY ( comTX_MIN_BLOCK_TIME >> ( TickType_t ) 2 )
/* The string that is transmitted and received. */
-#define comTRANSACTED_STRING "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
+#define comTRANSACTED_STRING "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
/* A block time of 0 simply means "don't block". */
-#define comtstDONT_BLOCK ( TickType_t ) 0
+#define comtstDONT_BLOCK ( TickType_t ) 0
/* Handle to the com port used by both tasks. */
static xComPortHandle xPort = NULL;
/* The callback function allocated to the transmit timer, as described in the
-comments at the top of this file. */
+ * comments at the top of this file. */
static void prvComTxTimerCallback( TimerHandle_t xTimer );
/* The receive task as described in the comments at the top of this file. */
-static void vComRxTask( void *pvParameters );
+static void vComRxTask( void * pvParameters );
/* The Rx task will toggle LED ( uxBaseLED + comRX_LED_OFFSET). The Tx task
-will toggle LED ( uxBaseLED + comTX_LED_OFFSET ). */
+ * will toggle LED ( uxBaseLED + comTX_LED_OFFSET ). */
static UBaseType_t uxBaseLED = 0;
/* The Rx task toggles uxRxLoops on each successful iteration of its defined
-function - provided no errors have ever been latched. If this variable stops
-incrementing, then an error has occurred. */
+ * function - provided no errors have ever been latched. If this variable stops
+ * incrementing, then an error has occurred. */
static volatile UBaseType_t uxRxLoops = 0UL;
/* The timer used to periodically transmit the string. This is the timer that
-has prvComTxTimerCallback allocated to it as its callback function. */
+ * has prvComTxTimerCallback allocated to it as its callback function. */
static TimerHandle_t xTxTimer = NULL;
/* The string length is held at file scope so the Tx timer does not need to
-calculate it each time it executes. */
+ * calculate it each time it executes. */
static size_t xStringLength = 0U;
/*-----------------------------------------------------------*/
-void vStartComTestStringsTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED )
+void vStartComTestStringsTasks( UBaseType_t uxPriority,
+ uint32_t ulBaudRate,
+ UBaseType_t uxLED )
{
- /* Store values that are used at run time. */
- uxBaseLED = uxLED;
-
- /* Calculate the string length here, rather than each time the Tx timer
- executes. */
- xStringLength = strlen( comTRANSACTED_STRING );
-
- /* Include the null terminator in the string length as this is used to
- detect the end of the string in the Rx task. */
- xStringLength++;
-
- /* Initialise the com port, then spawn the Rx task and create the Tx
- timer. */
- xSerialPortInitMinimal( ulBaudRate, ( xStringLength * 2U ) );
-
- /* Create the Rx task and the Tx timer. The timer is started from the
- Rx task. */
- xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
- xTxTimer = xTimerCreate( "TxTimer", comTX_MIN_BLOCK_TIME, pdFALSE, NULL, prvComTxTimerCallback );
- configASSERT( xTxTimer );
+ /* Store values that are used at run time. */
+ uxBaseLED = uxLED;
+
+ /* Calculate the string length here, rather than each time the Tx timer
+ * executes. */
+ xStringLength = strlen( comTRANSACTED_STRING );
+
+ /* Include the null terminator in the string length as this is used to
+ * detect the end of the string in the Rx task. */
+ xStringLength++;
+
+ /* Initialise the com port, then spawn the Rx task and create the Tx
+ * timer. */
+ xSerialPortInitMinimal( ulBaudRate, ( xStringLength * 2U ) );
+
+ /* Create the Rx task and the Tx timer. The timer is started from the
+ * Rx task. */
+ xTaskCreate( vComRxTask, "COMRx", comSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
+ xTxTimer = xTimerCreate( "TxTimer", comTX_MIN_BLOCK_TIME, pdFALSE, NULL, prvComTxTimerCallback );
+ configASSERT( xTxTimer );
}
/*-----------------------------------------------------------*/
static void prvComTxTimerCallback( TimerHandle_t xTimer )
{
-TickType_t xTimeToWait;
+ TickType_t xTimeToWait;
- /* The parameter is not used in this case. */
- ( void ) xTimer;
+ /* The parameter is not used in this case. */
+ ( void ) xTimer;
- /* Send the string. How this is actually performed depends on the
- sample driver provided with this demo. However - as this is a timer,
- it executes in the context of the timer task and therefore must not
- block. */
- vSerialPutString( xPort, comTRANSACTED_STRING, xStringLength );
+ /* Send the string. How this is actually performed depends on the
+ * sample driver provided with this demo. However - as this is a timer,
+ * it executes in the context of the timer task and therefore must not
+ * block. */
+ vSerialPutString( xPort, comTRANSACTED_STRING, xStringLength );
- /* Toggle an LED to give a visible indication that another transmission
- has been performed. */
- vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
+ /* Toggle an LED to give a visible indication that another transmission
+ * has been performed. */
+ vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET );
- /* Wait a pseudo random time before sending the string again. */
- xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
+ /* Wait a pseudo random time before sending the string again. */
+ xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME;
- /* Ensure the time to wait is not greater than comTX_MAX_BLOCK_TIME. */
- xTimeToWait %= comTX_MAX_BLOCK_TIME;
+ /* Ensure the time to wait is not greater than comTX_MAX_BLOCK_TIME. */
+ xTimeToWait %= comTX_MAX_BLOCK_TIME;
- /* Ensure the time to wait is not less than comTX_MIN_BLOCK_TIME. */
- if( xTimeToWait < comTX_MIN_BLOCK_TIME )
- {
- xTimeToWait = comTX_MIN_BLOCK_TIME;
- }
+ /* Ensure the time to wait is not less than comTX_MIN_BLOCK_TIME. */
+ if( xTimeToWait < comTX_MIN_BLOCK_TIME )
+ {
+ xTimeToWait = comTX_MIN_BLOCK_TIME;
+ }
- /* Reset the timer to run again xTimeToWait ticks from now. This function
- is called from the context of the timer task, so the block time must not
- be anything other than zero. */
- xTimerChangePeriod( xTxTimer, xTimeToWait, comtstDONT_BLOCK );
+ /* Reset the timer to run again xTimeToWait ticks from now. This function
+ * is called from the context of the timer task, so the block time must not
+ * be anything other than zero. */
+ xTimerChangePeriod( xTxTimer, xTimeToWait, comtstDONT_BLOCK );
}
/*-----------------------------------------------------------*/
-static void vComRxTask( void *pvParameters )
+static void vComRxTask( void * pvParameters )
{
-BaseType_t xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
-char *pcExpectedByte, cRxedChar;
-const xComPortHandle xPort = NULL;
-
- /* The parameter is not used in this example. */
- ( void ) pvParameters;
-
- /* Start the Tx timer. This only needs to be started once, as it will
- reset itself thereafter. */
- xTimerStart( xTxTimer, portMAX_DELAY );
-
- /* The first expected Rx character is the first in the string that is
- transmitted. */
- pcExpectedByte = comTRANSACTED_STRING;
-
- for( ;; )
- {
- /* Wait for the next character. */
- if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )
- {
- /* A character definitely should have been received by now. As a
- character was not received an error must have occurred (which might
- just be that the loopback connector is not fitted). */
- xErrorOccurred = pdTRUE;
- }
-
- switch( xState )
- {
- case comtstWAITING_START_OF_STRING:
- if( cRxedChar == *pcExpectedByte )
- {
- /* The received character was the first character of the
- string. Move to the next state to check each character
- as it comes in until the entire string has been received. */
- xState = comtstWAITING_END_OF_STRING;
- pcExpectedByte++;
-
- /* Block for a short period. This just allows the Rx queue
- to contain more than one character, and therefore prevent
- thrashing reads to the queue, and repetitive context
- switches as each character is received. */
- vTaskDelay( comSHORT_DELAY );
- }
- break;
-
- case comtstWAITING_END_OF_STRING:
- if( cRxedChar == *pcExpectedByte )
- {
- /* The received character was the expected character. Was
- it the last character in the string - i.e. the null
- terminator? */
- if( cRxedChar == 0x00 )
- {
- /* The entire string has been received. If no errors
- have been latched, then increment the loop counter to
- show this task is still healthy. */
- if( xErrorOccurred == pdFALSE )
- {
- uxRxLoops++;
-
- /* Toggle an LED to give a visible sign that a
- complete string has been received. */
- vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
- }
-
- /* Go back to wait for the start of the next string. */
- pcExpectedByte = comTRANSACTED_STRING;
- xState = comtstWAITING_START_OF_STRING;
- }
- else
- {
- /* Wait for the next character in the string. */
- pcExpectedByte++;
- }
- }
- else
- {
- /* The character received was not that expected. */
- xErrorOccurred = pdTRUE;
- }
- break;
-
- default:
- /* Should not get here. Stop the Rx loop counter from
- incrementing to latch the error. */
- xErrorOccurred = pdTRUE;
- break;
- }
- }
+ BaseType_t xState = comtstWAITING_START_OF_STRING, xErrorOccurred = pdFALSE;
+ char * pcExpectedByte, cRxedChar;
+ const xComPortHandle xPort = NULL;
+
+ /* The parameter is not used in this example. */
+ ( void ) pvParameters;
+
+ /* Start the Tx timer. This only needs to be started once, as it will
+ * reset itself thereafter. */
+ xTimerStart( xTxTimer, portMAX_DELAY );
+
+ /* The first expected Rx character is the first in the string that is
+ * transmitted. */
+ pcExpectedByte = comTRANSACTED_STRING;
+
+ for( ; ; )
+ {
+ /* Wait for the next character. */
+ if( xSerialGetChar( xPort, &cRxedChar, ( comTX_MAX_BLOCK_TIME * 2 ) ) == pdFALSE )
+ {
+ /* A character definitely should have been received by now. As a
+ * character was not received an error must have occurred (which might
+ * just be that the loopback connector is not fitted). */
+ xErrorOccurred = pdTRUE;
+ }
+
+ switch( xState )
+ {
+ case comtstWAITING_START_OF_STRING:
+
+ if( cRxedChar == *pcExpectedByte )
+ {
+ /* The received character was the first character of the
+ * string. Move to the next state to check each character
+ * as it comes in until the entire string has been received. */
+ xState = comtstWAITING_END_OF_STRING;
+ pcExpectedByte++;
+
+ /* Block for a short period. This just allows the Rx queue
+ * to contain more than one character, and therefore prevent
+ * thrashing reads to the queue, and repetitive context
+ * switches as each character is received. */
+ vTaskDelay( comSHORT_DELAY );
+ }
+
+ break;
+
+ case comtstWAITING_END_OF_STRING:
+
+ if( cRxedChar == *pcExpectedByte )
+ {
+ /* The received character was the expected character. Was
+ * it the last character in the string - i.e. the null
+ * terminator? */
+ if( cRxedChar == 0x00 )
+ {
+ /* The entire string has been received. If no errors
+ * have been latched, then increment the loop counter to
+ * show this task is still healthy. */
+ if( xErrorOccurred == pdFALSE )
+ {
+ uxRxLoops++;
+
+ /* Toggle an LED to give a visible sign that a
+ * complete string has been received. */
+ vParTestToggleLED( uxBaseLED + comRX_LED_OFFSET );
+ }
+
+ /* Go back to wait for the start of the next string. */
+ pcExpectedByte = comTRANSACTED_STRING;
+ xState = comtstWAITING_START_OF_STRING;
+ }
+ else
+ {
+ /* Wait for the next character in the string. */
+ pcExpectedByte++;
+ }
+ }
+ else
+ {
+ /* The character received was not that expected. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ break;
+
+ default:
+
+ /* Should not get here. Stop the Rx loop counter from
+ * incrementing to latch the error. */
+ xErrorOccurred = pdTRUE;
+ break;
+ }
+ }
}
/*-----------------------------------------------------------*/
BaseType_t xAreComTestTasksStillRunning( void )
{
-BaseType_t xReturn;
-
- /* If the count of successful reception loops has not changed than at
- some time an error occurred (i.e. a character was received out of sequence)
- and false is returned. */
- if( uxRxLoops == 0UL )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
-
- /* Reset the count of successful Rx loops. When this function is called
- again it should have been incremented again. */
- uxRxLoops = 0UL;
-
- return xReturn;
+ BaseType_t xReturn;
+
+ /* If the count of successful reception loops has not changed than at
+ * some time an error occurred (i.e. a character was received out of sequence)
+ * and false is returned. */
+ if( uxRxLoops == 0UL )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ xReturn = pdTRUE;
+ }
+
+ /* Reset the count of successful Rx loops. When this function is called
+ * again it should have been incremented again. */
+ uxRxLoops = 0UL;
+
+ return xReturn;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/countsem.c b/FreeRTOS/Demo/Common/Minimal/countsem.c
index afabce40d..7dd278e29 100644
--- a/FreeRTOS/Demo/Common/Minimal/countsem.c
+++ b/FreeRTOS/Demo/Common/Minimal/countsem.c
@@ -39,24 +39,24 @@
#include "countsem.h"
/* The maximum count value that the semaphore used for the demo can hold. */
-#define countMAX_COUNT_VALUE ( 200 )
+#define countMAX_COUNT_VALUE ( 200 )
/* Constants used to indicate whether or not the semaphore should have been
-created with its maximum count value, or its minimum count value. These
-numbers are used to ensure that the pointers passed in as the task parameters
-are valid. */
-#define countSTART_AT_MAX_COUNT ( 0xaa )
-#define countSTART_AT_ZERO ( 0x55 )
+ * created with its maximum count value, or its minimum count value. These
+ * numbers are used to ensure that the pointers passed in as the task parameters
+ * are valid. */
+#define countSTART_AT_MAX_COUNT ( 0xaa )
+#define countSTART_AT_ZERO ( 0x55 )
/* Two tasks are created for the test. One uses a semaphore created with its
-count value set to the maximum, and one with the count value set to zero. */
-#define countNUM_TEST_TASKS ( 2 )
-#define countDONT_BLOCK ( 0 )
+ * count value set to the maximum, and one with the count value set to zero. */
+#define countNUM_TEST_TASKS ( 2 )
+#define countDONT_BLOCK ( 0 )
/*-----------------------------------------------------------*/
/* Flag that will be latched to pdTRUE should any unexpected behaviour be
-detected in any of the tasks. */
+ * detected in any of the tasks. */
static volatile BaseType_t xErrorDetected = pdFALSE;
/*-----------------------------------------------------------*/
@@ -67,36 +67,38 @@ static volatile BaseType_t xErrorDetected = pdFALSE;
* 'take' is inspected, with an error being flagged if it is found not to be
* the expected result.
*/
-static void prvCountingSemaphoreTask( void *pvParameters );
+static void prvCountingSemaphoreTask( void * pvParameters );
/*
* Utility function to increment the semaphore count value up from zero to
* countMAX_COUNT_VALUE.
*/
-static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter );
+static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
+ volatile UBaseType_t * puxLoopCounter );
/*
* Utility function to decrement the semaphore count value up from
* countMAX_COUNT_VALUE to zero.
*/
-static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter );
+static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
+ volatile UBaseType_t * puxLoopCounter );
/*-----------------------------------------------------------*/
/* The structure that is passed into the task as the task parameter. */
typedef struct COUNT_SEM_STRUCT
{
- /* The semaphore to be used for the demo. */
- SemaphoreHandle_t xSemaphore;
+ /* The semaphore to be used for the demo. */
+ SemaphoreHandle_t xSemaphore;
- /* Set to countSTART_AT_MAX_COUNT if the semaphore should be created with
- its count value set to its max count value, or countSTART_AT_ZERO if it
- should have been created with its count value set to 0. */
- UBaseType_t uxExpectedStartCount;
+ /* Set to countSTART_AT_MAX_COUNT if the semaphore should be created with
+ * its count value set to its max count value, or countSTART_AT_ZERO if it
+ * should have been created with its count value set to 0. */
+ UBaseType_t uxExpectedStartCount;
- /* Incremented on each cycle of the demo task. Used to detect a stalled
- task. */
- volatile UBaseType_t uxLoopCounter;
+ /* Incremented on each cycle of the demo task. Used to detect a stalled
+ * task. */
+ volatile UBaseType_t uxLoopCounter;
} xCountSemStruct;
/* Two structures are defined, one is passed to each test task. */
@@ -106,183 +108,184 @@ static xCountSemStruct xParameters[ countNUM_TEST_TASKS ];
void vStartCountingSemaphoreTasks( void )
{
- /* Create the semaphores that we are going to use for the test/demo. The
- first should be created such that it starts at its maximum count value,
- the second should be created such that it starts with a count value of zero. */
- xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE );
- xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT;
- xParameters[ 0 ].uxLoopCounter = 0;
-
- xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );
- xParameters[ 1 ].uxExpectedStartCount = 0;
- xParameters[ 1 ].uxLoopCounter = 0;
-
- /* Were the semaphores created? */
- if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) )
- {
- /* vQueueAddToRegistry() adds the semaphore to the registry, if one is
- in use. The registry is provided as a means for kernel aware
- debuggers to locate semaphores and has no purpose if a kernel aware
- debugger is not being used. The call to vQueueAddToRegistry() will be
- removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
- defined or is defined to be less than 1. */
- vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" );
- vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" );
-
- /* Create the demo tasks, passing in the semaphore to use as the parameter. */
- xTaskCreate( prvCountingSemaphoreTask, "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL );
- xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL );
- }
+ /* Create the semaphores that we are going to use for the test/demo. The
+ * first should be created such that it starts at its maximum count value,
+ * the second should be created such that it starts with a count value of zero. */
+ xParameters[ 0 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, countMAX_COUNT_VALUE );
+ xParameters[ 0 ].uxExpectedStartCount = countSTART_AT_MAX_COUNT;
+ xParameters[ 0 ].uxLoopCounter = 0;
+
+ xParameters[ 1 ].xSemaphore = xSemaphoreCreateCounting( countMAX_COUNT_VALUE, 0 );
+ xParameters[ 1 ].uxExpectedStartCount = 0;
+ xParameters[ 1 ].uxLoopCounter = 0;
+
+ /* Were the semaphores created? */
+ if( ( xParameters[ 0 ].xSemaphore != NULL ) || ( xParameters[ 1 ].xSemaphore != NULL ) )
+ {
+ /* vQueueAddToRegistry() adds the semaphore to the registry, if one is
+ * in use. The registry is provided as a means for kernel aware
+ * debuggers to locate semaphores and has no purpose if a kernel aware
+ * debugger is not being used. The call to vQueueAddToRegistry() will be
+ * removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
+ * defined or is defined to be less than 1. */
+ vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 0 ].xSemaphore, "Counting_Sem_1" );
+ vQueueAddToRegistry( ( QueueHandle_t ) xParameters[ 1 ].xSemaphore, "Counting_Sem_2" );
+
+ /* Create the demo tasks, passing in the semaphore to use as the parameter. */
+ xTaskCreate( prvCountingSemaphoreTask, "CNT1", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 0 ] ), tskIDLE_PRIORITY, NULL );
+ xTaskCreate( prvCountingSemaphoreTask, "CNT2", configMINIMAL_STACK_SIZE, ( void * ) &( xParameters[ 1 ] ), tskIDLE_PRIORITY, NULL );
+ }
}
/*-----------------------------------------------------------*/
-static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter )
+static void prvDecrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
+ volatile UBaseType_t * puxLoopCounter )
{
-UBaseType_t ux;
-
- /* If the semaphore count is at its maximum then we should not be able to
- 'give' the semaphore. */
- if( xSemaphoreGive( xSemaphore ) == pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */
- for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
- {
- configASSERT( uxSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) );
-
- if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS )
- {
- /* We expected to be able to take the semaphore. */
- xErrorDetected = pdTRUE;
- }
-
- ( *puxLoopCounter )++;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* If the semaphore count is zero then we should not be able to 'take'
- the semaphore. */
- configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
- if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
+ UBaseType_t ux;
+
+ /* If the semaphore count is at its maximum then we should not be able to
+ * 'give' the semaphore. */
+ if( xSemaphoreGive( xSemaphore ) == pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */
+ for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
+ {
+ configASSERT( uxSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) );
+
+ if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS )
+ {
+ /* We expected to be able to take the semaphore. */
+ xErrorDetected = pdTRUE;
+ }
+
+ ( *puxLoopCounter )++;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* If the semaphore count is zero then we should not be able to 'take'
+ * the semaphore. */
+ configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );
+
+ if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
}
/*-----------------------------------------------------------*/
-static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore, volatile UBaseType_t *puxLoopCounter )
+static void prvIncrementSemaphoreCount( SemaphoreHandle_t xSemaphore,
+ volatile UBaseType_t * puxLoopCounter )
{
-UBaseType_t ux;
-
- /* If the semaphore count is zero then we should not be able to 'take'
- the semaphore. */
- if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- /* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */
- for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
- {
- configASSERT( uxSemaphoreGetCount( xSemaphore ) == ux );
-
- if( xSemaphoreGive( xSemaphore ) != pdPASS )
- {
- /* We expected to be able to take the semaphore. */
- xErrorDetected = pdTRUE;
- }
-
- ( *puxLoopCounter )++;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* If the semaphore count is at its maximum then we should not be able to
- 'give' the semaphore. */
- if( xSemaphoreGive( xSemaphore ) == pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
+ UBaseType_t ux;
+
+ /* If the semaphore count is zero then we should not be able to 'take'
+ * the semaphore. */
+ if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ /* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */
+ for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
+ {
+ configASSERT( uxSemaphoreGetCount( xSemaphore ) == ux );
+
+ if( xSemaphoreGive( xSemaphore ) != pdPASS )
+ {
+ /* We expected to be able to take the semaphore. */
+ xErrorDetected = pdTRUE;
+ }
+
+ ( *puxLoopCounter )++;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* If the semaphore count is at its maximum then we should not be able to
+ * 'give' the semaphore. */
+ if( xSemaphoreGive( xSemaphore ) == pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
}
/*-----------------------------------------------------------*/
-static void prvCountingSemaphoreTask( void *pvParameters )
+static void prvCountingSemaphoreTask( void * pvParameters )
{
-xCountSemStruct *pxParameter;
-
- #ifdef USE_STDIO
- void vPrintDisplayMessage( const char * const * ppcMessageToSend );
-
- const char * const pcTaskStartMsg = "Counting semaphore demo started.\r\n";
-
- /* Queue a message for printing to say the task has started. */
- vPrintDisplayMessage( &pcTaskStartMsg );
- #endif
-
- /* The semaphore to be used was passed as the parameter. */
- pxParameter = ( xCountSemStruct * ) pvParameters;
-
- /* Did we expect to find the semaphore already at its max count value, or
- at zero? */
- if( pxParameter->uxExpectedStartCount == countSTART_AT_MAX_COUNT )
- {
- prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
- }
-
- /* Now we expect the semaphore count to be 0, so this time there is an
- error if we can take the semaphore. */
- if( xSemaphoreTake( pxParameter->xSemaphore, 0 ) == pdPASS )
- {
- xErrorDetected = pdTRUE;
- }
-
- for( ;; )
- {
- prvIncrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
- prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
- }
+ xCountSemStruct * pxParameter;
+
+ #ifdef USE_STDIO
+ void vPrintDisplayMessage( const char * const * ppcMessageToSend );
+
+ const char * const pcTaskStartMsg = "Counting semaphore demo started.\r\n";
+
+ /* Queue a message for printing to say the task has started. */
+ vPrintDisplayMessage( &pcTaskStartMsg );
+ #endif
+
+ /* The semaphore to be used was passed as the parameter. */
+ pxParameter = ( xCountSemStruct * ) pvParameters;
+
+ /* Did we expect to find the semaphore already at its max count value, or
+ * at zero? */
+ if( pxParameter->uxExpectedStartCount == countSTART_AT_MAX_COUNT )
+ {
+ prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
+ }
+
+ /* Now we expect the semaphore count to be 0, so this time there is an
+ * error if we can take the semaphore. */
+ if( xSemaphoreTake( pxParameter->xSemaphore, 0 ) == pdPASS )
+ {
+ xErrorDetected = pdTRUE;
+ }
+
+ for( ; ; )
+ {
+ prvIncrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
+ prvDecrementSemaphoreCount( pxParameter->xSemaphore, &( pxParameter->uxLoopCounter ) );
+ }
}
/*-----------------------------------------------------------*/
BaseType_t xAreCountingSemaphoreTasksStillRunning( void )
{
-static UBaseType_t uxLastCount0 = 0, uxLastCount1 = 0;
-BaseType_t xReturn = pdPASS;
-
- /* Return fail if any 'give' or 'take' did not result in the expected
- behaviour. */
- if( xErrorDetected != pdFALSE )
- {
- xReturn = pdFAIL;
- }
-
- /* Return fail if either task is not still incrementing its loop counter. */
- if( uxLastCount0 == xParameters[ 0 ].uxLoopCounter )
- {
- xReturn = pdFAIL;
- }
- else
- {
- uxLastCount0 = xParameters[ 0 ].uxLoopCounter;
- }
-
- if( uxLastCount1 == xParameters[ 1 ].uxLoopCounter )
- {
- xReturn = pdFAIL;
- }
- else
- {
- uxLastCount1 = xParameters[ 1 ].uxLoopCounter;
- }
-
- return xReturn;
+ static UBaseType_t uxLastCount0 = 0, uxLastCount1 = 0;
+ BaseType_t xReturn = pdPASS;
+
+ /* Return fail if any 'give' or 'take' did not result in the expected
+ * behaviour. */
+ if( xErrorDetected != pdFALSE )
+ {
+ xReturn = pdFAIL;
+ }
+
+ /* Return fail if either task is not still incrementing its loop counter. */
+ if( uxLastCount0 == xParameters[ 0 ].uxLoopCounter )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ uxLastCount0 = xParameters[ 0 ].uxLoopCounter;
+ }
+
+ if( uxLastCount1 == xParameters[ 1 ].uxLoopCounter )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ uxLastCount1 = xParameters[ 1 ].uxLoopCounter;
+ }
+
+ return xReturn;
}
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/crflash.c b/FreeRTOS/Demo/Common/Minimal/crflash.c
index d3da4b235..8619db793 100644
--- a/FreeRTOS/Demo/Common/Minimal/crflash.c
+++ b/FreeRTOS/Demo/Common/Minimal/crflash.c
@@ -61,34 +61,36 @@
#include "crflash.h"
/* The queue should only need to be of length 1. See the description at the
-top of the file. */
-#define crfQUEUE_LENGTH 1
+ * top of the file. */
+#define crfQUEUE_LENGTH 1
-#define crfFIXED_DELAY_PRIORITY 0
-#define crfFLASH_PRIORITY 1
+#define crfFIXED_DELAY_PRIORITY 0
+#define crfFLASH_PRIORITY 1
/* Only one flash co-routine is created so the index is not significant. */
-#define crfFLASH_INDEX 0
+#define crfFLASH_INDEX 0
/* Don't allow more than crfMAX_FLASH_TASKS 'fixed delay' co-routines to be
-created. */
-#define crfMAX_FLASH_TASKS 8
+ * created. */
+#define crfMAX_FLASH_TASKS 8
/* We don't want to block when posting to the queue. */
-#define crfPOSTING_BLOCK_TIME 0
+#define crfPOSTING_BLOCK_TIME 0
/*
* The 'fixed delay' co-routine as described at the top of the file.
*/
-static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex );
+static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle,
+ UBaseType_t uxIndex );
/*
* The 'flash' co-routine as described at the top of the file.
*/
-static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex );
+static void prvFlashCoRoutine( CoRoutineHandle_t xHandle,
+ UBaseType_t uxIndex );
/* The queue used to pass data between the 'fixed delay' co-routines and the
-'flash' co-routine. */
+ * 'flash' co-routine. */
static QueueHandle_t xFlashQueue;
/* This will be set to pdFALSE if we detect an error. */
@@ -101,108 +103,113 @@ static BaseType_t xCoRoutineFlashStatus = pdPASS;
*/
void vStartFlashCoRoutines( UBaseType_t uxNumberToCreate )
{
-UBaseType_t uxIndex;
-
- if( uxNumberToCreate > crfMAX_FLASH_TASKS )
- {
- uxNumberToCreate = crfMAX_FLASH_TASKS;
- }
-
- /* Create the queue used to pass data between the co-routines. */
- xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( UBaseType_t ) );
-
- if( xFlashQueue )
- {
- /* Create uxNumberToCreate 'fixed delay' co-routines. */
- for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )
- {
- xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );
- }
-
- /* Create the 'flash' co-routine. */
- xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );
- }
+ UBaseType_t uxIndex;
+
+ if( uxNumberToCreate > crfMAX_FLASH_TASKS )
+ {
+ uxNumberToCreate = crfMAX_FLASH_TASKS;
+ }
+
+ /* Create the queue used to pass data between the co-routines. */
+ xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( UBaseType_t ) );
+
+ if( xFlashQueue )
+ {
+ /* Create uxNumberToCreate 'fixed delay' co-routines. */
+ for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )
+ {
+ xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );
+ }
+
+ /* Create the 'flash' co-routine. */
+ xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );
+ }
}
/*-----------------------------------------------------------*/
-static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle,
+ UBaseType_t uxIndex )
{
/* Even though this is a co-routine the xResult variable does not need to be
-static as we do not need it to maintain its state between blocks. */
-BaseType_t xResult;
+ * static as we do not need it to maintain its state between blocks. */
+ BaseType_t xResult;
+
/* The uxIndex parameter of the co-routine function is used as an index into
-the xFlashRates array to obtain the delay period to use. */
-static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_PERIOD_MS,
- 200 / portTICK_PERIOD_MS,
- 250 / portTICK_PERIOD_MS,
- 300 / portTICK_PERIOD_MS,
- 350 / portTICK_PERIOD_MS,
- 400 / portTICK_PERIOD_MS,
- 450 / portTICK_PERIOD_MS,
- 500 / portTICK_PERIOD_MS };
-
- /* Co-routines MUST start with a call to crSTART. */
- crSTART( xHandle );
-
- for( ;; )
- {
- /* Post our uxIndex value onto the queue. This is used as the LED to
- flash. */
- crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );
-
- if( xResult != pdPASS )
- {
- /* For the reasons stated at the top of the file we should always
- find that we can post to the queue. If we could not then an error
- has occurred. */
- xCoRoutineFlashStatus = pdFAIL;
- }
-
- crDELAY( xHandle, xFlashRates[ uxIndex ] );
- }
-
- /* Co-routines MUST end with a call to crEND. */
- crEND();
+ * the xFlashRates array to obtain the delay period to use. */
+ static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] =
+ {
+ 150 / portTICK_PERIOD_MS,
+ 200 / portTICK_PERIOD_MS,
+ 250 / portTICK_PERIOD_MS,
+ 300 / portTICK_PERIOD_MS,
+ 350 / portTICK_PERIOD_MS,
+ 400 / portTICK_PERIOD_MS,
+ 450 / portTICK_PERIOD_MS,
+ 500 / portTICK_PERIOD_MS
+ };
+
+ /* Co-routines MUST start with a call to crSTART. */
+ crSTART( xHandle );
+
+ for( ; ; )
+ {
+ /* Post our uxIndex value onto the queue. This is used as the LED to
+ * flash. */
+ crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );
+
+ if( xResult != pdPASS )
+ {
+ /* For the reasons stated at the top of the file we should always
+ * find that we can post to the queue. If we could not then an error
+ * has occurred. */
+ xCoRoutineFlashStatus = pdFAIL;
+ }
+
+ crDELAY( xHandle, xFlashRates[ uxIndex ] );
+ }
+
+ /* Co-routines MUST end with a call to crEND. */
+ crEND();
}
/*-----------------------------------------------------------*/
-static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+static void prvFlashCoRoutine( CoRoutineHandle_t xHandle,
+ UBaseType_t uxIndex )
{
/* Even though this is a co-routine the variable do not need to be
-static as we do not need it to maintain their state between blocks. */
-BaseType_t xResult;
-UBaseType_t uxLEDToFlash;
-
- /* Co-routines MUST start with a call to crSTART. */
- crSTART( xHandle );
- ( void ) uxIndex;
-
- for( ;; )
- {
- /* Block to wait for the number of the LED to flash. */
- crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
-
- if( xResult != pdPASS )
- {
- /* We would not expect to wake unless we received something. */
- xCoRoutineFlashStatus = pdFAIL;
- }
- else
- {
- /* We received the number of an LED to flash - flash it! */
- vParTestToggleLED( uxLEDToFlash );
- }
- }
-
- /* Co-routines MUST end with a call to crEND. */
- crEND();
+ * static as we do not need it to maintain their state between blocks. */
+ BaseType_t xResult;
+ UBaseType_t uxLEDToFlash;
+
+ /* Co-routines MUST start with a call to crSTART. */
+ crSTART( xHandle );
+ ( void ) uxIndex;
+
+ for( ; ; )
+ {
+ /* Block to wait for the number of the LED to flash. */
+ crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
+
+ if( xResult != pdPASS )
+ {
+ /* We would not expect to wake unless we received something. */
+ xCoRoutineFlashStatus = pdFAIL;
+ }
+ else
+ {
+ /* We received the number of an LED to flash - flash it! */
+ vParTestToggleLED( uxLEDToFlash );
+ }
+ }
+
+ /* Co-routines MUST end with a call to crEND. */
+ crEND();
}
/*-----------------------------------------------------------*/
BaseType_t xAreFlashCoRoutinesStillRunning( void )
{
- /* Return pdPASS or pdFAIL depending on whether an error has been detected
- or not. */
- return xCoRoutineFlashStatus;
+ /* Return pdPASS or pdFAIL depending on whether an error has been detected
+ * or not. */
+ return xCoRoutineFlashStatus;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/crhook.c b/FreeRTOS/Demo/Common/Minimal/crhook.c
index 5670930bc..f32bee267 100644
--- a/FreeRTOS/Demo/Common/Minimal/crhook.c
+++ b/FreeRTOS/Demo/Common/Minimal/crhook.c
@@ -57,27 +57,28 @@
#include "crhook.h"
/* The number of 'hook' co-routines that are to be created. */
-#define hookNUM_HOOK_CO_ROUTINES ( 4 )
+#define hookNUM_HOOK_CO_ROUTINES ( 4 )
/* The number of times the tick hook should be called before a character is
-posted to the 'hook' co-routines. */
-#define hookTICK_CALLS_BEFORE_POST ( 500 )
+ * posted to the 'hook' co-routines. */
+#define hookTICK_CALLS_BEFORE_POST ( 500 )
/* There should never be more than one item in any queue at any time. */
-#define hookHOOK_QUEUE_LENGTH ( 1 )
+#define hookHOOK_QUEUE_LENGTH ( 1 )
/* Don't block when initially posting to the queue. */
-#define hookNO_BLOCK_TIME ( 0 )
+#define hookNO_BLOCK_TIME ( 0 )
/* The priority relative to other co-routines (rather than tasks) that the
-'hook' co-routines should take. */
-#define mainHOOK_CR_PRIORITY ( 1 )
+ * 'hook' co-routines should take. */
+#define mainHOOK_CR_PRIORITY ( 1 )
/*-----------------------------------------------------------*/
/*
* The co-routine function itself.
*/
-static void prvHookCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex );
+static void prvHookCoRoutine( CoRoutineHandle_t xHandle,
+ UBaseType_t uxIndex );
/*
@@ -90,13 +91,13 @@ void vApplicationTickHook( void );
/*-----------------------------------------------------------*/
/* Queues used to send data FROM a co-routine TO the tick hook function.
-The hook functions received (Rx's) on these queues. One queue per
-'hook' co-routine. */
+ * The hook functions received (Rx's) on these queues. One queue per
+ * 'hook' co-routine. */
static QueueHandle_t xHookRxQueues[ hookNUM_HOOK_CO_ROUTINES ];
/* Queues used to send data FROM the tick hook TO a co-routine function.
-The hood function transmits (Tx's) on these queues. One queue per
-'hook' co-routine. */
+ * The hood function transmits (Tx's) on these queues. One queue per
+ * 'hook' co-routine. */
static QueueHandle_t xHookTxQueues[ hookNUM_HOOK_CO_ROUTINES ];
/* Set to true if an error is detected at any time. */
@@ -106,127 +107,128 @@ static BaseType_t xCoRoutineErrorDetected = pdFALSE;
void vStartHookCoRoutines( void )
{
-UBaseType_t uxIndex, uxValueToPost = 0;
-
- for( uxIndex = 0; uxIndex < hookNUM_HOOK_CO_ROUTINES; uxIndex++ )
- {
- /* Create a queue to transmit to and receive from each 'hook'
- co-routine. */
- xHookRxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
- xHookTxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
-
- /* To start things off the tick hook function expects the queue it
- uses to receive data to contain a value. */
- xQueueSend( xHookRxQueues[ uxIndex ], &uxValueToPost, hookNO_BLOCK_TIME );
-
- /* Create the 'hook' co-routine itself. */
- xCoRoutineCreate( prvHookCoRoutine, mainHOOK_CR_PRIORITY, uxIndex );
- }
+ UBaseType_t uxIndex, uxValueToPost = 0;
+
+ for( uxIndex = 0; uxIndex < hookNUM_HOOK_CO_ROUTINES; uxIndex++ )
+ {
+ /* Create a queue to transmit to and receive from each 'hook'
+ * co-routine. */
+ xHookRxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
+ xHookTxQueues[ uxIndex ] = xQueueCreate( hookHOOK_QUEUE_LENGTH, sizeof( UBaseType_t ) );
+
+ /* To start things off the tick hook function expects the queue it
+ * uses to receive data to contain a value. */
+ xQueueSend( xHookRxQueues[ uxIndex ], &uxValueToPost, hookNO_BLOCK_TIME );
+
+ /* Create the 'hook' co-routine itself. */
+ xCoRoutineCreate( prvHookCoRoutine, mainHOOK_CR_PRIORITY, uxIndex );
+ }
}
/*-----------------------------------------------------------*/
static UBaseType_t uxCallCounter = 0, uxNumberToPost = 0;
void vApplicationTickHook( void )
{
-UBaseType_t uxReceivedNumber;
-BaseType_t xIndex, xCoRoutineWoken;
-
- /* Is it time to talk to the 'hook' co-routines again? */
- uxCallCounter++;
- if( uxCallCounter >= hookTICK_CALLS_BEFORE_POST )
- {
- uxCallCounter = 0;
-
- for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
- {
- xCoRoutineWoken = pdFALSE;
- if( crQUEUE_RECEIVE_FROM_ISR( xHookRxQueues[ xIndex ], &uxReceivedNumber, &xCoRoutineWoken ) != pdPASS )
- {
- /* There is no reason why we would not expect the queue to
- contain a value. */
- xCoRoutineErrorDetected = pdTRUE;
- }
- else
- {
- /* Each queue used to receive data from the 'hook' co-routines
- should contain the number we last posted to the same co-routine. */
- if( uxReceivedNumber != uxNumberToPost )
- {
- xCoRoutineErrorDetected = pdTRUE;
- }
-
- /* Nothing should be blocked waiting to post to the queue. */
- if( xCoRoutineWoken != pdFALSE )
- {
- xCoRoutineErrorDetected = pdTRUE;
- }
- }
- }
-
- /* Start the next cycle by posting the next number onto each Tx queue. */
- uxNumberToPost++;
-
- for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
- {
- if( crQUEUE_SEND_FROM_ISR( xHookTxQueues[ xIndex ], &uxNumberToPost, pdFALSE ) != pdTRUE )
- {
- /* Posting to the queue should have woken the co-routine that
- was blocked on the queue. */
- xCoRoutineErrorDetected = pdTRUE;
- }
- }
- }
+ UBaseType_t uxReceivedNumber;
+ BaseType_t xIndex, xCoRoutineWoken;
+
+ /* Is it time to talk to the 'hook' co-routines again? */
+ uxCallCounter++;
+
+ if( uxCallCounter >= hookTICK_CALLS_BEFORE_POST )
+ {
+ uxCallCounter = 0;
+
+ for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
+ {
+ xCoRoutineWoken = pdFALSE;
+
+ if( crQUEUE_RECEIVE_FROM_ISR( xHookRxQueues[ xIndex ], &uxReceivedNumber, &xCoRoutineWoken ) != pdPASS )
+ {
+ /* There is no reason why we would not expect the queue to
+ * contain a value. */
+ xCoRoutineErrorDetected = pdTRUE;
+ }
+ else
+ {
+ /* Each queue used to receive data from the 'hook' co-routines
+ * should contain the number we last posted to the same co-routine. */
+ if( uxReceivedNumber != uxNumberToPost )
+ {
+ xCoRoutineErrorDetected = pdTRUE;
+ }
+
+ /* Nothing should be blocked waiting to post to the queue. */
+ if( xCoRoutineWoken != pdFALSE )
+ {
+ xCoRoutineErrorDetected = pdTRUE;
+ }
+ }
+ }
+
+ /* Start the next cycle by posting the next number onto each Tx queue. */
+ uxNumberToPost++;
+
+ for( xIndex = 0; xIndex < hookNUM_HOOK_CO_ROUTINES; xIndex++ )
+ {
+ if( crQUEUE_SEND_FROM_ISR( xHookTxQueues[ xIndex ], &uxNumberToPost, pdFALSE ) != pdTRUE )
+ {
+ /* Posting to the queue should have woken the co-routine that
+ * was blocked on the queue. */
+ xCoRoutineErrorDetected = pdTRUE;
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
-static void prvHookCoRoutine( CoRoutineHandle_t xHandle, UBaseType_t uxIndex )
+static void prvHookCoRoutine( CoRoutineHandle_t xHandle,
+ UBaseType_t uxIndex )
{
-static UBaseType_t uxReceivedValue[ hookNUM_HOOK_CO_ROUTINES ];
-BaseType_t xResult;
-
- /* Each co-routine MUST start with a call to crSTART(); */
- crSTART( xHandle );
-
- for( ;; )
- {
- /* Wait to receive a value from the tick hook. */
- xResult = pdFAIL;
- crQUEUE_RECEIVE( xHandle, xHookTxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), portMAX_DELAY, &xResult );
-
- /* There is no reason why we should not have received something on
- the queue. */
- if( xResult != pdPASS )
- {
- xCoRoutineErrorDetected = pdTRUE;
- }
-
- /* Send the same number back to the idle hook so it can verify it. */
- xResult = pdFAIL;
- crQUEUE_SEND( xHandle, xHookRxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), hookNO_BLOCK_TIME, &xResult );
- if( xResult != pdPASS )
- {
- /* There is no reason why we should not have been able to post to
- the queue. */
- xCoRoutineErrorDetected = pdTRUE;
- }
- }
-
- /* Each co-routine MUST end with a call to crEND(). */
- crEND();
+ static UBaseType_t uxReceivedValue[ hookNUM_HOOK_CO_ROUTINES ];
+ BaseType_t xResult;
+
+ /* Each co-routine MUST start with a call to crSTART(); */
+ crSTART( xHandle );
+
+ for( ; ; )
+ {
+ /* Wait to receive a value from the tick hook. */
+ xResult = pdFAIL;
+ crQUEUE_RECEIVE( xHandle, xHookTxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), portMAX_DELAY, &xResult );
+
+ /* There is no reason why we should not have received something on
+ * the queue. */
+ if( xResult != pdPASS )
+ {
+ xCoRoutineErrorDetected = pdTRUE;
+ }
+
+ /* Send the same number back to the idle hook so it can verify it. */
+ xResult = pdFAIL;
+ crQUEUE_SEND( xHandle, xHookRxQueues[ uxIndex ], &( uxReceivedValue[ uxIndex ] ), hookNO_BLOCK_TIME, &xResult );
+
+ if( xResult != pdPASS )
+ {
+ /* There is no reason why we should not have been able to post to
+ * the queue. */
+ xCoRoutineErrorDetected = pdTRUE;
+ }
+ }
+
+ /* Each co-routine MUST end with a call to crEND(). */
+ crEND();
}
/*-----------------------------------------------------------*/
BaseType_t xAreHookCoRoutinesStillRunning( void )
{
- if( xCoRoutineErrorDetected )
- {
- return pdFALSE;
- }
- else
- {
- return pdTRUE;
- }
+ if( xCoRoutineErrorDetected )
+ {
+ return pdFALSE;
+ }
+ else
+ {
+ return pdTRUE;
+ }
}
-
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/death.c b/FreeRTOS/Demo/Common/Minimal/death.c
index 9f054714b..67113feb5 100644
--- a/FreeRTOS/Demo/Common/Minimal/death.c
+++ b/FreeRTOS/Demo/Common/Minimal/death.c
@@ -54,150 +54,148 @@
/* Demo program include files. */
#include "death.h"
-#define deathSTACK_SIZE ( configMINIMAL_STACK_SIZE + 60 )
+#define deathSTACK_SIZE ( configMINIMAL_STACK_SIZE + 60 )
/* The task originally created which is responsible for periodically dynamically
-creating another four tasks. */
+ * creating another four tasks. */
static portTASK_FUNCTION_PROTO( vCreateTasks, pvParameters );
/* The task function of the dynamically created tasks. */
static portTASK_FUNCTION_PROTO( vSuicidalTask, pvParameters );
/* A variable which is incremented every time the dynamic tasks are created. This
-is used to check that the task is still running. */
+ * is used to check that the task is still running. */
static volatile uint16_t usCreationCount = 0;
/* Used to store the number of tasks that were originally running so the creator
-task can tell if any of the suicidal tasks have failed to die.
-*/
+ * task can tell if any of the suicidal tasks have failed to die.
+ */
static volatile UBaseType_t uxTasksRunningAtStart = 0;
/* When a task deletes itself, it stack and TCB are cleaned up by the Idle task.
-Under heavy load the idle task might not get much processing time, so it would
-be legitimate for several tasks to remain undeleted for a short period. There
-may also be a few other unexpected tasks if, for example, the tasks that test
-static allocation are also being used. */
+ * Under heavy load the idle task might not get much processing time, so it would
+ * be legitimate for several tasks to remain undeleted for a short period. There
+ * may also be a few other unexpected tasks if, for example, the tasks that test
+ * static allocation are also being used. */
static const UBaseType_t uxMaxNumberOfExtraTasksRunning = 3;
/* Used to store a handle to the task that should be killed by a suicidal task,
-before it kills itself. */
+ * before it kills itself. */
TaskHandle_t xCreatedTask;
/*-----------------------------------------------------------*/
void vCreateSuicidalTasks( UBaseType_t uxPriority )
{
- xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) NULL, uxPriority, NULL );
+ xTaskCreate( vCreateTasks, "CREATOR", deathSTACK_SIZE, ( void * ) NULL, uxPriority, NULL );
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vSuicidalTask, pvParameters )
{
-volatile long l1, l2;
-TaskHandle_t xTaskToKill;
-const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 200 );
-
- /* Test deletion of a task's secure context, if any. */
- portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
-
- if( pvParameters != NULL )
- {
- /* This task is periodically created four times. Two created tasks are
- passed a handle to the other task so it can kill it before killing itself.
- The other task is passed in null. */
- xTaskToKill = *( TaskHandle_t* )pvParameters;
- }
- else
- {
- xTaskToKill = NULL;
- }
-
- for( ;; )
- {
- /* Do something random just to use some stack and registers. */
- l1 = 2;
- l2 = 89;
- l2 *= l1;
- vTaskDelay( xDelay );
-
- if( xTaskToKill != NULL )
- {
- /* Make sure the other task has a go before we delete it. */
- vTaskDelay( ( TickType_t ) 0 );
-
- /* Kill the other task that was created by vCreateTasks(). */
- vTaskDelete( xTaskToKill );
-
- /* Kill ourselves. */
- vTaskDelete( NULL );
- }
- }
-}/*lint !e818 !e550 Function prototype must be as per standard for task functions. */
+ volatile long l1, l2;
+ TaskHandle_t xTaskToKill;
+ const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 200 );
+
+ /* Test deletion of a task's secure context, if any. */
+ portALLOCATE_SECURE_CONTEXT( configMINIMAL_SECURE_STACK_SIZE );
+
+ if( pvParameters != NULL )
+ {
+ /* This task is periodically created four times. Two created tasks are
+ * passed a handle to the other task so it can kill it before killing itself.
+ * The other task is passed in null. */
+ xTaskToKill = *( TaskHandle_t * ) pvParameters;
+ }
+ else
+ {
+ xTaskToKill = NULL;
+ }
+
+ for( ; ; )
+ {
+ /* Do something random just to use some stack and registers. */
+ l1 = 2;
+ l2 = 89;
+ l2 *= l1;
+ vTaskDelay( xDelay );
+
+ if( xTaskToKill != NULL )
+ {
+ /* Make sure the other task has a go before we delete it. */
+ vTaskDelay( ( TickType_t ) 0 );
+
+ /* Kill the other task that was created by vCreateTasks(). */
+ vTaskDelete( xTaskToKill );
+
+ /* Kill ourselves. */
+ vTaskDelete( NULL );
+ }
+ }
+} /*lint !e818 !e550 Function prototype must be as per standard for task functions. */
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCreateTasks, pvParameters )
{
-const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 1000 );
-UBaseType_t uxPriority;
+ const TickType_t xDelay = pdMS_TO_TICKS( ( TickType_t ) 1000 );
+ UBaseType_t uxPriority;
- /* Remove compiler warning about unused parameter. */
- ( void ) pvParameters;
+ /* Remove compiler warning about unused parameter. */
+ ( void ) pvParameters;
- /* Delay at the start to ensure tasks created by other demos have been
- created before storing the current number of tasks. */
- vTaskDelay( xDelay );
- uxTasksRunningAtStart = ( UBaseType_t ) uxTaskGetNumberOfTasks();
+ /* Delay at the start to ensure tasks created by other demos have been
+ * created before storing the current number of tasks. */
+ vTaskDelay( xDelay );
+ uxTasksRunningAtStart = ( UBaseType_t ) uxTaskGetNumberOfTasks();
- uxPriority = uxTaskPriorityGet( NULL );
+ uxPriority = uxTaskPriorityGet( NULL );
- for( ;; )
- {
- /* Just loop round, delaying then creating the four suicidal tasks. */
- vTaskDelay( xDelay );
+ for( ; ; )
+ {
+ /* Just loop round, delaying then creating the four suicidal tasks. */
+ vTaskDelay( xDelay );
- xCreatedTask = NULL;
+ xCreatedTask = NULL;
- xTaskCreate( vSuicidalTask, "SUICID1", configMINIMAL_STACK_SIZE, NULL, uxPriority, &xCreatedTask );
- xTaskCreate( vSuicidalTask, "SUICID2", configMINIMAL_STACK_SIZE, &xCreatedTask, uxPriority, NULL );
+ xTaskCreate( vSuicidalTask, "SUICID1", configMINIMAL_STACK_SIZE, NULL, uxPriority, &xCreatedTask );
+ xTaskCreate( vSuicidalTask, "SUICID2", configMINIMAL_STACK_SIZE, &xCreatedTask, uxPriority, NULL );
- ++usCreationCount;
- }
+ ++usCreationCount;
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that the creator task is still running and that there
-are not any more than four extra tasks. */
+ * are not any more than four extra tasks. */
BaseType_t xIsCreateTaskStillRunning( void )
{
-static uint16_t usLastCreationCount = 0xfff;
-BaseType_t xReturn = pdTRUE;
-static UBaseType_t uxTasksRunningNow;
-
- if( usLastCreationCount == usCreationCount )
- {
- xReturn = pdFALSE;
- }
- else
- {
- usLastCreationCount = usCreationCount;
- }
-
- uxTasksRunningNow = ( UBaseType_t ) uxTaskGetNumberOfTasks();
-
- if( uxTasksRunningNow < uxTasksRunningAtStart )
- {
- xReturn = pdFALSE;
- }
- else if( ( uxTasksRunningNow - uxTasksRunningAtStart ) > uxMaxNumberOfExtraTasksRunning )
- {
- xReturn = pdFALSE;
- }
- else
- {
- /* Everything is okay. */
- }
-
- return xReturn;
+ static uint16_t usLastCreationCount = 0xfff;
+ BaseType_t xReturn = pdTRUE;
+ static UBaseType_t uxTasksRunningNow;
+
+ if( usLastCreationCount == usCreationCount )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ usLastCreationCount = usCreationCount;
+ }
+
+ uxTasksRunningNow = ( UBaseType_t ) uxTaskGetNumberOfTasks();
+
+ if( uxTasksRunningNow < uxTasksRunningAtStart )
+ {
+ xReturn = pdFALSE;
+ }
+ else if( ( uxTasksRunningNow - uxTasksRunningAtStart ) > uxMaxNumberOfExtraTasksRunning )
+ {
+ xReturn = pdFALSE;
+ }
+ else
+ {
+ /* Everything is okay. */
+ }
+
+ return xReturn;
}
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/dynamic.c b/FreeRTOS/Demo/Common/Minimal/dynamic.c
index c270b1edf..a6da72fc6 100644
--- a/FreeRTOS/Demo/Common/Minimal/dynamic.c
+++ b/FreeRTOS/Demo/Common/Minimal/dynamic.c
@@ -106,29 +106,29 @@ static portTASK_FUNCTION_PROTO( vQueueSendWhenSuspendedTask, pvParameters );
/* Demo task specific constants. */
#ifndef priSUSPENDED_RX_TASK_STACK_SIZE
- #define priSUSPENDED_RX_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
+ #define priSUSPENDED_RX_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
#endif
-#define priSTACK_SIZE ( configMINIMAL_STACK_SIZE )
-#define priSLEEP_TIME pdMS_TO_TICKS( 128 )
-#define priLOOPS ( 5 )
-#define priMAX_COUNT ( ( uint32_t ) 0xff )
-#define priNO_BLOCK ( ( TickType_t ) 0 )
-#define priSUSPENDED_QUEUE_LENGTH ( 1 )
+#define priSTACK_SIZE ( configMINIMAL_STACK_SIZE )
+#define priSLEEP_TIME pdMS_TO_TICKS( 128 )
+#define priLOOPS ( 5 )
+#define priMAX_COUNT ( ( uint32_t ) 0xff )
+#define priNO_BLOCK ( ( TickType_t ) 0 )
+#define priSUSPENDED_QUEUE_LENGTH ( 1 )
/*-----------------------------------------------------------*/
/* Handles to the two counter tasks. These could be passed in as parameters
-to the controller task to prevent them having to be file scope. */
+ * to the controller task to prevent them having to be file scope. */
static TaskHandle_t xContinuousIncrementHandle, xLimitedIncrementHandle;
/* The shared counter variable. This is passed in as a parameter to the two
-counter variables for demonstration purposes. */
+ * counter variables for demonstration purposes. */
static uint32_t ulCounter;
/* Variables used to check that the tasks are still operating without error.
-Each complete iteration of the controller task increments this variable
-provided no errors have been found. The variable maintaining the same value
-is therefore indication of an error. */
+ * Each complete iteration of the controller task increments this variable
+ * provided no errors have been found. The variable maintaining the same value
+ * is therefore indication of an error. */
static volatile uint16_t usCheckVariable = ( uint16_t ) 0;
static volatile BaseType_t xSuspendedQueueSendError = pdFALSE;
static volatile BaseType_t xSuspendedQueueReceiveError = pdFALSE;
@@ -137,35 +137,36 @@ static volatile BaseType_t xSuspendedQueueReceiveError = pdFALSE;
QueueHandle_t xSuspendedTestQueue;
/* The value the queue receive task expects to receive next. This is file
-scope so xAreDynamicPriorityTasksStillRunning() can ensure it is still
-incrementing. */
+ * scope so xAreDynamicPriorityTasksStillRunning() can ensure it is still
+ * incrementing. */
static uint32_t ulExpectedValue = ( uint32_t ) 0;
/*-----------------------------------------------------------*/
+
/*
* Start the three tasks as described at the top of the file.
* Note that the limited count task is given a higher priority.
*/
void vStartDynamicPriorityTasks( void )
{
- xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( uint32_t ) );
-
- if( xSuspendedTestQueue != NULL )
- {
- /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
- in use. The queue registry is provided as a means for kernel aware
- debuggers to locate queues and has no purpose if a kernel aware debugger
- is not being used. The call to vQueueAddToRegistry() will be removed
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
- defined to be less than 1. */
- vQueueAddToRegistry( xSuspendedTestQueue, "Suspended_Test_Queue" );
-
- xTaskCreate( vContinuousIncrementTask, "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
- xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
- xTaskCreate( vCounterControlTask, "C_CTRL", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RX", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
- }
+ xSuspendedTestQueue = xQueueCreate( priSUSPENDED_QUEUE_LENGTH, sizeof( uint32_t ) );
+
+ if( xSuspendedTestQueue != NULL )
+ {
+ /* vQueueAddToRegistry() adds the queue to the queue registry, if one is
+ * in use. The queue registry is provided as a means for kernel aware
+ * debuggers to locate queues and has no purpose if a kernel aware debugger
+ * is not being used. The call to vQueueAddToRegistry() will be removed
+ * by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
+ * defined to be less than 1. */
+ vQueueAddToRegistry( xSuspendedTestQueue, "Suspended_Test_Queue" );
+
+ xTaskCreate( vContinuousIncrementTask, "CNT_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY, &xContinuousIncrementHandle );
+ xTaskCreate( vLimitedIncrementTask, "LIM_INC", priSTACK_SIZE, ( void * ) &ulCounter, tskIDLE_PRIORITY + 1, &xLimitedIncrementHandle );
+ xTaskCreate( vCounterControlTask, "C_CTRL", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vQueueSendWhenSuspendedTask, "SUSP_TX", priSTACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ xTaskCreate( vQueueReceiveWhenSuspendedTask, "SUSP_RX", priSUSPENDED_RX_TASK_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
+ }
}
/*-----------------------------------------------------------*/
@@ -175,26 +176,26 @@ void vStartDynamicPriorityTasks( void )
*/
static portTASK_FUNCTION( vLimitedIncrementTask, pvParameters )
{
-volatile uint32_t *pulCounter;
-
- /* Take a pointer to the shared variable from the parameters passed into
- the task. */
- pulCounter = ( volatile uint32_t * ) pvParameters;
-
- /* This will run before the control task, so the first thing it does is
- suspend - the control task will resume it when ready. */
- vTaskSuspend( NULL );
-
- for( ;; )
- {
- /* Just count up to a value then suspend. */
- ( *pulCounter )++;
-
- if( *pulCounter >= priMAX_COUNT )
- {
- vTaskSuspend( NULL );
- }
- }
+ volatile uint32_t * pulCounter;
+
+ /* Take a pointer to the shared variable from the parameters passed into
+ * the task. */
+ pulCounter = ( volatile uint32_t * ) pvParameters;
+
+ /* This will run before the control task, so the first thing it does is
+ * suspend - the control task will resume it when ready. */
+ vTaskSuspend( NULL );
+
+ for( ; ; )
+ {
+ /* Just count up to a value then suspend. */
+ ( *pulCounter )++;
+
+ if( *pulCounter >= priMAX_COUNT )
+ {
+ vTaskSuspend( NULL );
+ }
+ }
}
/*-----------------------------------------------------------*/
@@ -204,34 +205,34 @@ volatile uint32_t *pulCounter;
*/
static portTASK_FUNCTION( vContinuousIncrementTask, pvParameters )
{
-volatile uint32_t *pulCounter;
-UBaseType_t uxOurPriority;
-
- /* Take a pointer to the shared variable from the parameters passed into
- the task. */
- pulCounter = ( volatile uint32_t * ) pvParameters;
-
- /* Query our priority so we can raise it when exclusive access to the
- shared variable is required. */
- uxOurPriority = uxTaskPriorityGet( NULL );
-
- for( ;; )
- {
- /* Raise the priority above the controller task to ensure a context
- switch does not occur while the variable is being accessed. */
- vTaskPrioritySet( NULL, uxOurPriority + 1 );
- {
- configASSERT( ( uxTaskPriorityGet( NULL ) == ( uxOurPriority + 1 ) ) );
- ( *pulCounter )++;
- }
- vTaskPrioritySet( NULL, uxOurPriority );
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
-
- configASSERT( ( uxTaskPriorityGet( NULL ) == uxOurPriority ) );
- }
+ volatile uint32_t * pulCounter;
+ UBaseType_t uxOurPriority;
+
+ /* Take a pointer to the shared variable from the parameters passed into
+ * the task. */
+ pulCounter = ( volatile uint32_t * ) pvParameters;
+
+ /* Query our priority so we can raise it when exclusive access to the
+ * shared variable is required. */
+ uxOurPriority = uxTaskPriorityGet( NULL );
+
+ for( ; ; )
+ {
+ /* Raise the priority above the controller task to ensure a context
+ * switch does not occur while the variable is being accessed. */
+ vTaskPrioritySet( NULL, uxOurPriority + 1 );
+ {
+ configASSERT( ( uxTaskPriorityGet( NULL ) == ( uxOurPriority + 1 ) ) );
+ ( *pulCounter )++;
+ }
+ vTaskPrioritySet( NULL, uxOurPriority );
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+
+ configASSERT( ( uxTaskPriorityGet( NULL ) == uxOurPriority ) );
+ }
}
/*-----------------------------------------------------------*/
@@ -240,200 +241,200 @@ UBaseType_t uxOurPriority;
*/
static portTASK_FUNCTION( vCounterControlTask, pvParameters )
{
-uint32_t ulLastCounter;
-short sLoops;
-short sError = pdFALSE;
-
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Start with the counter at zero. */
- ulCounter = ( uint32_t ) 0;
-
- /* First section : */
-
- /* Check the continuous count task is running. */
- for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
- {
- /* Suspend the continuous count task so we can take a mirror of the
- shared variable without risk of corruption. This is not really
- needed as the other task raises its priority above this task's
- priority. */
- vTaskSuspend( xContinuousIncrementHandle );
- {
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eSuspended );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- ulLastCounter = ulCounter;
- }
- vTaskResume( xContinuousIncrementHandle );
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
-
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eReady );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* Now delay to ensure the other task has processor time. */
- vTaskDelay( priSLEEP_TIME );
-
- /* Check the shared variable again. This time to ensure mutual
- exclusion the whole scheduler will be locked. This is just for
- demo purposes! */
- vTaskSuspendAll();
- {
- if( ulLastCounter == ulCounter )
- {
- /* The shared variable has not changed. There is a problem
- with the continuous count task so flag an error. */
- sError = pdTRUE;
- }
- }
- xTaskResumeAll();
- }
-
- /* Second section: */
-
- /* Suspend the continuous counter task so it stops accessing the shared
- variable. */
- vTaskSuspend( xContinuousIncrementHandle );
-
- /* Reset the variable. */
- ulCounter = ( uint32_t ) 0;
-
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* Resume the limited count task which has a higher priority than us.
- We should therefore not return from this call until the limited count
- task has suspended itself with a known value in the counter variable. */
- vTaskResume( xLimitedIncrementHandle );
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
-
- /* This task should not run again until xLimitedIncrementHandle has
- suspended itself. */
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* Does the counter variable have the expected value? */
- if( ulCounter != priMAX_COUNT )
- {
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If no errors have occurred then increment the check variable. */
- portENTER_CRITICAL();
- usCheckVariable++;
- portEXIT_CRITICAL();
- }
-
- /* Resume the continuous count task and do it all again. */
- vTaskResume( xContinuousIncrementHandle );
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
- }
+ uint32_t ulLastCounter;
+ short sLoops;
+ short sError = pdFALSE;
+
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Start with the counter at zero. */
+ ulCounter = ( uint32_t ) 0;
+
+ /* First section : */
+
+ /* Check the continuous count task is running. */
+ for( sLoops = 0; sLoops < priLOOPS; sLoops++ )
+ {
+ /* Suspend the continuous count task so we can take a mirror of the
+ * shared variable without risk of corruption. This is not really
+ * needed as the other task raises its priority above this task's
+ * priority. */
+ vTaskSuspend( xContinuousIncrementHandle );
+ {
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eSuspended );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ ulLastCounter = ulCounter;
+ }
+ vTaskResume( xContinuousIncrementHandle );
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xContinuousIncrementHandle ) == eReady );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* Now delay to ensure the other task has processor time. */
+ vTaskDelay( priSLEEP_TIME );
+
+ /* Check the shared variable again. This time to ensure mutual
+ * exclusion the whole scheduler will be locked. This is just for
+ * demo purposes! */
+ vTaskSuspendAll();
+ {
+ if( ulLastCounter == ulCounter )
+ {
+ /* The shared variable has not changed. There is a problem
+ * with the continuous count task so flag an error. */
+ sError = pdTRUE;
+ }
+ }
+ xTaskResumeAll();
+ }
+
+ /* Second section: */
+
+ /* Suspend the continuous counter task so it stops accessing the shared
+ * variable. */
+ vTaskSuspend( xContinuousIncrementHandle );
+
+ /* Reset the variable. */
+ ulCounter = ( uint32_t ) 0;
+
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* Resume the limited count task which has a higher priority than us.
+ * We should therefore not return from this call until the limited count
+ * task has suspended itself with a known value in the counter variable. */
+ vTaskResume( xLimitedIncrementHandle );
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+
+ /* This task should not run again until xLimitedIncrementHandle has
+ * suspended itself. */
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xLimitedIncrementHandle ) == eSuspended );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* Does the counter variable have the expected value? */
+ if( ulCounter != priMAX_COUNT )
+ {
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If no errors have occurred then increment the check variable. */
+ portENTER_CRITICAL();
+ usCheckVariable++;
+ portEXIT_CRITICAL();
+ }
+
+ /* Resume the continuous count task and do it all again. */
+ vTaskResume( xContinuousIncrementHandle );
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vQueueSendWhenSuspendedTask, pvParameters )
{
-static uint32_t ulValueToSend = ( uint32_t ) 0;
-
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- vTaskSuspendAll();
- {
- /* We must not block while the scheduler is suspended! */
- if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
- {
- xSuspendedQueueSendError = pdTRUE;
- }
- }
- xTaskResumeAll();
-
- vTaskDelay( priSLEEP_TIME );
-
- ++ulValueToSend;
- }
+ static uint32_t ulValueToSend = ( uint32_t ) 0;
+
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ vTaskSuspendAll();
+ {
+ /* We must not block while the scheduler is suspended! */
+ if( xQueueSend( xSuspendedTestQueue, ( void * ) &ulValueToSend, priNO_BLOCK ) != pdTRUE )
+ {
+ xSuspendedQueueSendError = pdTRUE;
+ }
+ }
+ xTaskResumeAll();
+
+ vTaskDelay( priSLEEP_TIME );
+
+ ++ulValueToSend;
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vQueueReceiveWhenSuspendedTask, pvParameters )
{
-uint32_t ulReceivedValue;
-BaseType_t xGotValue;
-
- /* Just to stop warning messages. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- do
- {
- /* Suspending the scheduler here is fairly pointless and
- undesirable for a normal application. It is done here purely
- to test the scheduler. The inner xTaskResumeAll() should
- never return pdTRUE as the scheduler is still locked by the
- outer call. */
- vTaskSuspendAll();
- {
- vTaskSuspendAll();
- {
- xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
- }
- if( xTaskResumeAll() != pdFALSE )
- {
- xSuspendedQueueReceiveError = pdTRUE;
- }
- }
- xTaskResumeAll();
-
- #if configUSE_PREEMPTION == 0
- {
- taskYIELD();
- }
- #endif
-
- } while( xGotValue == pdFALSE );
-
- if( ulReceivedValue != ulExpectedValue )
- {
- xSuspendedQueueReceiveError = pdTRUE;
- }
-
- if( xSuspendedQueueReceiveError != pdTRUE )
- {
- /* Only increment the variable if an error has not occurred. This
- allows xAreDynamicPriorityTasksStillRunning() to check for stalled
- tasks as well as explicit errors. */
- ++ulExpectedValue;
- }
- }
+ uint32_t ulReceivedValue;
+ BaseType_t xGotValue;
+
+ /* Just to stop warning messages. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ do
+ {
+ /* Suspending the scheduler here is fairly pointless and
+ * undesirable for a normal application. It is done here purely
+ * to test the scheduler. The inner xTaskResumeAll() should
+ * never return pdTRUE as the scheduler is still locked by the
+ * outer call. */
+ vTaskSuspendAll();
+ {
+ vTaskSuspendAll();
+ {
+ xGotValue = xQueueReceive( xSuspendedTestQueue, ( void * ) &ulReceivedValue, priNO_BLOCK );
+ }
+
+ if( xTaskResumeAll() != pdFALSE )
+ {
+ xSuspendedQueueReceiveError = pdTRUE;
+ }
+ }
+ xTaskResumeAll();
+
+ #if configUSE_PREEMPTION == 0
+ {
+ taskYIELD();
+ }
+ #endif
+ } while( xGotValue == pdFALSE );
+
+ if( ulReceivedValue != ulExpectedValue )
+ {
+ xSuspendedQueueReceiveError = pdTRUE;
+ }
+
+ if( xSuspendedQueueReceiveError != pdTRUE )
+ {
+ /* Only increment the variable if an error has not occurred. This
+ * allows xAreDynamicPriorityTasksStillRunning() to check for stalled
+ * tasks as well as explicit errors. */
+ ++ulExpectedValue;
+ }
+ }
}
/*-----------------------------------------------------------*/
@@ -441,39 +442,39 @@ BaseType_t xGotValue;
BaseType_t xAreDynamicPriorityTasksStillRunning( void )
{
/* Keep a history of the check variables so we know if it has been incremented
-since the last call. */
-static uint16_t usLastTaskCheck = ( uint16_t ) 0;
-static uint32_t ulLastExpectedValue = ( uint32_t ) 0U;
-BaseType_t xReturn = pdTRUE;
-
- /* Check the tasks are still running by ensuring the check variable
- is still incrementing. */
-
- if( usCheckVariable == usLastTaskCheck )
- {
- /* The check has not incremented so an error exists. */
- xReturn = pdFALSE;
- }
-
- if( ulExpectedValue == ulLastExpectedValue )
- {
- /* The value being received by the queue receive task has not
- incremented so an error exists. */
- xReturn = pdFALSE;
- }
-
- if( xSuspendedQueueSendError == pdTRUE )
- {
- xReturn = pdFALSE;
- }
-
- if( xSuspendedQueueReceiveError == pdTRUE )
- {
- xReturn = pdFALSE;
- }
-
- usLastTaskCheck = usCheckVariable;
- ulLastExpectedValue = ulExpectedValue;
-
- return xReturn;
+ * since the last call. */
+ static uint16_t usLastTaskCheck = ( uint16_t ) 0;
+ static uint32_t ulLastExpectedValue = ( uint32_t ) 0U;
+ BaseType_t xReturn = pdTRUE;
+
+ /* Check the tasks are still running by ensuring the check variable
+ * is still incrementing. */
+
+ if( usCheckVariable == usLastTaskCheck )
+ {
+ /* The check has not incremented so an error exists. */
+ xReturn = pdFALSE;
+ }
+
+ if( ulExpectedValue == ulLastExpectedValue )
+ {
+ /* The value being received by the queue receive task has not
+ * incremented so an error exists. */
+ xReturn = pdFALSE;
+ }
+
+ if( xSuspendedQueueSendError == pdTRUE )
+ {
+ xReturn = pdFALSE;
+ }
+
+ if( xSuspendedQueueReceiveError == pdTRUE )
+ {
+ xReturn = pdFALSE;
+ }
+
+ usLastTaskCheck = usCheckVariable;
+ ulLastExpectedValue = ulExpectedValue;
+
+ return xReturn;
}
diff --git a/FreeRTOS/Demo/Common/Minimal/flash.c b/FreeRTOS/Demo/Common/Minimal/flash.c
index c65ae57ac..43935ab43 100644
--- a/FreeRTOS/Demo/Common/Minimal/flash.c
+++ b/FreeRTOS/Demo/Common/Minimal/flash.c
@@ -49,12 +49,12 @@
#include "partest.h"
#include "flash.h"
-#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
-#define ledNUMBER_OF_LEDS ( 3 )
-#define ledFLASH_RATE_BASE ( ( TickType_t ) 333 )
+#define ledSTACK_SIZE configMINIMAL_STACK_SIZE
+#define ledNUMBER_OF_LEDS ( 3 )
+#define ledFLASH_RATE_BASE ( ( TickType_t ) 333 )
/* Variable used by the created tasks to calculate the LED number to use, and
-the rate at which they should flash the LED. */
+ * the rate at which they should flash the LED. */
static volatile UBaseType_t uxFlashTaskNumber = 0;
/* The task that is created three times. */
@@ -64,56 +64,55 @@ static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
void vStartLEDFlashTasks( UBaseType_t uxPriority )
{
-BaseType_t xLEDTask;
-
- /* Create the three tasks. */
- for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
- {
- /* Spawn the task. */
- xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
- }
+ BaseType_t xLEDTask;
+
+ /* Create the three tasks. */
+ for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
+ {
+ /* Spawn the task. */
+ xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
{
-TickType_t xFlashRate, xLastFlashTime;
-UBaseType_t uxLED;
-
- /* The parameters are not used. */
- ( void ) pvParameters;
-
- /* Calculate the LED and flash rate. */
- portENTER_CRITICAL();
- {
- /* See which of the eight LED's we should use. */
- uxLED = uxFlashTaskNumber;
-
- /* Update so the next task uses the next LED. */
- uxFlashTaskNumber++;
- }
- portEXIT_CRITICAL();
-
- xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( TickType_t ) uxLED );
- xFlashRate /= portTICK_PERIOD_MS;
-
- /* We will turn the LED on and off again in the delay period, so each
- delay is only half the total period. */
- xFlashRate /= ( TickType_t ) 2;
-
- /* We need to initialise xLastFlashTime prior to the first call to
- vTaskDelayUntil(). */
- xLastFlashTime = xTaskGetTickCount();
-
- for(;;)
- {
- /* Delay for half the flash period then turn the LED on. */
- vTaskDelayUntil( &xLastFlashTime, xFlashRate );
- vParTestToggleLED( uxLED );
-
- /* Delay for half the flash period then turn the LED off. */
- vTaskDelayUntil( &xLastFlashTime, xFlashRate );
- vParTestToggleLED( uxLED );
- }
+ TickType_t xFlashRate, xLastFlashTime;
+ UBaseType_t uxLED;
+
+ /* The parameters are not used. */
+ ( void ) pvParameters;
+
+ /* Calculate the LED and flash rate. */
+ portENTER_CRITICAL();
+ {
+ /* See which of the eight LED's we should use. */
+ uxLED = uxFlashTaskNumber;
+
+ /* Update so the next task uses the next LED. */
+ uxFlashTaskNumber++;
+ }
+ portEXIT_CRITICAL();
+
+ xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( TickType_t ) uxLED );
+ xFlashRate /= portTICK_PERIOD_MS;
+
+ /* We will turn the LED on and off again in the delay period, so each
+ * delay is only half the total period. */
+ xFlashRate /= ( TickType_t ) 2;
+
+ /* We need to initialise xLastFlashTime prior to the first call to
+ * vTaskDelayUntil(). */
+ xLastFlashTime = xTaskGetTickCount();
+
+ for( ; ; )
+ {
+ /* Delay for half the flash period then turn the LED on. */
+ vTaskDelayUntil( &xLastFlashTime, xFlashRate );
+ vParTestToggleLED( uxLED );
+
+ /* Delay for half the flash period then turn the LED off. */
+ vTaskDelayUntil( &xLastFlashTime, xFlashRate );
+ vParTestToggleLED( uxLED );
+ }
} /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
-
diff --git a/FreeRTOS/Demo/Common/Minimal/flash_timer.c b/FreeRTOS/Demo/Common/Minimal/flash_timer.c
index a7699c571..4e13e2373 100644
--- a/FreeRTOS/Demo/Common/Minimal/flash_timer.c
+++ b/FreeRTOS/Demo/Common/Minimal/flash_timer.c
@@ -39,10 +39,10 @@
#include "flash_timer.h"
/* The toggle rates are all a multple of ledFLASH_RATE_BASE. */
-#define ledFLASH_RATE_BASE ( ( ( TickType_t ) 333 ) / portTICK_PERIOD_MS )
+#define ledFLASH_RATE_BASE ( ( ( TickType_t ) 333 ) / portTICK_PERIOD_MS )
/* A block time of zero simple means "don't block". */
-#define ledDONT_BLOCK ( ( TickType_t ) 0 )
+#define ledDONT_BLOCK ( ( TickType_t ) 0 )
/*-----------------------------------------------------------*/
@@ -57,42 +57,40 @@ static void prvLEDTimerCallback( TimerHandle_t xTimer );
void vStartLEDFlashTimers( UBaseType_t uxNumberOfLEDs )
{
-UBaseType_t uxLEDTimer;
-TimerHandle_t xTimer;
+ UBaseType_t uxLEDTimer;
+ TimerHandle_t xTimer;
- /* Create and start the requested number of timers. */
- for( uxLEDTimer = 0; uxLEDTimer < uxNumberOfLEDs; ++uxLEDTimer )
- {
- /* Create the timer. */
- xTimer = xTimerCreate( "Flasher", /* A text name, purely to help debugging. */
- ledFLASH_RATE_BASE * ( uxLEDTimer + 1 ),/* The timer period, which is a multiple of ledFLASH_RATE_BASE. */
- pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
- ( void * ) uxLEDTimer, /* The ID is used to identify the timer within the timer callback function, as each timer uses the same callback. */
- prvLEDTimerCallback /* Each timer uses the same callback. */
- );
+ /* Create and start the requested number of timers. */
+ for( uxLEDTimer = 0; uxLEDTimer < uxNumberOfLEDs; ++uxLEDTimer )
+ {
+ /* Create the timer. */
+ xTimer = xTimerCreate( "Flasher", /* A text name, purely to help debugging. */
+ ledFLASH_RATE_BASE * ( uxLEDTimer + 1 ), /* The timer period, which is a multiple of ledFLASH_RATE_BASE. */
+ pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
+ ( void * ) uxLEDTimer, /* The ID is used to identify the timer within the timer callback function, as each timer uses the same callback. */
+ prvLEDTimerCallback /* Each timer uses the same callback. */
+ );
- /* If the timer was created successfully, attempt to start it. If the
- scheduler has not yet been started then the timer command queue must
- be long enough to hold each command sent to it until such time that the
- scheduler is started. The timer command queue length is set by
- configTIMER_QUEUE_LENGTH in FreeRTOSConfig.h. */
- if( xTimer != NULL )
- {
- xTimerStart( xTimer, ledDONT_BLOCK );
- }
- }
+ /* If the timer was created successfully, attempt to start it. If the
+ * scheduler has not yet been started then the timer command queue must
+ * be long enough to hold each command sent to it until such time that the
+ * scheduler is started. The timer command queue length is set by
+ * configTIMER_QUEUE_LENGTH in FreeRTOSConfig.h. */
+ if( xTimer != NULL )
+ {
+ xTimerStart( xTimer, ledDONT_BLOCK );
+ }
+ }
}
/*-----------------------------------------------------------*/
static void prvLEDTimerCallback( TimerHandle_t xTimer )
{
-BaseType_t xTimerID;
+ BaseType_t xTimerID;
- /* The timer ID is used to identify the timer that has actually expired as
- each timer uses the same callback. The ID is then also used as the number
- of the LED that is to be toggled. */
- xTimerID = ( BaseType_t ) pvTimerGetTimerID( xTimer );
- vParTestToggleLED( xTimerID );
+ /* The timer ID is used to identify the timer that has actually expired as
+ * each timer uses the same callback. The ID is then also used as the number
+ * of the LED that is to be toggled. */
+ xTimerID = ( BaseType_t ) pvTimerGetTimerID( xTimer );
+ vParTestToggleLED( xTimerID );
}
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/flop.c b/FreeRTOS/Demo/Common/Minimal/flop.c
index be38eb53e..c405e9968 100644
--- a/FreeRTOS/Demo/Common/Minimal/flop.c
+++ b/FreeRTOS/Demo/Common/Minimal/flop.c
@@ -50,300 +50,298 @@
#include "flop.h"
#ifndef mathSTACK_SIZE
- #define mathSTACK_SIZE configMINIMAL_STACK_SIZE
+ #define mathSTACK_SIZE configMINIMAL_STACK_SIZE
#endif
-#define mathNUMBER_OF_TASKS ( 4 )
+#define mathNUMBER_OF_TASKS ( 4 )
/* Four tasks, each of which performs a different floating point calculation.
-Each of the four is created twice. */
+ * Each of the four is created twice. */
static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
/* These variables are used to check that all the tasks are still running. If a
-task gets a calculation wrong it will stop setting its check variable. */
+ * task gets a calculation wrong it will stop setting its check variable. */
static uint16_t usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
/*-----------------------------------------------------------*/
void vStartMathTasks( UBaseType_t uxPriority )
{
- xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
{
-volatile portDOUBLE d1, d2, d3, d4;
-volatile uint16_t *pusTaskCheckVariable;
-volatile portDOUBLE dAnswer;
-short sError = pdFALSE;
-
- /* Some ports require that tasks that use a hardware floating point unit
- tell the kernel that they require a floating point context before any
- floating point instructions are executed. */
- portTASK_USES_FLOATING_POINT();
-
- d1 = 123.4567;
- d2 = 2345.6789;
- d3 = -918.222;
-
- dAnswer = ( d1 + d2 ) * d3;
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for(;;)
- {
- d1 = 123.4567;
- d2 = 2345.6789;
- d3 = -918.222;
-
- d4 = ( d1 + d2 ) * d3;
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( fabs( d4 - dAnswer ) > 0.001 )
- {
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct then set set the check
- variable. The check variable will get set to pdFALSE each time
- xAreMathsTaskStillRunning() is executed. */
- ( *pusTaskCheckVariable ) = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- }
+ volatile portDOUBLE d1, d2, d3, d4;
+ volatile uint16_t * pusTaskCheckVariable;
+ volatile portDOUBLE dAnswer;
+ short sError = pdFALSE;
+
+ /* Some ports require that tasks that use a hardware floating point unit
+ * tell the kernel that they require a floating point context before any
+ * floating point instructions are executed. */
+ portTASK_USES_FLOATING_POINT();
+
+ d1 = 123.4567;
+ d2 = 2345.6789;
+ d3 = -918.222;
+
+ dAnswer = ( d1 + d2 ) * d3;
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ d1 = 123.4567;
+ d2 = 2345.6789;
+ d3 = -918.222;
+
+ d4 = ( d1 + d2 ) * d3;
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( fabs( d4 - dAnswer ) > 0.001 )
+ {
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct then set set the check
+ * variable. The check variable will get set to pdFALSE each time
+ * xAreMathsTaskStillRunning() is executed. */
+ ( *pusTaskCheckVariable ) = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
{
-volatile portDOUBLE d1, d2, d3, d4;
-volatile uint16_t *pusTaskCheckVariable;
-volatile portDOUBLE dAnswer;
-short sError = pdFALSE;
-
- /* Some ports require that tasks that use a hardware floating point unit
- tell the kernel that they require a floating point context before any
- floating point instructions are executed. */
- portTASK_USES_FLOATING_POINT();
-
- d1 = -389.38;
- d2 = 32498.2;
- d3 = -2.0001;
-
- dAnswer = ( d1 / d2 ) * d3;
-
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for( ;; )
- {
- d1 = -389.38;
- d2 = 32498.2;
- d3 = -2.0001;
-
- d4 = ( d1 / d2 ) * d3;
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( fabs( d4 - dAnswer ) > 0.001 )
- {
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct then set set the check
- variable. The check variable will get set to pdFALSE each time
- xAreMathsTaskStillRunning() is executed. */
- ( *pusTaskCheckVariable ) = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
- }
+ volatile portDOUBLE d1, d2, d3, d4;
+ volatile uint16_t * pusTaskCheckVariable;
+ volatile portDOUBLE dAnswer;
+ short sError = pdFALSE;
+
+ /* Some ports require that tasks that use a hardware floating point unit
+ * tell the kernel that they require a floating point context before any
+ * floating point instructions are executed. */
+ portTASK_USES_FLOATING_POINT();
+
+ d1 = -389.38;
+ d2 = 32498.2;
+ d3 = -2.0001;
+
+ dAnswer = ( d1 / d2 ) * d3;
+
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ d1 = -389.38;
+ d2 = 32498.2;
+ d3 = -2.0001;
+
+ d4 = ( d1 / d2 ) * d3;
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( fabs( d4 - dAnswer ) > 0.001 )
+ {
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct then set set the check
+ * variable. The check variable will get set to pdFALSE each time
+ * xAreMathsTaskStillRunning() is executed. */
+ ( *pusTaskCheckVariable ) = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
{
-volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
-volatile uint16_t *pusTaskCheckVariable;
-const size_t xArraySize = 10;
-size_t xPosition;
-short sError = pdFALSE;
-
- /* Some ports require that tasks that use a hardware floating point unit
- tell the kernel that they require a floating point context before any
- floating point instructions are executed. */
- portTASK_USES_FLOATING_POINT();
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
-
- pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
-
- /* Keep filling an array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- dTotal1 = 0.0;
- dTotal2 = 0.0;
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
- dTotal1 += ( portDOUBLE ) xPosition + 5.5;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- dTotal2 += pdArray[ xPosition ];
- }
-
- dDifference = dTotal1 - dTotal2;
- if( fabs( dDifference ) > 0.001 )
- {
- sError = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct then set set the check
- variable. The check variable will get set to pdFALSE each time
- xAreMathsTaskStillRunning() is executed. */
- ( *pusTaskCheckVariable ) = pdTRUE;
- }
- }
+ volatile portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
+ volatile uint16_t * pusTaskCheckVariable;
+ const size_t xArraySize = 10;
+ size_t xPosition;
+ short sError = pdFALSE;
+
+ /* Some ports require that tasks that use a hardware floating point unit
+ * tell the kernel that they require a floating point context before any
+ * floating point instructions are executed. */
+ portTASK_USES_FLOATING_POINT();
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
+
+ pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
+
+ /* Keep filling an array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ dTotal1 = 0.0;
+ dTotal2 = 0.0;
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
+ dTotal1 += ( portDOUBLE ) xPosition + 5.5;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ dTotal2 += pdArray[ xPosition ];
+ }
+
+ dDifference = dTotal1 - dTotal2;
+
+ if( fabs( dDifference ) > 0.001 )
+ {
+ sError = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct then set set the check
+ * variable. The check variable will get set to pdFALSE each time
+ * xAreMathsTaskStillRunning() is executed. */
+ ( *pusTaskCheckVariable ) = pdTRUE;
+ }
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
{
-volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
-volatile uint16_t *pusTaskCheckVariable;
-const size_t xArraySize = 10;
-size_t xPosition;
-short sError = pdFALSE;
-
- /* Some ports require that tasks that use a hardware floating point unit
- tell the kernel that they require a floating point context before any
- floating point instructions are executed. */
- portTASK_USES_FLOATING_POINT();
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
-
- pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
-
- /* Keep filling an array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- dTotal1 = 0.0;
- dTotal2 = 0.0;
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
- dTotal1 += ( portDOUBLE ) xPosition * 12.123;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- dTotal2 += pdArray[ xPosition ];
- }
-
- dDifference = dTotal1 - dTotal2;
- if( fabs( dDifference ) > 0.001 )
- {
- sError = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct then set set the check
- variable. The check variable will get set to pdFALSE each time
- xAreMathsTaskStillRunning() is executed. */
- ( *pusTaskCheckVariable ) = pdTRUE;
- }
- }
+ volatile portDOUBLE * pdArray, dTotal1, dTotal2, dDifference;
+ volatile uint16_t * pusTaskCheckVariable;
+ const size_t xArraySize = 10;
+ size_t xPosition;
+ short sError = pdFALSE;
+
+ /* Some ports require that tasks that use a hardware floating point unit
+ * tell the kernel that they require a floating point context before any
+ * floating point instructions are executed. */
+ portTASK_USES_FLOATING_POINT();
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters;
+
+ pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
+
+ /* Keep filling an array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ dTotal1 = 0.0;
+ dTotal2 = 0.0;
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
+ dTotal1 += ( portDOUBLE ) xPosition * 12.123;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ dTotal2 += pdArray[ xPosition ];
+ }
+
+ dDifference = dTotal1 - dTotal2;
+
+ if( fabs( dDifference ) > 0.001 )
+ {
+ sError = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct then set set the check
+ * variable. The check variable will get set to pdFALSE each time
+ * xAreMathsTaskStillRunning() is executed. */
+ ( *pusTaskCheckVariable ) = pdTRUE;
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreMathsTaskStillRunning( void )
{
-BaseType_t xReturn = pdPASS, xTask;
-
- /* Check the maths tasks are still running by ensuring their check variables
- have been set to pdPASS. */
- for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
- {
- if( usTaskCheck[ xTask ] != pdTRUE )
- {
- /* The check has not been set so the associated task has either
- stalled or detected an error. */
- xReturn = pdFAIL;
- }
- else
- {
- /* Reset the variable so it can be checked again the next time this
- function is executed. */
- usTaskCheck[ xTask ] = pdFALSE;
- }
- }
-
- return xReturn;
+ BaseType_t xReturn = pdPASS, xTask;
+
+ /* Check the maths tasks are still running by ensuring their check variables
+ * have been set to pdPASS. */
+ for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
+ {
+ if( usTaskCheck[ xTask ] != pdTRUE )
+ {
+ /* The check has not been set so the associated task has either
+ * stalled or detected an error. */
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ /* Reset the variable so it can be checked again the next time this
+ * function is executed. */
+ usTaskCheck[ xTask ] = pdFALSE;
+ }
+ }
+
+ return xReturn;
}
-
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/integer.c b/FreeRTOS/Demo/Common/Minimal/integer.c
index 7d5802df6..9efd44ae4 100644
--- a/FreeRTOS/Demo/Common/Minimal/integer.c
+++ b/FreeRTOS/Demo/Common/Minimal/integer.c
@@ -42,122 +42,121 @@
#include "integer.h"
/* The constants used in the calculation. */
-#define intgCONST1 ( ( long ) 123 )
-#define intgCONST2 ( ( long ) 234567 )
-#define intgCONST3 ( ( long ) -3 )
-#define intgCONST4 ( ( long ) 7 )
-#define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
+#define intgCONST1 ( ( long ) 123 )
+#define intgCONST2 ( ( long ) 234567 )
+#define intgCONST3 ( ( long ) -3 )
+#define intgCONST4 ( ( long ) 7 )
+#define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
-#define intgSTACK_SIZE configMINIMAL_STACK_SIZE
+#define intgSTACK_SIZE configMINIMAL_STACK_SIZE
/* As this is the minimal version, we will only create one task. */
-#define intgNUMBER_OF_TASKS ( 1 )
+#define intgNUMBER_OF_TASKS ( 1 )
/* The task function. Repeatedly performs a 32 bit calculation, checking the
-result against the expected result. If the result is incorrect then the
-context switch must have caused some corruption. */
+ * result against the expected result. If the result is incorrect then the
+ * context switch must have caused some corruption. */
static portTASK_FUNCTION_PROTO( vCompeteingIntMathTask, pvParameters );
/* Variables that are set to true within the calculation task to indicate
-that the task is still executing. The check task sets the variable back to
-false, flagging an error if the variable is still false the next time it
-is called. */
+ * that the task is still executing. The check task sets the variable back to
+ * false, flagging an error if the variable is still false the next time it
+ * is called. */
static BaseType_t xTaskCheck[ intgNUMBER_OF_TASKS ] = { ( BaseType_t ) pdFALSE };
/*-----------------------------------------------------------*/
void vStartIntegerMathTasks( UBaseType_t uxPriority )
{
-short sTask;
+ short sTask;
- for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
- {
- xTaskCreate( vCompeteingIntMathTask, "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( TaskHandle_t * ) NULL );
- }
+ for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
+ {
+ xTaskCreate( vCompeteingIntMathTask, "IntMath", intgSTACK_SIZE, ( void * ) &( xTaskCheck[ sTask ] ), uxPriority, ( TaskHandle_t * ) NULL );
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompeteingIntMathTask, pvParameters )
{
/* These variables are all effectively set to constants so they are volatile to
-ensure the compiler does not just get rid of them. */
-volatile long lValue;
-short sError = pdFALSE;
-volatile BaseType_t *pxTaskHasExecuted;
-
- /* Set a pointer to the variable we are going to set to true each
- iteration. This is also a good test of the parameter passing mechanism
- within each port. */
- pxTaskHasExecuted = ( volatile BaseType_t * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for( ;; )
- {
- /* Perform the calculation. This will store partial value in
- registers, resulting in a good test of the context switch mechanism. */
- lValue = intgCONST1;
- lValue += intgCONST2;
-
- /* Yield in case cooperative scheduling is being used. */
- #if configUSE_PREEMPTION == 0
- {
- taskYIELD();
- }
- #endif
-
- /* Finish off the calculation. */
- lValue *= intgCONST3;
- lValue /= intgCONST4;
-
- /* If the calculation is found to be incorrect we stop setting the
- TaskHasExecuted variable so the check task can see an error has
- occurred. */
- if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
- {
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* We have not encountered any errors, so set the flag that show
- we are still executing. This will be periodically cleared by
- the check task. */
- portENTER_CRITICAL();
- *pxTaskHasExecuted = pdTRUE;
- portEXIT_CRITICAL();
- }
-
- /* Yield in case cooperative scheduling is being used. */
- #if configUSE_PREEMPTION == 0
- {
- taskYIELD();
- }
- #endif
- }
+ * ensure the compiler does not just get rid of them. */
+ volatile long lValue;
+ short sError = pdFALSE;
+ volatile BaseType_t * pxTaskHasExecuted;
+
+ /* Set a pointer to the variable we are going to set to true each
+ * iteration. This is also a good test of the parameter passing mechanism
+ * within each port. */
+ pxTaskHasExecuted = ( volatile BaseType_t * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ /* Perform the calculation. This will store partial value in
+ * registers, resulting in a good test of the context switch mechanism. */
+ lValue = intgCONST1;
+ lValue += intgCONST2;
+
+ /* Yield in case cooperative scheduling is being used. */
+ #if configUSE_PREEMPTION == 0
+ {
+ taskYIELD();
+ }
+ #endif
+
+ /* Finish off the calculation. */
+ lValue *= intgCONST3;
+ lValue /= intgCONST4;
+
+ /* If the calculation is found to be incorrect we stop setting the
+ * TaskHasExecuted variable so the check task can see an error has
+ * occurred. */
+ if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
+ {
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* We have not encountered any errors, so set the flag that show
+ * we are still executing. This will be periodically cleared by
+ * the check task. */
+ portENTER_CRITICAL();
+ *pxTaskHasExecuted = pdTRUE;
+ portEXIT_CRITICAL();
+ }
+
+ /* Yield in case cooperative scheduling is being used. */
+ #if configUSE_PREEMPTION == 0
+ {
+ taskYIELD();
+ }
+ #endif
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreIntegerMathsTaskStillRunning( void )
{
-BaseType_t xReturn = pdTRUE;
-short sTask;
-
- /* Check the maths tasks are still running by ensuring their check variables
- are still being set to true. */
- for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
- {
- if( xTaskCheck[ sTask ] == pdFALSE )
- {
- /* The check has not incremented so an error exists. */
- xReturn = pdFALSE;
- }
-
- /* Reset the check variable so we can tell if it has been set by
- the next time around. */
- xTaskCheck[ sTask ] = pdFALSE;
- }
-
- return xReturn;
+ BaseType_t xReturn = pdTRUE;
+ short sTask;
+
+ /* Check the maths tasks are still running by ensuring their check variables
+ * are still being set to true. */
+ for( sTask = 0; sTask < intgNUMBER_OF_TASKS; sTask++ )
+ {
+ if( xTaskCheck[ sTask ] == pdFALSE )
+ {
+ /* The check has not incremented so an error exists. */
+ xReturn = pdFALSE;
+ }
+
+ /* Reset the check variable so we can tell if it has been set by
+ * the next time around. */
+ xTaskCheck[ sTask ] = pdFALSE;
+ }
+
+ return xReturn;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/recmutex.c b/FreeRTOS/Demo/Common/Minimal/recmutex.c
index 2050ca181..fc63a9bfd 100644
--- a/FreeRTOS/Demo/Common/Minimal/recmutex.c
+++ b/FreeRTOS/Demo/Common/Minimal/recmutex.c
@@ -26,40 +26,40 @@
*/
/*
- The tasks defined on this page demonstrate the use of recursive mutexes.
-
- For recursive mutex functionality the created mutex should be created using
- xSemaphoreCreateRecursiveMutex(), then be manipulated
- using the xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() API
- functions.
-
- This demo creates three tasks all of which access the same recursive mutex:
-
- prvRecursiveMutexControllingTask() has the highest priority so executes
- first and grabs the mutex. It then performs some recursive accesses -
- between each of which it sleeps for a short period to let the lower
- priority tasks execute. When it has completed its demo functionality
- it gives the mutex back before suspending itself.
-
- prvRecursiveMutexBlockingTask() attempts to access the mutex by performing
- a blocking 'take'. The blocking task has a lower priority than the
- controlling task so by the time it executes the mutex has already been
- taken by the controlling task, causing the blocking task to block. It
- does not unblock until the controlling task has given the mutex back,
- and it does not actually run until the controlling task has suspended
- itself (due to the relative priorities). When it eventually does obtain
- the mutex all it does is give the mutex back prior to also suspending
- itself. At this point both the controlling task and the blocking task are
- suspended.
-
- prvRecursiveMutexPollingTask() runs at the idle priority. It spins round
- a tight loop attempting to obtain the mutex with a non-blocking call. As
- the lowest priority task it will not successfully obtain the mutex until
- both the controlling and blocking tasks are suspended. Once it eventually
- does obtain the mutex it first unsuspends both the controlling task and
- blocking task prior to giving the mutex back - resulting in the polling
- task temporarily inheriting the controlling tasks priority.
-*/
+ * The tasks defined on this page demonstrate the use of recursive mutexes.
+ *
+ * For recursive mutex functionality the created mutex should be created using
+ * xSemaphoreCreateRecursiveMutex(), then be manipulated
+ * using the xSemaphoreTakeRecursive() and xSemaphoreGiveRecursive() API
+ * functions.
+ *
+ * This demo creates three tasks all of which access the same recursive mutex:
+ *
+ * prvRecursiveMutexControllingTask() has the highest priority so executes
+ * first and grabs the mutex. It then performs some recursive accesses -
+ * between each of which it sleeps for a short period to let the lower
+ * priority tasks execute. When it has completed its demo functionality
+ * it gives the mutex back before suspending itself.
+ *
+ * prvRecursiveMutexBlockingTask() attempts to access the mutex by performing
+ * a blocking 'take'. The blocking task has a lower priority than the
+ * controlling task so by the time it executes the mutex has already been
+ * taken by the controlling task, causing the blocking task to block. It
+ * does not unblock until the controlling task has given the mutex back,
+ * and it does not actually run until the controlling task has suspended
+ * itself (due to the relative priorities). When it eventually does obtain
+ * the mutex all it does is give the mutex back prior to also suspending
+ * itself. At this point both the controlling task and the blocking task are
+ * suspended.
+ *
+ * prvRecursiveMutexPollingTask() runs at the idle priority. It spins round
+ * a tight loop attempting to obtain the mutex with a non-blocking call. As
+ * the lowest priority task it will not successfully obtain the mutex until
+ * both the controlling and blocking tasks are suspended. Once it eventually
+ * does obtain the mutex it first unsuspends both the controlling task and
+ * blocking task prior to giving the mutex back - resulting in the polling
+ * task temporarily inheriting the controlling tasks priority.
+ */
/* Scheduler include files. */
#include "FreeRTOS.h"
@@ -70,29 +70,29 @@
#include "recmutex.h"
/* Priorities assigned to the three tasks. recmuCONTROLLING_TASK_PRIORITY can
-be overridden by a definition in FreeRTOSConfig.h. */
+ * be overridden by a definition in FreeRTOSConfig.h. */
#ifndef recmuCONTROLLING_TASK_PRIORITY
- #define recmuCONTROLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
+ #define recmuCONTROLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
#endif
-#define recmuBLOCKING_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
-#define recmuPOLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 0 )
+#define recmuBLOCKING_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
+#define recmuPOLLING_TASK_PRIORITY ( tskIDLE_PRIORITY + 0 )
/* The recursive call depth. */
-#define recmuMAX_COUNT ( 10 )
+#define recmuMAX_COUNT ( 10 )
/* Misc. */
-#define recmuSHORT_DELAY ( pdMS_TO_TICKS( 20 ) )
-#define recmuNO_DELAY ( ( TickType_t ) 0 )
-#define recmu15ms_DELAY ( pdMS_TO_TICKS( 15 ) )
+#define recmuSHORT_DELAY ( pdMS_TO_TICKS( 20 ) )
+#define recmuNO_DELAY ( ( TickType_t ) 0 )
+#define recmu15ms_DELAY ( pdMS_TO_TICKS( 15 ) )
#ifndef recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE
- #define recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
+ #define recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#endif
/* The three tasks as described at the top of this file. */
-static void prvRecursiveMutexControllingTask( void *pvParameters );
-static void prvRecursiveMutexBlockingTask( void *pvParameters );
-static void prvRecursiveMutexPollingTask( void *pvParameters );
+static void prvRecursiveMutexControllingTask( void * pvParameters );
+static void prvRecursiveMutexBlockingTask( void * pvParameters );
+static void prvRecursiveMutexPollingTask( void * pvParameters );
/* The mutex used by the demo. */
static SemaphoreHandle_t xMutex;
@@ -102,315 +102,311 @@ static volatile BaseType_t xErrorOccurred = pdFALSE, xControllingIsSuspended = p
static volatile UBaseType_t uxControllingCycles = 0, uxBlockingCycles = 0, uxPollingCycles = 0;
/* Handles of the two higher priority tasks, required so they can be resumed
-(unsuspended). */
+ * (unsuspended). */
static TaskHandle_t xControllingTaskHandle, xBlockingTaskHandle;
/*-----------------------------------------------------------*/
void vStartRecursiveMutexTasks( void )
{
- /* Just creates the mutex and the three tasks. */
-
- xMutex = xSemaphoreCreateRecursiveMutex();
-
- if( xMutex != NULL )
- {
- /* vQueueAddToRegistry() adds the mutex to the registry, if one is
- in use. The registry is provided as a means for kernel aware
- debuggers to locate mutex and has no purpose if a kernel aware debugger
- is not being used. The call to vQueueAddToRegistry() will be removed
- by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
- defined to be less than 1. */
- vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Recursive_Mutex" );
-
- xTaskCreate( prvRecursiveMutexControllingTask, "Rec1", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle );
- xTaskCreate( prvRecursiveMutexBlockingTask, "Rec2", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle );
- xTaskCreate( prvRecursiveMutexPollingTask, "Rec3", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, NULL );
- }
+ /* Just creates the mutex and the three tasks. */
+
+ xMutex = xSemaphoreCreateRecursiveMutex();
+
+ if( xMutex != NULL )
+ {
+ /* vQueueAddToRegistry() adds the mutex to the registry, if one is
+ * in use. The registry is provided as a means for kernel aware
+ * debuggers to locate mutex and has no purpose if a kernel aware debugger
+ * is not being used. The call to vQueueAddToRegistry() will be removed
+ * by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is
+ * defined to be less than 1. */
+ vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Recursive_Mutex" );
+
+ xTaskCreate( prvRecursiveMutexControllingTask, "Rec1", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle );
+ xTaskCreate( prvRecursiveMutexBlockingTask, "Rec2", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle );
+ xTaskCreate( prvRecursiveMutexPollingTask, "Rec3", recmuRECURSIVE_MUTEX_TEST_TASK_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, NULL );
+ }
}
/*-----------------------------------------------------------*/
-static void prvRecursiveMutexControllingTask( void *pvParameters )
+static void prvRecursiveMutexControllingTask( void * pvParameters )
{
-UBaseType_t ux;
-
- /* Just to remove compiler warning. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Should not be able to 'give' the mutex, as we have not yet 'taken'
- it. The first time through, the mutex will not have been used yet,
- subsequent times through, at this point the mutex will be held by the
- polling task. */
- if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- for( ux = 0; ux < recmuMAX_COUNT; ux++ )
- {
- /* We should now be able to take the mutex as many times as
- we like.
-
- The first time through the mutex will be immediately available, on
- subsequent times through the mutex will be held by the polling task
- at this point and this Take will cause the polling task to inherit
- the priority of this task. In this case the block time must be
- long enough to ensure the polling task will execute again before the
- block time expires. If the block time does expire then the error
- flag will be set here. */
- if( xSemaphoreTakeRecursive( xMutex, recmu15ms_DELAY ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Ensure the other task attempting to access the mutex (and the
- other demo tasks) are able to execute to ensure they either block
- (where a block time is specified) or return an error (where no
- block time is specified) as the mutex is held by this task. */
- vTaskDelay( recmuSHORT_DELAY );
- }
-
- /* For each time we took the mutex, give it back. */
- for( ux = 0; ux < recmuMAX_COUNT; ux++ )
- {
- /* Ensure the other task attempting to access the mutex (and the
- other demo tasks) are able to execute. */
- vTaskDelay( recmuSHORT_DELAY );
-
- /* We should now be able to give the mutex as many times as we
- took it. When the mutex is available again the Blocking task
- should be unblocked but not run because it has a lower priority
- than this task. The polling task should also not run at this point
- as it too has a lower priority than this task. */
- if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
- }
-
- /* Having given it back the same number of times as it was taken, we
- should no longer be the mutex owner, so the next give should fail. */
- if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Keep count of the number of cycles this task has performed so a
- stall can be detected. */
- uxControllingCycles++;
-
- /* Suspend ourselves so the blocking task can execute. */
- xControllingIsSuspended = pdTRUE;
- vTaskSuspend( NULL );
- xControllingIsSuspended = pdFALSE;
- }
+ UBaseType_t ux;
+
+ /* Just to remove compiler warning. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Should not be able to 'give' the mutex, as we have not yet 'taken'
+ * it. The first time through, the mutex will not have been used yet,
+ * subsequent times through, at this point the mutex will be held by the
+ * polling task. */
+ if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ for( ux = 0; ux < recmuMAX_COUNT; ux++ )
+ {
+ /* We should now be able to take the mutex as many times as
+ * we like.
+ *
+ * The first time through the mutex will be immediately available, on
+ * subsequent times through the mutex will be held by the polling task
+ * at this point and this Take will cause the polling task to inherit
+ * the priority of this task. In this case the block time must be
+ * long enough to ensure the polling task will execute again before the
+ * block time expires. If the block time does expire then the error
+ * flag will be set here. */
+ if( xSemaphoreTakeRecursive( xMutex, recmu15ms_DELAY ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Ensure the other task attempting to access the mutex (and the
+ * other demo tasks) are able to execute to ensure they either block
+ * (where a block time is specified) or return an error (where no
+ * block time is specified) as the mutex is held by this task. */
+ vTaskDelay( recmuSHORT_DELAY );
+ }
+
+ /* For each time we took the mutex, give it back. */
+ for( ux = 0; ux < recmuMAX_COUNT; ux++ )
+ {
+ /* Ensure the other task attempting to access the mutex (and the
+ * other demo tasks) are able to execute. */
+ vTaskDelay( recmuSHORT_DELAY );
+
+ /* We should now be able to give the mutex as many times as we
+ * took it. When the mutex is available again the Blocking task
+ * should be unblocked but not run because it has a lower priority
+ * than this task. The polling task should also not run at this point
+ * as it too has a lower priority than this task. */
+ if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+ }
+
+ /* Having given it back the same number of times as it was taken, we
+ * should no longer be the mutex owner, so the next give should fail. */
+ if( xSemaphoreGiveRecursive( xMutex ) == pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Keep count of the number of cycles this task has performed so a
+ * stall can be detected. */
+ uxControllingCycles++;
+
+ /* Suspend ourselves so the blocking task can execute. */
+ xControllingIsSuspended = pdTRUE;
+ vTaskSuspend( NULL );
+ xControllingIsSuspended = pdFALSE;
+ }
}
/*-----------------------------------------------------------*/
-static void prvRecursiveMutexBlockingTask( void *pvParameters )
+static void prvRecursiveMutexBlockingTask( void * pvParameters )
{
- /* Just to remove compiler warning. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* This task will run while the controlling task is blocked, and the
- controlling task will block only once it has the mutex - therefore
- this call should block until the controlling task has given up the
- mutex, and not actually execute past this call until the controlling
- task is suspended. portMAX_DELAY - 1 is used instead of portMAX_DELAY
- to ensure the task's state is reported as Blocked and not Suspended in
- a later call to configASSERT() (within the polling task). */
- if( xSemaphoreTakeRecursive( xMutex, ( portMAX_DELAY - 1 ) ) == pdPASS )
- {
- if( xControllingIsSuspended != pdTRUE )
- {
- /* Did not expect to execute until the controlling task was
- suspended. */
- xErrorOccurred = pdTRUE;
- }
- else
- {
- /* Give the mutex back before suspending ourselves to allow
- the polling task to obtain the mutex. */
- if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- xBlockingIsSuspended = pdTRUE;
- vTaskSuspend( NULL );
- xBlockingIsSuspended = pdFALSE;
- }
- }
- else
- {
- /* We should not leave the xSemaphoreTakeRecursive() function
- until the mutex was obtained. */
- xErrorOccurred = pdTRUE;
- }
-
- /* The controlling and blocking tasks should be in lock step. */
- if( uxControllingCycles != (UBaseType_t) ( uxBlockingCycles + 1 ) )
- {
- xErrorOccurred = pdTRUE;
- }
-
- /* Keep count of the number of cycles this task has performed so a
- stall can be detected. */
- uxBlockingCycles++;
- }
+ /* Just to remove compiler warning. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* This task will run while the controlling task is blocked, and the
+ * controlling task will block only once it has the mutex - therefore
+ * this call should block until the controlling task has given up the
+ * mutex, and not actually execute past this call until the controlling
+ * task is suspended. portMAX_DELAY - 1 is used instead of portMAX_DELAY
+ * to ensure the task's state is reported as Blocked and not Suspended in
+ * a later call to configASSERT() (within the polling task). */
+ if( xSemaphoreTakeRecursive( xMutex, ( portMAX_DELAY - 1 ) ) == pdPASS )
+ {
+ if( xControllingIsSuspended != pdTRUE )
+ {
+ /* Did not expect to execute until the controlling task was
+ * suspended. */
+ xErrorOccurred = pdTRUE;
+ }
+ else
+ {
+ /* Give the mutex back before suspending ourselves to allow
+ * the polling task to obtain the mutex. */
+ if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ xBlockingIsSuspended = pdTRUE;
+ vTaskSuspend( NULL );
+ xBlockingIsSuspended = pdFALSE;
+ }
+ }
+ else
+ {
+ /* We should not leave the xSemaphoreTakeRecursive() function
+ * until the mutex was obtained. */
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* The controlling and blocking tasks should be in lock step. */
+ if( uxControllingCycles != ( UBaseType_t ) ( uxBlockingCycles + 1 ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ /* Keep count of the number of cycles this task has performed so a
+ * stall can be detected. */
+ uxBlockingCycles++;
+ }
}
/*-----------------------------------------------------------*/
-static void prvRecursiveMutexPollingTask( void *pvParameters )
+static void prvRecursiveMutexPollingTask( void * pvParameters )
{
- /* Just to remove compiler warning. */
- ( void ) pvParameters;
-
- for( ;; )
- {
- /* Keep attempting to obtain the mutex. It should only be obtained when
- the blocking task has suspended itself, which in turn should only
- happen when the controlling task is also suspended. */
- if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
- {
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xControllingTaskHandle ) == eSuspended );
- configASSERT( eTaskGetState( xBlockingTaskHandle ) == eSuspended );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* Is the blocking task suspended? */
- if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
- {
- xErrorOccurred = pdTRUE;
- }
- else
- {
- /* Keep count of the number of cycles this task has performed
- so a stall can be detected. */
- uxPollingCycles++;
-
- /* We can resume the other tasks here even though they have a
- higher priority than the polling task. When they execute they
- will attempt to obtain the mutex but fail because the polling
- task is still the mutex holder. The polling task (this task)
- will then inherit the higher priority. The Blocking task will
- block indefinitely when it attempts to obtain the mutex, the
- Controlling task will only block for a fixed period and an
- error will be latched if the polling task has not returned the
- mutex by the time this fixed period has expired. */
- vTaskResume( xBlockingTaskHandle );
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
-
- vTaskResume( xControllingTaskHandle );
- #if( configUSE_PREEMPTION == 0 )
- taskYIELD();
- #endif
-
- /* The other two tasks should now have executed and no longer
- be suspended. */
- if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
- {
- xErrorOccurred = pdTRUE;
- }
-
- #if( INCLUDE_uxTaskPriorityGet == 1 )
- {
- /* Check priority inherited. */
- configASSERT( uxTaskPriorityGet( NULL ) == recmuCONTROLLING_TASK_PRIORITY );
- }
- #endif /* INCLUDE_uxTaskPriorityGet */
-
- #if( INCLUDE_eTaskGetState == 1 )
- {
- configASSERT( eTaskGetState( xControllingTaskHandle ) == eBlocked );
- configASSERT( eTaskGetState( xBlockingTaskHandle ) == eBlocked );
- }
- #endif /* INCLUDE_eTaskGetState */
-
- /* Release the mutex, disinheriting the higher priority again. */
- if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
- {
- xErrorOccurred = pdTRUE;
- }
-
- #if( INCLUDE_uxTaskPriorityGet == 1 )
- {
- /* Check priority disinherited. */
- configASSERT( uxTaskPriorityGet( NULL ) == recmuPOLLING_TASK_PRIORITY );
- }
- #endif /* INCLUDE_uxTaskPriorityGet */
- }
- }
-
- #if configUSE_PREEMPTION == 0
- {
- taskYIELD();
- }
- #endif
- }
+ /* Just to remove compiler warning. */
+ ( void ) pvParameters;
+
+ for( ; ; )
+ {
+ /* Keep attempting to obtain the mutex. It should only be obtained when
+ * the blocking task has suspended itself, which in turn should only
+ * happen when the controlling task is also suspended. */
+ if( xSemaphoreTakeRecursive( xMutex, recmuNO_DELAY ) == pdPASS )
+ {
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xControllingTaskHandle ) == eSuspended );
+ configASSERT( eTaskGetState( xBlockingTaskHandle ) == eSuspended );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* Is the blocking task suspended? */
+ if( ( xBlockingIsSuspended != pdTRUE ) || ( xControllingIsSuspended != pdTRUE ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ else
+ {
+ /* Keep count of the number of cycles this task has performed
+ * so a stall can be detected. */
+ uxPollingCycles++;
+
+ /* We can resume the other tasks here even though they have a
+ * higher priority than the polling task. When they execute they
+ * will attempt to obtain the mutex but fail because the polling
+ * task is still the mutex holder. The polling task (this task)
+ * will then inherit the higher priority. The Blocking task will
+ * block indefinitely when it attempts to obtain the mutex, the
+ * Controlling task will only block for a fixed period and an
+ * error will be latched if the polling task has not returned the
+ * mutex by the time this fixed period has expired. */
+ vTaskResume( xBlockingTaskHandle );
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+
+ vTaskResume( xControllingTaskHandle );
+ #if ( configUSE_PREEMPTION == 0 )
+ taskYIELD();
+ #endif
+
+ /* The other two tasks should now have executed and no longer
+ * be suspended. */
+ if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ #if ( INCLUDE_uxTaskPriorityGet == 1 )
+ {
+ /* Check priority inherited. */
+ configASSERT( uxTaskPriorityGet( NULL ) == recmuCONTROLLING_TASK_PRIORITY );
+ }
+ #endif /* INCLUDE_uxTaskPriorityGet */
+
+ #if ( INCLUDE_eTaskGetState == 1 )
+ {
+ configASSERT( eTaskGetState( xControllingTaskHandle ) == eBlocked );
+ configASSERT( eTaskGetState( xBlockingTaskHandle ) == eBlocked );
+ }
+ #endif /* INCLUDE_eTaskGetState */
+
+ /* Release the mutex, disinheriting the higher priority again. */
+ if( xSemaphoreGiveRecursive( xMutex ) != pdPASS )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+
+ #if ( INCLUDE_uxTaskPriorityGet == 1 )
+ {
+ /* Check priority disinherited. */
+ configASSERT( uxTaskPriorityGet( NULL ) == recmuPOLLING_TASK_PRIORITY );
+ }
+ #endif /* INCLUDE_uxTaskPriorityGet */
+ }
+ }
+
+ #if configUSE_PREEMPTION == 0
+ {
+ taskYIELD();
+ }
+ #endif
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreRecursiveMutexTasksStillRunning( void )
{
-BaseType_t xReturn;
-static UBaseType_t uxLastControllingCycles = 0, uxLastBlockingCycles = 0, uxLastPollingCycles = 0;
-
- /* Is the controlling task still cycling? */
- if( uxLastControllingCycles == uxControllingCycles )
- {
- xErrorOccurred = pdTRUE;
- }
- else
- {
- uxLastControllingCycles = uxControllingCycles;
- }
-
- /* Is the blocking task still cycling? */
- if( uxLastBlockingCycles == uxBlockingCycles )
- {
- xErrorOccurred = pdTRUE;
- }
- else
- {
- uxLastBlockingCycles = uxBlockingCycles;
- }
-
- /* Is the polling task still cycling? */
- if( uxLastPollingCycles == uxPollingCycles )
- {
- xErrorOccurred = pdTRUE;
- }
- else
- {
- uxLastPollingCycles = uxPollingCycles;
- }
-
- if( xErrorOccurred == pdTRUE )
- {
- xReturn = pdFAIL;
- }
- else
- {
- xReturn = pdPASS;
- }
-
- return xReturn;
+ BaseType_t xReturn;
+ static UBaseType_t uxLastControllingCycles = 0, uxLastBlockingCycles = 0, uxLastPollingCycles = 0;
+
+ /* Is the controlling task still cycling? */
+ if( uxLastControllingCycles == uxControllingCycles )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ else
+ {
+ uxLastControllingCycles = uxControllingCycles;
+ }
+
+ /* Is the blocking task still cycling? */
+ if( uxLastBlockingCycles == uxBlockingCycles )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ else
+ {
+ uxLastBlockingCycles = uxBlockingCycles;
+ }
+
+ /* Is the polling task still cycling? */
+ if( uxLastPollingCycles == uxPollingCycles )
+ {
+ xErrorOccurred = pdTRUE;
+ }
+ else
+ {
+ uxLastPollingCycles = uxPollingCycles;
+ }
+
+ if( xErrorOccurred == pdTRUE )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ xReturn = pdPASS;
+ }
+
+ return xReturn;
}
-
-
-
-
diff --git a/FreeRTOS/Demo/Common/Minimal/semtest.c b/FreeRTOS/Demo/Common/Minimal/semtest.c
index a4c006909..57504f684 100644
--- a/FreeRTOS/Demo/Common/Minimal/semtest.c
+++ b/FreeRTOS/Demo/Common/Minimal/semtest.c
@@ -60,14 +60,14 @@
#include "semtest.h"
/* The value to which the shared variables are counted. */
-#define semtstBLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xfff )
-#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xff )
+#define semtstBLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xfff )
+#define semtstNON_BLOCKING_EXPECTED_VALUE ( ( uint32_t ) 0xff )
-#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
+#define semtstSTACK_SIZE configMINIMAL_STACK_SIZE
-#define semtstNUM_TASKS ( 4 )
+#define semtstNUM_TASKS ( 4 )
-#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
+#define semtstDELAY_FACTOR ( ( TickType_t ) 10 )
/* The task function as described at the top of the file. */
static portTASK_FUNCTION_PROTO( prvSemaphoreTest, pvParameters );
@@ -75,9 +75,9 @@ static portTASK_FUNCTION_PROTO( prvSemaphoreTest, pvParameters );
/* Structure used to pass parameters to each task. */
typedef struct SEMAPHORE_PARAMETERS
{
- SemaphoreHandle_t xSemaphore;
- volatile uint32_t *pulSharedVariable;
- TickType_t xBlockTime;
+ SemaphoreHandle_t xSemaphore;
+ volatile uint32_t * pulSharedVariable;
+ TickType_t xBlockTime;
} xSemaphoreParameters;
/* Variables used to check that all the tasks are still running without errors. */
@@ -88,185 +88,185 @@ static volatile short sNextCheckVariable = 0;
void vStartSemaphoreTasks( UBaseType_t uxPriority )
{
-xSemaphoreParameters *pxFirstSemaphoreParameters, *pxSecondSemaphoreParameters;
-const TickType_t xBlockTime = ( TickType_t ) 100;
-
- /* Create the structure used to pass parameters to the first two tasks. */
- pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
-
- if( pxFirstSemaphoreParameters != NULL )
- {
- /* Create the semaphore used by the first two tasks. */
- pxFirstSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
-
- if( pxFirstSemaphoreParameters->xSemaphore != NULL )
- {
- xSemaphoreGive( pxFirstSemaphoreParameters->xSemaphore );
-
- /* Create the variable which is to be shared by the first two tasks. */
- pxFirstSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
-
- /* Initialise the share variable to the value the tasks expect. */
- *( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
-
- /* The first two tasks do not block on semaphore calls. */
- pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
-
- /* Spawn the first two tasks. As they poll they operate at the idle priority. */
- xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
- xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
-
- /* vQueueAddToRegistry() adds the semaphore to the registry, if one
- is in use. The registry is provided as a means for kernel aware
- debuggers to locate semaphores and has no purpose if a kernel aware
- debugger is not being used. The call to vQueueAddToRegistry() will
- be removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
- defined or is defined to be less than 1. */
- vQueueAddToRegistry( ( QueueHandle_t ) pxFirstSemaphoreParameters->xSemaphore, "Counting_Sem_1" );
- }
- }
-
- /* Do exactly the same to create the second set of tasks, only this time
- provide a block time for the semaphore calls. */
- pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
- if( pxSecondSemaphoreParameters != NULL )
- {
- pxSecondSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
-
- if( pxSecondSemaphoreParameters->xSemaphore != NULL )
- {
- xSemaphoreGive( pxSecondSemaphoreParameters->xSemaphore );
-
- pxSecondSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
- *( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
- pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
-
- xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
- xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
-
- /* vQueueAddToRegistry() adds the semaphore to the registry, if one
- is in use. The registry is provided as a means for kernel aware
- debuggers to locate semaphores and has no purpose if a kernel aware
- debugger is not being used. The call to vQueueAddToRegistry() will
- be removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
- defined or is defined to be less than 1. */
- vQueueAddToRegistry( ( QueueHandle_t ) pxSecondSemaphoreParameters->xSemaphore, "Counting_Sem_2" );
- }
- }
+ xSemaphoreParameters * pxFirstSemaphoreParameters, * pxSecondSemaphoreParameters;
+ const TickType_t xBlockTime = ( TickType_t ) 100;
+
+ /* Create the structure used to pass parameters to the first two tasks. */
+ pxFirstSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
+
+ if( pxFirstSemaphoreParameters != NULL )
+ {
+ /* Create the semaphore used by the first two tasks. */
+ pxFirstSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
+
+ if( pxFirstSemaphoreParameters->xSemaphore != NULL )
+ {
+ xSemaphoreGive( pxFirstSemaphoreParameters->xSemaphore );
+
+ /* Create the variable which is to be shared by the first two tasks. */
+ pxFirstSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
+
+ /* Initialise the share variable to the value the tasks expect. */
+ *( pxFirstSemaphoreParameters->pulSharedVariable ) = semtstNON_BLOCKING_EXPECTED_VALUE;
+
+ /* The first two tasks do not block on semaphore calls. */
+ pxFirstSemaphoreParameters->xBlockTime = ( TickType_t ) 0;
+
+ /* Spawn the first two tasks. As they poll they operate at the idle priority. */
+ xTaskCreate( prvSemaphoreTest, "PolSEM1", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
+ xTaskCreate( prvSemaphoreTest, "PolSEM2", semtstSTACK_SIZE, ( void * ) pxFirstSemaphoreParameters, tskIDLE_PRIORITY, ( TaskHandle_t * ) NULL );
+
+ /* vQueueAddToRegistry() adds the semaphore to the registry, if one
+ * is in use. The registry is provided as a means for kernel aware
+ * debuggers to locate semaphores and has no purpose if a kernel aware
+ * debugger is not being used. The call to vQueueAddToRegistry() will
+ * be removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
+ * defined or is defined to be less than 1. */
+ vQueueAddToRegistry( ( QueueHandle_t ) pxFirstSemaphoreParameters->xSemaphore, "Counting_Sem_1" );
+ }
+ }
+
+ /* Do exactly the same to create the second set of tasks, only this time
+ * provide a block time for the semaphore calls. */
+ pxSecondSemaphoreParameters = ( xSemaphoreParameters * ) pvPortMalloc( sizeof( xSemaphoreParameters ) );
+
+ if( pxSecondSemaphoreParameters != NULL )
+ {
+ pxSecondSemaphoreParameters->xSemaphore = xSemaphoreCreateBinary();
+
+ if( pxSecondSemaphoreParameters->xSemaphore != NULL )
+ {
+ xSemaphoreGive( pxSecondSemaphoreParameters->xSemaphore );
+
+ pxSecondSemaphoreParameters->pulSharedVariable = ( uint32_t * ) pvPortMalloc( sizeof( uint32_t ) );
+ *( pxSecondSemaphoreParameters->pulSharedVariable ) = semtstBLOCKING_EXPECTED_VALUE;
+ pxSecondSemaphoreParameters->xBlockTime = xBlockTime / portTICK_PERIOD_MS;
+
+ xTaskCreate( prvSemaphoreTest, "BlkSEM1", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
+ xTaskCreate( prvSemaphoreTest, "BlkSEM2", semtstSTACK_SIZE, ( void * ) pxSecondSemaphoreParameters, uxPriority, ( TaskHandle_t * ) NULL );
+
+ /* vQueueAddToRegistry() adds the semaphore to the registry, if one
+ * is in use. The registry is provided as a means for kernel aware
+ * debuggers to locate semaphores and has no purpose if a kernel aware
+ * debugger is not being used. The call to vQueueAddToRegistry() will
+ * be removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not
+ * defined or is defined to be less than 1. */
+ vQueueAddToRegistry( ( QueueHandle_t ) pxSecondSemaphoreParameters->xSemaphore, "Counting_Sem_2" );
+ }
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( prvSemaphoreTest, pvParameters )
{
-xSemaphoreParameters *pxParameters;
-volatile uint32_t *pulSharedVariable, ulExpectedValue;
-uint32_t ulCounter;
-short sError = pdFALSE, sCheckVariableToUse;
-
- /* See which check variable to use. sNextCheckVariable is not semaphore
- protected! */
- portENTER_CRITICAL();
- sCheckVariableToUse = sNextCheckVariable;
- sNextCheckVariable++;
- portEXIT_CRITICAL();
-
- /* A structure is passed in as the parameter. This contains the shared
- variable being guarded. */
- pxParameters = ( xSemaphoreParameters * ) pvParameters;
- pulSharedVariable = pxParameters->pulSharedVariable;
-
- /* If we are blocking we use a much higher count to ensure loads of context
- switches occur during the count. */
- if( pxParameters->xBlockTime > ( TickType_t ) 0 )
- {
- ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
- }
- else
- {
- ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
- }
-
- for( ;; )
- {
- /* Try to obtain the semaphore. */
- if( xSemaphoreTake( pxParameters->xSemaphore, pxParameters->xBlockTime ) == pdPASS )
- {
- /* We have the semaphore and so expect any other tasks using the
- shared variable to have left it in the state we expect to find
- it. */
- if( *pulSharedVariable != ulExpectedValue )
- {
- sError = pdTRUE;
- }
-
- /* Clear the variable, then count it back up to the expected value
- before releasing the semaphore. Would expect a context switch or
- two during this time. */
- for( ulCounter = ( uint32_t ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
- {
- *pulSharedVariable = ulCounter;
- if( *pulSharedVariable != ulCounter )
- {
- sError = pdTRUE;
- }
- }
-
- /* Release the semaphore, and if no errors have occurred increment the check
- variable. */
- if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
- {
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- if( sCheckVariableToUse < semtstNUM_TASKS )
- {
- ( sCheckVariables[ sCheckVariableToUse ] )++;
- }
- }
-
- /* If we have a block time then we are running at a priority higher
- than the idle priority. This task takes a long time to complete
- a cycle (deliberately so to test the guarding) so will be starving
- out lower priority tasks. Block for some time to allow give lower
- priority tasks some processor time. */
- if( pxParameters->xBlockTime != ( TickType_t ) 0 )
- {
- vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
- }
-
- }
- else
- {
- if( pxParameters->xBlockTime == ( TickType_t ) 0 )
- {
- /* We have not got the semaphore yet, so no point using the
- processor. We are not blocking when attempting to obtain the
- semaphore. */
- taskYIELD();
- }
- }
- }
+ xSemaphoreParameters * pxParameters;
+ volatile uint32_t * pulSharedVariable, ulExpectedValue;
+ uint32_t ulCounter;
+ short sError = pdFALSE, sCheckVariableToUse;
+
+ /* See which check variable to use. sNextCheckVariable is not semaphore
+ * protected! */
+ portENTER_CRITICAL();
+ sCheckVariableToUse = sNextCheckVariable;
+ sNextCheckVariable++;
+ portEXIT_CRITICAL();
+
+ /* A structure is passed in as the parameter. This contains the shared
+ * variable being guarded. */
+ pxParameters = ( xSemaphoreParameters * ) pvParameters;
+ pulSharedVariable = pxParameters->pulSharedVariable;
+
+ /* If we are blocking we use a much higher count to ensure loads of context
+ * switches occur during the count. */
+ if( pxParameters->xBlockTime > ( TickType_t ) 0 )
+ {
+ ulExpectedValue = semtstBLOCKING_EXPECTED_VALUE;
+ }
+ else
+ {
+ ulExpectedValue = semtstNON_BLOCKING_EXPECTED_VALUE;
+ }
+
+ for( ; ; )
+ {
+ /* Try to obtain the semaphore. */
+ if( xSemaphoreTake( pxParameters->xSemaphore, pxParameters->xBlockTime ) == pdPASS )
+ {
+ /* We have the semaphore and so expect any other tasks using the
+ * shared variable to have left it in the state we expect to find
+ * it. */
+ if( *pulSharedVariable != ulExpectedValue )
+ {
+ sError = pdTRUE;
+ }
+
+ /* Clear the variable, then count it back up to the expected value
+ * before releasing the semaphore. Would expect a context switch or
+ * two during this time. */
+ for( ulCounter = ( uint32_t ) 0; ulCounter <= ulExpectedValue; ulCounter++ )
+ {
+ *pulSharedVariable = ulCounter;
+
+ if( *pulSharedVariable != ulCounter )
+ {
+ sError = pdTRUE;
+ }
+ }
+
+ /* Release the semaphore, and if no errors have occurred increment the check
+ * variable. */
+ if( xSemaphoreGive( pxParameters->xSemaphore ) == pdFALSE )
+ {
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ if( sCheckVariableToUse < semtstNUM_TASKS )
+ {
+ ( sCheckVariables[ sCheckVariableToUse ] )++;
+ }
+ }
+
+ /* If we have a block time then we are running at a priority higher
+ * than the idle priority. This task takes a long time to complete
+ * a cycle (deliberately so to test the guarding) so will be starving
+ * out lower priority tasks. Block for some time to allow give lower
+ * priority tasks some processor time. */
+ if( pxParameters->xBlockTime != ( TickType_t ) 0 )
+ {
+ vTaskDelay( pxParameters->xBlockTime * semtstDELAY_FACTOR );
+ }
+ }
+ else
+ {
+ if( pxParameters->xBlockTime == ( TickType_t ) 0 )
+ {
+ /* We have not got the semaphore yet, so no point using the
+ * processor. We are not blocking when attempting to obtain the
+ * semaphore. */
+ taskYIELD();
+ }
+ }
+ }
}
/*-----------------------------------------------------------*/
/* This is called to check that all the created tasks are still running. */
BaseType_t xAreSemaphoreTasksStillRunning( void )
{
-static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
-BaseType_t xTask, xReturn = pdTRUE;
+ static short sLastCheckVariables[ semtstNUM_TASKS ] = { 0 };
+ BaseType_t xTask, xReturn = pdTRUE;
- for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
- {
- if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
- {
- xReturn = pdFALSE;
- }
+ for( xTask = 0; xTask < semtstNUM_TASKS; xTask++ )
+ {
+ if( sLastCheckVariables[ xTask ] == sCheckVariables[ xTask ] )
+ {
+ xReturn = pdFALSE;
+ }
- sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
- }
+ sLastCheckVariables[ xTask ] = sCheckVariables[ xTask ];
+ }
- return xReturn;
+ return xReturn;
}
-
diff --git a/FreeRTOS/Demo/Common/Minimal/sp_flop.c b/FreeRTOS/Demo/Common/Minimal/sp_flop.c
index 725e603ce..faf7b44f4 100644
--- a/FreeRTOS/Demo/Common/Minimal/sp_flop.c
+++ b/FreeRTOS/Demo/Common/Minimal/sp_flop.c
@@ -48,254 +48,255 @@
/* Demo program include files. */
#include "flop.h"
-#define mathSTACK_SIZE configMINIMAL_STACK_SIZE
-#define mathNUMBER_OF_TASKS ( 8 )
+#define mathSTACK_SIZE configMINIMAL_STACK_SIZE
+#define mathNUMBER_OF_TASKS ( 8 )
/* Four tasks, each of which performs a different floating point calculation.
-Each of the four is created twice. */
+ * Each of the four is created twice. */
static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
/* These variables are used to check that all the tasks are still running. If a
-task gets a calculation wrong it will
-stop incrementing its check variable. */
+ * task gets a calculation wrong it will
+ * stop incrementing its check variable. */
static volatile uint16_t usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
/*-----------------------------------------------------------*/
void vStartMathTasks( UBaseType_t uxPriority )
{
- xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
- xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
+ xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
{
-volatile float f1, f2, f3, f4;
-volatile uint16_t *pusTaskCheckVariable;
-volatile float fAnswer;
-short sError = pdFALSE;
-
- f1 = 123.4567F;
- f2 = 2345.6789F;
- f3 = -918.222F;
-
- fAnswer = ( f1 + f2 ) * f3;
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( uint16_t * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for(;;)
- {
- f1 = 123.4567F;
- f2 = 2345.6789F;
- f3 = -918.222F;
-
- f4 = ( f1 + f2 ) * f3;
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( fabs( f4 - fAnswer ) > 0.001F )
- {
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- }
+ volatile float f1, f2, f3, f4;
+ volatile uint16_t * pusTaskCheckVariable;
+ volatile float fAnswer;
+ short sError = pdFALSE;
+
+ f1 = 123.4567F;
+ f2 = 2345.6789F;
+ f3 = -918.222F;
+
+ fAnswer = ( f1 + f2 ) * f3;
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( uint16_t * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ f1 = 123.4567F;
+ f2 = 2345.6789F;
+ f3 = -918.222F;
+
+ f4 = ( f1 + f2 ) * f3;
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( fabs( f4 - fAnswer ) > 0.001F )
+ {
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
{
-volatile float f1, f2, f3, f4;
-volatile uint16_t *pusTaskCheckVariable;
-volatile float fAnswer;
-short sError = pdFALSE;
-
- f1 = -389.38F;
- f2 = 32498.2F;
- f3 = -2.0001F;
-
- fAnswer = ( f1 / f2 ) * f3;
-
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( uint16_t * ) pvParameters;
-
- /* Keep performing a calculation and checking the result against a constant. */
- for( ;; )
- {
- f1 = -389.38F;
- f2 = 32498.2F;
- f3 = -2.0001F;
-
- f4 = ( f1 / f2 ) * f3;
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- /* If the calculation does not match the expected constant, stop the
- increment of the check variable. */
- if( fabs( f4 - fAnswer ) > 0.001F )
- {
- sError = pdTRUE;
- }
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know
- this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
- }
+ volatile float f1, f2, f3, f4;
+ volatile uint16_t * pusTaskCheckVariable;
+ volatile float fAnswer;
+ short sError = pdFALSE;
+
+ f1 = -389.38F;
+ f2 = 32498.2F;
+ f3 = -2.0001F;
+
+ fAnswer = ( f1 / f2 ) * f3;
+
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( uint16_t * ) pvParameters;
+
+ /* Keep performing a calculation and checking the result against a constant. */
+ for( ; ; )
+ {
+ f1 = -389.38F;
+ f2 = 32498.2F;
+ f3 = -2.0001F;
+
+ f4 = ( f1 / f2 ) * f3;
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ /* If the calculation does not match the expected constant, stop the
+ * increment of the check variable. */
+ if( fabs( f4 - fAnswer ) > 0.001F )
+ {
+ sError = pdTRUE;
+ }
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know
+ * this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
{
-volatile float *pfArray, fTotal1, fTotal2, fDifference, fPosition;
-volatile uint16_t *pusTaskCheckVariable;
-const size_t xArraySize = 10;
-size_t xPosition;
-short sError = pdFALSE;
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( uint16_t * ) pvParameters;
-
- pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
-
- /* Keep filling an array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- fTotal1 = 0.0F;
- fTotal2 = 0.0F;
- fPosition = 0.0F;
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- pfArray[ xPosition ] = fPosition + 5.5F;
- fTotal1 += fPosition + 5.5F;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- fTotal2 += pfArray[ xPosition ];
- }
-
- fDifference = fTotal1 - fTotal2;
- if( fabs( fDifference ) > 0.001F )
- {
- sError = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ volatile float * pfArray, fTotal1, fTotal2, fDifference, fPosition;
+ volatile uint16_t * pusTaskCheckVariable;
+ const size_t xArraySize = 10;
+ size_t xPosition;
+ short sError = pdFALSE;
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( uint16_t * ) pvParameters;
+
+ pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
+
+ /* Keep filling an array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ fTotal1 = 0.0F;
+ fTotal2 = 0.0F;
+ fPosition = 0.0F;
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ pfArray[ xPosition ] = fPosition + 5.5F;
+ fTotal1 += fPosition + 5.5F;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ fTotal2 += pfArray[ xPosition ];
+ }
+
+ fDifference = fTotal1 - fTotal2;
+
+ if( fabs( fDifference ) > 0.001F )
+ {
+ sError = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
{
-volatile float *pfArray, fTotal1, fTotal2, fDifference, fPosition;
-volatile uint16_t *pusTaskCheckVariable;
-const size_t xArraySize = 10;
-size_t xPosition;
-short sError = pdFALSE;
-
- /* The variable this task increments to show it is still running is passed in
- as the parameter. */
- pusTaskCheckVariable = ( uint16_t * ) pvParameters;
-
- pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
-
- /* Keep filling an array, keeping a running total of the values placed in the
- array. Then run through the array adding up all the values. If the two totals
- do not match, stop the check variable from incrementing. */
- for( ;; )
- {
- fTotal1 = 0.0F;
- fTotal2 = 0.0F;
- fPosition = 0.0F;
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- pfArray[ xPosition ] = fPosition * 12.123F;
- fTotal1 += fPosition * 12.123F;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- for( xPosition = 0; xPosition < xArraySize; xPosition++ )
- {
- fTotal2 += pfArray[ xPosition ];
- }
-
- fDifference = fTotal1 - fTotal2;
- if( fabs( fDifference ) > 0.001F )
- {
- sError = pdTRUE;
- }
-
- #if configUSE_PREEMPTION == 0
- taskYIELD();
- #endif
-
- if( sError == pdFALSE )
- {
- /* If the calculation has always been correct, increment the check
- variable so we know this task is still running okay. */
- ( *pusTaskCheckVariable )++;
- }
- }
+ volatile float * pfArray, fTotal1, fTotal2, fDifference, fPosition;
+ volatile uint16_t * pusTaskCheckVariable;
+ const size_t xArraySize = 10;
+ size_t xPosition;
+ short sError = pdFALSE;
+
+ /* The variable this task increments to show it is still running is passed in
+ * as the parameter. */
+ pusTaskCheckVariable = ( uint16_t * ) pvParameters;
+
+ pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
+
+ /* Keep filling an array, keeping a running total of the values placed in the
+ * array. Then run through the array adding up all the values. If the two totals
+ * do not match, stop the check variable from incrementing. */
+ for( ; ; )
+ {
+ fTotal1 = 0.0F;
+ fTotal2 = 0.0F;
+ fPosition = 0.0F;
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ pfArray[ xPosition ] = fPosition * 12.123F;
+ fTotal1 += fPosition * 12.123F;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ for( xPosition = 0; xPosition < xArraySize; xPosition++ )
+ {
+ fTotal2 += pfArray[ xPosition ];
+ }
+
+ fDifference = fTotal1 - fTotal2;
+
+ if( fabs( fDifference ) > 0.001F )
+ {
+ sError = pdTRUE;
+ }
+
+ #if configUSE_PREEMPTION == 0
+ taskYIELD();
+ #endif
+
+ if( sError == pdFALSE )
+ {
+ /* If the calculation has always been correct, increment the check
+ * variable so we know this task is still running okay. */
+ ( *pusTaskCheckVariable )++;
+ }
+ }
}
/*-----------------------------------------------------------*/
@@ -303,25 +304,22 @@ short sError = pdFALSE;
BaseType_t xAreMathsTaskStillRunning( void )
{
/* Keep a history of the check variables so we know if they have been incremented
-since the last call. */
-static uint16_t usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
-BaseType_t xReturn = pdTRUE, xTask;
-
- /* Check the maths tasks are still running by ensuring their check variables
- are still incrementing. */
- for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
- {
- if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
- {
- /* The check has not incremented so an error exists. */
- xReturn = pdFALSE;
- }
-
- usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
- }
-
- return xReturn;
+ * since the last call. */
+ static uint16_t usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
+ BaseType_t xReturn = pdTRUE, xTask;
+
+ /* Check the maths tasks are still running by ensuring their check variables
+ * are still incrementing. */
+ for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
+ {
+ if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
+ {
+ /* The check has not incremented so an error exists. */
+ xReturn = pdFALSE;
+ }
+
+ usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
+ }
+
+ return xReturn;
}
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/AbortDelay.h b/FreeRTOS/Demo/Common/include/AbortDelay.h
index 5324e1481..db2e5269d 100644
--- a/FreeRTOS/Demo/Common/include/AbortDelay.h
+++ b/FreeRTOS/Demo/Common/include/AbortDelay.h
@@ -32,5 +32,3 @@ void vCreateAbortDelayTasks( void );
BaseType_t xAreAbortDelayTestTasksStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/BlockQ.h b/FreeRTOS/Demo/Common/include/BlockQ.h
index 621d42b7e..42ec77386 100644
--- a/FreeRTOS/Demo/Common/include/BlockQ.h
+++ b/FreeRTOS/Demo/Common/include/BlockQ.h
@@ -32,5 +32,3 @@ void vStartBlockingQueueTasks( UBaseType_t uxPriority );
BaseType_t xAreBlockingQueuesStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/EventGroupsDemo.h b/FreeRTOS/Demo/Common/include/EventGroupsDemo.h
index 71f6503ef..a21cfc30e 100644
--- a/FreeRTOS/Demo/Common/include/EventGroupsDemo.h
+++ b/FreeRTOS/Demo/Common/include/EventGroupsDemo.h
@@ -41,4 +41,3 @@ BaseType_t xAreEventGroupTasksStillRunning( void );
void vPeriodicEventGroupsProcessing( void );
#endif /* EVENT_GROUPS_DEMO_H */
-
diff --git a/FreeRTOS/Demo/Common/include/GenQTest.h b/FreeRTOS/Demo/Common/include/GenQTest.h
index 400ea28f7..7c74b07af 100644
--- a/FreeRTOS/Demo/Common/include/GenQTest.h
+++ b/FreeRTOS/Demo/Common/include/GenQTest.h
@@ -33,6 +33,3 @@ BaseType_t xAreGenericQueueTasksStillRunning( void );
void vMutexISRInteractionTest( void );
#endif /* GEN_Q_TEST_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/IntQueue.h b/FreeRTOS/Demo/Common/include/IntQueue.h
index bd4a0f962..5713bee9b 100644
--- a/FreeRTOS/Demo/Common/include/IntQueue.h
+++ b/FreeRTOS/Demo/Common/include/IntQueue.h
@@ -34,9 +34,3 @@ BaseType_t xFirstTimerHandler( void );
BaseType_t xSecondTimerHandler( void );
#endif /* QUEUE_ACCESS_TEST */
-
-
-
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/IntSemTest.h b/FreeRTOS/Demo/Common/include/IntSemTest.h
index 26c26b1c7..7cebd5855 100644
--- a/FreeRTOS/Demo/Common/include/IntSemTest.h
+++ b/FreeRTOS/Demo/Common/include/IntSemTest.h
@@ -33,6 +33,3 @@ BaseType_t xAreInterruptSemaphoreTasksStillRunning( void );
void vInterruptSemaphorePeriodicTest( void );
#endif /* INT_SEM_TEST_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/MessageBufferDemo.h b/FreeRTOS/Demo/Common/include/MessageBufferDemo.h
index 0fabd67dc..7080dd60a 100644
--- a/FreeRTOS/Demo/Common/include/MessageBufferDemo.h
+++ b/FreeRTOS/Demo/Common/include/MessageBufferDemo.h
@@ -28,10 +28,7 @@
#ifndef MESSAGE_BUFFER_TEST_H
#define MESSAGE_BUFFER_TEST_H
-void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize );
+void vStartMessageBufferTasks( configSTACK_DEPTH_TYPE xStackSize );
BaseType_t xAreMessageBufferTasksStillRunning( void );
#endif /* MESSAGE_BUFFER_TEST_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/PollQ.h b/FreeRTOS/Demo/Common/include/PollQ.h
index c5da3f615..e499c9cb5 100644
--- a/FreeRTOS/Demo/Common/include/PollQ.h
+++ b/FreeRTOS/Demo/Common/include/PollQ.h
@@ -32,5 +32,3 @@ void vStartPolledQueueTasks( UBaseType_t uxPriority );
BaseType_t xArePollingQueuesStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/QPeek.h b/FreeRTOS/Demo/Common/include/QPeek.h
index ddf6c7a65..8c83f8a36 100644
--- a/FreeRTOS/Demo/Common/include/QPeek.h
+++ b/FreeRTOS/Demo/Common/include/QPeek.h
@@ -32,6 +32,3 @@ void vStartQueuePeekTasks( void );
BaseType_t xAreQueuePeekTasksStillRunning( void );
#endif /* Q_PEEK_TEST_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/QueueOverwrite.h b/FreeRTOS/Demo/Common/include/QueueOverwrite.h
index 5315afb48..c4a0c77e8 100644
--- a/FreeRTOS/Demo/Common/include/QueueOverwrite.h
+++ b/FreeRTOS/Demo/Common/include/QueueOverwrite.h
@@ -33,5 +33,3 @@ BaseType_t xIsQueueOverwriteTaskStillRunning( void );
void vQueueOverwritePeriodicISRDemo( void );
#endif /* QUEUE_OVERWRITE_H */
-
-
diff --git a/FreeRTOS/Demo/Common/include/QueueSet.h b/FreeRTOS/Demo/Common/include/QueueSet.h
index fdc7691e4..b5ff61f92 100644
--- a/FreeRTOS/Demo/Common/include/QueueSet.h
+++ b/FreeRTOS/Demo/Common/include/QueueSet.h
@@ -33,5 +33,3 @@ BaseType_t xAreQueueSetTasksStillRunning( void );
void vQueueSetAccessQueueSetFromISR( void );
#endif /* QUEUE_WAIT_MULTIPLE_H */
-
-
diff --git a/FreeRTOS/Demo/Common/include/QueueSetPolling.h b/FreeRTOS/Demo/Common/include/QueueSetPolling.h
index 65d366668..004e1d052 100644
--- a/FreeRTOS/Demo/Common/include/QueueSetPolling.h
+++ b/FreeRTOS/Demo/Common/include/QueueSetPolling.h
@@ -33,5 +33,3 @@ BaseType_t xAreQueueSetPollTasksStillRunning( void );
void vQueueSetPollingInterruptAccess( void );
#endif /* QUEUE_SET_POLLING_H */
-
-
diff --git a/FreeRTOS/Demo/Common/include/StaticAllocation.h b/FreeRTOS/Demo/Common/include/StaticAllocation.h
index 79d682d20..9ef3290e2 100644
--- a/FreeRTOS/Demo/Common/include/StaticAllocation.h
+++ b/FreeRTOS/Demo/Common/include/StaticAllocation.h
@@ -28,10 +28,7 @@
#ifndef STATIC_ALLOCATION_H
#define STATIC_ALLOCATION_H
-void vStartStaticallyAllocatedTasks( void );
+void vStartStaticallyAllocatedTasks( void );
BaseType_t xAreStaticAllocationTasksStillRunning( void );
#endif /* STATIC_ALLOCATION_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/StreamBufferDemo.h b/FreeRTOS/Demo/Common/include/StreamBufferDemo.h
index 33be223cb..f438db274 100644
--- a/FreeRTOS/Demo/Common/include/StreamBufferDemo.h
+++ b/FreeRTOS/Demo/Common/include/StreamBufferDemo.h
@@ -33,6 +33,3 @@ BaseType_t xAreStreamBufferTasksStillRunning( void );
void vPeriodicStreamBufferProcessing( void );
#endif /* STREAM_BUFFER_TEST_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/TaskNotify.h b/FreeRTOS/Demo/Common/include/TaskNotify.h
index 911633e51..5298df0cd 100644
--- a/FreeRTOS/Demo/Common/include/TaskNotify.h
+++ b/FreeRTOS/Demo/Common/include/TaskNotify.h
@@ -28,11 +28,8 @@
#ifndef TASK_NOTIFY_H
#define TASK_NOTIFY_H
-void vStartTaskNotifyTask( void );
+void vStartTaskNotifyTask( void );
BaseType_t xAreTaskNotificationTasksStillRunning( void );
void xNotifyTaskFromISR( void );
#endif /* TASK_NOTIFY_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/TaskNotifyArray.h b/FreeRTOS/Demo/Common/include/TaskNotifyArray.h
index c4aefe5cc..396429ae0 100644
--- a/FreeRTOS/Demo/Common/include/TaskNotifyArray.h
+++ b/FreeRTOS/Demo/Common/include/TaskNotifyArray.h
@@ -28,11 +28,8 @@
#ifndef TASK_NOTIFY_ARRAY_H
#define TASK_NOTIFY_ARRAY_H
-void vStartTaskNotifyArrayTask( void );
+void vStartTaskNotifyArrayTask( void );
BaseType_t xAreTaskNotificationArrayTasksStillRunning( void );
void xNotifyArrayTaskFromISR( void );
#endif /* TASK_NOTIFY_ARRAY_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/TimerDemo.h b/FreeRTOS/Demo/Common/include/TimerDemo.h
index 368c69124..6c60e1c85 100644
--- a/FreeRTOS/Demo/Common/include/TimerDemo.h
+++ b/FreeRTOS/Demo/Common/include/TimerDemo.h
@@ -33,6 +33,3 @@ void vTimerPeriodicISRTests( void );
void vTimerDemoIncludeBacklogTests( BaseType_t includeBacklogTests );
#endif /* TIMER_DEMO_H */
-
-
-
diff --git a/FreeRTOS/Demo/Common/include/blocktim.h b/FreeRTOS/Demo/Common/include/blocktim.h
index 8ca7fa9ed..a6f6f845d 100644
--- a/FreeRTOS/Demo/Common/include/blocktim.h
+++ b/FreeRTOS/Demo/Common/include/blocktim.h
@@ -32,5 +32,3 @@ void vCreateBlockTimeTasks( void );
BaseType_t xAreBlockTimeTestTasksStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/comtest.h b/FreeRTOS/Demo/Common/include/comtest.h
index 1656f0e3b..a41015956 100644
--- a/FreeRTOS/Demo/Common/include/comtest.h
+++ b/FreeRTOS/Demo/Common/include/comtest.h
@@ -28,10 +28,13 @@
#ifndef COMTEST_H
#define COMTEST_H
-void vAltStartComTestTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED );
-void vStartComTestTasks( UBaseType_t uxPriority, eCOMPort ePort, eBaud eBaudRate );
+void vAltStartComTestTasks( UBaseType_t uxPriority,
+ uint32_t ulBaudRate,
+ UBaseType_t uxLED );
+void vStartComTestTasks( UBaseType_t uxPriority,
+ eCOMPort ePort,
+ eBaud eBaudRate );
BaseType_t xAreComTestTasksStillRunning( void );
void vComTestUnsuspendTask( void );
-#endif
-
+#endif /* ifndef COMTEST_H */
diff --git a/FreeRTOS/Demo/Common/include/comtest2.h b/FreeRTOS/Demo/Common/include/comtest2.h
index 0a6ec2694..e2867bc70 100644
--- a/FreeRTOS/Demo/Common/include/comtest2.h
+++ b/FreeRTOS/Demo/Common/include/comtest2.h
@@ -28,8 +28,9 @@
#ifndef COMTEST_H
#define COMTEST_H
-void vAltStartComTestTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED );
+void vAltStartComTestTasks( UBaseType_t uxPriority,
+ uint32_t ulBaudRate,
+ UBaseType_t uxLED );
BaseType_t xAreComTestTasksStillRunning( void );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/comtest_strings.h b/FreeRTOS/Demo/Common/include/comtest_strings.h
index 8a69bddaf..be2c8c9d3 100644
--- a/FreeRTOS/Demo/Common/include/comtest_strings.h
+++ b/FreeRTOS/Demo/Common/include/comtest_strings.h
@@ -28,8 +28,9 @@
#ifndef COMTEST_STRINGS_H
#define COMTEST_STRINGS_H
-void vStartComTestStringsTasks( UBaseType_t uxPriority, uint32_t ulBaudRate, UBaseType_t uxLED );
+void vStartComTestStringsTasks( UBaseType_t uxPriority,
+ uint32_t ulBaudRate,
+ UBaseType_t uxLED );
BaseType_t xAreComTestTasksStillRunning( void );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/countsem.h b/FreeRTOS/Demo/Common/include/countsem.h
index 3457494b3..2727c9d83 100644
--- a/FreeRTOS/Demo/Common/include/countsem.h
+++ b/FreeRTOS/Demo/Common/include/countsem.h
@@ -32,4 +32,3 @@ void vStartCountingSemaphoreTasks( void );
BaseType_t xAreCountingSemaphoreTasksStillRunning( void );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/crflash.h b/FreeRTOS/Demo/Common/include/crflash.h
index 280bfce0e..9708df844 100644
--- a/FreeRTOS/Demo/Common/include/crflash.h
+++ b/FreeRTOS/Demo/Common/include/crflash.h
@@ -44,4 +44,3 @@ void vStartFlashCoRoutines( UBaseType_t uxPriority );
BaseType_t xAreFlashCoRoutinesStillRunning( void );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/crhook.h b/FreeRTOS/Demo/Common/include/crhook.h
index d35fd0d0e..d36066d01 100644
--- a/FreeRTOS/Demo/Common/include/crhook.h
+++ b/FreeRTOS/Demo/Common/include/crhook.h
@@ -40,4 +40,3 @@ void vStartHookCoRoutines( void );
BaseType_t xAreHookCoRoutinesStillRunning( void );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/death.h b/FreeRTOS/Demo/Common/include/death.h
index 3ca466108..6c98d3e74 100644
--- a/FreeRTOS/Demo/Common/include/death.h
+++ b/FreeRTOS/Demo/Common/include/death.h
@@ -32,5 +32,3 @@ void vCreateSuicidalTasks( UBaseType_t uxPriority );
BaseType_t xIsCreateTaskStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/dynamic.h b/FreeRTOS/Demo/Common/include/dynamic.h
index 904c32371..fcb64581a 100644
--- a/FreeRTOS/Demo/Common/include/dynamic.h
+++ b/FreeRTOS/Demo/Common/include/dynamic.h
@@ -32,5 +32,3 @@ void vStartDynamicPriorityTasks( void );
BaseType_t xAreDynamicPriorityTasksStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/fileIO.h b/FreeRTOS/Demo/Common/include/fileIO.h
index 077d9c55d..a86afdfab 100644
--- a/FreeRTOS/Demo/Common/include/fileIO.h
+++ b/FreeRTOS/Demo/Common/include/fileIO.h
@@ -30,7 +30,7 @@
void vDisplayMessage( const char * const pcMessageToPrint );
void vWriteMessageToDisk( const char * const pcMessage );
-void vWriteBufferToDisk( const char * const pcBuffer, uint32_t ulBufferLength );
+void vWriteBufferToDisk( const char * const pcBuffer,
+ uint32_t ulBufferLength );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/flash.h b/FreeRTOS/Demo/Common/include/flash.h
index e7e76194a..861ed6ccf 100644
--- a/FreeRTOS/Demo/Common/include/flash.h
+++ b/FreeRTOS/Demo/Common/include/flash.h
@@ -31,4 +31,3 @@
void vStartLEDFlashTasks( UBaseType_t uxPriority );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/flash_timer.h b/FreeRTOS/Demo/Common/include/flash_timer.h
index f3765c0b8..2504438c1 100644
--- a/FreeRTOS/Demo/Common/include/flash_timer.h
+++ b/FreeRTOS/Demo/Common/include/flash_timer.h
@@ -30,7 +30,7 @@
/*
* Creates the LED flashing timers. xNumberOfLEDs specifies how many timers to
- * create, with each timer toggling a different LED. The first LED to be
+ * create, with each timer toggling a different LED. The first LED to be
* toggled is LED 0, with subsequent LEDs following on in numerical order. Each
* timer uses the exact same callback function, with the timer ID being used
* within the callback function to determine which timer has actually expired
diff --git a/FreeRTOS/Demo/Common/include/flop.h b/FreeRTOS/Demo/Common/include/flop.h
index c2d6eeaac..f77a5f90a 100644
--- a/FreeRTOS/Demo/Common/include/flop.h
+++ b/FreeRTOS/Demo/Common/include/flop.h
@@ -32,5 +32,3 @@ void vStartMathTasks( UBaseType_t uxPriority );
BaseType_t xAreMathsTaskStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/integer.h b/FreeRTOS/Demo/Common/include/integer.h
index a4b362410..d3ecbd37a 100644
--- a/FreeRTOS/Demo/Common/include/integer.h
+++ b/FreeRTOS/Demo/Common/include/integer.h
@@ -32,5 +32,3 @@ void vStartIntegerMathTasks( UBaseType_t uxPriority );
BaseType_t xAreIntegerMathsTaskStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/mevents.h b/FreeRTOS/Demo/Common/include/mevents.h
index 3b5177655..ce0ec8678 100644
--- a/FreeRTOS/Demo/Common/include/mevents.h
+++ b/FreeRTOS/Demo/Common/include/mevents.h
@@ -32,5 +32,3 @@ void vStartMultiEventTasks( void );
BaseType_t xAreMultiEventTasksStillRunning( void );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/partest.h b/FreeRTOS/Demo/Common/include/partest.h
index 8605bcdfd..4577a6e82 100644
--- a/FreeRTOS/Demo/Common/include/partest.h
+++ b/FreeRTOS/Demo/Common/include/partest.h
@@ -28,11 +28,11 @@
#ifndef PARTEST_H
#define PARTEST_H
-#define partstDEFAULT_PORT_ADDRESS ( ( uint16_t ) 0x378 )
+#define partstDEFAULT_PORT_ADDRESS ( ( uint16_t ) 0x378 )
void vParTestInitialise( void );
-void vParTestSetLED( UBaseType_t uxLED, BaseType_t xValue );
+void vParTestSetLED( UBaseType_t uxLED,
+ BaseType_t xValue );
void vParTestToggleLED( UBaseType_t uxLED );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/print.h b/FreeRTOS/Demo/Common/include/print.h
index daa49a884..40db8b592 100644
--- a/FreeRTOS/Demo/Common/include/print.h
+++ b/FreeRTOS/Demo/Common/include/print.h
@@ -30,8 +30,6 @@
void vPrintInitialise( void );
void vPrintDisplayMessage( const char * const * pcMessageToSend );
-const char *pcPrintGetNextMessage( TickType_t xPrintRate );
+const char * pcPrintGetNextMessage( TickType_t xPrintRate );
#endif
-
-
diff --git a/FreeRTOS/Demo/Common/include/recmutex.h b/FreeRTOS/Demo/Common/include/recmutex.h
index a0357888b..5b2ab28dd 100644
--- a/FreeRTOS/Demo/Common/include/recmutex.h
+++ b/FreeRTOS/Demo/Common/include/recmutex.h
@@ -32,4 +32,3 @@ void vStartRecursiveMutexTasks( void );
BaseType_t xAreRecursiveMutexTasksStillRunning( void );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/semtest.h b/FreeRTOS/Demo/Common/include/semtest.h
index faf9519b0..096f1690a 100644
--- a/FreeRTOS/Demo/Common/include/semtest.h
+++ b/FreeRTOS/Demo/Common/include/semtest.h
@@ -32,4 +32,3 @@ void vStartSemaphoreTasks( UBaseType_t uxPriority );
BaseType_t xAreSemaphoreTasksStillRunning( void );
#endif
-
diff --git a/FreeRTOS/Demo/Common/include/serial.h b/FreeRTOS/Demo/Common/include/serial.h
index de8dfb32f..351d5ab82 100644
--- a/FreeRTOS/Demo/Common/include/serial.h
+++ b/FreeRTOS/Demo/Common/include/serial.h
@@ -31,68 +31,79 @@
typedef void * xComPortHandle;
typedef enum
-{
- serCOM1,
- serCOM2,
- serCOM3,
- serCOM4,
- serCOM5,
- serCOM6,
- serCOM7,
- serCOM8
+{
+ serCOM1,
+ serCOM2,
+ serCOM3,
+ serCOM4,
+ serCOM5,
+ serCOM6,
+ serCOM7,
+ serCOM8
} eCOMPort;
-typedef enum
-{
- serNO_PARITY,
- serODD_PARITY,
- serEVEN_PARITY,
- serMARK_PARITY,
- serSPACE_PARITY
+typedef enum
+{
+ serNO_PARITY,
+ serODD_PARITY,
+ serEVEN_PARITY,
+ serMARK_PARITY,
+ serSPACE_PARITY
} eParity;
-typedef enum
-{
- serSTOP_1,
- serSTOP_2
+typedef enum
+{
+ serSTOP_1,
+ serSTOP_2
} eStopBits;
-typedef enum
-{
- serBITS_5,
- serBITS_6,
- serBITS_7,
- serBITS_8
+typedef enum
+{
+ serBITS_5,
+ serBITS_6,
+ serBITS_7,
+ serBITS_8
} eDataBits;
-typedef enum
-{
- ser50,
- ser75,
- ser110,
- ser134,
- ser150,
- ser200,
- ser300,
- ser600,
- ser1200,
- ser1800,
- ser2400,
- ser4800,
- ser9600,
- ser19200,
- ser38400,
- ser57600,
- ser115200
+typedef enum
+{
+ ser50,
+ ser75,
+ ser110,
+ ser134,
+ ser150,
+ ser200,
+ ser300,
+ ser600,
+ ser1200,
+ ser1800,
+ ser2400,
+ ser4800,
+ ser9600,
+ ser19200,
+ ser38400,
+ ser57600,
+ ser115200
} eBaud;
-xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength );
-xComPortHandle xSerialPortInit( eCOMPort ePort, eBaud eWantedBaud, eParity eWantedParity, eDataBits eWantedDataBits, eStopBits eWantedStopBits, unsigned portBASE_TYPE uxBufferLength );
-void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength );
-signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort, signed char *pcRxedChar, TickType_t xBlockTime );
-signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime );
+xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud,
+ unsigned portBASE_TYPE uxQueueLength );
+xComPortHandle xSerialPortInit( eCOMPort ePort,
+ eBaud eWantedBaud,
+ eParity eWantedParity,
+ eDataBits eWantedDataBits,
+ eStopBits eWantedStopBits,
+ unsigned portBASE_TYPE uxBufferLength );
+void vSerialPutString( xComPortHandle pxPort,
+ const signed char * const pcString,
+ unsigned short usStringLength );
+signed portBASE_TYPE xSerialGetChar( xComPortHandle pxPort,
+ signed char * pcRxedChar,
+ TickType_t xBlockTime );
+signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort,
+ signed char cOutChar,
+ TickType_t xBlockTime );
portBASE_TYPE xSerialWaitForSemaphore( xComPortHandle xPort );
void vSerialClose( xComPortHandle xPort );
-#endif
-
+#endif /* ifndef SERIAL_COMMS_H */
diff --git a/FreeRTOS/README.md b/FreeRTOS/README.md
index 36f69f460..c5dd0890f 100644
--- a/FreeRTOS/README.md
+++ b/FreeRTOS/README.md
@@ -10,10 +10,10 @@ FreeRTOS port, and contains its own readme file.
See [FreeRTOS/SourceOrganization](http://www.freertos.org/a00017.html) for full details of the directory structure and information on locating the files you require.
-The easiest way to use FreeRTOS is to start with one of the pre-configured demo
-application projects (found in the FreeRTOS/Demo directory). That way you will
+The easiest way to use FreeRTOS is to start with one of the pre-configured demo
+ application projects (found in the FreeRTOS/Demo directory). That way you will
have the correct FreeRTOS source files included, and the correct include paths
-configured.
+configured.
Once a demo application is building and executing you can remove
the demo application file, and start to add in your own application source
files.
diff --git a/FreeRTOS/Test/CBMC/include/aws_freertos_ip_verification_access_ip_define.h b/FreeRTOS/Test/CBMC/include/aws_freertos_ip_verification_access_ip_define.h
index 22434a91c..f238af08d 100644
--- a/FreeRTOS/Test/CBMC/include/aws_freertos_ip_verification_access_ip_define.h
+++ b/FreeRTOS/Test/CBMC/include/aws_freertos_ip_verification_access_ip_define.h
@@ -1,3 +1,5 @@
-eFrameProcessingResult_t publicProcessIPPacket( IPPacket_t * const pxIPPacket, NetworkBufferDescriptor_t * const pxNetworkBuffer ) {
- prvProcessIPPacket(pxIPPacket, pxNetworkBuffer);
+eFrameProcessingResult_t publicProcessIPPacket( IPPacket_t * const pxIPPacket,
+ NetworkBufferDescriptor_t * const pxNetworkBuffer )
+{
+ prvProcessIPPacket( pxIPPacket, pxNetworkBuffer );
}
diff --git a/FreeRTOS/Test/CBMC/include/aws_freertos_tcp_verification_access_tcp_define.h b/FreeRTOS/Test/CBMC/include/aws_freertos_tcp_verification_access_tcp_define.h
index 01075d2ba..5d95619cb 100644
--- a/FreeRTOS/Test/CBMC/include/aws_freertos_tcp_verification_access_tcp_define.h
+++ b/FreeRTOS/Test/CBMC/include/aws_freertos_tcp_verification_access_tcp_define.h
@@ -1,12 +1,20 @@
-int32_t publicTCPPrepareSend( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer, UBaseType_t uxOptionsLength ) {
- prvTCPPrepareSend( pxSocket, ppxNetworkBuffer, uxOptionsLength );
+int32_t publicTCPPrepareSend( FreeRTOS_Socket_t * pxSocket,
+ NetworkBufferDescriptor_t ** ppxNetworkBuffer,
+ UBaseType_t uxOptionsLength )
+{
+ prvTCPPrepareSend( pxSocket, ppxNetworkBuffer, uxOptionsLength );
}
-BaseType_t publicTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer ) {
- prvTCPHandleState(pxSocket, ppxNetworkBuffer);
+BaseType_t publicTCPHandleState( FreeRTOS_Socket_t * pxSocket,
+ NetworkBufferDescriptor_t ** ppxNetworkBuffer )
+{
+ prvTCPHandleState( pxSocket, ppxNetworkBuffer );
}
-void publicTCPReturnPacket( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer,
- uint32_t ulLen, BaseType_t xReleaseAfterSend ) {
- prvTCPReturnPacket(pxSocket, pxNetworkBuffer, ulLen, xReleaseAfterSend );
+void publicTCPReturnPacket( FreeRTOS_Socket_t * pxSocket,
+ NetworkBufferDescriptor_t * pxNetworkBuffer,
+ uint32_t ulLen,
+ BaseType_t xReleaseAfterSend )
+{
+ prvTCPReturnPacket( pxSocket, pxNetworkBuffer, ulLen, xReleaseAfterSend );
}
diff --git a/FreeRTOS/Test/CBMC/include/cbmc.h b/FreeRTOS/Test/CBMC/include/cbmc.h
index c30063bae..9c43cc502 100644
--- a/FreeRTOS/Test/CBMC/include/cbmc.h
+++ b/FreeRTOS/Test/CBMC/include/cbmc.h
@@ -18,12 +18,12 @@
#include "NetworkInterface.h"
/*
- * CBMC models a pointer as an object id and an offset into that
- * object. The top bits of a pointer encode the object id and the
- * remaining bits encode the offset. This means there is a bound on
- * the maximum offset into an object in CBMC, and hence a bound on the
- * size of objects in CBMC.
- */
+ * CBMC models a pointer as an object id and an offset into that
+ * object. The top bits of a pointer encode the object id and the
+ * remaining bits encode the offset. This means there is a bound on
+ * the maximum offset into an object in CBMC, and hence a bound on the
+ * size of objects in CBMC.
+ */
#define CBMC_BITS 7
#define CBMC_MAX_OBJECT_SIZE ( 0xFFFFFFFF >> ( CBMC_BITS + 1 ) )
@@ -70,19 +70,19 @@ enum CBMC_LOOP_CONDITION
#define __CPROVER_printf2_ptr( str, exp ) { uint8_t * ValueOf_ ## str = ( uint8_t * ) ( exp ); }
/*
- * An assertion that pvPortMalloc returns NULL when asked to allocate 0 bytes.
- * This assertion is used in some of the TaskPool proofs.
- */
+ * An assertion that pvPortMalloc returns NULL when asked to allocate 0 bytes.
+ * This assertion is used in some of the TaskPool proofs.
+ */
#define __CPROVER_assert_zero_allocation() \
__CPROVER_assert( pvPortMalloc( 0 ) == NULL, \
"pvPortMalloc allows zero-allocated memory." )
/*
- * A stub for pvPortMalloc that nondeterministically chooses to return
- * either NULL or an allocation of the requested space. The stub is
- * guaranteed to return NULL when asked to allocate 0 bytes.
- * This stub is used in some of the TaskPool proofs.
- */
+ * A stub for pvPortMalloc that nondeterministically chooses to return
+ * either NULL or an allocation of the requested space. The stub is
+ * guaranteed to return NULL when asked to allocate 0 bytes.
+ * This stub is used in some of the TaskPool proofs.
+ */
void * pvPortMalloc( size_t xWantedSize )
{
if( xWantedSize == 0 )
diff --git a/FreeRTOS/Test/CBMC/include/queue_init.h b/FreeRTOS/Test/CBMC/include/queue_init.h
index 1ec75cb48..0093c2117 100644
--- a/FreeRTOS/Test/CBMC/include/queue_init.h
+++ b/FreeRTOS/Test/CBMC/include/queue_init.h
@@ -3,144 +3,170 @@
#include "queue_datastructure.h"
#ifndef CBMC_OBJECT_BITS
-#define CBMC_OBJECT_BITS 7
+ #define CBMC_OBJECT_BITS 7
#endif
#ifndef CBMC_OBJECT_MAX_SIZE
-#define CBMC_OBJECT_MAX_SIZE (UINT32_MAX>>(CBMC_OBJECT_BITS+1))
+ #define CBMC_OBJECT_MAX_SIZE ( UINT32_MAX >> ( CBMC_OBJECT_BITS + 1 ) )
#endif
/* Using prvCopyDataToQueue together with prvNotifyQueueSetContainer
- leads to a problem space explosion. Therefore, we use this stub
- and a sepearted proof on prvCopyDataToQueue to deal with it.
- As prvNotifyQueueSetContainer is disabled if configUSE_QUEUE_SETS != 1,
- in other cases the original implementation should be used. */
-#if( configUSE_QUEUE_SETS == 1 )
- BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
- {
- if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
- {
- __CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
- if(xPosition == queueSEND_TO_BACK){
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
- }else{
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
- }
- return pdFALSE;
- }else
- {
- return nondet_BaseType_t();
- }
- }
-#endif
+ * leads to a problem space explosion. Therefore, we use this stub
+ * and a sepearted proof on prvCopyDataToQueue to deal with it.
+ * As prvNotifyQueueSetContainer is disabled if configUSE_QUEUE_SETS != 1,
+ * in other cases the original implementation should be used. */
+#if ( configUSE_QUEUE_SETS == 1 )
+ BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition )
+ {
+ if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
+ {
+ __CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
+
+ if( xPosition == queueSEND_TO_BACK )
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
+ }
+ else
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
+ }
+
+ return pdFALSE;
+ }
+ else
+ {
+ return nondet_BaseType_t();
+ }
+ }
+#endif /* if ( configUSE_QUEUE_SETS == 1 ) */
/* xQueueCreateSet is compiled out if configUSE_QUEUE_SETS != 1.*/
-#if( configUSE_QUEUE_SETS == 1 )
- QueueSetHandle_t xUnconstrainedQueueSet()
- {
- UBaseType_t uxEventQueueLength = 2;
- QueueSetHandle_t xSet = xQueueCreateSet(uxEventQueueLength);
- if( xSet )
- {
- xSet->cTxLock = nondet_int8_t();
- __CPROVER_assume(xSet->cTxLock != 127);
- xSet->cRxLock = nondet_int8_t();
- xSet->uxMessagesWaiting = nondet_UBaseType_t();
- xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
- /* This is an invariant checked with a couple of asserts in the code base.
- If it is false from the beginning, the CBMC proofs are not able to succeed*/
- __CPROVER_assume(xSet->uxMessagesWaiting < xSet->uxLength);
- xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
- }
- return xSet;
- }
-#endif
+#if ( configUSE_QUEUE_SETS == 1 )
+ QueueSetHandle_t xUnconstrainedQueueSet()
+ {
+ UBaseType_t uxEventQueueLength = 2;
+ QueueSetHandle_t xSet = xQueueCreateSet( uxEventQueueLength );
+
+ if( xSet )
+ {
+ xSet->cTxLock = nondet_int8_t();
+ __CPROVER_assume( xSet->cTxLock != 127 );
+ xSet->cRxLock = nondet_int8_t();
+ xSet->uxMessagesWaiting = nondet_UBaseType_t();
+ xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
+
+ /* This is an invariant checked with a couple of asserts in the code base.
+ * If it is false from the beginning, the CBMC proofs are not able to succeed*/
+ __CPROVER_assume( xSet->uxMessagesWaiting < xSet->uxLength );
+ xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
+ }
+
+ return xSet;
+ }
+#endif /* if ( configUSE_QUEUE_SETS == 1 ) */
/* Create a mostly unconstrained Queue but bound the max item size.
- This is required for performance reasons in CBMC at the moment. */
-QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound ) {
- UBaseType_t uxQueueLength;
- UBaseType_t uxItemSize;
- uint8_t ucQueueType;
- __CPROVER_assume(uxQueueLength > 0);
- __CPROVER_assume(uxItemSize < uxItemSizeBound);
-
- // QueueGenericCreate method does not check for multiplication overflow
- size_t uxQueueStorageSize;
- __CPROVER_assume(uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE);
- __CPROVER_assume(uxItemSize < uxQueueStorageSize/uxQueueLength);
-
- QueueHandle_t xQueue =
- xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
- if(xQueue){
- xQueue->cTxLock = nondet_int8_t();
- __CPROVER_assume(xQueue->cTxLock != 127);
- xQueue->cRxLock = nondet_int8_t();
- __CPROVER_assume(xQueue->cRxLock != 127);
- xQueue->uxMessagesWaiting = nondet_UBaseType_t();
- /* This is an invariant checked with a couple of asserts in the code base.
- If it is false from the beginning, the CBMC proofs are not able to succeed*/
- __CPROVER_assume(xQueue->uxMessagesWaiting < xQueue->uxLength);
- xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
- xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
- #if( configUSE_QUEUE_SETS == 1)
- xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
- #endif
- }
- return xQueue;
+ * This is required for performance reasons in CBMC at the moment. */
+QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound )
+{
+ UBaseType_t uxQueueLength;
+ UBaseType_t uxItemSize;
+ uint8_t ucQueueType;
+
+ __CPROVER_assume( uxQueueLength > 0 );
+ __CPROVER_assume( uxItemSize < uxItemSizeBound );
+
+ /* QueueGenericCreate method does not check for multiplication overflow */
+ size_t uxQueueStorageSize;
+ __CPROVER_assume( uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE );
+ __CPROVER_assume( uxItemSize < uxQueueStorageSize / uxQueueLength );
+
+ QueueHandle_t xQueue =
+ xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
+
+ if( xQueue )
+ {
+ xQueue->cTxLock = nondet_int8_t();
+ __CPROVER_assume( xQueue->cTxLock != 127 );
+ xQueue->cRxLock = nondet_int8_t();
+ __CPROVER_assume( xQueue->cRxLock != 127 );
+ xQueue->uxMessagesWaiting = nondet_UBaseType_t();
+
+ /* This is an invariant checked with a couple of asserts in the code base.
+ * If it is false from the beginning, the CBMC proofs are not able to succeed*/
+ __CPROVER_assume( xQueue->uxMessagesWaiting < xQueue->uxLength );
+ xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
+ xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
+ #if ( configUSE_QUEUE_SETS == 1 )
+ xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
+ #endif
+ }
+
+ return xQueue;
}
/* Create a mostly unconstrained Queue */
-QueueHandle_t xUnconstrainedQueue( void ) {
- UBaseType_t uxQueueLength;
- UBaseType_t uxItemSize;
- uint8_t ucQueueType;
-
- __CPROVER_assume(uxQueueLength > 0);
-
- // QueueGenericCreate method does not check for multiplication overflow
- size_t uxQueueStorageSize;
- __CPROVER_assume(uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE);
- __CPROVER_assume(uxItemSize < uxQueueStorageSize/uxQueueLength);
-
- QueueHandle_t xQueue =
- xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
-
- if(xQueue){
- xQueue->cTxLock = nondet_int8_t();
- __CPROVER_assume(xQueue->cTxLock != 127);
- xQueue->cRxLock = nondet_int8_t();
- xQueue->uxMessagesWaiting = nondet_UBaseType_t();
- /* This is an invariant checked with a couple of asserts in the code base.
- If it is false from the beginning, the CBMC proofs are not able to succeed*/
- __CPROVER_assume(xQueue->uxMessagesWaiting < xQueue->uxLength);
- xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
- xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
- #if( configUSE_QUEUE_SETS == 1)
- xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
- #endif
- }
- return xQueue;
+QueueHandle_t xUnconstrainedQueue( void )
+{
+ UBaseType_t uxQueueLength;
+ UBaseType_t uxItemSize;
+ uint8_t ucQueueType;
+
+ __CPROVER_assume( uxQueueLength > 0 );
+
+ /* QueueGenericCreate method does not check for multiplication overflow */
+ size_t uxQueueStorageSize;
+ __CPROVER_assume( uxQueueStorageSize < CBMC_OBJECT_MAX_SIZE );
+ __CPROVER_assume( uxItemSize < uxQueueStorageSize / uxQueueLength );
+
+ QueueHandle_t xQueue =
+ xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
+
+ if( xQueue )
+ {
+ xQueue->cTxLock = nondet_int8_t();
+ __CPROVER_assume( xQueue->cTxLock != 127 );
+ xQueue->cRxLock = nondet_int8_t();
+ xQueue->uxMessagesWaiting = nondet_UBaseType_t();
+
+ /* This is an invariant checked with a couple of asserts in the code base.
+ * If it is false from the beginning, the CBMC proofs are not able to succeed*/
+ __CPROVER_assume( xQueue->uxMessagesWaiting < xQueue->uxLength );
+ xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
+ xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
+ #if ( configUSE_QUEUE_SETS == 1 )
+ xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
+ #endif
+ }
+
+ return xQueue;
}
/* Create a mostly unconstrained Mutex */
-QueueHandle_t xUnconstrainedMutex( void ) {
- uint8_t ucQueueType;
- QueueHandle_t xQueue =
- xQueueCreateMutex(ucQueueType);
- if(xQueue){
- xQueue->cTxLock = nondet_int8_t();
- __CPROVER_assume(xQueue->cTxLock != 127);
- xQueue->cRxLock = nondet_int8_t();
- xQueue->uxMessagesWaiting = nondet_UBaseType_t();
- /* This is an invariant checked with a couple of asserts in the code base.
- If it is false from the beginning, the CBMC proofs are not able to succeed*/
- __CPROVER_assume(xQueue->uxMessagesWaiting < xQueue->uxLength);
- xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
- xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
- #if( configUSE_QUEUE_SETS == 1)
- xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
- #endif
- }
- return xQueue;
+QueueHandle_t xUnconstrainedMutex( void )
+{
+ uint8_t ucQueueType;
+ QueueHandle_t xQueue =
+ xQueueCreateMutex( ucQueueType );
+
+ if( xQueue )
+ {
+ xQueue->cTxLock = nondet_int8_t();
+ __CPROVER_assume( xQueue->cTxLock != 127 );
+ xQueue->cRxLock = nondet_int8_t();
+ xQueue->uxMessagesWaiting = nondet_UBaseType_t();
+
+ /* This is an invariant checked with a couple of asserts in the code base.
+ * If it is false from the beginning, the CBMC proofs are not able to succeed*/
+ __CPROVER_assume( xQueue->uxMessagesWaiting < xQueue->uxLength );
+ xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
+ xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
+ #if ( configUSE_QUEUE_SETS == 1 )
+ xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
+ #endif
+ }
+
+ return xQueue;
}
diff --git a/FreeRTOS/Test/CBMC/include/tasksStubs.h b/FreeRTOS/Test/CBMC/include/tasksStubs.h
index a0dd6de4a..e50a5cad1 100644
--- a/FreeRTOS/Test/CBMC/include/tasksStubs.h
+++ b/FreeRTOS/Test/CBMC/include/tasksStubs.h
@@ -5,6 +5,7 @@
#include "task.h"
BaseType_t xState;
-void vInitTaskCheckForTimeOut(BaseType_t maxCounter, BaseType_t maxCounter_limit);
+void vInitTaskCheckForTimeOut( BaseType_t maxCounter,
+ BaseType_t maxCounter_limit );
#endif /* INC_TASK_STUBS_H */
diff --git a/FreeRTOS/Test/CBMC/patches/FreeRTOSConfig.h b/FreeRTOS/Test/CBMC/patches/FreeRTOSConfig.h
index 454291682..512d28388 100644
--- a/FreeRTOS/Test/CBMC/patches/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CBMC/patches/FreeRTOSConfig.h
@@ -53,10 +53,10 @@
#define configIDLE_SHOULD_YIELD 1
#define configUSE_CO_ROUTINES 0
#ifndef configUSE_MUTEXES
- #define configUSE_MUTEXES 1
+ #define configUSE_MUTEXES 1
#endif
#ifndef configUSE_RECURSIVE_MUTEXES
- #define configUSE_RECURSIVE_MUTEXES 1
+ #define configUSE_RECURSIVE_MUTEXES 1
#endif
#define configQUEUE_REGISTRY_SIZE 0
#define configUSE_APPLICATION_TASK_TAG 1
@@ -67,31 +67,31 @@
/* Hook function related definitions. */
#ifndef configUSE_TICK_HOOK
- #define configUSE_TICK_HOOK 0
+ #define configUSE_TICK_HOOK 0
#endif
-#define configUSE_IDLE_HOOK 1
-#define configUSE_MALLOC_FAILED_HOOK 1
-#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */
+#define configUSE_IDLE_HOOK 1
+#define configUSE_MALLOC_FAILED_HOOK 1
+#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */
/* Software timer related definitions. */
-#define configUSE_TIMERS 1
-#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
-#define configTIMER_QUEUE_LENGTH 5
-#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
+#define configUSE_TIMERS 1
+#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
+#define configTIMER_QUEUE_LENGTH 5
+#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
/* Event group related definitions. */
-#define configUSE_EVENT_GROUPS 1
+#define configUSE_EVENT_GROUPS 1
/* Co-routine definitions. */
-#define configUSE_CO_ROUTINES 0
-#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
+#define configUSE_CO_ROUTINES 0
+#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Memory allocation strategy. */
#ifndef configSUPPORT_DYNAMIC_ALLOCATION
- #define configSUPPORT_DYNAMIC_ALLOCATION 1
+ #define configSUPPORT_DYNAMIC_ALLOCATION 1
#endif
#ifndef configSUPPORT_STATIC_ALLOCATION
- #define configSUPPORT_STATIC_ALLOCATION 1
+ #define configSUPPORT_STATIC_ALLOCATION 1
#endif
@@ -102,13 +102,13 @@
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#ifndef INCLUDE_vTaskSuspend
- #define INCLUDE_vTaskSuspend 1
+ #define INCLUDE_vTaskSuspend 1
#endif
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#ifndef INCLUDE_xTaskGetSchedulerState
- #define INCLUDE_xTaskGetSchedulerState 1
+ #define INCLUDE_xTaskGetSchedulerState 1
#endif
#define INCLUDE_xTimerGetTimerTaskHandle 0
#define INCLUDE_xTaskGetIdleTaskHandle 0
@@ -132,7 +132,7 @@
extern void vAssertCalled( const char * pcFile,
uint32_t ulLine );
#ifndef configASSERT
-#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
+ #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
#endif
/* Remove logging in formal verification */
diff --git a/FreeRTOS/Test/CBMC/patches/FreeRTOSIPConfig.h b/FreeRTOS/Test/CBMC/patches/FreeRTOSIPConfig.h
index a2b122e89..80997f2af 100644
--- a/FreeRTOS/Test/CBMC/patches/FreeRTOSIPConfig.h
+++ b/FreeRTOS/Test/CBMC/patches/FreeRTOSIPConfig.h
@@ -1,27 +1,27 @@
/*
-FreeRTOS V202104.00
-Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
- http://aws.amazon.com/freertos
- http://www.FreeRTOS.org
-*/
+ * FreeRTOS V202104.00
+ * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * http://aws.amazon.com/freertos
+ * http://www.FreeRTOS.org
+ */
/*****************************************************************************
@@ -156,19 +156,19 @@ extern uint32_t ulRand();
* cache then the UDP message is replaced by a ARP message that solicits the
* required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
* number of entries that can exist in the ARP table at any one time. */
-#define ipconfigARP_CACHE_ENTRIES 6
+#define ipconfigARP_CACHE_ENTRIES 6
/* ARP requests that do not result in an ARP response will be re-transmitted a
* maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
* aborted. */
-#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
+#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
* table being created or refreshed and the entry being removed because it is stale.
* New ARP requests are sent for ARP cache entries that are nearing their maximum
* age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
* equal to 1500 seconds (or 25 minutes). */
-#define ipconfigMAX_ARP_AGE 150
+#define ipconfigMAX_ARP_AGE 150
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
* routines, which are relatively large. To save code space the full
@@ -180,14 +180,14 @@ extern uint32_t ulRand();
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
-#define ipconfigINCLUDE_FULL_INET_ADDR 1
+#define ipconfigINCLUDE_FULL_INET_ADDR 1
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#ifndef ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS
- #define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
+ #define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
#endif
/* A FreeRTOS queue is used to send events from application tasks to the IP
diff --git a/FreeRTOS/Test/CBMC/proofs/CBMCStubLibrary/tasksStubs.c b/FreeRTOS/Test/CBMC/proofs/CBMCStubLibrary/tasksStubs.c
index 3fe245f80..a9064ee40 100644
--- a/FreeRTOS/Test/CBMC/proofs/CBMCStubLibrary/tasksStubs.c
+++ b/FreeRTOS/Test/CBMC/proofs/CBMCStubLibrary/tasksStubs.c
@@ -3,15 +3,15 @@
#include "tasksStubs.h"
#ifndef TASK_STUB_COUNTER
- #define TASK_STUB_COUNTER 0;
+ #define TASK_STUB_COUNTER 0;
#endif
/* 5 is a magic number, but we need some number here as a default value.
- This value is used to bound any loop depending on xTaskCheckForTimeOut
- as a loop bound. It should be overwritten in the Makefile.json adapting
- to the performance requirements of the harness. */
+ * This value is used to bound any loop depending on xTaskCheckForTimeOut
+ * as a loop bound. It should be overwritten in the Makefile.json adapting
+ * to the performance requirements of the harness. */
#ifndef TASK_STUB_COUNTER_LIMIT
- #define TASK_STUB_COUNTER_LIMIT 5;
+ #define TASK_STUB_COUNTER_LIMIT 5;
#endif
@@ -20,28 +20,32 @@ static BaseType_t xCounterLimit = TASK_STUB_COUNTER_LIMIT;
BaseType_t xTaskGetSchedulerState( void )
{
- return xState;
+ return xState;
}
/* This function is another method apart from overwritting the defines to init the max
- loop bound. */
-void vInitTaskCheckForTimeOut(BaseType_t maxCounter, BaseType_t maxCounter_limit)
+ * loop bound. */
+void vInitTaskCheckForTimeOut( BaseType_t maxCounter,
+ BaseType_t maxCounter_limit )
{
- xCounter = maxCounter;
- xCounterLimit = maxCounter_limit;
+ xCounter = maxCounter;
+ xCounterLimit = maxCounter_limit;
}
/* This is mostly called in a loop. For CBMC, we have to bound the loop
- to a max limits of calls. Therefore this Stub models a nondet timeout in
- max TASK_STUB_COUNTER_LIMIT iterations.*/
-BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) {
- ++xCounter;
- if(xCounter == xCounterLimit)
- {
- return pdTRUE;
- }
- else
- {
- return nondet_basetype();
- }
+ * to a max limits of calls. Therefore this Stub models a nondet timeout in
+ * max TASK_STUB_COUNTER_LIMIT iterations.*/
+BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
+ TickType_t * const pxTicksToWait )
+{
+ ++xCounter;
+
+ if( xCounter == xCounterLimit )
+ {
+ return pdTRUE;
+ }
+ else
+ {
+ return nondet_basetype();
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/CMakeLists.txt b/FreeRTOS/Test/CBMC/proofs/CMakeLists.txt
index aaa2e3c8a..e493850e1 100644
--- a/FreeRTOS/Test/CBMC/proofs/CMakeLists.txt
+++ b/FreeRTOS/Test/CBMC/proofs/CMakeLists.txt
@@ -17,7 +17,7 @@ list(APPEND cbmc_compile_includes
${CMAKE_SOURCE_DIR}/Source/include
${CMAKE_SOURCE_DIR}/Source/portable/MSVC-MingW
${CMAKE_SOURCE_DIR}/Source/../../FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement
- ${CMAKE_SOURCE_DIR}/Source/../../FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include
+ ${CMAKE_SOURCE_DIR}/Source/../../FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include
${CMAKE_SOURCE_DIR}/Source/../../FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/MSVC
${cbmc_dir}/include
${cbmc_dir}/windows
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueCreateMutex/QueueCreateMutex_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueCreateMutex/QueueCreateMutex_harness.c
index 3528d9640..628e95423 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueCreateMutex/QueueCreateMutex_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueCreateMutex/QueueCreateMutex_harness.c
@@ -31,8 +31,9 @@
#include "cbmc.h"
-void harness() {
- uint8_t ucQueueType;
+void harness()
+{
+ uint8_t ucQueueType;
- xQueueCreateMutex(ucQueueType);
+ xQueueCreateMutex( ucQueueType );
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSend/QueueGenericSend_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSend/QueueGenericSend_harness.c
index fae965ad8..84a35beed 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSend/QueueGenericSend_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSend/QueueGenericSend_harness.c
@@ -34,94 +34,112 @@
#include "cbmc.h"
#ifndef LOCK_BOUND
- #define LOCK_BOUND 4
+ #define LOCK_BOUND 4
#endif
#ifndef QUEUE_SEND_BOUND
- #define QUEUE_SEND_BOUND 4
+ #define QUEUE_SEND_BOUND 4
#endif
-#if( configUSE_QUEUE_SETS == 0 )
-BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
+#if ( configUSE_QUEUE_SETS == 0 )
+ BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition )
+ {
+ if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
+ {
+ __CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
+
+ if( xPosition == queueSEND_TO_BACK )
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
+ }
+ else
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
+ }
+
+ return pdFALSE;
+ }
+ else
+ {
+ return nondet_BaseType_t();
+ }
+ }
+#else /* if ( configUSE_QUEUE_SETS == 0 ) */
+ BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
+ {
+ Queue_t * pxQueueSetContainer = pxQueue->pxQueueSetContainer;
+
+ configASSERT( pxQueueSetContainer );
+ }
+
+ void prvUnlockQueue( Queue_t * const pxQueue )
+ {
+ configASSERT( pxQueue );
+
+ if( pxQueue->pxQueueSetContainer != NULL )
+ {
+ prvNotifyQueueSetContainer( pxQueue );
+ }
+
+ listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) );
+ pxQueue->cTxLock = queueUNLOCKED;
+
+ listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) );
+ pxQueue->cRxLock = queueUNLOCKED;
+ }
+
+#endif /* if ( configUSE_QUEUE_SETS == 0 ) */
+
+void harness()
{
- if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
- {
- __CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
- if(xPosition == queueSEND_TO_BACK){
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
- }else{
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
- }
- return pdFALSE;
- }else
- {
- return nondet_BaseType_t();
- }
+ /*Initialise the tasksStubs */
+ vInitTaskCheckForTimeOut( 0, QUEUE_SEND_BOUND - 1 );
+ xState = nondet_basetype();
+ QueueHandle_t xQueue =
+ xUnconstrainedQueueBoundedItemSize( 2 );
+
+ TickType_t xTicksToWait;
+
+ if( xState == taskSCHEDULER_SUSPENDED )
+ {
+ xTicksToWait = 0;
+ }
+
+ if( xQueue )
+ {
+ void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
+ BaseType_t xCopyPosition;
+
+ if( xCopyPosition == queueOVERWRITE )
+ {
+ xQueue->uxLength = 1;
+ }
+
+ if( xQueue->uxItemSize == 0 )
+ {
+ /* uxQueue->xQueueType is a pointer to the head of the queue storage area.
+ * If an item has a sice, this pointer must not be modified after init.
+ * Otherwise some of the write statements will fail. */
+ xQueue->uxQueueType = nondet_int8_t();
+ pvItemToQueue = 0;
+ }
+
+ /* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
+ * invariant. */
+ xQueue->uxMessagesWaiting = nondet_UBaseType_t();
+
+ /* These values are decremented during a while loop interacting with task.c.
+ * This interaction is currently abstracted away.*/
+ xQueue->cTxLock = LOCK_BOUND - 1;
+ xQueue->cRxLock = LOCK_BOUND - 1;
+
+ if( !pvItemToQueue )
+ {
+ xQueue->uxItemSize = 0;
+ }
+
+ xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, xCopyPosition );
+ }
}
-#else
- BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
- {
- Queue_t *pxQueueSetContainer = pxQueue->pxQueueSetContainer;
- configASSERT( pxQueueSetContainer );
- }
-
- void prvUnlockQueue( Queue_t * const pxQueue ) {
- configASSERT( pxQueue );
- if( pxQueue->pxQueueSetContainer != NULL )
- {
- prvNotifyQueueSetContainer(pxQueue);
- }
- listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) );
- pxQueue->cTxLock = queueUNLOCKED;
-
- listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) );
- pxQueue->cRxLock = queueUNLOCKED;
- }
-
-#endif
-
-void harness(){
- //Initialise the tasksStubs
- vInitTaskCheckForTimeOut(0, QUEUE_SEND_BOUND - 1);
- xState = nondet_basetype();
- QueueHandle_t xQueue =
- xUnconstrainedQueueBoundedItemSize(2);
-
- TickType_t xTicksToWait;
- if(xState == taskSCHEDULER_SUSPENDED){
- xTicksToWait = 0;
- }
-
- if(xQueue){
- void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
- BaseType_t xCopyPosition;
-
- if(xCopyPosition == queueOVERWRITE){
- xQueue->uxLength = 1;
- }
-
- if(xQueue->uxItemSize == 0)
- {
- /* uxQueue->xQueueType is a pointer to the head of the queue storage area.
- If an item has a sice, this pointer must not be modified after init.
- Otherwise some of the write statements will fail. */
- xQueue->uxQueueType = nondet_int8_t();
- pvItemToQueue = 0;
- }
- /* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
- invariant. */
- xQueue->uxMessagesWaiting = nondet_UBaseType_t();
-
- /* These values are decremented during a while loop interacting with task.c.
- This interaction is currently abstracted away.*/
- xQueue->cTxLock = LOCK_BOUND - 1;
- xQueue->cRxLock = LOCK_BOUND - 1;
-
- if(!pvItemToQueue){
- xQueue->uxItemSize = 0;
- }
-
- xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, xCopyPosition );
- }
-}
-
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSendFromISR/QueueGenericSendFromISR_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSendFromISR/QueueGenericSendFromISR_harness.c
index 0c8a98cf2..26b16bdfb 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSendFromISR/QueueGenericSendFromISR_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGenericSendFromISR/QueueGenericSendFromISR_harness.c
@@ -33,53 +33,70 @@
#include "cbmc.h"
#ifndef ITEM_BOUND
- #define ITEM_BOUND 10
+ #define ITEM_BOUND 10
#endif
-#if( configUSE_QUEUE_SETS == 0 )
- BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
- {
- if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
- {
- __CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
- if(xPosition == queueSEND_TO_BACK){
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
- }else{
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
- }
- return pdFALSE;
- }else
- {
- return nondet_BaseType_t();
- }
- }
-#endif
+#if ( configUSE_QUEUE_SETS == 0 )
+ BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition )
+ {
+ if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
+ {
+ __CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
+
+ if( xPosition == queueSEND_TO_BACK )
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
+ }
+ else
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
+ }
+
+ return pdFALSE;
+ }
+ else
+ {
+ return nondet_BaseType_t();
+ }
+ }
+#endif /* if ( configUSE_QUEUE_SETS == 0 ) */
+
+void harness()
+{
+ QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize( ITEM_BOUND );
+
+
+ if( xQueue )
+ {
+ void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
+ BaseType_t * xHigherPriorityTaskWoken = pvPortMalloc( sizeof( BaseType_t ) );
+ BaseType_t xCopyPosition;
+
+ if( xQueue->uxItemSize == 0 )
+ {
+ /* uxQueue->xQueueType is a pointer to the head of the queue storage area.
+ * If an item has a size, this pointer must not be modified after init.
+ * Otherwise some of the write statements will fail. */
+ xQueue->uxQueueType = nondet_int8_t();
+ pvItemToQueue = 0;
+ }
+
+ /* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
+ * invariant. */
+ xQueue->uxMessagesWaiting = nondet_UBaseType_t();
-void harness(){
- QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize(ITEM_BOUND);
+ if( !pvItemToQueue )
+ {
+ xQueue->uxItemSize = 0;
+ }
+ if( xCopyPosition == 2 )
+ {
+ __CPROVER_assume( xQueue->uxLength == 1 );
+ }
- if( xQueue ){
- void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
- BaseType_t *xHigherPriorityTaskWoken = pvPortMalloc(sizeof(BaseType_t));
- BaseType_t xCopyPosition;
- if(xQueue->uxItemSize == 0)
- {
- /* uxQueue->xQueueType is a pointer to the head of the queue storage area.
- If an item has a size, this pointer must not be modified after init.
- Otherwise some of the write statements will fail. */
- xQueue->uxQueueType = nondet_int8_t();
- pvItemToQueue = 0;
- }
- /* This code checks explicitly for violations of the pxQueue->uxMessagesWaiting < pxQueue->uxLength
- invariant. */
- xQueue->uxMessagesWaiting = nondet_UBaseType_t();
- if(!pvItemToQueue){
- xQueue->uxItemSize = 0;
- }
- if(xCopyPosition == 2 ){
- __CPROVER_assume(xQueue->uxLength == 1);
- }
- xQueueGenericSendFromISR( xQueue, pvItemToQueue, xHigherPriorityTaskWoken, xCopyPosition );
- }
+ xQueueGenericSendFromISR( xQueue, pvItemToQueue, xHigherPriorityTaskWoken, xCopyPosition );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolder/QueueGetMutexHolder_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolder/QueueGetMutexHolder_harness.c
index 1bba9b7f8..9abaf0574 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolder/QueueGetMutexHolder_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolder/QueueGetMutexHolder_harness.c
@@ -32,10 +32,13 @@
#include "cbmc.h"
-void harness() {
- QueueHandle_t xSemaphore = xUnconstrainedQueue();
- if (xSemaphore) {
- xSemaphore->uxQueueType = nondet_uint8_t();
- xQueueGetMutexHolder(xSemaphore);
- }
+void harness()
+{
+ QueueHandle_t xSemaphore = xUnconstrainedQueue();
+
+ if( xSemaphore )
+ {
+ xSemaphore->uxQueueType = nondet_uint8_t();
+ xQueueGetMutexHolder( xSemaphore );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolderFromISR/QueueGetMutexHolderFromISR_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolderFromISR/QueueGetMutexHolderFromISR_harness.c
index a0543a70c..3fc4a4b7c 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolderFromISR/QueueGetMutexHolderFromISR_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGetMutexHolderFromISR/QueueGetMutexHolderFromISR_harness.c
@@ -32,10 +32,12 @@
#include "cbmc.h"
-void harness(){
- QueueHandle_t xSemaphore = pvPortMalloc(sizeof(Queue_t));
- if (xSemaphore) {
- xQueueGetMutexHolderFromISR( xSemaphore );
- }
-}
+void harness()
+{
+ QueueHandle_t xSemaphore = pvPortMalloc( sizeof( Queue_t ) );
+ if( xSemaphore )
+ {
+ xQueueGetMutexHolderFromISR( xSemaphore );
+ }
+}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveFromISR/QueueGiveFromISR_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveFromISR/QueueGiveFromISR_harness.c
index b6be1aa80..59e117667 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveFromISR/QueueGiveFromISR_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveFromISR/QueueGiveFromISR_harness.c
@@ -32,12 +32,14 @@
#include "cbmc.h"
-void harness(){
- QueueHandle_t xQueue = xUnconstrainedMutex();
- BaseType_t *xHigherPriorityTaskWoken = pvPortMalloc(sizeof(BaseType_t));
- if(xQueue){
- xQueue->uxMessagesWaiting = nondet_UBaseType_t();
- xQueueGiveFromISR( xQueue, xHigherPriorityTaskWoken );
- }
+void harness()
+{
+ QueueHandle_t xQueue = xUnconstrainedMutex();
+ BaseType_t * xHigherPriorityTaskWoken = pvPortMalloc( sizeof( BaseType_t ) );
+ if( xQueue )
+ {
+ xQueue->uxMessagesWaiting = nondet_UBaseType_t();
+ xQueueGiveFromISR( xQueue, xHigherPriorityTaskWoken );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveMutexRecursive/QueueGiveMutexRecursive_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveMutexRecursive/QueueGiveMutexRecursive_harness.c
index 6df3a36ee..661208a1f 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveMutexRecursive/QueueGiveMutexRecursive_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueGiveMutexRecursive/QueueGiveMutexRecursive_harness.c
@@ -32,17 +32,21 @@
#include "cbmc.h"
-void harness() {
- uint8_t ucQueueType;
- QueueHandle_t xMutex =
- xQueueCreateMutex( ucQueueType);
- if (xMutex) {
- xMutex->uxQueueType = ucQueueType;
- UBaseType_t uxCounter;
- /* This assumption is explained in the queue.c file inside the method body
- xQueueGiveMutexRecursive and guards against an underflow error. */
- __CPROVER_assume(uxCounter > 0);
- xMutex->u.xSemaphore.uxRecursiveCallCount = uxCounter;
- xQueueGiveMutexRecursive(xMutex);
- }
+void harness()
+{
+ uint8_t ucQueueType;
+ QueueHandle_t xMutex =
+ xQueueCreateMutex( ucQueueType );
+
+ if( xMutex )
+ {
+ xMutex->uxQueueType = ucQueueType;
+ UBaseType_t uxCounter;
+
+ /* This assumption is explained in the queue.c file inside the method body
+ * xQueueGiveMutexRecursive and guards against an underflow error. */
+ __CPROVER_assume( uxCounter > 0 );
+ xMutex->u.xSemaphore.uxRecursiveCallCount = uxCounter;
+ xQueueGiveMutexRecursive( xMutex );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueMessagesWaiting/QueueMessagesWaiting_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueMessagesWaiting/QueueMessagesWaiting_harness.c
index 8e5f3d050..2a2bef755 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueMessagesWaiting/QueueMessagesWaiting_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueMessagesWaiting/QueueMessagesWaiting_harness.c
@@ -32,10 +32,12 @@
#include "cbmc.h"
-void harness(){
- QueueHandle_t xQueue = pvPortMalloc(sizeof(Queue_t));
+void harness()
+{
+ QueueHandle_t xQueue = pvPortMalloc( sizeof( Queue_t ) );
- if(xQueue){
- uxQueueMessagesWaiting( xQueue );
- }
+ if( xQueue )
+ {
+ uxQueueMessagesWaiting( xQueue );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueuePeek/QueuePeek_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueuePeek/QueuePeek_harness.c
index 53c2c9050..019c47499 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueuePeek/QueuePeek_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueuePeek/QueuePeek_harness.c
@@ -34,46 +34,52 @@
#include "cbmc.h"
#ifndef LOCK_BOUND
- #define LOCK_BOUND 4
+ #define LOCK_BOUND 4
#endif
#ifndef QUEUE_PEEK_BOUND
- #define QUEUE_PEEK_BOUND 4
+ #define QUEUE_PEEK_BOUND 4
#endif
QueueHandle_t xQueue;
/* This method is called to initialize pxTimeOut.
- Setting up the data structure is not interesting for the proof,
- but the harness uses it to model a release
- on the queue after first check. */
-void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ){
- xQueue-> uxMessagesWaiting = nondet_BaseType_t();
+ * Setting up the data structure is not interesting for the proof,
+ * but the harness uses it to model a release
+ * on the queue after first check. */
+void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )
+{
+ xQueue->uxMessagesWaiting = nondet_BaseType_t();
}
-void harness(){
- xQueue = xUnconstrainedQueueBoundedItemSize(10);
+void harness()
+{
+ xQueue = xUnconstrainedQueueBoundedItemSize( 10 );
- //Initialise the tasksStubs
- vInitTaskCheckForTimeOut(0, QUEUE_PEEK_BOUND - 1);
+ /*Initialise the tasksStubs */
+ vInitTaskCheckForTimeOut( 0, QUEUE_PEEK_BOUND - 1 );
- TickType_t xTicksToWait;
- if(xState == taskSCHEDULER_SUSPENDED){
- xTicksToWait = 0;
- }
+ TickType_t xTicksToWait;
- if(xQueue){
- __CPROVER_assume(xQueue->cTxLock < LOCK_BOUND - 1);
- __CPROVER_assume(xQueue->cRxLock < LOCK_BOUND - 1);
+ if( xState == taskSCHEDULER_SUSPENDED )
+ {
+ xTicksToWait = 0;
+ }
- void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
+ if( xQueue )
+ {
+ __CPROVER_assume( xQueue->cTxLock < LOCK_BOUND - 1 );
+ __CPROVER_assume( xQueue->cRxLock < LOCK_BOUND - 1 );
- /* In case malloc fails as this is otherwise an invariant violation. */
- if(!pvItemToQueue){
- xQueue->uxItemSize = 0;
- }
+ void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
- xQueuePeek( xQueue, pvItemToQueue, xTicksToWait );
- }
+ /* In case malloc fails as this is otherwise an invariant violation. */
+ if( !pvItemToQueue )
+ {
+ xQueue->uxItemSize = 0;
+ }
+
+ xQueuePeek( xQueue, pvItemToQueue, xTicksToWait );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceive/QueueReceive_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceive/QueueReceive_harness.c
index 533f69caf..aae44fb83 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceive/QueueReceive_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceive/QueueReceive_harness.c
@@ -33,56 +33,63 @@
#include "cbmc.h"
/* prvUnlockQueue is going to decrement this value to 0 in the loop.
- We need a bound for the loop. Using 4 has a reasonable performance resulting
- in 3 unwinding iterations of the loop. The loop is mostly modifying a
- data structure in task.c that is not in the scope of the proof. */
+* We need a bound for the loop. Using 4 has a reasonable performance resulting
+* in 3 unwinding iterations of the loop. The loop is mostly modifying a
+* data structure in task.c that is not in the scope of the proof. */
#ifndef LOCK_BOUND
- #define LOCK_BOUND 4
+ #define LOCK_BOUND 4
#endif
/* This code checks for time outs. This value is used to bound the time out
- wait period. The stub function xTaskCheckForTimeOut used to model
- this wait time will be bounded to this define. */
+ * wait period. The stub function xTaskCheckForTimeOut used to model
+ * this wait time will be bounded to this define. */
#ifndef QUEUE_RECEIVE_BOUND
- #define QUEUE_RECEIVE_BOUND 4
+ #define QUEUE_RECEIVE_BOUND 4
#endif
/* If the item size is not bounded, the proof does not finish in a reasonable
- time due to the involved memcpy commands. */
+ * time due to the involved memcpy commands. */
#ifndef MAX_ITEM_SIZE
- #define MAX_ITEM_SIZE 20
+ #define MAX_ITEM_SIZE 20
#endif
QueueHandle_t xQueue;
/* This method is used to model side effects of concurrency.
- The initialization of pxTimeOut is not relevant for this harness. */
-void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ){
- __CPROVER_assert(__CPROVER_w_ok(&(pxTimeOut->xOverflowCount), sizeof(BaseType_t)), "pxTimeOut should be a valid pointer and xOverflowCount writable");
- __CPROVER_assert(__CPROVER_w_ok(&(pxTimeOut->xTimeOnEntering), sizeof(TickType_t)), "pxTimeOut should be a valid pointer and xTimeOnEntering writable");
- xQueue->uxMessagesWaiting = nondet_BaseType_t();
+ * The initialization of pxTimeOut is not relevant for this harness. */
+void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )
+{
+ __CPROVER_assert( __CPROVER_w_ok( &( pxTimeOut->xOverflowCount ), sizeof( BaseType_t ) ), "pxTimeOut should be a valid pointer and xOverflowCount writable" );
+ __CPROVER_assert( __CPROVER_w_ok( &( pxTimeOut->xTimeOnEntering ), sizeof( TickType_t ) ), "pxTimeOut should be a valid pointer and xTimeOnEntering writable" );
+ xQueue->uxMessagesWaiting = nondet_BaseType_t();
}
-void harness(){
- vInitTaskCheckForTimeOut(0, QUEUE_RECEIVE_BOUND - 1);
+void harness()
+{
+ vInitTaskCheckForTimeOut( 0, QUEUE_RECEIVE_BOUND - 1 );
- xQueue = xUnconstrainedQueueBoundedItemSize(MAX_ITEM_SIZE);
+ xQueue = xUnconstrainedQueueBoundedItemSize( MAX_ITEM_SIZE );
- TickType_t xTicksToWait;
- if(xState == taskSCHEDULER_SUSPENDED){
- xTicksToWait = 0;
- }
+ TickType_t xTicksToWait;
- if(xQueue){
- xQueue->cTxLock = LOCK_BOUND - 1;
- xQueue->cRxLock = LOCK_BOUND - 1;
-
- void *pvBuffer = pvPortMalloc(xQueue->uxItemSize);
- if(!pvBuffer){
- xQueue->uxItemSize = 0;
- }
- xQueueReceive( xQueue, pvBuffer, xTicksToWait );
+ if( xState == taskSCHEDULER_SUSPENDED )
+ {
+ xTicksToWait = 0;
}
+ if( xQueue )
+ {
+ xQueue->cTxLock = LOCK_BOUND - 1;
+ xQueue->cRxLock = LOCK_BOUND - 1;
+
+ void * pvBuffer = pvPortMalloc( xQueue->uxItemSize );
+
+ if( !pvBuffer )
+ {
+ xQueue->uxItemSize = 0;
+ }
+
+ xQueueReceive( xQueue, pvBuffer, xTicksToWait );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceiveFromISR/QueueReceiveFromISR_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceiveFromISR/QueueReceiveFromISR_harness.c
index 9a4b2cf2a..d9920895b 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceiveFromISR/QueueReceiveFromISR_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueReceiveFromISR/QueueReceiveFromISR_harness.c
@@ -32,22 +32,27 @@
#include "cbmc.h"
/* If the item size is not bounded, the proof does not finish in a reasonable
- time due to the involved memcpy commands. */
+ * time due to the involved memcpy commands. */
#ifndef MAX_ITEM_SIZE
- #define MAX_ITEM_SIZE 10
+ #define MAX_ITEM_SIZE 10
#endif
-void harness(){
- QueueHandle_t xQueue =
- xUnconstrainedQueueBoundedItemSize(MAX_ITEM_SIZE);
+void harness()
+{
+ QueueHandle_t xQueue =
+ xUnconstrainedQueueBoundedItemSize( MAX_ITEM_SIZE );
- BaseType_t *xHigherPriorityTaskWoken = pvPortMalloc(sizeof(BaseType_t));
+ BaseType_t * xHigherPriorityTaskWoken = pvPortMalloc( sizeof( BaseType_t ) );
- if(xQueue){
- void *pvBuffer = pvPortMalloc(xQueue->uxItemSize);
- if(!pvBuffer){
- xQueue->uxItemSize = 0;
- }
- xQueueReceiveFromISR( xQueue, pvBuffer, xHigherPriorityTaskWoken );
- }
+ if( xQueue )
+ {
+ void * pvBuffer = pvPortMalloc( xQueue->uxItemSize );
+
+ if( !pvBuffer )
+ {
+ xQueue->uxItemSize = 0;
+ }
+
+ xQueueReceiveFromISR( xQueue, pvBuffer, xHigherPriorityTaskWoken );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueSemaphoreTake/QueueSemaphoreTake_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueSemaphoreTake/QueueSemaphoreTake_harness.c
index 21fdbf80e..7480858aa 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueSemaphoreTake/QueueSemaphoreTake_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueSemaphoreTake/QueueSemaphoreTake_harness.c
@@ -36,53 +36,57 @@ BaseType_t state;
QueueHandle_t xQueue;
BaseType_t counter;
-BaseType_t xTaskGetSchedulerState(void)
+BaseType_t xTaskGetSchedulerState( void )
{
- return state;
+ return state;
}
void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )
{
- /* QueueSemaphoreTake might be blocked to wait for
- another process to release a token to the semaphore.
- This is currently not in the CBMC model. Anyhow,
- vTaskInternalSetTimeOutState is set a timeout for
- QueueSemaphoreTake operation. We use this to model a successful
- release during wait time. */
- UBaseType_t bound;
- __CPROVER_assume((bound >= 0 && xQueue->uxLength >= bound));
- xQueue->uxMessagesWaiting = bound;
+ /* QueueSemaphoreTake might be blocked to wait for
+ * another process to release a token to the semaphore.
+ * This is currently not in the CBMC model. Anyhow,
+ * vTaskInternalSetTimeOutState is set a timeout for
+ * QueueSemaphoreTake operation. We use this to model a successful
+ * release during wait time. */
+ UBaseType_t bound;
+
+ __CPROVER_assume( ( bound >= 0 && xQueue->uxLength >= bound ) );
+ xQueue->uxMessagesWaiting = bound;
}
void harness()
{
- /* Init task stub to make sure that the third loop iteration
- simulates a time out */
- vInitTaskCheckForTimeOut(0, 3);
+ /* Init task stub to make sure that the third loop iteration
+ * simulates a time out */
+ vInitTaskCheckForTimeOut( 0, 3 );
+
+ xQueue = xUnconstrainedMutex();
+ TickType_t xTicksToWait;
- xQueue = xUnconstrainedMutex();
- TickType_t xTicksToWait;
+ if( state == taskSCHEDULER_SUSPENDED )
+ {
+ xTicksToWait = 0;
+ }
- if(state == taskSCHEDULER_SUSPENDED){
- xTicksToWait = 0;
- }
- if (xQueue) {
- /* Bounding the loop in prvUnlockQueue to
- PRV_UNLOCK_QUEUE_BOUND. As the loop is not relevant
- in this proof the value might be set to any
- positive 8-bit integer value. We subtract one,
- because the bound must be one greater than the
- amount of loop iterations. */
- __CPROVER_assert(PRV_UNLOCK_QUEUE_BOUND > 0, "Make sure, a valid macro value is chosen.");
- xQueue->cTxLock = PRV_UNLOCK_QUEUE_BOUND - 1;
- xQueue->cRxLock = PRV_UNLOCK_QUEUE_BOUND - 1;
- ((&(xQueue->xTasksWaitingToReceive))->xListEnd).pxNext->xItemValue = nondet_ticktype();
+ if( xQueue )
+ {
+ /* Bounding the loop in prvUnlockQueue to
+ * PRV_UNLOCK_QUEUE_BOUND. As the loop is not relevant
+ * in this proof the value might be set to any
+ * positive 8-bit integer value. We subtract one,
+ * because the bound must be one greater than the
+ * amount of loop iterations. */
+ __CPROVER_assert( PRV_UNLOCK_QUEUE_BOUND > 0, "Make sure, a valid macro value is chosen." );
+ xQueue->cTxLock = PRV_UNLOCK_QUEUE_BOUND - 1;
+ xQueue->cRxLock = PRV_UNLOCK_QUEUE_BOUND - 1;
+ ( ( &( xQueue->xTasksWaitingToReceive ) )->xListEnd ).pxNext->xItemValue = nondet_ticktype();
- /* This assumptions is required to prevent an overflow in l. 2057 of queue.c
- in the prvGetDisinheritPriorityAfterTimeout() function. */
- __CPROVER_assume( (
- ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( xQueue->xTasksWaitingToReceive ) )
- <= ( ( UBaseType_t ) configMAX_PRIORITIES)));
- xQueueSemaphoreTake(xQueue, xTicksToWait);
- }
+ /* This assumptions is required to prevent an overflow in l. 2057 of queue.c
+ * in the prvGetDisinheritPriorityAfterTimeout() function. */
+ __CPROVER_assume( (
+ ( UBaseType_t ) listGET_ITEM_VALUE_OF_HEAD_ENTRY( &( xQueue->xTasksWaitingToReceive ) )
+ <= ( ( UBaseType_t ) configMAX_PRIORITIES ) ) );
+ xQueueSemaphoreTake( xQueue, xTicksToWait );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueSpacesAvailable/QueueSpacesAvailable_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueSpacesAvailable/QueueSpacesAvailable_harness.c
index c56f9008e..c470f79b7 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueSpacesAvailable/QueueSpacesAvailable_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueSpacesAvailable/QueueSpacesAvailable_harness.c
@@ -31,11 +31,12 @@
#include "queue_init.h"
#include "cbmc.h"
-void harness(){
- QueueHandle_t xQueue = xUnconstrainedQueue();
+void harness()
+{
+ QueueHandle_t xQueue = xUnconstrainedQueue();
- // QueueSpacesAvailable asserts nonnull pointer
- __CPROVER_assume(xQueue);
+ /* QueueSpacesAvailable asserts nonnull pointer */
+ __CPROVER_assume( xQueue );
- uxQueueSpacesAvailable( xQueue );
+ uxQueueSpacesAvailable( xQueue );
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/QueueTakeMutexRecursive/QueueTakeMutexRecursive_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/QueueTakeMutexRecursive/QueueTakeMutexRecursive_harness.c
index 9864321e0..c180b9012 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/QueueTakeMutexRecursive/QueueTakeMutexRecursive_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/QueueTakeMutexRecursive/QueueTakeMutexRecursive_harness.c
@@ -36,36 +36,42 @@ QueueHandle_t xMutex;
void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut )
{
- /* QueueSemaphoreTake might be blocked to wait for
- another process to release a token to the semaphore.
- This is currently not in the CBMC model. Anyhow,
- vTaskInternalSetTimeOutState is set a timeout for
- QueueSemaphoreTake operation. We use this to model a successful
- release during wait time. */
- UBaseType_t bound;
- __CPROVER_assume((bound >= 0 && xMutex->uxLength >= bound));
- xMutex->uxMessagesWaiting = bound;
+ /* QueueSemaphoreTake might be blocked to wait for
+ * another process to release a token to the semaphore.
+ * This is currently not in the CBMC model. Anyhow,
+ * vTaskInternalSetTimeOutState is set a timeout for
+ * QueueSemaphoreTake operation. We use this to model a successful
+ * release during wait time. */
+ UBaseType_t bound;
+
+ __CPROVER_assume( ( bound >= 0 && xMutex->uxLength >= bound ) );
+ xMutex->uxMessagesWaiting = bound;
}
-BaseType_t xTaskGetSchedulerState( void ) {
- BaseType_t ret;
- __CPROVER_assume(ret != taskSCHEDULER_SUSPENDED);
- return ret;
+BaseType_t xTaskGetSchedulerState( void )
+{
+ BaseType_t ret;
+
+ __CPROVER_assume( ret != taskSCHEDULER_SUSPENDED );
+ return ret;
}
-void harness() {
- uint8_t ucQueueType;
- xMutex = xQueueCreateMutex(ucQueueType);
- TickType_t xTicksToWait;
+void harness()
+{
+ uint8_t ucQueueType;
+
+ xMutex = xQueueCreateMutex( ucQueueType );
+ TickType_t xTicksToWait;
- /* Init task stub to make sure that the QueueSemaphoreTake_BOUND - 1
- loop iteration simulates a time out */
- vInitTaskCheckForTimeOut(0, QueueSemaphoreTake_BOUND - 1);
+ /* Init task stub to make sure that the QueueSemaphoreTake_BOUND - 1
+ * loop iteration simulates a time out */
+ vInitTaskCheckForTimeOut( 0, QueueSemaphoreTake_BOUND - 1 );
- if(xMutex){
- xMutex->cTxLock = PRV_UNLOCK_UNWINDING_BOUND - 1;
- xMutex->cRxLock = PRV_UNLOCK_UNWINDING_BOUND - 1;
- xMutex->uxMessagesWaiting = nondet_UBaseType_t();
- xQueueTakeMutexRecursive(xMutex, xTicksToWait);
- }
+ if( xMutex )
+ {
+ xMutex->cTxLock = PRV_UNLOCK_UNWINDING_BOUND - 1;
+ xMutex->cRxLock = PRV_UNLOCK_UNWINDING_BOUND - 1;
+ xMutex->uxMessagesWaiting = nondet_UBaseType_t();
+ xQueueTakeMutexRecursive( xMutex, xTicksToWait );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/prvCopyDataToQueue/prvCopyDataToQueue_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/prvCopyDataToQueue/prvCopyDataToQueue_harness.c
index 80398bfa2..cd053e44d 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/prvCopyDataToQueue/prvCopyDataToQueue_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/prvCopyDataToQueue/prvCopyDataToQueue_harness.c
@@ -31,24 +31,30 @@
#include "queue_init.h"
#include "cbmc.h"
-BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition );
-
-void harness(){
- QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize(10);
-
-
- if( xQueue ){
- void *pvItemToQueue = pvPortMalloc(xQueue->uxItemSize);
- if( !pvItemToQueue )
- {
- xQueue->uxItemSize = 0;
- }
- if(xQueue->uxItemSize == 0)
- {
- xQueue->uxQueueType = nondet_int8_t();
- }
- BaseType_t xPosition;
- prvCopyDataToQueue( xQueue, pvItemToQueue, xPosition );
- }
+BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition );
+void harness()
+{
+ QueueHandle_t xQueue = xUnconstrainedQueueBoundedItemSize( 10 );
+
+
+ if( xQueue )
+ {
+ void * pvItemToQueue = pvPortMalloc( xQueue->uxItemSize );
+
+ if( !pvItemToQueue )
+ {
+ xQueue->uxItemSize = 0;
+ }
+
+ if( xQueue->uxItemSize == 0 )
+ {
+ xQueue->uxQueueType = nondet_int8_t();
+ }
+
+ BaseType_t xPosition;
+ prvCopyDataToQueue( xQueue, pvItemToQueue, xPosition );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c
index 46372c895..ff57f215b 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c
@@ -32,63 +32,81 @@
#include "cbmc.h"
#ifndef LOCK_BOUND
- #define LOCK_BOUND 4
+ #define LOCK_BOUND 4
#endif
-BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue, const BaseType_t xCopyPosition );
+BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue,
+ const BaseType_t xCopyPosition );
-BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
+BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition )
{
- if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
- {
- __CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
- if(xPosition == queueSEND_TO_BACK){
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
- }else{
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
- }
- return pdFALSE;
- }else
- {
- return nondet_BaseType_t();
- }
+ if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
+ {
+ __CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
+
+ if( xPosition == queueSEND_TO_BACK )
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
+ }
+ else
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
+ }
+
+ return pdFALSE;
+ }
+ else
+ {
+ return nondet_BaseType_t();
+ }
}
QueueSetHandle_t xUnconstrainedQueueSet()
{
- UBaseType_t uxEventQueueLength = 2;
- QueueSetHandle_t xSet = xQueueCreateSet(uxEventQueueLength);
- if( xSet )
- {
- xSet->cTxLock = nondet_int8_t();
- __CPROVER_assume(xSet->cTxLock != 127);
- xSet->cRxLock = nondet_int8_t();
- xSet->uxMessagesWaiting = nondet_UBaseType_t();
- xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
- xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
- }
- return xSet;
+ UBaseType_t uxEventQueueLength = 2;
+ QueueSetHandle_t xSet = xQueueCreateSet( uxEventQueueLength );
+
+ if( xSet )
+ {
+ xSet->cTxLock = nondet_int8_t();
+ __CPROVER_assume( xSet->cTxLock != 127 );
+ xSet->cRxLock = nondet_int8_t();
+ xSet->uxMessagesWaiting = nondet_UBaseType_t();
+ xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
+ xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
+ }
+
+ return xSet;
}
-void harness(){
- UBaseType_t uxQueueLength;
- UBaseType_t uxItemSize;
- uint8_t ucQueueType;
- __CPROVER_assume(uxQueueLength > 0);
- __CPROVER_assume(uxItemSize < 10);
- /* The implicit assumption for the QueueGenericCreate method is,
- that there are no overflows in the computation and the inputs are safe.
- There is no check for this in the code base */
- UBaseType_t upper_bound = portMAX_DELAY - sizeof(Queue_t);
- __CPROVER_assume(uxItemSize < (upper_bound)/uxQueueLength);
- QueueHandle_t xQueue =
- xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
- if( xQueue ){
- xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
- if(xQueue->pxQueueSetContainer) {
- __CPROVER_assume(xQueue->pxQueueSetContainer->uxMessagesWaiting < xQueue->pxQueueSetContainer->uxLength);
- BaseType_t xCopyPosition = nondet_BaseType_t();
- prvNotifyQueueSetContainer(xQueue, xCopyPosition );
- }
- }
+void harness()
+{
+ UBaseType_t uxQueueLength;
+ UBaseType_t uxItemSize;
+ uint8_t ucQueueType;
+
+ __CPROVER_assume( uxQueueLength > 0 );
+ __CPROVER_assume( uxItemSize < 10 );
+
+ /* The implicit assumption for the QueueGenericCreate method is,
+ * that there are no overflows in the computation and the inputs are safe.
+ * There is no check for this in the code base */
+ UBaseType_t upper_bound = portMAX_DELAY - sizeof( Queue_t );
+ __CPROVER_assume( uxItemSize < ( upper_bound ) / uxQueueLength );
+ QueueHandle_t xQueue =
+ xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
+
+ if( xQueue )
+ {
+ xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
+
+ if( xQueue->pxQueueSetContainer )
+ {
+ __CPROVER_assume( xQueue->pxQueueSetContainer->uxMessagesWaiting < xQueue->pxQueueSetContainer->uxLength );
+ BaseType_t xCopyPosition = nondet_BaseType_t();
+ prvNotifyQueueSetContainer( xQueue, xCopyPosition );
+ }
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c
index 04fb98020..dd385633e 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c
@@ -33,72 +33,89 @@
#include "cbmc.h"
#ifndef LOCK_BOUND
- #define LOCK_BOUND 4
+ #define LOCK_BOUND 4
#endif
void prvUnlockQueue( Queue_t * const pxQueue );
-BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition )
+BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition )
{
- if(pxQueue->uxItemSize > ( UBaseType_t ) 0)
- {
- __CPROVER_assert(__CPROVER_r_ok(pvItemToQueue, ( size_t ) pxQueue->uxItemSize), "pvItemToQueue region must be readable");
- if(xPosition == queueSEND_TO_BACK){
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize), "pxQueue->pcWriteTo region must be writable");
- }else{
- __CPROVER_assert(__CPROVER_w_ok(( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize), "pxQueue->u.xQueue.pcReadFrom region must be writable");
- }
- return pdFALSE;
- }else
- {
- return nondet_BaseType_t();
- }
+ if( pxQueue->uxItemSize > ( UBaseType_t ) 0 )
+ {
+ __CPROVER_assert( __CPROVER_r_ok( pvItemToQueue, ( size_t ) pxQueue->uxItemSize ), "pvItemToQueue region must be readable" );
+
+ if( xPosition == queueSEND_TO_BACK )
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->pcWriteTo, ( size_t ) pxQueue->uxItemSize ), "pxQueue->pcWriteTo region must be writable" );
+ }
+ else
+ {
+ __CPROVER_assert( __CPROVER_w_ok( ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ), "pxQueue->u.xQueue.pcReadFrom region must be writable" );
+ }
+
+ return pdFALSE;
+ }
+ else
+ {
+ return nondet_BaseType_t();
+ }
}
QueueSetHandle_t xUnconstrainedQueueSet()
{
- UBaseType_t uxEventQueueLength = 2;
- QueueSetHandle_t xSet = xQueueCreateSet(uxEventQueueLength);
- if( xSet )
- {
- xSet->cTxLock = nondet_int8_t();
- __CPROVER_assume( xSet->cTxLock != 127 );
- xSet->cRxLock = nondet_int8_t();
- xSet->uxMessagesWaiting = nondet_UBaseType_t();
- xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
- /* This is an invariant checked with a couple of asserts in the code base.
- If it is false from the beginning, there is no chance for the proof to succeed*/
- __CPROVER_assume(xSet->uxMessagesWaiting < xSet->uxLength);
- xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
- }
- return xSet;
+ UBaseType_t uxEventQueueLength = 2;
+ QueueSetHandle_t xSet = xQueueCreateSet( uxEventQueueLength );
+
+ if( xSet )
+ {
+ xSet->cTxLock = nondet_int8_t();
+ __CPROVER_assume( xSet->cTxLock != 127 );
+ xSet->cRxLock = nondet_int8_t();
+ xSet->uxMessagesWaiting = nondet_UBaseType_t();
+ xSet->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
+
+ /* This is an invariant checked with a couple of asserts in the code base.
+ * If it is false from the beginning, there is no chance for the proof to succeed*/
+ __CPROVER_assume( xSet->uxMessagesWaiting < xSet->uxLength );
+ xSet->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
+ }
+
+ return xSet;
}
-void harness(){
- UBaseType_t uxQueueLength;
- UBaseType_t uxItemSize;
- uint8_t ucQueueType;
- __CPROVER_assume(uxQueueLength > 0);
- __CPROVER_assume(uxItemSize < 10);
- /* The implicit assumption for the QueueGenericCreate method is,
- that there are no overflows in the computation and the inputs are safe.
- There is no check for this in the code base */
- UBaseType_t upper_bound = portMAX_DELAY - sizeof(Queue_t);
- __CPROVER_assume(uxItemSize < (upper_bound)/uxQueueLength);
- QueueHandle_t xQueue =
- xQueueGenericCreate(uxQueueLength, uxItemSize, ucQueueType);
- if(xQueue){
- xQueue->cTxLock = LOCK_BOUND - 1;
- xQueue->cRxLock = LOCK_BOUND - 1;
- xQueue->uxMessagesWaiting = nondet_UBaseType_t();
- /* This is an invariant checked with a couple of asserts in the code base.
- If it is false from the beginning, there is no chance for the proof to succeed*/
- __CPROVER_assume(xQueue->uxMessagesWaiting < xQueue->uxLength);
- xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
- xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
- #if( configUSE_QUEUE_SETS == 1)
- xQueueAddToSet(xQueue, xUnconstrainedQueueSet());
- #endif
- prvUnlockQueue(xQueue);
- }
+void harness()
+{
+ UBaseType_t uxQueueLength;
+ UBaseType_t uxItemSize;
+ uint8_t ucQueueType;
+
+ __CPROVER_assume( uxQueueLength > 0 );
+ __CPROVER_assume( uxItemSize < 10 );
+
+ /* The implicit assumption for the QueueGenericCreate method is,
+ * that there are no overflows in the computation and the inputs are safe.
+ * There is no check for this in the code base */
+ UBaseType_t upper_bound = portMAX_DELAY - sizeof( Queue_t );
+ __CPROVER_assume( uxItemSize < ( upper_bound ) / uxQueueLength );
+ QueueHandle_t xQueue =
+ xQueueGenericCreate( uxQueueLength, uxItemSize, ucQueueType );
+
+ if( xQueue )
+ {
+ xQueue->cTxLock = LOCK_BOUND - 1;
+ xQueue->cRxLock = LOCK_BOUND - 1;
+ xQueue->uxMessagesWaiting = nondet_UBaseType_t();
+
+ /* This is an invariant checked with a couple of asserts in the code base.
+ * If it is false from the beginning, there is no chance for the proof to succeed*/
+ __CPROVER_assume( xQueue->uxMessagesWaiting < xQueue->uxLength );
+ xQueue->xTasksWaitingToReceive.uxNumberOfItems = nondet_UBaseType_t();
+ xQueue->xTasksWaitingToSend.uxNumberOfItems = nondet_UBaseType_t();
+ #if ( configUSE_QUEUE_SETS == 1 )
+ xQueueAddToSet( xQueue, xUnconstrainedQueueSet() );
+ #endif
+ prvUnlockQueue( xQueue );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/TaskCheckForTimeOut_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/TaskCheckForTimeOut_harness.c
index d78189d3c..24190e80f 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/TaskCheckForTimeOut_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/TaskCheckForTimeOut_harness.c
@@ -41,14 +41,14 @@ BaseType_t xPrepareCurrentTCB( void );
*/
void harness()
{
- UBaseType_t xTasksPrepared;
- TimeOut_t pxTimeOut;
- TickType_t pxTicksToWait;
+ UBaseType_t xTasksPrepared;
+ TimeOut_t pxTimeOut;
+ TickType_t pxTicksToWait;
- xTasksPrepared = xPrepareCurrentTCB();
+ xTasksPrepared = xPrepareCurrentTCB();
- if ( xTasksPrepared != pdFAIL )
- {
- xTaskCheckForTimeOut( &pxTimeOut, &pxTicksToWait );
- }
+ if( xTasksPrepared != pdFAIL )
+ {
+ xTaskCheckForTimeOut( &pxTimeOut, &pxTicksToWait );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/tasks_test_access_functions.h
index 926986b35..639bc10b2 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskCheckForTimeOut/tasks_test_access_functions.h
@@ -33,9 +33,9 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
- return pxTCB;
+ return pxTCB;
}
/*
@@ -43,9 +43,9 @@ TaskHandle_t xUnconstrainedTCB( void )
*/
BaseType_t xPrepareCurrentTCB( void )
{
- __CPROVER_assert_zero_allocation();
+ __CPROVER_assert_zero_allocation();
- pxCurrentTCB = xUnconstrainedTCB();
+ pxCurrentTCB = xUnconstrainedTCB();
- return pxCurrentTCB == NULL ? pdFAIL : pdPASS;
+ return pxCurrentTCB == NULL ? pdFAIL : pdPASS;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/TaskCreate_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/TaskCreate_harness.c
index 6331c785b..148fa1ca2 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/TaskCreate_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/TaskCreate_harness.c
@@ -33,31 +33,32 @@
void vNondetSetCurrentTCB( void );
void vSetGlobalVariables( void );
void vPrepareTaskLists( void );
-TaskHandle_t *pxNondetSetTaskHandle( void );
-char *pcNondetSetString( size_t xSizeLength );
+TaskHandle_t * pxNondetSetTaskHandle( void );
+char * pcNondetSetString( size_t xSizeLength );
void harness()
{
- TaskFunction_t pxTaskCode;
- char * pcName;
- configSTACK_DEPTH_TYPE usStackDepth = STACK_DEPTH;
- void * pvParameters;
- TaskHandle_t * pxCreatedTask;
+ TaskFunction_t pxTaskCode;
+ char * pcName;
+ configSTACK_DEPTH_TYPE usStackDepth = STACK_DEPTH;
+ void * pvParameters;
+ TaskHandle_t * pxCreatedTask;
+
+ UBaseType_t uxPriority;
- UBaseType_t uxPriority;
__CPROVER_assume( uxPriority < configMAX_PRIORITIES );
- vNondetSetCurrentTCB();
- vSetGlobalVariables();
- vPrepareTaskLists();
+ vNondetSetCurrentTCB();
+ vSetGlobalVariables();
+ vPrepareTaskLists();
- pxCreatedTask = pxNondetSetTaskHandle();
- pcName = pcNondetSetString( configMAX_TASK_NAME_LEN );
+ pxCreatedTask = pxNondetSetTaskHandle();
+ pcName = pcNondetSetString( configMAX_TASK_NAME_LEN );
- xTaskCreate(pxTaskCode,
- pcName,
- usStackDepth,
- pvParameters,
- uxPriority,
- pxCreatedTask );
+ xTaskCreate( pxTaskCode,
+ pcName,
+ usStackDepth,
+ pvParameters,
+ uxPriority,
+ pxCreatedTask );
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/tasks_test_access_functions.h
index 9e48040c7..76d1cd338 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskCreate/tasks_test_access_functions.h
@@ -34,16 +34,17 @@
*/
void vNondetSetCurrentTCB( void )
{
- pxCurrentTCB = pvPortMalloc( sizeof(TCB_t) );
+ pxCurrentTCB = pvPortMalloc( sizeof( TCB_t ) );
}
+
/*
* We just require task lists to be initialized for this proof
*/
void vPrepareTaskLists( void )
{
- __CPROVER_assert_zero_allocation();
+ __CPROVER_assert_zero_allocation();
- prvInitialiseTaskLists();
+ prvInitialiseTaskLists();
}
/*
@@ -52,33 +53,35 @@ void vPrepareTaskLists( void )
*/
void vSetGlobalVariables( void )
{
- xSchedulerRunning = nondet_basetype();
- uxCurrentNumberOfTasks = nondet_ubasetype();
+ xSchedulerRunning = nondet_basetype();
+ uxCurrentNumberOfTasks = nondet_ubasetype();
}
/*
* pvPortMalloc is nondeterministic by definition, thus we do not need
* to check for NULL allocation in this function
*/
-TaskHandle_t *pxNondetSetTaskHandle( void )
+TaskHandle_t * pxNondetSetTaskHandle( void )
{
- TaskHandle_t *pxNondetTaskHandle = pvPortMalloc( sizeof(TaskHandle_t) );
- return pxNondetTaskHandle;
+ TaskHandle_t * pxNondetTaskHandle = pvPortMalloc( sizeof( TaskHandle_t ) );
+
+ return pxNondetTaskHandle;
}
/*
* Tries to allocate a string of size xStringLength and sets the string
* to be terminated using a nondeterministic index if allocation was successful
*/
-char *pcNondetSetString( size_t xStringLength )
+char * pcNondetSetString( size_t xStringLength )
{
- char *pcName = pvPortMalloc( xStringLength );
+ char * pcName = pvPortMalloc( xStringLength );
- if ( pcName != NULL ) {
- size_t uNondetIndex;
- __CPROVER_assume( uNondetIndex < xStringLength );
- pcName[uNondetIndex] = '\0';
- }
+ if( pcName != NULL )
+ {
+ size_t uNondetIndex;
+ __CPROVER_assume( uNondetIndex < xStringLength );
+ pcName[ uNondetIndex ] = '\0';
+ }
- return pcName;
+ return pcName;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/TaskDelay_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/TaskDelay_harness.c
index 2ef21dedb..d38eb5579 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/TaskDelay_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/TaskDelay_harness.c
@@ -40,8 +40,9 @@ BaseType_t xTaskResumeAllStub( void );
* This is a trick to overcome the "redefined twice" error
* when stubbing out the `xTaskResumeAll` function in the header
*/
-BaseType_t xTaskResumeAll( void ) {
- return xTaskResumeAllStub();
+BaseType_t xTaskResumeAll( void )
+{
+ return xTaskResumeAllStub();
}
/*
@@ -50,16 +51,14 @@ BaseType_t xTaskResumeAll( void ) {
*/
void harness()
{
- TickType_t xTicksToDelay;
- BaseType_t xTasksPrepared;
+ TickType_t xTicksToDelay;
+ BaseType_t xTasksPrepared;
- vSetGlobalVariables();
- xTasksPrepared = xPrepareTaskLists();
+ vSetGlobalVariables();
+ xTasksPrepared = xPrepareTaskLists();
- if ( xTasksPrepared != pdFAIL )
- {
- vTaskDelay( xTicksToDelay );
- }
+ if( xTasksPrepared != pdFAIL )
+ {
+ vTaskDelay( xTicksToDelay );
+ }
}
-
-
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/tasks_test_access_functions.h
index b6b1210b0..f70c66ecf 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelay/tasks_test_access_functions.h
@@ -33,37 +33,40 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
-
- if ( pxTCB == NULL )
- return NULL;
-
- __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
-
- vListInitialiseItem( &( pxTCB->xStateListItem ) );
- vListInitialiseItem( &( pxTCB->xEventListItem ) );
-
- listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
- listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
- }
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
- }
- return pxTCB;
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
+
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
+
+ __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
+
+ vListInitialiseItem( &( pxTCB->xStateListItem ) );
+ vListInitialiseItem( &( pxTCB->xEventListItem ) );
+
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
+ }
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
+ }
+
+ return pxTCB;
}
/*
@@ -74,9 +77,9 @@ TaskHandle_t xUnconstrainedTCB( void )
void vSetGlobalVariables( void )
{
- uxSchedulerSuspended = pdFALSE;
- xTickCount = nondet_ticktype();
- xNextTaskUnblockTime = nondet_ticktype();
+ uxSchedulerSuspended = pdFALSE;
+ xTickCount = nondet_ticktype();
+ xNextTaskUnblockTime = nondet_ticktype();
}
/*
@@ -86,39 +89,42 @@ void vSetGlobalVariables( void )
*/
BaseType_t xPrepareTaskLists( void )
{
- TCB_t * pxTCB = NULL;
-
- __CPROVER_assert_zero_allocation();
-
- prvInitialiseTaskLists();
-
- /* The current task will be moved to the delayed list */
- pxCurrentTCB = xUnconstrainedTCB();
- if ( pxCurrentTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
-
- /*
- * Nondeterministic insertion of a task in the ready tasks list
- * guarantees coverage in line 5104 (tasks.c)
- */
- if ( nondet_bool() )
- {
- pxTCB = xUnconstrainedTCB();
- if ( pxTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( &pxReadyTasksLists[ pxTCB->uxPriority ], &( pxTCB->xStateListItem ) );
-
- /* Use of this macro ensures coverage on line 185 (list.c) */
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB , &pxReadyTasksLists[ pxTCB->uxPriority ] );
- }
-
-
- return pdPASS;
+ TCB_t * pxTCB = NULL;
+
+ __CPROVER_assert_zero_allocation();
+
+ prvInitialiseTaskLists();
+
+ /* The current task will be moved to the delayed list */
+ pxCurrentTCB = xUnconstrainedTCB();
+
+ if( pxCurrentTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
+
+ /*
+ * Nondeterministic insertion of a task in the ready tasks list
+ * guarantees coverage in line 5104 (tasks.c)
+ */
+ if( nondet_bool() )
+ {
+ pxTCB = xUnconstrainedTCB();
+
+ if( pxTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( &pxReadyTasksLists[ pxTCB->uxPriority ], &( pxTCB->xStateListItem ) );
+
+ /* Use of this macro ensures coverage on line 185 (list.c) */
+ listGET_OWNER_OF_NEXT_ENTRY( pxTCB, &pxReadyTasksLists[ pxTCB->uxPriority ] );
+ }
+
+ return pdPASS;
}
/*
@@ -129,17 +135,17 @@ BaseType_t xPrepareTaskLists( void )
*/
BaseType_t xTaskResumeAllStub( void )
{
- BaseType_t xAlreadyYielded;
+ BaseType_t xAlreadyYielded;
- configASSERT( uxSchedulerSuspended );
+ configASSERT( uxSchedulerSuspended );
- taskENTER_CRITICAL();
- {
- --uxSchedulerSuspended;
- __CPROVER_assert( listLIST_IS_EMPTY( &xPendingReadyList ), "Pending ready tasks list not empty." );
- __CPROVER_assert( xPendedTicks == 0 , "xPendedTicks is not equal to zero.");
- }
- taskEXIT_CRITICAL();
+ taskENTER_CRITICAL();
+ {
+ --uxSchedulerSuspended;
+ __CPROVER_assert( listLIST_IS_EMPTY( &xPendingReadyList ), "Pending ready tasks list not empty." );
+ __CPROVER_assert( xPendedTicks == 0, "xPendedTicks is not equal to zero." );
+ }
+ taskEXIT_CRITICAL();
- return xAlreadyYielded;
+ return xAlreadyYielded;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/TaskDelete_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/TaskDelete_harness.c
index 4bc5cc7cf..6358bf7ef 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/TaskDelete_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/TaskDelete_harness.c
@@ -41,14 +41,14 @@ BaseType_t xPrepareTaskLists( TaskHandle_t * xTask );
*/
void harness()
{
- TaskHandle_t xTaskToDelete;
- BaseType_t xTasksPrepared;
+ TaskHandle_t xTaskToDelete;
+ BaseType_t xTasksPrepared;
- vSetGlobalVariables();
- xTasksPrepared = xPrepareTaskLists( &xTaskToDelete );
+ vSetGlobalVariables();
+ xTasksPrepared = xPrepareTaskLists( &xTaskToDelete );
- if ( xTasksPrepared != pdFAIL )
- {
- vTaskDelete( xTaskToDelete );
- }
+ if( xTasksPrepared != pdFAIL )
+ {
+ vTaskDelete( xTaskToDelete );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/tasks_test_access_functions.h
index 67c367cd7..591103bd3 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskDelete/tasks_test_access_functions.h
@@ -33,50 +33,53 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
- uint8_t ucStaticAllocationFlag;
-
- if ( pxTCB == NULL )
- return NULL;
-
- __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
-
- vListInitialiseItem( &( pxTCB->xStateListItem ) );
- vListInitialiseItem( &( pxTCB->xEventListItem ) );
-
- listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
- listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
- }
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
- }
-
- pxTCB->pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) STACK_DEPTH ) * sizeof( StackType_t ) ) );
- if ( pxTCB->pxStack == NULL )
- {
- vPortFree( pxTCB );
- return NULL;
- }
-
- __CPROVER_assume( ucStaticAllocationFlag <= tskSTATICALLY_ALLOCATED_STACK_AND_TCB );
- __CPROVER_assume( ucStaticAllocationFlag >= tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB );
- pxTCB->ucStaticallyAllocated = ucStaticAllocationFlag;
-
- return pxTCB;
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
+ uint8_t ucStaticAllocationFlag;
+
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
+
+ __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
+
+ vListInitialiseItem( &( pxTCB->xStateListItem ) );
+ vListInitialiseItem( &( pxTCB->xEventListItem ) );
+
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
+ }
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
+ }
+
+ pxTCB->pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) STACK_DEPTH ) * sizeof( StackType_t ) ) );
+
+ if( pxTCB->pxStack == NULL )
+ {
+ vPortFree( pxTCB );
+ return NULL;
+ }
+
+ __CPROVER_assume( ucStaticAllocationFlag <= tskSTATICALLY_ALLOCATED_STACK_AND_TCB );
+ __CPROVER_assume( ucStaticAllocationFlag >= tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB );
+ pxTCB->ucStaticallyAllocated = ucStaticAllocationFlag;
+
+ return pxTCB;
}
/*
@@ -85,7 +88,7 @@ TaskHandle_t xUnconstrainedTCB( void )
*/
void vSetGlobalVariables()
{
- xSchedulerRunning = nondet_basetype();
+ xSchedulerRunning = nondet_basetype();
}
/*
@@ -95,78 +98,84 @@ void vSetGlobalVariables()
*/
BaseType_t xPrepareTaskLists( TaskHandle_t * xTask )
{
- TCB_t * pxTCB = NULL;
-
- __CPROVER_assert_zero_allocation();
-
- prvInitialiseTaskLists();
-
- /*
- * The task handle passed to TaskDelete can be NULL. In that case, the
- * task to delete is the one in `pxCurrentTCB`, see the macro `prvGetTCBFromHandle`
- * in line 1165 (tasks.c) for reference. For that reason, we provide a similar
- * initialization for an arbitrary task `pxTCB` and `pxCurrentTCB`.
- */
-
- pxTCB = xUnconstrainedTCB();
- if ( pxTCB != NULL )
- {
- if ( nondet_bool() )
- {
- TCB_t * pxOtherTCB;
- pxOtherTCB = xUnconstrainedTCB();
- /*
- * Nondeterministic insertion of another TCB in the same list
- * to guarantee coverage in line 1174 (tasks.c)
- */
- if ( pxOtherTCB != NULL )
- {
- vListInsert( &xPendingReadyList, &( pxOtherTCB->xStateListItem ) );
- }
- }
- vListInsert( &xPendingReadyList, &( pxTCB->xStateListItem ) );
-
- /*
- * Nondeterministic insertion of an event list item to guarantee
- * coverage in lines 1180-1184 (tasks.c)
- */
- if ( nondet_bool() )
- {
- vListInsert( pxDelayedTaskList, &( pxTCB->xEventListItem ) );
- }
- }
-
- /* Note that `*xTask = NULL` can happen here, but this is fine -- `pxCurrentTCB` will be used instead */
- *xTask = pxTCB;
-
- /*
- * `pxCurrentTCB` must be initialized the same way as the previous task, but an
- * allocation failure cannot happen in this case (i.e., if the previous task is NULL)
- */
- pxCurrentTCB = xUnconstrainedTCB();
- if ( pxCurrentTCB == NULL )
- {
- return pdFAIL;
- }
-
- if ( nondet_bool() )
- {
- TCB_t * pxOtherTCB;
- pxOtherTCB = xUnconstrainedTCB();
- if ( pxOtherTCB != NULL )
- {
- vListInsert( &pxReadyTasksLists[ pxOtherTCB->uxPriority ], &( pxOtherTCB->xStateListItem ) );
- }
- }
- vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
-
- /* Use of this macro ensures coverage on line 185 (list.c) */
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB , &pxReadyTasksLists[ pxCurrentTCB->uxPriority ] );
-
- if ( nondet_bool() )
- {
- vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xEventListItem ) );
- }
-
- return pdPASS;
+ TCB_t * pxTCB = NULL;
+
+ __CPROVER_assert_zero_allocation();
+
+ prvInitialiseTaskLists();
+
+ /*
+ * The task handle passed to TaskDelete can be NULL. In that case, the
+ * task to delete is the one in `pxCurrentTCB`, see the macro `prvGetTCBFromHandle`
+ * in line 1165 (tasks.c) for reference. For that reason, we provide a similar
+ * initialization for an arbitrary task `pxTCB` and `pxCurrentTCB`.
+ */
+
+ pxTCB = xUnconstrainedTCB();
+
+ if( pxTCB != NULL )
+ {
+ if( nondet_bool() )
+ {
+ TCB_t * pxOtherTCB;
+ pxOtherTCB = xUnconstrainedTCB();
+
+ /*
+ * Nondeterministic insertion of another TCB in the same list
+ * to guarantee coverage in line 1174 (tasks.c)
+ */
+ if( pxOtherTCB != NULL )
+ {
+ vListInsert( &xPendingReadyList, &( pxOtherTCB->xStateListItem ) );
+ }
+ }
+
+ vListInsert( &xPendingReadyList, &( pxTCB->xStateListItem ) );
+
+ /*
+ * Nondeterministic insertion of an event list item to guarantee
+ * coverage in lines 1180-1184 (tasks.c)
+ */
+ if( nondet_bool() )
+ {
+ vListInsert( pxDelayedTaskList, &( pxTCB->xEventListItem ) );
+ }
+ }
+
+ /* Note that `*xTask = NULL` can happen here, but this is fine -- `pxCurrentTCB` will be used instead */
+ *xTask = pxTCB;
+
+ /*
+ * `pxCurrentTCB` must be initialized the same way as the previous task, but an
+ * allocation failure cannot happen in this case (i.e., if the previous task is NULL)
+ */
+ pxCurrentTCB = xUnconstrainedTCB();
+
+ if( pxCurrentTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ if( nondet_bool() )
+ {
+ TCB_t * pxOtherTCB;
+ pxOtherTCB = xUnconstrainedTCB();
+
+ if( pxOtherTCB != NULL )
+ {
+ vListInsert( &pxReadyTasksLists[ pxOtherTCB->uxPriority ], &( pxOtherTCB->xStateListItem ) );
+ }
+ }
+
+ vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
+
+ /* Use of this macro ensures coverage on line 185 (list.c) */
+ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &pxReadyTasksLists[ pxCurrentTCB->uxPriority ] );
+
+ if( nondet_bool() )
+ {
+ vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xEventListItem ) );
+ }
+
+ return pdPASS;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/TaskGetCurrentTaskHandle_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/TaskGetCurrentTaskHandle_harness.c
index dac3c6685..0f95dd9cc 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/TaskGetCurrentTaskHandle_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/TaskGetCurrentTaskHandle_harness.c
@@ -40,15 +40,15 @@ BaseType_t xPrepareCurrentTCB( void );
*/
void harness()
{
- TaskHandle_t xTask;
- BaseType_t xTasksPrepared;
+ TaskHandle_t xTask;
+ BaseType_t xTasksPrepared;
- xTasksPrepared = xPrepareCurrentTCB();
+ xTasksPrepared = xPrepareCurrentTCB();
- if ( xTasksPrepared != pdFAIL )
- {
- xTask = xTaskGetCurrentTaskHandle();
+ if( xTasksPrepared != pdFAIL )
+ {
+ xTask = xTaskGetCurrentTaskHandle();
- __CPROVER_assert( xTask != NULL , "Current task handle is NULL!");
- }
+ __CPROVER_assert( xTask != NULL, "Current task handle is NULL!" );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/tasks_test_access_functions.h
index 29505148d..b8049e65c 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetCurrentTaskHandle/tasks_test_access_functions.h
@@ -33,12 +33,14 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
- if ( pxTCB == NULL )
- return NULL;
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
- return pxTCB;
+ return pxTCB;
}
/*
@@ -46,13 +48,14 @@ TaskHandle_t xUnconstrainedTCB( void )
*/
BaseType_t xPrepareCurrentTCB( void )
{
- __CPROVER_assert_zero_allocation();
+ __CPROVER_assert_zero_allocation();
- pxCurrentTCB = xUnconstrainedTCB();
- if ( pxCurrentTCB == NULL )
- {
- return pdFAIL;
- }
+ pxCurrentTCB = xUnconstrainedTCB();
- return pdPASS;
+ if( pxCurrentTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ return pdPASS;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/TaskGetSchedulerState_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/TaskGetSchedulerState_harness.c
index 557fb598e..d5e2e8f5a 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/TaskGetSchedulerState_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/TaskGetSchedulerState_harness.c
@@ -40,9 +40,9 @@ void vSetGlobalVariables( void );
*/
void harness()
{
- BaseType_t xResult;
+ BaseType_t xResult;
- vSetGlobalVariables();
+ vSetGlobalVariables();
- xResult = xTaskGetSchedulerState();
+ xResult = xTaskGetSchedulerState();
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/tasks_test_access_functions.h
index 7e1b29489..31181374a 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetSchedulerState/tasks_test_access_functions.h
@@ -32,6 +32,6 @@
*/
void vSetGlobalVariables( void )
{
- xSchedulerRunning = nondet_basetype();
- uxSchedulerSuspended = nondet_ubasetype();
+ xSchedulerRunning = nondet_basetype();
+ uxSchedulerSuspended = nondet_ubasetype();
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/TaskGetTaskNumber_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/TaskGetTaskNumber_harness.c
index 6df4fe393..f33fcbaa0 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/TaskGetTaskNumber_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/TaskGetTaskNumber_harness.c
@@ -40,10 +40,10 @@ void vPrepareTask( TaskHandle_t * xTask );
*/
void harness()
{
- TaskHandle_t xTask;
- UBaseType_t uxTaskNumber;
+ TaskHandle_t xTask;
+ UBaseType_t uxTaskNumber;
- vPrepareTask( &xTask );
+ vPrepareTask( &xTask );
- uxTaskNumber = uxTaskGetTaskNumber( xTask );
+ uxTaskNumber = uxTaskGetTaskNumber( xTask );
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/tasks_test_access_functions.h
index cfd998f3a..e7e53fc77 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTaskNumber/tasks_test_access_functions.h
@@ -33,12 +33,14 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
- if ( pxTCB == NULL )
- return NULL;
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
- return pxTCB;
+ return pxTCB;
}
/*
@@ -47,7 +49,7 @@ TaskHandle_t xUnconstrainedTCB( void )
*/
void vPrepareTask( TaskHandle_t * xTask )
{
- __CPROVER_assert_zero_allocation();
+ __CPROVER_assert_zero_allocation();
- *xTask = xUnconstrainedTCB();
+ *xTask = xUnconstrainedTCB();
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTickCount/TaskGetTickCount_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTickCount/TaskGetTickCount_harness.c
index 4229606eb..91637362a 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTickCount/TaskGetTickCount_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskGetTickCount/TaskGetTickCount_harness.c
@@ -34,7 +34,7 @@
void harness()
{
- TickType_t xTickCount;
+ TickType_t xTickCount;
- xTickCount = xTaskGetTickCount();
+ xTickCount = xTaskGetTickCount();
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/TaskIncrementTick_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/TaskIncrementTick_harness.c
index db2b41472..73d3780a8 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/TaskIncrementTick_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/TaskIncrementTick_harness.c
@@ -41,13 +41,13 @@ BaseType_t xPrepareTaskLists( void );
*/
void harness()
{
- BaseType_t xTasksPrepared;
+ BaseType_t xTasksPrepared;
- vSetGlobalVariables();
- xTasksPrepared = xPrepareTaskLists();
+ vSetGlobalVariables();
+ xTasksPrepared = xPrepareTaskLists();
- if ( xTasksPrepared != pdFAIL )
- {
- xTaskIncrementTick();
- }
+ if( xTasksPrepared != pdFAIL )
+ {
+ xTaskIncrementTick();
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/tasks_test_access_functions.h
index e6bf00058..0a53b8ed9 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskIncrementTick/tasks_test_access_functions.h
@@ -33,37 +33,40 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
-
- if ( pxTCB == NULL )
- return NULL;
-
- __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
-
- vListInitialiseItem( &( pxTCB->xStateListItem ) );
- vListInitialiseItem( &( pxTCB->xEventListItem ) );
-
- listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
- listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
- }
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
- }
- return pxTCB;
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
+
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
+
+ __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
+
+ vListInitialiseItem( &( pxTCB->xStateListItem ) );
+ vListInitialiseItem( &( pxTCB->xEventListItem ) );
+
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
+ }
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
+ }
+
+ return pxTCB;
}
/*
@@ -72,10 +75,10 @@ TaskHandle_t xUnconstrainedTCB( void )
*/
void vSetGlobalVariables()
{
- xPendedTicks = nondet_ubasetype();
- uxSchedulerSuspended = nondet_ubasetype();
- xYieldPending = nondet_basetype();
- xTickCount = nondet_ticktype();
+ xPendedTicks = nondet_ubasetype();
+ uxSchedulerSuspended = nondet_ubasetype();
+ xYieldPending = nondet_basetype();
+ xTickCount = nondet_ticktype();
}
/*
@@ -85,42 +88,48 @@ void vSetGlobalVariables()
*/
BaseType_t xPrepareTaskLists( void )
{
- TCB_t * pxTCB = NULL;
-
- __CPROVER_assert_zero_allocation();
-
- prvInitialiseTaskLists();
-
- /* Needed for coverage: This task will be moved to a ready list */
- pxTCB = xUnconstrainedTCB();
- if ( pxTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xStateListItem ) );
-
- /* Needed for coverage. */
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB , pxOverflowDelayedTaskList );
-
- pxTCB = xUnconstrainedTCB();
- if ( pxTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( &xPendingReadyList, &( pxTCB->xStateListItem ) );
-
- /* Needed for coverage: A nondeterministic choice */
- if ( nondet_bool() )
- {
- vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xEventListItem ) );
- }
-
- pxCurrentTCB = xUnconstrainedTCB();
- if ( pxCurrentTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
-
- return pdPASS;
+ TCB_t * pxTCB = NULL;
+
+ __CPROVER_assert_zero_allocation();
+
+ prvInitialiseTaskLists();
+
+ /* Needed for coverage: This task will be moved to a ready list */
+ pxTCB = xUnconstrainedTCB();
+
+ if( pxTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xStateListItem ) );
+
+ /* Needed for coverage. */
+ listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxOverflowDelayedTaskList );
+
+ pxTCB = xUnconstrainedTCB();
+
+ if( pxTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( &xPendingReadyList, &( pxTCB->xStateListItem ) );
+
+ /* Needed for coverage: A nondeterministic choice */
+ if( nondet_bool() )
+ {
+ vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xEventListItem ) );
+ }
+
+ pxCurrentTCB = xUnconstrainedTCB();
+
+ if( pxCurrentTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
+
+ return pdPASS;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/TaskPrioritySet_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/TaskPrioritySet_harness.c
index 30339538d..92dd0dfdc 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/TaskPrioritySet_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/TaskPrioritySet_harness.c
@@ -41,17 +41,17 @@ BaseType_t xPrepareTaskLists( TaskHandle_t * xTask );
*/
void harness()
{
- TaskHandle_t xTask;
- UBaseType_t uxNewPriority;
- BaseType_t xTasksPrepared;
+ TaskHandle_t xTask;
+ UBaseType_t uxNewPriority;
+ BaseType_t xTasksPrepared;
- __CPROVER_assume( uxNewPriority < configMAX_PRIORITIES );
+ __CPROVER_assume( uxNewPriority < configMAX_PRIORITIES );
- xTasksPrepared = xPrepareTaskLists( &xTask );
+ xTasksPrepared = xPrepareTaskLists( &xTask );
- /* Check that this second invocation of xPrepareTaskLists is needed. */
- if ( xPrepareTaskLists( &xTask ) != pdFAIL )
- {
- vTaskPrioritySet( xTask, uxNewPriority );
- }
+ /* Check that this second invocation of xPrepareTaskLists is needed. */
+ if( xPrepareTaskLists( &xTask ) != pdFAIL )
+ {
+ vTaskPrioritySet( xTask, uxNewPriority );
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/tasks_test_access_functions.h
index 9128138ab..dc87f949a 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskPrioritySet/tasks_test_access_functions.h
@@ -33,39 +33,41 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
- uint8_t ucStaticAllocationFlag;
-
- if ( pxTCB == NULL )
- return NULL;
-
- __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
-
- vListInitialiseItem( &( pxTCB->xStateListItem ) );
- vListInitialiseItem( &( pxTCB->xEventListItem ) );
-
- listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
- listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
- }
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
- }
-
- return pxTCB;
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
+ uint8_t ucStaticAllocationFlag;
+
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
+
+ __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
+
+ vListInitialiseItem( &( pxTCB->xStateListItem ) );
+ vListInitialiseItem( &( pxTCB->xEventListItem ) );
+
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
+ }
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
+ }
+
+ return pxTCB;
}
/*
@@ -75,51 +77,53 @@ TaskHandle_t xUnconstrainedTCB( void )
*/
BaseType_t xPrepareTaskLists( TaskHandle_t * xTask )
{
- TCB_t * pxTCB = NULL;
-
- __CPROVER_assert_zero_allocation();
-
- prvInitialiseTaskLists();
-
- pxTCB = xUnconstrainedTCB();
-
- /* Needed for coverage: nondet insertion of task. */
- if ( nondet_bool() )
- {
- TCB_t * pxOtherTCB;
- pxOtherTCB = xUnconstrainedTCB();
- if ( pxOtherTCB != NULL )
- {
- vListInsert( &pxReadyTasksLists[ pxOtherTCB->uxPriority ], &( pxOtherTCB->xStateListItem ) );
- }
- }
-
- if ( pxTCB != NULL )
- {
- /* Needed for coverage: nondeterministic insertion of task */
- if ( nondet_bool() )
- {
- vListInsert( &pxReadyTasksLists[ pxTCB->uxPriority ], &( pxTCB->xStateListItem ) );
- }
- }
-
- /* Note that `*xTask = NULL` can happen here, but this is fine -- `pxCurrentTCB` will be used instead */
- *xTask = pxTCB;
-
- pxCurrentTCB = xUnconstrainedTCB();
- if ( pxCurrentTCB == NULL )
- {
- return pdFAIL;
- }
-
- /* Needed for coverage: nondeterministic insertion of task */
- if ( nondet_bool() )
- {
- vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
-
- /* Needed for coverage. */
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB , &pxReadyTasksLists[ pxCurrentTCB->uxPriority ] );
- }
-
- return pdPASS;
+ TCB_t * pxTCB = NULL;
+
+ __CPROVER_assert_zero_allocation();
+
+ prvInitialiseTaskLists();
+
+ pxTCB = xUnconstrainedTCB();
+
+ /* Needed for coverage: nondet insertion of task. */
+ if( nondet_bool() )
+ {
+ TCB_t * pxOtherTCB;
+ pxOtherTCB = xUnconstrainedTCB();
+
+ if( pxOtherTCB != NULL )
+ {
+ vListInsert( &pxReadyTasksLists[ pxOtherTCB->uxPriority ], &( pxOtherTCB->xStateListItem ) );
+ }
+ }
+
+ if( pxTCB != NULL )
+ {
+ /* Needed for coverage: nondeterministic insertion of task */
+ if( nondet_bool() )
+ {
+ vListInsert( &pxReadyTasksLists[ pxTCB->uxPriority ], &( pxTCB->xStateListItem ) );
+ }
+ }
+
+ /* Note that `*xTask = NULL` can happen here, but this is fine -- `pxCurrentTCB` will be used instead */
+ *xTask = pxTCB;
+
+ pxCurrentTCB = xUnconstrainedTCB();
+
+ if( pxCurrentTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ /* Needed for coverage: nondeterministic insertion of task */
+ if( nondet_bool() )
+ {
+ vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
+
+ /* Needed for coverage. */
+ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &pxReadyTasksLists[ pxCurrentTCB->uxPriority ] );
+ }
+
+ return pdPASS;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/TaskResumeAll_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/TaskResumeAll_harness.c
index fbb4956f5..636ca422c 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/TaskResumeAll_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/TaskResumeAll_harness.c
@@ -41,13 +41,13 @@ BaseType_t xPrepareTaskLists( void );
*/
void harness()
{
- BaseType_t xTasksPrepared;
+ BaseType_t xTasksPrepared;
- vSetGlobalVariables();
- xTasksPrepared = xPrepareTaskLists();
+ vSetGlobalVariables();
+ xTasksPrepared = xPrepareTaskLists();
- if ( xTasksPrepared != pdFAIL )
- {
- xTaskResumeAll();
- }
+ if( xTasksPrepared != pdFAIL )
+ {
+ xTaskResumeAll();
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/tasks_test_access_functions.h
index 981cd8284..906499432 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskResumeAll/tasks_test_access_functions.h
@@ -33,52 +33,56 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
-
- if ( pxTCB == NULL )
- return NULL;
-
- __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
-
- vListInitialiseItem( &( pxTCB->xStateListItem ) );
- vListInitialiseItem( &( pxTCB->xEventListItem ) );
-
- listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
- listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
- }
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
- }
- return pxTCB;
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
+
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
+
+ __CPROVER_assume( pxTCB->uxPriority < configMAX_PRIORITIES );
+
+ vListInitialiseItem( &( pxTCB->xStateListItem ) );
+ vListInitialiseItem( &( pxTCB->xEventListItem ) );
+
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
+ }
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
+ }
+
+ return pxTCB;
}
/*
* We set xPendedTicks since __CPROVER_assume does not work
* well with statically initialised variables
*/
-void vSetGlobalVariables( void ) {
- UBaseType_t uxNonZeroValue;
+void vSetGlobalVariables( void )
+{
+ UBaseType_t uxNonZeroValue;
- __CPROVER_assume( uxNonZeroValue != 0 );
+ __CPROVER_assume( uxNonZeroValue != 0 );
- uxSchedulerSuspended = uxNonZeroValue;
- xPendedTicks = nondet_bool() ? PENDED_TICKS : 0;
- uxCurrentNumberOfTasks = nondet_ubasetype();
- xTickCount = nondet_ticktype();
+ uxSchedulerSuspended = uxNonZeroValue;
+ xPendedTicks = nondet_bool() ? PENDED_TICKS : 0;
+ uxCurrentNumberOfTasks = nondet_ubasetype();
+ xTickCount = nondet_ticktype();
}
/*
@@ -88,51 +92,59 @@ void vSetGlobalVariables( void ) {
*/
BaseType_t xPrepareTaskLists( void )
{
- TCB_t * pxTCB = NULL;
-
- __CPROVER_assert_zero_allocation();
-
- prvInitialiseTaskLists();
-
- /* This task will be moved to a ready list, granting coverage
- * on lines 2780-2786 (tasks.c) */
- pxTCB = xUnconstrainedTCB();
- if ( pxTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xStateListItem ) );
-
- /* Use of this macro ensures coverage on line 185 (list.c) */
- listGET_OWNER_OF_NEXT_ENTRY( pxTCB , pxOverflowDelayedTaskList );
-
- pxTCB = xUnconstrainedTCB();
- if ( pxTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( &xPendingReadyList, &( pxTCB->xStateListItem ) );
- vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xEventListItem ) );
-
- pxTCB = xUnconstrainedTCB();
- if ( pxTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xStateListItem ) );
-
- /* This nondeterministic choice ensure coverage in line 2746 (tasks.c) */
- if ( nondet_bool() )
- {
- vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xEventListItem ) );
- }
-
- pxCurrentTCB = xUnconstrainedTCB();
- if ( pxCurrentTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
-
- return pdPASS;
+ TCB_t * pxTCB = NULL;
+
+ __CPROVER_assert_zero_allocation();
+
+ prvInitialiseTaskLists();
+
+ /* This task will be moved to a ready list, granting coverage
+ * on lines 2780-2786 (tasks.c) */
+ pxTCB = xUnconstrainedTCB();
+
+ if( pxTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xStateListItem ) );
+
+ /* Use of this macro ensures coverage on line 185 (list.c) */
+ listGET_OWNER_OF_NEXT_ENTRY( pxTCB, pxOverflowDelayedTaskList );
+
+ pxTCB = xUnconstrainedTCB();
+
+ if( pxTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( &xPendingReadyList, &( pxTCB->xStateListItem ) );
+ vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xEventListItem ) );
+
+ pxTCB = xUnconstrainedTCB();
+
+ if( pxTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xStateListItem ) );
+
+ /* This nondeterministic choice ensure coverage in line 2746 (tasks.c) */
+ if( nondet_bool() )
+ {
+ vListInsert( pxOverflowDelayedTaskList, &( pxTCB->xEventListItem ) );
+ }
+
+ pxCurrentTCB = xUnconstrainedTCB();
+
+ if( pxCurrentTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ vListInsert( &pxReadyTasksLists[ pxCurrentTCB->uxPriority ], &( pxCurrentTCB->xStateListItem ) );
+
+ return pdPASS;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskSetTimeOutState/TaskSetTimeOutState_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskSetTimeOutState/TaskSetTimeOutState_harness.c
index b38aee6ea..0e3becfc4 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskSetTimeOutState/TaskSetTimeOutState_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskSetTimeOutState/TaskSetTimeOutState_harness.c
@@ -38,7 +38,7 @@
*/
void harness()
{
- TimeOut_t xTime;
+ TimeOut_t xTime;
- vTaskSetTimeOutState( &xTime );
+ vTaskSetTimeOutState( &xTime );
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/TaskStartScheduler_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/TaskStartScheduler_harness.c
index ffa84fab1..89c9f1107 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/TaskStartScheduler_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/TaskStartScheduler_harness.c
@@ -40,12 +40,12 @@ BaseType_t xPrepareTasks( void );
*/
void harness()
{
- BaseType_t xTasksPrepared;
+ BaseType_t xTasksPrepared;
- xTasksPrepared = xPrepareTasks();
+ xTasksPrepared = xPrepareTasks();
- if ( xTasksPrepared != pdFAIL )
- {
- vTaskStartScheduler();
- }
+ if( xTasksPrepared != pdFAIL )
+ {
+ vTaskStartScheduler();
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/tasks_test_access_functions.h
index e8766145f..24a30b28a 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskStartScheduler/tasks_test_access_functions.h
@@ -35,18 +35,20 @@
*/
TaskHandle_t xUnconstrainedTCB( void )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
- if ( pxTCB == NULL )
- return NULL;
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
- return pxTCB;
+ return pxTCB;
}
-StaticTask_t *pxIdleTaskTCB;
-StaticTask_t *pxTimerTaskTCB;
-StackType_t *pxIdleTaskStack;
-StackType_t *pxTimerTaskStack;
+StaticTask_t * pxIdleTaskTCB;
+StaticTask_t * pxTimerTaskTCB;
+StackType_t * pxIdleTaskStack;
+StackType_t * pxTimerTaskStack;
/*
* `pxCurrentTCB` allocation is allowed to fail. The global variables above
@@ -56,37 +58,41 @@ StackType_t *pxTimerTaskStack;
*/
BaseType_t xPrepareTasks( void )
{
- __CPROVER_assert_zero_allocation();
+ __CPROVER_assert_zero_allocation();
- prvInitialiseTaskLists();
+ prvInitialiseTaskLists();
- pxCurrentTCB = xUnconstrainedTCB();
+ pxCurrentTCB = xUnconstrainedTCB();
- pxIdleTaskTCB = pvPortMalloc(sizeof(StaticTask_t));
- if (pxIdleTaskTCB == NULL )
- {
- return pdFAIL;
- }
+ pxIdleTaskTCB = pvPortMalloc( sizeof( StaticTask_t ) );
- pxIdleTaskStack = pvPortMalloc( sizeof(StackType_t) * configMINIMAL_STACK_SIZE );
- if ( pxIdleTaskStack == NULL )
- {
- return pdFAIL;
- }
+ if( pxIdleTaskTCB == NULL )
+ {
+ return pdFAIL;
+ }
- pxTimerTaskTCB = pvPortMalloc( sizeof(StaticTask_t) );
- if ( pxTimerTaskTCB == NULL )
- {
- return pdFAIL;
- }
+ pxIdleTaskStack = pvPortMalloc( sizeof( StackType_t ) * configMINIMAL_STACK_SIZE );
- pxTimerTaskStack = pvPortMalloc( sizeof(StackType_t) * configTIMER_TASK_STACK_DEPTH );
- if ( pxTimerTaskStack == NULL )
- {
- return pdFAIL;
- }
+ if( pxIdleTaskStack == NULL )
+ {
+ return pdFAIL;
+ }
- return pdPASS;
+ pxTimerTaskTCB = pvPortMalloc( sizeof( StaticTask_t ) );
+
+ if( pxTimerTaskTCB == NULL )
+ {
+ return pdFAIL;
+ }
+
+ pxTimerTaskStack = pvPortMalloc( sizeof( StackType_t ) * configTIMER_TASK_STACK_DEPTH );
+
+ if( pxTimerTaskStack == NULL )
+ {
+ return pdFAIL;
+ }
+
+ return pdPASS;
}
/*
@@ -96,17 +102,19 @@ void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize )
{
- *ppxIdleTaskTCBBuffer = pxIdleTaskTCB;
- *ppxIdleTaskStackBuffer = pxIdleTaskStack;
+ *ppxIdleTaskTCBBuffer = pxIdleTaskTCB;
+ *ppxIdleTaskStackBuffer = pxIdleTaskStack;
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
/*
* The buffers used here have been successfully allocated before (global variables)
*/
-void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
+void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
+ StackType_t ** ppxTimerTaskStackBuffer,
+ uint32_t * pulTimerTaskStackSize )
{
- *ppxTimerTaskTCBBuffer = pxTimerTaskTCB;
- *ppxTimerTaskStackBuffer = pxTimerTaskStack;
- *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
+ *ppxTimerTaskTCBBuffer = pxTimerTaskTCB;
+ *ppxTimerTaskStackBuffer = pxTimerTaskStack;
+ *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskSuspendAll/TaskSuspendAll_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskSuspendAll/TaskSuspendAll_harness.c
index 3fe438229..64607050f 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskSuspendAll/TaskSuspendAll_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskSuspendAll/TaskSuspendAll_harness.c
@@ -38,5 +38,5 @@
*/
void harness()
{
- vTaskSuspendAll();
+ vTaskSuspendAll();
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/TaskSwitchContext_harness.c b/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/TaskSwitchContext_harness.c
index 52295bc81..0a307cbf7 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/TaskSwitchContext_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/TaskSwitchContext_harness.c
@@ -42,13 +42,13 @@ BaseType_t xPrepareTaskLists( void );
*/
void harness()
{
- BaseType_t xTasksPrepared;
+ BaseType_t xTasksPrepared;
- vSetGlobalVariables();
- xTasksPrepared = xPrepareTaskLists();
+ vSetGlobalVariables();
+ xTasksPrepared = xPrepareTaskLists();
- if ( xTasksPrepared != pdFAIL )
- {
- vTaskSwitchContext();
- }
+ if( xTasksPrepared != pdFAIL )
+ {
+ vTaskSwitchContext();
+ }
}
diff --git a/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/tasks_test_access_functions.h b/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/tasks_test_access_functions.h
index 2b5ebff7f..b7fcddbb7 100644
--- a/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/tasks_test_access_functions.h
+++ b/FreeRTOS/Test/CBMC/proofs/Task/TaskSwitchContext/tasks_test_access_functions.h
@@ -33,38 +33,41 @@
*/
TaskHandle_t xUnconstrainedTCB( UBaseType_t uxPriority )
{
- TCB_t * pxTCB = pvPortMalloc(sizeof(TCB_t));
-
- if ( pxTCB == NULL )
- return NULL;
-
- /* uxPriority is set to a specific priority */
- pxTCB->uxPriority = uxPriority;
-
- vListInitialiseItem( &( pxTCB->xStateListItem ) );
- vListInitialiseItem( &( pxTCB->xEventListItem ) );
-
- listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
- listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
- }
-
- if ( nondet_bool() )
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
- }
- else
- {
- listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
- }
- return pxTCB;
+ TCB_t * pxTCB = pvPortMalloc( sizeof( TCB_t ) );
+
+ if( pxTCB == NULL )
+ {
+ return NULL;
+ }
+
+ /* uxPriority is set to a specific priority */
+ pxTCB->uxPriority = uxPriority;
+
+ vListInitialiseItem( &( pxTCB->xStateListItem ) );
+ vListInitialiseItem( &( pxTCB->xEventListItem ) );
+
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xStateListItem ), pxTCB );
+ listSET_LIST_ITEM_OWNER( &( pxTCB->xEventListItem ), pxTCB );
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xStateListItem ), portMAX_DELAY );
+ }
+
+ if( nondet_bool() )
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), ( TickType_t ) configMAX_PRIORITIES - ( TickType_t ) pxTCB->uxPriority );
+ }
+ else
+ {
+ listSET_LIST_ITEM_VALUE( &( pxTCB->xEventListItem ), portMAX_DELAY );
+ }
+
+ return pxTCB;
}
/*
@@ -73,7 +76,7 @@ TaskHandle_t xUnconstrainedTCB( UBaseType_t uxPriority )
*/
void vSetGlobalVariables( void )
{
- uxSchedulerSuspended = nondet_ubasetype();
+ uxSchedulerSuspended = nondet_ubasetype();
}
/*
@@ -82,22 +85,25 @@ void vSetGlobalVariables( void )
*/
BaseType_t xPrepareTaskLists( void )
{
- TCB_t * pxTCB = NULL;
+ TCB_t * pxTCB = NULL;
+
+ __CPROVER_assert_zero_allocation();
+
+ prvInitialiseTaskLists();
+
+ for( int i = 0; i < configMAX_PRIORITIES; ++i )
+ {
+ pxTCB = xUnconstrainedTCB( i );
- __CPROVER_assert_zero_allocation();
+ if( pxTCB == NULL )
+ {
+ return pdFAIL;
+ }
- prvInitialiseTaskLists();
+ vListInsert( &pxReadyTasksLists[ pxTCB->uxPriority ], &( pxTCB->xStateListItem ) );
+ }
- for ( int i = 0; i < configMAX_PRIORITIES; ++i )
- {
- pxTCB = xUnconstrainedTCB( i );
- if ( pxTCB == NULL )
- {
- return pdFAIL;
- }
- vListInsert( &pxReadyTasksLists[ pxTCB->uxPriority ], &( pxTCB->xStateListItem ) );
- }
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &pxReadyTasksLists[ configMAX_PRIORITIES - 1 ] );
+ listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB, &pxReadyTasksLists[ configMAX_PRIORITIES - 1 ] );
- return pdPASS;
+ return pdPASS;
}
diff --git a/FreeRTOS/Test/CBMC/proofs/utility/memory_assignments.c b/FreeRTOS/Test/CBMC/proofs/utility/memory_assignments.c
index 6bcb9319a..ed2ec5bbb 100644
--- a/FreeRTOS/Test/CBMC/proofs/utility/memory_assignments.c
+++ b/FreeRTOS/Test/CBMC/proofs/utility/memory_assignments.c
@@ -1,24 +1,30 @@
-#define ensure_memory_is_valid( px, length ) (px != NULL) && __CPROVER_w_ok((px), length)
+#define ensure_memory_is_valid( px, length ) ( px != NULL ) && __CPROVER_w_ok( ( px ), length )
/* Implementation of safe malloc which returns NULL if the requested size is 0.
- Warning: The behavior of malloc(0) is platform dependent.
- It is possible for malloc(0) to return an address without allocating memory.*/
-void *safeMalloc(size_t xWantedSize) {
- return nondet_bool() ? malloc(xWantedSize) : NULL;
+ * Warning: The behavior of malloc(0) is platform dependent.
+ * It is possible for malloc(0) to return an address without allocating memory.*/
+void * safeMalloc( size_t xWantedSize )
+{
+ return nondet_bool() ? malloc( xWantedSize ) : NULL;
}
/* Memory assignment for FreeRTOS_Socket_t */
-FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated () {
- FreeRTOS_Socket_t *pxSocket = safeMalloc(sizeof(FreeRTOS_Socket_t));
- if (ensure_memory_is_valid(pxSocket, sizeof(FreeRTOS_Socket_t))) {
- pxSocket->u.xTCP.rxStream = safeMalloc(sizeof(StreamBuffer_t));
- pxSocket->u.xTCP.txStream = safeMalloc(sizeof(StreamBuffer_t));
- pxSocket->u.xTCP.pxPeerSocket = safeMalloc(sizeof(FreeRTOS_Socket_t));
- }
- return pxSocket;
+FreeRTOS_Socket_t * ensure_FreeRTOS_Socket_t_is_allocated()
+{
+ FreeRTOS_Socket_t * pxSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
+
+ if( ensure_memory_is_valid( pxSocket, sizeof( FreeRTOS_Socket_t ) ) )
+ {
+ pxSocket->u.xTCP.rxStream = safeMalloc( sizeof( StreamBuffer_t ) );
+ pxSocket->u.xTCP.txStream = safeMalloc( sizeof( StreamBuffer_t ) );
+ pxSocket->u.xTCP.pxPeerSocket = safeMalloc( sizeof( FreeRTOS_Socket_t ) );
+ }
+
+ return pxSocket;
}
/* Memory assignment for FreeRTOS_Network_Buffer */
-NetworkBufferDescriptor_t * ensure_FreeRTOS_NetworkBuffer_is_allocated () {
- return safeMalloc(sizeof(NetworkBufferDescriptor_t));
+NetworkBufferDescriptor_t * ensure_FreeRTOS_NetworkBuffer_is_allocated()
+{
+ return safeMalloc( sizeof( NetworkBufferDescriptor_t ) );
}
diff --git a/FreeRTOS/Test/CBMC/windows/direct.h b/FreeRTOS/Test/CBMC/windows/direct.h
index 8b1378917..e69de29bb 100644
--- a/FreeRTOS/Test/CBMC/windows/direct.h
+++ b/FreeRTOS/Test/CBMC/windows/direct.h
@@ -1 +0,0 @@
-
diff --git a/FreeRTOS/Test/CMock/config/FreeRTOSConfig.h b/FreeRTOS/Test/CMock/config/FreeRTOSConfig.h
index dd8a590a7..b275391e3 100644
--- a/FreeRTOS/Test/CMock/config/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CMock/config/FreeRTOSConfig.h
@@ -126,7 +126,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
- } while ( 0 )
+ } while( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
diff --git a/FreeRTOS/Test/CMock/event_groups/event_groups_utest.c b/FreeRTOS/Test/CMock/event_groups/event_groups_utest.c
index ed55bb68d..35dc5968b 100644
--- a/FreeRTOS/Test/CMock/event_groups/event_groups_utest.c
+++ b/FreeRTOS/Test/CMock/event_groups/event_groups_utest.c
@@ -194,7 +194,7 @@ void test_xEventGroupStaticCreate_Success( void )
/*!
* @brief validate statically creating and deleting a new RTOS event group,
- *
+ *
*/
void test_xEventGroupStaticCreate_InvalidInput_Failed( void )
{
@@ -435,7 +435,7 @@ void test_xEventGroupWaitBits_WhenNoBitWasSet_WaitForBoth_ClearBit_Success( void
vListInitialise_Expect( 0 );
vListInitialise_IgnoreArg_pxList();
vListInitialise_ReturnThruPtr_pxList( pxListTemp );
-
+
/* Expectation of Function: xEventGroupWaitBits */
vTaskSuspendAll_Ignore();
xTaskGetSchedulerState_IgnoreAndReturn( taskSCHEDULER_SUSPENDED );
@@ -463,7 +463,7 @@ void test_xEventGroupWaitBits_WhenNoBitWasSet_WaitForBoth_ClearBit_Success( void
}
/*!
- * @brief validate non-block waiting on for either one bits is set when currently no bits are set.
+ * @brief validate non-block waiting on for either one bits is set when currently no bits are set.
* Don't clear the bit before return.
* @coverage xEventGroupWaitBits
*/
@@ -486,7 +486,7 @@ void test_xEventGroupWaitBits_WhenNoBitWasSet_NonBlock_WaitForEither_NoClear_Suc
StaticEventGroup_t xCreatedEventGroup = { 0 };
xEventGroupHandle = xEventGroupCreateStatic( &xCreatedEventGroup );
uxBitsSetVal = xEventGroupGetBits( xEventGroupHandle );
-
+
/* API to Test */
uxBitsGetVal = xEventGroupWaitBits(
xEventGroupHandle, /* The event group being tested. */
@@ -500,7 +500,7 @@ void test_xEventGroupWaitBits_WhenNoBitWasSet_NonBlock_WaitForEither_NoClear_Suc
}
/*!
- * @brief validate waiting on for either one bits. The function should return when one bits are set.
+ * @brief validate waiting on for either one bits. The function should return when one bits are set.
* Don't clear the bit before return.
* @coverage xEventGroupWaitBits
*/
@@ -528,7 +528,7 @@ void test_xEventGroupWaitBits_WhenBitWasSet_WaitForEither_NoClear_Success( void
const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
StaticEventGroup_t xCreatedEventGroup = { 0 };
xEventGroupHandle = xEventGroupCreateStatic( &xCreatedEventGroup );
- uxBitsSetVal = xEventGroupSetBits( xEventGroupHandle, BIT_0 ); /* BIT_0 was set */
+ uxBitsSetVal = xEventGroupSetBits( xEventGroupHandle, BIT_0 ); /* BIT_0 was set */
/* API to Test */
uxBitsSetVal = xEventGroupWaitBits(
@@ -574,8 +574,8 @@ void test_xEventGroupWaitBits_WhenBitWasSet_WaitForBoth_WithClear_Success( void
const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
StaticEventGroup_t xCreatedEventGroup = { 0 };
xEventGroupHandle = xEventGroupCreateStatic( &xCreatedEventGroup );
- uxBitsSetVal = xEventGroupSetBits( xEventGroupHandle, BIT_0 ); /* BIT_0 was set */
- uxBitsSetVal = xEventGroupSetBits( xEventGroupHandle, BIT_4 ); /* BIT_4 was set */
+ uxBitsSetVal = xEventGroupSetBits( xEventGroupHandle, BIT_0 ); /* BIT_0 was set */
+ uxBitsSetVal = xEventGroupSetBits( xEventGroupHandle, BIT_4 ); /* BIT_4 was set */
TEST_ASSERT_EQUAL( BIT_0 | BIT_4, uxBitsSetVal );
/* API to Test */
@@ -594,7 +594,7 @@ void test_xEventGroupWaitBits_WhenBitWasSet_WaitForBoth_WithClear_Success( void
/*!
* @brief validate tasks sync on event bits:
- * Set BIT_0 before reach the sync point and wait for all sync bits are set.
+ * Set BIT_0 before reach the sync point and wait for all sync bits are set.
* Should return due to timeout.
* @coverage xEventGroupSync
*/
@@ -611,7 +611,7 @@ void test_xEventGroupSync_SetBits_BlockWait_NotSynced_Success( void )
listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) NULL );
xTaskResumeAll_IgnoreAndReturn( 1 );
listGET_LIST_ITEM_VALUE_IgnoreAndReturn( 0 );
-
+
/* Expectation of Function: xEventGroupSync */
xTaskGetSchedulerState_IgnoreAndReturn( taskSCHEDULER_SUSPENDED );
vTaskPlaceOnUnorderedEventList_Ignore();
diff --git a/FreeRTOS/Test/CMock/message_buffer/message_buffer_utest.c b/FreeRTOS/Test/CMock/message_buffer/message_buffer_utest.c
index 4c3536d84..e0f8d9cb8 100644
--- a/FreeRTOS/Test/CMock/message_buffer/message_buffer_utest.c
+++ b/FreeRTOS/Test/CMock/message_buffer/message_buffer_utest.c
@@ -98,7 +98,7 @@
{ \
TEST_ASSERT_EQUAL( configASSERT_E, e ); \
} \
- } while ( 0 )
+ } while( 0 )
/* ============================ GLOBAL VARIABLES =========================== */
diff --git a/FreeRTOS/Test/CMock/queue/dynamic/FreeRTOSConfig.h b/FreeRTOS/Test/CMock/queue/dynamic/FreeRTOSConfig.h
index aa4968216..6407ac1ff 100644
--- a/FreeRTOS/Test/CMock/queue/dynamic/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CMock/queue/dynamic/FreeRTOSConfig.h
@@ -127,7 +127,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
- } while ( 0 )
+ } while( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
diff --git a/FreeRTOS/Test/CMock/queue/generic/FreeRTOSConfig.h b/FreeRTOS/Test/CMock/queue/generic/FreeRTOSConfig.h
index aa75e8817..e1e35f921 100644
--- a/FreeRTOS/Test/CMock/queue/generic/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CMock/queue/generic/FreeRTOSConfig.h
@@ -126,7 +126,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
- } while ( 0 )
+ } while( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
diff --git a/FreeRTOS/Test/CMock/queue/queue_utest_common.c b/FreeRTOS/Test/CMock/queue/queue_utest_common.c
index eed1b000b..4613e70ba 100644
--- a/FreeRTOS/Test/CMock/queue/queue_utest_common.c
+++ b/FreeRTOS/Test/CMock/queue/queue_utest_common.c
@@ -57,9 +57,9 @@ static uint32_t ulNumMallocCalls = 0;
/* =========================== HELPER FUNCTIONS =========================== */
void setxMaskAssertAndAbort( bool mask )
{
- xMaskAssertAndAbort = mask;
+ xMaskAssertAndAbort = mask;
}
-bool getxMaskAssertAndAbort( )
+bool getxMaskAssertAndAbort()
{
return xMaskAssertAndAbort;
}
diff --git a/FreeRTOS/Test/CMock/queue/queue_utest_common.h b/FreeRTOS/Test/CMock/queue/queue_utest_common.h
index bca0e16b7..15e69fd3e 100644
--- a/FreeRTOS/Test/CMock/queue/queue_utest_common.h
+++ b/FreeRTOS/Test/CMock/queue/queue_utest_common.h
@@ -70,7 +70,7 @@
/* =========================== FUNCTION PROTOTYPES ======================== */
void setxMaskAssertAndAbort( bool mask );
-bool getxMaskAssertAndAbort( );
+bool getxMaskAssertAndAbort();
/* ============================ GLOBAL VARIABLES =========================== */
/* ================================= MACROS ================================ */
@@ -93,7 +93,7 @@ bool getxMaskAssertAndAbort( );
} \
Catch( e ) \
TEST_ASSERT_EQUAL( configASSERT_E, e ); \
- } while ( 0 )
+ } while( 0 )
/* ========================== CALLBACK FUNCTIONS =========================== */
diff --git a/FreeRTOS/Test/CMock/queue/semaphore/FreeRTOSConfig.h b/FreeRTOS/Test/CMock/queue/semaphore/FreeRTOSConfig.h
index aa75e8817..e1e35f921 100644
--- a/FreeRTOS/Test/CMock/queue/semaphore/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CMock/queue/semaphore/FreeRTOSConfig.h
@@ -126,7 +126,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
- } while ( 0 )
+ } while( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
diff --git a/FreeRTOS/Test/CMock/queue/sets/FreeRTOSConfig.h b/FreeRTOS/Test/CMock/queue/sets/FreeRTOSConfig.h
index 65727250f..44caede51 100644
--- a/FreeRTOS/Test/CMock/queue/sets/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CMock/queue/sets/FreeRTOSConfig.h
@@ -126,7 +126,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
- } while ( 0 )
+ } while( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
diff --git a/FreeRTOS/Test/CMock/queue/static/FreeRTOSConfig.h b/FreeRTOS/Test/CMock/queue/static/FreeRTOSConfig.h
index 613ce07ed..d748899e3 100644
--- a/FreeRTOS/Test/CMock/queue/static/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CMock/queue/static/FreeRTOSConfig.h
@@ -127,7 +127,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
- } while ( 0 )
+ } while( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
diff --git a/FreeRTOS/Test/CMock/queue/tracing/FreeRTOSConfig.h b/FreeRTOS/Test/CMock/queue/tracing/FreeRTOSConfig.h
index 93855d01f..6d9810f91 100644
--- a/FreeRTOS/Test/CMock/queue/tracing/FreeRTOSConfig.h
+++ b/FreeRTOS/Test/CMock/queue/tracing/FreeRTOSConfig.h
@@ -126,7 +126,7 @@ void vConfigureTimerForRunTimeStats( void ); /* Prototype of function that in
{ \
vFakeAssert( false, __FILE__, __LINE__ ); \
} \
- } while ( 0 )
+ } while( 0 )
#define mtCOVERAGE_TEST_MARKER() __asm volatile ( "NOP" )
diff --git a/FreeRTOS/Test/CMock/stream_buffer/stream_buffer_utest.c b/FreeRTOS/Test/CMock/stream_buffer/stream_buffer_utest.c
index 618d33427..c5e9a8711 100644
--- a/FreeRTOS/Test/CMock/stream_buffer/stream_buffer_utest.c
+++ b/FreeRTOS/Test/CMock/stream_buffer/stream_buffer_utest.c
@@ -99,7 +99,7 @@
{ \
TEST_ASSERT_EQUAL( configASSERT_E, e ); \
} \
- } while ( 0 )
+ } while( 0 )
/* ============================ GLOBAL VARIABLES =========================== */
diff --git a/FreeRTOS/Test/README.md b/FreeRTOS/Test/README.md
index 47f440971..7a37272ca 100644
--- a/FreeRTOS/Test/README.md
+++ b/FreeRTOS/Test/README.md
@@ -1,10 +1,10 @@
## Testing in FreeRTOS
-FreeRTOS kernel consists of common code and porting layer. Extensive [static analysis](https://en.wikipedia.org/wiki/Static_program_analysis) and [dynamic analysis](https://en.wikipedia.org/wiki/Dynamic_program_analysis) are done on both to ensure functional correctness of FreeRTOS kernel.
+FreeRTOS kernel consists of common code and porting layer. Extensive [static analysis](https://en.wikipedia.org/wiki/Static_program_analysis) and [dynamic analysis](https://en.wikipedia.org/wiki/Dynamic_program_analysis) are done on both to ensure functional correctness of FreeRTOS kernel.
For more information on FreeRTOS testing please refer to https://www.freertos.org/FreeRTOS-Coding-Standard-and-Style-Guide.html.
## Directory structure
-This directory is in working progress -- we are migrating scattered test cases to this directory. Here only lists what's currently under this directory.
+This directory is in working progress -- we are migrating scattered test cases to this directory. Here only lists what's currently under this directory.
- ```./CBMC```: This directory contains automated proofs of the memory safety of various parts of the FreeRTOS code base.
- ```./VeriFast```: This directory contains automated proofs of the functional correctness of various parts of the FreeRTOS code base.
diff --git a/FreeRTOS/Test/VeriFast/include/proof/list.h b/FreeRTOS/Test/VeriFast/include/proof/list.h
index cdef4a593..098bf2337 100644
--- a/FreeRTOS/Test/VeriFast/include/proof/list.h
+++ b/FreeRTOS/Test/VeriFast/include/proof/list.h
@@ -30,14 +30,14 @@
#define VERIFAST
#include <stdlib.h>
#include <stdint.h>
-//@#include "common.gh"
+/*@#include "common.gh" */
-typedef size_t TickType_t;
-typedef size_t UBaseType_t;
-typedef ssize_t BaseType_t;
+typedef size_t TickType_t;
+typedef size_t UBaseType_t;
+typedef ssize_t BaseType_t;
-#define pdTRUE 1
-#define pdFALSE 0
+#define pdTRUE 1
+#define pdFALSE 0
/* Empty/no-op macros */
#define mtCOVERAGE_TEST_MARKER()
@@ -50,323 +50,327 @@ typedef ssize_t BaseType_t;
#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxListItem )
/* Max value stored in sentinel xListEnd element */
-#define portMAX_DELAY UINT_MAX
+#define portMAX_DELAY UINT_MAX
struct xLIST;
-struct xLIST_ITEM {
- TickType_t xItemValue;
- struct xLIST_ITEM * pxNext;
- struct xLIST_ITEM * pxPrevious;
- void * pvOwner;
- struct xLIST *pxContainer;
+struct xLIST_ITEM
+{
+ TickType_t xItemValue;
+ struct xLIST_ITEM * pxNext;
+ struct xLIST_ITEM * pxPrevious;
+ void * pvOwner;
+ struct xLIST * pxContainer;
};
typedef struct xLIST_ITEM ListItem_t;
-typedef struct xLIST {
- UBaseType_t uxNumberOfItems;
- struct xLIST_ITEM *pxIndex;
-#ifdef VERIFAST /*< ***change MiniList_t to ListItem_t*** */
- struct xLIST_ITEM xListEnd;
-#else
- MiniListItem_t xListEnd;
-#endif
+typedef struct xLIST
+{
+ UBaseType_t uxNumberOfItems;
+ struct xLIST_ITEM * pxIndex;
+ #ifdef VERIFAST /*< ***change MiniList_t to ListItem_t*** */
+ struct xLIST_ITEM xListEnd;
+ #else
+ MiniListItem_t xListEnd;
+ #endif
} List_t;
/*@
-predicate xLIST_ITEM(
- struct xLIST_ITEM *n,
- TickType_t xItemValue,
- struct xLIST_ITEM *pxNext,
- struct xLIST_ITEM *pxPrevious,
- struct xLIST *pxContainer;) =
- n->xItemValue |-> xItemValue &*&
- n->pxNext |-> pxNext &*&
- n->pxPrevious |-> pxPrevious &*&
- n->pvOwner |-> _ &*&
- n->pxContainer |-> pxContainer;
-@*/
+ * predicate xLIST_ITEM(
+ * struct xLIST_ITEM *n,
+ * TickType_t xItemValue,
+ * struct xLIST_ITEM *pxNext,
+ * struct xLIST_ITEM *pxPrevious,
+ * struct xLIST *pxContainer;) =
+ * n->xItemValue |-> xItemValue &*&
+ * n->pxNext |-> pxNext &*&
+ * n->pxPrevious |-> pxPrevious &*&
+ * n->pvOwner |-> _ &*&
+ * n->pxContainer |-> pxContainer;
+ * @*/
/* Ferreira et al. (STTT'14) doubly-linked list segment (DLS). */
-/*@
-predicate DLS(
- struct xLIST_ITEM *n,
- struct xLIST_ITEM *nprev,
- struct xLIST_ITEM *mnext,
- struct xLIST_ITEM *m,
- list<struct xLIST_ITEM * > cells,
- list<TickType_t > vals,
- struct xLIST *pxContainer) =
- n == m
- ? cells == cons(n, nil) &*&
- vals == cons(?v, nil) &*&
- xLIST_ITEM(n, v, mnext, nprev, pxContainer)
- : cells == cons(n, ?cells0) &*&
- vals == cons(?v, ?vals0) &*&
- xLIST_ITEM(n, v, ?o, nprev, pxContainer) &*& DLS(o, n, mnext, m, cells0, vals0, pxContainer);
-
-lemma void dls_star_item(
- struct xLIST_ITEM *n,
- struct xLIST_ITEM *m,
- struct xLIST_ITEM *o)
-requires DLS(n, ?nprev, ?mnext, m, ?cells, ?vals, ?l) &*& xLIST_ITEM(o, ?v, ?onext, ?oprev, ?l2);
-ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& xLIST_ITEM(o, v, onext, oprev, l2) &*& mem(o, cells) == false;
-{
- open DLS(n, nprev, mnext, m, cells, vals, l);
- if (n == m) {
- assert xLIST_ITEM(n, _, _, _, _);
- open xLIST_ITEM(n, _, _, _, _);
- open xLIST_ITEM(o, _, _, _, _);
- assert n != o;
- close xLIST_ITEM(o, _, _, _, _);
- close xLIST_ITEM(n, _, _, _, _);
- close DLS(n, nprev, mnext, m, cells, vals, l);
- }
- else {
- assert DLS(?nnext, n, mnext, m, tail(cells), tail(vals), l);
- dls_star_item(nnext, m, o);
- open xLIST_ITEM(n, _, _, _, _);
- open xLIST_ITEM(o, _, _, _, _);
- assert n != o;
- close xLIST_ITEM(o, _, _, _, _);
- close xLIST_ITEM(n, _, _, _, _);
- close DLS(n, nprev, mnext, m, cells, vals, l);
- }
-}
-
-lemma void dls_distinct(
- struct xLIST_ITEM *n,
- struct xLIST_ITEM *nprev,
- struct xLIST_ITEM *mnext,
- struct xLIST_ITEM *m,
- list<struct xLIST_ITEM * > cells)
-requires DLS(n, nprev, mnext, m, cells, ?vals, ?l);
-ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& distinct(cells) == true;
-{
- if (n == m) {
- open DLS(n, nprev, mnext, m, cells, vals, l);
- close DLS(n, nprev, mnext, m, cells, vals, l);
- } else {
- open DLS(n, nprev, mnext, m, cells, vals, l);
- assert DLS(?nnext, n, mnext, m, tail(cells), tail(vals), l);
- dls_distinct(nnext, n, mnext, m, tail(cells));
- dls_star_item(nnext, m, n);
- close DLS(n, nprev, mnext, m, cells, vals, l);
- }
-}
-
-predicate xLIST(
- struct xLIST *l,
- int uxNumberOfItems,
- struct xLIST_ITEM *pxIndex,
- struct xLIST_ITEM *xListEnd,
- list<struct xLIST_ITEM *>cells,
- list<TickType_t >vals) =
- l->uxNumberOfItems |-> uxNumberOfItems &*&
- l->pxIndex |-> pxIndex &*&
- mem(pxIndex, cells) == true &*&
- xListEnd == &(l->xListEnd) &*&
- xListEnd == head(cells) &*&
- portMAX_DELAY == head(vals) &*&
- struct_xLIST_ITEM_padding(&l->xListEnd) &*&
- length(cells) == length(vals) &*&
- uxNumberOfItems + 1 == length(cells) &*&
- DLS(xListEnd, ?endprev, xListEnd, endprev, cells, vals, l);
-
-lemma void xLIST_distinct_cells(struct xLIST *l)
-requires xLIST(l, ?n, ?idx, ?end, ?cells, ?vals);
-ensures xLIST(l, n, idx, end, cells, vals) &*& distinct(cells) == true;
-{
- open xLIST(l, n, idx, end, cells, vals);
- assert DLS(end, ?endprev, end, _, cells, vals, l);
- dls_distinct(end, endprev, end, endprev, cells);
- close xLIST(l, n, idx, end, cells, vals);
-}
-
-lemma void xLIST_star_item(struct xLIST *l, struct xLIST_ITEM *x)
-requires xLIST(l, ?n, ?idx, ?end, ?cells, ?vals) &*& xLIST_ITEM(x, ?v, ?xnext, ?xprev, ?l2);
-ensures xLIST(l, n, idx, end, cells, vals) &*& xLIST_ITEM(x, v, xnext, xprev, l2) &*& mem(x, cells) == false;
-{
- open xLIST(l, n, idx, end, cells, vals);
- assert DLS(end, ?endprev, end, _, cells, vals, l);
- dls_distinct(end, endprev, end, endprev, cells);
- dls_star_item(end, endprev, x);
- close xLIST(l, n, idx, end, cells, vals);
-}
-
-lemma void dls_first_mem(
- struct xLIST_ITEM *n,
- struct xLIST_ITEM *nprev,
- struct xLIST_ITEM *mnext,
- struct xLIST_ITEM *m,
- list<struct xLIST_ITEM * > cells)
-requires DLS(n, nprev, mnext, m, cells, ?vals, ?l);
-ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& mem(n, cells) == true &*& index_of(n, cells) == 0;
-{
- open DLS(n, nprev, mnext, m, cells, vals, l);
- if (n == m) {
- assert cells == cons(n, nil);
- close DLS(n, nprev, mnext, m, cells, vals, l);
- } else {
- assert cells == cons(n, ?tail);
- close DLS(n, nprev, mnext, m, cells, vals, l);
- }
-}
-
-lemma void dls_not_empty(
- struct xLIST_ITEM *n,
- struct xLIST_ITEM *m,
- list<struct xLIST_ITEM * > cells,
- struct xLIST_ITEM *x)
-requires DLS(n, m, n, m, cells, ?vals, ?l) &*& mem(x, cells) == true &*& x != n;
-ensures DLS(n, m, n, m, cells, vals, l) &*& n != m;
-{
- open DLS(n, m, n, m, cells, vals, l);
- close DLS(n, m, n, m, cells, vals, l);
-}
-
-lemma void dls_last_mem(
- struct xLIST_ITEM *n,
- struct xLIST_ITEM *nprev,
- struct xLIST_ITEM *mnext,
- struct xLIST_ITEM *m,
- list<struct xLIST_ITEM * > cells)
-requires DLS(n, nprev, mnext, m, cells, ?vals, ?l);
-ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& mem(m, cells) == true &*& index_of(m, cells) == length(cells) - 1;
-{
- open DLS(n, nprev, mnext, m, cells, vals, l);
- if (n == m) {
- // trivial
- } else {
- open xLIST_ITEM(n, _, ?nnext, _, l);
- assert DLS(?o, n, mnext, m, tail(cells), tail(vals), l);
- dls_last_mem(o, n, mnext, m, tail(cells));
- close xLIST_ITEM(n, _, nnext, _, l);
- }
- close DLS(n, nprev, mnext, m, cells, vals, l);
-}
-
-lemma void split(
- struct xLIST_ITEM *n,
- struct xLIST_ITEM *nprev,
- struct xLIST_ITEM *mnext,
- struct xLIST_ITEM *m,
- list<struct xLIST_ITEM * > cells,
- list<TickType_t > vals,
- struct xLIST_ITEM *x,
- int i)
-requires DLS(n, nprev, mnext, m, cells, vals, ?l) &*& x != n &*& mem(x, cells) == true &*& index_of(x,cells) == i;
-ensures DLS(n, nprev, x, ?xprev, take(i, cells), take(i, vals), l) &*& DLS(x, xprev, mnext, m, drop(i, cells), drop(i, vals), l) &*& xprev == nth(i-1, cells);
-{
- open DLS(n, nprev, mnext, m, cells, vals, l);
- assert n != m;
- assert xLIST_ITEM(n, ?v, ?nnext, _, _);
- assert DLS(nnext, n, mnext, m, tail(cells), tail(vals), l);
- if (nnext == x) {
- close DLS(n, nprev, x, n, singleton(n), singleton(v), l);
- open DLS(x, n, mnext, m, tail(cells), tail(vals), l);
- open xLIST_ITEM(x, _, ?xnext, ?xprev, l);
- close xLIST_ITEM(x, _, xnext, xprev, l);
- close DLS(x, n, mnext, m, tail(cells), tail(vals), l);
- } else {
- assert nnext != x;
- split(nnext, n, mnext, m, tail(cells), tail(vals), x, i - 1);
- assert DLS(nnext, n, x, ?xprev, take(i-1, tail(cells)), take(i-1, tail(vals)), l);
- dls_distinct(nnext, n, x, xprev, take(i-1, tail(cells)));
- dls_star_item(nnext, xprev, n);
- dls_last_mem(nnext, n, x, xprev, take(i-1, tail(cells)));
- assert n != xprev;
- close DLS(n, nprev, x, xprev, take(i, cells), take(i, vals), l);
- }
-}
-
-lemma void join(
- struct xLIST_ITEM *n1,
- struct xLIST_ITEM *nprev1,
- struct xLIST_ITEM *mnext1,
- struct xLIST_ITEM *m1,
- list<struct xLIST_ITEM * > cells1,
- list<TickType_t > vals1,
- struct xLIST_ITEM *n2,
- struct xLIST_ITEM *nprev2,
- struct xLIST_ITEM *mnext2,
- struct xLIST_ITEM *m2,
- list<struct xLIST_ITEM * > cells2,
- list<TickType_t > vals2)
-requires
- DLS(n1, nprev1, mnext1, m1, cells1, vals1, ?l) &*&
- DLS(n2, nprev2, mnext2, m2, cells2, vals2, l) &*&
- mnext1 == n2 &*& m1 == nprev2;
-ensures DLS(n1, nprev1, mnext2, m2, append(cells1, cells2), append(vals1, vals2), l);
-{
- if (n1 == m1) {
- dls_first_mem(n1, nprev1, mnext1, m1, cells1);
- dls_last_mem(n2, nprev2, mnext2, m2, cells2);
- open DLS(n1, nprev1, mnext1, m1, cells1, vals1, l);
- dls_star_item(n2, m2, n1);
- close DLS(n1, nprev1, mnext2, m2, append(singleton(n1), cells2), append(vals1, vals2), l);
- } else {
- open DLS(n1, nprev1, mnext1, m1, cells1, vals1, l);
- assert DLS(?o, n1, mnext1, m1, ?cells1_tail, ?vals1_tail, l);
- join(o, n1, mnext1, m1, cells1_tail, vals1_tail,
- n2, nprev2, mnext2, m2, cells2, vals2);
- assert DLS(o, n1, mnext2, m2, append(cells1_tail, cells2), append(vals1_tail, vals2), l);
- dls_last_mem(o, n1, mnext2, m2, append(cells1_tail, cells2));
- dls_star_item(o, m2, n1);
- close DLS(n1, nprev1, mnext2, m2, append(cells1, cells2), append(vals1, vals2), l);
- }
-}
-lemma void idx_remains_in_list<t>(
- list<t> cells,
- t idx,
- t x,
- int ix)
-requires
- idx != x &*&
- mem(idx, cells) == true &*&
- mem(x, cells) == true &*&
- index_of(x, cells) == ix;
-ensures mem(idx, remove_nth(ix, cells)) == true;
-{
- neq_mem_remove(idx, x, cells);
- remove_remove_nth(cells, x);
-}
-@*/
+/*@
+ * predicate DLS(
+ * struct xLIST_ITEM *n,
+ * struct xLIST_ITEM *nprev,
+ * struct xLIST_ITEM *mnext,
+ * struct xLIST_ITEM *m,
+ * list<struct xLIST_ITEM * > cells,
+ * list<TickType_t > vals,
+ * struct xLIST *pxContainer) =
+ * n == m
+ * ? cells == cons(n, nil) &*&
+ * vals == cons(?v, nil) &*&
+ * xLIST_ITEM(n, v, mnext, nprev, pxContainer)
+ * : cells == cons(n, ?cells0) &*&
+ * vals == cons(?v, ?vals0) &*&
+ * xLIST_ITEM(n, v, ?o, nprev, pxContainer) &*& DLS(o, n, mnext, m, cells0, vals0, pxContainer);
+ *
+ * lemma void dls_star_item(
+ * struct xLIST_ITEM *n,
+ * struct xLIST_ITEM *m,
+ * struct xLIST_ITEM *o)
+ * requires DLS(n, ?nprev, ?mnext, m, ?cells, ?vals, ?l) &*& xLIST_ITEM(o, ?v, ?onext, ?oprev, ?l2);
+ * ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& xLIST_ITEM(o, v, onext, oprev, l2) &*& mem(o, cells) == false;
+ * {
+ * open DLS(n, nprev, mnext, m, cells, vals, l);
+ * if (n == m) {
+ * assert xLIST_ITEM(n, _, _, _, _);
+ * open xLIST_ITEM(n, _, _, _, _);
+ * open xLIST_ITEM(o, _, _, _, _);
+ * assert n != o;
+ * close xLIST_ITEM(o, _, _, _, _);
+ * close xLIST_ITEM(n, _, _, _, _);
+ * close DLS(n, nprev, mnext, m, cells, vals, l);
+ * }
+ * else {
+ * assert DLS(?nnext, n, mnext, m, tail(cells), tail(vals), l);
+ * dls_star_item(nnext, m, o);
+ * open xLIST_ITEM(n, _, _, _, _);
+ * open xLIST_ITEM(o, _, _, _, _);
+ * assert n != o;
+ * close xLIST_ITEM(o, _, _, _, _);
+ * close xLIST_ITEM(n, _, _, _, _);
+ * close DLS(n, nprev, mnext, m, cells, vals, l);
+ * }
+ * }
+ *
+ * lemma void dls_distinct(
+ * struct xLIST_ITEM *n,
+ * struct xLIST_ITEM *nprev,
+ * struct xLIST_ITEM *mnext,
+ * struct xLIST_ITEM *m,
+ * list<struct xLIST_ITEM * > cells)
+ * requires DLS(n, nprev, mnext, m, cells, ?vals, ?l);
+ * ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& distinct(cells) == true;
+ * {
+ * if (n == m) {
+ * open DLS(n, nprev, mnext, m, cells, vals, l);
+ * close DLS(n, nprev, mnext, m, cells, vals, l);
+ * } else {
+ * open DLS(n, nprev, mnext, m, cells, vals, l);
+ * assert DLS(?nnext, n, mnext, m, tail(cells), tail(vals), l);
+ * dls_distinct(nnext, n, mnext, m, tail(cells));
+ * dls_star_item(nnext, m, n);
+ * close DLS(n, nprev, mnext, m, cells, vals, l);
+ * }
+ * }
+ *
+ * predicate xLIST(
+ * struct xLIST *l,
+ * int uxNumberOfItems,
+ * struct xLIST_ITEM *pxIndex,
+ * struct xLIST_ITEM *xListEnd,
+ * list<struct xLIST_ITEM *>cells,
+ * list<TickType_t >vals) =
+ * l->uxNumberOfItems |-> uxNumberOfItems &*&
+ * l->pxIndex |-> pxIndex &*&
+ * mem(pxIndex, cells) == true &*&
+ * xListEnd == &(l->xListEnd) &*&
+ * xListEnd == head(cells) &*&
+ * portMAX_DELAY == head(vals) &*&
+ * struct_xLIST_ITEM_padding(&l->xListEnd) &*&
+ * length(cells) == length(vals) &*&
+ * uxNumberOfItems + 1 == length(cells) &*&
+ * DLS(xListEnd, ?endprev, xListEnd, endprev, cells, vals, l);
+ *
+ * lemma void xLIST_distinct_cells(struct xLIST *l)
+ * requires xLIST(l, ?n, ?idx, ?end, ?cells, ?vals);
+ * ensures xLIST(l, n, idx, end, cells, vals) &*& distinct(cells) == true;
+ * {
+ * open xLIST(l, n, idx, end, cells, vals);
+ * assert DLS(end, ?endprev, end, _, cells, vals, l);
+ * dls_distinct(end, endprev, end, endprev, cells);
+ * close xLIST(l, n, idx, end, cells, vals);
+ * }
+ *
+ * lemma void xLIST_star_item(struct xLIST *l, struct xLIST_ITEM *x)
+ * requires xLIST(l, ?n, ?idx, ?end, ?cells, ?vals) &*& xLIST_ITEM(x, ?v, ?xnext, ?xprev, ?l2);
+ * ensures xLIST(l, n, idx, end, cells, vals) &*& xLIST_ITEM(x, v, xnext, xprev, l2) &*& mem(x, cells) == false;
+ * {
+ * open xLIST(l, n, idx, end, cells, vals);
+ * assert DLS(end, ?endprev, end, _, cells, vals, l);
+ * dls_distinct(end, endprev, end, endprev, cells);
+ * dls_star_item(end, endprev, x);
+ * close xLIST(l, n, idx, end, cells, vals);
+ * }
+ *
+ * lemma void dls_first_mem(
+ * struct xLIST_ITEM *n,
+ * struct xLIST_ITEM *nprev,
+ * struct xLIST_ITEM *mnext,
+ * struct xLIST_ITEM *m,
+ * list<struct xLIST_ITEM * > cells)
+ * requires DLS(n, nprev, mnext, m, cells, ?vals, ?l);
+ * ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& mem(n, cells) == true &*& index_of(n, cells) == 0;
+ * {
+ * open DLS(n, nprev, mnext, m, cells, vals, l);
+ * if (n == m) {
+ * assert cells == cons(n, nil);
+ * close DLS(n, nprev, mnext, m, cells, vals, l);
+ * } else {
+ * assert cells == cons(n, ?tail);
+ * close DLS(n, nprev, mnext, m, cells, vals, l);
+ * }
+ * }
+ *
+ * lemma void dls_not_empty(
+ * struct xLIST_ITEM *n,
+ * struct xLIST_ITEM *m,
+ * list<struct xLIST_ITEM * > cells,
+ * struct xLIST_ITEM *x)
+ * requires DLS(n, m, n, m, cells, ?vals, ?l) &*& mem(x, cells) == true &*& x != n;
+ * ensures DLS(n, m, n, m, cells, vals, l) &*& n != m;
+ * {
+ * open DLS(n, m, n, m, cells, vals, l);
+ * close DLS(n, m, n, m, cells, vals, l);
+ * }
+ *
+ * lemma void dls_last_mem(
+ * struct xLIST_ITEM *n,
+ * struct xLIST_ITEM *nprev,
+ * struct xLIST_ITEM *mnext,
+ * struct xLIST_ITEM *m,
+ * list<struct xLIST_ITEM * > cells)
+ * requires DLS(n, nprev, mnext, m, cells, ?vals, ?l);
+ * ensures DLS(n, nprev, mnext, m, cells, vals, l) &*& mem(m, cells) == true &*& index_of(m, cells) == length(cells) - 1;
+ * {
+ * open DLS(n, nprev, mnext, m, cells, vals, l);
+ * if (n == m) {
+ * // trivial
+ * } else {
+ * open xLIST_ITEM(n, _, ?nnext, _, l);
+ * assert DLS(?o, n, mnext, m, tail(cells), tail(vals), l);
+ * dls_last_mem(o, n, mnext, m, tail(cells));
+ * close xLIST_ITEM(n, _, nnext, _, l);
+ * }
+ * close DLS(n, nprev, mnext, m, cells, vals, l);
+ * }
+ *
+ * lemma void split(
+ * struct xLIST_ITEM *n,
+ * struct xLIST_ITEM *nprev,
+ * struct xLIST_ITEM *mnext,
+ * struct xLIST_ITEM *m,
+ * list<struct xLIST_ITEM * > cells,
+ * list<TickType_t > vals,
+ * struct xLIST_ITEM *x,
+ * int i)
+ * requires DLS(n, nprev, mnext, m, cells, vals, ?l) &*& x != n &*& mem(x, cells) == true &*& index_of(x,cells) == i;
+ * ensures DLS(n, nprev, x, ?xprev, take(i, cells), take(i, vals), l) &*& DLS(x, xprev, mnext, m, drop(i, cells), drop(i, vals), l) &*& xprev == nth(i-1, cells);
+ * {
+ * open DLS(n, nprev, mnext, m, cells, vals, l);
+ * assert n != m;
+ * assert xLIST_ITEM(n, ?v, ?nnext, _, _);
+ * assert DLS(nnext, n, mnext, m, tail(cells), tail(vals), l);
+ * if (nnext == x) {
+ * close DLS(n, nprev, x, n, singleton(n), singleton(v), l);
+ * open DLS(x, n, mnext, m, tail(cells), tail(vals), l);
+ * open xLIST_ITEM(x, _, ?xnext, ?xprev, l);
+ * close xLIST_ITEM(x, _, xnext, xprev, l);
+ * close DLS(x, n, mnext, m, tail(cells), tail(vals), l);
+ * } else {
+ * assert nnext != x;
+ * split(nnext, n, mnext, m, tail(cells), tail(vals), x, i - 1);
+ * assert DLS(nnext, n, x, ?xprev, take(i-1, tail(cells)), take(i-1, tail(vals)), l);
+ * dls_distinct(nnext, n, x, xprev, take(i-1, tail(cells)));
+ * dls_star_item(nnext, xprev, n);
+ * dls_last_mem(nnext, n, x, xprev, take(i-1, tail(cells)));
+ * assert n != xprev;
+ * close DLS(n, nprev, x, xprev, take(i, cells), take(i, vals), l);
+ * }
+ * }
+ *
+ * lemma void join(
+ * struct xLIST_ITEM *n1,
+ * struct xLIST_ITEM *nprev1,
+ * struct xLIST_ITEM *mnext1,
+ * struct xLIST_ITEM *m1,
+ * list<struct xLIST_ITEM * > cells1,
+ * list<TickType_t > vals1,
+ * struct xLIST_ITEM *n2,
+ * struct xLIST_ITEM *nprev2,
+ * struct xLIST_ITEM *mnext2,
+ * struct xLIST_ITEM *m2,
+ * list<struct xLIST_ITEM * > cells2,
+ * list<TickType_t > vals2)
+ * requires
+ * DLS(n1, nprev1, mnext1, m1, cells1, vals1, ?l) &*&
+ * DLS(n2, nprev2, mnext2, m2, cells2, vals2, l) &*&
+ * mnext1 == n2 &*& m1 == nprev2;
+ * ensures DLS(n1, nprev1, mnext2, m2, append(cells1, cells2), append(vals1, vals2), l);
+ * {
+ * if (n1 == m1) {
+ * dls_first_mem(n1, nprev1, mnext1, m1, cells1);
+ * dls_last_mem(n2, nprev2, mnext2, m2, cells2);
+ * open DLS(n1, nprev1, mnext1, m1, cells1, vals1, l);
+ * dls_star_item(n2, m2, n1);
+ * close DLS(n1, nprev1, mnext2, m2, append(singleton(n1), cells2), append(vals1, vals2), l);
+ * } else {
+ * open DLS(n1, nprev1, mnext1, m1, cells1, vals1, l);
+ * assert DLS(?o, n1, mnext1, m1, ?cells1_tail, ?vals1_tail, l);
+ * join(o, n1, mnext1, m1, cells1_tail, vals1_tail,
+ * n2, nprev2, mnext2, m2, cells2, vals2);
+ * assert DLS(o, n1, mnext2, m2, append(cells1_tail, cells2), append(vals1_tail, vals2), l);
+ * dls_last_mem(o, n1, mnext2, m2, append(cells1_tail, cells2));
+ * dls_star_item(o, m2, n1);
+ * close DLS(n1, nprev1, mnext2, m2, append(cells1, cells2), append(vals1, vals2), l);
+ * }
+ * }
+ *
+ * lemma void idx_remains_in_list<t>(
+ * list<t> cells,
+ * t idx,
+ * t x,
+ * int ix)
+ * requires
+ * idx != x &*&
+ * mem(idx, cells) == true &*&
+ * mem(x, cells) == true &*&
+ * index_of(x, cells) == ix;
+ * ensures mem(idx, remove_nth(ix, cells)) == true;
+ * {
+ * neq_mem_remove(idx, x, cells);
+ * remove_remove_nth(cells, x);
+ * }
+ * @*/
/* Following lemma from `verifast/examples/shared_boxes/concurrentqueue.c`.
-Used in the uxListRemove proof to show that the item to remove `x` must
-have value `nth(i, vals)` where `i == index_of(x, cells)`. */
+ * Used in the uxListRemove proof to show that the item to remove `x` must
+ * have value `nth(i, vals)` where `i == index_of(x, cells)`. */
+
/*@
-lemma void drop_nth_index_of<t>(list<t> vs, int i)
-requires
- 0 <= i && i < length(vs);
-ensures
- head(drop(i , vs)) == nth(i, vs);
-{
- switch(vs) {
- case nil:
- case cons(h, t):
- if (i == 0) {
- // trivial
- } else {
- drop_nth_index_of(t, i - 1);
- }
- }
-}
-@*/
+ * lemma void drop_nth_index_of<t>(list<t> vs, int i)
+ * requires
+ * 0 <= i && i < length(vs);
+ * ensures
+ * head(drop(i , vs)) == nth(i, vs);
+ * {
+ * switch(vs) {
+ * case nil:
+ * case cons(h, t):
+ * if (i == 0) {
+ * // trivial
+ * } else {
+ * drop_nth_index_of(t, i - 1);
+ * }
+ * }
+ * }
+ * @*/
/*@
-lemma void remove_append<t>(t x, list<t> l1, list<t> l2)
- requires mem(x, l1) == false;
- ensures remove(x, append(l1, l2)) == append(l1, remove(x, l2));
-{
- switch(l1) {
- case nil:
- case cons(h1, t1):
- remove_append(x, t1, l2);
- }
-}
-@*/
+ * lemma void remove_append<t>(t x, list<t> l1, list<t> l2)
+ * requires mem(x, l1) == false;
+ * ensures remove(x, append(l1, l2)) == append(l1, remove(x, l2));
+ * {
+ * switch(l1) {
+ * case nil:
+ * case cons(h1, t1):
+ * remove_append(x, t1, l2);
+ * }
+ * }
+ * @*/
#endif /* LIST_H */
diff --git a/FreeRTOS/Test/VeriFast/include/proof/queue.h b/FreeRTOS/Test/VeriFast/include/proof/queue.h
index 6dd35186e..a630e683c 100644
--- a/FreeRTOS/Test/VeriFast/include/proof/queue.h
+++ b/FreeRTOS/Test/VeriFast/include/proof/queue.h
@@ -34,51 +34,51 @@
#include <threading.h>
/*@#include "common.gh"@*/
-typedef size_t TickType_t;
-typedef size_t UBaseType_t;
-typedef ssize_t BaseType_t;
+typedef size_t TickType_t;
+typedef size_t UBaseType_t;
+typedef ssize_t BaseType_t;
/* Empty/no-op macros */
/* Tracing */
-#define traceBLOCKING_ON_QUEUE_PEEK(x)
-#define traceBLOCKING_ON_QUEUE_RECEIVE(x)
-#define traceBLOCKING_ON_QUEUE_SEND(x)
-#define traceQUEUE_CREATE(x)
-#define traceQUEUE_CREATE_FAILED(x)
-#define traceQUEUE_DELETE(x)
-#define traceQUEUE_PEEK(x)
-#define traceQUEUE_PEEK_FAILED(x)
-#define traceQUEUE_PEEK_FROM_ISR(x)
-#define traceQUEUE_PEEK_FROM_ISR_FAILED(x)
-#define traceQUEUE_RECEIVE(x)
-#define traceQUEUE_RECEIVE_FAILED(x)
-#define traceQUEUE_RECEIVE_FROM_ISR(x)
-#define traceQUEUE_RECEIVE_FROM_ISR_FAILED(x)
-#define traceQUEUE_SEND(x)
-#define traceQUEUE_SEND_FAILED(x)
-#define traceQUEUE_SEND_FROM_ISR(x)
-#define traceQUEUE_SEND_FROM_ISR_FAILED(x)
+#define traceBLOCKING_ON_QUEUE_PEEK( x )
+#define traceBLOCKING_ON_QUEUE_RECEIVE( x )
+#define traceBLOCKING_ON_QUEUE_SEND( x )
+#define traceQUEUE_CREATE( x )
+#define traceQUEUE_CREATE_FAILED( x )
+#define traceQUEUE_DELETE( x )
+#define traceQUEUE_PEEK( x )
+#define traceQUEUE_PEEK_FAILED( x )
+#define traceQUEUE_PEEK_FROM_ISR( x )
+#define traceQUEUE_PEEK_FROM_ISR_FAILED( x )
+#define traceQUEUE_RECEIVE( x )
+#define traceQUEUE_RECEIVE_FAILED( x )
+#define traceQUEUE_RECEIVE_FROM_ISR( x )
+#define traceQUEUE_RECEIVE_FROM_ISR_FAILED( x )
+#define traceQUEUE_SEND( x )
+#define traceQUEUE_SEND_FAILED( x )
+#define traceQUEUE_SEND_FROM_ISR( x )
+#define traceQUEUE_SEND_FROM_ISR_FAILED( x )
/* Coverage */
#define mtCOVERAGE_TEST_MARKER()
/* Asserts */
-#define configASSERT(x)
+#define configASSERT( x )
#define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()
/* Map portable memory management functions */
-#define pvPortMalloc malloc
-#define vPortFree free
+#define pvPortMalloc malloc
+#define vPortFree free
-#define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
-#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
-#define queueOVERWRITE ( ( BaseType_t ) 2 )
+#define queueSEND_TO_BACK ( ( BaseType_t ) 0 )
+#define queueSEND_TO_FRONT ( ( BaseType_t ) 1 )
+#define queueOVERWRITE ( ( BaseType_t ) 2 )
-#define pdTRUE 1
-#define pdFALSE 0
+#define pdTRUE 1
+#define pdFALSE 0
-#define pdPASS pdTRUE
-#define pdFAIL pdFALSE
-#define errQUEUE_FULL 0
-#define errQUEUE_EMPTY 0
+#define pdPASS pdTRUE
+#define pdFAIL pdFALSE
+#define errQUEUE_FULL 0
+#define errQUEUE_EMPTY 0
/* Constants used with the cRxLock and cTxLock structure members. */
#define queueUNLOCKED ( ( int8_t ) -1 )
@@ -93,26 +93,28 @@ typedef struct QueuePointers
typedef struct SemaphoreData
{
-#ifdef VERIFAST /*< do not model xMutexHolder */
- void *xMutexHolder;
-#else
- TaskHandle_t xMutexHolder; /*< The handle of the task that holds the mutex. */
-#endif
+ #ifdef VERIFAST /*< do not model xMutexHolder */
+ void * xMutexHolder;
+ #else
+ TaskHandle_t xMutexHolder; /*< The handle of the task that holds the mutex. */
+ #endif
UBaseType_t uxRecursiveCallCount; /*< Maintains a count of the number of times a recursive mutex has been recursively 'taken' when the structure is used as a mutex. */
} SemaphoreData_t;
/* VeriFast does not support unions so we replace with a struct */
-struct fake_union_t {
+struct fake_union_t
+{
QueuePointers_t xQueue;
SemaphoreData_t xSemaphore;
};
-typedef struct xLIST {
+typedef struct xLIST
+{
UBaseType_t uxNumberOfItems;
-#ifndef VERIFAST /*< do not model pxIndex and xListEnd of xLIST struct */
- struct xLIST_ITEM *pxIndex;
- MiniListItem_t xListEnd;
-#endif
+ #ifndef VERIFAST /*< do not model pxIndex and xListEnd of xLIST struct */
+ struct xLIST_ITEM * pxIndex;
+ MiniListItem_t xListEnd;
+ #endif
} List_t;
typedef struct QueueDefinition /* The old naming convention is used to prevent breaking kernel aware debuggers. */
@@ -120,15 +122,15 @@ typedef struct QueueDefinition /* The old naming convention is used to prevent b
int8_t * pcHead; /*< Points to the beginning of the queue storage area. */
int8_t * pcWriteTo; /*< Points to the free next place in the storage area. */
-#ifdef VERIFAST /*< VeriFast does not model unions */
- struct fake_union_t u;
-#else
- union
- {
- QueuePointers_t xQueue; /*< Data required exclusively when this structure is used as a queue. */
- SemaphoreData_t xSemaphore; /*< Data required exclusively when this structure is used as a semaphore. */
- } u;
-#endif
+ #ifdef VERIFAST /*< VeriFast does not model unions */
+ struct fake_union_t u;
+ #else
+ union
+ {
+ QueuePointers_t xQueue; /*< Data required exclusively when this structure is used as a queue. */
+ SemaphoreData_t xSemaphore; /*< Data required exclusively when this structure is used as a semaphore. */
+ } u;
+ #endif
List_t xTasksWaitingToSend; /*< List of tasks that are blocked waiting to post onto this queue. Stored in priority order. */
List_t xTasksWaitingToReceive; /*< List of tasks that are blocked waiting to read from this queue. Stored in priority order. */
@@ -158,271 +160,278 @@ typedef struct QueueDefinition /* The old naming convention is used to prevent b
/*@struct mutex *locked;@*/ /*< Ghost mutex simulates the effect of queue locking */
} xQUEUE;
-typedef xQUEUE Queue_t;
+typedef xQUEUE Queue_t;
-typedef struct QueueDefinition * QueueHandle_t;
+typedef struct QueueDefinition * QueueHandle_t;
/*@
-#define QUEUE_SHAPE(q, Storage, N, M, K) \
- malloc_block_QueueDefinition(q) &*& \
- q->pcHead |-> Storage &*& \
- q->pcWriteTo |-> ?WPtr &*& \
- q->u.xQueue.pcTail |-> ?End &*& \
- q->u.xQueue.pcReadFrom |-> ?RPtr &*& \
- q->uxItemSize |-> M &*& \
- q->uxLength |-> N &*& \
- q->uxMessagesWaiting |-> K &*& \
- q->cRxLock |-> ?rxLock &*& \
- q->cTxLock |-> ?txLock &*& \
- struct_QueuePointers_padding(&q->u.xQueue) &*& \
- struct_SemaphoreData_padding(&q->u.xSemaphore) &*& \
- struct_fake_union_t_padding(&q->u) &*& \
- struct_xLIST_padding(&q->xTasksWaitingToSend) &*& \
- struct_xLIST_padding(&q->xTasksWaitingToReceive) &*& \
- q->u.xSemaphore.xMutexHolder |-> _ &*& \
- q->u.xSemaphore.uxRecursiveCallCount |-> _ &*& \
- true
-
-predicate queue(QueueHandle_t q, int8_t *Storage, size_t N, size_t M, size_t W, size_t R, size_t K, bool is_locked; list<list<char> >abs) =
- QUEUE_SHAPE(q, Storage, N, M, K) &*&
- 0 < N &*&
- 0 < M &*&
- 0 <= W &*& W < N &*&
- 0 <= R &*& R < N &*&
- 0 <= K &*& K <= N &*&
- W == (R + 1 + K) % N &*&
- (-1) <= rxLock &*&
- (-1) <= txLock &*&
- (is_locked ? 0 <= rxLock : (-1) == rxLock) &*&
- (is_locked ? 0 <= txLock : (-1) == txLock) &*&
- WPtr == Storage + (W*M) &*&
- RPtr == Storage + (R*M) &*&
- End == Storage + (N*M) &*&
- buffer(Storage, N, M, ?contents) &*&
- length(contents) == N &*&
- abs == take(K, rotate_left((R+1)%N, contents)) &*&
- malloc_block(Storage, N*M) &*&
- true
- ;
-@*/
+ #define QUEUE_SHAPE(q, Storage, N, M, K) \
+ * malloc_block_QueueDefinition(q) &*& \
+ * q->pcHead |-> Storage &*& \
+ * q->pcWriteTo |-> ?WPtr &*& \
+ * q->u.xQueue.pcTail |-> ?End &*& \
+ * q->u.xQueue.pcReadFrom |-> ?RPtr &*& \
+ * q->uxItemSize |-> M &*& \
+ * q->uxLength |-> N &*& \
+ * q->uxMessagesWaiting |-> K &*& \
+ * q->cRxLock |-> ?rxLock &*& \
+ * q->cTxLock |-> ?txLock &*& \
+ * struct_QueuePointers_padding(&q->u.xQueue) &*& \
+ * struct_SemaphoreData_padding(&q->u.xSemaphore) &*& \
+ * struct_fake_union_t_padding(&q->u) &*& \
+ * struct_xLIST_padding(&q->xTasksWaitingToSend) &*& \
+ * struct_xLIST_padding(&q->xTasksWaitingToReceive) &*& \
+ * q->u.xSemaphore.xMutexHolder |-> _ &*& \
+ * q->u.xSemaphore.uxRecursiveCallCount |-> _ &*& \
+ * true
+ *
+ * predicate queue(QueueHandle_t q, int8_t *Storage, size_t N, size_t M, size_t W, size_t R, size_t K, bool is_locked; list<list<char> >abs) =
+ * QUEUE_SHAPE(q, Storage, N, M, K) &*&
+ * 0 < N &*&
+ * 0 < M &*&
+ * 0 <= W &*& W < N &*&
+ * 0 <= R &*& R < N &*&
+ * 0 <= K &*& K <= N &*&
+ * W == (R + 1 + K) % N &*&
+ * (-1) <= rxLock &*&
+ * (-1) <= txLock &*&
+ * (is_locked ? 0 <= rxLock : (-1) == rxLock) &*&
+ * (is_locked ? 0 <= txLock : (-1) == txLock) &*&
+ * WPtr == Storage + (W*M) &*&
+ * RPtr == Storage + (R*M) &*&
+ * End == Storage + (N*M) &*&
+ * buffer(Storage, N, M, ?contents) &*&
+ * length(contents) == N &*&
+ * abs == take(K, rotate_left((R+1)%N, contents)) &*&
+ * malloc_block(Storage, N*M) &*&
+ * true
+ * ;
+ * @*/
/* A buffer allows us to interpret a flat character array of `N*M` bytes as a
-list of `N` elements where each element is `M` bytes */
-/*@
-predicate buffer(char *buffer, size_t N, size_t M; list<list<char> > elements) =
- N == 0
- ? elements == nil
- : chars(buffer, M, ?x) &*& buffer(buffer + M, N - 1, M, ?xs) &*& elements == cons(x, xs);
-
-lemma void buffer_length(char *buffer, size_t N, size_t M)
-requires buffer(buffer, N, M, ?elements);
-ensures buffer(buffer, N, M, elements) &*& length(elements) == N;
-{
- if (N == 0) {
- open buffer(buffer, N, M, elements);
- close buffer(buffer, N, M, elements);
- } else {
- open buffer(buffer, N, M, elements);
- buffer_length(buffer+M, N-1, M);
- }
-}
-@*/
+ * list of `N` elements where each element is `M` bytes */
-/*
-There is no need in the queue proofs to preserve a relationship between `cs`
-and `elements` (i.e., `flatten(elements) == cs`) because we only move in one
-direction from `cs` to `elements` during queue creation when the contents is
-fresh from `malloc` (i.e., uninitialized). If we needed to do a roundtrip from
-elements back to cs then this would require a stronger lemma.
-*/
/*@
-lemma void buffer_from_chars(char *buffer, size_t N, size_t M)
-requires chars(buffer, N*M, ?cs) &*& 0 <= N &*& 0 < M;
-ensures exists<list<list<char> > >(?elements) &*& buffer(buffer, N, M, elements) &*& length(elements) == N;
-{
- if (N == 0) {
- close exists(nil);
- } else {
- int i = 0;
- while (i < N)
- invariant 0 <= i &*& i <= N &*&
- chars(buffer, (N-i)*M, ?xs) &*& xs == take((N-i)*M, cs) &*&
- buffer(buffer + (N-i)*M, i, M, ?ys);
- decreases N-i;
- {
- mul_mono_l(0, N-i-1, M);
- chars_split(buffer, (N-i-1)*M);
- mul_mono_l(i, N, M);
- mul_mono_l(N-i, N, M);
- take_take((N-i-1)*M, (N-i)*M, cs);
- i++;
- }
- close exists(ys);
- buffer_length(buffer, N, M);
- }
-}
-
-lemma void append_buffer(char *buffer, size_t N1, size_t N2, size_t M)
-requires
- buffer(buffer, N1, M, ?elements1) &*&
- buffer(buffer + N1 * M, N2, M, ?elements2) &*&
- 0 <= N1 &*& 0 <= N2;
-ensures buffer(buffer, N1+N2, M, append(elements1, elements2));
-{
- if (N1 == 0) {
- open buffer(buffer, 0, M, _);
- } else if (N2 == 0) {
- open buffer(buffer + N1 * M, 0, M, _);
- } else {
- open buffer(buffer, N1, M, elements1);
- append_buffer(buffer + M, N1-1, N2, M);
- close buffer(buffer, N1+N2, M, cons(?x, append(xs, elements2)));
- }
-}
-
-lemma void split_element<t>(char *buffer, size_t N, size_t M, size_t i)
-requires buffer(buffer, N, M, ?elements) &*& 0 <= i &*& i < N;
-ensures
- buffer(buffer, i, M, take(i, elements)) &*&
- chars(buffer + i * M, M, nth(i, elements)) &*&
- buffer(buffer + (i + 1) * M, (N-1-i), M, drop(i+1, elements));
-{
- if (i == 0) {
- // straightforward
- } else {
- buffer_length(buffer, N, M);
- int j = 0;
- while (j < i)
- invariant 0 <= j &*& j <= i &*&
- buffer(buffer, j, M, take(j, elements)) &*&
- buffer(buffer + j * M, N-j, M, drop(j, elements));
- decreases i-j;
- {
- drop_drop(1, j, elements);
- nth_drop2(elements, j);
- open buffer(buffer + j * M, N-j, M, drop(j, elements));
- assert chars(buffer + j * M, M, ?x) &*& x == nth(j, elements);
- close buffer(buffer + j * M, 1, M, singleton(x));
- append_buffer(buffer, j, 1, M);
- take_plus_one(j, elements);
- j++;
- }
- drop_drop(1, j, elements);
- nth_drop2(elements, i);
- }
-}
-
-lemma void join_element(char *buffer, size_t N, size_t M, size_t i)
-requires
- 0 <= i &*& i < N &*&
- buffer(buffer, i, M, ?prefix) &*&
- chars(buffer + i * M, M, ?element) &*&
- buffer(buffer + (i + 1) * M, (N-1-i), M, ?suffix);
-ensures buffer(buffer, N, M, append(prefix, cons(element, suffix)));
-{
- if (i == 0) {
- open buffer(buffer, i, M, prefix);
- assert prefix == nil;
- close buffer(buffer, N, M, cons(element, suffix));
- } else {
- close buffer(buffer + i * M, N-i, M, cons(element, suffix));
- append_buffer(buffer, i, N-i, M);
- }
-}
+ * predicate buffer(char *buffer, size_t N, size_t M; list<list<char> > elements) =
+ * N == 0
+ * ? elements == nil
+ * : chars(buffer, M, ?x) &*& buffer(buffer + M, N - 1, M, ?xs) &*& elements == cons(x, xs);
+ *
+ * lemma void buffer_length(char *buffer, size_t N, size_t M)
+ * requires buffer(buffer, N, M, ?elements);
+ * ensures buffer(buffer, N, M, elements) &*& length(elements) == N;
+ * {
+ * if (N == 0) {
+ * open buffer(buffer, N, M, elements);
+ * close buffer(buffer, N, M, elements);
+ * } else {
+ * open buffer(buffer, N, M, elements);
+ * buffer_length(buffer+M, N-1, M);
+ * }
+ * }
+ * @*/
-predicate list(List_t *l;) =
- l->uxNumberOfItems |-> _;
+/*
+ * There is no need in the queue proofs to preserve a relationship between `cs`
+ * and `elements` (i.e., `flatten(elements) == cs`) because we only move in one
+ * direction from `cs` to `elements` during queue creation when the contents is
+ * fresh from `malloc` (i.e., uninitialized). If we needed to do a roundtrip from
+ * elements back to cs then this would require a stronger lemma.
+ */
-predicate queuelists(QueueHandle_t q;) =
- list(&q->xTasksWaitingToSend) &*&
- list(&q->xTasksWaitingToReceive);
-@*/
+/*@
+ * lemma void buffer_from_chars(char *buffer, size_t N, size_t M)
+ * requires chars(buffer, N*M, ?cs) &*& 0 <= N &*& 0 < M;
+ * ensures exists<list<list<char> > >(?elements) &*& buffer(buffer, N, M, elements) &*& length(elements) == N;
+ * {
+ * if (N == 0) {
+ * close exists(nil);
+ * } else {
+ * int i = 0;
+ * while (i < N)
+ * invariant 0 <= i &*& i <= N &*&
+ * chars(buffer, (N-i)*M, ?xs) &*& xs == take((N-i)*M, cs) &*&
+ * buffer(buffer + (N-i)*M, i, M, ?ys);
+ * decreases N-i;
+ * {
+ * mul_mono_l(0, N-i-1, M);
+ * chars_split(buffer, (N-i-1)*M);
+ * mul_mono_l(i, N, M);
+ * mul_mono_l(N-i, N, M);
+ * take_take((N-i-1)*M, (N-i)*M, cs);
+ * i++;
+ * }
+ * close exists(ys);
+ * buffer_length(buffer, N, M);
+ * }
+ * }
+ *
+ * lemma void append_buffer(char *buffer, size_t N1, size_t N2, size_t M)
+ * requires
+ * buffer(buffer, N1, M, ?elements1) &*&
+ * buffer(buffer + N1 * M, N2, M, ?elements2) &*&
+ * 0 <= N1 &*& 0 <= N2;
+ * ensures buffer(buffer, N1+N2, M, append(elements1, elements2));
+ * {
+ * if (N1 == 0) {
+ * open buffer(buffer, 0, M, _);
+ * } else if (N2 == 0) {
+ * open buffer(buffer + N1 * M, 0, M, _);
+ * } else {
+ * open buffer(buffer, N1, M, elements1);
+ * append_buffer(buffer + M, N1-1, N2, M);
+ * close buffer(buffer, N1+N2, M, cons(?x, append(xs, elements2)));
+ * }
+ * }
+ *
+ * lemma void split_element<t>(char *buffer, size_t N, size_t M, size_t i)
+ * requires buffer(buffer, N, M, ?elements) &*& 0 <= i &*& i < N;
+ * ensures
+ * buffer(buffer, i, M, take(i, elements)) &*&
+ * chars(buffer + i * M, M, nth(i, elements)) &*&
+ * buffer(buffer + (i + 1) * M, (N-1-i), M, drop(i+1, elements));
+ * {
+ * if (i == 0) {
+ * // straightforward
+ * } else {
+ * buffer_length(buffer, N, M);
+ * int j = 0;
+ * while (j < i)
+ * invariant 0 <= j &*& j <= i &*&
+ * buffer(buffer, j, M, take(j, elements)) &*&
+ * buffer(buffer + j * M, N-j, M, drop(j, elements));
+ * decreases i-j;
+ * {
+ * drop_drop(1, j, elements);
+ * nth_drop2(elements, j);
+ * open buffer(buffer + j * M, N-j, M, drop(j, elements));
+ * assert chars(buffer + j * M, M, ?x) &*& x == nth(j, elements);
+ * close buffer(buffer + j * M, 1, M, singleton(x));
+ * append_buffer(buffer, j, 1, M);
+ * take_plus_one(j, elements);
+ * j++;
+ * }
+ * drop_drop(1, j, elements);
+ * nth_drop2(elements, i);
+ * }
+ * }
+ *
+ * lemma void join_element(char *buffer, size_t N, size_t M, size_t i)
+ * requires
+ * 0 <= i &*& i < N &*&
+ * buffer(buffer, i, M, ?prefix) &*&
+ * chars(buffer + i * M, M, ?element) &*&
+ * buffer(buffer + (i + 1) * M, (N-1-i), M, ?suffix);
+ * ensures buffer(buffer, N, M, append(prefix, cons(element, suffix)));
+ * {
+ * if (i == 0) {
+ * open buffer(buffer, i, M, prefix);
+ * assert prefix == nil;
+ * close buffer(buffer, N, M, cons(element, suffix));
+ * } else {
+ * close buffer(buffer + i * M, N-i, M, cons(element, suffix));
+ * append_buffer(buffer, i, N-i, M);
+ * }
+ * }
+ *
+ * predicate list(List_t *l;) =
+ * l->uxNumberOfItems |-> _;
+ *
+ * predicate queuelists(QueueHandle_t q;) =
+ * list(&q->xTasksWaitingToSend) &*&
+ * list(&q->xTasksWaitingToReceive);
+ * @*/
/* Because prvCopyDataFromQueue does *not* decrement uxMessagesWaiting (K) the
-queue predicate above does not hold as a postcondition. If the caller
-subsequently decrements K then the queue predicate can be reinstated. */
+ * queue predicate above does not hold as a postcondition. If the caller
+ * subsequently decrements K then the queue predicate can be reinstated. */
+
/*@
-predicate queue_after_prvCopyDataFromQueue(QueueHandle_t q, int8_t *Storage, size_t N, size_t M, size_t W, size_t R, size_t K, bool is_locked; list<list<char> >abs) =
- QUEUE_SHAPE(q, Storage, N, M, K) &*&
- 0 < N &*&
- 0 < M &*&
- 0 <= W &*& W < N &*&
- 0 <= R &*& R < N &*&
- 0 <= K &*& K <= N &*&
- W == (R + K) % N &*& //< Differs from queue predicate
- (-1) <= rxLock &*&
- (-1) <= txLock &*&
- (is_locked ? 0 <= rxLock : (-1) == rxLock) &*&
- (is_locked ? 0 <= txLock : (-1) == txLock) &*&
- WPtr == Storage + (W*M) &*&
- RPtr == Storage + (R*M) &*&
- End == Storage + (N*M) &*&
- buffer(Storage, N, M, ?contents) &*&
- length(contents) == N &*&
- abs == take(K, rotate_left(R, contents)) &*& //< Differs from queue predicate
- malloc_block(Storage, N*M) &*&
- true
- ;
-@*/
+ * predicate queue_after_prvCopyDataFromQueue(QueueHandle_t q, int8_t *Storage, size_t N, size_t M, size_t W, size_t R, size_t K, bool is_locked; list<list<char> >abs) =
+ * QUEUE_SHAPE(q, Storage, N, M, K) &*&
+ * 0 < N &*&
+ * 0 < M &*&
+ * 0 <= W &*& W < N &*&
+ * 0 <= R &*& R < N &*&
+ * 0 <= K &*& K <= N &*&
+ * W == (R + K) % N &*& //< Differs from queue predicate
+ * (-1) <= rxLock &*&
+ * (-1) <= txLock &*&
+ * (is_locked ? 0 <= rxLock : (-1) == rxLock) &*&
+ * (is_locked ? 0 <= txLock : (-1) == txLock) &*&
+ * WPtr == Storage + (W*M) &*&
+ * RPtr == Storage + (R*M) &*&
+ * End == Storage + (N*M) &*&
+ * buffer(Storage, N, M, ?contents) &*&
+ * length(contents) == N &*&
+ * abs == take(K, rotate_left(R, contents)) &*& //< Differs from queue predicate
+ * malloc_block(Storage, N*M) &*&
+ * true
+ * ;
+ * @*/
/* Can't be called `mutex` as this clashes with VeriFast's predicate */
+
/*@
-predicate freertos_mutex(QueueHandle_t q, int8_t *Storage, size_t N, size_t K;) =
- QUEUE_SHAPE(q, Storage, N, 0, K) &*&
- queuelists(q) &*&
- 0 < N &*&
- 0 <= K &*& K <= N &*&
- (-1) <= rxLock &*&
- (-1) <= txLock &*&
- WPtr == Storage &*&
- RPtr == Storage &*&
- End == Storage &*&
- malloc_block(Storage, 0) &*&
- chars(Storage, 0, _) &*&
- true
- ;
-@*/
+ * predicate freertos_mutex(QueueHandle_t q, int8_t *Storage, size_t N, size_t K;) =
+ * QUEUE_SHAPE(q, Storage, N, 0, K) &*&
+ * queuelists(q) &*&
+ * 0 < N &*&
+ * 0 <= K &*& K <= N &*&
+ * (-1) <= rxLock &*&
+ * (-1) <= txLock &*&
+ * WPtr == Storage &*&
+ * RPtr == Storage &*&
+ * End == Storage &*&
+ * malloc_block(Storage, 0) &*&
+ * chars(Storage, 0, _) &*&
+ * true
+ * ;
+ * @*/
/* A queuehandle can be shared between tasks and ISRs. Acquiring the ghost
-`irqMask` gives access to the core queue resources. The permissions granted
-after masking interrupts depends on the caller:
-- A task has access to the queue and the queuelists
-- An ISR has access to the queue and, if the queue is unlocked, the queuelists */
-/*@
-predicate queuehandle(QueueHandle_t q, size_t N, size_t M, bool is_isr;) =
- q->irqMask |-> ?m &*& mutex(m, irqs_masked_invariant(q, N, M, is_isr));
+ * `irqMask` gives access to the core queue resources. The permissions granted
+ * after masking interrupts depends on the caller:
+ * - A task has access to the queue and the queuelists
+ * - An ISR has access to the queue and, if the queue is unlocked, the queuelists */
-predicate_ctor irqs_masked_invariant(QueueHandle_t queue, size_t N, size_t M, bool is_isr)() =
- queue(queue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- (is_isr && is_locked ? true : queuelists(queue));
-@*/
+/*@
+ * predicate queuehandle(QueueHandle_t q, size_t N, size_t M, bool is_isr;) =
+ * q->irqMask |-> ?m &*& mutex(m, irqs_masked_invariant(q, N, M, is_isr));
+ *
+ * predicate_ctor irqs_masked_invariant(QueueHandle_t queue, size_t N, size_t M, bool is_isr)() =
+ * queue(queue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
+ * (is_isr && is_locked ? true : queuelists(queue));
+ * @*/
/* A queuesuspend can be shared between tasks. Acquiring the ghost `schedulerSuspend` gives access to the `locked` mutex. */
-/*@
-predicate_ctor scheduler_suspended_invariant(QueueHandle_t queue)() =
- queue->locked |-> ?m &*&
- mutex(m, queue_locked_invariant(queue));
-predicate queuesuspend(QueueHandle_t q;) =
- q->schedulerSuspend |-> ?m &*&
- mutex(m, scheduler_suspended_invariant(q));
-@*/
+/*@
+ * predicate_ctor scheduler_suspended_invariant(QueueHandle_t queue)() =
+ * queue->locked |-> ?m &*&
+ * mutex(m, queue_locked_invariant(queue));
+ *
+ * predicate queuesuspend(QueueHandle_t q;) =
+ * q->schedulerSuspend |-> ?m &*&
+ * mutex(m, scheduler_suspended_invariant(q));
+ * @*/
/* A queuelock is exclusively acquired by a task. Acquiring the ghost `queuelock` gives access to the queue list resources. */
-/*@
-predicate queuelock(QueueHandle_t q;) =
- q->locked |-> ?m &*&
- mutex(m, queue_locked_invariant(q));
-predicate_ctor queue_locked_invariant(QueueHandle_t queue)() =
- queuelists(queue);
-@*/
+/*@
+ * predicate queuelock(QueueHandle_t q;) =
+ * q->locked |-> ?m &*&
+ * mutex(m, queue_locked_invariant(q));
+ *
+ * predicate_ctor queue_locked_invariant(QueueHandle_t queue)() =
+ * queuelists(queue);
+ * @*/
-BaseType_t vListInitialise(List_t *list);
+BaseType_t vListInitialise( List_t * list );
/*@requires list(list);@*/
/*@ensures list(list);@*/
-BaseType_t listLIST_IS_EMPTY(List_t *list);
+BaseType_t listLIST_IS_EMPTY( List_t * list );
/*@requires list->uxNumberOfItems |-> ?len;@*/
/*@ensures list->uxNumberOfItems |-> len &*& result == (len == 0 ? pdTRUE : pdFALSE);@*/
@@ -433,25 +442,27 @@ typedef struct xTIME_OUT
} TimeOut_t;
/*@
-predicate xTIME_OUT(struct xTIME_OUT *to;) =
- to->xOverflowCount |-> _ &*&
- to->xTimeOnEntering |-> _ &*&
- struct_xTIME_OUT_padding(to);
-@*/
+ * predicate xTIME_OUT(struct xTIME_OUT *to;) =
+ * to->xOverflowCount |-> _ &*&
+ * to->xTimeOnEntering |-> _ &*&
+ * struct_xTIME_OUT_padding(to);
+ * @*/
-void vTaskInternalSetTimeOutState( TimeOut_t * x);
+void vTaskInternalSetTimeOutState( TimeOut_t * x );
/*@requires xTIME_OUT(x);@*/
/*@ensures xTIME_OUT(x);@*/
-BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
+BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
+ TickType_t * const pxTicksToWait );
/*@requires xTIME_OUT(pxTimeOut) &*& u_integer(pxTicksToWait, _);@*/
/*@ensures xTIME_OUT(pxTimeOut) &*& u_integer(pxTicksToWait, _);@*/
-BaseType_t xTaskRemoveFromEventList(List_t *list);
+BaseType_t xTaskRemoveFromEventList( List_t * list );
/*@requires list(list);@*/
/*@ensures list(list);@*/
-void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait );
+void vTaskPlaceOnEventList( List_t * const pxEventList,
+ const TickType_t xTicksToWait );
/*@requires list(pxEventList);@*/
/*@ensures list(pxEventList);@*/
@@ -460,94 +471,107 @@ void vTaskMissedYield();
/*@ensures true;@*/
void vTaskSuspendAll();
+
/*@requires exists<QueueHandle_t>(?xQueue) &*&
- [1/2]xQueue->schedulerSuspend |-> ?m &*&
- [1/2]mutex(m, scheduler_suspended_invariant(xQueue));@*/
+ * [1/2]xQueue->schedulerSuspend |-> ?m &*&
+ * [1/2]mutex(m, scheduler_suspended_invariant(xQueue));@*/
+
/*@ensures [1/2]xQueue->schedulerSuspend |-> m &*&
- mutex_held(m, scheduler_suspended_invariant(xQueue), currentThread, 1/2) &*&
- xQueue->locked |-> ?m2 &*&
- mutex(m2, queue_locked_invariant(xQueue));@*/
+ * mutex_held(m, scheduler_suspended_invariant(xQueue), currentThread, 1/2) &*&
+ * xQueue->locked |-> ?m2 &*&
+ * mutex(m2, queue_locked_invariant(xQueue));@*/
BaseType_t xTaskResumeAll( void );
+
/*@requires exists<QueueHandle_t>(?xQueue) &*&
- [1/2]xQueue->schedulerSuspend |-> ?m &*&
- mutex_held(m, scheduler_suspended_invariant(xQueue), currentThread, 1/2) &*&
- xQueue->locked |-> ?m2 &*&
- mutex(m2, queue_locked_invariant(xQueue));@*/
+ * [1/2]xQueue->schedulerSuspend |-> ?m &*&
+ * mutex_held(m, scheduler_suspended_invariant(xQueue), currentThread, 1/2) &*&
+ * xQueue->locked |-> ?m2 &*&
+ * mutex(m2, queue_locked_invariant(xQueue));@*/
+
/*@ensures [1/2]xQueue->schedulerSuspend |-> m &*&
- [1/2]mutex(m, scheduler_suspended_invariant(xQueue));@*/
+ * [1/2]mutex(m, scheduler_suspended_invariant(xQueue));@*/
void prvLockQueue( QueueHandle_t xQueue );
+
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
- [1/2]queuelock(xQueue); @*/
+ * [1/2]queuelock(xQueue); @*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]xQueue->locked |-> ?m &*&
- mutex_held(m, queue_locked_invariant(xQueue), currentThread, 1/2) &*&
- queue_locked_invariant(xQueue)();@*/
+ * [1/2]xQueue->locked |-> ?m &*&
+ * mutex_held(m, queue_locked_invariant(xQueue), currentThread, 1/2) &*&
+ * queue_locked_invariant(xQueue)();@*/
void prvUnlockQueue( QueueHandle_t xQueue );
+
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
- [1/2]xQueue->locked |-> ?m &*&
- mutex_held(m, queue_locked_invariant(xQueue), currentThread, 1/2) &*&
- queue_locked_invariant(xQueue)();@*/
+ * [1/2]xQueue->locked |-> ?m &*&
+ * mutex_held(m, queue_locked_invariant(xQueue), currentThread, 1/2) &*&
+ * queue_locked_invariant(xQueue)();@*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]queuelock(xQueue);@*/
+ * [1/2]queuelock(xQueue);@*/
-void setInterruptMask(QueueHandle_t xQueue)
+void setInterruptMask( QueueHandle_t xQueue )
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false;@*/
+
/*@ensures [1/2]xQueue->irqMask |-> ?m &*&
- mutex_held(m, irqs_masked_invariant(xQueue, N, M, is_isr), currentThread, 1/2) &*&
- queue(xQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- queuelists(xQueue);@*/
+ * mutex_held(m, irqs_masked_invariant(xQueue, N, M, is_isr), currentThread, 1/2) &*&
+ * queue(xQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
+ * queuelists(xQueue);@*/
{
/*@open queuehandle(xQueue, N, M, is_isr);@*/
- mutex_acquire(xQueue->irqMask);
+ mutex_acquire( xQueue->irqMask );
/*@open irqs_masked_invariant(xQueue, N, M, is_isr)();@*/
}
-void clearInterruptMask(QueueHandle_t xQueue)
+void clearInterruptMask( QueueHandle_t xQueue )
+
/*@requires queue(xQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- [1/2]xQueue->irqMask |-> ?m &*&
- mutex_held(m, irqs_masked_invariant(xQueue, N, M, false), currentThread, 1/2) &*&
- queuelists(xQueue);@*/
+ * [1/2]xQueue->irqMask |-> ?m &*&
+ * mutex_held(m, irqs_masked_invariant(xQueue, N, M, false), currentThread, 1/2) &*&
+ * queuelists(xQueue);@*/
/*@ensures [1/2]queuehandle(xQueue, N, M, false);@*/
{
/*@close irqs_masked_invariant(xQueue, N, M, false)();@*/
- mutex_release(xQueue->irqMask);
+ mutex_release( xQueue->irqMask );
/*@close [1/2]queuehandle(xQueue, N, M, false);@*/
}
-#define taskENTER_CRITICAL() setInterruptMask(xQueue)
-#define taskEXIT_CRITICAL() clearInterruptMask(xQueue)
+#define taskENTER_CRITICAL() setInterruptMask( xQueue )
+#define taskEXIT_CRITICAL() clearInterruptMask( xQueue )
#define portYIELD_WITHIN_API()
#define queueYIELD_IF_USING_PREEMPTION()
-UBaseType_t setInterruptMaskFromISR(QueueHandle_t xQueue)
+UBaseType_t setInterruptMaskFromISR( QueueHandle_t xQueue )
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true;@*/
+
/*@ensures [1/2]xQueue->irqMask |-> ?m &*&
- mutex_held(m, irqs_masked_invariant(xQueue, N, M, is_isr), currentThread, 1/2) &*&
- queue(xQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- (is_locked ? true : queuelists(xQueue));@*/
+ * mutex_held(m, irqs_masked_invariant(xQueue, N, M, is_isr), currentThread, 1/2) &*&
+ * queue(xQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
+ * (is_locked ? true : queuelists(xQueue));@*/
{
/*@open queuehandle(xQueue, N, M, is_isr);@*/
- mutex_acquire(xQueue->irqMask);
+ mutex_acquire( xQueue->irqMask );
/*@open irqs_masked_invariant(xQueue, N, M, is_isr)();@*/
return 0;
}
-void clearInterruptMaskFromISR(QueueHandle_t xQueue, UBaseType_t uxSavedInterruptStatus)
+void clearInterruptMaskFromISR( QueueHandle_t xQueue,
+ UBaseType_t uxSavedInterruptStatus )
+
/*@requires queue(xQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- [1/2]xQueue->irqMask |-> ?m &*&
- mutex_held(m, irqs_masked_invariant(xQueue, N, M, true), currentThread, 1/2) &*&
- (is_locked ? true : queuelists(xQueue));@*/
+ * [1/2]xQueue->irqMask |-> ?m &*&
+ * mutex_held(m, irqs_masked_invariant(xQueue, N, M, true), currentThread, 1/2) &*&
+ * (is_locked ? true : queuelists(xQueue));@*/
/*@ensures [1/2]queuehandle(xQueue, N, M, true);@*/
{
/*@close irqs_masked_invariant(xQueue, N, M, true)();@*/
- mutex_release(xQueue->irqMask);
+ mutex_release( xQueue->irqMask );
/*@close [1/2]queuehandle(xQueue, N, M, true);@*/
}
-#define portSET_INTERRUPT_MASK_FROM_ISR() setInterruptMaskFromISR(xQueue)
-#define portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedInterruptStatus) clearInterruptMaskFromISR(xQueue, uxSavedInterruptStatus)
+#define portSET_INTERRUPT_MASK_FROM_ISR() setInterruptMaskFromISR( xQueue )
+#define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ) clearInterruptMaskFromISR( xQueue, uxSavedInterruptStatus )
#endif /* QUEUE_H */
diff --git a/FreeRTOS/Test/VeriFast/include/proof/queuecontracts.h b/FreeRTOS/Test/VeriFast/include/proof/queuecontracts.h
index e25c510ea..73d68caa8 100644
--- a/FreeRTOS/Test/VeriFast/include/proof/queuecontracts.h
+++ b/FreeRTOS/Test/VeriFast/include/proof/queuecontracts.h
@@ -29,26 +29,32 @@
#include "queue.h"
-void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer );
+void prvCopyDataFromQueue( Queue_t * const pxQueue,
+ void * const pvBuffer );
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*& 0 < K &*& chars(pvBuffer, M, _);@*/
+
/*@ensures queue_after_prvCopyDataFromQueue(pxQueue, Storage, N, M, W, (R+1)%N, K, is_locked, abs) &*&
- chars(pvBuffer, M, head(abs));@*/
+ * chars(pvBuffer, M, head(abs));@*/
+
+BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition );
-BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition );
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- (K < N || xPosition == queueOVERWRITE) &*&
- chars(pvItemToQueue, M, ?x) &*&
- (xPosition == queueSEND_TO_BACK || xPosition == queueSEND_TO_FRONT || (xPosition == queueOVERWRITE && N == 1));@*/
+ * (K < N || xPosition == queueOVERWRITE) &*&
+ * chars(pvItemToQueue, M, ?x) &*&
+ * (xPosition == queueSEND_TO_BACK || xPosition == queueSEND_TO_FRONT || (xPosition == queueOVERWRITE && N == 1));@*/
+
/*@ensures
- (xPosition == queueSEND_TO_BACK
- ? queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)))
- : (xPosition == queueSEND_TO_FRONT
- ? (R == 0
- ? queue(pxQueue, Storage, N, M, W, (N-1), (K+1), is_locked, cons(x, abs))
- : queue(pxQueue, Storage, N, M, W, (R-1), (K+1), is_locked, cons(x, abs)))
- : xPosition == queueOVERWRITE &*& queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x)))
- ) &*&
- chars(pvItemToQueue, M, x);@*/
+ * (xPosition == queueSEND_TO_BACK
+ * ? queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)))
+ * : (xPosition == queueSEND_TO_FRONT
+ * ? (R == 0
+ * ? queue(pxQueue, Storage, N, M, W, (N-1), (K+1), is_locked, cons(x, abs))
+ * : queue(pxQueue, Storage, N, M, W, (R-1), (K+1), is_locked, cons(x, abs)))
+ * : xPosition == queueOVERWRITE &*& queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x)))
+ * ) &*&
+ * chars(pvItemToQueue, M, x);@*/
BaseType_t prvIsQueueEmpty( Queue_t * pxQueue );
/*@requires [1/2]queuehandle(pxQueue, ?N, ?M, ?is_isr) &*& is_isr == false;@*/
diff --git a/FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c b/FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c
index db17485ad..539585d50 100644
--- a/FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c
+++ b/FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c
@@ -27,12 +27,13 @@
#include "proof/list.h"
/* Wrap the macro in a function call so we can give a function contract */
-#define listLIST_IS_EMPTY( pxList ) ( ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ? pdTRUE : pdFALSE )
+#define listLIST_IS_EMPTY( pxList ) ( ( ( pxList )->uxNumberOfItems == ( UBaseType_t ) 0 ) ? pdTRUE : pdFALSE )
BaseType_t wrapper_listLIST_IS_EMPTY( List_t * pxList )
/*@requires xLIST(pxList, ?len, ?idx, ?end, ?cells, ?vals);@*/
+
/*@ensures xLIST(pxList, len, idx, end, cells, vals) &*&
- result == ((len == 0) ? pdTRUE : pdFALSE); @*/
+ * result == ((len == 0) ? pdTRUE : pdFALSE); @*/
{
/*@open xLIST(pxList, len, _, _, _, _);@*/
return listLIST_IS_EMPTY( pxList );
diff --git a/FreeRTOS/Test/VeriFast/list/uxListRemove.c b/FreeRTOS/Test/VeriFast/list/uxListRemove.c
index 502f40564..51540030b 100644
--- a/FreeRTOS/Test/VeriFast/list/uxListRemove.c
+++ b/FreeRTOS/Test/VeriFast/list/uxListRemove.c
@@ -27,16 +27,18 @@
#include "proof/list.h"
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
+
/*@requires
- exists<struct xLIST * >(?l) &*&
- xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
- end != pxItemToRemove &*&
- mem(pxItemToRemove, cells) == true;@*/
+ * exists<struct xLIST * >(?l) &*&
+ * xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
+ * end != pxItemToRemove &*&
+ * mem(pxItemToRemove, cells) == true;@*/
+
/*@ensures
- result == len-1 &*&
- xLIST_ITEM(pxItemToRemove, nth(index_of(pxItemToRemove, cells), vals), _, ?pxItemToRemovePrevious, NULL) &*&
- pxItemToRemovePrevious == nth(index_of(pxItemToRemove, cells)-1, cells) &*&
- xLIST(l, result, idx == pxItemToRemove ? pxItemToRemovePrevious : idx, end, remove(pxItemToRemove, cells), remove_nth(index_of(pxItemToRemove, cells), vals));@*/
+ * result == len-1 &*&
+ * xLIST_ITEM(pxItemToRemove, nth(index_of(pxItemToRemove, cells), vals), _, ?pxItemToRemovePrevious, NULL) &*&
+ * pxItemToRemovePrevious == nth(index_of(pxItemToRemove, cells)-1, cells) &*&
+ * xLIST(l, result, idx == pxItemToRemove ? pxItemToRemovePrevious : idx, end, remove(pxItemToRemove, cells), remove_nth(index_of(pxItemToRemove, cells), vals));@*/
{
/* For brevity we alias x to pxItemToRemove */
/*@struct xLIST_ITEM *x = pxItemToRemove;@*/
@@ -48,7 +50,7 @@ UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
/*@dls_not_empty(end, endprev, cells, x);@*/
/* We know the xLIST is a DLS: end...endprev
- Split this into DLS1:end...xprev and DLS2:x...endprev */
+ * Split this into DLS1:end...xprev and DLS2:x...endprev */
/*@int i = index_of(x, cells);@*/
/*@split(end, endprev, end, endprev, cells, vals, x, i);@*/
/*@list<struct xLIST_ITEM *> ys = take(i, cells);@*/
@@ -61,106 +63,107 @@ UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
/*@assert DLS(x, xprev, end, endprev, zs, ws, l);@*/ /*< DLS2 (zs, ws) */
/* Now case split to open DLS1 and DLS2 appropriately */
+
/*@
- if (end == xprev)
- {
- if (x == endprev)
- {
- //Case A
- //DLS1: extract end=prev=next
- open DLS(end, endprev, x, xprev, ys, vs, l);
- open xLIST_ITEM(end, portMAX_DELAY, x, endprev, l);
- //DLS2: extract x
- open DLS(x, xprev, end, endprev, zs, ws, l);
- //Lengths
- assert length(ys) == 1;
- assert length(zs) == 1;
- }
- else
- {
- //Case B
- //DLS1: extract end=prev
- open DLS(end, endprev, x, xprev, ys, vs, l);
- open xLIST_ITEM(end, portMAX_DELAY, x, endprev, l);
- //DLS2: extract next and x
- open DLS(x, end, end, endprev, zs, ws, l);
- assert DLS(?xnext, x, end, endprev, tail(zs), tail(ws), l);
- open DLS(xnext, x, end, endprev, tail(zs), tail(ws), l);
- open xLIST_ITEM(xnext, _, _, x, l);
- //Lengths
- assert length(ys) == 1;
- }
- }
- else
- {
- if (x == endprev)
- {
- //Case C
- //DLS1: extract end=next and prev
- dls_last_mem(end, endprev, x, xprev, ys);
- assert mem(xprev, ys) == true;
- open DLS(end, endprev, x, xprev, ys, vs, l);
- open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, l);
- if (endnext == xprev)
- {
- open DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
- open xLIST_ITEM(xprev, _, x, _, l);
- }
- else
- {
- assert DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
- int k = index_of(xprev, tail(ys));
- dls_last_mem(endnext, end, x, xprev, tail(ys));
- split(endnext, end, x, xprev, tail(ys), tail(vs), xprev, k);
- open DLS(xprev, _, x, xprev, _, _, l);
- open xLIST_ITEM(xprev, _, x, _, l);
- }
- //DLS2: extract x
- open DLS(x, xprev, end, endprev, zs, ws, l);
- //Lengths
- assert length(zs) == 1;
- }
- else
- {
- //Case D
- //DLS1: extract prev
- dls_last_mem(end, endprev, x, xprev, ys);
- int j = index_of(xprev, ys);
- open DLS(end, endprev, x, xprev, ys, vs, l);
- open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, l);
- if (endnext == xprev)
- {
- open DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
- assert tail(ys) == singleton(xprev);
- open xLIST_ITEM(xprev, _, x, _, l);
- }
- else
- {
- assert DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
- int k = index_of(xprev, tail(ys));
- dls_last_mem(endnext, end, x, xprev, tail(ys));
- split(endnext, end, x, xprev, tail(ys), tail(vs), xprev, k);
- open DLS(xprev, _, x, xprev, _, _, l);
- open xLIST_ITEM(xprev, _, x, _, l);
- }
- //DLS2: extract next and x
- open DLS(x, xprev, end, endprev, zs, ws, l);
- assert xLIST_ITEM(x, _, ?xnext, _, l);
- open DLS(xnext, x, end, endprev, tail(zs), tail(ws), l);
- open xLIST_ITEM(xnext, _, _, x, l);
- }
- }
- @*/
+ * if (end == xprev)
+ * {
+ * if (x == endprev)
+ * {
+ * //Case A
+ * //DLS1: extract end=prev=next
+ * open DLS(end, endprev, x, xprev, ys, vs, l);
+ * open xLIST_ITEM(end, portMAX_DELAY, x, endprev, l);
+ * //DLS2: extract x
+ * open DLS(x, xprev, end, endprev, zs, ws, l);
+ * //Lengths
+ * assert length(ys) == 1;
+ * assert length(zs) == 1;
+ * }
+ * else
+ * {
+ * //Case B
+ * //DLS1: extract end=prev
+ * open DLS(end, endprev, x, xprev, ys, vs, l);
+ * open xLIST_ITEM(end, portMAX_DELAY, x, endprev, l);
+ * //DLS2: extract next and x
+ * open DLS(x, end, end, endprev, zs, ws, l);
+ * assert DLS(?xnext, x, end, endprev, tail(zs), tail(ws), l);
+ * open DLS(xnext, x, end, endprev, tail(zs), tail(ws), l);
+ * open xLIST_ITEM(xnext, _, _, x, l);
+ * //Lengths
+ * assert length(ys) == 1;
+ * }
+ * }
+ * else
+ * {
+ * if (x == endprev)
+ * {
+ * //Case C
+ * //DLS1: extract end=next and prev
+ * dls_last_mem(end, endprev, x, xprev, ys);
+ * assert mem(xprev, ys) == true;
+ * open DLS(end, endprev, x, xprev, ys, vs, l);
+ * open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, l);
+ * if (endnext == xprev)
+ * {
+ * open DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
+ * open xLIST_ITEM(xprev, _, x, _, l);
+ * }
+ * else
+ * {
+ * assert DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
+ * int k = index_of(xprev, tail(ys));
+ * dls_last_mem(endnext, end, x, xprev, tail(ys));
+ * split(endnext, end, x, xprev, tail(ys), tail(vs), xprev, k);
+ * open DLS(xprev, _, x, xprev, _, _, l);
+ * open xLIST_ITEM(xprev, _, x, _, l);
+ * }
+ * //DLS2: extract x
+ * open DLS(x, xprev, end, endprev, zs, ws, l);
+ * //Lengths
+ * assert length(zs) == 1;
+ * }
+ * else
+ * {
+ * //Case D
+ * //DLS1: extract prev
+ * dls_last_mem(end, endprev, x, xprev, ys);
+ * int j = index_of(xprev, ys);
+ * open DLS(end, endprev, x, xprev, ys, vs, l);
+ * open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, l);
+ * if (endnext == xprev)
+ * {
+ * open DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
+ * assert tail(ys) == singleton(xprev);
+ * open xLIST_ITEM(xprev, _, x, _, l);
+ * }
+ * else
+ * {
+ * assert DLS(endnext, end, x, xprev, tail(ys), tail(vs), l);
+ * int k = index_of(xprev, tail(ys));
+ * dls_last_mem(endnext, end, x, xprev, tail(ys));
+ * split(endnext, end, x, xprev, tail(ys), tail(vs), xprev, k);
+ * open DLS(xprev, _, x, xprev, _, _, l);
+ * open xLIST_ITEM(xprev, _, x, _, l);
+ * }
+ * //DLS2: extract next and x
+ * open DLS(x, xprev, end, endprev, zs, ws, l);
+ * assert xLIST_ITEM(x, _, ?xnext, _, l);
+ * open DLS(xnext, x, end, endprev, tail(zs), tail(ws), l);
+ * open xLIST_ITEM(xnext, _, _, x, l);
+ * }
+ * }
+ * @*/
/*@drop_nth_index_of(vals, i);@*/
/*@open xLIST_ITEM(x, nth(i, vals), ?xnext, xprev, l);@*/
/* The list item knows which list it is in. Obtain the list from the list
* item. */
-#ifdef VERIFAST /*< const pointer declaration */
- List_t * pxList = pxItemToRemove->pxContainer;
-#else
- List_t * const pxList = pxItemToRemove->pxContainer;
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ List_t * pxList = pxItemToRemove->pxContainer;
+ #else
+ List_t * const pxList = pxItemToRemove->pxContainer;
+ #endif
pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
@@ -184,101 +187,105 @@ UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
return pxList->uxNumberOfItems;
/*@
- // Reassemble DLS1 and a modified DLS2, which no longer includes x
- if (end == xprev)
- {
- if (x == endprev)
- {
- //Case A
- close xLIST_ITEM(end, portMAX_DELAY, _, _, _);
- close DLS(end, end, end, end, singleton(end), singleton(portMAX_DELAY), l);
- }
- else
- {
- //Case B
- close xLIST_ITEM(xprev, _, xnext, endprev, l);
- close DLS(end, endprev, xnext, xprev, singleton(end), singleton(portMAX_DELAY), l);
- close xLIST_ITEM(xnext, _, _, xprev, l);
- close DLS(xnext, xprev, end, endprev, tail(zs), tail(ws), l);
- join(end, endprev, xnext, xprev, singleton(end), singleton(portMAX_DELAY),
- xnext, xprev, end, endprev, tail(zs), tail(ws));
- }
- }
- else
- {
- if (x == endprev)
- {
- //Case C
- close xLIST_ITEM(end, _, ?endnext, xprev, l);
- close xLIST_ITEM(xprev, ?xprev_val, end, _, l);
- if (endnext == xprev)
- {
- close DLS(xprev, end, end, xprev, singleton(xprev), singleton(xprev_val), l);
- close DLS(end, xprev, end, xprev, cons(end, singleton(xprev)), cons(portMAX_DELAY, singleton(xprev_val)), l);
- }
- else
- {
- close DLS(xprev, ?xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val), l);
- assert DLS(endnext, end, xprev, xprevprev, ?cells_endnext_to_xprevprev, ?vals_endnext_to_xprevprev, l);
- join(endnext, end, xprev, xprevprev, cells_endnext_to_xprevprev, vals_endnext_to_xprevprev,
- xprev, xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val));
- close DLS(end, xprev, end, xprev, ys, vs, l);
- }
- }
- else
- {
- //Case D
- close xLIST_ITEM(xnext, _, ?xnextnext, xprev, l);
- close DLS(xnext, xprev, end, endprev, tail(zs), tail(ws), l);
- close xLIST_ITEM(end, _, ?endnext, endprev, l);
- close xLIST_ITEM(xprev, ?xprev_val, xnext, _, l);
- if (endnext == xprev)
- {
- close DLS(xprev, _, xnext, xprev, singleton(xprev), singleton(xprev_val), l);
- close DLS(end, endprev, xnext, xprev, ys, vs, l);
- join(end, endprev, xnext, xprev, ys, vs,
- xnext, xprev, end, endprev, tail(zs), tail(ws));
- }
- else
- {
- close DLS(xprev, ?xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val), l);
- assert DLS(endnext, end, xprev, xprevprev, ?cells_endnext_to_xprevprev, ?vals_endnext_to_xprevprev, l);
- join(endnext, end, xprev, xprevprev, cells_endnext_to_xprevprev, vals_endnext_to_xprevprev,
- xprev, xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val));
- close DLS(end, endprev, xnext, xprev, ys, vs, l);
- join(end, endprev, xnext, xprev, ys, vs,
- xnext, xprev, end, endprev, tail(zs), tail(ws));
- }
- }
- }
- @*/
+ * // Reassemble DLS1 and a modified DLS2, which no longer includes x
+ * if (end == xprev)
+ * {
+ * if (x == endprev)
+ * {
+ * //Case A
+ * close xLIST_ITEM(end, portMAX_DELAY, _, _, _);
+ * close DLS(end, end, end, end, singleton(end), singleton(portMAX_DELAY), l);
+ * }
+ * else
+ * {
+ * //Case B
+ * close xLIST_ITEM(xprev, _, xnext, endprev, l);
+ * close DLS(end, endprev, xnext, xprev, singleton(end), singleton(portMAX_DELAY), l);
+ * close xLIST_ITEM(xnext, _, _, xprev, l);
+ * close DLS(xnext, xprev, end, endprev, tail(zs), tail(ws), l);
+ * join(end, endprev, xnext, xprev, singleton(end), singleton(portMAX_DELAY),
+ * xnext, xprev, end, endprev, tail(zs), tail(ws));
+ * }
+ * }
+ * else
+ * {
+ * if (x == endprev)
+ * {
+ * //Case C
+ * close xLIST_ITEM(end, _, ?endnext, xprev, l);
+ * close xLIST_ITEM(xprev, ?xprev_val, end, _, l);
+ * if (endnext == xprev)
+ * {
+ * close DLS(xprev, end, end, xprev, singleton(xprev), singleton(xprev_val), l);
+ * close DLS(end, xprev, end, xprev, cons(end, singleton(xprev)), cons(portMAX_DELAY, singleton(xprev_val)), l);
+ * }
+ * else
+ * {
+ * close DLS(xprev, ?xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val), l);
+ * assert DLS(endnext, end, xprev, xprevprev, ?cells_endnext_to_xprevprev, ?vals_endnext_to_xprevprev, l);
+ * join(endnext, end, xprev, xprevprev, cells_endnext_to_xprevprev, vals_endnext_to_xprevprev,
+ * xprev, xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val));
+ * close DLS(end, xprev, end, xprev, ys, vs, l);
+ * }
+ * }
+ * else
+ * {
+ * //Case D
+ * close xLIST_ITEM(xnext, _, ?xnextnext, xprev, l);
+ * close DLS(xnext, xprev, end, endprev, tail(zs), tail(ws), l);
+ * close xLIST_ITEM(end, _, ?endnext, endprev, l);
+ * close xLIST_ITEM(xprev, ?xprev_val, xnext, _, l);
+ * if (endnext == xprev)
+ * {
+ * close DLS(xprev, _, xnext, xprev, singleton(xprev), singleton(xprev_val), l);
+ * close DLS(end, endprev, xnext, xprev, ys, vs, l);
+ * join(end, endprev, xnext, xprev, ys, vs,
+ * xnext, xprev, end, endprev, tail(zs), tail(ws));
+ * }
+ * else
+ * {
+ * close DLS(xprev, ?xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val), l);
+ * assert DLS(endnext, end, xprev, xprevprev, ?cells_endnext_to_xprevprev, ?vals_endnext_to_xprevprev, l);
+ * join(endnext, end, xprev, xprevprev, cells_endnext_to_xprevprev, vals_endnext_to_xprevprev,
+ * xprev, xprevprev, xnext, xprev, singleton(xprev), singleton(xprev_val));
+ * close DLS(end, endprev, xnext, xprev, ys, vs, l);
+ * join(end, endprev, xnext, xprev, ys, vs,
+ * xnext, xprev, end, endprev, tail(zs), tail(ws));
+ * }
+ * }
+ * }
+ * @*/
/*@remove_remove_nth(cells, x);@*/
+
/*@
- if (idx == x)
- {
- close xLIST(l, len-1, xprev, end, append(ys, tail(zs)), append(vs, tail(ws)));
- }
- else
- {
- idx_remains_in_list(cells, idx, x, i);
- close xLIST(l, len-1, idx, end, append(ys, tail(zs)), append(vs, tail(ws)));
- }
- @*/
+ * if (idx == x)
+ * {
+ * close xLIST(l, len-1, xprev, end, append(ys, tail(zs)), append(vs, tail(ws)));
+ * }
+ * else
+ * {
+ * idx_remains_in_list(cells, idx, x, i);
+ * close xLIST(l, len-1, idx, end, append(ys, tail(zs)), append(vs, tail(ws)));
+ * }
+ * @*/
/*@close xLIST_ITEM(x, nth(i, vals), xnext, xprev, NULL);@*/
}
ListItem_t * client_example( List_t * l )
+
/*@requires
- xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
- idx != end &*&
- cells == cons(end, cons(idx, ?cells_tl)) &*&
- vals == cons(portMAX_DELAY, cons(42, ?vals_tl));@*/
+ * xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
+ * idx != end &*&
+ * cells == cons(end, cons(idx, ?cells_tl)) &*&
+ * vals == cons(portMAX_DELAY, cons(42, ?vals_tl));@*/
+
/*@ensures
- xLIST(l, len - 1, _, end, cons(end, cells_tl), cons(portMAX_DELAY, vals_tl)) &*&
- xLIST_ITEM(result, 42, _, _, NULL);@*/
+ * xLIST(l, len - 1, _, end, cons(end, cells_tl), cons(portMAX_DELAY, vals_tl)) &*&
+ * xLIST_ITEM(result, 42, _, _, NULL);@*/
{
/*@open xLIST(l, len, idx, end, cells, vals);@*/
- ListItem_t *index = l->pxIndex;
+ ListItem_t * index = l->pxIndex;
+
/*@close xLIST(l, len, idx, end, cells, vals);@*/
/*@close exists(l);@*/
uxListRemove( index );
@@ -286,19 +293,22 @@ ListItem_t * client_example( List_t * l )
}
void client_example2( List_t * l )
+
/*@requires
- xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
- cells == cons(end, cons(?x1, cons(?x2, ?cells_tl))) &*&
- idx == x2 &*&
- vals == cons(portMAX_DELAY, cons(1, cons(2, ?vals_tl)));@*/
+ * xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
+ * cells == cons(end, cons(?x1, cons(?x2, ?cells_tl))) &*&
+ * idx == x2 &*&
+ * vals == cons(portMAX_DELAY, cons(1, cons(2, ?vals_tl)));@*/
+
/*@ensures
- xLIST(l, len-2, end, end, cons(end, cells_tl), cons(portMAX_DELAY, vals_tl)) &*&
- xLIST_ITEM(_, 1, _, _, NULL) &*&
- xLIST_ITEM(_, 2, _, _, NULL);@*/
+ * xLIST(l, len-2, end, end, cons(end, cells_tl), cons(portMAX_DELAY, vals_tl)) &*&
+ * xLIST_ITEM(_, 1, _, _, NULL) &*&
+ * xLIST_ITEM(_, 2, _, _, NULL);@*/
{
/*@xLIST_distinct_cells(l);@*/
/*@open xLIST(l, len, idx, end, cells, vals);@*/
- ListItem_t *index = l->pxIndex;
+ ListItem_t * index = l->pxIndex;
+
/*@close xLIST(l, len, idx, end, cells, vals);@*/
/*@close exists(l);@*/
uxListRemove( index );
diff --git a/FreeRTOS/Test/VeriFast/list/vListInitialise.c b/FreeRTOS/Test/VeriFast/list/vListInitialise.c
index 5400f3884..f96f6269b 100644
--- a/FreeRTOS/Test/VeriFast/list/vListInitialise.c
+++ b/FreeRTOS/Test/VeriFast/list/vListInitialise.c
@@ -27,16 +27,16 @@
#include "proof/list.h"
/*@
-predicate xLIST_uninitialised(struct xLIST *l) =
- l->uxNumberOfItems |-> _ &*&
- l->pxIndex |-> _ &*&
- l->xListEnd.xItemValue |-> _ &*&
- l->xListEnd.pxNext |-> _ &*&
- l->xListEnd.pxPrevious |-> _ &*&
- l->xListEnd.pvOwner |-> _ &*&
- l->xListEnd.pxContainer |-> _ &*&
- struct_xLIST_ITEM_padding(&l->xListEnd);
-@*/
+ * predicate xLIST_uninitialised(struct xLIST *l) =
+ * l->uxNumberOfItems |-> _ &*&
+ * l->pxIndex |-> _ &*&
+ * l->xListEnd.xItemValue |-> _ &*&
+ * l->xListEnd.pxNext |-> _ &*&
+ * l->xListEnd.pxPrevious |-> _ &*&
+ * l->xListEnd.pvOwner |-> _ &*&
+ * l->xListEnd.pxContainer |-> _ &*&
+ * struct_xLIST_ITEM_padding(&l->xListEnd);
+ * @*/
void vListInitialise( List_t * const pxList )
/*@requires xLIST_uninitialised(pxList);@*/
@@ -65,9 +65,9 @@ void vListInitialise( List_t * const pxList )
listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
-#ifdef VERIFAST /*< ***change MiniList_t to ListItem_t*** */
- pxList->xListEnd.pxContainer = pxList;
-#endif
+ #ifdef VERIFAST /*< ***change MiniList_t to ListItem_t*** */
+ pxList->xListEnd.pxContainer = pxList;
+ #endif
/*@ListItem_t *end = &(pxList->xListEnd);@*/
/*@close xLIST_ITEM(end, portMAX_DELAY, _, _, pxList);@*/
/*@close DLS(end, end, end, end, singleton(end), singleton(portMAX_DELAY), pxList);@*/
diff --git a/FreeRTOS/Test/VeriFast/list/vListInsert.c b/FreeRTOS/Test/VeriFast/list/vListInsert.c
index 71edfea61..c4010240d 100644
--- a/FreeRTOS/Test/VeriFast/list/vListInsert.c
+++ b/FreeRTOS/Test/VeriFast/list/vListInsert.c
@@ -27,18 +27,21 @@
#include "proof/list.h"
-ListItem_t * choose(List_t * list);
+ListItem_t * choose( List_t * list );
/*@ requires DLS(&(list->xListEnd), ?endprev, &(list->xListEnd), endprev, ?cells, ?vals, ?container);@*/
+
/*@ ensures DLS(&(list->xListEnd), endprev, &(list->xListEnd), endprev, cells, vals, container) &*&
- mem(result, cells) == true;@*/
+ * mem(result, cells) == true;@*/
void vListInsert( List_t * const pxList,
ListItem_t * const pxNewListItem )
+
/*@requires xLIST(pxList, ?len, ?idx, ?end, ?cells, ?vals) &*&
- xLIST_ITEM(pxNewListItem, ?val, _, _, _);@*/
+ * xLIST_ITEM(pxNewListItem, ?val, _, _, _);@*/
+
/*@ensures xLIST(pxList, len+1, idx, end, ?new_cells, ?new_vals) &*&
- remove(pxNewListItem, new_cells) == cells
-;@*/
+ * remove(pxNewListItem, new_cells) == cells
+ * ;@*/
{
/*@xLIST_star_item(pxList, pxNewListItem);@*/
/*@open xLIST_ITEM(pxNewListItem, _, _, _, _);@*/
@@ -65,23 +68,24 @@ void vListInsert( List_t * const pxList,
{
/*@open DLS(end, endprev, end, endprev, cells, vals, pxList);@*/
/*@open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, pxList);@*/
+
/*@
- if (end != endprev)
- {
- assert DLS(endnext, end, end, endprev, tail(cells), tail(vals), pxList);
- if (endnext == endprev)
- {
- // done
- }
- else
- {
- dls_last_mem(endnext, end, end, endprev, tail(cells));
- split(endnext, end, end, endprev, tail(cells), tail(vals), endprev, index_of(endprev, tail(cells)));
- }
- open DLS(endprev, _, _, _, _, _, _);
- open xLIST_ITEM(endprev, _, _, _, _);
- }
- @*/
+ * if (end != endprev)
+ * {
+ * assert DLS(endnext, end, end, endprev, tail(cells), tail(vals), pxList);
+ * if (endnext == endprev)
+ * {
+ * // done
+ * }
+ * else
+ * {
+ * dls_last_mem(endnext, end, end, endprev, tail(cells));
+ * split(endnext, end, end, endprev, tail(cells), tail(vals), endprev, index_of(endprev, tail(cells)));
+ * }
+ * open DLS(endprev, _, _, _, _, _, _);
+ * open xLIST_ITEM(endprev, _, _, _, _);
+ * }
+ * @*/
pxIterator = pxList->xListEnd.pxPrevious;
}
else
@@ -108,52 +112,53 @@ void vListInsert( List_t * const pxList,
* before vTaskStartScheduler() has been called?).
**********************************************************************/
-#ifdef VERIFAST /*< ***over-approximate list insert loop*** */
- pxIterator = choose(pxList);
-#else
- for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
- {
- /* There is nothing to do here, just iterating to the wanted
- * insertion position. */
- }
-#endif
- /*@int i = index_of(pxIterator, cells);@*/
- /*@
- if (pxIterator == end)
- {
- open DLS(end, endprev, end, endprev, cells, vals, pxList);
- open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, pxList);
- if (end != endprev)
+ #ifdef VERIFAST /*< ***over-approximate list insert loop*** */
+ pxIterator = choose( pxList );
+ #else
+ for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
{
- assert DLS(endnext, end, end, endprev, tail(cells), tail(vals), pxList);
- open DLS(endnext, _, _, _, _, _, _);
- open xLIST_ITEM(endnext, _, _, _, _);
+ /* There is nothing to do here, just iterating to the wanted
+ * insertion position. */
}
- }
- else
- {
- assert DLS(end, endprev, end, endprev, cells, vals, pxList);
- dls_first_mem(end, endprev, end, endprev, cells);
- assert pxIterator != end;
- assert index_of(end, cells) == 0;
- split(end, endprev, end, endprev, cells, vals, pxIterator, i);
- assert DLS(end, endprev, pxIterator, ?iterprev, take(i, cells), take(i, vals), pxList);
- assert DLS(pxIterator, iterprev, end, endprev, drop(i, cells), drop(i, vals), pxList);
- open DLS(pxIterator, iterprev, end, endprev, drop(i, cells), drop(i, vals), pxList);
- open xLIST_ITEM(pxIterator, _, ?iternext, iterprev, pxList);
- if (pxIterator == endprev)
- {
- open DLS(end, endprev, pxIterator, iterprev, take(i, cells), take(i, vals), pxList);
- take_take(1, i, vals);
- assert xLIST_ITEM(end, portMAX_DELAY, _, _, _);
- open xLIST_ITEM(iternext, _, _, pxIterator, _);
- }
- else
- {
- open DLS(iternext, pxIterator, end, endprev, _, _, _);
- open xLIST_ITEM(iternext, _, _, pxIterator, _);
- }
- }@*/
+ #endif
+ /*@int i = index_of(pxIterator, cells);@*/
+
+ /*@
+ * if (pxIterator == end)
+ * {
+ * open DLS(end, endprev, end, endprev, cells, vals, pxList);
+ * open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, pxList);
+ * if (end != endprev)
+ * {
+ * assert DLS(endnext, end, end, endprev, tail(cells), tail(vals), pxList);
+ * open DLS(endnext, _, _, _, _, _, _);
+ * open xLIST_ITEM(endnext, _, _, _, _);
+ * }
+ * }
+ * else
+ * {
+ * assert DLS(end, endprev, end, endprev, cells, vals, pxList);
+ * dls_first_mem(end, endprev, end, endprev, cells);
+ * assert pxIterator != end;
+ * assert index_of(end, cells) == 0;
+ * split(end, endprev, end, endprev, cells, vals, pxIterator, i);
+ * assert DLS(end, endprev, pxIterator, ?iterprev, take(i, cells), take(i, vals), pxList);
+ * assert DLS(pxIterator, iterprev, end, endprev, drop(i, cells), drop(i, vals), pxList);
+ * open DLS(pxIterator, iterprev, end, endprev, drop(i, cells), drop(i, vals), pxList);
+ * open xLIST_ITEM(pxIterator, _, ?iternext, iterprev, pxList);
+ * if (pxIterator == endprev)
+ * {
+ * open DLS(end, endprev, pxIterator, iterprev, take(i, cells), take(i, vals), pxList);
+ * take_take(1, i, vals);
+ * assert xLIST_ITEM(end, portMAX_DELAY, _, _, _);
+ * open xLIST_ITEM(iternext, _, _, pxIterator, _);
+ * }
+ * else
+ * {
+ * open DLS(iternext, pxIterator, end, endprev, _, _, _);
+ * open xLIST_ITEM(iternext, _, _, pxIterator, _);
+ * }
+ * }@*/
}
pxNewListItem->pxNext = pxIterator->pxNext;
@@ -169,152 +174,153 @@ void vListInsert( List_t * const pxList,
/*@close xLIST_ITEM(pxNewListItem, val, ?iternext, pxIterator, pxList);@*/
/*@close xLIST_ITEM(pxIterator, ?iterval, pxNewListItem, ?iterprev, pxList);@*/
- /*@
- if( xValueOfInsertion == portMAX_DELAY )
- {
- assert iternext == end;
- assert pxIterator == endprev;
- if (end == endprev)
- {
- close DLS(end, pxNewListItem, pxNewListItem, end, cells, vals, pxList);
- close DLS(pxNewListItem, end, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
- join(end, pxNewListItem, pxNewListItem, end, cells, vals,
- pxNewListItem, end, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
- close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
- }
- else
- {
- close xLIST_ITEM(end, portMAX_DELAY, ?endnext, pxNewListItem, pxList);
- close DLS(pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
- if (endnext == endprev)
- {
- assert xLIST_ITEM(endnext, ?endnextval, pxNewListItem, end, pxList);
- close DLS(end, pxNewListItem, endnext, end, singleton(end), singleton(portMAX_DELAY), pxList);
- close DLS(endnext, end, pxNewListItem, endnext, singleton(endnext), singleton(endnextval), pxList);
- join(end, pxNewListItem, endnext, end, singleton(end), singleton(portMAX_DELAY),
- endnext, end, pxNewListItem, endnext, singleton(endnext), singleton(endnextval));
- assert DLS(end, pxNewListItem, pxNewListItem, endnext, cells, vals, pxList);
- }
- else
- {
- assert DLS(endnext, end, endprev, ?endprevprev, ?cells_endnext_to_endprevprev, ?vals_endnext_to_endprevprev, pxList);
- assert cells_endnext_to_endprevprev == take(index_of(endprev, tail(cells)), tail(cells));
- assert index_of(endprev, tail(cells)) == length(tail(cells)) - 1;
- assert cells_endnext_to_endprevprev == take(length(tail(cells)) - 1, tail(cells));
- assert xLIST_ITEM(endprev, ?endprevval, pxNewListItem, endprevprev, pxList);
- close DLS(endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval), pxList);
- dls_last_mem(endnext, end, endprev, endprevprev, cells_endnext_to_endprevprev);
- dls_star_item(endnext, endprevprev, end);
- close DLS(end, pxNewListItem, endprev, endprevprev, cons(end, cells_endnext_to_endprevprev), cons(portMAX_DELAY, vals_endnext_to_endprevprev), pxList);
- join(end, pxNewListItem, endprev, endprevprev, cons(end, cells_endnext_to_endprevprev), cons(portMAX_DELAY, vals_endnext_to_endprevprev),
- endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval));
- assert DLS(end, pxNewListItem, pxNewListItem, endprev, cells, vals, pxList);
- }
- join(end, pxNewListItem, pxNewListItem, endprev, cells, vals,
- pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
- remove_append(pxNewListItem, cells, singleton(pxNewListItem));
- close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
- }
- }
- else
- {
- if (pxIterator == end)
- {
- if (iternext == end)
- {
- close DLS(end, pxNewListItem, pxNewListItem, end, cells, vals, pxList);
- close DLS(pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
- join(end, pxNewListItem, pxNewListItem, end, cells, vals,
- pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
- close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
- }
- else
- {
- close xLIST_ITEM(iternext, ?iternextval, _, pxNewListItem, pxList);
- if (iternext == endprev)
- {
- close DLS(iternext, pxNewListItem, end, endprev, singleton(iternext), singleton(iternextval), pxList);
- dls_last_mem(iternext, pxNewListItem, end, endprev, singleton(iternext));
- }
- else
- {
- assert DLS(?iternextnext, iternext, end, endprev, ?cells_iternextnext_to_endprev, ?vals_iternextnext_to_endprev, pxList);
- close DLS(iternext, pxNewListItem, end, endprev, cons(iternext, cells_iternextnext_to_endprev), cons(iternextval, vals_iternextnext_to_endprev), pxList);
- dls_last_mem(iternext, pxNewListItem, end, endprev, cons(iternext, cells_iternextnext_to_endprev));
- }
- close DLS(end, endprev, pxNewListItem, end, singleton(end), singleton(portMAX_DELAY), pxList);
- assert DLS(iternext, pxNewListItem, end, endprev, ?cells_iternext_to_endprev, ?vals_iternext_to_endprev, pxList);
- dls_star_item(iternext, endprev, pxNewListItem);
- close DLS(pxNewListItem, pxIterator, end, endprev, cons(pxNewListItem, cells_iternext_to_endprev), cons(val, vals_iternext_to_endprev), pxList);
- join(end, endprev, pxNewListItem, end, singleton(end), singleton(portMAX_DELAY),
- pxNewListItem, pxIterator, end, endprev, cons(pxNewListItem, cells_iternext_to_endprev), cons(val, vals_iternext_to_endprev));
- close xLIST(pxList, len+1, idx, end, cons(end, cons(pxNewListItem, cells_iternext_to_endprev)), cons(portMAX_DELAY, cons(val, vals_iternext_to_endprev)));
- }
- }
- else
- {
- close xLIST_ITEM(iternext, ?iternextval, _, pxNewListItem, pxList);
- if (pxIterator == endprev)
- {
- if (iterprev == end)
- {
- close DLS(end, pxNewListItem, pxIterator, end, singleton(end), singleton(portMAX_DELAY), pxList);
- }
- else
- {
- assert DLS(_, iternext, pxIterator, iterprev, ?cells1, ?vals1, _);
- close DLS(end, pxNewListItem, pxIterator, iterprev, cons(end, cells1), cons(portMAX_DELAY, vals1), pxList);
- }
- int i = index_of(pxIterator, cells);
- assert DLS(end, pxNewListItem, pxIterator, iterprev, take(i, cells), take(i, vals), pxList);
- close DLS(pxIterator, iterprev, pxNewListItem, pxIterator, drop(i, cells), drop(i, vals), pxList);
- close DLS(pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
- join(end, pxNewListItem, pxIterator, iterprev, take(i, cells), take(i, vals),
- pxIterator, iterprev, pxNewListItem, pxIterator, drop(i, cells), drop(i, vals));
- join(end, pxNewListItem, pxNewListItem, pxIterator, cells, vals,
- pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
- close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
- remove_append(pxNewListItem, cells, singleton(pxNewListItem));
- }
- else
- {
- int i = index_of(pxIterator, cells);
- if (iternext == endprev)
- {
- close DLS(iternext, pxNewListItem, end, endprev, singleton(iternext), singleton(iternextval), pxList);
- }
- else
- {
- assert DLS(_, iternext, end, endprev, ?cells0, ?vals0, pxList);
- dls_star_item(end, iterprev, iternext);
- close DLS(iternext, pxNewListItem, end, endprev, tail(drop(i, cells)), tail(drop(i, vals)), pxList);
- }
- drop_drop(1, i, cells);
- drop_drop(1, i, vals);
- assert DLS(iternext, pxNewListItem, end, endprev, drop(i+1, cells), drop(i+1, vals), pxList);
- assert DLS(end, endprev, pxIterator, iterprev, take(i, cells), take(i, vals), pxList);
- dls_star_item(iternext, endprev, pxNewListItem);
- dls_last_mem(iternext, pxNewListItem, end, endprev, drop(i+1, cells));
- close DLS(pxNewListItem, pxIterator, end, endprev, cons(pxNewListItem, drop(i+1, cells)), cons(val, drop(i+1, vals)), pxList);
- close DLS(pxIterator, iterprev, end, endprev, cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))), cons(iterval, cons(val, drop(i+1, vals))), pxList);
- join(end, endprev, pxIterator, iterprev, take(i, cells), take(i, vals),
- pxIterator, iterprev, end, endprev, cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))), cons(iterval, cons(val, drop(i+1, vals))));
- list<struct xLIST_ITEM * >new_cells = append(take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))));
- list<TickType_t >new_vals = append(take(i, vals), cons(iterval, cons(val, drop(i+1, vals))));
- head_append(take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))));
- take_head(take(i, cells));
- take_take(1, i, cells);
- assert( end == head(new_cells) );
- head_append(take(i, vals), cons(iterval, cons(val, drop(i+1, vals))));
- take_head(take(i, vals));
- take_take(1, i, vals);
- assert( portMAX_DELAY == head(new_vals) );
- append_take_drop_n(cells, index_of(pxIterator, cells));
- close xLIST(pxList, len+1, idx, end, append(take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells)))), append(take(i, vals), cons(iterval, cons(val, drop(i+1, vals)))));
- mem_take_false(pxNewListItem, i, cells);
- remove_append(pxNewListItem, take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))));
- }
- }
- }@*/
+ /*@
+ * if( xValueOfInsertion == portMAX_DELAY )
+ * {
+ * assert iternext == end;
+ * assert pxIterator == endprev;
+ * if (end == endprev)
+ * {
+ * close DLS(end, pxNewListItem, pxNewListItem, end, cells, vals, pxList);
+ * close DLS(pxNewListItem, end, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
+ * join(end, pxNewListItem, pxNewListItem, end, cells, vals,
+ * pxNewListItem, end, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
+ * close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
+ * }
+ * else
+ * {
+ * close xLIST_ITEM(end, portMAX_DELAY, ?endnext, pxNewListItem, pxList);
+ * close DLS(pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
+ * if (endnext == endprev)
+ * {
+ * assert xLIST_ITEM(endnext, ?endnextval, pxNewListItem, end, pxList);
+ * close DLS(end, pxNewListItem, endnext, end, singleton(end), singleton(portMAX_DELAY), pxList);
+ * close DLS(endnext, end, pxNewListItem, endnext, singleton(endnext), singleton(endnextval), pxList);
+ * join(end, pxNewListItem, endnext, end, singleton(end), singleton(portMAX_DELAY),
+ * endnext, end, pxNewListItem, endnext, singleton(endnext), singleton(endnextval));
+ * assert DLS(end, pxNewListItem, pxNewListItem, endnext, cells, vals, pxList);
+ * }
+ * else
+ * {
+ * assert DLS(endnext, end, endprev, ?endprevprev, ?cells_endnext_to_endprevprev, ?vals_endnext_to_endprevprev, pxList);
+ * assert cells_endnext_to_endprevprev == take(index_of(endprev, tail(cells)), tail(cells));
+ * assert index_of(endprev, tail(cells)) == length(tail(cells)) - 1;
+ * assert cells_endnext_to_endprevprev == take(length(tail(cells)) - 1, tail(cells));
+ * assert xLIST_ITEM(endprev, ?endprevval, pxNewListItem, endprevprev, pxList);
+ * close DLS(endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval), pxList);
+ * dls_last_mem(endnext, end, endprev, endprevprev, cells_endnext_to_endprevprev);
+ * dls_star_item(endnext, endprevprev, end);
+ * close DLS(end, pxNewListItem, endprev, endprevprev, cons(end, cells_endnext_to_endprevprev), cons(portMAX_DELAY, vals_endnext_to_endprevprev), pxList);
+ * join(end, pxNewListItem, endprev, endprevprev, cons(end, cells_endnext_to_endprevprev), cons(portMAX_DELAY, vals_endnext_to_endprevprev),
+ * endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval));
+ * assert DLS(end, pxNewListItem, pxNewListItem, endprev, cells, vals, pxList);
+ *
+ * }
+ * join(end, pxNewListItem, pxNewListItem, endprev, cells, vals,
+ * pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
+ * remove_append(pxNewListItem, cells, singleton(pxNewListItem));
+ * close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
+ * }
+ * }
+ * else
+ * {
+ * if (pxIterator == end)
+ * {
+ * if (iternext == end)
+ * {
+ * close DLS(end, pxNewListItem, pxNewListItem, end, cells, vals, pxList);
+ * close DLS(pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
+ * join(end, pxNewListItem, pxNewListItem, end, cells, vals,
+ * pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
+ * close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
+ * }
+ * else
+ * {
+ * close xLIST_ITEM(iternext, ?iternextval, _, pxNewListItem, pxList);
+ * if (iternext == endprev)
+ * {
+ * close DLS(iternext, pxNewListItem, end, endprev, singleton(iternext), singleton(iternextval), pxList);
+ * dls_last_mem(iternext, pxNewListItem, end, endprev, singleton(iternext));
+ * }
+ * else
+ * {
+ * assert DLS(?iternextnext, iternext, end, endprev, ?cells_iternextnext_to_endprev, ?vals_iternextnext_to_endprev, pxList);
+ * close DLS(iternext, pxNewListItem, end, endprev, cons(iternext, cells_iternextnext_to_endprev), cons(iternextval, vals_iternextnext_to_endprev), pxList);
+ * dls_last_mem(iternext, pxNewListItem, end, endprev, cons(iternext, cells_iternextnext_to_endprev));
+ * }
+ * close DLS(end, endprev, pxNewListItem, end, singleton(end), singleton(portMAX_DELAY), pxList);
+ * assert DLS(iternext, pxNewListItem, end, endprev, ?cells_iternext_to_endprev, ?vals_iternext_to_endprev, pxList);
+ * dls_star_item(iternext, endprev, pxNewListItem);
+ * close DLS(pxNewListItem, pxIterator, end, endprev, cons(pxNewListItem, cells_iternext_to_endprev), cons(val, vals_iternext_to_endprev), pxList);
+ * join(end, endprev, pxNewListItem, end, singleton(end), singleton(portMAX_DELAY),
+ * pxNewListItem, pxIterator, end, endprev, cons(pxNewListItem, cells_iternext_to_endprev), cons(val, vals_iternext_to_endprev));
+ * close xLIST(pxList, len+1, idx, end, cons(end, cons(pxNewListItem, cells_iternext_to_endprev)), cons(portMAX_DELAY, cons(val, vals_iternext_to_endprev)));
+ * }
+ * }
+ * else
+ * {
+ * close xLIST_ITEM(iternext, ?iternextval, _, pxNewListItem, pxList);
+ * if (pxIterator == endprev)
+ * {
+ * if (iterprev == end)
+ * {
+ * close DLS(end, pxNewListItem, pxIterator, end, singleton(end), singleton(portMAX_DELAY), pxList);
+ * }
+ * else
+ * {
+ * assert DLS(_, iternext, pxIterator, iterprev, ?cells1, ?vals1, _);
+ * close DLS(end, pxNewListItem, pxIterator, iterprev, cons(end, cells1), cons(portMAX_DELAY, vals1), pxList);
+ * }
+ * int i = index_of(pxIterator, cells);
+ * assert DLS(end, pxNewListItem, pxIterator, iterprev, take(i, cells), take(i, vals), pxList);
+ * close DLS(pxIterator, iterprev, pxNewListItem, pxIterator, drop(i, cells), drop(i, vals), pxList);
+ * close DLS(pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
+ * join(end, pxNewListItem, pxIterator, iterprev, take(i, cells), take(i, vals),
+ * pxIterator, iterprev, pxNewListItem, pxIterator, drop(i, cells), drop(i, vals));
+ * join(end, pxNewListItem, pxNewListItem, pxIterator, cells, vals,
+ * pxNewListItem, pxIterator, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
+ * close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
+ * remove_append(pxNewListItem, cells, singleton(pxNewListItem));
+ * }
+ * else
+ * {
+ * int i = index_of(pxIterator, cells);
+ * if (iternext == endprev)
+ * {
+ * close DLS(iternext, pxNewListItem, end, endprev, singleton(iternext), singleton(iternextval), pxList);
+ * }
+ * else
+ * {
+ * assert DLS(_, iternext, end, endprev, ?cells0, ?vals0, pxList);
+ * dls_star_item(end, iterprev, iternext);
+ * close DLS(iternext, pxNewListItem, end, endprev, tail(drop(i, cells)), tail(drop(i, vals)), pxList);
+ * }
+ * drop_drop(1, i, cells);
+ * drop_drop(1, i, vals);
+ * assert DLS(iternext, pxNewListItem, end, endprev, drop(i+1, cells), drop(i+1, vals), pxList);
+ * assert DLS(end, endprev, pxIterator, iterprev, take(i, cells), take(i, vals), pxList);
+ * dls_star_item(iternext, endprev, pxNewListItem);
+ * dls_last_mem(iternext, pxNewListItem, end, endprev, drop(i+1, cells));
+ * close DLS(pxNewListItem, pxIterator, end, endprev, cons(pxNewListItem, drop(i+1, cells)), cons(val, drop(i+1, vals)), pxList);
+ * close DLS(pxIterator, iterprev, end, endprev, cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))), cons(iterval, cons(val, drop(i+1, vals))), pxList);
+ * join(end, endprev, pxIterator, iterprev, take(i, cells), take(i, vals),
+ * pxIterator, iterprev, end, endprev, cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))), cons(iterval, cons(val, drop(i+1, vals))));
+ * list<struct xLIST_ITEM * >new_cells = append(take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))));
+ * list<TickType_t >new_vals = append(take(i, vals), cons(iterval, cons(val, drop(i+1, vals))));
+ * head_append(take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))));
+ * take_head(take(i, cells));
+ * take_take(1, i, cells);
+ * assert( end == head(new_cells) );
+ * head_append(take(i, vals), cons(iterval, cons(val, drop(i+1, vals))));
+ * take_head(take(i, vals));
+ * take_take(1, i, vals);
+ * assert( portMAX_DELAY == head(new_vals) );
+ * append_take_drop_n(cells, index_of(pxIterator, cells));
+ * close xLIST(pxList, len+1, idx, end, append(take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells)))), append(take(i, vals), cons(iterval, cons(val, drop(i+1, vals)))));
+ * mem_take_false(pxNewListItem, i, cells);
+ * remove_append(pxNewListItem, take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))));
+ * }
+ * }
+ * }@*/
}
diff --git a/FreeRTOS/Test/VeriFast/list/vListInsertEnd.c b/FreeRTOS/Test/VeriFast/list/vListInsertEnd.c
index c8e99b648..f07cdc84a 100644
--- a/FreeRTOS/Test/VeriFast/list/vListInsertEnd.c
+++ b/FreeRTOS/Test/VeriFast/list/vListInsertEnd.c
@@ -28,90 +28,93 @@
void vListInsertEnd( List_t * const pxList,
ListItem_t * const pxNewListItem )
+
/*@requires xLIST(pxList, ?len, ?idx, ?end, ?cells, ?vals) &*&
- xLIST_ITEM(pxNewListItem, ?val, _, _, _);@*/
+ * xLIST_ITEM(pxNewListItem, ?val, _, _, _);@*/
+
/*@ensures xLIST(pxList, len+1, idx, end, ?new_cells, ?new_vals) &*&
- idx == end
- ? (new_cells == append(cells, singleton(pxNewListItem)) &*&
- new_vals == append(vals, singleton(val)))
- : (new_cells == append(take(index_of(idx, cells), cells), append(singleton(pxNewListItem), drop(index_of(idx, cells), cells))) &*&
- new_vals == append(take(index_of(idx, cells), vals), append(singleton(val), drop(index_of(idx, cells), vals))));@*/
+ * idx == end
+ * ? (new_cells == append(cells, singleton(pxNewListItem)) &*&
+ * new_vals == append(vals, singleton(val)))
+ * : (new_cells == append(take(index_of(idx, cells), cells), append(singleton(pxNewListItem), drop(index_of(idx, cells), cells))) &*&
+ * new_vals == append(take(index_of(idx, cells), vals), append(singleton(val), drop(index_of(idx, cells), vals))));@*/
{
/*@xLIST_star_item(pxList, pxNewListItem);@*/
/*@assert mem(pxNewListItem, cells) == false;@*/
/*@open xLIST(pxList, len, idx, end, cells, vals);@*/
-#ifdef VERIFAST /*< const pointer declaration */
- ListItem_t * pxIndex = pxList->pxIndex;
-#else
- ListItem_t * const pxIndex = pxList->pxIndex;
-
- /* Only effective when configASSERT() is also defined, these tests may catch
- * the list data structures being overwritten in memory. They will not catch
- * data errors caused by incorrect configuration or use of FreeRTOS. */
- listTEST_LIST_INTEGRITY( pxList );
- listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ ListItem_t * pxIndex = pxList->pxIndex;
+ #else
+ ListItem_t * const pxIndex = pxList->pxIndex;
+
+ /* Only effective when configASSERT() is also defined, these tests may catch
+ * the list data structures being overwritten in memory. They will not catch
+ * data errors caused by incorrect configuration or use of FreeRTOS. */
+ listTEST_LIST_INTEGRITY( pxList );
+ listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
+ #endif
/*@open xLIST_ITEM(pxNewListItem, _, _, _, _);@*/
/*@assert DLS(end, ?endprev, end, _, cells, vals, pxList);@*/
/*@dls_first_mem(end, endprev, end, endprev, cells);@*/
/*@dls_last_mem(end, endprev, end, endprev, cells);@*/
+
/*@
- if (end == idx)
- {
- open DLS(end, endprev, end, endprev, cells, vals, pxList);
- open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, pxList);
- if (end == endprev)
- {
- // Case A (singleton): idx==end==endprev
- }
- else
- {
- assert DLS(endnext, end, end, endprev, tail(cells), tail(vals), pxList);
- if (endnext == endprev)
- {
- // Case B (two): idx==end and endnext==endprev
- open DLS(endnext, end, end, endnext, _, _, _);
- open xLIST_ITEM(endnext, _, _, _, _);
- }
- else
- {
- // Case C: idx==end and DLS:endnext...endprev
- split(endnext, end, end, endprev, tail(cells), tail(vals), endprev, index_of(endprev, tail(cells)));
- open DLS(endprev, _, _, _, _, _, _);
- open xLIST_ITEM(endprev, _, _, _, _);
- }
- }
- }
- else
- {
- int i = index_of(idx, cells);
- split(end, endprev, end, endprev, cells, vals, idx, i);
- assert DLS(end, endprev, idx, ?idxprev, take(i, cells), take(i, vals), pxList);
- assert DLS(idx, idxprev, end, endprev, drop(i, cells), drop(i, vals), pxList);
- open DLS(idx, idxprev, end, endprev, _, _, _);
- open xLIST_ITEM(idx, _, _, _, _);
- if (end == idxprev)
- {
- // Case D: end==idxprev and DLS:idx...endprev
- take_take(1, i, vals);
- take_head(vals);
- open DLS(end, endprev, idx, idxprev, take(i, cells), take(i, vals), pxList);
- open xLIST_ITEM(end, portMAX_DELAY, _, _, _);
- assert length(take(i, cells)) == 1;
- }
- else
- {
- // Case E: DLS:end...idxprev and DLS:idx...endprev
- dls_last_mem(end, endprev, idx, idxprev, take(i, cells));
- split(end, endprev, idx, idxprev, take(i, cells), take(i, vals), idxprev, index_of(idxprev, take(i, cells)));
- open DLS(idxprev, _, _, idxprev, _, _, _);
- length_take(i, cells);
- drop_take_singleton(i, vals);
- open xLIST_ITEM(idxprev, nth(i-1, vals), _, _, _);
- }
- }
- @*/
+ * if (end == idx)
+ * {
+ * open DLS(end, endprev, end, endprev, cells, vals, pxList);
+ * open xLIST_ITEM(end, portMAX_DELAY, ?endnext, endprev, pxList);
+ * if (end == endprev)
+ * {
+ * // Case A (singleton): idx==end==endprev
+ * }
+ * else
+ * {
+ * assert DLS(endnext, end, end, endprev, tail(cells), tail(vals), pxList);
+ * if (endnext == endprev)
+ * {
+ * // Case B (two): idx==end and endnext==endprev
+ * open DLS(endnext, end, end, endnext, _, _, _);
+ * open xLIST_ITEM(endnext, _, _, _, _);
+ * }
+ * else
+ * {
+ * // Case C: idx==end and DLS:endnext...endprev
+ * split(endnext, end, end, endprev, tail(cells), tail(vals), endprev, index_of(endprev, tail(cells)));
+ * open DLS(endprev, _, _, _, _, _, _);
+ * open xLIST_ITEM(endprev, _, _, _, _);
+ * }
+ * }
+ * }
+ * else
+ * {
+ * int i = index_of(idx, cells);
+ * split(end, endprev, end, endprev, cells, vals, idx, i);
+ * assert DLS(end, endprev, idx, ?idxprev, take(i, cells), take(i, vals), pxList);
+ * assert DLS(idx, idxprev, end, endprev, drop(i, cells), drop(i, vals), pxList);
+ * open DLS(idx, idxprev, end, endprev, _, _, _);
+ * open xLIST_ITEM(idx, _, _, _, _);
+ * if (end == idxprev)
+ * {
+ * // Case D: end==idxprev and DLS:idx...endprev
+ * take_take(1, i, vals);
+ * take_head(vals);
+ * open DLS(end, endprev, idx, idxprev, take(i, cells), take(i, vals), pxList);
+ * open xLIST_ITEM(end, portMAX_DELAY, _, _, _);
+ * assert length(take(i, cells)) == 1;
+ * }
+ * else
+ * {
+ * // Case E: DLS:end...idxprev and DLS:idx...endprev
+ * dls_last_mem(end, endprev, idx, idxprev, take(i, cells));
+ * split(end, endprev, idx, idxprev, take(i, cells), take(i, vals), idxprev, index_of(idxprev, take(i, cells)));
+ * open DLS(idxprev, _, _, idxprev, _, _, _);
+ * length_take(i, cells);
+ * drop_take_singleton(i, vals);
+ * open xLIST_ITEM(idxprev, nth(i-1, vals), _, _, _);
+ * }
+ * }
+ * @*/
/* Insert a new list item into pxList, but rather than sort the list,
* makes the new list item the last item to be removed by a call to
@@ -131,108 +134,111 @@ void vListInsertEnd( List_t * const pxList,
( pxList->uxNumberOfItems )++;
/*@
- if (end == idx)
- {
- close xLIST_ITEM(pxNewListItem, val, end, endprev, pxList);
- close DLS(pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
- close xLIST_ITEM(end, portMAX_DELAY, ?endnext, pxNewListItem, pxList);
- if (end == endprev)
- {
- // Case A (singleton): idx==end==endprev
- close DLS(end, pxNewListItem, endnext, end, cells, vals, pxList);
- join(end, pxNewListItem, endnext, end, cells, vals,
- pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
- close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
- }
- else
- {
- close xLIST_ITEM(endprev, ?endprevval, pxNewListItem, ?endprevprev, _);
- if (endnext == endprev)
- {
- // Case B (two): idx==end and endnext==endprev
- close DLS(endprev, end, pxNewListItem, endprev, singleton(endprev), singleton(endprevval), pxList);
- close DLS(end, pxNewListItem, pxNewListItem, endprev, cells, vals, pxList);
- join(end, pxNewListItem, pxNewListItem, endprev, cells, vals,
- pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
- close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
- }
- else
- {
- // Case C: idx==end and DLS:endnext...endprev
- close DLS(endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval), pxList);
- assert DLS(endnext, end, endprev, endprevprev, ?cells_endnext_to_endprevprev, ?vals_endnext_to_endprevprev, pxList);
- join(endnext, end, endprev, endprevprev, cells_endnext_to_endprevprev, vals_endnext_to_endprevprev,
- endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval));
- close DLS(end, pxNewListItem, pxNewListItem, endprev, cells, vals, pxList);
- join(end, pxNewListItem, pxNewListItem, endprev, cells, vals,
- pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
- close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
- }
- }
- }
- else
- {
- // Case D: end==idxprev and DLS:idx...endprev
- // Case E: DLS:end...idxprev and DLS:idx...endprev
- int i = index_of(idx, cells);
- close xLIST_ITEM(pxNewListItem, val, idx, ?idxprev, pxList);
- close xLIST_ITEM(idx, ?idxval, ?idxnext, pxNewListItem, pxList);
- nth_drop2(vals, i);
- assert idxval == nth(i, vals);
- close xLIST_ITEM(idxprev, ?idxprevval, pxNewListItem, ?idxprevprev, pxList);
-
- if (end == idxprev)
- {
- close DLS(end, endprev, pxNewListItem, end, singleton(end), singleton(portMAX_DELAY), pxList);
- }
- else
- {
- length_take(i, cells);
- take_take(i-1, i, vals);
- take_singleton(i-1, vals);
- take_singleton(i, vals);
- assert DLS(end, endprev, idxprev, idxprevprev, ?cells_end_to_idxprevprev, take(i-1, vals), pxList);
- close DLS(idxprev, idxprevprev, pxNewListItem, idxprev, singleton(idxprev), singleton(idxprevval), pxList);
- join(end, endprev, idxprev, idxprevprev, cells_end_to_idxprevprev, take(i-1, vals),
- idxprev, idxprevprev, pxNewListItem, idxprev, singleton(idxprev), singleton(idxprevval));
- }
-
- if (idx == endprev)
- {
- close DLS(idx, pxNewListItem, end, idx, singleton(idx), singleton(idxval), pxList);
- }
- else
- {
- assert DLS(end, endprev, pxNewListItem, idxprev, ?cells_end_to_idxprev, ?vals_end_to_idxprev, pxList);
- close DLS(idx, pxNewListItem, end, endprev, drop(i, cells), drop(i, vals), pxList);
- }
-
- assert DLS(end, endprev, pxNewListItem, idxprev, take(i, cells), take(i, vals), pxList);
- assert DLS(idx, pxNewListItem, end, endprev, drop(i, cells), drop(i, vals), pxList);
- assert xLIST_ITEM(pxNewListItem, val, idx, idxprev, pxList);
- dls_star_item(idx, endprev, pxNewListItem);
- close DLS(pxNewListItem, idxprev, end, endprev, cons(pxNewListItem, drop(i, cells)), cons(val, drop(i, vals)), pxList);
- join(end, endprev, pxNewListItem, idxprev, take(i, cells), take(i, vals),
- pxNewListItem, idxprev, end, endprev, cons(pxNewListItem, drop(i, cells)), cons(val, drop(i, vals)));
- assert DLS(end, endprev, end, endprev, ?cells_new, ?vals_new, pxList);
- assert cells_new == append(take(i, cells), append(singleton(pxNewListItem), drop(i, cells)));
- assert vals_new == append(take(i, vals) , append(singleton(val), drop(i, vals)));
- head_append(take(i, cells), append(singleton(pxNewListItem), drop(i, cells)));
- take_take(1, i, cells);
- head_append(take(i, vals), append(singleton(val), drop(i, vals)));
- take_take(1, i, vals);
- close xLIST(pxList, len+1, idx, end, cells_new, vals_new);
- }
- @*/
+ * if (end == idx)
+ * {
+ * close xLIST_ITEM(pxNewListItem, val, end, endprev, pxList);
+ * close DLS(pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val), pxList);
+ * close xLIST_ITEM(end, portMAX_DELAY, ?endnext, pxNewListItem, pxList);
+ * if (end == endprev)
+ * {
+ * // Case A (singleton): idx==end==endprev
+ * close DLS(end, pxNewListItem, endnext, end, cells, vals, pxList);
+ * join(end, pxNewListItem, endnext, end, cells, vals,
+ * pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
+ * close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
+ * }
+ * else
+ * {
+ * close xLIST_ITEM(endprev, ?endprevval, pxNewListItem, ?endprevprev, _);
+ * if (endnext == endprev)
+ * {
+ * // Case B (two): idx==end and endnext==endprev
+ * close DLS(endprev, end, pxNewListItem, endprev, singleton(endprev), singleton(endprevval), pxList);
+ * close DLS(end, pxNewListItem, pxNewListItem, endprev, cells, vals, pxList);
+ * join(end, pxNewListItem, pxNewListItem, endprev, cells, vals,
+ * pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
+ * close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
+ * }
+ * else
+ * {
+ * // Case C: idx==end and DLS:endnext...endprev
+ * close DLS(endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval), pxList);
+ * assert DLS(endnext, end, endprev, endprevprev, ?cells_endnext_to_endprevprev, ?vals_endnext_to_endprevprev, pxList);
+ * join(endnext, end, endprev, endprevprev, cells_endnext_to_endprevprev, vals_endnext_to_endprevprev,
+ * endprev, endprevprev, pxNewListItem, endprev, singleton(endprev), singleton(endprevval));
+ * close DLS(end, pxNewListItem, pxNewListItem, endprev, cells, vals, pxList);
+ * join(end, pxNewListItem, pxNewListItem, endprev, cells, vals,
+ * pxNewListItem, endprev, end, pxNewListItem, singleton(pxNewListItem), singleton(val));
+ * close xLIST(pxList, len+1, idx, end, append(cells, singleton(pxNewListItem)), append(vals, singleton(val)));
+ * }
+ * }
+ * }
+ * else
+ * {
+ * // Case D: end==idxprev and DLS:idx...endprev
+ * // Case E: DLS:end...idxprev and DLS:idx...endprev
+ * int i = index_of(idx, cells);
+ * close xLIST_ITEM(pxNewListItem, val, idx, ?idxprev, pxList);
+ * close xLIST_ITEM(idx, ?idxval, ?idxnext, pxNewListItem, pxList);
+ * nth_drop2(vals, i);
+ * assert idxval == nth(i, vals);
+ * close xLIST_ITEM(idxprev, ?idxprevval, pxNewListItem, ?idxprevprev, pxList);
+ *
+ * if (end == idxprev)
+ * {
+ * close DLS(end, endprev, pxNewListItem, end, singleton(end), singleton(portMAX_DELAY), pxList);
+ * }
+ * else
+ * {
+ * length_take(i, cells);
+ * take_take(i-1, i, vals);
+ * take_singleton(i-1, vals);
+ * take_singleton(i, vals);
+ * assert DLS(end, endprev, idxprev, idxprevprev, ?cells_end_to_idxprevprev, take(i-1, vals), pxList);
+ * close DLS(idxprev, idxprevprev, pxNewListItem, idxprev, singleton(idxprev), singleton(idxprevval), pxList);
+ * join(end, endprev, idxprev, idxprevprev, cells_end_to_idxprevprev, take(i-1, vals),
+ * idxprev, idxprevprev, pxNewListItem, idxprev, singleton(idxprev), singleton(idxprevval));
+ * }
+ *
+ * if (idx == endprev)
+ * {
+ * close DLS(idx, pxNewListItem, end, idx, singleton(idx), singleton(idxval), pxList);
+ * }
+ * else
+ * {
+ * assert DLS(end, endprev, pxNewListItem, idxprev, ?cells_end_to_idxprev, ?vals_end_to_idxprev, pxList);
+ * close DLS(idx, pxNewListItem, end, endprev, drop(i, cells), drop(i, vals), pxList);
+ * }
+ *
+ * assert DLS(end, endprev, pxNewListItem, idxprev, take(i, cells), take(i, vals), pxList);
+ * assert DLS(idx, pxNewListItem, end, endprev, drop(i, cells), drop(i, vals), pxList);
+ * assert xLIST_ITEM(pxNewListItem, val, idx, idxprev, pxList);
+ * dls_star_item(idx, endprev, pxNewListItem);
+ * close DLS(pxNewListItem, idxprev, end, endprev, cons(pxNewListItem, drop(i, cells)), cons(val, drop(i, vals)), pxList);
+ * join(end, endprev, pxNewListItem, idxprev, take(i, cells), take(i, vals),
+ * pxNewListItem, idxprev, end, endprev, cons(pxNewListItem, drop(i, cells)), cons(val, drop(i, vals)));
+ * assert DLS(end, endprev, end, endprev, ?cells_new, ?vals_new, pxList);
+ * assert cells_new == append(take(i, cells), append(singleton(pxNewListItem), drop(i, cells)));
+ * assert vals_new == append(take(i, vals) , append(singleton(val), drop(i, vals)));
+ * head_append(take(i, cells), append(singleton(pxNewListItem), drop(i, cells)));
+ * take_take(1, i, cells);
+ * head_append(take(i, vals), append(singleton(val), drop(i, vals)));
+ * take_take(1, i, vals);
+ * close xLIST(pxList, len+1, idx, end, cells_new, vals_new);
+ * }
+ * @*/
}
-void client_example1( List_t * const l, ListItem_t * const pxNewListItem )
+void client_example1( List_t * const l,
+ ListItem_t * const pxNewListItem )
+
/*@requires
- xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
- xLIST_ITEM(pxNewListItem, ?val, _, _, _) &*&
- idx == end;@*/
+ * xLIST(l, ?len, ?idx, ?end, ?cells, ?vals) &*&
+ * xLIST_ITEM(pxNewListItem, ?val, _, _, _) &*&
+ * idx == end;@*/
+
/*@ensures
- xLIST(l, len + 1, idx, end, _, append(vals, singleton(val)));@*/
+ * xLIST(l, len + 1, idx, end, _, append(vals, singleton(val)));@*/
{
- vListInsertEnd(l, pxNewListItem);
+ vListInsertEnd( l, pxNewListItem );
}
diff --git a/FreeRTOS/Test/VeriFast/queue/create.c b/FreeRTOS/Test/VeriFast/queue/create.c
index 144e87839..3282676a9 100644
--- a/FreeRTOS/Test/VeriFast/queue/create.c
+++ b/FreeRTOS/Test/VeriFast/queue/create.c
@@ -37,35 +37,37 @@
/* The following intermediate queue predicates summarise states used by queue
* initialization but not used elsewhere so we confine them to these proofs
* locally. */
+
/*@
-predicate queue_init1(QueueHandle_t q;) =
- QUEUE_SHAPE(q, _, _, _, _) &*&
- queuelists(q)
- ;
-
-predicate queue_init2(QueueHandle_t q, int8_t *Storage, size_t N, size_t M;) =
- QUEUE_SHAPE(q, Storage, N, M, _) &*&
- queuelists(q) &*&
- 0 < N &*&
- chars(Storage, (N*M), _) &*&
- malloc_block(Storage, N*M) &*&
- Storage + N * M <= (int8_t *)UINTPTR_MAX &*&
- true
- ;
-@*/
+ * predicate queue_init1(QueueHandle_t q;) =
+ * QUEUE_SHAPE(q, _, _, _, _) &*&
+ * queuelists(q)
+ * ;
+ *
+ * predicate queue_init2(QueueHandle_t q, int8_t *Storage, size_t N, size_t M;) =
+ * QUEUE_SHAPE(q, Storage, N, M, _) &*&
+ * queuelists(q) &*&
+ * 0 < N &*&
+ * chars(Storage, (N*M), _) &*&
+ * malloc_block(Storage, N*M) &*&
+ * Storage + N * M <= (int8_t *)UINTPTR_MAX &*&
+ * true
+ * ;
+ * @*/
BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
BaseType_t xNewQueue )
/*@requires queue_init2(xQueue, ?Storage, ?N, ?M);@*/
+
/*@ensures 0 == M
- ? freertos_mutex(xQueue, Storage, N, 0)
- : queue(xQueue, Storage, N, M, 0, (N-1), 0, false, nil) &*& queuelists(xQueue);@*/
+ * ? freertos_mutex(xQueue, Storage, N, 0)
+ * : queue(xQueue, Storage, N, M, 0, (N-1), 0, false, nil) &*& queuelists(xQueue);@*/
{
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+ #endif
configASSERT( pxQueue );
@@ -125,18 +127,20 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
Queue_t * pxNewQueue )
/*@requires queue_init1(pxNewQueue) &*&
- 0 < uxQueueLength &*& 0 < uxItemSize &*&
- malloc_block(pucQueueStorage, uxQueueLength * uxItemSize) &*&
- pucQueueStorage + uxQueueLength * uxItemSize <= (uint8_t *)UINTPTR_MAX &*&
- uchars(pucQueueStorage, uxQueueLength * uxItemSize,_);@*/
+ * 0 < uxQueueLength &*& 0 < uxItemSize &*&
+ * malloc_block(pucQueueStorage, uxQueueLength * uxItemSize) &*&
+ * pucQueueStorage + uxQueueLength * uxItemSize <= (uint8_t *)UINTPTR_MAX &*&
+ * uchars(pucQueueStorage, uxQueueLength * uxItemSize,_);@*/
+
/*@ensures queue(pxNewQueue, ((int8_t *)(void *)pucQueueStorage), uxQueueLength, uxItemSize, 0, (uxQueueLength-1), 0, false, nil) &*&
- queuelists(pxNewQueue);@*/
+ * queuelists(pxNewQueue);@*/
{
-#ifndef VERIFAST /*< void cast of unused var */
- /* Remove compiler warnings about unused parameters should
- * configUSE_TRACE_FACILITY not be set to 1. */
- ( void ) ucQueueType;
-#endif
+ #ifndef VERIFAST /*< void cast of unused var */
+
+ /* Remove compiler warnings about unused parameters should
+ * configUSE_TRACE_FACILITY not be set to 1. */
+ ( void ) ucQueueType;
+ #endif
if( uxItemSize == ( UBaseType_t ) 0 )
{
@@ -144,20 +148,20 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
* be set to NULL because NULL is used as a key to say the queue is used as
* a mutex. Therefore just set pcHead to point to the queue as a benign
* value that is known to be within the memory map. */
-#ifdef VERIFAST /*< stricter casting */
- pxNewQueue->pcHead = ( int8_t * ) ( void * ) pxNewQueue;
-#else
- pxNewQueue->pcHead = ( int8_t * ) pxNewQueue;
-#endif
+ #ifdef VERIFAST /*< stricter casting */
+ pxNewQueue->pcHead = ( int8_t * ) ( void * ) pxNewQueue;
+ #else
+ pxNewQueue->pcHead = ( int8_t * ) pxNewQueue;
+ #endif
}
else
{
/* Set the head to the start of the queue storage area. */
-#ifdef VERIFAST /*< stricter casting */
- pxNewQueue->pcHead = ( int8_t * ) ( void * ) pucQueueStorage;
-#else
- pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage;
-#endif
+ #ifdef VERIFAST /*< stricter casting */
+ pxNewQueue->pcHead = ( int8_t * ) ( void * ) pucQueueStorage;
+ #else
+ pxNewQueue->pcHead = ( int8_t * ) pucQueueStorage;
+ #endif
}
/* Initialise the queue members as described where the queue type is
@@ -165,11 +169,11 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
pxNewQueue->uxLength = uxQueueLength;
pxNewQueue->uxItemSize = uxItemSize;
/*@close queue_init2(pxNewQueue, _, uxQueueLength, uxItemSize);@*/
-#ifdef VERIFAST /*< void cast of unused return value */
- xQueueGenericReset( pxNewQueue, pdTRUE );
-#else
- ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ xQueueGenericReset( pxNewQueue, pdTRUE );
+ #else
+ ( void ) xQueueGenericReset( pxNewQueue, pdTRUE );
+ #endif
#if ( configUSE_TRACE_FACILITY == 1 )
{
@@ -187,41 +191,44 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
}
- QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
- const UBaseType_t uxItemSize,
- const uint8_t ucQueueType )
- /*@requires 0 < uxQueueLength &*&
- 0 < uxItemSize &*&
- 0 < uxQueueLength * uxItemSize &*&
- uxQueueLength * uxItemSize <= UINT_MAX;@*/
- /*@ensures result == NULL
- ? true
- : queue(result, _, uxQueueLength, uxItemSize, 0, (uxQueueLength-1), 0, false, nil) &*&
- queuelists(result) &*&
- result->irqMask |-> _ &*&
- result->schedulerSuspend |-> _ &*&
- result->locked |-> _;@*/
- {
- Queue_t * pxNewQueue;
- size_t xQueueSizeInBytes;
- uint8_t * pucQueueStorage;
+QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
+ const UBaseType_t uxItemSize,
+ const uint8_t ucQueueType )
- configASSERT( uxQueueLength > ( UBaseType_t ) 0 );
+/*@requires 0 < uxQueueLength &*&
+ * 0 < uxItemSize &*&
+ * 0 < uxQueueLength * uxItemSize &*&
+ * uxQueueLength * uxItemSize <= UINT_MAX;@*/
+
+/*@ensures result == NULL
+ * ? true
+ * : queue(result, _, uxQueueLength, uxItemSize, 0, (uxQueueLength-1), 0, false, nil) &*&
+ * queuelists(result) &*&
+ * result->irqMask |-> _ &*&
+ * result->schedulerSuspend |-> _ &*&
+ * result->locked |-> _;@*/
+{
+ Queue_t * pxNewQueue;
+ size_t xQueueSizeInBytes;
+ uint8_t * pucQueueStorage;
- /* Allocate enough space to hold the maximum number of items that
- * can be in the queue at any time. It is valid for uxItemSize to be
- * zero in the case the queue is used as a semaphore. */
- xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
+ configASSERT( uxQueueLength > ( UBaseType_t ) 0 );
- /* Check for multiplication overflow. */
- configASSERT( ( uxItemSize == 0 ) || ( uxQueueLength == ( xQueueSizeInBytes / uxItemSize ) ) );
+ /* Allocate enough space to hold the maximum number of items that
+ * can be in the queue at any time. It is valid for uxItemSize to be
+ * zero in the case the queue is used as a semaphore. */
+ xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
- /* Check for addition overflow. */
- configASSERT( ( sizeof( Queue_t ) + xQueueSizeInBytes ) > xQueueSizeInBytes );
+ /* Check for multiplication overflow. */
+ configASSERT( ( uxItemSize == 0 ) || ( uxQueueLength == ( xQueueSizeInBytes / uxItemSize ) ) );
-#ifdef VERIFAST /*< ***model single malloc of struct and buffer*** */
+ /* Check for addition overflow. */
+ configASSERT( ( sizeof( Queue_t ) + xQueueSizeInBytes ) > xQueueSizeInBytes );
+
+ #ifdef VERIFAST /*< ***model single malloc of struct and buffer*** */
pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) );
-#else
+ #else
+
/* Allocate the queue and storage area. Justification for MISRA
* deviation as follows: pvPortMalloc() always ensures returned memory
* blocks are aligned per the requirements of the MCU stack. In this case
@@ -232,11 +239,11 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
* is safe. In other cases alignment requirements are not strict (one or
* two bytes). */
pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) + xQueueSizeInBytes ); /*lint !e9087 !e9079 see comment above. */
-#endif
+ #endif
- if( pxNewQueue != NULL )
- {
-#ifdef VERIFAST /*< ***model single malloc of struct and buffer*** */
+ if( pxNewQueue != NULL )
+ {
+ #ifdef VERIFAST /*< ***model single malloc of struct and buffer*** */
pucQueueStorage = ( uint8_t * ) pvPortMalloc( xQueueSizeInBytes );
if( pucQueueStorage == NULL )
@@ -246,29 +253,30 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength,
}
/*@malloc_block_limits(pucQueueStorage);@*/
-#else
+ #else
+
/* Jump past the queue structure to find the location of the queue
* storage area. */
pucQueueStorage = ( uint8_t * ) pxNewQueue;
pucQueueStorage += sizeof( Queue_t ); /*lint !e9016 Pointer arithmetic allowed on char types, especially when it assists conveying intent. */
-#endif
+ #endif /* ifdef VERIFAST */
- #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- /* Queues can be created either statically or dynamically, so
- * note this task was created dynamically in case it is later
- * deleted. */
- pxNewQueue->ucStaticallyAllocated = pdFALSE;
- }
- #endif /* configSUPPORT_STATIC_ALLOCATION */
-
- prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );
- }
- else
- {
- traceQUEUE_CREATE_FAILED( ucQueueType );
- mtCOVERAGE_TEST_MARKER();
- }
+ #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
+ {
+ /* Queues can be created either statically or dynamically, so
+ * note this task was created dynamically in case it is later
+ * deleted. */
+ pxNewQueue->ucStaticallyAllocated = pdFALSE;
+ }
+ #endif /* configSUPPORT_STATIC_ALLOCATION */
- return pxNewQueue;
+ prvInitialiseNewQueue( uxQueueLength, uxItemSize, pucQueueStorage, ucQueueType, pxNewQueue );
+ }
+ else
+ {
+ traceQUEUE_CREATE_FAILED( ucQueueType );
+ mtCOVERAGE_TEST_MARKER();
}
+
+ return pxNewQueue;
+}
diff --git a/FreeRTOS/Test/VeriFast/queue/prvCopyDataFromQueue.c b/FreeRTOS/Test/VeriFast/queue/prvCopyDataFromQueue.c
index ae572a297..8288c4ab6 100644
--- a/FreeRTOS/Test/VeriFast/queue/prvCopyDataFromQueue.c
+++ b/FreeRTOS/Test/VeriFast/queue/prvCopyDataFromQueue.c
@@ -29,8 +29,9 @@
static void prvCopyDataFromQueue( Queue_t * const pxQueue,
void * const pvBuffer )
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*& 0 < K &*& chars(pvBuffer, M, _);@*/
+
/*@ensures queue_after_prvCopyDataFromQueue(pxQueue, Storage, N, M, W, (R+1)%N, K, is_locked, abs) &*&
- chars(pvBuffer, M, head(abs));@*/
+ * chars(pvBuffer, M, head(abs));@*/
{
if( pxQueue->uxItemSize != ( UBaseType_t ) 0 )
{
@@ -46,44 +47,48 @@ static void prvCopyDataFromQueue( Queue_t * const pxQueue,
else
{
/*@{
- div_lt(R+1, N, M); // now we know R+1 < N
- mod_lt(R+1, N); // so, R+1 == (R+1)%N
- note(pxQueue->u.xQueue.pcReadFrom == Storage + ((R + 1) * M));
- note( Storage + ((R + 1) * M) == Storage + (((R + 1) % N) * M));
- }@*/
+ * div_lt(R+1, N, M); // now we know R+1 < N
+ * mod_lt(R+1, N); // so, R+1 == (R+1)%N
+ * note(pxQueue->u.xQueue.pcReadFrom == Storage + ((R + 1) * M));
+ * note( Storage + ((R + 1) * M) == Storage + (((R + 1) % N) * M));
+ * }@*/
mtCOVERAGE_TEST_MARKER();
}
/*@mod_plus(R+1, K, N);@*/
/*@mod_mod(R+1, N);@*/
/*@split_element(Storage, N, M, (R+1)%N);@*/
+
/*@assert
- buffer(Storage, (R+1)%N, M, ?prefix) &*&
- chars(Storage + ((R+1)%N) * M, M, ?element) &*&
- buffer(Storage + ((R+1)%N + 1) * M, (N-1-(R+1)%N), M, ?suffix);@*/
-#ifdef VERIFAST /*< void cast of unused return value */
- memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize );
-#else
- ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports. Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */
-#endif
+ * buffer(Storage, (R+1)%N, M, ?prefix) &*&
+ * chars(Storage + ((R+1)%N) * M, M, ?element) &*&
+ * buffer(Storage + ((R+1)%N + 1) * M, (N-1-(R+1)%N), M, ?suffix);@*/
+ #ifdef VERIFAST /*< void cast of unused return value */
+ memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize );
+ #else
+ ( void ) memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->u.xQueue.pcReadFrom, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports. Also previous logic ensures a null pointer can only be passed to memcpy() when the count is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */
+ #endif
+
/*@{
- combine_list_no_change(prefix, element, suffix, (R+1)%N, contents);
- join_element(Storage, N, M, (R+1)%N);
- length_take(K, contents);
- take_length_eq(K, rotate_left((R+1)%N, contents), abs);
- deq_value_lemma(K, (R+1)%N, contents, abs);
- }@*/
+ * combine_list_no_change(prefix, element, suffix, (R+1)%N, contents);
+ * join_element(Storage, N, M, (R+1)%N);
+ * length_take(K, contents);
+ * take_length_eq(K, rotate_left((R+1)%N, contents), abs);
+ * deq_value_lemma(K, (R+1)%N, contents, abs);
+ * }@*/
}
}
void caller_reinstates_queue_predicate( Queue_t * const pxQueue,
void * const pvBuffer )
+
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- 0 < K &*&
- chars(pvBuffer, M, _);@*/
+ * 0 < K &*&
+ * chars(pvBuffer, M, _);@*/
+
/*@ensures
- queue(pxQueue, Storage, N, M, W, (R+1)%N, K-1, is_locked, tail(abs)) &*&
- chars(pvBuffer, M, head(abs));@*/
+ * queue(pxQueue, Storage, N, M, W, (R+1)%N, K-1, is_locked, tail(abs)) &*&
+ * chars(pvBuffer, M, head(abs));@*/
{
prvCopyDataFromQueue( pxQueue, pvBuffer );
/*@open queue_after_prvCopyDataFromQueue(pxQueue, Storage, N, M, W, (R+1)%N, K, is_locked, abs);@*/
diff --git a/FreeRTOS/Test/VeriFast/queue/prvCopyDataToQueue.c b/FreeRTOS/Test/VeriFast/queue/prvCopyDataToQueue.c
index c9e8073b4..fa5f803f7 100644
--- a/FreeRTOS/Test/VeriFast/queue/prvCopyDataToQueue.c
+++ b/FreeRTOS/Test/VeriFast/queue/prvCopyDataToQueue.c
@@ -29,20 +29,22 @@
static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
const void * pvItemToQueue,
const BaseType_t xPosition )
+
/*@requires queue(pxQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- (K < N || xPosition == queueOVERWRITE) &*&
- chars(pvItemToQueue, M, ?x) &*&
- (xPosition == queueSEND_TO_BACK || xPosition == queueSEND_TO_FRONT || (xPosition == queueOVERWRITE && N == 1));@*/
+ * (K < N || xPosition == queueOVERWRITE) &*&
+ * chars(pvItemToQueue, M, ?x) &*&
+ * (xPosition == queueSEND_TO_BACK || xPosition == queueSEND_TO_FRONT || (xPosition == queueOVERWRITE && N == 1));@*/
+
/*@ensures
- (xPosition == queueSEND_TO_BACK
- ? queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)))
- : (xPosition == queueSEND_TO_FRONT
- ? (R == 0
- ? queue(pxQueue, Storage, N, M, W, (N-1), (K+1), is_locked, cons(x, abs))
- : queue(pxQueue, Storage, N, M, W, (R-1), (K+1), is_locked, cons(x, abs)))
- : xPosition == queueOVERWRITE &*& queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x)))
- ) &*&
- chars(pvItemToQueue, M, x);@*/
+ * (xPosition == queueSEND_TO_BACK
+ * ? queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)))
+ * : (xPosition == queueSEND_TO_FRONT
+ * ? (R == 0
+ * ? queue(pxQueue, Storage, N, M, W, (N-1), (K+1), is_locked, cons(x, abs))
+ * : queue(pxQueue, Storage, N, M, W, (R-1), (K+1), is_locked, cons(x, abs)))
+ * : xPosition == queueOVERWRITE &*& queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x)))
+ * ) &*&
+ * chars(pvItemToQueue, M, x);@*/
{
BaseType_t xReturn = pdFALSE;
UBaseType_t uxMessagesWaiting;
@@ -74,27 +76,29 @@ static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
}
else if( xPosition == queueSEND_TO_BACK )
{
-#ifdef VERIFAST /*< void cast of unused return value */
- /* Now we focus the proof on the logical element of the buffer that
- * will be updated using the following lemma to split the buffer into 3
- * parts: a prefix, the element we want to update, and the suffix. This
- * enables the subsequent memcpy to verify. */
- /*@split_element(Storage, N, M, W);@*/
- /*@assert
- buffer(Storage, W, M, ?prefix) &*&
- chars(Storage + W * M, M, _) &*&
- buffer(Storage + (W + 1) * M, (N-1-W), M, ?suffix);@*/
- memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );
- /* After the update we stitch the buffer back together */
- /*@join_element(Storage, N, M, W);@*/
- /*@combine_list_update(prefix, x, suffix, W, contents);@*/
-#else
- ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+
+ /* Now we focus the proof on the logical element of the buffer that
+ * will be updated using the following lemma to split the buffer into 3
+ * parts: a prefix, the element we want to update, and the suffix. This
+ * enables the subsequent memcpy to verify. */
+ /*@split_element(Storage, N, M, W);@*/
+
+ /*@assert
+ * buffer(Storage, W, M, ?prefix) &*&
+ * chars(Storage + W * M, M, _) &*&
+ * buffer(Storage + (W + 1) * M, (N-1-W), M, ?suffix);@*/
+ memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );
+ /* After the update we stitch the buffer back together */
+ /*@join_element(Storage, N, M, W);@*/
+ /*@combine_list_update(prefix, x, suffix, W, contents);@*/
+ #else
+ ( void ) memcpy( ( void * ) pxQueue->pcWriteTo, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e418 !e9087 MISRA exception as the casts are only redundant for some ports, plus previous logic ensures a null pointer can only be passed to memcpy() if the copy size is 0. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. */
+ #endif /* ifdef VERIFAST */
/*@mul_mono_l(W, N-1, M);@*/
- pxQueue->pcWriteTo += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */
+ pxQueue->pcWriteTo += pxQueue->uxItemSize; /*lint !e9016 Pointer arithmetic on char types ok, especially in this use case where it is the clearest way of conveying intent. */
- if( pxQueue->pcWriteTo >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
+ if( pxQueue->pcWriteTo >= pxQueue->u.xQueue.pcTail ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
{
/*@div_leq(N, W+1, M);@*/ /* now we know W == N-1 so (W+1)%N == 0 */
pxQueue->pcWriteTo = pxQueue->pcHead;
@@ -102,28 +106,29 @@ static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
else
{
/*@{
- div_lt(W+1, N, M); // now we know W+1 < N
- mod_lt(W+1, N); // so, W+1 == (W+1)%N
- note(pxQueue->pcWriteTo == Storage + ((W + 1) * M));
- note( Storage + ((W + 1) * M) == Storage + (((W + 1) % N) * M));
- }@*/
+ * div_lt(W+1, N, M); // now we know W+1 < N
+ * mod_lt(W+1, N); // so, W+1 == (W+1)%N
+ * note(pxQueue->pcWriteTo == Storage + ((W + 1) * M));
+ * note( Storage + ((W + 1) * M) == Storage + (((W + 1) % N) * M));
+ * }@*/
mtCOVERAGE_TEST_MARKER();
}
}
else
{
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@split_element(Storage, N, M, R);@*/
- /*@assert
- buffer(Storage, R, M, ?prefix) &*&
- chars(Storage + R * M, M, _) &*&
- buffer(Storage + (R + 1) * M, (N-1-R), M, ?suffix);@*/
- memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );
- /*@join_element(Storage, N, M, R);@*/
- /*@combine_list_update(prefix, x, suffix, R, contents);@*/
-#else
- ( void ) memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e9087 !e418 MISRA exception as the casts are only redundant for some ports. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. Assert checks null pointer only used when length is 0. */
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@split_element(Storage, N, M, R);@*/
+
+ /*@assert
+ * buffer(Storage, R, M, ?prefix) &*&
+ * chars(Storage + R * M, M, _) &*&
+ * buffer(Storage + (R + 1) * M, (N-1-R), M, ?suffix);@*/
+ memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize );
+ /*@join_element(Storage, N, M, R);@*/
+ /*@combine_list_update(prefix, x, suffix, R, contents);@*/
+ #else
+ ( void ) memcpy( ( void * ) pxQueue->u.xQueue.pcReadFrom, pvItemToQueue, ( size_t ) pxQueue->uxItemSize ); /*lint !e961 !e9087 !e418 MISRA exception as the casts are only redundant for some ports. Cast to void required by function signature and safe as no alignment requirement and copy length specified in bytes. Assert checks null pointer only used when length is 0. */
+ #endif
pxQueue->u.xQueue.pcReadFrom -= pxQueue->uxItemSize;
if( pxQueue->u.xQueue.pcReadFrom < pxQueue->pcHead ) /*lint !e946 MISRA exception justified as comparison of pointers is the cleanest solution. */
@@ -141,12 +146,12 @@ static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
}
/*@
- if (R == 0)
- {
- mod_plus(N, (K+1), N); mod_same(N); mod_mod(K+1, N);
- assert W == ((N-1) + 1 + (K+1)) % N;
- }
- @*/
+ * if (R == 0)
+ * {
+ * mod_plus(N, (K+1), N); mod_same(N); mod_mod(K+1, N);
+ * assert W == ((N-1) + 1 + (K+1)) % N;
+ * }
+ * @*/
if( xPosition == queueOVERWRITE )
{
if( uxMessagesWaiting > ( UBaseType_t ) 0 )
@@ -171,20 +176,20 @@ static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
pxQueue->uxMessagesWaiting = uxMessagesWaiting + ( UBaseType_t ) 1;
/*@
- if (xPosition == queueSEND_TO_BACK)
- {
- enq_lemma(K, (R+1)%N, contents, abs, x);
- mod_plus_one(W, R + 1 + K, N);
- mod_plus_distr(R+1, K, N);
- }
- else if (xPosition == queueSEND_TO_FRONT)
- {
- front_enq_lemma(K, R, contents, abs, x);
- if (0 < R)
- {
- mod_lt(R, N);
- }
- }
- @*/
+ * if (xPosition == queueSEND_TO_BACK)
+ * {
+ * enq_lemma(K, (R+1)%N, contents, abs, x);
+ * mod_plus_one(W, R + 1 + K, N);
+ * mod_plus_distr(R+1, K, N);
+ * }
+ * else if (xPosition == queueSEND_TO_FRONT)
+ * {
+ * front_enq_lemma(K, R, contents, abs, x);
+ * if (0 < R)
+ * {
+ * mod_lt(R, N);
+ * }
+ * }
+ * @*/
return xReturn;
}
diff --git a/FreeRTOS/Test/VeriFast/queue/prvLockQueue.c b/FreeRTOS/Test/VeriFast/queue/prvLockQueue.c
index b3dab3fe8..57dd04f0d 100644
--- a/FreeRTOS/Test/VeriFast/queue/prvLockQueue.c
+++ b/FreeRTOS/Test/VeriFast/queue/prvLockQueue.c
@@ -46,11 +46,12 @@
void wrapper_prvLockQueue( QueueHandle_t xQueue )
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
- [1/2]queuelock(xQueue);@*/
+ * [1/2]queuelock(xQueue);@*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]xQueue->locked |-> ?m &*&
- mutex_held(m, queue_locked_invariant(xQueue), currentThread, 1/2) &*&
- queue_locked_invariant(xQueue)();@*/
+ * [1/2]xQueue->locked |-> ?m &*&
+ * mutex_held(m, queue_locked_invariant(xQueue), currentThread, 1/2) &*&
+ * queue_locked_invariant(xQueue)();@*/
{
taskENTER_CRITICAL();
/*@open queue(xQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
@@ -67,7 +68,7 @@ void wrapper_prvLockQueue( QueueHandle_t xQueue )
}
/*@close queue(xQueue, Storage, N, M, W, R, K, true, abs);@*/
taskEXIT_CRITICAL();
-#ifdef VERIFAST /*< ghost action */
- mutex_acquire( xQueue->locked );
-#endif
+ #ifdef VERIFAST /*< ghost action */
+ mutex_acquire( xQueue->locked );
+ #endif
}
diff --git a/FreeRTOS/Test/VeriFast/queue/prvUnlockQueue.c b/FreeRTOS/Test/VeriFast/queue/prvUnlockQueue.c
index 62b5a62cd..e392a023f 100644
--- a/FreeRTOS/Test/VeriFast/queue/prvUnlockQueue.c
+++ b/FreeRTOS/Test/VeriFast/queue/prvUnlockQueue.c
@@ -32,12 +32,14 @@
* decrementing `cTxLock` and `cRxLock`. */
static void prvUnlockQueue( Queue_t * const pxQueue )
+
/*@requires [1/2]queuehandle(pxQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
- [1/2]pxQueue->locked |-> ?m &*&
- mutex_held(m, queue_locked_invariant(pxQueue), currentThread, 1/2) &*&
- queue_locked_invariant(pxQueue)();@*/
+ * [1/2]pxQueue->locked |-> ?m &*&
+ * mutex_held(m, queue_locked_invariant(pxQueue), currentThread, 1/2) &*&
+ * queue_locked_invariant(pxQueue)();@*/
+
/*@ensures [1/2]queuehandle(pxQueue, N, M, is_isr) &*&
- [1/2]queuelock(pxQueue);@*/
+ * [1/2]queuelock(pxQueue);@*/
{
/* THIS FUNCTION MUST BE CALLED WITH THE SCHEDULER SUSPENDED. */
@@ -125,12 +127,12 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
pxQueue->cTxLock = queueUNLOCKED;
}
-#ifndef VERIFAST /*< ***merge cTxLock and cRxLock critical regions*** */
- taskEXIT_CRITICAL();
+ #ifndef VERIFAST /*< ***merge cTxLock and cRxLock critical regions*** */
+ taskEXIT_CRITICAL();
- /* Do the same for the Rx lock. */
- taskENTER_CRITICAL();
-#endif
+ /* Do the same for the Rx lock. */
+ taskENTER_CRITICAL();
+ #endif
{
int8_t cRxLock = pxQueue->cRxLock;
@@ -160,7 +162,7 @@ static void prvUnlockQueue( Queue_t * const pxQueue )
}
/*@close queue(pxQueue, Storage, N, M, W, R, K, false, abs);@*/
taskEXIT_CRITICAL();
-#ifdef VERIFAST /*< ghost action */
- mutex_release( pxQueue->locked );
-#endif
+ #ifdef VERIFAST /*< ghost action */
+ mutex_release( pxQueue->locked );
+ #endif
}
diff --git a/FreeRTOS/Test/VeriFast/queue/uxQueueMessagesWaiting.c b/FreeRTOS/Test/VeriFast/queue/uxQueueMessagesWaiting.c
index cdb76b898..9373ed4dd 100644
--- a/FreeRTOS/Test/VeriFast/queue/uxQueueMessagesWaiting.c
+++ b/FreeRTOS/Test/VeriFast/queue/uxQueueMessagesWaiting.c
@@ -41,11 +41,11 @@ UBaseType_t uxQueueMessagesWaitingFromISR( const QueueHandle_t xQueue )
{
UBaseType_t uxReturn;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+ #endif
configASSERT( pxQueue );
uxReturn = pxQueue->uxMessagesWaiting;
diff --git a/FreeRTOS/Test/VeriFast/queue/uxQueueSpacesAvailable.c b/FreeRTOS/Test/VeriFast/queue/uxQueueSpacesAvailable.c
index fb8a182c9..296c22aa8 100644
--- a/FreeRTOS/Test/VeriFast/queue/uxQueueSpacesAvailable.c
+++ b/FreeRTOS/Test/VeriFast/queue/uxQueueSpacesAvailable.c
@@ -32,11 +32,11 @@ UBaseType_t uxQueueSpacesAvailable( const QueueHandle_t xQueue )
{
UBaseType_t uxReturn;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+ #endif
configASSERT( pxQueue );
diff --git a/FreeRTOS/Test/VeriFast/queue/vQueueDelete.c b/FreeRTOS/Test/VeriFast/queue/vQueueDelete.c
index 8107a2aa9..9dc67d6ef 100644
--- a/FreeRTOS/Test/VeriFast/queue/vQueueDelete.c
+++ b/FreeRTOS/Test/VeriFast/queue/vQueueDelete.c
@@ -29,18 +29,19 @@
#define configSUPPORT_STATIC_ALLOCATION 0
void vQueueDelete( QueueHandle_t xQueue )
+
/*@requires queue(xQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs) &*&
- queuelists(xQueue) &*&
- xQueue->irqMask |-> _ &*&
- xQueue->schedulerSuspend |-> _ &*&
- xQueue->locked |-> _;@*/
+ * queuelists(xQueue) &*&
+ * xQueue->irqMask |-> _ &*&
+ * xQueue->schedulerSuspend |-> _ &*&
+ * xQueue->locked |-> _;@*/
/*@ensures true;@*/
{
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+ #endif
configASSERT( pxQueue );
traceQUEUE_DELETE( pxQueue );
@@ -56,10 +57,10 @@ void vQueueDelete( QueueHandle_t xQueue )
/* The queue can only have been allocated dynamically - free it
* again. */
vPortFree( pxQueue );
-#ifdef VERIFAST /*< leak ghost state on deletion */
- /*@leak buffer(_, _, _, _);@*/
- /*@leak malloc_block(_, _);@*/
-#endif
+ #ifdef VERIFAST /*< leak ghost state on deletion */
+ /*@leak buffer(_, _, _, _);@*/
+ /*@leak malloc_block(_, _);@*/
+ #endif
}
#elif ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
{
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueueGenericSend.c b/FreeRTOS/Test/VeriFast/queue/xQueueGenericSend.c
index 0b4fdbc3c..e40fe22e4 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueueGenericSend.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueueGenericSend.c
@@ -31,45 +31,50 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
const void * const pvItemToQueue,
TickType_t xTicksToWait,
const BaseType_t xCopyPosition )
+
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
- [1/2]queuesuspend(xQueue) &*&
- chars(pvItemToQueue, M, ?x) &*&
- (xCopyPosition == queueSEND_TO_BACK || xCopyPosition == queueSEND_TO_FRONT || (xCopyPosition == queueOVERWRITE && N == 1));@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * chars(pvItemToQueue, M, ?x) &*&
+ * (xCopyPosition == queueSEND_TO_BACK || xCopyPosition == queueSEND_TO_FRONT || (xCopyPosition == queueOVERWRITE && N == 1));@*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]queuesuspend(xQueue) &*&
- chars(pvItemToQueue, M, x);@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * chars(pvItemToQueue, M, x);@*/
{
BaseType_t xEntryTimeSet = pdFALSE, xYieldRequired;
TimeOut_t xTimeOut;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
- configASSERT( pxQueue );
- configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
- configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
- #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
- {
- configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
- }
- #endif
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+
+ configASSERT( pxQueue );
+ configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
+ configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
+ #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
+ {
+ configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
+ }
+ #endif
+ #endif /* ifdef VERIFAST */
/*lint -save -e904 This function relaxes the coding standard somewhat to
* allow return statements within the function itself. This is done in the
* interest of execution time efficiency. */
for( ; ; )
+
/*@invariant [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]queuesuspend(xQueue) &*&
- chars(pvItemToQueue, M, x) &*&
- u_integer(&xTicksToWait, _) &*&
- (xCopyPosition == queueSEND_TO_BACK || xCopyPosition == queueSEND_TO_FRONT || (xCopyPosition == queueOVERWRITE && N == 1)) &*&
- xTIME_OUT(&xTimeOut);@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * chars(pvItemToQueue, M, x) &*&
+ * u_integer(&xTicksToWait, _) &*&
+ * (xCopyPosition == queueSEND_TO_BACK || xCopyPosition == queueSEND_TO_FRONT || (xCopyPosition == queueOVERWRITE && N == 1)) &*&
+ * xTIME_OUT(&xTimeOut);@*/
{
taskENTER_CRITICAL();
{
/*@assert queue(pxQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
+
/* Is there room on the queue now? The running task must be the
* highest priority task wanting to access the queue. If the head item
* in the queue is to be overwritten then it does not matter if the
@@ -177,19 +182,19 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
#endif /* configUSE_QUEUE_SETS */
/*@
- if (xCopyPosition == queueSEND_TO_BACK)
- {
- close queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)));
- }
- else if (xCopyPosition == queueSEND_TO_FRONT)
- {
- close queue(pxQueue, Storage, N, M, W, (R == 0 ? (N-1) : (R-1)), (K+1), is_locked, cons(x, abs));
- }
- else if (xCopyPosition == queueOVERWRITE)
- {
- close queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x));
- }
- @*/
+ * if (xCopyPosition == queueSEND_TO_BACK)
+ * {
+ * close queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)));
+ * }
+ * else if (xCopyPosition == queueSEND_TO_FRONT)
+ * {
+ * close queue(pxQueue, Storage, N, M, W, (R == 0 ? (N-1) : (R-1)), (K+1), is_locked, cons(x, abs));
+ * }
+ * else if (xCopyPosition == queueOVERWRITE)
+ * {
+ * close queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x));
+ * }
+ * @*/
taskEXIT_CRITICAL();
return pdPASS;
}
@@ -198,6 +203,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
if( xTicksToWait == ( TickType_t ) 0 )
{
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
+
/* The queue was full and no block time is specified (or
* the block time has expired) so leave now. */
taskEXIT_CRITICAL();
@@ -220,6 +226,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
mtCOVERAGE_TEST_MARKER();
}
}
+
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
}
taskEXIT_CRITICAL();
@@ -263,24 +270,24 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue,
{
/* Try again. */
prvUnlockQueue( pxQueue );
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@close exists(pxQueue);@*/
- xTaskResumeAll();
-#else
- ( void ) xTaskResumeAll();
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@close exists(pxQueue);@*/
+ xTaskResumeAll();
+ #else
+ ( void ) xTaskResumeAll();
+ #endif
}
}
else
{
/* The timeout has expired. */
prvUnlockQueue( pxQueue );
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@close exists(pxQueue);@*/
- xTaskResumeAll();
-#else
- ( void ) xTaskResumeAll();
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@close exists(pxQueue);@*/
+ xTaskResumeAll();
+ #else
+ ( void ) xTaskResumeAll();
+ #endif
traceQUEUE_SEND_FAILED( pxQueue );
return errQUEUE_FULL;
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueueGenericSendFromISR.c b/FreeRTOS/Test/VeriFast/queue/xQueueGenericSendFromISR.c
index 85b5b79e1..3889d1074 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueueGenericSendFromISR.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueueGenericSendFromISR.c
@@ -31,28 +31,30 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
const void * const pvItemToQueue,
BaseType_t * const pxHigherPriorityTaskWoken,
const BaseType_t xCopyPosition )
+
/*@requires
- [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true &*&
- chars(pvItemToQueue, M, ?x) &*&
- integer(pxHigherPriorityTaskWoken, _) &*&
- (xCopyPosition == queueSEND_TO_BACK || xCopyPosition == queueSEND_TO_FRONT || (xCopyPosition == queueOVERWRITE && N == 1));@*/
+ * [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true &*&
+ * chars(pvItemToQueue, M, ?x) &*&
+ * integer(pxHigherPriorityTaskWoken, _) &*&
+ * (xCopyPosition == queueSEND_TO_BACK || xCopyPosition == queueSEND_TO_FRONT || (xCopyPosition == queueOVERWRITE && N == 1));@*/
+
/*@ensures
- [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- chars(pvItemToQueue, M, x) &*&
- integer(pxHigherPriorityTaskWoken, _);@*/
+ * [1/2]queuehandle(xQueue, N, M, is_isr) &*&
+ * chars(pvItemToQueue, M, x) &*&
+ * integer(pxHigherPriorityTaskWoken, _);@*/
{
BaseType_t xReturn;
UBaseType_t uxSavedInterruptStatus;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
- configASSERT( pxQueue );
- configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
- configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
-#endif
+ configASSERT( pxQueue );
+ configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
+ configASSERT( !( ( xCopyPosition == queueOVERWRITE ) && ( pxQueue->uxLength != 1 ) ) );
+ #endif
/* RTOS ports that support interrupt nesting have the concept of a maximum
* system call (or maximum API call) interrupt priority. Interrupts that are
@@ -90,12 +92,12 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
* in a task disinheriting a priority and prvCopyDataToQueue() can be
* called here even though the disinherit function does not check if
* the scheduler is suspended before accessing the ready lists. */
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
- prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
-#else
- ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
+ prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
+ #else
+ ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );
+ #endif
/*@open queue(pxQueue, _, N, M, _, _, _, _, _);@*/
/* The event list is not altered if the queue is locked. This will
@@ -189,9 +191,9 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
}
/* Not used in this path. */
-#ifndef VERIFAST /*< void cast of unused var */
- ( void ) uxPreviousMessagesWaiting;
-#endif
+ #ifndef VERIFAST /*< void cast of unused var */
+ ( void ) uxPreviousMessagesWaiting;
+ #endif
}
#endif /* configUSE_QUEUE_SETS */
}
@@ -205,26 +207,27 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue,
}
xReturn = pdPASS;
+
/*@
- if (xCopyPosition == queueSEND_TO_BACK)
- {
- close queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)));
- }
- else if (xCopyPosition == queueSEND_TO_FRONT)
- {
- if (R == 0)
- {
- close queue(pxQueue, Storage, N, M, W, (N-1), (K+1), is_locked, cons(x, abs));
- }
- else
- {
- close queue(pxQueue, Storage, N, M, W, (R-1), (K+1), is_locked, cons(x, abs));
- }
- } else if (xCopyPosition == queueOVERWRITE)
- {
- close queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x));
- }
- @*/
+ * if (xCopyPosition == queueSEND_TO_BACK)
+ * {
+ * close queue(pxQueue, Storage, N, M, (W+1)%N, R, (K+1), is_locked, append(abs, singleton(x)));
+ * }
+ * else if (xCopyPosition == queueSEND_TO_FRONT)
+ * {
+ * if (R == 0)
+ * {
+ * close queue(pxQueue, Storage, N, M, W, (N-1), (K+1), is_locked, cons(x, abs));
+ * }
+ * else
+ * {
+ * close queue(pxQueue, Storage, N, M, W, (R-1), (K+1), is_locked, cons(x, abs));
+ * }
+ * } else if (xCopyPosition == queueOVERWRITE)
+ * {
+ * close queue(pxQueue, Storage, N, M, W, R, 1, is_locked, singleton(x));
+ * }
+ * @*/
}
else
{
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueEmptyFromISR.c b/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueEmptyFromISR.c
index fe2ba2af2..45a7bcef4 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueEmptyFromISR.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueEmptyFromISR.c
@@ -28,16 +28,17 @@
BaseType_t xQueueIsQueueEmptyFromISR( const QueueHandle_t xQueue )
/*@requires queue(xQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
+
/*@ensures queue(xQueue, Storage, N, M, W, R, K, is_locked, abs) &*&
- result == ((K == 0) ? pdTRUE : pdFALSE);@*/
+ * result == ((K == 0) ? pdTRUE : pdFALSE);@*/
{
BaseType_t xReturn;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+ #endif
configASSERT( pxQueue );
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueFullFromISR.c b/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueFullFromISR.c
index 2b88a420e..37292dd81 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueFullFromISR.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueueIsQueueFullFromISR.c
@@ -28,16 +28,17 @@
BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
/*@requires queue(xQueue, ?Storage, ?N, ?M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
+
/*@ensures queue(xQueue, Storage, N, M, W, R, K, is_locked, abs) &*&
- result == ((K == N) ? pdTRUE : pdFALSE);@*/
+ * result == ((K == N) ? pdTRUE : pdFALSE);@*/
{
BaseType_t xReturn;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+ #endif
configASSERT( pxQueue );
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueuePeek.c b/FreeRTOS/Test/VeriFast/queue/xQueuePeek.c
index 5a95fee59..a8da91759 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueuePeek.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueuePeek.c
@@ -30,45 +30,49 @@
BaseType_t xQueuePeek( QueueHandle_t xQueue,
void * const pvBuffer,
TickType_t xTicksToWait )
+
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
- [1/2]queuesuspend(xQueue) &*&
- chars(pvBuffer, M, ?x);@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * chars(pvBuffer, M, ?x);@*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]queuesuspend(xQueue) &*&
- (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x));@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x));@*/
{
BaseType_t xEntryTimeSet = pdFALSE;
TimeOut_t xTimeOut;
int8_t * pcOriginalReadPosition;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
- /* Check the pointer is not NULL. */
- configASSERT( ( pxQueue ) );
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
- /* The buffer into which data is received can only be NULL if the data size
- * is zero (so no data is copied into the buffer. */
- configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
+ /* Check the pointer is not NULL. */
+ configASSERT( ( pxQueue ) );
- /* Cannot block if the scheduler is suspended. */
- #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
- {
- configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
- }
- #endif
-#endif
+ /* The buffer into which data is received can only be NULL if the data size
+ * is zero (so no data is copied into the buffer. */
+ configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
+
+ /* Cannot block if the scheduler is suspended. */
+ #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
+ {
+ configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
+ }
+ #endif
+ #endif /* ifdef VERIFAST */
/*lint -save -e904 This function relaxes the coding standard somewhat to
* allow return statements within the function itself. This is done in the
* interest of execution time efficiency. */
for( ; ; )
+
/*@invariant [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]queuesuspend(xQueue) &*&
- chars(pvBuffer, M, x) &*&
- u_integer(&xTicksToWait, _) &*&
- xTIME_OUT(&xTimeOut);@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * chars(pvBuffer, M, x) &*&
+ * u_integer(&xTicksToWait, _) &*&
+ * xTIME_OUT(&xTimeOut);@*/
{
taskENTER_CRITICAL();
/*@assert queue(pxQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
@@ -178,12 +182,12 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
/* There is data in the queue now, so don't enter the blocked
* state, instead return to try and obtain the data. */
prvUnlockQueue( pxQueue );
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@close exists<QueueHandle_t>(pxQueue);@*/
- xTaskResumeAll();
-#else
- ( void ) xTaskResumeAll();
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@close exists<QueueHandle_t>(pxQueue);@*/
+ xTaskResumeAll();
+ #else
+ ( void ) xTaskResumeAll();
+ #endif
}
}
else
@@ -191,12 +195,12 @@ BaseType_t xQueuePeek( QueueHandle_t xQueue,
/* The timeout has expired. If there is still no data in the queue
* exit, otherwise go back and try to read the data again. */
prvUnlockQueue( pxQueue );
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@close exists<QueueHandle_t>(pxQueue);@*/
- xTaskResumeAll();
-#else
- ( void ) xTaskResumeAll();
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@close exists<QueueHandle_t>(pxQueue);@*/
+ xTaskResumeAll();
+ #else
+ ( void ) xTaskResumeAll();
+ #endif
if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
{
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueuePeekFromISR.c b/FreeRTOS/Test/VeriFast/queue/xQueuePeekFromISR.c
index 1dc0d5f59..a2d174b8b 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueuePeekFromISR.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueuePeekFromISR.c
@@ -29,23 +29,26 @@
BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue,
void * const pvBuffer )
+
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true &*&
- chars(pvBuffer, M, ?x);@*/
+ * chars(pvBuffer, M, ?x);@*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x));@*/
+ * (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x));@*/
{
BaseType_t xReturn;
UBaseType_t uxSavedInterruptStatus;
int8_t * pcOriginalReadPosition;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
- configASSERT( pxQueue );
- configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
- configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+
+ configASSERT( pxQueue );
+ configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
+ configASSERT( pxQueue->uxItemSize != 0 ); /* Can't peek a semaphore. */
+ #endif
/* RTOS ports that support interrupt nesting have the concept of a maximum
* system call (or maximum API call) interrupt priority. Interrupts that are
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueueReceive.c b/FreeRTOS/Test/VeriFast/queue/xQueueReceive.c
index ac8740eda..63a13cc3d 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueueReceive.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueueReceive.c
@@ -30,44 +30,48 @@
BaseType_t xQueueReceive( QueueHandle_t xQueue,
void * const pvBuffer,
TickType_t xTicksToWait )
+
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == false &*&
- [1/2]queuesuspend(xQueue) &*&
- chars(pvBuffer, M, ?x);@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * chars(pvBuffer, M, ?x);@*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]queuesuspend(xQueue) &*&
- (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x));@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x));@*/
{
BaseType_t xEntryTimeSet = pdFALSE;
TimeOut_t xTimeOut;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
- /* Check the pointer is not NULL. */
- configASSERT( ( pxQueue ) );
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
- /* The buffer into which data is received can only be NULL if the data size
- * is zero (so no data is copied into the buffer). */
- configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
+ /* Check the pointer is not NULL. */
+ configASSERT( ( pxQueue ) );
- /* Cannot block if the scheduler is suspended. */
- #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
- {
- configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
- }
- #endif
-#endif
+ /* The buffer into which data is received can only be NULL if the data size
+ * is zero (so no data is copied into the buffer). */
+ configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );
+
+ /* Cannot block if the scheduler is suspended. */
+ #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
+ {
+ configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
+ }
+ #endif
+ #endif /* ifdef VERIFAST */
/*lint -save -e904 This function relaxes the coding standard somewhat to
* allow return statements within the function itself. This is done in the
* interest of execution time efficiency. */
for( ; ; )
+
/*@invariant [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- [1/2]queuesuspend(xQueue) &*&
- chars(pvBuffer, M, x) &*&
- u_integer(&xTicksToWait, _) &*&
- xTIME_OUT(&xTimeOut);@*/
+ * [1/2]queuesuspend(xQueue) &*&
+ * chars(pvBuffer, M, x) &*&
+ * u_integer(&xTicksToWait, _) &*&
+ * xTIME_OUT(&xTimeOut);@*/
{
taskENTER_CRITICAL();
/*@assert queue(pxQueue, ?Storage, N, M, ?W, ?R, ?K, ?is_locked, ?abs);@*/
@@ -86,9 +90,10 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;
/*@assert
- pxQueue->pcHead |-> ?buffer &*&
- buffer(buffer, N, M, ?contents);@*/
+ * pxQueue->pcHead |-> ?buffer &*&
+ * buffer(buffer, N, M, ?contents);@*/
/*@deq_lemma(K, (R+1)%N, contents, abs, head(abs));@*/
+
/* There is now space in the queue, were any tasks waiting to
* post to the queue? If so, unblock the highest priority waiting
* task. */
@@ -118,6 +123,7 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
if( xTicksToWait == ( TickType_t ) 0 )
{
/*@close queue(pxQueue, Storage, N, M, W, R, K, is_locked, abs);@*/
+
/* The queue was empty and no block time is specified (or
* the block time has expired) so leave now. */
taskEXIT_CRITICAL();
@@ -176,12 +182,12 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
/* The queue contains data again. Loop back to try and read the
* data. */
prvUnlockQueue( pxQueue );
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@close exists(pxQueue);@*/
- xTaskResumeAll();
-#else
- ( void ) xTaskResumeAll();
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@close exists(pxQueue);@*/
+ xTaskResumeAll();
+ #else
+ ( void ) xTaskResumeAll();
+ #endif
}
}
else
@@ -189,12 +195,12 @@ BaseType_t xQueueReceive( QueueHandle_t xQueue,
/* Timed out. If there is no data in the queue exit, otherwise loop
* back and attempt to read the data. */
prvUnlockQueue( pxQueue );
-#ifdef VERIFAST /*< void cast of unused return value */
- /*@close exists(pxQueue);@*/
- xTaskResumeAll();
-#else
- ( void ) xTaskResumeAll();
-#endif
+ #ifdef VERIFAST /*< void cast of unused return value */
+ /*@close exists(pxQueue);@*/
+ xTaskResumeAll();
+ #else
+ ( void ) xTaskResumeAll();
+ #endif
if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
{
diff --git a/FreeRTOS/Test/VeriFast/queue/xQueueReceiveFromISR.c b/FreeRTOS/Test/VeriFast/queue/xQueueReceiveFromISR.c
index 79900b972..283157e71 100644
--- a/FreeRTOS/Test/VeriFast/queue/xQueueReceiveFromISR.c
+++ b/FreeRTOS/Test/VeriFast/queue/xQueueReceiveFromISR.c
@@ -30,23 +30,26 @@
BaseType_t xQueueReceiveFromISR( QueueHandle_t xQueue,
void * const pvBuffer,
BaseType_t * const pxHigherPriorityTaskWoken )
+
/*@requires [1/2]queuehandle(xQueue, ?N, ?M, ?is_isr) &*& is_isr == true &*&
- chars(pvBuffer, M, ?x) &*&
- pxHigherPriorityTaskWoken == NULL ? true : integer(pxHigherPriorityTaskWoken, _);@*/
+ * chars(pvBuffer, M, ?x) &*&
+ * pxHigherPriorityTaskWoken == NULL ? true : integer(pxHigherPriorityTaskWoken, _);@*/
+
/*@ensures [1/2]queuehandle(xQueue, N, M, is_isr) &*&
- (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x)) &*&
- (pxHigherPriorityTaskWoken == NULL ? true : integer(pxHigherPriorityTaskWoken, _));@*/
+ * (result == pdPASS ? chars(pvBuffer, M, _) : chars(pvBuffer, M, x)) &*&
+ * (pxHigherPriorityTaskWoken == NULL ? true : integer(pxHigherPriorityTaskWoken, _));@*/
{
BaseType_t xReturn;
UBaseType_t uxSavedInterruptStatus;
-#ifdef VERIFAST /*< const pointer declaration */
- Queue_t * pxQueue = xQueue;
-#else
- Queue_t * const pxQueue = xQueue;
- configASSERT( pxQueue );
- configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
-#endif
+ #ifdef VERIFAST /*< const pointer declaration */
+ Queue_t * pxQueue = xQueue;
+ #else
+ Queue_t * const pxQueue = xQueue;
+
+ configASSERT( pxQueue );
+ configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );
+ #endif
/* RTOS ports that support interrupt nesting have the concept of a maximum
* system call (or maximum API call) interrupt priority. Interrupts that are