]> git.sur5r.net Git - freertos/commitdiff
Continued to work on the MQTT demo project.
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 24 Jul 2019 00:27:14 +0000 (00:27 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 24 Jul 2019 00:27:14 +0000 (00:27 +0000)
A few review comments added into the MQTT implementation.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2704 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

21 files changed:
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/DemoTasks/SimpleMQTTExamples.c
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/FreeRTOSConfig.h
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/FreeRTOSIPConfig.h
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/WIN32.vcxproj.filters
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/iot_config.h
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/iot_config_common.h
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/mqtt/main.c
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config.h
FreeRTOS-Plus/Demo/FreeRTOS_IoT_Libraries/task_pool/iot_config_common.h
FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/abstractions/directories.txt [new file with mode: 0644]
FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/abstractions/platform/freertos/iot_network_freertos.c
FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/directories.txt [new file with mode: 0644]
FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/common/taskpool/iot_taskpool.c
FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/directories.txt [new file with mode: 0644]
FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/mqtt/src/iot_mqtt_api.c
FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/directories.txt [new file with mode: 0644]
FreeRTOS/Source/portable/MSVC-MingW/port.c
FreeRTOS/Source/portable/MemMang/heap_4.c
FreeRTOS/Source/portable/MemMang/heap_5.c
FreeRTOS/Source/tasks.c

index bae6e0824f6f65295b5481a9f17f394f877aa39e..1ef921cd22152e7a8ccbd67d09f86dc63a441d83 100644 (file)
@@ -140,31 +140,31 @@ static void prvMQTTDemoTask( void *pvParameters );
 /**\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
@@ -191,7 +191,7 @@ static void prvMQTTUnsubscribe( void );
 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
@@ -207,7 +207,7 @@ TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;
 }\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
@@ -227,6 +227,12 @@ TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;
        /* 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
@@ -252,7 +258,8 @@ void vStartSimpleMQTTDemo( void )
 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
@@ -272,55 +279,77 @@ const TickType_t xNoDelay = ( TickType_t ) 0;
                /* 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
@@ -351,11 +380,12 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
        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
@@ -373,11 +403,13 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
         * 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
@@ -389,7 +421,7 @@ IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;
        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
@@ -408,7 +440,7 @@ IotMqttSubscription_t xMQTTSubscription;
        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
index 1ab0867f1d3880f6f57e90b31bde1970d561b3aa..f03164c14951fabb54230fa251377f106501a871 100644 (file)
@@ -138,10 +138,8 @@ configNETWORK_INTERFACE_TO_USE to 2 results in the wireless network being
 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
@@ -154,9 +152,9 @@ configNETWORK_INTERFACE_TO_USE definition above for information on how to
 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
@@ -202,5 +200,11 @@ ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
 #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
index 4729ef107ba4eb2afc1148ae096428889181546a..dba43cdba353e9e06f3d0f7402e35f1f55a97895 100644 (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\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
index f2157c81345c68f74a13acf94ca44399cb08197b..0f5843a36e1c23d2450f80e1e46fd93aa4a66367 100644 (file)
     <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
index 23bf06ef27f378c4e40b166830811ef4709fc4e7..4edf58197fefe0389223c7b1e76a1eb4611ce006 100644 (file)
     <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
index d267447793a2fb9ee068c2c1936f41c98bfd238b..f7485acde316d181918e2c25802d0c637a3c1dc5 100644 (file)
@@ -24,9 +24,6 @@
 #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
@@ -49,7 +46,7 @@
 \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
index 7867744234245ae675b4ae8ac110f6d9a54b1898..8d39bac4f47cb1658f4e5440630e0470ac245223 100644 (file)
@@ -34,9 +34,6 @@
 /* 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
index cbec6796e167c6cbe9087492b1a8c82f724cdc39..305e2153e3a56b76677eb1f207c013f24b23b0fe 100644 (file)
@@ -136,30 +136,6 @@ int main( void )
 }\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
@@ -199,6 +175,30 @@ static BaseType_t xTasksAlreadyCreated = pdFALSE;
 }\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
@@ -230,7 +230,13 @@ uint32_t ulLoggingIPAddress;
        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
index 0121f276dbb287f0a2cc2d0f0c629166ec23638f..68517887a1b3429f844baa2d3dd29d1fc5b3a39a 100644 (file)
@@ -24,9 +24,6 @@
 #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
index 8dd158db75c487a1f5bb5bdb5605d33e090885de..8b976103ecebc7e4fa096cbbccdb01fb2dbb02c8 100644 (file)
 #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
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/abstractions/directories.txt b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/abstractions/directories.txt
new file mode 100644 (file)
index 0000000..6eb48c1
--- /dev/null
@@ -0,0 +1,4 @@
++ platform\r
+Contains FreeRTOS specific implementations of abstractions used within the IoT\r
+libraries.\r
+\r
index 50d4c4a98987479a829092f1635342f10efd2141..dbe55dbbd3a50d2a9c51d471433827dc1479548a 100644 (file)
@@ -219,7 +219,7 @@ static void _networkReceiveTask( void * pArgument )
 \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
@@ -228,7 +228,8 @@ IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
     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
@@ -279,7 +280,7 @@ IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,
         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
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/directories.txt b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/directories.txt
new file mode 100644 (file)
index 0000000..a5f2fbf
--- /dev/null
@@ -0,0 +1,3 @@
++ standard\r
+Contains the implementation of IoT libraries that implement standard protocols\r
+and interfaces, such a MQTT.\r
index 0a51c3a57e64e75b210398c19af8a69250db2078..56849933776fe8780eac83b28c33184f7d713829 100644 (file)
@@ -665,8 +665,8 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
     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
@@ -682,11 +682,11 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
 \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
@@ -699,17 +699,17 @@ static IotTaskPoolError_t _createTaskPool( const IotTaskPoolInfo_t * const pInfo
 \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
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/directories.txt b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/c_sdk/standard/directories.txt
new file mode 100644 (file)
index 0000000..5492b09
--- /dev/null
@@ -0,0 +1,7 @@
++ 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
index 7df5326dcc6ab60acee35f704ba17771c934782a..23133f46b78776713c4a39d5f1088ae7e5038fc0 100644 (file)
@@ -853,7 +853,7 @@ IotMqttError_t IotMqtt_Init( void )
     #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
@@ -896,7 +896,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
     _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
@@ -911,7 +911,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
     }\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
@@ -1002,7 +1002,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
 \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
@@ -1127,7 +1127,7 @@ IotMqttError_t IotMqtt_Connect( const IotMqttNetworkInfo_t * pNetworkInfo,
     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
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/directories.txt b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries/directories.txt
new file mode 100644 (file)
index 0000000..b22d7e6
--- /dev/null
@@ -0,0 +1,8 @@
+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
index c2e2a82acdf4d24fcf9f00bb90fa1e5d82a790fe..2e67896d0e85c8f934f6d6fcd74700f4784a3913 100644 (file)
@@ -639,7 +639,7 @@ int32_t lMutexNeedsReleasing, lWaitForYield = pdFALSE;
                                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
index 927064634492a3945d6f0b643e4b00080edbccd3..b1d8fc894e67b587cd36e3e34477091b318e1918 100644 (file)
@@ -330,58 +330,6 @@ void vPortInitialiseBlocks( void )
 }\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
@@ -489,4 +437,56 @@ uint8_t *puc;
                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
index 614210edf3e5f0c01efedc17325aec740f0e9b2b..cf814d116afec2e5401fa030facc3f9bf0b8db21 100644 (file)
@@ -490,8 +490,8 @@ const HeapRegion_t *pxHeapRegion;
 \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
@@ -512,9 +512,15 @@ void vPortGetHeapStats( HeapStats_t *pxHeapStats )
                                        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
index f15d1ddf5fd55cf383767e8a9bb692aee0d8b9dd..6cecac0e260efad315aefea5ecef3ccef016a2c8 100644 (file)
@@ -5077,10 +5077,12 @@ TickType_t uxReturn;
 /*-----------------------------------------------------------*/\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