From a691c6199eebd1f8a8c434ac3e658337bfda6bf6 Mon Sep 17 00:00:00 2001
From: Cobus van Eeden <35851496+cobusve@users.noreply.github.com>
Date: Wed, 26 Aug 2020 13:07:15 -0700
Subject: [PATCH 01/40] Updating queue.c patches for CBMC proofs (#216)
---
...emove-static-from-prvCopyDataToQueue.patch | 26 +++++++++----------
...atic-from-prvNotifyQueueSetContainer.patch | 2 +-
2 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/FreeRTOS/Test/CBMC/patches/0005-remove-static-from-prvCopyDataToQueue.patch b/FreeRTOS/Test/CBMC/patches/0005-remove-static-from-prvCopyDataToQueue.patch
index 5a79ae8cd4..e081f47252 100644
--- a/FreeRTOS/Test/CBMC/patches/0005-remove-static-from-prvCopyDataToQueue.patch
+++ b/FreeRTOS/Test/CBMC/patches/0005-remove-static-from-prvCopyDataToQueue.patch
@@ -1,22 +1,22 @@
diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c
-index df2b9c8c..c2265c26 100644
+index edd08b26e..8fa137c9b 100644
--- a/FreeRTOS/Source/queue.c
+++ b/FreeRTOS/Source/queue.c
-@@ -105,7 +105,7 @@ static BaseType_t prvIsQueueFull( const Queue_t *pxQueue ) PRIVILEGED_FUNCTION;
+@@ -191,7 +191,7 @@ static BaseType_t prvIsQueueFull( const Queue_t * pxQueue ) PRIVILEGED_FUNCTION;
* Copies an item into the queue, either at the front of the queue or the
* back of the queue.
*/
--static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition ) PRIVILEGED_FUNCTION;
-+BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvItemToQueue, const BaseType_t xPosition ) PRIVILEGED_FUNCTION;
-
- /*
- * Copies an item out of a queue.
-@@ -1985,7 +1985,7 @@ Queue_t * const pxQueue = xQueue;
+-static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
++BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition ) PRIVILEGED_FUNCTION;
+
+@@ -2120,7 +2120,7 @@ void vQueueDelete( QueueHandle_t xQueue )
#endif /* configUSE_MUTEXES */
/*-----------------------------------------------------------*/
-
--static 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 )
+
+-static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
++BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue,
+ const void * pvItemToQueue,
+ const BaseType_t xPosition )
{
- BaseType_t xReturn = pdFALSE;
- UBaseType_t uxMessagesWaiting;
diff --git a/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch b/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch
index 9cbe7cf5f7..bcbd2b5cbd 100644
--- a/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch
+++ b/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch
@@ -11,7 +11,7 @@ index 17a6964e..24a40c29 100644
#endif
/*
-@@ -2887,7 +2887,7 @@ Queue_t * const pxQueue = xQueue;
+@@ -2957,7 +2957,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
#if ( configUSE_QUEUE_SETS == 1 )
From 4a026fd703f945d4f5c2f3c3b866a53a53a31cb9 Mon Sep 17 00:00:00 2001
From: Cobus van Eeden <35851496+cobusve@users.noreply.github.com>
Date: Wed, 26 Aug 2020 23:50:09 -0700
Subject: [PATCH 02/40] Move forward Kernel submodule pointer (#218)
* Move forward Kernel submodule pointer
* Fixing patches for CBMC proofs
* Update proofs to assume cTxLock != 127
* Update proofs to assume cRxLock != 127
---
FreeRTOS-Plus/Test/CBMC/include/queue_init.h | 4 ++
FreeRTOS/Source | 2 +-
FreeRTOS/Test/CBMC/include/queue_init.h | 5 ++
...atile-qualifier-from-tasks-variables.patch | 47 +++++++++----------
...atic-from-prvNotifyQueueSetContainer.patch | 14 +++---
.../prvNotifyQueueSetContainer_harness.c | 1 +
.../prvUnlockQueue/prvUnlockQueue_harness.c | 1 +
7 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/FreeRTOS-Plus/Test/CBMC/include/queue_init.h b/FreeRTOS-Plus/Test/CBMC/include/queue_init.h
index f05d18830e..10b7e5607f 100644
--- a/FreeRTOS-Plus/Test/CBMC/include/queue_init.h
+++ b/FreeRTOS-Plus/Test/CBMC/include/queue_init.h
@@ -43,6 +43,7 @@
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();
@@ -73,6 +74,7 @@ QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound )
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.
@@ -105,6 +107,7 @@ QueueHandle_t xUnconstrainedQueue( void ) {
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.
@@ -126,6 +129,7 @@ QueueHandle_t xUnconstrainedMutex( void ) {
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.
diff --git a/FreeRTOS/Source b/FreeRTOS/Source
index 6199b72fbf..805b15a022 160000
--- a/FreeRTOS/Source
+++ b/FreeRTOS/Source
@@ -1 +1 @@
-Subproject commit 6199b72fbf57a7c5b3d7b195a3bd1446779314cd
+Subproject commit 805b15a0224672bc89b2effffb7ab4c1debc7325
diff --git a/FreeRTOS/Test/CBMC/include/queue_init.h b/FreeRTOS/Test/CBMC/include/queue_init.h
index f05d18830e..1ec75cb489 100644
--- a/FreeRTOS/Test/CBMC/include/queue_init.h
+++ b/FreeRTOS/Test/CBMC/include/queue_init.h
@@ -43,6 +43,7 @@
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();
@@ -73,7 +74,9 @@ QueueHandle_t xUnconstrainedQueueBoundedItemSize( UBaseType_t uxItemSizeBound )
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*/
@@ -105,6 +108,7 @@ QueueHandle_t xUnconstrainedQueue( void ) {
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.
@@ -126,6 +130,7 @@ QueueHandle_t xUnconstrainedMutex( void ) {
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.
diff --git a/FreeRTOS/Test/CBMC/patches/0005-Remove-volatile-qualifier-from-tasks-variables.patch b/FreeRTOS/Test/CBMC/patches/0005-Remove-volatile-qualifier-from-tasks-variables.patch
index 29cde0e774..7eb4870a07 100644
--- a/FreeRTOS/Test/CBMC/patches/0005-Remove-volatile-qualifier-from-tasks-variables.patch
+++ b/FreeRTOS/Test/CBMC/patches/0005-Remove-volatile-qualifier-from-tasks-variables.patch
@@ -45,35 +45,32 @@ diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c
index ff657733..8b57d198 100644
--- a/FreeRTOS/Source/tasks.c
+++ b/FreeRTOS/Source/tasks.c
-@@ -331,7 +331,7 @@ typedef tskTCB TCB_t;
+@@ -335,7 +335,7 @@ typedef tskTCB TCB_t;
/*lint -save -e956 A manual analysis and inspection has been used to determine
- which static variables must be declared volatile. */
+ * which static variables must be declared volatile. */
-PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;
+PRIVILEGED_DATA TCB_t * pxCurrentTCB = NULL;
/* Lists for ready and blocked tasks. --------------------
- xDelayedTaskList1 and xDelayedTaskList2 could be move to function scople but
-@@ -340,8 +340,8 @@ the static qualifier. */
- PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */
- PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */
- PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
--PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
--PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
-+PRIVILEGED_DATA static List_t * pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
-+PRIVILEGED_DATA static List_t * pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
- PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */
+ * xDelayedTaskList1 and xDelayedTaskList2 could be move to function scople but
+@@ -344,8 +344,8 @@ PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;
+ PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ]; /*< Prioritised ready tasks. */
+ PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */
+ PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
+-PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
+-PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
++PRIVILEGED_DATA static List_t * pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
++PRIVILEGED_DATA static List_t * pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
+ PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */
- #if( INCLUDE_vTaskDelete == 1 )
-@@ -368,10 +368,10 @@ PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseTyp
-
- /* Other file private variables. --------------------------------*/
- PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
- PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;
- PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;
- PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;
--PRIVILEGED_DATA static volatile TickType_t xPendedTicks = ( TickType_t ) 0U;
-+PRIVILEGED_DATA static TickType_t xPendedTicks = ( TickType_t ) 0U;
- PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE;
- PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0;
- PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U;
+ #if ( INCLUDE_vTaskDelete == 1 )
+@@ -372,7 +372,7 @@ PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType
+ PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;
+ PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;
+ PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;
+-PRIVILEGED_DATA static volatile TickType_t xPendedTicks = ( TickType_t ) 0U;
++PRIVILEGED_DATA static TickType_t xPendedTicks = ( TickType_t ) 0U;
+ PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE;
+ PRIVILEGED_DATA static volatile BaseType_t xNumOfOverflows = ( BaseType_t ) 0;
+ PRIVILEGED_DATA static UBaseType_t uxTaskNumber = ( UBaseType_t ) 0U;
diff --git a/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch b/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch
index bcbd2b5cbd..bb8e724d74 100644
--- a/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch
+++ b/FreeRTOS/Test/CBMC/patches/0006-Remove-static-from-prvNotifyQueueSetContainer.patch
@@ -12,11 +12,11 @@ index 17a6964e..24a40c29 100644
/*
@@ -2957,7 +2957,7 @@ BaseType_t xQueueIsQueueFullFromISR( const QueueHandle_t xQueue )
-
+
#if ( configUSE_QUEUE_SETS == 1 )
-
-- static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
-+ BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
- {
- Queue_t *pxQueueSetContainer = pxQueue->pxQueueSetContainer;
- BaseType_t xReturn = pdFALSE;
+
+- static BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
++ BaseType_t prvNotifyQueueSetContainer( const Queue_t * const pxQueue )
+ {
+ Queue_t * pxQueueSetContainer = pxQueue->pxQueueSetContainer;
+ BaseType_t xReturn = pdFALSE;
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c
index e9575adabd..46372c8953 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/prvNotifyQueueSetContainer/prvNotifyQueueSetContainer_harness.c
@@ -61,6 +61,7 @@ QueueSetHandle_t xUnconstrainedQueueSet()
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();
diff --git a/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c b/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c
index 1db4249982..04fb980207 100644
--- a/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c
+++ b/FreeRTOS/Test/CBMC/proofs/Queue/prvUnlockQueue/prvUnlockQueue_harness.c
@@ -62,6 +62,7 @@ QueueSetHandle_t xUnconstrainedQueueSet()
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();
From a9680a54cfd07cd35070301f284ab0c9c54cbf7e Mon Sep 17 00:00:00 2001
From: RichardBarry <3073890+RichardBarry@users.noreply.github.com>
Date: Thu, 27 Aug 2020 00:40:47 -0700
Subject: [PATCH 03/40] Fix warnings after moving callback prototypes (#208)
* Recently the prototypes for the application hook functions were
moved out of the kernel .c files and into the .h files. That
changes results in compile time warnings for projects that provide
hook functions with a slightly different prototype - in particular
where signed char * is used in place of just char * as an older
FreeRTOS coding convention required chars to be explicitly qualified
as signed or unsigned.
This checkin fixes the warnings by ensuring the signature of
implemented hook functions matches the signature of the prototypes.
---
.../RTOSDemo/main.c | 4 +-
FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c | 6 +-
FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c | 4 +-
.../RTOSDemo/main.c | 14 ++---
.../Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c | 4 +-
FreeRTOS/Demo/AVR_Dx_IAR/main.c | 6 +-
FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c | 2 +-
.../.settings/language.settings.xml | 2 +-
FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c | 6 +-
FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c | 6 +-
.../Projects/IAR/NonSecure/main_ns.c | 2 +-
.../Projects/Keil/NonSecure/main_ns.c | 2 +-
.../Projects/MCUXpresso/NonSecure/main_ns.c | 2 +-
.../NonSecure/main_ns.c | 2 +-
.../sources/main.c | 2 +-
.../ColdFire_MCF52233_Eclipse/RTOSDemo/main.c | 2 +-
.../Demo/ColdFire_MCF52259_CodeWarrior/main.c | 2 +-
FreeRTOS/Demo/NEC_78K0R_IAR/main.c | 61 ++++++++++---------
FreeRTOS/Demo/NEC_V850ES_IAR/main.c | 39 ++++++------
.../RTOSDemo/main.c | 55 +++++++++--------
.../RTOSDemo/main.c | 4 +-
.../RTOSDemo/main.c | 4 +-
.../PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c | 4 +-
23 files changed, 122 insertions(+), 113 deletions(-)
diff --git a/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c b/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c
index aa2dd84d93..e7e32f0943 100644
--- a/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/main.c
@@ -51,7 +51,7 @@ int main( void )
#elif ( mainSELECTED_APPLICATION == 2 )
main_full();
#endif
-
+
return 0;
}
@@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this
hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in
"FreeRTOSConfig.h" header file. */
-// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName )
+// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName )
// {
// for( ;; );
// }
diff --git a/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c b/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c
index 27e816e106..a19870dc52 100644
--- a/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c
+++ b/FreeRTOS/Demo/AVR_ATMega4809_IAR/main.c
@@ -43,7 +43,7 @@ extern void init_full( void );
int main( void )
{
prvSetupHardware();
-
+
#if ( mainSELECTED_APPLICATION == 0 )
main_blinky();
#elif ( mainSELECTED_APPLICATION == 1 )
@@ -51,7 +51,7 @@ int main( void )
#elif ( mainSELECTED_APPLICATION == 2 )
main_full();
#endif
-
+
return 0;
}
@@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this
hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in
"FreeRTOSConfig.h" header file. */
-// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName )
+// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName )
// {
// for( ;; );
// }
diff --git a/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c b/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c
index aa2dd84d93..e7e32f0943 100644
--- a/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c
+++ b/FreeRTOS/Demo/AVR_ATMega4809_MPLAB.X/main.c
@@ -51,7 +51,7 @@ int main( void )
#elif ( mainSELECTED_APPLICATION == 2 )
main_full();
#endif
-
+
return 0;
}
@@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this
hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in
"FreeRTOSConfig.h" header file. */
-// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName )
+// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName )
// {
// for( ;; );
// }
diff --git a/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c
index fe5702f05c..1a968b2652 100644
--- a/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/AVR_ATmega328PB_Xplained_mini_GCC/RTOSDemo/main.c
@@ -59,10 +59,10 @@ int main(void)
/* Initializes MCU, drivers and middleware.
This is generated from Atmel START project. */
atmel_start_init();
-
+
/* Standard register test. */
vStartRegTestTasks();
-
+
/* Optionally enable below tests. This port only has 2KB RAM. */
vStartIntegerMathTasks( tskIDLE_PRIORITY );
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
@@ -102,7 +102,7 @@ BaseType_t xFirstTimeCheck = pdTRUE;
{
uxErrorHasOccurred |= ( 0x01U << 2);
}
-
+
/* When check task runs before any other tasks, all above checks shall fail.
To avoid false alarm, clear errors upon first entry. */
if ( xFirstTimeCheck == pdTRUE )
@@ -110,7 +110,7 @@ BaseType_t xFirstTimeCheck = pdTRUE;
uxErrorHasOccurred = 0;
xFirstTimeCheck = pdFALSE;
}
-
+
/* Could set break point at below line to verify uxErrorHasOccurred. */
vTaskDelay( mainCHECK_PERIOD );
}
@@ -126,7 +126,7 @@ static void vBlinkOnboardUserLED( void *pvParameters )
for( ;; )
{
vParTestToggleLED( 0 );
-
+
vTaskDelay( mainBLINK_LED_OK_HALF_PERIOD );
}
@@ -141,9 +141,9 @@ void vApplicationIdleHook( void )
/*-----------------------------------------------------------*/
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
- /* When stack overflow happens, trap instead of attempting to recover.
+ /* When stack overflow happens, trap instead of attempting to recover.
Read input arguments to learn about the offending task. */
for( ;; )
{
diff --git a/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c b/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c
index aa2dd84d93..e7e32f0943 100644
--- a/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/AVR_Dx_Atmel_Studio/RTOSDemo/main.c
@@ -51,7 +51,7 @@ int main( void )
#elif ( mainSELECTED_APPLICATION == 2 )
main_full();
#endif
-
+
return 0;
}
@@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this
hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in
"FreeRTOSConfig.h" header file. */
-// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName )
+// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName )
// {
// for( ;; );
// }
diff --git a/FreeRTOS/Demo/AVR_Dx_IAR/main.c b/FreeRTOS/Demo/AVR_Dx_IAR/main.c
index 27e816e106..a19870dc52 100644
--- a/FreeRTOS/Demo/AVR_Dx_IAR/main.c
+++ b/FreeRTOS/Demo/AVR_Dx_IAR/main.c
@@ -43,7 +43,7 @@ extern void init_full( void );
int main( void )
{
prvSetupHardware();
-
+
#if ( mainSELECTED_APPLICATION == 0 )
main_blinky();
#elif ( mainSELECTED_APPLICATION == 1 )
@@ -51,7 +51,7 @@ int main( void )
#elif ( mainSELECTED_APPLICATION == 2 )
main_full();
#endif
-
+
return 0;
}
@@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this
hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in
"FreeRTOSConfig.h" header file. */
-// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName )
+// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName )
// {
// for( ;; );
// }
diff --git a/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c b/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c
index aa2dd84d93..8d7412fe11 100644
--- a/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c
+++ b/FreeRTOS/Demo/AVR_Dx_MPLAB.X/main.c
@@ -78,7 +78,7 @@ This is usefull in application development, for debugging. To use this
hook, uncomment it, and set configCHECK_FOR_STACK_OVERFLOW to 1 in
"FreeRTOSConfig.h" header file. */
-// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName )
+// void vApplicationStackOverflowHook(TaskHandle_t *pxTask, char *pcTaskName )
// {
// for( ;; );
// }
diff --git a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml
index fe0e11ea46..19d9a19240 100644
--- a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml
+++ b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
diff --git a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c
index 13443156d4..29d9d3031f 100644
--- a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c
+++ b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/main.c
@@ -158,7 +158,7 @@ extern void vSetupHighFrequencyTimer( void );
/*
* Hook functions that can get called by the kernel.
*/
-void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName );
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
void vApplicationTickHook( void );
/*
@@ -379,8 +379,8 @@ void ( *vOLEDClear )( void ) = NULL;
}
/*-----------------------------------------------------------*/
-volatile signed char *pcOverflowedTask = NULL; /* Prevent task name being optimised away. */
-void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
+volatile char *pcOverflowedTask = NULL; /* Prevent task name being optimised away. */
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
( void ) pxTask;
pcOverflowedTask = pcTaskName;
diff --git a/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c b/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c
index 4e39a252c0..e0be52c690 100644
--- a/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c
+++ b/FreeRTOS/Demo/CORTEX_LM3Sxxxx_IAR_Keil/main.c
@@ -185,7 +185,7 @@ extern void vSetupHighFrequencyTimer( void );
/*
* Hook functions that can get called by the kernel.
*/
-void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName );
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
void vApplicationTickHook( void );
static void prvPrintString( const char * pcString );
@@ -453,8 +453,8 @@ void ( *vOLEDClear )( void ) = NULL;
}
/*-----------------------------------------------------------*/
-volatile signed char *pcOverflowedTask = NULL;
-void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
+volatile char *pcOverflowedTask = NULL;
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
( void ) pxTask;
pcOverflowedTask = pcTaskName;
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c
index 47ddbf6015..39151caaf4 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c
+++ b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/IAR/NonSecure/main_ns.c
@@ -88,7 +88,7 @@ static void prvCreateTasks( void )
/*-----------------------------------------------------------*/
/* Stack overflow hook. */
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
/* Force an assert. */
configASSERT( pcTaskName == 0 );
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c
index 757524f01a..6f63f48eb9 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c
+++ b/FreeRTOS/Demo/CORTEX_MPU_M23_Nuvoton_NuMaker_PFM_M2351_IAR_GCC/Projects/Keil/NonSecure/main_ns.c
@@ -131,7 +131,7 @@ static void prvCreateTasks( void )
/*-----------------------------------------------------------*/
/* Stack overflow hook. */
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
/* Force an assert. */
configASSERT( pcTaskName == 0 );
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c
index 834fbe80f3..e426bf5b03 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/NonSecure/main_ns.c
@@ -101,7 +101,7 @@ void SystemInit( void )
/*-----------------------------------------------------------*/
/* Stack overflow hook. */
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
/* Force an assert. */
configASSERT( pcTaskName == 0 );
diff --git a/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c b/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c
index da49146546..c0eb37de3d 100644
--- a/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c
+++ b/FreeRTOS/Demo/CORTEX_MPU_M33F_Simulator_Keil_GCC/NonSecure/main_ns.c
@@ -126,7 +126,7 @@ static void prvCreateTasks( void )
/*-----------------------------------------------------------*/
/* Stack overflow hook. */
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
/* Force an assert. */
configASSERT( pcTaskName == 0 );
diff --git a/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c b/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c
index ebdf052714..39f9556961 100644
--- a/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c
+++ b/FreeRTOS/Demo/ColdFire_MCF52221_CodeWarrior/sources/main.c
@@ -238,7 +238,7 @@ void prvSetupHardware( void )
}
/*-----------------------------------------------------------*/
-void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
/* This will get called if a stack overflow is detected during the context
switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
diff --git a/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c b/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c
index 562aa911e0..99b2830eab 100644
--- a/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/main.c
@@ -285,7 +285,7 @@ static const unsigned long _cfm[6] = {
}
/*-----------------------------------------------------------*/
-void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
{
/* This will get called if a stack overflow is detected during the context
switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
diff --git a/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c b/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c
index 9b3fe51082..5d331d33dc 100644
--- a/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c
+++ b/FreeRTOS/Demo/ColdFire_MCF52259_CodeWarrior/main.c
@@ -253,7 +253,7 @@ void prvSetupHardware( void )
}
/*-----------------------------------------------------------*/
-void vApplicationStackOverflowHook( TaskHandle_t *pxTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
/* This will get called if a stack overflow is detected during the context
switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
diff --git a/FreeRTOS/Demo/NEC_78K0R_IAR/main.c b/FreeRTOS/Demo/NEC_78K0R_IAR/main.c
index ecc2223b6d..00b5d3b6fa 100644
--- a/FreeRTOS/Demo/NEC_78K0R_IAR/main.c
+++ b/FreeRTOS/Demo/NEC_78K0R_IAR/main.c
@@ -150,11 +150,11 @@ short main( void )
/* Create the RegTest tasks as described at the top of this file. */
xTaskCreate( vRegTest1, "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
- xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
-
+ xTaskCreate( vRegTest2, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
+
/* Create the button push task as described at the top of this file. */
- xTaskCreate( vButtonTask, "Button", configMINIMAL_STACK_SIZE, NULL, mainBUTTON_PRIORITY, NULL );
-
+ xTaskCreate( vButtonTask, "Button", configMINIMAL_STACK_SIZE, NULL, mainBUTTON_PRIORITY, NULL );
+
/* Create the 'check' task as described at the top of this file. */
xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, ( void* )mainCHECK_PARAMETER_VALUE, mainCHECK_TASK_PRIORITY, NULL );
@@ -167,7 +167,7 @@ short main( void )
vCreateBlockTimeTasks();
}
#endif
-
+
/* Finally start the scheduler running. */
vTaskStartScheduler();
@@ -218,24 +218,24 @@ TickType_t xToggleRate = mainNO_ERROR_TOGGLE_PERIOD, xLastWakeTime;
{
xToggleRate = mainERROR_TOGGLE_PERIOD;
}
-
+
if( xAreSemaphoreTasksStillRunning() != pdTRUE)
{
xToggleRate = mainERROR_TOGGLE_PERIOD;
}
-
+
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
{
xToggleRate = mainERROR_TOGGLE_PERIOD;
- }
-
+ }
+
if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
{
xToggleRate = mainERROR_TOGGLE_PERIOD;
- }
+ }
}
#endif
-
+
/* Toggle the LED. The toggle rate will depend on whether or not an
error has been found in any tasks. */
mainLED_0 = !mainLED_0;
@@ -281,24 +281,24 @@ unsigned char ucResetFlag = RESF;
X1 and X2 pin in crystal resonator mode
High speed oszillation frequency 10MHz < fMX <= 20MHz */
CMC = 0x41;
-
+
/* Set oscillation stabilization time. */
OSTS = 0x07;
-
+
/* Set speed mode: fMX > 10MHz for Flash memory high speed operation. */
OSMC = 0x01;
-
+
/* Start up X1 oscillator operation
Internal high-speed oscillator operating. */
MSTOP = 0;
-
+
/* Check oscillation stabilization time status. */
while(OSTC < 0x07)
{
/* Wait until X1 clock stabilization time. */
portNOP();
}
-
+
/* Switch CPU clock to X1 oscillator. */
MCM0 = 1;
while(MCS != 1)
@@ -309,10 +309,10 @@ unsigned char ucResetFlag = RESF;
/* Stop the internal high-speed oscillator operation. */
HIOSTOP = 1;
-
+
/* Stop the XT1 oscillator operation. */
XTSTOP = 1;
-
+
/* Operating frequency f = fx
Change clock generator setting, if necessary. */
CKC &= 0xF8;
@@ -320,31 +320,31 @@ unsigned char ucResetFlag = RESF;
/* From here onwards the X1 oscillator is supplied to the CPU. */
}
#endif
-
+
/* LED port initialization - set port register. */
P7 = 0x80;
-
+
/* Set port mode register. */
PM7 = 0x3F;
-
+
/* Switch pin initialization - enable pull-up resistor. */
PU12_bit.no0 = 1;
/* INTP0 is used by the button on the target board. */
-
+
/* INTP0 disable. */
- PMK0 = 1;
-
+ PMK0 = 1;
+
/* INTP0 IF clear. */
- PIF0 = 0;
+ PIF0 = 0;
EGN0_bit.no0 = 1;
-
+
/* INTP0 priority low. */
PPR10 = 0;
PPR00 = 1;
-
+
/* Enable ext. INTP0 interrupt */
- PMK0 = 0;
+ PMK0 = 0;
return pdTRUE;
}
@@ -362,8 +362,11 @@ void vRegTestError( void )
}
/*-----------------------------------------------------------*/
-void vApplicationStackOverflowHook( void )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
+ ( void ) xTask;
+ ( void ) pcTaskName;
+
/* This will get called if an overflow is detected in the stack of a task.
Inspect pxCurrentTCB to see which was the offending task. */
for( ;; );
diff --git a/FreeRTOS/Demo/NEC_V850ES_IAR/main.c b/FreeRTOS/Demo/NEC_V850ES_IAR/main.c
index 684bf5d6a2..fec73376e4 100644
--- a/FreeRTOS/Demo/NEC_V850ES_IAR/main.c
+++ b/FreeRTOS/Demo/NEC_V850ES_IAR/main.c
@@ -124,7 +124,7 @@ void main( void )
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
vStartQueuePeekTasks();
-
+
/* Create the check task as described at the top of this file. */
xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, mainCHECK_PARAMETER, mainCHECK_TASK_PRIORITY, NULL );
@@ -135,22 +135,22 @@ void main( void )
#ifdef __IAR_V850ES_Fx3__
{
/* The extra IO required for the com test and led flashing tasks is only
- available on the application board, not the target boards. */
+ available on the application board, not the target boards. */
vAltStartComTestTasks( mainCOMTEST_PRIORITY, mainBAUD_RATE, mainCOMTEST_LED );
vStartLEDFlashTasks( mainFLASH_PRIORITY );
-
+
/* The Fx3 also has enough RAM to run loads more tasks. */
vStartRecursiveMutexTasks();
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
- vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
+ vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
}
- #endif
-
+ #endif
+
/* The suicide tasks must be created last as they need to know how many
tasks were running prior to their creation in order to ascertain whether
or not the correct/expected number of tasks are running at any given time. */
vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
-
+
/* Start the scheduler. */
vTaskStartScheduler();
@@ -170,23 +170,23 @@ unsigned portBASE_TYPE uxLEDToUse = 0;
{
xDelayPeriod = mainERROR_DELAY;
}
-
+
/* Initialise xLastWakeTime before it is used. After this point it is not
written to directly. */
xLastWakeTime = xTaskGetTickCount();
-
+
/* Cycle for ever, delaying then checking all the other tasks are still
operating without error. */
for( ;; )
{
/* Wait until it is time to check all the other tasks again. */
vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );
-
+
if( lRegTestStatus != pdPASS )
{
xDelayPeriod = mainERROR_DELAY;
}
-
+
if( xAreGenericQueueTasksStillRunning() != pdTRUE )
{
xDelayPeriod = mainERROR_DELAY;
@@ -207,14 +207,14 @@ unsigned portBASE_TYPE uxLEDToUse = 0;
xDelayPeriod = mainERROR_DELAY;
}
- /* The Fx3 runs more tasks, so more checks are performed. */
+ /* The Fx3 runs more tasks, so more checks are performed. */
#ifdef __IAR_V850ES_Fx3__
{
if( xAreComTestTasksStillRunning() != pdTRUE )
{
xDelayPeriod = mainERROR_DELAY;
}
-
+
if( xArePollingQueuesStillRunning() != pdTRUE )
{
xDelayPeriod = mainERROR_DELAY;
@@ -224,12 +224,12 @@ unsigned portBASE_TYPE uxLEDToUse = 0;
{
xDelayPeriod = mainERROR_DELAY;
}
-
+
if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
{
xDelayPeriod = mainERROR_DELAY;
- }
-
+ }
+
/* The application board has more LEDs and uses the flash tasks
so the check task instead uses LED3 as LED3 is still spare. */
uxLEDToUse = 3;
@@ -252,8 +252,11 @@ static void prvSetupHardware( void )
}
/*-----------------------------------------------------------*/
-void vApplicationStackOverflowHook( void )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
+ ( void ) xTask;
+ ( void ) pcTaskName;
+
/* This will be called if a task overflows its stack. pxCurrentTCB
can be inspected to see which is the offending task. */
for( ;; );
@@ -265,7 +268,7 @@ void vRegTestFailed( void )
/* Called by the RegTest tasks if an error is found. lRegTestStatus is
inspected by the check task. */
lRegTestStatus = pdFAIL;
-
+
/* Do not return from here as the reg test tasks clobber all registers so
function calls may not function correctly. */
for( ;; );
diff --git a/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c
index b91d78da83..bf37aaa3d9 100644
--- a/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/NiosII_CycloneIII_DBC3C40_GCC/RTOSDemo/main.c
@@ -31,13 +31,13 @@
* defined and/or created within this file:
*
* "Check" task - This only executes every five seconds but has the highest
- * priority so is guaranteed to get processor time. Its main function is to
+ * priority so is guaranteed to get processor time. Its main function is to
* check that all the standard demo tasks are still operational. The check
* task will write an error message to the console should an error be detected
* within any of the demo tasks. The check task also toggles the LED defined
* by mainCHECK_LED every 5 seconds while the system is error free, with the
* toggle rate increasing to every 500ms should an error occur.
- *
+ *
* "Reg test" tasks - These fill the registers with known values, then check
* that each register still contains its expected value. Each task uses
* different values. The tasks run with very low priority so get preempted very
@@ -92,7 +92,7 @@ error has been detected. */
/* The LED toggled by the Check task. */
#define mainCHECK_LED ( 7 )
-/* The first LED used by the ComTest tasks. One LED toggles each time a
+/* The first LED used by the ComTest tasks. One LED toggles each time a
character is transmitted, and one each time a character is received and
verified as being the expected character. */
#define mainCOMTEST_LED ( 4 )
@@ -125,7 +125,7 @@ static void prvSetupHardware( void );
/*
* Execute all of the check functions to ensure the tests haven't failed.
- */
+ */
static void prvCheckTask( void *pvParameters );
/*
@@ -149,7 +149,7 @@ int main( void )
{
/* Configure any hardware required for this demo. */
prvSetupHardware();
-
+
/* Create all the other standard demo tasks. These serve no purpose other
than to test the port and demonstrate the use of the FreeRTOS API. */
vStartLEDFlashTasks( tskIDLE_PRIORITY );
@@ -164,10 +164,10 @@ int main( void )
vStartCountingSemaphoreTasks();
vStartRecursiveMutexTasks();
vAltStartComTestTasks( mainCOM_TEST_PRIORITY, 0, mainCOMTEST_LED );
-
+
/* prvCheckTask uses sprintf so requires more stack. */
xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
-
+
/* The RegTest tasks as described at the top of this file. */
xTaskCreate( prvFirstRegTestTask, "Rreg1", configMINIMAL_STACK_SIZE, mainREG_TEST_1_PARAMETER, mainREG_TEST_PRIORITY, NULL );
xTaskCreate( prvSecondRegTestTask, "Rreg2", configMINIMAL_STACK_SIZE, mainREG_TEST_2_PARAMETER, mainREG_TEST_PRIORITY, NULL );
@@ -178,7 +178,7 @@ int main( void )
/* Finally start the scheduler. */
vTaskStartScheduler();
-
+
/* Will only reach here if there is insufficient heap available to start
the scheduler. */
for( ;; );
@@ -192,8 +192,11 @@ static void prvSetupHardware( void )
}
/*-----------------------------------------------------------*/
-void vApplicationStackOverflowHook( void )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
+ ( void ) xTask;
+ ( void ) pcTaskName;
+
/* Look at pxCurrentTCB to see which task overflowed its stack. */
for( ;; )
{
@@ -204,7 +207,7 @@ void vApplicationStackOverflowHook( void )
void _general_exception_handler( unsigned long ulCause, unsigned long ulStatus )
{
- /* This overrides the definition provided by the kernel. Other exceptions
+ /* This overrides the definition provided by the kernel. Other exceptions
should be handled here. */
for( ;; )
{
@@ -227,8 +230,8 @@ const char * pcMessage;
{
/* Wait until it is time to run the tests again. */
vTaskDelayUntil( &xLastExecutionTime, ulTicksToWait );
-
- /* Have any of the standard demo tasks detected an error in their
+
+ /* Have any of the standard demo tasks detected an error in their
operation? */
if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
{
@@ -300,7 +303,7 @@ const char * pcMessage;
else if( ulLastRegTest2 == ulRegTest2Counter )
{
/* ulRegTest2Counter is no longer being incremented, indicating
- that an error has been discovered in prvSecondRegTestTask(). */
+ that an error has been discovered in prvSecondRegTestTask(). */
ulTicksToWait = mainERROR_PERIOD;
pcMessage = "Error: Reg Test2.\n";
}
@@ -308,19 +311,19 @@ const char * pcMessage;
{
pcMessage = NULL;
}
-
+
/* Remember the counter values this time around so a counter failing
to be incremented correctly can be spotted. */
ulLastRegTest1 = ulRegTest1Counter;
ulLastRegTest2 = ulRegTest2Counter;
-
- /* Print out an error message if there is one. Mutual exclusion is
+
+ /* Print out an error message if there is one. Mutual exclusion is
not used as this is the only task accessing stdout. */
if( pcMessage != NULL )
{
printf( pcMessage );
}
-
+
/* Provide visual feedback of the system status. If the LED is toggled
every 5 seconds then no errors have been found. If the LED is toggled
every 500ms then at least one error has been found. */
@@ -334,17 +337,17 @@ static void prvFirstRegTestTask( void *pvParameters )
/* Check the parameters are passed in as expected. */
if( pvParameters != mainREG_TEST_1_PARAMETER )
{
- /* Don't execute any further so an error is recognised by the check
+ /* Don't execute any further so an error is recognised by the check
task. */
vTaskDelete( NULL );
}
-
+
/* Fill registers with known values, then check that each register still
contains its expected value. An incorrect value is indicative of an error
- in the context switching process.
-
+ in the context switching process.
+
If no errors are found ulRegTest1Counter is incremented. The check task
- will recognise an error if ulRegTest1Counter stops being incremented.
+ will recognise an error if ulRegTest1Counter stops being incremented.
This task also performs a manual yield in the middle of its execution, just
to increase the test coverage. */
asm volatile (
@@ -438,15 +441,15 @@ static void prvSecondRegTestTask( void *pvParameters )
/* Check the parameters are passed in as expected. */
if( pvParameters != mainREG_TEST_2_PARAMETER )
{
- /* Don't execute any further so an error is recognised by the check
+ /* Don't execute any further so an error is recognised by the check
task. */
vTaskDelete( NULL );
}
-
+
/* Fill registers with known values, then check that each register still
contains its expected value. An incorrect value is indicative of an error
- in the context switching process.
-
+ in the context switching process.
+
If no errors are found ulRegTest2Counter is incremented. The check task
will recognise an error if ulRegTest2Counter stops being incremented. */
asm volatile (
diff --git a/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
index 5fedf1f785..482a284908 100644
--- a/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/PPC440_DP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
@@ -653,8 +653,8 @@ static void prvRegTestTask2( void *pvParameters )
/* This hook function will get called if there is a suspected stack overflow.
An overflow can cause the task name to be corrupted, in which case the task
handle needs to be used to determine the offending task. */
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName );
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
/* To prevent the optimiser removing the variables. */
volatile TaskHandle_t xTaskIn = xTask;
diff --git a/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
index 25dad61d80..03e652bbdf 100644
--- a/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/main.c
@@ -653,8 +653,8 @@ static void prvRegTestTask2( void *pvParameters )
/* This hook function will get called if there is a suspected stack overflow.
An overflow can cause the task name to be corrupted, in which case the task
handle needs to be used to determine the offending task. */
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName );
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
/* To prevent the optimiser removing the variables. */
volatile TaskHandle_t xTaskIn = xTask;
diff --git a/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c b/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c
index 66a65e55a1..d94ab8190f 100644
--- a/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c
+++ b/FreeRTOS/Demo/PPC440_Xilinx_Virtex5_GCC/RTOSDemo/main.c
@@ -659,8 +659,8 @@ static void prvRegTestTask2( void *pvParameters )
/* This hook function will get called if there is a suspected stack overflow.
An overflow can cause the task name to be corrupted, in which case the task
handle needs to be used to determine the offending task. */
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName );
-void vApplicationStackOverflowHook( TaskHandle_t xTask, signed char *pcTaskName )
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName );
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
/* To prevent the optimiser removing the variables. */
volatile TaskHandle_t xTaskIn = xTask;
From 638262fab193f1ba4d67eaf76db36783db43aedc Mon Sep 17 00:00:00 2001
From: alfred gedeon
Date: Thu, 27 Aug 2020 00:41:42 -0700
Subject: [PATCH 04/40] Fix Posix demo build and remove src directory (#213)
* Fix: build errors, remove src directory and bring all files up
* Fix: Remove not needed header
* Doc: fix main comments
* Doc: fix comment
Co-authored-by: Alfred Gedeon
---
.../NetworkInterface/linux/NetworkInterface.c | 1 -
.../Demo/Posix_GCC/{src => }/FreeRTOSConfig.h | 0
.../Posix_GCC/{src => }/FreeRTOSIPConfig.h | 614 +++++++--------
FreeRTOS/Demo/Posix_GCC/{src => }/SConscript | 0
FreeRTOS/Demo/Posix_GCC/SConstruct | 10 +-
.../Posix_GCC/{src => }/SimpleTCPEchoServer.c | 576 +++++++-------
.../{src => }/TCPEchoClient_SingleTasks.c | 744 +++++++++---------
.../{src => }/TCPEchoClient_SingleTasks.h | 80 +-
.../{src => }/code_coverage_additions.c | 0
FreeRTOS/Demo/Posix_GCC/{src => }/console.c | 0
FreeRTOS/Demo/Posix_GCC/{src => }/console.h | 0
FreeRTOS/Demo/Posix_GCC/{src => }/main.c | 38 +-
.../Demo/Posix_GCC/{src => }/main_blinky.c | 0
FreeRTOS/Demo/Posix_GCC/{src => }/main_full.c | 0
.../Posix_GCC/{src => }/main_networking.c | 0
.../{src => }/run-time-stats-utils.c | 0
FreeRTOS/Demo/Posix_GCC/{src => }/trcConfig.h | 2 +-
.../Posix_GCC/{src => }/trcSnapshotConfig.h | 0
.../{src => }/utils/wait_for_event.c | 0
.../{src => }/utils/wait_for_event.h | 0
20 files changed, 1035 insertions(+), 1030 deletions(-)
rename FreeRTOS/Demo/Posix_GCC/{src => }/FreeRTOSConfig.h (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/FreeRTOSIPConfig.h (97%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/SConscript (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/SimpleTCPEchoServer.c (97%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/TCPEchoClient_SingleTasks.c (97%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/TCPEchoClient_SingleTasks.h (97%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/code_coverage_additions.c (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/console.c (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/console.h (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/main.c (90%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/main_blinky.c (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/main_full.c (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/main_networking.c (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/run-time-stats-utils.c (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/trcConfig.h (99%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/trcSnapshotConfig.h (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/utils/wait_for_event.c (100%)
rename FreeRTOS/Demo/Posix_GCC/{src => }/utils/wait_for_event.h (100%)
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c
index 41f28a0d27..04d9569890 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c
@@ -44,7 +44,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include
#include
#include
-#include
#include
#include
diff --git a/FreeRTOS/Demo/Posix_GCC/src/FreeRTOSConfig.h b/FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/FreeRTOSConfig.h
rename to FreeRTOS/Demo/Posix_GCC/FreeRTOSConfig.h
diff --git a/FreeRTOS/Demo/Posix_GCC/src/FreeRTOSIPConfig.h b/FreeRTOS/Demo/Posix_GCC/FreeRTOSIPConfig.h
similarity index 97%
rename from FreeRTOS/Demo/Posix_GCC/src/FreeRTOSIPConfig.h
rename to FreeRTOS/Demo/Posix_GCC/FreeRTOSIPConfig.h
index 261774fad9..5926ff0ad1 100644
--- a/FreeRTOS/Demo/Posix_GCC/src/FreeRTOSIPConfig.h
+++ b/FreeRTOS/Demo/Posix_GCC/FreeRTOSIPConfig.h
@@ -1,307 +1,307 @@
-/*
- * FreeRTOS Kernel V10.3.0
- * 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://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-
-/*****************************************************************************
- *
- * See the following URL for configuration information.
- * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
- *
- *****************************************************************************/
-
-#ifndef FREERTOS_IP_CONFIG_H
-#define FREERTOS_IP_CONFIG_H
-
-/* Prototype for the function used to print out. In this case it prints to the
-console before the network is connected then a UDP port after the network has
-connected. */
-extern void vLoggingPrintf( const char *pcFormatString, ... );
-
-/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
-1 then FreeRTOS_debug_printf should be defined to the function used to print
-out the debugging messages. */
-#define ipconfigHAS_DEBUG_PRINTF 1
-#if( ipconfigHAS_DEBUG_PRINTF == 1 )
- #define FreeRTOS_debug_printf(X) vLoggingPrintf X
-#endif
-
-/* Set to 1 to print out non debugging messages, for example the output of the
-FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
-then FreeRTOS_printf should be set to the function used to print out the
-messages. */
-#define ipconfigHAS_PRINTF 1
-#if( ipconfigHAS_PRINTF == 1 )
- #define FreeRTOS_printf(X) vLoggingPrintf X
-#endif
-
-/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
-on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
-#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
-
-/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
-then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
-stack repeating the checksum calculations. */
-#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
-
-/* Several API's will block until the result is known, or the action has been
-performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
-set per socket, using setsockopt(). If not set, the times below will be
-used as defaults. */
-#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
-#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
-
-/* Include support for LLMNR: Link-local Multicast Name Resolution
-(non-Microsoft) */
-#define ipconfigUSE_LLMNR ( 1 )
-
-/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
-#define ipconfigUSE_NBNS ( 1 )
-
-/* Include support for DNS caching. For TCP, having a small DNS cache is very
-useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
-and also DNS may use small timeouts. If a DNS reply comes in after the DNS
-socket has been destroyed, the result will be stored into the cache. The next
-call to FreeRTOS_gethostbyname() will return immediately, without even creating
-a socket. */
-#define ipconfigUSE_DNS_CACHE ( 1 )
-#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
-#define ipconfigDNS_CACHE_ENTRIES ( 4 )
-#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
-
-/* The IP stack executes it its own task (although any application task can make
-use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
-sets the priority of the task that executes the IP stack. The priority is a
-standard FreeRTOS task priority so can take any value from 0 (the lowest
-priority) to (configMAX_PRIORITIES - 1) (the highest priority).
-configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
-FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
-the priority assigned to the task executing the IP stack relative to the
-priority assigned to tasks that use the IP stack. */
-#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
-
-/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
-task. This setting is less important when the FreeRTOS Win32 simulator is used
-as the Win32 simulator only stores a fixed amount of information on the task
-stack. FreeRTOS includes optional stack overflow detection, see:
-http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
-#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
-
-/* ipconfigRAND32() is called by the IP stack to generate random numbers for
-things such as a DHCP transaction number or initial sequence number. Random
-number generation is performed via this macro to allow applications to use their
-own random number generation method. For example, it might be possible to
-generate a random number by sampling noise on an analogue input. */
-extern UBaseType_t uxRand();
-#define ipconfigRAND32() uxRand()
-
-/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
-network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
-is not set to 1 then the network event hook will never be called. See
-http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml
-*/
-#define ipconfigUSE_NETWORK_EVENT_HOOK 1
-
-/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
-a network buffer cannot be obtained then the calling task is held in the Blocked
-state (so other tasks can continue to executed) until either a network buffer
-becomes available or the send block time expires. If the send block time expires
-then the send operation is aborted. The maximum allowable send block time is
-capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
-maximum allowable send block time prevents prevents a deadlock occurring when
-all the network buffers are in use and the tasks that process (and subsequently
-free) the network buffers are themselves blocked waiting for a network buffer.
-ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
-milliseconds can be converted to a time in ticks by dividing the time in
-milliseconds by portTICK_PERIOD_MS. */
-#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
-
-/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
-address, netmask, DNS server address and gateway address from a DHCP server. If
-ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
-stack will revert to using the static IP address even when ipconfigUSE_DHCP is
-set to 1 if a valid configuration cannot be obtained from a DHCP server for any
-reason. The static configuration used is that passed into the stack by the
-FreeRTOS_IPInit() function call. */
-#define ipconfigUSE_DHCP 0
-
-/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
-increasing time intervals until either a reply is received from a DHCP server
-and accepted, or the interval between transmissions reaches
-ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
-static IP address passed as a parameter to FreeRTOS_IPInit() if the
-re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
-a DHCP reply being received. */
-#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000U / portTICK_PERIOD_MS )
-
-/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
-stack can only send a UDP message to a remove IP address if it knowns the MAC
-address associated with the IP address, or the MAC address of the router used to
-contact the remote IP address. When a UDP message is received from a remote IP
-address the MAC address and IP address are added to the ARP cache. When a UDP
-message is sent to a remote IP address that does not already appear in the ARP
-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
-
-/* 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 )
-
-/* 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
-
-/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
-routines, which are relatively large. To save code space the full
-FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
-alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
-takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
-FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
-(for example, 192, 168, 0, 1) as its parameters. If
-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
-
-/* 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. */
-#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
-
-/* A FreeRTOS queue is used to send events from application tasks to the IP
-stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
-be queued for processing at any one time. The event queue must be a minimum of
-5 greater than the total number of network buffers. */
-#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
-
-/* The address of a socket is the combination of its IP address and its port
-number. FreeRTOS_bind() is used to manually allocate a port number to a socket
-(to 'bind' the socket to a port), but manual binding is not normally necessary
-for client sockets (those sockets that initiate outgoing connections rather than
-wait for incoming connections on a known port number). If
-ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
-FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
-stack automatically binding the socket to a port number from the range
-socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
-ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
-on a socket that has not yet been bound will result in the send operation being
-aborted. */
-#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
-
-/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
-#define ipconfigUDP_TIME_TO_LIVE 128
-#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */
-
-/* USE_TCP: Use TCP and all its features */
-#define ipconfigUSE_TCP ( 1 )
-
-/* USE_WIN: Let TCP use windowing mechanism. */
-#define ipconfigUSE_TCP_WIN ( 1 )
-
-/* The MTU is the maximum number of bytes the payload of a network frame can
-contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
-lower value can save RAM, depending on the buffer management scheme used. If
-ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
-be divisible by 8. */
-#define ipconfigNETWORK_MTU 1200U
-
-/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
-through the FreeRTOS_gethostbyname() API function. */
-#define ipconfigUSE_DNS 1
-
-/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
-generate replies to incoming ICMP echo (ping) requests. */
-#define ipconfigREPLY_TO_INCOMING_PINGS 1
-
-/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
-FreeRTOS_SendPingRequest() API function is available. */
-#define ipconfigSUPPORT_OUTGOING_PINGS 0
-
-/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
-(and associated) API function is available. */
-#define ipconfigSUPPORT_SELECT_FUNCTION 1
-
-/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
-that are not in Ethernet II format will be dropped. This option is included for
-potential future IP stack developments. */
-#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
-
-/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
-responsibility of the Ethernet interface to filter out packets that are of no
-interest. If the Ethernet interface does not implement this functionality, then
-set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
-perform the filtering instead (it is much less efficient for the stack to do it
-because the packet will already have been passed into the stack). If the
-Ethernet driver does all the necessary filtering in hardware then software
-filtering can be removed by using a value other than 1 or 0. */
-#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
-
-/* The windows simulator cannot really simulate MAC interrupts, and needs to
-block occasionally to allow other tasks to run. */
-#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS )
-
-/* Advanced only: in order to access 32-bit fields in the IP packets with
-32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits.
-This has to do with the contents of the IP-packets: all 32-bit fields are
-32-bit-aligned, plus 16-bit(!) */
-#define ipconfigPACKET_FILLER_SIZE 2U
-
-/* Define the size of the pool of TCP window descriptors. On the average, each
-TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
-outstanding packets (for Rx and Tx). When using up to 10 TP sockets
-simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
-#define ipconfigTCP_WIN_SEG_COUNT 240
-
-/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
-maximum size. Define the size of Rx buffer for TCP sockets. */
-#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 )
-
-/* Define the size of Tx buffer for TCP sockets. */
-#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 )
-
-/* When using call-back handlers, the driver may check if the handler points to
-real program memory (RAM or flash) or just has a random non-zero value. */
-#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL )
-
-/* Include support for TCP hang protection. All sockets in a connecting or
-disconnecting stage will timeout after a period of non-activity. */
-#define ipconfigTCP_HANG_PROTECTION ( 1 )
-#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 )
-
-/* Include support for TCP keep-alive messages. */
-#define ipconfigTCP_KEEP_ALIVE ( 1 )
-#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */
-
-#define portINLINE __inline
-
-#endif /* FREERTOS_IP_CONFIG_H */
+/*
+ * FreeRTOS Kernel V10.3.0
+ * 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://www.FreeRTOS.org
+ * http://aws.amazon.com/freertos
+ *
+ * 1 tab == 4 spaces!
+ */
+
+
+/*****************************************************************************
+ *
+ * See the following URL for configuration information.
+ * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
+ *
+ *****************************************************************************/
+
+#ifndef FREERTOS_IP_CONFIG_H
+#define FREERTOS_IP_CONFIG_H
+
+/* Prototype for the function used to print out. In this case it prints to the
+console before the network is connected then a UDP port after the network has
+connected. */
+extern void vLoggingPrintf( const char *pcFormatString, ... );
+
+/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
+1 then FreeRTOS_debug_printf should be defined to the function used to print
+out the debugging messages. */
+#define ipconfigHAS_DEBUG_PRINTF 1
+#if( ipconfigHAS_DEBUG_PRINTF == 1 )
+ #define FreeRTOS_debug_printf(X) vLoggingPrintf X
+#endif
+
+/* Set to 1 to print out non debugging messages, for example the output of the
+FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
+then FreeRTOS_printf should be set to the function used to print out the
+messages. */
+#define ipconfigHAS_PRINTF 0
+#if( ipconfigHAS_PRINTF == 1 )
+ #define FreeRTOS_printf(X) vLoggingPrintf X
+#endif
+
+/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
+on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
+#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
+
+/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
+then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
+stack repeating the checksum calculations. */
+#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
+
+/* Several API's will block until the result is known, or the action has been
+performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
+set per socket, using setsockopt(). If not set, the times below will be
+used as defaults. */
+#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
+#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
+
+/* Include support for LLMNR: Link-local Multicast Name Resolution
+(non-Microsoft) */
+#define ipconfigUSE_LLMNR ( 1 )
+
+/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
+#define ipconfigUSE_NBNS ( 1 )
+
+/* Include support for DNS caching. For TCP, having a small DNS cache is very
+useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
+and also DNS may use small timeouts. If a DNS reply comes in after the DNS
+socket has been destroyed, the result will be stored into the cache. The next
+call to FreeRTOS_gethostbyname() will return immediately, without even creating
+a socket. */
+#define ipconfigUSE_DNS_CACHE ( 1 )
+#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
+#define ipconfigDNS_CACHE_ENTRIES ( 4 )
+#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
+
+/* The IP stack executes it its own task (although any application task can make
+use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
+sets the priority of the task that executes the IP stack. The priority is a
+standard FreeRTOS task priority so can take any value from 0 (the lowest
+priority) to (configMAX_PRIORITIES - 1) (the highest priority).
+configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
+FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
+the priority assigned to the task executing the IP stack relative to the
+priority assigned to tasks that use the IP stack. */
+#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
+
+/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
+task. This setting is less important when the FreeRTOS Win32 simulator is used
+as the Win32 simulator only stores a fixed amount of information on the task
+stack. FreeRTOS includes optional stack overflow detection, see:
+http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
+#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
+
+/* ipconfigRAND32() is called by the IP stack to generate random numbers for
+things such as a DHCP transaction number or initial sequence number. Random
+number generation is performed via this macro to allow applications to use their
+own random number generation method. For example, it might be possible to
+generate a random number by sampling noise on an analogue input. */
+extern UBaseType_t uxRand();
+#define ipconfigRAND32() uxRand()
+
+/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
+network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
+is not set to 1 then the network event hook will never be called. See
+http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml
+*/
+#define ipconfigUSE_NETWORK_EVENT_HOOK 1
+
+/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
+a network buffer cannot be obtained then the calling task is held in the Blocked
+state (so other tasks can continue to executed) until either a network buffer
+becomes available or the send block time expires. If the send block time expires
+then the send operation is aborted. The maximum allowable send block time is
+capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
+maximum allowable send block time prevents prevents a deadlock occurring when
+all the network buffers are in use and the tasks that process (and subsequently
+free) the network buffers are themselves blocked waiting for a network buffer.
+ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
+milliseconds can be converted to a time in ticks by dividing the time in
+milliseconds by portTICK_PERIOD_MS. */
+#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
+
+/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
+address, netmask, DNS server address and gateway address from a DHCP server. If
+ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
+stack will revert to using the static IP address even when ipconfigUSE_DHCP is
+set to 1 if a valid configuration cannot be obtained from a DHCP server for any
+reason. The static configuration used is that passed into the stack by the
+FreeRTOS_IPInit() function call. */
+#define ipconfigUSE_DHCP 0
+
+/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
+increasing time intervals until either a reply is received from a DHCP server
+and accepted, or the interval between transmissions reaches
+ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
+static IP address passed as a parameter to FreeRTOS_IPInit() if the
+re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
+a DHCP reply being received. */
+#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000U / portTICK_PERIOD_MS )
+
+/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
+stack can only send a UDP message to a remove IP address if it knowns the MAC
+address associated with the IP address, or the MAC address of the router used to
+contact the remote IP address. When a UDP message is received from a remote IP
+address the MAC address and IP address are added to the ARP cache. When a UDP
+message is sent to a remote IP address that does not already appear in the ARP
+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
+
+/* 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 )
+
+/* 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
+
+/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
+routines, which are relatively large. To save code space the full
+FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
+alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
+takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
+FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
+(for example, 192, 168, 0, 1) as its parameters. If
+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
+
+/* 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. */
+#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
+
+/* A FreeRTOS queue is used to send events from application tasks to the IP
+stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
+be queued for processing at any one time. The event queue must be a minimum of
+5 greater than the total number of network buffers. */
+#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
+
+/* The address of a socket is the combination of its IP address and its port
+number. FreeRTOS_bind() is used to manually allocate a port number to a socket
+(to 'bind' the socket to a port), but manual binding is not normally necessary
+for client sockets (those sockets that initiate outgoing connections rather than
+wait for incoming connections on a known port number). If
+ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
+FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
+stack automatically binding the socket to a port number from the range
+socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
+ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
+on a socket that has not yet been bound will result in the send operation being
+aborted. */
+#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
+
+/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
+#define ipconfigUDP_TIME_TO_LIVE 128
+#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */
+
+/* USE_TCP: Use TCP and all its features */
+#define ipconfigUSE_TCP ( 1 )
+
+/* USE_WIN: Let TCP use windowing mechanism. */
+#define ipconfigUSE_TCP_WIN ( 1 )
+
+/* The MTU is the maximum number of bytes the payload of a network frame can
+contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
+lower value can save RAM, depending on the buffer management scheme used. If
+ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
+be divisible by 8. */
+#define ipconfigNETWORK_MTU 1200U
+
+/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
+through the FreeRTOS_gethostbyname() API function. */
+#define ipconfigUSE_DNS 1
+
+/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
+generate replies to incoming ICMP echo (ping) requests. */
+#define ipconfigREPLY_TO_INCOMING_PINGS 1
+
+/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
+FreeRTOS_SendPingRequest() API function is available. */
+#define ipconfigSUPPORT_OUTGOING_PINGS 0
+
+/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
+(and associated) API function is available. */
+#define ipconfigSUPPORT_SELECT_FUNCTION 1
+
+/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
+that are not in Ethernet II format will be dropped. This option is included for
+potential future IP stack developments. */
+#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
+
+/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
+responsibility of the Ethernet interface to filter out packets that are of no
+interest. If the Ethernet interface does not implement this functionality, then
+set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
+perform the filtering instead (it is much less efficient for the stack to do it
+because the packet will already have been passed into the stack). If the
+Ethernet driver does all the necessary filtering in hardware then software
+filtering can be removed by using a value other than 1 or 0. */
+#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
+
+/* The windows simulator cannot really simulate MAC interrupts, and needs to
+block occasionally to allow other tasks to run. */
+#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS )
+
+/* Advanced only: in order to access 32-bit fields in the IP packets with
+32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits.
+This has to do with the contents of the IP-packets: all 32-bit fields are
+32-bit-aligned, plus 16-bit(!) */
+#define ipconfigPACKET_FILLER_SIZE 2U
+
+/* Define the size of the pool of TCP window descriptors. On the average, each
+TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
+outstanding packets (for Rx and Tx). When using up to 10 TP sockets
+simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
+#define ipconfigTCP_WIN_SEG_COUNT 240
+
+/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
+maximum size. Define the size of Rx buffer for TCP sockets. */
+#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 )
+
+/* Define the size of Tx buffer for TCP sockets. */
+#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 )
+
+/* When using call-back handlers, the driver may check if the handler points to
+real program memory (RAM or flash) or just has a random non-zero value. */
+#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL )
+
+/* Include support for TCP hang protection. All sockets in a connecting or
+disconnecting stage will timeout after a period of non-activity. */
+#define ipconfigTCP_HANG_PROTECTION ( 1 )
+#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 )
+
+/* Include support for TCP keep-alive messages. */
+#define ipconfigTCP_KEEP_ALIVE ( 1 )
+#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */
+
+#define portINLINE __inline
+
+#endif /* FREERTOS_IP_CONFIG_H */
diff --git a/FreeRTOS/Demo/Posix_GCC/src/SConscript b/FreeRTOS/Demo/Posix_GCC/SConscript
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/SConscript
rename to FreeRTOS/Demo/Posix_GCC/SConscript
diff --git a/FreeRTOS/Demo/Posix_GCC/SConstruct b/FreeRTOS/Demo/Posix_GCC/SConstruct
index e055a3c253..fd6ef6298f 100644
--- a/FreeRTOS/Demo/Posix_GCC/SConstruct
+++ b/FreeRTOS/Demo/Posix_GCC/SConstruct
@@ -27,10 +27,10 @@
import os
# Create a symlink to the FreeRTOS sources.
-if not os.path.exists("src/FreeRTOS"):
- os.symlink("../../..", "src/FreeRTOS")
-if not os.path.exists("src/FreeRTOS-Plus"):
- os.symlink("../../../../FreeRTOS-Plus", "src/FreeRTOS-Plus")
+if not os.path.exists("FreeRTOS"):
+ os.symlink("../..", "FreeRTOS")
+if not os.path.exists("FreeRTOS-Plus"):
+ os.symlink("../../../FreeRTOS-Plus", "FreeRTOS-Plus")
AddOption("--simple",
action='store_true',
@@ -49,4 +49,4 @@ env.Append(CFLAGS = [
"-O2",
])
-SConscript("src/SConscript", variant_dir="build", duplicate=0)
+SConscript("./SConscript", variant_dir="build", duplicate=0)
diff --git a/FreeRTOS/Demo/Posix_GCC/src/SimpleTCPEchoServer.c b/FreeRTOS/Demo/Posix_GCC/SimpleTCPEchoServer.c
similarity index 97%
rename from FreeRTOS/Demo/Posix_GCC/src/SimpleTCPEchoServer.c
rename to FreeRTOS/Demo/Posix_GCC/SimpleTCPEchoServer.c
index 2a2c704d74..ef690b894f 100644
--- a/FreeRTOS/Demo/Posix_GCC/src/SimpleTCPEchoServer.c
+++ b/FreeRTOS/Demo/Posix_GCC/SimpleTCPEchoServer.c
@@ -1,288 +1,288 @@
-/*
- FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
- All rights reserved
-
- VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
-
- This file is part of the FreeRTOS distribution.
-
- FreeRTOS is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License (version 2) as published by the
- Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
-
- ***************************************************************************
- >>! NOTE: The modification to the GPL is included to allow you to !<<
- >>! distribute a combined work that includes FreeRTOS without being !<<
- >>! obliged to provide the source code for proprietary components !<<
- >>! outside of the FreeRTOS kernel. !<<
- ***************************************************************************
-
- FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. Full license text is available on the following
- link: http://www.freertos.org/a00114.html
-
- ***************************************************************************
- * *
- * FreeRTOS provides completely free yet professionally developed, *
- * robust, strictly quality controlled, supported, and cross *
- * platform software that is more than just the market leader, it *
- * is the industry's de facto standard. *
- * *
- * Help yourself get started quickly while simultaneously helping *
- * to support the FreeRTOS project by purchasing a FreeRTOS *
- * tutorial book, reference manual, or both: *
- * http://www.FreeRTOS.org/Documentation *
- * *
- ***************************************************************************
-
- http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
- the FAQ page "My application does not run, what could be wrong?". Have you
- defined configASSERT()?
-
- http://www.FreeRTOS.org/support - In return for receiving this top quality
- embedded software for free we request you assist our global community by
- participating in the support forum.
-
- http://www.FreeRTOS.org/training - Investing in training allows your team to
- be as productive as possible as early as possible. Now you can receive
- FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
- Ltd, and the world's leading authority on the world's leading RTOS.
-
- http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
- including FreeRTOS+Trace - an indispensable productivity tool, a DOS
- compatible FAT file system, and our tiny thread aware UDP/IP stack.
-
- http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
- Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
-
- http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
- Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
- licenses offer ticketed support, indemnification and commercial middleware.
-
- http://www.SafeRTOS.com - High Integrity Systems also provide a safety
- engineered and independently SIL3 certified version for use in safety and
- mission critical applications that require provable dependability.
-
- 1 tab == 4 spaces!
-*/
-
-/*
- * FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the
- * standard echo port number (7).
- *
- * See the following web page for essential demo usage and configuration
- * details:
- * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Server.html
- */
-
-/* Standard includes. */
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "semphr.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-
-/* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */
-#if( ipconfigUSE_TCP == 1 )
-
-/* The maximum time to wait for a closing socket to close. */
-#define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) )
-
-/* The standard echo port number. */
-#define tcpechoPORT_NUMBER 7
-
-/* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by
-ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be
-configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note
-ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
-stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in
-FreeRTOSConfig.h as it is a demo application constant. */
-#ifndef configECHO_SERVER_TX_WINDOW_SIZE
- #define configECHO_SERVER_TX_WINDOW_SIZE 2
-#endif
-
-/* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by
-ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be
-configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note
-ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
-stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in
-FreeRTOSConfig.h as it is a demo application constant. */
-#ifndef configECHO_SERVER_RX_WINDOW_SIZE
- #define configECHO_SERVER_RX_WINDOW_SIZE 2
-#endif
-
-/*-----------------------------------------------------------*/
-
-/*
- * Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task
- * to handle each connection.
- */
-static void prvConnectionListeningTask( void *pvParameters );
-
-/*
- * Created by the connection listening task to handle a single connection.
- */
-static void prvServerConnectionInstance( void *pvParameters );
-
-/*-----------------------------------------------------------*/
-
-/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be
-reused when the server listening task creates tasks to handle connections. */
-static uint16_t usUsedStackSize = 0;
-
-/*-----------------------------------------------------------*/
-
-void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority )
-{
- /* Create the TCP echo server. */
- xTaskCreate( prvConnectionListeningTask, "ServerListener", usStackSize, NULL, uxPriority + 1, NULL );
-
- /* Remember the requested stack size so it can be re-used by the server
- listening task when it creates tasks to handle connections. */
- usUsedStackSize = usStackSize;
-}
-/*-----------------------------------------------------------*/
-
-static void prvConnectionListeningTask( void *pvParameters )
-{
-struct freertos_sockaddr xClient, xBindAddress;
-Socket_t xListeningSocket, xConnectedSocket;
-socklen_t xSize = sizeof( xClient );
-static const TickType_t xReceiveTimeOut = portMAX_DELAY;
-const BaseType_t xBacklog = 20;
-
-#if( ipconfigUSE_TCP_WIN == 1 )
- WinProperties_t xWinProps;
-
- /* Fill in the buffer and window sizes that will be used by the socket. */
- xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH;
- xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE;
- xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH;
- xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE;
-#endif /* ipconfigUSE_TCP_WIN */
-
- /* Just to prevent compiler warnings. */
- ( void ) pvParameters;
-
- /* Attempt to open the socket. */
- xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
- configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
-
- /* Set a time out so accept() will just wait for a connection. */
- FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
-
- /* Set the window and buffer sizes. */
- #if( ipconfigUSE_TCP_WIN == 1 )
- {
- FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
- }
- #endif /* ipconfigUSE_TCP_WIN */
-
- /* Bind the socket to the port that the client task will send to, then
- listen for incoming connections. */
- xBindAddress.sin_port = tcpechoPORT_NUMBER;
- xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
- FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
- FreeRTOS_listen( xListeningSocket, xBacklog );
-
- for( ;; )
- {
- /* Wait for a client to connect. */
- xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
- configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
-
- /* Spawn a task to handle the connection. */
- xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY, NULL );
- }
-}
-/*-----------------------------------------------------------*/
-
-static void prvServerConnectionInstance( void *pvParameters )
-{
-int32_t lBytes, lSent, lTotalSent;
-Socket_t xConnectedSocket;
-static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
-static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 );
-TickType_t xTimeOnShutdown;
-uint8_t *pucRxBuffer;
-
- xConnectedSocket = ( Socket_t ) pvParameters;
-
- /* Attempt to create the buffer used to receive the string to be echoed
- back. This could be avoided using a zero copy interface that just returned
- the same buffer. */
- pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS );
-
- if( pucRxBuffer != NULL )
- {
- FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
- FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
-
- for( ;; )
- {
- /* Zero out the receive array so there is NULL at the end of the string
- when it is printed out. */
- memset( pucRxBuffer, 0x00, ipconfigTCP_MSS );
-
- /* Receive data on the socket. */
- lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 );
-
- /* If data was received, echo it back. */
- if( lBytes >= 0 )
- {
- lSent = 0;
- lTotalSent = 0;
-
- /* Call send() until all the data has been sent. */
- while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) )
- {
- lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 );
- lTotalSent += lSent;
- }
-
- if( lSent < 0 )
- {
- /* Socket closed? */
- break;
- }
- }
- else
- {
- /* Socket closed? */
- break;
- }
- }
- }
-
- /* Initiate a shutdown in case it has not already been initiated. */
- FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR );
-
- /* Wait for the shutdown to take effect, indicated by FreeRTOS_recv()
- returning an error. */
- xTimeOnShutdown = xTaskGetTickCount();
- do
- {
- if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 )
- {
- break;
- }
- } while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY );
-
- /* Finished with the socket, buffer, the task. */
- vPortFree( pucRxBuffer );
- FreeRTOS_closesocket( xConnectedSocket );
-
- vTaskDelete( NULL );
-}
-/*-----------------------------------------------------------*/
-
-/* The whole file is excluded if TCP is not compiled in. */
-#endif /* ipconfigUSE_TCP */
-
+/*
+ FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
+ All rights reserved
+
+ VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
+
+ This file is part of the FreeRTOS distribution.
+
+ FreeRTOS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License (version 2) as published by the
+ Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
+
+ ***************************************************************************
+ >>! NOTE: The modification to the GPL is included to allow you to !<<
+ >>! distribute a combined work that includes FreeRTOS without being !<<
+ >>! obliged to provide the source code for proprietary components !<<
+ >>! outside of the FreeRTOS kernel. !<<
+ ***************************************************************************
+
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. Full license text is available on the following
+ link: http://www.freertos.org/a00114.html
+
+ ***************************************************************************
+ * *
+ * FreeRTOS provides completely free yet professionally developed, *
+ * robust, strictly quality controlled, supported, and cross *
+ * platform software that is more than just the market leader, it *
+ * is the industry's de facto standard. *
+ * *
+ * Help yourself get started quickly while simultaneously helping *
+ * to support the FreeRTOS project by purchasing a FreeRTOS *
+ * tutorial book, reference manual, or both: *
+ * http://www.FreeRTOS.org/Documentation *
+ * *
+ ***************************************************************************
+
+ http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
+ the FAQ page "My application does not run, what could be wrong?". Have you
+ defined configASSERT()?
+
+ http://www.FreeRTOS.org/support - In return for receiving this top quality
+ embedded software for free we request you assist our global community by
+ participating in the support forum.
+
+ http://www.FreeRTOS.org/training - Investing in training allows your team to
+ be as productive as possible as early as possible. Now you can receive
+ FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
+ Ltd, and the world's leading authority on the world's leading RTOS.
+
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
+ including FreeRTOS+Trace - an indispensable productivity tool, a DOS
+ compatible FAT file system, and our tiny thread aware UDP/IP stack.
+
+ http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
+ Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
+
+ http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
+ Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
+ licenses offer ticketed support, indemnification and commercial middleware.
+
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety
+ engineered and independently SIL3 certified version for use in safety and
+ mission critical applications that require provable dependability.
+
+ 1 tab == 4 spaces!
+*/
+
+/*
+ * FreeRTOS tasks are used with FreeRTOS+TCP to create a TCP echo server on the
+ * standard echo port number (7).
+ *
+ * See the following web page for essential demo usage and configuration
+ * details:
+ * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Server.html
+ */
+
+/* Standard includes. */
+#include
+#include
+
+/* FreeRTOS includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+#include "semphr.h"
+
+/* FreeRTOS+TCP includes. */
+#include "FreeRTOS_IP.h"
+#include "FreeRTOS_Sockets.h"
+
+/* Remove the whole file if FreeRTOSIPConfig.h is set to exclude TCP. */
+#if( ipconfigUSE_TCP == 1 )
+
+/* The maximum time to wait for a closing socket to close. */
+#define tcpechoSHUTDOWN_DELAY ( pdMS_TO_TICKS( 5000 ) )
+
+/* The standard echo port number. */
+#define tcpechoPORT_NUMBER 7
+
+/* If ipconfigUSE_TCP_WIN is 1 then the Tx sockets will use a buffer size set by
+ipconfigTCP_TX_BUFFER_LENGTH, and the Tx window size will be
+configECHO_SERVER_TX_WINDOW_SIZE times the buffer size. Note
+ipconfigTCP_TX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
+stack constant, whereas configECHO_SERVER_TX_WINDOW_SIZE is set in
+FreeRTOSConfig.h as it is a demo application constant. */
+#ifndef configECHO_SERVER_TX_WINDOW_SIZE
+ #define configECHO_SERVER_TX_WINDOW_SIZE 2
+#endif
+
+/* If ipconfigUSE_TCP_WIN is 1 then the Rx sockets will use a buffer size set by
+ipconfigTCP_RX_BUFFER_LENGTH, and the Rx window size will be
+configECHO_SERVER_RX_WINDOW_SIZE times the buffer size. Note
+ipconfigTCP_RX_BUFFER_LENGTH is set in FreeRTOSIPConfig.h as it is a standard TCP/IP
+stack constant, whereas configECHO_SERVER_RX_WINDOW_SIZE is set in
+FreeRTOSConfig.h as it is a demo application constant. */
+#ifndef configECHO_SERVER_RX_WINDOW_SIZE
+ #define configECHO_SERVER_RX_WINDOW_SIZE 2
+#endif
+
+/*-----------------------------------------------------------*/
+
+/*
+ * Uses FreeRTOS+TCP to listen for incoming echo connections, creating a task
+ * to handle each connection.
+ */
+static void prvConnectionListeningTask( void *pvParameters );
+
+/*
+ * Created by the connection listening task to handle a single connection.
+ */
+static void prvServerConnectionInstance( void *pvParameters );
+
+/*-----------------------------------------------------------*/
+
+/* Stores the stack size passed into vStartSimpleTCPServerTasks() so it can be
+reused when the server listening task creates tasks to handle connections. */
+static uint16_t usUsedStackSize = 0;
+
+/*-----------------------------------------------------------*/
+
+void vStartSimpleTCPServerTasks( uint16_t usStackSize, UBaseType_t uxPriority )
+{
+ /* Create the TCP echo server. */
+ xTaskCreate( prvConnectionListeningTask, "ServerListener", usStackSize, NULL, uxPriority + 1, NULL );
+
+ /* Remember the requested stack size so it can be re-used by the server
+ listening task when it creates tasks to handle connections. */
+ usUsedStackSize = usStackSize;
+}
+/*-----------------------------------------------------------*/
+
+static void prvConnectionListeningTask( void *pvParameters )
+{
+struct freertos_sockaddr xClient, xBindAddress;
+Socket_t xListeningSocket, xConnectedSocket;
+socklen_t xSize = sizeof( xClient );
+static const TickType_t xReceiveTimeOut = portMAX_DELAY;
+const BaseType_t xBacklog = 20;
+
+#if( ipconfigUSE_TCP_WIN == 1 )
+ WinProperties_t xWinProps;
+
+ /* Fill in the buffer and window sizes that will be used by the socket. */
+ xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH;
+ xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE;
+ xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH;
+ xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE;
+#endif /* ipconfigUSE_TCP_WIN */
+
+ /* Just to prevent compiler warnings. */
+ ( void ) pvParameters;
+
+ /* Attempt to open the socket. */
+ xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
+ configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
+
+ /* Set a time out so accept() will just wait for a connection. */
+ FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
+
+ /* Set the window and buffer sizes. */
+ #if( ipconfigUSE_TCP_WIN == 1 )
+ {
+ FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
+ }
+ #endif /* ipconfigUSE_TCP_WIN */
+
+ /* Bind the socket to the port that the client task will send to, then
+ listen for incoming connections. */
+ xBindAddress.sin_port = tcpechoPORT_NUMBER;
+ xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
+ FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
+ FreeRTOS_listen( xListeningSocket, xBacklog );
+
+ for( ;; )
+ {
+ /* Wait for a client to connect. */
+ xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
+ configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
+
+ /* Spawn a task to handle the connection. */
+ xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY, NULL );
+ }
+}
+/*-----------------------------------------------------------*/
+
+static void prvServerConnectionInstance( void *pvParameters )
+{
+int32_t lBytes, lSent, lTotalSent;
+Socket_t xConnectedSocket;
+static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
+static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 );
+TickType_t xTimeOnShutdown;
+uint8_t *pucRxBuffer;
+
+ xConnectedSocket = ( Socket_t ) pvParameters;
+
+ /* Attempt to create the buffer used to receive the string to be echoed
+ back. This could be avoided using a zero copy interface that just returned
+ the same buffer. */
+ pucRxBuffer = ( uint8_t * ) pvPortMalloc( ipconfigTCP_MSS );
+
+ if( pucRxBuffer != NULL )
+ {
+ FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
+ FreeRTOS_setsockopt( xConnectedSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
+
+ for( ;; )
+ {
+ /* Zero out the receive array so there is NULL at the end of the string
+ when it is printed out. */
+ memset( pucRxBuffer, 0x00, ipconfigTCP_MSS );
+
+ /* Receive data on the socket. */
+ lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 );
+
+ /* If data was received, echo it back. */
+ if( lBytes >= 0 )
+ {
+ lSent = 0;
+ lTotalSent = 0;
+
+ /* Call send() until all the data has been sent. */
+ while( ( lSent >= 0 ) && ( lTotalSent < lBytes ) )
+ {
+ lSent = FreeRTOS_send( xConnectedSocket, pucRxBuffer, lBytes - lTotalSent, 0 );
+ lTotalSent += lSent;
+ }
+
+ if( lSent < 0 )
+ {
+ /* Socket closed? */
+ break;
+ }
+ }
+ else
+ {
+ /* Socket closed? */
+ break;
+ }
+ }
+ }
+
+ /* Initiate a shutdown in case it has not already been initiated. */
+ FreeRTOS_shutdown( xConnectedSocket, FREERTOS_SHUT_RDWR );
+
+ /* Wait for the shutdown to take effect, indicated by FreeRTOS_recv()
+ returning an error. */
+ xTimeOnShutdown = xTaskGetTickCount();
+ do
+ {
+ if( FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 ) < 0 )
+ {
+ break;
+ }
+ } while( ( xTaskGetTickCount() - xTimeOnShutdown ) < tcpechoSHUTDOWN_DELAY );
+
+ /* Finished with the socket, buffer, the task. */
+ vPortFree( pucRxBuffer );
+ FreeRTOS_closesocket( xConnectedSocket );
+
+ vTaskDelete( NULL );
+}
+/*-----------------------------------------------------------*/
+
+/* The whole file is excluded if TCP is not compiled in. */
+#endif /* ipconfigUSE_TCP */
+
diff --git a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.c b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.c
similarity index 97%
rename from FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.c
rename to FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.c
index 4fc2fc08af..5497d14033 100644
--- a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.c
+++ b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.c
@@ -1,372 +1,372 @@
-/*
- * FreeRTOS Kernel V10.3.0
- * 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://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-/*
- * A set of tasks are created that send TCP echo requests to the standard echo
- * port (port 7) on the IP address set by the configECHO_SERVER_ADDR0 to
- * configECHO_SERVER_ADDR3 constants, then wait for and verify the reply
- * (another demo is avilable that demonstrates the reception being performed in
- * a task other than that from with the request was made).
- *
- * See the following web page for essential demo usage and configuration
- * details:
- * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
- */
-
-/* Standard includes. */
-#include
-#include
-#include
-
-/* FreeRTOS includes. */
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-
-/* FreeRTOS+TCP includes. */
-#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-
-/* Exclude the whole file if FreeRTOSIPConfig.h is configured to use UDP only. */
-#if ( ipconfigUSE_TCP == 1 )
-
-/* The echo tasks create a socket, send out a number of echo requests, listen
-for the echo reply, then close the socket again before starting over. This
-delay is used between each iteration to ensure the network does not get too
-congested. */
- #define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS )
-
-/* The echo server is assumed to be on port 7, which is the standard echo
-protocol port. */
- #define echoECHO_PORT ( 7 )
-
-/* The size of the buffers is a multiple of the MSS - the length of the data
-sent is a pseudo random size between 20 and echoBUFFER_SIZES. */
- #define echoBUFFER_SIZE_MULTIPLIER ( 3 )
- #define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER )
-
-/* The number of instances of the echo client task to create. */
- #define echoNUM_ECHO_CLIENTS ( 1 )
-
-/*-----------------------------------------------------------*/
-
-/*
- * Uses a socket to send data to, then receive data from, the standard echo
- * port number 7.
- */
- static void prvEchoClientTask( void *pvParameters );
-
-/*
- * Creates a pseudo random sized buffer of data to send to the echo server.
- */
- static BaseType_t prvCreateTxData( char *ucBuffer,
- uint32_t ulBufferLength );
-
-/*-----------------------------------------------------------*/
-
-/* Rx and Tx time outs are used to ensure the sockets do not wait too long for
-missing data. */
- static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 );
- static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 );
-
-/* Counters for each created task - for inspection only. */
- static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 },
- ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 },
- ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
-
-/* Rx and Tx buffers for each created task. */
- static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ],
- cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ];
-
-/*-----------------------------------------------------------*/
-
- void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize,
- UBaseType_t uxTaskPriority )
- {
- BaseType_t x;
-
- /* Create the echo client tasks. */
- for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
- {
- xTaskCreate( prvEchoClientTask, /* The function that implements the task. */
- "Echo0", /* Just a text name for the task to aid debugging. */
- usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
- ( void * ) x, /* The task parameter, not used in this case. */
- uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
- NULL ); /* The task handle is not used. */
- }
- }
-/*-----------------------------------------------------------*/
-
- static void prvEchoClientTask( void *pvParameters )
- {
- Socket_t xSocket;
- struct freertos_sockaddr xEchoServerAddress;
- int32_t lLoopCount = 0UL;
- const int32_t lMaxLoopCount = 1;
- volatile uint32_t ulTxCount = 0UL;
- BaseType_t xReceivedBytes, xReturned, xInstance;
- BaseType_t lTransmitted, lStringLength;
- char *pcTransmittedString, *pcReceivedString;
- WinProperties_t xWinProps;
- TickType_t xTimeOnEntering;
- BaseType_t ret;
-
- /* Fill in the buffer and window sizes that will be used by the socket. */
- xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS;
- xWinProps.lTxWinSize = 3;
- xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS;
- xWinProps.lRxWinSize = 3;
-
- /* This task can be created a number of times. Each instance is numbered
- to enable each instance to use a different Rx and Tx buffer. The number is
- passed in as the task's parameter. */
- xInstance = ( BaseType_t ) pvParameters;
-
- /* Point to the buffers to be used by this instance of this task. */
- pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] );
- pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] );
-
- /* Echo requests are sent to the echo server. The address of the echo
- server is configured by the constants configECHO_SERVER_ADDR0 to
- configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
- xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
- xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
- configECHO_SERVER_ADDR1,
- configECHO_SERVER_ADDR2,
- configECHO_SERVER_ADDR3 );
-
- for( ; ; )
- {
- /* Create a TCP socket. */
- xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
- configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
-
- /* Set a time out so a missing reply does not cause the task to block
- indefinitely. */
- FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
- FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
-
- /* Set the window and buffer sizes. */
- FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
-
- /* Connect to the echo server. */
- printf( "connecting to echo server....\n" );
-
- ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) );
-
- if( ret == 0 )
- {
- printf( "Connected to server.. \n" );
- ulConnections[ xInstance ]++;
-
- /* Send a number of echo requests. */
- for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
- {
- /* Create the string that is sent to the echo server. */
- lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES );
-
- /* Add in some unique text at the front of the string. */
- sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount );
- ulTxCount++;
-
- printf( "sending data to the echo server \n" );
- /* Send the string to the socket. */
- lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */
- ( void * ) pcTransmittedString, /* The data being sent. */
- lStringLength, /* The length of the data being sent. */
- 0 ); /* No flags. */
-
- if( lTransmitted < 0 )
- {
- /* Error? */
- break;
- }
-
- /* Clear the buffer into which the echoed string will be
- placed. */
- memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES );
- xReceivedBytes = 0;
-
- /* Receive data echoed back to the socket. */
- while( xReceivedBytes < lTransmitted )
- {
- xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
- &( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */
- lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */
- 0 ); /* No flags. */
-
- if( xReturned < 0 )
- {
- /* Error occurred. Latch it so it can be detected
- below. */
- xReceivedBytes = xReturned;
- break;
- }
- else if( xReturned == 0 )
- {
- /* Timed out. */
- break;
- }
- else
- {
- /* Keep a count of the bytes received so far. */
- xReceivedBytes += xReturned;
- }
- }
-
- /* If an error occurred it will be latched in xReceivedBytes,
- otherwise xReceived bytes will be just that - the number of
- bytes received from the echo server. */
- if( xReceivedBytes > 0 )
- {
- /* Compare the transmitted string to the received string. */
- configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 );
-
- if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 )
- {
- /* The echo reply was received without error. */
- ulTxRxCycles[ xInstance ]++;
- }
- else
- {
- /* The received string did not match the transmitted
- string. */
- ulTxRxFailures[ xInstance ]++;
- break;
- }
- }
- else if( xReceivedBytes < 0 )
- {
- /* FreeRTOS_recv() returned an error. */
- break;
- }
- else
- {
- /* Timed out without receiving anything? */
- break;
- }
- }
-
- /* Finished using the connected socket, initiate a graceful close:
- FIN, FIN+ACK, ACK. */
- FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR );
-
- /* Expect FreeRTOS_recv() to return an error once the shutdown is
- complete. */
- xTimeOnEntering = xTaskGetTickCount();
-
- do
- {
- xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
- &( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */
- echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */
- 0 );
-
- if( xReturned < 0 )
- {
- break;
- }
- } while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut );
- }
- else
- {
- printf( "Could not connect to server %ld\n", ret );
- }
-
- /* Close this socket before looping back to create another. */
- FreeRTOS_closesocket( xSocket );
-
- /* Pause for a short while to ensure the network is not too
- congested. */
- vTaskDelay( echoLOOP_DELAY );
- }
- }
-/*-----------------------------------------------------------*/
-
- static BaseType_t prvCreateTxData( char *cBuffer,
- uint32_t ulBufferLength )
- {
- BaseType_t lCharactersToAdd, lCharacter;
- char cChar = '0';
- const BaseType_t lMinimumLength = 60;
-
- /* Randomise the number of characters that will be sent in the echo
- request. */
- do
- {
- lCharactersToAdd = ipconfigRAND32() % ( ulBufferLength - 20UL );
- } while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */
-
- /* Fill the buffer. */
- for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ )
- {
- cBuffer[ lCharacter ] = cChar;
- cChar++;
-
- if( cChar > '~' )
- {
- cChar = '0';
- }
- }
-
- return lCharactersToAdd;
- }
-/*-----------------------------------------------------------*/
-
- BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void )
- {
- static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
- BaseType_t xReturn = pdPASS, x;
-
- /* Return fail is the number of cycles does not increment between
- consecutive calls. */
- for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
- {
- if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] )
- {
- xReturn = pdFAIL;
- }
- else
- {
- ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ];
- }
-
- if( ulConnections[ x ] == ulLastConnections[ x ] )
- {
- xReturn = pdFAIL;
- }
- else
- {
- ulConnections[ x ] = ulLastConnections[ x ];
- }
- }
-
- return xReturn;
- }
-
-#endif /* ipconfigUSE_TCP */
+/*
+ * FreeRTOS Kernel V10.3.0
+ * 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://www.FreeRTOS.org
+ * http://aws.amazon.com/freertos
+ *
+ * 1 tab == 4 spaces!
+ */
+
+/*
+ * A set of tasks are created that send TCP echo requests to the standard echo
+ * port (port 7) on the IP address set by the configECHO_SERVER_ADDR0 to
+ * configECHO_SERVER_ADDR3 constants, then wait for and verify the reply
+ * (another demo is avilable that demonstrates the reception being performed in
+ * a task other than that from with the request was made).
+ *
+ * See the following web page for essential demo usage and configuration
+ * details:
+ * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
+ */
+
+/* Standard includes. */
+#include
+#include
+#include
+
+/* FreeRTOS includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+
+/* FreeRTOS+TCP includes. */
+#include "FreeRTOS_IP.h"
+#include "FreeRTOS_Sockets.h"
+
+/* Exclude the whole file if FreeRTOSIPConfig.h is configured to use UDP only. */
+#if ( ipconfigUSE_TCP == 1 )
+
+/* The echo tasks create a socket, send out a number of echo requests, listen
+for the echo reply, then close the socket again before starting over. This
+delay is used between each iteration to ensure the network does not get too
+congested. */
+ #define echoLOOP_DELAY ( ( TickType_t ) 150 / portTICK_PERIOD_MS )
+
+/* The echo server is assumed to be on port 7, which is the standard echo
+protocol port. */
+ #define echoECHO_PORT ( 7 )
+
+/* The size of the buffers is a multiple of the MSS - the length of the data
+sent is a pseudo random size between 20 and echoBUFFER_SIZES. */
+ #define echoBUFFER_SIZE_MULTIPLIER ( 3 )
+ #define echoBUFFER_SIZES ( ipconfigTCP_MSS * echoBUFFER_SIZE_MULTIPLIER )
+
+/* The number of instances of the echo client task to create. */
+ #define echoNUM_ECHO_CLIENTS ( 1 )
+
+/*-----------------------------------------------------------*/
+
+/*
+ * Uses a socket to send data to, then receive data from, the standard echo
+ * port number 7.
+ */
+ static void prvEchoClientTask( void *pvParameters );
+
+/*
+ * Creates a pseudo random sized buffer of data to send to the echo server.
+ */
+ static BaseType_t prvCreateTxData( char *ucBuffer,
+ uint32_t ulBufferLength );
+
+/*-----------------------------------------------------------*/
+
+/* Rx and Tx time outs are used to ensure the sockets do not wait too long for
+missing data. */
+ static const TickType_t xReceiveTimeOut = pdMS_TO_TICKS( 4000 );
+ static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 2000 );
+
+/* Counters for each created task - for inspection only. */
+ static uint32_t ulTxRxCycles[ echoNUM_ECHO_CLIENTS ] = { 0 },
+ ulTxRxFailures[ echoNUM_ECHO_CLIENTS ] = { 0 },
+ ulConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
+
+/* Rx and Tx buffers for each created task. */
+ static char cTxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ],
+ cRxBuffers[ echoNUM_ECHO_CLIENTS ][ echoBUFFER_SIZES ];
+
+/*-----------------------------------------------------------*/
+
+ void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize,
+ UBaseType_t uxTaskPriority )
+ {
+ BaseType_t x;
+
+ /* Create the echo client tasks. */
+ for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
+ {
+ xTaskCreate( prvEchoClientTask, /* The function that implements the task. */
+ "Echo0", /* Just a text name for the task to aid debugging. */
+ usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
+ ( void * ) x, /* The task parameter, not used in this case. */
+ uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
+ NULL ); /* The task handle is not used. */
+ }
+ }
+/*-----------------------------------------------------------*/
+
+ static void prvEchoClientTask( void *pvParameters )
+ {
+ Socket_t xSocket;
+ struct freertos_sockaddr xEchoServerAddress;
+ int32_t lLoopCount = 0UL;
+ const int32_t lMaxLoopCount = 1;
+ volatile uint32_t ulTxCount = 0UL;
+ BaseType_t xReceivedBytes, xReturned, xInstance;
+ BaseType_t lTransmitted, lStringLength;
+ char *pcTransmittedString, *pcReceivedString;
+ WinProperties_t xWinProps;
+ TickType_t xTimeOnEntering;
+ BaseType_t ret;
+
+ /* Fill in the buffer and window sizes that will be used by the socket. */
+ xWinProps.lTxBufSize = 6 * ipconfigTCP_MSS;
+ xWinProps.lTxWinSize = 3;
+ xWinProps.lRxBufSize = 6 * ipconfigTCP_MSS;
+ xWinProps.lRxWinSize = 3;
+
+ /* This task can be created a number of times. Each instance is numbered
+ to enable each instance to use a different Rx and Tx buffer. The number is
+ passed in as the task's parameter. */
+ xInstance = ( BaseType_t ) pvParameters;
+
+ /* Point to the buffers to be used by this instance of this task. */
+ pcTransmittedString = &( cTxBuffers[ xInstance ][ 0 ] );
+ pcReceivedString = &( cRxBuffers[ xInstance ][ 0 ] );
+
+ /* Echo requests are sent to the echo server. The address of the echo
+ server is configured by the constants configECHO_SERVER_ADDR0 to
+ configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
+ xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
+ xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
+ configECHO_SERVER_ADDR1,
+ configECHO_SERVER_ADDR2,
+ configECHO_SERVER_ADDR3 );
+
+ for( ; ; )
+ {
+ /* Create a TCP socket. */
+ xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
+ configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
+
+ /* Set a time out so a missing reply does not cause the task to block
+ indefinitely. */
+ FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
+ FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
+
+ /* Set the window and buffer sizes. */
+ FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
+
+ /* Connect to the echo server. */
+ printf( "connecting to echo server....\n" );
+
+ ret = FreeRTOS_connect( xSocket, &xEchoServerAddress, sizeof( xEchoServerAddress ) );
+
+ if( ret == 0 )
+ {
+ printf( "Connected to server.. \n" );
+ ulConnections[ xInstance ]++;
+
+ /* Send a number of echo requests. */
+ for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
+ {
+ /* Create the string that is sent to the echo server. */
+ lStringLength = prvCreateTxData( pcTransmittedString, echoBUFFER_SIZES );
+
+ /* Add in some unique text at the front of the string. */
+ sprintf( pcTransmittedString, "TxRx message number %u", ulTxCount );
+ ulTxCount++;
+
+ printf( "sending data to the echo server \n" );
+ /* Send the string to the socket. */
+ lTransmitted = FreeRTOS_send( xSocket, /* The socket being sent to. */
+ ( void * ) pcTransmittedString, /* The data being sent. */
+ lStringLength, /* The length of the data being sent. */
+ 0 ); /* No flags. */
+
+ if( lTransmitted < 0 )
+ {
+ /* Error? */
+ break;
+ }
+
+ /* Clear the buffer into which the echoed string will be
+ placed. */
+ memset( ( void * ) pcReceivedString, 0x00, echoBUFFER_SIZES );
+ xReceivedBytes = 0;
+
+ /* Receive data echoed back to the socket. */
+ while( xReceivedBytes < lTransmitted )
+ {
+ xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
+ &( pcReceivedString[ xReceivedBytes ] ), /* The buffer into which the received data will be written. */
+ lStringLength - xReceivedBytes, /* The size of the buffer provided to receive the data. */
+ 0 ); /* No flags. */
+
+ if( xReturned < 0 )
+ {
+ /* Error occurred. Latch it so it can be detected
+ below. */
+ xReceivedBytes = xReturned;
+ break;
+ }
+ else if( xReturned == 0 )
+ {
+ /* Timed out. */
+ break;
+ }
+ else
+ {
+ /* Keep a count of the bytes received so far. */
+ xReceivedBytes += xReturned;
+ }
+ }
+
+ /* If an error occurred it will be latched in xReceivedBytes,
+ otherwise xReceived bytes will be just that - the number of
+ bytes received from the echo server. */
+ if( xReceivedBytes > 0 )
+ {
+ /* Compare the transmitted string to the received string. */
+ configASSERT( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 );
+
+ if( strncmp( pcReceivedString, pcTransmittedString, lTransmitted ) == 0 )
+ {
+ /* The echo reply was received without error. */
+ ulTxRxCycles[ xInstance ]++;
+ }
+ else
+ {
+ /* The received string did not match the transmitted
+ string. */
+ ulTxRxFailures[ xInstance ]++;
+ break;
+ }
+ }
+ else if( xReceivedBytes < 0 )
+ {
+ /* FreeRTOS_recv() returned an error. */
+ break;
+ }
+ else
+ {
+ /* Timed out without receiving anything? */
+ break;
+ }
+ }
+
+ /* Finished using the connected socket, initiate a graceful close:
+ FIN, FIN+ACK, ACK. */
+ FreeRTOS_shutdown( xSocket, FREERTOS_SHUT_RDWR );
+
+ /* Expect FreeRTOS_recv() to return an error once the shutdown is
+ complete. */
+ xTimeOnEntering = xTaskGetTickCount();
+
+ do
+ {
+ xReturned = FreeRTOS_recv( xSocket, /* The socket being received from. */
+ &( pcReceivedString[ 0 ] ), /* The buffer into which the received data will be written. */
+ echoBUFFER_SIZES, /* The size of the buffer provided to receive the data. */
+ 0 );
+
+ if( xReturned < 0 )
+ {
+ break;
+ }
+ } while( ( xTaskGetTickCount() - xTimeOnEntering ) < xReceiveTimeOut );
+ }
+ else
+ {
+ printf( "Could not connect to server %ld\n", ret );
+ }
+
+ /* Close this socket before looping back to create another. */
+ FreeRTOS_closesocket( xSocket );
+
+ /* Pause for a short while to ensure the network is not too
+ congested. */
+ vTaskDelay( echoLOOP_DELAY );
+ }
+ }
+/*-----------------------------------------------------------*/
+
+ static BaseType_t prvCreateTxData( char *cBuffer,
+ uint32_t ulBufferLength )
+ {
+ BaseType_t lCharactersToAdd, lCharacter;
+ char cChar = '0';
+ const BaseType_t lMinimumLength = 60;
+
+ /* Randomise the number of characters that will be sent in the echo
+ request. */
+ do
+ {
+ lCharactersToAdd = ipconfigRAND32() % ( ulBufferLength - 20UL );
+ } while( ( lCharactersToAdd == 0 ) || ( lCharactersToAdd < lMinimumLength ) ); /* Must be at least enough to add the unique text to the start of the string later. */
+
+ /* Fill the buffer. */
+ for( lCharacter = 0; lCharacter < lCharactersToAdd; lCharacter++ )
+ {
+ cBuffer[ lCharacter ] = cChar;
+ cChar++;
+
+ if( cChar > '~' )
+ {
+ cChar = '0';
+ }
+ }
+
+ return lCharactersToAdd;
+ }
+/*-----------------------------------------------------------*/
+
+ BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void )
+ {
+ static uint32_t ulLastEchoSocketCount[ echoNUM_ECHO_CLIENTS ] = { 0 }, ulLastConnections[ echoNUM_ECHO_CLIENTS ] = { 0 };
+ BaseType_t xReturn = pdPASS, x;
+
+ /* Return fail is the number of cycles does not increment between
+ consecutive calls. */
+ for( x = 0; x < echoNUM_ECHO_CLIENTS; x++ )
+ {
+ if( ulTxRxCycles[ x ] == ulLastEchoSocketCount[ x ] )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ ulLastEchoSocketCount[ x ] = ulTxRxCycles[ x ];
+ }
+
+ if( ulConnections[ x ] == ulLastConnections[ x ] )
+ {
+ xReturn = pdFAIL;
+ }
+ else
+ {
+ ulConnections[ x ] = ulLastConnections[ x ];
+ }
+ }
+
+ return xReturn;
+ }
+
+#endif /* ipconfigUSE_TCP */
diff --git a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.h b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.h
similarity index 97%
rename from FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.h
rename to FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.h
index 864a3a10f2..0c692e02e7 100644
--- a/FreeRTOS/Demo/Posix_GCC/src/TCPEchoClient_SingleTasks.h
+++ b/FreeRTOS/Demo/Posix_GCC/TCPEchoClient_SingleTasks.h
@@ -1,40 +1,40 @@
-/*
- * FreeRTOS Kernel V10.3.0
- * 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://www.FreeRTOS.org
- * http://aws.amazon.com/freertos
- *
- * 1 tab == 4 spaces!
- */
-
-#ifndef SINGLE_TASK_TCP_ECHO_CLIENTS_H
-#define SINGLE_TASK_TCP_ECHO_CLIENTS_H
-
-/*
- * Create the TCP echo client tasks. This is the version where an echo request
- * is made from the same task that listens for the echo reply.
- */
-void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority );
-BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void );
-
-#endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */
-
-
+/*
+ * FreeRTOS Kernel V10.3.0
+ * 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://www.FreeRTOS.org
+ * http://aws.amazon.com/freertos
+ *
+ * 1 tab == 4 spaces!
+ */
+
+#ifndef SINGLE_TASK_TCP_ECHO_CLIENTS_H
+#define SINGLE_TASK_TCP_ECHO_CLIENTS_H
+
+/*
+ * Create the TCP echo client tasks. This is the version where an echo request
+ * is made from the same task that listens for the echo reply.
+ */
+void vStartTCPEchoClientTasks_SingleTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority );
+BaseType_t xAreSingleTaskTCPEchoClientsStillRunning( void );
+
+#endif /* SINGLE_TASK_TCP_ECHO_CLIENTS_H */
+
+
diff --git a/FreeRTOS/Demo/Posix_GCC/src/code_coverage_additions.c b/FreeRTOS/Demo/Posix_GCC/code_coverage_additions.c
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/code_coverage_additions.c
rename to FreeRTOS/Demo/Posix_GCC/code_coverage_additions.c
diff --git a/FreeRTOS/Demo/Posix_GCC/src/console.c b/FreeRTOS/Demo/Posix_GCC/console.c
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/console.c
rename to FreeRTOS/Demo/Posix_GCC/console.c
diff --git a/FreeRTOS/Demo/Posix_GCC/src/console.h b/FreeRTOS/Demo/Posix_GCC/console.h
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/console.h
rename to FreeRTOS/Demo/Posix_GCC/console.h
diff --git a/FreeRTOS/Demo/Posix_GCC/src/main.c b/FreeRTOS/Demo/Posix_GCC/main.c
similarity index 90%
rename from FreeRTOS/Demo/Posix_GCC/src/main.c
rename to FreeRTOS/Demo/Posix_GCC/main.c
index dd2406ac41..93772b2c4c 100644
--- a/FreeRTOS/Demo/Posix_GCC/src/main.c
+++ b/FreeRTOS/Demo/Posix_GCC/main.c
@@ -26,25 +26,26 @@
*/
/******************************************************************************
- * This project provides two demo applications. A simple blinky style project,
- * and a more comprehensive test and demo application. The
- * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.
+ * This project provides three demo applications. A simple blinky style project,
+ * a more comprehensive test and demo application, and a TCP echo application.
+ * The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between
+ * the two if mainCREATE_TCP_ECHO_TASKS_SINGLE is 0.
* The simply blinky demo is implemented and described in main_blinky.c. The
* more comprehensive test and demo application is implemented and described in
* main_full.c.
+ * The mainCREATE_TCP_ECHO_TASKS_SINGLE setting is used to select the tcp echo
+ * application regardless of the value of mainCREATE_SIMPLE_BLINKY_DEMO_ONLY.
*
* This file implements the code that is not demo specific, including the
* hardware setup and FreeRTOS hook functions.
*
*******************************************************************************
- * NOTE: Windows will not be running the FreeRTOS demo threads continuously, so
- * do not expect to get real time behaviour from the FreeRTOS Windows port, or
+ * NOTE: Linux will not be running the FreeRTOS demo threads continuously, so
+ * do not expect to get real time behaviour from the FreeRTOS Linux port, or
* this demo application. Also, the timing information in the FreeRTOS+Trace
- * logs have no meaningful units. See the documentation page for the Windows
+ * logs have no meaningful units. See the documentation page for the Linux
* port for further information:
- * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html
- *
-
+ * https://freertos.org/FreeRTOS-simulator-for-Linux.html
*
*******************************************************************************
*/
@@ -62,16 +63,21 @@
/* Local includes. */
#include "console.h"
-/* This project provides two demo applications. A simple blinky style demo
-application, and a more comprehensive test and demo application. The
-mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two.
+/* This project provides three demo applications. A simple blinky style demo
+application, a more comprehensive test and demo application, and a TCP
+echo application. The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY and
+mainCREATE_TCP_ECHO_TASKS_SINGLE settings are used to select between the three.
-If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is 1 then the blinky demo will be built.
+If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is 1 & mainCREATE_TCP_ECHO_TASKS_SINGLE
+is not 1 then the blinky demo will be built.
The blinky demo is implemented and described in main_blinky.c.
-If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 then the comprehensive test and
+If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 &
+mainCREATE_TCP_ECHO_TASKS_SINGLE is not 1 then the comprehensive test and
demo application will be built. The comprehensive test and demo application is
-implemented and described in main_full.c. */
+implemented and described in main_full.c the tcp echo demo application
+is implemented in main_networking.c. */
+
#ifndef mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0
#endif
@@ -223,7 +229,7 @@ void vApplicationStackOverflowHook( TaskHandle_t pxTask,
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
function is called if a stack overflow is detected. This function is
provided as an example only as stack overflow checking does not function
- when running the FreeRTOS Windows port. */
+ when running the FreeRTOS POSIX port. */
vAssertCalled( __FILE__, __LINE__ );
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS/Demo/Posix_GCC/src/main_blinky.c b/FreeRTOS/Demo/Posix_GCC/main_blinky.c
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/main_blinky.c
rename to FreeRTOS/Demo/Posix_GCC/main_blinky.c
diff --git a/FreeRTOS/Demo/Posix_GCC/src/main_full.c b/FreeRTOS/Demo/Posix_GCC/main_full.c
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/main_full.c
rename to FreeRTOS/Demo/Posix_GCC/main_full.c
diff --git a/FreeRTOS/Demo/Posix_GCC/src/main_networking.c b/FreeRTOS/Demo/Posix_GCC/main_networking.c
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/main_networking.c
rename to FreeRTOS/Demo/Posix_GCC/main_networking.c
diff --git a/FreeRTOS/Demo/Posix_GCC/src/run-time-stats-utils.c b/FreeRTOS/Demo/Posix_GCC/run-time-stats-utils.c
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/run-time-stats-utils.c
rename to FreeRTOS/Demo/Posix_GCC/run-time-stats-utils.c
diff --git a/FreeRTOS/Demo/Posix_GCC/src/trcConfig.h b/FreeRTOS/Demo/Posix_GCC/trcConfig.h
similarity index 99%
rename from FreeRTOS/Demo/Posix_GCC/src/trcConfig.h
rename to FreeRTOS/Demo/Posix_GCC/trcConfig.h
index 5e1ed6a290..133971c0b5 100644
--- a/FreeRTOS/Demo/Posix_GCC/src/trcConfig.h
+++ b/FreeRTOS/Demo/Posix_GCC/trcConfig.h
@@ -113,7 +113,7 @@ extern "C" {
* TRC_FREERTOS_VERSION_9_0_2 If using FreeRTOS v9.0.2
* TRC_FREERTOS_VERSION_10_0_0 If using FreeRTOS v10.0.0 or later
*****************************************************************************/
-#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_0_0
+#define TRC_CFG_FREERTOS_VERSION TRC_FREERTOS_VERSION_10_4_0
/*******************************************************************************
* TRC_CFG_SCHEDULING_ONLY
diff --git a/FreeRTOS/Demo/Posix_GCC/src/trcSnapshotConfig.h b/FreeRTOS/Demo/Posix_GCC/trcSnapshotConfig.h
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/trcSnapshotConfig.h
rename to FreeRTOS/Demo/Posix_GCC/trcSnapshotConfig.h
diff --git a/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.c b/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.c
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.c
rename to FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.c
diff --git a/FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.h b/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.h
similarity index 100%
rename from FreeRTOS/Demo/Posix_GCC/src/utils/wait_for_event.h
rename to FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.h
From 6d35a38bdd7d24b1ebb177656f3a06037f5554e2 Mon Sep 17 00:00:00 2001
From: Yuhui Zheng <10982575+yuhui-zheng@users.noreply.github.com>
Date: Thu, 27 Aug 2020 00:51:41 -0700
Subject: [PATCH 05/40] Removed issue tempate for general inquiries, and hinted
that users could use forum for such purpose. (#105)
---
.github/ISSUE_TEMPLATE/bug_report.md | 2 ++
.github/ISSUE_TEMPLATE/documentation-issue.md | 2 ++
.github/ISSUE_TEMPLATE/general-inquiry.md | 12 ------------
3 files changed, 4 insertions(+), 12 deletions(-)
delete mode 100644 .github/ISSUE_TEMPLATE/general-inquiry.md
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
index d44477c032..2807ece489 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.md
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -34,3 +34,5 @@ If applicable, add screenshots to help explain your problem.
Add any other context about the problem here.
e.g. code snippet to reproduce the issue.
e.g. stack trace, memory dump, debugger log, and many etc.
+
+
diff --git a/.github/ISSUE_TEMPLATE/documentation-issue.md b/.github/ISSUE_TEMPLATE/documentation-issue.md
index 062a678b53..3f81276f93 100644
--- a/.github/ISSUE_TEMPLATE/documentation-issue.md
+++ b/.github/ISSUE_TEMPLATE/documentation-issue.md
@@ -19,3 +19,5 @@ If applicable, please attach screenshot.
**Browser**
- Browser: [e.g. Chrome]
- Version: [e.g. 80.0.3987.132]
+
+
diff --git a/.github/ISSUE_TEMPLATE/general-inquiry.md b/.github/ISSUE_TEMPLATE/general-inquiry.md
deleted file mode 100644
index d3b8baf701..0000000000
--- a/.github/ISSUE_TEMPLATE/general-inquiry.md
+++ /dev/null
@@ -1,12 +0,0 @@
----
-name: General inquiry
-about: Free form communication.
-title: "[Inquiry]"
-labels: question
-assignees: ''
-
----
-
-We do encourage you to take a look at [FreeRTOS official site](https://www.freertos.org) for general information and [FreeRTOS forum](https://forums.freertos.org) to access our community.
-
-If still needed, could create a general inquiry report here.
From 669084ee8f49566d5ea488b1b1d950faae1977c5 Mon Sep 17 00:00:00 2001
From: Nathan Chong <52972368+nchong-at-aws@users.noreply.github.com>
Date: Thu, 27 Aug 2020 14:59:12 -0400
Subject: [PATCH 06/40] List proofs and signoff (#194)
---
FreeRTOS/Test/VeriFast/Makefile | 56 +--
FreeRTOS/Test/VeriFast/README.md | 44 ++-
FreeRTOS/Test/VeriFast/docs/signoff.md | 144 +++++++
.../Test/VeriFast/include/proof/common.gh | 79 +++-
FreeRTOS/Test/VeriFast/include/proof/list.h | 368 ++++++++++++++++++
FreeRTOS/Test/VeriFast/include/proof/queue.h | 1 -
FreeRTOS/Test/VeriFast/list/README.md | 69 ++++
.../Test/VeriFast/list/listLIST_IS_EMPTY.c | 36 ++
FreeRTOS/Test/VeriFast/list/uxListRemove.c | 306 +++++++++++++++
FreeRTOS/Test/VeriFast/list/vListInitialise.c | 71 ++++
.../Test/VeriFast/list/vListInitialiseItem.c | 37 ++
FreeRTOS/Test/VeriFast/list/vListInsert.c | 316 +++++++++++++++
FreeRTOS/Test/VeriFast/list/vListInsertEnd.c | 234 +++++++++++
.../VeriFast/scripts/annotation_overhead.sh | 2 +-
FreeRTOS/Test/VeriFast/scripts/diff_files.md | 4 +-
.../VeriFast/scripts/generate_diff_files.sh | 29 +-
16 files changed, 1737 insertions(+), 59 deletions(-)
create mode 100644 FreeRTOS/Test/VeriFast/docs/signoff.md
create mode 100644 FreeRTOS/Test/VeriFast/include/proof/list.h
create mode 100644 FreeRTOS/Test/VeriFast/list/README.md
create mode 100644 FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c
create mode 100644 FreeRTOS/Test/VeriFast/list/uxListRemove.c
create mode 100644 FreeRTOS/Test/VeriFast/list/vListInitialise.c
create mode 100644 FreeRTOS/Test/VeriFast/list/vListInitialiseItem.c
create mode 100644 FreeRTOS/Test/VeriFast/list/vListInsert.c
create mode 100644 FreeRTOS/Test/VeriFast/list/vListInsertEnd.c
diff --git a/FreeRTOS/Test/VeriFast/Makefile b/FreeRTOS/Test/VeriFast/Makefile
index 9e774f61ad..3d9fb48002 100644
--- a/FreeRTOS/Test/VeriFast/Makefile
+++ b/FreeRTOS/Test/VeriFast/Makefile
@@ -14,28 +14,37 @@ check_coverage = perl -pe \
$$status=/$1 statements verified/ ? 0 : 1;'
endif
-all: queue
+all: queue list
.PHONY: queue
queue:
- @$(VERIFAST) $(VERIFAST_ARGS) queue/create.c | $(call check_coverage,317)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/prvCopyDataFromQueue.c | $(call check_coverage,301)
- @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/prvCopyDataToQueue.c | $(call check_coverage,329)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueEmpty.c | $(call check_coverage,282)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueFull.c | $(call check_coverage,282)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/prvLockQueue.c | $(call check_coverage,283)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/prvUnlockQueue.c | $(call check_coverage,297)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueMessagesWaiting.c | $(call check_coverage,285)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueSpacesAvailable.c | $(call check_coverage,283)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/vQueueDelete.c | $(call check_coverage,280)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueGenericSend.c | $(call check_coverage,328)
- @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueGenericSendFromISR.c | $(call check_coverage,310)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueEmptyFromISR.c | $(call check_coverage,280)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueFullFromISR.c | $(call check_coverage,280)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeek.c | $(call check_coverage,328)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeekFromISR.c | $(call check_coverage,293)
- @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueReceive.c | $(call check_coverage,330)
- @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueReceiveFromISR.c | $(call check_coverage,307)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/create.c | $(call check_coverage,324)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/prvCopyDataFromQueue.c | $(call check_coverage,308)
+ @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/prvCopyDataToQueue.c | $(call check_coverage,336)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueEmpty.c | $(call check_coverage,289)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/prvIsQueueFull.c | $(call check_coverage,289)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/prvLockQueue.c | $(call check_coverage,290)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/prvUnlockQueue.c | $(call check_coverage,304)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueMessagesWaiting.c | $(call check_coverage,292)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/uxQueueSpacesAvailable.c | $(call check_coverage,290)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/vQueueDelete.c | $(call check_coverage,287)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueGenericSend.c | $(call check_coverage,335)
+ @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueGenericSendFromISR.c | $(call check_coverage,317)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueEmptyFromISR.c | $(call check_coverage,287)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueIsQueueFullFromISR.c | $(call check_coverage,287)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeek.c | $(call check_coverage,335)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueuePeekFromISR.c | $(call check_coverage,300)
+ @$(VERIFAST) $(VERIFAST_ARGS) queue/xQueueReceive.c | $(call check_coverage,337)
+ @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check queue/xQueueReceiveFromISR.c | $(call check_coverage,314)
+
+.PHONY: list
+list:
+ @$(VERIFAST) $(VERIFAST_ARGS) list/listLIST_IS_EMPTY.c | $(call check_coverage,314)
+ @$(VERIFAST) $(VERIFAST_ARGS) list/uxListRemove.c | $(call check_coverage,440)
+ @$(VERIFAST) $(VERIFAST_ARGS) list/vListInitialise.c | $(call check_coverage,325)
+ @$(VERIFAST) $(VERIFAST_ARGS) list/vListInitialiseItem.c | $(call check_coverage,316)
+ @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check list/vListInsertEnd.c | $(call check_coverage,410)
+ @$(VERIFAST) $(VERIFAST_ARGS) -disable_overflow_check list/vListInsert.c | $(call check_coverage,456)
.PHONY: proof_changes
proof_changes:
@@ -43,10 +52,13 @@ proof_changes:
GIT?=git
NO_CHANGE_CHECKOUT_DIR=no-change-check-freertos-kernel
-NO_CHANGE_EXPECTED_HASH=587a83d6476
+NO_CHANGE_EXPECTED_HASH_QUEUE=587a83d6476
+NO_CHANGE_EXPECTED_HASH_LIST=bb1c4293787
.PHONY: synced_with_source_check
synced_with_source_check:
@rm -rf $(NO_CHANGE_CHECKOUT_DIR)
@$(GIT) clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git $(NO_CHANGE_CHECKOUT_DIR)
- @cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH) queue.c
- @cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH) include/queue.h
+ @cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH_QUEUE) queue.c
+ @cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH_QUEUE) include/queue.h
+ @cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH_LIST) list.c
+ @cd $(NO_CHANGE_CHECKOUT_DIR) && $(GIT) diff --quiet $(NO_CHANGE_EXPECTED_HASH_LIST) include/list.h
diff --git a/FreeRTOS/Test/VeriFast/README.md b/FreeRTOS/Test/VeriFast/README.md
index f0deecdfc4..5d472692f0 100644
--- a/FreeRTOS/Test/VeriFast/README.md
+++ b/FreeRTOS/Test/VeriFast/README.md
@@ -1,8 +1,19 @@
# FreeRTOS VeriFast proofs
-This directory contains automated functional correctness proofs of the FreeRTOS
-kernel queue data structure. These properties are proven with the
-[VeriFast](https://github.com/verifast/verifast) verifier.
+This directory contains unbounded proofs of the FreeRTOS kernel queue and list
+data structures. Unbounded proofs mean that these results hold independent of
+the length of the queue or list.
+
+Informally, the queue proofs demonstrate that the queue implementation is
+memory safe (does not access invalid memory), thread safe (properly
+synchronizes accesses) and functionally correct (behaves like a queue) under
+any arbitrary number of tasks or ISRs. The list proofs demonstrate that the
+list implementation is memory safe and functionally correct.
+
+These properties are proven with the
+[VeriFast](https://github.com/verifast/verifast) verifier. See the proof
+[signoff](docs/signoff.md) document for more on the proof properties,
+assumptions, and simplifications.
## Proof directory structure
@@ -14,6 +25,7 @@ predicates, functions and lemmas used by all proofs is maintained in the
`include/proof` directory.
- `queue`: proofs for the FreeRTOS queue data structure
+ - `list`: proofs for the FreeRTOS list data structure
The following figure gives the callgraph of the queue proofs. Green=Proven
functions, Blue=Functions modeled by lock invariants (underlying implementation
@@ -49,7 +61,7 @@ and uncheck `Check arithmetic overflow`).
- `queue/xQueueReceiveFromISR.c`
A successful proof results in the top banner turning green with a statement
-similar to: `0 errors found (328 statements verified)`.
+similar to: `0 errors found (335 statements verified)`.
## Proof checking a single proof at the command-line
@@ -65,7 +77,7 @@ A successful proof results in output similar to:
```
queue/xQueueGenericSend.c
-0 errors found (328 statements verified)
+0 errors found (335 statements verified)
```
## Running proof regression
@@ -87,7 +99,8 @@ $ VERIFAST=/path/to/verifast NO_COVERAGE=1 make
## Annotation burden
VeriFast can emit statistics about the number of source code lines and
-annotations. These range from .3-2x annotations per line of source code.
+annotations. These range from .3-2x annotations per line of source code for the
+queue proofs and up to 7x for the list proofs.
```
$ VERIFAST=/path/to/verifast ./scripts/annotation_overhead.sh
@@ -96,15 +109,12 @@ $ VERIFAST=/path/to/verifast ./scripts/annotation_overhead.sh
## Reading a VeriFast proof
VeriFast is a modular deductive verifier using separation logic. A quick
-introduction is given by [Jacobs and
-Piessens](https://people.cs.kuleuven.be/~bart.jacobs/verifast/verifast.pdf).
-In particular, Section 1 Introduction, gives a high-level overview of the proof
-technique, which uses forward symbolic execution over a symbolic heap.
+introduction is given by [Jacobs and Piessens][1]. In particular, Section 1
+Introduction, gives a high-level overview of the proof technique, which uses
+forward symbolic execution over a symbolic heap.
-Learning how to use VeriFast will help you read and understand the proofs.
-The VeriFast
-[tutorial](https://people.cs.kuleuven.be/~bart.jacobs/verifast/tutorial.pdf) is
-a good guide. You will need to understand:
+Learning how to use VeriFast will help you read and understand the proofs. The
+VeriFast [tutorial][2] is a good guide. You will need to understand:
- Sec 4. Functions and Contracts
- Sec 5. Patterns
@@ -115,8 +125,12 @@ a good guide. You will need to understand:
- Sec 10. Inductive Datatypes
- Sec 11. Lemmas
+[1]: https://people.cs.kuleuven.be/~bart.jacobs/verifast/verifast.pdf
+[2]: https://people.cs.kuleuven.be/~bart.jacobs/verifast/tutorial.pdf
+
## Contributors
-We acknowledge and thank the following contributors, listed alphabetically:
+We acknowledge and thank the following contributors:
- Bart Jacobs, KU Leuven, https://people.cs.kuleuven.be/~bart.jacobs/
+ - Aalok Thakkar, University of Pennsylvania, https://aalok-thakkar.github.io/
diff --git a/FreeRTOS/Test/VeriFast/docs/signoff.md b/FreeRTOS/Test/VeriFast/docs/signoff.md
new file mode 100644
index 0000000000..71af7ddbf7
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/docs/signoff.md
@@ -0,0 +1,144 @@
+# FreeRTOS VeriFast Proof Signoff
+
+Verification tool: VeriFast (code-level proof)
+
+Proofs: `queue/` and `list`
+
+Implementation: Kernel queue data structure (`queue.c`) and list data structure (`list.c`)
+
+Specification / Properties:
+ - *Memory safety*: the implementation only accesses valid memory. In the case
+ of the queue, this is true under any arbitrary number of tasks or ISRs.
+ - *Thread safety*: in the case of the queue, tasks and ISRs only update
+ objects that they own via proper synchronization.
+ - *Functional correctness*: the queue and list implementations behave like an
+ abstract queue and list. In the case of the queue, this is true under any
+ arbitrary number of tasks or ISRs.
+
+## Queue proof assumptions
+
+Generally, we assume well-behaved clients; the correctness of underlying
+primitives (memory allocation, task scheduling, scheduler suspension); and
+assumptions about the system.
+
+ - Well-behaved client: all client tasks and ISRs use the queue API in a
+ manner that adheres to the specification. A badly-behaved client can
+ invalidate the proven properties. For example, a client that reads or
+ writes to the queue storage directly, without masking interrupts, is racy
+ and no longer thread safe. The specification forbids this behavior by
+ the definition of `queuehandle`, which is a handle to acquire ownership of
+ the queue through interrupt masking, but we cannot, in general, enforce
+ this behavior since we do not verify client code.
+
+ - Memory safety, thread safety and function contracts for the following
+ primitives. For the list and task functions we give a contract that is
+ maximal in terms of the queue objects that can be updated, but we do not
+ model their function effect (e.g., task blocking and the moving of task
+ control blocks between scheduler lists).
+
+ pvPortMalloc
+ vPortFree
+ memcpy
+ vListInitialise
+ xTaskRemoveFromEventList
+ vTaskMissedYield
+ xTaskCheckForTimeOut
+ vTaskInternalSetTimeOutState
+ vTaskPlaceOnEventList
+
+ - We assume interrupt masking gives strong isolation between tasks and ISRs.
+ See Appendix. We further assume the system is configured as required by
+ `configASSERT`. For example, interrupts with a priority greater than the
+ maximum system call priority must not call queue API functions, otherwise
+ the strong isolation guarantee is not maintained.
+
+## List proof assumptions
+
+The list proofs are sequential. We assume the caller of the list API functions
+has taken appropriate synchronization steps to avoid races.
+
+## Simplifications
+
+A list of changes to the source code required for the proofs can be generated:
+
+```
+make proof_changes
+```
+
+A side-by-side diff with respect to the source code can be generated. See
+.
+
+The main queue changes are:
+
+ - merge cTxLock and cRxLock critical regions: under approximate queue
+ unlock behavior to atomically set `cTxLock` and `cRxLock` to unlocked in a
+ single critical region instead of two separate critical regions. In
+ practice, this is not an issue since no ISR function reads-from both
+ cTxLock and cRxLock.
+ - model single malloc of struct and buffer: split the single malloc of the
+ queue struct and storage into two separate mallocs.
+ - xQueueGenericReset happens-before concurrent behavior: assume that queue
+ initialisation is not concurrent.
+ - do not model pxIndex and xListEnd of xLIST struct: ignore these fields in
+ the list structs of the queue implementation
+
+The main list changes are:
+
+ - change `MiniList_t` to `ListItem_t`: simplifying assumption on the list
+ structure.
+ - over-approximate list insert loop: replace a loop in the insert function
+ that finds the insertion point with an over-approximating function call.
+
+The following minor changes due to the stricter typing and parser of VeriFast:
+
+ - replacing a union declaration with a struct
+ - const pointer declaration
+ - stricter casting
+ - void cast of unused return value
+ - void cast of unused var
+
+The following minor changes due to the modeling of interrupts and scheduler
+suspension in the proofs as ghost state.
+
+ - ghost action
+ - leak ghost state on deletion
+
+## Configuration
+
+We do not verify across the full configuration space of FreeRTOS. In
+particular, the queue proofs do not apply when the following options are
+enabled:
+
+ - `configUSE_QUEUE_SETS`
+ - `configSUPPORT_STATIC_ALLOCATION`
+
+For both the queue and list proofs we assume that coverage and tracing
+macros are no-ops.
+
+## Trusted computing base
+
+ - Soundness of verification tools: VeriFast, Redux prover
+ - C Compiler, because the verification is at the C code-level and the
+ properties proved may not be preserved by compilation.
+
+## References
+
+[N1570] ISO/IEC. Programming languages – C. International standard 9899:201x,
+2011
+
+## Appendix
+
+Assumption on strong isolation induced by interrupt masking and scheduler
+suspension for queue proofs. Informally, we need the following:
+
+```
+// Initially *data == 0
+// Task 1
+taskENTER_CRITICAL()
+*data = 1;
+*data = 2;
+taskEXIT_CRITICAL()
+
+// ISR or Task 2
+r0 = *data; //< guaranteed to read 0 or 2, never 1
+```
diff --git a/FreeRTOS/Test/VeriFast/include/proof/common.gh b/FreeRTOS/Test/VeriFast/include/proof/common.gh
index c3b0649390..f8acfdddca 100644
--- a/FreeRTOS/Test/VeriFast/include/proof/common.gh
+++ b/FreeRTOS/Test/VeriFast/include/proof/common.gh
@@ -191,6 +191,45 @@ lemma_auto void mod_range(int x, int n)
div_rem_nonneg(x, n);
}
+lemma void head_append(list xs, list ys)
+ requires 0 < length(xs);
+ ensures head(append(xs, ys)) == head(xs);
+{
+ switch(xs)
+ {
+ case cons(c, cs):
+ case nil:
+ }
+}
+
+lemma void drop_take_singleton(int i, list xs)
+ requires 0 < i && i < length(xs);
+ ensures drop(i-1, take(i, xs)) == singleton(nth(i-1, xs));
+{
+ switch (xs) {
+ case nil:
+ case cons(x0, xs0):
+ if (i == 1) {
+ } else {
+ drop_take_singleton(i-1, xs0);
+ }
+ }
+}
+
+lemma void take_singleton(int i, list xs)
+ requires 0 <= i && i < length(xs);
+ ensures append(take(i, xs), singleton(nth(i, xs))) == take(i+1, xs);
+{
+ switch (xs) {
+ case nil:
+ case cons(x0, xs0):
+ if (i == 0) {
+ } else {
+ take_singleton(i-1, xs0);
+ }
+ }
+}
+
lemma void drop_update_le(int i, int j, t x, list xs)
requires 0 <= i && i <= j && j < length(xs);
ensures drop(i, update(j, x, xs)) == update(j - i, x, drop(i, xs));
@@ -298,21 +337,17 @@ lemma void take_take(int m, int n, list xs)
}
}
-lemma void index_of_distinct(list xs, t x1, t x2)
- requires mem(x1, xs) == true &*& mem(x2, xs) == true &*& x1 != x2;
- ensures index_of(x1, xs) != index_of(x2, xs);
+lemma_auto void take_head(list xs)
+ requires 0 < length(xs);
+ ensures take(1, xs) == singleton(head(xs));
{
- switch (xs) {
+ switch(xs) {
case nil:
- case cons(h, tl):
- if (h == x1 || h == x2) {
- /* trivial */
- } else {
- index_of_distinct(tl, x1, x2);
- }
+ case cons(x0, xs0):
}
}
+/* Following lemma from `verifast/bin/rt/_list.java` */
lemma void remove_remove_nth(list xs, t x)
requires mem(x, xs) == true;
ensures remove(x, xs) == remove_nth(index_of(x, xs), xs);
@@ -328,6 +363,18 @@ lemma void remove_remove_nth(list xs, t x)
}
}
+lemma void mem_take_false(t x, int n, list xs)
+ requires mem(x, xs) == false;
+ ensures mem(x, take(n, xs)) == false;
+{
+ switch (xs) {
+ case nil:
+ case cons(x0, xs0):
+ if (x0 != x && n != 0)
+ mem_take_false(x, n - 1, xs0);
+ }
+}
+
/* Following lemma from `verifast/bin/rt/_list.java`. Renamed to
avoid clash with listex.c's nth_drop lemma. */
lemma void nth_drop2(list vs, int i)
@@ -536,12 +583,12 @@ lemma void update_rewrite(list vs, t v, int pos)
ensures update(pos, v, vs) == append(take(pos, vs), cons(v, (drop(pos+1, vs))));
{
switch(vs) {
- case nil:
- case cons(h, t):
- if(pos == 0) {
- } else {
- update_rewrite(t, v, pos - 1);
- }
+ case nil:
+ case cons(h, t):
+ if (pos == 0) {
+ } else {
+ update_rewrite(t, v, pos - 1);
+ }
}
}
diff --git a/FreeRTOS/Test/VeriFast/include/proof/list.h b/FreeRTOS/Test/VeriFast/include/proof/list.h
new file mode 100644
index 0000000000..21f9b42b0f
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/include/proof/list.h
@@ -0,0 +1,368 @@
+/*
+ * FreeRTOS VeriFast Proofs
+ * Copyright (C) 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.
+ */
+
+#ifndef LIST_H
+#define LIST_H
+
+#define VERIFAST
+#include
+#include
+//@#include "common.gh"
+
+typedef size_t TickType_t;
+typedef size_t UBaseType_t;
+typedef ssize_t BaseType_t;
+
+#define pdTRUE 1
+#define pdFALSE 0
+
+/* Empty/no-op macros */
+#define mtCOVERAGE_TEST_MARKER()
+#define mtCOVERAGE_TEST_DELAY()
+#define listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList )
+#define listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList )
+#define listTEST_LIST_INTEGRITY( pxList )
+#define listTEST_LIST_ITEM_INTEGRITY( pxListItem )
+#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxListItem )
+#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxListItem )
+
+/* Max value stored in sentinel xListEnd element */
+#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;
+};
+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
+} 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;
+@*/
+
+/* 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 cells,
+ list 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 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,
+ listcells,
+ listvals) =
+ 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 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 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 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 cells,
+ list 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 cells1,
+ list vals1,
+ struct xLIST_ITEM *n2,
+ struct xLIST_ITEM *nprev2,
+ struct xLIST_ITEM *mnext2,
+ struct xLIST_ITEM *m2,
+ list cells2,
+ list 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(
+ list 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)`. */
+/*@
+lemma void drop_nth_index_of(list 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 x, list l1, list 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 610bc03d93..a05b327f75 100644
--- a/FreeRTOS/Test/VeriFast/include/proof/queue.h
+++ b/FreeRTOS/Test/VeriFast/include/proof/queue.h
@@ -305,7 +305,6 @@ ensures
}
drop_drop(1, j, elements);
nth_drop2(elements, i);
- open buffer(buffer + (i+1) * M, (N-1-i), M, _);
}
}
diff --git a/FreeRTOS/Test/VeriFast/list/README.md b/FreeRTOS/Test/VeriFast/list/README.md
new file mode 100644
index 0000000000..b9385b920a
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/list/README.md
@@ -0,0 +1,69 @@
+# FreeRTOS list proofs
+
+The list predicates and proofs are inspired by and based on the work from
+Ferreira et al. (STTT'14).
+
+The main shape predicate is a doubly-linked list segment (DLS), as defined
+by Ferreira et al. in Fig 15. A DLS is defined by two `xLIST_ITEM` struct
+pointers `n` and `m` (possibly pointing to the same item) which are the start
+and end of the segment. We track the item pointers and values within the DLS in
+the lists `cells` and `vals`, respectively. Therefore `n` and `m` are the first
+and last items of `cells`.
+
+```
+ +--+ +--+
+ -----n-> |*n| ... |*m| -mnext->
+ <-nprev- | | | | <-m-----
+ +--+ +--+
+ ^-----------^
+ DLS(n, nprev, mnext, m)
+```
+
+With base case: `n == m` (single item case)
+
+```
+ +--+
+ -----n-> |*n| -mnext->
+ <-nprev- | | <-n-----
+ +--+
+ ^--^
+ xLIST_ITEM
+ DLS(n, nprev, mnext, n)
+```
+
+Cons case:
+
+```
+ +--+ +--+ +--+
+ -----n-> |*n| -o-> |*o| ... |*m| -mnext->
+ <-nprev- | | <-n- | | | | <-m-----
+ +--+ +--+ +--+
+ ^--^ ^-----------^
+ xLIST_ITEM DLS(o, n, mnext, m)
+
+ ^---------------------^
+ DLS(n, nprev, mnext, m)
+```
+
+A DLS can be made into a well-formed list by joining `n` and `m` into a cycle.
+Note that unlike Ferreira et al.'s list shape predicate, we always start with
+the sentinel end item to avoid a top-level case-split. So in the following
+diagram the start and end of the DLS are `end` and the item-before-end
+`endprev`.
+
+```
+ .-----------------------------------.
+ | +--------+ +--------+ |
+ `--> |*end | ... |*endprev| ----'
+ .---- | | | | <---.
+ | +--------+ +--------+ |
+ `----------------------------------'
+ ^-----------------------^
+ DLS(end, endprev, end, endprev)
+```
+
+## References
+
+- Automated Verification of the FreeRTOS Scheduler in HIP/SLEEK\
+ João F. Ferreira, Cristian Gherghina, Guanhua He, Shengchao Qin, Wei-Ngan Chin\
+ https://joaoff.com/publication/2014/sttt/
diff --git a/FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c b/FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c
new file mode 100644
index 0000000000..ab6e12b4a4
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/list/listLIST_IS_EMPTY.c
@@ -0,0 +1,36 @@
+/*
+ * FreeRTOS VeriFast Proofs
+ * Copyright (C) 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.
+ */
+
+#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 )
+
+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); @*/
+{
+ /*@open xLIST(pxList, len, _, _, _, _);@*/
+ return listLIST_IS_EMPTY( pxList );
+ /*@close xLIST(pxList, len, _, _, cells, vals);@*/
+}
diff --git a/FreeRTOS/Test/VeriFast/list/uxListRemove.c b/FreeRTOS/Test/VeriFast/list/uxListRemove.c
new file mode 100644
index 0000000000..1d244bc06c
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/list/uxListRemove.c
@@ -0,0 +1,306 @@
+/*
+ * FreeRTOS VeriFast Proofs
+ * Copyright (C) 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.
+ */
+
+#include "proof/list.h"
+
+UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
+/*@requires
+ exists(?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));@*/
+{
+ /* For brevity we alias x to pxItemToRemove */
+ /*@struct xLIST_ITEM *x = pxItemToRemove;@*/
+
+ /* Start by establishing that the list must be non-empty since x != end */
+ /*@open xLIST(l, len, idx, end, cells, vals);@*/
+ /*@assert DLS(end, ?endprev, end, _, cells, vals, l);@*/
+ /*@assert vals == cons(portMAX_DELAY, _);@*/
+ /*@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 */
+ /*@int i = index_of(x, cells);@*/
+ /*@split(end, endprev, end, endprev, cells, vals, x, i);@*/
+ /*@list ys = take(i, cells);@*/
+ /*@list zs = drop(i, cells);@*/
+ /*@list vs = take(i, vals);@*/
+ /*@list ws = drop(i, vals);@*/
+ /*@assert length(ys) == length(vs);@*/
+ /*@assert length(zs) == length(ws);@*/
+ /*@assert DLS(end, endprev, x, ?xprev, ys, vs, l);@*/ /*< DLS1 (ys, vs) */
+ /*@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);
+ }
+ }
+ @*/
+ /*@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
+
+ pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
+ pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
+
+ /* Only used during decision coverage testing. */
+ mtCOVERAGE_TEST_DELAY();
+
+ /* Make sure the index is left pointing to a valid item. */
+ if( pxList->pxIndex == pxItemToRemove )
+ {
+ pxList->pxIndex = pxItemToRemove->pxPrevious;
+ }
+ else
+ {
+ mtCOVERAGE_TEST_MARKER();
+ }
+
+ pxItemToRemove->pxContainer = NULL;
+ ( pxList->uxNumberOfItems )--;
+
+ 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));
+ }
+ }
+ }
+ @*/
+ /*@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)));
+ }
+ @*/
+ /*@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));@*/
+/*@ensures
+ 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;
+ /*@close xLIST(l, len, idx, end, cells, vals);@*/
+ /*@close exists(l);@*/
+ uxListRemove( index );
+ return index;
+}
+
+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)));@*/
+/*@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_distinct_cells(l);@*/
+ /*@open xLIST(l, len, idx, end, cells, vals);@*/
+ ListItem_t *index = l->pxIndex;
+ /*@close xLIST(l, len, idx, end, cells, vals);@*/
+ /*@close exists(l);@*/
+ uxListRemove( index );
+ /*@open xLIST(l, len-1, x1, end, cons(end, cons(x1, cells_tl)), cons(portMAX_DELAY, cons(1, vals_tl)));@*/
+ index = l->pxIndex;
+ /*@close xLIST(l, len-1, x1, end, cons(end, cons(x1, cells_tl)), cons(portMAX_DELAY, cons(1, vals_tl)));@*/
+ /*@close exists(l);@*/
+ uxListRemove( index );
+}
diff --git a/FreeRTOS/Test/VeriFast/list/vListInitialise.c b/FreeRTOS/Test/VeriFast/list/vListInitialise.c
new file mode 100644
index 0000000000..6ea02e6afc
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/list/vListInitialise.c
@@ -0,0 +1,71 @@
+/*
+ * FreeRTOS VeriFast Proofs
+ * Copyright (C) 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.
+ */
+
+#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);
+@*/
+
+void vListInitialise( List_t * const pxList )
+/*@requires xLIST_uninitialised(pxList);@*/
+/*@ensures xLIST(pxList, 0, ?end, end, singleton(end), singleton(portMAX_DELAY));@*/
+{
+ /*@open xLIST_uninitialised(pxList);@*/
+
+ /* The list structure contains a list item which is used to mark the
+ * end of the list. To initialise the list the list end is inserted
+ * as the only list entry. */
+ pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
+
+ /* The list end value is the highest possible value in the list to
+ * ensure it remains at the end of the list. */
+ pxList->xListEnd.xItemValue = portMAX_DELAY;
+
+ /* The list end next and previous pointers point to itself so we know
+ * when the list is empty. */
+ pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
+ pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */
+
+ pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
+
+ /* Write known values into the list if
+ * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
+ 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
+ /*@ListItem_t *end = &(pxList->xListEnd);@*/
+ /*@close xLIST_ITEM(end, portMAX_DELAY, _, _, pxList);@*/
+ /*@close DLS(end, end, end, end, singleton(end), singleton(portMAX_DELAY), pxList);@*/
+ /*@close xLIST(pxList, 0, end, end, singleton(end), singleton(portMAX_DELAY));@*/
+}
diff --git a/FreeRTOS/Test/VeriFast/list/vListInitialiseItem.c b/FreeRTOS/Test/VeriFast/list/vListInitialiseItem.c
new file mode 100644
index 0000000000..d744f5f289
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/list/vListInitialiseItem.c
@@ -0,0 +1,37 @@
+/*
+ * FreeRTOS VeriFast Proofs
+ * Copyright (C) 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.
+ */
+
+#include "proof/list.h"
+
+void vListInitialiseItem( ListItem_t * const pxItem )
+/*@requires xLIST_ITEM(pxItem, _, _, _, _);@*/
+/*@ensures xLIST_ITEM(pxItem, _, _, _, NULL);@*/
+{
+ /* Make sure the list item is not recorded as being on a list. */
+ pxItem->pxContainer = NULL;
+
+ /* Write known values into the list item if
+ * configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
+ listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
+ listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
+ /*@close xLIST_ITEM(pxItem, _, _, _, NULL);@*/
+}
diff --git a/FreeRTOS/Test/VeriFast/list/vListInsert.c b/FreeRTOS/Test/VeriFast/list/vListInsert.c
new file mode 100644
index 0000000000..96e333832e
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/list/vListInsert.c
@@ -0,0 +1,316 @@
+/*
+ * FreeRTOS VeriFast Proofs
+ * Copyright (C) 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.
+ */
+
+#include "proof/list.h"
+
+
+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;@*/
+
+void vListInsert( List_t * const pxList,
+ ListItem_t * const pxNewListItem )
+/*@requires xLIST(pxList, ?len, ?idx, ?end, ?cells, ?vals) &*&
+ xLIST_ITEM(pxNewListItem, ?val, _, _, _);@*/
+/*@ensures xLIST(pxList, len+1, idx, end, ?new_cells, ?new_vals) &*&
+ remove(pxNewListItem, new_cells) == cells
+;@*/
+{
+ /*@xLIST_star_item(pxList, pxNewListItem);@*/
+ /*@open xLIST_ITEM(pxNewListItem, _, _, _, _);@*/
+ /*@open xLIST(pxList, len, idx, end, cells, vals);@*/
+ /*@assert DLS(end, ?endprev, end, endprev, cells, vals, pxList);@*/
+ ListItem_t * pxIterator;
+ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
+
+ /* 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 );
+
+ /* Insert the new list item into the list, sorted in xItemValue order.
+ *
+ * If the list already contains a list item with the same item value then the
+ * new list item should be placed after it. This ensures that TCBs which are
+ * stored in ready lists (all of which have the same xItemValue value) get a
+ * share of the CPU. However, if the xItemValue is the same as the back marker
+ * the iteration loop below will not end. Therefore the value is checked
+ * first, and the algorithm slightly modified if necessary. */
+ if( xValueOfInsertion == portMAX_DELAY )
+ {
+ /*@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, _, _, _, _);
+ }
+ @*/
+ pxIterator = pxList->xListEnd.pxPrevious;
+ }
+ else
+ {
+ /* *** NOTE ***********************************************************
+ * If you find your application is crashing here then likely causes are
+ * listed below. In addition see https://www.freertos.org/FAQHelp.html for
+ * more tips, and ensure configASSERT() is defined!
+ * https://www.freertos.org/a00110.html#configASSERT
+ *
+ * 1) Stack overflow -
+ * see https://www.freertos.org/Stacks-and-stack-overflow-checking.html
+ * 2) Incorrect interrupt priority assignment, especially on Cortex-M
+ * parts where numerically high priority values denote low actual
+ * interrupt priorities, which can seem counter intuitive. See
+ * https://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
+ * of configMAX_SYSCALL_INTERRUPT_PRIORITY on
+ * https://www.freertos.org/a00110.html
+ * 3) Calling an API function from within a critical section or when
+ * the scheduler is suspended, or calling an API function that does
+ * not end in "FromISR" from an interrupt.
+ * 4) Using a queue or semaphore before it has been initialised or
+ * before the scheduler has been started (are interrupts firing
+ * 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)
+ {
+ 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;
+ pxNewListItem->pxNext->pxPrevious = pxNewListItem;
+ pxNewListItem->pxPrevious = pxIterator;
+ pxIterator->pxNext = pxNewListItem;
+
+ /* Remember which list the item is in. This allows fast removal of the
+ * item later. */
+ pxNewListItem->pxContainer = pxList;
+
+ ( pxList->uxNumberOfItems )++;
+
+ /*@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))));
+ listnew_cells = append(take(i, cells), cons(pxIterator, cons(pxNewListItem, drop(i+1, cells))));
+ listnew_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
new file mode 100644
index 0000000000..063eeb7a64
--- /dev/null
+++ b/FreeRTOS/Test/VeriFast/list/vListInsertEnd.c
@@ -0,0 +1,234 @@
+/*
+ * FreeRTOS VeriFast Proofs
+ * Copyright (C) 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.
+ */
+
+#include "proof/list.h"
+
+void vListInsertEnd( List_t * const pxList,
+ ListItem_t * const pxNewListItem )
+/*@requires xLIST(pxList, ?len, ?idx, ?end, ?cells, ?vals) &*&
+ 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))));@*/
+{
+ /*@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
+
+ /*@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), _, _, _);
+ }
+ }
+ @*/
+
+ /* 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
+ * listGET_OWNER_OF_NEXT_ENTRY(). */
+ pxNewListItem->pxNext = pxIndex;
+ pxNewListItem->pxPrevious = pxIndex->pxPrevious;
+
+ /* Only used during decision coverage testing. */
+ mtCOVERAGE_TEST_DELAY();
+
+ pxIndex->pxPrevious->pxNext = pxNewListItem;
+ pxIndex->pxPrevious = pxNewListItem;
+
+ /* Remember which list the item is in. */
+ pxNewListItem->pxContainer = 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);
+ }
+ @*/
+}
+
+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;@*/
+/*@ensures
+ xLIST(l, len + 1, idx, end, _, append(vals, singleton(val)));@*/
+{
+ vListInsertEnd(l, pxNewListItem);
+}
diff --git a/FreeRTOS/Test/VeriFast/scripts/annotation_overhead.sh b/FreeRTOS/Test/VeriFast/scripts/annotation_overhead.sh
index 3384ea1aae..b49fc84bc7 100755
--- a/FreeRTOS/Test/VeriFast/scripts/annotation_overhead.sh
+++ b/FreeRTOS/Test/VeriFast/scripts/annotation_overhead.sh
@@ -1,3 +1,3 @@
#!/bin/bash -eu
-NO_COVERAGE=1 EXTRA_VERIFAST_ARGS=-stats make queue | grep overhead: | sort | uniq
+NO_COVERAGE=1 EXTRA_VERIFAST_ARGS=-stats make queue list | grep overhead: | sort | uniq
diff --git a/FreeRTOS/Test/VeriFast/scripts/diff_files.md b/FreeRTOS/Test/VeriFast/scripts/diff_files.md
index 59f62d3640..cfc2fb7dea 100644
--- a/FreeRTOS/Test/VeriFast/scripts/diff_files.md
+++ b/FreeRTOS/Test/VeriFast/scripts/diff_files.md
@@ -16,7 +16,7 @@ implementation and the proof directory.
```
cd scripts
./generate_diff_files.sh
-# will extract to ./FreeRTOS-Kernel/generated and ./queue/generated
+# will extract to ./FreeRTOS-Kernel/generated and ./queue/generated and ./list/generated
```
Then use `diff` for a side-by-side comparison. Note that the `--color=always`
@@ -24,12 +24,14 @@ flag needs v3.4+:
```
diff --color=always --width=$COLUMNS --suppress-common-lines --side-by-side FreeRTOS-Kernel/generated queue/generated | less -r
+diff --color=always --width=$COLUMNS --suppress-common-lines --side-by-side FreeRTOS-Kernel/generated list/generated | less -r
```
Or generate a html report using `diff2html`:
```
diff -u FreeRTOS-Kernel/generated queue/generated | diff2html -i stdin
+diff -u FreeRTOS-Kernel/generated list/generated | diff2html -i stdin
```
The expectation is that the proofs make minimal changes to the original source
diff --git a/FreeRTOS/Test/VeriFast/scripts/generate_diff_files.sh b/FreeRTOS/Test/VeriFast/scripts/generate_diff_files.sh
index 55f9cfbd24..db4d9469ae 100755
--- a/FreeRTOS/Test/VeriFast/scripts/generate_diff_files.sh
+++ b/FreeRTOS/Test/VeriFast/scripts/generate_diff_files.sh
@@ -1,6 +1,6 @@
#!/bin/bash -eu
-FUNCS=(
+QUEUE_FUNCS=(
prvCopyDataFromQueue
prvCopyDataToQueue
prvInitialiseNewQueue
@@ -22,6 +22,14 @@ FUNCS=(
xQueueReceiveFromISR
)
+LIST_FUNCS=(
+ uxListRemove
+ vListInitialise
+ vListInitialiseItem
+ vListInsertEnd
+ vListInsert
+)
+
if [ ! -d "FreeRTOS-Kernel" ]; then
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git
fi
@@ -29,7 +37,11 @@ pushd FreeRTOS-Kernel > /dev/null
rm -rf tags generated
ctags --excmd=number queue.c
mkdir generated
-for f in ${FUNCS[@]}; do
+for f in ${QUEUE_FUNCS[@]}; do
+ ../extract.py tags $f > generated/$f.c
+done
+ctags --excmd=number list.c
+for f in ${LIST_FUNCS[@]}; do
../extract.py tags $f > generated/$f.c
done
popd > /dev/null
@@ -40,8 +52,19 @@ pushd queue > /dev/null
rm -rf tags generated
ctags --excmd=number *.c
mkdir generated
-for f in ${FUNCS[@]}; do
+for f in ${QUEUE_FUNCS[@]}; do
../scripts/extract.py tags $f > generated/$f.c
done
popd > /dev/null
echo "created: queue/generated"
+
+ln -fs ../list .
+pushd list > /dev/null
+rm -rf tags generated
+ctags --excmd=number *.c
+mkdir generated
+for f in ${LIST_FUNCS[@]}; do
+ ../scripts/extract.py tags $f > generated/$f.c
+done
+popd > /dev/null
+echo "created: list/generated"
From 0b48e6a3b5bc7db36dc392a449cc5c4dede089f4 Mon Sep 17 00:00:00 2001
From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
Date: Thu, 27 Aug 2020 15:37:03 -0700
Subject: [PATCH 07/40] Utility macros to improve readability/static analysis.
(#219)
* Update FreeRTOS_IP_Private.h
* Update FreeRTOS_Sockets.h
* Update FreeRTOS_DNS.c
* Correct version number
* Update version number
* Update version number
---
.../Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c | 59 +++++++++++++------
.../include/FreeRTOS_IP_Private.h | 37 ++++++++----
.../include/FreeRTOS_Sockets.h | 18 ++----
3 files changed, 72 insertions(+), 42 deletions(-)
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
index c63ba537a2..ca9a7bd906 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
@@ -250,6 +250,17 @@ struct xDNSMessage
#include "pack_struct_end.h"
typedef struct xDNSMessage DNSMessage_t;
+ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSMessage_t )
+ {
+ /* coverity[misra_c_2012_rule_11_3_violation] */
+ return ( DNSMessage_t *)pvArgument;
+ }
+ static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( DNSMessage_t )
+ {
+ /* coverity[misra_c_2012_rule_11_3_violation] */
+ return ( const DNSMessage_t *) pvArgument;
+ }
+
/* A DNS query consists of a header, as described in 'struct xDNSMessage'
It is followed by 1 or more queries, each one consisting of a name and a tail,
with two fields: type and class
@@ -263,6 +274,12 @@ struct xDNSTail
#include "pack_struct_end.h"
typedef struct xDNSTail DNSTail_t;
+ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSTail_t )
+ {
+ /* coverity[misra_c_2012_rule_11_3_violation] */
+ return ( DNSTail_t * ) pvArgument;
+ }
+
/* DNS answer record header. */
#include "pack_struct_start.h"
struct xDNSAnswerRecord
@@ -275,6 +292,12 @@ struct xDNSAnswerRecord
#include "pack_struct_end.h"
typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
+ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSAnswerRecord_t )
+ {
+ /* coverity[misra_c_2012_rule_11_3_violation] */
+ return ( DNSAnswerRecord_t * ) pvArgument;
+ }
+
#if( ipconfigUSE_LLMNR == 1 )
#include "pack_struct_start.h"
@@ -377,7 +400,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
void vDNSCheckCallBack( void *pvSearchID )
{
const ListItem_t * pxIterator;
- const ListItem_t * xEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xCallbackList ) );
+ const ListItem_t * xEnd = listGET_END_MARKER( &xCallbackList );
vTaskSuspendAll();
{
@@ -467,7 +490,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
{
BaseType_t xResult = pdFALSE;
const ListItem_t * pxIterator;
- const ListItem_t * xEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xCallbackList ) );
+ const ListItem_t * xEnd = listGET_END_MARKER( &xCallbackList );
vTaskSuspendAll();
{
@@ -549,8 +572,8 @@ TickType_t uxIdentifier = 0U;
else
{
FreeRTOS_printf( ( "prvPrepareLookup: name is too long ( %lu > %lu )\n",
- ( unsigned long ) xLength,
- ( unsigned long ) ipconfigDNS_CACHE_NAME_LENGTH ) );
+ ( uint32_t ) xLength,
+ ( uint32_t ) ipconfigDNS_CACHE_NAME_LENGTH ) );
}
}
}
@@ -709,7 +732,7 @@ TickType_t uxWriteTimeOut_ticks = ipconfigDNS_SEND_BLOCK_TIME_TICKS;
if( bHasDot == pdFALSE )
{
/* Use LLMNR addressing. */
- ( ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer ) )->usFlags = 0;
+ ( ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer ) )->usFlags = 0;
xAddress.sin_addr = ipLLMNR_IP_ADDR; /* Is in network byte order. */
xAddress.sin_port = ipLLMNR_PORT;
xAddress.sin_port = FreeRTOS_ntohs( xAddress.sin_port );
@@ -732,7 +755,7 @@ TickType_t uxWriteTimeOut_ticks = ipconfigDNS_SEND_BLOCK_TIME_TICKS;
if( lBytes > 0 )
{
BaseType_t xExpected;
- const DNSMessage_t *pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucReceiveBuffer );
+ const DNSMessage_t *pxDNSMessageHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( DNSMessage_t, pucReceiveBuffer );
/* See if the identifiers match. */
if( uxIdentifier == ( TickType_t ) pxDNSMessageHeader->usIdentifier )
@@ -815,7 +838,7 @@ static const DNSMessage_t xDefaultPartDNSHeader =
/* Write in a unique identifier. Cast the Payload Buffer to DNSMessage_t
* to easily access fields of the DNS Message. */
- pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer );
+ pxDNSMessageHeader = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer );
pxDNSMessageHeader->usIdentifier = ( uint16_t ) uxIdentifier;
/* Create the resource record at the end of the header. First
@@ -856,7 +879,7 @@ static const DNSMessage_t xDefaultPartDNSHeader =
/* Finish off the record. Cast the record onto DNSTail_t stucture to easily
* access the fields of the DNS Message. */
- pxTail = ipPOINTER_CAST(DNSTail_t *, &( pucByte[ 1 ] ) );
+ pxTail = ipCAST_PTR_TO_TYPE_PTR( DNSTail_t, &( pucByte[ 1 ] ) );
#if defined( _lint ) || defined( __COVERITY__ )
( void ) pxTail;
@@ -1051,7 +1074,7 @@ size_t uxPayloadSize;
if( uxPayloadSize >= sizeof( DNSMessage_t ) )
{
pxDNSMessageHeader =
- ipPOINTER_CAST( DNSMessage_t *, &( pxNetworkBuffer->pucEthernetBuffer [ sizeof( UDPPacket_t ) ] ) );
+ ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pxNetworkBuffer->pucEthernetBuffer );
/* The parameter pdFALSE indicates that the reply was not expected. */
( void ) prvParseDNSReply( ( uint8_t * ) pxDNSMessageHeader,
@@ -1069,7 +1092,7 @@ size_t uxPayloadSize;
uint32_t ulNBNSHandlePacket( NetworkBufferDescriptor_t * pxNetworkBuffer )
{
- UDPPacket_t *pxUDPPacket = ipPOINTER_CAST( UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ UDPPacket_t *pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
uint8_t *pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ sizeof( *pxUDPPacket ) ] );
prvTreatNBNS( pucUDPPayloadBuffer,
@@ -1119,7 +1142,7 @@ BaseType_t xReturn = pdTRUE;
/* Parse the DNS message header. Map the byte stream onto a structure
* for easier access. */
- pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer );
+ pxDNSMessageHeader = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer );
/* Introduce a do {} while (0) to allow the use of breaks. */
do
@@ -1266,7 +1289,7 @@ BaseType_t xReturn = pdTRUE;
/* This is the required record type and is of sufficient size. */
/* Mapping pucByte to a DNSAnswerRecord allows easy access of the
* fields of the structure. */
- pxDNSAnswerRecord = ipPOINTER_CAST( DNSAnswerRecord_t *, pucByte );
+ pxDNSAnswerRecord = ipCAST_PTR_TO_TYPE_PTR( DNSAnswerRecord_t, pucByte );
/* Sanity check the data length of an IPv4 answer. */
if( FreeRTOS_ntohs( pxDNSAnswerRecord->usDataLength ) == ( uint16_t ) sizeof( uint32_t ) )
@@ -1319,7 +1342,7 @@ BaseType_t xReturn = pdTRUE;
/* It's not an A record, so skip it. Get the header location
and then jump over the header. */
/* Cast the response to DNSAnswerRecord for easy access to fields of the DNS response. */
- pxDNSAnswerRecord = ipPOINTER_CAST( DNSAnswerRecord_t *, pucByte );
+ pxDNSAnswerRecord = ipCAST_PTR_TO_TYPE_PTR( DNSAnswerRecord_t, pucByte );
pucByte = &( pucByte[ sizeof( DNSAnswerRecord_t ) ] );
uxSourceBytesRemaining -= sizeof( DNSAnswerRecord_t );
@@ -1380,7 +1403,7 @@ BaseType_t xReturn = pdTRUE;
pucByte = &( pucNewBuffer[ xOffset1 ] );
pcRequestedName = ( char * ) &( pucNewBuffer[ xOffset2 ] );
- pxDNSMessageHeader = ipPOINTER_CAST( DNSMessage_t *, pucNewBuffer );
+ pxDNSMessageHeader = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucNewBuffer );
}
else
{
@@ -1568,7 +1591,7 @@ BaseType_t xReturn = pdTRUE;
/* Should not occur: pucUDPPayloadBuffer is part of a xNetworkBufferDescriptor */
if( pxNetworkBuffer != NULL )
{
- pxMessage = ipPOINTER_CAST( DNSMessage_t *, pucUDPPayloadBuffer );
+ pxMessage = ipCAST_PTR_TO_TYPE_PTR( DNSMessage_t, pucUDPPayloadBuffer );
/* As the fields in the structures are not word-aligned, we have to
copy the values byte-by-byte using macro's vSetField16() and vSetField32() */
@@ -1615,7 +1638,7 @@ BaseType_t xReturn;
/* This must be the first time this function has been called. Create
the socket. */
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
- if( ( xSocket == FREERTOS_INVALID_SOCKET ) || ( xSocket == NULL ) )
+ if( prvSocketValid( xSocket ) != pdTRUE )
{
/* There was an error, return NULL. */
xSocket = NULL;
@@ -1652,7 +1675,7 @@ BaseType_t xReturn;
UDPHeader_t *pxUDPHeader;
size_t uxDataLength;
- pxUDPPacket = ipPOINTER_CAST( UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
pxIPHeader = &pxUDPPacket->xIPHeader;
pxUDPHeader = &pxUDPPacket->xUDPHeader;
/* HT: started using defines like 'ipSIZE_OF_xxx' */
@@ -1700,7 +1723,7 @@ BaseType_t xReturn;
{
BaseType_t x;
BaseType_t xFound = pdFALSE;
- uint32_t ulCurrentTimeSeconds = ( xTaskGetTickCount() / portTICK_PERIOD_MS ) / 1000U;
+ uint32_t ulCurrentTimeSeconds = ( xTaskGetTickCount() / portTICK_PERIOD_MS ) / 1000UL;
uint32_t ulIPAddressIndex = 0;
static BaseType_t xFreeEntry = 0;
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
index e59ee63da1..e9478d946e 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
@@ -45,6 +45,20 @@ extern "C" {
#include "event_groups.h"
+/*-----------------------------------------------------------*/
+/* Utility macros for marking casts as recognized during */
+/* static analysis. */
+/*-----------------------------------------------------------*/
+#define ipCAST_PTR_TO_TYPE_PTR( TYPE, pointer ) ( vCastPointerTo_##TYPE( ( void * )( pointer ) ) )
+#define ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( TYPE, pointer ) ( vCastConstPointerTo_##TYPE( ( const void * )( pointer ) ) )
+
+/*-----------------------------------------------------------*/
+/* Utility macros for declaring cast utility functions in */
+/* order to centralize typecasting for static analysis. */
+/*-----------------------------------------------------------*/
+#define ipDECL_CAST_PTR_FUNC_FOR_TYPE( TYPE ) TYPE * vCastPointerTo_##TYPE( void * pvArgument )
+#define ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TYPE ) const TYPE * vCastConstPointerTo_##TYPE( const void * pvArgument )
+
typedef struct xNetworkAddressingParameters
{
uint32_t ulDefaultIPAddress;
@@ -189,6 +203,17 @@ struct xUDP_PACKET
#include "pack_struct_end.h"
typedef struct xUDP_PACKET UDPPacket_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( UDPPacket_t )
+{
+ /* coverity[misra_c_2012_rule_11_3_violation] */
+ return ( UDPPacket_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( UDPPacket_t )
+{
+ /* coverity[misra_c_2012_rule_11_3_violation] */
+ return ( const UDPPacket_t *) pvArgument;
+}
+
#include "pack_struct_start.h"
struct xTCP_PACKET
{
@@ -828,15 +853,3 @@ void vIPNetworkUpCalls( void );
#endif /* FREERTOS_IP_PRIVATE_H */
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h
index a6329ebc39..0ff55d17a0 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_Sockets.h
@@ -205,6 +205,12 @@ struct xSOCKET;
typedef struct xSOCKET *Socket_t;
typedef struct xSOCKET const * ConstSocket_t;
+static portINLINE int prvSocketValid( Socket_t xSocket )
+{
+ /* coverity[misra_c_2012_rule_11_4_violation] */
+ return ( ( xSocket != FREERTOS_INVALID_SOCKET ) && ( xSocket != NULL ) );
+}
+
#if( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
/* The SocketSet_t type is the equivalent to the fd_set type used by the
Berkeley API. */
@@ -417,15 +423,3 @@ void FreeRTOS_netstat( void );
#endif /* FREERTOS_SOCKETS_H */
-
-
-
-
-
-
-
-
-
-
-
-
From 66371d0cf0dcbc4df8a8101d9d1b67b3efd9e786 Mon Sep 17 00:00:00 2001
From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
Date: Thu, 27 Aug 2020 16:25:17 -0700
Subject: [PATCH 08/40] Add CBMC proof for prvProcessEthernetPacket (#199)
* Add proof
* Remove and Rename files
* Modify the makefile
* Update Makefile.json
* Add _static to FreeRTOS_IP.c
* Update prvProcessEthernetPacket_harness.c
* Update the proof and add list to stubs
* add assertions
* Update the proof
* cleanup
* Update
* Update after @yanjos-dev's comment
* Remove unnecessary assumption
---
.../prvProcessEthernetPacket/Makefile.json | 32 ++++++++++
.../prvProcessEthernetPacket_harness.c | 63 +++++++++++++++++++
.../CBMC/proofs/utility/memory_assignments.c | 2 +
3 files changed, 97 insertions(+)
create mode 100644 FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/Makefile.json
create mode 100644 FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/prvProcessEthernetPacket_harness.c
diff --git a/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/Makefile.json b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/Makefile.json
new file mode 100644
index 0000000000..7c7af99859
--- /dev/null
+++ b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/Makefile.json
@@ -0,0 +1,32 @@
+{
+ "ENTRY": "prvProcessEthernetPacket",
+ "CBMCFLAGS":
+ [
+ "--unwind 1",
+ "--unwindset prvTCPSendRepeated.0:13",
+ "--nondet-static",
+ "--flush"
+ ],
+ "OBJS":
+ [
+ "$(ENTRY)_harness.goto",
+ "$(FREERTOS)/../FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.goto"
+ ],
+ "INSTFLAGS":
+ [
+ ],
+ "OPT":
+ [
+ "--export-file-local-symbols"
+ ],
+ "DEF":
+ [
+ "FREERTOS_TCP_ENABLE_VERIFICATION"
+ ],
+ "INC":
+ [
+ "$(FREERTOS)/../FreeRTOS-Plus/Test/CBMC/include",
+ "$(FREERTOS)/../FreeRTOS-Plus/Test/CBMC/proofs/utility",
+ "$(FREERTOS)/../FreeRTOS-Plus/Test/CBMC/stubs"
+ ]
+}
diff --git a/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/prvProcessEthernetPacket_harness.c b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/prvProcessEthernetPacket_harness.c
new file mode 100644
index 0000000000..c70bfaa94e
--- /dev/null
+++ b/FreeRTOS-Plus/Test/CBMC/proofs/prvProcessEthernetPacket/prvProcessEthernetPacket_harness.c
@@ -0,0 +1,63 @@
+/* Standard includes. */
+#include
+#include
+
+/* FreeRTOS includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#include "semphr.h"
+
+/* FreeRTOS+TCP includes. */
+#include "FreeRTOS_IP.h"
+#include "FreeRTOS_Sockets.h"
+#include "FreeRTOS_IP_Private.h"
+#include "FreeRTOS_UDP_IP.h"
+#include "FreeRTOS_DHCP.h"
+#include "NetworkInterface.h"
+#include "NetworkBufferManagement.h"
+#include "FreeRTOS_ARP.h"
+
+#include "memory_assignments.c"
+#include "freertos_api.c"
+
+/****************************************************************
+ * Signature of function under test
+ ****************************************************************/
+void __CPROVER_file_local_FreeRTOS_IP_c_prvProcessEthernetPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
+
+
+/* This function has been proved to be memory safe in another proof (in ARP/ARPRefreshCacheEntry). Hence we assume it to be correct here. */
+void vARPRefreshCacheEntry( const MACAddress_t * pxMACAddress, const uint32_t ulIPAddress )
+{
+ /* pxMACAddress can be NULL or non-NULL. No need to assert. */
+}
+
+/* This function has been proved to be memory safe in another proof (in ARP/ARPProcessPacket). Hence we assume it to be correct here. */
+eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame )
+{
+ __CPROVER_assert( pxARPFrame != NULL, "pxARPFrame cannot be NULL" );
+
+ eFrameProcessingResult_t eReturn;
+ return eReturn;
+}
+
+/* This function has been proved to be memory safe in another proof (in parsing/ProcessIPPacket). Hence we assume it to be correct here. */
+eFrameProcessingResult_t __CPROVER_file_local_FreeRTOS_IP_c_prvProcessIPPacket( IPPacket_t * pxIPPacket, NetworkBufferDescriptor_t * const pxNetworkBuffer )
+{
+ __CPROVER_assert( pxIPPacket != NULL, "pxIPPacket cannot be NULL" );
+ __CPROVER_assert( pxNetworkBuffer != NULL, "pxNetworkBuffer cannot be NULL" );
+
+ eFrameProcessingResult_t result;
+ return result;
+}
+
+void harness() {
+
+ NetworkBufferDescriptor_t * const pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ipTOTAL_ETHERNET_FRAME_SIZE, 0 );
+
+ /* The network buffer cannot be NULL for this function call. If it is, it will hit an assert in the function. */
+ __CPROVER_assume( pxNetworkBuffer != NULL );
+
+ __CPROVER_file_local_FreeRTOS_IP_c_prvProcessEthernetPacket( pxNetworkBuffer );
+}
diff --git a/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c b/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c
index 6bcb9319a2..9866eff264 100644
--- a/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c
+++ b/FreeRTOS-Plus/Test/CBMC/proofs/utility/memory_assignments.c
@@ -1,3 +1,5 @@
+#include
+
#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.
From 3fc432f7beb830cfab5bad5ae0e4f52a1ea59ce7 Mon Sep 17 00:00:00 2001
From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
Date: Fri, 28 Aug 2020 15:14:37 -0700
Subject: [PATCH 09/40] TCP: Address MISRA rule11.3 violations (#225)
---
.../Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c | 4 +-
.../Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c | 14 ++-
.../Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c | 66 ++++++++------
.../Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c | 61 +++++++------
.../FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c | 81 +++++++++++-------
.../include/FreeRTOS_IP_Private.h | 85 ++++++++++++++++++-
6 files changed, 222 insertions(+), 89 deletions(-)
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c
index 9104a72361..e86e7e61a6 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c
@@ -656,7 +656,7 @@ ARPPacket_t *pxARPPacket;
configASSERT( pxNetworkBuffer != NULL );
configASSERT( pxNetworkBuffer->xDataLength >= sizeof(ARPPacket_t) );
- pxARPPacket = ipPOINTER_CAST( ARPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ pxARPPacket = ipCAST_PTR_TO_TYPE_PTR( ARPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
/* memcpy the const part of the header information into the correct
location in the packet. This copies:
@@ -693,7 +693,7 @@ BaseType_t xCheckLoopback( NetworkBufferDescriptor_t * const pxDescriptor, BaseT
{
BaseType_t xResult = pdFALSE;
NetworkBufferDescriptor_t * pxUseDescriptor = pxDescriptor;
-const IPPacket_t *pxIPPacket = ipPOINTER_CAST( IPPacket_t *, pxUseDescriptor->pucEthernetBuffer );
+const IPPacket_t *pxIPPacket = ipCAST_PTR_TO_TYPE_PTR( IPPacket_t, pxUseDescriptor->pucEthernetBuffer );
/* This function will check if the target IP-address belongs to this device.
* If so, the packet will be passed to the IP-stack, who will answer it.
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c
index e12db9162c..b0b0687bfd 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c
@@ -154,6 +154,16 @@ struct xDHCPMessage_IPv4
#include "pack_struct_end.h"
typedef struct xDHCPMessage_IPv4 DHCPMessage_IPv4_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DHCPMessage_IPv4_t )
+{
+ return ( DHCPMessage_IPv4_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( DHCPMessage_IPv4_t )
+{
+ return ( const DHCPMessage_IPv4_t *) pvArgument;
+}
+
+
/* The UDP socket used for all incoming and outgoing DHCP traffic. */
_static Socket_t xDHCPSocket;
@@ -639,7 +649,7 @@ const uint32_t ulMandatoryOptions = 2UL; /* DHCP server address, and the correct
if( lBytes > 0 )
{
/* Map a DHCP structure onto the received data. */
- pxDHCPMessage = ipPOINTER_CAST( const DHCPMessage_IPv4_t *, pucUDPPayload );
+ pxDHCPMessage = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( DHCPMessage_IPv4_t, pucUDPPayload );
/* Sanity check. */
if( lBytes < ( int32_t ) sizeof( DHCPMessage_IPv4_t ) )
@@ -887,7 +897,7 @@ uint8_t *pucUDPPayloadBuffer;
/* Leave space for the UPD header. */
pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );
- pxDHCPMessage = ipPOINTER_CAST( DHCPMessage_IPv4_t *, pucUDPPayloadBuffer );
+ pxDHCPMessage = ipCAST_PTR_TO_TYPE_PTR( DHCPMessage_IPv4_t, pucUDPPayloadBuffer );
/* Most fields need to be zero. */
( void ) memset( pxDHCPMessage, 0x00, sizeof( DHCPMessage_IPv4_t ) );
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
index ca9a7bd906..a24bcb507f 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c
@@ -250,16 +250,14 @@ struct xDNSMessage
#include "pack_struct_end.h"
typedef struct xDNSMessage DNSMessage_t;
- static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSMessage_t )
- {
- /* coverity[misra_c_2012_rule_11_3_violation] */
- return ( DNSMessage_t *)pvArgument;
- }
- static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( DNSMessage_t )
- {
- /* coverity[misra_c_2012_rule_11_3_violation] */
- return ( const DNSMessage_t *) pvArgument;
- }
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSMessage_t )
+{
+ return ( DNSMessage_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( DNSMessage_t )
+{
+ return ( const DNSMessage_t *) pvArgument;
+}
/* A DNS query consists of a header, as described in 'struct xDNSMessage'
It is followed by 1 or more queries, each one consisting of a name and a tail,
@@ -274,11 +272,10 @@ struct xDNSTail
#include "pack_struct_end.h"
typedef struct xDNSTail DNSTail_t;
- static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSTail_t )
- {
- /* coverity[misra_c_2012_rule_11_3_violation] */
- return ( DNSTail_t * ) pvArgument;
- }
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSTail_t )
+{
+ return ( DNSTail_t * ) pvArgument;
+}
/* DNS answer record header. */
#include "pack_struct_start.h"
@@ -292,11 +289,10 @@ struct xDNSAnswerRecord
#include "pack_struct_end.h"
typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
- static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSAnswerRecord_t )
- {
- /* coverity[misra_c_2012_rule_11_3_violation] */
- return ( DNSAnswerRecord_t * ) pvArgument;
- }
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSAnswerRecord_t )
+{
+ return ( DNSAnswerRecord_t * ) pvArgument;
+}
#if( ipconfigUSE_LLMNR == 1 )
@@ -314,6 +310,12 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
#include "pack_struct_end.h"
typedef struct xLLMNRAnswer LLMNRAnswer_t;
+ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( LLMNRAnswer_t )
+ {
+ return ( LLMNRAnswer_t *)pvArgument;
+ }
+
+
#endif /* ipconfigUSE_LLMNR == 1 */
#if( ipconfigUSE_NBNS == 1 )
@@ -349,6 +351,11 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
#include "pack_struct_end.h"
typedef struct xNBNSAnswer NBNSAnswer_t;
+ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( NBNSAnswer_t )
+ {
+ return ( NBNSAnswer_t *)pvArgument;
+ }
+
#endif /* ipconfigUSE_NBNS == 1 */
/*-----------------------------------------------------------*/
@@ -376,6 +383,11 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
char pcName[ 1 ];
} DNSCallback_t;
+ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( DNSCallback_t )
+ {
+ return ( DNSCallback_t *)pvArgument;
+ }
+
static List_t xCallbackList;
/* Define FreeRTOS_gethostbyname() as a normal blocking call. */
@@ -408,7 +420,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
pxIterator != xEnd;
)
{
- DNSCallback_t *pxCallback = ipPOINTER_CAST( DNSCallback_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ DNSCallback_t *pxCallback = ipCAST_PTR_TO_TYPE_PTR( DNSCallback_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
/* Move to the next item because we might remove this item */
pxIterator = ( const ListItem_t * ) listGET_NEXT( pxIterator );
if( ( pvSearchID != NULL ) && ( pvSearchID == pxCallback->pvSearchID ) )
@@ -453,7 +465,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
TickType_t uxIdentifier )
{
size_t lLength = strlen( pcHostName );
- DNSCallback_t *pxCallback = ipPOINTER_CAST( DNSCallback_t *, pvPortMalloc( sizeof( *pxCallback ) + lLength ) );
+ DNSCallback_t *pxCallback = ipCAST_PTR_TO_TYPE_PTR( DNSCallback_t, pvPortMalloc( sizeof( *pxCallback ) + lLength ) );
/* Translate from ms to number of clock ticks. */
uxTimeout /= portTICK_PERIOD_MS;
@@ -471,7 +483,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
pxCallback->pvSearchID = pvSearchID;
pxCallback->uxRemaningTime = uxTimeout;
vTaskSetTimeOutState( &pxCallback->uxTimeoutState );
- listSET_LIST_ITEM_OWNER( &( pxCallback->xListItem ), ipPOINTER_CAST( void *, pxCallback ) );
+ listSET_LIST_ITEM_OWNER( &( pxCallback->xListItem ), ( void *) pxCallback );
listSET_LIST_ITEM_VALUE( &( pxCallback->xListItem ), uxIdentifier );
vTaskSuspendAll();
{
@@ -500,7 +512,7 @@ typedef struct xDNSAnswerRecord DNSAnswerRecord_t;
{
if( listGET_LIST_ITEM_VALUE( pxIterator ) == uxIdentifier )
{
- DNSCallback_t *pxCallback = ipPOINTER_CAST( DNSCallback_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ DNSCallback_t *pxCallback = ipCAST_PTR_TO_TYPE_PTR( DNSCallback_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
pxCallback->pCallbackFunction( pcName, pxCallback->pvSearchID, ulIPAddress );
( void ) uxListRemove( &pxCallback->xListItem );
@@ -1415,7 +1427,7 @@ BaseType_t xReturn = pdTRUE;
/* The test on 'pucNewBuffer' is only to satisfy lint. */
if( ( pxNetworkBuffer != NULL ) && ( pucNewBuffer != NULL ) )
{
- pxAnswer = ipPOINTER_CAST( LLMNRAnswer_t *, pucByte );
+ pxAnswer = ipCAST_PTR_TO_TYPE_PTR( LLMNRAnswer_t, pucByte );
/* We leave 'usIdentifier' and 'usQuestions' untouched */
#ifndef _lint
@@ -1604,8 +1616,8 @@ BaseType_t xReturn = pdTRUE;
#else
( void ) pxMessage;
#endif
-
- pxAnswer = ipPOINTER_CAST( NBNSAnswer_t *, &( pucUDPPayloadBuffer[ offsetof( NBNSRequest_t, usType ) ] ) );
+
+ pxAnswer = ipCAST_PTR_TO_TYPE_PTR( NBNSAnswer_t, &( pucUDPPayloadBuffer[ offsetof( NBNSRequest_t, usType ) ] ) );
#ifndef _lint
vSetField16( pxAnswer, NBNSAnswer_t, usType, usType ); /* Type */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
index bfd2a9c156..5dff8ef4a9 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
@@ -158,6 +158,16 @@ typedef union _xUnionPtr
uint8_t *u8ptr;
} xUnionPtr;
+
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( NetworkBufferDescriptor_t )
+{
+ return ( NetworkBufferDescriptor_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( NetworkBufferDescriptor_t )
+{
+ return ( const NetworkBufferDescriptor_t *) pvArgument;
+}
+
/*-----------------------------------------------------------*/
/*
@@ -362,7 +372,7 @@ struct freertos_sockaddr xAddress;
/* Wait until there is something to do. If the following call exits
* due to a time out rather than a message being received, set a
* 'NoEvent' value. */
- if ( xQueueReceive( xNetworkEventQueue, ipPOINTER_CAST( void *, &xReceivedEvent ), xNextIPSleep ) == pdFALSE )
+ if ( xQueueReceive( xNetworkEventQueue, ( void *) &xReceivedEvent, xNextIPSleep ) == pdFALSE )
{
xReceivedEvent.eEventType = eNoEvent;
}
@@ -395,14 +405,14 @@ struct freertos_sockaddr xAddress;
case eNetworkRxEvent:
/* The network hardware driver has received a new packet. A
pointer to the received buffer is located in the pvData member
- of the received event structure. */
- prvHandleEthernetPacket( ipPOINTER_CAST( NetworkBufferDescriptor_t *, xReceivedEvent.pvData ) );
+ of the received event structure. */
+ prvHandleEthernetPacket( ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, xReceivedEvent.pvData ) );
break;
case eNetworkTxEvent:
/* Send a network packet. The ownership will be transferred to
the driver, which will release it after delivery. */
- ( void ) xNetworkInterfaceOutput( ipPOINTER_CAST( NetworkBufferDescriptor_t *, xReceivedEvent.pvData ), pdTRUE );
+ ( void ) xNetworkInterfaceOutput( ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, xReceivedEvent.pvData ), pdTRUE );
break;
case eARPTimerEvent :
@@ -416,7 +426,7 @@ struct freertos_sockaddr xAddress;
usLocalPort. vSocketBind() will actually bind the socket and the
API will unblock as soon as the eSOCKET_BOUND event is
triggered. */
- pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, xReceivedEvent.pvData );
+ pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, xReceivedEvent.pvData );
xAddress.sin_addr = 0U; /* For the moment. */
xAddress.sin_port = FreeRTOS_ntohs( pxSocket->usLocalPort );
pxSocket->usLocalPort = 0U;
@@ -434,14 +444,14 @@ struct freertos_sockaddr xAddress;
IP-task to actually close a socket. This is handled in
vSocketClose(). As the socket gets closed, there is no way to
report back to the API, so the API won't wait for the result */
- ( void ) vSocketClose( ipPOINTER_CAST( FreeRTOS_Socket_t *, xReceivedEvent.pvData ) );
+ ( void ) vSocketClose( ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, xReceivedEvent.pvData ) );
break;
case eStackTxEvent :
/* The network stack has generated a packet to send. A
pointer to the generated buffer is located in the pvData
member of the received event structure. */
- vProcessGeneratedUDPPacket( ipPOINTER_CAST( NetworkBufferDescriptor_t *, xReceivedEvent.pvData ) );
+ vProcessGeneratedUDPPacket( ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, xReceivedEvent.pvData ) );
break;
case eDHCPEvent:
@@ -462,13 +472,13 @@ struct freertos_sockaddr xAddress;
{
#if( ipconfigSELECT_USES_NOTIFY != 0 )
{
- SocketSelectMessage_t *pxMessage = ipPOINTER_CAST( SocketSelectMessage_t *, xReceivedEvent.pvData );
+ SocketSelectMessage_t *pxMessage = ipCAST_PTR_TO_TYPE_PTR( SocketSelectMessage_t, xReceivedEvent.pvData );
vSocketSelect( pxMessage->pxSocketSet );
( void ) xTaskNotifyGive( pxMessage->xTaskhandle );
}
#else
- {
- vSocketSelect( ipPOINTER_CAST( SocketSelect_t *, xReceivedEvent.pvData ) );
+ {
+ vSocketSelect( ipCAST_PTR_TO_TYPE_PTR( SocketSelect_t, xReceivedEvent.pvData ) );
}
#endif /* ( ipconfigSELECT_USES_NOTIFY != 0 ) */
}
@@ -501,7 +511,7 @@ struct freertos_sockaddr xAddress;
received a new connection. */
#if( ipconfigUSE_TCP == 1 )
{
- pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, xReceivedEvent.pvData );
+ pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, xReceivedEvent.pvData );
if( xTCPCheckNewClient( pxSocket ) != pdFALSE )
{
@@ -1153,11 +1163,10 @@ void FreeRTOS_SetAddressConfiguration( const uint32_t *pulIPAddress,
}
if( ( uxGetNumberOfFreeNetworkBuffers() >= 3U ) && ( uxNumberOfBytesToSend >= 1U ) && ( xEnoughSpace != pdFALSE ) )
{
- pxEthernetHeader = ipPOINTER_CAST( EthernetHeader_t *, pxNetworkBuffer->pucEthernetBuffer );
+ pxEthernetHeader = ipCAST_PTR_TO_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer );
pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE;
-
- pxICMPHeader = ipPOINTER_CAST( ICMPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipIP_PAYLOAD_OFFSET ] ) );
+ pxICMPHeader = ipCAST_PTR_TO_TYPE_PTR( ICMPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipIP_PAYLOAD_OFFSET ] ) );
usSequenceNumber++;
/* Fill in the basic header information. */
@@ -1289,7 +1298,7 @@ eFrameProcessingResult_t eReturn;
const EthernetHeader_t *pxEthernetHeader;
/* Map the buffer onto Ethernet Header struct for easy access to fields. */
- pxEthernetHeader = ipPOINTER_CAST( const EthernetHeader_t *, pucEthernetBuffer );
+ pxEthernetHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( EthernetHeader_t, pucEthernetBuffer );
if( memcmp( ipLOCAL_MAC_ADDRESS, pxEthernetHeader->xDestinationAddress.ucBytes, sizeof( MACAddress_t ) ) == 0 )
{
@@ -1430,7 +1439,7 @@ eFrameProcessingResult_t eReturned = eReleaseBuffer;
eReturned = ipCONSIDER_FRAME_FOR_PROCESSING( pxNetworkBuffer->pucEthernetBuffer );
/* Map the buffer onto the Ethernet Header struct for easy access to the fields. */
- pxEthernetHeader = ipPOINTER_CAST( const EthernetHeader_t *, pxNetworkBuffer->pucEthernetBuffer );
+ pxEthernetHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer );
/* The condition "eReturned == eProcessBuffer" must be true. */
#if( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 )
@@ -1444,7 +1453,7 @@ eFrameProcessingResult_t eReturned = eReleaseBuffer;
/* The Ethernet frame contains an ARP packet. */
if( pxNetworkBuffer->xDataLength >= sizeof( ARPPacket_t ) )
{
- eReturned = eARPProcessPacket( ipPOINTER_CAST( ARPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ) );
+ eReturned = eARPProcessPacket( ipCAST_PTR_TO_TYPE_PTR( ARPPacket_t, pxNetworkBuffer->pucEthernetBuffer ) );
}
else
{
@@ -1456,7 +1465,7 @@ eFrameProcessingResult_t eReturned = eReleaseBuffer;
/* The Ethernet frame contains an IP packet. */
if( pxNetworkBuffer->xDataLength >= sizeof( IPPacket_t ) )
{
- eReturned = prvProcessIPPacket( ipPOINTER_CAST( IPPacket_t *, pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer );
+ eReturned = prvProcessIPPacket( ipCAST_PTR_TO_TYPE_PTR( IPPacket_t, pxNetworkBuffer->pucEthernetBuffer ), pxNetworkBuffer );
}
else
{
@@ -1643,7 +1652,7 @@ eFrameProcessingResult_t eReturn = eProcessBuffer;
const uint16_t *pusChecksum;
/* pxProtPack will point to the offset were the protocols begin. */
- pxProtPack = ipPOINTER_CAST( ProtocolPacket_t *, &( pxNetworkBuffer->pucEthernetBuffer[ uxHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );
+ pxProtPack = ipCAST_PTR_TO_TYPE_PTR( ProtocolPacket_t, &( pxNetworkBuffer->pucEthernetBuffer[ uxHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );
pusChecksum = ( const uint16_t * ) ( &( pxProtPack->xUDPPacket.xUDPHeader.usChecksum ) );
if( *pusChecksum == ( uint16_t ) 0U )
{
@@ -1762,7 +1771,7 @@ uint8_t ucProtocol;
{
/* Map the buffer onto a ICMP-Packet struct to easily access the
* fields of ICMP packet. */
- ICMPPacket_t *pxICMPPacket = ipPOINTER_CAST( ICMPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ ICMPPacket_t *pxICMPPacket = ipCAST_PTR_TO_TYPE_PTR( ICMPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
if( pxIPHeader->ulDestinationIPAddress == *ipLOCAL_IP_ADDRESS_POINTER )
{
eReturn = prvProcessICMPPacket( pxICMPPacket );
@@ -1782,7 +1791,7 @@ uint8_t ucProtocol;
/* Map the buffer onto a UDP-Packet struct to easily access the
* fields of UDP packet. */
- const UDPPacket_t *pxUDPPacket = ipPOINTER_CAST( const UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ const UDPPacket_t *pxUDPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
uint16_t usLength;
/* Note the header values required prior to the checksum
@@ -2010,7 +2019,7 @@ uint8_t ucProtocol;
/* Map the buffer onto a IP-Packet struct to easily access the
* fields of the IP packet. */
- pxIPPacket = ipPOINTER_CAST( const IPPacket_t *, pucEthernetBuffer );
+ pxIPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPPacket_t, pucEthernetBuffer );
ucVersionHeaderLength = pxIPPacket->xIPHeader.ucVersionHeaderLength;
/* Test if the length of the IP-header is between 20 and 60 bytes,
@@ -2049,7 +2058,7 @@ uint8_t ucProtocol;
of this calculation. */
/* Map the Buffer onto the Protocol Packet struct for easy access to the
* struct fields. */
- pxProtPack = ipPOINTER_CAST( ProtocolPacket_t *, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );
+ pxProtPack = ipCAST_PTR_TO_TYPE_PTR( ProtocolPacket_t, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );
/* Switch on the Layer 3/4 protocol. */
if( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP )
@@ -2133,7 +2142,7 @@ BaseType_t location = 0;
}
/* Parse the packet length. */
- pxIPPacket = ipPOINTER_CAST( const IPPacket_t *, pucEthernetBuffer );
+ pxIPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPPacket_t, pucEthernetBuffer );
/* Per https://tools.ietf.org/html/rfc791, the four-bit Internet Header
Length field contains the length of the internet header in 32-bit words. */
@@ -2165,7 +2174,7 @@ BaseType_t location = 0;
and IP headers incorrectly aligned. However, either way, the "third"
protocol (Layer 3 or 4) header will be aligned, which is the convenience
of this calculation. */
- pxProtPack = ipPOINTER_CAST( ProtocolPacket_t *, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );
+ pxProtPack = ipCAST_PTR_TO_TYPE_PTR( ProtocolPacket_t, &( pucEthernetBuffer[ uxIPHeaderLength - ipSIZE_OF_IPv4_HEADER ] ) );
/* Switch on the Layer 3/4 protocol. */
if( ucProtocol == ( uint8_t ) ipPROTOCOL_UDP )
@@ -2578,7 +2587,7 @@ EthernetHeader_t *pxEthernetHeader;
#endif
{
/* Map the Buffer to Ethernet Header struct for easy access to fields. */
- pxEthernetHeader = ipPOINTER_CAST( EthernetHeader_t *, pxNetworkBuffer->pucEthernetBuffer );
+ pxEthernetHeader = ipCAST_PTR_TO_TYPE_PTR( EthernetHeader_t, pxNetworkBuffer->pucEthernetBuffer );
/* Swap source and destination MAC addresses. */
( void ) memcpy( &( pxEthernetHeader->xDestinationAddress ), &( pxEthernetHeader->xSourceAddress ), sizeof( pxEthernetHeader->xDestinationAddress ) );
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
index 25d1dbd755..66275d7f47 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
@@ -87,7 +87,28 @@ range 1024-65535" excluding those already in use (inbound or outbound). */
#define sock80_PERCENT 80U
#define sock100_PERCENT 100U
+#if( ipconfigUSE_CALLBACKS != 0 )
+ static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( F_TCP_UDP_Handler_t )
+ {
+ return ( F_TCP_UDP_Handler_t *)pvArgument;
+ }
+ static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( F_TCP_UDP_Handler_t )
+ {
+ return ( const F_TCP_UDP_Handler_t *) pvArgument;
+ }
+#endif
+
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( NetworkBufferDescriptor_t )
+{
+ return ( NetworkBufferDescriptor_t *)pvArgument;
+}
+
+
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( StreamBuffer_t )
+{
+ return ( StreamBuffer_t *)pvArgument;
+}
/*-----------------------------------------------------------*/
/*
@@ -294,7 +315,7 @@ Socket_t xReturn;
size depends on the type of socket: UDP sockets need less space. A
define 'pvPortMallocSocket' will used to allocate the necessary space.
By default it points to the FreeRTOS function 'pvPortMalloc()'. */
- pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, pvPortMallocSocket( uxSocketSize ) );
+ pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, pvPortMallocSocket( uxSocketSize ) );
if( pxSocket == NULL )
{
@@ -394,7 +415,7 @@ Socket_t xReturn;
{
SocketSelect_t *pxSocketSet;
- pxSocketSet = ipPOINTER_CAST( SocketSelect_t *, pvPortMalloc( sizeof( *pxSocketSet ) ) );
+ pxSocketSet = ipCAST_PTR_TO_TYPE_PTR( SocketSelect_t, pvPortMalloc( sizeof( *pxSocketSet ) ) );
if( pxSocketSet != NULL )
{
@@ -733,7 +754,7 @@ EventBits_t xEventBits = ( EventBits_t ) 0;
taskENTER_CRITICAL();
{
/* The owner of the list item is the network buffer. */
- pxNetworkBuffer = ipPOINTER_CAST( NetworkBufferDescriptor_t *, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) );
+ pxNetworkBuffer = ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) );
if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_MSG_PEEK ) == 0U )
{
@@ -1273,7 +1294,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
{
while( listCURRENT_LIST_LENGTH( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) > 0U )
{
- pxNetworkBuffer = ipPOINTER_CAST( NetworkBufferDescriptor_t *, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) );
+ pxNetworkBuffer = ipCAST_PTR_TO_TYPE_PTR( NetworkBufferDescriptor_t, listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->u.xUDP.xWaitingPacketsList ) ) );
( void ) uxListRemove( &( pxNetworkBuffer->xBufferListItem ) );
vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
}
@@ -1317,7 +1338,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
static void prvTCPSetSocketCount( FreeRTOS_Socket_t const * pxSocketToDelete )
{
const ListItem_t *pxIterator;
- const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) );
+ const ListItem_t *pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList );
FreeRTOS_Socket_t *pxOtherSocket;
uint16_t usLocalPort = pxSocketToDelete->usLocalPort;
@@ -1325,7 +1346,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) )
{
- pxOtherSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ pxOtherSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
if( ( pxOtherSocket->u.xTCP.ucTCPState == ( uint8_t ) eTCP_LISTEN ) &&
( pxOtherSocket->usLocalPort == usLocalPort ) &&
( pxOtherSocket->u.xTCP.usChildCount != 0U ) )
@@ -1409,12 +1430,12 @@ FreeRTOS_Socket_t *pxSocket;
{
case FREERTOS_SO_RCVTIMEO :
/* Receive time out. */
- pxSocket->xReceiveBlockTime = *( ipPOINTER_CAST( const TickType_t *, pvOptionValue ) );
+ pxSocket->xReceiveBlockTime = *( ( TickType_t *) pvOptionValue );
xReturn = 0;
break;
case FREERTOS_SO_SNDTIMEO :
- pxSocket->xSendBlockTime = *( ipPOINTER_CAST( const TickType_t *, pvOptionValue ) );
+ pxSocket->xSendBlockTime = *( ( TickType_t *) pvOptionValue );
if( pxSocket->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_UDP )
{
/* The send time out is capped for the reason stated in the
@@ -1498,20 +1519,20 @@ FreeRTOS_Socket_t *pxSocket;
{
#if ipconfigUSE_TCP == 1
case FREERTOS_SO_TCP_CONN_HANDLER:
- pxSocket->u.xTCP.pxHandleConnected = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPConnected;
+ pxSocket->u.xTCP.pxHandleConnected = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnTCPConnected;
break;
case FREERTOS_SO_TCP_RECV_HANDLER:
- pxSocket->u.xTCP.pxHandleReceive = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPReceive;
+ pxSocket->u.xTCP.pxHandleReceive = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnTCPReceive;
break;
case FREERTOS_SO_TCP_SENT_HANDLER:
- pxSocket->u.xTCP.pxHandleSent = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnTCPSent;
+ pxSocket->u.xTCP.pxHandleSent = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnTCPSent;
break;
#endif /* ipconfigUSE_TCP */
case FREERTOS_SO_UDP_RECV_HANDLER:
- pxSocket->u.xUDP.pxHandleReceive = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnUDPReceive;
+ pxSocket->u.xUDP.pxHandleReceive = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnUDPReceive;
break;
case FREERTOS_SO_UDP_SENT_HANDLER:
- pxSocket->u.xUDP.pxHandleSent = ipPOINTER_CAST( const F_TCP_UDP_Handler_t *, pvOptionValue )->pxOnUDPSent;
+ pxSocket->u.xUDP.pxHandleSent = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( F_TCP_UDP_Handler_t, pvOptionValue )->pxOnUDPSent;
break;
default:
/* Should it throw an error here? */
@@ -1640,7 +1661,7 @@ FreeRTOS_Socket_t *pxSocket;
{
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
}
- if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 )
+ if( *( ( BaseType_t * ) pvOptionValue ) != 0 )
{
pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE;
}
@@ -1659,7 +1680,7 @@ FreeRTOS_Socket_t *pxSocket;
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
}
- if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 )
+ if( *( ( BaseType_t * ) pvOptionValue ) != 0 )
{
pxSocket->u.xTCP.bits.bCloseAfterSend = pdTRUE;
}
@@ -1678,7 +1699,7 @@ FreeRTOS_Socket_t *pxSocket;
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
}
- if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 )
+ if( *( ( BaseType_t *) pvOptionValue ) != 0 )
{
pxSocket->u.xTCP.xTCPWindow.u.bits.bSendFullSize = pdTRUE;
}
@@ -1704,7 +1725,7 @@ FreeRTOS_Socket_t *pxSocket;
{
break; /* will return -pdFREERTOS_ERRNO_EINVAL */
}
- if( *( ipPOINTER_CAST( const BaseType_t *, pvOptionValue ) ) != 0 )
+ if( *( ( BaseType_t * ) pvOptionValue ) != 0 )
{
pxSocket->u.xTCP.bits.bRxStopped = pdTRUE;
}
@@ -1803,7 +1824,7 @@ const ListItem_t * pxResult = NULL;
if( ( xIPIsNetworkTaskReady() != pdFALSE ) && ( pxList != NULL ) )
{
const ListItem_t *pxIterator;
- const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t*, listGET_END_MARKER( pxList ) );
+ const ListItem_t *pxEnd = listGET_END_MARKER( pxList );
for( pxIterator = listGET_NEXT( pxEnd );
pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) )
@@ -1835,7 +1856,7 @@ FreeRTOS_Socket_t *pxSocket = NULL;
if( pxListItem != NULL )
{
/* The owner of the list item is the socket itself. */
- pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxListItem ) );
+ pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxListItem ) );
configASSERT( pxSocket != NULL );
}
return pxSocket;
@@ -3058,7 +3079,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket )
TickType_t xNow = xTaskGetTickCount();
static TickType_t xLastTime = 0U;
TickType_t xDelta = xNow - xLastTime;
- const ListItem_t* pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) );
+ const ListItem_t* pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList );
const ListItem_t *pxIterator = ( const ListItem_t * ) listGET_HEAD_ENTRY( &xBoundTCPSocketsList );
xLastTime = xNow;
@@ -3070,7 +3091,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket )
while( pxIterator != pxEnd )
{
- pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
pxIterator = ( ListItem_t * ) listGET_NEXT( pxIterator );
/* Sockets with 'tmout == 0' do not need any regular attention. */
@@ -3142,7 +3163,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket )
{
const ListItem_t *pxIterator;
FreeRTOS_Socket_t *pxResult = NULL, *pxListenSocket = NULL;
- const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) );
+ const ListItem_t *pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList );
/* Parameter not yet supported. */
( void ) ulLocalIP;
@@ -3151,7 +3172,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket )
pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) )
{
- FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ FreeRTOS_Socket_t *pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
if( pxSocket->usLocalPort == ( uint16_t ) uxLocalPort )
{
@@ -3245,7 +3266,7 @@ void vSocketWakeUpUser( FreeRTOS_Socket_t *pxSocket )
uxSize = ( sizeof( *pxBuffer ) + uxLength ) - sizeof( pxBuffer->ucArray );
- pxBuffer = ipPOINTER_CAST( StreamBuffer_t *, pvPortMallocLarge( uxSize ) );
+ pxBuffer = ipCAST_PTR_TO_TYPE_PTR( StreamBuffer_t, pvPortMallocLarge( uxSize ) );
if( pxBuffer == NULL )
{
@@ -3701,14 +3722,14 @@ BaseType_t FreeRTOS_udp_rx_size( Socket_t xSocket )
}
else
{
- const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) );
- const ListItem_t *pxEndUDP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundUDPSocketsList ) );
+ const ListItem_t *pxEndTCP = listGET_END_MARKER( &xBoundTCPSocketsList );
+ const ListItem_t *pxEndUDP = listGET_END_MARKER( &xBoundUDPSocketsList );
FreeRTOS_printf( ( "Prot Port IP-Remote : Port R/T Status Alive tmout Child\n" ) );
for( pxIterator = listGET_HEAD_ENTRY( &xBoundTCPSocketsList );
pxIterator != pxEndTCP;
pxIterator = listGET_NEXT( pxIterator ) )
{
- const FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( const FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ const FreeRTOS_Socket_t *pxSocket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
#if( ipconfigTCP_KEEP_ALIVE == 1 )
TickType_t age = xTaskGetTickCount() - pxSocket->u.xTCP.xLastAliveTime;
#else
@@ -3782,19 +3803,19 @@ BaseType_t FreeRTOS_udp_rx_size( Socket_t xSocket )
const ListItem_t *pxEnd;
if( xRound == 0 )
{
- pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundUDPSocketsList ) );
+ pxEnd = listGET_END_MARKER( &xBoundUDPSocketsList );
}
#if ipconfigUSE_TCP == 1
else
{
- pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) );
+ pxEnd = listGET_END_MARKER( &xBoundTCPSocketsList );
}
#endif /* ipconfigUSE_TCP == 1 */
for( pxIterator = listGET_NEXT( pxEnd );
pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) )
{
- FreeRTOS_Socket_t *pxSocket = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ FreeRTOS_Socket_t *pxSocket = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
if( pxSocket->pxSocketSet != pxSocketSet )
{
/* Socket does not belong to this select group. */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
index e9478d946e..f254312225 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
@@ -85,6 +85,17 @@ struct xETH_HEADER
#include "pack_struct_end.h"
typedef struct xETH_HEADER EthernetHeader_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( EthernetHeader_t )
+{
+ return ( EthernetHeader_t *)pvArgument;
+}
+
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( EthernetHeader_t )
+{
+ return ( const EthernetHeader_t *) pvArgument;
+}
+
+
#include "pack_struct_start.h"
struct xARP_HEADER
{
@@ -130,6 +141,16 @@ struct xICMP_HEADER
#include "pack_struct_end.h"
typedef struct xICMP_HEADER ICMPHeader_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPHeader_t )
+{
+ return ( ICMPHeader_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ICMPHeader_t )
+{
+ return ( const ICMPHeader_t *) pvArgument;
+}
+
+
#include "pack_struct_start.h"
struct xUDP_HEADER
{
@@ -174,6 +195,16 @@ struct xARP_PACKET
#include "pack_struct_end.h"
typedef struct xARP_PACKET ARPPacket_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ARPPacket_t )
+{
+ return ( ARPPacket_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ARPPacket_t )
+{
+ return ( const ARPPacket_t *) pvArgument;
+}
+
+
#include "pack_struct_start.h"
struct xIP_PACKET
{
@@ -183,6 +214,16 @@ struct xIP_PACKET
#include "pack_struct_end.h"
typedef struct xIP_PACKET IPPacket_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPPacket_t )
+{
+ return ( IPPacket_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPPacket_t )
+{
+ return ( const IPPacket_t *) pvArgument;
+}
+
+
#include "pack_struct_start.h"
struct xICMP_PACKET
{
@@ -193,6 +234,12 @@ struct xICMP_PACKET
#include "pack_struct_end.h"
typedef struct xICMP_PACKET ICMPPacket_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPPacket_t )
+{
+ return ( ICMPPacket_t *)pvArgument;
+}
+
+
#include "pack_struct_start.h"
struct xUDP_PACKET
{
@@ -205,12 +252,10 @@ typedef struct xUDP_PACKET UDPPacket_t;
static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( UDPPacket_t )
{
- /* coverity[misra_c_2012_rule_11_3_violation] */
return ( UDPPacket_t *)pvArgument;
}
static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( UDPPacket_t )
{
- /* coverity[misra_c_2012_rule_11_3_violation] */
return ( const UDPPacket_t *) pvArgument;
}
@@ -232,6 +277,15 @@ typedef union XPROT_PACKET
ICMPPacket_t xICMPPacket;
} ProtocolPacket_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t )
+{
+ return ( ProtocolPacket_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t )
+{
+ return ( const ProtocolPacket_t *) pvArgument;
+}
+
typedef union xPROT_HEADERS
{
ICMPHeader_t xICMPHeader;
@@ -690,6 +744,15 @@ typedef struct xSOCKET
} u;
} FreeRTOS_Socket_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t )
+{
+ return ( FreeRTOS_Socket_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t )
+{
+ return ( const FreeRTOS_Socket_t *) pvArgument;
+}
+
#if( ipconfigUSE_TCP == 1 )
/*
* Lookup a TCP socket, using a multiple matching: both port numbers and
@@ -826,6 +889,15 @@ typedef struct xSOCKET_SET
EventGroupHandle_t xSelectGroup;
} SocketSelect_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelect_t )
+{
+ return ( SocketSelect_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelect_t )
+{
+ return ( const SocketSelect_t *) pvArgument;
+}
+
extern void vSocketSelect( SocketSelect_t *pxSocketSet );
/* Define the data that must be passed for a 'eSocketSelectEvent'. */
@@ -835,6 +907,15 @@ typedef struct xSocketSelectMessage
SocketSelect_t *pxSocketSet;
} SocketSelectMessage_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t )
+{
+ return ( SocketSelectMessage_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t )
+{
+ return ( const SocketSelectMessage_t *) pvArgument;
+}
+
#endif /* ipconfigSUPPORT_SELECT_FUNCTION */
void vIPSetDHCPTimerEnableState( BaseType_t xEnableState );
From bcd5dec6c46392c8ab30a091dda65379d46a2fb5 Mon Sep 17 00:00:00 2001
From: Gary Wicker <14828980+gkwicker@users.noreply.github.com>
Date: Fri, 28 Aug 2020 16:24:25 -0700
Subject: [PATCH 10/40] Use unsigned types/constants where needed. (#226)
Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
---
.../portable/BufferManagement/BufferAllocation_1.c | 5 +++--
.../portable/BufferManagement/BufferAllocation_2.c | 7 ++++---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c
index cf0fa11054..4da626c95a 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_1.c
@@ -161,7 +161,8 @@ section macros. */
BaseType_t xNetworkBuffersInitialise( void )
{
-BaseType_t xReturn, x;
+BaseType_t xReturn;
+uint32_t x;
/* Only initialise the buffers and their associated kernel objects if they
have not been initialised before. */
@@ -182,7 +183,7 @@ BaseType_t xReturn, x;
from the network interface, and different hardware has different
requirements. */
vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers );
- for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
+ for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
{
/* Initialise and set the owner of the buffer list items. */
vListInitialiseItem( &( xNetworkBuffers[ x ].xBufferListItem ) );
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c
index d8d95e64f4..896ca731e2 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c
@@ -95,7 +95,8 @@ static SemaphoreHandle_t xNetworkBufferSemaphore = NULL;
BaseType_t xNetworkBuffersInitialise( void )
{
-BaseType_t xReturn, x;
+BaseType_t xReturn;
+uint32_t x;
/* Only initialise the buffers and their associated kernel objects if they
have not been initialised before. */
@@ -126,7 +127,7 @@ BaseType_t xReturn, x;
/* Initialise all the network buffers. No storage is allocated to
the buffers yet. */
- for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
+ for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
{
/* Initialise and set the owner of the buffer list items. */
xNetworkBufferDescriptors[ x ].pucEthernetBuffer = NULL;
@@ -248,7 +249,7 @@ size_t uxCount;
/* Allocate storage of exactly the requested size to the buffer. */
configASSERT( pxReturn->pucEthernetBuffer == NULL );
- if( xRequestedSizeBytes > 0 )
+ if( xRequestedSizeBytes > 0U )
{
/* Extra space is obtained so a pointer to the network buffer can
be stored at the beginning of the buffer. */
From 7cb57324fdaa9bb79fcfe65b0ceb0066b4cb249b Mon Sep 17 00:00:00 2001
From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
Date: Mon, 31 Aug 2020 09:49:43 -0700
Subject: [PATCH 11/40] TCP: Address MISRA rule 11.3 violations (Part 2) (#227)
---
.../FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c | 46 +++++++++----------
.../FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c | 38 ++++++++-------
.../FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c | 4 +-
.../include/FreeRTOS_IP_Private.h | 30 ++++++++++++
4 files changed, 77 insertions(+), 41 deletions(-)
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
index 0ce010d429..31a90e1e89 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c
@@ -618,7 +618,7 @@ NetworkBufferDescriptor_t *pxNetworkBuffer;
now, proceed to send the packet with the SYN flag.
prvTCPPrepareConnect() prepares 'xPacket' and returns pdTRUE if
the Ethernet address of the peer or the gateway is found. */
- pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) );
+ pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxHeaderSize ] ) );
/* About to send a SYN packet. Call prvSetSynAckOptions() to set
the proper options: The size of MSS and whether SACK's are
@@ -743,7 +743,7 @@ NetworkBufferDescriptor_t xTempBuffer;
#endif
{
/* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
- pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
pxIPHeader = &pxTCPPacket->xIPHeader;
pxEthernetHeader = &pxTCPPacket->xEthernetHeader;
@@ -1051,7 +1051,7 @@ uint32_t ulInitialSequenceNumber = 0;
/* The MAC-address of the peer (or gateway) has been found,
* now prepare the initial TCP packet and some fields in the socket. Map
* the buffer onto the TCPPacket_t struct to easily access it's field. */
- pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxSocket->u.xTCP.xPacket.u.ucLastPacket );
+ pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxSocket->u.xTCP.xPacket.u.ucLastPacket );
pxIPHeader = &pxTCPPacket->xIPHeader;
/* reset the retry counter to zero. */
@@ -1145,7 +1145,7 @@ uint32_t ulInitialSequenceNumber = 0;
_static void prvCheckOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{
size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer );
-const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) );
const TCPHeader_t * pxTCPHeader;
const uint8_t *pucPtr;
@@ -1798,7 +1798,7 @@ int32_t lStreamPos;
}
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
- pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
+ pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
pxTCPWindow = &( pxSocket->u.xTCP.xTCPWindow );
lDataLen = 0;
lStreamPos = 0;
@@ -1828,7 +1828,7 @@ int32_t lStreamPos;
/* Map the byte stream onto ProtocolHeaders_t struct for easy
* access to the fields. */
- pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
+ pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t, &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
pucSendData = &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) + ipSIZE_OF_TCP_HEADER + uxOptionsLength ] );
@@ -2074,7 +2074,7 @@ int32_t lCount, lLength;
static BaseType_t prvTCPHandleFin( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
uint8_t ucTCPFlags = pxTCPHeader->ucTCPFlags;
@@ -2171,13 +2171,13 @@ uint32_t ulAckNr = FreeRTOS_ntohl( pxTCPHeader->ulAckNr );
static BaseType_t prvCheckRxData( const NetworkBufferDescriptor_t *pxNetworkBuffer, uint8_t **ppucRecvData )
{
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
const TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
int32_t lLength, lTCPHeaderLength, lReceiveLength, lUrgentLength;
/* Map the buffer onto an IPHeader_t struct for easy access to fields. */
-const IPHeader_t *pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
+const IPHeader_t *pxIPHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
const size_t xIPHeaderLength = ipSIZE_OF_IPv4_HEADER;
uint16_t usLength;
@@ -2246,7 +2246,7 @@ static BaseType_t prvStoreRxData( FreeRTOS_Socket_t *pxSocket, const uint8_t *pu
NetworkBufferDescriptor_t *pxNetworkBuffer, uint32_t ulReceiveLength )
{
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *,
+const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@@ -2324,7 +2324,7 @@ BaseType_t xResult = 0;
static UBaseType_t prvSetOptions( FreeRTOS_Socket_t *pxSocket, const NetworkBufferDescriptor_t *pxNetworkBuffer )
{
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@@ -2387,7 +2387,7 @@ static BaseType_t prvHandleSynReceived( FreeRTOS_Socket_t *pxSocket, const Netwo
uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
{
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@@ -2429,7 +2429,7 @@ BaseType_t xSendLength = 0;
if( pxSocket->u.xTCP.ucTCPState == ( uint8_t ) eCONNECT_SYN )
{
/* Map the Last packet onto the ProtocolHeader_t struct for easy access to the fields. */
- ProtocolHeaders_t *pxLastHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ ProtocolHeaders_t *pxLastHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( pxSocket->u.xTCP.xPacket.u.ucLastPacket[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
/* Clear the SYN flag in lastPacket. */
@@ -2507,7 +2507,7 @@ static BaseType_t prvHandleEstablished( FreeRTOS_Socket_t *pxSocket, NetworkBuff
uint32_t ulReceiveLength, UBaseType_t uxOptionsLength )
{
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizeSocket( pxSocket ) ] ) );
TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@@ -2671,7 +2671,7 @@ static BaseType_t prvSendData( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescrip
uint32_t ulReceiveLength, BaseType_t xByteCount )
{
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) );
const TCPHeader_t *pxTCPHeader = &pxProtocolHeaders->xTCPHeader;
const TCPWindow_t *pxTCPWindow = &pxSocket->u.xTCP.xTCPWindow;
@@ -2816,7 +2816,7 @@ BaseType_t xSendLength = xByteCount;
static BaseType_t prvTCPHandleState( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t **ppxNetworkBuffer )
{
/* Map the buffer onto the ProtocolHeader_t struct for easy access to the fields. */
-ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( ProtocolHeaders_t *,
+ProtocolHeaders_t *pxProtocolHeaders = ipCAST_PTR_TO_TYPE_PTR( ProtocolHeaders_t,
&( ( *ppxNetworkBuffer )->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( *ppxNetworkBuffer ) ] ) );
TCPHeader_t *pxTCPHeader = &( pxProtocolHeaders->xTCPHeader );
BaseType_t xSendLength = 0;
@@ -3001,7 +3001,7 @@ static BaseType_t prvTCPSendSpecialPacketHelper( NetworkBufferDescriptor_t *pxNe
#else
{
/* Map the ethernet buffer onto the TCPPacket_t struct for easy access to the fields. */
- TCPPacket_t *pxTCPPacket = ipPOINTER_CAST( TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ TCPPacket_t *pxTCPPacket = ipCAST_PTR_TO_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
const uint32_t ulSendLength = ( uint32_t )
( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_TCP_HEADER ); /* Plus 0 options. */
@@ -3065,7 +3065,7 @@ BaseType_t xProcessReceivedTCPPacket( NetworkBufferDescriptor_t *pxDescriptor )
NetworkBufferDescriptor_t *pxNetworkBuffer = pxDescriptor;
/* Map the buffer onto a ProtocolHeaders_t struct for easy access to the fields. */
-const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *,
+const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
FreeRTOS_Socket_t *pxSocket;
uint16_t ucTCPFlags = pxProtocolHeaders->xTCPHeader.ucTCPFlags;
@@ -3088,7 +3088,7 @@ const IPHeader_t *pxIPHeader;
else
{
/* Map the ethernet buffer onto the IPHeader_t struct for easy access to the fields. */
- pxIPHeader = ipPOINTER_CAST( const IPHeader_t *, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
+ pxIPHeader = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( IPHeader_t, &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
ulLocalIP = FreeRTOS_htonl( pxIPHeader->ulDestinationIPAddress );
ulRemoteIP = FreeRTOS_htonl( pxIPHeader->ulSourceIPAddress );
@@ -3296,7 +3296,7 @@ const IPHeader_t *pxIPHeader;
static FreeRTOS_Socket_t *prvHandleListen( FreeRTOS_Socket_t *pxSocket, NetworkBufferDescriptor_t *pxNetworkBuffer )
{
/* Map the ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
-const TCPPacket_t * pxTCPPacket = ipPOINTER_CAST( const TCPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+const TCPPacket_t * pxTCPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( TCPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
FreeRTOS_Socket_t *pxReturn = NULL;
uint32_t ulInitialSequenceNumber;
@@ -3363,7 +3363,7 @@ uint32_t ulInitialSequenceNumber;
if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) )
{
/* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */
- const ProtocolHeaders_t *pxProtocolHeaders = ipPOINTER_CAST( const ProtocolHeaders_t *,
+ const ProtocolHeaders_t *pxProtocolHeaders = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( ProtocolHeaders_t,
&( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + xIPHeaderSize( pxNetworkBuffer ) ] ) );
pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort );
@@ -3529,7 +3529,7 @@ TickType_t uxLocalPort = ( TickType_t ) FreeRTOS_htons( pxSocket->usLocalPort );
const ListItem_t *pxIterator;
FreeRTOS_Socket_t *pxFound;
BaseType_t xResult = pdFALSE;
-const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &xBoundTCPSocketsList ) );
+const ListItem_t *pxEndTCP = listGET_END_MARKER( &xBoundTCPSocketsList );
/* Here xBoundTCPSocketsList can be accessed safely IP-task is the only one
who has access. */
@@ -3539,7 +3539,7 @@ const ListItem_t *pxEndTCP = ipPOINTER_CAST( const ListItem_t *, listGET_END_MAR
{
if( listGET_LIST_ITEM_VALUE( pxIterator ) == ( configLIST_VOLATILE TickType_t ) uxLocalPort )
{
- pxFound = ipPOINTER_CAST( FreeRTOS_Socket_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ pxFound = ipCAST_PTR_TO_TYPE_PTR( FreeRTOS_Socket_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
if( ( pxFound->ucProtocol == ( uint8_t ) FREERTOS_IPPROTO_TCP ) && ( pxFound->u.xTCP.bits.bPassAccept != pdFALSE_UNSIGNED ) )
{
pxSocket->u.xTCP.pxPeerSocket = pxFound;
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c
index 5adcc9f314..c2e6426166 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c
@@ -55,6 +55,12 @@
#define winSRTT_DECREMENT_CURRENT 7
#define winSRTT_CAP_mS 50
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPSegment_t )
+{
+ return ( TCPSegment_t *)pvArgument;
+}
+
+
#if( ipconfigUSE_TCP_WIN == 1 )
#define xTCPWindowRxNew( pxWindow, ulSequenceNumber, lCount ) xTCPWindowNew( pxWindow, ulSequenceNumber, lCount, pdTRUE )
@@ -309,7 +315,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Insert a new list item into pxList, it does not sort the list,
but it puts the item just before xListEnd, so it will be the last item
returned by listGET_HEAD_ENTRY() */
- pxNewListItem->pxNext = ipPOINTER_CAST(struct xLIST_ITEM * configLIST_VOLATILE, pxWhere );
+ pxNewListItem->pxNext = ( struct xLIST_ITEM * configLIST_VOLATILE )pxWhere;
pxNewListItem->pxPrevious = pxWhere->pxPrevious;
pxWhere->pxPrevious->pxNext = pxNewListItem;
pxWhere->pxPrevious = pxNewListItem;
@@ -330,7 +336,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Allocate space for 'xTCPSegments' and store them in 'xSegmentList'. */
vListInitialise( &xSegmentList );
- xTCPSegments = ipPOINTER_CAST( TCPSegment_t *, pvPortMallocLarge( ( size_t ) ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ) );
+ xTCPSegments = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, pvPortMallocLarge( ( size_t ) ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ) );
if( xTCPSegments == NULL )
{
@@ -348,8 +354,8 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
{
/* Could call vListInitialiseItem here but all data has been
nulled already. Set the owner to a segment descriptor. */
- listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xSegmentItem ), ipPOINTER_CAST( void *, &( xTCPSegments[ xIndex ] ) ) );
- listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xQueueItem ), ipPOINTER_CAST( void *, &( xTCPSegments[ xIndex ] ) ) );
+ listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xSegmentItem ),( void * ) &( xTCPSegments[ xIndex ] ) );
+ listSET_LIST_ITEM_OWNER( &( xTCPSegments[ xIndex ].xQueueItem ), ( void * ) &( xTCPSegments[ xIndex ] ) );
/* And add it to the pool of available segments */
vListInsertFifo( &xSegmentList, &( xTCPSegments[xIndex].xSegmentItem ) );
@@ -374,13 +380,13 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Find a segment with a given sequence number in the list of received
segments. */
- pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xRxSegments ) );
+ pxEnd = listGET_END_MARKER( &pxWindow->xRxSegments );
for( pxIterator = listGET_NEXT( pxEnd );
pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) )
{
- pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
if( pxSegment->ulSequenceNumber == ulSequenceNumber )
{
@@ -416,7 +422,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
/* Pop the item at the head of the list. Semaphore protection is
not required as only the IP task will call these functions. */
pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( &xSegmentList );
- pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) );
+ pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) );
configASSERT( pxItem != NULL );
configASSERT( pxSegment != NULL );
@@ -512,7 +518,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
else
{
pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList );
- pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) );
+ pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) );
( void ) uxListRemove( pxItem );
}
@@ -538,7 +544,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
else
{
pxItem = ( ListItem_t * ) listGET_HEAD_ENTRY( pxList );
- pxReturn = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxItem ) );
+ pxReturn = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxItem ) );
}
return pxReturn;
@@ -604,7 +610,7 @@ static void vListInsertGeneric( List_t * const pxList, ListItem_t * const pxNewL
{
while( listCURRENT_LIST_LENGTH( pxSegments ) > 0U )
{
- pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_OWNER_OF_HEAD_ENTRY( pxSegments ) );
+ pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_OWNER_OF_HEAD_ENTRY( pxSegments ) );
vTCPWindowFree( pxSegment );
}
}
@@ -741,7 +747,7 @@ const int32_t l500ms = 500;
TCPSegment_t *pxBest = NULL;
const ListItem_t *pxIterator;
uint32_t ulNextSequenceNumber = ulSequenceNumber + ulLength;
- const ListItem_t * pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xRxSegments ) );
+ const ListItem_t * pxEnd = listGET_END_MARKER( &pxWindow->xRxSegments );
TCPSegment_t *pxSegment;
/* A segment has been received with sequence number 'ulSequenceNumber',
@@ -757,7 +763,7 @@ const int32_t l500ms = 500;
pxIterator != pxEnd;
pxIterator = listGET_NEXT( pxIterator ) )
{
- pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
/* And see if there is a segment for which:
'ulSequenceNumber' <= 'pxSegment->ulSequenceNumber' < 'ulNextSequenceNumber'
If there are more matching segments, the one with the lowest sequence number
@@ -1495,7 +1501,7 @@ const int32_t l500ms = 500;
uint32_t ulBytesConfirmed = 0U;
uint32_t ulSequenceNumber = ulFirst, ulDataLength;
const ListItem_t *pxIterator;
- const ListItem_t *pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &pxWindow->xTxSegments ) );
+ const ListItem_t *pxEnd = listGET_END_MARKER( &pxWindow->xTxSegments );
BaseType_t xDoUnlink;
TCPSegment_t *pxSegment;
/* An acknowledgement or a selective ACK (SACK) was received. See if some outstanding data
@@ -1523,7 +1529,7 @@ const int32_t l500ms = 500;
while( ( pxIterator != pxEnd ) && ( xSequenceLessThan( ulSequenceNumber, ulLast ) != 0 ) )
{
xDoUnlink = pdFALSE;
- pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
/* Move to the next item because the current item might get
removed. */
@@ -1650,14 +1656,14 @@ const int32_t l500ms = 500;
/* A higher Tx block has been acknowledged. Now iterate through the
xWaitQueue to find a possible condition for a FAST retransmission. */
- pxEnd = ipPOINTER_CAST( const ListItem_t *, listGET_END_MARKER( &( pxWindow->xWaitQueue ) ) );
+ pxEnd = listGET_END_MARKER( &( pxWindow->xWaitQueue ) );
pxIterator = listGET_NEXT( pxEnd );
while( pxIterator != pxEnd )
{
/* Get the owner, which is a TCP segment. */
- pxSegment = ipPOINTER_CAST( TCPSegment_t *, listGET_LIST_ITEM_OWNER( pxIterator ) );
+ pxSegment = ipCAST_PTR_TO_TYPE_PTR( TCPSegment_t, listGET_LIST_ITEM_OWNER( pxIterator ) );
/* Hop to the next item before the current gets unlinked. */
pxIterator = listGET_NEXT( pxIterator );
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c
index 715a2b1c6c..ad477312a1 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c
@@ -82,7 +82,7 @@ uint32_t ulIPAddress = pxNetworkBuffer->ulIPAddress;
size_t uxPayloadSize;
/* Map the UDP packet onto the start of the frame. */
- pxUDPPacket = ipPOINTER_CAST( UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+ pxUDPPacket = ipCAST_PTR_TO_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
if( pxNetworkBuffer->usPort == ( uint16_t ) ipPACKET_CONTAINS_ICMP_DATA )
@@ -258,7 +258,7 @@ configASSERT( pxNetworkBuffer != NULL );
configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );
/* Map the ethernet buffer to the UDPPacket_t struct for easy access to the fields. */
-const UDPPacket_t *pxUDPPacket = ipPOINTER_CAST( const UDPPacket_t *, pxNetworkBuffer->pucEthernetBuffer );
+const UDPPacket_t *pxUDPPacket = ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( UDPPacket_t, pxNetworkBuffer->pucEthernetBuffer );
/* Caller must check for minimum packet size. */
pxSocket = pxUDPSocketLookup( usPort );
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
index f254312225..3e002abf0e 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/FreeRTOS_IP_Private.h
@@ -129,6 +129,16 @@ struct xIP_HEADER
#include "pack_struct_end.h"
typedef struct xIP_HEADER IPHeader_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPHeader_t )
+{
+ return ( IPHeader_t *)pvArgument;
+}
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPHeader_t )
+{
+ return ( const IPHeader_t *) pvArgument;
+}
+
+
#include "pack_struct_start.h"
struct xICMP_HEADER
{
@@ -269,6 +279,17 @@ struct xTCP_PACKET
#include "pack_struct_end.h"
typedef struct xTCP_PACKET TCPPacket_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPPacket_t )
+{
+ return ( TCPPacket_t *)pvArgument;
+}
+
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TCPPacket_t )
+{
+ return ( const TCPPacket_t *) pvArgument;
+}
+
+
typedef union XPROT_PACKET
{
ARPPacket_t xARPPacket;
@@ -293,6 +314,15 @@ typedef union xPROT_HEADERS
TCPHeader_t xTCPHeader;
} ProtocolHeaders_t;
+static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t )
+{
+ return ( ProtocolHeaders_t *)pvArgument;
+}
+
+static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t )
+{
+ return ( const ProtocolHeaders_t *) pvArgument;
+}
/* The maximum UDP payload length. */
#define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER )
From e2ab0923517d81883d28bf714f014e01b70a2b5e Mon Sep 17 00:00:00 2001
From: Gary Wicker <14828980+gkwicker@users.noreply.github.com>
Date: Mon, 31 Aug 2020 12:05:59 -0700
Subject: [PATCH 12/40] Address MISRA 21.15 violations in FreeRTOS_Sockets.c
(#229)
* Use unsigned types/constants where needed.
* Address MISRA 21.15 violations in FreeRTOS_Sockets.c
Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
---
.../Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
index 66275d7f47..29d863a546 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c
@@ -660,6 +660,7 @@ int32_t FreeRTOS_recvfrom( Socket_t xSocket, void *pvBuffer, size_t uxBufferLeng
{
BaseType_t lPacketCount;
NetworkBufferDescriptor_t *pxNetworkBuffer;
+const void *pvCopySource;
FreeRTOS_Socket_t const * pxSocket = xSocket;
TickType_t xRemainingTime = ( TickType_t ) 0; /* Obsolete assignment, but some compilers output a warning if its not done. */
BaseType_t xTimed = pdFALSE;
@@ -789,7 +790,8 @@ EventBits_t xEventBits = ( EventBits_t ) 0;
/* Copy the received data into the provided buffer, then release the
network buffer. */
- ( void ) memcpy( pvBuffer, &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] ), ( size_t )lReturn );
+ pvCopySource = ( const void *) &pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ];
+ ( void ) memcpy( pvBuffer, pvCopySource, ( size_t )lReturn );
if( ( ( UBaseType_t ) xFlags & ( UBaseType_t ) FREERTOS_MSG_PEEK ) == 0U )
{
@@ -827,6 +829,7 @@ EventBits_t xEventBits = ( EventBits_t ) 0;
int32_t FreeRTOS_sendto( Socket_t xSocket, const void *pvBuffer, size_t uxTotalDataLength, BaseType_t xFlags, const struct freertos_sockaddr *pxDestinationAddress, socklen_t xDestinationAddressLength )
{
NetworkBufferDescriptor_t *pxNetworkBuffer;
+void *pvCopyDest;
IPStackEvent_t xStackTxEvent = { eStackTxEvent, NULL };
TimeOut_t xTimeOut;
TickType_t xTicksToWait;
@@ -883,7 +886,8 @@ const size_t uxPayloadOffset = ( size_t ) ipUDP_PAYLOAD_OFFSET_IPv4;
if( pxNetworkBuffer != NULL )
{
- ( void ) memcpy( &( pxNetworkBuffer->pucEthernetBuffer[ uxPayloadOffset ] ), pvBuffer, uxTotalDataLength );
+ pvCopyDest = ( void * ) &pxNetworkBuffer->pucEthernetBuffer[ uxPayloadOffset ];
+ ( void ) memcpy( pvCopyDest, pvBuffer, uxTotalDataLength );
if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdTRUE )
{
@@ -1971,6 +1975,7 @@ const char *pcResult;
const char *FreeRTOS_inet_ntop4( const void *pvSource, char *pcDestination, socklen_t uxSize )
{
uint32_t ulIPAddress;
+void *pvCopyDest;
const char *pcReturn;
if( uxSize < 16U )
@@ -1980,7 +1985,8 @@ const char *pcReturn;
}
else
{
- ( void ) memcpy( &( ulIPAddress ), pvSource, sizeof( ulIPAddress ) );
+ pvCopyDest = ( void * ) &ulIPAddress;
+ ( void ) memcpy( pvCopyDest, pvSource, sizeof( ulIPAddress ) );
( void ) FreeRTOS_inet_ntoa( ulIPAddress, pcDestination );
pcReturn = pcDestination;
}
@@ -1996,6 +2002,7 @@ uint32_t ulReturn = 0UL, ulValue;
UBaseType_t uxOctetNumber;
BaseType_t xResult = pdPASS;
const char *pcIPAddress = pcSource;
+const void *pvCopySource;
/* Translate "192.168.2.100" to a 32-bit number, network-endian. */
for( uxOctetNumber = 0U; uxOctetNumber < socketMAX_IP_ADDRESS_OCTETS; uxOctetNumber++ )
@@ -2076,7 +2083,8 @@ const char *pcIPAddress = pcSource;
{
ulReturn = 0UL;
}
- ( void ) memcpy( pvDestination, &( ulReturn ), sizeof( ulReturn ) );
+ pvCopySource = ( const void * ) &ulReturn;
+ ( void ) memcpy( pvDestination, pvCopySource, sizeof( ulReturn ) );
return xResult;
}
From 18d238ad5cc21ec53008cd21c62c2c10414db3c2 Mon Sep 17 00:00:00 2001
From: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
Date: Mon, 31 Aug 2020 12:55:38 -0700
Subject: [PATCH 13/40] Address a few MISRA 2.2 violations in FreeRTOS_IP.c
(#230)
* Make changes for MISRA rule 2.2
* Add comments to explain changes
* Fix a typo
* Actually fix a typo
I missed a spot in the previous commit.
---
FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
index 5dff8ef4a9..007880473d 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c
@@ -2105,6 +2105,11 @@ uint8_t ucProtocol;
if( xResult != pdPASS )
{
FreeRTOS_printf( ( "xCheckSizeFields: location %ld\n", xLocation ) );
+
+ /* If FreeRTOS_printf is not defined, not using xLocation will be a violation of MISRA
+ * rule 2.2 as the value assigned to xLocation will not be used. The below statement uses
+ * the variable without modifying the logic of the source. */
+ ( void ) xLocation;
}
return xResult;
@@ -2379,6 +2384,11 @@ BaseType_t location = 0;
( usChecksum == ipINVALID_LENGTH ) )
{
FreeRTOS_printf( ( "CRC error: %04x location %ld\n", usChecksum, location ) );
+
+ /* If FreeRTOS_printf is not defined, not using 'location' will be a violation of MISRA
+ * rule 2.2 as the value assigned to 'location' will not be used. The below statement uses
+ * the variable without modifying the logic of the source. */
+ ( void ) location;
}
return usChecksum;
From 584517d467566e5a6e0b6832a6846452bfbecfb1 Mon Sep 17 00:00:00 2001
From: Ravishankar Bhagavandas
Date: Tue, 1 Sep 2020 09:26:25 -0700
Subject: [PATCH 14/40] cbmc: Add patch to remove overflow assert (#232)
---
...flow-assert-from-xQueueGenericCreate.patch | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 FreeRTOS/Test/CBMC/patches/0008-Remove-overflow-assert-from-xQueueGenericCreate.patch
diff --git a/FreeRTOS/Test/CBMC/patches/0008-Remove-overflow-assert-from-xQueueGenericCreate.patch b/FreeRTOS/Test/CBMC/patches/0008-Remove-overflow-assert-from-xQueueGenericCreate.patch
new file mode 100644
index 0000000000..6acf1c89a6
--- /dev/null
+++ b/FreeRTOS/Test/CBMC/patches/0008-Remove-overflow-assert-from-xQueueGenericCreate.patch
@@ -0,0 +1,20 @@
+diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c
+index edd08b26e..259c609f4 100644
+--- a/FreeRTOS/Source/queue.c
++++ b/FreeRTOS/Source/queue.c
+@@ -394,8 +394,13 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
+ * 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 multiplication overflow. */
+- configASSERT( ( uxItemSize == 0 ) || ( uxQueueLength == ( xQueueSizeInBytes / uxItemSize ) ) );
++ /*
++ * Multiplication overflow check is commented out in CBMC test as it involves an
++ * expensive division operation and consumes longer compute time against a wide
++ * range of input combination in CBMC proof.
++ *
++ * configASSERT( ( uxItemSize == 0 ) || ( uxQueueLength == ( xQueueSizeInBytes / uxItemSize ) ) );
++ */
+
+ /* Allocate the queue and storage area. Justification for MISRA
+ * deviation as follows: pvPortMalloc() always ensures returned memory
From a72f040861b5e7e9d4808cd1aeec4b924c802119 Mon Sep 17 00:00:00 2001
From: Ming Yue
Date: Tue, 1 Sep 2020 11:05:23 -0700
Subject: [PATCH 15/40] Fix the path and command in demo projects to make it
compatiable to Linux and MacOS (#220)
* Update the the path in .launch file to make it compatiable with MacOS/Linux.
* Remove .exe from command and use slash in file path
Co-authored-by: Cobus van Eeden <35851496+cobusve@users.noreply.github.com>
---
.../Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch | 2 +-
FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject | 6 +++---
.../RISC-V-Qemu-sifive_e-Eclipse-GCC/Hardware_Qemu.launch | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch
index 8833e2ab5e..38afff0e1b 100644
--- a/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch
+++ b/FreeRTOS/Demo/CORTEX_LM3S6965_GCC_QEMU/RTOSDemo Debug.launch
@@ -31,7 +31,7 @@
-
+
diff --git a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject
index 3598301483..cc74c9c9f6 100644
--- a/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject
+++ b/FreeRTOS/Demo/RISC-V-Qemu-sifive_e-Eclipse-GCC/.cproject
@@ -19,7 +19,7 @@
-
+
-
+
@@ -56,7 +56,7 @@
-
+