From 702103a2037c7958f20b668aa138e4975a802c02 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 16 Dec 2020 15:25:08 +0800 Subject: prepare for usleep --- components/libc/compilers/armlibc/sys/types.h | 14 ++++++++------ components/libc/compilers/armlibc/sys/unistd.h | 5 ++++- components/libc/compilers/dlib/sys/types.h | 13 +++++++------ components/libc/compilers/dlib/sys/unistd.h | 5 +++++ components/libc/time/posix_sleep.c | 8 ++++++-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/components/libc/compilers/armlibc/sys/types.h b/components/libc/compilers/armlibc/sys/types.h index 2aad77c99d..78fee1bb99 100644 --- a/components/libc/compilers/armlibc/sys/types.h +++ b/components/libc/compilers/armlibc/sys/types.h @@ -5,20 +5,22 @@ * * Change Logs: * Date Author Notes - * 2020-09-05 Meco Man fix bugs + * 2020-09-05 Meco Man fix bugs + * 2020-12-16 Meco Man add useconds_t */ #ifndef __TYPES_H__ #define __TYPES_H__ #include -typedef int32_t clockid_t; -typedef int32_t key_t; /* Used for interprocess communication. */ -typedef int32_t pid_t; /* Used for process IDs and process group IDs. */ +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int32_t pid_t; /* Used for process IDs and process group IDs. */ #ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ #else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ #endif +typedef unsigned long useconds_t; /* microseconds (unsigned) */ #endif diff --git a/components/libc/compilers/armlibc/sys/unistd.h b/components/libc/compilers/armlibc/sys/unistd.h index 549771e8f4..73a73a267e 100644 --- a/components/libc/compilers/armlibc/sys/unistd.h +++ b/components/libc/compilers/armlibc/sys/unistd.h @@ -5,11 +5,13 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add usleep */ #ifndef _SYS_UNISTD_H #define _SYS_UNISTD_H -#include +#include +#include "types.h" #ifdef RT_USING_DFS @@ -69,5 +71,6 @@ int isatty (int fd); char * ttyname (int desc); unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); #endif /* _SYS_UNISTD_H */ diff --git a/components/libc/compilers/dlib/sys/types.h b/components/libc/compilers/dlib/sys/types.h index 001ace4dd2..7dbeddcaa9 100644 --- a/components/libc/compilers/dlib/sys/types.h +++ b/components/libc/compilers/dlib/sys/types.h @@ -5,20 +5,21 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add useconds_t */ #ifndef __TYPES_H__ #define __TYPES_H__ #include -#include -typedef rt_int32_t clockid_t; -typedef rt_int32_t key_t; /* Used for interprocess communication. */ -typedef rt_int32_t pid_t; /* Used for process IDs and process group IDs. */ +typedef int32_t clockid_t; +typedef int32_t key_t; /* Used for interprocess communication. */ +typedef int32_t pid_t; /* Used for process IDs and process group IDs. */ #ifndef ARCH_CPU_64BIT -typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */ #else -typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ +typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */ #endif +typedef unsigned long useconds_t; /* microseconds (unsigned) */ #endif diff --git a/components/libc/compilers/dlib/sys/unistd.h b/components/libc/compilers/dlib/sys/unistd.h index 982a29135d..6d99cd6c55 100644 --- a/components/libc/compilers/dlib/sys/unistd.h +++ b/components/libc/compilers/dlib/sys/unistd.h @@ -5,10 +5,14 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add usleep */ #ifndef _SYS_UNISTD_H #define _SYS_UNISTD_H +#include +#include "types.h" + #ifdef RT_USING_DFS #define STDIN_FILENO 0 /* standard input file descriptor */ @@ -41,5 +45,6 @@ int isatty (int fd); char * ttyname (int desc); unsigned int sleep(unsigned int seconds); +int usleep(useconds_t usec); #endif /* _SYS_UNISTD_H */ diff --git a/components/libc/time/posix_sleep.c b/components/libc/time/posix_sleep.c index f21b0a7994..d45b3b945f 100644 --- a/components/libc/time/posix_sleep.c +++ b/components/libc/time/posix_sleep.c @@ -5,10 +5,9 @@ * * Change Logs: * Date Author Notes + * 2020-12-16 Meco Man add usleep */ -#include #include - #include unsigned int sleep(unsigned int seconds) @@ -21,3 +20,8 @@ unsigned int sleep(unsigned int seconds) return seconds - delta_tick/RT_TICK_PER_SECOND; } + +int usleep(useconds_t usec) +{ + +} -- cgit v1.3.1 From 9d004a2892394436e3a07a5dfb3e0fa9e8076433 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 16 Dec 2020 15:34:41 +0800 Subject: 实现 usleep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/time/posix_sleep.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/libc/time/posix_sleep.c b/components/libc/time/posix_sleep.c index d45b3b945f..e50bda7d4a 100644 --- a/components/libc/time/posix_sleep.c +++ b/components/libc/time/posix_sleep.c @@ -8,6 +8,7 @@ * 2020-12-16 Meco Man add usleep */ #include +#include #include unsigned int sleep(unsigned int seconds) @@ -23,5 +24,7 @@ unsigned int sleep(unsigned int seconds) int usleep(useconds_t usec) { - + rt_thread_mdelay(usec / 1000u); + rt_hw_us_delay(usec % 1000u); + return 0; } -- cgit v1.3.1 From e5b10628ee001543c6ee8d458b1dde5d4941953c Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Wed, 16 Dec 2020 16:05:43 +0800 Subject: update --- components/libc/compilers/common/sys/time.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 952dbf32a5..06add3ba91 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -36,8 +36,7 @@ struct timeval { }; #endif /* _TIMEVAL_DEFINED */ -#ifndef _TIMESPEC -#define _TIMESPEC +#ifndef __GNUC__ struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ -- cgit v1.3.1 From ab754255407c2af40d6cea61dae1a314947d0886 Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Thu, 17 Dec 2020 11:32:10 +0800 Subject: update --- components/libc/compilers/common/sys/time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 06add3ba91..28a977c1f9 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -36,7 +36,7 @@ struct timeval { }; #endif /* _TIMEVAL_DEFINED */ -#ifndef __GNUC__ +#if !defined __GNUC__ && !defined __ICCARM__ struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* and nanoseconds */ -- cgit v1.3.1