소스 검색

serial: set the errno if and only if in thread context

The errno is associated with threads. It will crash the thread if we set
it in interrupt context.
Grissiom 11 년 전
부모
커밋
07bd09fc0f
1개의 변경된 파일4개의 추가작업 그리고 3개의 파일을 삭제
  1. 4 3
      components/drivers/serial/serial.c

+ 4 - 3
components/drivers/serial/serial.c

@@ -257,8 +257,8 @@ static rt_size_t rt_serial_read(struct rt_device *dev,
     }
 
     read_nbytes = (rt_uint32_t)ptr - (rt_uint32_t)buffer;
-    /* set error code */
-    if (read_nbytes == 0)
+    /* set error code if and only if in thread context */
+    if (read_nbytes == 0 && !rt_interrupt_get_nest())
     {
         rt_set_errno(-RT_EEMPTY);
     }
@@ -349,7 +349,8 @@ static rt_size_t rt_serial_write(struct rt_device *dev,
     }
 
     write_nbytes = (rt_uint32_t)ptr - (rt_uint32_t)buffer;
-    if (write_nbytes == 0)
+    /* set error code if and only if in thread context */
+    if (write_nbytes == 0 && !rt_interrupt_get_nest())
     {
         rt_set_errno(-RT_EFULL);
     }