diff --git a/etc/visual-studio/libopenthread-cli.vcxproj b/etc/visual-studio/libopenthread-cli.vcxproj
new file mode 100644
index 000000000..3d6f976ad
--- /dev/null
+++ b/etc/visual-studio/libopenthread-cli.vcxproj
@@ -0,0 +1,165 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+
+
+
+
+
+
+ {41B32069-632E-4578-855B-A36EBFA80B56}
+ Win32Proj
+ Thread
+ 8.1
+
+
+
+ StaticLibrary
+ true
+ v140
+ Unicode
+
+
+ StaticLibrary
+ false
+ v140
+ true
+ Unicode
+
+
+ StaticLibrary
+ true
+ v140
+ Unicode
+
+
+ StaticLibrary
+ false
+ v140
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+ true
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+ false
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+ false
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+
+
+
+ Level3
+ Disabled
+ WIN32;_DEBUG;_LIB;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+
+
+ Windows
+
+
+
+
+
+
+ Level3
+ Disabled
+ _DEBUG;_LIB;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+
+
+ Windows
+
+
+
+
+ Level3
+
+
+ MaxSpeed
+ true
+ true
+ WIN32;NDEBUG;_LIB;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+
+
+ Windows
+ true
+ true
+
+
+
+
+ Level3
+
+
+ MaxSpeed
+ true
+ true
+ NDEBUG;_LIB;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+
+
+ Windows
+ true
+ true
+
+
+
+
+
+
\ No newline at end of file
diff --git a/etc/visual-studio/libopenthread-cli.vcxproj.filters b/etc/visual-studio/libopenthread-cli.vcxproj.filters
new file mode 100644
index 000000000..cf6c8a37b
--- /dev/null
+++ b/etc/visual-studio/libopenthread-cli.vcxproj.filters
@@ -0,0 +1,23 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
\ No newline at end of file
diff --git a/etc/visual-studio/libopenthread-windows.vcxproj b/etc/visual-studio/libopenthread-windows.vcxproj
new file mode 100644
index 000000000..f53a7bbce
--- /dev/null
+++ b/etc/visual-studio/libopenthread-windows.vcxproj
@@ -0,0 +1,174 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}
+ Win32Proj
+ Thread
+ 8.1
+ libopenthread-windows
+
+
+
+ StaticLibrary
+ true
+ v140
+ Unicode
+
+
+ StaticLibrary
+ false
+ v140
+ true
+ Unicode
+
+
+ StaticLibrary
+ true
+ v140
+ Unicode
+
+
+ StaticLibrary
+ false
+ v140
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+ true
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+ false
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+ false
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\
+
+
+
+
+
+ Level3
+ Disabled
+ WIN32;_DEBUG;_WINDOWS;_USRDLL;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..examples\platforms
+
+
+ Windows
+ true
+
+
+
+
+
+
+ Level3
+ Disabled
+ _DEBUG;_WINDOWS;_USRDLL;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..examples\platforms
+
+
+ Windows
+
+
+
+
+ Level3
+
+
+ MaxSpeed
+ true
+ true
+ WIN32;NDEBUG;_WINDOWS;_USRDLL;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..examples\platforms
+
+
+ Windows
+ true
+ true
+
+
+
+
+ Level3
+
+
+ MaxSpeed
+ true
+ true
+ NDEBUG;_WINDOWS;_USRDLL;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..examples\platforms
+
+
+ Windows
+ true
+ true
+
+
+
+
+
+
\ No newline at end of file
diff --git a/etc/visual-studio/libopenthread-windows.vcxproj.filters b/etc/visual-studio/libopenthread-windows.vcxproj.filters
new file mode 100644
index 000000000..bc34f58f9
--- /dev/null
+++ b/etc/visual-studio/libopenthread-windows.vcxproj.filters
@@ -0,0 +1,43 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {af2a0e04-134d-40b3-84d4-82c8c622f9ae}
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+
\ No newline at end of file
diff --git a/etc/visual-studio/openthread.sln b/etc/visual-studio/openthread.sln
index fd1ea5adc..150034748 100644
--- a/etc/visual-studio/openthread.sln
+++ b/etc/visual-studio/openthread.sln
@@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config files", "config file
..\..\.travis.yml = ..\..\.travis.yml
EndProjectSection
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{76EA541E-CAB1-4DB5-A39F-E3DB2A78CDDD}"
+EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{95BD0669-04C8-4EEB-B3CC-0535B03F4468}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{35F6AB71-5BD2-4D53-8A51-D75CCD4CCC3D}"
@@ -26,6 +28,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mbedtls_k", "mbedtls_k.vcxp
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests.vcxproj", "{FD64BF17-8D36-4578-8D13-77B123BE30D3}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libopenthread-windows", "libopenthread-windows.vcxproj", "{30723C38-BA3B-44C9-8D64-C5861A26934F}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libopenthread-cli", "libopenthread-cli.vcxproj", "{41B32069-632E-4578-855B-A36EBFA80B56}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ot-cli", "ot-cli.vcxproj", "{91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -78,6 +86,30 @@ Global
{FD64BF17-8D36-4578-8D13-77B123BE30D3}.Release|x64.Build.0 = Release|x64
{FD64BF17-8D36-4578-8D13-77B123BE30D3}.Release|x86.ActiveCfg = Release|Win32
{FD64BF17-8D36-4578-8D13-77B123BE30D3}.Release|x86.Build.0 = Release|Win32
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Debug|x64.ActiveCfg = Debug|x64
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Debug|x64.Build.0 = Debug|x64
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Debug|x86.ActiveCfg = Debug|Win32
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Debug|x86.Build.0 = Debug|Win32
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Release|x64.ActiveCfg = Release|x64
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Release|x64.Build.0 = Release|x64
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Release|x86.ActiveCfg = Release|Win32
+ {30723C38-BA3B-44C9-8D64-C5861A26934F}.Release|x86.Build.0 = Release|Win32
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Debug|x64.ActiveCfg = Debug|x64
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Debug|x64.Build.0 = Debug|x64
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Debug|x86.ActiveCfg = Debug|Win32
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Debug|x86.Build.0 = Debug|Win32
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Release|x64.ActiveCfg = Release|x64
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Release|x64.Build.0 = Release|x64
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Release|x86.ActiveCfg = Release|Win32
+ {41B32069-632E-4578-855B-A36EBFA80B56}.Release|x86.Build.0 = Release|Win32
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Debug|x64.ActiveCfg = Debug|x64
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Debug|x64.Build.0 = Debug|x64
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Debug|x86.ActiveCfg = Debug|Win32
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Debug|x86.Build.0 = Debug|Win32
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Release|x64.ActiveCfg = Release|x64
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Release|x64.Build.0 = Release|x64
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Release|x86.ActiveCfg = Release|Win32
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -88,5 +120,8 @@ Global
{4111C8BB-D354-4348-AD3C-EB6832E84831} = {873E9D16-2A08-41FC-B301-79C95B3A8F98}
{69BE8E8C-CF1E-46D6-932B-DB435F47059B} = {873E9D16-2A08-41FC-B301-79C95B3A8F98}
{FD64BF17-8D36-4578-8D13-77B123BE30D3} = {35F6AB71-5BD2-4D53-8A51-D75CCD4CCC3D}
+ {30723C38-BA3B-44C9-8D64-C5861A26934F} = {76EA541E-CAB1-4DB5-A39F-E3DB2A78CDDD}
+ {41B32069-632E-4578-855B-A36EBFA80B56} = {95BD0669-04C8-4EEB-B3CC-0535B03F4468}
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF} = {76EA541E-CAB1-4DB5-A39F-E3DB2A78CDDD}
EndGlobalSection
EndGlobal
diff --git a/etc/visual-studio/ot-cli.vcxproj b/etc/visual-studio/ot-cli.vcxproj
new file mode 100644
index 000000000..56a0cb642
--- /dev/null
+++ b/etc/visual-studio/ot-cli.vcxproj
@@ -0,0 +1,185 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ {91D3ADEA-F1FE-4433-95B6-F8F6A7CF7BAF}
+ Win32Proj
+ Thread
+ 8.1
+ ot-cli
+
+
+
+ Application
+ true
+ v140
+ Unicode
+
+
+ Application
+ false
+ v140
+ true
+ Unicode
+
+
+ Application
+ true
+ v140
+ Unicode
+
+
+ Application
+ false
+ v140
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\exe\
+
+
+ true
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\exe\
+
+
+ false
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\exe\
+
+
+ false
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+ ..\..\build\bin\$(Platform)\$(Configuration)\exe\
+
+
+
+
+
+ Level3
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..\examples\platforms
+
+
+ Console
+ true
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-cli.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-windows.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+ Level3
+ Disabled
+ _DEBUG;_CONSOLE;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..\examples\platforms
+
+
+ Console
+ true
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-cli.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-windows.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+
+
+ MaxSpeed
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..\examples\platforms
+
+
+ Console
+ true
+ true
+ true
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-cli.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-windows.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+
+
+ MaxSpeed
+ true
+ true
+ NDEBUG;_CONSOLE;OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+ ..\..\include;..\..\src\core;..\..\examples\platforms
+
+
+ Console
+ true
+ true
+ true
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-cli.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread-windows.lib;ws2_32.lib;%(AdditionalDependencies)
+
+
+
+
+ {41b32069-632e-4578-855b-a36ebfa80b56}
+
+
+ {dd5018be-54c6-4fd4-9f8d-08d52fc0cd40}
+
+
+ {4111c8bb-d354-4348-ad3c-eb6832e84831}
+
+
+ {30723c38-ba3b-44c9-8d64-c5861a26934f}
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/etc/visual-studio/ot-cli.vcxproj.filters b/etc/visual-studio/ot-cli.vcxproj.filters
new file mode 100644
index 000000000..5d735b3db
--- /dev/null
+++ b/etc/visual-studio/ot-cli.vcxproj.filters
@@ -0,0 +1,14 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+
+
+ Source Files
+
+
+
\ No newline at end of file
diff --git a/examples/platforms/posix/Makefile.am b/examples/platforms/posix/Makefile.am
index c45a4db7f..d567f4f57 100644
--- a/examples/platforms/posix/Makefile.am
+++ b/examples/platforms/posix/Makefile.am
@@ -44,7 +44,7 @@ libopenthread_posix_a_SOURCES = \
platform.c \
radio.c \
random.c \
- uart.c \
+ uart-posix.c \
flash.c \
$(NULL)
diff --git a/examples/platforms/posix/alarm.c b/examples/platforms/posix/alarm.c
index 90d945493..bdfc68889 100644
--- a/examples/platforms/posix/alarm.c
+++ b/examples/platforms/posix/alarm.c
@@ -26,23 +26,20 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "platform-posix.h"
+
#include
#include
#include
-#include
-
-#include
-#include
#include
#include
-#include "platform-posix.h"
static bool s_is_running = false;
static uint32_t s_alarm = 0;
static struct timeval s_start;
-void posixAlarmInit(void)
+void platformAlarmInit(void)
{
gettimeofday(&s_start, NULL);
}
@@ -70,7 +67,7 @@ void otPlatAlarmStop(otInstance *aInstance)
s_is_running = false;
}
-void posixAlarmUpdateTimeout(struct timeval *aTimeout)
+void platformAlarmUpdateTimeout(struct timeval *aTimeout)
{
int32_t remaining;
@@ -101,7 +98,7 @@ void posixAlarmUpdateTimeout(struct timeval *aTimeout)
}
}
-void posixAlarmProcess(otInstance *aInstance)
+void platformAlarmProcess(otInstance *aInstance)
{
int32_t remaining;
diff --git a/examples/platforms/posix/diag.c b/examples/platforms/posix/diag.c
index a84897a3c..93239879b 100644
--- a/examples/platforms/posix/diag.c
+++ b/examples/platforms/posix/diag.c
@@ -26,6 +26,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "platform-posix.h"
+
#include
#include
#include
@@ -35,7 +37,6 @@
#include
#include
-#include "platform-posix.h"
/**
* diagnostics mode flag.
diff --git a/examples/platforms/posix/flash.c b/examples/platforms/posix/flash.c
index d749355be..52aefeddb 100644
--- a/examples/platforms/posix/flash.c
+++ b/examples/platforms/posix/flash.c
@@ -26,6 +26,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "platform-posix.h"
+
#include
#include
#include
@@ -37,7 +39,6 @@
#include
#include
-#include "platform-posix.h"
static int sFlashFd;
uint32_t sEraseAddress;
diff --git a/examples/platforms/posix/logging.c b/examples/platforms/posix/logging.c
index 74a73d990..1addd37c0 100644
--- a/examples/platforms/posix/logging.c
+++ b/examples/platforms/posix/logging.c
@@ -26,16 +26,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "platform-posix.h"
+
#include
#include
#include
#include
#include
#include
-#include
#include
-#include
#include
// Macro to append content to end of the log string.
diff --git a/examples/platforms/posix/misc.c b/examples/platforms/posix/misc.c
index c043bc0af..2cca2dae9 100644
--- a/examples/platforms/posix/misc.c
+++ b/examples/platforms/posix/misc.c
@@ -26,9 +26,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "platform-posix.h"
+
#include
#include
-#include "platform-posix.h"
void otPlatReset(otInstance *aInstance)
{
diff --git a/examples/platforms/posix/platform-posix.h b/examples/platforms/posix/platform-posix.h
index 652254676..2958914bb 100644
--- a/examples/platforms/posix/platform-posix.h
+++ b/examples/platforms/posix/platform-posix.h
@@ -29,17 +29,59 @@
/**
* @file
* @brief
- * This file includes the posix platform-specific initializers.
+ * This file includes the (posix or windows) platform-specific initializers.
*/
#ifndef PLATFORM_POSIX_H_
#define PLATFORM_POSIX_H_
-#include
-#include
-#include
+#ifdef OPENTHREAD_CONFIG_FILE
+#include OPENTHREAD_CONFIG_FILE
+#else
+#include
+#endif
-#include
+#if _WIN32
+#define _CRT_SECURE_NO_WARNINGS
+#include
+#include
+#include
+#define POLL WSAPoll
+#define ssize_t int
+// In user mode, define some Linux functions
+__forceinline int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ (void)tz;
+ tv->tv_sec = (long)GetTickCount(); // Generally 0 at the start of the application
+ tv->tv_usec = 0;
+ return 0;
+}
+__forceinline void timersub(struct timeval *a, struct timeval *b, struct timeval *res)
+{
+ res->tv_sec = a->tv_sec - b->tv_sec;
+ res->tv_usec = 0;
+}
+#else
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#define POLL poll
+#endif
+
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
/**
* Unique node ID.
@@ -57,7 +99,7 @@ extern uint32_t WELLKNOWN_NODE_ID;
* This function initializes the alarm service used by OpenThread.
*
*/
-void posixAlarmInit(void);
+void platformAlarmInit(void);
/**
* This function retrieves the time remaining until the alarm fires.
@@ -65,7 +107,7 @@ void posixAlarmInit(void);
* @param[out] aTimeval A pointer to the timeval struct.
*
*/
-void posixAlarmUpdateTimeout(struct timeval *tv);
+void platformAlarmUpdateTimeout(struct timeval *tv);
/**
* This function performs alarm driver processing.
@@ -73,13 +115,13 @@ void posixAlarmUpdateTimeout(struct timeval *tv);
* @param[in] aInstance The OpenThread instance structure.
*
*/
-void posixAlarmProcess(otInstance *aInstance);
+void platformAlarmProcess(otInstance *aInstance);
/**
* This function initializes the radio service used by OpenThread.
*
*/
-void posixRadioInit(void);
+void platformRadioInit(void);
/**
* This function updates the file descriptor sets with file descriptors used by the radio driver.
@@ -89,7 +131,7 @@ void posixRadioInit(void);
* @param[inout] aMaxFd A pointer to the max file descriptor.
*
*/
-void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd);
+void platformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd);
/**
* This function performs radio driver processing.
@@ -97,13 +139,13 @@ void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
* @param[in] aInstance The OpenThread instance structure.
*
*/
-void posixRadioProcess(otInstance *aInstance);
+void platformRadioProcess(otInstance *aInstance);
/**
* This function initializes the random number service used by OpenThread.
*
*/
-void posixRandomInit(void);
+void platformRandomInit(void);
/**
* This function updates the file descriptor sets with file descriptors used by the UART driver.
@@ -113,12 +155,12 @@ void posixRandomInit(void);
* @param[inout] aMaxFd A pointer to the max file descriptor.
*
*/
-void posixUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aErrorFdSet, int *aMaxFd);
+void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aErrorFdSet, int *aMaxFd);
/**
* This function performs radio driver processing.
*
*/
-void posixUartProcess(void);
+void platformUartProcess(void);
#endif // PLATFORM_POSIX_H_
diff --git a/examples/platforms/posix/platform.c b/examples/platforms/posix/platform.c
index 5b0f837a4..e83ee60bc 100644
--- a/examples/platforms/posix/platform.c
+++ b/examples/platforms/posix/platform.c
@@ -32,18 +32,18 @@
* This file includes the platform-specific initializers.
*/
+#include "platform-posix.h"
+
#include
#include
#include
#include
#include
#include
-#include
#include
#include
#include
-#include "platform-posix.h"
uint32_t NODE_ID = 1;
uint32_t WELLKNOWN_NODE_ID = 34;
@@ -65,12 +65,13 @@ void PlatformInit(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- posixAlarmInit();
- posixRadioInit();
- posixRandomInit();
- otPlatUartEnable();
+ platformAlarmInit();
+ platformRadioInit();
+ platformRandomInit();
}
+bool UartInitialized = false;
+
void PlatformProcessDrivers(otInstance *aInstance)
{
fd_set read_fds;
@@ -80,13 +81,19 @@ void PlatformProcessDrivers(otInstance *aInstance)
struct timeval timeout;
int rval;
+ if (!UartInitialized)
+ {
+ UartInitialized = true;
+ otPlatUartEnable();
+ }
+
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
FD_ZERO(&error_fds);
- posixUartUpdateFdSet(&read_fds, &write_fds, &error_fds, &max_fd);
- posixRadioUpdateFdSet(&read_fds, &write_fds, &max_fd);
- posixAlarmUpdateTimeout(&timeout);
+ platformUartUpdateFdSet(&read_fds, &write_fds, &error_fds, &max_fd);
+ platformRadioUpdateFdSet(&read_fds, &write_fds, &max_fd);
+ platformAlarmUpdateTimeout(&timeout);
if (!otAreTaskletsPending(aInstance))
{
@@ -99,8 +106,8 @@ void PlatformProcessDrivers(otInstance *aInstance)
}
}
- posixUartProcess();
- posixRadioProcess(aInstance);
- posixAlarmProcess(aInstance);
+ platformUartProcess();
+ platformRadioProcess(aInstance);
+ platformAlarmProcess(aInstance);
}
diff --git a/examples/platforms/posix/radio.c b/examples/platforms/posix/radio.c
index 2ee56b85b..28dcb0a41 100644
--- a/examples/platforms/posix/radio.c
+++ b/examples/platforms/posix/radio.c
@@ -26,28 +26,11 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
+#include "platform-posix.h"
#include
#include
-#include
-#include "platform-posix.h"
-
enum
{
IEEE802154_MIN_LENGTH = 5,
@@ -90,7 +73,8 @@ enum
IEEE802154_MACCMD_DATA_REQ = 4,
};
-struct OT_TOOL_PACKED_BEGIN RadioMessage
+OT_TOOL_PACKED_BEGIN
+struct RadioMessage
{
uint8_t mChannel;
uint8_t mPsdu[kMaxPHYPacketSize];
@@ -370,7 +354,7 @@ void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
sPromiscuous = aEnable;
}
-void posixRadioInit(void)
+void platformRadioInit(void)
{
struct sockaddr_in sockaddr;
char *offset;
@@ -405,7 +389,7 @@ void posixRadioInit(void)
sockaddr.sin_addr.s_addr = INADDR_ANY;
- sSockFd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ sSockFd = (int)socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
bind(sSockFd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
sReceiveFrame.mPsdu = sReceiveMessage.mPsdu;
@@ -517,7 +501,7 @@ bool otPlatRadioGetPromiscuous(otInstance *aInstance)
void radioReceive(otInstance *aInstance)
{
- ssize_t rval = recvfrom(sSockFd, &sReceiveMessage, sizeof(sReceiveMessage), 0, NULL, NULL);
+ ssize_t rval = recvfrom(sSockFd, (char *)&sReceiveMessage, sizeof(sReceiveMessage), 0, NULL, NULL);
if (rval < 0)
{
@@ -580,7 +564,7 @@ void radioSendMessage(otInstance *aInstance)
}
}
-void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
+void platformRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
{
if (aReadFdSet != NULL && (sState != kStateTransmit || sAckWait))
{
@@ -603,12 +587,12 @@ void posixRadioUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, int *aMaxFd)
}
}
-void posixRadioProcess(otInstance *aInstance)
+void platformRadioProcess(otInstance *aInstance)
{
const int flags = POLLIN | POLLRDNORM | POLLERR | POLLNVAL | POLLHUP;
struct pollfd pollfd = { sSockFd, flags, 0 };
- if (poll(&pollfd, 1, 0) > 0 && (pollfd.revents & flags) != 0)
+ if (POLL(&pollfd, 1, 0) > 0 && (pollfd.revents & flags) != 0)
{
radioReceive(aInstance);
}
@@ -649,7 +633,7 @@ void radioTransmit(struct RadioMessage *msg, const struct RadioPacket *pkt)
}
sockaddr.sin_port = htons(9000 + sPortOffset + i);
- rval = sendto(sSockFd, msg, 1 + pkt->mLength,
+ rval = sendto(sSockFd, (const char *)msg, 1 + pkt->mLength,
0, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
if (rval < 0)
diff --git a/examples/platforms/posix/random.c b/examples/platforms/posix/random.c
index 72a27a4c5..6f76b4bb6 100644
--- a/examples/platforms/posix/random.c
+++ b/examples/platforms/posix/random.c
@@ -34,16 +34,16 @@
* This implementation is not a true random number generator and does @em satisfy the Thread requirements.
*/
-#include
+#include "platform-posix.h"
+
#include
#include
#include
-#include "platform-posix.h"
static uint32_t s_state = 1;
-void posixRandomInit(void)
+void platformRandomInit(void)
{
// Multiplying NODE_ID assures that no two nodes gets the same seed within an hour.
s_state = (uint32_t)time(NULL) + (3600 * NODE_ID);
diff --git a/examples/platforms/posix/spi-stubs.c b/examples/platforms/posix/spi-stubs.c
index 838ea3d70..96ba5bc23 100644
--- a/examples/platforms/posix/spi-stubs.c
+++ b/examples/platforms/posix/spi-stubs.c
@@ -26,6 +26,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "platform-posix.h"
#include
#include
diff --git a/examples/platforms/posix/uart.c b/examples/platforms/posix/uart-posix.c
similarity index 98%
rename from examples/platforms/posix/uart.c
rename to examples/platforms/posix/uart-posix.c
index 48faf7fe9..c9b1805c5 100644
--- a/examples/platforms/posix/uart.c
+++ b/examples/platforms/posix/uart-posix.c
@@ -26,6 +26,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "platform-posix.h"
+
#include
#include
#include
@@ -38,7 +40,6 @@
#include
#include
-#include "platform-posix.h"
#ifdef OPENTHREAD_TARGET_LINUX
#include
@@ -176,7 +177,7 @@ exit:
return error;
}
-void posixUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aErrorFdSet, int *aMaxFd)
+void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aErrorFdSet, int *aMaxFd)
{
if (aReadFdSet != NULL)
{
@@ -209,7 +210,7 @@ void posixUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aErro
}
}
-void posixUartProcess(void)
+void platformUartProcess(void)
{
ssize_t rval;
const int error_flags = POLLERR | POLLNVAL | POLLHUP;
diff --git a/examples/platforms/posix/uart-windows.c b/examples/platforms/posix/uart-windows.c
new file mode 100644
index 000000000..6152f1796
--- /dev/null
+++ b/examples/platforms/posix/uart-windows.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2016, The OpenThread Authors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "platform-posix.h"
+
+#include
+
+static HANDLE s_WorkerThread;
+static HANDLE s_StopWorkerEvent;
+
+DWORD WINAPI
+windowsUartWorkerThread(
+ _In_ LPVOID lpThreadParameter
+ )
+{
+ DWORD originalConsoleMode;
+ HANDLE waitHandles[] = { s_StopWorkerEvent, GetStdHandle(STD_INPUT_HANDLE) };
+ uint8_t ch;
+
+ // Cache the original console mode
+ GetConsoleMode(waitHandles[1], &originalConsoleMode);
+
+ // Fake the first new line
+ ch = '\n';
+ otPlatUartReceived(&ch, 1);
+
+ // Wait for console events
+ while (WaitForMultipleObjects(ARRAYSIZE(waitHandles), waitHandles, FALSE, INFINITE) == WAIT_OBJECT_0 + 1)
+ {
+ DWORD numberOfEvent = 0;
+ if (GetNumberOfConsoleInputEvents(waitHandles[1], &numberOfEvent))
+ {
+ for (; numberOfEvent > 0; numberOfEvent--)
+ {
+ INPUT_RECORD record;
+ DWORD numRead;
+ if (!ReadConsoleInput(waitHandles[1], &record, 1, &numRead) ||
+ record.EventType != KEY_EVENT ||
+ !record.Event.KeyEvent.bKeyDown)
+ continue;
+
+ ch = (uint8_t)record.Event.KeyEvent.uChar.AsciiChar;
+ otPlatUartReceived(&ch, 1);
+ }
+ }
+ }
+
+ return NO_ERROR;
+}
+
+ThreadError otPlatUartEnable(void)
+{
+ ThreadError error = kThreadError_None;
+
+ // Create the worker thread stop event
+ VerifyOrExit((s_StopWorkerEvent = CreateEvent(NULL, TRUE, FALSE, NULL)) != NULL, error = kThreadError_Error);
+
+ // Start the worker thread
+ VerifyOrExit((s_WorkerThread = CreateThread(NULL, 0, windowsUartWorkerThread, NULL, 0, NULL)) != NULL, error = kThreadError_Error);
+
+ return error;
+
+exit:
+ CloseHandle(s_StopWorkerEvent);
+ s_StopWorkerEvent = NULL;
+ return error;
+}
+
+ThreadError otPlatUartDisable(void)
+{
+ ThreadError error = kThreadError_None;
+
+ // Set the shutdown event
+ SetEvent(s_StopWorkerEvent);
+
+ // Wait for the worker to compelte
+ WaitForSingleObject(s_WorkerThread, INFINITE);
+
+ CloseHandle(s_WorkerThread);
+ s_WorkerThread = NULL;
+
+ CloseHandle(s_StopWorkerEvent);
+ s_StopWorkerEvent = NULL;
+
+ return error;
+}
+
+ThreadError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
+{
+ ThreadError error = kThreadError_None;
+
+ DWORD dwNumCharsWritten = 0;
+ VerifyOrExit(WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), aBuf, aBufLength, &dwNumCharsWritten, NULL), error = kThreadError_Error);
+
+ otPlatUartSendDone();
+
+exit:
+ return error;
+}
+
+void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aErrorFdSet, int *aMaxFd)
+{
+ // No-op on Windows
+ UNREFERENCED_PARAMETER(aReadFdSet);
+ UNREFERENCED_PARAMETER(aWriteFdSet);
+ UNREFERENCED_PARAMETER(aErrorFdSet);
+ UNREFERENCED_PARAMETER(aMaxFd);
+}
+
+void platformUartProcess(void)
+{
+ // No-op on Windows
+}