Esempio n. 1
0
int csp_route_next_packet(csp_route_queue_t * input) {

#ifdef CSP_USE_QOS
    int prio, found, event;

    /* Wait for packet in any queue */
    if (csp_queue_dequeue(router_input_event, &event, CSP_ROUTER_RX_TIMEOUT) != CSP_QUEUE_OK)
        return CSP_ERR_TIMEDOUT;

    /* Find packet with highest priority */
    found = 0;
    for (prio = 0; prio < CSP_ROUTE_FIFOS; prio++) {
        if (csp_queue_dequeue(router_input_fifo[prio], input, 0) == CSP_QUEUE_OK) {
            found = 1;
            break;
        }
    }

    if (!found) {
        csp_log_warn("Spurious wakeup of router task. No packet found\r\n");
        return CSP_ERR_TIMEDOUT;
    }
#else
    if (csp_queue_dequeue(router_input_fifo[0], input, CSP_ROUTER_RX_TIMEOUT) != CSP_QUEUE_OK)
        return CSP_ERR_TIMEDOUT;
#endif

    return CSP_ERR_NONE;

}
Esempio n. 2
0
File: csp_io.c Progetto: janbre/NUTS
csp_packet_t * csp_read(csp_conn_t * conn, uint32_t timeout) {

    csp_packet_t * packet = NULL;

    if (conn == NULL || conn->state != CONN_OPEN)
        return NULL;

#ifdef CSP_USE_QOS
    int prio, event;
    if (csp_queue_dequeue(conn->rx_event, &event, timeout) != CSP_QUEUE_OK)
        return NULL;

    for (prio = 0; prio < CSP_RX_QUEUES; prio++)
        if (csp_queue_dequeue(conn->rx_queue[prio], &packet, 0) == CSP_QUEUE_OK)
            break;
#else
    if (csp_queue_dequeue(conn->rx_queue[0], &packet, timeout) != CSP_QUEUE_OK)
        return NULL;
#endif

#ifdef CSP_USE_RDP
    /* Packet read could trigger ACK transmission */
    if (conn->idin.flags & CSP_FRDP)
        csp_rdp_check_ack(conn);
#endif

    return packet;

}
Esempio n. 3
0
void *csp_buffer_get(size_t buf_size) {

	csp_skbf_t * buffer = NULL;

	if (buf_size + CSP_BUFFER_PACKET_OVERHEAD > size) {
		csp_log_error("Attempt to allocate too large block %u\r\n", buf_size);
		return NULL;
	}

	csp_queue_dequeue(csp_buffers, &buffer, 0);
	if (buffer == NULL) {
		csp_log_error("Out of buffers\r\n");
		return NULL;
	}

	csp_log_buffer("GET: %p %p\r\n", buffer, buffer->skbf_addr);

	if (buffer != buffer->skbf_addr) {
		csp_log_error("Corrupt CSP buffer\r\n");
		return NULL;
	}

	buffer->refcount++;
	return buffer->skbf_data;
}
Esempio n. 4
0
csp_packet_t * csp_promisc_read(uint32_t timeout) {

    if (csp_promisc_queue == NULL)
        return NULL;

    csp_packet_t * packet = NULL;
    csp_queue_dequeue(csp_promisc_queue, &packet, timeout);

    return packet;

}
Esempio n. 5
0
File: csp_io.c Progetto: janbre/NUTS
csp_packet_t * csp_recvfrom(csp_socket_t * socket, uint32_t timeout) {

    if ((socket == NULL) || (!(socket->opts & CSP_SO_CONN_LESS)))
        return NULL;

    csp_packet_t * packet = NULL;
    csp_queue_dequeue(socket->socket, &packet, timeout);

    return packet;

}
Esempio n. 6
0
/**
 * Read data from a connection
 * This fuction uses the RX queue of a connection to receive a packet
 * If no packet is available and a timeout has been specified
 * The call will block.
 * Do NOT call this from ISR
 * @param conn pointer to connection
 * @param timeout timeout in ms, use CSP_MAX_DELAY for infinite blocking time
 * @return Returns pointer to csp_packet_t, which you MUST free yourself, either by calling csp_buffer_free() or reusing the buffer for a new csp_send.
 */
csp_packet_t * csp_read(csp_conn_t * conn, unsigned int timeout) {

	if ((conn == NULL) || (conn->state != CONN_OPEN))
		return NULL;

	csp_packet_t * packet = NULL;
    csp_queue_dequeue(conn->rx_queue, &packet, timeout);

	return packet;

}
Esempio n. 7
0
int csp_conn_flush_rx_queue(csp_conn_t * conn) {

    csp_packet_t * packet;

    int prio;

    /* Flush packet queues */
    for (prio = 0; prio < CSP_RX_QUEUES; prio++) {
        while (csp_queue_dequeue(conn->rx_queue[prio], &packet, 0) == CSP_QUEUE_OK)
            if (packet != NULL)
                csp_buffer_free(packet);
    }

    /* Flush event queue */
#ifdef CSP_USE_QOS
    int event;
    while (csp_queue_dequeue(conn->rx_event, &event, 0) == CSP_QUEUE_OK);
#endif

    return CSP_ERR_NONE;

}
Esempio n. 8
0
File: csp_io.c Progetto: janbre/NUTS
csp_conn_t * csp_accept(csp_socket_t * sock, uint32_t timeout) {

    if (sock == NULL)
        return NULL;

    if (sock->socket == NULL)
        return NULL;

    csp_conn_t * conn;
    if (csp_queue_dequeue(sock->socket, &conn, timeout) == CSP_QUEUE_OK)
        return conn;

    return NULL;

}
Esempio n. 9
0
/**
 * Wait for a new connection on a socket created by csp_socket
 * @param sock Socket to accept connections on
 * @param timeout use portMAX_DELAY for infinite timeout
 * @return Return pointer to csp_conn_t or NULL if timeout was reached
 */
csp_conn_t * csp_accept(csp_socket_t * sock, unsigned int timeout) {

    if (sock == NULL)
        return NULL;

    if (sock->conn_queue == NULL)
    	return NULL;

	csp_conn_t * conn;
    if (csp_queue_dequeue(sock->conn_queue, &conn, timeout) == CSP_QUEUE_OK)
        return conn;

	return NULL;

}
Esempio n. 10
0
void *csp_buffer_get(size_t buf_size) {
	void *buffer;

	if (buf_size + CSP_BUFFER_PACKET_OVERHEAD > size) {
		csp_log_error("Attempt to allocate too large block %u\r\n", buf_size);
		return NULL;
	}

	csp_queue_dequeue(csp_buffers, &buffer, 0);

	if (buffer != NULL) {
		csp_log_buffer("BUFFER: Using element at %p\r\n", buffer);
	} else {
		csp_log_error("Out of buffers\r\n");
	}

	return buffer;
}
Esempio n. 11
0
int csp_queue_dequeue_isr(csp_queue_handle_t handle, void *buf, CSP_BASE_TYPE * task_woken) {
	*task_woken = 0;
	return csp_queue_dequeue(handle, buf, 0);
}