/* This function will write the specified length of data to the pipe.  */
rt_ssize_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count)
/* This function will write the specified length of data to the pipe.  */
rt_ssize_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count)
{
    uint8_t *pbuf;
    rt_size_t write_bytes = 0;
    rt_pipe_t *pipe = (rt_pipe_t *)device;
    if (device == RT_NULL)
    {
        rt_set_errno(-EINVAL);
        return 0;
    }
    if (count == 0)
    {
        return 0;
    }
    pbuf = (uint8_t*)buffer;
    rt_mutex_take(&pipe->lock, -1);
    while (write_bytes < count)
    {
        int len = rt_ringbuffer_put(pipe->fifo, &pbuf[write_bytes], count - write_bytes);
        if (len <= 0)
        {
            break;
        }
        write_bytes += len;
    }
    rt_mutex_release(&pipe->lock);
    return write_bytes;
}