Merge pull request 'micro' (#83) from micro into master

Reviewed-on: https://git.shs.tools/SHS/pip/pulls/83
This commit was merged in pull request #83.
This commit is contained in:
2022-03-14 12:10:32 +03:00
50 changed files with 490 additions and 220 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@
/doc/rtf /doc/rtf
_unsused _unsused
CMakeLists.txt.user* CMakeLists.txt.user*
/include

29
library.json Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "PIP",
"keywords": "pip",
"description": "Platform-Independent Primitives",
"repository":
{
"type": "git",
"url": "https://git.shs.tools/SHS/pip.git"
},
"frameworks": "*",
"platforms": "*",
"dependencies": {
"mike-matera/ArduinoSTL": "^1.3.2",
"linlin-study/FreeRTOS-Kernel": ">=10.0.0"
},
"build":
{
"srcFilter": [
"+<libs/main/core/*.cpp>",
"+<libs/main/containers/*.cpp>",
"+<libs/main/math/*.cpp>",
"+<libs/main/thread/*.cpp>",
"+<libs/main/io_uutils/*.cpp>",
"+<libs/main/geo/*.cpp>"
],
"extraScript": "platformio_pre.py",
"flags": "-DPIP_FREERTOS"
}
}

View File

@@ -19,7 +19,7 @@
#include "picompress.h" #include "picompress.h"
#ifdef PIP_COMPRESS #ifdef PIP_COMPRESS
# ifdef FREERTOS # ifdef ESP_PLATFORM
# include "esp32/rom/miniz.h" # include "esp32/rom/miniz.h"
# define compress2 mz_compress2 # define compress2 mz_compress2
# define Z_OK MZ_OK # define Z_OK MZ_OK

View File

@@ -63,7 +63,7 @@ PIScreen::SystemConsole::SystemConsole() {
GetConsoleMode(PRIVATE->hOut, &PRIVATE->smode); GetConsoleMode(PRIVATE->hOut, &PRIVATE->smode);
GetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo); GetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo);
#else #else
# ifdef FREERTOS # ifdef MICRO_PIP
w = 80; w = 80;
h = 24; h = 24;
# else # else
@@ -115,7 +115,7 @@ void PIScreen::SystemConsole::prepare() {
w = PRIVATE->csbi.srWindow.Right - PRIVATE->csbi.srWindow.Left + 1; w = PRIVATE->csbi.srWindow.Right - PRIVATE->csbi.srWindow.Left + 1;
h = PRIVATE->csbi.srWindow.Bottom - PRIVATE->csbi.srWindow.Top + 1; h = PRIVATE->csbi.srWindow.Bottom - PRIVATE->csbi.srWindow.Top + 1;
#else #else
# ifndef FREERTOS # ifndef MICRO_PIP
winsize ws; winsize ws;
ioctl(0, TIOCGWINSZ, &ws); ioctl(0, TIOCGWINSZ, &ws);
w = ws.ws_col; w = ws.ws_col;

View File

@@ -19,7 +19,7 @@
#include "piincludes_p.h" #include "piincludes_p.h"
#include "piterminal.h" #include "piterminal.h"
#include "pisharedmemory.h" #include "pisharedmemory.h"
#ifndef FREERTOS #ifndef MICRO_PIP
#ifdef WINDOWS #ifdef WINDOWS
# include <windows.h> # include <windows.h>
# include <wingdi.h> # include <wingdi.h>
@@ -918,4 +918,4 @@ bool PITerminal::resize(int cols, int rows) {
return ret; return ret;
} }
#endif // FREERTOS #endif // MICRO_PIP

View File

