From 0504fa187e3d6b24b73c55cbc66bd97bd6e8d7e4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 14 Jan 2022 14:37:51 +0300 Subject: [PATCH 01/12] define PIP_MICRO detect AVR_GCC add library.json --- include_pip.py | 3 +++ library.json | 29 +++++++++++++++++++++++++++++ libs/main/containers/picontainers.h | 10 ++++++---- libs/main/core/pibase.h | 18 ++++++++++-------- libs/main/core/piincludes.h | 5 +++-- libs/main/piplatform.h | 4 ++++ 6 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 include_pip.py create mode 100644 library.json diff --git a/include_pip.py b/include_pip.py new file mode 100644 index 00000000..c9fb712d --- /dev/null +++ b/include_pip.py @@ -0,0 +1,3 @@ +Import("env") + +env.Append(CCFLAGS=["-Ilib/pip/libs/main/core", "-Ilib/pip/libs/main/containers", "-Ilib/pip/libs/main/introspection"]) diff --git a/library.json b/library.json new file mode 100644 index 00000000..c5cd63bf --- /dev/null +++ b/library.json @@ -0,0 +1,29 @@ +{ + "name": "PIP", + "version": "2.33.0", + "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"}, + "build": + { + "srcDir": "libs/main", + "srcFilter": [ + "+", + "+", + "+", + "+" + ], + "flags": [ + "-std=c++11", + "-DPIP_MICRO" + ], + "extraScript": "include_pip.py" + } +} \ No newline at end of file diff --git a/libs/main/containers/picontainers.h b/libs/main/containers/picontainers.h index b14fce98..5c67211b 100644 --- a/libs/main/containers/picontainers.h +++ b/libs/main/containers/picontainers.h @@ -28,10 +28,12 @@ #include "picout.h" #include "piintrospection_containers.h" -#ifdef MAC_OS -# include -#else -# include +#ifndef PIP_MICRO +# ifdef MAC_OS +# include +# else +# include +# endif #endif #include #include diff --git a/libs/main/core/pibase.h b/libs/main/core/pibase.h index de83702b..bc26962e 100644 --- a/libs/main/core/pibase.h +++ b/libs/main/core/pibase.h @@ -31,8 +31,6 @@ #include "pip_export.h" #include "pip_defs.h" #include "string.h" -#include - //! Meta-information section for any entity. //! Parsing by \a pip_cmg and can be accessed by \a PICodeInfo. //! Contains sequence of key=value pairs, e.g. @@ -119,9 +117,14 @@ #endif //DOXYGEN +#ifdef CC_AVR_GCC +# include +#endif #include - #include +#include +#include + #ifdef WINDOWS # ifdef CC_VC # define SHUT_RDWR 2 @@ -162,7 +165,6 @@ #ifdef NDEBUG # undef NDEBUG #endif -#include #ifndef assert # define assert(x) # define assertm(exp, msg) @@ -364,7 +366,7 @@ inline bool piCompareBinary(const void * f, const void * s, size_t size) { */ template inline bool piCompare(const T & a, const T & b, const T & epsilon = std::numeric_limits::epsilon()) { - return std::abs(a - b) <= epsilon; + return piAbs(a - b) <= epsilon; } /*! @brief Templated function return round of float falue @@ -499,13 +501,13 @@ template inline void piLetobe(T * v) {piLetobe(v, sizeof(T));} template inline T piLetobe(const T & v) {T tv(v); piLetobe(&tv, sizeof(T)); return tv;} // specialization -template<> inline ushort piLetobe(const ushort & 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 uint16_t piLetobe(const uint16_t & v) {return (v << 8) | (v >> 8);} +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) { union _pletobe_f { _pletobe_f(const float &f_) {f = f_;} float f; - uint v; + uint32_t v; }; _pletobe_f a(v); a.v = (a.v >> 24) | ((a.v >> 8) & 0xFF00) | ((a.v << 8) & 0xFF0000) | ((a.v << 24) & 0xFF000000); diff --git a/libs/main/core/piincludes.h b/libs/main/core/piincludes.h index af46c13b..c9b44e2a 100644 --- a/libs/main/core/piincludes.h +++ b/libs/main/core/piincludes.h @@ -26,8 +26,9 @@ #ifdef PIP_STD_IOSTREAM # include #endif -#include - +#ifndef PIP_MICRO +# include +#endif class PIMutex; class PIMutexLocker; diff --git a/libs/main/piplatform.h b/libs/main/piplatform.h index cb46423d..0c86dd68 100644 --- a/libs/main/piplatform.h +++ b/libs/main/piplatform.h @@ -84,6 +84,10 @@ # define CC_OTHER #endif +#ifdef __AVR__ +# define CC_AVR_GCC +#endif + #ifdef WINDOWS # ifdef CC_GCC # define typeof __typeof From a7df53fbfe79e579b167f613635914246078dfb0 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 14 Jan 2022 18:15:56 +0300 Subject: [PATCH 02/12] platformio_pre.py --- include_pip.py | 3 - library.json | 10 +-- libs/compress/picompress.cpp | 2 +- libs/console/piscreen.cpp | 4 +- libs/console/piterminal.cpp | 4 +- libs/main/containers/picontainers.h | 4 +- libs/main/core/pibase.h | 3 +- libs/main/core/pibytearray.h | 2 +- libs/main/core/piincludes.h | 3 - libs/main/core/piinit.cpp | 71 ++++++++++---------- libs/main/core/piobject.cpp | 8 +-- libs/main/core/piobject.h | 6 +- libs/main/core/pitime.cpp | 15 +++-- libs/main/core/pivariantsimple.h | 6 +- libs/main/io_devices/pibinarylog.cpp | 2 +- libs/main/io_devices/pican.cpp | 2 +- libs/main/io_devices/piethernet.cpp | 22 +++--- libs/main/io_devices/pifile.cpp | 2 +- libs/main/io_devices/piiodevice.cpp | 6 +- libs/main/io_devices/piserial.cpp | 2 +- libs/main/io_devices/pispi.cpp | 2 +- libs/main/io_utils/pibasetransfer.cpp | 2 +- libs/main/io_utils/pipacketextractor.cpp | 2 +- libs/main/piplatform.h | 5 +- libs/main/system/pilibrary.cpp | 4 +- libs/main/system/pilibrary.h | 4 +- libs/main/system/piplugin.cpp | 4 +- libs/main/system/piplugin.h | 4 +- libs/main/system/piprocess.cpp | 4 +- libs/main/system/piprocess.h | 4 +- libs/main/system/pisystemmonitor.cpp | 12 ++-- libs/main/system/pisystemmonitor.h | 4 +- libs/main/system/pisystemtests.cpp | 4 +- platformio_pre.py | 85 ++++++++++++++++++++++++ 34 files changed, 200 insertions(+), 117 deletions(-) delete mode 100644 include_pip.py create mode 100644 platformio_pre.py diff --git a/include_pip.py b/include_pip.py deleted file mode 100644 index c9fb712d..00000000 --- a/include_pip.py +++ /dev/null @@ -1,3 +0,0 @@ -Import("env") - -env.Append(CCFLAGS=["-Ilib/pip/libs/main/core", "-Ilib/pip/libs/main/containers", "-Ilib/pip/libs/main/introspection"]) diff --git a/library.json b/library.json index c5cd63bf..39351b7f 100644 --- a/library.json +++ b/library.json @@ -13,17 +13,13 @@ "dependencies": {"mike-matera/ArduinoSTL": "^1.3.2"}, "build": { - "srcDir": "libs/main", "srcFilter": [ - "+", - "+", - "+", - "+" + "+", + "+" ], "flags": [ - "-std=c++11", "-DPIP_MICRO" ], - "extraScript": "include_pip.py" + "extraScript": "platformio_pre.py" } } \ No newline at end of file diff --git a/libs/compress/picompress.cpp b/libs/compress/picompress.cpp index b9d73a51..6fc21a30 100644 --- a/libs/compress/picompress.cpp +++ b/libs/compress/picompress.cpp @@ -19,7 +19,7 @@ #include "picompress.h" #ifdef PIP_COMPRESS -# ifdef FREERTOS +# ifdef ESP_PLATFORM # include "esp32/rom/miniz.h" # define compress2 mz_compress2 # define Z_OK MZ_OK diff --git a/libs/console/piscreen.cpp b/libs/console/piscreen.cpp index 9dbb9c70..232ad3e5 100644 --- a/libs/console/piscreen.cpp +++ b/libs/console/piscreen.cpp @@ -63,7 +63,7 @@ PIScreen::SystemConsole::SystemConsole() { GetConsoleMode(PRIVATE->hOut, &PRIVATE->smode); GetConsoleCursorInfo(PRIVATE->hOut, &PRIVATE->curinfo); #else -# ifdef FREERTOS +# ifdef MICRO_PIP w = 80; h = 24; # else @@ -115,7 +115,7 @@ void PIScreen::SystemConsole::prepare() { w = PRIVATE->csbi.srWindow.Right - PRIVATE->csbi.srWindow.Left + 1; h = PRIVATE->csbi.srWindow.Bottom - PRIVATE->csbi.srWindow.Top + 1; #else -# ifndef FREERTOS +# ifndef MICRO_PIP winsize ws; ioctl(0, TIOCGWINSZ, &ws); w = ws.ws_col; diff --git a/libs/console/piterminal.cpp b/libs/console/piterminal.cpp index 75163b8e..d63fca89 100644 --- a/libs/console/piterminal.cpp +++ b/libs/console/piterminal.cpp @@ -19,7 +19,7 @@ #include "piincludes_p.h" #include "piterminal.h" #include "pisharedmemory.h" -#ifndef FREERTOS +#ifndef MICRO_PIP #ifdef WINDOWS # include # include @@ -918,4 +918,4 @@ bool PITerminal::resize(int cols, int rows) { return ret; } -#endif // FREERTOS +#endif // MICRO_PIP diff --git a/libs/main/containers/picontainers.h b/libs/main/containers/picontainers.h index 5c67211b..f0aa9921 100644 --- a/libs/main/containers/picontainers.h +++ b/libs/main/containers/picontainers.h @@ -28,13 +28,13 @@ #include "picout.h" #include "piintrospection_containers.h" -#ifndef PIP_MICRO +//#ifndef PIP_MICRO # ifdef MAC_OS # include # else # include # endif -#endif +//#endif #include #include #include diff --git a/libs/main/core/pibase.h b/libs/main/core/pibase.h index bc26962e..2e6f01b8 100644 --- a/libs/main/core/pibase.h +++ b/libs/main/core/pibase.h @@ -124,6 +124,7 @@ #include #include #include +#include #ifdef WINDOWS # ifdef CC_VC @@ -277,7 +278,7 @@ } _PIP_ADD_COUNTER(_pip_initializer_); -#ifdef FREERTOS +#ifdef MICRO_PIP # define PIP_MIN_MSLEEP 10. #else # define PIP_MIN_MSLEEP 1. diff --git a/libs/main/core/pibytearray.h b/libs/main/core/pibytearray.h index 40ed546c..9887337a 100644 --- a/libs/main/core/pibytearray.h +++ b/libs/main/core/pibytearray.h @@ -29,7 +29,7 @@ #include "pivector2d.h" #include -#ifdef FREERTOS +#ifdef MICRO_PIP # define _TYPENAME_(T) "?" #else # define _TYPENAME_(T) typeid(T).name() diff --git a/libs/main/core/piincludes.h b/libs/main/core/piincludes.h index c9b44e2a..41748b2c 100644 --- a/libs/main/core/piincludes.h +++ b/libs/main/core/piincludes.h @@ -26,9 +26,6 @@ #ifdef PIP_STD_IOSTREAM # include #endif -#ifndef PIP_MICRO -# include -#endif class PIMutex; class PIMutexLocker; diff --git a/libs/main/core/piinit.cpp b/libs/main/core/piinit.cpp index 38e64be8..2a221934 100644 --- a/libs/main/core/piinit.cpp +++ b/libs/main/core/piinit.cpp @@ -25,7 +25,7 @@ #include "pisysteminfo.h" #include "piresourcesstorage.h" #include "pidir.h" -#ifndef FREERTOS +#ifndef MICRO_PIP # include "piprocess.h" #endif #ifdef ESP_PLATFORM @@ -49,7 +49,7 @@ void __PISetTimerResolution() { } #else # include -# ifndef FREERTOS +# ifndef MICRO_PIP # include # endif # include @@ -84,7 +84,7 @@ ULONG prev_res; bool delete_locs; PRIVATE_DEFINITION_END(PIInit) -#ifndef FREERTOS +#ifndef MICRO_PIP void __sighandler__(PISignals::Signal s) { //piCout << Hex << int(s); if (s == PISignals::StopTTYInput || s == PISignals::StopTTYOutput) @@ -106,12 +106,12 @@ PIInit::PIInit() { file_charset = 0; PISystemInfo * sinfo = PISystemInfo::instance(); sinfo->execDateTime = PIDateTime::current(); +#ifndef MICRO_PIP setFileCharset("UTF-8"); -#ifndef FREERTOS -#ifndef ANDROID +# ifndef ANDROID PISignals::setSlot(__sighandler__); PISignals::grabSignals(PISignals::UserDefined1); -# ifndef WINDOWS +# ifndef WINDOWS PISignals::grabSignals(PISignals::StopTTYInput | PISignals::StopTTYOutput); sigset_t ss; sigemptyset(&ss); @@ -128,7 +128,7 @@ PIInit::PIInit() { break; } } -# else +# else //WINDOWS // OS version DWORD dwVersion = GetVersion(); DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); @@ -154,33 +154,33 @@ PIInit::PIInit() { setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution"); __PISetTimerResolution(); } -# endif -# ifdef HAS_LOCALE +# endif //WINDOWS +# ifdef HAS_LOCALE //cout << "has locale" << endl; if (currentLocale_t != 0) { freelocale(currentLocale_t); currentLocale_t = 0; } currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0); -# else +# else //HAS_LOCALE setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); -# endif -#else +# endif //HAS_LOCALE +# else //ANDROID struct sigaction actions; memset(&actions, 0, sizeof(actions)); sigemptyset(&actions.sa_mask); actions.sa_flags = 0; actions.sa_handler = android_thread_exit_handler; sigaction(SIGTERM, &actions, 0); -#endif +# endif //ANDROID PRIVATE->delete_locs = false; __syslocname__ = __sysoemname__ = 0; __utf8name__ = const_cast("UTF-8"); -#ifdef PIP_ICU +# ifdef PIP_ICU UErrorCode e((UErrorCode)0); u_init(&e); -# ifdef WINDOWS +# ifdef WINDOWS PRIVATE->delete_locs = true; CPINFOEX cpinfo; int l = 0; @@ -192,30 +192,30 @@ PIInit::PIInit() { memset(__sysoemname__, 0, 256); memcpy(__sysoemname__, "ibm-", 4); memcpy(&(__sysoemname__[4]), cpinfo.CodePageName, l); -# else +# else /*PIString en(getenv("LANG")); if (!en.isEmpty()) en = en.mid(en.find(".") + 1); PIByteArray enba = en.toByteArray(); memcpy(__syslocname__, enba.data(), enba.size_s());*/ -# endif +# endif //piCout << __syslocname__; //piCout << __sysoemname__; -#else -# ifdef WINDOWS +# else //PIP_ICU +# ifdef WINDOWS __syslocname__ = (char *)CP_ACP; __sysoemname__ = (char *)CP_OEMCP; __utf8name__ = (char *)CP_UTF8; -# endif -#endif -#ifdef MAC_OS +# endif +# endif //PIP_ICU +# ifdef MAC_OS host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock); -#endif +# endif char cbuff[1024]; memset(cbuff, 0, 1024); if (gethostname(cbuff, 1023) == 0) sinfo->hostname = cbuff; -#ifdef WINDOWS +# ifdef WINDOWS SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); sinfo->processorsCount = sysinfo.dwNumberOfProcessors; @@ -236,7 +236,7 @@ PIInit::PIInit() { ulong unlen = 1023; if (GetUserName(cbuff, &unlen) != 0) sinfo->user = cbuff; -#else +# else //WINDOWS sinfo->processorsCount = piMaxi(1, int(sysconf(_SC_NPROCESSORS_ONLN))); passwd * ps = getpwuid(getuid()); if (ps) @@ -252,8 +252,9 @@ PIInit::PIInit() { sinfo->OS_version = uns.release; sinfo->architecture = uns.machine; } -# endif -#endif +# endif //WINDOWS +#endif // MICRO_PIP + #ifdef ESP_PLATFORM esp_chip_info_t chip_info; esp_chip_info(&chip_info); @@ -265,19 +266,21 @@ PIInit::PIInit() { sinfo->OS_name = #ifdef WINDOWS PIStringAscii("Windows"); -#elif defined(QNX) +# elif defined(QNX) PIStringAscii("QNX"); -#elif defined(MAC_OS) +# elif defined(MAC_OS) PIStringAscii("MacOS"); -#elif defined(ANDROID) +# elif defined(ANDROID) PIStringAscii("Android"); -#elif defined(FREE_BSD) +# elif defined(FREE_BSD) PIStringAscii("FreeBSD"); -#elif defined(FREERTOS) +# elif defined(FREERTOS) PIStringAscii("FreeRTOS"); -#else +# elif defined(MICRO_PIP) + PIStringAscii("MicroPIP"); +# else uns.sysname; -#endif +# endif } diff --git a/libs/main/core/piobject.cpp b/libs/main/core/piobject.cpp index 7a7ae457..1ec4714e 100644 --- a/libs/main/core/piobject.cpp +++ b/libs/main/core/piobject.cpp @@ -21,7 +21,7 @@ #include "pisysteminfo.h" #include "pithread.h" #include "piconditionvar.h" -#ifndef FREERTOS +#ifndef MICRO_PIP # include "pifile.h" #endif @@ -355,7 +355,7 @@ void PIObject::piDisconnect(PIObject * src, const PIString & sig) { src->connections.remove(i); i--; 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); #endif dest->updateConnectors(); @@ -373,7 +373,7 @@ void PIObject::piDisconnectAll() { // piCout << "disconnect"<< src << o; if (!o || (o == this)) 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); #endif PIVector & oc(o->connections); @@ -615,7 +615,7 @@ void dumpApplication() { } -#ifndef FREERTOS +#ifndef MICRO_PIP bool dumpApplicationToFile(const PIString & path) { PIFile f(path + "_tmp"); f.setName("__S__DumpFile"); diff --git a/libs/main/core/piobject.h b/libs/main/core/piobject.h index 5d11c0ed..b7955006 100644 --- a/libs/main/core/piobject.h +++ b/libs/main/core/piobject.h @@ -192,9 +192,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 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 * f, const char * loc); - template - static std::function * __newFunctor(void(*stat_handler)(void*,TYPES...), INPUT functor) { - return (std::function*)(new std::function(functor)); + template + static std::function * __newFunctor(void(*stat_handler)(void*,PITYPES...), PIINPUT functor) { + return (std::function*)(new std::function(functor)); } diff --git a/libs/main/core/pitime.cpp b/libs/main/core/pitime.cpp index f19e038f..605c4707 100644 --- a/libs/main/core/pitime.cpp +++ b/libs/main/core/pitime.cpp @@ -35,6 +35,9 @@ # include "freertos/FreeRTOS.h" # include "freertos/task.h" #endif +#ifdef MICRO_PIP +# include +#endif /*! \class PISystemTime * @brief System time @@ -252,12 +255,10 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) { ullong lt = ullong(sft.dwHighDateTime) * 0x100000000U + ullong(sft.dwLowDateTime); return PISystemTime(lt / 10000000U, (lt % 10000000U) * 100U); } -#else -# ifdef MAC_OS +#elif defined(MAC_OS) mach_timespec_t t_cur; clock_get_time(__pi_mac_clock, &t_cur); -# else -# ifdef FREERTOS +#elif defined(MICRO_PIP) timespec t_cur; timeval tv; tv.tv_sec = 0; @@ -265,11 +266,11 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) { gettimeofday(&tv, NULL); t_cur.tv_sec = tv.tv_sec; t_cur.tv_nsec = tv.tv_usec * 1000; -# else +#else timespec 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); #endif } diff --git a/libs/main/core/pivariantsimple.h b/libs/main/core/pivariantsimple.h index 152c3782..56afc755 100644 --- a/libs/main/core/pivariantsimple.h +++ b/libs/main/core/pivariantsimple.h @@ -27,7 +27,7 @@ #include "pistring.h" #include -#ifdef PIP_FREERTOS +#ifdef MICRO_PIP #include "pivariant.h" #endif @@ -48,10 +48,10 @@ template class __VariantFunctions__: public __VariantFunctionsBase__ { public: __VariantFunctionsBase__ * instance() final {static __VariantFunctions__ ret; return &ret;} -#ifdef PIP_FREERTOS +#ifdef MICRO_PIP PIString typeName() const final {static PIString ret(PIVariant(T()).typeName()); return ret;} #else - PIString typeName() const final {static PIString ret(typeid(T).name()); return ret;} + PIString typeName() const final {static PIString ret(_TYPENAME_(T)); return ret;} #endif uint hash() const final {static uint ret = typeName().hash(); return ret;} void newT(void *& ptr, const void * value) final {ptr = (void*)(new T(*(const T*)value));} diff --git a/libs/main/io_devices/pibinarylog.cpp b/libs/main/io_devices/pibinarylog.cpp index 9358664a..bc593ed9 100644 --- a/libs/main/io_devices/pibinarylog.cpp +++ b/libs/main/io_devices/pibinarylog.cpp @@ -53,7 +53,7 @@ static const uchar binlog_sig[] = {'B','I','N','L','O','G'}; REGISTER_DEVICE(PIBinaryLog) PIBinaryLog::PIBinaryLog() { -#ifdef FREERTOS +#ifdef MICRO_PIP setThreadedReadBufferSize(512); #else setThreadedReadBufferSize(65536); diff --git a/libs/main/io_devices/pican.cpp b/libs/main/io_devices/pican.cpp index 38f6ae00..b4d1f827 100644 --- a/libs/main/io_devices/pican.cpp +++ b/libs/main/io_devices/pican.cpp @@ -19,7 +19,7 @@ #include "pican.h" #include "pipropertystorage.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 #endif #ifdef PIP_CAN diff --git a/libs/main/io_devices/piethernet.cpp b/libs/main/io_devices/piethernet.cpp index 7f2e797e..dd9f5b25 100644 --- a/libs/main/io_devices/piethernet.cpp +++ b/libs/main/io_devices/piethernet.cpp @@ -58,10 +58,10 @@ # include # include # include -# if !defined(ANDROID) && !defined(FREERTOS) +# if !defined(ANDROID) && !defined(LWIP) # include # endif -# ifdef FREERTOS +# ifdef LWIP # include # endif # endif @@ -260,7 +260,7 @@ void PIEthernet::construct() { setMulticastTTL(1); server_thread_.setData(this); server_thread_.setName("__S__server_thread"); -#ifdef FREERTOS +#ifdef MICRO_PIP setThreadedReadBufferSize(512); #else setThreadedReadBufferSize(65536); @@ -473,7 +473,7 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) { } PIFlags params = parameters(); addr_r.set(path()); -#ifndef FREERTOS +#ifndef LWIP struct ip_mreqn mreq; #else struct ip_mreq mreq; @@ -486,13 +486,13 @@ bool PIEthernet::joinMulticastGroup(const PIString & group) { if (ci != 0) mreq.imr_ifindex = ci->index;*/ #endif if (params[PIEthernet::Broadcast]) -#ifndef FREERTOS +#ifndef LWIP mreq.imr_address.s_addr = INADDR_ANY; #else mreq.imr_interface.s_addr = INADDR_ANY; #endif else -#ifndef FREERTOS +#ifndef LWIP mreq.imr_address.s_addr = addr_r.ip(); #else mreq.imr_interface.s_addr = addr_r.ip(); @@ -520,20 +520,20 @@ bool PIEthernet::leaveMulticastGroup(const PIString & group) { } PIFlags params = parameters(); addr_r.set(path()); -#ifndef FREERTOS +#ifndef LWIP struct ip_mreqn mreq; #else struct ip_mreq mreq; #endif memset(&mreq, 0, sizeof(mreq)); if (params[PIEthernet::Broadcast]) -#ifndef FREERTOS +#ifndef LWIP mreq.imr_address.s_addr = INADDR_ANY; #else mreq.imr_interface.s_addr = INADDR_ANY; #endif else -#ifndef FREERTOS +#ifndef LWIP mreq.imr_address.s_addr = addr_r.ip(); #else mreq.imr_interface.s_addr = addr_r.ip(); @@ -1053,7 +1053,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() { if (pAdapterInfo) HeapFree(GetProcessHeap(), 0, (pAdapterInfo)); #else -#ifdef FREERTOS +#ifdef MICRO_PIP #else # ifdef ANDROID struct ifconf ifc; @@ -1165,7 +1165,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() { 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"; return Address(); #else diff --git a/libs/main/io_devices/pifile.cpp b/libs/main/io_devices/pifile.cpp index 4abd37b6..813818b1 100644 --- a/libs/main/io_devices/pifile.cpp +++ b/libs/main/io_devices/pifile.cpp @@ -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)); # 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_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); diff --git a/libs/main/io_devices/piiodevice.cpp b/libs/main/io_devices/piiodevice.cpp index 7e1c1863..c3e2cbc3 100644 --- a/libs/main/io_devices/piiodevice.cpp +++ b/libs/main/io_devices/piiodevice.cpp @@ -155,7 +155,7 @@ bool PIIODevice::setOption(PIIODevice::DeviceOption o, bool yes) { bool stopThread(PIThread * t, bool hard) { -#ifdef FREERTOS +#ifdef MICRO_PIP t->stop(true); #else if (hard) { @@ -222,7 +222,7 @@ void PIIODevice::_init() { setOptions(0); setReopenEnabled(true); setReopenTimeout(1000); -#ifdef FREERTOS +#ifdef MICRO_PIP threaded_read_buffer_size = 512; //setThreadedReadBufferSize(512); #else @@ -276,7 +276,7 @@ void PIIODevice::terminate() { thread_started_ = false; if (!init_) return; if (isRunning()) { -#ifdef FREERTOS +#ifdef MICRO_PIP stop(true); #else stop(); diff --git a/libs/main/io_devices/piserial.cpp b/libs/main/io_devices/piserial.cpp index 33484c1b..f8264da3 100644 --- a/libs/main/io_devices/piserial.cpp +++ b/libs/main/io_devices/piserial.cpp @@ -24,7 +24,7 @@ #include "pipropertystorage.h" #include -#if defined(FREERTOS) +#if defined(MICRO_PIP) # define PISERIAL_NO_PINS #endif #if defined(PISERIAL_NO_PINS) || defined(WINDOWS) diff --git a/libs/main/io_devices/pispi.cpp b/libs/main/io_devices/pispi.cpp index 80a1e5bc..4dd441e5 100644 --- a/libs/main/io_devices/pispi.cpp +++ b/libs/main/io_devices/pispi.cpp @@ -42,7 +42,7 @@ REGISTER_DEVICE(PISPI) PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : PIIODevice(path, mode) { -#ifdef FREERTOS +#ifdef MICRO_PIP setThreadedReadBufferSize(512); #else setThreadedReadBufferSize(1024); diff --git a/libs/main/io_utils/pibasetransfer.cpp b/libs/main/io_utils/pibasetransfer.cpp index 7f18c752..323b43b8 100644 --- a/libs/main/io_utils/pibasetransfer.cpp +++ b/libs/main/io_utils/pibasetransfer.cpp @@ -37,7 +37,7 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) { diag.setName("PIBaseTransfer"); diag.start(50); packets_count = 10; -#ifdef FREERTOS +#ifdef MICRO_PIP setPacketSize(512); #else setPacketSize(4096); diff --git a/libs/main/io_utils/pipacketextractor.cpp b/libs/main/io_utils/pipacketextractor.cpp index e4812c9c..0a15880b 100644 --- a/libs/main/io_utils/pipacketextractor.cpp +++ b/libs/main/io_utils/pipacketextractor.cpp @@ -94,7 +94,7 @@ void PIPacketExtractor::construct() { ret_func_header = ret_func_footer = 0; setPayloadSize(0); setTimeout(100); -#ifdef FREERTOS +#ifdef MICRO_PIP setBufferSize(512); #else setBufferSize(65536); diff --git a/libs/main/piplatform.h b/libs/main/piplatform.h index 0c86dd68..548cbe29 100644 --- a/libs/main/piplatform.h +++ b/libs/main/piplatform.h @@ -51,13 +51,16 @@ #ifdef PIP_FREERTOS # define FREERTOS #endif +#if defined(FREERTOS) || defined(PLATFORMIO) +# define MICRO_PIP +#endif #ifndef WINDOWS # ifndef QNX # ifndef FREE_BSD # ifndef MAC_OS # ifndef ANDROID # ifndef BLACKBERRY -# ifndef FREERTOS +# ifndef MICRO_PIP # define LINUX # endif # endif diff --git a/libs/main/system/pilibrary.cpp b/libs/main/system/pilibrary.cpp index 955f3c55..e8afdc1d 100644 --- a/libs/main/system/pilibrary.cpp +++ b/libs/main/system/pilibrary.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#ifndef PIP_FREERTOS +#ifndef MICRO_PIP #include "pilibrary.h" #include "piincludes_p.h" @@ -110,4 +110,4 @@ void PILibrary::getLastError() { #endif } -#endif // PIP_FREERTOS +#endif // MICRO_PIP diff --git a/libs/main/system/pilibrary.h b/libs/main/system/pilibrary.h index 27802d8b..e5ec0845 100644 --- a/libs/main/system/pilibrary.h +++ b/libs/main/system/pilibrary.h @@ -23,7 +23,7 @@ #ifndef PILIBRARY_H #define PILIBRARY_H -#ifndef PIP_FREERTOS +#ifndef MICRO_PIP #include "pistring.h" @@ -50,5 +50,5 @@ private: }; -#endif // PIP_FREERTOS +#endif // MICRO_PIP #endif // PILIBRARY_H diff --git a/libs/main/system/piplugin.cpp b/libs/main/system/piplugin.cpp index ac531aaa..beef10b7 100644 --- a/libs/main/system/piplugin.cpp +++ b/libs/main/system/piplugin.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#ifndef PIP_FREERTOS +#ifndef MICRO_PIP #include "piplugin.h" #include "pifile.h" @@ -408,4 +408,4 @@ PIString PIPluginLoader::libExtension() { } -#endif // PIP_FREERTOS +#endif // MICRO_PIP diff --git a/libs/main/system/piplugin.h b/libs/main/system/piplugin.h index 58c8d203..0b240efb 100644 --- a/libs/main/system/piplugin.h +++ b/libs/main/system/piplugin.h @@ -23,7 +23,7 @@ #ifndef PIPLUGIN_H #define PIPLUGIN_H -#ifndef PIP_FREERTOS +#ifndef MICRO_PIP #include "pilibrary.h" #include "pistringlist.h" @@ -212,5 +212,5 @@ private: }; -#endif // PIP_FREERTOS +#endif // MICRO_PIP #endif // PIPLUGIN_H diff --git a/libs/main/system/piprocess.cpp b/libs/main/system/piprocess.cpp index 7158ddcd..b9dfc791 100644 --- a/libs/main/system/piprocess.cpp +++ b/libs/main/system/piprocess.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#ifndef PIP_FREERTOS +#ifndef MICRO_PIP #include "piincludes_p.h" #include "piprocess.h" @@ -290,5 +290,5 @@ PIString PIProcess::getEnvironmentVariable(const PIString & variable) { return PIString(); } -#endif // PIP_FREERTOS +#endif // MICRO_PIP diff --git a/libs/main/system/piprocess.h b/libs/main/system/piprocess.h index 3240d0c7..3d60aeff 100644 --- a/libs/main/system/piprocess.h +++ b/libs/main/system/piprocess.h @@ -23,7 +23,7 @@ #ifndef PIPROCESS_H #define PIPROCESS_H -#ifndef PIP_FREERTOS +#ifndef MICRO_PIP #include "pithread.h" #include "pifile.h" @@ -104,5 +104,5 @@ private: }; -#endif // PIP_FREERTOS +#endif // MICRO_PIP #endif // PIPROCESS_H diff --git a/libs/main/system/pisystemmonitor.cpp b/libs/main/system/pisystemmonitor.cpp index 4e33b848..cb1647b1 100644 --- a/libs/main/system/pisystemmonitor.cpp +++ b/libs/main/system/pisystemmonitor.cpp @@ -59,7 +59,7 @@ PISystemMonitor::ThreadStatsFixed::ThreadStatsFixed() { } -#ifndef FREERTOS +#ifndef MICRO_PIP PRIVATE_DEFINITION_START(PISystemMonitor) #ifndef WINDOWS # ifdef MAC_OS @@ -83,7 +83,7 @@ PRIVATE_DEFINITION_END(PISystemMonitor) PISystemMonitor::PISystemMonitor(): PIThread() { pID_ = cycle = 0; cpu_count = PISystemInfo::instance()->processorsCount; -#ifndef FREERTOS +#ifndef MICRO_PIP #ifndef WINDOWS # ifdef QNX page_size = 4096; @@ -104,7 +104,7 @@ PISystemMonitor::~PISystemMonitor() { } -#ifndef FREERTOS +#ifndef MICRO_PIP bool PISystemMonitor::startOnProcess(int pID, int interval_ms) { stop(); pID_ = pID; @@ -134,7 +134,7 @@ bool PISystemMonitor::startOnProcess(int pID, int interval_ms) { bool PISystemMonitor::startOnSelf(int interval_ms) { -#ifndef FREERTOS +#ifndef MICRO_PIP bool ret = startOnProcess(PIProcess::currentPID(), interval_ms); cycle = -1; #else @@ -196,7 +196,7 @@ void PISystemMonitor::run() { //piCout << tbid.keys().toType(); ProcessStats tstat; tstat.ID = pID_; -#ifdef FREERTOS +#ifdef MICRO_PIP piForeach (PIThread * t, tv) if (t->isPIObject()) gatherThread(t->tid()); @@ -357,7 +357,7 @@ void PISystemMonitor::run() { void PISystemMonitor::gatherThread(llong id) { PISystemMonitor::ThreadStats ts; ts.id = id; -#ifdef FREERTOS +#ifdef MICRO_PIP ts.name = tbid.value(id, ""); #else ts.name = tbid.value(id, ""); diff --git a/libs/main/system/pisystemmonitor.h b/libs/main/system/pisystemmonitor.h index dbae9e97..a4721e69 100644 --- a/libs/main/system/pisystemmonitor.h +++ b/libs/main/system/pisystemmonitor.h @@ -79,7 +79,7 @@ public: PIString name; }; -#ifndef FREERTOS +#ifndef MICRO_PIP bool startOnProcess(int pID, int interval_ms = 1000); #endif bool startOnSelf(int interval_ms = 1000); @@ -106,7 +106,7 @@ private: PIMap tbid; mutable PIMutex stat_mutex; int pID_, page_size, cpu_count, cycle; -#ifndef FREERTOS +#ifndef MICRO_PIP PRIVATE_DECLARATION(PIP_EXPORT) #endif diff --git a/libs/main/system/pisystemtests.cpp b/libs/main/system/pisystemtests.cpp index ee1b9797..cb9bc800 100644 --- a/libs/main/system/pisystemtests.cpp +++ b/libs/main/system/pisystemtests.cpp @@ -19,7 +19,7 @@ #include "pisystemtests.h" -#ifndef PIP_FREERTOS +#ifndef MICRO_PIP # include "piconfig.h" #endif @@ -35,7 +35,7 @@ namespace PISystemTests { PISystemTests::PISystemTestReader::PISystemTestReader() { -#if !defined(WINDOWS) && !defined(FREERTOS) +#if !defined(WINDOWS) && !defined(MICRO_PIP) PIConfig conf(PIStringAscii("/etc/pip.conf"), PIIODevice::ReadOnly); time_resolution_ns = conf.getValue(PIStringAscii("time_resolution_ns"), 1).toLong(); time_elapsed_ns = conf.getValue(PIStringAscii("time_elapsed_ns"), 0).toLong(); diff --git a/platformio_pre.py b/platformio_pre.py new file mode 100644 index 00000000..c9fe7da5 --- /dev/null +++ b/platformio_pre.py @@ -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) + From d4c6c410da0aa2cbac3b4f3f3f2c7bdd58984548 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 14 Jan 2022 18:25:41 +0300 Subject: [PATCH 03/12] some fixes --- library.json | 3 --- libs/main/containers/picontainers.h | 12 +++++------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/library.json b/library.json index 39351b7f..5d86bdfb 100644 --- a/library.json +++ b/library.json @@ -17,9 +17,6 @@ "+", "+" ], - "flags": [ - "-DPIP_MICRO" - ], "extraScript": "platformio_pre.py" } } \ No newline at end of file diff --git a/libs/main/containers/picontainers.h b/libs/main/containers/picontainers.h index f0aa9921..b14fce98 100644 --- a/libs/main/containers/picontainers.h +++ b/libs/main/containers/picontainers.h @@ -28,13 +28,11 @@ #include "picout.h" #include "piintrospection_containers.h" -//#ifndef PIP_MICRO -# ifdef MAC_OS -# include -# else -# include -# endif -//#endif +#ifdef MAC_OS +# include +#else +# include +#endif #include #include #include From c9e329d27d6e9bb4d673a7a8766b7fbb6adfccdf Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 14 Jan 2022 18:51:37 +0300 Subject: [PATCH 04/12] rename PIInit BuildOption --- libs/main/core/piinit.cpp | 32 ++++++++++++++++---------------- libs/main/core/piinit.h | 16 ++++++++-------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libs/main/core/piinit.cpp b/libs/main/core/piinit.cpp index 2a221934..05746823 100644 --- a/libs/main/core/piinit.cpp +++ b/libs/main/core/piinit.cpp @@ -308,49 +308,49 @@ PIInit::~PIInit() { bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) { switch (o) { - case ICU: return + case boICU: return #ifdef PIP_ICU true; #else false; #endif - case USB: return + case boUSB: return #ifdef PIP_USB true; #else false; #endif - case Crypt: return + case boCrypt: return #ifdef PIP_CRYPT true; #else false; #endif - case Introspection: return + case boIntrospection: return #ifdef PIP_INTROSPECTION true; #else false; #endif - case FFTW: return + case boFFTW: return #ifdef PIP_FFTW true; #else false; #endif - case Compress: return + case boCompress: return #ifdef PIP_COMPRESS true; #else false; #endif - case OpenCL: return + case boOpenCL: return #ifdef PIP_OPENCL true; #else false; #endif - case Cloud: return + case boCloud: return #ifdef PIP_CLOUD true; #else @@ -364,14 +364,14 @@ bool PIInit::isBuildOptionEnabled(PIInit::BuildOption o) { PIStringList PIInit::buildOptions() { PIStringList ret; - if (isBuildOptionEnabled(ICU)) ret << "ICU"; - if (isBuildOptionEnabled(USB)) ret << "USB"; - if (isBuildOptionEnabled(Crypt)) ret << "Crypt"; - if (isBuildOptionEnabled(Introspection)) ret << "Introspection"; - if (isBuildOptionEnabled(FFTW)) ret << "FFTW"; - if (isBuildOptionEnabled(Compress)) ret << "Compress"; - if (isBuildOptionEnabled(OpenCL)) ret << "OpenCL"; - if (isBuildOptionEnabled(Cloud)) ret << "Cloud"; + if (isBuildOptionEnabled(boICU)) ret << "ICU"; + if (isBuildOptionEnabled(boUSB)) ret << "USB"; + if (isBuildOptionEnabled(boCrypt)) ret << "Crypt"; + if (isBuildOptionEnabled(boIntrospection)) ret << "Introspection"; + if (isBuildOptionEnabled(boFFTW)) ret << "FFTW"; + if (isBuildOptionEnabled(boCompress)) ret << "Compress"; + if (isBuildOptionEnabled(boOpenCL)) ret << "OpenCL"; + if (isBuildOptionEnabled(boCloud)) ret << "Cloud"; return ret; } diff --git a/libs/main/core/piinit.h b/libs/main/core/piinit.h index 7cf40c7c..97e62d19 100644 --- a/libs/main/core/piinit.h +++ b/libs/main/core/piinit.h @@ -49,14 +49,14 @@ public: //! @brief Build options which PIP library was built enum BuildOption { - ICU /*! Unicode support */ = 0x01, - USB /*! USB support */ = 0x02, - Crypt /*! Crypt support */ = 0x08, - Introspection /*! Introspection */ = 0x010, - FFTW /*! FFTW3 support */ = 0x40, - Compress /*! Zlib compression support */ = 0x80, - OpenCL /*! OpenCL support */ = 0x100, - Cloud /*! Cloud transport support */ = 0x200, + boICU /*! Unicode support */ = 0x01, + boUSB /*! USB support */ = 0x02, + boCrypt /*! Crypt support */ = 0x08, + boIntrospection /*! Introspection */ = 0x010, + boFFTW /*! FFTW3 support */ = 0x40, + boCompress /*! Zlib compression support */ = 0x80, + boOpenCL /*! OpenCL support */ = 0x100, + boCloud /*! Cloud transport support */ = 0x200, }; static PIInit * instance() {return __PIInit_Initializer__::__instance__;} static bool isBuildOptionEnabled(BuildOption o); From 86130d7105e7f235bdad23ebad31bae88b17ad60 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 15 Jan 2022 14:54:36 +0300 Subject: [PATCH 05/12] compiled for esp32 --- library.json | 8 +-- libs/main/core/piincludes.h | 2 + libs/main/core/piinit.cpp | 77 ++++++++++++++--------------- libs/main/core/piinit.h | 5 ++ libs/main/math/pifft.cpp | 3 ++ libs/main/math/pifft.h | 7 ++- libs/main/thread/piconditionvar.cpp | 2 +- platformio_pre.py | 2 +- 8 files changed, 60 insertions(+), 46 deletions(-) diff --git a/library.json b/library.json index 5d86bdfb..d8cf5bc6 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,5 @@ { "name": "PIP", - "version": "2.33.0", "keywords": "pip", "description": "Platform-Independent Primitives", "repository": @@ -15,8 +14,11 @@ { "srcFilter": [ "+", - "+" + "+", + "+", + "+" ], - "extraScript": "platformio_pre.py" + "extraScript": "platformio_pre.py", + "flags": "-DPIP_FREERTOS" } } \ No newline at end of file diff --git a/libs/main/core/piincludes.h b/libs/main/core/piincludes.h index 41748b2c..a65591ac 100644 --- a/libs/main/core/piincludes.h +++ b/libs/main/core/piincludes.h @@ -32,7 +32,9 @@ class PIMutexLocker; class PIObject; class PIString; class PIByteArray; +#ifndef MICRO_PIP class PIInit; +#endif class PIChar; class PICout; diff --git a/libs/main/core/piinit.cpp b/libs/main/core/piinit.cpp index 05746823..78417830 100644 --- a/libs/main/core/piinit.cpp +++ b/libs/main/core/piinit.cpp @@ -19,15 +19,15 @@ #include "piincludes_p.h" #include "piinit.h" +#ifndef MICRO_PIP + #include "pitime.h" #include "pisignals.h" #include "piobject.h" #include "pisysteminfo.h" #include "piresourcesstorage.h" #include "pidir.h" -#ifndef MICRO_PIP -# include "piprocess.h" -#endif +#include "piprocess.h" #ifdef ESP_PLATFORM # include "esp_system.h" #endif @@ -49,9 +49,7 @@ void __PISetTimerResolution() { } #else # include -# ifndef MICRO_PIP -# include -# endif +# include # include # ifdef BLACKBERRY # include @@ -84,7 +82,6 @@ ULONG prev_res; bool delete_locs; PRIVATE_DEFINITION_END(PIInit) -#ifndef MICRO_PIP void __sighandler__(PISignals::Signal s) { //piCout << Hex << int(s); if (s == PISignals::StopTTYInput || s == PISignals::StopTTYOutput) @@ -92,7 +89,6 @@ void __sighandler__(PISignals::Signal s) { if (s == PISignals::UserDefined1) dumpApplicationToFile(PIDir::home().path() + PIDir::separator + PIStringAscii("_PIP_DUMP_") + PIString::fromNumber(PIProcess::currentPID())); } -#endif #ifdef ANDROID @@ -106,12 +102,11 @@ PIInit::PIInit() { file_charset = 0; PISystemInfo * sinfo = PISystemInfo::instance(); sinfo->execDateTime = PIDateTime::current(); -#ifndef MICRO_PIP setFileCharset("UTF-8"); -# ifndef ANDROID +#ifndef ANDROID PISignals::setSlot(__sighandler__); PISignals::grabSignals(PISignals::UserDefined1); -# ifndef WINDOWS +# ifndef WINDOWS PISignals::grabSignals(PISignals::StopTTYInput | PISignals::StopTTYOutput); sigset_t ss; sigemptyset(&ss); @@ -128,7 +123,7 @@ PIInit::PIInit() { break; } } -# else //WINDOWS +# else //WINDOWS // OS version DWORD dwVersion = GetVersion(); DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); @@ -154,33 +149,33 @@ PIInit::PIInit() { setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution"); __PISetTimerResolution(); } -# endif //WINDOWS -# ifdef HAS_LOCALE +# endif //WINDOWS +# ifdef HAS_LOCALE //cout << "has locale" << endl; if (currentLocale_t != 0) { freelocale(currentLocale_t); currentLocale_t = 0; } currentLocale_t = newlocale(LC_ALL, setlocale(LC_ALL, ""), 0); -# else //HAS_LOCALE +# else //HAS_LOCALE setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); -# endif //HAS_LOCALE -# else //ANDROID +# endif //HAS_LOCALE +#else //ANDROID struct sigaction actions; memset(&actions, 0, sizeof(actions)); sigemptyset(&actions.sa_mask); actions.sa_flags = 0; actions.sa_handler = android_thread_exit_handler; sigaction(SIGTERM, &actions, 0); -# endif //ANDROID +#endif //ANDROID PRIVATE->delete_locs = false; __syslocname__ = __sysoemname__ = 0; __utf8name__ = const_cast("UTF-8"); -# ifdef PIP_ICU +#ifdef PIP_ICU UErrorCode e((UErrorCode)0); u_init(&e); -# ifdef WINDOWS +# ifdef WINDOWS PRIVATE->delete_locs = true; CPINFOEX cpinfo; int l = 0; @@ -192,30 +187,30 @@ PIInit::PIInit() { memset(__sysoemname__, 0, 256); memcpy(__sysoemname__, "ibm-", 4); memcpy(&(__sysoemname__[4]), cpinfo.CodePageName, l); -# else +# else /*PIString en(getenv("LANG")); if (!en.isEmpty()) en = en.mid(en.find(".") + 1); PIByteArray enba = en.toByteArray(); memcpy(__syslocname__, enba.data(), enba.size_s());*/ -# endif +# endif //piCout << __syslocname__; //piCout << __sysoemname__; -# else //PIP_ICU -# ifdef WINDOWS +#else //PIP_ICU +# ifdef WINDOWS __syslocname__ = (char *)CP_ACP; __sysoemname__ = (char *)CP_OEMCP; __utf8name__ = (char *)CP_UTF8; -# endif -# endif //PIP_ICU -# ifdef MAC_OS - host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock); # endif +#endif //PIP_ICU +#ifdef MAC_OS + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock); +#endif char cbuff[1024]; memset(cbuff, 0, 1024); if (gethostname(cbuff, 1023) == 0) sinfo->hostname = cbuff; -# ifdef WINDOWS +#ifdef WINDOWS SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); sinfo->processorsCount = sysinfo.dwNumberOfProcessors; @@ -236,7 +231,7 @@ PIInit::PIInit() { ulong unlen = 1023; if (GetUserName(cbuff, &unlen) != 0) sinfo->user = cbuff; -# else //WINDOWS +#else //WINDOWS sinfo->processorsCount = piMaxi(1, int(sysconf(_SC_NPROCESSORS_ONLN))); passwd * ps = getpwuid(getuid()); if (ps) @@ -252,8 +247,7 @@ PIInit::PIInit() { sinfo->OS_version = uns.release; sinfo->architecture = uns.machine; } -# endif //WINDOWS -#endif // MICRO_PIP +#endif //WINDOWS #ifdef ESP_PLATFORM esp_chip_info_t chip_info; @@ -266,21 +260,21 @@ PIInit::PIInit() { sinfo->OS_name = #ifdef WINDOWS PIStringAscii("Windows"); -# elif defined(QNX) +#elif defined(QNX) PIStringAscii("QNX"); -# elif defined(MAC_OS) +#elif defined(MAC_OS) PIStringAscii("MacOS"); -# elif defined(ANDROID) +#elif defined(ANDROID) PIStringAscii("Android"); -# elif defined(FREE_BSD) +#elif defined(FREE_BSD) PIStringAscii("FreeBSD"); -# elif defined(FREERTOS) +#elif defined(FREERTOS) PIStringAscii("FreeRTOS"); -# elif defined(MICRO_PIP) +#elif defined(MICRO_PIP) PIStringAscii("MicroPIP"); -# else +#else uns.sysname; -# endif +#endif } @@ -418,3 +412,6 @@ __PIInit_Initializer__::~__PIInit_Initializer__() { __instance__ = 0; } } + +#endif // MICRO_PIP + diff --git a/libs/main/core/piinit.h b/libs/main/core/piinit.h index 97e62d19..2ea2936a 100644 --- a/libs/main/core/piinit.h +++ b/libs/main/core/piinit.h @@ -23,6 +23,10 @@ #ifndef PIINIT_H #define PIINIT_H +#include "pibase.h" + +#ifndef MICRO_PIP + #include "piincludes.h" @@ -70,4 +74,5 @@ private: }; +#endif // MICRO_PIP #endif // PIINIT_H diff --git a/libs/main/math/pifft.cpp b/libs/main/math/pifft.cpp index 6a0ea413..923be1e8 100644 --- a/libs/main/math/pifft.cpp +++ b/libs/main/math/pifft.cpp @@ -19,6 +19,7 @@ #include "pifft.h" +#ifndef MICRO_PIP PIFFT_double::PIFFT_double() { } @@ -1883,3 +1884,5 @@ void PIFFT_float::ftbase_ffttwcalc(PIVector * a, int aoffset, int n1, int } } } + +#endif // MICRO_PIP diff --git a/libs/main/math/pifft.h b/libs/main/math/pifft.h index a3827415..d06f8101 100644 --- a/libs/main/math/pifft.h +++ b/libs/main/math/pifft.h @@ -23,9 +23,12 @@ #ifndef PIFFT_H #define PIFFT_H -#include "pip_fftw_export.h" #include "pimathcomplex.h" +#ifndef MICRO_PIP + +#include "pip_fftw_export.h" + class PIP_EXPORT PIFFT_double { public: @@ -194,4 +197,6 @@ typedef PIFFTW PIFFTWld; #endif +#endif // MICRO_PIP + #endif // PIFFT_H diff --git a/libs/main/thread/piconditionvar.cpp b/libs/main/thread/piconditionvar.cpp index d679c777..908199c9 100644 --- a/libs/main/thread/piconditionvar.cpp +++ b/libs/main/thread/piconditionvar.cpp @@ -46,7 +46,7 @@ PIConditionVariable::PIConditionVariable() { pthread_condattr_t condattr; pthread_condattr_init(&condattr); -# ifndef MAC_OS +# if !defined(MAC_OS) && !defined(FREERTOS) pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); # endif memset(&(PRIVATE->nativeHandle), 0, sizeof(PRIVATE->nativeHandle)); diff --git a/platformio_pre.py b/platformio_pre.py index c9fe7da5..aa681846 100644 --- a/platformio_pre.py +++ b/platformio_pre.py @@ -2,7 +2,7 @@ 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) From 542f180d9d7dfa4fdc12a39ceb88f46e50cff631 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 17 Jan 2022 18:39:57 +0300 Subject: [PATCH 06/12] add Freertos dependency --- library.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index d8cf5bc6..520dcb44 100644 --- a/library.json +++ b/library.json @@ -9,7 +9,10 @@ }, "frameworks": "*", "platforms": "*", - "dependencies": {"mike-matera/ArduinoSTL": "^1.3.2"}, + "dependencies": { + "mike-matera/ArduinoSTL": "^1.3.2", + "linlin-study/FreeRTOS-Kernel": ">=10.0.0" + }, "build": { "srcFilter": [ From cde2341c1ffc18216abc6e868f7da46a70d4267c Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 20 Jan 2022 16:46:04 +0300 Subject: [PATCH 07/12] fix freertos includes --- library.json | 3 +-- libs/main/core/piincludes_p.h | 9 +++++++++ libs/main/core/pitime.cpp | 4 ---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/library.json b/library.json index 520dcb44..29a6a46e 100644 --- a/library.json +++ b/library.json @@ -18,8 +18,7 @@ "srcFilter": [ "+", "+", - "+", - "+" + "+" ], "extraScript": "platformio_pre.py", "flags": "-DPIP_FREERTOS" diff --git a/libs/main/core/piincludes_p.h b/libs/main/core/piincludes_p.h index b2f8a348..e3c622ca 100644 --- a/libs/main/core/piincludes_p.h +++ b/libs/main/core/piincludes_p.h @@ -40,6 +40,15 @@ typedef LONG(NTAPI*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG); #include #include +#ifdef FREERTOS +# ifdef ESP_PLATFORM +# include "freertos/FreeRTOS.h" +# include "freertos/task.h" +# endif +# ifdef ARDUINO_ARCH_STM32 +# include +# endif +#endif #endif // PIINCLUDES_P_H diff --git a/libs/main/core/pitime.cpp b/libs/main/core/pitime.cpp index 605c4707..bca22117 100644 --- a/libs/main/core/pitime.cpp +++ b/libs/main/core/pitime.cpp @@ -31,10 +31,6 @@ //# include extern clock_serv_t __pi_mac_clock; #endif -#ifdef FREERTOS -# include "freertos/FreeRTOS.h" -# include "freertos/task.h" -#endif #ifdef MICRO_PIP # include #endif From 7403ee67be9a9f9631c5edeedb6eac9b9dedd47d Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 20 Jan 2022 16:54:20 +0300 Subject: [PATCH 08/12] gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e47ef87b..9a909f74 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /.svn /doc/rtf _unsused -CMakeLists.txt.user* \ No newline at end of file +CMakeLists.txt.user* +/include \ No newline at end of file From 8296e9a32bb417221969b53d7b0073f56aa47fa2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 21 Jan 2022 14:15:42 +0300 Subject: [PATCH 09/12] add FreeRTOS support for PIThread PIMutex PIConditionVariable --- library.json | 5 +- libs/main/core/piobject.cpp | 4 +- libs/main/core/piobject.h | 7 +- libs/main/core/pivarianttypes.cpp | 9 ++- libs/main/thread/piconditionvar.cpp | 66 +++++++++++---- libs/main/thread/pimutex.cpp | 32 ++++++-- libs/main/thread/pimutex.h | 1 - libs/main/thread/pithread.cpp | 120 ++++++++++++++++++---------- libs/main/thread/pithread.h | 6 +- 9 files changed, 173 insertions(+), 77 deletions(-) diff --git a/library.json b/library.json index 29a6a46e..097d2330 100644 --- a/library.json +++ b/library.json @@ -18,7 +18,10 @@ "srcFilter": [ "+", "+", - "+" + "+", + "+", + "+", + "+" ], "extraScript": "platformio_pre.py", "flags": "-DPIP_FREERTOS" diff --git a/libs/main/core/piobject.cpp b/libs/main/core/piobject.cpp index 1ec4714e..ab051a78 100644 --- a/libs/main/core/piobject.cpp +++ b/libs/main/core/piobject.cpp @@ -18,10 +18,10 @@ */ #include "piobject.h" -#include "pisysteminfo.h" #include "pithread.h" #include "piconditionvar.h" #ifndef MICRO_PIP +# include "pisysteminfo.h" # include "pifile.h" #endif @@ -589,6 +589,7 @@ void PIObject::dump(const PIString & line_prefix) const { } +#ifndef MICRO_PIP void dumpApplication() { PIMutexLocker _ml(PIObject::mutexObjects()); //printf("dump application ...\n"); @@ -615,7 +616,6 @@ void dumpApplication() { } -#ifndef MICRO_PIP bool dumpApplicationToFile(const PIString & path) { PIFile f(path + "_tmp"); f.setName("__S__DumpFile"); diff --git a/libs/main/core/piobject.h b/libs/main/core/piobject.h index b7955006..c6c6451a 100644 --- a/libs/main/core/piobject.h +++ b/libs/main/core/piobject.h @@ -37,11 +37,13 @@ typedef void (*Handler)(void * ); class PIP_EXPORT PIObject { +#ifndef MICRO_PIP friend class PIObjectManager; friend void dumpApplication(); + friend class PIIntrospection; +#endif typedef PIObject __PIObject__; typedef void __Parent__; - friend class PIIntrospection; public: NO_COPY_CLASS(PIObject) @@ -539,8 +541,9 @@ private: }; - +#ifndef MICRO_PIP PIP_EXPORT void dumpApplication(); PIP_EXPORT bool dumpApplicationToFile(const PIString & path); +#endif #endif // PIOBJECT_H diff --git a/libs/main/core/pivarianttypes.cpp b/libs/main/core/pivarianttypes.cpp index 13c556fa..de21989e 100644 --- a/libs/main/core/pivarianttypes.cpp +++ b/libs/main/core/pivarianttypes.cpp @@ -19,8 +19,9 @@ #include "pivarianttypes.h" #include "pipropertystorage.h" -#include "piiodevice.h" - +#ifndef MICRO_PIP +# include "piiodevice.h" +#endif int PIVariantTypes::Enum::selectedValue() const { piForeachC (Enumerator & e, enum_list) @@ -83,7 +84,7 @@ PIStringList PIVariantTypes::Enum::names() const { - +#ifndef MICRO_PIP PIVariantTypes::IODevice::IODevice() { mode = PIIODevice::ReadWrite; options = 0; @@ -125,7 +126,7 @@ PIString PIVariantTypes::IODevice::toPICout() const { s << ")"; return s; } - +#endif // MICRO_PIP diff --git a/libs/main/thread/piconditionvar.cpp b/libs/main/thread/piconditionvar.cpp index 908199c9..2143ac24 100644 --- a/libs/main/thread/piconditionvar.cpp +++ b/libs/main/thread/piconditionvar.cpp @@ -20,7 +20,7 @@ #include "piconditionvar.h" #include "pithread.h" #include "pitime.h" - +#include "piincludes_p.h" #ifdef WINDOWS # undef _WIN32_WINNT # define _WIN32_WINNT 0x0600 @@ -28,25 +28,32 @@ # include # include #endif +#ifdef FREERTOS +# include +#endif PRIVATE_DEFINITION_START(PIConditionVariable) -#ifdef WINDOWS - CONDITION_VARIABLE nativeHandle; +#if defined(WINDOWS) + CONDITION_VARIABLE +#elif defined(FREERTOS) + EventGroupHandle_t #else - pthread_cond_t nativeHandle; + pthread_cond_t #endif + nativeHandle; PRIVATE_DEFINITION_END(PIConditionVariable) PIConditionVariable::PIConditionVariable() { -#ifdef WINDOWS +#if defined(WINDOWS) InitializeConditionVariable(&PRIVATE->nativeHandle); +#elif defined(FREERTOS) + PRIVATE->nativeHandle = xEventGroupCreate(); #else - pthread_condattr_t condattr; pthread_condattr_init(&condattr); -# if !defined(MAC_OS) && !defined(FREERTOS) +# if !defined(MAC_OS) pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); # endif memset(&(PRIVATE->nativeHandle), 0, sizeof(PRIVATE->nativeHandle)); @@ -56,7 +63,9 @@ PIConditionVariable::PIConditionVariable() { PIConditionVariable::~PIConditionVariable() { -#ifdef WINDOWS +#if defined(WINDOWS) +#elif defined(FREERTOS) + vEventGroupDelete(PRIVATE->nativeHandle); #else pthread_cond_destroy(&PRIVATE->nativeHandle); #endif @@ -64,8 +73,11 @@ PIConditionVariable::~PIConditionVariable() { void PIConditionVariable::wait(PIMutex& lk) { -#ifdef WINDOWS +#if defined(WINDOWS) SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE); +#elif defined(FREERTOS) + xEventGroupClearBits(PRIVATE->nativeHandle, 1); + xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY); #else pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle()); #endif @@ -77,8 +89,11 @@ void PIConditionVariable::wait(PIMutex& lk, const std::function& conditi while (true) { isCondition = condition(); if (isCondition) break; -#ifdef WINDOWS +#if defined(WINDOWS) SleepConditionVariableCS(&PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), INFINITE); +#elif defined(FREERTOS) + xEventGroupClearBits(PRIVATE->nativeHandle, 1); + xEventGroupWaitBits(PRIVATE->nativeHandle, 1, pdTRUE, pdTRUE, portMAX_DELAY); #else pthread_cond_wait(&PRIVATE->nativeHandle, (pthread_mutex_t*)lk.handle()); #endif @@ -88,8 +103,13 @@ void PIConditionVariable::wait(PIMutex& lk, const std::function& conditi bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) { bool isNotTimeout; -#ifdef WINDOWS +#if defined(WINDOWS) 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 timespec expire_ts; PISystemTime st = PISystemTime::current(true); @@ -103,24 +123,32 @@ bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) { bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::function &condition) { bool isCondition; -#ifdef WINDOWS +#if defined(WINDOWS) || defined(FREERTOS) PITimeMeasurer measurer; #else timespec expire_ts; PISystemTime st = PISystemTime::current(true); st.addMilliseconds(timeoutMs); st.toTimespec(&expire_ts); +#endif +#ifdef FREERTOS + xEventGroupClearBits(PRIVATE->nativeHandle, 1); #endif while (true) { isCondition = condition(); if (isCondition) break; -#ifdef WINDOWS - bool isTimeout = SleepConditionVariableCS( + bool isTimeout; +#if defined(WINDOWS) + isTimeout = SleepConditionVariableCS( &PRIVATE->nativeHandle, (PCRITICAL_SECTION)lk.handle(), 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 - 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 if (isTimeout) return false; } @@ -129,8 +157,10 @@ bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::functio void PIConditionVariable::notifyOne() { -#ifdef WINDOWS +#if defined(WINDOWS) WakeConditionVariable(&PRIVATE->nativeHandle); +#elif defined(FREERTOS) + xEventGroupSetBits(PRIVATE->nativeHandle, 1); #else pthread_cond_signal(&PRIVATE->nativeHandle); #endif @@ -138,8 +168,10 @@ void PIConditionVariable::notifyOne() { void PIConditionVariable::notifyAll() { -#ifdef WINDOWS +#if defined(WINDOWS) WakeAllConditionVariable(&PRIVATE->nativeHandle); +#elif defined(FREERTOS) + xEventGroupSetBits(PRIVATE->nativeHandle, 1); #else pthread_cond_broadcast(&PRIVATE->nativeHandle); #endif diff --git a/libs/main/thread/pimutex.cpp b/libs/main/thread/pimutex.cpp index 80ea11fd..db42b86f 100644 --- a/libs/main/thread/pimutex.cpp +++ b/libs/main/thread/pimutex.cpp @@ -36,8 +36,10 @@ #include "pimutex.h" #include "piincludes_p.h" -#ifdef WINDOWS +#if defined(WINDOWS) # include +#elif defined(FREERTOS) +# include #else # include #endif @@ -45,8 +47,10 @@ PRIVATE_DEFINITION_START(PIMutex) -#ifdef WINDOWS +#if defined(WINDOWS) CRITICAL_SECTION +#elif defined(FREERTOS) + SemaphoreHandle_t #else pthread_mutex_t #endif @@ -65,8 +69,10 @@ PIMutex::~PIMutex() { void PIMutex::lock() { -#ifdef WINDOWS +#if defined(WINDOWS) EnterCriticalSection(&(PRIVATE->mutex)); +#elif defined(FREERTOS) + xSemaphoreTake(PRIVATE->mutex, portMAX_DELAY); #else pthread_mutex_lock(&(PRIVATE->mutex)); #endif @@ -74,8 +80,10 @@ void PIMutex::lock() { void PIMutex::unlock() { -#ifdef WINDOWS +#if defined(WINDOWS) LeaveCriticalSection(&(PRIVATE->mutex)); +#elif defined(FREERTOS) + xSemaphoreGive(PRIVATE->mutex); #else pthread_mutex_unlock(&(PRIVATE->mutex)); #endif @@ -84,8 +92,10 @@ void PIMutex::unlock() { bool PIMutex::tryLock() { bool ret = -#ifdef WINDOWS +#if defined(WINDOWS) (TryEnterCriticalSection(&(PRIVATE->mutex)) != 0); +#elif defined(FREERTOS) + xSemaphoreTake(PRIVATE->mutex, 0); #else (pthread_mutex_trylock(&(PRIVATE->mutex)) == 0); #endif @@ -94,13 +104,19 @@ bool PIMutex::tryLock() { void * PIMutex::handle() { +#ifdef FREERTOS + return PRIVATE->mutex; +#else return (void*)&(PRIVATE->mutex); +#endif } void PIMutex::init() { -#ifdef WINDOWS +#if defined(WINDOWS) InitializeCriticalSection(&(PRIVATE->mutex)); +#elif defined(FREERTOS) + PRIVATE->mutex = xSemaphoreCreateMutex(); #else pthread_mutexattr_t attr; memset(&attr, 0, sizeof(attr)); @@ -114,8 +130,10 @@ void PIMutex::init() { void PIMutex::destroy() { -#ifdef WINDOWS +#if defined(WINDOWS) DeleteCriticalSection(&(PRIVATE->mutex)); +#elif defined(FREERTOS) + vSemaphoreDelete(PRIVATE->mutex); #else pthread_mutex_destroy(&(PRIVATE->mutex)); #endif diff --git a/libs/main/thread/pimutex.h b/libs/main/thread/pimutex.h index dab51359..847d5eb6 100644 --- a/libs/main/thread/pimutex.h +++ b/libs/main/thread/pimutex.h @@ -24,7 +24,6 @@ #define PIMUTEX_H #include "piinit.h" -#include class PIP_EXPORT PIMutex diff --git a/libs/main/thread/pithread.cpp b/libs/main/thread/pithread.cpp index 863d6a63..e1eb1f4d 100644 --- a/libs/main/thread/pithread.cpp +++ b/libs/main/thread/pithread.cpp @@ -19,27 +19,40 @@ #include "piincludes_p.h" #include "pithread.h" -#include "pisystemtests.h" #include "piintrospection_threads.h" +#ifndef MICRO_PIP +# include "pisystemtests.h" +#endif #include -#ifdef WINDOWS +#if defined(WINDOWS) # define __THREAD_FUNC_RET__ uint __stdcall +#elif defined(FREERTOS) +# define __THREAD_FUNC_RET__ void #else # define __THREAD_FUNC_RET__ void* #endif +#ifndef FREERTOS +# define __THREAD_FUNC_END__ 0 +#else +# define __THREAD_FUNC_END__ +#endif #if defined(LINUX) # include # define gettid() syscall(SYS_gettid) #endif -#if defined(MAC_OS) || defined(BLACKBERRY) || defined(FREERTOS) +#if defined(MAC_OS) || defined(BLACKBERRY) # include #endif -__THREAD_FUNC_RET__ thread_function(void * t) {((PIThread*)t)->__thread_func__(); return 0;} -__THREAD_FUNC_RET__ thread_function_once(void * t) {((PIThread*)t)->__thread_func_once__(); return 0;} - -#define REGISTER_THREAD(t) __PIThreadCollection::instance()->registerThread(t) -#define UNREGISTER_THREAD(t) __PIThreadCollection::instance()->unregisterThread(t) +__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 __THREAD_FUNC_END__;} +#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 * @brief Thread class @@ -90,6 +103,7 @@ end(); * */ +#ifndef MICRO_PIP __PIThreadCollection *__PIThreadCollection::instance() { return __PIThreadCollection_Initializer__::__instance__; @@ -158,15 +172,17 @@ __PIThreadCollection_Initializer__::~__PIThreadCollection_Initializer__() { } } - +#endif // MICRO_PIP PRIVATE_DEFINITION_START(PIThread) -#ifndef WINDOWS +#if defined(WINDOWS) + void * thread; +#elif defined(FREERTOS) + TaskHandle_t thread; +#else pthread_t thread; sched_param sparam; -#else - void * thread; #endif PRIVATE_DEFINITION_END(PIThread) @@ -267,22 +283,22 @@ void PIThread::terminate() { terminating = running_ = false; tid_ = -1; //PICout(PICoutManipulators::DefaultControls) << "terminate" << PRIVATE->thread; -#ifndef WINDOWS -# ifdef ANDROID +# ifndef WINDOWS +# ifdef ANDROID pthread_kill(PRIVATE->thread, SIGTERM); -# else +# else //pthread_kill(PRIVATE->thread, SIGKILL); //void * ret(0); pthread_cancel(PRIVATE->thread); //pthread_join(PRIVATE->thread, &ret); -# endif -#else +# endif +# else TerminateThread(PRIVATE->thread, 0); CloseHandle(PRIVATE->thread); -#endif +# endif PRIVATE->thread = 0; end(); -#endif +#endif //FREERTOS PIINTROSPECTION_THREAD_STOP(this); //PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ok" << running_; } @@ -290,27 +306,31 @@ void PIThread::terminate() { int PIThread::priority2System(PIThread::Priority p) { switch (p) { -# ifdef QNX +#if defined(QNX) case piLowerst: return 8; case piLow: return 9; case piNormal: return 10; case piHigh: return 11; case piHighest: return 12; -# else -# ifdef WINDOWS +#elif defined(WINDOWS) case piLowerst: return -2; case piLow: return -1; case piNormal: return 0; case piHigh: return 1; 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 piLow: return 1; case piNormal: return 0; case piHigh: return -1; case piHighest: return -2; -# endif -# endif +#endif default: return 0; } return 0; @@ -320,11 +340,11 @@ int PIThread::priority2System(PIThread::Priority p) { bool PIThread::_startThread(void * func) { terminating = false; running_ = true; -#ifndef WINDOWS +#if !defined(WINDOWS) && !defined(FREERTOS) pthread_attr_t attr; pthread_attr_init(&attr); 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; pthread_attr_destroy(&attr); if (ret == 0) { @@ -332,22 +352,32 @@ bool PIThread::_startThread(void * func) { pthread_setname_np(((PIString&)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii()); pthread_threadid_np(PRIVATE->thread, (__uint64_t*)&tid_); # else -# ifdef FREERTOS - tid_ = PRIVATE->thread; -# else pthread_setname_np(PRIVATE->thread, ((PIString&)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii()); -# endif # endif -#else +#endif +#ifdef WINDOWS if (PRIVATE->thread) CloseHandle(PRIVATE->thread); # 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 PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0); # endif if (PRIVATE->thread != 0) { #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_); +#endif return true; } else { running_ = false; @@ -360,10 +390,12 @@ bool PIThread::_startThread(void * func) { void PIThread::setPriority(PIThread::Priority prior) { -#ifndef FREERTOS // FreeRTOS can't change priority runtime priority_ = prior; -# ifndef WINDOWS if (!running_ || (PRIVATE->thread == 0)) return; +#ifdef FREERTOS + vTaskPrioritySet(PRIVATE->thread, priority2System(priority_)); +#else +# ifndef WINDOWS //PICout(PICoutManipulators::DefaultControls) << "setPriority" << PRIVATE->thread; policy_ = 0; memset(&(PRIVATE->sparam), 0, sizeof(PRIVATE->sparam)); @@ -503,18 +535,18 @@ void PIThread::_endThread() { //PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread; UNREGISTER_THREAD(this); PIINTROSPECTION_THREAD_STOP(this); -#ifndef WINDOWS - pthread_detach(PRIVATE->thread); - PRIVATE->thread = 0; -#endif -#ifndef WINDOWS - pthread_exit(0); -#else +#if defined(WINDOWS) # ifdef CC_GCC _endthreadex(0); # else ExitThread(0); # endif +#elif defined(FREERTOS) + PRIVATE->thread = 0; +#else + pthread_detach(PRIVATE->thread); + PRIVATE->thread = 0; + pthread_exit(0); #endif } @@ -558,8 +590,10 @@ void PIThread::runOnce(PIObject * object, const char * handler, const PIString & delete t; return; } +#ifndef MICRO_PIP __PIThreadCollection::instance()->startedAuto(t); CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto); +#endif t->startOnce(); } @@ -568,8 +602,10 @@ void PIThread::runOnce(std::function func, const PIString & name) { PIThread * t = new PIThread(); t->setName(name); t->setSlot(func); +#ifndef MICRO_PIP __PIThreadCollection::instance()->startedAuto(t); CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto); +#endif t->startOnce(); } diff --git a/libs/main/thread/pithread.h b/libs/main/thread/pithread.h index db6053cd..6d676f68 100644 --- a/libs/main/thread/pithread.h +++ b/libs/main/thread/pithread.h @@ -30,6 +30,8 @@ #include "piobject.h" class PIThread; + +#ifndef MICRO_PIP class PIIntrospectionThreads; class PIP_EXPORT __PIThreadCollection: public PIObject { @@ -58,14 +60,16 @@ public: }; static __PIThreadCollection_Initializer__ __PIThreadCollection_initializer__; - +#endif // MICRO_PIP typedef std::function ThreadFunc; class PIP_EXPORT PIThread: public PIObject { PIOBJECT_SUBCLASS(PIThread, PIObject) +#ifndef MICRO_PIP friend class PIIntrospectionThreads; +#endif public: NO_COPY_CLASS(PIThread) From 4921a3b0fdac759b56134868e74392b289706af4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 21 Jan 2022 17:09:21 +0300 Subject: [PATCH 10/12] arduino PISystemTime::current --- libs/main/core/pitime.cpp | 37 ++++++++++++++++++++++++++----- libs/main/core/pivarianttypes.cpp | 8 +++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/libs/main/core/pitime.cpp b/libs/main/core/pitime.cpp index bca22117..7cc9123c 100644 --- a/libs/main/core/pitime.cpp +++ b/libs/main/core/pitime.cpp @@ -19,7 +19,11 @@ #include "piincludes_p.h" #include "pitime.h" -#include "pisystemtests.h" +#ifndef MICRO_PIP +# include "pisystemtests.h" +#elif defined(ARDUINO) +# include +#endif #ifdef WINDOWS extern FILETIME __pi_ftjan1970; long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;} @@ -256,12 +260,19 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) { clock_get_time(__pi_mac_clock, &t_cur); #elif defined(MICRO_PIP) 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; tv.tv_sec = 0; tv.tv_usec = 0; gettimeofday(&tv, NULL); t_cur.tv_sec = tv.tv_sec; t_cur.tv_nsec = tv.tv_usec * 1000; +# endif #else timespec t_cur; clock_gettime(precise_but_not_system ? CLOCK_MONOTONIC : 0, &t_cur); @@ -404,22 +415,38 @@ PITimeMeasurer::PITimeMeasurer() { 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 { - 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 { - 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 { - 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 + ; } diff --git a/libs/main/core/pivarianttypes.cpp b/libs/main/core/pivarianttypes.cpp index de21989e..6eb609cb 100644 --- a/libs/main/core/pivarianttypes.cpp +++ b/libs/main/core/pivarianttypes.cpp @@ -84,9 +84,12 @@ PIStringList PIVariantTypes::Enum::names() const { -#ifndef MICRO_PIP PIVariantTypes::IODevice::IODevice() { +#ifndef MICRO_PIP mode = PIIODevice::ReadWrite; +#else + mode = 0; // TODO: PIIODevice for MICRO PIP +#endif // MICRO_PIP options = 0; } @@ -113,12 +116,14 @@ PIString PIVariantTypes::IODevice::toPICout() const { if (mode & 2) {s << "w"; ++rwc;} if (rwc == 1) s << "o"; s << ", flags="; +#ifndef MICRO_PIP // TODO: PIIODevice for MICRO PIP if (options != 0) { if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingRead]) s << " br"; if (((PIIODevice::DeviceOptions)options)[PIIODevice::BlockingWrite]) s << " bw"; } +#endif // MICRO_PIP PIPropertyStorage ps = get(); piForeachC (PIPropertyStorage::Property & p, ps) { s << ", " << p.name << "=\"" << p.value.toString() << "\""; @@ -126,7 +131,6 @@ PIString PIVariantTypes::IODevice::toPICout() const { s << ")"; return s; } -#endif // MICRO_PIP From fff2aa468a1e20d3941b1374874de71d7e4c4fcc Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 11 Feb 2022 12:00:34 +0300 Subject: [PATCH 11/12] PIP_FORCE_NO_PIINTROSPECTION --- libs/main/introspection/piintrospection_base.h | 2 +- libs/main/introspection/piintrospection_containers.cpp | 4 ++-- libs/main/introspection/piintrospection_containers.h | 4 ++-- libs/main/introspection/piintrospection_server.cpp | 2 +- libs/main/introspection/piintrospection_server.h | 3 +-- libs/main/introspection/piintrospection_threads.cpp | 2 +- libs/main/introspection/piintrospection_threads.h | 5 ++--- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libs/main/introspection/piintrospection_base.h b/libs/main/introspection/piintrospection_base.h index e21f9830..0b1063f0 100644 --- a/libs/main/introspection/piintrospection_base.h +++ b/libs/main/introspection/piintrospection_base.h @@ -29,7 +29,7 @@ class PIPeer; class PIIntrospection; class PIIntrospectionServer; -#ifdef PIP_INTROSPECTION +#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) #define __PIINTROSPECTION_SINGLETON_H__(T) \ static PIIntrospection##T##Interface * instance(); diff --git a/libs/main/introspection/piintrospection_containers.cpp b/libs/main/introspection/piintrospection_containers.cpp index 2142a578..3d3f9aa3 100644 --- a/libs/main/introspection/piintrospection_containers.cpp +++ b/libs/main/introspection/piintrospection_containers.cpp @@ -17,11 +17,11 @@ along with this program. If not, see . */ +#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) + #include "piintrospection_containers.h" #include "piintrospection_containers_p.h" -#ifdef PIP_INTROSPECTION - __PIINTROSPECTION_SINGLETON_CPP__(Containers) diff --git a/libs/main/introspection/piintrospection_containers.h b/libs/main/introspection/piintrospection_containers.h index 23de690f..7af41f50 100644 --- a/libs/main/introspection/piintrospection_containers.h +++ b/libs/main/introspection/piintrospection_containers.h @@ -20,10 +20,10 @@ #ifndef PIINTROSPECTION_CONTAINERS_H #define PIINTROSPECTION_CONTAINERS_H +#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) + #include "piintrospection_base.h" - -#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) class PIIntrospectionContainers; #define PIINTROSPECTION_CONTAINERS (PIIntrospectionContainersInterface::instance())//(PIIntrospectionContainersInterface::instance()) diff --git a/libs/main/introspection/piintrospection_server.cpp b/libs/main/introspection/piintrospection_server.cpp index 6275d91d..a8f7042e 100644 --- a/libs/main/introspection/piintrospection_server.cpp +++ b/libs/main/introspection/piintrospection_server.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#ifdef PIP_INTROSPECTION +#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) #include "piintrospection_server.h" #include "piintrospection_server_p.h" diff --git a/libs/main/introspection/piintrospection_server.h b/libs/main/introspection/piintrospection_server.h index 31b2620a..2fc1f31b 100644 --- a/libs/main/introspection/piintrospection_server.h +++ b/libs/main/introspection/piintrospection_server.h @@ -20,11 +20,10 @@ #ifndef PIINTROSPECTION_SERVER_H #define PIINTROSPECTION_SERVER_H +#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) #include "pipeer.h" -#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) - class PIIntrospectionServer; class PISystemMonitor; diff --git a/libs/main/introspection/piintrospection_threads.cpp b/libs/main/introspection/piintrospection_threads.cpp index 98d829d0..4ecc9ffd 100644 --- a/libs/main/introspection/piintrospection_threads.cpp +++ b/libs/main/introspection/piintrospection_threads.cpp @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#ifdef PIP_INTROSPECTION +#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) #include "piintrospection_threads.h" #include "piintrospection_threads_p.h" diff --git a/libs/main/introspection/piintrospection_threads.h b/libs/main/introspection/piintrospection_threads.h index e582ae07..3d024f6b 100644 --- a/libs/main/introspection/piintrospection_threads.h +++ b/libs/main/introspection/piintrospection_threads.h @@ -20,11 +20,10 @@ #ifndef PIINTROSPECTION_THREADS_H #define PIINTROSPECTION_THREADS_H -#include "piintrospection_base.h" - - #if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION) +#include "piintrospection_base.h" + class PIIntrospectionThreads; #define PIINTROSPECTION_THREADS (PIIntrospectionThreadsInterface::instance()) From c3c98b9d78a6b50df7b3ea4c9e97e3bfd6e2f2a7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 14 Feb 2022 14:01:54 +0300 Subject: [PATCH 12/12] include fixes --- libs/main/core/pivariantsimple.h | 2 +- libs/main/thread/piconditionvar.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/main/core/pivariantsimple.h b/libs/main/core/pivariantsimple.h index 56afc755..dd6067e9 100644 --- a/libs/main/core/pivariantsimple.h +++ b/libs/main/core/pivariantsimple.h @@ -51,7 +51,7 @@ public: #ifdef MICRO_PIP PIString typeName() const final {static PIString ret(PIVariant(T()).typeName()); return ret;} #else - PIString typeName() const final {static PIString ret(_TYPENAME_(T)); return ret;} + PIString typeName() const final {static PIString ret(typeid(T).name()); return ret;} #endif uint hash() const final {static uint ret = typeName().hash(); return ret;} void newT(void *& ptr, const void * value) final {ptr = (void*)(new T(*(const T*)value));} diff --git a/libs/main/thread/piconditionvar.cpp b/libs/main/thread/piconditionvar.cpp index 2143ac24..78c4ecb5 100644 --- a/libs/main/thread/piconditionvar.cpp +++ b/libs/main/thread/piconditionvar.cpp @@ -17,13 +17,17 @@ along with this program. If not, see . */ +#include "piplatform.h" +#ifdef WINDOWS +# undef _WIN32_WINNT +# define _WIN32_WINNT 0x0600 +#endif + #include "piconditionvar.h" #include "pithread.h" #include "pitime.h" #include "piincludes_p.h" #ifdef WINDOWS -# undef _WIN32_WINNT -# define _WIN32_WINNT 0x0600 # include # include # include