/* This function will initialize a pipe device and put it under control of resource management. */
rt_err_t rt_pipe_init(struct rt_pipe_device *pipe, const char *name, enum rt_pipe_flag flag, rt_uint8_t *buf, rt_size_t size)
/* This function will initialize a pipe device and put it under control of resource management. */
rt_err_t rt_pipe_init(struct rt_pipe_device *pipe, const char *name, enum rt_pipe_flag flag, rt_uint8_t *buf, rt_size_t size)
{
    RT_ASSERT(pipe);
    RT_ASSERT(buf);
    rt_list_init(&pipe->suspended_read_list);
    rt_list_init(&pipe->suspended_write_list);
    rt_ringbuffer_init(&pipe->ringbuffer, buf, size);
    pipe->flag = flag;
    pipe->parent.type    = RT_Device_Class_Pipe;
    pipe->parent.init    = RT_NULL;
    pipe->parent.open    = RT_NULL;
    pipe->parent.close   = RT_NULL;
    pipe->parent.read    = rt_pipe_read;
    pipe->parent.write   = rt_pipe_write;
    pipe->parent.control = rt_pipe_control;
    return rt_device_register(&(pipe->parent), name, RT_DEVICE_FLAG_RDWR);
}