@@ -31,8 +31,6 @@
#include "pip_export.h" #include "pip_export.h"
#include "pip_defs.h" #include "pip_defs.h"
#include "string.h" #include "string.h"
#include <limits>
//! Meta-information section for any entity. //! Meta-information section for any entity.
//! Parsing by \a pip_cmg and can be accessed by \a PICodeInfo. //! Parsing by \a pip_cmg and can be accessed by \a PICodeInfo.
//! Contains sequence of key=value pairs, e.g. //! Contains sequence of key=value pairs, e.g.
@@ -119,9 +117,15 @@
#endif //DOXYGEN #endif //DOXYGEN
#ifdef CC_AVR_GCC
# include <ArduinoSTL.h>
#endif
#include <functional> #include <functional>
#include <cstddef> #include <cstddef>
#include <cassert>
#include <limits>
#include <atomic>
#ifdef WINDOWS #ifdef WINDOWS
# ifdef CC_VC # ifdef CC_VC
# define SHUT_RDWR 2 # define SHUT_RDWR 2
@@ -162,7 +166,6 @@
#ifdef NDEBUG #ifdef NDEBUG
# undef NDEBUG # undef NDEBUG
#endif #endif
#include <cassert>
#ifndef assert #ifndef assert
# define assert(x) # define assert(x)
# define assertm(exp, msg) # define assertm(exp, msg)
@@ -275,7 +278,7 @@
} _PIP_ADD_COUNTER(_pip_initializer_); } _PIP_ADD_COUNTER(_pip_initializer_);
#ifdef FREERTOS #ifdef MICRO_PIP
# define PIP_MIN_MSLEEP 10. # define PIP_MIN_MSLEEP 10.
#else #else
# define PIP_MIN_MSLEEP 1. # define PIP_MIN_MSLEEP 1.
@@ -499,13 +502,13 @@ template<typename T> inline void piLetobe(T * v) {piLetobe(v, sizeof(T));}
template<typename T> inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, sizeof(T)); return tv;} template<typename T> inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, sizeof(T)); return tv;}
// specialization // specialization
template<> inline ushort piLetobe(const ushort & v) {return (v << 8) | (v >> 8);} template<> inline uint16_t piLetobe(const uint16_t & v) {return (v << 8) | (v >> 8);}
template<> inline uint piLetobe(const uint & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);} template<> inline uint32_t piLetobe(const uint32_t & v) {return (v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | ((v << 24) & 0xFF000000);}
template<> inline float piLetobe(const float & v) { template<> inline float piLetobe(const float & v) {
union _pletobe_f { union _pletobe_f {
_pletobe_f(const float &f_) {f = f_;} _pletobe_f(const float &f_) {f = f_;}
float f; float f;
uint v; uint32_t v;
}; };
_pletobe_f a(v); _pletobe_f a(v);
a.v = (a.v >> 24) | ((a.v >> 8) & 0xFF00) | ((a.v << 8) & 0xFF0000) | ((a.v << 24) & 0xFF000000); a.v = (a.v >> 24) | ((a.v >> 8) & 0xFF00) | ((a.v << 8) & 0xFF0000) | ((a.v << 24) & 0xFF000000);

View File

@@ -29,7 +29,7 @@
#include "pivector2d.h" #include "pivector2d.h"
#include <stdio.h> #include <stdio.h>
#ifdef FREERTOS #ifdef MICRO_PIP
# define _TYPENAME_(T) "?" # define _TYPENAME_(T) "?"
#else #else
# define _TYPENAME_(T) typeid(T).name() # define _TYPENAME_(T) typeid(T).name()

View File

@@ -26,15 +26,15 @@
#ifdef PIP_STD_IOSTREAM #ifdef PIP_STD_IOSTREAM
# include <iostream> # include <iostream>
#endif #endif
#include <atomic>
class PIMutex; class PIMutex;
class PIMutexLocker; class PIMutexLocker;
class PIObject; class PIObject;
class PIString; class PIString;
class PIByteArray; class PIByteArray;
#ifndef MICRO_PIP
class PIInit; class PIInit;
#endif
class PIChar; class PIChar;
class PICout; class PICout;

View File

@@ -40,6 +40,15 @@ typedef LONG(NTAPI*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#ifdef FREERTOS
# ifdef ESP_PLATFORM
# include "freertos/FreeRTOS.h"
# include "freertos/task.h"
# endif
# ifdef ARDUINO_ARCH_STM32
# include <STM32FreeRTOS.h>
# endif
#endif
#endif // PIINCLUDES_P_H #endif // PIINCLUDES_P_H

View File

@@ -19,15 +19,15 @@
#include "piincludes_p.h" #include "piincludes_p.h"
#include "piinit.h" #include "piinit.h"
#ifndef MICRO_PIP
#include "pitime.h" #include "pitime.h"
#include "pisignals.h" #include "pisignals.h"
#include "piobject.h" #include "piobject.h"
#include "pisysteminfo.h" #include "pisysteminfo.h"
#include "piresourcesstorage.h" #include "piresourcesstorage.h"
#include "pidir.h" #include "pidir.h"
#ifndef FREERTOS #include "piprocess.h"
# include "piprocess.h"
#endif
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
# include "esp_system.h" # include "esp_system.h"
#endif #endif
@@ -49,9 +49,7 @@ void __PISetTimerResolution() {
} }
#else #else
# include <pwd.h> # include <pwd.h>
# ifndef FREERTOS
# include <sys/utsname.h> # include <sys/utsname.h>
# endif
# include <pthread.h> # include <pthread.h>
# ifdef BLACKBERRY # ifdef BLACKBERRY
# include <signal.h> # include <signal.h>
@@ -84,7 +82,6 @@ ULONG prev_res;
bool delete_locs; bool delete_locs;
PRIVATE_DEFINITION_END(PIInit) PRIVATE_DEFINITION_END(PIInit)
#ifndef FREERTOS
void __sighandler__(PISignals::Signal s) { void __sighandler__(PISignals::Signal s) {
//piCout << Hex << int(s); //piCout << Hex << int(s);
if (s == PISignals::StopTTYInput || s == PISignals::StopTTYOutput) if (s == PISignals::StopTTYInput || s == PISignals::StopTTYOutput)
@@ -92,7 +89,6 @@ void __sighandler__(PISignals::Signal s) {
if (s == PISignals::UserDefined1) if (s == PISignals::UserDefined1)
dumpApplicationToFile(PIDir::home().path() + PIDir::separator + PIStringAscii("_PIP_DUMP_") + PIString::fromNumber(PIProcess::currentPID())); dumpApplicationToFile(PIDir::home().path() + PIDir::separator + PIStringAscii("_PIP_DUMP_") + PIString::fromNumber(PIProcess::currentPID()));
} }
#endif
#ifdef ANDROID #ifdef ANDROID
@@ -107,7 +103,6 @@ PIInit::PIInit() {
PISystemInfo * sinfo = PISystemInfo::instance(); PISystemInfo * sinfo = PISystemInfo::instance();
sinfo->execDateTime = PIDateTime::current(); sinfo->execDateTime = PIDateTime::current();
setFileCharset("UTF-8"); setFileCharset("UTF-8");
#ifndef FREERTOS
#ifndef ANDROID #ifndef ANDROID
PISignals::setSlot(__sighandler__); PISignals::setSlot(__sighandler__);
PISignals::grabSignals(PISignals::UserDefined1); PISignals::grabSignals(PISignals::UserDefined1);
@@ -128,7 +123,7 @@ PIInit::PIInit() {
break; break;
} }
} }
# else # else //WINDOWS
// OS version // OS version
DWORD dwVersion = GetVersion(); DWORD dwVersion = GetVersion();
DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
@@ -154,7 +149,7 @@ PIInit::PIInit() {
setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution"); setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution");
__PISetTimerResolution(); __PISetTimerResolution();
} }
# endif # endif //WINDOWS
# ifdef HAS_LOCALE # ifdef HAS_LOCALE
//cout << "has locale" << endl; //cout << "has locale" << endl;
if (currentLocale_t != 0) { if (currentLocale_t != 0) {
@@ -162,18 +157,18 @@ PIInit::PIInit() {
currentLocale_t = 0; currentLocale_t = 0;
} }
currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0); currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0);
# else # else //HAS_LOCALE
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
setlocale(LC_NUMERIC, "C"); setlocale(LC_NUMERIC, "C");
# endif # endif //HAS_LOCALE
#else #else //ANDROID
struct sigaction actions; struct sigaction actions;
memset(&actions, 0, sizeof(actions)); memset(&actions, 0, sizeof(actions));
sigemptyset(&actions.sa_mask); sigemptyset(&actions.sa_mask);
actions.sa_flags = 0; actions.sa_flags = 0;
actions.sa_handler = android_thread_exit_handler; actions.sa_handler = android_thread_exit_handler;
sigaction(SIGTERM, &actions, 0); sigaction(SIGTERM, &actions, 0);
#endif #endif //ANDROID
PRIVATE->delete_locs = false; PRIVATE->delete_locs = false;
__syslocname__ = __sysoemname__ = 0; __syslocname__ = __sysoemname__ = 0;
__utf8name__ = const_cast<char*>("UTF-8"); __utf8name__ = const_cast<char*>("UTF-8");
@@ -201,13 +196,13 @@ PIInit::PIInit() {
# endif # endif
//piCout << __syslocname__; //piCout << __syslocname__;
//piCout << __sysoemname__; //piCout << __sysoemname__;
#else #else //PIP_ICU
# ifdef WINDOWS # ifdef WINDOWS
__syslocname__ = (char *)CP_ACP; __syslocname__ = (char *)CP_ACP;
__sysoemname__ = (char *)CP_OEMCP; __sysoemname__ = (char *)CP_OEMCP;
__utf8name__ = (char *)CP_UTF8; __utf8name__ = (char *)CP_UTF8;
# endif # endif
#endif #endif //PIP_ICU
#ifdef MAC_OS #ifdef MAC_OS
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock); host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock);
#endif #endif
@@ -236,7 +231,7 @@ PIInit::PIInit() {
ulong unlen = 1023; ulong unlen = 1023;
if (GetUserName(cbuff, &unlen) != 0) if (GetUserName(cbuff, &unlen) != 0)
sinfo->user = cbuff; sinfo->user = cbuff;
#else #else //WINDOWS
sinfo->processorsCount = piMaxi(1, int(sysconf(_SC_NPROCESSORS_ONLN))); sinfo->processorsCount = piMaxi(1, int(sysconf(_SC_NPROCESSORS_ONLN)));
passwd * ps = getpwuid(getuid()); passwd * ps = getpwuid(getuid());
if (ps) if (ps)
@@ -252,8 +247,8 @@ PIInit::PIInit() {
sinfo->OS_version = uns.release; sinfo->OS_version = uns.release;
sinfo->architecture = uns.machine; sinfo->architecture = uns.machine;
} }
# endif #endif //WINDOWS
#endif
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
esp_chip_info_t chip_info; esp_chip_info_t chip_info;
esp_chip_info(&chip_info); esp_chip_info(&chip_info);
@@ -275,6 +270,8 @@ PIInit::PIInit() {
PIStringAscii("FreeBSD"); PIStringAscii("FreeBSD");
#elif defined(FREERTOS) #elif defined(FREERTOS)
PIStringAscii("FreeRTOS"); PIStringAscii("FreeRTOS");
#elif defined(MICRO_PIP)
PIStringAscii("MicroPIP");
#else #else
uns.sysname; uns.sysname;
#endif #endif
@@ -305,49 +302,49 @@ PIInit::~PIInit() {
bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) { bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) {
switch (o) { switch (o) {
case ICU: return case boICU: return
#ifdef PIP_ICU #ifdef PIP_ICU
true; true;
#else #else
false; false;
#endif #endif
case USB: return case boUSB: return
#ifdef PIP_USB #ifdef PIP_USB
true; true;
#else #else
false; false;
#endif #endif
case Crypt: return case boCrypt: return
#ifdef PIP_CRYPT #ifdef PIP_CRYPT
true; true;
#else #else
false; false;
#endif #endif
case Introspection: return case boIntrospection: return
#ifdef PIP_INTROSPECTION #ifdef PIP_INTROSPECTION
true; true;
#else #else
false; false;
#endif #endif
case FFTW: return case boFFTW: return
#ifdef PIP_FFTW #ifdef PIP_FFTW
true; true;
#else #else
false; false;
#endif #endif
case Compress: return case boCompress: return
#ifdef PIP_COMPRESS #ifdef PIP_COMPRESS
true; true;
#else #else
false; false;
#endif #endif
case OpenCL: return case boOpenCL: return
#ifdef PIP_OPENCL #ifdef PIP_OPENCL
true; true;
#else #else
false; false;
#endif #endif
case Cloud: return case boCloud: return
#ifdef PIP_CLOUD #ifdef PIP_CLOUD
true; true;
#else #else
@@ -361,14 +358,14 @@ bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) {
PIStringList PIInit::buildOptions() { PIStringList PIInit::buildOptions() {
PIStringList ret; PIStringList ret;
if (isBuildOptionEnabled(ICU)) ret << "ICU"; if (isBuildOptionEnabled(boICU)) ret << "ICU";
if (isBuildOptionEnabled(USB)) ret << "USB"; if (isBuildOptionEnabled(boUSB)) ret << "USB";
if (isBuildOptionEnabled(Crypt)) ret << "Crypt"; if (isBuildOptionEnabled(boCrypt)) ret << "Crypt";
if (isBuildOptionEnabled(Introspection)) ret << "Introspection"; if (isBuildOptionEnabled(boIntrospection)) ret << "Introspection";
if (isBuildOptionEnabled(FFTW)) ret << "FFTW"; if (isBuildOptionEnabled(boFFTW)) ret << "FFTW";
if (isBuildOptionEnabled(Compress)) ret << "Compress"; if (isBuildOptionEnabled(boCompress)) ret << "Compress";
if (isBuildOptionEnabled(OpenCL)) ret << "OpenCL"; if (isBuildOptionEnabled(boOpenCL)) ret << "OpenCL";
if (isBuildOptionEnabled(Cloud)) ret << "Cloud"; if (isBuildOptionEnabled(boCloud)) ret << "Cloud";
return ret; return ret;
} }
@@ -415,3 +412,6 @@ __PIInit_Initializer__::~__PIInit_Initializer__() {
__instance__ = 0; __instance__ = 0;
} }
} }
#endif // MICRO_PIP

View File

@@ -23,6 +23,10 @@
#ifndef PIINIT_H #ifndef PIINIT_H
#define PIINIT_H #define PIINIT_H
#include "pibase.h"
#ifndef MICRO_PIP
#include "piincludes.h" #include "piincludes.h"
@@ -49,14 +53,14 @@ public:
//! @brief Build options which PIP library was built //! @brief Build options which PIP library was built
enum BuildOption { enum BuildOption {
ICU /*! Unicode support */ = 0x01, boICU /*! Unicode support */ = 0x01,
USB /*! USB support */ = 0x02, boUSB /*! USB support */ = 0x02,
Crypt /*! Crypt support */ = 0x08, boCrypt /*! Crypt support */ = 0x08,
Introspection /*! Introspection */ = 0x010, boIntrospection /*! Introspection */ = 0x010,
FFTW /*! FFTW3 support */ = 0x40, boFFTW /*! FFTW3 support */ = 0x40,
Compress /*! Zlib compression support */ = 0x80, boCompress /*! Zlib compression support */ = 0x80,
OpenCL /*! OpenCL support */ = 0x100, boOpenCL /*! OpenCL support */ = 0x100,
Cloud /*! Cloud transport support */ = 0x200, boCloud /*! Cloud transport support */ = 0x200,
}; };
static PIInit * instance() {return __PIInit_Initializer__::__instance__;} static PIInit * instance() {return __PIInit_Initializer__::__instance__;}
static bool isBuildOptionEnabled(BuildOption o); static bool isBuildOptionEnabled(BuildOption o);
@@ -70,4 +74,5 @@ private:
}; };
#endif // MICRO_PIP
#endif // PIINIT_H #endif // PIINIT_H

View File

