Continued to work on the MQTT demo project.

A few review comments added into the MQTT implementation.
This commit is contained in:
Richard Barry 2019-07-24 00:27:14 +00:00
parent 53842d4cac
commit fe4511b35e
21 changed files with 244 additions and 166 deletions

View File

@ -146,8 +146,8 @@ static void prvMQTTDemoTask( void *pvParameters );
* @param[in] pxCallbackParams Contains the reason why the MQTT connection was
* disconnected.
*/
static void prvExample_DisconnectCallback( void * pvCallbackContext,
IotMqttCallbackParam_t * pxCallbackParams );
static void prvExample_OnDisconnect( void * pvCallbackContext,
IotMqttCallbackParam_t * pxCallbackParams );
/**
* @brief The callback invoked by the MQTT library when a message is received on
@ -158,8 +158,8 @@ static void prvExample_DisconnectCallback( void * pvCallbackContext,
* @param[in] pxCallbackParams Contain the details about the received message -
* topic on which the message was received, the received message.
*/
static void prvExample_PublishCallback( void * pvCallbackContext,
IotMqttCallbackParam_t * pxCallbackParams );
static void prvExample_OnMessageReceived( void * pvCallbackContext,
IotMqttCallbackParam_t * pxCallbackParams );
/**
* @brief Connects to the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT
@ -191,7 +191,7 @@ static void prvMQTTUnsubscribe( void );
static void prvMQTTDisconnect( void );
/*-----------------------------------------------------------*/
static void prvExample_DisconnectCallback( void * pvCallbackContext,
static void prvExample_OnDisconnect( void * pvCallbackContext,
IotMqttCallbackParam_t * pxCallbackParams )
{
TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;
@ -207,7 +207,7 @@ TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;
}
/*-----------------------------------------------------------*/
static void prvExample_PublishCallback( void * pvCallbackContext,
static void prvExample_OnMessageReceived( void * pvCallbackContext,
IotMqttCallbackParam_t * pxCallbackParams )
{
TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;
@ -227,6 +227,12 @@ TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;
/* Ensure that the message QoS is as expected. */
configASSERT( pxCallbackParams->u.message.info.qos == IOT_MQTT_QOS_1 );
/* Although this print uses the constants rather than the data from the
message payload the asserts above have already checked the message payload
equals the constants, and it is more efficient not to have to worry about
lengths in the print. */
configPRINTF( ( "Received %s from topic %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) );
/* Inform the demo task about the message received from the MQTT broker. */
xTaskNotify( xDemoTaskHandle,
mqttexampleMESSAGE_RECEIVED_BIT,
@ -252,7 +258,8 @@ void vStartSimpleMQTTDemo( void )
static void prvMQTTDemoTask( void *pvParameters )
{
IotMqttError_t xResult;
uint32_t ulNotificationValue = 0;
uint32_t ulNotificationValue = 0, ulIterations;
const uint32_t ulMaxIterations = 5UL;
const TickType_t xNoDelay = ( TickType_t ) 0;
/* Remove compiler warnings about unused parameters. */
@ -272,55 +279,77 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
/* Don't expect any notifications to be pending yet. */
configASSERT( ulTaskNotifyTake( pdTRUE, xNoDelay ) == 0 );
/******************** CONNECT ****************************************/
/* Establish a connection to the MQTT broker. This example connects to
* the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT and
* mqttexampleMQTT_BROKER_PORT at the top of this file. Please change
* it to the MQTT broker you want to connect to. Note that this example
* does not use TLS and therefore will not work with AWS IoT. */
prvMQTTConnect();
configPRINTF( ( "Connected to %s\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) );
/* Subscribe to the topic as specified in mqttexampleTOPIC at the top
* of this file. */
/******************* SUBSCRIBE ***************************************/
/* The client is now connected to the broker. Subscribe to the topic
as specified in mqttexampleTOPIC at the top of this file. This client
will then publish to the same topic it subscribed to, so will expect
all the messages it sends to the broker to be sent back to it from the
broker. */
prvMQTTSubscribe();
configPRINTF( ( "Subscribed to %s\r\n", mqttexampleTOPIC ) );
/* Publish a message on the mqttexampleTOPIC topic as specified at the
* top of this file. */
prvMQTTPublish();
/* Since we are subscribed on the same topic, we will get the same
* message back from the MQTT broker. Wait for the message to be
* received which is informed to us by the publish callback
* (prvExample_PublishCallback) by setting the mqttexampleMESSAGE_RECEIVED_BIT
* in 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. */
pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );
configASSERT( ( ulNotificationValue & mqttexampleMESSAGE_RECEIVED_BIT ) == mqttexampleMESSAGE_RECEIVED_BIT );
/******************* PUBLISH 5 TIMES *********************************/
/* Unsubscribe from the topic mqttexampleTOPIC. */
/* Publish a few messages while connected. */
for( ulIterations = 0; ulIterations < ulMaxIterations; ulIterations++ )
{
/* Publish a message on the mqttexampleTOPIC topic as specified at the
* top of this file. */
prvMQTTPublish();
configPRINTF( ( "Published %s to %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) );
/* Since we are subscribed on the same topic, we will get the same
* message back from the MQTT broker. Wait for the message to be
* received which is informed to us by the publish callback
* (prvExample_OnMessageReceived) by setting the
* mqttexampleMESSAGE_RECEIVED_BIT in this task's notification
value. */
xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
mqttexampleMESSAGE_RECEIVED_BIT, /* Clear bit on exit. */
&( ulNotificationValue ), /* Obtain the notification value. */
pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );
configASSERT( ( ulNotificationValue & mqttexampleMESSAGE_RECEIVED_BIT ) == mqttexampleMESSAGE_RECEIVED_BIT );
}
/******************* UNSUBSCRIBE AND DISCONNECT **********************/
/* Unsubscribe from the topic mqttexampleTOPIC the disconnect
gracefully. */
prvMQTTUnsubscribe();
/* Gracefully disconnect from the MQTT broker by sending an MQTT
* DISCONNECT message. */
prvMQTTDisconnect();
configPRINTF( ( "Disconnected from from %s\r\n\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) );
/* Wait for the disconnect operation to complete which is informed to us
* by the disconnect callback (prvExample_DisconnectCallback)by setting
* by the disconnect callback (prvExample_OnDisconnect)by setting
* the mqttexampleDISCONNECTED_BIT in this task's notification value.
* Note that all bits are cleared in the task's notification value to
* ensure that it is ready for the next run. */
xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */
portMAX_DELAY, /* Clear all bits on exit - portMAX_DELAY is used as it is a portable way of having all bits set. */
mqttexampleDISCONNECTED_BIT, /* Clear bit again on exit. */
&( ulNotificationValue ), /* Obtain the notification value. */
pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );
configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT );
printf( "prvMQTTDemoTask() completed an iteration without hitting an assert.\r\n" );
fflush( stdout );
/* Wait for some time between two iterations to ensure that we do not
* bombard the public test mosquitto broker. */
configPRINTF( ( "prvMQTTDemoTask() completed an iteration without hitting an assert. Total free heap is %u\r\n\r\n", xPortGetFreeHeapSize() ) );
vTaskDelay( pdMS_TO_TICKS( 5000 ) );
}
}
@ -351,11 +380,12 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
xNetworkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_FREERTOS;
/* Setup the callback which is called when the MQTT connection is disconnected. */
xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();
xNetworkInfo.disconnectCallback.function = prvExample_DisconnectCallback;
xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();//_RB_ Why the task handle?
xNetworkInfo.disconnectCallback.function = prvExample_OnDisconnect;
/****************** MQTT Connection information setup. ********************/
/* This example does not use TLS and therefore won't work with AWS IoT. */
/* Set this flag to true if connecting to the AWS IoT MQTT broker. This
example does not use TLS and therefore won't work with AWS IoT. */
xConnectInfo.awsIotMqttMode = false;
/* Start with a clean session i.e. direct the MQTT broker to discard any
@ -373,11 +403,13 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
* client gets disconnected. */
xConnectInfo.pWillInfo = NULL;
/* Send an MQTT PING request every minute. */
/* Send an MQTT PING request every minute to keep the connection open if
there is no other MQTT trafic. */
xConnectInfo.keepAliveSeconds = mqttexampleKEEP_ALIVE_SECONDS;
/* The client identifier is used to uniquely identify this MQTT client to
* the MQTT broker. */
* the MQTT broker. In a production device the identifier can be something
unique, such as a device serial number. */
xConnectInfo.pClientIdentifier = mqttexampleCLIENT_IDENTIFIER;
xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( mqttexampleCLIENT_IDENTIFIER );
@ -389,7 +421,7 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
xConnectInfo.passwordLength = 0;
/* Establish the connection to the MQTT broker - It is a blocking call and
will return only when connection is complete. */
will return only when connection is complete or a timeout occurrs. */
xResult = IotMqtt_Connect( &( xNetworkInfo ),
&( xConnectInfo ),
mqttexampleMQTT_TIMEOUT_MS,
@ -408,7 +440,7 @@ IotMqttSubscription_t xMQTTSubscription;
xMQTTSubscription.pTopicFilter = mqttexampleTOPIC;
xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );
xMQTTSubscription.callback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();
xMQTTSubscription.callback.function = prvExample_PublishCallback;
xMQTTSubscription.callback.function = prvExample_OnMessageReceived;
/* Use the synchronous API to subscribe - It is a blocking call and only
* returns when the subscribe operation is complete. */

View File

@ -138,10 +138,8 @@ configNETWORK_INTERFACE_TO_USE to 2 results in the wireless network being
used. */
#define configNETWORK_INTERFACE_TO_USE 3L
/* The address of an echo server that will be used by the two demo echo client
tasks.
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Clients.html
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/UDP_Echo_Clients.html */
/* The address of an echo server is only left in this project as it douples as
the address to which logging is sent should UDP logging be enabled. */
#define configECHO_SERVER_ADDR0 192
#define configECHO_SERVER_ADDR1 168
#define configECHO_SERVER_ADDR2 0
@ -154,9 +152,9 @@ configNETWORK_INTERFACE_TO_USE definition above for information on how to
configure the real network connection to use. */
#define configMAC_ADDR0 0x00
#define configMAC_ADDR1 0x11
#define configMAC_ADDR2 0x22
#define configMAC_ADDR3 0x33
#define configMAC_ADDR4 0x44
#define configMAC_ADDR2 0x11
#define configMAC_ADDR3 0x11
#define configMAC_ADDR4 0x11
#define configMAC_ADDR5 0x41
/* Default IP address configuration. Used in ipconfigUSE_DNS is set to 0, or
@ -202,5 +200,11 @@ ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
#define strncasecmp _strnicmp
#define strcmpi _strcmpi
/* Prototype for the function used to print out. In this case it prints to the
console before the network is connected then a UDP port after the network has
connected. */
extern void vLoggingPrintf( const char *pcFormatString, ... );
#define configPRINTF( X ) vLoggingPrintf X
#endif /* FREERTOS_CONFIG_H */

View File

@ -44,7 +44,7 @@ extern void vLoggingPrintf( const char *pcFormatString, ... );
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
1 then FreeRTOS_debug_printf should be defined to the function used to print
out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 0
#define ipconfigHAS_DEBUG_PRINTF 1
#if( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf(X) vLoggingPrintf X
#endif

View File

@ -168,7 +168,6 @@
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement\BufferAllocation_2.c" />
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\NetworkInterface\WinPCap\NetworkInterface.c" />
<ClCompile Include="DemoTasks\SimpleMQTTExamples.c" />
<ClCompile Include="DemoTasks\SimpleUDPClientAndServer.c" />
<ClCompile Include="demo_logging.c" />
<ClCompile Include="main.c">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

View File

@ -110,9 +110,6 @@
<ClCompile Include="..\..\..\..\FreeRTOS\Source\tasks.c">
<Filter>FreeRTOS\Source</Filter>
</ClCompile>
<ClCompile Include="DemoTasks\SimpleUDPClientAndServer.c">
<Filter>DemoTasks</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_UDP_IP.c">
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
</ClCompile>

View File

@ -24,9 +24,6 @@
#ifndef IOT_CONFIG_H_
#define IOT_CONFIG_H_
/* Use platform types on FreeRTOS. */
#include "FreeRTOS.h"
#include "platform/iot_platform_types_freertos.h" //_RB_Makes common config file FreeRTOS specific
/**
* @brief The number of recyclable jobs for the task pool to cache.
@ -82,7 +79,7 @@
* 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_LOG_LEVEL_TASKPOOL IOT_LOG_WARN
/**
@ -107,6 +104,18 @@
*/
#define AWS_IOT_MQTT_ENABLE_METRICS 0
/*
* @brief 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_MQTT IOT_LOG_WARN
/* Include the common configuration file for FreeRTOS. */
#include "iot_config_common.h"

View File

@ -34,9 +34,6 @@
/* 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"

View File

@ -136,30 +136,6 @@ int main( void )
}
/*-----------------------------------------------------------*/
void vAssertCalled( const char *pcFile, uint32_t ulLine )
{
volatile uint32_t ulBlockVariable = 0UL;
volatile char *pcFileName = ( volatile char * ) pcFile;
volatile uint32_t ulLineNumber = ulLine;
( void ) pcFileName;
( void ) ulLineNumber;
printf( "vAssertCalled( %s, %u\n", pcFile, ulLine );
/* Setting ulBlockVariable to a non-zero value in the debugger will allow
this function to be exited. */
taskDISABLE_INTERRUPTS();
{
while( ulBlockVariable == 0UL )
{
__debugbreak();
}
}
taskENABLE_INTERRUPTS();
}
/*-----------------------------------------------------------*/
/* Called by FreeRTOS+TCP when the network connects or disconnects. Disconnect
events are only received if implemented in the MAC driver. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
@ -199,6 +175,30 @@ static BaseType_t xTasksAlreadyCreated = pdFALSE;
}
/*-----------------------------------------------------------*/
void vAssertCalled( const char *pcFile, uint32_t ulLine )
{
volatile uint32_t ulBlockVariable = 0UL;
volatile char *pcFileName = ( volatile char * ) pcFile;
volatile uint32_t ulLineNumber = ulLine;
( void ) pcFileName;
( void ) ulLineNumber;
printf( "vAssertCalled( %s, %u\n", pcFile, ulLine );
/* Setting ulBlockVariable to a non-zero value in the debugger will allow
this function to be exited. */
taskDISABLE_INTERRUPTS();
{
while( ulBlockVariable == 0UL )
{
__debugbreak();
}
}
taskENABLE_INTERRUPTS();
}
/*-----------------------------------------------------------*/
UBaseType_t uxRand( void )
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
@ -230,7 +230,13 @@ uint32_t ulLoggingIPAddress;
ulLoggingIPAddress = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0, configECHO_SERVER_ADDR1, configECHO_SERVER_ADDR2, configECHO_SERVER_ADDR3 );
vLoggingInit( xLogToStdout, xLogToFile, xLogToUDP, ulLoggingIPAddress, configPRINT_PORT );
/* Seed the random number generator. */
/*
* Seed random number generator.
*
* !!!NOTE!!!
* This is not a secure method of generating a random number. Production
* devices should use a True Random Number Generator (TRNG).
*/
time( &xTimeNow );
FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );
prvSRand( ( uint32_t ) xTimeNow );

View File

@ -24,9 +24,6 @@
#ifndef IOT_CONFIG_H_
#define IOT_CONFIG_H_
/* 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.

View File

@ -28,6 +28,12 @@
#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
/* SDK version. */
#define IOT_SDK_VERSION "4.0.0"

View File

@ -0,0 +1,4 @@
+ platform
Contains FreeRTOS specific implementations of abstractions used within the IoT
libraries.

View File

@ -219,7 +219,7 @@ static void _networkReceiveTask( void * pArgument )
IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
void * pCredentialInfo,
void ** pConnection )
void ** pConnection ) //_RB_ Why all void* and why a void**?
{
IOT_FUNCTION_ENTRY( IotNetworkError_t, IOT_NETWORK_SUCCESS );
Socket_t tcpSocket = FREERTOS_INVALID_SOCKET;
@ -228,7 +228,8 @@ IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
const TickType_t receiveTimeout = pdMS_TO_TICKS( IOT_NETWORK_SOCKET_POLL_MS );
_networkConnection_t * pNewNetworkConnection = NULL;
/* TLS is not supported yet and therefore pCredentialInfo must be NULL. */
/* TLS is not enabled in this version and therefore pCredentialInfo
must be NULL. */
configASSERT( pCredentialInfo == NULL );
/* Cast function parameters to correct types. */
@ -279,7 +280,7 @@ IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
IotLogError( "Failed to resolve %s.", pServerInfo->pHostName );
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );
}
//_RB_ Connects without setting a read block time.
socketStatus = FreeRTOS_connect( tcpSocket,
&serverAddress,
sizeof( serverAddress ) );

View File

@ -0,0 +1,3 @@
+ standard
Contains the implementation of IoT libraries that implement standard protocols
and interfaces, such a MQTT.

View File

@ -665,8 +665,8 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
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;
/* 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 taskName[ 10 ];
@ -682,11 +682,11 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
/* Create the timer for a new connection. */
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. */
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
@ -699,17 +699,17 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
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. */
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. */
&( workerTaskTCBs[ threadsCreated ] ) ); /* Pointer to static storage for te task's TCB. */
/* Upon successful thread creation, increase the number of active threads. */
/* Upon successful thread creation, increase the number of active threads. */
pTaskPool->activeThreads++;
++threadsCreated;
}
pTaskPool->running = true;
pTaskPool->running = true;
TASKPOOL_FUNCTION_CLEANUP();

