Relocate logging sources under FreeRTOS-Plus/Source/Logging (#354)

As suggested, because logging_stack.h and logging_levels.h are used not only by demos but also by platform-specific transport code, it would make sense to move FreeRTOS-Plus/Demos/Common/Logging to FreeRTOS-Plus/Source/Logging. The same is done for demo_logging.c and demo_logging.h, which are duplicated by several demos. Win32.vcxproj project files are also updated to follow suite.
pull/356/head
Oscar Michael Abrina 4 years ago committed by GitHub
parent 553d448865
commit 10842c9189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,7 +46,7 @@
#include "FreeRTOS_Sockets.h"
/* Demo logging includes. */
#include "demo_logging.h"
#include "logging.h"
/* Demo Specific configs. */
#include "demo_config.h"

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\Common\Logging;..\common\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\..\Source\Application-Protocols\platform\include;..\..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\..\Source\mbedtls_utils;..\..\..\..\ThirdParty\mbedtls\include;..\..\..\..\Source\AWS\device-shadow-for-aws-iot-embedded-sdk\source\include;..\..\..\..\Source\coreJSON\source\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\..\FreeRTOS-Plus\Source\Logging;..\common\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\..\Source\Application-Protocols\platform\include;..\..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\..\Source\mbedtls_utils;..\..\..\..\ThirdParty\mbedtls\include;..\..\..\..\Source\AWS\device-shadow-for-aws-iot-embedded-sdk\source\include;..\..\..\..\Source\coreJSON\source\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MBEDTLS_CONFIG_FILE="mbedtls_config.h";WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -487,7 +487,7 @@
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">TurnOffAllWarnings</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">TurnOffAllWarnings</WarningLevel>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\ShadowDemoMainExample.c" />
<ClCompile Include="DemoTasks\shadow_demo_helpers.c" />
@ -516,6 +516,9 @@
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h" />
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h" />
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h" />
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\mbedtls_error.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\threading_alt.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\platform\freertos\transport\include\freertos_sockets_wrapper.h" />

@ -139,7 +139,7 @@
<ClCompile Include="..\..\..\..\..\FreeRTOS\Source\stream_buffer.c">
<Filter>FreeRTOS\Source</Filter>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_serializer.c">
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\coreMQTT\src</Filter>
@ -165,85 +165,243 @@
<ClCompile Include="..\..\..\..\Source\Application-Protocols\platform\freertos\transport\src\freertos_sockets_wrapper.c">
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\platform\freertos\transport\src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\aes.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\aesni.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\arc4.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\aria.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\asn1parse.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\asn1write.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\base64.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\bignum.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\blowfish.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\camellia.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ccm.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\certs.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\chacha20.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\chachapoly.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\cipher.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\cipher_wrap.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\cmac.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ctr_drbg.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\debug.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\des.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\dhm.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecdh.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecdsa.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecjpake.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecp.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecp_curves.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\entropy.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\entropy_poll.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\error.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\gcm.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\havege.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\hkdf.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\hmac_drbg.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md2.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md4.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md5.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\memory_buffer_alloc.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\net_sockets.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\nist_kw.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\oid.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\padlock.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pem.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pk.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkcs11.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkcs12.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkcs5.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkparse.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkwrite.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pk_wrap.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\platform.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\platform_util.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\poly1305.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ripemd160.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\rsa.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\rsa_internal.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\sha1.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\sha256.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\sha512.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_cache.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_ciphersuites.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_cli.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_cookie.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_msg.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_srv.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_ticket.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_tls.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_tls13_keys.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\threading.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\timing.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\version.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\version_features.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509write_crt.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509write_csr.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_create.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_crl.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_crt.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_csr.c" />
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\aes.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\aesni.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\arc4.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\aria.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\asn1parse.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\asn1write.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\base64.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\bignum.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\blowfish.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\camellia.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ccm.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\certs.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\chacha20.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\chachapoly.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\cipher.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\cipher_wrap.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\cmac.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ctr_drbg.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\debug.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\des.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\dhm.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecdh.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecdsa.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecjpake.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecp.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ecp_curves.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\entropy.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\entropy_poll.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\error.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\gcm.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\havege.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\hkdf.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\hmac_drbg.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md2.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md4.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\md5.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\memory_buffer_alloc.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\net_sockets.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\nist_kw.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\oid.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\padlock.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pem.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pk.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkcs11.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkcs12.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkcs5.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkparse.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pkwrite.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\pk_wrap.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\platform.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\platform_util.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\poly1305.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ripemd160.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\rsa.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\rsa_internal.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\sha1.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\sha256.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\sha512.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_cache.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_ciphersuites.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_cli.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_cookie.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_msg.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_srv.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_ticket.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_tls.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\ssl_tls13_keys.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\threading.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\timing.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\version.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\version_features.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509write_crt.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509write_csr.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_create.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_crl.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_crt.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509_csr.c" >
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\xtea.c" />
<ClCompile Include="DemoTasks\shadow_demo_helpers.c">
<Filter>DemoTasks</Filter>

@ -116,7 +116,7 @@
<ProgramDataBaseFileName>.\Release/</ProgramDataBaseFileName>
<WarningLevel>Level3</WarningLevel>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalIncludeDirectories>..\Common\Utils;..\Common\ethernet\lwip-1.4.0\ports\win32\WinPCap;..\Common\ethernet\lwip-1.4.0\src\include\ipv4;..\Common\ethernet\lwip-1.4.0\src\include;..\..\Source\include;..\..\Source\portable\MSVC-MingW;..\Common\ethernet\lwip-1.4.0\ports\win32\include;..\Common\Include;.\lwIP_Apps;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\Common\Utils;..\Common\ethernet\lwip-1.4.0\ports\win32\WinPCap;..\Common\ethernet\lwip-1.4.0\src\include\ipv4;..\Common\ethernet\lwip-1.4.0\src\include;..\..\Source\include;..\..\Source\portable\MSVC-MingW;..\Common\ethernet\lwip-1.4.0\ports\win32\include;..\Common\Include;..\..\Source\Logging;.\lwIP_Apps;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@ -155,10 +155,10 @@
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_UDP_IP.c" />
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement\BufferAllocation_2.c" />
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\portable\NetworkInterface\WinPCap\NetworkInterface.c" />
<ClCompile Include="..\..\Source\Logging\logging.c" />
<ClCompile Include="DemoTasks\SimpleTCPEchoServer.c" />
<ClCompile Include="DemoTasks\TCPEchoClient_SingleTasks.c" />
<ClCompile Include="DemoTasks\SimpleUDPClientAndServer.c" />
<ClCompile Include="demo_logging.c" />
<ClCompile Include="main.c">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>

@ -96,7 +96,7 @@
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_Stream_Buffer.c">
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
</ClCompile>
<ClCompile Include="demo_logging.c" />
<ClCompile Include="..\..\Source\Logging\logging.c" />
<ClCompile Include="DemoTasks\SimpleTCPEchoServer.c">
<Filter>DemoTasks</Filter>
</ClCompile>

@ -1,526 +0,0 @@
/*
* FreeRTOS Kernel V10.4.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/*
* Logging utility that allows FreeRTOS tasks to log to a UDP port, stdout, and
* disk file without making any Win32 system calls themselves.
*
* Messages logged to a UDP port are sent directly (using FreeRTOS+TCP), but as
* FreeRTOS tasks cannot make Win32 system calls messages sent to stdout or a
* disk file are sent via a stream buffer to a Win32 thread which then performs
* the actual output.
*/
/* Standard includes. */
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <io.h>
#include <ctype.h>
/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_Stream_Buffer.h"
/* Demo includes. */
#include "demo_logging.h"
/*-----------------------------------------------------------*/
/* The maximum size to which the log file may grow, before being renamed
to .ful. */
#define dlLOGGING_FILE_SIZE ( 40ul * 1024ul * 1024ul )
/* Dimensions the arrays into which print messages are created. */
#define dlMAX_PRINT_STRING_LENGTH 255
/* The size of the stream buffer used to pass messages from FreeRTOS tasks to
the Win32 thread that is responsible for making any Win32 system calls that are
necessary for the selected logging method. */
#define dlLOGGING_STREAM_BUFFER_SIZE 32768
/* A block time of zero simply means don't block. */
#define dlDONT_BLOCK 0
/*-----------------------------------------------------------*/
/*
* Called from vLoggingInit() to start a new disk log file.
*/
static void prvFileLoggingInit( void );
/*
* Attempt to write a message to the file.
*/
static void prvLogToFile( const char *pcMessage, size_t xLength );
/*
* Simply close the logging file, if it is open.
*/
static void prvFileClose( void );
/*
* Before the scheduler is started this function is called directly. After the
* scheduler has started it is called from the Windows thread dedicated to
* outputting log messages. Only the windows thread actually performs the
* writing so as not to disrupt the simulation by making Windows system calls
* from FreeRTOS tasks.
*/
static void prvLoggingFlushBuffer( void );
/*
* The windows thread that performs the actual writing of messages that require
* Win32 system calls. Only the windows thread can make system calls so as not
* to disrupt the simulation by making Windows calls from FreeRTOS tasks.
*/
static DWORD WINAPI prvWin32LoggingThread( void *pvParam );
/*
* Creates the socket to which UDP messages are sent. This function is not
* called directly to prevent the print socket being created from within the IP
* task - which could result in a deadlock. Instead the function call is
* deferred to run in the RTOS daemon task - hence it prototype.
*/
static void prvCreatePrintSocket( void *pvParameter1, uint32_t ulParameter2 );
/*-----------------------------------------------------------*/
/* Windows event used to wake the Win32 thread which performs any logging that
needs Win32 system calls. */
static void *pvLoggingThreadEvent = NULL;
/* Stores the selected logging targets passed in as parameters to the
vLoggingInit() function. */
BaseType_t xStdoutLoggingUsed = pdFALSE, xDiskFileLoggingUsed = pdFALSE, xUDPLoggingUsed = pdFALSE;
/* Circular buffer used to pass messages from the FreeRTOS tasks to the Win32
thread that is responsible for making Win32 calls (when stdout or a disk log is
used). */
static StreamBuffer_t *xLogStreamBuffer = NULL;
/* Handle to the file used for logging. This is left open while there are
messages waiting to be logged, then closed again in between logs. */
static FILE *pxLoggingFileHandle = NULL;
/* When true prints are performed directly. After start up xDirectPrint is set
to pdFALSE - at which time prints that require Win32 system calls are done by
the Win32 thread responsible for logging. */
BaseType_t xDirectPrint = pdTRUE;
/* File names for the in use and complete (full) log files. */
static const char *pcLogFileName = "RTOSDemo.log";
static const char *pcFullLogFileName = "RTOSDemo.ful";
/* Keep the current file size in a variable, as an optimisation. */
static size_t ulSizeOfLoggingFile = 0ul;
/* The UDP socket and address on/to which print messages are sent. */
Socket_t xPrintSocket = FREERTOS_INVALID_SOCKET;
struct freertos_sockaddr xPrintUDPAddress;
/*-----------------------------------------------------------*/
void vLoggingInit( BaseType_t xLogToStdout, BaseType_t xLogToFile, BaseType_t xLogToUDP, uint32_t ulRemoteIPAddress, uint16_t usRemotePort )
{
/* Can only be called before the scheduler has started. */
configASSERT( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED );
#if( ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) )
{
HANDLE Win32Thread;
/* Record which output methods are to be used. */
xStdoutLoggingUsed = xLogToStdout;
xDiskFileLoggingUsed = xLogToFile;
xUDPLoggingUsed = xLogToUDP;
/* If a disk file is used then initialise it now. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvFileLoggingInit();
}
/* If UDP logging is used then store the address to which the log data
will be sent - but don't create the socket yet because the network is
not initialised. */
if( xUDPLoggingUsed != pdFALSE )
{
/* Set the address to which the print messages are sent. */
xPrintUDPAddress.sin_port = FreeRTOS_htons( usRemotePort );
xPrintUDPAddress.sin_addr = ulRemoteIPAddress;
}
/* If a disk file or stdout are to be used then Win32 system calls will
have to be made. Such system calls cannot be made from FreeRTOS tasks
so create a stream buffer to pass the messages to a Win32 thread, then
create the thread itself, along with a Win32 event that can be used to
unblock the thread. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
/* Create the buffer. */
xLogStreamBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) + dlLOGGING_STREAM_BUFFER_SIZE + 1 );
configASSERT( xLogStreamBuffer );
memset( xLogStreamBuffer, '\0', sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) );
xLogStreamBuffer->LENGTH = dlLOGGING_STREAM_BUFFER_SIZE + 1;
/* Create the Windows event. */
pvLoggingThreadEvent = CreateEvent( NULL, FALSE, TRUE, "StdoutLoggingEvent" );
/* Create the thread itself. */
Win32Thread = CreateThread(
NULL, /* Pointer to thread security attributes. */
0, /* Initial thread stack size, in bytes. */
prvWin32LoggingThread, /* Pointer to thread function. */
NULL, /* Argument for new thread. */
0, /* Creation flags. */
NULL );
/* Use the cores that are not used by the FreeRTOS tasks. */
SetThreadAffinityMask( Win32Thread, ~0x01u );
SetThreadPriorityBoost( Win32Thread, TRUE );
SetThreadPriority( Win32Thread, THREAD_PRIORITY_IDLE );
}
}
#else
{
/* FreeRTOSIPConfig is set such that no print messages will be output.
Avoid compiler warnings about unused parameters. */
( void ) xLogToStdout;
( void ) xLogToFile;
( void ) xLogToUDP;
( void ) usRemotePort;
( void ) ulRemoteIPAddress;
}
#endif /* ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) */
}
/*-----------------------------------------------------------*/
static void prvCreatePrintSocket( void *pvParameter1, uint32_t ulParameter2 )
{
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 0 );
Socket_t xSocket;
/* The function prototype is that of a deferred function, but the parameters
are not actually used. */
( void ) pvParameter1;
( void ) ulParameter2;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
/* FreeRTOS+TCP decides which port to bind to. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
FreeRTOS_bind( xSocket, NULL, 0 );
/* Now the socket is bound it can be assigned to the print socket. */
xPrintSocket = xSocket;
}
}
/*-----------------------------------------------------------*/
void vLoggingPrintf( const char *pcFormat, ... )
{
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
char cOutputString[ dlMAX_PRINT_STRING_LENGTH ];
char *pcSource, *pcTarget, *pcBegin;
size_t xLength, xLength2, rc;
static BaseType_t xMessageNumber = 0;
va_list args;
uint32_t ulIPAddress;
const char *pcTaskName;
const char *pcNoTask = "None";
int iOriginalPriority;
HANDLE xCurrentTask;
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) || ( xUDPLoggingUsed != pdFALSE ) )
{
/* There are a variable number of parameters. */
va_start( args, pcFormat );
/* Additional info to place at the start of the log. */
if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )
{
pcTaskName = pcTaskGetName( NULL );
}
else
{
pcTaskName = pcNoTask;
}
if( strcmp( pcFormat, "\n" ) != 0 )
{
xLength = snprintf( cPrintString, dlMAX_PRINT_STRING_LENGTH, "%lu %lu [%s] ",
xMessageNumber++,
( unsigned long ) xTaskGetTickCount(),
pcTaskName );
}
else
{
xLength = 0;
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
}
xLength2 = vsnprintf( cPrintString + xLength, dlMAX_PRINT_STRING_LENGTH - xLength, pcFormat, args );
if( xLength2 < 0 )
{
/* Clean up. */
xLength2 = dlMAX_PRINT_STRING_LENGTH - 1 - xLength;
cPrintString[ dlMAX_PRINT_STRING_LENGTH - 1 ] = '\0';
}
xLength += xLength2;
va_end( args );
/* For ease of viewing, copy the string into another buffer, converting
IP addresses to dot notation on the way. */
pcSource = cPrintString;
pcTarget = cOutputString;
while( ( *pcSource ) != '\0' )
{
*pcTarget = *pcSource;
pcTarget++;
pcSource++;
/* Look forward for an IP address denoted by 'ip'. */
if( ( isxdigit( pcSource[ 0 ] ) != pdFALSE ) && ( pcSource[ 1 ] == 'i' ) && ( pcSource[ 2 ] == 'p' ) )
{
*pcTarget = *pcSource;
pcTarget++;
*pcTarget = '\0';
pcBegin = pcTarget - 8;
while( ( pcTarget > pcBegin ) && ( isxdigit( pcTarget[ -1 ] ) != pdFALSE ) )
{
pcTarget--;
}
sscanf( pcTarget, "%8X", &ulIPAddress );
rc = sprintf( pcTarget, "%lu.%lu.%lu.%lu",
( unsigned long ) ( ulIPAddress >> 24UL ),
( unsigned long ) ( (ulIPAddress >> 16UL) & 0xffUL ),
( unsigned long ) ( (ulIPAddress >> 8UL) & 0xffUL ),
( unsigned long ) ( ulIPAddress & 0xffUL ) );
pcTarget += rc;
pcSource += 3; /* skip "<n>ip" */
}
}
/* How far through the buffer was written? */
xLength = ( BaseType_t ) ( pcTarget - cOutputString );
/* If the message is to be logged to a UDP port then it can be sent directly
because it only uses FreeRTOS function (not Win32 functions). */
if( xUDPLoggingUsed != pdFALSE )
{
if( ( xPrintSocket == FREERTOS_INVALID_SOCKET ) && ( FreeRTOS_IsNetworkUp() != pdFALSE ) )
{
/* Create and bind the socket to which print messages are sent. The
xTimerPendFunctionCall() function is used even though this is
not an interrupt because this function is called from the IP task
and the IP task cannot itself wait for a socket to bind. The
parameters to prvCreatePrintSocket() are not required so set to
NULL or 0. */
xTimerPendFunctionCall( prvCreatePrintSocket, NULL, 0, dlDONT_BLOCK );
}
if( xPrintSocket != FREERTOS_INVALID_SOCKET )
{
FreeRTOS_sendto( xPrintSocket, cOutputString, xLength, 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
/* Just because the UDP data logger I'm using is dumb. */
FreeRTOS_sendto( xPrintSocket, "\r", sizeof( char ), 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
}
}
/* If logging is also to go to either stdout or a disk file then it cannot
be output here - so instead write the message to the stream buffer and wake
the Win32 thread which will read it from the stream buffer and perform the
actual output. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
configASSERT( xLogStreamBuffer );
/* How much space is in the buffer? */
xLength2 = uxStreamBufferGetSpace( xLogStreamBuffer );
/* There must be enough space to write both the string and the length of
the string. */
if( xLength2 >= ( xLength + sizeof( xLength ) ) )
{
/* First write in the length of the data, then write in the data
itself. Raising the thread priority is used as a critical section
as there are potentially multiple writers. The stream buffer is
only thread safe when there is a single writer (likewise for
reading from the buffer). */
xCurrentTask = GetCurrentThread();
iOriginalPriority = GetThreadPriority( xCurrentTask );
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) &( xLength ), sizeof( xLength ) );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) cOutputString, xLength );
SetThreadPriority( GetCurrentThread(), iOriginalPriority );
}
/* xDirectPrint is initialised to pdTRUE, and while it remains true the
logging output function is called directly. When the system is running
the output function cannot be called directly because it would get
called from both FreeRTOS tasks and Win32 threads - so instead wake the
Win32 thread responsible for the actual output. */
if( xDirectPrint != pdFALSE )
{
/* While starting up, the thread which calls prvWin32LoggingThread()
is not running yet and xDirectPrint will be pdTRUE. */
prvLoggingFlushBuffer();
}
else if( pvLoggingThreadEvent != NULL )
{
/* While running, wake up prvWin32LoggingThread() to send the
logging data. */
SetEvent( pvLoggingThreadEvent );
}
}
}
}
/*-----------------------------------------------------------*/
static void prvLoggingFlushBuffer( void )
{
size_t xLength;
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
/* Is there more than the length value stored in the circular buffer
used to pass data from the FreeRTOS simulator into this Win32 thread? */
while( uxStreamBufferGetSize( xLogStreamBuffer ) > sizeof( xLength ) )
{
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) &xLength, sizeof( xLength ), pdFALSE );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) cPrintString, xLength, pdFALSE );
/* Write the message to standard out if requested to do so when
vLoggingInit() was called, or if the network is not yet up. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( FreeRTOS_IsNetworkUp() == pdFALSE ) )
{
/* Write the message to stdout. */
printf( "%s", cPrintString ); /*_RB_ Replace with _write(). */
}
/* Write the message to a file if requested to do so when
vLoggingInit() was called. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvLogToFile( cPrintString, xLength );
}
}
prvFileClose();
}
/*-----------------------------------------------------------*/
static DWORD WINAPI prvWin32LoggingThread( void *pvParameter )
{
const DWORD xMaxWait = 1000;
( void ) pvParameter;
/* From now on, prvLoggingFlushBuffer() will only be called from this
Windows thread */
xDirectPrint = pdFALSE;
for( ;; )
{
/* Wait to be told there are message waiting to be logged. */
WaitForSingleObject( pvLoggingThreadEvent, xMaxWait );
/* Write out all waiting messages. */
prvLoggingFlushBuffer();
}
}
/*-----------------------------------------------------------*/
static void prvFileLoggingInit( void )
{
FILE *pxHandle = fopen( pcLogFileName, "a" );
if( pxHandle != NULL )
{
fseek( pxHandle, SEEK_END, 0ul );
ulSizeOfLoggingFile = ftell( pxHandle );
fclose( pxHandle );
}
else
{
ulSizeOfLoggingFile = 0ul;
}
}
/*-----------------------------------------------------------*/
static void prvFileClose( void )
{
if( pxLoggingFileHandle != NULL )
{
fclose( pxLoggingFileHandle );
pxLoggingFileHandle = NULL;
}
}
/*-----------------------------------------------------------*/
static void prvLogToFile( const char *pcMessage, size_t xLength )
{
if( pxLoggingFileHandle == NULL )
{
pxLoggingFileHandle = fopen( pcLogFileName, "a" );
}
if( pxLoggingFileHandle != NULL )
{
fwrite( pcMessage, 1, xLength, pxLoggingFileHandle );
ulSizeOfLoggingFile += xLength;
/* If the file has grown to its maximum permissible size then close and
rename it - then start with a new file. */
if( ulSizeOfLoggingFile > ( size_t ) dlLOGGING_FILE_SIZE )
{
prvFileClose();
if( _access( pcFullLogFileName, 00 ) == 0 )
{
remove( pcFullLogFileName );
}
rename( pcLogFileName, pcFullLogFileName );
ulSizeOfLoggingFile = 0;
}
}
}
/*-----------------------------------------------------------*/

