]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - embedded/app/usbcan/can_quesysless.c
embedded: reintroduce missing emulated bus initialization for UL_USB1 board.
[lincan.git] / embedded / app / usbcan / can_quesysless.c
index 7ceeb4392cb2fdb88f18eaddaff9247d24fc5706..c7c7f33c84bcd1c06c9de6ce4cbfbfbaff1c6b0b 100644 (file)
@@ -1,28 +1,53 @@
-/* can_quekern.c - CAN message queues functions for the Linux kernel
- * Linux CAN-bus device driver.
- * New CAN queues by Pavel Pisa - OCERA team member
- * email:pisa@cmp.felk.cvut.cz
- * This software is released under the GPL-License.
- * Version lincan-0.3  17 Jun 2004
- */
+/**************************************************************************/
+/* File: can_quesysless.c - CAN queue functions for embedded target       */
+/*                                                                        */
+/* LinCAN - (Not only) Linux CAN bus driver                               */
+/* Copyright (C) 2002-2009 DCE FEE CTU Prague <http://dce.felk.cvut.cz>   */
+/* Copyright (C) 2002-2009 Pavel Pisa <pisa@cmp.felk.cvut.cz>             */
+/* Funded by OCERA and FRESCOR IST projects                               */
+/*                                                                        */
+/* LinCAN is free software; you can redistribute it and/or modify it      */
+/* under terms of the GNU General Public License as published by the      */
+/* Free Software Foundation; either version 2, or (at your option) any    */
+/* later version.  LinCAN is distributed in the hope that it will be      */
+/* useful, but WITHOUT ANY WARRANTY; without even the implied warranty    */
+/* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU    */
+/* General Public License for more details. You should have received a    */
+/* copy of the GNU General Public License along with LinCAN; see file     */
+/* COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,  */
+/* Cambridge, MA 02139, USA.                                              */
+/*                                                                        */
+/* To allow use of LinCAN in the compact embedded systems firmware        */
+/* and RT-executives (RTEMS for example), main authors agree with next    */
+/* special exception:                                                     */
+/*                                                                        */
+/* Including LinCAN header files in a file, instantiating LinCAN generics */
+/* or templates, or linking other files with LinCAN objects to produce    */
+/* an application image/executable, does not by itself cause the          */
+/* resulting application image/executable to be covered by                */
+/* the GNU General Public License.                                        */
+/* This exception does not however invalidate any other reasons           */
+/* why the executable file might be covered by the GNU Public License.    */
+/* Publication of enhanced or derived LinCAN files is required although.  */
+/**************************************************************************/
 
 #include "./can/can.h"
 #include "./can/can_sysdep.h"
 #include "./can/can_queue.h"
 
-//#define CAN_DEBUG
+// #define CAN_DEBUG
 
 extern atomic_t edge_num_cnt;
 
 #ifdef CAN_DEBUG
-       #define DEBUGQUE(fmt,args...) can_printk(KERN_ERR "can_quekern (debug): " fmt,\
+       #define DEBUGQUE(fmt,args...) can_printk(KERN_ERR "can_quesysless (debug): " fmt,\
        ##args)
 
 #else
        #define DEBUGQUE(fmt,args...)
 #endif
 
-#define ERRMSGQUE(fmt,args...) can_printk(KERN_ERR "can_quekern: " fmt,\
+#define ERRMSGQUE(fmt,args...) can_printk(KERN_ERR "can_quesysless: " fmt,\
        ##args)
 
 
@@ -42,7 +67,7 @@ LIST_HEAD(canque_dead_ends);
 /* retrieved by list_entry(canque_dead_ends.next,struct canque_ends_t,dead_peers) */
 LIST_HEAD(canque_dead_edges);
 /* retrieved by list_entry(canque_dead_edges.next,struct canque_edge_t,inpeers) */
-DECLARE_TASKLET(canque_dead_tl, canque_dead_func, 0);
+// DECLARE_TASKLET(canque_dead_tl, canque_dead_func, 0);
 /* activated by tasklet_schedule(&canque_dead_tl) */
 
 
@@ -83,9 +108,6 @@ void canque_dead_func(unsigned long data)
 
        can_spin_lock_irqsave(&canque_dead_func_lock, flags);
        entry=canque_dead_ends.next;
