]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/finish.c
a5cd8d176413cf85b38595d07211a7a66cdc06e1
[lincan.git] / lincan / src / finish.c
1 #include "../include/can.h"
2 #include "../include/can_sysdep.h"
3 #include "../include/main.h"
4 #include "../include/devcommon.h"
5 #include "../include/finish.h"
6 #include "../include/setup.h"
7
8
9
10 void msgobj_done(struct msgobj_t *obj)
11 {
12         if(obj->qends) {
13                 if(canqueue_ends_done_chip(obj->qends) < 0)
14                         CANMSG("msgobj_done: problem with chip queue ends\n");
15         }
16
17         if((obj->hostchip) && (obj->object>0)) {
18                 if(obj->hostchip->msgobj[obj->object-1] == obj)
19                         obj->hostchip->msgobj[obj->object-1]=NULL;
20                 else
21                         CANMSG("msgobj_done: not registered in the chip_t\n");
22                 obj->hostchip=NULL;
23         }
24         
25         if((obj->minor>=0)) {
26                 if(objects_p[obj->minor] == obj)
27                         objects_p[obj->minor] = NULL;
28                 else
29                         CANMSG("msgobj_done: not registered as minor\n");
30         }
31         
32         del_timer_sync(&obj->tx_timeout);
33
34         if(obj->qends) {
35                 can_checked_free(obj->qends);
36         }
37         obj->qends=NULL;
38 }
39
40
41 void canchip_done(struct chip_t *chip)
42 {
43
44         int i;
45         struct msgobj_t *obj;
46
47         if((chip->hostdevice) && (chip->chip_idx>=0)) {
48                 if(chip->hostdevice->chip[chip->chip_idx] == chip)
49                         chip->hostdevice->chip[chip->chip_idx] = NULL;
50                 else
51                         CANMSG("canchip_done: not registered in hostdevice\n");
52         }
53
54         if((chip->flags & CHIP_IRQ_SETUP) && (chip->chip_irq>=0)) {
55                 free_irq(chip->chip_irq, chip);
56                 chip->flags &= ~CHIP_IRQ_SETUP;
57         }
58                 
59         can_synchronize_irq(chip->chip_irq);
60         
61         for(i=0; i<chip->max_objects; i++){
62                 if((obj=chip->msgobj[i])==NULL)
63                         continue;
64                 msgobj_done(obj);
65                 can_checked_free(obj);
66         }
67         
68         can_checked_free(chip->chipspecops);
69         chip->chipspecops=NULL;
70
71 }
72
73 void candevice_done(struct candevice_t *candev)
74 {
75         int i;
76         struct chip_t *chip;
77         
78         for(i=0; i<candev->nr_all_chips; i++){
79                 if((chip=candev->chip[i])==NULL)
80                         continue;
81                 canchip_done(chip);
82                 can_checked_free(chip);
83         
84         }
85         if(candev->flags & CANDEV_IO_RESERVED) {
86                 candev->hwspecops->release_io(candev);
87                 candev->flags &= ~CANDEV_IO_RESERVED;
88         }
89         can_checked_free(candev->hwspecops);
90         candev->hwspecops=NULL;
91 }
92
93 void canhardware_done(struct canhardware_t *canhw)
94 {
95         int i;
96         struct candevice_t *candev;
97         
98         for(i=0; i<canhw->nr_boards; i++){
99                 if((candev=canhw->candevice[i])==NULL)
100                         continue;
101                 candevice_done(candev);
102                 can_checked_free(candev);
103         }
104
105 }