File tree Expand file tree Collapse file tree 6 files changed +96
-17
lines changed Expand file tree Collapse file tree 6 files changed +96
-17
lines changed Original file line number Diff line number Diff line change 31
31
#define pthread_barrier_t zap_pthread_barrier_t
32
32
#define pthread_barrierattr_t zap_pthread_barrierattr_t
33
33
#define pthread_attr_t zap_pthread_attr_t
34
+ #define clockid_t zap_clockid_t
35
+ #define sched_param zap_sched_param
34
36
35
37
/* Condition variables */
36
38
#define pthread_cond_init (...) zap_pthread_cond_init(__VA_ARGS__)
99
101
#define sleep (...) zap_sleep(__VA_ARGS__)
100
102
#define usleep (...) zap_usleep(__VA_ARGS__)
101
103
104
+ /* Clock */
105
+ #define clock_gettime (...) zap_clock_gettime(__VA_ARGS__)
106
+ #define clock_settime (...) zap_clock_settime(__VA_ARGS__)
107
+
102
108
#endif /* CONFIG_ARCH_POSIX */
103
109
104
110
#endif
Original file line number Diff line number Diff line change 8
8
#define __PTHREAD_H__
9
9
10
10
#include <kernel.h>
11
- #ifdef CONFIG_NEWLIB_LIBC
12
11
#include <time.h>
13
- #else
14
- /* This should probably live somewhere else but Zephyr doesn't
15
- * currently have a stdc layer to provide it
16
- */
17
- struct timespec {
18
- s32_t tv_sec ;
19
- s32_t tv_nsec ;
20
- };
21
- #endif /* CONFIG_NEWLIB_LIBC */
22
-
23
12
#include "sys/types.h"
24
13
#include "posix_sched.h"
25
14
#include "unistd.h"
@@ -63,11 +52,6 @@ struct posix_thread {
63
52
#define PTHREAD_CANCEL_ENABLE (0 << _PTHREAD_CANCEL_POS)
64
53
#define PTHREAD_CANCEL_DISABLE (1 << _PTHREAD_CANCEL_POS)
65
54
66
- static inline s32_t _ts_to_ms (const struct timespec * to )
67
- {
68
- return (to -> tv_sec * 1000 ) + (to -> tv_nsec / 1000000 );
69
- }
70
-
71
55
/**
72
56
* @brief Declare a pthread condition variable
73
57
*
Original file line number Diff line number Diff line change 7
7
#ifndef __POSIX_TYPES_H__
8
8
#define __POSIX_TYPES_H__
9
9
10
-
11
10
#ifdef __cplusplus
12
11
extern "C" {
13
12
#endif
14
13
15
14
#include_next <sys/types.h>
16
15
17
16
#ifdef CONFIG_PTHREAD_IPC
17
+ #include <kernel.h>
18
18
19
19
/* Thread attributes */
20
20
typedef struct pthread_attr_t {
@@ -60,6 +60,9 @@ typedef struct pthread_barrierattr {
60
60
} pthread_barrierattr_t ;
61
61
62
62
/* time related attributes */
63
+ #ifndef CONFIG_NEWLIB_LIBC
64
+ typedef u32_t clockid_t ;
65
+ #endif /*CONFIG_NEWLIB_LIBC */
63
66
typedef unsigned long useconds_t ;
64
67
65
68
#endif /* CONFIG_PTHREAD_IPC */
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2018 Intel Corporation
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ #ifndef __POSIX_TIME_H__
7
+ #define __POSIX_TIME_H__
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ #ifdef CONFIG_NEWLIB_LIBC
14
+ #include_next <time.h>
15
+ #else
16
+ struct timespec {
17
+ s32_t tv_sec ;
18
+ s32_t tv_nsec ;
19
+ };
20
+ #endif /* CONFIG_NEWLIB_LIBC */
21
+ #include <kernel.h>
22
+ #include <errno.h>
23
+ #include "sys/types.h"
24
+
25
+ #define CLOCK_MONOTONIC 1
26
+
27
+ static inline s32_t _ts_to_ms (const struct timespec * to )
28
+ {
29
+ return (to -> tv_sec * 1000 ) + (to -> tv_nsec / 1000000 );
30
+ }
31
+
32
+ /**
33
+ * @brief Set clock time.
34
+ *
35
+ * See IEEE 1003.1
36
+ */
37
+ static inline int clock_settime (clockid_t clock_id , const struct timespec * ts )
38
+ {
39
+ errno = ENOSYS ;
40
+ return -1 ;
41
+ }
42
+
43
+ int clock_gettime (clockid_t clock_id , struct timespec * ts );
44
+
45
+ #ifdef __cplusplus
46
+ }
47
+ #endif
48
+
49
+ #endif /* __POSIX_TIME_H__ */
Original file line number Diff line number Diff line change @@ -4,3 +4,4 @@ target_sources(kernel PRIVATE posix/pthread_mutex.c)
4
4
target_sources (kernel PRIVATE posix/pthread_barrier.c)
5
5
target_sources (kernel PRIVATE posix/pthread.c)
6
6
target_sources (kernel PRIVATE posix/pthread_sched.c)
7
+ target_sources (kernel PRIVATE posix/clock.c)
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2018 Intel Corporation
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ #include <kernel.h>
7
+ #include <time.h>
8
+ #include <errno.h>
9
+
10
+ /**
11
+ * @brief Get clock time specified by clock_id.
12
+ *
13
+ * See IEEE 1003.1
14
+ */
15
+ int clock_gettime (clockid_t clock_id , struct timespec * ts )
16
+ {
17
+ s64_t elapsed_msecs , elapsed_secs ;
18
+ s64_t elapsed_nsec , elapsed_cycles ;
19
+
20
+ if (clock_id != CLOCK_MONOTONIC ) {
21
+ errno = EINVAL ;
22
+ return -1 ;
23
+ }
24
+
25
+ elapsed_msecs = k_uptime_get ();
26
+ elapsed_secs = elapsed_msecs / MSEC_PER_SEC ;
27
+
28
+ elapsed_cycles = (s64_t ) (k_cycle_get_32 () %
29
+ sys_clock_hw_cycles_per_sec );
30
+ elapsed_nsec = (s64_t ) ((elapsed_cycles * NSEC_PER_SEC ) /
31
+ sys_clock_hw_cycles_per_sec );
32
+
33
+ ts -> tv_sec = (s32_t ) elapsed_secs ;
34
+ ts -> tv_nsec = (s32_t ) elapsed_nsec ;
35
+ return 0 ;
36
+ }
You can’t perform that action at this time.
0 commit comments