Skip to content

Commit

Permalink
Sming Host Emulator (#1692)
Browse files Browse the repository at this point in the history
Initial PR providing support for building and running Sming applications directly within Host environment (Linux / Windows).

Implemented 
* Serial port driver emulation, based on gdbstub technique. Socket server support added to allow multiple terminal connection via telnet.
* Flash memory emulated using backing file
* Dummy gdbstub component (not required)
* Task queues
* Timers
* Basic time functions
* Network support for Linux and Windows
  
Dummy modules
* Digital
* Interrupts
  
Build
* Use different build subdirectory for Linux/Windows (based on UNAME)
* Add `HostTests` sample
	* Runs some tests against ArduinoJson6 and filesystem, asserts on failure
	* Remove related code from LiveDebug sample
* Travis-CI
  * Move script into separate `build.sh` file
  * Host compilation requires more up to date GCC - conflict with `std::isnan` and `std::isinf` and stdc function declarations
  * Build and run `HostTests` sample
* Appveyor
  * Add basic Host build

File layout changes
* Move `pwm.h` into `Components/drivers`, consistent with ESP-IDF
* Add `esp_wifi` component

Build conflicts
* Replace `itoa` macro with function definition
* Rename `random()` in WMath.cpp (name conflict)
* `#undef` conflicting structure member names in `gdb_syscall.h`
* Fix implementation of sprintf_P()

Fix `IMPORT_FSTR` for Linux/Windows host builds
* `.word` only emits 2 bytes on Linux, so use `.long` which is fine for all 32-bit machines
* Windows (COFF format) requires different implemention
* Use `.irom0.text`, not `.irom.text` (fixes 'section changed' warning)
  • Loading branch information
mikee47 authored and slaff committed May 30, 2019
1 parent 6a8da63 commit a8ce067
Show file tree
Hide file tree
Showing 192 changed files with 7,703 additions and 771 deletions.
42 changes: 42 additions & 0 deletions .appveyor/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
REM Windows build script

SET SMING_HOME=%APPVEYOR_BUILD_FOLDER%\Sming

IF "%SMING_ARCH%" == "Esp8266" SET ESP_HOME=c:\Espressif

cd %SMING_HOME%
gcc -v

make help
make list-config

REM Compile the tools first
make tools V=1 || goto :error

cd %SMING_HOME%
make STRICT=1 || goto :error


if "%SMING_ARCH%" == "Host" (

REM Build a couple of basic applications
make Basic_Serial || goto :error
make Basic_ProgMem || goto :error

REM Run basic tests
cd %SMING_HOME%\..\tests\HostTests
make flash || goto :error

) ELSE (

make Basic_Blink V=1 || goto :error
make Basic_Ssl || goto :error
make Basic_SmartConfig || goto :error

)

goto :EOF

:error
echo Failed with error #%errorlevel%.
exit /b %errorlevel%
26 changes: 26 additions & 0 deletions .appveyor/install.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
REM Windows install script

goto :%SMING_ARCH%

:Esp8266

IF "%SDK_VERSION%" == "1.5.0" (
choco install esp8266-udk --source https://www.myget.org/F/kireevco-chocolatey/ -y --no-progress
mkdir c:\Espressif\utils\ESP8266
copy /b c:\Espressif\utils\memanalyzer.exe c:\Espressif\utils\ESP8266\memanalyzer.exe
copy /b c:\Espressif\utils\esptool.exe c:\Espressif\utils\ESP8266\esptool.exe
) ELSE (
choco install esp8266-udk --source https://www.myget.org/F/sming/ -y --no-progress
)

goto :EOF


:Host

REM Ensure MinGW installation is up to date
mingw-get update
mingw-get upgrade

goto :EOF

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ vssver2.scc

.metadata
.submodule
/Sming/Arch/Host/Components/lwip/Windows/src
/Sming/Arch/Host/Components/lwip/Windows/tmp
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@
[submodule "Libraries.ArduinoJson"]
path = Sming/Libraries/ArduinoJson
url = https://github.com/bblanchon/ArduinoJson.git

[submodule "Host.lwip"]
path = Sming/Arch/Host/Components/lwip/lwip
url = git://git.savannah.gnu.org/lwip.git
ignore = dirty
80 changes: 32 additions & 48 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,34 @@ env:
global:
- SDK_BUILD=258
- secure: D/cPk+sL2MNHLtfuU/rMiVN63+CTFpo9Chqa39LEH5VloGqC5f7RyIi2Maa3C/U2JQfM01HlsNR7E5bB0W8DQYbtzBDTqbZ4C7ppZRU5jCQ+L51ERKJ0EAV3KkaravQCRbWt3tlgOp6Xk6xaRMBaHEGrdbFjHYgEMPVteUQNr0A=
matrix:
jobs:
include:
- os: linux
env: SDK_VERSION=1.5.0
- os: linux
env: SDK_VERSION=2.0.0
- os: linux
env: SDK_VERSION=3.0.0
- stage: test
os: linux
dist: xenial
addons:
apt:
packages:
- clang-format-6.0
- gcc-multilib
- g++-multilib
env: SMING_ARCH=Host

- stage: build
os: linux
env: SMING_ARCH=Esp8266 SDK_VERSION=1.5.0

- stage: build
os: linux
env: SMING_ARCH=Esp8266 SDK_VERSION=2.0.0

- stage: build
os: linux
env: SMING_ARCH=Esp8266 SDK_VERSION=3.0.0

git:
submodules: false

addons:
apt:
sources:
Expand All @@ -27,53 +45,19 @@ addons:
- doxygen-gui
- graphviz
- xmlstarlet
- clang-format-6.0
install:
- sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 100
- if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then export
SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip"; fi
- if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then export
SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz"; fi
- mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk
- if [ "$SDK_VERSION" == "1.5.0" ]; then wget https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME};
fi
- if [ "$SDK_VERSION" == "1.5.0" ]; then bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk;
fi
- if [[ "$SDK_VERSION" != "1.5.0" && "$TRAVIS_OS_NAME" == "linux" ]]; then wget https://github.com/nodemcu/nodemcu-firmware/raw/2d958750b56fc60297f564b4ec303e47928b5927/tools/esp-open-sdk.tar.xz;
tar -Jxvf esp-open-sdk.tar.xz; ln -s `pwd`/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/.
; fi
- if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then wget
https://www.espressif.com/sites/default/files/sdks/esp8266_nonos_sdk_v2.0.0_16_08_10.zip
-O sdk.zip; unzip sdk.zip; ln -s `pwd`/ESP8266_NONOS_SDK/ $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/sdk;
export DEPLOY='true'; fi
script:
- env
- unset SPIFFY
- unset ESPTOOL2

