libgloss/arm clock [PATCH]
Shaun Jackman
sjackman@gmail.com
Mon Nov 28 21:32:00 GMT 2005
This patch provides clock, sleep, and usleep for libgloss/arm. Please apply.
Cheers,
Shaun
2005-11-28 Shaun Jackman <sjackman@gmail.com>
* arm/libcfunc.c (clock, sleep, usleep): New function.
* arm/syscalls.c (_clock): New function.
(_times): Call clock.
Index: arm/libcfunc.c
===================================================================
RCS file: /cvs/src/src/libgloss/arm/libcfunc.c,v
retrieving revision 1.5
diff -u -r1.5 libcfunc.c
--- arm/libcfunc.c 17 Nov 2005 18:56:41 -0000 1.5
+++ arm/libcfunc.c 28 Nov 2005 20:18:25 -0000
@@ -43,6 +43,12 @@
return 0;
}
+clock_t __attribute__((weak))
+clock (void)
+{
+ return _clock();
+}
+
int _isatty(int fildes);
int __attribute__((weak))
isatty(int fildes)
@@ -56,3 +62,26 @@
errno = ENOSYS;
return -1;
}
+
+#include <sys/types.h>
+#include <time.h>
+
+unsigned __attribute__((weak))
+sleep(unsigned seconds)
+{
+ clock_t t0 = _clock();
+ clock_t dt = seconds * CLOCKS_PER_SEC;
+
+ while (_clock() - t0 < dt);
+ return 0;
+}
+
+int __attribute__((weak))
+usleep(useconds_t useconds)
+{
+ clock_t t0 = _clock();
+ clock_t dt = useconds / (1000000/CLOCKS_PER_SEC);
+
+ while (_clock() - t0 < dt);
+ return 0;
+}
Index: arm/syscalls.c
===================================================================
RCS file: /cvs/src/src/libgloss/arm/syscalls.c,v
retrieving revision 1.7
diff -u -r1.7 syscalls.c
--- arm/syscalls.c 16 Aug 2005 18:05:35 -0000 1.7
+++ arm/syscalls.c 28 Nov 2005 20:18:25 -0000
@@ -596,8 +596,8 @@
}
/* Return a clock that ticks at 100Hz. */
-clock_t
-_times (struct tms * tp)
+clock_t
+_clock(void)
{
clock_t timeval;
@@ -606,6 +606,14 @@
#else
asm ("swi %a1; mov %0, r0" : "=r" (timeval): "i" (SWI_Clock) : "r0");
#endif
+ return timeval;
+}
+
+/* Return a clock that ticks at 100Hz. */
+clock_t
+_times (struct tms * tp)
+{
+ clock_t timeval = _clock();
if (tp)
{
More information about the Newlib
mailing list