]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/sja1000.c
Added support for local message processing and some cleanups.
[lincan.git] / lincan / src / sja1000.c
index bca1fec9c86b6c2554b678fe8b288847803fef77..46033f2990baaba0806d96f34e9ea9fb820b62bf 100644 (file)
@@ -222,6 +222,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 +237,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 +246,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 +385,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 +410,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;
        }