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

Function rt_ringbuffer_get

components/drivers/ipc/ringbuffer.c:177–218  ·  view source on GitHub ↗

* @brief Get data from the ring buffer. * * @param rb A pointer to the ring buffer. * @param ptr A pointer to the data buffer. * @param length The size of the data we want to read from the ring buffer. * * @return Return the data size we read from the ring buffer. */

Source from the content-addressed store, hash-verified

175 * @return Return the data size we read from the ring buffer.
176 */
177rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb,
178 rt_uint8_t *ptr,
179 rt_uint32_t length)
180{
181 rt_size_t size;
182
183 RT_ASSERT(rb != RT_NULL);
184
185 /* whether has enough data */
186 size = rt_ringbuffer_data_len(rb);
187
188 /* no data */
189 if (size == 0)
190 return 0;
191
192 /* less data */
193 if (size < length)
194 length = size;
195
196 if (rb->buffer_size - rb->read_index > length)
197 {
198 /* copy all of data */
199 rt_memcpy(ptr, &rb->buffer_ptr[rb->read_index], length);
200 /* this should not cause overflow because there is enough space for
201 * length of data in current mirror */
202 rb->read_index += length;
203 return length;
204 }
205
206 rt_memcpy(&ptr[0],
207 &rb->buffer_ptr[rb->read_index],
208 rb->buffer_size - rb->read_index);
209 rt_memcpy(&ptr[rb->buffer_size - rb->read_index],
210 &rb->buffer_ptr[0],
211 length - (rb->buffer_size - rb->read_index));
212
213 /* we are going into the other side of the mirror */
214 rb->read_mirror = ~rb->read_mirror;
215 rb->read_index = length - (rb->buffer_size - rb->read_index);
216
217 return length;
218}
219RTM_EXPORT(rt_ringbuffer_get);
220
221/**

Callers 14

vcom_tx_thread_entryFunction · 0.85
_serial_fifo_rxFunction · 0.85
rt_hw_can_isrFunction · 0.85
rt_audio_pipe_readFunction · 0.85
rt_inputcapture_readFunction · 0.85
usbd_adb_shell_readFunction · 0.85
usbh_serial_readFunction · 0.85
usbd_serial_readFunction · 0.85
pipe_fops_readFunction · 0.85
rt_pipe_readFunction · 0.85
ulog_async_outputFunction · 0.85
rt_uart_readFunction · 0.85

Calls 2

rt_ringbuffer_data_lenFunction · 0.85
rt_memcpyFunction · 0.85

Tested by 2

ringbuffer_exampleFunction · 0.68
ringbuffer_force_exampleFunction · 0.68