]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/setup.c
LinCAN can be compiled in mode with RT-Linux chip worker threads now.
[lincan.git] / lincan / src / setup.c
index 57883ce39533747aa3c0876a63c922dd456dd057..acc7cacf3ccb6fa0bdbf64e3c2b102a7ae825eec 100644 (file)
@@ -207,14 +207,15 @@ int init_device_struct(int card)
        if (candev->hwspecops->init_hw_data(candev))
                goto error_nodev;
 
-       if (init_chip_struct(candev))
-               goto error_nodev;
+       if ((ret=init_chip_struct(candev)))
+               goto error_chip;
 
        return 0;
 
     error_nodev:
-       candevice_done(candev);
        ret=-ENODEV;
+    error_chip:
+       candevice_done(candev);
        goto error_both;
 
     error_nomem:
@@ -232,39 +233,40 @@ int init_device_struct(int card)
  */
 int init_chip_struct(struct candevice_t *candev)
 {
+       struct chip_t *chip;
        static int irq_count=0;
        int i=0;
 
        /* Alocate and initialize the chip structures */
        for (i=0; i < candev->nr_all_chips; i++) {
                candev->chip[i]=(struct chip_t *)can_checked_malloc(sizeof(struct chip_t));
-               if (candev->chip[i]==NULL)
+               if ((chip=candev->chip[i])==NULL)
                        return -ENOMEM;
 
-               memset(candev->chip[i], 0, sizeof(struct chip_t));
+               memset(chip, 0, sizeof(struct chip_t));
                
-               candev->chip[i]->write_register=candev->hwspecops->write_register;
-               candev->chip[i]->read_register=candev->hwspecops->read_register;
+               chip->write_register=candev->hwspecops->write_register;
+               chip->read_register=candev->hwspecops->read_register;
 
-               candev->chip[i]->chipspecops=can_checked_malloc(sizeof(struct chipspecops_t));
-               if (candev->chip[i]->chipspecops==NULL)
+               chip->chipspecops=can_checked_malloc(sizeof(struct chipspecops_t));
+               if (chip->chipspecops==NULL)
                        return -ENOMEM;
-
-                chips_p[irq_count]=candev->chip[i];
-               candev->chip[i]->chip_idx=i;
-               candev->chip[i]->hostdevice=candev;
-               candev->chip[i]->chip_irq=irq[irq_count];
-               candev->chip[i]->baudrate=baudrate[irq_count]*1000;
-               if(!candev->chip[i]->baudrate)
-                       candev->chip[i]->baudrate=baudrate[0]*1000;
-               candev->chip[i]->flags=0x0;
+               
+                chips_p[irq_count]=chip;
+               chip->chip_idx=i;
+               chip->hostdevice=candev;
+               chip->chip_irq=irq[irq_count];
+               chip->baudrate=baudrate[irq_count]*1000;
+               if(!chip->baudrate)
+                       chip->baudrate=baudrate[0]*1000;
+               chip->flags=0x0;
 
                candev->hwspecops->init_chip_data(candev,i);
 
                if (init_chipspecops(candev,i))
                        return -ENODEV;
-
-               init_obj_struct(candev, candev->chip[i], minor[irq_count]);
+               
+               init_obj_struct(candev, chip, minor[irq_count]);
 
                irq_count++;
        } 
@@ -300,7 +302,7 @@ int init_obj_struct(struct candevice_t *candev, struct chip_t *hostchip, int min
                obj->qends=qends;
                obj->tx_qedge=NULL;
                obj->tx_slot=NULL;
-               obj->flags = 0x0;
+               obj->obj_flags = 0x0;
 
                canqueue_ends_init_chip(qends, hostchip, obj);
                
@@ -351,3 +353,32 @@ int init_chipspecops(struct candevice_t *candev, int chipnr)
 
        return 0;
 }
+
+#ifndef CAN_WITH_RTL
+
+int can_chip_setup_irq(struct chip_t *chip)
+{
+       if(chip==NULL)
+               return -1;
+       if(!chip->chipspecops->irq_handler)
+               return 0;
+                       
+       if (request_irq(chip->chip_irq,chip->chipspecops->irq_handler,SA_SHIRQ,DEVICE_NAME,chip))
+               return -1;
+       else {
+               DEBUGMSG("Registered interrupt %d\n",chip->chip_irq);
+               chip->flags |= CHIP_IRQ_SETUP;
+       }
+       return 1;
+}
+
+
+void can_chip_free_irq(struct chip_t *chip)
+{
+       if((chip->flags & CHIP_IRQ_SETUP) && (chip->chip_irq>=0)) {
+               free_irq(chip->chip_irq, chip);
+               chip->flags &= ~CHIP_IRQ_SETUP;
+       }
+}
+
+#endif /*CAN_WITH_RTL*/