From 081218e24682be11668ec5218dcd8b49630d7a87 Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Mon, 9 Apr 2012 17:17:30 +0200 Subject: [PATCH] Some bugs related with bit timing fixed. --- embedded/app/usbcan/lpc17xx_can.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/embedded/app/usbcan/lpc17xx_can.c b/embedded/app/usbcan/lpc17xx_can.c index fd09804..7cd0f56 100644 --- a/embedded/app/usbcan/lpc17xx_can.c +++ b/embedded/app/usbcan/lpc17xx_can.c @@ -3,6 +3,8 @@ static void CAN_configPin(); static void CAN_setBusTiming(struct canchip_t *chip); +#define MAX_TRANSMIT_WAIT_LOOPS 20 + //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- @@ -102,10 +104,20 @@ int lpc17xx_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj, int lpc17xx_send_msg(struct canchip_t *chip, struct msgobj_t *obj, struct canmsg_t *msg) { - + uint32_t i=0; + // write transmission request can_write_reg(chip, (CAN_CMR_TR | CAN_CMR_STB1), CAN_CMR_o); + while (!(can_read_reg(chip, CAN_SR_o) & (1<<3))){ + if(i++tx_slot){ /* Do local transmitted message distribution if enabled */ if (processlocal){ @@ -357,14 +370,22 @@ void CAN_recv(struct canchip_t *chip, canmsg_t* msg){ } + void CAN_send(struct canchip_t *chip, canmsg_t* msg){ volatile uint32_t data; volatile uint32_t can_tfi1; - uint32_t i; + uint32_t i=0; // check status of TB1 - while (!(can_read_reg(chip, CAN_SR_o) & CAN_SR_TBS1)){} + while (!(can_read_reg(chip, CAN_SR_o) & CAN_SR_TBS1)){ + if(i++