Exemplo n.º 1
0
uint32_t app_fifo_write(app_fifo_t * p_fifo, uint8_t const * p_byte_array, uint32_t * p_size)
{
    VERIFY_PARAM_NOT_NULL(p_fifo);
    VERIFY_PARAM_NOT_NULL(p_size);

    const uint32_t available_count = p_fifo->buf_size_mask - fifo_length(p_fifo) + 1;
    const uint32_t requested_len   = (*p_size);
    uint32_t       index           = 0;
    uint32_t       write_size      = MIN(requested_len, available_count);

    (*p_size) = available_count;

    // Check if the FIFO is FULL.
    if (available_count == 0)
    {
        return NRF_ERROR_NO_MEM;
    }

    // Check if application has requested only the size.
    if (p_byte_array == NULL)
    {
        return NRF_SUCCESS;
    }

    //Fetch bytes from the FIFO.
    while (index < write_size)
    {
        fifo_put(p_fifo, p_byte_array[index++]);
    }

    (*p_size) = write_size;

    return NRF_SUCCESS;
}
Exemplo n.º 2
0
uint32_t app_fifo_read(app_fifo_t * p_fifo, uint8_t * p_byte_array, uint32_t * p_size)
{
    VERIFY_PARAM_NOT_NULL(p_fifo);
    VERIFY_PARAM_NOT_NULL(p_size);

    const uint32_t byte_count    = fifo_length(p_fifo);
    const uint32_t requested_len = (*p_size);
    uint32_t       index         = 0;
    uint32_t       read_size     = MIN(requested_len, byte_count);

    (*p_size) = byte_count;

    // Check if the FIFO is empty.
    if (byte_count == 0)
    {
        return NRF_ERROR_NOT_FOUND;
    }

    // Check if application has requested only the size.
    if (p_byte_array == NULL)
    {
        return NRF_SUCCESS;
    }

    // Fetch bytes from the FIFO.
    while (index < read_size)
    {
        fifo_get(p_fifo, &p_byte_array[index++]);
    }

    (*p_size) = read_size;

    return NRF_SUCCESS;
}
Exemplo n.º 3
0
uint32_t fifo_state(struct fifo_t *queue)
{
	if (fifo_length(queue) == 0) {
		return FIFO_EMPTY;
	}

	return FIFO_OK;
}
Exemplo n.º 4
0
/* fifo_put -- insère un nouvel élément dans la file.
 * Ne fait rien si la file est pleine.
 * Complexité: O(1)
 */
void fifo_put(Fifo *fifo, void *item)
{
    assert((fifo != NULL) && (fifo->items != NULL) && (item != NULL));
    if (fifo_length(fifo) == fifo_max_size(fifo))
        return;

    fifo->items[fifo->newest++] = item;
    if (fifo->newest == fifo->max_size) fifo->newest = 0;
}
Exemplo n.º 5
0
int main()
{
    struct fifo * list = fifo_create_thread_safe_fifo();
    int i = 0;

    /*pop empty queue*/
    fifo_pop(list);

    printf("length: %d\n",fifo_length(list));
    
    for(;i<10;i++)
    {
        fifo_push(list,(void*)i);
    }

    printf("length: %d\n",fifo_length(list));

    for(i=0;i<5;i++)
    {
        printf("%d\n",(int)fifo_pop(list));
    }

    printf("length: %d\n",fifo_length(list));

    for(i=0;i<2;i++)
    {
        fifo_push(list,(void*)(i+10));
    }

    printf("length: %d\n",fifo_length(list));
        
    for(i=0;i<7;i++)
    {
        printf("%d\n",(int)fifo_pop(list));
    }
    
    printf("length: %d\n",fifo_length(list));

    for(i=0;i<2;i++)
    {
        fifo_push(list,(void*)(i+10));
    }

    printf("length: %d\n",fifo_length(list));
    
    for(i=0;i<2;i++)
    {
        printf("%d\n",(int)fifo_pop(list));
    }

    printf("length: %d\n",fifo_length(list));
    fifo_delete(list,NULL);
}
Exemplo n.º 6
0
uint32_t fifo_pop(struct fifo_t *queue, uint8_t *el)
{
	if (fifo_length(queue) == 0) {
		return FIFO_EMPTY;
	}

	++queue->q_top;

	if (queue->q_top == (queue->q_size - 1))
		queue->q_top = 0;

	*el = queue->q_data[queue->q_top];

	return FIFO_OK;
}
Exemplo n.º 7
0
uint32_t fifo_push(struct fifo_t *queue, uint8_t el)
{
	if (fifo_length(queue) == queue->q_size) {
		return FIFO_OVERFLOW;
	}

	++queue->q_end;

	if (queue->q_end == (queue->q_size - 1))
		queue->q_end = 0;

	queue->q_data[queue->q_end] = el;

	return FIFO_OK;
}
Exemplo n.º 8
0
uint32_t app_fifo_write(app_fifo_t * p_fifo, uint8_t const * p_byte_array, uint32_t * p_size)
{
    NULL_PARAM_CHECK(p_fifo);
    NULL_PARAM_CHECK(p_size);
    
    const uint32_t available_count = p_fifo->buf_size_mask - fifo_length(p_fifo) + 1;
    const uint32_t requested_len   = (*p_size);
    uint32_t       index           = 0;
    uint32_t       write_size      = 0;
    
    (*p_size) = available_count;
    
    // Check if the FIFO is FULL.
    if (available_count == 0)
    {
        return NRF_ERROR_NO_MEM; 
    }
    
    // Check if application has requested only the size.
    if (p_byte_array == NULL)
    {
        (*p_size) = available_count;
        return NRF_SUCCESS;
    }    
    
    // Check is available bytes in FIFO less than requested.
    if (requested_len < available_count)
    {
        write_size = requested_len;
    }
    else
    {
        write_size = available_count;
    }
    
    //Fetch bytes from the FIFO.
    do
    {
        fifo_put(p_fifo, p_byte_array[index++]);
    } while (index < write_size);
    
    (*p_size) = write_size;

    return NRF_SUCCESS;
}
Exemplo n.º 9
0
uint32_t app_fifo_read(app_fifo_t * p_fifo, uint8_t * p_byte_array, uint32_t * p_size)
{
    NULL_PARAM_CHECK(p_fifo);
    NULL_PARAM_CHECK(p_size);
    
    const uint32_t byte_count    = fifo_length(p_fifo);
    const uint32_t requested_len = (*p_size);
    uint32_t       index         = 0;
    uint32_t       read_size     = 0;
    
    (*p_size) = byte_count;
    
    // Check if the FIFO is empty.
    if (byte_count == 0)
    {
        return NRF_ERROR_NOT_FOUND; 
    }
    
    // Check if application has requested only the size.
    if (p_byte_array == NULL)
    {
        (*p_size) = byte_count;
        return NRF_SUCCESS;
    }    
    
    // Check is available bytes in FIFO less than requested.
    if (requested_len < byte_count)
    {
        read_size = requested_len;
    }
    else
    {
        read_size = byte_count;
    }
    
    // Fetch bytes from the FIFO.
    do
    {
        fifo_get(p_fifo, &p_byte_array[index++]);
    } while (index < read_size);
    
    (*p_size) = read_size;

    return NRF_SUCCESS;
}
Exemplo n.º 10
0
void EssReceive(void)
{
	if(BEnd.MicomUpdate_F==1)
	{
		Micom_Comm_Receive_Start_F=1;
	}
	else
	{
	#if 1
		if(fifo_length()>0) 
		{
			fifo_get(Rxd_result_buf);
			Check_BERcvData();
		}
	#else
		if(Micom_Comm_Receive_Start_F) 
		{
			Micom_Comm_Receive_Bytes(Rxd_result_buf);
			Check_BERcvData();
			Micom_Comm_Receive_Start_F = 0;
		}
	#endif
	}
}
Exemplo n.º 11
0
/* fifo_full -- détermine si une liste est pleine (ie ne peut plus
 * contenir d'éléments supplémentaires).
 * Complexité: O(1);
 */
int fifo_full(Fifo *fifo)
{
    assert(fifo != NULL);
    return (fifo_length(fifo) == fifo_max_size(fifo));
}
Exemplo n.º 12
0
/* fifo_empty -- détermine si une file est vide.
 * Complexité: O(1)
 */
int fifo_empty(Fifo *fifo)
{
    assert((fifo != NULL) && (fifo->items != NULL));
    return fifo_length(fifo) == 0;
}