]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/devcommon.c
LinCAN can be compiled in mode with RT-Linux chip worker threads now.
[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 void canqueue_notify_chip(struct canque_ends_t *qends, struct canque_edge_t *qedge, int what)
16 {
17         struct chip_t *chip=qends->endinfo.chipinfo.chip;
18         struct msgobj_t *obj=qends->endinfo.chipinfo.msgobj;
19
20         DEBUGMSG("canqueue_notify_chip for edge %d and event %d\n",qedge->edge_num,what);
21         switch(what){
22                 /*case CANQUEUE_NOTIFY_EMPTY:*/
23                 /*case CANQUEUE_NOTIFY_SPACE:*/
24                 /*case CANQUEUE_NOTIFY_NOUSR:
25                         wake_up(&qends->endinfo.chipinfo.daemonq);
26                         break;*/
27                 case CANQUEUE_NOTIFY_PROC:
28                     #ifndef CAN_WITH_RTL
29                         /*wake_up(&qends->endinfo.chipinfo.daemonq);*/
30                         chip->chipspecops->wakeup_tx(chip, obj);
31                     #else /*CAN_WITH_RTL*/
32                         can_msgobj_set_fl(obj,TX_REQUEST);
33                         if(qends->endinfo.chipinfo.worker_thread){
34                                 can_msgobj_set_fl(obj,WORKER_WAKE);
35                                 pthread_kill(qends->endinfo.chipinfo.worker_thread,RTL_SIGNAL_WAKEUP);
36                                 rtl_schedule();
37                         } else {
38                                 set_bit(MSGOBJ_TX_REQUEST_b,&chip->pend_flags);
39
40                                 if(chip->worker_thread) {
41                                         set_bit(MSGOBJ_WORKER_WAKE_b,&chip->pend_flags);
42                                         pthread_kill(chip->worker_thread,RTL_SIGNAL_WAKEUP);
43                                         rtl_schedule();
44                                 }
45                         }
46                     #endif /*CAN_WITH_RTL*/
47                         break;
48                 case CANQUEUE_NOTIFY_DEAD_WANTED:
49                 case CANQUEUE_NOTIFY_DEAD:
50                         if(canque_fifo_test_and_clear_fl(&qedge->fifo, READY))
51                                 canque_edge_decref(qedge);
52                         break;
53                 case CANQUEUE_NOTIFY_ATTACH:
54                         break;
55         }
56 }
57
58
59 int canqueue_ends_init_chip(struct canque_ends_t *qends, struct chip_t *chip, struct msgobj_t *obj)
60 {
61         int ret;
62         ret=canqueue_ends_init_gen(qends);
63         if(ret<0) return ret;
64         
65         qends->context=NULL;
66     #ifndef CAN_WITH_RTL
67         init_waitqueue_head(&qends->endinfo.chipinfo.daemonq);
68     #endif /*CAN_WITH_RTL*/
69         qends->endinfo.chipinfo.chip=chip;
70         qends->endinfo.chipinfo.msgobj=obj;
71         qends->notify=canqueue_notify_chip;
72
73         DEBUGMSG("canqueue_ends_init_chip\n");
74         return 0;
75 }
76
77
78 int canqueue_ends_done_chip(struct canque_ends_t *qends)
79 {
80         int delayed;
81         
82         /* Finish or kill all outgoing edges listed in inends */
83         delayed=canqueue_ends_kill_inlist(qends, 1);
84         /* Kill all incoming edges listed in outends */
85         delayed|=canqueue_ends_kill_outlist(qends);
86
87         return delayed;
88 }