@ -1,48 +0,0 @@
/*
* FreeRTOS Kernel V10.4.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef DEMO_LOGGING_H
#define DEMO_LOGGING_H
/*
* Initialise a logging system that can be used from FreeRTOS tasks and Win32
* threads. Do not call printf() directly while the scheduler is running.
*
* Set xLogToStdout, xLogToFile and xLogToUDP to either pdTRUE or pdFALSE to
* lot to stdout, a disk file and a UDP port respectively.
*
* If xLogToUDP is pdTRUE then ulRemoteIPAddress and usRemotePort must be set
* to the IP address and port number to which UDP log messages will be sent.
*/
void vLoggingInit( BaseType_t xLogToStdout,
BaseType_t xLogToFile,
BaseType_t xLogToUDP,
uint32_t ulRemoteIPAddress,
uint16_t usRemotePort );
#endif /* DEMO_LOGGING_H */

@ -46,50 +46,50 @@
#include "SimpleUDPClientAndServer.h"
#include "SimpleTCPEchoServer.h"
#include "TCPEchoClient_SingleTasks.h"
#include "demo_logging.h"
#include "logging.h"
/* Simple UDP client and server task parameters. */
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL )
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL )
/* Echo client task parameters - used for both TCP and UDP echo clients. */
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the Windows port. */
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the Windows port. */
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Echo server task parameters. */
#define mainECHO_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the Windows port. */
#define mainECHO_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainECHO_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the Windows port. */
#define mainECHO_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Define a name that will be used for LLMNR and NBNS searches. */
#define mainHOST_NAME "RTOSDemo"
#define mainDEVICE_NICK_NAME "windows_demo"
#define mainHOST_NAME "RTOSDemo"
#define mainDEVICE_NICK_NAME "windows_demo"
/* Set the following constants to 1 or 0 to define which tasks to include and
exclude:
mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS: When set to 1 two UDP client tasks
and two UDP server tasks are created. The clients talk to the servers. One set
of tasks use the standard sockets interface, and the other the zero copy sockets
interface. These tasks are self checking and will trigger a configASSERT() if
they detect a difference in the data that is received from that which was sent.
As these tasks use UDP, and can therefore loose packets, they will cause
configASSERT() to be called when they are run in a less than perfect networking
environment.
mainCREATE_TCP_ECHO_TASKS_SINGLE: When set to 1 a set of tasks are created that
send TCP echo requests to the standard echo port (port 7), then wait for and
verify the echo reply, from within the same task (Tx and Rx are performed in the
same RTOS task). The IP address of the echo server must be configured using the
configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in
FreeRTOSConfig.h.
mainCREATE_TCP_ECHO_SERVER_TASK: When set to 1 a task is created that accepts
connections on the standard echo port (port 7), then echos back any data
received on that connection.
*/
#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 1
#define mainCREATE_TCP_ECHO_TASKS_SINGLE 0
#define mainCREATE_TCP_ECHO_SERVER_TASK 0
* exclude:
*
* mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS: When set to 1 two UDP client tasks
* and two UDP server tasks are created. The clients talk to the servers. One set
* of tasks use the standard sockets interface, and the other the zero copy sockets
* interface. These tasks are self checking and will trigger a configASSERT() if
* they detect a difference in the data that is received from that which was sent.
* As these tasks use UDP, and can therefore loose packets, they will cause
* configASSERT() to be called when they are run in a less than perfect networking
* environment.
*
* mainCREATE_TCP_ECHO_TASKS_SINGLE: When set to 1 a set of tasks are created that
* send TCP echo requests to the standard echo port (port 7), then wait for and
* verify the echo reply, from within the same task (Tx and Rx are performed in the
* same RTOS task). The IP address of the echo server must be configured using the
* configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in
* FreeRTOSConfig.h.
*
* mainCREATE_TCP_ECHO_SERVER_TASK: When set to 1 a task is created that accepts
* connections on the standard echo port (port 7), then echos back any data
* received on that connection.
*/
#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 1
#define mainCREATE_TCP_ECHO_TASKS_SINGLE 0
#define mainCREATE_TCP_ECHO_SERVER_TASK 0
/*-----------------------------------------------------------*/
/*
@ -104,28 +104,28 @@ static void prvSRand( UBaseType_t ulSeed );
static void prvMiscInitialisation( void );
/* The default IP and MAC address used by the demo. The address configuration
defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
1 but a DHCP server could not be contacted. See the online documentation for
more information. */
* defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
* 1 but a DHCP server could not be contacted. See the online documentation for
* more information. */
static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
/* Set the following constant to pdTRUE to log using the method indicated by the
name of the constant, or pdFALSE to not log using the method indicated by the
name of the constant. Options include to standard out (xLogToStdout), to a disk
file (xLogToFile), and to a UDP port (xLogToUDP). If xLogToUDP is set to pdTRUE
then UDP messages are sent to the IP address configured as the echo server
address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
* name of the constant, or pdFALSE to not log using the method indicated by the
* name of the constant. Options include to standard out (xLogToStdout), to a disk
* file (xLogToFile), and to a UDP port (xLogToUDP). If xLogToUDP is set to pdTRUE
* then UDP messages are sent to the IP address configured as the echo server
* address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
* the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
const BaseType_t xLogToStdout = pdTRUE, xLogToFile = pdFALSE, xLogToUDP = pdFALSE;
/* Default MAC address configuration. The demo creates a virtual network
connection that uses this MAC address by accessing the raw Ethernet data
to and from a real network connection on the host PC. See the
configNETWORK_INTERFACE_TO_USE definition for information on how to configure
the real network connection to use. */
* connection that uses this MAC address by accessing the raw Ethernet data
* to and from a real network connection on the host PC. See the
* configNETWORK_INTERFACE_TO_USE definition for information on how to configure
* the real network connection to use. */
const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
/* Use by the pseudo random number generator. */
@ -135,222 +135,223 @@ static UBaseType_t ulNextRand;
int main( void )
{
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );
/*
* Instructions for using this project are provided on:
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
*/
/* Miscellaneous initialisation including preparing the logging and seeding
the random number generator. */
prvMiscInitialisation();
/* Initialise the network interface.
***NOTE*** Tasks that use the network are created in the network event hook
when the network is connected and ready for use (see the definition of
vApplicationIPNetworkEventHook() below). The address values passed in here
are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
but a DHCP server cannot be contacted. */
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ("vTaskStartScheduler\n") );
vTaskStartScheduler();
/* If all is well, the scheduler will now be running, and the following
line will never be reached. If the following line does execute, then
there was insufficient FreeRTOS heap memory available for the idle and/or
timer tasks to be created. See the memory management section on the
FreeRTOS web site for more details (this is standard text that is not not
really applicable to the Win32 simulator port). */
for( ;; )
{
Sleep( ulLongTime_ms );
}
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );
/*
* Instructions for using this project are provided on:
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
*/
/* Miscellaneous initialisation including preparing the logging and seeding
* the random number generator. */
prvMiscInitialisation();
/* Initialise the network interface.
*
***NOTE*** Tasks that use the network are created in the network event hook
* when the network is connected and ready for use (see the definition of
* vApplicationIPNetworkEventHook() below). The address values passed in here
* are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
* but a DHCP server cannot be contacted. */
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
vTaskStartScheduler();
/* If all is well, the scheduler will now be running, and the following
* line will never be reached. If the following line does execute, then
* there was insufficient FreeRTOS heap memory available for the idle and/or
* timer tasks to be created. See the memory management section on the
* FreeRTOS web site for more details (this is standard text that is not not
* really applicable to the Win32 simulator port). */
for( ; ; )
{
Sleep( ulLongTime_ms );
}
}
/*-----------------------------------------------------------*/
void vApplicationIdleHook( void )
{
const uint32_t ulMSToSleep = 1;
const uint32_t ulMSToSleep = 1;
/* This is just a trivial example of an idle hook. It is called on each
cycle of the idle task if configUSE_IDLE_HOOK is set to 1 in
FreeRTOSConfig.h. It must *NOT* attempt to block. In this case the
idle task just sleeps to lower the CPU usage. */
Sleep( ulMSToSleep );
/* This is just a trivial example of an idle hook. It is called on each
* cycle of the idle task if configUSE_IDLE_HOOK is set to 1 in
* FreeRTOSConfig.h. It must *NOT* attempt to block. In this case the
* idle task just sleeps to lower the CPU usage. */
Sleep( ulMSToSleep );
}
/*-----------------------------------------------------------*/
void vAssertCalled( const char *pcFile, uint32_t ulLine )
void vAssertCalled( const char * pcFile,
uint32_t ulLine )
{
const uint32_t ulLongSleep = 1000UL;
volatile uint32_t ulBlockVariable = 0UL;
volatile char *pcFileName = ( volatile char * ) pcFile;
volatile uint32_t ulLineNumber = ulLine;
( void ) pcFileName;
( void ) ulLineNumber;
FreeRTOS_debug_printf( ( "vAssertCalled( %s, %ld\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 )
{
Sleep( ulLongSleep );
}
}
taskENABLE_INTERRUPTS();
const uint32_t ulLongSleep = 1000UL;
volatile uint32_t ulBlockVariable = 0UL;
volatile char * pcFileName = ( volatile char * ) pcFile;
volatile uint32_t ulLineNumber = ulLine;
( void ) pcFileName;
( void ) ulLineNumber;
FreeRTOS_debug_printf( ( "vAssertCalled( %s, %ld\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 )
{
Sleep( ulLongSleep );
}
}
taskENABLE_INTERRUPTS();
}
/*-----------------------------------------------------------*/
/* Called by FreeRTOS+TCP when the network connects or disconnects. Disconnect
events are only received if implemented in the MAC driver. */
* events are only received if implemented in the MAC driver. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
char cBuffer[ 16 ];
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if( eNetworkEvent == eNetworkUp )
{
/* Create the tasks that use the IP stack if they have not already been
created. */
if( xTasksAlreadyCreated == pdFALSE )
{
/* See the comments above the definitions of these pre-processor
macros at the top of this file for a description of the individual
demo tasks. */
#if( mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS == 1 )
{
vStartSimpleUDPClientServerTasks( configMINIMAL_STACK_SIZE, mainSIMPLE_UDP_CLIENT_SERVER_PORT, mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY );
}
#endif /* mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS */
#if( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 )
{
vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
}
#endif /* mainCREATE_TCP_ECHO_TASKS_SINGLE */
#if( mainCREATE_TCP_ECHO_SERVER_TASK == 1 )
{
vStartSimpleTCPServerTasks( mainECHO_SERVER_TASK_STACK_SIZE, mainECHO_SERVER_TASK_PRIORITY );
}
#endif
xTasksAlreadyCreated = pdTRUE;
}
/* Print out the network configuration, which may have come from a DHCP
server. */
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
FreeRTOS_printf( ( "DNS Server Address: %s\r\n\r\n\r\n", cBuffer ) );
}
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
char cBuffer[ 16 ];
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if( eNetworkEvent == eNetworkUp )
{
/* Create the tasks that use the IP stack if they have not already been
* created. */
if( xTasksAlreadyCreated == pdFALSE )
{
/* See the comments above the definitions of these pre-processor
* macros at the top of this file for a description of the individual
* demo tasks. */
#if ( mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS == 1 )
{
vStartSimpleUDPClientServerTasks( configMINIMAL_STACK_SIZE, mainSIMPLE_UDP_CLIENT_SERVER_PORT, mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY );
}
#endif /* mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS */
#if ( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 )
{
vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
}
#endif /* mainCREATE_TCP_ECHO_TASKS_SINGLE */
#if ( mainCREATE_TCP_ECHO_SERVER_TASK == 1 )
{
vStartSimpleTCPServerTasks( mainECHO_SERVER_TASK_STACK_SIZE, mainECHO_SERVER_TASK_PRIORITY );
}
#endif
xTasksAlreadyCreated = pdTRUE;
}
/* Print out the network configuration, which may have come from a DHCP
* server. */
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
FreeRTOS_printf( ( "DNS Server Address: %s\r\n\r\n\r\n", cBuffer ) );
}
}
/*-----------------------------------------------------------*/
void vApplicationMallocFailedHook( void )
{
/* Called if a call to pvPortMalloc() fails because there is insufficient
free memory available in the FreeRTOS heap. pvPortMalloc() is called
internally by FreeRTOS API functions that create tasks, queues, software
timers, and semaphores. The size of the FreeRTOS heap is set by the
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
vAssertCalled( __FILE__, __LINE__ );
/* Called if a call to pvPortMalloc() fails because there is insufficient
* free memory available in the FreeRTOS heap. pvPortMalloc() is called
* internally by FreeRTOS API functions that create tasks, queues, software
* timers, and semaphores. The size of the FreeRTOS heap is set by the
* configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
vAssertCalled( __FILE__, __LINE__ );
}
/*-----------------------------------------------------------*/
UBaseType_t uxRand( void )
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
/* Utility function to generate a pseudo random number. */
/* Utility function to generate a pseudo random number. */
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
}
/*-----------------------------------------------------------*/
static void prvSRand( UBaseType_t ulSeed )
{
/* Utility function to seed the pseudo random number generator. */
ulNextRand = ulSeed;
/* Utility function to seed the pseudo random number generator. */
ulNextRand = ulSeed;
}
/*-----------------------------------------------------------*/
static void prvMiscInitialisation( void )
{
time_t xTimeNow;
uint32_t ulLoggingIPAddress;
time_t xTimeNow;
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 );
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. */
time( &xTimeNow );
FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );
prvSRand( ( uint32_t ) xTimeNow );
FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n", ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32() ) );
/* Seed the random number generator. */
time( &xTimeNow );
FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );
prvSRand( ( uint32_t ) xTimeNow );
FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n", ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32(), ipconfigRAND32() ) );
}
/*-----------------------------------------------------------*/
#if( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
const char *pcApplicationHostnameHook( void )
{
/* Assign the name "FreeRTOS" to this network node. This function will
be called during the DHCP: the machine will be registered with an IP
address plus this name. */
return mainHOST_NAME;
}
const char * pcApplicationHostnameHook( void )
{
/* Assign the name "FreeRTOS" to this network node. This function will
* be called during the DHCP: the machine will be registered with an IP
* address plus this name. */
return mainHOST_NAME;
}
#endif
/*-----------------------------------------------------------*/
#if( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
BaseType_t xApplicationDNSQueryHook( const char *pcName )
{
BaseType_t xReturn;
/* Determine if a name lookup is for this node. Two names are given
to this node: that returned by pcApplicationHostnameHook() and that set
by mainDEVICE_NICK_NAME. */
if( _stricmp( pcName, pcApplicationHostnameHook() ) == 0 )
{
xReturn = pdPASS;
}
else if( _stricmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
#endif
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
BaseType_t xApplicationDNSQueryHook( const char * pcName )
{
BaseType_t xReturn;
/* Determine if a name lookup is for this node. Two names are given
* to this node: that returned by pcApplicationHostnameHook() and that set
* by mainDEVICE_NICK_NAME. */
if( _stricmp( pcName, pcApplicationHostnameHook() ) == 0 )
{
xReturn = pdPASS;
}
else if( _stricmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
/*
* Callback that provides the inputs necessary to generate a randomized TCP
@ -359,26 +360,25 @@ uint32_t ulLoggingIPAddress;
* SYSTEMS.
*/
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
return uxRand();
return uxRand();
}
/*
* Supply a random number to FreeRTOS+TCP stack.
* THIS IS ONLY A DUMMY IMPLEMENTATION THAT RETURNS A PSEUDO RANDOM NUMBER
* Supply a random number to FreeRTOS+TCP stack.
* THIS IS ONLY A DUMMY IMPLEMENTATION THAT RETURNS A PSEUDO RANDOM NUMBER
* SO IS NOT INTENDED FOR USE IN PRODUCTION SYSTEMS.
*/
BaseType_t xApplicationGetRandomNumber(uint32_t* pulNumber)
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
*(pulNumber) = uxRand();
return pdTRUE;
*( pulNumber ) = uxRand();
return pdTRUE;
}

@ -1,536 +0,0 @@
/*
* FreeRTOS Kernel V10.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/*
* Logging utility that allows FreeRTOS tasks to log to a UDP port, stdout, and
* disk file without making any Win32 system calls themselves.
*
* Messages logged to a UDP port are sent directly (using FreeRTOS+TCP), but as
* FreeRTOS tasks cannot make Win32 system calls messages sent to stdout or a
* disk file are sent via a stream buffer to a Win32 thread which then performs
* the actual output.
*/
/* Standard includes. */
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <io.h>
#include <ctype.h>
/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_Stream_Buffer.h"
/* Demo includes. */
#include "demo_logging.h"
/*-----------------------------------------------------------*/
/* The maximum size to which the log file may grow, before being renamed
* to .ful. */
#define dlLOGGING_FILE_SIZE ( 40ul * 1024ul * 1024ul )
/* Dimensions the arrays into which print messages are created. */
#define dlMAX_PRINT_STRING_LENGTH 255
/* The size of the stream buffer used to pass messages from FreeRTOS tasks to
* the Win32 thread that is responsible for making any Win32 system calls that are
* necessary for the selected logging method. */
#define dlLOGGING_STREAM_BUFFER_SIZE 32768
/* A block time of zero simply means don't block. */
#define dlDONT_BLOCK 0
/*-----------------------------------------------------------*/
/*
* Called from vLoggingInit() to start a new disk log file.
*/
static void prvFileLoggingInit( void );
/*
* Attempt to write a message to the file.
*/
static void prvLogToFile( const char * pcMessage,
size_t xLength );
/*
* Simply close the logging file, if it is open.
*/
static void prvFileClose( void );
/*
* Before the scheduler is started this function is called directly. After the
* scheduler has started it is called from the Windows thread dedicated to
* outputting log messages. Only the windows thread actually performs the
* writing so as not to disrupt the simulation by making Windows system calls
* from FreeRTOS tasks.
*/
static void prvLoggingFlushBuffer( void );
/*
* The windows thread that performs the actual writing of messages that require
* Win32 system calls. Only the windows thread can make system calls so as not
* to disrupt the simulation by making Windows calls from FreeRTOS tasks.
*/
static DWORD WINAPI prvWin32LoggingThread( void * pvParam );
/*
* Creates the socket to which UDP messages are sent. This function is not
* called directly to prevent the print socket being created from within the IP
* task - which could result in a deadlock. Instead the function call is
* deferred to run in the RTOS daemon task - hence it prototype.
*/
static void prvCreatePrintSocket( void * pvParameter1,
uint32_t ulParameter2 );
/*-----------------------------------------------------------*/
/* Windows event used to wake the Win32 thread which performs any logging that
* needs Win32 system calls. */
static void * pvLoggingThreadEvent = NULL;
/* Stores the selected logging targets passed in as parameters to the
* vLoggingInit() function. */
BaseType_t xStdoutLoggingUsed = pdFALSE, xDiskFileLoggingUsed = pdFALSE, xUDPLoggingUsed = pdFALSE;
/* Circular buffer used to pass messages from the FreeRTOS tasks to the Win32
* thread that is responsible for making Win32 calls (when stdout or a disk log is
* used). */
static StreamBuffer_t * xLogStreamBuffer = NULL;
/* Handle to the file used for logging. This is left open while there are
* messages waiting to be logged, then closed again in between logs. */
static FILE * pxLoggingFileHandle = NULL;
/* When true prints are performed directly. After start up xDirectPrint is set
* to pdFALSE - at which time prints that require Win32 system calls are done by
* the Win32 thread responsible for logging. */
BaseType_t xDirectPrint = pdTRUE;
/* File names for the in use and complete (full) log files. */
static const char * pcLogFileName = "RTOSDemo.log";
static const char * pcFullLogFileName = "RTOSDemo.ful";
/* As an optimization, the current file size is kept in a variable. */
static size_t ulSizeOfLoggingFile = 0ul;
/* The UDP socket and address on/to which print messages are sent. */
Socket_t xPrintSocket = FREERTOS_INVALID_SOCKET;
struct freertos_sockaddr xPrintUDPAddress;
/*-----------------------------------------------------------*/
void vLoggingInit( BaseType_t xLogToStdout,
BaseType_t xLogToFile,
BaseType_t xLogToUDP,
uint32_t ulRemoteIPAddress,
uint16_t usRemotePort )
{
/* Can only be called before the scheduler has started. */
configASSERT( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED );
#if ( ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) )
{
HANDLE Win32Thread;
/* Record which output methods are to be used. */
xStdoutLoggingUsed = xLogToStdout;
xDiskFileLoggingUsed = xLogToFile;
xUDPLoggingUsed = xLogToUDP;
/* If a disk file is used then initialize it now. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvFileLoggingInit();
}
/* If UDP logging is used then store the address to which the log data
* will be sent - but don't create the socket yet because the network is
* not initialized. */
if( xUDPLoggingUsed != pdFALSE )
{
/* Set the address to which the print messages are sent. */
xPrintUDPAddress.sin_port = FreeRTOS_htons( usRemotePort );
xPrintUDPAddress.sin_addr = ulRemoteIPAddress;
}
/* If a disk file or stdout are to be used then Win32 system calls will
* have to be made. Such system calls cannot be made from FreeRTOS tasks
* so create a stream buffer to pass the messages to a Win32 thread, then
* create the thread itself, along with a Win32 event that can be used to
* unblock the thread. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
/* Create the buffer. */
xLogStreamBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) + dlLOGGING_STREAM_BUFFER_SIZE + 1 );
configASSERT( xLogStreamBuffer );
memset( xLogStreamBuffer, '\0', sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) );
xLogStreamBuffer->LENGTH = dlLOGGING_STREAM_BUFFER_SIZE + 1;
/* Create the Windows event. */
pvLoggingThreadEvent = CreateEvent( NULL, FALSE, TRUE, "StdoutLoggingEvent" );
/* Create the thread itself. */
Win32Thread = CreateThread(
NULL, /* Pointer to thread security attributes. */
0, /* Initial thread stack size, in bytes. */
prvWin32LoggingThread, /* Pointer to thread function. */
NULL, /* Argument for new thread. */
0, /* Creation flags. */
NULL );
/* Use the cores that are not used by the FreeRTOS tasks. */
SetThreadAffinityMask( Win32Thread, ~0x01u );
SetThreadPriorityBoost( Win32Thread, TRUE );
SetThreadPriority( Win32Thread, THREAD_PRIORITY_IDLE );
}
}
#else /* if ( ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) ) */
{
/* FreeRTOSIPConfig is set such that no print messages will be output.
* Avoid compiler warnings about unused parameters. */
( void ) xLogToStdout;
( void ) xLogToFile;
( void ) xLogToUDP;
( void ) usRemotePort;
( void ) ulRemoteIPAddress;
}
#endif /* ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) */
}
/*-----------------------------------------------------------*/
static void prvCreatePrintSocket( void * pvParameter1,
uint32_t ulParameter2 )
{
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 0 );
Socket_t xSocket;
/* The function prototype is that of a deferred function, but the parameters
* are not actually used. */
( void ) pvParameter1;
( void ) ulParameter2;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
/* FreeRTOS+TCP decides which port to bind to. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
FreeRTOS_bind( xSocket, NULL, 0 );
/* Now the socket is bound it can be assigned to the print socket. */
xPrintSocket = xSocket;
}
}
/*-----------------------------------------------------------*/
void vLoggingPrintf( const char * pcFormat,
... )
{
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
char cOutputString[ dlMAX_PRINT_STRING_LENGTH ];
char * pcSource, * pcTarget, * pcBegin;
size_t xLength, xLength2, rc;
static BaseType_t xMessageNumber = 0;
va_list args;
uint32_t ulIPAddress;
const char * pcTaskName;
const char * pcNoTask = "None";
int iOriginalPriority;
HANDLE xCurrentTask;
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) || ( xUDPLoggingUsed != pdFALSE ) )
{
/* There are a variable number of parameters. */
va_start( args, pcFormat );
/* Additional info to place at the start of the log. */
if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )
{
pcTaskName = pcTaskGetName( NULL );
}
else
{
pcTaskName = pcNoTask;
}
if( strcmp( pcFormat, "\n" ) != 0 )
{
xLength = snprintf( cPrintString, dlMAX_PRINT_STRING_LENGTH, "%lu %lu [%s] ",
xMessageNumber++,
( unsigned long ) xTaskGetTickCount(),
pcTaskName );
}
else
{
xLength = 0;
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
}
xLength2 = vsnprintf( cPrintString + xLength, dlMAX_PRINT_STRING_LENGTH - xLength, pcFormat, args );
if( xLength2 < 0 )
{
/* Clean up. */
xLength2 = dlMAX_PRINT_STRING_LENGTH - 1 - xLength;
cPrintString[ dlMAX_PRINT_STRING_LENGTH - 1 ] = '\0';
}
xLength += xLength2;
va_end( args );
/* For ease of viewing, copy the string into another buffer, converting
* IP addresses to dot notation on the way. */
pcSource = cPrintString;
pcTarget = cOutputString;
while( ( *pcSource ) != '\0' )
{
*pcTarget = *pcSource;
pcTarget++;
pcSource++;
/* Look forward for an IP address denoted by 'ip'. */
if( ( isxdigit( pcSource[ 0 ] ) != pdFALSE ) && ( pcSource[ 1 ] == 'i' ) && ( pcSource[ 2 ] == 'p' ) )
{
*pcTarget = *pcSource;
pcTarget++;
*pcTarget = '\0';
pcBegin = pcTarget - 8;
while( ( pcTarget > pcBegin ) && ( isxdigit( pcTarget[ -1 ] ) != pdFALSE ) )
{
pcTarget--;
}
sscanf( pcTarget, "%8X", &ulIPAddress );
rc = sprintf( pcTarget, "%lu.%lu.%lu.%lu",
( unsigned long ) ( ulIPAddress >> 24UL ),
( unsigned long ) ( ( ulIPAddress >> 16UL ) & 0xffUL ),
( unsigned long ) ( ( ulIPAddress >> 8UL ) & 0xffUL ),
( unsigned long ) ( ulIPAddress & 0xffUL ) );
pcTarget += rc;
pcSource += 3; /* skip "<n>ip" */
}
}
/* How far through the buffer was written? */
xLength = ( BaseType_t ) ( pcTarget - cOutputString );
/* If the message is to be logged to a UDP port then it can be sent directly
* because it only uses FreeRTOS function (not Win32 functions). */
if( xUDPLoggingUsed != pdFALSE )
{
if( ( xPrintSocket == FREERTOS_INVALID_SOCKET ) && ( FreeRTOS_IsNetworkUp() != pdFALSE ) )
{
/* Create and bind the socket to which print messages are sent. The
* xTimerPendFunctionCall() function is used even though this is
* not an interrupt because this function is called from the IP task
* and the IP task cannot itself wait for a socket to bind. The
* parameters to prvCreatePrintSocket() are not required so set to
* NULL or 0. */
xTimerPendFunctionCall( prvCreatePrintSocket, NULL, 0, dlDONT_BLOCK );
}
if( xPrintSocket != FREERTOS_INVALID_SOCKET )
{
FreeRTOS_sendto( xPrintSocket, cOutputString, xLength, 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
/* Just because the UDP data logger I'm using is dumb. */
FreeRTOS_sendto( xPrintSocket, "\r", sizeof( char ), 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
}
}
/* If logging is also to go to either stdout or a disk file then it cannot
* be output here - so instead write the message to the stream buffer and wake
* the Win32 thread which will read it from the stream buffer and perform the
* actual output. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
configASSERT( xLogStreamBuffer );
/* How much space is in the buffer? */
xLength2 = uxStreamBufferGetSpace( xLogStreamBuffer );
/* There must be enough space to write both the string and the length of
* the string. */
if( xLength2 >= ( xLength + sizeof( xLength ) ) )
{
/* First write in the length of the data, then write in the data
* itself. Raising the thread priority is used as a critical section
* as there are potentially multiple writers. The stream buffer is
* only thread safe when there is a single writer (likewise for
* reading from the buffer). */
xCurrentTask = GetCurrentThread();
iOriginalPriority = GetThreadPriority( xCurrentTask );
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) &( xLength ), sizeof( xLength ) );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) cOutputString, xLength );
SetThreadPriority( GetCurrentThread(), iOriginalPriority );
}
/* xDirectPrint is initialized to pdTRUE, and while it remains true the
* logging output function is called directly. When the system is running
* the output function cannot be called directly because it would get
* called from both FreeRTOS tasks and Win32 threads - so instead wake the
* Win32 thread responsible for the actual output. */
if( xDirectPrint != pdFALSE )
{
/* While starting up, the thread which calls prvWin32LoggingThread()
* is not running yet and xDirectPrint will be pdTRUE. */
prvLoggingFlushBuffer();
}
else if( pvLoggingThreadEvent != NULL )
{
/* While running, wake up prvWin32LoggingThread() to send the
* logging data. */
SetEvent( pvLoggingThreadEvent );
}
}
}
}
/*-----------------------------------------------------------*/
static void prvLoggingFlushBuffer( void )
{
size_t xLength;
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
/* Is there more than the length value stored in the circular buffer
* used to pass data from the FreeRTOS simulator into this Win32 thread? */
while( uxStreamBufferGetSize( xLogStreamBuffer ) > sizeof( xLength ) )
{
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) &xLength, sizeof( xLength ), pdFALSE );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) cPrintString, xLength, pdFALSE );
/* Write the message to standard out if requested to do so when
* vLoggingInit() was called, or if the network is not yet up. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( FreeRTOS_IsNetworkUp() == pdFALSE ) )
{
/* Write the message to stdout. */
_write( _fileno( stdout ), cPrintString, strlen( cPrintString ) );
}
/* Write the message to a file if requested to do so when
* vLoggingInit() was called. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvLogToFile( cPrintString, xLength );
}
}
prvFileClose();
}
/*-----------------------------------------------------------*/
static DWORD WINAPI prvWin32LoggingThread( void * pvParameter )
{
const DWORD xMaxWait = 1000;
( void ) pvParameter;
/* From now on, prvLoggingFlushBuffer() will only be called from this
* Windows thread */
xDirectPrint = pdFALSE;
for( ; ; )
{
/* Wait to be told there are message waiting to be logged. */
WaitForSingleObject( pvLoggingThreadEvent, xMaxWait );
/* Write out all waiting messages. */
prvLoggingFlushBuffer();
}
}
/*-----------------------------------------------------------*/
static void prvFileLoggingInit( void )
{
FILE * pxHandle = fopen( pcLogFileName, "a" );
if( pxHandle != NULL )
{
fseek( pxHandle, SEEK_END, 0ul );
ulSizeOfLoggingFile = ftell( pxHandle );
fclose( pxHandle );
}
else
{
ulSizeOfLoggingFile = 0ul;
}
}
/*-----------------------------------------------------------*/
static void prvFileClose( void )
{
if( pxLoggingFileHandle != NULL )
{
fclose( pxLoggingFileHandle );
pxLoggingFileHandle = NULL;
}
}
/*-----------------------------------------------------------*/
static void prvLogToFile( const char * pcMessage,
size_t xLength )
{
if( pxLoggingFileHandle == NULL )
{
pxLoggingFileHandle = fopen( pcLogFileName, "a" );
}
if( pxLoggingFileHandle != NULL )
{
fwrite( pcMessage, 1, xLength, pxLoggingFileHandle );
ulSizeOfLoggingFile += xLength;
/* If the file has grown to its maximum permissible size then close and
* rename it - then start with a new file. */
if( ulSizeOfLoggingFile > ( size_t ) dlLOGGING_FILE_SIZE )
{
prvFileClose();
if( _access( pcFullLogFileName, 00 ) == 0 )
{
remove( pcFullLogFileName );
}
rename( pcLogFileName, pcFullLogFileName );
ulSizeOfLoggingFile = 0;
}
}
}
/*-----------------------------------------------------------*/