-       can_spin_unlock_irqrestore(&canque_dead_func_lock,flags);
-       /* lock can be released there, because only one instance of canque_dead_tl
-          can run at once and all other functions add ends only to head */
        while(entry!=&canque_dead_ends){
                qends=list_entry(entry,struct canque_ends_t,dead_peers);
                entry=entry->next;
@@ -105,21 +127,21 @@ void canque_dead_func(unsigned long data)
            #endif /*CAN_WITH_RTL*/
                free(qends);
        }
-
+       can_spin_unlock_irqrestore(&canque_dead_func_lock,flags);
 }
 
-static inline void canque_dead_tasklet_schedule(void)
-{
-    #ifdef CAN_WITH_RTL
-       if(!rtl_rt_system_is_idle()){
-               set_bit(CAN_RTL2LIN_PEND_DEAD_b,&canqueue_rtl2lin_pend);
-               rtl_global_pend_irq (canqueue_rtl_irq);
-               return;
-       }
-    #endif /*CAN_WITH_RTL*/
-
-       tasklet_schedule(&canque_dead_tl);
-}
+// static inline void canque_dead_tasklet_schedule(void)
+// {
+//     #ifdef CAN_WITH_RTL
+//     if(!rtl_rt_system_is_idle()){
+//             set_bit(CAN_RTL2LIN_PEND_DEAD_b,&canqueue_rtl2lin_pend);
+//             rtl_global_pend_irq (canqueue_rtl_irq);
+//             return;
+//     }
+//     #endif /*CAN_WITH_RTL*/
+//
+//     tasklet_schedule(&canque_dead_tl);
+// }
 
 
 void canque_edge_do_dead(struct canque_edge_t *edge)
@@ -155,7 +177,8 @@ void canque_edge_do_dead(struct canque_edge_t *edge)
        can_spin_lock_irqsave(&canque_dead_func_lock, flags);
        list_add(&edge->inpeers,&canque_dead_edges);
        can_spin_unlock_irqrestore(&canque_dead_func_lock, flags);
-       canque_dead_tasklet_schedule();
+//     canque_dead_tasklet_schedule();
+       canque_dead_func(0);
 }
 
 
