]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/devcommon.c
Intel 82527 chip now configures acceptance identifiers and mask 15 according to edges.
[lincan.git] / lincan / src / devcommon.c
1 /* devcommon.c - common device code
2  * Linux CAN-bus device driver.
3  * New CAN queues by Pavel Pisa - OCERA team member
4  * email:pisa@cmp.felk.cvut.cz
5  * This software is released under the GPL-License.
6  * Version lincan-0.2  9 Jul 2003
7  */
8
9 #include "../include/can.h"
10 #include "../include/can_sysdep.h"
11 #include "../include/can_queue.h"
12 #include "../include/main.h"
13 #include "../include/devcommon.h"
14
15 /**
16  * canqueue_notify_chip - notification callback handler for CAN chips ends of queues
17  * @qends: pointer to the callback side ends structure
18  * @qedge: edge which invoked notification 
19  * @what: notification type
20  *
21  * This function has to deal with more possible cases. It can be called from
22  * the kernel or interrupt context for Linux only compilation of driver.
23  * The function can be called from kernel context or RT-Linux thread context
24  * for mixed mode Linux/RT-Linux compilation.
25  */
26 void canqueue_notify_chip(struct canque_ends_t *qends, struct canque_edge_t *qedge, int what)
27 {
28         struct chip_t *chip=qends->endinfo.chipinfo.chip;
29         struct msgobj_t *obj=qends->endinfo.chipinfo.msgobj;
30
31         DEBUGMSG("canqueue_notify_chip for edge %d and event %d\n",qedge->edge_num,what);
32         switch(what){
33                 /*case CANQUEUE_NOTIFY_EMPTY:*/
34                 /*case CANQUEUE_NOTIFY_SPACE:*/
35                 /*case CANQUEUE_NOTIFY_NOUSR:
36                         wake_up(&qends->endinfo.chipinfo.daemonq);
37                         break;*/
38                 case CANQUEUE_NOTIFY_PROC:
39                     #ifndef CAN_WITH_RTL
40                         /*wake_up(&qends->endinfo.chipinfo.daemonq);*/
41                         chip->chipspecops->wakeup_tx(chip, obj);
42                     #else /*CAN_WITH_RTL*/
43                         can_msgobj_set_fl(obj,TX_REQUEST);
44                         if(qends->endinfo.chipinfo.worker_thread){
45                                 can_msgobj_set_fl(obj,WORKER_WAKE);
46                                 pthread_kill(qends->endinfo.chipinfo.worker_thread,RTL_SIGNAL_WAKEUP);
47                                 rtl_schedule();
48                         } else {
49                                 set_bit(MSGOBJ_TX_REQUEST_b,&chip->pend_flags);
50
51                                 if(chip->worker_thread) {
52                                         set_bit(MSGOBJ_WORKER_WAKE_b,&chip->pend_flags);
53                                         pthread_kill(chip->worker_thread,RTL_SIGNAL_WAKEUP);
54                                         rtl_schedule();
55                                 }
56                         }
57                     #endif /*CAN_WITH_RTL*/
58                         break;
59                 case CANQUEUE_NOTIFY_DEAD_WANTED:
60                 case CANQUEUE_NOTIFY_DEAD:
61                         if(canque_fifo_test_and_clear_fl(&qedge->fifo, READY))
62                                 canque_edge_decref(qedge);
63                         break;
64                 case CANQUEUE_NOTIFY_ATTACH:
65                         break;
66                 case CANQUEUE_NOTIFY_FILTCH:
67                         if(!chip->chipspecops->filtch_rq)
68                                 break;
69                     #ifndef CAN_WITH_RTL
70                         chip->chipspecops->filtch_rq(chip, obj);
71                     #else /*CAN_WITH_RTL*/
72                     #endif /*CAN_WITH_RTL*/
73                         
74                         break;
75         }
76 }
77
78
79 /**
80  * canqueue_ends_init_chip - CAN chip specific ends initialization
81  * @qends: pointer to the ends structure
82  * @chip: pointer to the corresponding CAN chip structure
83  * @obj: pointer to the corresponding message object structure
84  */
85 int canqueue_ends_init_chip(struct canque_ends_t *qends, struct chip_t *chip, struct msgobj_t *obj)
86 {
87         int ret;
88         ret=canqueue_ends_init_gen(qends);
89         if(ret<0) return ret;
90         
91         qends->context=NULL;
92     #ifndef CAN_WITH_RTL
93         init_waitqueue_head(&qends->endinfo.chipinfo.daemonq);
94     #endif /*CAN_WITH_RTL*/
95         qends->endinfo.chipinfo.chip=chip;
96         qends->endinfo.chipinfo.msgobj=obj;
97         qends->notify=canqueue_notify_chip;
98
99         DEBUGMSG("canqueue_ends_init_chip\n");
100         return 0;
101 }
102
103
104 /**
105  * canqueue_ends_done_chip - finalizing of the ends structure for CAN chips
106  * @qends: pointer to ends structure
107  *
108  * Return Value: Function should be designed such way to not fail.
109  */
110 int canqueue_ends_done_chip(struct canque_ends_t *qends)
111 {
112         int delayed;
113         
114         /* Finish or kill all outgoing edges listed in inends */
115         delayed=canqueue_ends_kill_inlist(qends, 1);
116         /* Kill all incoming edges listed in outends */
117         delayed|=canqueue_ends_kill_outlist(qends);
118
119         return delayed;
120 }