@ -1,47 +0,0 @@
/*
* FreeRTOS Kernel V10.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef DEMO_LOGGING_H
#define DEMO_LOGGING_H
/*
* Initialize a logging system that can be used from FreeRTOS tasks and Win32
* threads. Do not call printf() directly while the scheduler is running.
*
* Set xLogToStdout, xLogToFile and xLogToUDP to either pdTRUE or pdFALSE to
* lot to stdout, a disk file and a UDP port respectively.
*
* If xLogToUDP is pdTRUE then ulRemoteIPAddress and usRemotePort must be set
* to the IP address and port number to which UDP log messages will be sent.
*/
void vLoggingInit( BaseType_t xLogToStdout,
BaseType_t xLogToFile,
BaseType_t xLogToUDP,
uint32_t ulRemoteIPAddress,
uint16_t usRemotePort );
#endif /* DEMO_LOGGING_H */

@ -46,7 +46,7 @@
#include "FreeRTOS_Sockets.h"
/* Demo logging includes. */
#include "demo_logging.h"
#include "logging.h"
/* Demo Specific configs. */
#include "demo_config.h"

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\Common\Logging;..\common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\Source\mbedtls_utils;..\..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\FreeRTOS-Plus\Source\Logging;..\common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\Source\mbedtls_utils;..\..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MBEDTLS_CONFIG_FILE="mbedtls_config.h";WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -485,7 +485,7 @@
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">TurnOffAllWarnings</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">TurnOffAllWarnings</WarningLevel>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\BasicTLSMQTTExample.c" />
</ItemGroup>
@ -513,6 +513,9 @@
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\mbedtls_error.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\threading_alt.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\transport\include\freertos_sockets_wrapper.h" />

