+ /***********************************************************************
+ * CAN device initialization - device side (adapted from LinCAN setup.c)
+ ***********************************************************************/
+
+
+ baudrate[0]=1000;
+
+ canqueue_kern_initialize();
+
+ hardware_p->nr_boards=1;
+
+ candev=(struct candevice_t *)malloc(sizeof(struct candevice_t));
+ if (candev==NULL) sys_err();
+ memset(candev, 0, sizeof(struct candevice_t));
+
+ hardware_p->candevice[0]=candev;
+ candev->candev_idx=0;
+ candev->io_addr=0;
+ candev->dev_base_addr=0;
+
+ candev->hwspecops=(struct hwspecops_t *)malloc(sizeof(struct hwspecops_t));
+ if (candev->hwspecops==NULL) sys_err();
+ memset(candev->hwspecops, 0, sizeof(struct hwspecops_t));
+
+ ul_usb1_register(candev->hwspecops);
+
+ bd=baudrate[0];
+ if (candev->hwspecops->init_hw_data(candev)) sys_err();
+ /* Alocate and initialize the chip structures */
+ for (chipnr=0; chipnr < candev->nr_all_chips; chipnr++) {
+/* if(chipnr<irqnum)
+ irqsig=irq[*irq_param_idx_p+chipnr];*/
+ if (init_chip_struct(candev, chipnr, 0, bd*1000)) sys_err();
+ }
+ if (candev->hwspecops->request_io(candev))
+ sys_err();
+ candev->flags|=CANDEV_IO_RESERVED;
+ if (candev->hwspecops->reset(candev))
+ sys_err();
+ for(chipnr=0; chipnr<candev->nr_all_chips; chipnr++) {
+ if((chip=candev->chip[chipnr])==NULL)
+ continue;
+
+ if(chip->chipspecops->attach_to_chip(chip)<0) {
+// CANMSG("Initial attach to the chip HW failed\n");
+ sys_err();
+ }
+
+ chip->flags |= CHIP_ATTACHED;
+
+// Interrupts from chip are served in main cycle
+/* if(can_chip_setup_irq(chip)<0) {
+// CANMSG("Error to setup chip IRQ\n");
+ sys_err();
+ }*/
+ }
+
+ if (candev->flags & CANDEV_PROGRAMMABLE_IRQ)
+ if (candev->hwspecops->program_irq(candev)){
+// CANMSG("Error to program board interrupt\n");
+ sys_err();
+ }
+
+ /***********************************************************************
+ * CAN device initialization - client side (adapted from LinCAN open.c)
+ ***********************************************************************/
+
+ chip=candev->chip[0];
+ obj=chip->msgobj[0];
+ atomic_inc(&obj->obj_used);
+ can_msgobj_set_fl(obj,OPENED);
+
+ if (chip->flags & CHIP_CONFIGURED)
+ DEBUGMSG("Device is already configured.\n");
+ else {
+ if (chip->chipspecops->chip_config(chip))
+ CANMSG("Error configuring chip.\n");
+ else
+ chip->flags |= CHIP_CONFIGURED;
+
+ if (chip->chipspecops->pre_read_config(chip,obj)<0)
+ CANMSG("Error initializing chip for receiving\n");
+
+ } /* End of chip configuration */
+
+ canuser = (struct canuser_t *)malloc(sizeof(struct canuser_t));
+ if(canuser == NULL) sys_err();
+ canuser->flags=0;
+// canuser->userinfo.fileinfo.file = file;
+ canuser->msgobj = obj;
+// canuser->magic = CAN_USER_MAGIC;
+// file->private_data = canuser;
+
+ qends = (struct canque_ends_t *)malloc(sizeof(struct canque_ends_t));
+ if(qends == NULL) sys_err();
+ canqueue_ends_init_kern(qends);
+ canuser->qends = qends;
+
+ /*required to synchronize with RT-Linux context*/
+ can_spin_lock_irqsave(&canuser_manipulation_lock, iflags);
+ list_add(&canuser->peers, &obj->obj_users);
+ can_spin_unlock_irqrestore(&canuser_manipulation_lock, iflags);
+
+ if(canqueue_connect_edge(edge=canque_new_edge_kern(MAX_BUF_LENGTH),
+ canuser->qends, obj->qends)<0) sys_err();
+
+ if(canqueue_connect_edge(canuser->rx_edge0=canque_new_edge_kern(MAX_BUF_LENGTH),
+ obj->qends, canuser->qends)<0) sys_err();
+ /*FIXME: more generic model should be used there*/
+ canque_edge_decref(canuser->rx_edge0);
+ canque_edge_decref(edge);
+
+
+ /***********************************************************************
+ * USB Init
+ ***********************************************************************/
+
+ memset( &usb_device, 0, sizeof( usb_device));
+ usb_device.id = 1;
+ usb_device.init = usb_lpc_init;
+ usb_debug_set_level(DEBUG_LEVEL_NONE);