summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErnest <[email protected]>2019-10-31 18:32:34 +0800
committerErnest <[email protected]>2019-11-01 10:38:07 +0800
commitf82d4f1f6f06de0260707a40e3fec6f5faa8de30 (patch)
treee46da807eadad3a36f4f5fafe512f513a163447a
parente1a01253fab507ce38efb3be7a1eb7e8ddcd5ecb (diff)
[DeviceDrivers] add warning about overflow by serial receiver
-rw-r--r--components/drivers/serial/serial.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c
index e1d606557b..50dd7e188b 100644
--- a/components/drivers/serial/serial.c
+++ b/components/drivers/serial/serial.c
@@ -327,6 +327,18 @@ rt_inline int _serial_int_tx(struct rt_serial_device *serial, const rt_uint8_t *
return size - length;
}
+static void _serial_check_buffer_size(void)
+{
+ static rt_bool_t already_output = RT_FALSE;
+
+ if (already_output == RT_FALSE)
+ {
+ LOG_W("Warning: There is no enough buffer for saving data,"
+ " please increase the RT_SERIAL_RB_BUFSZ option.");
+ already_output = RT_TRUE;
+ }
+}
+
#if defined(RT_USING_POSIX) || defined(RT_SERIAL_USING_DMA)
static rt_size_t _serial_fifo_calc_recved_len(struct rt_serial_device *serial)
{
@@ -430,6 +442,7 @@ static void rt_dma_recv_update_put_index(struct rt_serial_device *serial, rt_siz
if(rx_fifo->is_full == RT_TRUE)
{
+ _serial_check_buffer_size();
rx_fifo->get_index = rx_fifo->put_index;
}
}
@@ -1170,6 +1183,8 @@ void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
rx_fifo->get_index += 1;
rx_fifo->is_full = RT_TRUE;
if (rx_fifo->get_index >= serial->config.bufsz) rx_fifo->get_index = 0;
+
+ _serial_check_buffer_size();
}
/* enable interrupt */