@ -373,7 +373,7 @@
<ClCompile Include="..\..\..\ThirdParty\mbedtls\library\xtea.c">
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\BasicTLSMQTTExample.c">
<Filter>DemoTasks</Filter>

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\Common\Logging;..\Common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\FreeRTOS-Plus\Source\Logging;..\Common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -163,7 +163,7 @@
<ClCompile Include="..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_serializer.c" />
<ClCompile Include="..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_state.c" />
<ClCompile Include="..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt.c" />
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\KeepAliveMQTTExample.c" />
</ItemGroup>
@ -191,6 +191,9 @@
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\transport\include\plaintext_freertos.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\include\transport_interface.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\include\retry_utils.h" />

@ -106,7 +106,7 @@
<ClCompile Include="..\..\..\..\FreeRTOS\Source\stream_buffer.c">
<Filter>FreeRTOS\Source</Filter>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\KeepAliveMQTTExample.c">
<Filter>DemoTasks</Filter>

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\Common\Logging;..\common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\Source\mbedtls_utils;..\..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\FreeRTOS-Plus\Source\Logging;..\common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\Source\mbedtls_utils;..\..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MBEDTLS_CONFIG_FILE="mbedtls_config.h";WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -486,7 +486,7 @@
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">TurnOffAllWarnings</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">TurnOffAllWarnings</WarningLevel>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\MultitaskMQTTExample.c" />
</ItemGroup>
@ -514,6 +514,9 @@
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\mbedtls_error.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\threading_alt.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\transport\include\freertos_sockets_wrapper.h" />

@ -373,7 +373,7 @@
<ClCompile Include="..\..\..\ThirdParty\mbedtls\library\xtea.c">
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\MultitaskMQTTExample.c">
<Filter>DemoTasks</Filter>

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\Common\Logging;..\common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\Source\mbedtls_utils;..\..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\FreeRTOS-Plus\Source\Logging;..\common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\..\..\Source\mbedtls_utils;..\..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MBEDTLS_CONFIG_FILE="mbedtls_config.h";WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -485,7 +485,7 @@
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">TurnOffAllWarnings</WarningLevel>
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">TurnOffAllWarnings</WarningLevel>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\MutualAuthMQTTExample.c" />
</ItemGroup>
@ -513,6 +513,9 @@
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\mbedtls_error.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\threading_alt.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\transport\include\freertos_sockets_wrapper.h" />

@ -373,7 +373,7 @@
<ClCompile Include="..\..\..\ThirdParty\mbedtls\library\xtea.c">
<Filter>FreeRTOS+\mbedtls\library</Filter>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\MutualAuthMQTTExample.c">
<Filter>DemoTasks</Filter>

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\Common\Logging;..\Common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\FreeRTOS-Plus\Source\Logging;..\Common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\platform\freertos\transport\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -163,7 +163,7 @@
<ClCompile Include="..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_serializer.c" />
<ClCompile Include="..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_state.c" />
<ClCompile Include="..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt.c" />
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\PlainTextMQTTExample.c" />
</ItemGroup>
@ -191,6 +191,9 @@
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\transport\include\freertos_sockets_wrapper.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\transport\include\plaintext_freertos.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\include\transport_interface.h" />

@ -106,7 +106,7 @@
<ClCompile Include="..\..\..\..\FreeRTOS\Source\stream_buffer.c">
<Filter>FreeRTOS\Source</Filter>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\PlainTextMQTTExample.c">
<Filter>DemoTasks</Filter>

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\Common\Logging;..\Common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\coreMQTT\source\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\FreeRTOS-Plus\Source\Logging;..\Common\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\Application-Protocols\platform\include;..\..\..\Source\Application-Protocols\coreMQTT\source\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -159,7 +159,7 @@
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\NetworkInterface\WinPCap\NetworkInterface.c" />
<ClCompile Include="..\..\..\Source\Application-Protocols\platform\freertos\retry_utils\retry_utils_freertos.c" />
<ClCompile Include="..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_serializer.c" />
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\SerializerMQTTExample.c" />
</ItemGroup>

@ -106,7 +106,7 @@
<ClCompile Include="..\..\..\..\FreeRTOS\Source\stream_buffer.c">
<Filter>FreeRTOS\Source</Filter>
</ClCompile>
<ClCompile Include="..\Common\demo_logging.c" />
<ClCompile Include="..\..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\Common\main.c" />
<ClCompile Include="DemoTasks\SerializerMQTTExample.c">
<Filter>DemoTasks</Filter>

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\Common\Logging;..\coreMQTT_Windows_Simulator\Common;..\coreMQTT_Windows_Simulator\common\WinPCap;..\..\..\FreeRTOS\Source\include;..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\3rdparty\pkcs11;..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\Source\Application-Protocols\platform\include;..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\Source\mbedtls_utils;..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\FreeRTOS-Plus\Source\Logging;..\coreMQTT_Windows_Simulator\Common;..\coreMQTT_Windows_Simulator\common\WinPCap;..\..\..\FreeRTOS\Source\include;..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\Source\corePKCS11\source\include;..\..\Source\corePKCS11\3rdparty\pkcs11;..\..\Source\Application-Protocols\coreMQTT\source\include;..\..\Source\Application-Protocols\platform\include;..\..\Source\Application-Protocols\platform\freertos\transport\include;..\..\Source\Application-Protocols\platform\freertos\mbedtls;..\..\Source\mbedtls_utils;..\..\ThirdParty\mbedtls\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>MBEDTLS_CONFIG_FILE="mbedtls_config.h";WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -164,6 +164,7 @@
<ClCompile Include="..\..\..\FreeRTOS-Plus\Source\Application-Protocols\coreMQTT\source\core_mqtt_serializer.c" />
<ClCompile Include="..\..\..\FreeRTOS-Plus\Source\Application-Protocols\coreMQTT\source\core_mqtt_state.c" />
<ClCompile Include="..\..\..\FreeRTOS-Plus\Source\Application-Protocols\coreMQTT\source\core_mqtt.c" />
<ClCompile Include="..\..\..\FreeRTOS-Plus\Source\Logging\logging.c" />
<ClCompile Include="..\..\Source\Application-Protocols\platform\freertos\transport\src\tls_freertos_pkcs11.c" />
<ClCompile Include="..\..\Source\corePKCS11\source\core_pkcs11.c" />
<ClCompile Include="..\..\Source\corePKCS11\source\core_pki_utils.c" />
@ -255,7 +256,6 @@
<ClCompile Include="..\..\ThirdParty\mbedtls\library\x509_crt.c" />
<ClCompile Include="..\..\ThirdParty\mbedtls\library\x509_csr.c" />
<ClCompile Include="..\..\ThirdParty\mbedtls\library\xtea.c" />
<ClCompile Include="..\coreMQTT_Windows_Simulator\Common\demo_logging.c" />
<ClCompile Include="DemoTasks\MutualAuthMQTTExample.c" />
<ClCompile Include="main.c" />
</ItemGroup>
@ -283,6 +283,9 @@
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\mbedtls_error.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\mbedtls\threading_alt.h" />
<ClInclude Include="..\..\..\Source\Application-Protocols\platform\freertos\transport\include\freertos_sockets_wrapper.h" />

@ -179,7 +179,7 @@
<Filter>Transport</Filter>
</ClCompile>
<ClCompile Include="main.c" />
<ClCompile Include="..\coreMQTT_Windows_Simulator\Common\demo_logging.c">
<ClCompile Include="..\..\..\FreeRTOS-Plus\Logging\logging.c">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\..\Source\corePKCS11\source\core_pkcs11.c">

@ -49,7 +49,7 @@
#include "demo_config.h"
/* Demo logging includes. */
#include "demo_logging.h"
#include "logging.h"
/*
* Prototypes for the demos that can be started from this project. Note the

@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\FreeRTOS-Plus\Demo\Common\Logging;..\..\..\FreeRTOS-Plus\Source\corePKCS11\source\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\source\portable\mbedtls\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\pkcs11;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\mbedtls\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\mbedtls_utils;..\..\..\FreeRTOS\Source\include;..\..\..\FreeRTOS\Source\portable\MSVC-MingW;examples;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\FreeRTOS-Plus\Source\Logging;..\..\..\FreeRTOS-Plus\Source\corePKCS11\source\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\source\portable\mbedtls\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\pkcs11;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\mbedtls\include;..\..\..\FreeRTOS-Plus\Source\corePKCS11\3rdparty\mbedtls_utils;..\..\..\FreeRTOS\Source\include;..\..\..\FreeRTOS\Source\portable\MSVC-MingW;examples;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;MBEDTLS_CONFIG_FILE="aws_mbedtls_config.h";CONFIG_MEDTLS_USE_AFR_MEMORY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -149,6 +149,9 @@
<ClCompile Include="..\..\..\FreeRTOS\Source\stream_buffer.c" />
<ClCompile Include="..\..\..\FreeRTOS\Source\tasks.c" />
<ClCompile Include="..\..\..\FreeRTOS\Source\timers.c" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\Logging\logging.h" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\Logging\logging_levels.h" />
<ClInclude Include="..\..\..\FreeRTOS-Plus\Source\Logging\logging_stack.h" />
<ClCompile Include="..\..\Source\corePKCS11\3rdparty\mbedtls\library\aes.c" />
<ClCompile Include="..\..\Source\corePKCS11\3rdparty\mbedtls\library\aesni.c" />
<ClCompile Include="..\..\Source\corePKCS11\3rdparty\mbedtls\library\arc4.c" />
@ -337,8 +340,6 @@
<ClInclude Include="..\..\Source\corePKCS11\source\include\core_pkcs11_pal.h" />
<ClInclude Include="..\..\Source\corePKCS11\source\include\core_pki_utils.h" />
<ClInclude Include="..\..\Source\corePKCS11\source\portable\mbedtls\threading_alt.h" />
<ClInclude Include="..\Common\Logging\logging_levels.h" />
<ClInclude Include="..\Common\Logging\logging_stack.h" />
<ClInclude Include="aws_mbedtls_config.h" />
<ClInclude Include="examples\demo_helpers.h" />
<ClInclude Include="examples\pkcs11_demos.h" />

@ -52,7 +52,7 @@
#include "FreeRTOS_Stream_Buffer.h"
/* Demo includes. */
#include "demo_logging.h"
#include "logging.h"
/*-----------------------------------------------------------*/

