Skip to content

Commit

Permalink
Test, simplify init
Browse files Browse the repository at this point in the history
Don't need `host_init`, just wrap `init`
  • Loading branch information
mikee47 committed Apr 22, 2024
1 parent e8d825c commit 97e6bda
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 135 deletions.
30 changes: 0 additions & 30 deletions Sming/Arch/Host/Components/hostlib/include/hostlib/init.h

This file was deleted.

27 changes: 0 additions & 27 deletions Sming/Arch/Host/Components/hostlib/init.cpp

This file was deleted.

5 changes: 3 additions & 2 deletions Sming/Arch/Host/Components/hostlib/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <driver/hw_timer.h>
#include <esp_tasks.h>
#include <stdlib.h>
#include "include/hostlib/init.h"
#include "include/hostlib/emu.h"
#include "include/hostlib/hostlib.h"
#include "include/hostlib/CommandLine.h"
Expand All @@ -43,6 +42,8 @@
#include <host_lwip.h>
#endif

extern void init();

namespace
{
static int exitCode;
Expand Down Expand Up @@ -286,7 +287,7 @@ int main(int argc, char* argv[])

System.initialize();

host_init();
init();

while(!done) {
int due = host_main_loop();
Expand Down
4 changes: 3 additions & 1 deletion Sming/Arch/Host/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ TARGET_OUT_0 := $(FW_BASE)/$(APP_NAME)$(TOOL_EXT)

# Hosted Settings
ifneq ($(ENABLE_HOSTED),)
COMPONENTS_AR := $(USER_LIBDIR)/$(CLIB_PREFIX)Hosted-Lib-$(CMP_Hosted-Lib_LIBHASH).a $(COMPONENTS_AR)
COMPONENTS_AR := \
$(CMP_Hosted-Lib_TARGETS) \
$(COMPONENTS_AR)
endif

# Target definitions
Expand Down
8 changes: 6 additions & 2 deletions Sming/Components/Hosted/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ HostEd
The hosted component allows Sming's host emulator to run parts of the commands on an actual microcontroller.
The communication is done via `simplePRC <https://simplerpc.readthedocs.io/>`_ and the microcontroller has to be flashed with a special application.


Overview
--------

Sming's host emulator allows easier debugging and development of embedded applications. This component named "Hosted" extends the host emulator
and facilitates testing functionality that only a real microcontroller can provide as for example digital I/O operations or SPI operations.

Expand All @@ -24,7 +26,7 @@ We need to compile and flash also a special application on the desired microcont
This application will act as an RPC Server and will execute the commands from the host emulator on the microcontroller.

In the ``samples`` directory you will find the sample applications that will turn your microcontroller into
an RCP server.
an RPC server.

The compilation and flashing for ESP32, for example, can be done using the following commands::

Expand All @@ -33,7 +35,8 @@ The compilation and flashing for ESP32, for example, can be done using the follo
make flash

If you replace ``SMING_ARCH=Esp32`` with ``SMING_ARCH=Esp8266`` then the hosted application will be compiled and flashed on a ESP8266 microcontroller.
Make sure to replace the values of  WIFI_SSID and WIFI_PWD with the actual name and password for the Access Point (AP).
Make sure to replace the values of WIFI_SSID and WIFI_PWD with the actual name and password for the Access Point (AP).


Communication
-------------
Expand All @@ -42,6 +45,7 @@ can be done using TCP or serial interface.

The ``transport`` classes are located under ``include/Hosted/Transport``.


Configuration
-------------

Expand Down
16 changes: 10 additions & 6 deletions Sming/Components/Hosted/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENABLE_HOSTED ?=

ifneq ($(ENABLE_HOSTED),)
COMPONENT_SRCDIRS += init/$(ENABLE_HOSTED)
EXTRA_LDFLAGS := $(call Wrap,host_init)
EXTRA_LDFLAGS := $(call Wrap,_Z4initv)
COMPONENT_DEPENDS += SerialLib
ifeq ($(ENABLE_HOSTED),tcp)
COMPONENT_DEPENDS += Network
Expand All @@ -20,13 +20,17 @@ ifneq ($(ENABLE_HOSTED),)
endif
endif

COMPONENT_RELINK_VARS += HOSTED_SERVER_IP
COMPONENT_RELINK_VARS += \
HOSTED_SERVER_IP \
HOSTED_COM_PORT \
HOSTED_COM_SPEED

COMPONENT_RELINK_VARS += HOSTED_COM_PORT
HOSTED_COM_PORT ?= $(COM_PORT)

COMPONENT_RELINK_VARS += HOSTED_COM_SPEED
HOSTED_COM_SPEED ?= 115200

COMPONENT_CFLAGS = -DHOSTED_SERVER_IP=$(HOSTED_SERVER_IP) -DHOSTED_COM_PORT="\"$(HOSTED_COM_PORT)"\" -DHOSTED_COM_SPEED=$(HOSTED_COM_SPEED)
COMPONENT_CFLAGS = \
-DHOSTED_SERVER_IP=$(HOSTED_SERVER_IP) \
-DHOSTED_COM_PORT="\"$(HOSTED_COM_PORT)"\" \
-DHOSTED_COM_SPEED=$(HOSTED_COM_SPEED)

COMPONENT_CXXFLAGS := $(COMPONENT_CFLAGS)
1 change: 0 additions & 1 deletion Sming/Components/Hosted/include/Hosted/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ class Serial : public Stream

private:
String ttyDevice;

serialib transport;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <Stream.h>
#include <Delegate.h>

namespace Hosted
{
namespace Transport
namespace Hosted::Transport
{
class BaseTransport
{
Expand All @@ -38,6 +36,4 @@ class BaseTransport
DataHandler handler;
};

} // namespace Transport

} // namespace Hosted
} // namespace Hosted::Transport
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <HardwareSerial.h>
#include "BaseTransport.h"

namespace Hosted
{
namespace Transport
namespace Hosted::Transport
{
class SerialTransport : public BaseTransport
{
Expand All @@ -35,6 +33,4 @@ class SerialTransport : public BaseTransport
}
};

} // namespace Transport

} // namespace Hosted
} // namespace Hosted::Transport
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
#include <Network/TcpServer.h>
#include <Data/Buffer/CircularBuffer.h>

