-// int best_error = 1000000000, error;
-// int best_tseg=0, best_brp=0, best_rate=0, brp=0;
-// int tseg=0, tseg1=0, tseg2=0;
-//
-// if (usbcan_enable_configuration(chip))
-// return -ENODEV;
-//
-// clock /=2;
-//
-// // tseg even = round down, odd = round up
-// for (tseg=(0+0+2)*2; tseg<=(sjaMAX_TSEG2+sjaMAX_TSEG1+2)*2+1; tseg++) {
-// brp = clock/((1+tseg/2)*rate)+tseg%2;
-// if (brp == 0 || brp > 64)
-// continue;
-// error = rate - clock/(brp*(1+tseg/2));
-// if (error < 0)
-// error = -error;
-// if (error <= best_error) {
-// best_error = error;
-// best_tseg = tseg/2;
-// best_brp = brp-1;
-// best_rate = clock/(brp*(1+tseg/2));
-// }
-// }
-// if (best_error && (rate/best_error < 10)) {
-// CANMSG("baud rate %d is not possible with %d Hz clock\n",
-// rate, 2*clock);
-// CANMSG("%d bps. brp=%d, best_tseg=%d, tseg1=%d, tseg2=%d\n",
-// best_rate, best_brp, best_tseg, tseg1, tseg2);
-// return -EINVAL;
-// }
-// tseg2 = best_tseg-(sampl_pt*(best_tseg+1))/100;
-// if (tseg2 < 0)
-// tseg2 = 0;
-// if (tseg2 > sjaMAX_TSEG2)
-// tseg2 = sjaMAX_TSEG2;
-// tseg1 = best_tseg-tseg2-2;
-// if (tseg1>sjaMAX_TSEG1) {
-// tseg1 = sjaMAX_TSEG1;
-// tseg2 = best_tseg-tseg1-2;
-// }
-//
-// DEBUGMSG("Setting %d bps.\n", best_rate);
-// DEBUGMSG("brp=%d, best_tseg=%d, tseg1=%d, tseg2=%d, sampl_pt=%d\n",
-// best_brp, best_tseg, tseg1, tseg2,
-// (100*(best_tseg-tseg2)/(best_tseg+1)));
-//
-//
-// can_write_reg(chip, sjw<<6 | best_brp, SJABTR0);
-// can_write_reg(chip, ((flags & BTR1_SAM) != 0)<<7 | (tseg2<<4)
-// | tseg1, SJABTR1);
-//
-// usbcan_disable_configuration(chip);
-
- return 0;
-}
-
-/**
- * usbcan_read: - reads and distributes one or more received messages
- * @chip: pointer to chip state structure
- * @obj: pinter to CAN message queue information
- *
- * File: src/usbcan.c
- */
-void usbcan_read(struct canchip_t *chip, struct msgobj_t *obj) {
-/* int i, flags, len, datastart;
- do {
- flags = can_read_reg(chip,SJAFRM);
- if(flags&sjaFRM_FF) {
- obj->rx_msg.id =
- (can_read_reg(chip,SJAID0)<<21) +
- (can_read_reg(chip,SJAID1)<<13) +
- (can_read_reg(chip,SJAID2)<<5) +
- (can_read_reg(chip,SJAID3)>>3);
- datastart = SJADATE;
- } else {
- obj->rx_msg.id =
- (can_read_reg(chip,SJAID0)<<3) +
- (can_read_reg(chip,SJAID1)>>5);
- datastart = SJADATS;
- }
- obj->rx_msg.flags =
- ((flags & sjaFRM_RTR) ? MSG_RTR : 0) |
- ((flags & sjaFRM_FF) ? MSG_EXT : 0);
- len = flags & sjaFRM_DLC_M;
- obj->rx_msg.length = len;
- if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
- for(i=0; i< len; i++) {
- obj->rx_msg.data[i]=can_read_reg(chip,datastart+i);
- }
-
- // fill CAN message timestamp
- can_filltimestamp(&obj->rx_msg.timestamp);
-
- canque_filter_msg2edges(obj->qends, &obj->rx_msg);