@ -1,526 +0,0 @@
/*
* FreeRTOS Kernel V10.4.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/*
* Logging utility that allows FreeRTOS tasks to log to a UDP port, stdout, and
* disk file without making any Win32 system calls themselves.
*
* Messages logged to a UDP port are sent directly (using FreeRTOS+TCP), but as
* FreeRTOS tasks cannot make Win32 system calls messages sent to stdout or a
* disk file are sent via a stream buffer to a Win32 thread which then performs
* the actual output.
*/
/* Standard includes. */
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <io.h>
#include <ctype.h>
/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_Stream_Buffer.h"
/* Demo includes. */
#include "demo_logging.h"
/*-----------------------------------------------------------*/
/* The maximum size to which the log file may grow, before being renamed
to .ful. */
#define dlLOGGING_FILE_SIZE ( 40ul * 1024ul * 1024ul )
/* Dimensions the arrays into which print messages are created. */
#define dlMAX_PRINT_STRING_LENGTH 255
/* The size of the stream buffer used to pass messages from FreeRTOS tasks to
the Win32 thread that is responsible for making any Win32 system calls that are
necessary for the selected logging method. */
#define dlLOGGING_STREAM_BUFFER_SIZE 32768
/* A block time of zero simply means don't block. */
#define dlDONT_BLOCK 0
/*-----------------------------------------------------------*/
/*
* Called from vLoggingInit() to start a new disk log file.
*/
static void prvFileLoggingInit( void );
/*
* Attempt to write a message to the file.
*/
static void prvLogToFile( const char *pcMessage, size_t xLength );
/*
* Simply close the logging file, if it is open.
*/
static void prvFileClose( void );
/*
* Before the scheduler is started this function is called directly. After the
* scheduler has started it is called from the Windows thread dedicated to
* outputting log messages. Only the windows thread actually performs the
* writing so as not to disrupt the simulation by making Windows system calls
* from FreeRTOS tasks.
*/
static void prvLoggingFlushBuffer( void );
/*
* The windows thread that performs the actual writing of messages that require
* Win32 system calls. Only the windows thread can make system calls so as not
* to disrupt the simulation by making Windows calls from FreeRTOS tasks.
*/
static DWORD WINAPI prvWin32LoggingThread( void *pvParam );
/*
* Creates the socket to which UDP messages are sent. This function is not
* called directly to prevent the print socket being created from within the IP
* task - which could result in a deadlock. Instead the function call is
* deferred to run in the RTOS daemon task - hence it prototype.
*/
static void prvCreatePrintSocket( void *pvParameter1, uint32_t ulParameter2 );
/*-----------------------------------------------------------*/
/* Windows event used to wake the Win32 thread which performs any logging that
needs Win32 system calls. */
static void *pvLoggingThreadEvent = NULL;
/* Stores the selected logging targets passed in as parameters to the
vLoggingInit() function. */
BaseType_t xStdoutLoggingUsed = pdFALSE, xDiskFileLoggingUsed = pdFALSE, xUDPLoggingUsed = pdFALSE;
/* Circular buffer used to pass messages from the FreeRTOS tasks to the Win32
thread that is responsible for making Win32 calls (when stdout or a disk log is
used). */
static StreamBuffer_t *xLogStreamBuffer = NULL;
/* Handle to the file used for logging. This is left open while there are
messages waiting to be logged, then closed again in between logs. */
static FILE *pxLoggingFileHandle = NULL;
/* When true prints are performed directly. After start up xDirectPrint is set
to pdFALSE - at which time prints that require Win32 system calls are done by
the Win32 thread responsible for logging. */
BaseType_t xDirectPrint = pdTRUE;
/* File names for the in use and complete (full) log files. */
static const char *pcLogFileName = "RTOSDemo.log";
static const char *pcFullLogFileName = "RTOSDemo.ful";
/* Keep the current file size in a variable, as an optimisation. */
static size_t ulSizeOfLoggingFile = 0ul;
/* The UDP socket and address on/to which print messages are sent. */
Socket_t xPrintSocket = FREERTOS_INVALID_SOCKET;
struct freertos_sockaddr xPrintUDPAddress;
/*-----------------------------------------------------------*/
void vLoggingInit( BaseType_t xLogToStdout, BaseType_t xLogToFile, BaseType_t xLogToUDP, uint32_t ulRemoteIPAddress, uint16_t usRemotePort )
{
/* Can only be called before the scheduler has started. */
configASSERT( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED );
#if( ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) )
{
HANDLE Win32Thread;
/* Record which output methods are to be used. */
xStdoutLoggingUsed = xLogToStdout;
xDiskFileLoggingUsed = xLogToFile;
xUDPLoggingUsed = xLogToUDP;
/* If a disk file is used then initialise it now. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvFileLoggingInit();
}
/* If UDP logging is used then store the address to which the log data
will be sent - but don't create the socket yet because the network is
not initialised. */
if( xUDPLoggingUsed != pdFALSE )
{
/* Set the address to which the print messages are sent. */
xPrintUDPAddress.sin_port = FreeRTOS_htons( usRemotePort );
xPrintUDPAddress.sin_addr = ulRemoteIPAddress;
}
/* If a disk file or stdout are to be used then Win32 system calls will
have to be made. Such system calls cannot be made from FreeRTOS tasks
so create a stream buffer to pass the messages to a Win32 thread, then
create the thread itself, along with a Win32 event that can be used to
unblock the thread. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
/* Create the buffer. */
xLogStreamBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) + dlLOGGING_STREAM_BUFFER_SIZE + 1 );
configASSERT( xLogStreamBuffer );
memset( xLogStreamBuffer, '\0', sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) );
xLogStreamBuffer->LENGTH = dlLOGGING_STREAM_BUFFER_SIZE + 1;
/* Create the Windows event. */
pvLoggingThreadEvent = CreateEvent( NULL, FALSE, TRUE, "StdoutLoggingEvent" );
/* Create the thread itself. */
Win32Thread = CreateThread(
NULL, /* Pointer to thread security attributes. */
0, /* Initial thread stack size, in bytes. */
prvWin32LoggingThread, /* Pointer to thread function. */
NULL, /* Argument for new thread. */
0, /* Creation flags. */
NULL );
/* Use the cores that are not used by the FreeRTOS tasks. */
SetThreadAffinityMask( Win32Thread, ~0x01u );
SetThreadPriorityBoost( Win32Thread, TRUE );
SetThreadPriority( Win32Thread, THREAD_PRIORITY_IDLE );
}
}
#else
{
/* FreeRTOSIPConfig is set such that no print messages will be output.
Avoid compiler warnings about unused parameters. */
( void ) xLogToStdout;
( void ) xLogToFile;
( void ) xLogToUDP;
( void ) usRemotePort;
( void ) ulRemoteIPAddress;
}
#endif /* ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) */
}
/*-----------------------------------------------------------*/
static void prvCreatePrintSocket( void *pvParameter1, uint32_t ulParameter2 )
{
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 0 );
Socket_t xSocket;
/* The function prototype is that of a deferred function, but the parameters
are not actually used. */
( void ) pvParameter1;
( void ) ulParameter2;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
/* FreeRTOS+TCP decides which port to bind to. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
FreeRTOS_bind( xSocket, NULL, 0 );
/* Now the socket is bound it can be assigned to the print socket. */
xPrintSocket = xSocket;
}
}
/*-----------------------------------------------------------*/
void vLoggingPrintf( const char *pcFormat, ... )
{
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
char cOutputString[ dlMAX_PRINT_STRING_LENGTH ];
char *pcSource, *pcTarget, *pcBegin;
size_t xLength, xLength2, rc;
static BaseType_t xMessageNumber = 0;
va_list args;
uint32_t ulIPAddress;
const char *pcTaskName;
const char *pcNoTask = "None";
int iOriginalPriority;
HANDLE xCurrentTask;
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) || ( xUDPLoggingUsed != pdFALSE ) )
{
/* There are a variable number of parameters. */
va_start( args, pcFormat );
/* Additional info to place at the start of the log. */
if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )
{
pcTaskName = pcTaskGetName( NULL );
}
else
{
pcTaskName = pcNoTask;
}
if( strcmp( pcFormat, "\n" ) != 0 )
{
xLength = snprintf( cPrintString, dlMAX_PRINT_STRING_LENGTH, "%lu %lu [%s] ",
xMessageNumber++,
( unsigned long ) xTaskGetTickCount(),
pcTaskName );
}
else
{
xLength = 0;
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
}
xLength2 = vsnprintf( cPrintString + xLength, dlMAX_PRINT_STRING_LENGTH - xLength, pcFormat, args );
if( xLength2 < 0 )
{
/* Clean up. */
xLength2 = dlMAX_PRINT_STRING_LENGTH - 1 - xLength;
cPrintString[ dlMAX_PRINT_STRING_LENGTH - 1 ] = '\0';
}
xLength += xLength2;
va_end( args );
/* For ease of viewing, copy the string into another buffer, converting
IP addresses to dot notation on the way. */
pcSource = cPrintString;
pcTarget = cOutputString;
while( ( *pcSource ) != '\0' )
{
*pcTarget = *pcSource;
pcTarget++;
pcSource++;
/* Look forward for an IP address denoted by 'ip'. */
if( ( isxdigit( pcSource[ 0 ] ) != pdFALSE ) && ( pcSource[ 1 ] == 'i' ) && ( pcSource[ 2 ] == 'p' ) )
{
*pcTarget = *pcSource;
pcTarget++;
*pcTarget = '\0';
pcBegin = pcTarget - 8;
while( ( pcTarget > pcBegin ) && ( isxdigit( pcTarget[ -1 ] ) != pdFALSE ) )
{
pcTarget--;
}
sscanf( pcTarget, "%8X", &ulIPAddress );
rc = sprintf( pcTarget, "%lu.%lu.%lu.%lu",
( unsigned long ) ( ulIPAddress >> 24UL ),
( unsigned long ) ( (ulIPAddress >> 16UL) & 0xffUL ),
( unsigned long ) ( (ulIPAddress >> 8UL) & 0xffUL ),
( unsigned long ) ( ulIPAddress & 0xffUL ) );
pcTarget += rc;
pcSource += 3; /* skip "<n>ip" */
}
}
/* How far through the buffer was written? */
xLength = ( BaseType_t ) ( pcTarget - cOutputString );
/* If the message is to be logged to a UDP port then it can be sent directly
because it only uses FreeRTOS function (not Win32 functions). */
if( xUDPLoggingUsed != pdFALSE )
{
if( ( xPrintSocket == FREERTOS_INVALID_SOCKET ) && ( FreeRTOS_IsNetworkUp() != pdFALSE ) )
{
/* Create and bind the socket to which print messages are sent. The
xTimerPendFunctionCall() function is used even though this is
not an interrupt because this function is called from the IP task
and the IP task cannot itself wait for a socket to bind. The
parameters to prvCreatePrintSocket() are not required so set to
NULL or 0. */
xTimerPendFunctionCall( prvCreatePrintSocket, NULL, 0, dlDONT_BLOCK );
}
if( xPrintSocket != FREERTOS_INVALID_SOCKET )
{
FreeRTOS_sendto( xPrintSocket, cOutputString, xLength, 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
/* Just because the UDP data logger I'm using is dumb. */
FreeRTOS_sendto( xPrintSocket, "\r", sizeof( char ), 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
}
}
/* If logging is also to go to either stdout or a disk file then it cannot
be output here - so instead write the message to the stream buffer and wake
the Win32 thread which will read it from the stream buffer and perform the
actual output. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
configASSERT( xLogStreamBuffer );
/* How much space is in the buffer? */
xLength2 = uxStreamBufferGetSpace( xLogStreamBuffer );
/* There must be enough space to write both the string and the length of
the string. */
if( xLength2 >= ( xLength + sizeof( xLength ) ) )
{
/* First write in the length of the data, then write in the data
itself. Raising the thread priority is used as a critical section
as there are potentially multiple writers. The stream buffer is
only thread safe when there is a single writer (likewise for
reading from the buffer). */
xCurrentTask = GetCurrentThread();
iOriginalPriority = GetThreadPriority( xCurrentTask );
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) &( xLength ), sizeof( xLength ) );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) cOutputString, xLength );
SetThreadPriority( GetCurrentThread(), iOriginalPriority );
}
/* xDirectPrint is initialised to pdTRUE, and while it remains true the
logging output function is called directly. When the system is running
the output function cannot be called directly because it would get
called from both FreeRTOS tasks and Win32 threads - so instead wake the
Win32 thread responsible for the actual output. */
if( xDirectPrint != pdFALSE )
{
/* While starting up, the thread which calls prvWin32LoggingThread()
is not running yet and xDirectPrint will be pdTRUE. */
prvLoggingFlushBuffer();
}
else if( pvLoggingThreadEvent != NULL )
{
/* While running, wake up prvWin32LoggingThread() to send the
logging data. */
SetEvent( pvLoggingThreadEvent );
}
}
}
}
/*-----------------------------------------------------------*/
static void prvLoggingFlushBuffer( void )
{
size_t xLength;
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
/* Is there more than the length value stored in the circular buffer
used to pass data from the FreeRTOS simulator into this Win32 thread? */
while( uxStreamBufferGetSize( xLogStreamBuffer ) > sizeof( xLength ) )
{
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) &xLength, sizeof( xLength ), pdFALSE );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) cPrintString, xLength, pdFALSE );
/* Write the message to standard out if requested to do so when
vLoggingInit() was called, or if the network is not yet up. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( FreeRTOS_IsNetworkUp() == pdFALSE ) )
{
/* Write the message to stdout. */
printf( "%s", cPrintString ); /*_RB_ Replace with _write(). */
}
/* Write the message to a file if requested to do so when
vLoggingInit() was called. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvLogToFile( cPrintString, xLength );
}
}
prvFileClose();
}
/*-----------------------------------------------------------*/
static DWORD WINAPI prvWin32LoggingThread( void *pvParameter )
{
const DWORD xMaxWait = 1000;
( void ) pvParameter;
/* From now on, prvLoggingFlushBuffer() will only be called from this
Windows thread */
xDirectPrint = pdFALSE;
for( ;; )
{
/* Wait to be told there are message waiting to be logged. */
WaitForSingleObject( pvLoggingThreadEvent, xMaxWait );
/* Write out all waiting messages. */
prvLoggingFlushBuffer();
}
}
/*-----------------------------------------------------------*/
static void prvFileLoggingInit( void )
{
FILE *pxHandle = fopen( pcLogFileName, "a" );
if( pxHandle != NULL )
{
fseek( pxHandle, SEEK_END, 0ul );
ulSizeOfLoggingFile = ftell( pxHandle );
fclose( pxHandle );
}
else
{
ulSizeOfLoggingFile = 0ul;
}
}
/*-----------------------------------------------------------*/
static void prvFileClose( void )
{
if( pxLoggingFileHandle != NULL )
{
fclose( pxLoggingFileHandle );
pxLoggingFileHandle = NULL;
}
}
/*-----------------------------------------------------------*/
static void prvLogToFile( const char *pcMessage, size_t xLength )
{
if( pxLoggingFileHandle == NULL )
{
pxLoggingFileHandle = fopen( pcLogFileName, "a" );
}
if( pxLoggingFileHandle != NULL )
{
fwrite( pcMessage, 1, xLength, pxLoggingFileHandle );
ulSizeOfLoggingFile += xLength;
/* If the file has grown to its maximum permissible size then close and
rename it - then start with a new file. */
if( ulSizeOfLoggingFile > ( size_t ) dlLOGGING_FILE_SIZE )
{
prvFileClose();
if( _access( pcFullLogFileName, 00 ) == 0 )
{
remove( pcFullLogFileName );
}
rename( pcLogFileName, pcFullLogFileName );
ulSizeOfLoggingFile = 0;
}
}
}
/*-----------------------------------------------------------*/

@ -1,48 +0,0 @@
/*
* FreeRTOS Kernel V10.4.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef DEMO_LOGGING_H
#define DEMO_LOGGING_H
/*
* Initialise a logging system that can be used from FreeRTOS tasks and Win32
* threads. Do not call printf() directly while the scheduler is running.
*
* Set xLogToStdout, xLogToFile and xLogToUDP to either pdTRUE or pdFALSE to
* lot to stdout, a disk file and a UDP port respectively.
*
* If xLogToUDP is pdTRUE then ulRemoteIPAddress and usRemotePort must be set
* to the IP address and port number to which UDP log messages will be sent.
*/
void vLoggingInit( BaseType_t xLogToStdout,
BaseType_t xLogToFile,
BaseType_t xLogToUDP,
uint32_t ulRemoteIPAddress,
uint16_t usRemotePort );
#endif /* DEMO_LOGGING_H */

@ -62,7 +62,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\Logging;.\Test_Code\Test_Runner;..\..\..\CMock\vendor\unity\src;..\..\..\CMock\vendor\unity\extras\fixture\src;.\Config;..\..\..\CMock\vendor\unity\extras\memory\src;..\..\..\..\Source\FreeRTOS-Plus-FAT\include;..\..\..\..\Source\FreeRTOS-Plus-FAT\portable\common;..\..\..\..\Source\FreeRTOS-Plus-TCP\protocols\include;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\FreeRTOS-Plus-CLI;.\Test_Code\Test_Cases;..\..\..\..\Source\FreeRTOS-Plus-TCP\include;.\DemoTasks\include;.\TraceMacros\Example1;.\WinPCap;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\Logging;.\Test_Code\Test_Runner;..\..\..\CMock\vendor\unity\src;..\..\..\CMock\vendor\unity\extras\fixture\src;.\Config;..\..\..\CMock\vendor\unity\extras\memory\src;..\..\..\..\Source\FreeRTOS-Plus-FAT\include;..\..\..\..\Source\FreeRTOS-Plus-FAT\portable\common;..\..\..\..\Source\FreeRTOS-Plus-TCP\protocols\include;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\FreeRTOS-Plus-CLI;.\Test_Code\Test_Cases;..\..\..\..\Source\FreeRTOS-Plus-TCP\include;.\DemoTasks\include;.\TraceMacros\Example1;.\WinPCap;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;FREERTOS_ENABLE_UNIT_TESTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -162,7 +162,7 @@
<ClCompile Include="..\..\..\CMock\vendor\unity\extras\fixture\src\unity_fixture.c" />
<ClCompile Include="..\..\..\CMock\vendor\unity\extras\memory\src\unity_memory.c" />
<ClCompile Include="..\..\..\CMock\vendor\unity\src\unity.c" />
<ClCompile Include="Logging\demo_logging.c" />
<ClCompile Include="..\..\..\..\Source\Logging\logging.c" />
<ClCompile Include="main.c" />
<ClCompile Include="Test_code\Test_Cases\test_freertos_tcp.c" />
<ClCompile Include="Test_code\Test_Runner\test_runner.c" />

@ -116,7 +116,7 @@
<Filter>Test_Code\Test_Runner</Filter>
</ClCompile>
<ClCompile Include="main.c" />
<ClCompile Include="Logging\demo_logging.c" />
<ClCompile Include="..\..\..\..\Source\Logging\logging.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\FreeRTOS\Source\include\event_groups.h">

