/**\r
* @brief The callback invoked by the MQTT library when the MQTT connection gets\r
* disconnected.\r
- * \r
+ *\r
* @param[in] pvCallbackContext Callback context as provided at the time of\r
* connect.\r
* @param[in] pxCallbackParams Contains the reason why the MQTT connection was\r
* disconnected.\r
*/\r
-static void prvExample_DisconnectCallback( void * pvCallbackContext,\r
- IotMqttCallbackParam_t * pxCallbackParams );\r
+static void prvExample_OnDisconnect( void * pvCallbackContext,\r
+ IotMqttCallbackParam_t * pxCallbackParams );\r
\r
/**\r
* @brief The callback invoked by the MQTT library when a message is received on\r
* a subscribed topic from the MQTT broker.\r
- * \r
+ *\r
* @param[in] pvCallbackContext Callback context as provided at the time of\r
* subscribe.\r
- * @param[in] pxCallbackParams Contain the details about the received message - \r
+ * @param[in] pxCallbackParams Contain the details about the received message -\r
* topic on which the message was received, the received message.\r
*/\r
-static void prvExample_PublishCallback( void * pvCallbackContext,\r
- IotMqttCallbackParam_t * pxCallbackParams );\r
+static void prvExample_OnMessageReceived( void * pvCallbackContext,\r
+ IotMqttCallbackParam_t * pxCallbackParams );\r
\r
/**\r
* @brief Connects to the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT\r
* and mqttexampleMQTT_BROKER_PORT.\r
- * \r
+ *\r
* @note This example does not use TLS and therefore will not work with MQTT.\r
*/\r
static void prvMQTTConnect( void );\r
static void prvMQTTDisconnect( void );\r
/*-----------------------------------------------------------*/\r
\r
-static void prvExample_DisconnectCallback( void * pvCallbackContext,\r
+static void prvExample_OnDisconnect( void * pvCallbackContext,\r
IotMqttCallbackParam_t * pxCallbackParams )\r
{\r
TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void prvExample_PublishCallback( void * pvCallbackContext,\r
+static void prvExample_OnMessageReceived( void * pvCallbackContext,\r
IotMqttCallbackParam_t * pxCallbackParams )\r
{\r
TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;\r
/* Ensure that the message QoS is as expected. */\r
configASSERT( pxCallbackParams->u.message.info.qos == IOT_MQTT_QOS_1 );\r
\r
+ /* Although this print uses the constants rather than the data from the\r
+ message payload the asserts above have already checked the message payload\r
+ equals the constants, and it is more efficient not to have to worry about\r
+ lengths in the print. */\r
+ configPRINTF( ( "Received %s from topic %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) );\r
+\r
/* Inform the demo task about the message received from the MQTT broker. */\r
xTaskNotify( xDemoTaskHandle,\r
mqttexampleMESSAGE_RECEIVED_BIT,\r
static void prvMQTTDemoTask( void *pvParameters )\r
{\r
IotMqttError_t xResult;\r
-uint32_t ulNotificationValue = 0;\r
+uint32_t ulNotificationValue = 0, ulIterations;\r
+const uint32_t ulMaxIterations = 5UL;\r
const TickType_t xNoDelay = ( TickType_t ) 0;\r
\r
/* Remove compiler warnings about unused parameters. */\r
/* Don't expect any notifications to be pending yet. */\r
configASSERT( ulTaskNotifyTake( pdTRUE, xNoDelay ) == 0 );\r
\r
+\r
+ /******************** CONNECT ****************************************/\r
+\r
/* Establish a connection to the MQTT broker. This example connects to\r
* the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT and\r
* mqttexampleMQTT_BROKER_PORT at the top of this file. Please change\r
* it to the MQTT broker you want to connect to. Note that this example\r
* does not use TLS and therefore will not work with AWS IoT. */\r
prvMQTTConnect();\r
+ configPRINTF( ( "Connected to %s\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) );\r
+\r
\r
- /* Subscribe to the topic as specified in mqttexampleTOPIC at the top\r
- * of this file. */\r
+ /******************* SUBSCRIBE ***************************************/\r
+\r
+ /* The client is now connected to the broker. Subscribe to the topic\r
+ as specified in mqttexampleTOPIC at the top of this file. This client\r
+ will then publish to the same topic it subscribed to, so will expect\r
+ all the messages it sends to the broker to be sent back to it from the\r
+ broker. */\r
prvMQTTSubscribe();\r
+ configPRINTF( ( "Subscribed to %s\r\n", mqttexampleTOPIC ) );\r
\r
- /* Publish a message on the mqttexampleTOPIC topic as specified at the\r
- * top of this file. */\r
- prvMQTTPublish();\r
\r
- /* Since we are subscribed on the same topic, we will get the same\r
- * message back from the MQTT broker. Wait for the message to be\r
- * received which is informed to us by the publish callback\r
- * (prvExample_PublishCallback) by setting the mqttexampleMESSAGE_RECEIVED_BIT\r
- * in this task's notification value. */\r
- xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
- 0UL, /* Don't clear any bits on exit. */\r
- &( ulNotificationValue ), /* Obtain the notification value. */\r
- pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
- configASSERT( ( ulNotificationValue & mqttexampleMESSAGE_RECEIVED_BIT ) == mqttexampleMESSAGE_RECEIVED_BIT );\r
+ /******************* PUBLISH 5 TIMES *********************************/\r
\r
- /* Unsubscribe from the topic mqttexampleTOPIC. */\r
- prvMQTTUnsubscribe();\r
+ /* Publish a few messages while connected. */\r
+ for( ulIterations = 0; ulIterations < ulMaxIterations; ulIterations++ )\r
+ {\r
+ /* Publish a message on the mqttexampleTOPIC topic as specified at the\r
+ * top of this file. */\r
+ prvMQTTPublish();\r
+ configPRINTF( ( "Published %s to %s\r\n", mqttexampleMESSAGE, mqttexampleTOPIC ) );\r
+\r
+ /* Since we are subscribed on the same topic, we will get the same\r
+ * message back from the MQTT broker. Wait for the message to be\r
+ * received which is informed to us by the publish callback\r
+ * (prvExample_OnMessageReceived) by setting the\r
+ * mqttexampleMESSAGE_RECEIVED_BIT in this task's notification\r
+ value. */\r
+ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
+ mqttexampleMESSAGE_RECEIVED_BIT, /* Clear bit on exit. */\r
+ &( ulNotificationValue ), /* Obtain the notification value. */\r
+ pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
+ configASSERT( ( ulNotificationValue & mqttexampleMESSAGE_RECEIVED_BIT ) == mqttexampleMESSAGE_RECEIVED_BIT );\r
+ }\r
\r
- /* Gracefully disconnect from the MQTT broker by sending an MQTT\r
- * DISCONNECT message. */\r
+\r
+ /******************* UNSUBSCRIBE AND DISCONNECT **********************/\r
+\r
+ /* Unsubscribe from the topic mqttexampleTOPIC the disconnect\r
+ gracefully. */\r
+ prvMQTTUnsubscribe();\r
prvMQTTDisconnect();\r
+ configPRINTF( ( "Disconnected from from %s\r\n\r\n", mqttexampleMQTT_BROKER_ENDPOINT ) );\r
\r
/* Wait for the disconnect operation to complete which is informed to us\r
- * by the disconnect callback (prvExample_DisconnectCallback)by setting\r
+ * by the disconnect callback (prvExample_OnDisconnect)by setting\r
* the mqttexampleDISCONNECTED_BIT in this task's notification value.\r
* Note that all bits are cleared in the task's notification value to\r
* ensure that it is ready for the next run. */\r
xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
- portMAX_DELAY, /* Clear all bits on exit - portMAX_DELAY is used as it is a portable way of having all bits set. */\r
+ mqttexampleDISCONNECTED_BIT, /* Clear bit again on exit. */\r
&( ulNotificationValue ), /* Obtain the notification value. */\r
pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT );\r
\r
- printf( "prvMQTTDemoTask() completed an iteration without hitting an assert.\r\n" );\r
- fflush( stdout );\r
+\r
\r
/* Wait for some time between two iterations to ensure that we do not\r
* bombard the public test mosquitto broker. */\r
+ configPRINTF( ( "prvMQTTDemoTask() completed an iteration without hitting an assert. Total free heap is %u\r\n\r\n", xPortGetFreeHeapSize() ) );\r
vTaskDelay( pdMS_TO_TICKS( 5000 ) );\r
}\r
}\r
xNetworkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_FREERTOS;\r
\r
/* Setup the callback which is called when the MQTT connection is disconnected. */\r
- xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();\r
- xNetworkInfo.disconnectCallback.function = prvExample_DisconnectCallback;\r
+ xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();//_RB_ Why the task handle?\r
+ xNetworkInfo.disconnectCallback.function = prvExample_OnDisconnect;\r
\r
/****************** MQTT Connection information setup. ********************/\r
- /* This example does not use TLS and therefore won't work with AWS IoT. */\r
+ /* Set this flag to true if connecting to the AWS IoT MQTT broker. This\r
+ example does not use TLS and therefore won't work with AWS IoT. */\r
xConnectInfo.awsIotMqttMode = false;\r
\r
/* Start with a clean session i.e. direct the MQTT broker to discard any\r
* client gets disconnected. */\r
xConnectInfo.pWillInfo = NULL;\r
\r
- /* Send an MQTT PING request every minute. */\r
+ /* Send an MQTT PING request every minute to keep the connection open if\r
+ there is no other MQTT trafic. */\r
xConnectInfo.keepAliveSeconds = mqttexampleKEEP_ALIVE_SECONDS;\r
\r
/* The client identifier is used to uniquely identify this MQTT client to\r
- * the MQTT broker. */\r
+ * the MQTT broker. In a production device the identifier can be something\r
+ unique, such as a device serial number. */\r
xConnectInfo.pClientIdentifier = mqttexampleCLIENT_IDENTIFIER;\r
xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( mqttexampleCLIENT_IDENTIFIER );\r
\r
xConnectInfo.passwordLength = 0;\r
\r
/* Establish the connection to the MQTT broker - It is a blocking call and\r
- will return only when connection is complete. */\r
+ will return only when connection is complete or a timeout occurrs. */\r
xResult = IotMqtt_Connect( &( xNetworkInfo ),\r
&( xConnectInfo ),\r
mqttexampleMQTT_TIMEOUT_MS,\r
xMQTTSubscription.pTopicFilter = mqttexampleTOPIC;\r
xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );\r
xMQTTSubscription.callback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();\r
- xMQTTSubscription.callback.function = prvExample_PublishCallback;\r
+ xMQTTSubscription.callback.function = prvExample_OnMessageReceived;\r
\r
/* Use the synchronous API to subscribe - It is a blocking call and only\r
* returns when the subscribe operation is complete. */\r
used. */\r
#define configNETWORK_INTERFACE_TO_USE 3L\r
\r
-/* The address of an echo server that will be used by the two demo echo client\r
-tasks.\r
-http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Clients.html\r
-http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/UDP_Echo_Clients.html */\r
+/* The address of an echo server is only left in this project as it douples as\r
+the address to which logging is sent should UDP logging be enabled. */\r
#define configECHO_SERVER_ADDR0 192\r
#define configECHO_SERVER_ADDR1 168\r
#define configECHO_SERVER_ADDR2 0\r
configure the real network connection to use. */\r
#define configMAC_ADDR0 0x00\r
#define configMAC_ADDR1 0x11\r
-#define configMAC_ADDR2 0x22\r
-#define configMAC_ADDR3 0x33\r
-#define configMAC_ADDR4 0x44\r
+#define configMAC_ADDR2 0x11\r
+#define configMAC_ADDR3 0x11\r
+#define configMAC_ADDR4 0x11\r
#define configMAC_ADDR5 0x41\r
\r
/* Default IP address configuration. Used in ipconfigUSE_DNS is set to 0, or\r
#define strncasecmp _strnicmp\r
#define strcmpi _strcmpi\r
\r
+/* Prototype for the function used to print out. In this case it prints to the\r
+console before the network is connected then a UDP port after the network has\r
+connected. */\r
+extern void vLoggingPrintf( const char *pcFormatString, ... );\r
+#define configPRINTF( X ) vLoggingPrintf X\r
+\r
#endif /* FREERTOS_CONFIG_H */\r
\r
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to\r
1 then FreeRTOS_debug_printf should be defined to the function used to print\r
out the debugging messages. */\r
-#define ipconfigHAS_DEBUG_PRINTF 0\r
+#define ipconfigHAS_DEBUG_PRINTF 1\r
#if( ipconfigHAS_DEBUG_PRINTF == 1 )\r
#define FreeRTOS_debug_printf(X) vLoggingPrintf X\r
#endif\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement\BufferAllocation_2.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\NetworkInterface\WinPCap\NetworkInterface.c" />\r
<ClCompile Include="DemoTasks\SimpleMQTTExamples.c" />\r
- <ClCompile Include="DemoTasks\SimpleUDPClientAndServer.c" />\r
<ClCompile Include="demo_logging.c" />\r
<ClCompile Include="main.c">\r
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\tasks.c">\r
<Filter>FreeRTOS\Source</Filter>\r
</ClCompile>\r
- <ClCompile Include="DemoTasks\SimpleUDPClientAndServer.c">\r
- <Filter>DemoTasks</Filter>\r
- </ClCompile>\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_UDP_IP.c">\r
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>\r
</ClCompile>\r
#ifndef IOT_CONFIG_H_\r
#define IOT_CONFIG_H_\r
\r
-/* Use platform types on FreeRTOS. */\r
-#include "FreeRTOS.h"\r
-#include "platform/iot_platform_types_freertos.h" //_RB_Makes common config file FreeRTOS specific\r
\r
/**\r
* @brief The number of recyclable jobs for the task pool to cache.\r
\r
/**\r
* @brief Enable/Disable asserts for the task pool library.\r
- * \r
+ *\r
* Set this to 1 to perform sanity checks when using the task pool library.\r
* Asserts are useful for debugging, but should be disabled in production code.\r
* If this is set to 1, IotTaskPool_Assert can be defined to set the assertion\r
* Default value (if undefined): IOT_LOG_LEVEL_GLOBAL; if that is undefined,\r
* then IOT_LOG_NONE.\r
*/\r
-#define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_INFO\r
+#define IOT_LOG_LEVEL_TASKPOOL IOT_LOG_WARN\r
\r
\r
/**\r
* @brief The stack size (in bytes) for each worker task in the task pool.\r
- * \r
+ *\r
* The minimal version of the of task pool library only supports one task pool\r
* and the configuration of each worker task fixed at the compile time.\r
*/\r
*/\r
#define AWS_IOT_MQTT_ENABLE_METRICS 0\r
\r
+/*\r
+ * @brief Set the log level of the task pool library.\r
+ *\r
+ * Log messages from the task pool library at or below this setting will be\r
+ * printed.\r
+ *\r
+ * Possible values: One of the Log levels.\r
+ * Default value (if undefined): IOT_LOG_LEVEL_GLOBAL; if that is undefined,\r
+ * then IOT_LOG_NONE.\r
+ */\r
+#define IOT_LOG_LEVEL_MQTT IOT_LOG_WARN\r
+\r
/* Include the common configuration file for FreeRTOS. */\r
#include "iot_config_common.h"\r
\r
/* Use platform types on FreeRTOS. */\r
#include "platform/iot_platform_types_freertos.h" //_RB_Makes common config file FreeRTOS specific\r
\r
-/* Used to get the cloud broker endpoint for FreeRTOS. */\r
-//_RB_#include "aws_clientcredential.h"\r
-\r
/* SDK version. */\r
#define IOT_SDK_VERSION "4.0.0"\r
\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vAssertCalled( const char *pcFile, uint32_t ulLine )\r
-{\r
-volatile uint32_t ulBlockVariable = 0UL;\r
-volatile char *pcFileName = ( volatile char * ) pcFile;\r
-volatile uint32_t ulLineNumber = ulLine;\r
-\r
- ( void ) pcFileName;\r
- ( void ) ulLineNumber;\r
-\r
- printf( "vAssertCalled( %s, %u\n", pcFile, ulLine );\r
-\r
- /* Setting ulBlockVariable to a non-zero value in the debugger will allow\r
- this function to be exited. */\r
- taskDISABLE_INTERRUPTS();\r
- {\r
- while( ulBlockVariable == 0UL )\r
- {\r
- __debugbreak();\r
- }\r
- }\r
- taskENABLE_INTERRUPTS();\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
/* Called by FreeRTOS+TCP when the network connects or disconnects. Disconnect\r
events are only received if implemented in the MAC driver. */\r
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )\r
}\r
/*-----------------------------------------------------------*/\r
\r
+void vAssertCalled( const char *pcFile, uint32_t ulLine )\r
+{\r
+ volatile uint32_t ulBlockVariable = 0UL;\r
+ volatile char *pcFileName = ( volatile char * ) pcFile;\r
+ volatile uint32_t ulLineNumber = ulLine;\r
+\r
+ ( void ) pcFileName;\r
+ ( void ) ulLineNumber;\r
+\r
+ printf( "vAssertCalled( %s, %u\n", pcFile, ulLine );\r
+\r
+ /* Setting ulBlockVariable to a non-zero value in the debugger will allow\r
+ this function to be exited. */\r
+ taskDISABLE_INTERRUPTS();\r
+ {\r
+ while( ulBlockVariable == 0UL )\r
+ {\r
+ __debugbreak();\r
+ }\r
+ }\r
+ taskENABLE_INTERRUPTS();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
UBaseType_t uxRand( void )\r
{\r
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;\r
ulLoggingIPAddress = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0, configECHO_SERVER_ADDR1, configECHO_SERVER_ADDR2, configECHO_SERVER_ADDR3 );\r
vLoggingInit( xLogToStdout, xLogToFile, xLogToUDP, ulLoggingIPAddress, configPRINT_PORT );\r
\r
- /* Seed the random number generator. */\r
+ /*\r
+ * Seed random number generator.\r
+ *\r
+ * !!!NOTE!!!\r
+ * This is not a secure method of generating a random number. Production\r
+ * devices should use a True Random Number Generator (TRNG).\r
+ */\r
time( &xTimeNow );\r
FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );\r
prvSRand( ( uint32_t ) xTimeNow );\r
#ifndef IOT_CONFIG_H_\r
#define IOT_CONFIG_H_\r
\r
-/* Use platform types on FreeRTOS. */\r
-#include "FreeRTOS.h"\r
-#include "platform/iot_platform_types_freertos.h" //_RB_Makes common config file FreeRTOS specific\r
\r
/*\r
* Set this to the number of recyclable tasks for the task pool to cache.\r
#ifndef IOT_CONFIG_COMMON_H_\r
#define IOT_CONFIG_COMMON_H_\r
\r
+/* FreeRTOS include. */\r
+#include "FreeRTOS.h" //_RB_Makes common config file FreeRTOS specific\r
+\r
+/* Use platform types on FreeRTOS. */\r
+#include "platform/iot_platform_types_freertos.h" //_RB_Makes common config file FreeRTOS specific\r
+\r
/* SDK version. */\r
#define IOT_SDK_VERSION "4.0.0"\r
\r
--- /dev/null
++ platform\r
+Contains FreeRTOS specific implementations of abstractions used within the IoT\r
+libraries.\r
+\r
\r
IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,\r
void * pCredentialInfo,\r
- void ** pConnection )\r
+ void ** pConnection ) //_RB_ Why all void* and why a void**?\r
{\r
IOT_FUNCTION_ENTRY( IotNetworkError_t, IOT_NETWORK_SUCCESS );\r
Socket_t tcpSocket = FREERTOS_INVALID_SOCKET;\r
const TickType_t receiveTimeout = pdMS_TO_TICKS( IOT_NETWORK_SOCKET_POLL_MS );\r
_networkConnection_t * pNewNetworkConnection = NULL;\r
\r
- /* TLS is not supported yet and therefore pCredentialInfo must be NULL. */\r
+ /* TLS is not enabled in this version and therefore pCredentialInfo\r
+ must be NULL. */\r
configASSERT( pCredentialInfo == NULL );\r
\r
/* Cast function parameters to correct types. */\r
IotLogError( "Failed to resolve %s.", pServerInfo->pHostName );\r
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
}\r
-\r
+ //_RB_ Connects without setting a read block time.\r
socketStatus = FreeRTOS_connect( tcpSocket,\r
&serverAddress,\r
sizeof( serverAddress ) );\r
--- /dev/null
++ standard\r
+Contains the implementation of IoT libraries that implement standard protocols\r
+and interfaces, such a MQTT.\r
static StaticTask_t workerTaskTCBs[ IOT_TASKPOOL_NUMBER_OF_WORKERS ];\r
static StackType_t workerTaskStacks[ IOT_TASKPOOL_NUMBER_OF_WORKERS ][ IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ) ];\r
\r
- /* Static structure to hold te software timer. */\r
- static StaticTimer_t staticTimer;\r
+ /* Static structure to hold te software timer. */\r
+ static StaticTimer_t staticTimer;\r
\r
uint32_t threadsCreated = 0; /* Although initialised before use removing the initialiser here results in compiler warnings. */\r
char taskName[ 10 ];\r
\r
/* Create the timer for a new connection. */\r
pTaskPool->timer = xTimerCreateStatic( NULL, /* Text name for the timer, only used for debugging. */\r
- portMAX_DELAY, /* Timer period in ticks. */\r
- pdFALSE, /* pdFALSE means its a one-shot timer. */\r
- ( void * ) pTaskPool, /* Parameter passed into callback. */\r
- _timerCallback, /* Callback that executes when the timer expires. */\r
- &staticTimer ); /* Static storage for the timer's data structure. */\r
+ portMAX_DELAY, /* Timer period in ticks. */\r
+ pdFALSE, /* pdFALSE means its a one-shot timer. */\r
+ ( void * ) pTaskPool, /* Parameter passed into callback. */\r
+ _timerCallback, /* Callback that executes when the timer expires. */\r
+ &staticTimer ); /* Static storage for the timer's data structure. */\r
\r
/* The task pool will initialize the minimum number of threads requested by the user upon start.\r
Note this tailored version of the task pool does not autoscale, but fixes the number of tasks\r
\r
xTaskCreateStatic( _taskPoolWorker, /* Function that implements the task. */\r
taskName, /* Text name for the task, used for debugging only. */\r
- IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ), /* xTaskCreate() expects the stack size to be specified in words. */\r
+ IOT_TASKPOOL_WORKER_STACK_SIZE_BYTES / sizeof( portSTACK_TYPE ), /* xTaskCreate() expects the stack size to be specified in words. */\r
pTaskPool, /* Parameter passed into the task. */\r
pInfo->priority, /* Priority at which the task starts running. */\r
&( workerTaskStacks[ threadsCreated ][ 0 ] ), /* Pointer to static storage for the task's stack. */\r
- &( workerTaskTCBs[ threadsCreated ] ) ); /* Pointer to static storage for te task's TCB. */\r
+ &( workerTaskTCBs[ threadsCreated ] ) ); /* Pointer to static storage for te task's TCB. */\r
\r
- /* Upon successful thread creation, increase the number of active threads. */\r
+ /* Upon successful thread creation, increase the number of active threads. */\r
pTaskPool->activeThreads++;\r
++threadsCreated;\r
}\r
- pTaskPool->running = true;\r
+ pTaskPool->running = true;\r
\r
TASKPOOL_FUNCTION_CLEANUP();\r
\r
--- /dev/null
++ mqtt\r
+Contains the implementation of the MQTT library.\r
+\r
++ common\r
+Contains the implementation of utility functions used by other IoT libraries.\r
+\r
+Further libraries will be rolled out soon.\r
#endif /* if IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES == 1 */\r
\r
/* Log initialization status. */\r
- if( status != IOT_MQTT_SUCCESS )\r
+ if( status != IOT_MQTT_SUCCESS ) //_RB_ This will generate compiler warnings if IOT_MQTT_ENABLE_SERIALIZER_OVERRIDES != 0\r
{\r
IotLogError( "Failed to initialize MQTT library serializer. " );\r
}\r
_mqttConnection_t * pNewMqttConnection = NULL;\r
\r
/* Default CONNECT serializer function. */\r
- IotMqttError_t ( * serializeConnect )( const IotMqttConnectInfo_t *,\r
+ 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.\r
uint8_t **,\r
size_t * ) = _IotMqtt_SerializeConnect;\r
\r
}\r
\r
/* Validate network interface and connect info. */\r
- if( _IotMqtt_ValidateConnect( pConnectInfo ) == false )\r
+ if( _IotMqtt_ValidateConnect( pConnectInfo ) == false ) //_RB_ A lot of code in here that could be replaced by asserts().\r
{\r
IOT_SET_AND_GOTO_CLEANUP( IOT_MQTT_BAD_PARAMETER );\r
}\r
\r
IotLogInfo( "Establishing new MQTT connection." );\r
\r
- /* Initialize a new MQTT connection object. */\r
+ /* 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.\r
pNewMqttConnection = _createMqttConnection( pConnectInfo->awsIotMqttMode,\r
pNetworkInfo,\r
pConnectInfo->keepAliveSeconds );\r
IotMqtt_Assert( pOperation->u.operation.packetSize > 0 );\r
\r
/* Add the CONNECT operation to the send queue for network transmission. */\r
- status = _IotMqtt_ScheduleOperation( pOperation,\r
+ status = _IotMqtt_ScheduleOperation( pOperation, // Why schedule a job if going to wait for comletion?\r
_IotMqtt_ProcessSend,\r
0 );\r
\r
--- /dev/null
+Base directory for the FreeRTOS IoT Libraries.\r
+\r
++ abstractions\r
+Contains FreeRTOS specific implementations of abstractions used within the IoT\r
+libraries.\r
+\r
++ c_sdk\r
+Contains the implementations of the IoT libraries - more will be rolled out soon.\r
configASSERT( xPortRunning );\r
SetEvent( pvInterruptEvent );\r
\r
- if( ( ulPendingInterrupts & ( 1 << portINTERRUPT_YIELD ) ) != 0 )\r
+ if( ulPendingInterrupts != 0 )\r
{\r
/* Going to wait for an event - make sure the event is not already\r
signaled. */\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vPortGetHeapStats( HeapStats_t *pxHeapStats )\r
-{\r
-BlockLink_t *pxBlock;\r
-size_t xBlocks = 0, xMaxSize = 0, xMinSize = 0;\r
-\r
- vTaskSuspendAll();\r
- {\r
- pxBlock = xStart.pxNextFreeBlock;\r
-\r
- /* pxBlock will be NULL if the heap has not been initialised. The heap\r
- is initialised automatically when the first allocation is made. */\r
- if( pxBlock != NULL )\r
- {\r
- do\r
- {\r
- /* Increment the number of blocks and record the largest block seen\r
- so far. */\r
- xBlocks++;\r
-\r
- if( pxBlock->xBlockSize > xMaxSize )\r
- {\r
- xMaxSize = pxBlock->xBlockSize;\r
- }\r
-\r
- if( pxBlock->xBlockSize < xMinSize )\r
- {\r
- xMinSize = pxBlock->xBlockSize;\r
- }\r
-\r
- /* Move to the next block in the chain until the last block is\r
- reached. */\r
- pxBlock = pxBlock->pxNextFreeBlock;\r
- } while( pxBlock != pxEnd );\r
- }\r
- }\r
- xTaskResumeAll();\r
-\r
- pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;\r
- pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;\r
- pxHeapStats->xNumberOfFreeBlocks = xBlocks;\r
-\r
- taskENTER_CRITICAL();\r
- {\r
- pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;\r
- pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;\r
- pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;\r
- pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;\r
- }\r
- taskEXIT_CRITICAL();\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
static void prvHeapInit( void )\r
{\r
BlockLink_t *pxFirstFreeBlock;\r
mtCOVERAGE_TEST_MARKER();\r
}\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortGetHeapStats( HeapStats_t *pxHeapStats )\r
+{\r
+BlockLink_t *pxBlock;\r
+size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */\r
+\r
+ vTaskSuspendAll();\r
+ {\r
+ pxBlock = xStart.pxNextFreeBlock;\r
+\r
+ /* pxBlock will be NULL if the heap has not been initialised. The heap\r
+ is initialised automatically when the first allocation is made. */\r
+ if( pxBlock != NULL )\r
+ {\r
+ do\r
+ {\r
+ /* Increment the number of blocks and record the largest block seen\r
+ so far. */\r
+ xBlocks++;\r
+\r
+ if( pxBlock->xBlockSize > xMaxSize )\r
+ {\r
+ xMaxSize = pxBlock->xBlockSize;\r
+ }\r
+\r
+ if( pxBlock->xBlockSize < xMinSize )\r
+ {\r
+ xMinSize = pxBlock->xBlockSize;\r
+ }\r
+\r
+ /* Move to the next block in the chain until the last block is\r
+ reached. */\r
+ pxBlock = pxBlock->pxNextFreeBlock;\r
+ } while( pxBlock != pxEnd );\r
+ }\r
+ }\r
+ xTaskResumeAll();\r
+\r
+ pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;\r
+ pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;\r
+ pxHeapStats->xNumberOfFreeBlocks = xBlocks;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;\r
+ pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;\r
+ pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;\r
+ pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+}\r
\r
\r
void vPortGetHeapStats( HeapStats_t *pxHeapStats )\r
{\r
- BlockLink_t *pxBlock;\r
- size_t xBlocks = 0, xMaxSize = 0, xMinSize = 0;\r
+BlockLink_t *pxBlock;\r
+size_t xBlocks = 0, xMaxSize = 0, xMinSize = portMAX_DELAY; /* portMAX_DELAY used as a portable way of getting the maximum value. */\r
\r
vTaskSuspendAll();\r
{\r
xMaxSize = pxBlock->xBlockSize;\r
}\r
\r
- if( pxBlock->xBlockSize < xMinSize )\r
+ /* Heap five will have a zero sized block at the end of each\r
+ each region - the block is only used to link to the next\r
+ heap region so it not a real block. */\r
+ if( pxBlock->xBlockSize != 0 )\r
{\r
- xMinSize = pxBlock->xBlockSize;\r
+ if( pxBlock->xBlockSize < xMinSize )\r
+ {\r
+ xMinSize = pxBlock->xBlockSize;\r
+ }\r
}\r
\r
/* Move to the next block in the chain until the last block is\r
/*-----------------------------------------------------------*/\r
\r
#if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )\r
+\r
TickType_t xTaskGetIdleRunTimeCounter( void )\r
{\r
return xIdleTaskHandle->ulRunTimeCounter;\r
}\r
+\r
#endif\r
/*-----------------------------------------------------------*/\r
\r