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

Function rt_ringbuffer_putchar_force

components/drivers/ipc/ringbuffer.c:305–334  ·  view source on GitHub ↗

* @brief Put a byte into the ring buffer. If ring buffer is full, it will discard an old data and put into a new data. * * @param rb A pointer to the ring buffer object. * @param ch A byte put into the ring buffer. * * @return Return the data size we put into the ring buffer. Always return 1. */

Source from the content-addressed store, hash-verified

303 * @return Return the data size we put into the ring buffer. Always return 1.
304 */
305rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch)
306{
307 enum rt_ringbuffer_state old_state;
308
309 RT_ASSERT(rb != RT_NULL);
310
311 old_state = rt_ringbuffer_status(rb);
312
313 rb->buffer_ptr[rb->write_index] = ch;
314
315 /* flip mirror */
316 if (rb->write_index == rb->buffer_size - 1)
317 {
318 rb->write_mirror = ~rb->write_mirror;
319 rb->write_index = 0;
320 if (old_state == RT_RINGBUFFER_FULL)
321 {
322 rb->read_mirror = ~rb->read_mirror;
323 rb->read_index = rb->write_index;
324 }
325 }
326 else
327 {
328 rb->write_index++;
329 if (old_state == RT_RINGBUFFER_FULL)
330 rb->read_index = rb->write_index;
331 }
332
333 return 1;
334}
335RTM_EXPORT(rt_ringbuffer_putchar_force);
336
337/**

Callers 4

_vcom_putcFunction · 0.85
rt_hw_serial_control_isrFunction · 0.85
uart_irq_handlerFunction · 0.85
serial_rxcallbackFunction · 0.85

Calls 1

rt_ringbuffer_statusFunction · 0.70

Tested by

no test coverage detected