@ -1,5 +1,5 @@
/*
* FreeRTOS
* FreeRTOS
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@ -23,12 +23,12 @@
* http://www.FreeRTOS.org
*/
/**
* @file main.c
* @brief Implements the main function.
*/
/**
* @file main.c
* @brief Implements the main function.
*/
/* FreeRTOS include. */
/* FreeRTOS include. */
#include <FreeRTOS.h>
#include "task.h"
@ -46,11 +46,11 @@
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_DHCP.h"
#include "demo_logging.h"
#include "logging.h"
#include "errhandlingapi.h"
//#include "iot_system_init.h"
/*#include "iot_system_init.h" */
//#include "aws_dev_mode_key_provisioning.h"
/*#include "aws_dev_mode_key_provisioning.h" */
/* Unity includes. */
#include "unity.h"
@ -64,8 +64,8 @@
#define TEST_RUNNER_TASK_STACK_SIZE 10000
#define FIRST_EXCEPTION_HANDLER 1
/* Windows-NT VectoredHandler callback function. */
static LONG CALLBACK prvExceptionHandler(_In_ PEXCEPTION_POINTERS ExceptionInfo);
/* Windows-NT VectoredHandler callback function. */
static LONG CALLBACK prvExceptionHandler( _In_ PEXCEPTION_POINTERS ExceptionInfo );
jmp_buf xMark; /* Address for long jump to jump to. */
/*-----------------------------------------------------------*/
@ -78,7 +78,7 @@ static BaseType_t xTraceRunning = pdTRUE;
* to and from a real network connection on the host PC. See the
* configNETWORK_INTERFACE_TO_USE definition for information on how to configure
* the real network connection to use. */
const uint8_t ucMACAddress[6] =
const uint8_t ucMACAddress[ 6 ] =
{
configMAC_ADDR0,
configMAC_ADDR1,
@ -93,28 +93,28 @@ const uint8_t ucMACAddress[6] =
* 1 but a DHCP server could not be contacted. See the online documentation for
* more information. In both cases the node can be discovered using
* "ping RTOSDemo". */
static const uint8_t ucIPAddress[4] =
static const uint8_t ucIPAddress[ 4 ] =
{
configIP_ADDR0,
configIP_ADDR1,
configIP_ADDR2,
configIP_ADDR3
};
static const uint8_t ucNetMask[4] =
static const uint8_t ucNetMask[ 4 ] =
{
configNET_MASK0,
configNET_MASK1,
configNET_MASK2,
configNET_MASK3
};
static const uint8_t ucGatewayAddress[4] =
static const uint8_t ucGatewayAddress[ 4 ] =
{
configGATEWAY_ADDR0,
configGATEWAY_ADDR1,
configGATEWAY_ADDR2,
configGATEWAY_ADDR3
};
static const uint8_t ucDNSServerAddress[4] =
static const uint8_t ucDNSServerAddress[ 4 ] =
{
configDNS_SERVER_ADDR0,
configDNS_SERVER_ADDR1,
@ -126,10 +126,10 @@ static const uint8_t ucDNSServerAddress[4] =
static UBaseType_t ulNextRand;
/*-----------------------------------------------------------*/
int main(void)
int main( void )
{
/* Register the Windows VEH for exceptions. */
//AddVectoredExceptionHandler(FIRST_EXCEPTION_HANDLER, prvExceptionHandler);
/*AddVectoredExceptionHandler(FIRST_EXCEPTION_HANDLER, prvExceptionHandler); */
/* Initialize logging for libraries that depend on it. */
vLoggingInit(
@ -137,7 +137,7 @@ int main(void)
pdFALSE,
pdFALSE,
0,
0);
0 );
/* Initialize the network interface.
*
@ -146,13 +146,13 @@ int main(void)
* vApplicationIPNetworkEventHook() below). The address values passed in here
* are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
* but a DHCP server cannot be contacted. */
FreeRTOS_printf(("FreeRTOS_IPInit\n"));
FreeRTOS_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit(
ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress);
ucMACAddress );
vTaskStartScheduler();
@ -160,18 +160,18 @@ int main(void)
}
/*-----------------------------------------------------------*/
void vApplicationIPNetworkEventHook(eIPCallbackEvent_t eNetworkEvent)
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if ((eNetworkEvent == eNetworkUp) && (xTasksAlreadyCreated == pdFALSE))
if( ( eNetworkEvent == eNetworkUp ) && ( xTasksAlreadyCreated == pdFALSE ) )
{
xTaskCreate(TEST_RUNNER_RunTests_task,
"TestRunner",
TEST_RUNNER_TASK_STACK_SIZE,
NULL,
tskIDLE_PRIORITY, NULL);
xTaskCreate( TEST_RUNNER_RunTests_task,
"TestRunner",
TEST_RUNNER_TASK_STACK_SIZE,
NULL,
tskIDLE_PRIORITY, NULL );
xTasksAlreadyCreated = pdTRUE;
}
@ -179,7 +179,7 @@ void vApplicationIPNetworkEventHook(eIPCallbackEvent_t eNetworkEvent)
/*-----------------------------------------------------------*/
static LONG CALLBACK prvExceptionHandler(_In_ PEXCEPTION_POINTERS ExceptionInfo)
static LONG CALLBACK prvExceptionHandler( _In_ PEXCEPTION_POINTERS ExceptionInfo )
{
/* If this function is called during a test, the test immediately fails. */
TEST_FAIL();
@ -193,48 +193,48 @@ static LONG CALLBACK prvExceptionHandler(_In_ PEXCEPTION_POINTERS ExceptionInfo)
( ipconfigUSE_NBNS != 0 ) || \
( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) )
const char* pcApplicationHostnameHook(void)
{
/* This function will be called during the DHCP: the machine will be registered
* with an IP address plus this name. */
return mainHOST_NAME;
}
const char * pcApplicationHostnameHook( void )
{
/* This function will be called during the DHCP: the machine will be registered
* with an IP address plus this name. */
return mainHOST_NAME;
}
#endif /* if ( ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) ) */
/*-----------------------------------------------------------*/
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
BaseType_t xApplicationDNSQueryHook(const char* pcName)
{
BaseType_t xReturn;
/* Determine if a name lookup is for this node. Two names are given
* to this node: that returned by pcApplicationHostnameHook() and that set
* by mainDEVICE_NICK_NAME. */
if (_stricmp(pcName, pcApplicationHostnameHook()) == 0)
{
xReturn = pdPASS;
}
else if (_stricmp(pcName, mainDEVICE_NICK_NAME) == 0)
BaseType_t xApplicationDNSQueryHook( const char * pcName )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
BaseType_t xReturn;
return xReturn;
}
/* Determine if a name lookup is for this node. Two names are given
* to this node: that returned by pcApplicationHostnameHook() and that set
* by mainDEVICE_NICK_NAME. */
if( _stricmp( pcName, pcApplicationHostnameHook() ) == 0 )
{
xReturn = pdPASS;
}
else if( _stricmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
/*-----------------------------------------------------------*/
void vApplicationIdleHook(void)
void vApplicationIdleHook( void )
{
const uint32_t ulMSToSleep = 1;
const TickType_t xKitHitCheckPeriod = pdMS_TO_TICKS(1000UL);
const TickType_t xKitHitCheckPeriod = pdMS_TO_TICKS( 1000UL );
static TickType_t xTimeNow, xLastTimeCheck = 0;
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
@ -247,19 +247,17 @@ void vApplicationIdleHook(void)
* because it is the responsibility of the idle task to clean up memory
* allocated by the kernel to any task that has since deleted itself. */
/* _kbhit() is a Windows system function, and system functions can cause
* crashes if they somehow block the FreeRTOS thread. The call to _kbhit()
* can be removed if it causes problems. Limiting the frequency of calls to
* _kbhit() should minimize the potential for issues. */
/* _kbhit() is a Windows system function, and system functions can cause
* crashes if they somehow block the FreeRTOS thread. The call to _kbhit()
* can be removed if it causes problems. Limiting the frequency of calls to
* _kbhit() should minimize the potential for issues. */
xTimeNow = xTaskGetTickCount();
if ((xTimeNow - xLastTimeCheck) > xKitHitCheckPeriod)
if( ( xTimeNow - xLastTimeCheck ) > xKitHitCheckPeriod )
{
/* Uncomment the print line to get confirmation that tests are still
* running if you suspect a previous run resulted in a crash. */
/* configPRINTF( ( "Running...\n" ) ); /**/
/* configPRINTF( ( "Running...\n" ) ); /**/
xLastTimeCheck = xTimeNow;
}
@ -267,53 +265,53 @@ void vApplicationIdleHook(void)
* cycle of the idle task if configUSE_IDLE_HOOK is set to 1 in
* FreeRTOSConfig.h. It must *NOT* attempt to block. In this case the
* idle task just sleeps to lower the CPU usage. */
Sleep(ulMSToSleep);
Sleep( ulMSToSleep );
}
/*-----------------------------------------------------------*/
void vAssertCalled(const char* pcFile,
uint32_t ulLine)
void vAssertCalled( const char * pcFile,
uint32_t ulLine )
{
const uint32_t ulLongSleep = 1000UL;
volatile uint32_t ulBlockVariable = 0UL;
volatile char* pcFileName = (volatile char*)pcFile;
volatile char * pcFileName = ( volatile char * ) pcFile;
volatile uint32_t ulLineNumber = ulLine;
(void)pcFileName;
(void)ulLineNumber;
( void ) pcFileName;
( void ) ulLineNumber;
printf("vAssertCalled %s, %ld\n", pcFile, (long)ulLine);
fflush(stdout);
printf( "vAssertCalled %s, %ld\n", pcFile, ( long ) ulLine );
fflush( stdout );
/* Setting ulBlockVariable to a non-zero value in the debugger will allow
* this function to be exited. */
taskDISABLE_INTERRUPTS();
{
while (ulBlockVariable == 0UL)
while( ulBlockVariable == 0UL )
{
Sleep(ulLongSleep);
Sleep( ulLongSleep );
}
}
taskENABLE_INTERRUPTS();
}
/*-----------------------------------------------------------*/
void getUserCmd(char* pucUserCmd)
void getUserCmd( char * pucUserCmd )
{
char cTmp;
scanf("%c%c", pucUserCmd, &cTmp);
scanf( "%c%c", pucUserCmd, &cTmp );
}
/*-----------------------------------------------------------*/
UBaseType_t uxRand(void)
UBaseType_t uxRand( void )
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
/* Utility function to generate a pseudo random number. */
ulNextRand = (ulMultiplier * ulNextRand) + ulIncrement;
return((int)(ulNextRand >> 16UL) & 0x7fffUL);
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
}
BaseType_t xApplicationGetRandomNumber()
@ -327,15 +325,15 @@ BaseType_t xApplicationGetRandomNumber()
* THAT RETURNS A PSEUDO RANDOM NUMBER SO IS NOT INTENDED FOR USE IN PRODUCTION
* SYSTEMS.
*/
extern uint32_t ulApplicationGetNextSequenceNumber(uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort)
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
(void)ulSourceAddress;
(void)usSourcePort;
(void)ulDestinationAddress;
(void)usDestinationPort;
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
return uxRand();
}
}

