* @brief This function will open the pipe and actually creates the pipe buffer. * * @param device is a pointer to the pipe device descriptor. * * @param oflag is the open method, but it is not used yet. * * @return Return the operation status. * When the return value is RT_EOK, the operation is successful. * When the return value is -RT_EINVAL, it means the d
| 424 | * When the return value is -RT_ENOMEM, it means insufficient memory allocation failed. |
| 425 | */ |
| 426 | rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag) |
| 427 | { |
| 428 | rt_pipe_t *pipe = (rt_pipe_t *)device; |
| 429 | rt_err_t ret = RT_EOK; |
| 430 | |
| 431 | if (device == RT_NULL) |
| 432 | { |
| 433 | ret = -RT_EINVAL; |
| 434 | goto __exit; |
| 435 | } |
| 436 | |
| 437 | rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER); |
| 438 | |
| 439 | if (pipe->fifo == RT_NULL) |
| 440 | { |
| 441 | pipe->fifo = rt_ringbuffer_create(pipe->bufsz); |
| 442 | if (pipe->fifo == RT_NULL) |
| 443 | { |
| 444 | ret = -RT_ENOMEM; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | rt_mutex_release(&pipe->lock); |
| 449 | |
| 450 | __exit: |
| 451 | return ret; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * @brief This function will close the pipe and release the pipe buffer. |
nothing calls this directly
no test coverage detected