- export SMING_HOME=$TRAVIS_BUILD_DIR/Sming
- export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk
- if [ "$SDK_VERSION" == "3.0.0" ]; then export SDK_BASE=$SMING_HOME/third-party/ESP8266_NONOS_SDK;
fi
- export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/:$SMING_HOME/../.travis/tools
- cd $SMING_HOME
- if [ "$SDK_VERSION" == "2.0.0" ]; then ../.travis/tools/clang/format-pr.sh; fi
- cd $SMING_HOME
- make help
- make list-config
- make STRICT=1
- make samples
- make clean samples-clean
- make ENABLE_CUSTOM_HEAP=1 STRICT=1
- make Basic_Blink ENABLE_CUSTOM_HEAP=1 DEBUG_VERBOSE_LEVEL=3
- make dist-clean; make HttpServer_ConfigNetwork ENABLE_CUSTOM_LWIP=2 STRICT=1
install: .travis/install.sh

script: .travis/build.sh

deploy:
provider: script
script: sh $TRAVIS_BUILD_DIR/.travis/deploy.sh $TRAVIS_TAG
script: .travis/deploy.sh $TRAVIS_TAG
skip_cleanup: true
on:
tags: true
condition: "$DEPLOY == true"
condition: "$SDK_VERSION==2.0.0"

notifications:
webhooks:
urls:
Expand Down
48 changes: 48 additions & 0 deletions .travis/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
set -ex # exit with nonzero exit code if anything fails

env
unset SPIFFY
unset ESPTOOL2

export SMING_HOME=$TRAVIS_BUILD_DIR/Sming

# Check coding style
if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then
.travis/tools/clang/format-pr.sh;
fi

# Setup ARCH SDK paths
if [ "$SMING_ARCH" == "Esp8266" ]; then
export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk
if [ "$SDK_VERSION" == "3.0.0" ]; then
export SDK_BASE=$SMING_HOME/third-party/ESP8266_NONOS_SDK
fi

export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/
fi

# Full compile checks please
export STRICT=1

# Diagnostic info
cd $SMING_HOME
make help
make list-config

# Build the framework
make

if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then
make Basic_Blink Basic_DateTime Basic_Delegates Basic_Interrupts Basic_ProgMem Basic_Serial Basic_Servo LiveDebug DEBUG_VERBOSE_LEVEL=3
cd ../tests/HostTests
make flash
else
make samples
make clean samples-clean
make ENABLE_CUSTOM_HEAP=1 STRICT=1
make Basic_Blink ENABLE_CUSTOM_HEAP=1 DEBUG_VERBOSE_LEVEL=3

make dist-clean
make HttpServer_ConfigNetwork ENABLE_CUSTOM_LWIP=2 STRICT=1
fi
2 changes: 1 addition & 1 deletion .travis/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e # exit with nonzero exit code if anything fails
set -ex # exit with nonzero exit code if anything fails

