Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-pico
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-pico
Commits
af8b548e
Unverified
Commit
af8b548e
authored
May 16, 2021
by
Earle F. Philhower, III
Committed by
GitHub
May 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add time support (time, gettimeofday, etc.) (#138)
parent
0550fe75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
5 deletions
+48
-5
cores/rp2040/main.cpp
cores/rp2040/main.cpp
+20
-5
libraries/rp2040/examples/Time/Time.ino
libraries/rp2040/examples/Time/Time.ino
+28
-0
No files found.
cores/rp2040/main.cpp
View file @
af8b548e
...
...
@@ -149,12 +149,27 @@ extern "C" int _getpid (void) {
return
-
1
;
}
struct
timeval
;
extern
"C"
int
_gettimeofday
(
struct
timeval
*
ptimeval
,
void
*
ptimezone
)
{
errno
=
ENOSYS
;
return
-
1
;
static
int64_t
__timedelta_us
=
0.0
;
extern
"C"
int
_gettimeofday
(
struct
timeval
*
tv
,
void
*
tz
)
{
uint64_t
now_us
=
to_us_since_boot
(
get_absolute_time
())
+
__timedelta_us
;
if
(
tv
)
{
tv
->
tv_sec
=
now_us
/
1000000L
;
tv
->
tv_usec
=
now_us
%
1000000L
;
}
return
0
;
}
extern
"C"
int
settimeofday
(
const
struct
timeval
*
tv
,
const
struct
timezone
*
tz
)
{
uint64_t
now_us
=
to_us_since_boot
(
get_absolute_time
());
if
(
tv
)
{
uint64_t
newnow_us
;
newnow_us
=
tv
->
tv_sec
*
1000000L
;
newnow_us
+=
tv
->
tv_usec
;
__timedelta_us
=
newnow_us
-
now_us
;
}
return
0
;
}
extern
"C"
int
_isatty
(
int
file
)
{
...
...
libraries/rp2040/examples/Time/Time.ino
0 → 100644
View file @
af8b548e
/* Simple demonstration of setting and printing the current time */
/* The initial time will need to come from an RTC, NTP, or user */
/* Released to the public domain by Earle F. Philhower, III <earlephilhower@yahoo.com> */
#include <time.h>
#include <sys/time.h>
void
setup
()
{
Serial
.
begin
(
115200
);
delay
(
5000
);
struct
timeval
tv
;
tv
.
tv_sec
=
1611198855
;
// Jan 21, 2021 3:14:15AM ...RPi Pico Release;
tv
.
tv_usec
=
0
;
settimeofday
(
&
tv
,
nullptr
);
}
void
loop
()
{
time_t
now
;
struct
tm
*
info
;
char
buff
[
80
];
time
(
&
now
);
strftime
(
buff
,
sizeof
(
buff
),
"%c"
,
localtime
(
&
now
));
Serial
.
println
(
buff
);
delay
(
1000
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment