Exemplo n.º 1
0
wiced_result_t bt_packet_pool_init( bt_packet_pool_t* pool, uint32_t packet_count, uint32_t header_size, uint32_t data_size )
{
    uint32_t       packet_size = header_size + data_size + sizeof(bt_packet_t) - 1;
    uint32_t       buffer_size = packet_count * packet_size;
    uint8_t*       packet_ptr  = NULL;
    void*          buffer      = NULL;
    wiced_result_t result;
    uint32_t       a;

    memset( pool, 0, sizeof( *pool ) );

    buffer = (void*)malloc_named( "bt_packet_pool", buffer_size );
    if ( buffer == NULL )
    {
        return WICED_BT_OUT_OF_HEAP_SPACE;
    }

    result = linked_list_init( &pool->pool_list );
    if ( result != WICED_BT_SUCCESS )
    {
        return result;
    }

    pool->pool_id          = PACKET_POOL_ID;
    pool->max_packet_count = packet_count;
    pool->header_size      = header_size;
    pool->data_size        = data_size;
    pool->pool_buffer      = buffer;
    packet_ptr             = buffer;

    for ( a = 0; a < packet_count; a++ )
    {
        bt_packet_t* packet = (bt_packet_t*)packet_ptr;

        result = linked_list_insert_node_at_front( &pool->pool_list, &packet->node );

        if ( result == WICED_BT_SUCCESS )
        {
            packet->node.data = (void*)packet;
            packet->pool      = pool;
            packet->packet_id = PACKET_ID;

        }
        else
        {
            return result;
        }

        packet_ptr += packet_size;
    }

    return wiced_rtos_init_mutex( &pool->mutex );
}
// dbSetValue
// searches the database and newValue is not found then it inserts it or
// overwrite the value
//
void dbSetValue(dbEntry_t *newValue)
{
	dbEntry_t *found = dbFind(newValue);
	if(found) // if it is already in the database
	{
		found->value = newValue->value;
	}
	else // add it to the linked list
	{
		linked_list_node_t *newNode = (linked_list_node_t *)malloc(sizeof(linked_list_node_t));
		newNode->data = newValue;
		linked_list_insert_node_at_front( &db, newNode );
	}
}
Exemplo n.º 3
0
wiced_result_t bt_packet_pool_free_packet( bt_packet_t* packet )
{
    if ( packet == NULL )
    {
        return WICED_BT_BADARG;
    }

    if ( packet->pool == DYNAMIC_PACKET_POOL )
    {
        malloc_transfer_to_curr_thread( packet );
        packet->owner     = BT_PACKET_OWNER_POOL;
        packet->node.prev = NULL;
        packet->node.next = NULL;
        packet->node.data = NULL;
        free( packet );
        bt_dynamic_packet_deleted++;
        return WICED_BT_SUCCESS;
    }
    else if ( packet->packet_id == PACKET_ID )
    {
        wiced_result_t result;

        wiced_rtos_lock_mutex( &packet->pool->mutex );

        result = linked_list_insert_node_at_front( &packet->pool->pool_list, &packet->node );

        if ( result == WICED_SUCCESS )
        {
            packet->owner = BT_PACKET_OWNER_POOL;
            packet->pool->packet_deleted++;
        }

        wiced_rtos_unlock_mutex( &packet->pool->mutex );

        return result;
    }

    return WICED_BT_UNKNOWN_PACKET;
}