From: Pavel Pisa Date: Fri, 25 May 2012 17:11:36 +0000 (+0200) Subject: embedded ul_usb1: provide support for external bittiming parameters calculation. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/commitdiff_plain/34a7c9b2a76484048a8206cc4552b24ee036c90d?hp=2ddc142b196858f6025508f31dd0ce693d0f5c02 embedded ul_usb1: provide support for external bittiming parameters calculation. Signed-off-by: Pavel Pisa --- diff --git a/embedded/app/usbcan/main.c b/embedded/app/usbcan/main.c index 54b505a..873f4c6 100644 --- a/embedded/app/usbcan/main.c +++ b/embedded/app/usbcan/main.c @@ -416,9 +416,11 @@ int main(void) usb_check_events(&usb_device); usb_control_response(&usb_device); -// useless with lpc17xx: -// if (!(IO0PIN&P0_SJA1000_INT_PIN)) //INT PIN is inverted -// chip->chipspecops->irq_handler(0,chip); +#ifdef CONFIG_OC_LINCAN_CARD_ul_usb1 + /* polled IRQ mode for ul_usb1 board*/ + if (!(IO0PIN&P0_SJA1000_INT_PIN)) /* INT PIN is inverted */ + chip->chipspecops->irq_handler(0,chip); +#endif if (usb_device.ep_events & MASK_EP1RX) { //EP1RX - data waiting to receive diff --git a/embedded/app/usbcan/sja1000p.c b/embedded/app/usbcan/sja1000p.c index bbee1cd..76ad469 100644 --- a/embedded/app/usbcan/sja1000p.c +++ b/embedded/app/usbcan/sja1000p.c @@ -348,6 +348,70 @@ int sja1000p_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw, return 0; } + +/** + * sja1000p_set_bittiming: - set bittiming according to already computed parameters. + * @chip: pointer to chip state structure + * @bpr: baud rate prescaler + * @sjw: synchronization jump width in bittime quanta + * @tseg1: length of the segment 1 in bittime quanta + * @tseg2: length of the segment 2 in bittime quanta + * + * Return Value: negative value reports error. + * File: src/sja1000p.c + */ +int sja1000p_set_bittiming(struct canchip_t *chip, int brp, int sjw, int tseg1, int tseg2) +{ + uint8_t sam3times = 0; /* 0 = the bus is sampled once */ + + if((--brp)<0) + return -EINVAL; + + if((--sjw)<0) + return -EINVAL; + + if((--tseg1)<0) + return -EINVAL; + + if((--tseg2)<0) + return -EINVAL; + + + + if (sja1000p_enable_configuration(chip)) + return -ENODEV; + + can_write_reg(chip, sjw<<6 | brp, SJABTR0); + can_write_reg(chip, (sam3times<<7) | (tseg2<<4) | tseg1, SJABTR1); + + sja1000p_disable_configuration(chip); + + return 0; +} + +/** + * sja1000p_get_bittiming_const: - obtain description of chip bittiming calculation. + * @chip: pointer to chip state structure + * @btc: pointer to the structure filled by data + * + * Return Value: negative value reports error. + * File: src/sja1000p.c + */ +int sja1000p_get_bittiming_const(struct canchip_t *chip, struct can_bittiming_const *btc) +{ + btc->tseg1_min = 1; + btc->tseg1_max = 16; /* sjaMAX_TSEG1+1 */ + btc->tseg2_min = 1; + btc->tseg2_max = 8; /* sjaMAX_TSEG2+1 */ + btc->sjw_max = 4; + btc->brp_min = 1; + btc->brp_max = 64; + btc->brp_inc = 1; + + return 0; +} + + /** * sja1000p_read: - reads and distributes one or more received messages * @chip: pointer to chip state structure @@ -915,6 +979,8 @@ int sja1000p_register(struct chipspecops_t *chipspecops) chipspecops->stop_chip=sja1000p_stop_chip; chipspecops->irq_handler=sja1000p_irq_handler; chipspecops->irq_accept=NULL; + chipspecops->set_bittiming=sja1000p_set_bittiming; + chipspecops->get_bittiming_const=sja1000p_get_bittiming_const; return 0; }