@ -1,526 +0,0 @@
/*
* FreeRTOS Kernel V10.4.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/*
* Logging utility that allows FreeRTOS tasks to log to a UDP port, stdout, and
* disk file without making any Win32 system calls themselves.
*
* Messages logged to a UDP port are sent directly (using FreeRTOS+TCP), but as
* FreeRTOS tasks cannot make Win32 system calls messages sent to stdout or a
* disk file are sent via a stream buffer to a Win32 thread which then performs
* the actual output.
*/
/* Standard includes. */
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <io.h>
#include <ctype.h>
/* FreeRTOS includes. */
#include <FreeRTOS.h>
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_Stream_Buffer.h"
/* Demo includes. */
#include "demo_logging.h"
/*-----------------------------------------------------------*/
/* The maximum size to which the log file may grow, before being renamed
to .ful. */
#define dlLOGGING_FILE_SIZE ( 40ul * 1024ul * 1024ul )
/* Dimensions the arrays into which print messages are created. */
#define dlMAX_PRINT_STRING_LENGTH 255
/* The size of the stream buffer used to pass messages from FreeRTOS tasks to
the Win32 thread that is responsible for making any Win32 system calls that are
necessary for the selected logging method. */
#define dlLOGGING_STREAM_BUFFER_SIZE 32768
/* A block time of zero simply means don't block. */
#define dlDONT_BLOCK 0
/*-----------------------------------------------------------*/
/*
* Called from vLoggingInit() to start a new disk log file.
*/
static void prvFileLoggingInit( void );
/*
* Attempt to write a message to the file.
*/
static void prvLogToFile( const char *pcMessage, size_t xLength );
/*
* Simply close the logging file, if it is open.
*/
static void prvFileClose( void );
/*
* Before the scheduler is started this function is called directly. After the
* scheduler has started it is called from the Windows thread dedicated to
* outputting log messages. Only the windows thread actually performs the
* writing so as not to disrupt the simulation by making Windows system calls
* from FreeRTOS tasks.
*/
static void prvLoggingFlushBuffer( void );
/*
* The windows thread that performs the actual writing of messages that require
* Win32 system calls. Only the windows thread can make system calls so as not
* to disrupt the simulation by making Windows calls from FreeRTOS tasks.
*/
static DWORD WINAPI prvWin32LoggingThread( void *pvParam );
/*
* Creates the socket to which UDP messages are sent. This function is not
* called directly to prevent the print socket being created from within the IP
* task - which could result in a deadlock. Instead the function call is
* deferred to run in the RTOS daemon task - hence it prototype.
*/
static void prvCreatePrintSocket( void *pvParameter1, uint32_t ulParameter2 );
/*-----------------------------------------------------------*/
/* Windows event used to wake the Win32 thread which performs any logging that
needs Win32 system calls. */
static void *pvLoggingThreadEvent = NULL;
/* Stores the selected logging targets passed in as parameters to the
vLoggingInit() function. */
BaseType_t xStdoutLoggingUsed = pdFALSE, xDiskFileLoggingUsed = pdFALSE, xUDPLoggingUsed = pdFALSE;
/* Circular buffer used to pass messages from the FreeRTOS tasks to the Win32
thread that is responsible for making Win32 calls (when stdout or a disk log is
used). */
static StreamBuffer_t *xLogStreamBuffer = NULL;
/* Handle to the file used for logging. This is left open while there are
messages waiting to be logged, then closed again in between logs. */
static FILE *pxLoggingFileHandle = NULL;
/* When true prints are performed directly. After start up xDirectPrint is set
to pdFALSE - at which time prints that require Win32 system calls are done by
the Win32 thread responsible for logging. */
BaseType_t xDirectPrint = pdTRUE;
/* File names for the in use and complete (full) log files. */
static const char *pcLogFileName = "RTOSDemo.log";
static const char *pcFullLogFileName = "RTOSDemo.ful";
/* Keep the current file size in a variable, as an optimisation. */
static size_t ulSizeOfLoggingFile = 0ul;
/* The UDP socket and address on/to which print messages are sent. */
Socket_t xPrintSocket = FREERTOS_INVALID_SOCKET;
struct freertos_sockaddr xPrintUDPAddress;
/*-----------------------------------------------------------*/
void vLoggingInit( BaseType_t xLogToStdout, BaseType_t xLogToFile, BaseType_t xLogToUDP, uint32_t ulRemoteIPAddress, uint16_t usRemotePort )
{
/* Can only be called before the scheduler has started. */
configASSERT( xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED );
#if( ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) )
{
HANDLE Win32Thread;
/* Record which output methods are to be used. */
xStdoutLoggingUsed = xLogToStdout;
xDiskFileLoggingUsed = xLogToFile;
xUDPLoggingUsed = xLogToUDP;
/* If a disk file is used then initialise it now. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvFileLoggingInit();
}
/* If UDP logging is used then store the address to which the log data
will be sent - but don't create the socket yet because the network is
not initialised. */
if( xUDPLoggingUsed != pdFALSE )
{
/* Set the address to which the print messages are sent. */
xPrintUDPAddress.sin_port = FreeRTOS_htons( usRemotePort );
xPrintUDPAddress.sin_addr = ulRemoteIPAddress;
}
/* If a disk file or stdout are to be used then Win32 system calls will
have to be made. Such system calls cannot be made from FreeRTOS tasks
so create a stream buffer to pass the messages to a Win32 thread, then
create the thread itself, along with a Win32 event that can be used to
unblock the thread. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
/* Create the buffer. */
xLogStreamBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) + dlLOGGING_STREAM_BUFFER_SIZE + 1 );
configASSERT( xLogStreamBuffer );
memset( xLogStreamBuffer, '\0', sizeof( *xLogStreamBuffer ) - sizeof( xLogStreamBuffer->ucArray ) );
xLogStreamBuffer->LENGTH = dlLOGGING_STREAM_BUFFER_SIZE + 1;
/* Create the Windows event. */
pvLoggingThreadEvent = CreateEvent( NULL, FALSE, TRUE, "StdoutLoggingEvent" );
/* Create the thread itself. */
Win32Thread = CreateThread(
NULL, /* Pointer to thread security attributes. */
0, /* Initial thread stack size, in bytes. */
prvWin32LoggingThread, /* Pointer to thread function. */
NULL, /* Argument for new thread. */
0, /* Creation flags. */
NULL );
/* Use the cores that are not used by the FreeRTOS tasks. */
SetThreadAffinityMask( Win32Thread, ~0x01u );
SetThreadPriorityBoost( Win32Thread, TRUE );
SetThreadPriority( Win32Thread, THREAD_PRIORITY_IDLE );
}
}
#else
{
/* FreeRTOSIPConfig is set such that no print messages will be output.
Avoid compiler warnings about unused parameters. */
( void ) xLogToStdout;
( void ) xLogToFile;
( void ) xLogToUDP;
( void ) usRemotePort;
( void ) ulRemoteIPAddress;
}
#endif /* ( ipconfigHAS_DEBUG_PRINTF == 1 ) || ( ipconfigHAS_PRINTF == 1 ) */
}
/*-----------------------------------------------------------*/
static void prvCreatePrintSocket( void *pvParameter1, uint32_t ulParameter2 )
{
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 0 );
Socket_t xSocket;
/* The function prototype is that of a deferred function, but the parameters
are not actually used. */
( void ) pvParameter1;
( void ) ulParameter2;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
/* FreeRTOS+TCP decides which port to bind to. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xSendTimeOut ) );
FreeRTOS_bind( xSocket, NULL, 0 );
/* Now the socket is bound it can be assigned to the print socket. */
xPrintSocket = xSocket;
}
}
/*-----------------------------------------------------------*/
void vLoggingPrintf( const char *pcFormat, ... )
{
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
char cOutputString[ dlMAX_PRINT_STRING_LENGTH ];
char *pcSource, *pcTarget, *pcBegin;
size_t xLength, xLength2, rc;
static BaseType_t xMessageNumber = 0;
va_list args;
uint32_t ulIPAddress;
const char *pcTaskName;
const char *pcNoTask = "None";
int iOriginalPriority;
HANDLE xCurrentTask;
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) || ( xUDPLoggingUsed != pdFALSE ) )
{
/* There are a variable number of parameters. */
va_start( args, pcFormat );
/* Additional info to place at the start of the log. */
if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )
{
pcTaskName = pcTaskGetName( NULL );
}
else
{
pcTaskName = pcNoTask;
}
if( strcmp( pcFormat, "\n" ) != 0 )
{
xLength = snprintf( cPrintString, dlMAX_PRINT_STRING_LENGTH, "%lu %lu [%s] ",
xMessageNumber++,
( unsigned long ) xTaskGetTickCount(),
pcTaskName );
}
else
{
xLength = 0;
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
}
xLength2 = vsnprintf( cPrintString + xLength, dlMAX_PRINT_STRING_LENGTH - xLength, pcFormat, args );
if( xLength2 < 0 )
{
/* Clean up. */
xLength2 = dlMAX_PRINT_STRING_LENGTH - 1 - xLength;
cPrintString[ dlMAX_PRINT_STRING_LENGTH - 1 ] = '\0';
}
xLength += xLength2;
va_end( args );
/* For ease of viewing, copy the string into another buffer, converting
IP addresses to dot notation on the way. */
pcSource = cPrintString;
pcTarget = cOutputString;
while( ( *pcSource ) != '\0' )
{
*pcTarget = *pcSource;
pcTarget++;
pcSource++;
/* Look forward for an IP address denoted by 'ip'. */
if( ( isxdigit( pcSource[ 0 ] ) != pdFALSE ) && ( pcSource[ 1 ] == 'i' ) && ( pcSource[ 2 ] == 'p' ) )
{
*pcTarget = *pcSource;
pcTarget++;
*pcTarget = '\0';
pcBegin = pcTarget - 8;
while( ( pcTarget > pcBegin ) && ( isxdigit( pcTarget[ -1 ] ) != pdFALSE ) )
{
pcTarget--;
}
sscanf( pcTarget, "%8X", &ulIPAddress );
rc = sprintf( pcTarget, "%lu.%lu.%lu.%lu",
( unsigned long ) ( ulIPAddress >> 24UL ),
( unsigned long ) ( (ulIPAddress >> 16UL) & 0xffUL ),
( unsigned long ) ( (ulIPAddress >> 8UL) & 0xffUL ),
( unsigned long ) ( ulIPAddress & 0xffUL ) );
pcTarget += rc;
pcSource += 3; /* skip "<n>ip" */
}
}
/* How far through the buffer was written? */
xLength = ( BaseType_t ) ( pcTarget - cOutputString );
/* If the message is to be logged to a UDP port then it can be sent directly
because it only uses FreeRTOS function (not Win32 functions). */
if( xUDPLoggingUsed != pdFALSE )
{
if( ( xPrintSocket == FREERTOS_INVALID_SOCKET ) && ( FreeRTOS_IsNetworkUp() != pdFALSE ) )
{
/* Create and bind the socket to which print messages are sent. The
xTimerPendFunctionCall() function is used even though this is
not an interrupt because this function is called from the IP task
and the IP task cannot itself wait for a socket to bind. The
parameters to prvCreatePrintSocket() are not required so set to
NULL or 0. */
xTimerPendFunctionCall( prvCreatePrintSocket, NULL, 0, dlDONT_BLOCK );
}
if( xPrintSocket != FREERTOS_INVALID_SOCKET )
{
FreeRTOS_sendto( xPrintSocket, cOutputString, xLength, 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
/* Just because the UDP data logger I'm using is dumb. */
FreeRTOS_sendto( xPrintSocket, "\r", sizeof( char ), 0, &xPrintUDPAddress, sizeof( xPrintUDPAddress ) );
}
}
/* If logging is also to go to either stdout or a disk file then it cannot
be output here - so instead write the message to the stream buffer and wake
the Win32 thread which will read it from the stream buffer and perform the
actual output. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( xDiskFileLoggingUsed != pdFALSE ) )
{
configASSERT( xLogStreamBuffer );
/* How much space is in the buffer? */
xLength2 = uxStreamBufferGetSpace( xLogStreamBuffer );
/* There must be enough space to write both the string and the length of
the string. */
if( xLength2 >= ( xLength + sizeof( xLength ) ) )
{
/* First write in the length of the data, then write in the data
itself. Raising the thread priority is used as a critical section
as there are potentially multiple writers. The stream buffer is
only thread safe when there is a single writer (likewise for
reading from the buffer). */
xCurrentTask = GetCurrentThread();
iOriginalPriority = GetThreadPriority( xCurrentTask );
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) &( xLength ), sizeof( xLength ) );
uxStreamBufferAdd( xLogStreamBuffer, 0, ( const uint8_t * ) cOutputString, xLength );
SetThreadPriority( GetCurrentThread(), iOriginalPriority );
}
/* xDirectPrint is initialised to pdTRUE, and while it remains true the
logging output function is called directly. When the system is running
the output function cannot be called directly because it would get
called from both FreeRTOS tasks and Win32 threads - so instead wake the
Win32 thread responsible for the actual output. */
if( xDirectPrint != pdFALSE )
{
/* While starting up, the thread which calls prvWin32LoggingThread()
is not running yet and xDirectPrint will be pdTRUE. */
prvLoggingFlushBuffer();
}
else if( pvLoggingThreadEvent != NULL )
{
/* While running, wake up prvWin32LoggingThread() to send the
logging data. */
SetEvent( pvLoggingThreadEvent );
}
}
}
}
/*-----------------------------------------------------------*/
static void prvLoggingFlushBuffer( void )
{
size_t xLength;
char cPrintString[ dlMAX_PRINT_STRING_LENGTH ];
/* Is there more than the length value stored in the circular buffer
used to pass data from the FreeRTOS simulator into this Win32 thread? */
while( uxStreamBufferGetSize( xLogStreamBuffer ) > sizeof( xLength ) )
{
memset( cPrintString, 0x00, dlMAX_PRINT_STRING_LENGTH );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) &xLength, sizeof( xLength ), pdFALSE );
uxStreamBufferGet( xLogStreamBuffer, 0, ( uint8_t * ) cPrintString, xLength, pdFALSE );
/* Write the message to standard out if requested to do so when
vLoggingInit() was called, or if the network is not yet up. */
if( ( xStdoutLoggingUsed != pdFALSE ) || ( FreeRTOS_IsNetworkUp() == pdFALSE ) )
{
/* Write the message to stdout. */
printf( "%s", cPrintString ); /*_RB_ Replace with _write(). */
}
/* Write the message to a file if requested to do so when
vLoggingInit() was called. */
if( xDiskFileLoggingUsed != pdFALSE )
{
prvLogToFile( cPrintString, xLength );
}
}
prvFileClose();
}
/*-----------------------------------------------------------*/
static DWORD WINAPI prvWin32LoggingThread( void *pvParameter )
{
const DWORD xMaxWait = 1000;
( void ) pvParameter;
/* From now on, prvLoggingFlushBuffer() will only be called from this
Windows thread */
xDirectPrint = pdFALSE;
for( ;; )
{
/* Wait to be told there are message waiting to be logged. */
WaitForSingleObject( pvLoggingThreadEvent, xMaxWait );
/* Write out all waiting messages. */
prvLoggingFlushBuffer();
}
}
/*-----------------------------------------------------------*/
static void prvFileLoggingInit( void )
{
FILE *pxHandle = fopen( pcLogFileName, "a" );
if( pxHandle != NULL )
{
fseek( pxHandle, SEEK_END, 0ul );
ulSizeOfLoggingFile = ftell( pxHandle );
fclose( pxHandle );
}
else
{
ulSizeOfLoggingFile = 0ul;
}
}
/*-----------------------------------------------------------*/
static void prvFileClose( void )
{
if( pxLoggingFileHandle != NULL )
{
fclose( pxLoggingFileHandle );
pxLoggingFileHandle = NULL;
}
}
/*-----------------------------------------------------------*/
static void prvLogToFile( const char *pcMessage, size_t xLength )
{
if( pxLoggingFileHandle == NULL )
{
pxLoggingFileHandle = fopen( pcLogFileName, "a" );
}
if( pxLoggingFileHandle != NULL )
{
fwrite( pcMessage, 1, xLength, pxLoggingFileHandle );
ulSizeOfLoggingFile += xLength;
/* If the file has grown to its maximum permissible size then close and
rename it - then start with a new file. */
if( ulSizeOfLoggingFile > ( size_t ) dlLOGGING_FILE_SIZE )
{
prvFileClose();
if( _access( pcFullLogFileName, 00 ) == 0 )
{
remove( pcFullLogFileName );
}
rename( pcLogFileName, pcFullLogFileName );
ulSizeOfLoggingFile = 0;
}
}
}
/*-----------------------------------------------------------*/

@ -1,48 +0,0 @@
/*
* FreeRTOS Kernel V10.4.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef DEMO_LOGGING_H
#define DEMO_LOGGING_H
/*
* Initialise a logging system that can be used from FreeRTOS tasks and Win32
* threads. Do not call printf() directly while the scheduler is running.
*
* Set xLogToStdout, xLogToFile and xLogToUDP to either pdTRUE or pdFALSE to
* lot to stdout, a disk file and a UDP port respectively.
*
* If xLogToUDP is pdTRUE then ulRemoteIPAddress and usRemotePort must be set
* to the IP address and port number to which UDP log messages will be sent.
*/
void vLoggingInit( BaseType_t xLogToStdout,
BaseType_t xLogToFile,
BaseType_t xLogToUDP,
uint32_t ulRemoteIPAddress,
uint16_t usRemotePort );
#endif /* DEMO_LOGGING_H */

@ -62,7 +62,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.\Logging;.\Config;.\Test_Code\Test_Cases\include;..\..\..\CMock\vendor\unity\extras\fixture\src;..\..\..\..\Source\FreeRTOS-Plus-FAT\include;..\..\..\..\Source\FreeRTOS-Plus-FAT\portable\common;..\..\..\..\Source\FreeRTOS-Plus-TCP\protocols\include;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\Source\FreeRTOS-Plus-TCP\include;..\..\..\CMock\vendor\unity\extras\memory\src;.\DemoTasks\include;.\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\FreeRTOS-Plus-CLI;..\..\..\CMock\vendor\unity\src;.\TraceMacros\Example1;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\..\Source\Logging;.\Config;.\Test_Code\Test_Cases\include;..\..\..\CMock\vendor\unity\extras\fixture\src;..\..\..\..\Source\FreeRTOS-Plus-FAT\include;..\..\..\..\Source\FreeRTOS-Plus-FAT\portable\common;..\..\..\..\Source\FreeRTOS-Plus-TCP\protocols\include;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\..\..\Source\FreeRTOS-Plus-TCP\include;..\..\..\CMock\vendor\unity\extras\memory\src;.\DemoTasks\include;.\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\FreeRTOS-Plus-CLI;..\..\..\CMock\vendor\unity\src;.\TraceMacros\Example1;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0600;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -162,7 +162,7 @@
<ClCompile Include="..\..\..\CMock\vendor\unity\extras\fixture\src\unity_fixture.c" />
<ClCompile Include="..\..\..\CMock\vendor\unity\extras\memory\src\unity_memory.c" />
<ClCompile Include="..\..\..\CMock\vendor\unity\src\unity.c" />
<ClCompile Include="Logging\demo_logging.c" />
<ClCompile Include="..\..\..\..\Source\Logging\logging.c" />
<ClCompile Include="Logging\run-time-stats-utils.c" />
<ClCompile Include="main.c">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

@ -120,7 +120,7 @@
<ClCompile Include="..\..\..\CMock\vendor\unity\extras\memory\src\unity_memory.c">
<Filter>Unity</Filter>
</ClCompile>
<ClCompile Include="Logging\demo_logging.c" />
<ClCompile Include="..\..\..\..\Source\Logging\logging.c" />
<ClCompile Include="Logging\run-time-stats-utils.c">
<Filter>Application Code</Filter>
</ClCompile>

