]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/sja1000.c
Header-files cleanup and CAN queue edges and ends locking reimplemented.
[lincan.git] / lincan / src / sja1000.c
index bca1fec9c86b6c2554b678fe8b288847803fef77..92115118be0afc465dd81c1ade039b70fd55e3b1 100644 (file)
@@ -7,12 +7,8 @@
  * Version lincan-0.2  9 Jul 2003
  */
 
-#include <linux/autoconf.h>
-
-#include <linux/sched.h>
-#include <linux/delay.h>
-#include <asm/irq.h>
-
+#include "../include/can.h"
+#include "../include/can_sysdep.h"
 #include "../include/main.h"
 #include "../include/sja1000.h"
 
@@ -79,9 +75,9 @@ int sja1000_chip_config(struct chip_t *chip)
        if (sja1000_standard_mask(chip,0x0000, 0xffff))
                return -ENODEV;
        
-       if (!baudrate)
-               baudrate=1000;
-       if (sja1000_baud_rate(chip,1000*baudrate,chip->clock,0,75,0))
+       if (!chip->baudrate)
+               chip->baudrate=1000000;
+       if (sja1000_baud_rate(chip,chip->baudrate,chip->clock,0,75,0))
                return -ENODEV;
 
        /* Enable hardware interrupts */
@@ -222,6 +218,7 @@ int sja1000_pre_write_config(struct chip_t *chip, struct msgobj_t *obj,
                                                        struct canmsg_t *msg)
 {
        int i=0, id=0;
+       int len;
 
        sja1000_start_chip(chip); //sja1000 goes automatically into reset mode on errors
 
@@ -236,7 +233,7 @@ int sja1000_pre_write_config(struct chip_t *chip, struct msgobj_t *obj,
                can_write_reg(chip, CMR_AT, SJACMR);
                i=0;
                while ( !(can_read_reg(chip, SJASR) & SR_TBS) &&
-                                               i++<MAX_TRANSMIT_WAIT_LOOPS) {
+                               i++<MAX_TRANSMIT_WAIT_LOOPS) {
                        udelay(i);
                }
                if (!(can_read_reg(chip, SJASR) & SR_TBS)) {
@@ -245,12 +242,14 @@ int sja1000_pre_write_config(struct chip_t *chip, struct msgobj_t *obj,
                }
        }
 
-       id = (msg->id<<5) | ((msg->flags&MSG_RTR)?ID0_RTR:0) | msg->length;
+       len = msg->length;
+       if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
+       id = (msg->id<<5) | ((msg->flags&MSG_RTR)?ID0_RTR:0) | len;
 
        can_write_reg(chip, id>>8, SJATXID1);
        can_write_reg(chip, id & 0xff , SJATXID0);
 
-       for (i=0; i<msg->length; i++)
+       for (i=0; i<len; i++)
                can_write_reg(chip, msg->data[i], SJATXDAT0+i);
 
        return 0;
@@ -382,17 +381,18 @@ irqreturn_t sja1000_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
 
 void sja1000_irq_read_handler(struct chip_t *chip, struct msgobj_t *obj)
 {
-       int i=0, id=0;
+       int i=0, id=0, len;
 
        do {
                id = can_read_reg(chip, SJARXID0) | (can_read_reg(chip, SJARXID1)<<8);
-               obj->rx_msg.length = id & 0x0f;
+               obj->rx_msg.length = len = id & 0x0f;
                obj->rx_msg.flags = id&ID0_RTR ? MSG_RTR : 0;
                obj->rx_msg.timestamp = 0;
                obj->rx_msg.cob = 0;
                obj->rx_msg.id = id>>5;
 
-               for (i=0; i<obj->rx_msg.length; i++)
+               if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
+               for (i=0; i<len; i++)
                        obj->rx_msg.data[i]=can_read_reg(chip, SJARXDAT0 + i);
 
                can_write_reg(chip, CMR_RRB, SJACMR);
@@ -406,6 +406,12 @@ void sja1000_irq_write_handler(struct chip_t *chip, struct msgobj_t *obj)
        int cmd;
        
        if(obj->tx_slot){
+               /* Do local transmitted message distribution if enabled */
+               if (processlocal){
+                       obj->tx_slot->msg.flags |= MSG_LOCAL;
+                       canque_filter_msg2edges(obj->qends, &obj->tx_slot->msg);
+               }
+               /* Free transmitted slot */
                canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
                obj->tx_slot=NULL;
        }