MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_pipe_read

Function rt_pipe_read

components/drivers/ipc/pipe.c:495–527  ·  view source on GitHub ↗

* @brief This function will read the specified length of data from the pipe. * * @param device is a pointer to the pipe device descriptor. * * @param pos is a parameter compatible with POSIX standard interface (currently meaningless, just pass in 0). * * @param buffer is a pointer to the buffer to store the read data. * * @param count is the length of data to be read. * *

Source from the content-addressed store, hash-verified

493 * When the return value is 0, it means the pipe device handle is empty or the count is 0.
494 */
495rt_ssize_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count)
496{
497 uint8_t *pbuf;
498 rt_size_t read_bytes = 0;
499 rt_pipe_t *pipe = (rt_pipe_t *)device;
500
501 if (device == RT_NULL)
502 {
503 rt_set_errno(-EINVAL);
504 return 0;
505 }
506 if (count == 0)
507 {
508 return 0;
509 }
510
511 pbuf = (uint8_t*)buffer;
512 rt_mutex_take(&pipe->lock, RT_WAITING_FOREVER);
513
514 while (read_bytes < count)
515 {
516 int len = rt_ringbuffer_get(pipe->fifo, &pbuf[read_bytes], count - read_bytes);
517 if (len <= 0)
518 {
519 break;
520 }
521
522 read_bytes += len;
523 }
524 rt_mutex_release(&pipe->lock);
525
526 return read_bytes;
527}
528
529/**
530 * @brief This function will write the specified length of data to the pipe.

Callers

nothing calls this directly

Calls 4

rt_set_errnoFunction · 0.85
rt_mutex_takeFunction · 0.85
rt_ringbuffer_getFunction · 0.85
rt_mutex_releaseFunction · 0.85

Tested by

no test coverage detected