@ -1,5 +1,5 @@
/*
* FreeRTOS
* FreeRTOS
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
@ -23,12 +23,12 @@
* http://www.FreeRTOS.org
*/
/**
* @file main.c
* @brief Implements the main function.
*/
/**
* @file main.c
* @brief Implements the main function.
*/
/* FreeRTOS include. */
/* FreeRTOS include. */
#include <FreeRTOS.h>
#include "task.h"
@ -46,11 +46,11 @@
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_DHCP.h"
#include "demo_logging.h"
#include "logging.h"
#include "errhandlingapi.h"
//#include "iot_system_init.h"
/*#include "iot_system_init.h" */
//#include "aws_dev_mode_key_provisioning.h"
/*#include "aws_dev_mode_key_provisioning.h" */
/* Unity includes. */
#include "unity.h"
@ -64,8 +64,8 @@
#define TEST_RUNNER_TASK_STACK_SIZE 10000
#define FIRST_EXCEPTION_HANDLER 1
/* Windows-NT VectoredHandler callback function. */
static LONG CALLBACK prvExceptionHandler(_In_ PEXCEPTION_POINTERS ExceptionInfo);
/* Windows-NT VectoredHandler callback function. */
static LONG CALLBACK prvExceptionHandler( _In_ PEXCEPTION_POINTERS ExceptionInfo );
jmp_buf xMark; /* Address for long jump to jump to. */
/*-----------------------------------------------------------*/
@ -78,7 +78,7 @@ static BaseType_t xTraceRunning = pdTRUE;
* to and from a real network connection on the host PC. See the
* configNETWORK_INTERFACE_TO_USE definition for information on how to configure
* the real network connection to use. */
const uint8_t ucMACAddress[6] =
const uint8_t ucMACAddress[ 6 ] =
{
configMAC_ADDR0,
configMAC_ADDR1,
@ -93,28 +93,28 @@ const uint8_t ucMACAddress[6] =
* 1 but a DHCP server could not be contacted. See the online documentation for
* more information. In both cases the node can be discovered using
* "ping RTOSDemo". */
static const uint8_t ucIPAddress[4] =
static const uint8_t ucIPAddress[ 4 ] =
{
configIP_ADDR0,
configIP_ADDR1,
configIP_ADDR2,
configIP_ADDR3
};
static const uint8_t ucNetMask[4] =
static const uint8_t ucNetMask[ 4 ] =
{
configNET_MASK0,
configNET_MASK1,
configNET_MASK2,
configNET_MASK3
};
static const uint8_t ucGatewayAddress[4] =
static const uint8_t ucGatewayAddress[ 4 ] =
{
configGATEWAY_ADDR0,
configGATEWAY_ADDR1,
configGATEWAY_ADDR2,
configGATEWAY_ADDR3
};
static const uint8_t ucDNSServerAddress[4] =
static const uint8_t ucDNSServerAddress[ 4 ] =
{
configDNS_SERVER_ADDR0,
configDNS_SERVER_ADDR1,
@ -126,10 +126,10 @@ static const uint8_t ucDNSServerAddress[4] =
static UBaseType_t ulNextRand;
/*-----------------------------------------------------------*/
int main(void)
int main( void )
{
/* Register the Windows VEH for exceptions. */
AddVectoredExceptionHandler(FIRST_EXCEPTION_HANDLER, prvExceptionHandler);
AddVectoredExceptionHandler( FIRST_EXCEPTION_HANDLER, prvExceptionHandler );
/* Initialize logging for libraries that depend on it. */
vLoggingInit(
@ -137,7 +137,7 @@ int main(void)
pdFALSE,
pdFALSE,
0,
0);
0 );
/* Initialize the network interface.
*
@ -146,13 +146,13 @@ int main(void)
* vApplicationIPNetworkEventHook() below). The address values passed in here
* are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
* but a DHCP server cannot be contacted. */
FreeRTOS_printf(("FreeRTOS_IPInit\n"));
FreeRTOS_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit(
ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress);
ucMACAddress );
vTaskStartScheduler();
@ -160,18 +160,18 @@ int main(void)
}
/*-----------------------------------------------------------*/
void vApplicationIPNetworkEventHook(eIPCallbackEvent_t eNetworkEvent)
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if ((eNetworkEvent == eNetworkUp) && (xTasksAlreadyCreated == pdFALSE))
if( ( eNetworkEvent == eNetworkUp ) && ( xTasksAlreadyCreated == pdFALSE ) )
{
xTaskCreate(TEST_RUNNER_RunTests_task,
"TestRunner",
TEST_RUNNER_TASK_STACK_SIZE,
NULL,
tskIDLE_PRIORITY, NULL);
xTaskCreate( TEST_RUNNER_RunTests_task,
"TestRunner",
TEST_RUNNER_TASK_STACK_SIZE,
NULL,
tskIDLE_PRIORITY, NULL );
xTasksAlreadyCreated = pdTRUE;
}
@ -179,7 +179,7 @@ void vApplicationIPNetworkEventHook(eIPCallbackEvent_t eNetworkEvent)
/*-----------------------------------------------------------*/
static LONG CALLBACK prvExceptionHandler(_In_ PEXCEPTION_POINTERS ExceptionInfo)
static LONG CALLBACK prvExceptionHandler( _In_ PEXCEPTION_POINTERS ExceptionInfo )
{
/* Remove warning about unused parameter */
( void ) ExceptionInfo;
@ -195,48 +195,48 @@ static LONG CALLBACK prvExceptionHandler(_In_ PEXCEPTION_POINTERS ExceptionInfo)
( ipconfigUSE_NBNS != 0 ) || \
( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) )
const char* pcApplicationHostnameHook(void)
{
/* This function will be called during the DHCP: the machine will be registered
* with an IP address plus this name. */
return mainHOST_NAME;
}
const char * pcApplicationHostnameHook( void )
{
/* This function will be called during the DHCP: the machine will be registered
* with an IP address plus this name. */
return mainHOST_NAME;
}
#endif /* if ( ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) ) */
/*-----------------------------------------------------------*/
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
BaseType_t xApplicationDNSQueryHook(const char* pcName)
{
BaseType_t xReturn;
/* Determine if a name lookup is for this node. Two names are given
* to this node: that returned by pcApplicationHostnameHook() and that set
* by mainDEVICE_NICK_NAME. */
if (_stricmp(pcName, pcApplicationHostnameHook()) == 0)
{
xReturn = pdPASS;
}
else if (_stricmp(pcName, mainDEVICE_NICK_NAME) == 0)
BaseType_t xApplicationDNSQueryHook( const char * pcName )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
BaseType_t xReturn;
return xReturn;
}
/* Determine if a name lookup is for this node. Two names are given
* to this node: that returned by pcApplicationHostnameHook() and that set
* by mainDEVICE_NICK_NAME. */
if( _stricmp( pcName, pcApplicationHostnameHook() ) == 0 )
{
xReturn = pdPASS;
}
else if( _stricmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
/*-----------------------------------------------------------*/
void vApplicationIdleHook(void)
void vApplicationIdleHook( void )
{
const uint32_t ulMSToSleep = 1;
const TickType_t xKitHitCheckPeriod = pdMS_TO_TICKS(1000UL);
const TickType_t xKitHitCheckPeriod = pdMS_TO_TICKS( 1000UL );
static TickType_t xTimeNow, xLastTimeCheck = 0;
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
@ -249,19 +249,17 @@ void vApplicationIdleHook(void)
* because it is the responsibility of the idle task to clean up memory
* allocated by the kernel to any task that has since deleted itself. */
/* _kbhit() is a Windows system function, and system functions can cause
* crashes if they somehow block the FreeRTOS thread. The call to _kbhit()
* can be removed if it causes problems. Limiting the frequency of calls to
* _kbhit() should minimize the potential for issues. */
/* _kbhit() is a Windows system function, and system functions can cause
* crashes if they somehow block the FreeRTOS thread. The call to _kbhit()
* can be removed if it causes problems. Limiting the frequency of calls to
* _kbhit() should minimize the potential for issues. */
xTimeNow = xTaskGetTickCount();
if ((xTimeNow - xLastTimeCheck) > xKitHitCheckPeriod)
if( ( xTimeNow - xLastTimeCheck ) > xKitHitCheckPeriod )
{
/* Uncomment the print line to get confirmation that tests are still
* running if you suspect a previous run resulted in a crash. */
/* configPRINTF( ( "Running...\n" ) ); /**/
/* configPRINTF( ( "Running...\n" ) ); /**/
xLastTimeCheck = xTimeNow;
}
@ -269,42 +267,42 @@ void vApplicationIdleHook(void)
* cycle of the idle task if configUSE_IDLE_HOOK is set to 1 in
* FreeRTOSConfig.h. It must *NOT* attempt to block. In this case the
* idle task just sleeps to lower the CPU usage. */
Sleep(ulMSToSleep);
Sleep( ulMSToSleep );
}
/*-----------------------------------------------------------*/
void vAssertCalled(const char* pcFile,
uint32_t ulLine)
void vAssertCalled( const char * pcFile,
uint32_t ulLine )
{
const uint32_t ulLongSleep = 1000UL;
volatile uint32_t ulBlockVariable = 0UL;
volatile char* pcFileName = (volatile char*)pcFile;
volatile char * pcFileName = ( volatile char * ) pcFile;
volatile uint32_t ulLineNumber = ulLine;
(void)pcFileName;
(void)ulLineNumber;
( void ) pcFileName;
( void ) ulLineNumber;
printf("vAssertCalled %s, %ld\n", pcFile, (long)ulLine);
fflush(stdout);
printf( "vAssertCalled %s, %ld\n", pcFile, ( long ) ulLine );
fflush( stdout );
/* Setting ulBlockVariable to a non-zero value in the debugger will allow
* this function to be exited. */
taskDISABLE_INTERRUPTS();
{
while (ulBlockVariable == 0UL)
while( ulBlockVariable == 0UL )
{
Sleep(ulLongSleep);
Sleep( ulLongSleep );
}
}
taskENABLE_INTERRUPTS();
}
/*-----------------------------------------------------------*/
void getUserCmd(char* pucUserCmd)
void getUserCmd( char * pucUserCmd )
{
char cTmp;
scanf("%c%c", pucUserCmd, &cTmp);
scanf( "%c%c", pucUserCmd, &cTmp );
}
/*-----------------------------------------------------------*/
@ -314,11 +312,11 @@ UBaseType_t uxRand( void )
/* Utility function to generate a pseudo random number. */
ulNextRand = (ulMultiplier * ulNextRand) + ulIncrement;
return((int)(ulNextRand) & 0x7fffUL);
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand ) & 0x7fffUL );
}
BaseType_t xApplicationGetRandomNumber( uint32_t* pulNumber )
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
*pulNumber = uxRand();
@ -331,15 +329,15 @@ BaseType_t xApplicationGetRandomNumber( uint32_t* pulNumber )
* THAT RETURNS A PSEUDO RANDOM NUMBER SO IS NOT INTENDED FOR USE IN PRODUCTION
* SYSTEMS.
*/
extern uint32_t ulApplicationGetNextSequenceNumber(uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort)
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
(void)ulSourceAddress;
(void)usSourcePort;
(void)ulDestinationAddress;
(void)usDestinationPort;
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
return uxRand();
}
}

@ -47,37 +47,37 @@
/*#include "SimpleUDPClientAndServer.h" */
/*#include "SimpleTCPEchoServer.h" */
/*#include "TCPEchoClient_SingleTasks.h" */
/*#include "demo_logging.h" */
/*#include "logging.h" */
#include "TCPEchoClient_SingleTasks.h"
/* Simple UDP client and server task parameters. */
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL )
#define mainSIMPLE_UDP_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
#define mainSIMPLE_UDP_CLIENT_SERVER_PORT ( 5005UL )
/* Echo client task parameters - used for both TCP and UDP echo clients. */
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the linux port. */
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the linux port. */
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Echo server task parameters. */
#define mainECHO_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the linux port. */
#define mainECHO_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainECHO_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) /* Not used in the linux port. */
#define mainECHO_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
/* Define a name that will be used for LLMNR and NBNS searches. */
#define mainHOST_NAME "RTOSDemo"
#define mainDEVICE_NICK_NAME "linux_demo"
#define mainHOST_NAME "RTOSDemo"
#define mainDEVICE_NICK_NAME "linux_demo"
/* Set the following constants to 1 or 0 to define which tasks to include and
exclude:
mainCREATE_TCP_ECHO_TASKS_SINGLE: When set to 1 a set of tasks are created that
send TCP echo requests to the standard echo port (port 7), then wait for and
verify the echo reply, from within the same task (Tx and Rx are performed in the
same RTOS task). The IP address of the echo server must be configured using the
configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in
FreeRTOSConfig.h.
*/
#define mainCREATE_TCP_ECHO_TASKS_SINGLE 1
* exclude:
*
* mainCREATE_TCP_ECHO_TASKS_SINGLE: When set to 1 a set of tasks are created that
* send TCP echo requests to the standard echo port (port 7), then wait for and
* verify the echo reply, from within the same task (Tx and Rx are performed in the
* same RTOS task). The IP address of the echo server must be configured using the
* configECHO_SERVER_ADDR0 to configECHO_SERVER_ADDR3 constants in
* FreeRTOSConfig.h.
*
*/
#define mainCREATE_TCP_ECHO_TASKS_SINGLE 1
/*-----------------------------------------------------------*/
/*
@ -92,28 +92,28 @@ static void prvSRand( UBaseType_t ulSeed );
static void prvMiscInitialisation( void );
/* The default IP and MAC address used by the demo. The address configuration
defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
1 but a DHCP server could not be contacted. See the online documentation for
more information. */
* defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
* 1 but a DHCP server could not be contacted. See the online documentation for
* more information. */
static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
/* Set the following constant to pdTRUE to log using the method indicated by the
name of the constant, or pdFALSE to not log using the method indicated by the
name of the constant. Options include to standard out (xLogToStdout), to a disk
file (xLogToFile), and to a UDP port (xLogToUDP). If xLogToUDP is set to pdTRUE
then UDP messages are sent to the IP address configured as the echo server
address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
* name of the constant, or pdFALSE to not log using the method indicated by the
* name of the constant. Options include to standard out (xLogToStdout), to a disk
* file (xLogToFile), and to a UDP port (xLogToUDP). If xLogToUDP is set to pdTRUE
* then UDP messages are sent to the IP address configured as the echo server
* address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
* the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
const BaseType_t xLogToStdout = pdTRUE, xLogToFile = pdFALSE, xLogToUDP = pdFALSE;
/* Default MAC address configuration. The demo creates a virtual network
connection that uses this MAC address by accessing the raw Ethernet data
to and from a real network connection on the host PC. See the
configNETWORK_INTERFACE_TO_USE definition for information on how to configure
the real network connection to use. */
* connection that uses this MAC address by accessing the raw Ethernet data
* to and from a real network connection on the host PC. See the
* configNETWORK_INTERFACE_TO_USE definition for information on how to configure
* the real network connection to use. */
const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
/* Use by the pseudo random number generator. */
@ -121,172 +121,172 @@ static UBaseType_t ulNextRand;
/*-----------------------------------------------------------*/
void main_tcp_echo_client_tasks( void )
void main_tcp_echo_client_tasks( void )
{
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );
/*
* Instructions for using this project are provided on:
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
*/
/* Miscellaneous initialisation including preparing the logging and seeding
the random number generator. */
prvMiscInitialisation();
/* Initialise the network interface.
***NOTE*** Tasks that use the network are created in the network event hook
when the network is connected and ready for use (see the definition of
vApplicationIPNetworkEventHook() below). The address values passed in here
are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
but a DHCP server cannot be contacted. */
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit( ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress );
/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
vTaskStartScheduler();
FreeRTOS_debug_printf( ( "Should not reach this point after scheduler\n" ) );
/* If all is well, the scheduler will now be running, and the following
line will never be reached. If the following line does execute, then
there was insufficient FreeRTOS heap memory available for the idle and/or
timer tasks to be created. See the memory management section on the
FreeRTOS web site for more details (this is standard text that is not not
really applicable to the Linux simulator port). */
for( ; ; )
{
usleep( ulLongTime_ms * 1000 );
}
const uint32_t ulLongTime_ms = pdMS_TO_TICKS( 1000UL );
/*
* Instructions for using this project are provided on:
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/examples_FreeRTOS_simulator.html
*/
/* Miscellaneous initialisation including preparing the logging and seeding
* the random number generator. */
prvMiscInitialisation();
/* Initialise the network interface.
*
***NOTE*** Tasks that use the network are created in the network event hook
* when the network is connected and ready for use (see the definition of
* vApplicationIPNetworkEventHook() below). The address values passed in here
* are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1
* but a DHCP server cannot be contacted. */
FreeRTOS_debug_printf( ( "FreeRTOS_IPInit\n" ) );
FreeRTOS_IPInit( ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress );
/* Start the RTOS scheduler. */
FreeRTOS_debug_printf( ( "vTaskStartScheduler\n" ) );
vTaskStartScheduler();
FreeRTOS_debug_printf( ( "Should not reach this point after scheduler\n" ) );
/* If all is well, the scheduler will now be running, and the following
* line will never be reached. If the following line does execute, then
* there was insufficient FreeRTOS heap memory available for the idle and/or
* timer tasks to be created. See the memory management section on the
* FreeRTOS web site for more details (this is standard text that is not not
* really applicable to the Linux simulator port). */
for( ; ; )
{
usleep( ulLongTime_ms * 1000 );
}
}
/*-----------------------------------------------------------*/
/* Called by FreeRTOS+TCP when the network connects or disconnects. Disconnect
events are only received if implemented in the MAC driver. */
* events are only received if implemented in the MAC driver. */
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
{
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
char cBuffer[ 16 ];
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if( eNetworkEvent == eNetworkUp )
{
/* Create the tasks that use the IP stack if they have not already been
created. */
if( xTasksAlreadyCreated == pdFALSE )
{
/* See the comments above the definitions of these pre-processor
macros at the top of this file for a description of the individual
demo tasks. */
#if ( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 )
{
vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
}
#endif /* mainCREATE_TCP_ECHO_TASKS_SINGLE */
xTasksAlreadyCreated = pdTRUE;
}
/* Print out the network configuration, which may have come from a DHCP
server. */
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
FreeRTOS_printf( ( "DNS Server Address: %s\r\n\r\n\r\n", cBuffer ) );
}
else
{
FreeRTOS_printf( "Application idle hook network down\n" );
}
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
char cBuffer[ 16 ];
static BaseType_t xTasksAlreadyCreated = pdFALSE;
/* If the network has just come up...*/
if( eNetworkEvent == eNetworkUp )
{
/* Create the tasks that use the IP stack if they have not already been
* created. */
if( xTasksAlreadyCreated == pdFALSE )
{
/* See the comments above the definitions of these pre-processor
* macros at the top of this file for a description of the individual
* demo tasks. */
#if ( mainCREATE_TCP_ECHO_TASKS_SINGLE == 1 )
{
vStartTCPEchoClientTasks_SingleTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
}
#endif /* mainCREATE_TCP_ECHO_TASKS_SINGLE */
xTasksAlreadyCreated = pdTRUE;
}
/* Print out the network configuration, which may have come from a DHCP
* server. */
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
FreeRTOS_printf( ( "\r\n\r\nIP Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
FreeRTOS_printf( ( "Subnet Mask: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
FreeRTOS_printf( ( "Gateway Address: %s\r\n", cBuffer ) );
FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
FreeRTOS_printf( ( "DNS Server Address: %s\r\n\r\n\r\n", cBuffer ) );
}
else
{
FreeRTOS_printf( "Application idle hook network down\n" );
}
}
/*-----------------------------------------------------------*/
UBaseType_t uxRand( void )
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
/* Utility function to generate a pseudo random number. */
/* Utility function to generate a pseudo random number. */
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
}
/*-----------------------------------------------------------*/
static void prvSRand( UBaseType_t ulSeed )
{
/* Utility function to seed the pseudo random number generator. */
ulNextRand = ulSeed;
/* Utility function to seed the pseudo random number generator. */
ulNextRand = ulSeed;
}
/*-----------------------------------------------------------*/
static void prvMiscInitialisation( void )
{
time_t xTimeNow;
/* Seed the random number generator. */
time( &xTimeNow );
FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );
prvSRand( ( uint32_t ) xTimeNow );
FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n",
ipconfigRAND32(),
ipconfigRAND32(),
ipconfigRAND32(),
ipconfigRAND32() ) );
time_t xTimeNow;
/* Seed the random number generator. */
time( &xTimeNow );
FreeRTOS_debug_printf( ( "Seed for randomiser: %lu\n", xTimeNow ) );
prvSRand( ( uint32_t ) xTimeNow );
FreeRTOS_debug_printf( ( "Random numbers: %08X %08X %08X %08X\n",
ipconfigRAND32(),
ipconfigRAND32(),
ipconfigRAND32(),
ipconfigRAND32() ) );
}
/*-----------------------------------------------------------*/
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
const char * pcApplicationHostnameHook( void )
{
/* Assign the name "FreeRTOS" to this network node. This function will
be called during the DHCP: the machine will be registered with an IP
address plus this name. */
return mainHOST_NAME;
}
const char * pcApplicationHostnameHook( void )
{
/* Assign the name "FreeRTOS" to this network node. This function will
* be called during the DHCP: the machine will be registered with an IP
* address plus this name. */
return mainHOST_NAME;
}
#endif
/*-----------------------------------------------------------*/
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
BaseType_t xApplicationDNSQueryHook( const char *pcName )
{
BaseType_t xReturn;
/* Determine if a name lookup is for this node. Two names are given
to this node: that returned by pcApplicationHostnameHook() and that set
by mainDEVICE_NICK_NAME. */
if( strcasecmp( pcName, pcApplicationHostnameHook() ) == 0 )
{
xReturn = pdPASS;
}
else if( strcasecmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
BaseType_t xApplicationDNSQueryHook( const char * pcName )
{
BaseType_t xReturn;
/* Determine if a name lookup is for this node. Two names are given
* to this node: that returned by pcApplicationHostnameHook() and that set
* by mainDEVICE_NICK_NAME. */
if( strcasecmp( pcName, pcApplicationHostnameHook() ) == 0 )
{
xReturn = pdPASS;
}
else if( strcasecmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
{
xReturn = pdPASS;
}
else
{
xReturn = pdFAIL;
}
return xReturn;
}
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
@ -297,16 +297,16 @@ time_t xTimeNow;
* SYSTEMS.
*/
extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
uint16_t usSourcePort,
uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;
return uxRand();
return uxRand();
}
/*
@ -316,6 +316,6 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
*/
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
*( pulNumber ) = uxRand();
return pdTRUE;
*( pulNumber ) = uxRand();
return pdTRUE;
}

Loading…
Cancel
Save