@@ -18,10 +18,10 @@
*/ */
#include "piobject.h" #include "piobject.h"
#include "pisysteminfo.h"
#include "pithread.h" #include "pithread.h"
#include "piconditionvar.h" #include "piconditionvar.h"
#ifndef FREERTOS #ifndef MICRO_PIP
# include "pisysteminfo.h"
# include "pifile.h" # include "pifile.h"
#endif #endif
@@ -355,7 +355,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig) {
src->connections.remove(i); src->connections.remove(i);
i--; i--;
if (dest) { if (dest) {
#if !defined(ANDROID) && !defined(MAC_OS) && !defined(FREERTOS) #if !defined(ANDROID) && !defined(MAC_OS) && !defined(MICRO_PIP)
PIMutexLocker _mld(dest->mutex_connect, src != dest); PIMutexLocker _mld(dest->mutex_connect, src != dest);
#endif #endif
dest->updateConnectors(); dest->updateConnectors();
@@ -373,7 +373,7 @@ void PIObject::piDisconnectAll() {
// piCout << "disconnect"<< src << o; // piCout << "disconnect"<< src << o;
if (!o || (o == this)) continue; if (!o || (o == this)) continue;
if (!o->isPIObject()) continue; if (!o->isPIObject()) continue;
#if !defined(ANDROID) && !defined(MAC_OS) && !defined(FREERTOS) #if !defined(ANDROID) && !defined(MAC_OS) && !defined(MICRO_PIP)
PIMutexLocker _mld(o->mutex_connect, this != o); PIMutexLocker _mld(o->mutex_connect, this != o);
#endif #endif
PIVector<Connection> & oc(o->connections); PIVector<Connection> & oc(o->connections);
@@ -589,6 +589,7 @@ void PIObject::dump(const PIString & line_prefix) const {
} }
#ifndef MICRO_PIP
void dumpApplication() { void dumpApplication() {
PIMutexLocker _ml(PIObject::mutexObjects()); PIMutexLocker _ml(PIObject::mutexObjects());
//printf("dump application ...\n"); //printf("dump application ...\n");
@@ -615,7 +616,6 @@ void dumpApplication() {
} }
#ifndef FREERTOS
bool dumpApplicationToFile(const PIString & path) { bool dumpApplicationToFile(const PIString & path) {
PIFile f(path + "_tmp"); PIFile f(path + "_tmp");
f.setName("__S__DumpFile"); f.setName("__S__DumpFile");

View File

@@ -37,11 +37,13 @@
typedef void (*Handler)(void * ); typedef void (*Handler)(void * );
class PIP_EXPORT PIObject { class PIP_EXPORT PIObject {
#ifndef MICRO_PIP
friend class PIObjectManager; friend class PIObjectManager;
friend void dumpApplication(); friend void dumpApplication();
friend class PIIntrospection;
#endif
typedef PIObject __PIObject__; typedef PIObject __PIObject__;
typedef void __Parent__; typedef void __Parent__;
friend class PIIntrospection;
public: public:
NO_COPY_CLASS(PIObject) NO_COPY_CLASS(PIObject)
@@ -192,9 +194,9 @@ public:
static PIObject::Connection piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc); static PIObject::Connection piConnect(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, void * ev_h, void * e_h, int args, const char * loc);
static PIObject::Connection piConnectU(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer = 0); static PIObject::Connection piConnectU(PIObject * src, const PIString & sig, PIObject * dest_o, void * dest, const PIString & hname, const char * loc, PIObject * performer = 0);
static PIObject::Connection piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc); static PIObject::Connection piConnectLS(PIObject * src, const PIString & sig, std::function<void()> * f, const char * loc);
template <typename INPUT, typename... TYPES> template <typename PIINPUT, typename... PITYPES>
static std::function<void()> * __newFunctor(void(*stat_handler)(void*,TYPES...), INPUT functor) { static std::function<void()> * __newFunctor(void(*stat_handler)(void*,PITYPES...), PIINPUT functor) {
return (std::function<void()>*)(new std::function<void(TYPES...)>(functor)); return (std::function<void()>*)(new std::function<void(PITYPES...)>(functor));
} }
@@ -539,8 +541,9 @@ private:
}; };
#ifndef MICRO_PIP
PIP_EXPORT void dumpApplication(); PIP_EXPORT void dumpApplication();
PIP_EXPORT bool dumpApplicationToFile(const PIString & path); PIP_EXPORT bool dumpApplicationToFile(const PIString & path);
#endif
#endif // PIOBJECT_H #endif // PIOBJECT_H

View File

@@ -19,7 +19,11 @@
#include "piincludes_p.h" #include "piincludes_p.h"
#include "pitime.h" #include "pitime.h"
#include "pisystemtests.h" #ifndef MICRO_PIP
# include "pisystemtests.h"
#elif defined(ARDUINO)
# include <Arduino.h>
#endif
#ifdef WINDOWS #ifdef WINDOWS
extern FILETIME __pi_ftjan1970; extern FILETIME __pi_ftjan1970;
long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;} long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
@@ -31,9 +35,8 @@
//# include <crt_externs.h> //# include <crt_externs.h>
extern clock_serv_t __pi_mac_clock; extern clock_serv_t __pi_mac_clock;
#endif #endif
#ifdef FREERTOS #ifdef MICRO_PIP
# include "freertos/FreeRTOS.h" # include <sys/time.h>
# include "freertos/task.h"
#endif #endif
/*! \class PISystemTime /*! \class PISystemTime
@@ -252,24 +255,29 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) {
ullong lt = ullong(sft.dwHighDateTime) * 0x100000000U + ullong(sft.dwLowDateTime); ullong lt = ullong(sft.dwHighDateTime) * 0x100000000U + ullong(sft.dwLowDateTime);
return PISystemTime(lt / 10000000U, (lt % 10000000U) * 100U); return PISystemTime(lt / 10000000U, (lt % 10000000U) * 100U);
} }
#else #elif defined(MAC_OS)
# ifdef MAC_OS
mach_timespec_t t_cur; mach_timespec_t t_cur;
clock_get_time(__pi_mac_clock, &t_cur); clock_get_time(__pi_mac_clock, &t_cur);
# else #elif defined(MICRO_PIP)
# ifdef FREERTOS
timespec t_cur; timespec t_cur;
# ifdef ARDUINO
static const uint32_t offSetSinceEpoch_s = 1581897605UL;
uint32_t mt = millis();
t_cur.tv_sec = offSetSinceEpoch_s + (mt / 1000);
t_cur.tv_nsec = (mt - (mt / 1000)) * 1000000UL;
# else
timeval tv; timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
t_cur.tv_sec = tv.tv_sec; t_cur.tv_sec = tv.tv_sec;
t_cur.tv_nsec = tv.tv_usec * 1000; t_cur.tv_nsec = tv.tv_usec * 1000;
# else # endif
#else
timespec t_cur; timespec t_cur;
clock_gettime(precise_but_not_system ? CLOCK_MONOTONIC : 0, &t_cur); clock_gettime(precise_but_not_system ? CLOCK_MONOTONIC : 0, &t_cur);
# endif #endif
# endif #ifndef WINDOWS
return PISystemTime(t_cur.tv_sec, t_cur.tv_nsec); return PISystemTime(t_cur.tv_sec, t_cur.tv_nsec);
#endif #endif
} }
@@ -407,22 +415,38 @@ PITimeMeasurer::PITimeMeasurer() {
double PITimeMeasurer::elapsed_n() const { double PITimeMeasurer::elapsed_n() const {
return (PISystemTime::current(true) - t_st).toNanoseconds() - PISystemTests::time_elapsed_ns; return (PISystemTime::current(true) - t_st).toNanoseconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns
#endif
;
} }
double PITimeMeasurer::elapsed_u() const { double PITimeMeasurer::elapsed_u() const {
return (PISystemTime::current(true) - t_st).toMicroseconds() - PISystemTests::time_elapsed_ns / 1.E+3; return (PISystemTime::current(true) - t_st).toMicroseconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns / 1.E+3
#endif
;
} }
double PITimeMeasurer::elapsed_m() const { double PITimeMeasurer::elapsed_m() const {
return (PISystemTime::current(true) - t_st).toMilliseconds() - PISystemTests::time_elapsed_ns / 1.E+6; return (PISystemTime::current(true) - t_st).toMilliseconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns / 1.E+6
#endif
;
} }
double PITimeMeasurer::elapsed_s() const { double PITimeMeasurer::elapsed_s() const {
return (PISystemTime::current(true) - t_st).toSeconds() - PISystemTests::time_elapsed_ns / 1.E+9; return (PISystemTime::current(true) - t_st).toSeconds()
#ifndef MICRO_PIP
- PISystemTests::time_elapsed_ns / 1.E+9
#endif
;
} }

View File

@@ -27,7 +27,7 @@
#include "pistring.h" #include "pistring.h"
#include <typeinfo> #include <typeinfo>
#ifdef PIP_FREERTOS #ifdef MICRO_PIP
#include "pivariant.h" #include "pivariant.h"
#endif #endif
@@ -48,7 +48,7 @@ template<typename T>
class __VariantFunctions__: public __VariantFunctionsBase__ { class __VariantFunctions__: public __VariantFunctionsBase__ {
public: public:
__VariantFunctionsBase__ * instance() final {static __VariantFunctions__<T> ret; return &ret;} __VariantFunctionsBase__ * instance() final {static __VariantFunctions__<T> ret; return &ret;}
#ifdef PIP_FREERTOS #ifdef MICRO_PIP
PIString typeName() const final {static PIString ret(PIVariant(T()).typeName()); return ret;} PIString typeName() const final {static PIString ret(PIVariant(T()).typeName()); return ret;}
#else #else
PIString typeName() const final {static PIString ret(typeid(T).name()); return ret;} PIString typeName() const final {static PIString ret(typeid(T).name()); return ret;}

View File

@@ -19,8 +19,9 @@
#include "pivarianttypes.h" #include "pivarianttypes.h"
#include "pipropertystorage.h" #include "pipropertystorage.h"
#include "piiodevice.h" #ifndef MICRO_PIP
# include "piiodevice.h"
#endif
int PIVariantTypes::Enum::selectedValue() const { int PIVariantTypes::Enum::selectedValue() const {
piForeachC (Enumerator & e, enum_list) piForeachC (Enumerator & e, enum_list)
@@ -83,9 +84,12 @@ PIStringList PIVariantTypes::Enum::names() const {
PIVariantTypes::IODevice::IODevice() { PIVariantTypes::IODevice::IODevice() {
#ifndef MICRO_PIP
mode = PIIODevice::ReadWrite; mode = PIIODevice::ReadWrite;
#else
mode = 0; // TODO: PIIODevice for MICRO PIP
#endif // MICRO_PIP
options = 0; options = 0;
} }
@@ -112,12 +116,14 @@ PIString PIVariantTypes::IODevice::toPICout() const {
if (mode & 2) {s << "w"; ++rwc;} if (mode & 2) {s << "w"; ++rwc;}
if (rwc == 1) s << "o"; if (rwc == 1) s << "o";
s << ", flags="; s << ", flags=";
#ifndef MICRO_PIP // TODO: PIIODevice for MICRO PIP
if (options != 0) { if (options != 0) {
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead]) if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead])
s << " br"; s << " br";
if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite]) if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite])
s << " bw"; s << " bw";
} }
#endif // MICRO_PIP
PIPropertyStorage ps = get(); PIPropertyStorage ps = get();
piForeachC (PIPropertyStorage::Property & p, ps) { piForeachC (PIPropertyStorage::Property & p, ps) {
s << ", " << p.name << "=\"" << p.value.toString() << "\""; s << ", " << p.name << "=\"" << p.value.toString() << "\"";
@@ -128,7 +134,6 @@ PIString PIVariantTypes::IODevice::toPICout() const {
PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIVariantTypes::Enumerator & v) { PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIVariantTypes::Enumerator & v) {
enum_list << v; enum_list << v;
return *this; return *this;

View File

@@ -29,7 +29,7 @@ class PIPeer;
class PIIntrospection; class PIIntrospection;
class PIIntrospectionServer; class PIIntrospectionServer;
#ifdef PIP_INTROSPECTION #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#define __PIINTROSPECTION_SINGLETON_H__(T) \ #define __PIINTROSPECTION_SINGLETON_H__(T) \
static PIIntrospection##T##Interface * instance(); static PIIntrospection##T##Interface * instance();

View File

@@ -17,11 +17,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "piintrospection_containers.h" #include "piintrospection_containers.h"
#include "piintrospection_containers_p.h" #include "piintrospection_containers_p.h"
#ifdef PIP_INTROSPECTION
__PIINTROSPECTION_SINGLETON_CPP__(Containers) __PIINTROSPECTION_SINGLETON_CPP__(Containers)

View File

@@ -20,10 +20,10 @@
#ifndef PIINTROSPECTION_CONTAINERS_H #ifndef PIINTROSPECTION_CONTAINERS_H
#define PIINTROSPECTION_CONTAINERS_H #define PIINTROSPECTION_CONTAINERS_H
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "piintrospection_base.h" #include "piintrospection_base.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
class PIIntrospectionContainers; class PIIntrospectionContainers;
#define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())//(PIIntrospectionContainersInterface::instance()) #define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())//(PIIntrospectionContainersInterface::instance())

View File

@@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef PIP_INTROSPECTION #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "piintrospection_server.h" #include "piintrospection_server.h"
#include "piintrospection_server_p.h" #include "piintrospection_server_p.h"

View File

@@ -20,11 +20,10 @@
#ifndef PIINTROSPECTION_SERVER_H #ifndef PIINTROSPECTION_SERVER_H
#define PIINTROSPECTION_SERVER_H #define PIINTROSPECTION_SERVER_H
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "pipeer.h" #include "pipeer.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
class PIIntrospectionServer; class PIIntrospectionServer;
class PISystemMonitor; class PISystemMonitor;

View File

@@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef PIP_INTROSPECTION #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "piintrospection_threads.h" #include "piintrospection_threads.h"
#include "piintrospection_threads_p.h" #include "piintrospection_threads_p.h"

View File

@@ -20,11 +20,10 @@
#ifndef PIINTROSPECTION_THREADS_H #ifndef PIINTROSPECTION_THREADS_H
#define PIINTROSPECTION_THREADS_H #define PIINTROSPECTION_THREADS_H
#include "piintrospection_base.h"
#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)
#include "piintrospection_base.h"
class PIIntrospectionThreads; class PIIntrospectionThreads;
#define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance()) #define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance())

View File

@@ -53,7 +53,7 @@ static const uchar binlog_sig[] = {'B','I','N','L','O','G'};
REGISTER_DEVICE(PIBinaryLog) REGISTER_DEVICE(PIBinaryLog)
PIBinaryLog::PIBinaryLog() { PIBinaryLog::PIBinaryLog() {
#ifdef FREERTOS #ifdef MICRO_PIP
setThreadedReadBufferSize(512); setThreadedReadBufferSize(512);
#else #else
setThreadedReadBufferSize(65536); setThreadedReadBufferSize(65536);

View File

@@ -19,7 +19,7 @@
#include "pican.h" #include "pican.h"
#include "pipropertystorage.h" #include "pipropertystorage.h"
#include "piincludes_p.h" #include "piincludes_p.h"
#if !defined(WINDOWS) && !defined(MAC_OS) && !defined(FREERTOS) #if !defined(WINDOWS) && !defined(MAC_OS) && !defined(MICRO_PIP)
# define PIP_CAN # define PIP_CAN
#endif #endif
#ifdef PIP_CAN #ifdef PIP_CAN

View File

@@ -58,10 +58,10 @@
# include <sys/socket.h> # include <sys/socket.h>
# include <netdb.h> # include <netdb.h>
# include <net/if.h> # include <net/if.h>
# if !defined(ANDROID) && !defined(FREERTOS) # if !defined(ANDROID) && !defined(LWIP)
# include <ifaddrs.h> # include <ifaddrs.h>
# endif # endif
# ifdef FREERTOS # ifdef LWIP
# include <lwip/sockets.h> # include <lwip/sockets.h>
# endif # endif
# endif # endif
@@ -260,7 +260,7 @@ void PIEthernet::construct() {
setMulticastTTL(1); setMulticastTTL(1);
server_thread_.setData(this); server_thread_.setData(this);
server_thread_.setName("__S__server_thread"); server_thread_.setName("__S__server_thread");
#ifdef FREERTOS #ifdef MICRO_PIP
setThreadedReadBufferSize(512); setThreadedReadBufferSize(512);
#else #else
setThreadedReadBufferSize(65536); setThreadedReadBufferSize(65536);
@@ -473,7 +473,7 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
} }
PIFlags<Parameters> params = parameters(); PIFlags<Parameters> params = parameters();
addr_r.set(path()); addr_r.set(path());
#ifndef FREERTOS #ifndef LWIP
struct ip_mreqn mreq; struct ip_mreqn mreq;
#else #else
struct ip_mreq mreq; struct ip_mreq mreq;
@@ -486,13 +486,13 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) {
if (ci != 0) mreq.imr_ifindex = ci->index;*/ if (ci != 0) mreq.imr_ifindex = ci->index;*/
#endif #endif
if (params[PIEthernet::Broadcast]) if (params[PIEthernet::Broadcast])
#ifndef FREERTOS #ifndef LWIP
mreq.imr_address.s_addr = INADDR_ANY; mreq.imr_address.s_addr = INADDR_ANY;
#else #else
mreq.imr_interface.s_addr = INADDR_ANY; mreq.imr_interface.s_addr = INADDR_ANY;
#endif #endif
else else
#ifndef FREERTOS #ifndef LWIP
mreq.imr_address.s_addr = addr_r.ip(); mreq.imr_address.s_addr = addr_r.ip();
#else #else
mreq.imr_interface.s_addr = addr_r.ip(); mreq.imr_interface.s_addr = addr_r.ip();
@@ -520,20 +520,20 @@ bool PIEthernet::leaveMulticastGroup(const PIString & group) {
} }
PIFlags<Parameters> params = parameters(); PIFlags<Parameters> params = parameters();
addr_r.set(path()); addr_r.set(path());
#ifndef FREERTOS #ifndef LWIP
struct ip_mreqn mreq; struct ip_mreqn mreq;
#else #else
struct ip_mreq mreq; struct ip_mreq mreq;
#endif #endif
memset(&mreq, 0, sizeof(mreq)); memset(&mreq, 0, sizeof(mreq));
if (params[PIEthernet::Broadcast]) if (params[PIEthernet::Broadcast])
#ifndef FREERTOS #ifndef LWIP
mreq.imr_address.s_addr = INADDR_ANY; mreq.imr_address.s_addr = INADDR_ANY;
#else #else
mreq.imr_interface.s_addr = INADDR_ANY; mreq.imr_interface.s_addr = INADDR_ANY;
#endif #endif
else else
#ifndef FREERTOS #ifndef LWIP
mreq.imr_address.s_addr = addr_r.ip(); mreq.imr_address.s_addr = addr_r.ip();
#else #else
mreq.imr_interface.s_addr = addr_r.ip(); mreq.imr_interface.s_addr = addr_r.ip();
@@ -1053,7 +1053,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
if (pAdapterInfo) if (pAdapterInfo)
HeapFree(GetProcessHeap(), 0, (pAdapterInfo)); HeapFree(GetProcessHeap(), 0, (pAdapterInfo));
#else #else
#ifdef FREERTOS #ifdef MICRO_PIP
#else #else
# ifdef ANDROID # ifdef ANDROID
struct ifconf ifc; struct ifconf ifc;
@@ -1165,7 +1165,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
PIEthernet::Address PIEthernet::interfaceAddress(const PIString & interface_) { PIEthernet::Address PIEthernet::interfaceAddress(const PIString & interface_) {
#if defined(WINDOWS) || defined(FREERTOS) #if defined(WINDOWS) || defined(MICRO_PIP)
piCout << "[PIEthernet] Not implemented, use \"PIEthernet::allAddresses\" or \"PIEthernet::interfaces\" instead"; piCout << "[PIEthernet] Not implemented, use \"PIEthernet::allAddresses\" or \"PIEthernet::interfaces\" instead";
return Address(); return Address();
#else #else

View File

@@ -711,7 +711,7 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.MTIME.tv_sec, fs.MTIME.tv_nsec)); ret.time_modification = PIDateTime::fromSystemTime(PISystemTime(fs.MTIME.tv_sec, fs.MTIME.tv_nsec));
# endif # endif
#endif #endif
#ifndef FREERTOS #ifndef MICRO_PIP
ret.perm_user = FileInfo::Permissions((mode & S_IRUSR) == S_IRUSR, (mode & S_IWUSR) == S_IWUSR, (mode & S_IXUSR) == S_IXUSR); ret.perm_user = FileInfo::Permissions((mode & S_IRUSR) == S_IRUSR, (mode & S_IWUSR) == S_IWUSR, (mode & S_IXUSR) == S_IXUSR);
ret.perm_group = FileInfo::Permissions((mode & S_IRGRP) == S_IRGRP, (mode & S_IWGRP) == S_IWGRP, (mode & S_IXGRP) == S_IXGRP); ret.perm_group = FileInfo::Permissions((mode & S_IRGRP) == S_IRGRP, (mode & S_IWGRP) == S_IWGRP, (mode & S_IXGRP) == S_IXGRP);
ret.perm_other = FileInfo::Permissions((mode & S_IROTH) == S_IROTH, (mode & S_IWOTH) == S_IWOTH, (mode & S_IXOTH) == S_IXOTH); ret.perm_other = FileInfo::Permissions((mode & S_IROTH) == S_IROTH, (mode & S_IWOTH) == S_IWOTH, (mode & S_IXOTH) == S_IXOTH);

View File

@@ -155,7 +155,7 @@ bool PIIODevice::setOption(PIIODevice::DeviceOption o, bool yes) {
bool stopThread(PIThread * t, bool hard) { bool stopThread(PIThread * t, bool hard) {
#ifdef FREERTOS #ifdef MICRO_PIP
t->stop(true); t->stop(true);
#else #else
if (hard) { if (hard) {
@@ -222,7 +222,7 @@ void PIIODevice::_init() {
setOptions(0); setOptions(0);
setReopenEnabled(true); setReopenEnabled(true);
setReopenTimeout(1000); setReopenTimeout(1000);
#ifdef FREERTOS #ifdef MICRO_PIP
threaded_read_buffer_size = 512; threaded_read_buffer_size = 512;
//setThreadedReadBufferSize(512); //setThreadedReadBufferSize(512);
#else #else
@@ -276,7 +276,7 @@ void PIIODevice::terminate() {
thread_started_ = false; thread_started_ = false;
if (!init_) return; if (!init_) return;
if (isRunning()) { if (isRunning()) {
#ifdef FREERTOS #ifdef MICRO_PIP
stop(true); stop(true);
#else #else
stop(); stop();

View File

@@ -24,7 +24,7 @@
#include "pipropertystorage.h" #include "pipropertystorage.h"
#include <errno.h> #include <errno.h>
#if defined(FREERTOS) #if defined(MICRO_PIP)
# define PISERIAL_NO_PINS # define PISERIAL_NO_PINS
#endif #endif
#if defined(PISERIAL_NO_PINS) || defined(WINDOWS) #if defined(PISERIAL_NO_PINS) || defined(WINDOWS)

View File

@@ -42,7 +42,7 @@ REGISTER_DEVICE(PISPI)
PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : PIIODevice(path, mode) { PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : PIIODevice(path, mode) {
#ifdef FREERTOS #ifdef MICRO_PIP
setThreadedReadBufferSize(512); setThreadedReadBufferSize(512);
#else #else
setThreadedReadBufferSize(1024); setThreadedReadBufferSize(1024);

View File

@@ -37,7 +37,7 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
diag.setName("PIBaseTransfer"); diag.setName("PIBaseTransfer");
diag.start(50); diag.start(50);
packets_count = 10; packets_count = 10;
#ifdef FREERTOS #ifdef MICRO_PIP
setPacketSize(512); setPacketSize(512);
#else #else
setPacketSize(4096); setPacketSize(4096);

View File

@@ -94,7 +94,7 @@ void PIPacketExtractor::construct() {
ret_func_header = ret_func_footer = 0; ret_func_header = ret_func_footer = 0;
setPayloadSize(0); setPayloadSize(0);
setTimeout(100); setTimeout(100);
#ifdef FREERTOS #ifdef MICRO_PIP
setBufferSize(512); setBufferSize(512);
#else #else
setBufferSize(65536); setBufferSize(65536);

View File

@@ -19,6 +19,7 @@
#include "pifft.h" #include "pifft.h"
#ifndef MICRO_PIP
PIFFT_double::PIFFT_double() { PIFFT_double::PIFFT_double() {
} }
@@ -1883,3 +1884,5 @@ void PIFFT_float::ftbase_ffttwcalc(PIVector<float> * a, int aoffset, int n1, int
} }
} }
} }
#endif // MICRO_PIP

View File

@@ -23,9 +23,12 @@
#ifndef PIFFT_H #ifndef PIFFT_H
#define PIFFT_H #define PIFFT_H
#include "pip_fftw_export.h"
#include "pimathcomplex.h" #include "pimathcomplex.h"
#ifndef MICRO_PIP
#include "pip_fftw_export.h"
class PIP_EXPORT PIFFT_double class PIP_EXPORT PIFFT_double
{ {
public: public:
@@ -194,4 +197,6 @@ typedef PIFFTW<ldouble> PIFFTWld;
#endif #endif
#endif // MICRO_PIP
#endif // PIFFT_H #endif // PIFFT_H

View File

@@ -51,13 +51,16 @@
#ifdef PIP_FREERTOS #ifdef PIP_FREERTOS
# define FREERTOS # define FREERTOS
#endif #endif
#if defined(FREERTOS) || defined(PLATFORMIO)
# define MICRO_PIP
#endif
#ifndef WINDOWS #ifndef WINDOWS
# ifndef QNX # ifndef QNX
# ifndef FREE_BSD # ifndef FREE_BSD
# ifndef MAC_OS # ifndef MAC_OS
# ifndef ANDROID # ifndef ANDROID
# ifndef BLACKBERRY # ifndef BLACKBERRY
# ifndef FREERTOS # ifndef MICRO_PIP
# define LINUX # define LINUX
# endif # endif
# endif # endif
@@ -84,6 +87,10 @@
# define CC_OTHER # define CC_OTHER
#endif #endif
#ifdef __AVR__
# define CC_AVR_GCC
#endif
#ifdef WINDOWS #ifdef WINDOWS
# ifdef CC_GCC # ifdef CC_GCC
# define typeof __typeof # define typeof __typeof

View File

@@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PIP_FREERTOS #ifndef MICRO_PIP
#include "pilibrary.h" #include "pilibrary.h"
#include "piincludes_p.h" #include "piincludes_p.h"
@@ -110,4 +110,4 @@ void PILibrary::getLastError() {
#endif #endif
} }
#endif // PIP_FREERTOS #endif // MICRO_PIP

View File

@@ -23,7 +23,7 @@
#ifndef PILIBRARY_H #ifndef PILIBRARY_H
#define PILIBRARY_H #define PILIBRARY_H
#ifndef PIP_FREERTOS #ifndef MICRO_PIP
#include "pistring.h" #include "pistring.h"
@@ -50,5 +50,5 @@ private:
}; };
#endif // PIP_FREERTOS #endif // MICRO_PIP
#endif // PILIBRARY_H #endif // PILIBRARY_H

View File

@@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PIP_FREERTOS #ifndef MICRO_PIP
#include "piplugin.h" #include "piplugin.h"
#include "pifile.h" #include "pifile.h"
@@ -408,4 +408,4 @@ PIString PIPluginLoader::libExtension() {
} }
#endif // PIP_FREERTOS #endif // MICRO_PIP

View File

@@ -23,7 +23,7 @@
#ifndef PIPLUGIN_H #ifndef PIPLUGIN_H
#define PIPLUGIN_H #define PIPLUGIN_H
#ifndef PIP_FREERTOS #ifndef MICRO_PIP
#include "pilibrary.h" #include "pilibrary.h"
#include "pistringlist.h" #include "pistringlist.h"
@@ -212,5 +212,5 @@ private:
}; };
#endif // PIP_FREERTOS #endif // MICRO_PIP
#endif // PIPLUGIN_H #endif // PIPLUGIN_H

View File

@@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PIP_FREERTOS #ifndef MICRO_PIP
#include "piincludes_p.h" #include "piincludes_p.h"
#include "piprocess.h" #include "piprocess.h"
@@ -290,5 +290,5 @@ PIString PIProcess::getEnvironmentVariable(const PIString & variable) {
return PIString(); return PIString();
} }
#endif // PIP_FREERTOS #endif // MICRO_PIP

View File

@@ -23,7 +23,7 @@
#ifndef PIPROCESS_H #ifndef PIPROCESS_H
#define PIPROCESS_H #define PIPROCESS_H
#ifndef PIP_FREERTOS #ifndef MICRO_PIP
#include "pithread.h" #include "pithread.h"
#include "pifile.h" #include "pifile.h"
@@ -104,5 +104,5 @@ private:
}; };
#endif // PIP_FREERTOS #endif // MICRO_PIP
#endif // PIPROCESS_H #endif // PIPROCESS_H

View File

@@ -59,7 +59,7 @@ PISystemMonitor::ThreadStatsFixed::ThreadStatsFixed() {
} }
#ifndef FREERTOS #ifndef MICRO_PIP
PRIVATE_DEFINITION_START(PISystemMonitor) PRIVATE_DEFINITION_START(PISystemMonitor)
#ifndef WINDOWS #ifndef WINDOWS
# ifdef MAC_OS # ifdef MAC_OS
@@ -83,7 +83,7 @@ PRIVATE_DEFINITION_END(PISystemMonitor)
PISystemMonitor::PISystemMonitor(): PIThread() { PISystemMonitor::PISystemMonitor(): PIThread() {
pID_ = cycle = 0; pID_ = cycle = 0;
cpu_count = PISystemInfo::instance()->processorsCount; cpu_count = PISystemInfo::instance()->processorsCount;
#ifndef FREERTOS #ifndef MICRO_PIP
#ifndef WINDOWS #ifndef WINDOWS
# ifdef QNX # ifdef QNX
page_size = 4096; page_size = 4096;
@@ -104,7 +104,7 @@ PISystemMonitor::~PISystemMonitor() {
} }
#ifndef FREERTOS #ifndef MICRO_PIP
bool PISystemMonitor::startOnProcess(int pID, int interval_ms) { bool PISystemMonitor::startOnProcess(int pID, int interval_ms) {
stop(); stop();
pID_ = pID; pID_ = pID;
@@ -134,7 +134,7 @@ bool PISystemMonitor::startOnProcess(int pID, int interval_ms) {
bool PISystemMonitor::startOnSelf(int interval_ms) { bool PISystemMonitor::startOnSelf(int interval_ms) {
#ifndef FREERTOS #ifndef MICRO_PIP
bool ret = startOnProcess(PIProcess::currentPID(), interval_ms); bool ret = startOnProcess(PIProcess::currentPID(), interval_ms);
cycle = -1; cycle = -1;
#else #else
@@ -196,7 +196,7 @@ void PISystemMonitor::run() {
//piCout << tbid.keys().toType<uint>(); //piCout << tbid.keys().toType<uint>();
ProcessStats tstat; ProcessStats tstat;
tstat.ID = pID_; tstat.ID = pID_;
#ifdef FREERTOS #ifdef MICRO_PIP
piForeach (PIThread * t, tv) piForeach (PIThread * t, tv)
if (t->isPIObject()) if (t->isPIObject())
gatherThread(t->tid()); gatherThread(t->tid());
@@ -357,7 +357,7 @@ void PISystemMonitor::run() {
void PISystemMonitor::gatherThread(llong id) { void PISystemMonitor::gatherThread(llong id) {
PISystemMonitor::ThreadStats ts; PISystemMonitor::ThreadStats ts;
ts.id = id; ts.id = id;
#ifdef FREERTOS #ifdef MICRO_PIP
ts.name = tbid.value(id, "<PIThread>"); ts.name = tbid.value(id, "<PIThread>");
#else #else
ts.name = tbid.value(id, "<non-PIThread>"); ts.name = tbid.value(id, "<non-PIThread>");

View File

@@ -79,7 +79,7 @@ public:
PIString name; PIString name;
}; };
#ifndef FREERTOS #ifndef MICRO_PIP
bool startOnProcess(int pID, int interval_ms = 1000); bool startOnProcess(int pID, int interval_ms = 1000);
#endif #endif
bool startOnSelf(int interval_ms = 1000); bool startOnSelf(int interval_ms = 1000);
@@ -106,7 +106,7 @@ private:
PIMap<llong, PIString> tbid; PIMap<llong, PIString> tbid;
mutable PIMutex stat_mutex; mutable PIMutex stat_mutex;
int pID_, page_size, cpu_count, cycle; int pID_, page_size, cpu_count, cycle;
#ifndef FREERTOS #ifndef MICRO_PIP
PRIVATE_DECLARATION(PIP_EXPORT) PRIVATE_DECLARATION(PIP_EXPORT)
#endif #endif

View File

@@ -19,7 +19,7 @@
#include "pisystemtests.h" #include "pisystemtests.h"
#ifndef PIP_FREERTOS #ifndef MICRO_PIP
# include "piconfig.h" # include "piconfig.h"
#endif #endif
@@ -35,7 +35,7 @@ namespace PISystemTests {
PISystemTests::PISystemTestReader::PISystemTestReader() { PISystemTests::PISystemTestReader::PISystemTestReader() {
#if !defined(WINDOWS) && !defined(FREERTOS) #if !defined(WINDOWS) && !defined(MICRO_PIP)
PIConfig conf(PIStringAscii("/etc/pip.conf"), PIIODevice::ReadOnly); PIConfig conf(PIStringAscii("/etc/pip.conf"), PIIODevice::ReadOnly);
time_resolution_ns = conf.getValue(PIStringAscii("time_resolution_ns"), 1).toLong(); time_resolution_ns = conf.getValue(PIStringAscii("time_resolution_ns"), 1).toLong();
time_elapsed_ns = conf.getValue(PIStringAscii("time_elapsed_ns"), 0).toLong(); time_elapsed_ns = conf.getValue(PIStringAscii("time_elapsed_ns"), 0).toLong();

View File

@@ -17,36 +17,47 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "piconditionvar.h" #include "piplatform.h"
#include "pithread.h"
#include "pitime.h"
#ifdef WINDOWS #ifdef WINDOWS
# undef _WIN32_WINNT # undef _WIN32_WINNT
# define _WIN32_WINNT 0x0600 # define _WIN32_WINNT 0x0600
#endif
#include "piconditionvar.h"
#include "pithread.h"
#include "pitime.h"
#include "piincludes_p.h"
#ifdef WINDOWS
# include <synchapi.h> # include <synchapi.h>
# include <windef.h> # include <windef.h>
# include <winbase.h> # include <winbase.h>
#endif #endif
#ifdef FREERTOS
# include <event_groups.h>
#endif
PRIVATE_DEFINITION_START(PIConditionVariable) PRIVATE_DEFINITION_START(PIConditionVariable)
#ifdef WINDOWS #if defined(WINDOWS)
CONDITION_VARIABLE nativeHandle; CONDITION_VARIABLE
#elif defined(FREERTOS)
EventGroupHandle_t
#else #else
pthread_cond_t nativeHandle; pthread_cond_t
#endif #endif
nativeHandle;
PRIVATE_DEFINITION_END(PIConditionVariable) PRIVATE_DEFINITION_END(PIConditionVariable)
PIConditionVariable::PIConditionVariable() { PIConditionVariable::PIConditionVariable() {
#ifdef WINDOWS #if defined(WINDOWS)
InitializeConditionVariable(&PRIVATE->nativeHandle); InitializeConditionVariable(&PRIVATE->nativeHandle);
#elif defined(FREERTOS)
PRIVATE->nativeHandle = xEventGroupCreate();
#else #else
pthread_condattr_t condattr; pthread_condattr_t condattr;
pthread_condattr_init(&condattr); pthread_condattr_init(&condattr);
# ifndef MAC_OS # if !defined(MAC_OS)
pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
# endif # endif
memset(&(PRIVATE->nativeHandle), 0, sizeof(PRIVATE->nativeHandle)); memset(&(PRIVATE->nativeHandle), 0, sizeof(PRIVATE->nativeHandle));
@@ -56,7 +67,9 @@ PIConditionVariable::PIConditionVariable() {
PIConditionVariable::~PIConditionVariable() { PIConditionVariable::~PIConditionVariable() {
#ifdef WINDOWS #if defined(WINDOWS)
#elif defined(FREERTOS)
vEventGroupDelete(PRIVATE->nativeHandle);
#else #else
pthread_cond_destroy(&PRIVATE->nativeHandle); pthread_cond_destroy(&PRIVATE->nativeHandle);
#endif #endif
@@ -64,8 +77,11 @@ PIConditionVariable::~PIConditionVariable() {
void PIConditionVariable::wait(PIMutex& lk) { void PIConditionVariable::wait(PIMutex& lk) {
#ifdef WINDOWS #if defined(WINDOWS)
SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE); SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE);
#elif defined(FREERTOS)
xEventGroupClearBits(PRIVATE->nativeHandle, 1);
xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY);
#else #else
pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle()); pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle());
#endif #endif
@@ -77,8 +93,11 @@ void PIConditionVariable::wait(PIMutex& lk, const std::function<bool()>& conditi
while (true) { while (true) {
isCondition = condition(); isCondition = condition();
if (isCondition) break; if (isCondition) break;
#ifdef WINDOWS #if defined(WINDOWS)
SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE); SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE);
#elif defined(FREERTOS)
xEventGroupClearBits(PRIVATE->nativeHandle, 1);
xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY);
#else #else
pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle()); pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle());
#endif #endif
@@ -88,8 +107,13 @@ void PIConditionVariable::wait(PIMutex& lk, const std::function<bool()>& conditi
bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) { bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) {
bool isNotTimeout; bool isNotTimeout;
#ifdef WINDOWS #if defined(WINDOWS)
isNotTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), timeoutMs) != 0; isNotTimeout = SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), timeoutMs) != 0;
#elif defined(FREERTOS)
xEventGroupClearBits(PRIVATE->nativeHandle, 1);
EventBits_t uxBits;
uxBits = xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, timeoutMs / portTICK_PERIOD_MS);
isNotTimeout = (uxBits & 1) != 0;
#else #else
timespec expire_ts; timespec expire_ts;
PISystemTime st = PISystemTime::current(true); PISystemTime st = PISystemTime::current(true);
@@ -103,24 +127,32 @@ bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) {
bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::function<bool()> &condition) { bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::function<bool()> &condition) {
bool isCondition; bool isCondition;
#ifdef WINDOWS #if defined(WINDOWS) || defined(FREERTOS)
PITimeMeasurer measurer; PITimeMeasurer measurer;
#else #else
timespec expire_ts; timespec expire_ts;
PISystemTime st = PISystemTime::current(true); PISystemTime st = PISystemTime::current(true);
st.addMilliseconds(timeoutMs); st.addMilliseconds(timeoutMs);
st.toTimespec(&expire_ts); st.toTimespec(&expire_ts);
#endif
#ifdef FREERTOS
xEventGroupClearBits(PRIVATE->nativeHandle, 1);
#endif #endif
while (true) { while (true) {
isCondition = condition(); isCondition = condition();
if (isCondition) break; if (isCondition) break;
#ifdef WINDOWS bool isTimeout;
bool isTimeout = SleepConditionVariableCS( #if defined(WINDOWS)
isTimeout = SleepConditionVariableCS(
&PRIVATE->nativeHandle, &PRIVATE->nativeHandle,
(PCRITICAL_SECTION)lk.handle(), (PCRITICAL_SECTION)lk.handle(),
timeoutMs - (int)measurer.elapsed_m()) == 0; timeoutMs - (int)measurer.elapsed_m()) == 0;
#elif defined(FREERTOS)
EventBits_t uxBits;
uxBits = xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, (timeoutMs - (int)measurer.elapsed_m()) / portTICK_PERIOD_MS);
isTimeout = (uxBits & 1) == 0;
#else #else
bool isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &expire_ts) != 0; isTimeout = pthread_cond_timedwait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle(), &expire_ts) != 0;
#endif #endif
if (isTimeout) return false; if (isTimeout) return false;
} }
@@ -129,8 +161,10 @@ bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::functio
void PIConditionVariable::notifyOne() { void PIConditionVariable::notifyOne() {
#ifdef WINDOWS #if defined(WINDOWS)
WakeConditionVariable(&PRIVATE->nativeHandle); WakeConditionVariable(&PRIVATE->nativeHandle);
#elif defined(FREERTOS)
xEventGroupSetBits(PRIVATE->nativeHandle, 1);
#else #else
pthread_cond_signal(&PRIVATE->nativeHandle); pthread_cond_signal(&PRIVATE->nativeHandle);
#endif #endif
@@ -138,8 +172,10 @@ void PIConditionVariable::notifyOne() {
void PIConditionVariable::notifyAll() { void PIConditionVariable::notifyAll() {
#ifdef WINDOWS #if defined(WINDOWS)
WakeAllConditionVariable(&PRIVATE->nativeHandle); WakeAllConditionVariable(&PRIVATE->nativeHandle);
#elif defined(FREERTOS)
xEventGroupSetBits(PRIVATE->nativeHandle, 1);
#else #else
pthread_cond_broadcast(&PRIVATE->nativeHandle); pthread_cond_broadcast(&PRIVATE->nativeHandle);
#endif #endif

View File

@@ -36,8 +36,10 @@
#include "pimutex.h" #include "pimutex.h"
#include "piincludes_p.h" #include "piincludes_p.h"
#ifdef WINDOWS #if defined(WINDOWS)
# include <synchapi.h> # include <synchapi.h>
#elif defined(FREERTOS)
# include <semphr.h>
#else #else
# include <pthread.h> # include <pthread.h>
#endif #endif
@@ -45,8 +47,10 @@
PRIVATE_DEFINITION_START(PIMutex) PRIVATE_DEFINITION_START(PIMutex)
#ifdef WINDOWS #if defined(WINDOWS)
CRITICAL_SECTION CRITICAL_SECTION
#elif defined(FREERTOS)
SemaphoreHandle_t
#else #else
pthread_mutex_t pthread_mutex_t
#endif #endif
@@ -65,8 +69,10 @@ PIMutex::~PIMutex() {
void PIMutex::lock() { void PIMutex::lock() {
#ifdef WINDOWS #if defined(WINDOWS)
EnterCriticalSection(&(PRIVATE->mutex)); EnterCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS)
xSemaphoreTake(PRIVATE->mutex, portMAX_DELAY);
#else #else
pthread_mutex_lock(&(PRIVATE->mutex)); pthread_mutex_lock(&(PRIVATE->mutex));
#endif #endif
@@ -74,8 +80,10 @@ void PIMutex::lock() {
void PIMutex::unlock() { void PIMutex::unlock() {
#ifdef WINDOWS #if defined(WINDOWS)
LeaveCriticalSection(&(PRIVATE->mutex)); LeaveCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS)
xSemaphoreGive(PRIVATE->mutex);
#else #else
pthread_mutex_unlock(&(PRIVATE->mutex)); pthread_mutex_unlock(&(PRIVATE->mutex));
#endif #endif
@@ -84,8 +92,10 @@ void PIMutex::unlock() {
bool PIMutex::tryLock() { bool PIMutex::tryLock() {
bool ret = bool ret =
#ifdef WINDOWS #if defined(WINDOWS)
(TryEnterCriticalSection(&(PRIVATE->mutex)) != 0); (TryEnterCriticalSection(&(PRIVATE->mutex)) != 0);
#elif defined(FREERTOS)
xSemaphoreTake(PRIVATE->mutex, 0);
#else #else
(pthread_mutex_trylock(&(PRIVATE->mutex)) == 0); (pthread_mutex_trylock(&(PRIVATE->mutex)) == 0);
#endif #endif
@@ -94,13 +104,19 @@ bool PIMutex::tryLock() {
void * PIMutex::handle() { void * PIMutex::handle() {
#ifdef FREERTOS
return PRIVATE->mutex;
#else
return (void*)&(PRIVATE->mutex); return (void*)&(PRIVATE->mutex);
#endif
} }
void PIMutex::init() { void PIMutex::init() {
#ifdef WINDOWS #if defined(WINDOWS)
InitializeCriticalSection(&(PRIVATE->mutex)); InitializeCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS)
PRIVATE->mutex = xSemaphoreCreateMutex();
#else #else
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
memset(&attr, 0, sizeof(attr)); memset(&attr, 0, sizeof(attr));
@@ -114,8 +130,10 @@ void PIMutex::init() {
void PIMutex::destroy() { void PIMutex::destroy() {
#ifdef WINDOWS #if defined(WINDOWS)
DeleteCriticalSection(&(PRIVATE->mutex)); DeleteCriticalSection(&(PRIVATE->mutex));
#elif defined(FREERTOS)
vSemaphoreDelete(PRIVATE->mutex);
#else #else
pthread_mutex_destroy(&(PRIVATE->mutex)); pthread_mutex_destroy(&(PRIVATE->mutex));
#endif #endif

View File

@@ -24,7 +24,6 @@
#define PIMUTEX_H #define PIMUTEX_H
#include "piinit.h" #include "piinit.h"
#include <mutex>
class PIP_EXPORT PIMutex class PIP_EXPORT PIMutex

View File

@@ -19,27 +19,40 @@
#include "piincludes_p.h" #include "piincludes_p.h"
#include "pithread.h" #include "pithread.h"
#include "pisystemtests.h"
#include "piintrospection_threads.h" #include "piintrospection_threads.h"
#ifndef MICRO_PIP
# include "pisystemtests.h"
#endif
#include <signal.h> #include <signal.h>
#ifdef WINDOWS #if defined(WINDOWS)
# define __THREAD_FUNC_RET__ uint __stdcall # define __THREAD_FUNC_RET__ uint __stdcall
#elif defined(FREERTOS)
# define __THREAD_FUNC_RET__ void
#else #else
# define __THREAD_FUNC_RET__ void* # define __THREAD_FUNC_RET__ void*
#endif #endif
#ifndef FREERTOS
# define __THREAD_FUNC_END__ 0
#else
# define __THREAD_FUNC_END__
#endif
#if defined(LINUX) #if defined(LINUX)
# include <sys/syscall.h> # include <sys/syscall.h>
# define gettid() syscall(SYS_gettid) # define gettid() syscall(SYS_gettid)
#endif #endif
#if defined(MAC_OS) || defined(BLACKBERRY) || defined(FREERTOS) #if defined(MAC_OS) || defined(BLACKBERRY)
# include <pthread.h> # include <pthread.h>
#endif #endif
__THREAD_FUNC_RET__ thread_function(void * t) {((PIThread*)t)->__thread_func__(); return 0;} __THREAD_FUNC_RET__ thread_function(void * t) {((PIThread*)t)->__thread_func__(); return __THREAD_FUNC_END__;}
__THREAD_FUNC_RET__ thread_function_once(void * t) {((PIThread*)t)->__thread_func_once__(); return 0;} __THREAD_FUNC_RET__ thread_function_once(void * t) {((PIThread*)t)->__thread_func_once__(); return __THREAD_FUNC_END__;}
#define REGISTER_THREAD(t) __PIThreadCollection::instance()->registerThread(t)
#define UNREGISTER_THREAD(t) __PIThreadCollection::instance()->unregisterThread(t)
#ifndef MICRO_PIP
# define REGISTER_THREAD(t) __PIThreadCollection::instance()->registerThread(t)
# define UNREGISTER_THREAD(t) __PIThreadCollection::instance()->unregisterThread(t)
#else
# define REGISTER_THREAD(t)
# define UNREGISTER_THREAD(t)
#endif
/*! \class PIThread /*! \class PIThread
* @brief Thread class * @brief Thread class
@@ -90,6 +103,7 @@ end();
* *
*/ */
#ifndef MICRO_PIP
__PIThreadCollection *__PIThreadCollection::instance() { __PIThreadCollection *__PIThreadCollection::instance() {
return __PIThreadCollection_Initializer__::__instance__; return __PIThreadCollection_Initializer__::__instance__;
@@ -158,15 +172,17 @@ __PIThreadCollection_Initializer__::~__PIThreadCollection_Initializer__() {
} }
} }
#endif // MICRO_PIP
PRIVATE_DEFINITION_START(PIThread) PRIVATE_DEFINITION_START(PIThread)
#ifndef WINDOWS #if defined(WINDOWS)
void * thread;
#elif defined(FREERTOS)
TaskHandle_t thread;
#else
pthread_t thread; pthread_t thread;
sched_param sparam; sched_param sparam;
#else
void * thread;
#endif #endif
PRIVATE_DEFINITION_END(PIThread) PRIVATE_DEFINITION_END(PIThread)
@@ -267,7 +283,7 @@ void PIThread::terminate() {
terminating = running_ = false; terminating = running_ = false;
tid_ = -1; tid_ = -1;
//PICout(PICoutManipulators::DefaultControls) << "terminate" << PRIVATE->thread; //PICout(PICoutManipulators::DefaultControls) << "terminate" << PRIVATE->thread;
#ifndef WINDOWS # ifndef WINDOWS
# ifdef ANDROID # ifdef ANDROID
pthread_kill(PRIVATE->thread, SIGTERM); pthread_kill(PRIVATE->thread, SIGTERM);
# else # else
@@ -276,13 +292,13 @@ void PIThread::terminate() {
pthread_cancel(PRIVATE->thread); pthread_cancel(PRIVATE->thread);
//pthread_join(PRIVATE->thread, &ret); //pthread_join(PRIVATE->thread, &ret);
# endif # endif
#else # else
TerminateThread(PRIVATE->thread, 0); TerminateThread(PRIVATE->thread, 0);
CloseHandle(PRIVATE->thread); CloseHandle(PRIVATE->thread);
#endif # endif
PRIVATE->thread = 0; PRIVATE->thread = 0;
end(); end();
#endif #endif //FREERTOS
PIINTROSPECTION_THREAD_STOP(this); PIINTROSPECTION_THREAD_STOP(this);
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ok" << running_; //PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ok" << running_;
} }
@@ -290,27 +306,31 @@ void PIThread::terminate() {
int PIThread::priority2System(PIThread::Priority p) { int PIThread::priority2System(PIThread::Priority p) {
switch (p) { switch (p) {
# ifdef QNX #if defined(QNX)
case piLowerst: return 8; case piLowerst: return 8;
case piLow: return 9; case piLow: return 9;
case piNormal: return 10; case piNormal: return 10;
case piHigh: return 11; case piHigh: return 11;
case piHighest: return 12; case piHighest: return 12;
# else #elif defined(WINDOWS)
# ifdef WINDOWS
case piLowerst: return -2; case piLowerst: return -2;
case piLow: return -1; case piLow: return -1;
case piNormal: return 0; case piNormal: return 0;
case piHigh: return 1; case piHigh: return 1;
case piHighest: return 2; case piHighest: return 2;
# else #elif defined(FREERTOS)
case piLowerst: return 2;
case piLow: return 3;
case piNormal: return 4;
case piHigh: return 5;
case piHighest: return 6;
#else
case piLowerst: return 2; case piLowerst: return 2;
case piLow: return 1; case piLow: return 1;
case piNormal: return 0; case piNormal: return 0;
case piHigh: return -1; case piHigh: return -1;
case piHighest: return -2; case piHighest: return -2;
# endif #endif
# endif
default: return 0; default: return 0;
} }
return 0; return 0;
@@ -320,34 +340,44 @@ int PIThread::priority2System(PIThread::Priority p) {
bool PIThread::_startThread(void * func) { bool PIThread::_startThread(void * func) {
terminating = false; terminating = false;
running_ = true; running_ = true;
#ifndef WINDOWS #if !defined(WINDOWS) && !defined(FREERTOS)
pthread_attr_t attr; pthread_attr_t attr;
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
int ret = pthread_create(&PRIVATE->thread, &attr, (void*(*)(void*))func, this); int ret = pthread_create(&PRIVATE->thread, &attr, (__THREAD_FUNC_RET__(*)(void*))func, this);
//PICout(PICoutManipulators::DefaultControls) << "pthread_create" << PRIVATE->thread; //PICout(PICoutManipulators::DefaultControls) << "pthread_create" << PRIVATE->thread;
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
if (ret == 0) { if (ret == 0) {
# ifdef MAC_OS # ifdef MAC_OS
pthread_setname_np(((PIString&)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii()); pthread_setname_np(((PIString&)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii());
pthread_threadid_np(PRIVATE->thread, (__uint64_t*)&tid_); pthread_threadid_np(PRIVATE->thread, (__uint64_t*)&tid_);
# else
# ifdef FREERTOS
tid_ = PRIVATE->thread;
# else # else
pthread_setname_np(PRIVATE->thread, ((PIString&)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii()); pthread_setname_np(PRIVATE->thread, ((PIString&)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii());
# endif # endif
# endif #endif
#else #ifdef WINDOWS
if (PRIVATE->thread) CloseHandle(PRIVATE->thread); if (PRIVATE->thread) CloseHandle(PRIVATE->thread);
# ifdef CC_GCC # ifdef CC_GCC
PRIVATE->thread = (void *)_beginthreadex(0, 0, (unsigned(__stdcall*)(void*))func, this, 0, 0); PRIVATE->thread = (void *)_beginthreadex(0, 0, (__THREAD_FUNC_RET__(*)(void*))func, this, 0, 0);
# else # else
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0); PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0);
# endif # endif
if (PRIVATE->thread != 0) { if (PRIVATE->thread != 0) {
#endif #endif
#ifdef FREERTOS
if (xTaskCreate(
(__THREAD_FUNC_RET__(*)(void*))func,
((PIString&)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii(), // A name just for humans
128, // This stack size can be checked & adjusted by reading the Stack Highwater
this,
priority_,
&PRIVATE->thread
) == pdPASS) {
tid_ = (llong)PRIVATE->thread;
#endif
#ifndef FREERTOS
setPriority(priority_); setPriority(priority_);
#endif
return true; return true;
} else { } else {
running_ = false; running_ = false;
@@ -360,10 +390,12 @@ bool PIThread::_startThread(void * func) {
void PIThread::setPriority(PIThread::Priority prior) { void PIThread::setPriority(PIThread::Priority prior) {
#ifndef FREERTOS // FreeRTOS can't change priority runtime
priority_ = prior; priority_ = prior;
# ifndef WINDOWS
if (!running_ || (PRIVATE->thread == 0)) return; if (!running_ || (PRIVATE->thread == 0)) return;
#ifdef FREERTOS
vTaskPrioritySet(PRIVATE->thread, priority2System(priority_));
#else
# ifndef WINDOWS
//PICout(PICoutManipulators::DefaultControls) << "setPriority" << PRIVATE->thread; //PICout(PICoutManipulators::DefaultControls) << "setPriority" << PRIVATE->thread;
policy_ = 0; policy_ = 0;
memset(&(PRIVATE->sparam), 0, sizeof(PRIVATE->sparam)); memset(&(PRIVATE->sparam), 0, sizeof(PRIVATE->sparam));
@@ -503,18 +535,18 @@ void PIThread::_endThread() {
//PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread; //PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread;
UNREGISTER_THREAD(this); UNREGISTER_THREAD(this);
PIINTROSPECTION_THREAD_STOP(this); PIINTROSPECTION_THREAD_STOP(this);
#ifndef WINDOWS #if defined(WINDOWS)
pthread_detach(PRIVATE->thread);
PRIVATE->thread = 0;
#endif
#ifndef WINDOWS
pthread_exit(0);
#else
# ifdef CC_GCC # ifdef CC_GCC
_endthreadex(0); _endthreadex(0);
# else # else
ExitThread(0); ExitThread(0);
# endif # endif
#elif defined(FREERTOS)
PRIVATE->thread = 0;
#else
pthread_detach(PRIVATE->thread);
PRIVATE->thread = 0;
pthread_exit(0);
#endif #endif
} }
@@ -558,8 +590,10 @@ void PIThread::runOnce(PIObject * object, const char * handler, const PIString &
delete t; delete t;
return; return;
} }
#ifndef MICRO_PIP
__PIThreadCollection::instance()->startedAuto(t); __PIThreadCollection::instance()->startedAuto(t);
CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto); CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto);
#endif
t->startOnce(); t->startOnce();
} }
@@ -568,8 +602,10 @@ void PIThread::runOnce(std::function<void ()> func, const PIString & name) {
PIThread * t = new PIThread(); PIThread * t = new PIThread();
t->setName(name); t->setName(name);
t->setSlot(func); t->setSlot(func);
#ifndef MICRO_PIP
__PIThreadCollection::instance()->startedAuto(t); __PIThreadCollection::instance()->startedAuto(t);
CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto); CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto);
#endif
t->startOnce(); t->startOnce();
} }

View File

@@ -30,6 +30,8 @@
#include "piobject.h" #include "piobject.h"
class PIThread; class PIThread;
#ifndef MICRO_PIP
class PIIntrospectionThreads; class PIIntrospectionThreads;
class PIP_EXPORT __PIThreadCollection: public PIObject { class PIP_EXPORT __PIThreadCollection: public PIObject {
@@ -58,14 +60,16 @@ public:
}; };
static __PIThreadCollection_Initializer__ __PIThreadCollection_initializer__; static __PIThreadCollection_Initializer__ __PIThreadCollection_initializer__;
#endif // MICRO_PIP
typedef std::function<void(void *)> ThreadFunc; typedef std::function<void(void *)> ThreadFunc;
class PIP_EXPORT PIThread: public PIObject class PIP_EXPORT PIThread: public PIObject
{ {
PIOBJECT_SUBCLASS(PIThread, PIObject) PIOBJECT_SUBCLASS(PIThread, PIObject)
#ifndef MICRO_PIP
friend class PIIntrospectionThreads; friend class PIIntrospectionThreads;
#endif
public: public:
NO_COPY_CLASS(PIThread) NO_COPY_CLASS(PIThread)

85
platformio_pre.py Normal file
View File

@@ -0,0 +1,85 @@
import os
import glob
import shutil
import re
# The list of items
files = glob.glob('libs/main/*/*.h', recursive=True)
files += glob.glob('libs/main/*.h', recursive=True)
tdir = './include/'
if os.path.exists(tdir):
shutil.rmtree(tdir)
os.mkdir(tdir)
for filename in files:
shutil.copy(filename, tdir)
with open(tdir+'pip_defs.h', 'w') as f:
f.write('// This file was generated by PlatformIO, don`t edit it!')
with open(tdir+'pip_export.h', 'w') as f:
f.write('''
#ifndef PIP_EXPORT_H
#define PIP_EXPORT_H
# define PIP_EXPORT
# define PIP_NO_EXPORT
#ifndef PIP_DEPRECATED
# define PIP_DEPRECATED __attribute__ ((__deprecated__))
#endif
#ifndef PIP_DEPRECATED_EXPORT
# define PIP_DEPRECATED_EXPORT PIP_EXPORT PIP_DEPRECATED
#endif
#ifndef PIP_DEPRECATED_NO_EXPORT
# define PIP_DEPRECATED_NO_EXPORT PIP_NO_EXPORT PIP_DEPRECATED
#endif
#endif /* PIP_EXPORT_H */
''')
version_h = '''
#ifndef PIP_VERSION_H
#define PIP_VERSION_H
// Project
#define PIP_VERSION_MAJOR ${VERSION_MAJOR}
#define PIP_VERSION_MINOR ${VERSION_MINOR}
#define PIP_VERSION_REVISION ${VERSION_REVISION}
#define PIP_VERSION_BUILD 0
#define PIP_VERSION_SUFFIX \"${VERSION_SUFFIX}\"
#define PIP_VERSION_NAME \"${VERSION}\"
#define PIP_MAKE_VERSION(major, minor, revision) ((major << 16) | (minor << 8) | revision)
#define PIP_VERSION PIP_MAKE_VERSION(PIP_VERSION_MAJOR, PIP_VERSION_MINOR, PIP_VERSION_REVISION)
#endif // PIP_VERSION_H
'''
with open('CMakeLists.txt') as cm:
str = cm.read()
v_major = re.findall(r'pip_MAJOR\s+(\d+)\)', str)
v_minor = re.findall(r'pip_MINOR\s+(\d+)\)', str)
v_rev = re.findall(r'pip_REVISION\s+(\d+)\)', str)
v_suffix = re.findall(r'pip_SUFFIX\s+(\w+)\)', str)
ver = ''
ver = v_major[0]+'.'+v_minor[0]+'.'+v_rev[0]
version_h.replace('${VERSION_MAJOR}', v_major[0])
version_h.replace('${VERSION_MINOR}', v_minor[0])
version_h.replace('${VERSION_REVISION}', v_rev[0])
if len(v_suffix):
ver += v_suffix[0]
version_h.replace('${VERSION_SUFFIX}', v_suffix[0])
else:
version_h.replace('${VERSION_SUFFIX}', '')
print('PIP version = '+ver)
with open(tdir+'pip_version.h', 'w') as f:
f.write(version_h)