Skip to content

Commit b00fa0f

Browse files
committed
【修复】machine.timer 模块重复初始化错误问题
Signed-off-by: chenyong <[email protected]>
1 parent 06318cf commit b00fa0f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

port/machine_timer.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
8787
self->base.type = &machine_timer_type;
8888
self->timerid = device_id;
8989
self->timeout = 0;
90+
self->timeout_cb = RT_NULL;
9091
self->is_repeat = RT_TRUE;
9192
self->is_init = RT_FALSE;
9293

9394
// return constant object
9495
return MP_OBJ_FROM_PTR(self);
9596
}
9697

98+
static machine_timer_obj_t *timer_self = RT_NULL;
99+
97100
STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
98101
machine_timer_obj_t *self = self_in;
99102
rt_err_t result = RT_EOK;
@@ -102,14 +105,13 @@ STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
102105
result = rt_device_close(self->timer_device);
103106
error_check(result == RT_EOK, "Timer device close error");
104107
self->is_init = RT_FALSE;
108+
timer_self = RT_NULL;
105109
}
106110

107111
return mp_const_none;
108112
}
109113
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit);
110114

111-
static machine_timer_obj_t *timer_self = RT_NULL;
112-
113115
STATIC rt_err_t timer_event_handler(rt_device_t dev, rt_size_t size) {
114116
machine_timer_obj_t *self = timer_self;
115117

0 commit comments

Comments
 (0)