/* Serial polling receive data routine, This function will receive data in a continuous loop by one by one byte.  */
rt_size_t _serial_poll_rx(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size)
/* Serial polling receive data routine, This function will receive data in a continuous loop by one by one byte.  */
rt_size_t _serial_poll_rx(struct rt_device *dev, rt_off_t pos, void *buffer, rt_size_t size)
{
    struct rt_serial_device *serial;
    rt_size_t getc_size;
    int getc_element;
    rt_uint8_t *getc_buffer;
    RT_ASSERT(dev != RT_NULL);
    serial = (struct rt_serial_device *)dev;
    RT_ASSERT(serial != RT_NULL);
    getc_buffer = (rt_uint8_t *)buffer;
    getc_size = size;
    while(size)
    {
        getc_element = serial->ops->getc(serial);
        if (getc_element == -1) break;
        *getc_buffer = getc_element;
        ++ getc_buffer;
        -- size;
        if (serial->parent.open_flag & RT_DEVICE_FLAG_STREAM)
        {
            if (getc_element == '\n') break;
        }
    }
   return getc_size - size;
}