+
+
+int set_bittiming_complete_fnc(struct usb_ep_t *ep, int status){
+ int dest_chip;
+
+ int32_t brp, sjw, tseg1, tseg2;
+
+ usb_device_t *udev=ep->udev;
+ unsigned char *data=ep->ptr - ep->actual;
+
+ if(ep->actual != USBCAN_BITTIMING_SIZE)
+ goto error;
+
+ if (udev->request.bRequest==USBCAN_VENDOR_SET_BITTIMING){
+ dest_chip=(udev->request.wIndex);
+ if ((dest_chip>=MAX_TOT_CHIPS)||(dest_chip<0))
+ goto error;
+ if (!chips_p[dest_chip])
+ goto error;
+
+ brp=*(int32_t *)(data);
+ sjw=*(int32_t *)(data+4);
+ tseg1=*(int32_t *)(data+8);
+ tseg2=*(int32_t *)(data+12);
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ brp = bswap_32(brp);
+ sjw = bswap_32(sjw);
+ tseg1 = bswap_32(tseg1);
+ tseg2 = bswap_32(tseg2);
+ #endif
+
+
+ if (chips_p[dest_chip]->chipspecops->set_bittiming(chips_p[dest_chip], brp, sjw, tseg1, tseg2)<0)
+ goto error;
+ }
+ return 0;
+
+error:
+ return -1;
+}
+
+int usbcan_get_bittiming_const_reply(usb_device_t *udev){
+ int dest_chip;
+ struct canchip_t *chip;
+
+ struct can_bittiming_const btc_buff;
+ struct can_bittiming_const *btc = &btc_buff;
+
+ uint8_t buffer[USBCAN_BITTIMING_CONST_SIZE];
+ uint32_t *ptr;
+
+ if (udev->request.bRequest==USBCAN_VENDOR_GET_BITTIMING_CONST){
+
+ dest_chip=(udev->request.wIndex);
+ if ((dest_chip>=MAX_TOT_CHIPS)||(dest_chip<0))
+ goto error;
+ if ((chip = chips_p[dest_chip]) == NULL)
+ goto error;
+ if (chip->chipspecops->get_bittiming_const == NULL){
+ goto error;
+ }
+
+ chip->chipspecops->get_bittiming_const(chip, btc);
+ ptr = (uint32_t*) buffer;
+
+ #if __BYTE_ORDER == __BIG_ENDIAN
+ *(ptr++) = bswap_32(chips_p[dest_chip]->clock);
+ *(ptr++) = bswap_32(btc->tseg1_min);
+ *(ptr++) = bswap_32(btc->tseg1_max);
+ *(ptr++) = bswap_32(btc->tseg2_min);
+ *(ptr++) = bswap_32(btc->tseg2_max);
+ *(ptr++) = bswap_32(btc->sjw_max);
+ *(ptr++) = bswap_32(btc->brp_min);
+ *(ptr++) = bswap_32(btc->brp_max);
+ *(ptr) = bswap_32(btc->brp_inc);
+ #else
+ *(ptr++) = chips_p[dest_chip]->clock;
+ *(ptr++) = btc->tseg1_min;
+ *(ptr++) = btc->tseg1_max;
+ *(ptr++) = btc->tseg2_min;
+ *(ptr++) = btc->tseg2_max;
+ *(ptr++) = btc->sjw_max;
+ *(ptr++) = btc->brp_min;
+ *(ptr++) = btc->brp_max;
+ *(ptr) = btc->brp_inc;
+ #endif
+
+ usb_send_control_data(udev, buffer, USBCAN_BITTIMING_CONST_SIZE);
+
+
+ }
+ return 0;
+
+error:
+ return -1;
+}
+