Преглед изворни кода

【修复】machine.timer 模块重复初始化错误问题

Signed-off-by: chenyong <1521761801@qq.com>
chenyong пре 6 година
родитељ
комит
b00fa0fd8b
1 измењених фајлова са 4 додато и 2 уклоњено
  1. 4 2
      port/machine_timer.c

+ 4 - 2
port/machine_timer.c

@@ -87,6 +87,7 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
     self->base.type = &machine_timer_type;
     self->timerid = device_id;
     self->timeout = 0;
+    self->timeout_cb = RT_NULL;
     self->is_repeat = RT_TRUE;
     self->is_init = RT_FALSE;
     
@@ -94,6 +95,8 @@ STATIC mp_obj_t machine_timer_make_new(const mp_obj_type_t *type, size_t n_args,
     return MP_OBJ_FROM_PTR(self);
 }
 
+static machine_timer_obj_t *timer_self = RT_NULL;
+
 STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
     machine_timer_obj_t *self = self_in;
     rt_err_t result = RT_EOK;
@@ -102,14 +105,13 @@ STATIC mp_obj_t machine_timer_deinit(mp_obj_t self_in) {
         result = rt_device_close(self->timer_device);
         error_check(result == RT_EOK, "Timer device close error");
         self->is_init = RT_FALSE;
+        timer_self = RT_NULL;
     }
 
     return mp_const_none;
 }
 STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_timer_deinit_obj, machine_timer_deinit);
 
-static machine_timer_obj_t *timer_self = RT_NULL;
-
 STATIC rt_err_t timer_event_handler(rt_device_t dev, rt_size_t size) {
     machine_timer_obj_t *self = timer_self;