int rb_put(RingBuffer * f, uchar8 d)
{
	if(rb_full(f))
		return 0;
		
	f->buffer[f->wr_idx++]=d;
	f->wr_idx %= MAXSIZE;
	f->size++;
	return 1;
}
/**
  * @brief          Test if UART buffer if full.
  */
int rakmgr_uartbuf_full(void)
{
    int full;
    
    rakmgr_uartbuf_lock();
    full = rb_full(&uartbuf);
    rakmgr_uartbuf_unlock();
    
    return full;
}
Пример #3
0
uint32_t
rb_write(ring_t* rb, uint8_t *data, uint32_t size)
{
    if (rb == NULL || rb->buffer_start == NULL || size <= 0)
        return 0;

    if (1 == rb_full(rb))
        return 0;

    else
    {
        rb->write_calls++;//debug       
        int32_t avaiable_space = rb_free_space(rb);
        if ( avaiable_space >= size)
        {
            memcpy(rb->head, data, size);
            rb->head = (rb->head + size);
            if (rb->head == rb->buffer_end)
            {
                rb->head = rb->buffer_start;
                rb->round_complete = 1;
            }
            return size;
        }
        else if (avaiable_space >= size)
        {
            uint32_t remaining_size = (rb->buffer_end - rb->head);
            memcpy(rb->head, data, remaining_size);
            rb->head = rb->buffer_start;
            uint32_t missing_size = size - remaining_size;
            if (missing_size <= 0)
                return 0;

            memcpy(rb->head, (data + remaining_size), missing_size);
            rb->head = (rb->head + missing_size);
            rb->round_complete = 1;
            return size;
        }
        else
            LOG_PRINT("rb_write:No more available memory! You must abort!\n");
    }
    return 0;
}