TAG=$1
if [ -z $TAG ]; then
Expand Down
34 changes: 34 additions & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
set -ex # exit with nonzero exit code if anything fails

if [ "$TRAVIS_BUILD_STAGE_NAME" == "Test" ]; then
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-6.0 100
fi

if [ "$SMING_ARCH" == "Esp8266" ]; then
if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then
SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip"
fi

if [ "$SDK_VERSION" == "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz"
fi

mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk

if [ "$SDK_VERSION" == "1.5.0" ]; then
wget --no-verbose https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME}
bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk
fi

if [ "$SDK_VERSION" != "1.5.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
wget --no-verbose https://github.com/nodemcu/nodemcu-firmware/raw/2d958750b56fc60297f564b4ec303e47928b5927/tools/esp-open-sdk.tar.xz
tar -Jxvf esp-open-sdk.tar.xz; ln -s $(pwd)/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/.
fi

if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
wget --no-verbose https://www.espressif.com/sites/default/files/sdks/esp8266_nonos_sdk_v2.0.0_16_08_10.zip -O sdk.zip
unzip sdk.zip
ln -s $(pwd)/ESP8266_NONOS_SDK/ $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/sdk
fi
fi # Esp8266
11 changes: 11 additions & 0 deletions Sming/Arch/Esp8266/Components/driver/include/driver/pwm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#if defined(__cplusplus)
extern "C" {
#endif

#include <pwm.h>

#if defined(__cplusplus)
}
#endif
12 changes: 12 additions & 0 deletions Sming/Arch/Esp8266/Components/esp_wifi/include/esp_smartconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#if defined (__cplusplus)
extern "C" {
#endif

#include <smartconfig.h>

#if defined (__cplusplus)
}
#endif

11 changes: 11 additions & 0 deletions Sming/Arch/Esp8266/Components/esp_wifi/include/esp_wifi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <user_interface.h>

#ifdef __cplusplus
}
#endif
42 changes: 1 addition & 41 deletions Sming/Arch/Esp8266/Platform/WifiEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,7 @@ WifiEventsClass WifiEvents;

WifiEventsClass::WifiEventsClass()
{
wifi_set_event_handler_cb(staticWifiEventHandler);
}

void WifiEventsClass::onStationConnect(StationConnectDelegate delegateFunction)
{
onSTAConnect = delegateFunction;
}

void WifiEventsClass::onStationDisconnect(StationDisconnectDelegate delegateFunction)
{
onSTADisconnect = delegateFunction;
}

void WifiEventsClass::onStationAuthModeChange(StationAuthModeChangeDelegate delegateFunction)
{
onSTAAuthModeChange = delegateFunction;
}

void WifiEventsClass::onStationGotIP(StationGotIPDelegate delegateFunction)
{
onSTAGotIP = delegateFunction;
}

void WifiEventsClass::onAccessPointConnect(AccessPointConnectDelegate delegateFunction)
{
onSOFTAPConnect = delegateFunction;
}

void WifiEventsClass::onAccessPointDisconnect(AccessPointDisconnectDelegate delegateFunction)
{
onSOFTAPDisconnect = delegateFunction;
}

void WifiEventsClass::onAccessPointProbeReqRecved(AccessPointProbeReqRecvedDelegate delegateFunction)
{
onSOFTAPProbeReqRecved = delegateFunction;
}

void WifiEventsClass::staticWifiEventHandler(System_Event_t* evt)
{
WifiEvents.WifiEventHandler(evt);
wifi_set_event_handler_cb([](System_Event_t* evt) { WifiEvents.WifiEventHandler(evt); });
}

void WifiEventsClass::WifiEventHandler(System_Event_t* evt)
Expand Down
4 changes: 0 additions & 4 deletions Sming/Arch/Esp8266/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#
###

ifndef ESP_HOME
$(error ESP_HOME variable is not set to a valid directory.)
endif

##@Building

.PHONY: all
Expand Down
9 changes: 2 additions & 7 deletions Sming/Arch/Esp8266/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#
##############

CFLAGS += -DARCH_ESP8266
CFLAGS += -DARCH_ESP8266
CXXFLAGS += -fno-rtti -fno-exceptions

ifndef ESP_HOME
$(error ESP_HOME variable is not set to a valid directory.)
Expand All @@ -17,12 +18,6 @@ endif
## MacOS / Linux:
# ESP_HOME = /opt/esp-open-sdk

#ifeq ($(OS),Windows_NT)
# # Convert Windows paths to POSIX paths
# ESP_HOME := $(subst \,/,$(addprefix /,$(subst :,,$(ESP_HOME))))
# ESP_HOME := $(subst //,/,$(ESP_HOME))
#endif

CONFIG_VARS += ESP_HOME
ESP_HOME := $(call FixPath,$(ESP_HOME))
export ESP_HOME
Expand Down
Loading

0 comments on commit a8ce067

Please sign in to comment.