namespace Hosted
{
namespace Transport
namespace Hosted::Transport
{
class TcpClientStream : public Stream
{
public:
TcpClientStream(TcpClient& client, size_t cbufferSize = 1024, size_t threshold = 400)
: cBuffer(cbufferSize), client(client), pendingBytes(0), threshold(threshold)
: cBuffer(cbufferSize), client(client), threshold(threshold)
{
client.setReceiveDelegate(TcpClientDataDelegate(&TcpClientStream::store, this));
}
Expand Down Expand Up @@ -87,7 +85,7 @@ class TcpClientStream : public Stream
private:
CircularBuffer cBuffer;
TcpClient& client;
size_t pendingBytes;
size_t pendingBytes{0};
size_t threshold;

bool store(TcpClient& client, char* data, int size)
Expand All @@ -96,6 +94,4 @@ class TcpClientStream : public Stream
}
};

} // namespace Transport

} // namespace Hosted
} // namespace Hosted::Transport
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
#include "TcpClientStream.h"
#include <memory>

namespace Hosted
{
namespace Transport
namespace Hosted::Transport
{
class TcpClientTransport : public TcpTransport
{
public:
TcpClientTransport(TcpClient& client) : stream(new TcpClientStream(client))
TcpClientTransport(TcpClient& client) : stream(std::make_unique<TcpClientStream>(client))
{
client.setReceiveDelegate(TcpClientDataDelegate(&TcpClientTransport::process, this));
}
Expand All @@ -44,6 +42,4 @@ class TcpClientTransport : public TcpTransport
std::unique_ptr<TcpClientStream> stream;
};

} // namespace Transport

} // namespace Hosted
} // namespace Hosted::Transport
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
#include "TcpTransport.h"
#include "TcpClientStream.h"

namespace Hosted
{
namespace Transport
namespace Hosted::Transport
{
class TcpServerTransport : public TcpTransport
{
public:
using ClientMap = ObjectMap<TcpClient*, TcpClientStream>;

TcpServerTransport(TcpServer& server)
{
server.setClientReceiveHandler(TcpClientDataDelegate(&TcpServerTransport::process, this));
Expand All @@ -52,9 +48,9 @@ class TcpServerTransport : public TcpTransport
}

private:
using ClientMap = ObjectMap<TcpClient*, TcpClientStream>;

ClientMap map;
};

} // namespace Transport

} // namespace Hosted
} // namespace Hosted::Transport
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
#include <Network/TcpServer.h>
#include "BaseTransport.h"

namespace Hosted
{
namespace Transport
namespace Hosted::Transport
{
class TcpTransport : public BaseTransport
{
protected:
virtual bool process(TcpClient& client, char* data, int size) = 0;
};

} // namespace Transport

} // namespace Hosted
} // namespace Hosted::Transport
20 changes: 9 additions & 11 deletions Sming/Components/Hosted/init/serial/InitClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,25 @@
#define HOSTED_COM_SPEED 115200
#endif

Hosted::Client* hostedClient{nullptr};
Hosted::Client* hostedClient;

extern void init();

extern "C" {
void __real_host_init();
void __wrap_host_init();
}
extern "C" void __real__Z4initv();

namespace
{
Hosted::Serial hostedSerial(HOSTED_COM_PORT);
}

void __wrap_host_init()
extern "C" void __wrap__Z4initv()
{
host_printf("Connecting to: %s ...\r\n", HOSTED_COM_PORT);

bool serialReady = false;
while(!(serialReady = hostedSerial.begin(HOSTED_COM_SPEED))) {
while(!hostedSerial.begin(HOSTED_COM_SPEED)) {
msleep(50);
}

hostedClient = new Hosted::Client(hostedSerial, '>');
hostedClient->getRemoteCommands();
init();

__real__Z4initv();
}
Loading

0 comments on commit 97e6bda

Please sign in to comment.