Пример #1
0
int csp_route_set(uint8_t node, csp_iface_t *ifc, uint8_t nexthop_mac_addr) {

    /* Don't add nothing */
    if (ifc == NULL)
        return CSP_ERR_INVAL;

    /**
     * Check if the interface has been added.
     *
     * NOTE: For future implementations, interfaces should call
     * csp_route_add_if in its csp_if_<name>_init function, instead
     * of registering at first route_set, in order to make the interface
     * available to network based (CMP) route configuration.
     */
    csp_route_add_if(ifc);

    /* Set route */
    if (node <= CSP_DEFAULT_ROUTE) {
        routes[node].interface = ifc;
        routes[node].nexthop_mac_addr = nexthop_mac_addr;
    } else {
        csp_log_error("Failed to set route: invalid node id %u\r\n", node);
        return CSP_ERR_INVAL;
    }

    return CSP_ERR_NONE;

}
Пример #2
0
void csp_tiradio_init (csp_iface_t *csp_iface,
                       csp_tiradio_driver_handle_t *csp_tiradio_handle,
                       const char *name) {

    csp_iface->driver = csp_tiradio_handle;
    csp_iface->mtu = TIRADIO_PACKET_MTU;
    csp_iface->nexthop = csp_tiradio_tx;
    csp_iface->name = name;

    /* Register interface */
    csp_route_add_if(csp_iface);
}
Пример #3
0
int csp_i2c_init(uint8_t addr, int handle) {

	/* Create i2c_handle */
	csp_i2c_handle = handle;
	if (i2c_init(csp_i2c_handle, I2C_MASTER, addr, CSP_I2C_SPEED, 5, 5, csp_i2c_rx) != E_NO_ERR)
		return CSP_ERR_DRIVER;

	/* Regsiter interface */
	csp_route_add_if(&csp_if_i2c);

	return CSP_ERR_NONE;

}
Пример #4
0
int csp_can_init(uint8_t mode, struct csp_can_config *conf) {

	int ret;
	uint32_t mask;

	/* Initialize packet buffer */
	if (pbuf_init() != 0) {
		csp_log_error("Failed to initialize CAN packet buffers\r\n");
		return CSP_ERR_NOMEM;
	}

	/* Initialize CFP identifier */
	if (id_init() != 0) {
		csp_log_error("Failed to initialize CAN identification number\r\n");
		return CSP_ERR_NOMEM;
	}

	if (mode == CSP_CAN_MASKED) {
		mask = CFP_MAKE_DST((1 << CFP_HOST_SIZE) - 1);
	} else if (mode == CSP_CAN_PROMISC) {
		mask = 0;
		csp_if_can.promisc = 1;
	} else {
		csp_log_error("Unknown CAN mode\r\n");
		return CSP_ERR_INVAL;
	}

	can_rx_queue = csp_queue_create(CSP_CAN_RX_QUEUE_SIZE, sizeof(can_frame_t));
	if (can_rx_queue == NULL) {
		csp_log_error("Failed to create CAN RX queue\r\n");
		return CSP_ERR_NOMEM;
	}

	ret = csp_thread_create(csp_can_rx_task, (signed char *) "CANRX",2048, NULL, 3, &can_rx_task);
	if (ret != 0) {
		csp_log_error("Failed to init CAN RX task\r\n");
		return CSP_ERR_NOMEM;
	}

	/* Initialize CAN driver */
	if (can_init(CFP_MAKE_DST(my_address), mask, csp_tx_callback, csp_rx_callback, conf) != 0) {
		csp_log_error("Failed to initialize CAN driver\r\n");
		return CSP_ERR_DRIVER;
	}

	/* Regsiter interface */
	csp_route_add_if(&csp_if_can);

	return CSP_ERR_NONE;

}