summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrissiom <[email protected]>2013-10-25 20:31:02 +0800
committerGrissiom <[email protected]>2013-10-25 20:31:02 +0800
commit07bd09fc0fc256e5c53ad3c6157802fd94c9910c (patch)
tree599c27f274eb2c35b763f4c6ded411f7a9a0aa24
parent21fb9a0bac9f5eaa57e41e60bab06e9f4dc216ae (diff)
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.
-rw-r--r--components/drivers/serial/serial.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c
index 5e7a8ec814..c4a7ac6980 100644
--- a/components/drivers/serial/serial.c
+++ b/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);
}