]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - embedded/app/usbcan/sja1000p.c
embedded: reintroduce missing emulated bus initialization for UL_USB1 board.
[lincan.git] / embedded / app / usbcan / sja1000p.c
index 8a527ffe23973e6a30b072211582e07cec0ade5a..76ad469a80a3622542664fcf694bf01fe335bcb2 100644 (file)
@@ -1,13 +1,37 @@
-/* sja1000.c
- * Linux CAN-bus device driver.
- * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
- * Changed for PeliCan mode SJA1000 by Tomasz Motylewski (BFAD GmbH)
- * T.Motylewski@bfad.de
- * Rewritten for 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: sja1000p.c - Philips/NXP SJA1000 chip PeliCanCAN mode support    */
+/*                                                                        */
+/* 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>             */
+/* Copyright (C) 2004-2005 Tomasz Motylewski (BFAD GmbH)                  */
+/* Funded by OCERA and FRESCOR IST projects                               */
+/* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl>      */
+/*                                                                        */
+/* 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"
@@ -324,6 +348,70 @@ int sja1000p_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw,
        return 0;
 }
 
+
+/**
+ * sja1000p_set_bittiming: - set bittiming according to already computed parameters.
+ * @chip: pointer to chip state structure
+ * @bpr: baud rate prescaler
+ * @sjw: synchronization jump width in bittime quanta
+ * @tseg1: length of the segment 1 in bittime quanta
+ * @tseg2: length of the segment 2 in bittime quanta
+ *
+ * Return Value: negative value reports error.
+ * File: src/sja1000p.c
+ */
+int sja1000p_set_bittiming(struct canchip_t *chip, int brp, int sjw, int tseg1, int tseg2)
+{
+       uint8_t sam3times = 0; /* 0 = the bus is sampled once */
+
+       if((--brp)<0)
+               return -EINVAL;
+
+       if((--sjw)<0)
+               return -EINVAL;
+
+       if((--tseg1)<0)
+               return -EINVAL;
+
+       if((--tseg2)<0)
+               return -EINVAL;
+       
+
+
+       if (sja1000p_enable_configuration(chip))
+               return -ENODEV;
+
+       can_write_reg(chip, sjw<<6 | brp, SJABTR0);
+       can_write_reg(chip, (sam3times<<7) | (tseg2<<4) | tseg1, SJABTR1);
+
+       sja1000p_disable_configuration(chip);
+       
+       return 0;
+}
+
+/**
+ * sja1000p_get_bittiming_const: - obtain description of chip bittiming calculation.
+ * @chip: pointer to chip state structure
+ * @btc: pointer to the structure filled by data
+ *
+ * Return Value: negative value reports error.
+ * File: src/sja1000p.c
+ */
+int sja1000p_get_bittiming_const(struct canchip_t *chip, struct can_bittiming_const *btc)
+{
+       btc->tseg1_min = 1;
+       btc->tseg1_max = 16; /* sjaMAX_TSEG1+1 */
+       btc->tseg2_min = 1;
+       btc->tseg2_max = 8; /* sjaMAX_TSEG2+1 */
+       btc->sjw_max = 4;
+       btc->brp_min = 1;
+       btc->brp_max = 64;
+       btc->brp_inc = 1;
+
+       return 0;
+}
+
+
 /**
  * sja1000p_read: - reads and distributes one or more received messages
  * @chip: pointer to chip state structure
@@ -891,6 +979,8 @@ int sja1000p_register(struct chipspecops_t *chipspecops)
        chipspecops->stop_chip=sja1000p_stop_chip;
        chipspecops->irq_handler=sja1000p_irq_handler;
        chipspecops->irq_accept=NULL;
+       chipspecops->set_bittiming=sja1000p_set_bittiming;
+       chipspecops->get_bittiming_const=sja1000p_get_bittiming_const;
        return 0;
 }