Exemplo n.º 1
0
int csp_route_table_init(void) {

    int prio;

    /* Clear rounting table */
    memset(routes, 0, sizeof(csp_route_t) * (CSP_ID_HOST_MAX + 2));

    /* Create routing table lock */
    if (csp_mutex_create(&routes_lock) != CSP_MUTEX_OK)
        return CSP_ERR_NOMEM;

    /* Create router fifos for each priority */
    for (prio = 0; prio < CSP_ROUTE_FIFOS; prio++) {
        router_input_fifo[prio] = csp_queue_create(CSP_FIFO_INPUT, sizeof(csp_route_queue_t));
        if (!router_input_fifo[prio])
            return CSP_ERR_NOMEM;
    }

#ifdef CSP_USE_QOS
    /* Create QoS fifo notification queue */
    router_input_event = csp_queue_create(CSP_FIFO_INPUT, sizeof(int));
    if (!router_input_event)
        return CSP_ERR_NOMEM;
#endif

    return CSP_ERR_NONE;

}
Exemplo n.º 2
0
int csp_conn_init(void) {

    /* Initialize source port */
    srand(csp_get_ms());
    sport = (rand() % (CSP_ID_PORT_MAX - CSP_MAX_BIND_PORT)) + (CSP_MAX_BIND_PORT + 1);

    if (csp_bin_sem_create(&sport_lock) != CSP_SEMAPHORE_OK) {
        csp_log_error("No more memory for sport semaphore\r\n");
        return CSP_ERR_NOMEM;
    }

    int i, prio;
    for (i = 0; i < CSP_CONN_MAX; i++) {
        for (prio = 0; prio < CSP_RX_QUEUES; prio++)
            arr_conn[i].rx_queue[prio] = csp_queue_create(CSP_RX_QUEUE_LENGTH, sizeof(csp_packet_t *));

#ifdef CSP_USE_QOS
        arr_conn[i].rx_event = csp_queue_create(CSP_CONN_QUEUE_LENGTH, sizeof(int));
#endif
        arr_conn[i].state = CONN_CLOSED;

        if (csp_mutex_create(&arr_conn[i].lock) != CSP_MUTEX_OK) {
            csp_log_error("Failed to create connection lock\r\n");
            return CSP_ERR_NOMEM;
        }

#ifdef CSP_USE_RDP
        if (csp_rdp_allocate(&arr_conn[i]) != CSP_ERR_NONE) {
            csp_log_error("Failed to create queues for RDP in csp_conn_init\r\n");
            return CSP_ERR_NOMEM;
        }
#endif
    }

    if (csp_bin_sem_create(&conn_lock) != CSP_SEMAPHORE_OK) {
        csp_log_error("No more memory for conn semaphore\r\n");
        return CSP_ERR_NOMEM;
    }

    return CSP_ERR_NONE;

}