From db67079080cbb672ca8e95a94942bef2be2b4d56 Mon Sep 17 00:00:00 2001 From: rtel Date: Tue, 23 Jul 2019 01:46:59 +0000 Subject: [PATCH] Update task pool so tasks and timer are allocated statically. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2695 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../FreeRTOS_IoT_Libraries/TaskPool/.cproject | 75 -- .../FreeRTOS_IoT_Libraries/TaskPool/.project | 159 ---- .../TaskPool/.settings/language.settings.xml | 14 - .../org.eclipse.cdt.managedbuilder.core.prefs | 11 - .../Configuration_Files/FreeRTOSConfig.h | 130 ---- .../TaskPool/Configuration_Files/iot_config.h | 59 -- .../Configuration_Files/iot_config_common.h | 203 ----- .../FreeRTOS_IoT_Libraries/TaskPool/main.c | 724 ------------------ .../DemoTasks/SimpleTaskPoolExamples.c | 2 +- .../task_pool/FreeRTOSConfig.h | 2 + .../task_pool/WIN32.vcxproj | 3 +- .../task_pool/WIN32.vcxproj.filters | 9 + .../task_pool/iot_config.h | 84 +- .../task_pool/iot_config_common.h | 12 - .../include/private/iot_taskpool_internal.h | 1 - .../common/include/types/iot_taskpool_types.h | 20 +- .../standard/common/taskpool/iot_taskpool.c | 67 +- 17 files changed, 106 insertions(+), 1469 deletions(-) delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.cproject delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.project delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/language.settings.xml delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/org.eclipse.cdt.managedbuilder.core.prefs delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/FreeRTOSConfig.h delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config.h delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config_common.h delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/main.c diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.cproject b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.cproject deleted file mode 100644 index 30bb63e72..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.cproject +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.project b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.project deleted file mode 100644 index ad46abe4c..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.project +++ /dev/null @@ -1,159 +0,0 @@ - - - RTOSDemo - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - clean,full,incremental, - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - org.eclipse.cdt.core.cnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - - - FreeRTOS-Plus-IoT-SDK - 2 - virtual:/virtual - - - FreeRTOS_Kernel_Source - 2 - virtual:/virtual - - - FreeRTOS-Plus-IoT-SDK/abstractions - 2 - virtual:/virtual - - - FreeRTOS-Plus-IoT-SDK/c_sdk - 2 - virtual:/virtual - - - FreeRTOS_Kernel_Source/event_groups.c - 1 - FREERTOS_ROOT/FreeRTOS/Source/event_groups.c - - - FreeRTOS_Kernel_Source/include - 2 - FREERTOS_ROOT/FreeRTOS/Source/include - - - FreeRTOS_Kernel_Source/list.c - 1 - FREERTOS_ROOT/FreeRTOS/Source/list.c - - - FreeRTOS_Kernel_Source/portable - 2 - virtual:/virtual - - - FreeRTOS_Kernel_Source/queue.c - 1 - FREERTOS_ROOT/FreeRTOS/Source/queue.c - - - FreeRTOS_Kernel_Source/readme.txt - 1 - FREERTOS_ROOT/FreeRTOS/Source/readme.txt - - - FreeRTOS_Kernel_Source/stream_buffer.c - 1 - FREERTOS_ROOT/FreeRTOS/Source/stream_buffer.c - - - FreeRTOS_Kernel_Source/tasks.c - 1 - FREERTOS_ROOT/FreeRTOS/Source/tasks.c - - - FreeRTOS_Kernel_Source/timers.c - 1 - FREERTOS_ROOT/FreeRTOS/Source/timers.c - - - FreeRTOS-Plus-IoT-SDK/abstractions/platform - 2 - virtual:/virtual - - - FreeRTOS-Plus-IoT-SDK/c_sdk/standard - 2 - virtual:/virtual - - - FreeRTOS_Kernel_Source/portable/MSVC-MingW - 2 - FREERTOS_ROOT/FreeRTOS/Source/portable/MSVC-MingW - - - FreeRTOS_Kernel_Source/portable/MemMang - 2 - virtual:/virtual - - - FreeRTOS-Plus-IoT-SDK/abstractions/platform/freertos - 2 - virtual:/virtual - - - FreeRTOS-Plus-IoT-SDK/abstractions/platform/include - 2 - FREERTOS_ROOT/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/abstractions/platform/include - - - FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common - 2 - virtual:/virtual - - - FreeRTOS_Kernel_Source/portable/MemMang/heap_4.c - 1 - FREERTOS_ROOT/FreeRTOS/Source/portable/MemMang/heap_4.c - - - FreeRTOS-Plus-IoT-SDK/abstractions/platform/freertos/include - 2 - FREERTOS_ROOT/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/abstractions/platform/freertos/include - - - FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include - 2 - FREERTOS_ROOT/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include - - - FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool - 2 - virtual:/virtual - - - FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool/iot_taskpool.c - 1 - FREERTOS_ROOT/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/taskpool/iot_taskpool.c - - - - - FREERTOS_ROOT - $%7BPARENT-4-PROJECT_LOC%7D - - - diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/language.settings.xml b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/language.settings.xml deleted file mode 100644 index aa36f4810..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/language.settings.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/org.eclipse.cdt.managedbuilder.core.prefs b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/org.eclipse.cdt.managedbuilder.core.prefs deleted file mode 100644 index b58567223..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/.settings/org.eclipse.cdt.managedbuilder.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/CPATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/CPATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/C_INCLUDE_PATH/delimiter=; -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/C_INCLUDE_PATH/operation=remove -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/append=true -environment/buildEnvironmentInclude/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/appendContributed=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/LIBRARY_PATH/delimiter=; -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/LIBRARY_PATH/operation=remove -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/append=true -environment/buildEnvironmentLibrary/cdt.managedbuild.config.gnu.mingw.exe.debug.1831810452/appendContributed=true diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/FreeRTOSConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/FreeRTOSConfig.h deleted file mode 100644 index 0fc6b57e1..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/FreeRTOSConfig.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * FreeRTOS Kernel V10.2.1 - * Copyright (C) 2019 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 FREERTOS_CONFIG_H -#define FREERTOS_CONFIG_H - -/*----------------------------------------------------------- - * Application specific definitions. - * - * These definitions should be adjusted for your particular hardware and - * application requirements. - * - * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See - * http://www.freertos.org/a00110.html - *----------------------------------------------------------*/ - -#define configUSE_PREEMPTION 1 -#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 -#define configUSE_IDLE_HOOK 1 -#define configUSE_TICK_HOOK 1 -#define configUSE_DAEMON_TASK_STARTUP_HOOK 1 -#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */ -#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */ -#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65 * 1024 ) ) -#define configMAX_TASK_NAME_LEN ( 12 ) -#define configUSE_TRACE_FACILITY 1 -#define configUSE_16_BIT_TICKS 0 -#define configIDLE_SHOULD_YIELD 1 -#define configUSE_MUTEXES 1 -#define configCHECK_FOR_STACK_OVERFLOW 0 -#define configUSE_RECURSIVE_MUTEXES 1 -#define configQUEUE_REGISTRY_SIZE 20 -#define configUSE_APPLICATION_TASK_TAG 1 -#define configUSE_COUNTING_SEMAPHORES 1 -#define configUSE_ALTERNATIVE_API 0 -#define configUSE_QUEUE_SETS 1 -#define configUSE_TASK_NOTIFICATIONS 1 -#define configSUPPORT_STATIC_ALLOCATION 1 - -/* Software timer related configuration options. The maximum possible task -priority is configMAX_PRIORITIES - 1. The priority of the timer task is -deliberately set higher to ensure it is correctly capped back to -configMAX_PRIORITIES - 1. */ -#define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) -#define configTIMER_QUEUE_LENGTH 20 -#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 ) - -#define configMAX_PRIORITIES ( 7 ) - -/* Run time stats gathering configuration options. */ -#define configGENERATE_RUN_TIME_STATS 0 - -/* Co-routine related configuration options. */ -#define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) - -/* This demo can use of one or more example stats formatting functions. These -format the raw data provided by the uxTaskGetSystemState() function in to human -readable ASCII form. See the notes in the implementation of vTaskList() within -FreeRTOS/Source/tasks.c for limitations. */ -#define configUSE_STATS_FORMATTING_FUNCTIONS 0 - -/* Enables the test whereby a stack larger than the total heap size is -requested. */ -#define configSTACK_DEPTH_TYPE uint32_t - -/* Set the following definitions to 1 to include the API function, or zero -to exclude the API function. In most cases the linker will remove unused -functions anyway. */ -#define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 -#define INCLUDE_vTaskDelete 1 -#define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 -#define INCLUDE_vTaskDelay 1 -#define INCLUDE_uxTaskGetStackHighWaterMark 1 -#define INCLUDE_uxTaskGetStackHighWaterMark2 1 -#define INCLUDE_xTaskGetSchedulerState 1 -#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1 -#define INCLUDE_xTaskGetIdleTaskHandle 1 -#define INCLUDE_xTaskGetHandle 1 -#define INCLUDE_eTaskGetState 1 -#define INCLUDE_xSemaphoreGetMutexHolder 1 -#define INCLUDE_xTimerPendFunctionCall 1 -#define INCLUDE_xTaskAbortDelay 1 - -#define configINCLUDE_MESSAGE_BUFFER_AMP_DEMO 0 -#if ( configINCLUDE_MESSAGE_BUFFER_AMP_DEMO == 1 ) - extern void vGenerateCoreBInterrupt( void * xUpdatedMessageBuffer ); - #define sbSEND_COMPLETED( pxStreamBuffer ) vGenerateCoreBInterrupt( pxStreamBuffer ) -#endif /* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */ - -extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName ); - -/* It is best practice to define configASSERT() while developing. configASSERT() -uses the same semantics as the standard C assert() macro. Don't define -configASSERT() when performing code coverage tests though, as it is not -intended to asserts() to fail, some some code is intended not to run if no -errors are present. */ -#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __LINE__, __FILE__ ) - -#define configUSE_MALLOC_FAILED_HOOK 1 - -#endif /* FREERTOS_CONFIG_H */ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config.h b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config.h deleted file mode 100644 index 3038f0b78..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2018 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. - */ - -/* This file contains configuration settings for the demos. */ - -#ifndef IOT_CONFIG_H_ -#define IOT_CONFIG_H_ - -/* How long the MQTT library will wait for PINGRESPs or PUBACKs. */ -#define IOT_MQTT_RESPONSE_WAIT_MS ( 10000 ) - -/* MQTT demo configuration. */ -#define IOT_DEMO_MQTT_PUBLISH_BURST_COUNT ( 10 ) -#define IOT_DEMO_MQTT_PUBLISH_BURST_SIZE ( 2 ) - -/* Shadow demo configuration. The demo publishes periodic Shadow updates and responds - * to changing Shadows. */ -#define AWS_IOT_DEMO_SHADOW_UPDATE_COUNT ( 20 ) /* Number of updates to publish. */ -#define AWS_IOT_DEMO_SHADOW_UPDATE_PERIOD_MS ( 3000 ) /* Period of Shadow updates. */ - -/* Library logging configuration. IOT_LOG_LEVEL_GLOBAL provides a global log - * level for all libraries; the library-specific settings override the global - * setting. If both the library-specific and global settings are undefined, - * no logs will be printed. */ -#define IOT_LOG_LEVEL_GLOBAL IOT_LOG_INFO -#define IOT_LOG_LEVEL_DEMO IOT_LOG_INFO -#define IOT_LOG_LEVEL_PLATFORM IOT_LOG_NONE -#define IOT_LOG_LEVEL_NETWORK IOT_LOG_INFO -#define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_NONE -#define IOT_LOG_LEVEL_MQTT IOT_LOG_INFO -#define AWS_IOT_LOG_LEVEL_SHADOW IOT_LOG_INFO -#define AWS_IOT_LOG_LEVEL_DEFENDER IOT_LOG_INFO - -/* Platform thread stack size and priority. */ -#define IOT_THREAD_DEFAULT_STACK_SIZE 2048 -#define IOT_THREAD_DEFAULT_PRIORITY 5 - -/* Include the common configuration file for FreeRTOS. */ -#include "iot_config_common.h" - -#endif /* ifndef IOT_CONFIG_H_ */ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config_common.h b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config_common.h deleted file mode 100644 index ab85d95f3..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/Configuration_Files/iot_config_common.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Amazon FreeRTOS V201906.00 Major - * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/* This file contains default configuration settings for the demos on FreeRTOS. */ - -#ifndef IOT_CONFIG_COMMON_H_ -#define IOT_CONFIG_COMMON_H_ - -/* FreeRTOS include. */ -#include "FreeRTOS.h" - -/* Use platform types on FreeRTOS. */ -#include "platform/iot_platform_types_afr.h" - -/* Used to get the cloud broker endpoint for FreeRTOS. */ -//_RB_#include "aws_clientcredential.h" - -/* SDK version. */ -#define IOT_SDK_VERSION "4.0.0" - -/* This config file is for the demos; disable any test code. */ -#define IOT_BUILD_TESTS ( 0 ) - -/* Logging puts function. */ -#define IotLogging_Puts( str ) configPRINTF( ( "%s\r\n", str ) ) - -/* Enable asserts in libraries by default. */ -#ifndef IOT_METRICS_ENABLE_ASSERTS - #define IOT_METRICS_ENABLE_ASSERTS ( 1 ) -#endif -#ifndef IOT_CONTAINERS_ENABLE_ASSERTS - #define IOT_CONTAINERS_ENABLE_ASSERTS ( 1 ) -#endif -#ifndef IOT_TASKPOOL_ENABLE_ASSERTS - #define IOT_TASKPOOL_ENABLE_ASSERTS ( 1 ) -#endif -#ifndef IOT_MQTT_ENABLE_ASSERTS - #define IOT_MQTT_ENABLE_ASSERTS ( 1 ) -#endif -#ifndef AWS_IOT_SHADOW_ENABLE_ASSERTS - #define AWS_IOT_SHADOW_ENABLE_ASSERTS ( 1 ) -#endif -#ifndef AWS_IOT_DEFENDER_ENABLE_ASSERTS - #define AWS_IOT_DEFENDER_ENABLE_ASSERTS ( 1 ) -#endif -#ifndef IOT_BLE_ENABLE_ASSERTS - #define IOT_BLE_ENABLE_ASSERTS ( 1 ) -#endif - -/* Assert functions. */ -#define IotMetrics_Assert( expression ) configASSERT( expression ) -#define IotContainers_Assert( expression ) configASSERT( expression ) -#define IotTaskPool_Assert( expression ) configASSERT( expression ) -#define IotMqtt_Assert( expression ) configASSERT( expression ) -#define AwsIotShadow_Assert( expression ) configASSERT( expression ) -#define AwsIotDefender_Assert( expression ) configASSERT( expression ) -#define IotBle_Assert( expression ) configASSERT( expression ) - -/* Control the usage of dynamic memory allocation. */ -#ifndef IOT_STATIC_MEMORY_ONLY - #define IOT_STATIC_MEMORY_ONLY ( 0 ) -#endif - -/* Memory allocation configuration. Note that these functions will not be affected - * by IOT_STATIC_MEMORY_ONLY. */ -#define IotNetwork_Malloc pvPortMalloc -#define IotNetwork_Free vPortFree -#define IotThreads_Malloc pvPortMalloc -#define IotThreads_Free vPortFree -#define IotLogging_Malloc pvPortMalloc -#define IotLogging_Free vPortFree -#define IotBle_Malloc pvPortMalloc -#define IotBle_Free vPortFree -/* #define IotLogging_StaticBufferSize */ - -/* Memory allocation function configuration for the MQTT and Defender library. - * These libraries will be affected by IOT_STATIC_MEMORY_ONLY. */ -#if IOT_STATIC_MEMORY_ONLY == 0 - #define IotMetrics_MallocTcpConnection pvPortMalloc - #define IotMetrics_FreeTcpConnection vPortFree - #define IotMetrics_MallocIpAddress pvPortMalloc - #define IotMetrics_FreeIpAddress vPortFree - - #define IotTaskPool_MallocTaskPool pvPortMalloc - #define IotTaskPool_FreeTaskPool vPortFree - #define IotTaskPool_MallocJob pvPortMalloc - #define IotTaskPool_FreeJob vPortFree - #define IotTaskPool_MallocTimerEvent pvPortMalloc - #define IotTaskPool_FreeTimerEvent vPortFree - - #define IotMqtt_MallocConnection pvPortMalloc - #define IotMqtt_FreeConnection vPortFree - #define IotMqtt_MallocMessage pvPortMalloc - #define IotMqtt_FreeMessage vPortFree - #define IotMqtt_MallocOperation pvPortMalloc - #define IotMqtt_FreeOperation vPortFree - #define IotMqtt_MallocSubscription pvPortMalloc - #define IotMqtt_FreeSubscription vPortFree - - #define IotSerializer_MallocCborEncoder pvPortMalloc - #define IotSerializer_FreeCborEncoder vPortFree - #define IotSerializer_MallocCborParser pvPortMalloc - #define IotSerializer_FreeCborParser vPortFree - #define IotSerializer_MallocCborValue pvPortMalloc - #define IotSerializer_FreeCborValue vPortFree - #define IotSerializer_MallocDecoderObject pvPortMalloc - #define IotSerializer_FreeDecoderObject vPortFree - - #define AwsIotShadow_MallocOperation pvPortMalloc - #define AwsIotShadow_FreeOperation vPortFree - #define AwsIotShadow_MallocString pvPortMalloc - #define AwsIotShadow_FreeString vPortFree - #define AwsIotShadow_MallocSubscription pvPortMalloc - #define AwsIotShadow_FreeSubscription vPortFree - - #define AwsIotDefender_MallocReport pvPortMalloc - #define AwsIotDefender_FreeReport vPortFree - #define AwsIotDefender_MallocTopic pvPortMalloc - #define AwsIotDefender_FreeTopic vPortFree -#endif /* if IOT_STATIC_MEMORY_ONLY == 0 */ - -/* Default platform thread stack size and priority. */ -#ifndef IOT_THREAD_DEFAULT_STACK_SIZE - #define IOT_THREAD_DEFAULT_STACK_SIZE 2048 -#endif -#ifndef IOT_THREAD_DEFAULT_PRIORITY - #define IOT_THREAD_DEFAULT_PRIORITY tskIDLE_PRIORITY -#endif - -/* Platform network configuration. */ -#ifndef IOT_NETWORK_RECEIVE_TASK_PRIORITY - #define IOT_NETWORK_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 ) -#endif -#ifndef IOT_NETWORK_RECEIVE_TASK_STACK_SIZE - #define IOT_NETWORK_RECEIVE_TASK_STACK_SIZE IOT_THREAD_DEFAULT_STACK_SIZE -#endif - -/* Platform and SDK name for AWS IoT MQTT metrics. Only used when - * AWS_IOT_MQTT_ENABLE_METRICS is 1. */ -#define IOT_SDK_NAME "AmazonFreeRTOS" -#ifdef configPLATFORM_NAME - #define IOT_PLATFORM_NAME configPLATFORM_NAME -#else - #define IOT_PLATFORM_NAME "Unknown" -#endif - -/* Cloud endpoint to which the device connects to. */ -#define IOT_CLOUD_ENDPOINT clientcredentialMQTT_BROKER_ENDPOINT - -/** - * @brief Unique identifier used to recognize a device by the cloud. - * This could be SHA-256 of the device certificate. - */ -extern const char *getDeviceIdentifier( void ); -#define IOT_DEVICE_IDENTIFIER getDeviceIdentifier() - -/** - * @brief Metrics emitted by the device. - */ -extern const char *getDeviceMetrics( void ); -#define AWS_IOT_METRICS_USERNAME getDeviceMetrics() - -/** - * @brief Length of the metrics emitted by device. - */ -extern uint16_t getDeviceMetricsLength( void ); -#define AWS_IOT_METRICS_USERNAME_LENGTH getDeviceMetricsLength() - -/* Define the data type of metrics connection id as same as Socket_t in aws_secure_socket.h */ -#define IotMetricsConnectionId_t void * - -/* Configuration for defender demo: set format to CBOR. */ -#define AWS_IOT_DEFENDER_FORMAT AWS_IOT_DEFENDER_FORMAT_CBOR - -/* Configuration for defender demo: use long tag for readable output. Please use short tag for the real application. */ -#define AWS_IOT_DEFENDER_USE_LONG_TAG ( 1 ) - -/* Demo runner configuration. */ -//_RB_#include "aws_demo_config.h" - -#endif /* ifndef IOT_CONFIG_COMMON_H_ */ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/main.c b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/main.c deleted file mode 100644 index a18b36663..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/TaskPool/main.c +++ /dev/null @@ -1,724 +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! - */ - -/* Kernel includes. */ -#include "FreeRTOS.h" -#include "task.h" - -/* Standard includes. */ -#include - -/* 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 - -/* - * Prototypes for the functions that demonstrate the task pool API. - */ -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. */ -static void prvSimpleTaskNotifyCallback( IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext ); - -/* - * Prototypes for the standard FreeRTOS application hook (callback) functions - * implemented within this file. See http://www.freertos.org/a00016.html . - */ -void vApplicationMallocFailedHook( void ); -void vApplicationIdleHook( void ); -void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ); -void vApplicationTickHook( void ); -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ); -void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ); - -/* - * The task used to demonstrate the task pool API. - */ -static void prvTaskPoolDemoTask( void *pvParameters ); - -static const IotTaskPoolInfo_t xTaskPoolParameters = { - /* Minimum number of threads in a task pool. */ - 2, - /* Maximum number of threads in a task pool. */ - 2, - /* Stack size for every task pool thread - in words, not bytes. */ - configMINIMAL_STACK_SIZE, - /* Priority for every task pool thread. */ - tpTASK_POOL_WORKER_PRIORITY, - }; - -/*-----------------------------------------------------------*/ - -int main( 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. */ - - vTaskStartScheduler(); - - /* Should not reach here as vTaskStartScheduler() will only return if there - was insufficient FreeRTOS heap memory to create the Idle or Timer - Daemon task. */ - return 0; -} -/*-----------------------------------------------------------*/ - -static void prvTaskPoolDemoTask( void *pvParameters ) -{ -IotTaskPoolError_t xResult; -uint32_t ulLoops; - - /* Remove compiler warnings about unused parameters. */ - ( void ) pvParameters; - - /* The task pool must be created before it can be used. */ - 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( "Performed %u successful iterations.\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. 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() ); - - /* 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 ulJobsToCreate = 5UL, ulNoFlags = 0UL; -IotTaskPoolJob_t xJobs[ ulJobsToCreate ]; -size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize(); -IotTaskPoolJobStatus_t xJobStatus; - - /* Don't expect any notifications to be pending yet. */ - configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 ); - - /* Create ulJobsToCreate 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 < ulJobsToCreate; 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 < ( ulJobsToCreate * 2UL ); x++ ) - { - /* Make sure array index does not go out of bounds. */ - xIndex = x % ulJobsToCreate; - - 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 < ulJobsToCreate ) - { - /* 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 < ulJobsToCreate; x++ ) - { - xResult = IotTaskPool_DestroyRecyclableJob( NULL, xJobs[ x ] ); - configASSERT( xResult == IOT_TASKPOOL_SUCCESS ); - - /* Attempting to destroy the same job twice will fail. */ -//_RB_ vPortFree() asserts because it attempts to free memory again. 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 ulJobsToCreate = 5UL; -const uint32_t ulNoFlags = 0UL; -IotTaskPoolJob_t xJobs[ ulJobsToCreate ]; -IotTaskPoolJobStorage_t xJobStorage[ ulJobsToCreate ]; -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 ulJobsToCreate 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 < ulJobsToCreate; 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 < ulJobsToCreate; 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 ulJobsToCreate 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 < ulJobsToCreate; 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. */ -} -/*-----------------------------------------------------------*/ - -void vApplicationMallocFailedHook( void ) -{ - /* vApplicationMallocFailedHook() will only be called if - configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook - function that will get called if a call to pvPortMalloc() fails. - pvPortMalloc() is called internally by the kernel whenever a task, queue, - timer or semaphore is created. It is also called by various parts of the - demo application. If heap_1.c, heap_2.c or heap_4.c is being used, then the - size of the heap available to pvPortMalloc() is defined by - configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() - API function can be used to query the size of free heap space that remains - (although it does not provide information on how the remaining heap might be - fragmented). See http://www.freertos.org/a00111.html for more - information. */ - vAssertCalled( __LINE__, __FILE__ ); -} -/*-----------------------------------------------------------*/ - -void vApplicationIdleHook( void ) -{ - /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set - to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle - task. It is essential that code added to this hook function never attempts - to block in any way (for example, call xQueueReceive() with a block time - specified, or call vTaskDelay()). If application tasks make use of the - vTaskDelete() API function to delete themselves then it is also important - that vApplicationIdleHook() is permitted to return to its calling function, - because it is the responsibility of the idle task to clean up memory - allocated by the kernel to any task that has since deleted itself. */ -} -/*-----------------------------------------------------------*/ - -void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) -{ - ( void ) pcTaskName; - ( void ) pxTask; - - /* Run time stack overflow checking is performed if - 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. */ - vAssertCalled( __LINE__, __FILE__ ); -} -/*-----------------------------------------------------------*/ - -void vApplicationTickHook( void ) -{ - /* This function will be called by each tick interrupt if - configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be - added here, but the tick hook is called from an interrupt context, so - code must not attempt to block, and only the interrupt safe FreeRTOS API - functions can be used (those that end in FromISR()). */ -} -/*-----------------------------------------------------------*/ - -void vApplicationDaemonTaskStartupHook( void ) -{ - /* This function will be called once only, when the daemon task starts to - execute (sometimes called the timer task). This is useful if the - application includes initialisation code that would benefit from executing - after the scheduler has been started. */ -} -/*-----------------------------------------------------------*/ - -void vAssertCalled( unsigned long ulLine, const char * const pcFileName ) -{ -volatile uint32_t ulSetToNonZeroInDebuggerToContinue = 0; - - /* Called if an assertion passed to configASSERT() fails. See - http://www.freertos.org/a00110.html#configASSERT for more information. */ - - /* Parameters are not used. */ - ( void ) ulLine; - ( void ) pcFileName; - - - taskENTER_CRITICAL(); - { - printf( "Assert hit on line %lu of %s\r\n", ulLine, pcFileName ); - fflush( stdout ); - - /* You can step out of this function to debug the assertion by using - the debugger to set ulSetToNonZeroInDebuggerToContinue to a non-zero - value. */ - while( ulSetToNonZeroInDebuggerToContinue == 0 ) - { - __asm volatile( "NOP" ); - __asm volatile( "NOP" ); - } - } - taskEXIT_CRITICAL(); -} -/*-----------------------------------------------------------*/ - -/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an -implementation of vApplicationGetIdleTaskMemory() to provide the memory that is -used by the Idle task. */ -void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) -{ -/* If the buffers to be provided to the Idle task are declared inside this -function then they must be declared static - otherwise they will be allocated on -the stack and so not exists after this function exits. */ -static StaticTask_t xIdleTaskTCB; -static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ]; - - /* Pass out a pointer to the StaticTask_t structure in which the Idle task's - state will be stored. */ - *ppxIdleTaskTCBBuffer = &xIdleTaskTCB; - - /* Pass out the array that will be used as the Idle task's stack. */ - *ppxIdleTaskStackBuffer = uxIdleTaskStack; - - /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer. - Note that, as the array is necessarily of type StackType_t, - configMINIMAL_STACK_SIZE is specified in words, not bytes. */ - *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE; -} -/*-----------------------------------------------------------*/ - -/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the -application must provide an implementation of vApplicationGetTimerTaskMemory() -to provide the memory that is used by the Timer service task. */ -void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize ) -{ -/* If the buffers to be provided to the Timer task are declared inside this -function then they must be declared static - otherwise they will be allocated on -the stack and so not exists after this function exits. */ -static StaticTask_t xTimerTaskTCB; -static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ]; - - /* Pass out a pointer to the StaticTask_t structure in which the Timer - task's state will be stored. */ - *ppxTimerTaskTCBBuffer = &xTimerTaskTCB; - - /* Pass out the array that will be used as the Timer task's stack. */ - *ppxTimerTaskStackBuffer = uxTimerTaskStack; - - /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer. - Note that, as the array is necessarily of type StackType_t, - configMINIMAL_STACK_SIZE is specified in words, not bytes. */ - *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; -} - diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/DemoTasks/SimpleTaskPoolExamples.c b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/DemoTasks/SimpleTaskPoolExamples.c index e7fb1e070..f1c7a42a4 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/DemoTasks/SimpleTaskPoolExamples.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/DemoTasks/SimpleTaskPoolExamples.c @@ -169,7 +169,7 @@ uint32_t ulLoops = 0; ulLoops++; if( ( ulLoops % 10UL ) == 0 ) { - printf( "prvTaskPoolDemoTask() performed %u iterations without hitting an assert.\r\n", ulLoops ); + configPRINTF( ( "prvTaskPoolDemoTask() performed %u iterations without hitting an assert.\r\n", ulLoops ) ); fflush( stdout ); } } diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/FreeRTOSConfig.h b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/FreeRTOSConfig.h index c60557dec..3b63eb063 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/FreeRTOSConfig.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/FreeRTOSConfig.h @@ -202,5 +202,7 @@ ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */ #define strncasecmp _strnicmp #define strcmpi _strcmpi +#define configPRINTF( X ) printf X + #endif /* FREERTOS_CONFIG_H */ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj index 8d0c04cfa..fd7b68118 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj @@ -60,7 +60,6 @@ Disabled ..\..\..\Source\FreeRTOS-Plus-TCP\include;..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;.\DemoTasks\include;.\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include;.;%(AdditionalIncludeDirectories) WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true EnableFastChecks MultiThreadedDLL .\Debug/WIN32.pch @@ -145,6 +144,8 @@ + + diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj.filters b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj.filters index cc6020ab6..215f940eb 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj.filters +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/WIN32.vcxproj.filters @@ -81,6 +81,9 @@ {35ce7745-52a2-4220-be31-50dfaa35c0ab} + + {6c8bc003-a388-4666-99f4-a31faa932a36} + @@ -148,6 +151,12 @@ DemoTasks + + FreeRTOS+\FreeRTOS IoT Libraries\standard\common\logging + + + FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos + diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config.h b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config.h index 3038f0b78..470a13d6d 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config.h @@ -24,34 +24,62 @@ #ifndef IOT_CONFIG_H_ #define IOT_CONFIG_H_ -/* How long the MQTT library will wait for PINGRESPs or PUBACKs. */ -#define IOT_MQTT_RESPONSE_WAIT_MS ( 10000 ) - -/* MQTT demo configuration. */ -#define IOT_DEMO_MQTT_PUBLISH_BURST_COUNT ( 10 ) -#define IOT_DEMO_MQTT_PUBLISH_BURST_SIZE ( 2 ) - -/* Shadow demo configuration. The demo publishes periodic Shadow updates and responds - * to changing Shadows. */ -#define AWS_IOT_DEMO_SHADOW_UPDATE_COUNT ( 20 ) /* Number of updates to publish. */ -#define AWS_IOT_DEMO_SHADOW_UPDATE_PERIOD_MS ( 3000 ) /* Period of Shadow updates. */ - -/* Library logging configuration. IOT_LOG_LEVEL_GLOBAL provides a global log - * level for all libraries; the library-specific settings override the global - * setting. If both the library-specific and global settings are undefined, - * no logs will be printed. */ -#define IOT_LOG_LEVEL_GLOBAL IOT_LOG_INFO -#define IOT_LOG_LEVEL_DEMO IOT_LOG_INFO -#define IOT_LOG_LEVEL_PLATFORM IOT_LOG_NONE -#define IOT_LOG_LEVEL_NETWORK IOT_LOG_INFO -#define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_NONE -#define IOT_LOG_LEVEL_MQTT IOT_LOG_INFO -#define AWS_IOT_LOG_LEVEL_SHADOW IOT_LOG_INFO -#define AWS_IOT_LOG_LEVEL_DEFENDER IOT_LOG_INFO - -/* Platform thread stack size and priority. */ -#define IOT_THREAD_DEFAULT_STACK_SIZE 2048 -#define IOT_THREAD_DEFAULT_PRIORITY 5 +/* Use platform types on FreeRTOS. */ +#include "FreeRTOS.h" +#include "platform/iot_platform_types_freertos.h" //_RB_Makes common config file FreeRTOS specific + +/* + * Set this to the number of recyclable tasks for the task pool to cache. + * + * Caching dynamically allocated tasks (recyclable tasks) helps the application + * to limit the number of allocations at runtime. Caching recyclable tasks may + * help making the application more responsive and predictable, by removing a + * potential for memory allocation failures, but it may also have negative + * repercussions on the amount of memory available at any given time. It is up + * to the application developer to strike the correct balance these competing + * needs. The task pool will cache when the application calling + * IotTaskPool_RecycleJob. Any recycled tasks in excess of + * IOT_TASKPOOL_JOBS_RECYCLE_LIMIT will be destroyed and its memory will be + * release. + * + * Default value (if undefined): 8 + */ +#define IOT_TASKPOOL_JOBS_RECYCLE_LIMIT 8 + +/* + * Set this to 1 to perform sanity checks when using the task pool library. + * + * Asserts are useful for debugging, but should be disabled in production code. + * If this is set to 1, IotTaskPool_Assert can be defined to set the assertion + * function; otherwise, the standard library's assert function will be used. + * + * Possible values: 0 (asserts disabled) or 1 (asserts enabled) + * Recommended values: 1 when debugging; 0 in production code. + * Default value (if undefined): 0 + */ +#define IOT_TASKPOOL_ENABLE_ASSERTS 1 + +/* + * Set the log level of the task pool library. + * + * Log messages from the task pool library at or below this setting will be + * printed. + * + * Possible values: One of the Log levels. + * Default value (if undefined): IOT_LOG_LEVEL_GLOBAL; if that is undefined, + * then IOT_LOG_NONE. + */ +#define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_INFO + +/* + * + */ +#define IOT_TASKPOOL_NUMBER_OF_WORKERS 3 + +/* + * + */ +#define IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES 2048 /* Include the common configuration file for FreeRTOS. */ #include "iot_config_common.h" diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config_common.h b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config_common.h index 786774423..8dd158db7 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config_common.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config_common.h @@ -28,15 +28,6 @@ #ifndef IOT_CONFIG_COMMON_H_ #define IOT_CONFIG_COMMON_H_ -/* FreeRTOS include. */ -#include "FreeRTOS.h" //_RB_Makes common config file FreeRTOS specific - -/* Use platform types on FreeRTOS. */ -#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" - /* SDK version. */ #define IOT_SDK_VERSION "4.0.0" @@ -197,7 +188,4 @@ extern uint16_t getDeviceMetricsLength( void ); /* Configuration for defender demo: use long tag for readable output. Please use short tag for the real application. */ #define AWS_IOT_DEFENDER_USE_LONG_TAG ( 1 ) -/* Demo runner configuration. */ -//_RB_#include "aws_demo_config.h" - #endif /* ifndef IOT_CONFIG_COMMON_H_ */ diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/private/iot_taskpool_internal.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/private/iot_taskpool_internal.h index b989c586c..3779ff958 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/private/iot_taskpool_internal.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/private/iot_taskpool_internal.h @@ -255,7 +255,6 @@ typedef struct _taskPool int32_t priority; /**< @brief The priority for all task pool threads. */ SemaphoreHandle_t dispatchSignal; /**< @brief The synchronization object on which threads are waiting for incoming jobs. */ StaticSemaphore_t dispatchSignalBuffer; /**< @brief The semaphore buffer. */ - SemaphoreHandle_t startStopSignal; /**< @brief The synchronization object for threads to signal start and stop condition. */ StaticSemaphore_t startStopSignalBuffer; /**< @brief The semaphore buffer. */ TimerHandle_t timer; /**< @brief The timer for deferred jobs. */ StaticTimer_t timerBuffer; /**< @brief The timer buffer. */ diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/types/iot_taskpool_types.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/types/iot_taskpool_types.h index 96485fddf..ce80167c2 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/types/iot_taskpool_types.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-IoT-SDK/c_sdk/standard/common/include/types/iot_taskpool_types.h @@ -235,12 +235,12 @@ typedef struct IotTaskPoolJobStorage /** * @ingroup taskpool_datatypes_handles * @brief Opaque handle of a Task Pool Job. - * + * * This type identifies a Task Pool Job instance, which is valid after a successful call * to @ref taskpool_function_createjob or @ref taskpool_function_createrecyclablejob. * - * A call to @ref taskpool_function_recyclejob or @ref taskpool_function_destroyrecyclablejob makes a - * task pool job handle invalid. Once @ref taskpool_function_recyclejob or + * A call to @ref taskpool_function_recyclejob or @ref taskpool_function_destroyrecyclablejob makes a + * task pool job handle invalid. Once @ref taskpool_function_recyclejob or * @ref taskpool_function_destroyrecyclablejob returns, the task job handle should no longer be used. * * @initializer{IotTaskPoolJob_t,IOT_TASKPOOL_JOB_INITIALIZER} @@ -325,21 +325,21 @@ typedef struct IotTaskPoolInfo */ /* @[define_taskpool_initializers] */ /** @brief Initializer for a small #IotTaskPoolInfo_t. */ -#define IOT_TASKPOOL_INFO_INITIALIZER_SMALL { .minThreads = 1, .maxThreads = 1, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } +#define IOT_TASKPOOL_INFO_INITIALIZER_SMALL { .minThreads = 1, .maxThreads = 1, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } /** @brief Initializer for a medium #IotTaskPoolInfo_t. */ -#define IOT_TASKPOOL_INFO_INITIALIZER_MEDIUM { .minThreads = 1, .maxThreads = 2, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } +#define IOT_TASKPOOL_INFO_INITIALIZER_MEDIUM { .minThreads = 1, .maxThreads = 2, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } /** @brief Initializer for a large #IotTaskPoolInfo_t. */ -#define IOT_TASKPOOL_INFO_INITIALIZER_LARGE { .minThreads = 2, .maxThreads = 3, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } +#define IOT_TASKPOOL_INFO_INITIALIZER_LARGE { .minThreads = 2, .maxThreads = 3, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } /** @brief Initializer for a very large #IotTaskPoolInfo_t. */ -#define IOT_TASKPOOL_INFO_INITIALIZER_XLARGE { .minThreads = 2, .maxThreads = 4, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } +#define IOT_TASKPOOL_INFO_INITIALIZER_XLARGE { .minThreads = 2, .maxThreads = 4, .stackSize = IOT_THREAD_DEFAULT_STACK_SIZE, .priority = IOT_THREAD_DEFAULT_PRIORITY } /** @brief Initializer for a typical #IotTaskPoolInfo_t. */ #define IOT_TASKPOOL_INFO_INITIALIZER IOT_TASKPOOL_INFO_INITIALIZER_MEDIUM /** @brief Initializer for a #IotTaskPool_t. */ -#define IOT_TASKPOOL_INITIALIZER NULL +#define IOT_TASKPOOL_INITIALIZER NULL /** @brief Initializer for a #IotTaskPoolJobStorage_t. */ -#define IOT_TASKPOOL_JOB_STORAGE_INITIALIZER { { NULL, NULL }, NULL, NULL, 0, IOT_TASKPOOL_STATUS_UNDEFINED } +#define IOT_TASKPOOL_JOB_STORAGE_INITIALIZER { { NULL, NULL }, NULL, NULL, 0, IOT_TASKPOOL_STATUS_UNDEFINED } /** @brief Initializer for a #IotTaskPoolJob_t. */ -#define IOT_TASKPOOL_JOB_INITIALIZER NULL +#define IOT_TASKPOOL_JOB_INITIALIZER NULL /* @[define_taskpool_initializers] */ /** 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 2144ba5d8..6f90c19af 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 @@ -42,7 +42,7 @@ #include #if !defined( configSUPPORT_STATIC_ALLOCATION ) || ( configSUPPORT_STATIC_ALLOCATION != 1 ) - #error configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h to build this file. + #error configSUPPORT_STATIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h to build this file. #endif /* Task pool internal include. */ @@ -653,8 +653,16 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo { TASKPOOL_FUNCTION_ENTRY( IOT_TASKPOOL_SUCCESS ); + /* Static TCB structures and arrays to be used by statically allocated + worker tasks. */ + static StaticTask_t workerTaskTCBs[ IOT_TASKPOOL_NUMBER_OF_WORKERS ]; + static StackType_t workerTaskStacks[ IOT_TASKPOOL_NUMBER_OF_WORKERS ][ IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ) ]; + + /* Static structure to hold te software timer. */ + static StaticTimer_t staticTimer; + uint32_t threadsCreated = 0; /* Although initialised before use removing the initialiser here results in compiler warnings. */ - char cTaskName[ 10 ]; + char taskName[ 10 ]; /* Check input values for consistency. */ TASKPOOL_ON_NULL_ARG_GOTO_CLEANUP( pTaskPool ); @@ -666,14 +674,12 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo _initTaskPoolControlStructures( pTaskPool ); /* Create the timer for a new connection. */ - pTaskPool->timer = xTimerCreate( NULL, portMAX_DELAY, pdFALSE, ( void * ) pTaskPool, _timerCallback ); - - if( pTaskPool->timer == NULL ) - { - IotLogError( "Failed to create timer for task pool." ); - - TASKPOOL_SET_AND_GOTO_CLEANUP( IOT_TASKPOOL_NO_MEMORY ); - } + pTaskPool->timer = xTimerCreateStatic( NULL, /* Text name for the timer, only used for debugging. */ + portMAX_DELAY, /* Timer period in ticks. */ + pdFALSE, /* pdFALSE means its a one-shot timer. */ + ( void * ) pTaskPool, /* Parameter passed into callback. */ + _timerCallback, /* Callback that executes when the timer expires. */ + &staticTimer ); /* Static storage for the timer's data structure. */ /* The task pool will initialize the minimum number of threads requested by the user upon start. Note this tailored version of the task pool does not autoscale, but fixes the number of tasks @@ -681,46 +687,25 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo /* Create the minimum number of threads specified by the user, and if one fails shutdown and return error. */ for( threadsCreated = 0; threadsCreated < pInfo->minThreads; ) { - TaskHandle_t task = NULL; - /* Generate a unique name for the task. */ - snprintf( cTaskName, sizeof( cTaskName ), "pool%d", ( int ) threadsCreated ); - - BaseType_t res = xTaskCreate( _taskPoolWorker, - cTaskName, - pInfo->stackSize / sizeof( portSTACK_TYPE ), /* xTaskCreate() expects the stack size to be specified in words. */ - pTaskPool, - pInfo->priority, - &task ); + snprintf( taskName, sizeof( taskName ), "pool%d", ( int ) threadsCreated ); - /* Create one thread. */ - if( res == pdFALSE ) //_RB_ would not be needed if tasks are created statically. - { - IotLogError( "Could not create worker thread! Exiting..." ); + xTaskCreateStatic( _taskPoolWorker, /* Function that implements the task. */ + taskName, /* Text name for the task, used for debugging only. */ + IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ), /* xTaskCreate() expects the stack size to be specified in words. */ + pTaskPool, /* Parameter passed into the task. */ + pInfo->priority, /* Priority at which the task starts running. */ + &( workerTaskStacks[ threadsCreated ][ 0 ] ), /* Pointer to static storage for the task's stack. */ + &( workerTaskTCBs[ threadsCreated ] ) ); /* Pointer to static storage for te task's TCB. */ - /* If creating one thread fails, set error condition and exit the loop. */ - TASKPOOL_SET_AND_GOTO_CLEANUP( IOT_TASKPOOL_NO_MEMORY ); - } - - /* Upon successful thread creation, increase the number of active threads. */ + /* Upon successful thread creation, increase the number of active threads. */ pTaskPool->activeThreads++; - IotTaskPool_Assert( task != NULL ); - ++threadsCreated; } + pTaskPool->running = true; TASKPOOL_FUNCTION_CLEANUP(); - /* In case of failure, wait on the created threads to exit. */ - if( TASKPOOL_FAILED( status ) ) - { - /* Set the exit condition for the newly created threads. */ -#pragma message( "Threads need to be created statically here to ensure creation cannot fail as there is no shutdown mechanism." ) - _destroyTaskPool( pTaskPool ); - } - - pTaskPool->running = true; - TASKPOOL_FUNCTION_CLEANUP_END(); } -- 2.39.5