@@ -195,28 +218,28 @@ void canqueue_notify_kern(struct canque_ends_t *qends, struct canque_edge_t *qed
 
        switch(what){
                case CANQUEUE_NOTIFY_EMPTY:
-                       wake_up(&qends->endinfo.fileinfo.emptyq);
+//                     wake_up(&qends->endinfo.fileinfo.emptyq);
                        if(canque_fifo_test_and_clear_fl(&qedge->fifo, FREEONEMPTY))
                                canque_edge_decref(qedge);
                        break;
                case CANQUEUE_NOTIFY_SPACE:
-                       wake_up(&qends->endinfo.fileinfo.writeq);
+//                     wake_up(&qends->endinfo.fileinfo.writeq);
                    #ifdef CAN_ENABLE_KERN_FASYNC
                        /* Asynchronous I/O processing */
                        kill_fasync(&qends->endinfo.fileinfo.fasync, SIGIO, POLL_OUT);
                    #endif /*CAN_ENABLE_KERN_FASYNC*/
                        break;
                case CANQUEUE_NOTIFY_PROC:
-                       wake_up(&qends->endinfo.fileinfo.readq);
+//                     wake_up(&qends->endinfo.fileinfo.readq);
                    #ifdef CAN_ENABLE_KERN_FASYNC
                        /* Asynchronous I/O processing */
                        kill_fasync(&qends->endinfo.fileinfo.fasync, SIGIO, POLL_IN);
                    #endif /*CAN_ENABLE_KERN_FASYNC*/
                        break;
                case CANQUEUE_NOTIFY_NOUSR:
-                       wake_up(&qends->endinfo.fileinfo.readq);
-                       wake_up(&qends->endinfo.fileinfo.writeq);
-                       wake_up(&qends->endinfo.fileinfo.emptyq);
+//                     wake_up(&qends->endinfo.fileinfo.readq);
+//                     wake_up(&qends->endinfo.fileinfo.writeq);
+//                     wake_up(&qends->endinfo.fileinfo.emptyq);
                        break;
                case CANQUEUE_NOTIFY_DEAD_WANTED:
                case CANQUEUE_NOTIFY_DEAD:
@@ -262,16 +285,16 @@ int canqueue_ends_init_kern(struct canque_ends_t *qends)
  * in case, that queue is full. Function is specific for Linux userspace clients.
  * Return Value: If there is no usable edge negative value is returned.
  */
-int canque_get_inslot4id_wait_kern(struct canque_ends_t *qends,
-       struct canque_edge_t **qedgep, struct canque_slot_t **slotp,
-       int cmd, unsigned long id, int prio)
-{
-       int ret=-1;
-       DEBUGQUE("canque_get_inslot4id_wait_kern for cmd %d, id %ld, prio %d\n",cmd,id,prio);
-       wait_event_interruptible((qends->endinfo.fileinfo.writeq),
-               (ret=canque_get_inslot4id(qends,qedgep,slotp,cmd,id,prio))!=-1);
-       return ret;
-}
+// int canque_get_inslot4id_wait_kern(struct canque_ends_t *qends,
+//     struct canque_edge_t **qedgep, struct canque_slot_t **slotp,
+//     int cmd, unsigned long id, int prio)
+// {
+//     int ret=-1;
+//     DEBUGQUE("canque_get_inslot4id_wait_kern for cmd %d, id %ld, prio %d\n",cmd,id,prio);
+//     wait_event_interruptible((qends->endinfo.fileinfo.writeq),
+//             (ret=canque_get_inslot4id(qends,qedgep,slotp,cmd,id,prio))!=-1);
+//     return ret;
+// }
 
 /**
  * canque_get_outslot_wait_kern - receive or wait for ready slot for given ends
@@ -285,15 +308,15 @@ int canque_get_inslot4id_wait_kern(struct canque_ends_t *qends,
  *     slot for given ends. Positive value is equal to the command
  *     slot has been allocated by the input side.
  */
-int canque_get_outslot_wait_kern(struct canque_ends_t *qends,
-       struct canque_edge_t **qedgep, struct canque_slot_t **slotp)
-{
-       int ret=-1;
-       DEBUGQUE("canque_get_outslot_wait_kern\n");
-       wait_event_interruptible((qends->endinfo.fileinfo.readq),
-               (ret=canque_test_outslot(qends,qedgep,slotp))!=-1);
-       return ret;
-}
+// int canque_get_outslot_wait_kern(struct canque_ends_t *qends,
+//     struct canque_edge_t **qedgep, struct canque_slot_t **slotp)
+// {
+//     int ret=-1;
+//     DEBUGQUE("canque_get_outslot_wait_kern\n");
+//     wait_event_interruptible((qends->endinfo.fileinfo.readq),
+//             (ret=canque_test_outslot(qends,qedgep,slotp))!=-1);
+//     return ret;
+// }
 
 /**
  * canque_sync_wait_kern - wait for all slots processing
@@ -304,14 +327,14 @@ int canque_get_outslot_wait_kern(struct canque_ends_t *qends,
  * Return Value: Positive value indicates, that edge empty state has been reached.
  *     Negative or zero value informs about interrupted wait or other problem.
  */
-int canque_sync_wait_kern(struct canque_ends_t *qends, struct canque_edge_t *qedge)
-{
-       int ret=-1;
-       DEBUGQUE("canque_sync_wait_kern\n");
-       wait_event_interruptible((qends->endinfo.fileinfo.emptyq),
-               (ret=canque_fifo_test_fl(&qedge->fifo,EMPTY)?1:0));
-       return ret;
-}
+// int canque_sync_wait_kern(struct canque_ends_t *qends, struct canque_edge_t *qedge)
+// {
+//     int ret=-1;
+//     DEBUGQUE("canque_sync_wait_kern\n");
+//     wait_event_interruptible((qends->endinfo.fileinfo.emptyq),
+//             (ret=canque_fifo_test_fl(&qedge->fifo,EMPTY)?1:0));
+//     return ret;
+// }
 
 
 /**
@@ -448,16 +471,16 @@ int canqueue_disconnect_list_kern(struct canque_ends_t *qends, struct list_head
 #endif /*USE_SYNC_DISCONNECT_EDGE_KERN*/
 
 
-int canqueue_ends_sync_all_kern(struct canque_ends_t *qends)
-{
-       struct canque_edge_t *qedge;
-
-       canque_for_each_inedge(qends, qedge){
-               DEBUGQUE("canque_sync_wait_kern called for edge %d\n",qedge->edge_num);
-               canque_sync_wait_kern(qends, qedge);
-       }
-       return 0;
-}
+// int canqueue_ends_sync_all_kern(struct canque_ends_t *qends)
+// {
+//     struct canque_edge_t *qedge;
+//
+//     canque_for_each_inedge(qends, qedge){
+//             DEBUGQUE("canque_sync_wait_kern called for edge %d\n",qedge->edge_num);
+//             canque_sync_wait_kern(qends, qedge);
+//     }
+//     return 0;
+// }
 
 
 void canqueue_ends_dispose_postpone(struct canque_ends_t *qends)
@@ -468,7 +491,8 @@ void canqueue_ends_dispose_postpone(struct canque_ends_t *qends)
        qends->ends_flags |= CAN_ENDSF_DEAD;
        list_add(&qends->dead_peers,&canque_dead_ends);
        can_spin_unlock_irqrestore(&canque_dead_func_lock, flags);
-       canque_dead_tasklet_schedule();
+       canque_dead_func(0);
+//     canque_dead_tasklet_schedule();
 }
 
 
@@ -480,38 +504,38 @@ void canqueue_ends_dispose_postpone(struct canque_ends_t *qends)
  *
  * Return Value: Function should be designed such way to not fail.
  */
-int canqueue_ends_dispose_kern(struct canque_ends_t *qends, int sync)
-{
-       int delayed;
-
-       DEBUGQUE("canqueue_ends_dispose_kern\n");
-       canqueue_block_inlist(qends);
-       canqueue_block_outlist(qends);
-
-       /*Wait for sending of all pending messages in the output FIFOs*/
-       if(sync)
-               canqueue_ends_sync_all_kern(qends);
-
-       /* Finish or kill all outgoing edges listed in inends */
-       delayed=canqueue_ends_kill_inlist(qends, 1);
-       /* Kill all incoming edges listed in outends */
-       delayed|=canqueue_ends_kill_outlist(qends);
-
-       wake_up(&qends->endinfo.fileinfo.readq);
-       wake_up(&qends->endinfo.fileinfo.writeq);
-       wake_up(&qends->endinfo.fileinfo.emptyq);
-
-       if(delayed){
-               canqueue_ends_dispose_postpone(qends);
-
-               DEBUGQUE("canqueue_ends_dispose_kern delayed\n");
-               return 1;
-       }
-
-       free(qends);
-       DEBUGQUE("canqueue_ends_dispose_kern finished\n");
-       return 0;
-}
+// int canqueue_ends_dispose_kern(struct canque_ends_t *qends, int sync)
+// {
+//     int delayed;
+//
+//     DEBUGQUE("canqueue_ends_dispose_kern\n");
+//     canqueue_block_inlist(qends);
+//     canqueue_block_outlist(qends);
+//
+//     /*Wait for sending of all pending messages in the output FIFOs*/
+//     if(sync)
+//             canqueue_ends_sync_all_kern(qends);
+//
+//     /* Finish or kill all outgoing edges listed in inends */
+//     delayed=canqueue_ends_kill_inlist(qends, 1);
+//     /* Kill all incoming edges listed in outends */
+//     delayed|=canqueue_ends_kill_outlist(qends);
+//
+// //  wake_up(&qends->endinfo.fileinfo.readq);
+// //  wake_up(&qends->endinfo.fileinfo.writeq);
+// //  wake_up(&qends->endinfo.fileinfo.emptyq);
+//
+//     if(delayed){
+//             canqueue_ends_dispose_postpone(qends);
+//
+//             DEBUGQUE("canqueue_ends_dispose_kern delayed\n");
+//             return 1;
+//     }
+//
+//     free(qends);
+//     DEBUGQUE("canqueue_ends_dispose_kern finished\n");
+//     return 0;
+// }
 
 void canqueue_kern_initialize()
 {