X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/blobdiff_plain/7eca1ac39aa9f2a65ba0607d55f7155f5a56ad15..e8a319104a2ef2df5b920950a15b1e39bfe3fad0:/lincan/src/c_can.c diff --git a/lincan/src/c_can.c b/lincan/src/c_can.c index e51181b..2add428 100644 --- a/lincan/src/c_can.c +++ b/lincan/src/c_can.c @@ -466,7 +466,7 @@ int c_can_config_irqs(struct canchip_t *pchip, DEBUGMSG("(c%d)calling c_can_config_irqs(...)\n", pchip->chip_idx); tempreg = c_can_read_reg_w(pchip, CCCR); - //DEBUGMSG("-> CAN Control Register: 0x%.4lx\n",(long)tempreg); + DEBUGMSG("-> CAN Control Register: 0x%4lx\n",(long)tempreg); c_can_write_reg_w(pchip, tempreg | (irqs & 0xe), CCCR); DEBUGMSG("-> Configured hardware interrupt delivery\n"); return 0; @@ -484,21 +484,30 @@ int c_can_pre_read_config(struct canchip_t *pchip, struct msgobj_t *pmsgobj) spin_lock( &c_can_if1lock ); - + if (c_can_if1_busycheck(pmsgobj->hostchip)) + goto error_enodev; + //loading Message Object in IF1 - if (c_can_if1_busycheck(pmsgobj->hostchip)) return -ENODEV; c_can_write_reg_w(pmsgobj->hostchip, readMaskCM, CCIF1CM); c_can_write_reg_w(pmsgobj->hostchip, pmsgobj->object, CCIF1CR); + + if (c_can_if1_busycheck(pmsgobj->hostchip)) + goto error_enodev; + //setting Message Valid Bit to zero - if (c_can_if1_busycheck(pmsgobj->hostchip)) return -ENODEV; c_can_write_reg_w(pmsgobj->hostchip, 0, CCIF1A2); c_can_write_reg_w(pmsgobj->hostchip, writeMaskCM, CCIF1CM); c_can_write_reg_w(pmsgobj->hostchip, pmsgobj->object, CCIF1CR); + + /* Only access when the C_CAN controller is idle */ + if (c_can_if1_busycheck(pmsgobj->hostchip)) + goto error_enodev; + //Configuring Message-Object - if (c_can_if1_busycheck(pmsgobj->hostchip)) return -ENODEV; - mcreg = c_can_read_reg_w(pmsgobj->hostchip, CCIF1CM); + mcreg = c_can_read_reg_w(pmsgobj->hostchip, CCIF1DMC); c_can_write_reg_w(pmsgobj->hostchip, ((mcreg & IFXMC_UMASK) | IFXMC_EOB | IFXMC_RXIE), CCIF1DMC); + //writing arbitration mask for extended or standart mode if (can_msgobj_test_fl(pmsgobj,RX_MODE_EXT)) { @@ -524,6 +533,12 @@ int c_can_pre_read_config(struct canchip_t *pchip, struct msgobj_t *pmsgobj) #endif return 0; + +error_enodev: + CANMSG("Timeout in c_can_if1_busycheck\n"); + spin_unlock(&c_can_if1lock); + return -ENODEV; + } /////////////////////////////////////////////////////////////////////// @@ -736,6 +751,29 @@ int c_can_stop_chip(struct canchip_t *pchip) return 0; } +int c_can_attach_to_chip(struct canchip_t *chip) +{ + return 0; +} + +int c_can_release_chip(struct canchip_t *chip) +{ + int temp; + + temp = c_can_read_reg_w(chip, CCCR); + + /* Disable IRQ generation */ + c_can_config_irqs(chip, 0); + + temp = c_can_read_reg_w(chip, CCCR); + + /* Power-down C_CAN, except this does nothing in the version 1.2 */ + c_can_stop_chip(chip); + + + return 0; +} + /////////////////////////////////////////////////////////////////////// /* *Check the TxOK bit of the Status Register and resets it afterwards. @@ -932,6 +970,8 @@ int c_can_register(struct chipspecops_t *chipspecops) chipspecops->remote_request=c_can_remote_request; chipspecops->enable_configuration=c_can_enable_configuration; chipspecops->disable_configuration=c_can_disable_configuration; + chipspecops->attach_to_chip=c_can_attach_to_chip; + chipspecops->release_chip=c_can_release_chip; chipspecops->set_btregs=c_can_set_btregs; chipspecops->start_chip=c_can_start_chip; chipspecops->stop_chip=c_can_stop_chip;