summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus
diff options
context:
space:
mode:
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2019-07-14 23:33:05 +0000
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>2019-07-14 23:33:05 +0000
commit8b71417a3128e3c52160c44af8b9fba2170e67a3 (patch)
tree7fd0331196963670b59a4c7d92ba8f98994b2066 /FreeRTOS-Plus
parent5b3b880fea1ec6bf45c458a213b22a9cc72ebdb2 (diff)
downloadfreertos-8b71417a3128e3c52160c44af8b9fba2170e67a3.tar.gz
Remove any TCP/IP functionality from the task pool demo - the TCP/IP stack is still built as it will be used in later revisions.
git-svn-id: http://svn.code.sf.net/p/freertos/code/trunk@2682 1d2547de-c912-0410-9cb9-b8ca96c0e9e2
Diffstat (limited to 'FreeRTOS-Plus')
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/SimpleTaskPoolExamples.c596
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/include/SimpleUDPClientAndServer.h33
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSConfig.h4
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSIPConfig.h6
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj1
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj.filters3
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/iot_config_common.h4
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/main.c298
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool/iot_taskpool.c2
9 files changed, 657 insertions, 290 deletions
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/SimpleTaskPoolExamples.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/SimpleTaskPoolExamples.c
new file mode 100644
index 000000000..ad15b13be
--- /dev/null
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/SimpleTaskPoolExamples.c
@@ -0,0 +1,596 @@
+/*
+ * FreeRTOS Kernel V10.2.1
+ * 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!
+ */
+
+//_RB_ Add link to docs here.
+
+/* Kernel includes. */
+#include "FreeRTOS.h"
+#include "task.h"
+
+/* Standard includes. */
+#include <stdio.h>
+
+/* IoT SDK includes. */
+#include "iot_taskpool.h"
+
+/* The priority at which that tasks in the task pool (the worker tasks) get
+created. */
+#define tpTASK_POOL_WORKER_PRIORITY 1
+
+/* The number of jobs created in the example functions that create more than
+one job. */
+#define tpJOBS_TO_CREATE 5
+
+/*
+ * Prototypes for the functions that demonstrate the task pool API.
+ * See the implementation of the prvTaskPoolDemoTask() function within this file
+ * for a description of the individual functions. A configASSERT() is hit if
+ * any of the demos encounter any unexpected behaviour.
+ */
+static void prvExample_BasicSingleJob( void );
+static void prvExample_DeferredSingleJob( void );
+static void prvExample_BasicRecyclableJob( void );
+static void prvExample_ReuseRecyclableJobFromLowPriorityTask( void );
+static void prvExample_ReuseRecyclableJobFromHighPriorityTask( void );
+
+/*
+ * Prototypes of the callback functions used in the examples. The callback
+ * simply sends a signal (in the form of a direct task notification) to the
+ * prvTaskPoolDemoTask() task to let the task know that the callback execute.
+ * The handle of the prvTaskPoolDemoTask() task is not accessed directly, but
+ * instead passed into the task pool job as the job's context.
+ */
+static void prvSimpleTaskNotifyCallback( IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext );
+
+/*
+ * The task used to demonstrate the task pool API. This task just loops through
+ * each demo in turn.
+ */
+static void prvTaskPoolDemoTask( void *pvParameters );
+
+/*-----------------------------------------------------------*/
+
+/* Parameters used to create the system task pool - see TBD for more information
+as the task pool used in this example is a slimmed down version of the full
+library - the slimmed down version being intended specifically for FreeRTOS
+kernel use cases. */
+static const IotTaskPoolInfo_t xTaskPoolParameters = {
+ /* Minimum number of threads in a task pool.
+ Note the slimmed down version of the task
+ pool used by this library does not autoscale
+ the number of tasks in the pool so in this
+ case this sets the number of tasks in the
+ pool. */
+ 2,
+ /* Maximum number of threads in a task pool.
+ Note the slimmed down version of the task
+ pool used by this library does not autoscale
+ the number of tasks in the pool so in this
+ case this parameter is just ignored. */
+ 2,
+ /* Stack size for every task pool thread - in
+ bytes, hence multiplying by the number of bytes
+ in a word as configMINIMAL_STACK_SIZE is
+ specified in words. */
+ configMINIMAL_STACK_SIZE * sizeof( portSTACK_TYPE ),
+ /* Priority for every task pool thread. */
+ tpTASK_POOL_WORKER_PRIORITY,
+ };
+
+/*-----------------------------------------------------------*/
+
+void vStartSimpleTaskPoolDemo( void )
+{
+ /* This example uses a single application task, which in turn is used to
+ create and send jobs to task pool tasks. */
+ xTaskCreate( prvTaskPoolDemoTask, /* Function that implements the task. */
+ "PoolDemo", /* Text name for the task - only used for debugging. */
+ configMINIMAL_STACK_SIZE, /* Size of stack (in words, not bytes) to allocate for the task. */
+ NULL, /* Task parameter - not used in this case. */
+ tskIDLE_PRIORITY, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */
+ NULL ); /* Used to pass out a handle to the created tsak - not used in this case. */
+}
+/*-----------------------------------------------------------*/
+
+static void prvTaskPoolDemoTask( void *pvParameters )
+{
+IotTaskPoolError_t xResult;
+uint32_t ulLoops = 0;
+
+ /* Remove compiler warnings about unused parameters. */
+ ( void ) pvParameters;
+
+ /* The task pool must be created before it can be used. The system task
+ pool is the task pool managed by the task pool library itself - the storage
+ used by the task pool is provided by the library. */
+ xResult = IotTaskPool_CreateSystemTaskPool( &xTaskPoolParameters );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* Attempting to create the task pool again should then appear to succeed
+ (in case it is initialised by more than one library), but have no effect. */
+ xResult = IotTaskPool_CreateSystemTaskPool( &xTaskPoolParameters );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ for( ;; )
+ {
+ /* Demonstrate the most basic use case where a non persistent job is
+ created and scheduled to run immediately. The task pool worker tasks
+ (in which the job callback function executes) have a priority above the
+ priority of this task so the job's callback executes as soon as it is
+ scheduled. */
+ prvExample_BasicSingleJob();
+
+ /* Demonstrate a job being scheduled to run at some time in the
+ future, and how a job scheduled to run in the future can be cancelled if
+ it has not yet started executing. */
+ prvExample_DeferredSingleJob();
+
+ /* Demonstrate the most basic use of a recyclable job. This is similar
+ to prvExample_BasicSingleJob() but using a recyclable job. Creating a
+ recyclable job will re-use a previously created and now spare job from
+ the task pool's job cache if one is available, or otherwise dynamically
+ create a new job if a spare job is not available in the cache but space
+ remains in the cache. */
+ prvExample_BasicRecyclableJob();
+
+ /* Demonstrate multiple recyclable jobs being created, used, and then
+ re-used. In this the task pool worker tasks (in which the job callback
+ functions execute) have a priority above the priority of this task so
+ the job's callback functions execute as soon as they are scheduled. */
+ prvExample_ReuseRecyclableJobFromLowPriorityTask();
+
+ /* Again demonstrate multiple recyclable jobs being used, but this time
+ the priority of the task pool worker tasks (in which the job callback
+ functions execute) are lower than the priority of this task so the job's
+ callback functions don't execute until this task enteres the blocked
+ state. */
+ prvExample_ReuseRecyclableJobFromHighPriorityTask();
+
+ ulLoops++;
+ if( ( ulLoops % 10UL ) == 0 )
+ {
+ printf( "prvTaskPoolDemoTask() performed %u iterations without hitting an assert.\r\n", ulLoops );
+ fflush( stdout );
+ }
+ }
+}
+/*-----------------------------------------------------------*/
+
+static void prvSimpleTaskNotifyCallback( IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext )
+{
+TaskHandle_t xTaskToNotify = ( TaskHandle_t ) pUserContext;
+
+ /* Remove warnings about unused parameters. */
+ ( void ) pTaskPool;
+ ( void ) pJob;
+
+ /* Notify the task that created this job. */
+ xTaskNotifyGive( xTaskToNotify );
+}
+/*-----------------------------------------------------------*/
+
+static void prvExample_BasicSingleJob( void )
+{
+IotTaskPoolJobStorage_t xJobStorage;
+IotTaskPoolJob_t xJob;
+IotTaskPoolError_t xResult;
+uint32_t ulReturn;
+const uint32_t ulNoFlags = 0UL;
+const TickType_t xNoDelay = ( TickType_t ) 0;
+size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();
+IotTaskPoolJobStatus_t xJobStatus;
+
+ /* Don't expect any notifications to be pending yet. */
+ configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );
+
+ /* Create and schedule a job using the handle of this task as the job's
+ context and the function that sends a notification to the task handle as
+ the jobs callback function. This is not a recyclable job so the storage
+ required to hold information about the job is provided by this task - in
+ this case the storage is on the stack of this task so no memory is allocated
+ dynamically but the stack frame must remain in scope for the lifetime of
+ the job. */
+ xResult = IotTaskPool_CreateJob( prvSimpleTaskNotifyCallback, /* Callback function. */
+ ( void * ) xTaskGetCurrentTaskHandle(), /* Job context. */
+ &xJobStorage,
+ &xJob );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* The job has been created but not scheduled so is now ready. */
+ IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_READY );
+
+ /* This is not a persistent (recyclable) job and its storage is on the
+ stack of this function, so the amount of heap space available should not
+ have chanced since entering this function. */
+ configASSERT( xFreeHeapBeforeCreatingJob == xPortGetFreeHeapSize() );
+
+ /* In the full task pool implementation the first parameter is used to
+ pass the handle of the task pool to schedule. The lean task pool
+ implementation used in this demo only supports a single task pool, which
+ is created internally within the library, so the first parameter is NULL. */
+ xResult = IotTaskPool_Schedule( NULL, xJob, ulNoFlags );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* Look for the notification coming from the job's callback function. The
+ priority of the task pool worker task that executes the callback is higher
+ than the priority of this task so a block time is not needed - the task pool
+ worker task pre-empts this task and sends the notification (from the job's
+ callback) as soon as the job is scheduled. */
+ ulReturn = ulTaskNotifyTake( pdTRUE, xNoDelay );
+ configASSERT( ulReturn );
+
+ /* The job's callback has executed so the job has now completed. */
+ IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_COMPLETED );
+}
+/*-----------------------------------------------------------*/
+
+static void prvExample_DeferredSingleJob( void )
+{
+IotTaskPoolJobStorage_t xJobStorage;
+IotTaskPoolJob_t xJob;
+IotTaskPoolError_t xResult;
+uint32_t ulReturn;
+const uint32_t ulShortDelay_ms = 100UL;
+const TickType_t xNoDelay = ( TickType_t ) 0, xAllowableMargin = ( TickType_t ) 5; /* Large margin for Windows port, which is not real time. */
+TickType_t xTimeBefore, xElapsedTime, xShortDelay_ticks;
+size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();
+IotTaskPoolJobStatus_t xJobStatus;
+
+ /* Don't expect any notifications to be pending yet. */
+ configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );
+
+ /* Create a job using the handle of this task as the job's context and the
+ function that sends a notification to the task handle as the jobs callback
+ function. The job is created using storage allocated on the stack of this
+ function - so no memory is allocated. */
+ xResult = IotTaskPool_CreateJob( prvSimpleTaskNotifyCallback, /* Callback function. */
+ ( void * ) xTaskGetCurrentTaskHandle(), /* Job context. */
+ &xJobStorage,
+ &xJob );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* The job has been created but not scheduled so is now ready. */
+ IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_READY );
+
+ /* This is not a persistent (recyclable) job and its storage is on the
+ stack of this function, so the amount of heap space available should not
+ have chanced since entering this function. */
+ configASSERT( xFreeHeapBeforeCreatingJob == xPortGetFreeHeapSize() );
+
+ /* Schedule the job to run its callback in xShortDelay_ms milliseconds time.
+ In the full task pool implementation the first parameter is used to pass the
+ handle of the task pool to schedule. The lean task pool implementation used
+ in this demo only supports a single task pool, which is created internally
+ within the library, so the first parameter is NULL. */
+ xResult = IotTaskPool_ScheduleDeferred( NULL, xJob, ulShortDelay_ms );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* The scheduled job should not have executed yet, so don't expect any
+ notifications and expect the job's status to be 'deferred'. */
+ ulReturn = ulTaskNotifyTake( pdTRUE, xNoDelay );
+ configASSERT( ulReturn == 0 );
+ IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_DEFERRED );
+
+ /* As the job has not yet been executed it can be stopped. */
+ xResult = IotTaskPool_TryCancel( NULL, xJob, &xJobStatus );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+ IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_CANCELED );
+
+ /* Schedule the job again, and this time wait until its callback is
+ executed (the callback function sends a notification to this task) to see
+ that it executes at the right time. */
+ xTimeBefore = xTaskGetTickCount();
+ xResult = IotTaskPool_ScheduleDeferred( NULL, xJob, ulShortDelay_ms );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* Wait twice the deferred execution time to ensure the callback is executed
+ before the call below times out. */
+ ulReturn = ulTaskNotifyTake( pdTRUE, pdMS_TO_TICKS( ulShortDelay_ms * 2UL ) );
+ xElapsedTime = xTaskGetTickCount() - xTimeBefore;
+
+ /* A single notification should not have been received... */
+ configASSERT( ulReturn == 1 );
+
+ /* ...and the time since scheduling the job should be greater than or
+ equal to the deferred execution time - which is converted to ticks for
+ comparison. */
+ xShortDelay_ticks = pdMS_TO_TICKS( ulShortDelay_ms );
+ configASSERT( ( xElapsedTime >= xShortDelay_ticks ) && ( xElapsedTime < ( xShortDelay_ticks + xAllowableMargin ) ) );
+}
+/*-----------------------------------------------------------*/
+
+static void prvExample_BasicRecyclableJob( void )
+{
+IotTaskPoolJob_t xJob;
+IotTaskPoolError_t xResult;
+uint32_t ulReturn;
+const uint32_t ulNoFlags = 0UL;
+const TickType_t xNoDelay = ( TickType_t ) 0;
+size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();
+
+ /* Don't expect any notifications to be pending yet. */
+ configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );
+
+ /* Create and schedule a job using the handle of this task as the job's
+ context and the function that sends a notification to the task handle as
+ the jobs callback function. The job is created as a recyclable job and in
+ this case the memory used to hold the job status is allocated inside the
+ create function. As the job is persistent it can be used multiple times,
+ as demonstrated in other examples within this demo. In the full task pool
+ implementation the first parameter is used to pass the handle of the task
+ pool this recyclable job is to be associated with. In the lean
+ implementation of the task pool used by this demo there is only one task
+ pool (the system task pool created within the task pool library) so the
+ first parameter is NULL. */
+ xResult = IotTaskPool_CreateRecyclableJob( NULL,
+ prvSimpleTaskNotifyCallback,
+ (void * ) xTaskGetCurrentTaskHandle(),
+ &xJob );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* This recyclable job is persistent, and in this case created dynamically,
+ so expect there to be less heap space then when entering the function. */
+ configASSERT( xPortGetFreeHeapSize() < xFreeHeapBeforeCreatingJob );
+
+ /* In the full task pool implementation the first parameter is used to
+ pass the handle of the task pool to schedule. The lean task pool
+ implementation used in this demo only supports a single task pool, which
+ is created internally within the library, so the first parameter is NULL. */
+ xResult = IotTaskPool_Schedule( NULL, xJob, ulNoFlags );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* Look for the notification coming from the job's callback function. The
+ priority of the task pool worker task that executes the callback is higher
+ than the priority of this task so a block time is not needed - the task pool
+ worker task pre-empts this task and sends the notification (from the job's
+ callback) as soon as the job is scheduled. */
+ ulReturn = ulTaskNotifyTake( pdTRUE, xNoDelay );
+ configASSERT( ulReturn );
+
+ /* Clean up recyclable job. In the full implementation of the task pool
+ the first parameter is used to pass a handle to the task pool the job is
+ associated with. In the lean implementation of the task pool used by this
+ demo there is only one task pool (the system task pool created in the
+ task pool library itself) so the first parameter is NULL. */
+ IotTaskPool_DestroyRecyclableJob( NULL, xJob );
+
+ /* Once the job has been deleted the memory used to hold the job is
+ returned, so the available heap should be exactly as when entering this
+ function. */
+ configASSERT( xPortGetFreeHeapSize() == xFreeHeapBeforeCreatingJob );
+}
+/*-----------------------------------------------------------*/
+
+static void prvExample_ReuseRecyclableJobFromLowPriorityTask( void )
+{
+IotTaskPoolError_t xResult;
+uint32_t x, xIndex, ulNotificationValue;
+const uint32_t ulNoFlags = 0UL;
+IotTaskPoolJob_t xJobs[ tpJOBS_TO_CREATE ];
+size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();
+IotTaskPoolJobStatus_t xJobStatus;
+
+ /* Don't expect any notifications to be pending yet. */
+ configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );
+
+ /* Create tpJOBS_TO_CREATE jobs using the handle of this task as the job's
+ context and the function that sends a notification to the task handle as
+ the jobs callback function. The jobs are created as a recyclable job and
+ in this case the memory to store the job information is allocated within
+ the create function as at this time there are no recyclable jobs in the
+ task pool jobs cache. As the jobs are persistent they can be used multiple
+ times. In the full task pool implementation the first parameter is used to
+ pass the handle of the task pool this recyclable job is to be associated
+ with. In the lean implementation of the task pool used by this demo there
+ is only one task pool (the system task pool created within the task pool
+ library) so the first parameter is NULL. */
+ for( x = 0; x < tpJOBS_TO_CREATE; x++ )
+ {
+ xResult = IotTaskPool_CreateRecyclableJob( NULL,
+ prvSimpleTaskNotifyCallback,
+ (void * ) xTaskGetCurrentTaskHandle(),
+ &( xJobs[ x ] ) );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* The job has been created but not scheduled so is now ready. */
+ IotTaskPool_GetStatus( NULL, xJobs[ x ], &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_READY );
+ }
+
+ /* Demonstrate that the jobs can be recycled by performing twice the number
+ of iterations of scheduling jobs than there actually are created jobs. This
+ works because the task pool task priorities are above the priority of this
+ task, so the tasks that run the jobs pre-empt this task as soon as a job is
+ ready. */
+ for( x = 0; x < ( tpJOBS_TO_CREATE * 2UL ); x++ )
+ {
+ /* Make sure array index does not go out of bounds. */
+ xIndex = x % tpJOBS_TO_CREATE;
+
+ xResult = IotTaskPool_Schedule( NULL, xJobs[ xIndex ], ulNoFlags );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* The priority of the task pool task(s) is higher than the priority
+ of this task, so the job's callback function should have already
+ executed, sending a notification to this task, and incrementing this
+ task's notification value. */
+ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
+ 0UL, /* Don't clear any bits on exit. */
+ &ulNotificationValue, /* Obtain the notification value. */
+ 0UL ); /* No block time, return immediately. */
+ configASSERT( ulNotificationValue == ( x + 1 ) );
+
+ /* The job's callback has executed so the job is now completed. */
+ IotTaskPool_GetStatus( NULL, xJobs[ xIndex ], &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_COMPLETED );
+
+ /* To leave the list of jobs empty we can stop re-creating jobs half
+ way through iterations of this loop. */
+ if( x < tpJOBS_TO_CREATE )
+ {
+ /* Recycle the job so it can be used again. In the full task pool
+ implementation the first parameter is used to pass the handle of the
+ task pool this job will be associated with. In this lean task pool
+ implementation only the system task pool exists (the task pool created
+ internally to the task pool library) so the first parameter is just
+ passed as NULL. *//*_RB_ Why not recycle it automatically? */
+ IotTaskPool_RecycleJob( NULL, xJobs[ xIndex ] );
+ xResult = IotTaskPool_CreateRecyclableJob( NULL,
+ prvSimpleTaskNotifyCallback,
+ (void * ) xTaskGetCurrentTaskHandle(),
+ &( xJobs[ xIndex ] ) );
+ }
+ }
+
+ /* Clear all the notification value bits again. */
+ xTaskNotifyWait( portMAX_DELAY, /* Clear all bits on entry - portMAX_DELAY is used as it is a portable way of having all bits set. */
+ 0UL, /* Don't clear any bits on exit. */
+ NULL, /* Don't need the notification value this time. */
+ 0UL ); /* No block time, return immediately. */
+ configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );
+
+ /* Clean up all the recyclable job. In the full implementation of the task
+ pool the first parameter is used to pass a handle to the task pool the job
+ is associated with. In the lean implementation of the task pool used by
+ this demo there is only one task pool (the system task pool created in the
+ task pool library itself) so the first parameter is NULL. */
+ for( x = 0; x < tpJOBS_TO_CREATE; x++ )
+ {
+ xResult = IotTaskPool_DestroyRecyclableJob( NULL, xJobs[ x ] );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+ }
+
+ /* Once the job has been deleted the memory used to hold the job is
+ returned, so the available heap should be exactly as when entering this
+ function. */
+ configASSERT( xPortGetFreeHeapSize() == xFreeHeapBeforeCreatingJob );
+}
+/*-----------------------------------------------------------*/
+
+static void prvExample_ReuseRecyclableJobFromHighPriorityTask( void )
+{
+IotTaskPoolError_t xResult;
+uint32_t x, ulNotificationValue;
+const uint32_t ulNoFlags = 0UL;
+IotTaskPoolJob_t xJobs[ tpJOBS_TO_CREATE ];
+IotTaskPoolJobStorage_t xJobStorage[ tpJOBS_TO_CREATE ];
+size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();
+TickType_t xShortDelay = pdMS_TO_TICKS( 150 );
+IotTaskPoolJobStatus_t xJobStatus;
+
+ /* Don't expect any notifications to be pending yet. */
+ configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );
+
+ /* prvExample_ReuseRecyclableJobFromLowPriorityTask() executes in a task
+ that has a lower [task] priority than the task pool's worker tasks.
+ Therefore a talk pool worker preempts the task that calls
+ prvExample_ReuseRecyclableJobFromHighPriorityTask() as soon as the job is
+ scheduled. prvExample_ReuseRecyclableJobFromHighPriorityTask() reverses the
+ priorities - prvExample_ReuseRecyclableJobFromHighPriorityTask() raises its
+ priority to above the task pool's worker tasks, so the worker tasks do not
+ execute until the calling task enters the blocked state. First raise the
+ priority - passing NULL means raise the priority of the calling task. */
+ vTaskPrioritySet( NULL, tpTASK_POOL_WORKER_PRIORITY + 1 );
+
+ /* Create tpJOBS_TO_CREATE jobs using the handle of this task as the job's
+ context and the function that sends a notification to the task handle as
+ the jobs callback function. */
+ for( x = 0; x < tpJOBS_TO_CREATE; x++ )
+ {
+ xResult = IotTaskPool_CreateJob( prvSimpleTaskNotifyCallback, /* Callback function. */
+ ( void * ) xTaskGetCurrentTaskHandle(), /* Job context. */
+ &( xJobStorage[ x ] ),
+ &( xJobs[ x ] ) );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* This is not a persistent (recyclable) job and its storage is on the
+ stack of this function, so the amount of heap space available should not
+ have chanced since entering this function. */
+ configASSERT( xFreeHeapBeforeCreatingJob == xPortGetFreeHeapSize() );
+ }
+
+ for( x = 0; x < tpJOBS_TO_CREATE; x++ )
+ {
+ /* Schedule the next job. */
+ xResult = IotTaskPool_Schedule( NULL, xJobs[ x ], ulNoFlags );
+ configASSERT( xResult == IOT_TASKPOOL_SUCCESS );
+
+ /* Although scheduled, the job's callback has not executed, so the job
+ reports itself as scheduled. */
+ IotTaskPool_GetStatus( NULL, xJobs[ x ], &xJobStatus );
+ configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_SCHEDULED );
+
+ /* The priority of the task pool task(s) is lower than the priority
+ of this task, so the job's callback function should not have executed
+ yes, so don't expect the notification value for this task to have
+ changed. */
+ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
+ 0UL, /* Don't clear any bits on exit. */
+ &ulNotificationValue, /* Obtain the notification value. */
+ 0UL ); /* No block time, return immediately. */
+ configASSERT( ulNotificationValue == 0 );
+ }
+
+ /* At this point there are tpJOBS_TO_CREATE scheduled, but none have executed
+ their callbacks because the priority of this task is higher than the
+ priority of the task pool worker threads. When this task blocks to wait for
+ a notification a worker thread will be able to executes - but as soon as its
+ callback function sends a notification to this task this task will
+ preempt it (because it has a higher priority) so this task only expects to
+ receive one notification at a time. */
+ for( x = 0; x < tpJOBS_TO_CREATE; x++ )
+ {
+ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
+ 0UL, /* Don't clear any bits on exit. */
+ &ulNotificationValue, /* Obtain the notification value. */
+ xShortDelay ); /* Short delay to allow a task pool worker to execute. */
+ configASSERT( ulNotificationValue == ( x + 1 ) );
+ }
+
+ /* All the scheduled jobs have now executed, so waiting for another
+ notification should timeout without the notification value changing. */
+ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
+ 0UL, /* Don't clear any bits on exit. */
+ &ulNotificationValue, /* Obtain the notification value. */
+ xShortDelay ); /* Short delay to allow a task pool worker to execute. */
+ configASSERT( ulNotificationValue == x );
+
+ /* Reset the priority of this task and clear the notifications ready for the
+ next example. */
+ vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
+ xTaskNotifyWait( portMAX_DELAY, /* Clear all bits on entry - portMAX_DELAY is used as it is a portable way of having all bits set. */
+ 0UL, /* Don't clear any bits on exit. */
+ NULL, /* Don't need the notification value this time. */
+ 0UL ); /* No block time, return immediately. */
+}
+/*-----------------------------------------------------------*/
+
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/include/SimpleUDPClientAndServer.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/include/SimpleUDPClientAndServer.h
deleted file mode 100644
index 342ab123a..000000000
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/DemoTasks/include/SimpleUDPClientAndServer.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * FreeRTOS Kernel V10.2.1
- * 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 SIMPLE_UDP_CLIENT_AND_SERVER_H
-#define SIMPLE_UDPCLIENT_AND_SERVER_H
-
-void vStartSimpleUDPClientServerTasks( uint16_t usStackSize, uint32_t ulsPort, UBaseType_t uxPriority );
-
-#endif /* SIMPLE_UDPCLIENT_AND_SERVER_H */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSConfig.h
index 01737d5f7..c60557dec 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSConfig.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSConfig.h
@@ -65,8 +65,8 @@
/* Hook function related definitions. */
#define configUSE_TICK_HOOK 0
-#define configUSE_IDLE_HOOK 1
-#define configUSE_MALLOC_FAILED_HOOK 1
+#define configUSE_IDLE_HOOK 0
+#define configUSE_MALLOC_FAILED_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */
/* Software timer related definitions. */
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSIPConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSIPConfig.h
index ff980e3cb..7092fca6a 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSIPConfig.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/FreeRTOSIPConfig.h
@@ -53,7 +53,7 @@ out the debugging messages. */
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
+#define ipconfigHAS_PRINTF 0
#if( ipconfigHAS_PRINTF == 1 )
#define FreeRTOS_printf(X) vLoggingPrintf X
#endif
@@ -76,10 +76,10 @@ used as defaults. */
/* Include support for LLMNR: Link-local Multicast Name Resolution
(non-Microsoft) */
-#define ipconfigUSE_LLMNR ( 1 )
+#define ipconfigUSE_LLMNR ( 0 )
/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
-#define ipconfigUSE_NBNS ( 1 )
+#define ipconfigUSE_NBNS ( 0 )
/* 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
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj
index ae147ddd7..8d0c04cfa 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj
@@ -157,6 +157,7 @@
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_UDP_IP.c" />
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement\BufferAllocation_2.c" />
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\NetworkInterface\WinPCap\NetworkInterface.c" />
+ <ClCompile Include="DemoTasks\SimpleTaskPoolExamples.c" />
<ClCompile Include="DemoTasks\SimpleUDPClientAndServer.c" />
<ClCompile Include="demo_logging.c" />
<ClCompile Include="main.c">
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj.filters b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj.filters
index f1df7966a..cc6020ab6 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj.filters
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/WIN32.vcxproj.filters
@@ -145,6 +145,9 @@
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\taskpool\iot_taskpool.c">
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\common\task_pool</Filter>
</ClCompile>
+ <ClCompile Include="DemoTasks\SimpleTaskPoolExamples.c">
+ <Filter>DemoTasks</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h">
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/iot_config_common.h b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/iot_config_common.h
index ab85d95f3..786774423 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/iot_config_common.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/iot_config_common.h
@@ -29,10 +29,10 @@
#define IOT_CONFIG_COMMON_H_
/* FreeRTOS include. */
-#include "FreeRTOS.h"
+#include "FreeRTOS.h" //_RB_Makes common config file FreeRTOS specific
/* Use platform types on FreeRTOS. */
-#include "platform/iot_platform_types_afr.h"
+#include "platform/iot_platform_types_freertos.h" //_RB_Makes common config file FreeRTOS specific
/* Used to get the cloud broker endpoint for FreeRTOS. */
//_RB_#include "aws_clientcredential.h"
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/main.c b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/main.c
index 9a93fcd3d..6361b49b2 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/main.c
+++ b/FreeRTOS-Plus/Demo/FreeRTOS_Plus_IoT_SDK/task_pool/main.c
@@ -36,116 +36,45 @@
#include <stdio.h>
#include <time.h>
+/* Visual studio intrinsics used so the __debugbreak() function is available
+should an assert get hit. */
+#include <intrin.h>
+
/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include "task.h"
-/* Demo application includes. */
+/* TCP/IP stack includes. */
#include "FreeRTOS_IP.h"
-#include "FreeRTOS_Sockets.h"
-#include "SimpleUDPClientAndServer.h"
-#include "demo_logging.h"
-
-/* Simple UDP client and server task parameters. */
-#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
-#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL )
-
-/* Define a name that will be used for LLMNR and NBNS searches. */
-#define mainHOST_NAME "RTOSDemo"
-#define mainDEVICE_NICK_NAME "windows_demo"
-
-/* Set the following constants to 1 or 0 to define which tasks to include and
-exclude:
-
-mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS: When set to 1 two UDP client tasks
-and two UDP server tasks are created. The clients talk to the servers. One set
-of tasks use the standard sockets interface, and the other the zero copy sockets
-interface. These tasks are self checking and will trigger a configASSERT() if
-they detect a difference in the data that is received from that which was sent.
-As these tasks use UDP, and can therefore loose packets, they will cause
-configASSERT() to be called when they are run in a less than perfect networking
-environment.
-
-mainCREATE_TCP_ECHO_TASKS_SINGLE: When set to 1 a set of tasks are created that
-send TCP echo requests to the standard echo port (port 7), then wait for and
-verify the echo reply, from within the same task (Tx and Rx are performed in the
-same RTOS task). The IP address of the echo server must be configured using the
-configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in
-FreeRTOSConfig.h.
-
-mainCREATE_TCP_ECHO_SERVER_TASK: When set to 1 a task is created that accepts
-connections on the standard echo port (port 7), then echos back any data
-received on that connection.
-*/
-#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 1
-/*-----------------------------------------------------------*/
-
-/*
- * Just seeds the simple pseudo random number generator.
- */
-static void prvSRand( UBaseType_t ulSeed );
/*
- * Miscellaneous initialisation including preparing the logging and seeding the
- * random number generator.
+ * Prototypes for the demos that can be started from this project.
*/
-static void prvMiscInitialisation( void );
+extern void vStartSimpleTaskPoolDemo( void );
-/* The default IP and MAC address used by the demo. The address configuration
-defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
-1 but a DHCP server could not be contacted. See the online documentation for
-more information. */
-static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
-static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
-static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
-static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
-
-/* Set the following constant to pdTRUE to log using the method indicated by the
-name of the constant, or pdFALSE to not log using the method indicated by the
-name of the constant. Options include to standard out (xLogToStdout), to a disk
-file (xLogToFile), and to a UDP port (xLogToUDP). If xLogToUDP is set to pdTRUE
-then UDP messages are sent to the IP address configured as the echo server
-address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
-the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
-const BaseType_t xLogToStdout = pdTRUE, xLogToFile = pdFALSE, xLogToUDP = pdFALSE;
-
-/* Default MAC address configuration. The demo creates a virtual network
-connection that uses this MAC address by accessing the raw Ethernet data
-to and from a real network connection on the host PC. See the
-configNETWORK_INTERFACE_TO_USE definition for information on how to configure
-the real network connection to use. */
+/* This example is the first in a sequence that adds IoT functionality into
+an existing TCP/IP project. In this first project the TCP/IP stack is not
+actually used, but it is still built, which requires this array to be
+present. */
const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
-/* Use by the pseudo random number generator. */
-static UBaseType_t ulNextRand;
-
/*-----------------------------------------------------------*/
int main( void )
{
-const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );
-
/*
* Instructions for using this project are provided on:
- * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
+ * TBD
*/
- /* Miscellaneous initialisation including preparing the logging and seeding
- the random number generator. */
- prvMiscInitialisation();
-
- /* Initialise the network interface.
+ /* Create the example that demonstrates task pool functionality. Examples
+ that demonstrate networking connectivity will be added in future projects
+ and get started after the network has connected (from within the
+ vApplicationIPNetworkEventHook() function).*/
+ vStartSimpleTaskPoolDemo();
- ***NOTE*** Tasks that use the network are created in the network event hook
- when the network is connected and ready for use (see the definition of
- vApplicationIPNetworkEventHook() below). The address values passed in here
- are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
- but a DHCP server cannot be contacted. */
- FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
- FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
-
- /* Start the RTOS scheduler. */
- FreeRTOS_debug_printf( ("vTaskStartScheduler\n") );
+ /* Start the scheduler - if all is well from this point on only FreeRTOS
+ tasks will execute. */
vTaskStartScheduler();
/* If all is well, the scheduler will now be running, and the following
@@ -156,26 +85,13 @@ const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );
really applicable to the Win32 simulator port). */
for( ;; )
{
- Sleep( ulLongTime_ms );
+ __debugbreak();
}
}
/*-----------------------------------------------------------*/
-void vApplicationIdleHook( void )
-{
-const uint32_t ulMSToSleep = 1;
-
- /* This is just a trivial example of an idle hook. It is called on each
- cycle of the idle task if configUSE_IDLE_HOOK is set to 1 in
- FreeRTOSConfig.h. It must *NOT* attempt to block. In this case the
- idle task just sleeps to lower the CPU usage. */
- Sleep( ulMSToSleep );
-}
-/*-----------------------------------------------------------*/
-
void vAssertCalled( const char *pcFile, uint32_t ulLine )
{
-const uint32_t ulLongSleep = 1000UL;
volatile uint32_t ulBlockVariable = 0UL;
volatile char *pcFileName = ( volatile char * ) pcFile;
volatile uint32_t ulLineNumber = ulLine;
@@ -183,7 +99,7 @@ volatile uint32_t ulLineNumber = ulLine;
( void ) pcFileName;
( void ) ulLineNumber;
- FreeRTOS_debug_printf( ( "vAssertCalled( %s, %ld\n", pcFile, ulLine ) );
+ printf( "vAssertCalled( %s, %u\n", pcFile, ulLine );
/* Setting ulBlockVariable to a non-zero value in the debugger will allow
this function to be exited. */
@@ -191,7 +107,7 @@ volatile uint32_t ulLineNumber = ulLine;
{
while( ulBlockVariable == 0UL )
{
- Sleep( ulLongSleep );
+ __debugbreak();
}
}
taskENABLE_INTERRUPTS();
@@ -202,162 +118,46 @@ volatile uint32_t ulLineNumber = ulLine;
events are only received if implemented in the MAC driver. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
-uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
-char cBuffer[ 16 ];
-static BaseType_t xTasksAlreadyCreated = pdFALSE;
-
- /* If the network has just come up...*/
- if( eNetworkEvent == eNetworkUp )
- {
- /* Create the tasks that use the IP stack if they have not already been
- created. */
- if( xTasksAlreadyCreated == pdFALSE )
- {
- /* See the comments above the definitions of these pre-processor
- macros at the top of this file for a description of the individual
- demo tasks. */
- #if( mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS == 1 )
- {
- vStartSimpleUDPClientServerTasks( configMINIMAL_STACK_SIZE, mainSIMPLE_UDP_CLIENT_SERVER_PORT, mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY );
- }
- #endif /* mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS */
-
- #if( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 )
- {
- vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
- }
- #endif /* mainCREATE_TCP_ECHO_TASKS_SINGLE */
-
- #if( mainCREATE_TCP_ECHO_SERVER_TASK == 1 )
- {
- vStartSimpleTCPServerTasks( mainECHO_SERVER_TASK_STACK_SIZE, mainECHO_SERVER_TASK_PRIORITY );
- }
- #endif
-
- xTasksAlreadyCreated = pdTRUE;
- }
-
- /* Print out the network configuration, which may have come from a DHCP
- server. */
- FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
- FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
- FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );
-
- FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
- FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );
-
- FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
- FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );
-
- FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
- FreeRTOS_printf( ( "DNS Server Address: %s\r\n\r\n\r\n", cBuffer ) );
- }
-}
-/*-----------------------------------------------------------*/
-
-void vApplicationMallocFailedHook( void )
-{
- /* Called if a call to pvPortMalloc() fails because there is insufficient
- free memory available in the FreeRTOS heap. pvPortMalloc() is called
- internally by FreeRTOS API functions that create tasks, queues, software
- timers, and semaphores. The size of the FreeRTOS heap is set by the
- configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
- vAssertCalled( __FILE__, __LINE__ );
+ /* This example is the first in a sequence that adds IoT functionality into
+ an existing TCP/IP project. In this first project the TCP/IP stack is not
+ actually used, but it is still built, which requires this function to be
+ present. For now this function does not need to do anything, so just ensure
+ the unused parameters don't cause compiler warnings and that calls to this
+ function are trapped by the debugger. */
+ __debugbreak();
+ ( void ) eNetworkEvent;
}
/*-----------------------------------------------------------*/
-UBaseType_t uxRand( void )
-{
-const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
-
- /* Utility function to generate a pseudo random number. */
-
- ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
- return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
-}
-/*-----------------------------------------------------------*/
-
-static void prvSRand( UBaseType_t ulSeed )
-{
- /* Utility function to seed the pseudo random number generator. */
- ulNextRand = ulSeed;
-}
-/*-----------------------------------------------------------*/
-
-static void prvMiscInitialisation( void )
-{
-time_t xTimeNow;
-uint32_t ulLoggingIPAddress;
-
- ulLoggingIPAddress = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0, configECHO_SERVER_ADDR1, configECHO_SERVER_ADDR2, configECHO_SERVER_ADDR3 );
- vLoggingInit( xLogToStdout, xLogToFile, xLogToUDP, ulLoggingIPAddress, configPRINT_PORT );
-
- /* Seed the random number generator. */
- time( &xTimeNow );
- FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );
- prvSRand( ( uint32_t ) xTimeNow );
- FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n", ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32() ) );
-}
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
-
- const char *pcApplicationHostnameHook( void )
- {
- /* Assign the name "FreeRTOS" to this network node. This function will
- be called during the DHCP: the machine will be registered with an IP
- address plus this name. */
- return mainHOST_NAME;
- }
-
-#endif
-/*-----------------------------------------------------------*/
-
-#if( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
-
- BaseType_t xApplicationDNSQueryHook( const char *pcName )
- {
- BaseType_t xReturn;
-
- /* Determine if a name lookup is for this node. Two names are given
- to this node: that returned by pcApplicationHostnameHook() and that set
- by mainDEVICE_NICK_NAME. */
- if( _stricmp( pcName, pcApplicationHostnameHook() ) == 0 )
- {
- xReturn = pdPASS;
- }
- else if( _stricmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
- {
- xReturn = pdPASS;
- }
- else
- {
- xReturn = pdFAIL;
- }
-
- return xReturn;
- }
-
-#endif
-/*-----------------------------------------------------------*/
-
-/*
- * Callback that provides the inputs necessary to generate a randomized TCP
- * Initial Sequence Number per RFC 6528. THIS IS ONLY A DUMMY IMPLEMENTATION
- * THAT RETURNS A PSEUDO RANDOM NUMBER SO IS NOT INTENDED FOR USE IN PRODUCTION
- * SYSTEMS.
- */
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
+ /* This example is the first in a sequence that adds IoT functionality into
+ an existing TCP/IP project. In this first project the TCP/IP stack is not
+ actually used, but it is still built, which requires this function to be
+ present. For now this function does not need to do anything, so just ensure
+ the unused parameters don't cause compiler warnings and that calls to this
+ function are trapped by the debugger. */
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
+ __debugbreak();
+ return 0;
+}
+/*-----------------------------------------------------------*/
- return uxRand();
+UBaseType_t uxRand( void )
+{
+ /* This example is the first in a sequence that adds IoT functionality into
+ an existing TCP/IP project. In this first project the TCP/IP stack is not
+ actually used, but it is still built, which requires this function to be
+ present. For now this function does not need to do anything, so just ensure
+ the calls to the function are trapped by the debugger. */
+ __debugbreak();
+ return 0;
}
/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool/iot_taskpool.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool/iot_taskpool.c
index 460117d63..5c66bc2e2 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool/iot_taskpool.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool/iot_taskpool.c
@@ -935,7 +935,7 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
BaseType_t res = xTaskCreate( _taskPoolWorker,
cTaskName,
- pInfo->stackSize,
+ pInfo->stackSize / sizeof( portSTACK_TYPE ), /* xTaskCreate() expects the stack size to be specified in words. */
pTaskPool,
pInfo->priority,
&task );