RTOS work threads
git-svn-id: svn://db.shs.com.ru/pip@687 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -18,7 +18,7 @@ set(COMPONENT_PRIV_REQUIRES pthread)
|
||||
register_component()
|
||||
set(PIP_FREERTOS ON)
|
||||
set(LIB OFF)
|
||||
include_directories(${IDF_INCLUDE_DIRECTORIES} ../newlib/platform_include ../libsodium/libsodium/src/libsodium/include ../libsodium/port_include)
|
||||
include_directories(${IDF_INCLUDE_DIRECTORIES} ../newlib/platform_include ../libsodium/libsodium/src/libsodium/include ../libsodium/port_include ../heap/include ../esp32/include ../spi_flash/include ../driver/include ../soc/include ../soc/esp32/include ../freertos/include)
|
||||
#message("IDF_COMPILE_DEFINITIONS = ${IDF_COMPILE_DEFINITIONS}")
|
||||
#message("IDF_INCLUDE_DIRECTORIES = ${IDF_INCLUDE_DIRECTORIES}")
|
||||
add_compile_options(${IDF_COMPILE_OPTIONS})
|
||||
@@ -28,4 +28,4 @@ add_definitions(-DGCC_NOT_5_2_0=0)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
add_subdirectory(pip)
|
||||
|
||||
target_link_libraries(${COMPONENT_TARGET} pip)
|
||||
target_link_libraries(${COMPONENT_TARGET} pip)
|
||||
|
||||
34
main.cpp
34
main.cpp
@@ -1,7 +1,33 @@
|
||||
#include "pip.h"
|
||||
|
||||
class A: public PIObject {
|
||||
PIOBJECT(A)
|
||||
public:
|
||||
A() {}
|
||||
EVENT_HANDLER1(void, handlerA1, PIString, s) {piCout << "handlerA1 s" << s;}
|
||||
EVENT_HANDLER1(void, handlerA1, float, f) {piCout << "handlerA1 f" << f;}
|
||||
//uchar _[0x10];
|
||||
};
|
||||
|
||||
|
||||
class B: public PIObject {
|
||||
PIOBJECT(B)
|
||||
public:
|
||||
B() {}
|
||||
EVENT1(eventB1, float, f)
|
||||
EVENT1(eventB2, PIString, s)
|
||||
//uchar _[0x20];
|
||||
};
|
||||
|
||||
int main() {
|
||||
A a;
|
||||
B b;
|
||||
CONNECTU(&b, eventB1, &a, handlerA1)
|
||||
CONNECTU(&b, eventB2, &a, handlerA1)
|
||||
a.dump();
|
||||
b.dump();
|
||||
b.eventB1(0.33);
|
||||
b.eventB2("str");
|
||||
/*PIByteArray msg = PIByteArray::fromHex("0110f0f00001020001");
|
||||
PIByteArray src = PIByteArray::fromHex("836f");
|
||||
ushort s; memcpy(&s, src.data(), 2);
|
||||
@@ -9,9 +35,9 @@ int main() {
|
||||
CRC_16 crc = CRC_16(0x8005, 0xFFFF, 0xFFFF, false);
|
||||
piCout << PICoutManipulators::Hex << s;
|
||||
piCout << PICoutManipulators::Hex << crc.calculate(msg);*/
|
||||
PIIODevice * ser = PIIODevice::createFromFullPath("ser://COM3:9600:7:e:1 (wo,bwr)");
|
||||
piCout << ser << ser->constructVariant() << ser->constructFullPath();
|
||||
ser = PIIODevice::createFromVariant(ser->constructVariant());
|
||||
piCout << ser << ser->constructVariant() << ser->constructFullPath();
|
||||
//PIIODevice * ser = PIIODevice::createFromFullPath("ser://COM3:9600:7:e:1 (wo,bwr)");
|
||||
//piCout << ser << ser->constructVariant() << ser->constructFullPath();
|
||||
//ser = PIIODevice::createFromVariant(ser->constructVariant());
|
||||
//piCout << ser << ser->constructVariant() << ser->constructFullPath();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
# include "pidir.h"
|
||||
# include "piprocess.h"
|
||||
#endif
|
||||
#ifdef ESP_PLATFORM
|
||||
# include "esp_system.h"
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# include <winsock2.h>
|
||||
extern FILETIME __pi_ftjan1970;
|
||||
@@ -261,6 +264,14 @@ PIInit::PIInit() {
|
||||
sinfo->architecture = uns.machine;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
sinfo->processorsCount = chip_info.cores;
|
||||
sinfo->architecture = "Xtensa LX6";
|
||||
//printf("silicon revision %d, ", chip_info.revision);
|
||||
sinfo->OS_version = esp_get_idf_version();
|
||||
#endif
|
||||
sinfo->OS_name =
|
||||
#ifdef WINDOWS
|
||||
|
||||
@@ -30,7 +30,10 @@
|
||||
//# include <crt_externs.h>
|
||||
extern clock_serv_t __pi_mac_clock;
|
||||
#endif
|
||||
|
||||
#ifdef FREERTOS
|
||||
# include "freertos/FreeRTOS.h"
|
||||
# include "freertos/task.h"
|
||||
#endif
|
||||
|
||||
/*! \class PISystemTime
|
||||
* \brief System time
|
||||
@@ -63,8 +66,12 @@ void piUSleep(int usecs) {
|
||||
//printf("Sleep %d\n", usecs / 1000);
|
||||
if (usecs > 0) Sleep(usecs / 1000);
|
||||
#else
|
||||
# ifdef FREERTOS
|
||||
vTaskDelay(usecs / 1000 / portTICK_PERIOD_MS);
|
||||
# else
|
||||
usecs -= PISystemTests::usleep_offset_us;
|
||||
if (usecs > 0) usleep(usecs);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -243,8 +250,18 @@ PISystemTime PISystemTime::current(bool precise_but_not_system) {
|
||||
mach_timespec_t t_cur;
|
||||
clock_get_time(__pi_mac_clock, &t_cur);
|
||||
# else
|
||||
# ifdef FREERTOS
|
||||
timespec t_cur;
|
||||
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
|
||||
timespec t_cur;
|
||||
clock_gettime(0, &t_cur);
|
||||
# endif
|
||||
# endif
|
||||
return PISystemTime(t_cur.tv_sec, t_cur.tv_nsec);
|
||||
#endif
|
||||
|
||||
@@ -25,13 +25,9 @@
|
||||
|
||||
|
||||
#include "pistring.h"
|
||||
#ifdef FREERTOS
|
||||
# include "time.h"
|
||||
#else
|
||||
# include <ctime>
|
||||
# ifdef QNX
|
||||
# include <time.h>
|
||||
# endif
|
||||
#include <ctime>
|
||||
#ifdef QNX
|
||||
# include <time.h>
|
||||
#endif
|
||||
//! \brief Sleep for "msecs" milliseconds
|
||||
PIP_EXPORT void msleep(int msecs);
|
||||
|
||||
@@ -168,7 +168,11 @@ void PIIODevice::_init() {
|
||||
setOptions(0);
|
||||
setReopenEnabled(true);
|
||||
setReopenTimeout(1000);
|
||||
#ifdef FREERTOS
|
||||
setThreadedReadBufferSize(512);
|
||||
#else
|
||||
setThreadedReadBufferSize(4096);
|
||||
#endif
|
||||
timer.setName("__S__reopen_timer");
|
||||
write_thread.setName("__S__write_thread");
|
||||
CONNECT2(void, void * , int, &timer, tickEvent, this, check_start);
|
||||
@@ -251,7 +255,7 @@ void PIIODevice::run() {
|
||||
return;
|
||||
}
|
||||
if (!thread_started_) {
|
||||
piMSleep(5);
|
||||
piMSleep(10);
|
||||
//cout << "not started\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
#define PIP_VERSION_MAJOR 1
|
||||
#define PIP_VERSION_MINOR 9
|
||||
#define PIP_VERSION_REVISION 0
|
||||
#define PIP_VERSION_SUFFIX "_alpha"
|
||||
#define PIP_VERSION_SUFFIX "_alpha_2"
|
||||
|
||||
#endif // PIVERSION_H
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
#include "pisysteminfo.h"
|
||||
#include "piincludes_p.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
# include "esp_heap_caps.h"
|
||||
# include "esp_system.h"
|
||||
# include "esp_spi_flash.h"
|
||||
#endif
|
||||
|
||||
|
||||
PISystemInfo::PISystemInfo() {
|
||||
processorsCount = 1;
|
||||
@@ -31,6 +37,36 @@ PISystemInfo * PISystemInfo::instance() {
|
||||
}
|
||||
|
||||
|
||||
ullong PISystemInfo::totalRAM() {
|
||||
#ifdef ESP_PLATFORM
|
||||
multi_heap_info_t heap_info;
|
||||
memset(&heap_info, 0, sizeof(multi_heap_info_t));
|
||||
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
|
||||
return heap_info.total_allocated_bytes + heap_info.total_free_bytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ullong PISystemInfo::freeRAM() {
|
||||
#ifdef ESP_PLATFORM
|
||||
multi_heap_info_t heap_info;
|
||||
memset(&heap_info, 0, sizeof(multi_heap_info_t));
|
||||
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
|
||||
return heap_info.total_free_bytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ullong PISystemInfo::usedRAM() {
|
||||
#ifdef ESP_PLATFORM
|
||||
multi_heap_info_t heap_info;
|
||||
memset(&heap_info, 0, sizeof(multi_heap_info_t));
|
||||
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
|
||||
return heap_info.total_allocated_bytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PIStringList PISystemInfo::mountRoots() {
|
||||
PIStringList ret;
|
||||
#ifdef WINDOWS
|
||||
@@ -178,6 +214,14 @@ PIVector<PISystemInfo::MountInfo> PISystemInfo::mountInfo() {
|
||||
}
|
||||
# else
|
||||
# endif
|
||||
#endif
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
m.device = ((chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded SPI flash" : "external SPI flash");
|
||||
m.space_all = spi_flash_get_chip_size();
|
||||
m.mount_point = "/";
|
||||
ret << m;
|
||||
#endif
|
||||
cache = ret;
|
||||
return ret;
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
};
|
||||
|
||||
PIString ifconfigPath, execCommand, hostname, user, OS_name, OS_version, architecture;
|
||||
ullong RAM_total, RAM_free;
|
||||
PIDateTime execDateTime;
|
||||
int processorsCount;
|
||||
|
||||
@@ -45,6 +46,9 @@ public:
|
||||
static PIVector<MountInfo> mountInfo();
|
||||
|
||||
static PISystemInfo * instance();
|
||||
static ullong totalRAM();
|
||||
static ullong freeRAM();
|
||||
static ullong usedRAM();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -40,6 +40,12 @@ __THREAD_FUNC_RET__ thread_function_once(void * t) {PIThread::__thread_func_once
|
||||
#define REGISTER_THREAD(t) __PIThreadCollection::instance()->registerThread(t)
|
||||
#define UNREGISTER_THREAD(t) __PIThreadCollection::instance()->unregisterThread(t)
|
||||
|
||||
#ifdef FREERTOS
|
||||
# define PTHREAD_MIN_MSLEEP 10.
|
||||
#else
|
||||
# define PTHREAD_MIN_MSLEEP 1.
|
||||
#endif
|
||||
|
||||
/*! \class PIThread
|
||||
* \brief Thread class
|
||||
* \details This class allow you exec your code in separate thread.
|
||||
@@ -286,7 +292,7 @@ void PIThread::terminate() {
|
||||
PIINTROSPECTION_UNREGISTER_THREAD(tid());
|
||||
terminating = running_ = false;
|
||||
tid_ = -1;
|
||||
//piCout << "terminate" << thread;
|
||||
//piCout << "terminate" << PRIVATE->thread;
|
||||
#ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
pthread_kill(PRIVATE->thread, SIGTERM);
|
||||
@@ -423,7 +429,7 @@ void PIThread::__thread_func__(void * t) {
|
||||
ct.tmr_.reset();
|
||||
double sl(0.);
|
||||
while (1) {
|
||||
sl = piMind(ct.delay_ - ct.tmr_.elapsed_m(), 2.);
|
||||
sl = piMind(ct.delay_ - ct.tmr_.elapsed_m(), PTHREAD_MIN_MSLEEP);
|
||||
#ifdef WINDOWS
|
||||
/*if (sl <= 1. && sl >= 0.) {
|
||||
piMSleep(1.);
|
||||
@@ -431,10 +437,9 @@ void PIThread::__thread_func__(void * t) {
|
||||
}*/
|
||||
#endif
|
||||
//printf("%f %f %f\n", double(ct.delay_), ct.tmr_.elapsed_m(), sl);
|
||||
if (ct.terminating) break;
|
||||
if (sl <= 0.) break;
|
||||
piMSleep(sl);
|
||||
if (ct.terminating)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -511,3 +516,4 @@ void PIThread::__thread_func_once__(void * t) {
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user