From d1e1d1dfe48d6e00899b15916d6a2a3dadc791ea Mon Sep 17 00:00:00 2001 From: rtel Date: Tue, 23 Jul 2019 19:23:12 +0000 Subject: [PATCH] Remove the simple UDP client/server tasks from the MQTT demo as the demo's network connection can be tested more easily just by pinging it. Tidy up the iot_config.h header files a little. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2703 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../Common/FreeRTOS_TCP_server.c | 2 +- .../mqtt/DemoTasks/SimpleUDPClientAndServer.c | 369 ------------------ .../FreeRTOS_IoT_Libraries/mqtt/iot_config.h | 22 +- .../Demo/FreeRTOS_IoT_Libraries/mqtt/main.c | 47 +-- .../task_pool/iot_config.h | 24 +- .../standard/common/taskpool/iot_taskpool.c | 51 +-- .../taskpool/iot_taskpool_static_memory.c | 175 --------- 7 files changed, 68 insertions(+), 622 deletions(-) delete mode 100644 FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleUDPClientAndServer.c delete mode 100644 FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool_static_memory.c diff --git a/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/Common/FreeRTOS_TCP_server.c b/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/Common/FreeRTOS_TCP_server.c index 3b9f8fb2f..4d8cd495e 100644 --- a/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/Common/FreeRTOS_TCP_server.c +++ b/FreeRTOS-Plus/Demo/Common/Demo_IP_Protocols/Common/FreeRTOS_TCP_server.c @@ -89,7 +89,7 @@ SocketSet_t xSocketSet; xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); FreeRTOS_printf( ( "TCP socket on port %d\n", ( int )xPortNumber ) ); - if( xSocket != FREERTOS_NO_SOCKET ) + if( xSocket != FREERTOS_INVALID_SOCKET ) { xAddress.sin_addr = FreeRTOS_GetIPAddress(); // Single NIC, currently not used xAddress.sin_port = FreeRTOS_htons( xPortNumber ); diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleUDPClientAndServer.c b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleUDPClientAndServer.c deleted file mode 100644 index 32a9aec1f..000000000 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleUDPClientAndServer.c +++ /dev/null @@ -1,369 +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! - */ - -/* - * Creates two transmitting tasks and two receiving tasks. The transmitting - * tasks send values that are received by the receiving tasks. One set of tasks - * uses the standard API. The other set of tasks uses the zero copy API. - * - * See the following web page for essential demo usage and configuration - * details: - * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html - */ - -/* Standard includes. */ -#include -#include - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" - -/* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" - -#if( configASSERT_DEFINED == 0 ) - #error This demo uses configASSERT() to trap errors. configASSERT() must be defined in FreeRTOSConfig.h https://www.freertos.org/a00110.html#configASSERT -#endif - -#define simpTINY_DELAY ( ( TickType_t ) 2 ) - -/* - * Uses a socket to send data without using the zero copy option. - * prvSimpleServerTask() will receive the data. - */ -static void prvSimpleClientTask( void *pvParameters ); - -/* - * Uses a socket to receive the data sent by the prvSimpleClientTask() task. - * Does not use the zero copy option. - */ -static void prvSimpleServerTask( void *pvParameters ); - -/* - * Uses a socket to send data using the zero copy option. - * prvSimpleZeroCopyServerTask() will receive the data. - */ -static void prvSimpleZeroCopyUDPClientTask( void *pvParameters ); - -/* - * Uses a socket to receive the data sent by the prvSimpleZeroCopyUDPClientTask() - * task. Uses the zero copy option. - */ -static void prvSimpleZeroCopyServerTask( void *pvParameters ); - -/*-----------------------------------------------------------*/ - -void vStartSimpleUDPClientServerTasks( uint16_t usStackSize, uint32_t ulPort, UBaseType_t uxPriority ) -{ - /* Create the client and server tasks that do not use the zero copy - interface. */ - xTaskCreate( prvSimpleClientTask, "SimpCpyClnt", usStackSize, ( void * ) ulPort, uxPriority, NULL ); - xTaskCreate( prvSimpleServerTask, "SimpCpySrv", usStackSize, ( void * ) ulPort, uxPriority + 1, NULL ); - - /* Create the client and server tasks that do use the zero copy interface. */ - xTaskCreate( prvSimpleZeroCopyUDPClientTask, "SimpZCpyClnt", usStackSize, ( void * ) ( ulPort + 1 ), uxPriority, NULL ); - xTaskCreate( prvSimpleZeroCopyServerTask, "SimpZCpySrv", usStackSize, ( void * ) ( ulPort + 1 ), uxPriority + 1, NULL ); -} -/*-----------------------------------------------------------*/ - -static void prvSimpleClientTask( void *pvParameters ) -{ -Socket_t xClientSocket; -struct freertos_sockaddr xDestinationAddress; -uint8_t cString[ 65 ]; -BaseType_t lReturned; -uint32_t ulCount = 0UL, ulIPAddress; -const uint32_t ulLoopsPerSocket = 10UL; -const TickType_t x150ms = 150UL / portTICK_PERIOD_MS; - - /* Remove compiler warning about unused parameters. */ - ( void ) pvParameters; - - FreeRTOS_printf( ( "Starting prvSimpleClientTask\r\n" ) ); - - /* It is assumed that this task is not created until the network is up, - so the IP address can be obtained immediately. store the IP address being - used in ulIPAddress. This is done so the socket can send to a different - port on the same IP address. */ - FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL ); - - /* This test sends to itself, so data sent from here is received by a server - socket on the same IP address. Setup the freertos_sockaddr structure with - this nodes IP address, and the port number being sent to. The strange - casting is to try and remove compiler warnings on 32 bit machines. */ - xDestinationAddress.sin_addr = ulIPAddress; - xDestinationAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL; - xDestinationAddress.sin_port = FreeRTOS_htons( xDestinationAddress.sin_port ); - - for( ;; ) - { - /* Create the socket. */ - xClientSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - configASSERT( xClientSocket != FREERTOS_INVALID_SOCKET ); - - /* The count is used to differentiate between different messages sent to - the server, and to break out of the do while loop below. */ - ulCount = 0UL; - - do - { - /* Create the string that is sent to the server. */ - sprintf( ( char * ) cString, "Server received (not zero copy): Message number %lu\r\n", ulCount ); - - /* Send the string to the socket. ulFlags is set to 0, so the zero - copy option is not selected. That means the data from cString[] is - copied into a network buffer inside FreeRTOS_sendto(), and cString[] - can be reused as soon as FreeRTOS_sendto() has returned. */ - lReturned = FreeRTOS_sendto( xClientSocket, ( void * ) cString, strlen( ( const char * ) cString ), 0, &xDestinationAddress, sizeof( xDestinationAddress ) ); - - ulCount++; - - } while( ( lReturned != FREERTOS_SOCKET_ERROR ) && ( ulCount < ulLoopsPerSocket ) ); - - FreeRTOS_closesocket( xClientSocket ); - - /* A short delay to prevent the messages printed by the server task - scrolling off the screen too quickly, and to prevent reduce the network - loading. */ - vTaskDelay( x150ms ); - } -} -/*-----------------------------------------------------------*/ - -static void prvSimpleServerTask( void *pvParameters ) -{ -int32_t lBytes; -uint8_t cReceivedString[ 60 ]; -struct freertos_sockaddr xClient, xBindAddress; -uint32_t xClientLength = sizeof( xClient ); -Socket_t xListeningSocket; - - /* Just to prevent compiler warnings. */ - ( void ) pvParameters; - - FreeRTOS_printf( ( "Starting prvSimpleServerTask\r\n" ) ); - - /* Attempt to open the socket. */ - xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET ); - - /* This test receives data sent from a different port on the same IP - address. Configure the freertos_sockaddr structure with the address being - bound to. The strange casting is to try and remove compiler warnings on 32 - bit machines. Note that this task is only created after the network is up, - so the IP address is valid here. */ - xBindAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL; - xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port ); - - /* Bind the socket to the port that the client task will send to. */ - FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) ); - - for( ;; ) - { - /* Zero out the receive array so there is NULL at the end of the string - when it is printed out. */ - memset( cReceivedString, 0x00, sizeof( cReceivedString ) ); - - /* Receive data on the socket. ulFlags is zero, so the zero copy option - is not set and the received data is copied into the buffer pointed to by - cReceivedString. By default the block time is portMAX_DELAY. - xClientLength is not actually used by FreeRTOS_recvfrom(), but is set - appropriately in case future versions do use it. */ - lBytes = FreeRTOS_recvfrom( xListeningSocket, cReceivedString, sizeof( cReceivedString ), 0, &xClient, &xClientLength ); - - /* Error check. */ - configASSERT( lBytes == ( BaseType_t ) strlen( ( const char * ) cReceivedString ) ); - FreeRTOS_printf( ( "prvSimpleServerTask() recieved %s\r\n", ( const char * ) cReceivedString ) ); - } -} -/*-----------------------------------------------------------*/ - -static void prvSimpleZeroCopyUDPClientTask( void *pvParameters ) -{ -Socket_t xClientSocket; -uint8_t *pucUDPPayloadBuffer; -struct freertos_sockaddr xDestinationAddress; -BaseType_t lReturned; -uint32_t ulCount = 0UL, ulIPAddress; -const uint32_t ulLoopsPerSocket = 10UL; -const char *pcStringToSend = "Server received (using zero copy): Message number "; -const TickType_t x150ms = 150UL / portTICK_PERIOD_MS; -/* 15 is added to ensure the number, \r\n and terminating zero fit. */ -const size_t xStringLength = strlen( pcStringToSend ) + 15; - - /* Remove compiler warning about unused parameters. */ - ( void ) pvParameters; - - FreeRTOS_printf( ( "Starting prvSimpleZeroCopyUDPClientTask\r\n" ) ); - - /* It is assumed that this task is not created until the network is up, - so the IP address can be obtained immediately. store the IP address being - used in ulIPAddress. This is done so the socket can send to a different - port on the same IP address. */ - FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL ); - - /* This test sends to itself, so data sent from here is received by a server - socket on the same IP address. Setup the freertos_sockaddr structure with - this nodes IP address, and the port number being sent to. The strange - casting is to try and remove compiler warnings on 32 bit machines. */ - xDestinationAddress.sin_addr = ulIPAddress; - xDestinationAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL; - xDestinationAddress.sin_port = FreeRTOS_htons( xDestinationAddress.sin_port ); - - for( ;; ) - { - /* Create the socket. */ - xClientSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - configASSERT( xClientSocket != FREERTOS_INVALID_SOCKET ); - - /* The count is used to differentiate between different messages sent to - the server, and to break out of the do while loop below. */ - ulCount = 0UL; - - do - { - /* This task is going to send using the zero copy interface. The - data being sent is therefore written directly into a buffer that is - passed into, rather than copied into, the FreeRTOS_sendto() - function. - - First obtain a buffer of adequate length from the IP stack into which - the string will be written. Although a max delay is used, the actual - delay will be capped to ipconfigMAX_SEND_BLOCK_TIME_TICKS, hence - the do while loop is used to ensure a buffer is obtained. */ - do - { - } while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xStringLength, portMAX_DELAY ) ) == NULL ); - - /* A buffer was successfully obtained. Create the string that is - sent to the server. First the string is filled with zeros as this will - effectively be the null terminator when the string is received at the other - end. Note that the string is being written directly into the buffer - obtained from the IP stack above. */ - memset( ( void * ) pucUDPPayloadBuffer, 0x00, xStringLength ); - sprintf( ( char * ) pucUDPPayloadBuffer, "%s%lu\r\n", pcStringToSend, ulCount ); - - /* Pass the buffer into the send function. ulFlags has the - FREERTOS_ZERO_COPY bit set so the IP stack will take control of the - buffer rather than copy data out of the buffer. */ - lReturned = FreeRTOS_sendto( xClientSocket, /* The socket being sent to. */ - ( void * ) pucUDPPayloadBuffer, /* A pointer to the the data being sent. */ - strlen( ( const char * ) pucUDPPayloadBuffer ) + 1, /* The length of the data being sent - including the string's null terminator. */ - FREERTOS_ZERO_COPY, /* ulFlags with the FREERTOS_ZERO_COPY bit set. */ - &xDestinationAddress, /* Where the data is being sent. */ - sizeof( xDestinationAddress ) ); - - if( lReturned == 0 ) - { - /* The send operation failed, so this task is still responsible - for the buffer obtained from the IP stack. To ensure the buffer - is not lost it must either be used again, or, as in this case, - returned to the IP stack using FreeRTOS_ReleaseUDPPayloadBuffer(). - pucUDPPayloadBuffer can be safely re-used after this call. */ - FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayloadBuffer ); - } - else - { - /* The send was successful so the IP stack is now managing the - buffer pointed to by pucUDPPayloadBuffer, and the IP stack will - return the buffer once it has been sent. pucUDPPayloadBuffer can - be safely re-used. */ - } - - ulCount++; - - } while( ( lReturned != FREERTOS_SOCKET_ERROR ) && ( ulCount < ulLoopsPerSocket ) ); - - FreeRTOS_closesocket( xClientSocket ); - - /* A short delay to prevent the messages scrolling off the screen too - quickly. */ - vTaskDelay( x150ms ); - } -} -/*-----------------------------------------------------------*/ - -static void prvSimpleZeroCopyServerTask( void *pvParameters ) -{ -int32_t lBytes; -uint8_t *pucUDPPayloadBuffer; -struct freertos_sockaddr xClient, xBindAddress; -uint32_t xClientLength = sizeof( xClient ), ulIPAddress; -Socket_t xListeningSocket; - - /* Just to prevent compiler warnings. */ - ( void ) pvParameters; - - FreeRTOS_printf( ( "Starting prvSimpleZeroCopyServerTask\r\n" ) ); - - /* Attempt to open the socket. */ - xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP ); - configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET ); - - /* This test receives data sent from a different port on the same IP address. - Obtain the nodes IP address. Configure the freertos_sockaddr structure with - the address being bound to. The strange casting is to try and remove - compiler warnings on 32 bit machines. Note that this task is only created - after the network is up, so the IP address is valid here. */ - FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL ); - xBindAddress.sin_addr = ulIPAddress; - xBindAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL; - xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port ); - - /* Bind the socket to the port that the client task will send to. */ - FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) ); - - for( ;; ) - { - /* Receive data on the socket. ulFlags has the zero copy bit set - (FREERTOS_ZERO_COPY) indicating to the stack that a reference to the - received data should be passed out to this task using the second - parameter to the FreeRTOS_recvfrom() call. When this is done the - IP stack is no longer responsible for releasing the buffer, and - the task *must* return the buffer to the stack when it is no longer - needed. By default the block time is portMAX_DELAY. */ - lBytes = FreeRTOS_recvfrom( xListeningSocket, ( void * ) &pucUDPPayloadBuffer, 0, FREERTOS_ZERO_COPY, &xClient, &xClientLength ); - - /* Print the received characters. */ - if( lBytes > 0 ) - { - /* It is expected to receive one more byte than the string length as - the NULL terminator is also transmitted. */ - configASSERT( lBytes == ( ( BaseType_t ) strlen( ( const char * ) pucUDPPayloadBuffer ) + 1 ) ); - FreeRTOS_printf( ( "prvSimpleZeroCopyServerTask() recieved %s\r\n", ( const char * ) pucUDPPayloadBuffer ) ); - } - - if( lBytes >= 0 ) - { - /* The buffer *must* be freed once it is no longer needed. */ - FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer ); - } - } -} - diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/iot_config.h b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/iot_config.h index 1f9568618..d26744779 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/iot_config.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/iot_config.h @@ -61,7 +61,18 @@ */ #define IOT_TASKPOOL_ENABLE_ASSERTS 1 -/** +/* + * The full IoT Task Pool Library has many use cases, including Linux + * development.  Typical FreeRTOS use cases do not require the full + * functionality so an optimised implementation is provided specifically for use + * with FreeRTOS. The optimised version has a fixed number of tasks in the + * pool, each of which uses statically allocated memory to ensure creation of + * the pool is guaranteed (it does not run out of heap space). + * IOT_TASKPOOL_NUMBER_OF_WORKERS sets the number of tasks in the pool. + */ +#define IOT_TASKPOOL_NUMBER_OF_WORKERS 3 + +/* * @brief Set the log level of the task pool library. * * Log messages from the task pool library at or below this setting will be @@ -73,13 +84,6 @@ */ #define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_INFO -/** - * @brief The number of worker tasks in the task pool. - * - * The minimal version of the of task pool library only supports one task pool - * and the number of the worker tasks is fixed at the compile time. - */ -#define IOT_TASKPOOL_NUMBER_OF_WORKERS 3 /** * @brief The stack size (in bytes) for each worker task in the task pool. @@ -98,7 +102,7 @@ /** * @brief Enable/Disable anonymous metrics collection when using AWS IoT. * - * This demo does not support TLS and so does not work with AWS IoT. Therefore, + * This demo does not use TLS and so does not work with AWS IoT. Therefore, * the metric collection must be disabled. */ #define AWS_IOT_MQTT_ENABLE_METRICS 0 diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/main.c b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/main.c index 5b6c054fb..cbec6796e 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/main.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/main.c @@ -26,10 +26,7 @@ */ /* - * This project is a cut down version of the project described on the following - * link. Only the simple UDP client and server and the TCP echo clients are - * included in the build: - * http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html + * TBD */ /* Standard includes. */ @@ -51,32 +48,13 @@ should an assert get hit. */ /* Demo app includes. */ #include "demo_logging.h" -/* 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_SIMPLE_MQTT_EXAMPLE_TASKS: TBD -*/ -#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 0 -#define mainCREATE_SIMPLE_MQTT_EXAMPLE_TASKS 1 - -/* Simple UDP client and server task parameters. */ -#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY ) -#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL ) - /* - * Prototypes for the demos that can be started from this project. + * Prototypes for the demos that can be started from this project. Note the + * MQTT demo is not actually started until the network is already, which is + * indicated by vApplicationIPNetworkEventHook() executing - hence + * prvStartSimpleMQTTDemo() is called from inside vApplicationIPNetworkEventHook(). */ extern void vStartSimpleMQTTDemo( void ); -extern void vStartSimpleUDPClientServerTasks( uint16_t usStackSize, uint32_t ulsPort, UBaseType_t uxPriority ); /* * Just seeds the simple pseudo random number generator. @@ -197,18 +175,9 @@ static BaseType_t xTasksAlreadyCreated = pdFALSE; created. */ if( xTasksAlreadyCreated == pdFALSE ) { - #if( mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS == 1 ) - { - vStartSimpleUDPClientServerTasks( configMINIMAL_STACK_SIZE, mainSIMPLE_UDP_CLIENT_SERVER_PORT, mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ); - } - #endif - - #if( mainCREATE_SIMPLE_MQTT_EXAMPLE_TASKS == 1 ) - { - vStartSimpleMQTTDemo(); - } - #endif - + /* Demos that use the nextwork are created after the nextwork is + up. */ + vStartSimpleMQTTDemo(); xTasksAlreadyCreated = pdTRUE; } 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 470a13d6d..0121f276d 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 @@ -59,6 +59,17 @@ */ #define IOT_TASKPOOL_ENABLE_ASSERTS 1 +/* + * The full IoT Task Pool Library has many use cases, including Linux + * development.  Typical FreeRTOS use cases do not require the full + * functionality so an optimised implementation is provided specifically for use + * with FreeRTOS. The optimised version has a fixed number of tasks in the + * pool, each of which uses statically allocated memory to ensure creation of + * the pool is guaranteed (it does not run out of heap space). + * IOT_TASKPOOL_NUMBER_OF_WORKERS sets the number of tasks in the pool. + */ +#define IOT_TASKPOOL_NUMBER_OF_WORKERS 3 + /* * Set the log level of the task pool library. * @@ -71,15 +82,14 @@ */ #define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_INFO -/* - * - */ -#define IOT_TASKPOOL_NUMBER_OF_WORKERS 3 -/* - * +/** + * @brief The stack size (in bytes) for each worker task in the task pool. + * + * The minimal version of the of task pool library only supports one task pool + * and the configuration of each worker task fixed at the compile time. */ -#define IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES 2048 +#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/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool.c index 6f90c19af..0a51c3a57 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool.c @@ -27,6 +27,35 @@ * @brief Implements the task pool functions in iot_taskpool.h */ + +/* + * The full IoT Task Pool Library has many use cases, including Linux + * development.  Typical FreeRTOS use cases do not require the full + * functionality so an optimised implementation is provided specifically for use + * with FreeRTOS. The optimised version has a fixed number of tasks in the + * pool, each of which uses statically allocated memory to ensure creation of + * the pool is guaranteed (it does not run out of heap space). The constant + * IOT_TASKPOOL_NUMBER_OF_WORKERS sets the number of tasks in the pool. + * + * Unlike the full version, this optimised version: + * + Only supports a single task pool (system task pool) at a time. + * + Does not auto-scale by dynamically adding more tasks if the number of + * + tasks in the pool becomes exhausted.  The number of tasks in the pool + * are fixed at compile time.  See the task pool configuration options for + * more information. + * + Cannot be shut down - it exists for the lifetime of the application. + * + * As such this file does not implement the following API functions: + * + IotTaskPool_GetSystemTaskPool() + * + IotTaskPool_Create() + * + IotTaskPool_Destroy() + * + IotTaskPool_SetMaxThreads() + * + * Users who are interested in the functionality of the full IoT Task Pool + * library can us it in place of this optimised version. + */ + + /* Kernel includes. */ #include "FreeRTOS.h" #include "semphr.h" @@ -224,28 +253,6 @@ static IotTaskPoolError_t _tryCancelInternal( _taskPool_t * const pTaskPool, /* ---------------------------------------------------------------------------------------------- */ -/* - * The full IoT Task Pool Library has many use cases, including Linux - * development.  Typical FreeRTOS use cases do not require the full - * functionality so optimised version is provided specifically for use with - * FreeRTOS. Unlike the full version, this optimised version: - * + Only supports a single task pool (system task pool) at a time. - * + Does not auto-scale by dynamically adding more tasks if the number of - * + tasks in the pool becomes exhausted.  The number of tasks in the pool - * are fixed at compile time.  See the task pool configuration options for - * more information. - * + Cannot be shut down - it exists for the lifetime of the application. - * - * As such this file does not implement the following API functions: - * + IotTaskPool_GetSystemTaskPool() - * + IotTaskPool_Create() - * + IotTaskPool_Destroy() - * + IotTaskPool_SetMaxThreads() - * - * Users who are interested in the functionality of the full IoT Task Pool - * library can us it in place of this optimised version. - */ - IotTaskPoolError_t IotTaskPool_CreateSystemTaskPool( const IotTaskPoolInfo_t * const pInfo ) { TASKPOOL_FUNCTION_ENTRY( IOT_TASKPOOL_SUCCESS ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool_static_memory.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool_static_memory.c deleted file mode 100644 index 8de4f6e27..000000000 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool_static_memory.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Amazon FreeRTOS Common V1.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. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_taskpool_static_memory.c - * @brief Implementation of task pool static memory functions. - */ - -/* The config header is always included first. */ -#include "iot_config.h" - -/* This file should only be compiled if dynamic memory allocation is forbidden. */ -#if IOT_STATIC_MEMORY_ONLY == 1 - -/* Standard includes. */ -#include -#include -#include - -/* Static memory include. */ -#include "private/iot_static_memory.h" - -/* Task pool internal include. */ -#include "private/iot_taskpool_internal.h" - -/*-----------------------------------------------------------*/ - -/* Validate static memory configuration settings. */ -#if IOT_TASKPOOL_JOBS_RECYCLE_LIMIT <= 0 - #error "IOT_TASKPOOL_JOBS_RECYCLE_LIMIT cannot be 0 or negative." -#endif - -/*-----------------------------------------------------------*/ - -/* - * Static memory buffers and flags, allocated and zeroed at compile-time. - */ -static bool _pInUseTaskPools[ IOT_TASKPOOLS ] = { 0 }; /**< @brief Task pools in-use flags. */ -static _taskPool_t _pTaskPools[ IOT_TASKPOOLS ] = { { .dispatchQueue = IOT_DEQUEUE_INITIALIZER } }; /**< @brief Task pools. */ - -static bool _pInUseTaskPoolJobs[ IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ] = { 0 }; /**< @brief Task pool jobs in-use flags. */ -static _taskPoolJob_t _pTaskPoolJobs[ IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ] = { { .link = IOT_LINK_INITIALIZER } }; /**< @brief Task pool jobs. */ - -static bool _pInUseTaskPoolTimerEvents[ IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ] = { 0 }; /**< @brief Task pool timer event in-use flags. */ -static _taskPoolTimerEvent_t _pTaskPoolTimerEvents[ IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ] = { { .link = { 0 } } }; /**< @brief Task pool timer events. */ - -/*-----------------------------------------------------------*/ - -void * IotTaskPool_MallocTaskPool( size_t size ) -{ - int freeIndex = -1; - void * pNewTaskPool = NULL; - - /* Check size argument. */ - if( size == sizeof( _taskPool_t ) ) - { - /* Find a free task pool job. */ - freeIndex = IotStaticMemory_FindFree( _pInUseTaskPools, IOT_TASKPOOLS ); - - if( freeIndex != -1 ) - { - pNewTaskPool = &( _pTaskPools[ freeIndex ] ); - } - } - - return pNewTaskPool; -} - -/*-----------------------------------------------------------*/ - -void IotTaskPool_FreeTaskPool( void * ptr ) -{ - /* Return the in-use task pool job. */ - IotStaticMemory_ReturnInUse( ptr, - _pTaskPools, - _pInUseTaskPools, - IOT_TASKPOOLS, - sizeof( _taskPool_t ) ); -} - -/*-----------------------------------------------------------*/ - -void * IotTaskPool_MallocJob( size_t size ) -{ - int32_t freeIndex = -1; - void * pNewJob = NULL; - - /* Check size argument. */ - if( size == sizeof( _taskPoolJob_t ) ) - { - /* Find a free task pool job. */ - freeIndex = IotStaticMemory_FindFree( _pInUseTaskPoolJobs, - IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ); - - if( freeIndex != -1 ) - { - pNewJob = &( _pTaskPoolJobs[ freeIndex ] ); - } - } - - return pNewJob; -} - -/*-----------------------------------------------------------*/ - -void IotTaskPool_FreeJob( void * ptr ) -{ - /* Return the in-use task pool job. */ - IotStaticMemory_ReturnInUse( ptr, - _pTaskPoolJobs, - _pInUseTaskPoolJobs, - IOT_TASKPOOL_JOBS_RECYCLE_LIMIT, - sizeof( _taskPoolJob_t ) ); -} - -/*-----------------------------------------------------------*/ - -void * IotTaskPool_MallocTimerEvent( size_t size ) -{ - int32_t freeIndex = -1; - void * pNewTimerEvent = NULL; - - /* Check size argument. */ - if( size == sizeof( _taskPoolTimerEvent_t ) ) - { - /* Find a free task pool timer event. */ - freeIndex = IotStaticMemory_FindFree( _pInUseTaskPoolTimerEvents, - IOT_TASKPOOL_JOBS_RECYCLE_LIMIT ); - - if( freeIndex != -1 ) - { - pNewTimerEvent = &( _pTaskPoolTimerEvents[ freeIndex ] ); - } - } - - return pNewTimerEvent; -} - -/*-----------------------------------------------------------*/ - -void IotTaskPool_FreeTimerEvent( void * ptr ) -{ - /* Return the in-use task pool timer event. */ - IotStaticMemory_ReturnInUse( ptr, - _pTaskPoolTimerEvents, - _pInUseTaskPoolTimerEvents, - IOT_TASKPOOL_JOBS_RECYCLE_LIMIT, - sizeof( _taskPoolTimerEvent_t ) ); -} - -/*-----------------------------------------------------------*/ - -#endif -- 2.39.2