]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
Some bugs related with bit timing fixed.
authorJiri Vanek <vanekjir@fel.cvut.cz>
Mon, 9 Apr 2012 15:17:30 +0000 (17:17 +0200)
committerJiri Vanek <vanekjir@fel.cvut.cz>
Mon, 9 Apr 2012 15:17:30 +0000 (17:17 +0200)
embedded/app/usbcan/lpc17xx_can.c

index fd0980485bc95141a30d2d1c0ed2aa1c55692b01..7cd0f56abd2aae3980b6a4491b184a08177837ec 100644 (file)
@@ -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++<MAX_TRANSMIT_WAIT_LOOPS)
+                       continue;
+
+               // request command to abort transmission request
+               can_write_reg(chip, CAN_CMR_AT, CAN_CMR_o);
+               break;
+       }
+
        return 0;
 }
 
@@ -186,6 +198,7 @@ void lpc17xx_irq_write_handler(struct canchip_t *chip, struct msgobj_t *obj)
 {
        int cmd;
 
+
        if(obj->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++<MAX_TRANSMIT_WAIT_LOOPS)
+                       continue;
+
+               // request command to abort transmission request
+               can_write_reg(chip, CAN_CMR_AT, CAN_CMR_o);
+               return;
+       }       
 
        can_tfi1 = can_read_reg(chip, CAN_TFI1_o);