Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
24411d34
Commit
24411d34
authored
Mar 11, 2015
by
funshine
Browse files
fix tmr.time()
parent
e9035e75
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/tmr.c
View file @
24411d34
...
@@ -148,24 +148,30 @@ static int tmr_wdclr( lua_State* L )
...
@@ -148,24 +148,30 @@ static int tmr_wdclr( lua_State* L )
}
}
static
os_timer_t
rtc_timer_updator
;
static
os_timer_t
rtc_timer_updator
;
static
uint
64
_t
cur_count
=
0
;
static
uint
32
_t
cur_count
=
0
;
static
uint
64
_t
rtc_
u
s
=
0
;
static
uint
32
_t
rtc_
10m
s
=
0
;
void
rtc_timer_update_cb
(
void
*
arg
){
void
rtc_timer_update_cb
(
void
*
arg
){
uint64_t
t
=
(
uint64_t
)
system_get_rtc_time
();
uint32_t
t
=
(
uint32_t
)
system_get_rtc_time
();
uint64_t
delta
=
(
t
>=
cur_count
)
?
(
t
-
cur_count
)
:
(
0x100000000
+
t
-
cur_count
);
uint32_t
delta
=
0
;
if
(
t
>=
cur_count
){
delta
=
t
-
cur_count
;
}
else
{
delta
=
0xFFFFFFF
-
cur_count
+
t
+
1
;
}
// uint64_t delta = (t>=cur_count)?(t - cur_count):(0x100000000 + t - cur_count);
// NODE_ERR("%x\n",t);
// NODE_ERR("%x\n",t);
cur_count
=
t
;
cur_count
=
t
;
u
nsigned
c
=
system_rtc_clock_cali_proc
();
u
int32_t
c
=
system_rtc_clock_cali_proc
();
uint
64
_t
itg
=
c
>>
12
;
uint
32
_t
itg
=
c
>>
12
;
// ~=5
uint
64
_t
dec
=
c
&
0xFFF
;
uint
32
_t
dec
=
c
&
0xFFF
;
// ~=2ff
rtc_
u
s
+=
(
delta
*
itg
+
((
delta
*
dec
)
>>
12
));
rtc_
10m
s
+=
(
delta
*
itg
+
((
delta
*
dec
)
>>
12
))
/
10000
;
// TODO: store rtc_
u
s to rtc memory.
// TODO: store rtc_
10m
s to rtc memory.
}
}
// Lua: time() , return rtc time in second
// Lua: time() , return rtc time in second
static
int
tmr_time
(
lua_State
*
L
)
static
int
tmr_time
(
lua_State
*
L
)
{
{
uint
64
_t
local
=
rtc_
u
s
;
uint
32
_t
local
=
rtc_
10m
s
;
lua_pushinteger
(
L
,
((
uint32_t
)(
local
/
100
0000
))
&
0x7FFFFFFF
);
lua_pushinteger
(
L
,
((
uint32_t
)(
local
/
100
))
&
0x7FFFFFFF
);
return
1
;
return
1
;
}
}
...
...
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