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

Function rt_ringbuffer_put

components/drivers/ipc/ringbuffer.c:63–104  ·  view source on GitHub ↗

* @brief Put a block of data into the ring buffer. If the capacity of ring buffer is insufficient, it will discard out-of-range data. * * @param rb A pointer to the ring buffer object. * @param ptr A pointer to the data buffer. * @param length The size of data in bytes. * * @return Return the data size we put into the ring buffer. */

Source from the content-addressed store, hash-verified

61 * @return Return the data size we put into the ring buffer.
62 */
63rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb,
64 const rt_uint8_t *ptr,
65 rt_uint32_t length)
66{
67 rt_uint32_t size;
68
69 RT_ASSERT(rb != RT_NULL);
70
71 /* whether has enough space */
72 size = rt_ringbuffer_space_len(rb);
73
74 /* no space */
75 if (size == 0)
76 return 0;
77
78 /* drop some data */
79 if (size < length)
80 length = size;
81
82 if (rb->buffer_size - rb->write_index > length)
83 {
84 /* read_index - write_index = empty space */
85 rt_memcpy(&rb->buffer_ptr[rb->write_index], ptr, length);
86 /* this should not cause overflow because there is enough space for
87 * length of data in current mirror */
88 rb->write_index += length;
89 return length;
90 }
91
92 rt_memcpy(&rb->buffer_ptr[rb->write_index],
93 &ptr[0],
94 rb->buffer_size - rb->write_index);
95 rt_memcpy(&rb->buffer_ptr[0],
96 &ptr[rb->buffer_size - rb->write_index],
97 length - (rb->buffer_size - rb->write_index));
98
99 /* we are going into the other side of the mirror */
100 rb->write_mirror = ~rb->write_mirror;
101 rb->write_index = length - (rb->buffer_size - rb->write_index);
102
103 return length;
104}
105RTM_EXPORT(rt_ringbuffer_put);
106
107/**

Callers 15

_ep_out_handlerFunction · 0.85
_vcom_rb_block_putFunction · 0.85
rt_hw_serial_isrFunction · 0.85
_can_nonblocking_txFunction · 0.85
rt_audio_pipe_writeFunction · 0.85
rt_hw_inputcapture_isrFunction · 0.85
usbh_cdc_acm_callbackFunction · 0.85
usbh_ftdi_callbackFunction · 0.85
usbh_ch34x_callbackFunction · 0.85

Calls 1

rt_memcpyFunction · 0.85

Tested by 1

ringbuffer_exampleFunction · 0.68