From 28533454c0c09d2c409efb33026a2f06a32f4247 Mon Sep 17 00:00:00 2001 From: Forsworns <378974295@qq.com> Date: Fri, 14 Jan 2022 11:22:29 +0800 Subject: [PATCH] successfully make --- .../control_app/s7_demo/s7_demo.cpp | 4 +- .../control/plc/interoperability/s7/Makefile | 2 +- .../plc/interoperability/s7/s7_text.cpp | 4 +- .../plc/interoperability/s7/snap_msgsock.h | 1 + .../plc/interoperability/s7/snap_threads.cpp | 7 +- .../plc/interoperability/s7/snap_threads.h | 73 +++++++----------- .../user_api/posix_support/include/pthread.h | 1 - Ubiquitous/XiUOS/lib/newlib/fs_syscalls.c | 1 - .../ethernet/LwIP/include/lwip/errno.h | 74 ++++++++++--------- 9 files changed, 70 insertions(+), 97 deletions(-) diff --git a/APP_Framework/Applications/control_app/s7_demo/s7_demo.cpp b/APP_Framework/Applications/control_app/s7_demo/s7_demo.cpp index 3c2b05eaa..6f1fcafae 100644 --- a/APP_Framework/Applications/control_app/s7_demo/s7_demo.cpp +++ b/APP_Framework/Applications/control_app/s7_demo/s7_demo.cpp @@ -31,7 +31,7 @@ static void CliDisconnect() void PerformTasks() { - while(true){ + while(1){ if(bWrite){ memset(Buffer, 0, sizeof(Buffer)); Buffer[0] = 0x01; @@ -70,5 +70,3 @@ void s7_demo() // Deletion Cli_Destroy(Client); } -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), - S7Demo, s7_demo, Siemens Snap7 Demo); diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/Makefile b/APP_Framework/Framework/control/plc/interoperability/s7/Makefile index cc36d59ae..091ffae50 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/Makefile +++ b/APP_Framework/Framework/control/plc/interoperability/s7/Makefile @@ -1,3 +1,3 @@ -SRC_FILES := s7_client.cpp s7_isotcp.cpp s7_micro_client.cpp s7_peer.cpp s7_text.cpp snap_msgsock.cpp snap_sysutils.cpp snap_threads.cpp snap_libmain.cpp +SRC_FILES := s7_client.cpp s7_isotcp.cpp s7_micro_client.cpp s7_peer.cpp s7_text.cpp snap_msgsock.cpp snap_sysutils.cpp snap_threads.cpp snap7_libmain.cpp include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/s7_text.cpp b/APP_Framework/Framework/control/plc/interoperability/s7/s7_text.cpp index 73f0664c5..f90fa4791 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/s7_text.cpp +++ b/APP_Framework/Framework/control/plc/interoperability/s7/s7_text.cpp @@ -25,7 +25,7 @@ |=============================================================================*/ #include "s7_text.h" //--------------------------------------------------------------------------- -static char* itoa(int value, char* result, int base) { +static char* s7_itoa(int value, char* result, int base) { // check that the base if valid if (base < 2 || base > 36){ *result = '\0'; return result; @@ -55,7 +55,7 @@ char* NumToString(int Value, int Base, int Len, char* Result) { char CNumber[64]; char Pad[65] = "0000000000000000000000000000000000000000000000000000000000000000"; - itoa(Value, CNumber, Base); + s7_itoa(Value, CNumber, Base); if (Len > 0) { diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h b/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h index faf9a79de..9253cb0c8 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h +++ b/APP_Framework/Framework/control/plc/interoperability/s7/snap_msgsock.h @@ -28,6 +28,7 @@ //--------------------------------------------------------------------------- #include "snap_platform.h" #include "snap_sysutils.h" +#include "errno.h" //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.cpp b/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.cpp index 7832aca53..5c6c40ac5 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.cpp +++ b/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.cpp @@ -32,8 +32,6 @@ void* ThreadProc(void* param) PSnapThread Thread; // Unix but not Solaris int last_type, last_state; - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &last_type); - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &last_state); Thread = PSnapThread(param); if (!Thread->Terminated) @@ -71,10 +69,7 @@ TSnapThread::~TSnapThread() //--------------------------------------------------------------------------- void TSnapThread::ThreadCreate() { - pthread_attr_t a; - pthread_attr_init(&a); - pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED); - pthread_create(&th, &a, &ThreadProc, this); + pthread_create(&th, NULL, &ThreadProc, this); } //--------------------------------------------------------------------------- void TSnapThread::Start() diff --git a/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.h b/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.h index 34545485d..1f149bd41 100644 --- a/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.h +++ b/APP_Framework/Framework/control/plc/interoperability/s7/snap_threads.h @@ -28,6 +28,8 @@ //--------------------------------------------------------------------------- #include "snap_platform.h" #include "snap_sysutils.h" +#include "pthread.h" +#include "mqueue.h" //--------------------------------------------------------------------------- class TSnapCriticalSection @@ -85,52 +87,35 @@ const longword WAIT_FAILED = 0xFFFFFFFFL; class TSnapEvent { private: - pthread_cond_t CVariable; - pthread_mutex_t Mutex; - bool AutoReset; - bool State; + mqd_t mq; // use message queue to simulate conditional variable public: - TSnapEvent(bool ManualReset) + TSnapEvent(bool _ManualReset) { - AutoReset = !ManualReset; - if (pthread_cond_init(&CVariable, 0) == 0) - pthread_mutex_init(&Mutex, 0); - State = false; + mq_close(mq); + mq = mq_open("mq event", 0); } ~TSnapEvent() { - pthread_cond_destroy(&CVariable); - pthread_mutex_destroy(&Mutex); + mq_close(mq); }; void Set() { - pthread_mutex_lock(&Mutex); - State = true; - if (AutoReset) - pthread_cond_signal(&CVariable); - else - pthread_cond_broadcast(&CVariable); - pthread_mutex_unlock(&Mutex); + mq_send(mq, "emit", 4, 0); }; void Reset() { - pthread_mutex_lock(&Mutex); - State = false; - pthread_mutex_unlock(&Mutex); } longword WaitForever() { - pthread_mutex_lock(&Mutex); - while (!State) // <-- to avoid spurious wakeups - pthread_cond_wait(&CVariable, &Mutex); - if (AutoReset) - State = false; - pthread_mutex_unlock(&Mutex); + // the mq must ensure the receive is blocking and atomic + char msg[10] = {0}; + unsigned msg_prio; + mq_receive(mq, msg, 0, &msg_prio); return WAIT_OBJECT_0; }; @@ -142,27 +127,19 @@ public: if (Timeout > 0) { - pthread_mutex_lock(&Mutex); - if (!State) - { - timespec ts; - timeval tv; - gettimeofday(&tv, NULL); - uint64_t nsecs = ((uint64_t) tv.tv_sec) * 1000000000 + - Timeout * 1000000 + - ((uint64_t) tv.tv_usec) * 1000; - ts.tv_sec = nsecs / 1000000000; - ts.tv_nsec = (nsecs - ((uint64_t) ts.tv_sec) * 1000000000); - do { - Result = pthread_cond_timedwait(&CVariable, &Mutex, &ts); - if (Result == ETIMEDOUT) - Result = WAIT_TIMEOUT; - } while (Result == 0 && !State); - } - else - if (AutoReset) // take the ownership - State = false; - pthread_mutex_unlock(&Mutex); + timespec ts; + uint32_t msec = PrivGetTickTime(); + uint64_t nsecs = msec * 1000000 + + Timeout * 1000000; + ts.tv_sec = nsecs / 1000000000; + ts.tv_nsec = (nsecs - ((uint64_t) ts.tv_sec) * 1000000000); + do { + char msg[10] = {0}; + unsigned msg_prio; + Result = mq_timedreceive(mq, msg, 0, &msg_prio, &ts); + if (Result == -ETIMEOUT) + Result = WAIT_TIMEOUT; + } while (Result == 0); return Result; } else // Timeout<0 diff --git a/APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/pthread.h b/APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/pthread.h index 9f65a971d..fd2254b7c 100644 --- a/APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/pthread.h +++ b/APP_Framework/Framework/transform_layer/xiuos/user_api/posix_support/include/pthread.h @@ -21,7 +21,6 @@ #ifndef PTHREAD_H #define PTHREAD_H - #ifdef __cplusplus extern "C" { #endif diff --git a/Ubiquitous/XiUOS/lib/newlib/fs_syscalls.c b/Ubiquitous/XiUOS/lib/newlib/fs_syscalls.c index 4a02ab97d..f104c964d 100644 --- a/Ubiquitous/XiUOS/lib/newlib/fs_syscalls.c +++ b/Ubiquitous/XiUOS/lib/newlib/fs_syscalls.c @@ -27,7 +27,6 @@ Modification: Use file system functions *************************************************/ #include -#include #include #include diff --git a/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/errno.h b/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/errno.h index 17fadeee4..f16cbb19b 100644 --- a/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/errno.h +++ b/Ubiquitous/XiUOS/resources/ethernet/LwIP/include/lwip/errno.h @@ -45,6 +45,10 @@ extern "C" { #ifdef LWIP_PROVIDE_ERRNO +# ifndef ENOTSUP +# define ENOTSUP EOPNOTSUPP +# endif + #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ @@ -79,15 +83,15 @@ extern "C" { #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ -// #define EDEADLK 35 /* Resource deadlock would occur */ -// #define ENAMETOOLONG 36 /* File name too long */ -// #define ENOLCK 37 /* No record locks available */ -// #define ENOSYS 38 /* Function not implemented */ -// #define ENOTEMPTY 39 /* Directory not empty */ -// #define ELOOP 40 /* Too many symbolic links encountered */ +#define EDEADLK 35 /* Resource deadlock would occur */ +#define ENAMETOOLONG 36 /* File name too long */ +#define ENOLCK 37 /* No record locks available */ +#define ENOSYS 38 /* Function not implemented */ +#define ENOTEMPTY 39 /* Directory not empty */ +#define ELOOP 40 /* Too many symbolic links encountered */ #define EWOULDBLOCK EAGAIN /* Operation would block */ -// #define ENOMSG 42 /* No message of desired type */ -// #define EIDRM 43 /* Identifier removed */ +#define ENOMSG 42 /* No message of desired type */ +#define EIDRM 43 /* Identifier removed */ #define ECHRNG 44 /* Channel number out of range */ #define EL2NSYNC 45 /* Level 2 not synchronized */ #define EL3HLT 46 /* Level 3 halted */ @@ -118,10 +122,10 @@ extern "C" { #define ESRMNT 69 /* Srmount error */ #define ECOMM 70 /* Communication error on send */ #define EPROTO 71 /* Protocol error */ -// #define EMULTIHOP 72 /* Multihop attempted */ +#define EMULTIHOP 72 /* Multihop attempted */ #define EDOTDOT 73 /* RFS specific error */ -// #define EBADMSG 74 /* Not a data message */ -// #define EOVERFLOW 75 /* Value too large for defined data type */ +#define EBADMSG 74 /* Not a data message */ +#define EOVERFLOW 75 /* Value too large for defined data type */ #define ENOTUNIQ 76 /* Name not unique on network */ #define EBADFD 77 /* File descriptor in bad state */ #define EREMCHG 78 /* Remote address changed */ @@ -130,45 +134,45 @@ extern "C" { #define ELIBSCN 81 /* .lib section in a.out corrupted */ #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ #define ELIBEXEC 83 /* Cannot exec a shared library directly */ -// #define EILSEQ 84 /* Illegal byte sequence */ +#define EILSEQ 84 /* Illegal byte sequence */ #define ERESTART 85 /* Interrupted system call should be restarted */ #define ESTRPIPE 86 /* Streams pipe error */ #define EUSERS 87 /* Too many users */ -// #define ENOTSOCK 88 /* Socket operation on non-socket */ -// #define EDESTADDRREQ 89 /* Destination address required */ -// #define EMSGSIZE 90 /* Message too long */ -// #define EPROTOTYPE 91 /* Protocol wrong type for socket */ -// #define ENOPROTOOPT 92 /* Protocol not available */ -// #define EPROTONOSUPPORT 93 /* Protocol not supported */ +#define ENOTSOCK 88 /* Socket operation on non-socket */ +#define EDESTADDRREQ 89 /* Destination address required */ +#define EMSGSIZE 90 /* Message too long */ +#define EPROTOTYPE 91 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 92 /* Protocol not available */ +#define EPROTONOSUPPORT 93 /* Protocol not supported */ #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ #define EPFNOSUPPORT 96 /* Protocol family not supported */ -// #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ -// #define EADDRINUSE 98 /* Address already in use */ -// #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ -// #define ENETDOWN 100 /* Network is down */ -// #define ENETUNREACH 101 /* Network is unreachable */ -// #define ENETRESET 102 /* Network dropped connection because of reset */ -// #define ECONNABORTED 103 /* Software caused connection abort */ +#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ +#define EADDRINUSE 98 /* Address already in use */ +#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ +#define ENETDOWN 100 /* Network is down */ +#define ENETUNREACH 101 /* Network is unreachable */ +#define ENETRESET 102 /* Network dropped connection because of reset */ +#define ECONNABORTED 103 /* Software caused connection abort */ #define ECONNRESET 104 /* Connection reset by peer */ #define ENOBUFS 105 /* No buffer space available */ -// #define EISCONN 106 /* Transport endpoint is already connected */ -// #define ENOTCONN 107 /* Transport endpoint is not connected */ +#define EISCONN 106 /* Transport endpoint is already connected */ +#define ENOTCONN 107 /* Transport endpoint is not connected */ #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ -// #define ETOOMANYREFS 109 /* Too many references: cannot splice */ -// #define ETIMEDOUT 110 /* Connection timed out */ +#define ETOOMANYREFS 109 /* Too many references: cannot splice */ +#define ETIMEDOUT 110 /* Connection timed out */ #define ECONNREFUSED 111 /* Connection refused */ -// #define EHOSTDOWN 112 /* Host is down */ -// #define EHOSTUNREACH 113 /* No route to host */ -// #define EALREADY 114 /* Operation already in progress */ -// #define EINPROGRESS 115 /* Operation now in progress */ -// #define ESTALE 116 /* Stale NFS file handle */ +#define EHOSTDOWN 112 /* Host is down */ +#define EHOSTUNREACH 113 /* No route to host */ +#define EALREADY 114 /* Operation already in progress */ +#define EINPROGRESS 115 /* Operation now in progress */ +#define ESTALE 116 /* Stale NFS file handle */ #define EUCLEAN 117 /* Structure needs cleaning */ #define ENOTNAM 118 /* Not a XENIX named type file */ #define ENAVAIL 119 /* No XENIX semaphores available */ #define EISNAM 120 /* Is a named type file */ #define EREMOTEIO 121 /* Remote I/O error */ -// #define EDQUOT 122 /* Quota exceeded */ +#define EDQUOT 122 /* Quota exceeded */ #define ENOMEDIUM 123 /* No medium found */ #define EMEDIUMTYPE 124 /* Wrong medium type */