#include <stdio.h>
#include <system_def.h>
-#include <hal_intr.h>
+//#include <hal_intr.h>
#include "./can/can.h"
#include "./can/can_sysdep.h"
#include "./can/main.h"
#include <byteswap.h>
#endif
+#include "./can/can_bittiming.h"
+
extern struct canuser_t *canuser;
extern uint8_t vendor_ret;
return -1;
}
+
+
+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;
+}
+
int usbcan_vendor(usb_device_t *udev)
{
// wIndex, wValue, bRequest, wLength
return -1; // Should look like ok (0) or stall (-1)?
switch ( udev->request.bRequest) {
+
+ //lpc17xx
+ case USBCAN_VENDOR_SET_BITTIMING:
+ udev->ep0.complete_fnc=set_bittiming_complete_fnc;
+ return 1;
+
+ case USBCAN_VENDOR_GET_BITTIMING_CONST:
+ usbcan_get_bittiming_const_reply(udev);
+ return 1;
+ //lpc17xx - end
+
case USBCAN_VENDOR_EXT_MASK_SET:
udev->ep0.complete_fnc=set_ext_mask_complete_fnc;
return 1;