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.
This commit is contained in:
Richard Barry
2019-07-23 19:23:12 +00:00
parent 95f60318d5
commit 53842d4cac
7 changed files with 68 additions and 622 deletions

View File

@ -89,7 +89,7 @@ SocketSet_t xSocketSet;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
FreeRTOS_printf( ( "TCP socket on port %d\n", ( int )xPortNumber ) ); 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_addr = FreeRTOS_GetIPAddress(); // Single NIC, currently not used
xAddress.sin_port = FreeRTOS_htons( xPortNumber ); xAddress.sin_port = FreeRTOS_htons( xPortNumber );

View File

@ -61,7 +61,18 @@
*/ */
#define IOT_TASKPOOL_ENABLE_ASSERTS 1 #define IOT_TASKPOOL_ENABLE_ASSERTS 1
/** /*
* The full IoT Task Pool Library has many use cases, including Linux
* development. <20>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. * @brief Set the log level of the task pool library.
* *
* Log messages from the task pool library at or below this setting will be * 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 #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. * @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. * @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. * the metric collection must be disabled.
*/ */
#define AWS_IOT_MQTT_ENABLE_METRICS 0 #define AWS_IOT_MQTT_ENABLE_METRICS 0

View File

@ -26,10 +26,7 @@
*/ */
/* /*
* This project is a cut down version of the project described on the following * TBD
* 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
*/ */
/* Standard includes. */ /* Standard includes. */
@ -51,32 +48,13 @@ should an assert get hit. */
/* Demo app includes. */ /* Demo app includes. */
#include "demo_logging.h" #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 vStartSimpleMQTTDemo( void );
extern void vStartSimpleUDPClientServerTasks( uint16_t usStackSize, uint32_t ulsPort, UBaseType_t uxPriority );
/* /*
* Just seeds the simple pseudo random number generator. * Just seeds the simple pseudo random number generator.
@ -197,18 +175,9 @@ static BaseType_t xTasksAlreadyCreated = pdFALSE;
created. */ created. */
if( xTasksAlreadyCreated == pdFALSE ) if( xTasksAlreadyCreated == pdFALSE )
{ {
#if( mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS == 1 ) /* Demos that use the nextwork are created after the nextwork is
{ up. */
vStartSimpleUDPClientServerTasks( configMINIMAL_STACK_SIZE, mainSIMPLE_UDP_CLIENT_SERVER_PORT, mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ); vStartSimpleMQTTDemo();
}
#endif
#if( mainCREATE_SIMPLE_MQTT_EXAMPLE_TASKS == 1 )
{
vStartSimpleMQTTDemo();
}
#endif
xTasksAlreadyCreated = pdTRUE; xTasksAlreadyCreated = pdTRUE;
} }

View File

@ -59,6 +59,17 @@
*/ */
#define IOT_TASKPOOL_ENABLE_ASSERTS 1 #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. * Set the log level of the task pool library.
* *
@ -71,15 +82,14 @@
*/ */
#define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_INFO #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 the common configuration file for FreeRTOS. */
#include "iot_config_common.h" #include "iot_config_common.h"

View File

@ -27,6 +27,35 @@
* @brief Implements the task pool functions in iot_taskpool.h * @brief Implements the task pool functions in iot_taskpool.h
*/ */
/*
* The full IoT Task Pool Library has many use cases, including Linux
* development. <20>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. <20>The number of tasks in the pool
* are fixed at compile time.<2E> 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. */ /* Kernel includes. */
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "semphr.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. <20>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. <20>The number of tasks in the pool
* are fixed at compile time.<2E> 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 ) IotTaskPoolError_t IotTaskPool_CreateSystemTaskPool( const IotTaskPoolInfo_t * const pInfo )
{ {
TASKPOOL_FUNCTION_ENTRY( IOT_TASKPOOL_SUCCESS ); TASKPOOL_FUNCTION_ENTRY( IOT_TASKPOOL_SUCCESS );

View File

@ -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 <stdbool.h>
#include <stddef.h>
#include <string.h>
/* 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