解决控制台无法输入bug
rt_uint16_t old_flag = _console_device->open_flag; _console_device->open_flag |= RT_DEVICE_FLAG_STREAM; rt_device_write(_console_device, 0, str, rt_strlen(str)); _console_device->open_flag = old_flag; 当一个线程正在执行 rt_device_write(_console_device, 0, str, rt_strlen(str));函数时,一个高优先级线程 抢占当前线程并修改 _console_device->open_flag(修改为RT_DEVICE_FLAG_INT_RX,之前不是中断接收), 高优先级线程执行完后,继续执行以前线程,此时old_flag与_console_device->open_flag不一致,执行 _console_device->open_flag = old_flag;后_console_device->open_flag新的值被覆盖。控制台串口实际配置 成硬件中断接收,因为_console_device->open_flag值被修改为不是中断,最后导致控制台串口无法接收任何数据 输入。
This commit is contained in:
parent
92beddf3bc
commit
caeea1f893
|
@ -1175,7 +1175,7 @@ void rt_kputs(const char *str)
|
|||
|
||||
_console_device->open_flag |= RT_DEVICE_FLAG_STREAM;
|
||||
rt_device_write(_console_device, 0, str, rt_strlen(str));
|
||||
_console_device->open_flag = old_flag;
|
||||
_console_device->open_flag ^= (~old_flag & RT_DEVICE_FLAG_STREAM);
|
||||
}
|
||||
#else
|
||||
rt_hw_console_output(str);
|
||||
|
@ -1213,7 +1213,7 @@ void rt_kprintf(const char *fmt, ...)
|
|||
|
||||
_console_device->open_flag |= RT_DEVICE_FLAG_STREAM;
|
||||
rt_device_write(_console_device, 0, rt_log_buf, length);
|
||||
_console_device->open_flag = old_flag;
|
||||
_console_device->open_flag ^= (~old_flag & RT_DEVICE_FLAG_STREAM);
|
||||
}
|
||||
#else
|
||||
rt_hw_console_output(rt_log_buf);
|
||||
|
|
Loading…
Reference in New Issue