Some bugs related with transmission/reception fixed.
authorJiri Vanek <vanekjir@fel.cvut.cz>
Sat, 5 May 2012 10:22:38 +0000 (12:22 +0200)
committerJiri Vanek <vanekjir@fel.cvut.cz>
Sat, 5 May 2012 10:22:38 +0000 (12:22 +0200)
embedded/app/usbcan/can/lpc17xx_can.h
embedded/app/usbcan/lpc17xx_can.c
embedded/app/usbcan/main.c

index 4e50be1..5f9f4c0 100644 (file)
@@ -149,7 +149,7 @@ extern "C"
 
 //----------------------------------
 
-#define MAX_TRANSMIT_WAIT_LOOPS 20
+#define MAX_TRANSMIT_WAIT_LOOPS 10000
 
 void CAN_init(struct canchip_t *chip);
 void CAN_send(struct canchip_t *chip, canmsg_t* msg);
index 9157dcf..0d42658 100644 (file)
@@ -50,7 +50,7 @@ int can_lmc1_init_chip_data(struct candevice_t *candev, int chipnr){
        chip_data = (struct can_lmc1_chip_data*) candev->chip[chipnr]->chip_data;
 
        btc = &chip_data->btc;
-
+       
        // set bittiming constants
        btc->tseg1_min = 1;
        btc->tseg1_max = 16;
@@ -180,7 +180,18 @@ int lpc17xx_chip_config(struct canchip_t *chip){
 int lpc17xx_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj,
                                                        struct canmsg_t *msg)
 {
+       uint32_t i=0;   
        
+       // check status of TB1
+       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 0;
+       }       
+
        CAN_send(chip, msg);
 
        return 0;
@@ -199,6 +210,8 @@ int lpc17xx_send_msg(struct canchip_t *chip, struct msgobj_t *obj,
                if(i++<MAX_TRANSMIT_WAIT_LOOPS)
                        continue;
 
+               CANMSG("Abort transmission request\n");
+
                // request command to abort transmission request
                can_write_reg(chip, CAN_CMR_AT, CAN_CMR_o);
                break;
@@ -239,7 +252,6 @@ int lpc17xx_irq_handler(int irq, struct canchip_t *chip)
        uint32_t i;
        struct msgobj_t *obj;   
        obj = chip->msgobj[0];
-
        
        i = can_read_reg(chip, CAN_ICR_o);
 
@@ -355,7 +367,7 @@ int lpc17xx_set_bittiming(struct canchip_t *chip, int brp, int sjw, int tseg1, i
        
 
        //debug print
-       printf("BRP: %d, SJW: %d, TSEG1: %d, TSEG2: %d \n", brp+1, sjw+1, tseg1+1, tseg2+1);
+       CANMSG("BRP: %d, SJW: %d, TSEG1: %d, TSEG2: %d \n", brp+1, sjw+1, tseg1+1, tseg2+1);
 
        can_disable_irq(chip->chip_irq);
 
@@ -501,16 +513,6 @@ void CAN_send(struct canchip_t *chip, canmsg_t* msg){
        volatile uint32_t can_tfi1;
        uint32_t i=0;
 
-       // check status of TB1
-       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);
 
        can_tfi1 &= ~0x000F0000;
index 71fb5e7..6a5b3d4 100644 (file)
@@ -532,6 +532,7 @@ int main(void)
 
                        }
                        
+
                }