View File

@ -0,0 +1,7 @@
+ mqtt
Contains the implementation of the MQTT library.
+ common
Contains the implementation of utility functions used by other IoT libraries.
Further libraries will be rolled out soon.

View File

@ -853,7 +853,7 @@ IotMqttError_t IotMqtt_Init( void )
#endif /* if IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES == 1 */
/* Log initialization status. */
if( status != IOT_MQTT_SUCCESS )
if( status != IOT_MQTT_SUCCESS ) //_RB_ This will generate compiler warnings if IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES != 0
{
IotLogError( "Failed to initialize MQTT library serializer. " );
}
@ -896,7 +896,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
_mqttConnection_t * pNewMqttConnection = NULL;
/* Default CONNECT serializer function. */
IotMqttError_t ( * serializeConnect )( const IotMqttConnectInfo_t *,
IotMqttError_t ( * serializeConnect )( const IotMqttConnectInfo_t *, //_RB_ Needs to be a typedef to make it easier to rease and more maintainable should the prototype change.
uint8_t **,
size_t * ) = _IotMqtt_SerializeConnect;
@ -911,7 +911,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
}
/* Validate network interface and connect info. */
if( _IotMqtt_ValidateConnect( pConnectInfo ) == false )
if( _IotMqtt_ValidateConnect( pConnectInfo ) == false ) //_RB_ A lot of code in here that could be replaced by asserts().
{
IOT_SET_AND_GOTO_CLEANUP( IOT_MQTT_BAD_PARAMETER );
}
@ -1002,7 +1002,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
IotLogInfo( "Establishing new MQTT connection." );
/* Initialize a new MQTT connection object. */
/* Initialize a new MQTT connection object. *///_RB_ Initialise, as per the comment, or create, as per the function name? I don't think this does create a connection as that happens below.
pNewMqttConnection = _createMqttConnection( pConnectInfo->awsIotMqttMode,
pNetworkInfo,
pConnectInfo->keepAliveSeconds );
@ -1127,7 +1127,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
IotMqtt_Assert( pOperation->u.operation.packetSize > 0 );
/* Add the CONNECT operation to the send queue for network transmission. */
status = _IotMqtt_ScheduleOperation( pOperation,
status = _IotMqtt_ScheduleOperation( pOperation, // Why schedule a job if going to wait for comletion?
_IotMqtt_ProcessSend,
0 );

View File

@ -0,0 +1,8 @@
Base directory for the FreeRTOS IoT Libraries.
+ abstractions
Contains FreeRTOS specific implementations of abstractions used within the IoT
libraries.
+ c_sdk
Contains the implementations of the IoT libraries - more will be rolled out soon.

View File

@ -639,7 +639,7 @@ int32_t lMutexNeedsReleasing, lWaitForYield = pdFALSE;
configASSERT( xPortRunning );
SetEvent( pvInterruptEvent );
if( ( ulPendingInterrupts & ( 1 << portINTERRUPT_YIELD ) ) != 0 )
if( ulPendingInterrupts != 0 )
{
/* Going to wait for an event - make sure the event is not already
signaled. */

View File

@ -330,58 +330,6 @@ void vPortInitialiseBlocks( void )
}
/*-----------------------------------------------------------*/
void vPortGetHeapStats( HeapStats_t *pxHeapStats )
{
BlockLink_t *pxBlock;
size_t xBlocks = 0, xMaxSize = 0, xMinSize = 0;
vTaskSuspendAll();
{
pxBlock = xStart.pxNextFreeBlock;
/* pxBlock will be NULL if the heap has not been initialised. The heap
is initialised automatically when the first allocation is made. */
if( pxBlock != NULL )
{
do
{
/* Increment the number of blocks and record the largest block seen
so far. */
xBlocks++;
if( pxBlock->xBlockSize > xMaxSize )
{
xMaxSize = pxBlock->xBlockSize;
}
if( pxBlock->xBlockSize < xMinSize )
{
xMinSize = pxBlock->xBlockSize;
}
/* Move to the next block in the chain until the last block is
reached. */
pxBlock = pxBlock->pxNextFreeBlock;
} while( pxBlock != pxEnd );
}
}
xTaskResumeAll();
pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;
pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;
pxHeapStats->xNumberOfFreeBlocks = xBlocks;
taskENTER_CRITICAL();
{
pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;
pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;
pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;
pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;
}
taskEXIT_CRITICAL();
}
/*-----------------------------------------------------------*/
static void prvHeapInit( void )
{
BlockLink_t *pxFirstFreeBlock;
@ -489,4 +437,56 @@ uint8_t *puc;
mtCOVERAGE_TEST_MARKER();
}
}
/*-----------------------------------------------------------*/
void vPortGetHeapStats( HeapStats_t *pxHeapStats )
{
BlockLink_t *pxBlock;
size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */
vTaskSuspendAll();
{
pxBlock = xStart.pxNextFreeBlock;
/* pxBlock will be NULL if the heap has not been initialised. The heap
is initialised automatically when the first allocation is made. */
if( pxBlock != NULL )
{
do
{
/* Increment the number of blocks and record the largest block seen
so far. */
xBlocks++;
if( pxBlock->xBlockSize > xMaxSize )
{
xMaxSize = pxBlock->xBlockSize;
}
if( pxBlock->xBlockSize < xMinSize )
{
xMinSize = pxBlock->xBlockSize;
}
/* Move to the next block in the chain until the last block is
reached. */
pxBlock = pxBlock->pxNextFreeBlock;
} while( pxBlock != pxEnd );
}
}
xTaskResumeAll();
pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;
pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;
pxHeapStats->xNumberOfFreeBlocks = xBlocks;
taskENTER_CRITICAL();
{
pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;
pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;
pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;
pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;
}
taskEXIT_CRITICAL();
}

