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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@
|
||||
/.svn
|
||||
/doc/rtf
|
||||
_unsused
|
||||
CMakeLists.txt.user*
|
||||
CMakeLists.txt.user*
|
||||
/include
|
||||
29
library.json
Normal file
29
library.json
Normal 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"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "piincludes_p.h"
|
||||
#include "piterminal.h"
|
||||
#include "pisharedmemory.h"
|
||||
#ifndef FREERTOS
|
||||
#ifndef MICRO_PIP
|
||||
#ifdef WINDOWS
|
||||
# include <windows.h>
|
||||
# include <wingdi.h>
|
||||
@@ -918,4 +918,4 @@ bool PITerminal::resize(int cols, int rows) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // FREERTOS
|
||||
#endif // MICRO_PIP
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
#include "pip_export.h"
|
||||
#include "pip_defs.h"
|
||||
#include "string.h"
|
||||
#include <limits>
|
||||
|
||||
//! 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,15 @@
|
||||
|
||||
#endif //DOXYGEN
|
||||
|
||||
#ifdef CC_AVR_GCC
|
||||
# include <ArduinoSTL.h>
|
||||
#endif
|
||||
#include <functional>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <atomic>
|
||||
|
||||
#ifdef WINDOWS
|
||||
# ifdef CC_VC
|
||||
# define SHUT_RDWR 2
|
||||
@@ -162,7 +166,6 @@
|
||||
#ifdef NDEBUG
|
||||
# undef NDEBUG
|
||||
#endif
|
||||
#include <cassert>
|
||||
#ifndef assert
|
||||
# define assert(x)
|
||||
# define assertm(exp, msg)
|
||||
@@ -275,7 +278,7 @@
|
||||
} _PIP_ADD_COUNTER(_pip_initializer_);
|
||||
|
||||
|
||||
#ifdef FREERTOS
|
||||
#ifdef MICRO_PIP
|
||||
# define PIP_MIN_MSLEEP 10.
|
||||
#else
|
||||
# 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;}
|
||||
|
||||
// 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);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "pivector2d.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef FREERTOS
|
||||
#ifdef MICRO_PIP
|
||||
# define _TYPENAME_(T) "?"
|
||||
#else
|
||||
# define _TYPENAME_(T) typeid(T).name()
|
||||
|
||||
@@ -26,15 +26,15 @@
|
||||
#ifdef PIP_STD_IOSTREAM
|
||||
# include <iostream>
|
||||
#endif
|
||||
#include <atomic>
|
||||
|
||||
|
||||
class PIMutex;
|
||||
class PIMutexLocker;
|
||||
class PIObject;
|
||||
class PIString;
|
||||
class PIByteArray;
|
||||
#ifndef MICRO_PIP
|
||||
class PIInit;
|
||||
#endif
|
||||
class PIChar;
|
||||
class PICout;
|
||||
|
||||
|
||||
@@ -40,6 +40,15 @@ typedef LONG(NTAPI*PINtSetTimerResolution)(ULONG, BOOLEAN, PULONG);
|
||||
#include <cstdio>
|
||||
#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
|
||||
|
||||
@@ -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 FREERTOS
|
||||
# include "piprocess.h"
|
||||
#endif
|
||||
#include "piprocess.h"
|
||||
#ifdef ESP_PLATFORM
|
||||
# include "esp_system.h"
|
||||
#endif
|
||||
@@ -49,9 +49,7 @@ void __PISetTimerResolution() {
|
||||
}
|
||||
#else
|
||||
# include <pwd.h>
|
||||
# ifndef FREERTOS
|
||||
# include <sys/utsname.h>
|
||||
# endif
|
||||
# include <sys/utsname.h>
|
||||
# include <pthread.h>
|
||||
# ifdef BLACKBERRY
|
||||
# include <signal.h>
|
||||
@@ -84,7 +82,6 @@ ULONG prev_res;
|
||||
bool delete_locs;
|
||||
PRIVATE_DEFINITION_END(PIInit)
|
||||
|
||||
#ifndef FREERTOS
|
||||
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
|
||||
@@ -107,7 +103,6 @@ PIInit::PIInit() {
|
||||
PISystemInfo * sinfo = PISystemInfo::instance();
|
||||
sinfo->execDateTime = PIDateTime::current();
|
||||
setFileCharset("UTF-8");
|
||||
#ifndef FREERTOS
|
||||
#ifndef ANDROID
|
||||
PISignals::setSlot(__sighandler__);
|
||||
PISignals::grabSignals(PISignals::UserDefined1);
|
||||
@@ -128,7 +123,7 @@ PIInit::PIInit() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
# else
|
||||
# else //WINDOWS
|
||||
// OS version
|
||||
DWORD dwVersion = GetVersion();
|
||||
DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
|
||||
@@ -154,7 +149,7 @@ PIInit::PIInit() {
|
||||
setTimerResolutionAddr = (PINtSetTimerResolution)GetProcAddress(PRIVATE->ntlib, "NtSetTimerResolution");
|
||||
__PISetTimerResolution();
|
||||
}
|
||||
# endif
|
||||
# endif //WINDOWS
|
||||
# ifdef HAS_LOCALE
|
||||
//cout << "has locale" << endl;
|
||||
if (currentLocale_t != 0) {
|
||||
@@ -162,18 +157,18 @@ PIInit::PIInit() {
|
||||
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<char*>("UTF-8");
|
||||
@@ -201,13 +196,13 @@ PIInit::PIInit() {
|
||||
# endif
|
||||
//piCout << __syslocname__;
|
||||
//piCout << __sysoemname__;
|
||||
#else
|
||||
#else //PIP_ICU
|
||||
# ifdef WINDOWS
|
||||
__syslocname__ = (char *)CP_ACP;
|
||||
__sysoemname__ = (char *)CP_OEMCP;
|
||||
__utf8name__ = (char *)CP_UTF8;
|
||||
# endif
|
||||
#endif
|
||||
#endif //PIP_ICU
|
||||
#ifdef MAC_OS
|
||||
host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &__pi_mac_clock);
|
||||
#endif
|
||||
@@ -236,7 +231,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 +247,8 @@ PIInit::PIInit() {
|
||||
sinfo->OS_version = uns.release;
|
||||
sinfo->architecture = uns.machine;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
#endif //WINDOWS
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
@@ -275,6 +270,8 @@ PIInit::PIInit() {
|
||||
PIStringAscii("FreeBSD");
|
||||
#elif defined(FREERTOS)
|
||||
PIStringAscii("FreeRTOS");
|
||||
#elif defined(MICRO_PIP)
|
||||
PIStringAscii("MicroPIP");
|
||||
#else
|
||||
uns.sysname;
|
||||
#endif
|
||||
@@ -305,49 +302,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
|
||||
@@ -361,14 +358,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;
|
||||
}
|
||||
|
||||
@@ -415,3 +412,6 @@ __PIInit_Initializer__::~__PIInit_Initializer__() {
|
||||
__instance__ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICRO_PIP
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#ifndef PIINIT_H
|
||||
#define PIINIT_H
|
||||
|
||||
#include "pibase.h"
|
||||
|
||||
#ifndef MICRO_PIP
|
||||
|
||||
#include "piincludes.h"
|
||||
|
||||
|
||||
@@ -49,14 +53,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);
|
||||
@@ -70,4 +74,5 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MICRO_PIP
|
||||
#endif // PIINIT_H
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
*/
|
||||
|
||||
#include "piobject.h"
|
||||
#include "pisysteminfo.h"
|
||||
#include "pithread.h"
|
||||
#include "piconditionvar.h"
|
||||
#ifndef FREERTOS
|
||||
#ifndef MICRO_PIP
|
||||
# include "pisysteminfo.h"
|
||||
# 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<Connection> & oc(o->connections);
|
||||
@@ -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 FREERTOS
|
||||
bool dumpApplicationToFile(const PIString & path) {
|
||||
PIFile f(path + "_tmp");
|
||||
f.setName("__S__DumpFile");
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 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);
|
||||
template <typename INPUT, typename... TYPES>
|
||||
static std::function<void()> * __newFunctor(void(*stat_handler)(void*,TYPES...), INPUT functor) {
|
||||
return (std::function<void()>*)(new std::function<void(TYPES...)>(functor));
|
||||
template <typename PIINPUT, typename... PITYPES>
|
||||
static std::function<void()> * __newFunctor(void(*stat_handler)(void*,PITYPES...), PIINPUT 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 bool dumpApplicationToFile(const PIString & path);
|
||||
#endif
|
||||
|
||||
#endif // PIOBJECT_H
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "pitime.h"
|
||||
#include "pisystemtests.h"
|
||||
#ifndef MICRO_PIP
|
||||
# include "pisystemtests.h"
|
||||
#elif defined(ARDUINO)
|
||||
# include <Arduino.h>
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
long long __PIQueryPerformanceCounter() {LARGE_INTEGER li; QueryPerformanceCounter(&li); return li.QuadPart;}
|
||||
@@ -31,9 +35,8 @@
|
||||
//# include <crt_externs.h>
|
||||
extern clock_serv_t __pi_mac_clock;
|
||||
#endif
|
||||
#ifdef FREERTOS
|
||||
# include "freertos/FreeRTOS.h"
|
||||
# include "freertos/task.h"
|
||||
#ifdef MICRO_PIP
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
/*! \class PISystemTime
|
||||
@@ -252,24 +255,29 @@ 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;
|
||||
# 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;
|
||||
# else
|
||||
# endif
|
||||
#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
|
||||
}
|
||||
@@ -407,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
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "pistring.h"
|
||||
#include <typeinfo>
|
||||
#ifdef PIP_FREERTOS
|
||||
#ifdef MICRO_PIP
|
||||
#include "pivariant.h"
|
||||
#endif
|
||||
|
||||
@@ -48,7 +48,7 @@ template<typename T>
|
||||
class __VariantFunctions__: public __VariantFunctionsBase__ {
|
||||
public:
|
||||
__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;}
|
||||
#else
|
||||
PIString typeName() const final {static PIString ret(typeid(T).name()); return ret;}
|
||||
|
||||
@@ -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,9 +84,12 @@ PIStringList PIVariantTypes::Enum::names() const {
|
||||
|
||||
|
||||
|
||||
|
||||
PIVariantTypes::IODevice::IODevice() {
|
||||
#ifndef MICRO_PIP
|
||||
mode = PIIODevice::ReadWrite;
|
||||
#else
|
||||
mode = 0; // TODO: PIIODevice for MICRO PIP
|
||||
#endif // MICRO_PIP
|
||||
options = 0;
|
||||
}
|
||||
|
||||
@@ -112,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() << "\"";
|
||||
@@ -128,7 +134,6 @@ PIString PIVariantTypes::IODevice::toPICout() const {
|
||||
|
||||
|
||||
|
||||
|
||||
PIVariantTypes::Enum & PIVariantTypes::Enum::operator <<(const PIVariantTypes::Enumerator & v) {
|
||||
enum_list << v;
|
||||
return *this;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
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_p.h"
|
||||
|
||||
#ifdef PIP_INTROSPECTION
|
||||
|
||||
__PIINTROSPECTION_SINGLETON_CPP__(Containers)
|
||||
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
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_p.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;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
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_p.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())
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -58,10 +58,10 @@
|
||||
# include <sys/socket.h>
|
||||
# include <netdb.h>
|
||||
# include <net/if.h>
|
||||
# if !defined(ANDROID) && !defined(FREERTOS)
|
||||
# if !defined(ANDROID) && !defined(LWIP)
|
||||
# include <ifaddrs.h>
|
||||
# endif
|
||||
# ifdef FREERTOS
|
||||
# ifdef LWIP
|
||||
# include <lwip/sockets.h>
|
||||
# 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<Parameters> 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<Parameters> 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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "pipropertystorage.h"
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(FREERTOS)
|
||||
#if defined(MICRO_PIP)
|
||||
# define PISERIAL_NO_PINS
|
||||
#endif
|
||||
#if defined(PISERIAL_NO_PINS) || defined(WINDOWS)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "pifft.h"
|
||||
|
||||
#ifndef MICRO_PIP
|
||||
|
||||
PIFFT_double::PIFFT_double() {
|
||||
}
|
||||
@@ -1883,3 +1884,5 @@ void PIFFT_float::ftbase_ffttwcalc(PIVector<float> * a, int aoffset, int n1, int
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICRO_PIP
|
||||
|
||||
@@ -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<ldouble> PIFFTWld;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MICRO_PIP
|
||||
|
||||
#endif // PIFFT_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
|
||||
@@ -84,6 +87,10 @@
|
||||
# define CC_OTHER
|
||||
#endif
|
||||
|
||||
#ifdef __AVR__
|
||||
# define CC_AVR_GCC
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
# ifdef CC_GCC
|
||||
# define typeof __typeof
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<uint>();
|
||||
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, "<PIThread>");
|
||||
#else
|
||||
ts.name = tbid.value(id, "<non-PIThread>");
|
||||
|
||||
@@ -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<llong, PIString> tbid;
|
||||
mutable PIMutex stat_mutex;
|
||||
int pID_, page_size, cpu_count, cycle;
|
||||
#ifndef FREERTOS
|
||||
#ifndef MICRO_PIP
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -17,36 +17,47 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piconditionvar.h"
|
||||
#include "pithread.h"
|
||||
#include "pitime.h"
|
||||
|
||||
#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
|
||||
# include <synchapi.h>
|
||||
# include <windef.h>
|
||||
# include <winbase.h>
|
||||
#endif
|
||||
#ifdef FREERTOS
|
||||
# include <event_groups.h>
|
||||
#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);
|
||||
# ifndef MAC_OS
|
||||
# if !defined(MAC_OS)
|
||||
pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
|
||||
# endif
|
||||
memset(&(PRIVATE->nativeHandle), 0, sizeof(PRIVATE->nativeHandle));
|
||||
@@ -56,7 +67,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 +77,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 +93,11 @@ void PIConditionVariable::wait(PIMutex& lk, const std::function<bool()>& 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 +107,13 @@ void PIConditionVariable::wait(PIMutex& lk, const std::function<bool()>& 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 +127,32 @@ bool PIConditionVariable::waitFor(PIMutex &lk, int timeoutMs) {
|
||||
|
||||
bool PIConditionVariable::waitFor(PIMutex& lk, int timeoutMs, const std::function<bool()> &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 +161,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 +172,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
|
||||
|
||||
@@ -36,8 +36,10 @@
|
||||
|
||||
#include "pimutex.h"
|
||||
#include "piincludes_p.h"
|
||||
#ifdef WINDOWS
|
||||
#if defined(WINDOWS)
|
||||
# include <synchapi.h>
|
||||
#elif defined(FREERTOS)
|
||||
# include <semphr.h>
|
||||
#else
|
||||
# include <pthread.h>
|
||||
#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
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#define PIMUTEX_H
|
||||
|
||||
#include "piinit.h"
|
||||
#include <mutex>
|
||||
|
||||
|
||||
class PIP_EXPORT PIMutex
|
||||
|
||||
@@ -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 <signal.h>
|
||||
#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 <sys/syscall.h>
|
||||
# define gettid() syscall(SYS_gettid)
|
||||
#endif
|
||||
#if defined(MAC_OS) || defined(BLACKBERRY) || defined(FREERTOS)
|
||||
#if defined(MAC_OS) || defined(BLACKBERRY)
|
||||
# include <pthread.h>
|
||||
#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<void ()> 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void(void *)> ThreadFunc;
|
||||
|
||||
class PIP_EXPORT PIThread: public PIObject
|
||||
{
|
||||
PIOBJECT_SUBCLASS(PIThread, PIObject)
|
||||
#ifndef MICRO_PIP
|
||||
friend class PIIntrospectionThreads;
|
||||
#endif
|
||||
public:
|
||||
NO_COPY_CLASS(PIThread)
|
||||
|
||||
|
||||
85
platformio_pre.py
Normal file
85
platformio_pre.py
Normal 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)
|
||||
|
||||
Reference in New Issue
Block a user