X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/3e5b474f9cd113def3be02af0cf6d5401a7427c9..659b098309c2bca57ac60a35a1b9900d6f28e74d:/lincan/src/sja1000.c diff --git a/lincan/src/sja1000.c b/lincan/src/sja1000.c index bca1fec..46033f2 100644 --- a/lincan/src/sja1000.c +++ b/lincan/src/sja1000.c @@ -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++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; ilength; i++) + for (i=0; idata[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; irx_msg.length; i++) + if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH; + for (i=0; irx_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; }