View File

@ -490,8 +490,8 @@ const HeapRegion_t *pxHeapRegion;
void vPortGetHeapStats( HeapStats_t *pxHeapStats )
{
BlockLink_t *pxBlock;
size_t xBlocks = 0, xMaxSize = 0, xMinSize = 0;
BlockLink_t *pxBlock;
size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */
vTaskSuspendAll();
{
@ -512,9 +512,15 @@ void vPortGetHeapStats( HeapStats_t *pxHeapStats )
xMaxSize = pxBlock->xBlockSize;
}
if( pxBlock->xBlockSize < xMinSize )
/* Heap five will have a zero sized block at the end of each
each region - the block is only used to link to the next
heap region so it not a real block. */
if( pxBlock->xBlockSize != 0 )
{
xMinSize = pxBlock->xBlockSize;
if( pxBlock->xBlockSize < xMinSize )
{
xMinSize = pxBlock->xBlockSize;
}
}
/* Move to the next block in the chain until the last block is

View File

@ -5077,10 +5077,12 @@ TickType_t uxReturn;
/*-----------------------------------------------------------*/
#if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
TickType_t xTaskGetIdleRunTimeCounter( void )
{
return xIdleTaskHandle->ulRunTimeCounter;
}
#endif
/*-----------------------------------------------------------*/