]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/c_can.c
The LinCAN driver license unified according to DCE FEE CTU head and superiors request.
[lincan.git] / lincan / src / c_can.c
index ed3991c7c90fc2ba69198c0aee6a637929300d54..e3e34aa5606b238f2107c8c1872e9d36f86cfd2f 100644 (file)
@@ -1,13 +1,39 @@
-/* c_can.c - Hynix HMS30c7202 ARM generic C_CAN module handling
- * Linux CAN-bus device driver.
- * Written by Sebastian Stolzenberg email:stolzi@sebastian-stolzenberg.de
- * Based on code from Arnaud Westenberg email:arnaud@wanadoo.nl
- * and Ake Hedman, eurosource, akhe@eurosource.se
- * 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: c_can.c - generic C_CAN Bosch IP core handling                   */
+/* The C_CAN core is found in Hynix HMS30c7202 and OKI OKI ML9620 devices */
+/*                                                                        */
+/* 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 Sebastian Stolzenberg <stolzi@sebastian-stolzenberg.de> */
+/* Funded by OCERA and FRESCOR IST projects                               */
+/* Based on CAN driver code by Arnaud Westenberg <arnaud@wanadoo.nl>      */
+/* and Ake Hedman, eurosource <akhe@eurosource.se>                        */
+/*                                                                        */
+/* 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.  */
+/**************************************************************************/
 
 #define __NO_VERSION__
 
 extern int stdmask;
 extern int extmask;
 
-can_spinlock_t c_can_spwlock = SPIN_LOCK_UNLOCKED;     // Spin lock for write operations
-can_spinlock_t c_can_sprlock = SPIN_LOCK_UNLOCKED;     // Spin lock for read operations
-can_spinlock_t c_can_if1lock = SPIN_LOCK_UNLOCKED;     // spin lock for the if1 register
-can_spinlock_t c_can_if2lock = SPIN_LOCK_UNLOCKED;     // spin lcok for the if2 register
+CAN_DEFINE_SPINLOCK(c_can_spwlock);    // Spin lock for write operations
+CAN_DEFINE_SPINLOCK(c_can_sprlock);    // Spin lock for read operations
+CAN_DEFINE_SPINLOCK(c_can_if1lock);    // spin lock for the if1 register
+CAN_DEFINE_SPINLOCK(c_can_if2lock);    // spin lcok for the if2 register
 
 /**
  * c_can_enable_configuration - enable chip configuration mode
@@ -96,10 +122,10 @@ int c_can_chip_config(struct canchip_t *pchip)
                return -1;
 
        if (pchip->baudrate == 0)
-               pchip->baudrate = 1000;
+               pchip->baudrate = 1000000;
 
        if (c_can_baud_rate
-           (pchip, pchip->baudrate * 1000, pchip->clock, 0, 75, 0)) {
+           (pchip, pchip->baudrate, pchip->clock, 0, 75, 0)) {
                CANMSG("Error configuring baud rate\n");
                return -ENODEV;
        }
@@ -143,8 +169,8 @@ int c_can_if1_busycheck(struct canchip_t *pchip)
        unsigned short comreg = 0;
 
        comreg = c_can_read_reg_w(pchip, CCIF1CR);
-       while ((comreg & IFXCR_BUSY) && (i <= 10)) {
-               udelay(100);    //100 microseconds
+       while ((comreg & IFXCR_BUSY) && (i <= 100)) {
+               udelay(1);      //1 microseconds
                i++;
                comreg = c_can_read_reg_w(pchip, CCIF1CR);
        }
@@ -167,8 +193,8 @@ int c_can_if2_busycheck(struct canchip_t *pchip)
        unsigned short comreg = 0;
 
        comreg = c_can_read_reg_w(pchip, CCIF2CR);
-       while ((comreg & IFXCR_BUSY) && (i <= 10)) {
-               udelay(100);    //100 microseconds
+       while ((comreg & IFXCR_BUSY) && (i <= 100)) {
+               udelay(1);      //1 microseconds
                i++;
                comreg = c_can_read_reg_w(pchip, CCIF2CR);
        }
@@ -296,6 +322,11 @@ int c_can_mask(struct msgobj_t *pmsgobj, u32 mask, u16 usedirbit)
        if (c_can_if1_busycheck(pmsgobj->hostchip))
                return -ENODEV;
 
+       //set indication, that mask is used
+       tempreg = c_can_read_reg_w(pmsgobj->hostchip, CCIF1DMC);
+       c_can_write_reg_w(pmsgobj->hostchip, tempreg | IFXMC_UMASK,
+               CCIF1DMC);
+
        //writing acceptance mask for extended or standart mode
        if (can_msgobj_test_fl(pmsgobj, RX_MODE_EXT)) {
                if (usedirbit)
@@ -317,6 +348,7 @@ int c_can_mask(struct msgobj_t *pmsgobj, u32 mask, u16 usedirbit)
                                          ((mask << 2) & 0x1FFC), CCIF1M2);
                c_can_write_reg_w(pmsgobj->hostchip, 0, CCIF1M1);
        }
+
        //seting Message Valid Bit to one
        tempreg = c_can_read_reg_w(pmsgobj->hostchip, CCIF1A2);
        c_can_write_reg_w(pmsgobj->hostchip, tempreg | IFXARB2_MVAL, CCIF1A2);