Beispiel #1
0
/**
 * put a character into ring buffer
 *
 * When the buffer is full, it will discard one old data.
 */
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch)
{
    enum rt_ringbuffer_state old_state;

    RT_ASSERT(rb != RT_NULL);

    old_state = rt_ringbuffer_status(rb);

    rb->buffer_ptr[rb->write_index] = ch;

    /* flip mirror */
    if (rb->write_index == rb->buffer_size-1)
    {
        rb->write_mirror = ~rb->write_mirror;
        rb->write_index = 0;
        if (old_state == RT_RINGBUFFER_FULL)
        {
            rb->read_mirror = ~rb->read_mirror;
            rb->read_index = rb->write_index;
        }
    }
    else
    {
        rb->write_index++;
        if (old_state == RT_RINGBUFFER_FULL)
            rb->read_index = rb->write_index;
    }

    return 1;
}
static inline rt_uint8_t _is_wrtnode2r_spi_stm32_write_buf_full(void)
{
    return (RT_RINGBUFFER_FULL == rt_ringbuffer_status(&spi_bridge.write_buf));
}
static inline rt_uint8_t _is_wrtnode2r_spi_stm32_read_buf_empty(void)
{
    return (RT_RINGBUFFER_EMPTY == rt_ringbuffer_status(&spi_bridge.read_buf));
}