struct canmsg_t *msg)
{
int i=0, id=0;
+ int len;
sja1000_start_chip(chip); //sja1000 goes automatically into reset mode on errors
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)) {
}
}
- 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;
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);
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;
}