]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/devcommon.c
e17a0618d7709a3ebc5c801077904c605fdab2d5
[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         }
67 }
68
69
70 /**
71  * canqueue_ends_init_chip - CAN chip specific ends initialization
72  * @qends: pointer to the ends structure
73  * @chip: pointer to the corresponding CAN chip structure
74  * @obj: pointer to the corresponding message object structure
75  */
76 int canqueue_ends_init_chip(struct canque_ends_t *qends, struct chip_t *chip, struct msgobj_t *obj)
77 {
78         int ret;
79         ret=canqueue_ends_init_gen(qends);
80         if(ret<0) return ret;
81         
82         qends->context=NULL;
83     #ifndef CAN_WITH_RTL
84         init_waitqueue_head(&qends->endinfo.chipinfo.daemonq);
85     #endif /*CAN_WITH_RTL*/
86         qends->endinfo.chipinfo.chip=chip;
87         qends->endinfo.chipinfo.msgobj=obj;
88         qends->notify=canqueue_notify_chip;
89
90         DEBUGMSG("canqueue_ends_init_chip\n");
91         return 0;
92 }
93
94
95 /**
96  * canqueue_ends_done_chip - finalizing of the ends structure for CAN chips
97  * @qends: pointer to ends structure
98  *
99  * Return Value: Function should be designed such way to not fail.
100  */
101 int canqueue_ends_done_chip(struct canque_ends_t *qends)
102 {
103         int delayed;
104         
105         /* Finish or kill all outgoing edges listed in inends */
106         delayed=canqueue_ends_kill_inlist(qends, 1);
107         /* Kill all incoming edges listed in outends */
108         delayed|=canqueue_ends_kill_outlist(qends);
109
110         return delayed;
111 }