Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
c2bd582c
Commit
c2bd582c
authored
Feb 26, 2016
by
Johny Mattsson
Browse files
Merge pull request #1083 from dnc40085/dev_tmr_lua_state_fix
Fix coroutine incompatibility in tmr module
parents
88369a5b
8e886122
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/tmr.c
View file @
c2bd582c
...
...
@@ -60,11 +60,8 @@ tmr.softwd(int)
#define TIMER_MODE_AUTO 1
#define TIMER_IDLE_FLAG (1<<7)
//in fact lua_State is constant, it's pointless to pass it around
//but hey, whatever, I'll just pass it, still we waste 28B here
typedef
struct
{
os_timer_t
os
;
lua_State
*
L
;
sint32_t
lua_ref
;
uint32_t
interval
;
uint8_t
mode
;
...
...
@@ -76,24 +73,26 @@ static union {
uint64_t
block
;
uint32_t
part
[
2
];
}
rtc_time
;
static
sint32_t
soft_watchdog
=
-
1
;
static
timer_struct_t
alarm_timers
[
NUM_TMR
];
static
os_timer_t
rtc_timer
;
static
void
alarm_timer_common
(
void
*
arg
){
timer_t
tmr
=
&
alarm_timers
[(
uint32_t
)
arg
];
if
(
tmr
->
lua_ref
==
LUA_NOREF
||
tmr
->
L
==
NULL
)
lua_State
*
L
=
lua_getstate
();
if
(
tmr
->
lua_ref
==
LUA_NOREF
)
return
;
lua_rawgeti
(
tmr
->
L
,
LUA_REGISTRYINDEX
,
tmr
->
lua_ref
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
tmr
->
lua_ref
);
//if the timer was set to single run we clean up after it
if
(
tmr
->
mode
==
TIMER_MODE_SINGLE
){
luaL_unref
(
tmr
->
L
,
LUA_REGISTRYINDEX
,
tmr
->
lua_ref
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
tmr
->
lua_ref
);
tmr
->
lua_ref
=
LUA_NOREF
;
tmr
->
mode
=
TIMER_MODE_OFF
;
}
else
if
(
tmr
->
mode
==
TIMER_MODE_SEMI
){
tmr
->
mode
|=
TIMER_IDLE_FLAG
;
}
lua_call
(
tmr
->
L
,
0
,
0
);
lua_call
(
L
,
0
,
0
);
}
// Lua: tmr.delay( us )
...
...
@@ -145,7 +144,6 @@ static int tmr_register(lua_State* L){
tmr
->
lua_ref
=
ref
;
tmr
->
mode
=
mode
|
TIMER_IDLE_FLAG
;
tmr
->
interval
=
interval
;
tmr
->
L
=
L
;
ets_timer_setfn
(
&
tmr
->
os
,
alarm_timer_common
,
(
void
*
)
id
);
return
0
;
}
...
...
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